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IAChD,CACA,MAAM,EAAU,SAAS,KAAK,UACxB,EAAY,EAAU,UAAU,GACtC,SAAS,KAAK,UAAY,CAC3B,CAEA,SAAS,iBAAiB,oBAAoB,KAC7C,iBAAiB,WAIjB,qBACA,uCACA","file":"/gh/gustambolopez/htmlium@latest/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /gh/gustambolopez/htmlium@latest/src/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * @typedef {Object} Config\n * @property {Object} component\n * @property {Object} interpolation\n * @property {Object} security\n */\n\n/*\nif you have any questions reach me at discord:\n      _  __      _ _ _\n  ___/ |/ /_  __| (_) |__\n / __| | '_ \\/ _` | | '_ \\\n \\__ \\ | (_) | (_| | | | |\n |___/_|\\___/\\__,_|_|_| |_|\n*/\n\n// SPDX-License-Identifier: MIT\n// Copyright (c) 2025 s16.org\n// License: https://opensource.org/license/mit/\n\n// the customizable part ig\nconst Config = {\n\tcomponent: {\n\t\ttagName: \"htmlium\",\n\t\tattributeName: \"loadcomponent\",\n\t\tsetTagName: \"htmlium-set\",\n\t},\n\tinterpolation: {\n\t\tstart: \"{{\",\n\t\tend: \"}}\",\n\t\tsanitize: true,\n\t},\n\tsecurity: {\n\t\tsanitizeHtml: true,\n\t},\n};\n// TODO... add better sanitization, add auto updating with no memory leaks\nconst sanitize = {\n\t\"<\": \"&lt;\",\n\t\">\": \"&gt;\",\n\t\"&\": \"&amp;\",\n\t'\"': \"&quot;\",\n\t\"'\": \"&#39;\",\n};\n\nimport jsyaml from \"https://cdn.jsdelivr.net/npm/js-yaml@4.1.0/dist/js-yaml.mjs\";\n\nasync function loadcomponents(url = \"components.yaml\") {\n\tconst response = await fetch(url);\n\tif (!response.ok) throw new Error(`Failed to load components from ${url}`);\n\tconst text = await response.text();\n\treturn jsyaml.load(text);\n}\n\nclass Processor {\n\t/**\n\t * @param {Config} config\n\t */\n\tconstructor(config = {}) {\n\t\tthis.config = this.mergeConfig(config);\n\t\tthis.regexpcache = new Map();\n\t\tthis.extcomps = {};\n\t}\n\n\t/**\n\t * @param {Object} components\n\t */\n\texternalcomponents(components) {\n\t\tthis.extcomps = components || {};\n\t}\n\n\tmergeConfig(config) {\n\t\tconst merged = JSON.parse(JSON.stringify(Config));\n\t\tthis.deepMerge(merged, config);\n\t\treturn merged;\n\t}\n\n\tdeepMerge(target, source) {\n\t\tfor (const key of Object.keys(source)) {\n\t\t\tif (\n\t\t\t\tsource[key] &&\n\t\t\t\ttypeof source[key] === \"object\" &&\n\t\t\t\t!Array.isArray(source[key])\n\t\t\t) {\n\t\t\t\tif (!target[key]) target[key] = {};\n\t\t\t\tthis.deepMerge(target[key], source[key]);\n\t\t\t} else {\n\t\t\t\ttarget[key] = source[key];\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * @param {string} str\n\t */\n\tescaperegexp(str) {\n\t\treturn str.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\t}\n\n\tregxep(key, factory) {\n\t\tif (!this.regexpcache.has(key)) {\n\t\t\tthis.regexpcache.set(key, factory());\n\t\t}\n\t\treturn this.regexpcache.get(key);\n\t}\n\n\tparsecomps(content) {\n\t\tconst { component } = this.config;\n\t\tconst pattern = this.regxep(\n\t\t\t\"componentSet\",\n\t\t\t() =>\n\t\t\t\tnew RegExp(\n\t\t\t\t\t`<${component.setTagName}\\\\s+([^>]+?)>([\\\\s\\\\S]*?)<\\\\/${component.setTagName}>`,\n\t\t\t\t\t\"g\",\n\t\t\t\t),\n\t\t);\n\t\tconst components = {};\n\t\tlet html = content;\n\n\t\tlet match = pattern.exec(content);\n\t\twhile (match !== null) {\n\t\t\tconst props = this.attributes(match[1]);\n\t\t\tconst componentName = props.component;\n\t\t\tif (componentName) {\n\t\t\t\tcomponents[componentName] = match[2];\n\t\t\t}\n\t\t\tmatch = pattern.exec(content);\n\t\t}\n\n\t\thtml = content.replace(\n\t\t\tnew RegExp(\n\t\t\t\t`<${component.setTagName}[^>]*>[\\\\s\\\\S]*?<\\\\/${component.setTagName}>`,\n\t\t\t\t\"g\",\n\t\t\t),\n\t\t\t\"\",\n\t\t);\n\n\t\treturn {\n\t\t\tcomponents,\n\t\t\thtml,\n\t\t};\n\t}\n\n\t/**\n\t * @param {string} text\n\t */\n\tsanitizer(text) {\n\t\treturn this.config.security.sanitizeHtml\n\t\t\t? text.replace(/[<>&\"']/g, (c) => sanitize[c])\n\t\t\t: text;\n\t}\n\n\tgetnestvalue(obj, path) {\n\t\treturn path.split(\".\").reduce((current, key) => current?.[key], obj);\n\t}\n\n\t/**\n\t * @param {string} template\n\t * @param {Object} data\n\t */\n\tconditionalsp(template, data) {\n\t\treturn template.replace(\n\t\t\t/\\{\\{#if\\s+([\\w.]+)\\}\\}([\\s\\S]*?)(?:\\{\\{#else\\}\\}([\\s\\S]*?))?\\{\\{\\/if\\}\\}/g,\n\t\t\t(_, path, ifContent, elseContent) => {\n\t\t\t\tconst val = this.getnestvalue(data, path);\n\t\t\t\tconst isTruthy = val && val !== \"false\" && val !== \"0\";\n\t\t\t\treturn isTruthy ? ifContent : elseContent || \"\";\n\t\t\t},\n\t\t);\n\t}\n\n\tploops(template, data) {\n\t\treturn template.replace(\n\t\t\t/\\{\\{#each\\s+([\\w.]+)\\}\\}([\\s\\S]*?)\\{\\{\\/each\\}\\}/g,\n\t\t\t(_, path, content) => {\n\t\t\t\tconst arr = this.getnestvalue(data, path);\n\t\t\t\tif (!Array.isArray(arr)) return \"\";\n\n\t\t\t\treturn arr\n\t\t\t\t\t.map((item, index) => {\n\t\t\t\t\t\tlet itemData;\n\t\t\t\t\t\tif (typeof item === \"object\" && item !== null) {\n\t\t\t\t\t\t\titemData = {\n\t\t\t\t\t\t\t\t...item,\n\t\t\t\t\t\t\t\t\"@index\": index,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\titemData = {\n\t\t\t\t\t\t\t\tthis: item,\n\t\t\t\t\t\t\t\t\"@index\": index,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet processed = this.conditionalsp(content, itemData);\n\t\t\t\t\t\tprocessed = this.ploops(processed, itemData);\n\t\t\t\t\t\treturn this.interpolate(processed, itemData);\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\");\n\t\t\t},\n\t\t);\n\t}\n\n\tinterpolate(template, data) {\n\t\tconst { interpolation } = this.config;\n\t\tconst pattern = this.regxep(\n\t\t\t\"interpolation\",\n\t\t\t() =>\n\t\t\t\tnew RegExp(\n\t\t\t\t\t`${this.escaperegexp(interpolation.start)}([\\\\w.@]+)${this.escaperegexp(interpolation.end)}`,\n\t\t\t\t\t\"g\",\n\t\t\t\t),\n\t\t);\n\t\treturn template.replace(pattern, (_, path) => {\n\t\t\tconst val = this.getnestvalue(data, path);\n\t\t\tif (val == null) return \"\";\n\t\t\treturn interpolation.sanitize ? this.sanitizer(String(val)) : String(val);\n\t\t});\n\t}\n\n\t/**\n\t * @param {string} tagString\n\t */\n\tattributes(tagString) {\n\t\tconst props = {};\n\t\tconst regex = /(\\w+)=\"([^\"]*)\"/g;\n\t\tlet match = regex.exec(tagString);\n\t\twhile (match !== null) {\n\t\t\tprops[match[1]] = match[2];\n\t\t\tmatch = regex.exec(tagString);\n\t\t}\n\n\t\treturn props;\n\t}\n\n\ttransform(content) {\n\t\tconst { components, html } = this.parsecomps(content);\n\t\tconst mergedComponents = {\n\t\t\t...this.extcomps,\n\t\t\t...components,\n\t\t};\n\t\tconst { component } = this.config;\n\t\tconst componentRegex = this.regxep(\n\t\t\t\"component\",\n\t\t\t() => new RegExp(`<${component.tagName}\\\\s+([^>]+?)(?:\\\\/?)>`, \"g\"),\n\t\t);\n\t\treturn html.replace(componentRegex, (_, attrs) => {\n\t\t\tconst props = this.attributes(attrs);\n\t\t\tconst componentName = props[component.attributeName];\n\t\t\tif (!componentName || !mergedComponents[componentName]) {\n\t\t\t\treturn \"\";\n\t\t\t}\n\t\t\tconst data = {\n\t\t\t\t...props,\n\t\t\t};\n\t\t\tdelete data[component.attributeName];\n\t\t\ttry {\n\t\t\t\tlet result = mergedComponents[componentName];\n\t\t\t\tresult = this.conditionalsp(result, data);\n\t\t\t\tresult = this.ploops(result, data);\n\t\t\t\treturn this.interpolate(result, data);\n\t\t\t} catch {\n\t\t\t\treturn \"\";\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * @param {string} content\n\t * @param {HTMLElement} targetElement\n\t */\n\trenderon(content, targetElement) {\n\t\tconst processed = this.transform(content);\n\t\tif (targetElement) {\n\t\t\ttargetElement.innerHTML = processed;\n\t\t}\n\t\treturn processed;\n\t}\n}\n\nfunction processorcreationig(config = {}) {\n\treturn new Processor(config);\n}\n\nasync function processDocument(\n\tconfig = {},\n\tcomponentslocation = \"components.yaml\",\n) {\n\tconst processor = processorcreationig(config);\n\ttry {\n\t\tconst external = await loadcomponents(componentslocation);\n\t\tprocessor.externalcomponents(external);\n\t} catch {\n\t\tconsole.warn(`Failed to load components from ${componentslocation}`);\n\t}\n\tconst content = document.body.innerHTML;\n\tconst processed = processor.transform(content);\n\tdocument.body.innerHTML = processed;\n}\n\ndocument.addEventListener(\"DOMContentLoaded\", () => {\n\tprocessDocument();\n});\n\nexport {\n\tProcessor as process,\n\tprocessorcreationig as createProcessor,\n\tprocessDocument,\n};\n"]}