{"version":3,"file":"mountApp-0eb72HN8.js","sources":["../../../app/frontend/utility/helpers.ts","../../../app/frontend/utility/mountApp.ts"],"sourcesContent":["import { camelCase } from \"lodash\";\nimport { toRaw, isRef, isReactive } from \"vue\";\n\nexport function camelizeKeys(obj: any): any {\n if (Array.isArray(obj)) {\n return obj.map((v) => camelizeKeys(v));\n } else if (obj != null && obj.constructor === Object) {\n return Object.keys(obj).reduce(\n (result, key) => ({\n ...result,\n [camelCase(key)]: camelizeKeys(obj[key]),\n }),\n {}\n );\n }\n return obj;\n}\n\nexport function dataUriToBlob(dataURI: string): Blob {\n var binary = atob(dataURI.split(\",\")[1]);\n var array = [];\n for (var i = 0; i < binary.length; i++) {\n array.push(binary.charCodeAt(i));\n }\n return new Blob([new Uint8Array(array)], { type: \"image/jpeg\" });\n}\n\nexport function snakeToHuman(str: string) {\n const result = str.replace(/_/g, \" \");\n return result.replace(/\\b\\w/g, (char) => char.toUpperCase());\n}\n\nexport function niceNumber(number: number) {\n const formatter = new Intl.NumberFormat(\"en-UK\");\n return formatter.format(number);\n}\n\nexport function niceCurrency(pence: number) {\n const formatter = new Intl.NumberFormat(\"en-UK\", {\n style: \"currency\",\n currency: \"GBP\",\n });\n return formatter.format(pence / 100);\n}\n\nexport function deepToRaw(obj: any) {\n // If the object is a ref, unwrap it\n if (isRef(obj)) {\n obj = obj.value;\n }\n\n // If the object is reactive, get its raw value\n if (isReactive(obj)) {\n obj = toRaw(obj);\n }\n\n // If the object is an array or a plain object, clone it deeply\n\n if (obj instanceof Blob || obj instanceof File || obj instanceof Date) {\n return obj;\n }\n\n if (Array.isArray(obj) || (obj !== null && typeof obj === \"object\")) {\n const clonedObj = Array.isArray(obj)\n ? ([] as any[])\n : ({} as Record);\n for (const key in obj) {\n if (typeof obj[key] === \"function\") {\n continue;\n }\n\n clonedObj[key] = deepToRaw(obj[key]);\n }\n return clonedObj;\n }\n\n // Return the value for other data types (numbers, strings, etc.)\n return obj;\n}\n","import { camelizeKeys } from \"../utility/helpers\";\nimport { Component, createApp } from \"vue\";\n\nlet mountedApps: Record = {};\n\nexport default function mountApp(name: string, RootComponent: Component) {\n window.addEventListener(\"DOMContentLoaded\", () => {\n if (mountedApps[name]) return;\n\n const el = document.getElementById(name);\n if (!el)\n throw new Error(`Could not mount vue app ${name}, element not found`);\n\n const props: Record = {};\n // Takes all the props in the data of the element and gets them with the correct prop names\n // Eg. takes data-vue-prop-name=val and puts it into { name: val }\n for (const key of Object.keys(el.dataset)) {\n if (!key.includes(\"vueProp\")) continue;\n\n const value = el.dataset[key];\n if (typeof value === \"undefined\") continue;\n\n let propName = key.replace(\"vueProp\", \"\");\n propName = `${propName[0].toLowerCase()}${propName.slice(1)}`;\n try {\n props[propName] = camelizeKeys(JSON.parse(value));\n } catch {\n props[propName] = value;\n }\n }\n\n const app = createApp(\n RootComponent,\n camelizeKeys(props) as Record\n );\n\n app.mount(el);\n mountedApps[name] = true;\n });\n}\n"],"names":["camelizeKeys","obj","v","result","key","camelCase","snakeToHuman","str","char","niceNumber","number","niceCurrency","pence","deepToRaw","isRef","isReactive","toRaw","clonedObj","mountedApps","mountApp","name","RootComponent","el","props","value","propName","createApp"],"mappings":"iYAGO,SAASA,EAAaC,EAAe,CACtC,OAAA,MAAM,QAAQA,CAAG,EACZA,EAAI,IAAKC,GAAMF,EAAaE,CAAC,CAAC,EAC5BD,GAAO,MAAQA,EAAI,cAAgB,OACrC,OAAO,KAAKA,CAAG,EAAE,OACtB,CAACE,EAAQC,KAAS,CAChB,GAAGD,EACH,CAACE,EAAAA,UAAUD,CAAG,CAAC,EAAGJ,EAAaC,EAAIG,CAAG,CAAC,CAAA,GAEzC,CAAC,CAAA,EAGEH,CACT,CAWO,SAASK,EAAaC,EAAa,CAExC,OADeA,EAAI,QAAQ,KAAM,GAAG,EACtB,QAAQ,QAAUC,GAASA,EAAK,aAAa,CAC7D,CAEO,SAASC,EAAWC,EAAgB,CAElC,OADW,IAAI,KAAK,aAAa,OAAO,EAC9B,OAAOA,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