{ "version": 3, "sources": ["../../../swapped_words/swap.ts"], "sourcesContent": ["// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later\nimport { e as getElementById, PopStateHandlers, post } from \"@utils/utils.js\";\n\nconst textInput = getElementById(\"text\") as HTMLInputElement;\nconst configInput = getElementById(\n \"config-textarea\",\n) as HTMLTextAreaElement;\nconst outputText = getElementById(\"output\")!;\nconst errorText = getElementById(\"error-msg\") as HTMLDivElement;\n\nif (errorText.innerHTML.trim()) {\n alert(errorText.innerHTML.trim());\n}\n\ninterface SwappedWordsData { // this is a mix of error data and success data\n stateType: string;\n error: string | null;\n line_num: number;\n line: string;\n text: string;\n config: string;\n replaced_text: string;\n}\n\nfunction ondata(\n data: SwappedWordsData | undefined,\n onpopstate = false,\n) {\n if (!data) {\n console.log(\"data is falsy!\");\n return;\n }\n if (data.error) {\n onerror(data);\n return;\n }\n if (!onpopstate) {\n data.stateType = \"swappedWords\";\n history.pushState(\n data,\n \"Vertauschte Wörter\",\n location.href,\n );\n }\n textInput.value = data.text || \"\";\n configInput.value = data.config || \"\";\n outputText.innerText = data.replaced_text || \"\";\n errorText.innerText = \"\";\n}\n\nfunction onerror(error: unknown) {\n const e = error as { error: string | null; line_num: number; line: string };\n console.error(e);\n if (e.error) {\n alert(e.error);\n errorText.innerText = `${e.error} In line ${e.line_num}: \"${e.line}\"`;\n } else {\n alert(e);\n errorText.innerText = JSON.stringify(e);\n }\n}\n\n(getElementById(\"form\") as HTMLFormElement).onsubmit = (e) => {\n e.preventDefault();\n};\n\n(getElementById(\"reset\")!).onclick = () =>\n post(\n \"/api/vertauschte-woerter\",\n {\n text: textInput.value,\n minify_config: false,\n return_config: true,\n },\n ondata,\n onerror,\n );\n\n(getElementById(\"submit\")!).onclick = () =>\n post(\n \"/api/vertauschte-woerter\",\n {\n text: textInput.value || \"\",\n config: configInput.value || \"\",\n minify_config: false,\n return_config: true,\n },\n ondata,\n onerror,\n );\n\nPopStateHandlers[\"swappedWords\"] = (event: PopStateEvent) => {\n if (event.state) {\n ondata(event.state as SwappedWordsData, true);\n }\n};\n"], "mappings": "AAAA;AACA,OAAS,KAAKA,EAAgB,oBAAAC,EAAkB,QAAAC,MAAY,+CAE5D,IAAMC,EAAYH,EAAe,MAAM,EACjCI,EAAcJ,EAChB,iBACJ,EACMK,EAAaL,EAAe,QAAQ,EACpCM,EAAYN,EAAe,WAAW,EAExCM,EAAU,UAAU,KAAK,GACzB,MAAMA,EAAU,UAAU,KAAK,CAAC,EAapC,SAASC,EACLC,EACAC,EAAa,GACf,CACE,GAAKD,EAIL,IAAIA,EAAK,MAAO,CACZE,EAAQF,CAAI,EACZ,MACJ,CACKC,IACDD,EAAK,UAAY,eACjB,QAAQ,UACJA,EACA,qBACA,SAAS,IACb,GAEJL,EAAU,MAAQK,EAAK,MAAQ,GAC/BJ,EAAY,MAAQI,EAAK,QAAU,GACnCH,EAAW,UAAYG,EAAK,eAAiB,GAC7CF,EAAU,UAAY,GAC1B,CAEA,SAASI,EAAQC,EAAgB,CAC7B,IAAMC,EAAID,EACV,QAAQ,MAAMC,CAAC,EACXA,EAAE,OACF,MAAMA,EAAE,KAAK,EACbN,EAAU,UAAY,GAAG,OAAAM,EAAE,MAAK,aAAY,OAAAA,EAAE,SAAQ,OAAM,OAAAA,EAAE,KAAI,OAElE,MAAMA,CAAC,EACPN,EAAU,UAAY,KAAK,UAAUM,CAAC,EAE9C,CAECZ,EAAe,MAAM,EAAsB,SAAY,GAAM,CAC1D,EAAE,eAAe,CACrB,EAECA,EAAe,OAAO,EAAI,QAAU,IACjCE,EACI,2BACA,CACI,KAAMC,EAAU,MAChB,cAAe,GACf,cAAe,EACnB,EACAI,EACAG,CACJ,EAEHV,EAAe,QAAQ,EAAI,QAAU,IAClCE,EACI,2BACA,CACI,KAAMC,EAAU,OAAS,GACzB,OAAQC,EAAY,OAAS,GAC7B,cAAe,GACf,cAAe,EACnB,EACAG,EACAG,CACJ,EAEJT,EAAiB,aAAmBY,GAAyB,CACrDA,EAAM,OACNN,EAAOM,EAAM,MAA2B,EAAI,CAEpD", "names": ["getElementById", "PopStateHandlers", "post", "textInput", "configInput", "outputText", "errorText", "ondata", "data", "onpopstate", "onerror", "error", "e", "event"] }