{ "version": 3, "sources": ["../../../currency_converter/converter.ts"], "sourcesContent": ["// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later\nimport { PopStateHandlers, setURLParam } from \"@utils/utils.js\";\n\nlet bigIntType = \"bigint\";\ntry {\n BigInt(69);\n} catch {\n // fix for cool browsers like Pale Moon that don't support BigInt\n // eslint-disable-next-line no-global-assign\n BigInt = Number as unknown as BigIntConstructor;\n bigIntType = \"number\";\n}\nconst output = document.getElementById(\"output\") as HTMLInputElement;\n\nconst fields: [\n HTMLInputElement,\n HTMLInputElement,\n HTMLInputElement,\n HTMLInputElement,\n] = [\n document.getElementById(\"euro\") as HTMLInputElement, // Euro\n document.getElementById(\"mark\") as HTMLInputElement, // Deutsche Mark\n document.getElementById(\"ost\") as HTMLInputElement, // Ostmark\n document.getElementById(\"schwarz\") as HTMLInputElement, // Ostmark auf dem Schwarzmarkt\n];\nconst factors: [\n bigint | number,\n bigint | number,\n bigint | number,\n bigint | number,\n] = [\n BigInt(1), // Euro\n BigInt(2), // Deutsche Mark\n BigInt(4), // Ostmark\n BigInt(20), // Ostmark auf dem Schwarzmarkt\n];\nconst numberRegex = /^(?:\\d+|(?:\\d+)?[,.]\\d{1,2}|\\d+[,.](?:\\d{1,2})?)?$/;\n\nconst isZero = (str: string) => /^0*$/.test(str);\n\nfunction getDisplayValue(wert: bigint | number | string): string | null {\n if (typeof wert === \"string\") {\n wert = strToBigInt(wert);\n }\n\n if (typeof wert !== bigIntType) {\n alert(`Ungültiger Wert ${wert} mit type ${typeof wert}`);\n return null;\n }\n\n if (typeof wert === \"number\") {\n wert = Math.floor(wert);\n }\n\n let str = wert.toString();\n if (bigIntType === \"number\" && str.includes(\"e\")) {\n const [num, pow] = str.split(\"e\");\n\n // @ts-expect-error TS2532\n if (pow.startsWith(\"-\")) {\n return \"0\"; // too small to be displayed\n }\n\n // @ts-expect-error TS2532\n // eslint-disable-next-line prefer-const\n let [int, dec] = num.split(\".\");\n dec = dec ?? \"\";\n // @ts-expect-error TS2345\n str = (int ?? \"\") + dec + \"0\".repeat(parseInt(pow) - dec.length);\n }\n if (isZero(str)) {\n return \"0\"; // is empty string or 0\n }\n\n const dec = str.slice(-2); // last two chars or whole str if len <= 2\n return (\n (str.slice(0, -2) || \"0\") + // integer part, but \"0\" instead of \"\"\n (\n isZero(dec)\n ? \"\" // if is integer do not append\n : \",\" + (dec.length === 1 ? \"0\" : \"\") + dec\n )\n );\n}\n\nfunction strToBigInt(str: string): bigint | number {\n if (isZero(str)) {\n return BigInt(0);\n }\n\n let [int, dec] = [str, \"00\"];\n if (str.includes(\",\")) {\n // @ts-expect-error TS2322\n [int, dec] = str.split(\",\");\n } else if (str.includes(\".\")) {\n // @ts-expect-error TS2322\n [int, dec] = str.split(\".\");\n }\n if (dec.length !== 2) {\n // get the first two digits after the comma, fill with 0 if needed\n dec = (dec + \"00\").slice(0, 2);\n }\n return BigInt(int + dec);\n}\n\nPopStateHandlers[\"currencyConverter\"] = (e: PopStateEvent) => {\n setAllFields(\n strToBigInt((e.state as { euro: string }).euro.toString()),\n );\n};\n\nconst setEuroParam = (euroVal: string, push: boolean) =>\n setURLParam(\n \"euro\",\n euroVal,\n { euro: euroVal },\n \"currencyConverter\",\n push,\n );\n\nfunction setAllFields(\n euroValue: bigint | number,\n ignored: number | null = null,\n) {\n setEuroParam(getDisplayValue(euroValue) ?? \"null\", false);\n for (let i = 0; i < 4; i++) {\n const value = getDisplayValue(\n (euroValue as bigint) * (factors[i] as bigint),\n );\n // @ts-expect-error TS2532\n fields[i].placeholder = value ?? \"null\";\n if (i !== ignored) {\n // @ts-expect-error TS2532\n fields[i].value = value ?? \"null\";\n }\n }\n}\n\nconst updateOutput = () => {\n // dprint-ignore\n output.value = fields[0].value + \" Euro, das sind ja \" +\n fields[1].value + \" Mark; \" +\n fields[2].value + \" Ostmark und \" +\n fields[3].value + \" Ostmark auf dem Schwarzmarkt!\";\n};\n\nfunction onSubmit(event: Event) {\n event.preventDefault();\n for (const field of fields) {\n field.value = getDisplayValue(field.value) ?? \"null\";\n }\n setEuroParam(fields[0].value, true);\n updateOutput();\n}\n\nfor (let i = 0; i < 4; i++) {\n // @ts-expect-error TS2532\n fields[i].oninput = () => {\n // remove \"invalid\" class\n for (const field of fields) {\n field.className = \"\";\n }\n // add \"invalid\" class if input is not a number\n // @ts-expect-error TS2532\n if (!numberRegex.test(fields[i].value)) {\n // @ts-expect-error TS2532\n fields[i].className = \"invalid\";\n return;\n }\n // parse input as it is a number\n setAllFields(\n // @ts-expect-error TS2532\n (strToBigInt(fields[i].value) as bigint) /\n (factors[i] as bigint),\n i,\n );\n\n updateOutput();\n };\n}\n// set the value of the fields to the placeholder set by Tornado\nfor (const field of fields) {\n field.value = field.placeholder;\n}\n// fix form submit\n(document.getElementById(\"form\") as HTMLFormElement).onsubmit = onSubmit;\n"], "mappings": "AAAA;AACA,OAAS,oBAAAA,EAAkB,eAAAC,MAAmB,+CAE9C,IAAIC,EAAa,SACjB,GAAI,CACA,OAAO,EAAE,CACb,OAAQC,EAAA,CAGJ,OAAS,OACTD,EAAa,QACjB,CACA,IAAME,EAAS,SAAS,eAAe,QAAQ,EAEzCC,EAKF,CACA,SAAS,eAAe,MAAM,EAC9B,SAAS,eAAe,MAAM,EAC9B,SAAS,eAAe,KAAK,EAC7B,SAAS,eAAe,SAAS,CACrC,EACMC,EAKF,CACA,OAAO,CAAC,EACR,OAAO,CAAC,EACR,OAAO,CAAC,EACR,OAAO,EAAE,CACb,EACMC,EAAc,qDAEdC,EAAUC,GAAgB,OAAO,KAAKA,CAAG,EAE/C,SAASC,EAAgBC,EAA+C,CAKpE,GAJI,OAAOA,GAAS,WAChBA,EAAOC,EAAYD,CAAI,GAGvB,OAAOA,IAAST,EAChB,aAAM,mBAAmB,OAAAS,EAAI,cAAa,cAAOA,EAAM,EAChD,KAGP,OAAOA,GAAS,WAChBA,EAAO,KAAK,MAAMA,CAAI,GAG1B,IAAI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BW,CAAS,IAAzB,KAAAE,EAA8B,OAAQ,EAAK,EACxD,QAASC,EAAI,EAAGA,EAAI,EAAGA,IAAK,CACxB,IAAMC,EAAQf,EACTW,EAAwBf,EAAQkB,CAAC,CACtC,EAEAnB,EAAOmB,CAAC,EAAE,YAAcC,GAAA,KAAAA,EAAS,OAC7BD,IAAMF,IAENjB,EAAOmB,CAAC,EAAE,MAAQC,GAAA,KAAAA,EAAS,OAEnC,CACJ,CAEA,IAAMC,EAAe,IAAM,CAEvBtB,EAAO,MAAQC,EAAO,CAAC,EAAE,MAAQ,sBAC7BA,EAAO,CAAC,EAAE,MAAQ,UAClBA,EAAO,CAAC,EAAE,MAAQ,gBAClBA,EAAO,CAAC,EAAE,MAAQ,gCAC1B,EAEA,SAASsB,EAASC,EAAc,CAlJhC,IAAAL,EAmJIK,EAAM,eAAe,EACrB,QAAWC,KAASxB,EAChBwB,EAAM,OAAQN,EAAAb,EAAgBmB,EAAM,KAAK,IAA3B,KAAAN,EAAgC,OAElDL,EAAab,EAAO,CAAC,EAAE,MAAO,EAAI,EAClCqB,EAAa,CACjB,CAEA,QAASF,EAAI,EAAGA,EAAI,EAAGA,IAEnBnB,EAAOmB,CAAC,EAAE,QAAU,IAAM,CAEtB,QAAWK,KAASxB,EAChBwB,EAAM,UAAY,GAItB,GAAI,CAACtB,EAAY,KAAKF,EAAOmB,CAAC,EAAE,KAAK,EAAG,CAEpCnB,EAAOmB,CAAC,EAAE,UAAY,UACtB,MACJ,CAEAP,EAEKL,EAAYP,EAAOmB,CAAC,EAAE,KAAK,EACvBlB,EAAQkB,CAAC,EACdA,CACJ,EAEAE,EAAa,CACjB,EAGJ,QAAWG,KAASxB,EAChBwB,EAAM,MAAQA,EAAM,YAGvB,SAAS,eAAe,MAAM,EAAsB,SAAWF", "names": ["PopStateHandlers", "setURLParam", "bigIntType", "e", "output", "fields", "factors", "numberRegex", "isZero", "str", "getDisplayValue", "wert", "strToBigInt", "num", "pow", "int", "dec", "setAllFields", "setEuroParam", "euroVal", "push", "euroValue", "ignored", "_a", "i", "value", "updateOutput", "onSubmit", "event", "field"] }