lightview 2.1.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/build-bundles.mjs +2 -6
  2. package/build.js +236 -46
  3. package/components/data-display/avatar.js +25 -1
  4. package/components/data-display/chart.js +22 -5
  5. package/components/data-display/countdown.js +3 -2
  6. package/components/data-input/checkbox.js +23 -1
  7. package/components/data-input/input.js +24 -1
  8. package/components/data-input/radio.js +37 -2
  9. package/components/data-input/select.js +24 -1
  10. package/components/data-input/toggle.js +21 -1
  11. package/components/navigation/breadcrumbs.js +42 -2
  12. package/docs/assets/js/examplify.js +1 -1
  13. package/docs/cdom-nav.html +32 -6
  14. package/docs/cdom.html +610 -180
  15. package/docs/components/avatar.html +24 -54
  16. package/docs/components/badge.html +14 -14
  17. package/docs/components/breadcrumbs.html +95 -29
  18. package/docs/components/chart-area.html +3 -3
  19. package/docs/components/chart-bar.html +4 -181
  20. package/docs/components/chart-column.html +4 -189
  21. package/docs/components/chart-line.html +3 -3
  22. package/docs/components/chart-pie.html +112 -166
  23. package/docs/components/chart.html +11 -13
  24. package/docs/components/checkbox.html +48 -28
  25. package/docs/components/collapse.html +6 -6
  26. package/docs/components/countdown.html +12 -12
  27. package/docs/components/dropdown.html +1 -1
  28. package/docs/components/file-input.html +4 -4
  29. package/docs/components/footer.html +11 -11
  30. package/docs/components/input.html +45 -29
  31. package/docs/components/join.html +4 -4
  32. package/docs/components/kbd.html +3 -3
  33. package/docs/components/loading.html +41 -53
  34. package/docs/components/pagination.html +4 -4
  35. package/docs/components/progress.html +6 -4
  36. package/docs/components/radio.html +42 -31
  37. package/docs/components/select.html +48 -59
  38. package/docs/components/toggle.html +44 -25
  39. package/docs/getting-started/index.html +4 -4
  40. package/jprx/LICENSE +21 -0
  41. package/jprx/README.md +130 -0
  42. package/{cdom → jprx}/helpers/array.js +9 -4
  43. package/{cdom → jprx}/helpers/state.js +6 -3
  44. package/jprx/index.js +69 -0
  45. package/jprx/package.json +24 -0
  46. package/jprx/parser.js +1517 -0
  47. package/lightview-all.js +3785 -1
  48. package/lightview-cdom.js +2128 -1
  49. package/lightview-router.js +179 -208
  50. package/lightview-x.js +1435 -1
  51. package/lightview.js +613 -1
  52. package/package.json +5 -2
  53. package/src/lightview-cdom.js +201 -49
  54. package/src/lightview-router.js +210 -0
  55. package/src/lightview-x.js +104 -55
  56. package/src/lightview.js +12 -1
  57. package/{watch.js → start-dev.js} +2 -1
  58. package/tests/cdom/parser.test.js +83 -12
  59. package/wrangler.toml +0 -3
  60. package/cdom/parser.js +0 -602
  61. package/test-text-tag.js +0 -6
  62. /package/{cdom → jprx}/helpers/compare.js +0 -0
  63. /package/{cdom → jprx}/helpers/conditional.js +0 -0
  64. /package/{cdom → jprx}/helpers/datetime.js +0 -0
  65. /package/{cdom → jprx}/helpers/format.js +0 -0
  66. /package/{cdom → jprx}/helpers/logic.js +0 -0
  67. /package/{cdom → jprx}/helpers/lookup.js +0 -0
  68. /package/{cdom → jprx}/helpers/math.js +0 -0
  69. /package/{cdom → jprx}/helpers/network.js +0 -0
  70. /package/{cdom → jprx}/helpers/stats.js +0 -0
  71. /package/{cdom → jprx}/helpers/string.js +0 -0
package/lightview-x.js CHANGED
@@ -1 +1,1435 @@
1
- !function(){"use strict";const e=globalThis.__LIGHTVIEW_INTERNALS__||(globalThis.__LIGHTVIEW_INTERNALS__={currentEffect:null,registry:new Map,dependencyMap:new WeakMap}),t=(t,n)=>{let r="string"==typeof n?n:null==n?void 0:n.name;const o=null==n?void 0:n.storage;if(r&&o)try{const e=o.getItem(r);null!==e&&(t=JSON.parse(e))}catch(l){}let s=t;const i=new Set,a=(...e)=>{if(0===e.length)return a.value;a.value=e[0]};if(Object.defineProperty(a,"value",{get:()=>(e.currentEffect&&(i.add(e.currentEffect),e.currentEffect.dependencies.add(i)),s),set(e){if(s!==e){if(s=e,r&&o)try{o.setItem(r,JSON.stringify(s))}catch(l){}[...i].forEach(e=>e())}}}),r)if(e.registry.has(r)){if(e.registry.get(r)!==a)throw new Error(`Lightview: A signal or state with the name "${r}" is already registered.`)}else e.registry.set(r,a);return a};t.get=(n,r)=>e.registry.has(n)||void 0===r?e.registry.get(n):t(r,n);const n=()=>e.registry,r=new WeakMap,o=new WeakMap,s=new WeakMap,i=(e,t)=>Object.getOwnPropertyNames(e).filter(n=>"function"==typeof e[n]&&t(n)),a=i(Date.prototype,e=>/^(to|get|valueOf)/.test(e)),l=i(Date.prototype,e=>/^set/.test(e)),c=["map","forEach","filter","find","findIndex","some","every","reduce","reduceRight","includes","indexOf","lastIndexOf","join","slice","concat","flat","flatMap","at","entries","keys","values"],h=["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"],u=["map","forEach","filter","find","findIndex","some","every","flatMap"],d=(e,t,n)=>{let r=e.get(t);return r||(r=n(),e.set(t,r)),r},f=(e,n,r,o)=>{if("__parent__"===n)return s.get(r);o.has(n)||o.set(n,t(Reflect.get(e,n,r)));const i=o.get(n).value;if("object"==typeof i&&null!==i){const e=g(i);return s.set(e,r),e}return i},m=(e,n,r,o,s)=>{s.has(n)||s.set(n,t(Reflect.get(e,n,o)));const i=Reflect.set(e,n,r,o),a=s.get(n);return i&&a&&(a.value=r),i},p=(e,n,r=[])=>{const i=d(o,e,()=>new Map);if(!i.has(n)){const r="function"==typeof e[n]?e[n].call(e):e[n];i.set(n,t(r))}const p=e instanceof Date,y=Array.isArray(e),v=p?a:y?c:r,b=p?l:y?h:[];return new Proxy(e,{get(e,t,r){if("__parent__"===t)return s.get(r);const o=e[t];if("function"==typeof o){const a=v.includes(t),l=b.includes(t);return function(...c){if(a){const e=i.get(n);e&&e.value}const h="function"==typeof e[n]?e[n].call(e):e[n];if(y&&u.includes(t)&&"function"==typeof c[0]){const e=c[0];c[0]=function(t,n,o){const i="object"==typeof t&&null!==t?g(t):t;return i&&"object"==typeof i&&s.set(i,r),e.call(this,i,n,o)}}const d=o.apply(e,c),f="function"==typeof e[n]?e[n].call(e):e[n];if(h!==f||l){const e=i.get(n);e&&e.value!==f&&(e.value=f)}return d}}if(t===n){const o=i.get(n);return o?o.value:Reflect.get(e,t,r)}if(y&&!isNaN(parseInt(t))){const e=i.get(n);e&&e.value}return f(e,t,r,i)},set(e,t,r,o){if(t===n){const s=Reflect.set(e,t,r,o);if(s){const e=i.get(n);e&&(e.value=r)}return s}return m(e,t,r,o,i)}})},g=(t,i)=>{if("object"!=typeof t||null===t)return t;const a="string"==typeof i?i:null==i?void 0:i.name,l=null==i?void 0:i.storage;if(a&&l)try{const e=l.getItem(a);if(e){const n=JSON.parse(e);Array.isArray(t)&&Array.isArray(n)?(t.length=0,t.push(...n)):Object.assign(t,n)}}catch(h){}let c=r.get(t);if(!c){const e=Array.isArray(t),n=t instanceof Date,i=e||n;if(!i&&(t instanceof RegExp||t instanceof Map||t instanceof Set||t instanceof WeakMap||t instanceof WeakSet))return t;c=i?p(t,e?"length":n?"getTime":null):new Proxy(t,{get:(e,t,n)=>"__parent__"===t?s.get(n):f(e,t,n,d(o,e,()=>new Map)),set:(e,t,n,r)=>m(e,t,n,r,d(o,e,()=>new Map))}),r.set(t,c)}if(a&&l&&(t=>{const n=()=>{if(n.active&&!n.running){n.dependencies.forEach(e=>e.delete(n)),n.dependencies.clear(),n.running=!0,e.currentEffect=n;try{t()}finally{e.currentEffect=null,n.running=!1}}};n.active=!0,n.running=!1,n.dependencies=new Set,n.stop=()=>{n.dependencies.forEach(e=>e.delete(n)),n.dependencies.clear(),n.active=!1},n()})(()=>{try{l.setItem(a,JSON.stringify(c))}catch(h){}}),a){const e=n();if(e.has(a)){if(e.get(a)!==c)throw new Error(`Lightview: A signal or state with the name "${a}" is already registered.`)}else e.set(a,c)}return c};g.get=(e,t)=>{const r=n();return r.has(e)||void 0===t?r.get(e):g(t,e)};const y=["img","script","iframe","video","audio","source","track","embed","input"],v=["a","area","base","link"],b=e=>{if(!e||"string"!=typeof e)return!1;const t=e.trim().toLowerCase();return t.startsWith("javascript:")||t.startsWith("vbscript:")||t.startsWith("data:text/html")||t.startsWith("data:application/javascript")},w=e=>{if(!e)return!1;if(!/^[a-z][a-z0-9+.-]*:/i.test(e))return!0;try{const t="undefined"!=typeof document?document.baseURI:globalThis.location.origin,n=new URL(e,"null"===t?void 0:t),r=globalThis.location;return n.origin===r.origin&&"null"!==n.origin||(!(!n.hostname||n.hostname!==r.hostname)||(!!(n.hostname&&r.hostname&&n.hostname.endsWith("."+r.hostname))||"file:"===r.protocol&&"file:"===n.protocol))}catch(t){return!1}},E=e=>{var t,n;if("object"!=typeof e||null===e)return e;if(Array.isArray(e))return e.map(E);if(e.tag)return{...e,children:e.children?E(e.children):[]};if(e.domEl||!(e=>{if("object"!=typeof e||null===e||Array.isArray(e)||e.tag||e.domEl)return!1;const t=Object.keys(e);return 1===t.length&&"string"==typeof(n=t[0])&&n.length>0&&"children"!==n&&"object"==typeof e[t[0]];var n})(e))return e;const r=Object.keys(e)[0],o=e[r],s="undefined"!=typeof window||"undefined"!=typeof globalThis?globalThis.Lightview:null,i=(null==(n=null==(t=null==s?void 0:s.tags)?void 0:t._customTags)?void 0:n[r])||r,{children:a,...l}=o;return{tag:i,attributes:l,children:a?E(a):[]}},S="https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css",T={initialized:!1,shadowDefault:!0,daisyStyleSheet:null,themeStyleSheet:null,componentStyleSheets:new Map,customStyleSheets:new Map},C=async(e,t)=>{if(!T.customStyleSheets.has(e))try{let n=t;if(void 0===n)if(e.startsWith("#")){const t=document.querySelector(e);if(!t)throw new Error(`Style block '${e}' not found`);n=t.textContent}else{const t=await fetch(e);if(!t.ok)throw new Error(`Fetch failed: ${t.status}`);n=await t.text()}if(void 0!==n){const t=new CSSStyleSheet;t.replaceSync(n),T.customStyleSheets.set(e,t)}}catch(n){console.error(`LightviewX: Failed to register stylesheet '${e}':`,n)}},L=()=>{try{if("undefined"!=typeof localStorage)return localStorage.getItem("lightview-theme")}catch(e){return null}},O=t("undefined"!=typeof document&&document.documentElement.getAttribute("data-theme")||L()||"light"),A=e=>{if(e){"undefined"!=typeof document&&document.documentElement.setAttribute("data-theme",e),O&&O.value!==e&&(O.value=e);try{"undefined"!=typeof localStorage&&localStorage.setItem("lightview-theme",e)}catch(t){}}},N=async(e={})=>{const{shadowDefault:t=!0}=e;if(T.shadowDefault=t,t)try{const e=await fetch(S);if(!e.ok)throw new Error(`Failed to fetch DaisyUI CSS: ${e.status}`);const t=await e.text(),n=new CSSStyleSheet;n.replaceSync(t),T.daisyStyleSheet=n}catch(n){console.error("LightviewX: Failed to preload DaisyUI stylesheet:",n)}T.initialized=!0};(async()=>{await N()})();const k=(e,t=[])=>{const n=[];if(T.daisyStyleSheet?n.push(T.daisyStyleSheet):n.push(S),T.themeStyleSheet&&n.push(T.themeStyleSheet),e){const t=T.componentStyleSheets.get(e);t&&n.push(t)}return Array.isArray(t)&&t.forEach(e=>{const t=T.customStyleSheets.get(e);t?n.push(t):(C(e),n.push(e))}),n},M=e=>{try{const t=e.trim().startsWith("${")&&e.trim().endsWith("}")&&!e.trim().includes("${",2)?"return "+e.trim().slice(2,-1):"return `"+e.replace(/\\/g,"\\\\").replace(/`/g,"\\`")+"`";return new Function("state","signal",t)}catch(t){return()=>""}},_=(e,t,n=null)=>{const r="script"===n||"style"===n,o=globalThis.Lightview;return e.map(e=>e.nodeType===Node.TEXT_NODE?((e,t,n)=>{const r=e.textContent;if(t)return r;if(!r.trim()&&!r.includes("${"))return null;if(r.includes("${")){const e=M(r);return()=>e(n.state,n.signal)}return r})(e,r,o):e.nodeType===Node.ELEMENT_NODE?((e,t,n)=>{const r=e.tagName.toLowerCase(),o={},s="script"===r||"style"===r,i="undefined"!=typeof window||"undefined"!=typeof globalThis?globalThis.Lightview:null;for(let a of e.attributes){const e=a.value;o[a.name]=!s&&e.includes("${")?(()=>{const t=M(e);return()=>t(i.state,i.signal)})():e}return t(r,o,n(Array.from(e.childNodes),t,r))})(e,t,_):null).filter(e=>null!==e)},W=new WeakMap,D=(e,t=!1)=>document.createComment(`lv-src-${t?"end":"start"}:${e}`),$=e=>{if(!e)return;e.querySelectorAll("script").forEach(e=>{const t=document.createElement("script");Array.from(e.attributes).forEach(e=>{t.setAttribute(e.name,e.value)}),e.src?t.src=e.src:t.textContent=e.textContent,e.parentNode.replaceChild(t,e)})},x=(e,t,n,r,o,s=!1,i="")=>{var a;if(t)return Array.isArray(e)?e:[e];if(s&&"cdomc"===i){const t=null==(a=globalThis.LightviewCDOM)?void 0:a.parseCDOMC;if(!t)return console.warn("LightviewX: CDOMC parser not found. Ensure lightview-cdom.js is loaded."),[];try{const n=t(e);return Array.isArray(n)?n:[n]}catch(l){return console.warn("LightviewX: Failed to parse .cdomc:",l),[]}}if(n){if("true"===r.domEl.getAttribute("escape"))return[e];const t=(new DOMParser).parseFromString(e.replace(/<head[^>]*>[\s\S]*?<\/head>/i,""),"text/html");return _([...Array.from(t.head.childNodes),...Array.from(t.body.childNodes)],o)}return[e]},R=(e,t,n,r,o,{element:s,setupChildren:i},a=null)=>{const l=`${r}-${o.slice(0,8)}`;let c=d(W,e.domEl,()=>({}));c[r]&&((e,t)=>{const n=`lv-src-start:${t}`,r=`lv-src-end:${t}`;let o=!1;const s=[],i=document.createTreeWalker(e.parentElement||e,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,null,!1);for(;i.nextNode();){const e=i.currentNode;if(e.nodeType===Node.COMMENT_NODE){if(e.textContent===n){o=!0,s.push(e);continue}if(e.textContent===r){s.push(e);break}}o&&s.push(e)}s.forEach(e=>e.remove()),s.length})(e.domEl,`${r}-${c[r].slice(0,8)}`),c[r]=o;const h=e=>{a&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{const t=a.startsWith("#")?a.slice(1):a,n=e.getElementById?e.getElementById(t):e.querySelector(`#${t}`);n&&(n.style.scrollMarginTop="calc(var(--site-nav-height, 0px) + 2rem)",n.scrollIntoView({behavior:"smooth",block:"start",inline:"start"}))})})};"shadow"===r?(e.domEl.shadowRoot||e.domEl.attachShadow({mode:"open"}),i(t,e.domEl.shadowRoot),$(e.domEl.shadowRoot),h(e.domEl.shadowRoot)):"innerhtml"===r?(e.children=t,$(e.domEl),h(document)):(((e,t,n,r,{element:o,setupChildren:s})=>{const i="outerhtml"===n,a="beforebegin"===n||"afterend"===n||i?t.parentElement:t;if(!a)return console.warn(`LightviewX: No parent for ${n}`);const l=document.createDocumentFragment();l.appendChild(D(r,!1)),e.forEach(e=>{var t,n,r;if("string"==typeof e)l.appendChild(document.createTextNode(e));else if(e.domEl)l.appendChild(e.domEl);else if(e instanceof Node)l.appendChild(e);else{const s=(null==(r=null==(t=globalThis.Lightview)?void 0:(n=t.hooks).processChild)?void 0:r.call(n,e))||e;if(s.tag){const e=o(s.tag,s.attributes||{},s.children||[]);(null==e?void 0:e.domEl)&&l.appendChild(e.domEl)}}}),l.appendChild(D(r,!0)),i?a.replaceChild(l,t):"beforebegin"===n?a.insertBefore(l,t):"afterend"===n?a.insertBefore(l,t.nextSibling):"afterbegin"===n?t.insertBefore(l,t.firstChild):"beforeend"===n&&t.appendChild(l),$(a)})(t,e.domEl,r,l,{element:s,setupChildren:i}),h(document))},I=async(e,t,n,{element:r,setupChildren:o})=>{if(y.includes(n))return;let s=[],i="",a=null;if("string"==typeof(l=t)&&!b(l)&&/^(https?:|\.|\/|[\w])|(\.(html|json|[vo]dom|cdomc?))$/i.test(l)){t.includes("#")&&([t,a]=t.split("#"));const n=await(async e=>{var t;try{const n=globalThis.Lightview;if((null==(t=null==n?void 0:n.hooks)?void 0:t.validateUrl)&&!n.hooks.validateUrl(e))return console.warn(`[LightviewX] Fetch blocked by validateUrl hook: ${e}`),null;const r=new URL(e,document.baseURI),o=await fetch(r);if(!o.ok)return null;const s=r.pathname.split(".").pop().toLowerCase(),i="vdom"===s||"odom"===s||"cdom"===s,a="html"===s,l="cdom"===s||"cdomc"===s,c=i?await o.json():await o.text();return{content:c,isJson:i,isHtml:a,isCdom:l,ext:s,raw:i?JSON.stringify(c):c}}catch(n){return null}})(t);n&&(s=x(n.content,n.isJson,n.isHtml,e,r,n.isCdom,n.ext),i=n.raw)}var l;if(!s.length){const e=((e,t)=>{try{const n=document.querySelectorAll(e);return n.length?{elements:_(Array.from(n),t),raw:Array.from(n).map(e=>e.outerHTML||e.textContent).join("")}:null}catch(n){return null}})(t,r);e&&(s=e.elements,i=e.raw)}if(!s.length)return;const c=(e.domEl.getAttribute("location")||"innerhtml").toLowerCase(),h=(e=>{let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t&=t;return t.toString(36)})(i);if(d(W,e.domEl,()=>({}))[c]!==h)R(e,s,0,c,h,{element:r,setupChildren:o},a);else if(a){const t="shadow"===c?e.domEl.shadowRoot:document;t&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{var e;const n=a.startsWith("#")?a.slice(1):a,r=t.getElementById?t.getElementById(n):null==(e=t.querySelector)?void 0:e.call(t,`#${n}`);r&&(r.style.scrollMarginTop="calc(var(--site-nav-height, 0px) + 2rem)",r.scrollIntoView({behavior:"smooth",block:"start",inline:"start"}))})})}},j=["beforebegin","afterbegin","beforeend","afterend","innerhtml","outerhtml","shadow"],F=(e,{domToElement:t,wrapDomElement:n})=>{var r;const o=e.target.closest("[href]");if(!o)return;const s=o.tagName.toLowerCase();if(v.includes(s))return;e.preventDefault();const i=o.getAttribute("href"),a=globalThis.Lightview;if(i&&(b(i)||(null==(r=null==a?void 0:a.hooks)?void 0:r.validateUrl)&&!a.hooks.validateUrl(i)))return void console.warn(`[LightviewX] Navigation or fetch blocked by security policy: ${i}`);const l=o.getAttribute("target");if(!l){let e=t.get(o);if(!e){const t={};for(let e of o.attributes)t[e.name]=e.value;e=n(o,s,t)}const r={...e.attributes,src:i};return void(e.attributes=r)}if(l.startsWith("_")){switch(l){case"_self":globalThis.location.href=i;break;case"_parent":globalThis.parent.location.href=i;break;case"_top":globalThis.top.location.href=i;break;default:globalThis.open(i,l)}return}const{selector:c,location:h}=(e=>{for(const t of j){const n=":"+t;if(e.toLowerCase().endsWith(n))return{selector:e.slice(0,-n.length),location:t}}return{selector:e,location:null}})(l);try{document.querySelectorAll(c).forEach(e=>{let r=t.get(e);if(!r){const t={};for(let n of e.attributes)t[n.name]=n.value;r=n(e,e.tagName.toLowerCase(),t)}const o={...r.attributes,src:i};h&&(o.location=h),r.attributes=o})}catch(u){console.warn("Invalid target selector:",c,u)}},P=new WeakMap,U="__lv_passed",X="__lv_resume",H=["click","dblclick","mousedown","mouseup","contextmenu","submit","reset","change","input","invalid","keydown","keyup","keypress","touchstart","touchend"],q=["focus","blur"],B=(e,t)=>{let n=P.get(e);n||(n=new Map,P.set(e,n));let r=n.get(t);return r||(r={},n.set(t,r)),r},J=function(e){const t=arguments[arguments.length-1];if(null==t?void 0:t[X])return!0;const n=`throttle-${(null==t?void 0:t.type)||"all"}-${e}`,r=B(this,n),o=Date.now();return o-(r.last||0)>=e&&(r.last=o,!0)},V=function(e){const t=arguments[arguments.length-1],n=`debounce-${(null==t?void 0:t.type)||"all"}-${e}`,r=B(this,n);return r.timer&&clearTimeout(r.timer),(null==t?void 0:t[X])&&r.passed?(r.passed=!1,!0):(r.timer=setTimeout(()=>{r.passed=!0;const e=new t.constructor(t.type,t);e[X]=!0,this.dispatchEvent(e)},e),!1)},z=async e=>{var t,n;if(e[U])return;const r=null==(n=(t=e.target).closest)?void 0:n.call(t,"[lv-before]");if(!r)return;const{events:o,exclusions:s,calls:i}=(e=>{const t=[];let n="",r=0,o=null;for(let c=0;c<e.length;c++){const s=e[c];o?(n+=s,s===o&&"\\"!==e[c-1]&&(o=null)):"'"===s||'"'===s?(o=s,n+=s):"("===s?(r++,n+=s):")"===s?(r--,n+=s):/\s/.test(s)&&0===r?(n&&t.push(n),n=""):n+=s}n&&t.push(n);const s=[],i=[],a=[];let l=0;for(;l<t.length;){const e=t[l];if(!e||e.includes("("))break;e.startsWith("!")?i.push(e.slice(1)):s.push(e),l++}for(;l<t.length;)t[l]&&a.push(t[l]),l++;return{events:s,exclusions:i,calls:a}})(r.getAttribute("lv-before")),a=s.includes(e.type),l=o.includes("*")||o.includes(e.type);if(a||!l)return;e.stopImmediatePropagation(),e.preventDefault();for(const u of i)try{const t=u.match(/^([\w\.]+)\((.*)\)$/);if(!t)continue;const n=t[1],o=t[2],s=globalThis.Lightview,i=globalThis.LightviewX;let a=n.split(".").reduce((e,t)=>null==e?void 0:e[t],globalThis);if(a||"throttle"!==n||(a=J),a||"debounce"!==n||(a=V),!a&&i&&i[n]&&(a=i[n]),"function"!=typeof a){console.warn(`LightviewX: lv-before function '${n}' not found`);continue}const l=new Function("event","state","signal",`return [${o}]`).call(r,e,(null==s?void 0:s.state)||{},(null==s?void 0:s.signal)||{});l.push(e);let c=a.apply(r,l);if(c instanceof Promise&&(c=await c),!1===c||null==c)return}catch(h){return void console.error(`LightviewX: Error executing lv-before gate '${u}':`,h)}const c=new e.constructor(e.type,e);c[U]=!0,r.dispatchEvent(c)},Y=(e,t)=>{if(e.nodeType!==Node.ELEMENT_NODE)return;const n=e.tagName.toLowerCase();if((e=>y.includes(e)||e.startsWith("lv-"))(n))return;const r=e.getAttribute("src");if(!r)return;let o=t.internals.domToElement.get(e);if(!o){const r={};for(let t of e.attributes)r[t.name]=t.value;o=t.internals.wrapDomElement(e,n,r,[])}I(o,r,n,{element:t.element,setupChildren:t.internals.setupChildren})},G=new WeakSet,K=(e,t)=>{if(!e||!t)return;const n=(e,n,r=!1,o=null)=>{if(G.has(e)&&!r)return;r||G.add(e);const s=M(n);t.effect(()=>{try{const n=s(t.state,t.signal);r?null==n||!1===n?e.removeAttribute(o):e.setAttribute(o,n):e.textContent=void 0!==n?n:""}catch(n){}})},r=document.evaluate(".//text()[contains(., '${')]",e,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);for(let s=0;s<r.snapshotLength;s++){const e=r.snapshotItem(s);e.parentElement&&e.parentElement.closest("SCRIPT, STYLE, CODE, PRE, TEMPLATE, NOSCRIPT")||n(e,e.textContent)}const o=document.evaluate(".//*[@*[contains(., '${')]]",e,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);for(let s=0;s<o.snapshotLength;s++){const e=o.snapshotItem(s);["SCRIPT","STYLE","CODE","PRE","TEMPLATE","NOSCRIPT"].includes(e.tagName)||Array.from(e.attributes).forEach(t=>{t.value.includes("${")&&n(e,t.value,!0,t.name)})}e.nodeType!==Node.ELEMENT_NODE||["SCRIPT","STYLE","CODE","PRE","TEMPLATE","NOSCRIPT"].includes(e.tagName)||Array.from(e.attributes).forEach(t=>{t.value.includes("${")&&n(e,t.value,!0,t.name)})},Q=(e,t,n)=>{if(e.nodeType!==Node.ELEMENT_NODE&&e.nodeType!==Node.TEXT_NODE||n.push(e),e.nodeType!==Node.ELEMENT_NODE)return;t.push(e);const r="[src]:not("+y.join("):not(")+")",o=e.querySelectorAll(r);for(const s of o)s.tagName.toLowerCase().startsWith("lv-")||t.push(s)},Z=e=>{const t=new MutationObserver(t=>{const{nodesToProcess:n,nodesToActivate:r}=(e=>{const t=[],n=[];for(const r of e)"childList"===r.type?r.addedNodes.forEach(e=>Q(e,t,n)):"attributes"===r.type&&"src"===r.attributeName&&t.push(r.target);return{nodesToProcess:t,nodesToActivate:n}})(t);(n.length>0||r.length>0)&&requestAnimationFrame(()=>{r.forEach(t=>K(t,e)),n.forEach(t=>Y(t,e))})});return t.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]}),t};if("undefined"!=typeof window&&globalThis.Lightview){const e=globalThis.Lightview;"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>Z(e)):Z(e);const t=()=>{requestAnimationFrame(()=>{K(document.body,e);const t="[src]:not("+y.join("):not(")+")";document.querySelectorAll(t).forEach(t=>{t.tagName.toLowerCase().startsWith("lv-")||Y(t,e)})})};document.body?t():document.addEventListener("DOMContentLoaded",t),e.hooks.onNonStandardHref=t=>{F(t,{domToElement:e.internals.domToElement,wrapDomElement:e.internals.wrapDomElement})},H.forEach(e=>window.addEventListener(e,z,!0)),q.forEach(e=>window.addEventListener(e,z,!0)),e.hooks.processChild=t=>{if(!t)return t;if("object"!=typeof t||Array.isArray(t)||t.tag||t.domEl||(t=E(t)),"string"==typeof t&&t.startsWith("$")&&isNaN(parseInt(t[1]))){const e=globalThis.LightviewCDOM;if(e)return e.parseExpression(t)}if("string"==typeof t&&(t.trim().startsWith("{")||t.trim().startsWith("[")))try{const e=new Function("return ("+t+")")();if("object"==typeof e&&null!==e)return Array.isArray(e)||e.tag||e.domEl?e:E(e)}catch(n){}return((e,t)=>{if("string"==typeof e&&e.includes("${")){const n=M(e);return()=>n(t.state,t.signal)}return e})(t,{state:g,signal:e.signal})}}const ee={state:g,themeSignal:O,setTheme:A,registerStyleSheet:C,registerThemeSheet:async e=>{try{const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch theme CSS: ${t.status}`);const n=await t.text(),r=new CSSStyleSheet;r.replaceSync(n),T.themeStyleSheet=r}catch(t){console.error(`LightviewX: Failed to register theme stylesheet '${e}':`,t)}},throttle:J,debounce:V,initComponents:N,componentConfig:T,shouldUseShadow:e=>void 0!==e?e:T.shadowDefault,getAdoptedStyleSheets:k,preloadComponentCSS:async e=>{T.componentStyleSheets.has(e)||await(async e=>{if(T.componentStyleSheets.has(e))return T.componentStyleSheets.get(e);try{const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch component CSS: ${t.status}`);const n=await t.text(),r=new CSSStyleSheet;return r.replaceSync(n),T.componentStyleSheets.set(e,r),r}catch(t){return console.error(`LightviewX: Failed to create stylesheet for ${e}:`,t),null}})(e)},createCustomElement:(e,t={})=>class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}async connectedCallback(){const{cssUrl:n,styles:r}=t;this.themeWrapper=document.createElement("div"),this.themeWrapper.style.display="contents";const o=()=>{const e=document.documentElement.getAttribute("data-theme")||"light";this.themeWrapper.setAttribute("data-theme",e)};o(),this.themeObserver=new MutationObserver(o),this.themeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),this.shadowRoot.appendChild(this.themeWrapper);const s=k(n,r);try{const e=s.filter(e=>e instanceof CSSStyleSheet);this.shadowRoot.adoptedStyleSheets=e}catch(i){}if(!T.daisyStyleSheet){const e=document.createElement("link");e.rel="stylesheet",e.href=S,this.shadowRoot.appendChild(e)}s.forEach(e=>{if("string"==typeof e){const t=document.createElement("link");t.rel="stylesheet",t.href=e,this.shadowRoot.appendChild(t)}}),this.render=()=>{const t={};for(const e of this.attributes){const n=e.name.replace(/-([a-z])/g,e=>e[1].toUpperCase());""===e.value?t[n]=!0:t[n]=e.value}t.useShadow=!1;const n=globalThis.Lightview.tags.slot(),r=e(t,n);globalThis.Lightview.internals.setupChildren([r],this.themeWrapper)},"undefined"!=typeof MutationObserver&&"undefined"!=typeof HTMLElement&&(this.attrObserver=new MutationObserver(e=>{this.render()}),this.attrObserver.observe(this,{attributes:!0})),this.render()}disconnectedCallback(){this.themeObserver&&this.themeObserver.disconnect(),this.attrObserver&&this.attrObserver.disconnect()}},customElementWrapper:(e,t={})=>{const{attributeMap:n={},childElements:r={}}=t;return class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}connectedCallback(){const e=document.createElement("link");e.rel="stylesheet",e.href="https://cdn.jsdelivr.net/npm/daisyui@5.5.14/daisyui.min.css",this.shadowRoot.appendChild(e);const t=document.createElement("div");t.setAttribute("data-theme",document.documentElement.getAttribute("data-theme")||"light"),t.style.display="contents",this.shadowRoot.appendChild(t),this.themeWrapper=t,this.themeObserver=new MutationObserver(()=>{const e=document.documentElement.getAttribute("data-theme")||"light";this.themeWrapper.setAttribute("data-theme",e)}),this.themeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),this.render();const o=Object.keys(n);o.length>0&&(this.attrObserver=new MutationObserver(()=>this.render()),this.attrObserver.observe(this,{attributes:!0,attributeFilter:o})),Object.keys(r).length>0&&(this.childObserver=new MutationObserver(()=>this.render()),this.childObserver.observe(this,{childList:!0,subtree:!0,attributes:!0}))}disconnectedCallback(){this.themeObserver&&this.themeObserver.disconnect(),this.attrObserver&&this.attrObserver.disconnect(),this.childObserver&&this.childObserver.disconnect()}parseChildrenToVDOM(){return Array.from(this.children).map(e=>{const t=e.tagName.toLowerCase(),n=r[t];if(!n)return null;const{component:o,attributeMap:s={},innerHTML:i=!1}=n,a={};return Object.entries(s).forEach(([t,n])=>{const r=e.getAttribute(t);null!==r&&(n===Boolean?a[t]="true"===r||""===r:a[t]=n===Number?Number(r):r)}),e.onclick&&(a.onclick=e.onclick.bind(e)),{tag:o,attributes:a,children:i?[e.innerHTML]:[e.textContent]}}).filter(Boolean)}render(){var t,o;const s={useShadow:!1};Object.entries(n).forEach(([e,t])=>{const n=this.getAttribute(e);null!==n&&(t===Boolean?s[e]="true"===n||""===n:s[e]=t===Number?Number(n):n)});const i=this.parseChildrenToVDOM(),a=Object.keys(r).length>0?i:[{tag:globalThis.Lightview.tags.slot}],l=e(s,...a);(null==(o=null==(t=globalThis.Lightview)?void 0:t.internals)?void 0:o.setupChildren)&&this.themeWrapper&&(this.themeWrapper.innerHTML="",globalThis.Lightview.internals.setupChildren([l],this.themeWrapper))}static get observedAttributes(){return Object.keys(n)}attributeChangedCallback(){this.render()}}},internals:{handleSrcAttribute:I,parseElements:x}};if("undefined"!=typeof module&&module.exports&&(module.exports=ee),"undefined"!=typeof window&&(globalThis.LightviewX=ee),"undefined"!=typeof window){try{const e=L();e&&A(e)}catch(te){}"undefined"!=typeof window&&globalThis.Lightview&&(globalThis.Lightview.hooks.validateUrl||(globalThis.Lightview.hooks.validateUrl=w))}"undefined"!=typeof globalThis&&globalThis.Lightview&&(globalThis.Lightview.hooks.validateUrl||(globalThis.Lightview.hooks.validateUrl=w))}();
1
+ (function() {
2
+ "use strict";
3
+ const _LV = globalThis.__LIGHTVIEW_INTERNALS__ || (globalThis.__LIGHTVIEW_INTERNALS__ = {
4
+ currentEffect: null,
5
+ registry: /* @__PURE__ */ new Map(),
6
+ dependencyMap: /* @__PURE__ */ new WeakMap()
7
+ // Tracking signals -> subscribers
8
+ });
9
+ const signal = (initialValue, optionsOrName) => {
10
+ let name = typeof optionsOrName === "string" ? optionsOrName : optionsOrName == null ? void 0 : optionsOrName.name;
11
+ const storage = optionsOrName == null ? void 0 : optionsOrName.storage;
12
+ if (name && storage) {
13
+ try {
14
+ const stored = storage.getItem(name);
15
+ if (stored !== null) {
16
+ initialValue = JSON.parse(stored);
17
+ }
18
+ } catch (e) {
19
+ }
20
+ }
21
+ let value = initialValue;
22
+ const subscribers = /* @__PURE__ */ new Set();
23
+ const f = (...args) => {
24
+ if (args.length === 0) return f.value;
25
+ f.value = args[0];
26
+ };
27
+ Object.defineProperty(f, "value", {
28
+ get() {
29
+ if (_LV.currentEffect) {
30
+ subscribers.add(_LV.currentEffect);
31
+ _LV.currentEffect.dependencies.add(subscribers);
32
+ }
33
+ return value;
34
+ },
35
+ set(newValue) {
36
+ if (value !== newValue) {
37
+ value = newValue;
38
+ if (name && storage) {
39
+ try {
40
+ storage.setItem(name, JSON.stringify(value));
41
+ } catch (e) {
42
+ }
43
+ }
44
+ [...subscribers].forEach((effect2) => effect2());
45
+ }
46
+ }
47
+ });
48
+ if (name) {
49
+ if (_LV.registry.has(name)) {
50
+ if (_LV.registry.get(name) !== f) {
51
+ throw new Error(`Lightview: A signal or state with the name "${name}" is already registered.`);
52
+ }
53
+ } else {
54
+ _LV.registry.set(name, f);
55
+ }
56
+ }
57
+ return f;
58
+ };
59
+ const getSignal = (name, defaultValue) => {
60
+ if (!_LV.registry.has(name) && defaultValue !== void 0) {
61
+ return signal(defaultValue, name);
62
+ }
63
+ return _LV.registry.get(name);
64
+ };
65
+ signal.get = getSignal;
66
+ const effect = (fn) => {
67
+ const execute = () => {
68
+ if (!execute.active || execute.running) return;
69
+ execute.dependencies.forEach((dep) => dep.delete(execute));
70
+ execute.dependencies.clear();
71
+ execute.running = true;
72
+ _LV.currentEffect = execute;
73
+ try {
74
+ fn();
75
+ } finally {
76
+ _LV.currentEffect = null;
77
+ execute.running = false;
78
+ }
79
+ };
80
+ execute.active = true;
81
+ execute.running = false;
82
+ execute.dependencies = /* @__PURE__ */ new Set();
83
+ execute.stop = () => {
84
+ execute.dependencies.forEach((dep) => dep.delete(execute));
85
+ execute.dependencies.clear();
86
+ execute.active = false;
87
+ };
88
+ execute();
89
+ return execute;
90
+ };
91
+ const getRegistry = () => _LV.registry;
92
+ const stateCache = /* @__PURE__ */ new WeakMap();
93
+ const stateSignals = /* @__PURE__ */ new WeakMap();
94
+ const parents = /* @__PURE__ */ new WeakMap();
95
+ const protoMethods = (proto, test) => Object.getOwnPropertyNames(proto).filter((k) => typeof proto[k] === "function" && test(k));
96
+ const DATE_TRACKING = protoMethods(Date.prototype, (k) => /^(to|get|valueOf)/.test(k));
97
+ const DATE_MUTATING = protoMethods(Date.prototype, (k) => /^set/.test(k));
98
+ const ARRAY_TRACKING = [
99
+ "map",
100
+ "forEach",
101
+ "filter",
102
+ "find",
103
+ "findIndex",
104
+ "some",
105
+ "every",
106
+ "reduce",
107
+ "reduceRight",
108
+ "includes",
109
+ "indexOf",
110
+ "lastIndexOf",
111
+ "join",
112
+ "slice",
113
+ "concat",
114
+ "flat",
115
+ "flatMap",
116
+ "at",
117
+ "entries",
118
+ "keys",
119
+ "values"
120
+ ];
121
+ const ARRAY_MUTATING = ["push", "pop", "shift", "unshift", "splice", "sort", "reverse", "fill", "copyWithin"];
122
+ const ARRAY_ITERATION = ["map", "forEach", "filter", "find", "findIndex", "some", "every", "flatMap"];
123
+ const getOrSet = (map, key, factory) => {
124
+ let v = map.get(key);
125
+ if (!v) {
126
+ v = factory();
127
+ map.set(key, v);
128
+ }
129
+ return v;
130
+ };
131
+ const proxyGet = (target, prop, receiver, signals) => {
132
+ if (prop === "__parent__") return parents.get(receiver);
133
+ if (!signals.has(prop)) {
134
+ signals.set(prop, signal(Reflect.get(target, prop, receiver)));
135
+ }
136
+ const signal$1 = signals.get(prop);
137
+ const val = signal$1.value;
138
+ if (typeof val === "object" && val !== null) {
139
+ const childProxy = state(val);
140
+ parents.set(childProxy, receiver);
141
+ return childProxy;
142
+ }
143
+ return val;
144
+ };
145
+ const proxySet = (target, prop, value, receiver, signals) => {
146
+ if (!signals.has(prop)) {
147
+ signals.set(prop, signal(Reflect.get(target, prop, receiver)));
148
+ }
149
+ const success = Reflect.set(target, prop, value, receiver);
150
+ const signal$1 = signals.get(prop);
151
+ if (success && signal$1) signal$1.value = value;
152
+ return success;
153
+ };
154
+ const createSpecialProxy = (obj, monitor, trackingProps = []) => {
155
+ const signals = getOrSet(stateSignals, obj, () => /* @__PURE__ */ new Map());
156
+ if (!signals.has(monitor)) {
157
+ const initialValue = typeof obj[monitor] === "function" ? obj[monitor].call(obj) : obj[monitor];
158
+ signals.set(monitor, signal(initialValue));
159
+ }
160
+ const isDate = obj instanceof Date;
161
+ const isArray = Array.isArray(obj);
162
+ const trackingMethods = isDate ? DATE_TRACKING : isArray ? ARRAY_TRACKING : trackingProps;
163
+ const mutatingMethods = isDate ? DATE_MUTATING : isArray ? ARRAY_MUTATING : [];
164
+ return new Proxy(obj, {
165
+ get(target, prop, receiver) {
166
+ if (prop === "__parent__") return parents.get(receiver);
167
+ const value = target[prop];
168
+ if (typeof value === "function") {
169
+ const isTracking = trackingMethods.includes(prop);
170
+ const isMutating = mutatingMethods.includes(prop);
171
+ return function(...args) {
172
+ if (isTracking) {
173
+ const sig = signals.get(monitor);
174
+ if (sig) void sig.value;
175
+ }
176
+ const startValue = typeof target[monitor] === "function" ? target[monitor].call(target) : target[monitor];
177
+ if (isArray && ARRAY_ITERATION.includes(prop) && typeof args[0] === "function") {
178
+ const originalCallback = args[0];
179
+ args[0] = function(element, index, array) {
180
+ const wrappedElement = typeof element === "object" && element !== null ? state(element) : element;
181
+ if (wrappedElement && typeof wrappedElement === "object") {
182
+ parents.set(wrappedElement, receiver);
183
+ }
184
+ return originalCallback.call(this, wrappedElement, index, array);
185
+ };
186
+ }
187
+ const result = value.apply(target, args);
188
+ const endValue = typeof target[monitor] === "function" ? target[monitor].call(target) : target[monitor];
189
+ if (startValue !== endValue || isMutating) {
190
+ const sig = signals.get(monitor);
191
+ if (sig && sig.value !== endValue) {
192
+ sig.value = endValue;
193
+ }
194
+ }
195
+ return result;
196
+ };
197
+ }
198
+ if (prop === monitor) {
199
+ const sig = signals.get(monitor);
200
+ return sig ? sig.value : Reflect.get(target, prop, receiver);
201
+ }
202
+ if (isArray && !isNaN(parseInt(prop))) {
203
+ const monitorSig = signals.get(monitor);
204
+ if (monitorSig) void monitorSig.value;
205
+ }
206
+ return proxyGet(target, prop, receiver, signals);
207
+ },
208
+ set(target, prop, value, receiver) {
209
+ if (prop === monitor) {
210
+ const success = Reflect.set(target, prop, value, receiver);
211
+ if (success) {
212
+ const sig = signals.get(monitor);
213
+ if (sig) sig.value = value;
214
+ }
215
+ return success;
216
+ }
217
+ return proxySet(target, prop, value, receiver, signals);
218
+ }
219
+ });
220
+ };
221
+ const state = (obj, optionsOrName) => {
222
+ if (typeof obj !== "object" || obj === null) return obj;
223
+ const name = typeof optionsOrName === "string" ? optionsOrName : optionsOrName == null ? void 0 : optionsOrName.name;
224
+ const storage = optionsOrName == null ? void 0 : optionsOrName.storage;
225
+ if (name && storage) {
226
+ try {
227
+ const item = storage.getItem(name);
228
+ if (item) {
229
+ const loaded = JSON.parse(item);
230
+ Array.isArray(obj) && Array.isArray(loaded) ? (obj.length = 0, obj.push(...loaded)) : Object.assign(obj, loaded);
231
+ }
232
+ } catch (e) {
233
+ }
234
+ }
235
+ let proxy = stateCache.get(obj);
236
+ if (!proxy) {
237
+ const isArray = Array.isArray(obj), isDate = obj instanceof Date;
238
+ const isSpecial = isArray || isDate;
239
+ const monitor = isArray ? "length" : isDate ? "getTime" : null;
240
+ if (isSpecial || !(obj instanceof RegExp || obj instanceof Map || obj instanceof Set || obj instanceof WeakMap || obj instanceof WeakSet)) {
241
+ proxy = isSpecial ? createSpecialProxy(obj, monitor) : new Proxy(obj, {
242
+ get(t, p, r) {
243
+ if (p === "__parent__") return parents.get(r);
244
+ return proxyGet(t, p, r, getOrSet(stateSignals, t, () => /* @__PURE__ */ new Map()));
245
+ },
246
+ set(t, p, v, r) {
247
+ return proxySet(t, p, v, r, getOrSet(stateSignals, t, () => /* @__PURE__ */ new Map()));
248
+ }
249
+ });
250
+ stateCache.set(obj, proxy);
251
+ } else return obj;
252
+ }
253
+ if (name && storage) {
254
+ effect(() => {
255
+ try {
256
+ storage.setItem(name, JSON.stringify(proxy));
257
+ } catch (e) {
258
+ }
259
+ });
260
+ }
261
+ if (name) {
262
+ const registry = getRegistry();
263
+ if (registry.has(name)) {
264
+ if (registry.get(name) !== proxy) {
265
+ throw new Error(`Lightview: A signal or state with the name "${name}" is already registered.`);
266
+ }
267
+ } else {
268
+ registry.set(name, proxy);
269
+ }
270
+ }
271
+ return proxy;
272
+ };
273
+ const getState = (name, defaultValue) => {
274
+ const registry = getRegistry();
275
+ if (!registry.has(name) && defaultValue !== void 0) {
276
+ return state(defaultValue, name);
277
+ }
278
+ return registry.get(name);
279
+ };
280
+ state.get = getState;
281
+ const STANDARD_SRC_TAGS = ["img", "script", "iframe", "video", "audio", "source", "track", "embed", "input"];
282
+ const isStandardSrcTag = (tagName) => STANDARD_SRC_TAGS.includes(tagName) || tagName.startsWith("lv-");
283
+ const STANDARD_HREF_TAGS = ["a", "area", "base", "link"];
284
+ const isValidTagName = (name) => typeof name === "string" && name.length > 0 && name !== "children";
285
+ const isDangerousProtocol = (url) => {
286
+ if (!url || typeof url !== "string") return false;
287
+ const normalized = url.trim().toLowerCase();
288
+ return normalized.startsWith("javascript:") || normalized.startsWith("vbscript:") || normalized.startsWith("data:text/html") || normalized.startsWith("data:application/javascript");
289
+ };
290
+ const validateUrl = (url) => {
291
+ if (!url) return false;
292
+ if (!/^[a-z][a-z0-9+.-]*:/i.test(url)) return true;
293
+ try {
294
+ const base = typeof document !== "undefined" ? document.baseURI : globalThis.location.origin;
295
+ const target = new URL(url, base === "null" ? void 0 : base);
296
+ const current = globalThis.location;
297
+ if (target.origin === current.origin && target.origin !== "null") return true;
298
+ if (target.hostname && target.hostname === current.hostname) return true;
299
+ if (target.hostname && current.hostname && target.hostname.endsWith("." + current.hostname)) return true;
300
+ if (current.protocol === "file:" && target.protocol === "file:") return true;
301
+ return false;
302
+ } catch (e) {
303
+ return false;
304
+ }
305
+ };
306
+ const isObjectDOM = (obj) => {
307
+ if (typeof obj !== "object" || obj === null || Array.isArray(obj) || obj.tag || obj.domEl) return false;
308
+ const keys = Object.keys(obj);
309
+ return keys.length === 1 && isValidTagName(keys[0]) && typeof obj[keys[0]] === "object";
310
+ };
311
+ const convertObjectDOM = (obj) => {
312
+ var _a, _b;
313
+ if (typeof obj !== "object" || obj === null) return obj;
314
+ if (Array.isArray(obj)) return obj.map(convertObjectDOM);
315
+ if (obj.tag) return { ...obj, children: obj.children ? convertObjectDOM(obj.children) : [] };
316
+ if (obj.domEl || !isObjectDOM(obj)) return obj;
317
+ const tagKey = Object.keys(obj)[0];
318
+ const content = obj[tagKey];
319
+ const LV = typeof window !== "undefined" ? globalThis.Lightview : typeof globalThis !== "undefined" ? globalThis.Lightview : null;
320
+ const tag = ((_b = (_a = LV == null ? void 0 : LV.tags) == null ? void 0 : _a._customTags) == null ? void 0 : _b[tagKey]) || tagKey;
321
+ const { children, ...attributes } = content;
322
+ return { tag, attributes, children: children ? convertObjectDOM(children) : [] };
323
+ };
324
+ const DAISYUI_CDN = "https://cdn.jsdelivr.net/npm/daisyui@4.12.23/dist/full.min.css";
325
+ const componentConfig = {
326
+ initialized: false,
327
+ shadowDefault: true,
328
+ // Default: components use shadow DOM
329
+ daisyStyleSheet: null,
330
+ themeStyleSheet: null,
331
+ // Global theme stylesheet
332
+ componentStyleSheets: /* @__PURE__ */ new Map(),
333
+ customStyleSheets: /* @__PURE__ */ new Map(),
334
+ // Registry for named custom stylesheets
335
+ customStyleSheetPromises: /* @__PURE__ */ new Map()
336
+ // Cache for pending stylesheet fetches
337
+ };
338
+ const registerStyleSheet = async (nameOrIdOrUrl, cssText) => {
339
+ if (componentConfig.customStyleSheets.has(nameOrIdOrUrl)) return componentConfig.customStyleSheets.get(nameOrIdOrUrl);
340
+ if (componentConfig.customStyleSheetPromises.has(nameOrIdOrUrl)) return componentConfig.customStyleSheetPromises.get(nameOrIdOrUrl);
341
+ const promise = (async () => {
342
+ try {
343
+ let finalCss = cssText;
344
+ if (finalCss === void 0) {
345
+ if (nameOrIdOrUrl.startsWith("#")) {
346
+ const el = document.querySelector(nameOrIdOrUrl);
347
+ if (el) {
348
+ finalCss = el.textContent;
349
+ } else {
350
+ throw new Error(`Style block '${nameOrIdOrUrl}' not found`);
351
+ }
352
+ } else {
353
+ const response = await fetch(nameOrIdOrUrl);
354
+ if (!response.ok) throw new Error(`Fetch failed: ${response.status}`);
355
+ finalCss = await response.text();
356
+ }
357
+ }
358
+ if (finalCss !== void 0) {
359
+ const sheet = new CSSStyleSheet();
360
+ sheet.replaceSync(finalCss);
361
+ componentConfig.customStyleSheets.set(nameOrIdOrUrl, sheet);
362
+ return sheet;
363
+ }
364
+ } catch (e) {
365
+ console.error(`LightviewX: Failed to register stylesheet '${nameOrIdOrUrl}':`, e);
366
+ } finally {
367
+ componentConfig.customStyleSheetPromises.delete(nameOrIdOrUrl);
368
+ }
369
+ })();
370
+ componentConfig.customStyleSheetPromises.set(nameOrIdOrUrl, promise);
371
+ return promise;
372
+ };
373
+ const getSavedTheme = () => {
374
+ try {
375
+ if (typeof localStorage !== "undefined") {
376
+ return localStorage.getItem("lightview-theme");
377
+ }
378
+ } catch (e) {
379
+ return null;
380
+ }
381
+ };
382
+ const themeSignal = signal(
383
+ typeof document !== "undefined" && document.documentElement.getAttribute("data-theme") || getSavedTheme() || "light"
384
+ );
385
+ const setTheme = (themeName) => {
386
+ if (!themeName) return;
387
+ if (typeof document !== "undefined") {
388
+ document.documentElement.setAttribute("data-theme", themeName);
389
+ }
390
+ if (themeSignal && themeSignal.value !== themeName) {
391
+ themeSignal.value = themeName;
392
+ }
393
+ try {
394
+ if (typeof localStorage !== "undefined") {
395
+ localStorage.setItem("lightview-theme", themeName);
396
+ }
397
+ } catch (e) {
398
+ }
399
+ };
400
+ const registerThemeSheet = async (url) => {
401
+ try {
402
+ const response = await fetch(url);
403
+ if (!response.ok) throw new Error(`Failed to fetch theme CSS: ${response.status}`);
404
+ const cssText = await response.text();
405
+ const sheet = new CSSStyleSheet();
406
+ sheet.replaceSync(cssText);
407
+ componentConfig.themeStyleSheet = sheet;
408
+ } catch (e) {
409
+ console.error(`LightviewX: Failed to register theme stylesheet '${url}':`, e);
410
+ }
411
+ };
412
+ const initComponents = async (options = {}) => {
413
+ const { shadowDefault = true } = options;
414
+ componentConfig.shadowDefault = shadowDefault;
415
+ if (shadowDefault) {
416
+ try {
417
+ const response = await fetch(DAISYUI_CDN);
418
+ if (!response.ok) {
419
+ throw new Error(`Failed to fetch DaisyUI CSS: ${response.status}`);
420
+ }
421
+ const cssText = await response.text();
422
+ const sheet = new CSSStyleSheet();
423
+ sheet.replaceSync(cssText);
424
+ componentConfig.daisyStyleSheet = sheet;
425
+ } catch (e) {
426
+ console.error("LightviewX: Failed to preload DaisyUI stylesheet:", e);
427
+ }
428
+ }
429
+ componentConfig.initialized = true;
430
+ };
431
+ (async () => await initComponents())();
432
+ const getComponentStyleSheet = async (cssUrl) => {
433
+ if (componentConfig.componentStyleSheets.has(cssUrl)) {
434
+ return componentConfig.componentStyleSheets.get(cssUrl);
435
+ }
436
+ try {
437
+ const response = await fetch(cssUrl);
438
+ if (!response.ok) {
439
+ throw new Error(`Failed to fetch component CSS: ${response.status}`);
440
+ }
441
+ const cssText = await response.text();
442
+ const sheet = new CSSStyleSheet();
443
+ sheet.replaceSync(cssText);
444
+ componentConfig.componentStyleSheets.set(cssUrl, sheet);
445
+ return sheet;
446
+ } catch (e) {
447
+ console.error(`LightviewX: Failed to create stylesheet for ${cssUrl}:`, e);
448
+ return null;
449
+ }
450
+ };
451
+ const shouldUseShadow = (useShadowProp) => {
452
+ if (useShadowProp !== void 0) {
453
+ return useShadowProp;
454
+ }
455
+ return componentConfig.shadowDefault;
456
+ };
457
+ const getAdoptedStyleSheets = (componentCssUrl, requestedSheets = []) => {
458
+ const result = [];
459
+ if (componentConfig.daisyStyleSheet) {
460
+ result.push(componentConfig.daisyStyleSheet);
461
+ } else {
462
+ result.push(DAISYUI_CDN);
463
+ }
464
+ if (componentConfig.themeStyleSheet) {
465
+ result.push(componentConfig.themeStyleSheet);
466
+ }
467
+ if (componentCssUrl) {
468
+ const componentSheet = componentConfig.componentStyleSheets.get(componentCssUrl);
469
+ if (componentSheet) {
470
+ result.push(componentSheet);
471
+ }
472
+ }
473
+ if (Array.isArray(requestedSheets)) {
474
+ requestedSheets.forEach((url) => {
475
+ const sheet = componentConfig.customStyleSheets.get(url);
476
+ if (sheet) {
477
+ result.push(sheet);
478
+ } else {
479
+ registerStyleSheet(url);
480
+ result.push(url);
481
+ }
482
+ });
483
+ }
484
+ return result;
485
+ };
486
+ const preloadComponentCSS = async (cssUrl) => {
487
+ if (!componentConfig.componentStyleSheets.has(cssUrl)) {
488
+ await getComponentStyleSheet(cssUrl);
489
+ }
490
+ };
491
+ const compileTemplate = (code) => {
492
+ try {
493
+ const isSingle = code.trim().startsWith("${") && code.trim().endsWith("}") && !code.trim().includes("${", 2);
494
+ const body = isSingle ? "return " + code.trim().slice(2, -1) : "return `" + code.replace(/\\/g, "\\\\").replace(/`/g, "\\`") + "`";
495
+ return new Function("state", "signal", body);
496
+ } catch (e) {
497
+ return () => "";
498
+ }
499
+ };
500
+ const processTemplateChild = (child, LV) => {
501
+ if (typeof child === "string" && child.includes("${")) {
502
+ const fn = compileTemplate(child);
503
+ return () => fn(LV.state, LV.signal);
504
+ }
505
+ return child;
506
+ };
507
+ const transformTextNode = (node, isRaw, LV) => {
508
+ const text = node.textContent;
509
+ if (isRaw) return text;
510
+ if (!text.trim() && !text.includes("${")) return null;
511
+ if (text.includes("${")) {
512
+ const fn = compileTemplate(text);
513
+ return () => fn(LV.state, LV.signal);
514
+ }
515
+ return text;
516
+ };
517
+ const transformElementNode = (node, element, domToElements2) => {
518
+ const tagName = node.tagName.toLowerCase();
519
+ const attributes = {};
520
+ const skip = tagName === "script" || tagName === "style";
521
+ const LV = typeof window !== "undefined" ? globalThis.Lightview : typeof globalThis !== "undefined" ? globalThis.Lightview : null;
522
+ for (let attr of node.attributes) {
523
+ const val = attr.value;
524
+ attributes[attr.name] = !skip && val.includes("${") ? (() => {
525
+ const fn = compileTemplate(val);
526
+ return () => fn(LV.state, LV.signal);
527
+ })() : val;
528
+ }
529
+ return element(tagName, attributes, domToElements2(Array.from(node.childNodes), element, tagName));
530
+ };
531
+ const domToElements = (domNodes, element, parentTagName = null) => {
532
+ const isRaw = parentTagName === "script" || parentTagName === "style";
533
+ const LV = globalThis.Lightview;
534
+ return domNodes.map((node) => {
535
+ if (node.nodeType === Node.TEXT_NODE) return transformTextNode(node, isRaw, LV);
536
+ if (node.nodeType === Node.ELEMENT_NODE) return transformElementNode(node, element, domToElements);
537
+ return null;
538
+ }).filter((n) => n !== null);
539
+ };
540
+ const insertedContentMap = /* @__PURE__ */ new WeakMap();
541
+ const hashContent = (str) => {
542
+ let hash = 0;
543
+ for (let i = 0; i < str.length; i++) {
544
+ const char = str.charCodeAt(i);
545
+ hash = (hash << 5) - hash + char;
546
+ hash = hash & hash;
547
+ }
548
+ return hash.toString(36);
549
+ };
550
+ const createMarker = (id, isEnd = false) => {
551
+ return document.createComment(`lv-src-${isEnd ? "end" : "start"}:${id}`);
552
+ };
553
+ const executeScripts = (container) => {
554
+ if (!container) return;
555
+ const scripts = container.querySelectorAll("script");
556
+ scripts.forEach((oldScript) => {
557
+ const newScript = document.createElement("script");
558
+ Array.from(oldScript.attributes).forEach((attr) => {
559
+ newScript.setAttribute(attr.name, attr.value);
560
+ });
561
+ if (oldScript.src) {
562
+ newScript.src = oldScript.src;
563
+ } else {
564
+ newScript.textContent = oldScript.textContent;
565
+ }
566
+ oldScript.parentNode.replaceChild(newScript, oldScript);
567
+ });
568
+ };
569
+ const removeInsertedContent = (parentEl, markerId) => {
570
+ const startMarker = `lv-src-start:${markerId}`;
571
+ const endMarker = `lv-src-end:${markerId}`;
572
+ let inRange = false;
573
+ const nodesToRemove = [];
574
+ const walker = document.createTreeWalker(
575
+ parentEl.parentElement || parentEl,
576
+ NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,
577
+ null,
578
+ false
579
+ );
580
+ while (walker.nextNode()) {
581
+ const node = walker.currentNode;
582
+ if (node.nodeType === Node.COMMENT_NODE) {
583
+ if (node.textContent === startMarker) {
584
+ inRange = true;
585
+ nodesToRemove.push(node);
586
+ continue;
587
+ }
588
+ if (node.textContent === endMarker) {
589
+ nodesToRemove.push(node);
590
+ break;
591
+ }
592
+ }
593
+ if (inRange) {
594
+ nodesToRemove.push(node);
595
+ }
596
+ }
597
+ nodesToRemove.forEach((node) => node.remove());
598
+ return nodesToRemove.length > 0;
599
+ };
600
+ const insert = (elements, parent, location, markerId, { element, setupChildren }) => {
601
+ const isSibling = location === "beforebegin" || location === "afterend";
602
+ const isOuter = location === "outerhtml";
603
+ const target = isSibling || isOuter ? parent.parentElement : parent;
604
+ if (!target) return console.warn(`LightviewX: No parent for ${location}`);
605
+ const frag = document.createDocumentFragment();
606
+ frag.appendChild(createMarker(markerId, false));
607
+ elements.forEach((c) => {
608
+ var _a, _b, _c;
609
+ if (typeof c === "string") frag.appendChild(document.createTextNode(c));
610
+ else if (c.domEl) frag.appendChild(c.domEl);
611
+ else if (c instanceof Node) frag.appendChild(c);
612
+ else {
613
+ const v = ((_c = (_a = globalThis.Lightview) == null ? void 0 : (_b = _a.hooks).processChild) == null ? void 0 : _c.call(_b, c)) || c;
614
+ if (v.tag) {
615
+ const n = element(v.tag, v.attributes || {}, v.children || []);
616
+ if (n == null ? void 0 : n.domEl) frag.appendChild(n.domEl);
617
+ }
618
+ }
619
+ });
620
+ frag.appendChild(createMarker(markerId, true));
621
+ if (isOuter) target.replaceChild(frag, parent);
622
+ else if (location === "beforebegin") target.insertBefore(frag, parent);
623
+ else if (location === "afterend") target.insertBefore(frag, parent.nextSibling);
624
+ else if (location === "afterbegin") parent.insertBefore(frag, parent.firstChild);
625
+ else if (location === "beforeend") parent.appendChild(frag);
626
+ executeScripts(target);
627
+ };
628
+ const isPath = (s) => typeof s === "string" && !isDangerousProtocol(s) && /^(https?:|\.|\/|[\w])|(\.(html|json|[vo]dom|cdomc?))$/i.test(s);
629
+ const fetchContent = async (src) => {
630
+ var _a;
631
+ try {
632
+ const LV = globalThis.Lightview;
633
+ if (((_a = LV == null ? void 0 : LV.hooks) == null ? void 0 : _a.validateUrl) && !LV.hooks.validateUrl(src)) {
634
+ console.warn(`[LightviewX] Fetch blocked by validateUrl hook: ${src}`);
635
+ return null;
636
+ }
637
+ const url = new URL(src, document.baseURI);
638
+ const res = await fetch(url);
639
+ if (!res.ok) return null;
640
+ const ext = url.pathname.split(".").pop().toLowerCase();
641
+ const isJson = ext === "vdom" || ext === "odom" || ext === "cdom";
642
+ const isHtml = ext === "html";
643
+ const isCdom = ext === "cdom" || ext === "cdomc";
644
+ const content = isJson ? await res.json() : await res.text();
645
+ return {
646
+ content,
647
+ isJson,
648
+ isHtml,
649
+ isCdom,
650
+ ext,
651
+ raw: isJson ? JSON.stringify(content) : content
652
+ };
653
+ } catch (e) {
654
+ return null;
655
+ }
656
+ };
657
+ const parseElements = (content, isJson, isHtml, el, element, isCdom = false, ext = "") => {
658
+ var _a;
659
+ if (isJson) return Array.isArray(content) ? content : [content];
660
+ if (isCdom && ext === "cdomc") {
661
+ const parser = (_a = globalThis.LightviewCDOM) == null ? void 0 : _a.parseCDOMC;
662
+ if (parser) {
663
+ try {
664
+ const obj = parser(content);
665
+ return Array.isArray(obj) ? obj : [obj];
666
+ } catch (e) {
667
+ console.warn("LightviewX: Failed to parse .cdomc:", e);
668
+ return [];
669
+ }
670
+ } else {
671
+ console.warn("LightviewX: CDOMC parser not found. Ensure lightview-cdom.js is loaded.");
672
+ return [];
673
+ }
674
+ }
675
+ if (isHtml) {
676
+ if (el.domEl.getAttribute("escape") === "true") return [content];
677
+ const doc = new DOMParser().parseFromString(content.replace(/<head[^>]*>[\s\S]*?<\/head>/i, ""), "text/html");
678
+ return domToElements([...Array.from(doc.head.childNodes), ...Array.from(doc.body.childNodes)], element);
679
+ }
680
+ return [content];
681
+ };
682
+ const elementsFromSelector = (selector, element) => {
683
+ try {
684
+ const sel = document.querySelectorAll(selector);
685
+ if (!sel.length) return null;
686
+ return {
687
+ elements: domToElements(Array.from(sel), element),
688
+ raw: Array.from(sel).map((n) => n.outerHTML || n.textContent).join("")
689
+ };
690
+ } catch (e) {
691
+ return null;
692
+ }
693
+ };
694
+ const updateTargetContent = (el, elements, raw, loc, contentHash, { element, setupChildren }, targetHash = null) => {
695
+ const markerId = `${loc}-${contentHash.slice(0, 8)}`;
696
+ let track = getOrSet(insertedContentMap, el.domEl, () => ({}));
697
+ if (track[loc]) removeInsertedContent(el.domEl, `${loc}-${track[loc].slice(0, 8)}`);
698
+ track[loc] = contentHash;
699
+ const performScroll = (root) => {
700
+ if (!targetHash) return;
701
+ requestAnimationFrame(() => {
702
+ requestAnimationFrame(() => {
703
+ const id = targetHash.startsWith("#") ? targetHash.slice(1) : targetHash;
704
+ const target = root.getElementById ? root.getElementById(id) : root.querySelector(`#${id}`);
705
+ if (target) {
706
+ target.style.scrollMarginTop = "calc(var(--site-nav-height, 0px) + 2rem)";
707
+ target.scrollIntoView({ behavior: "smooth", block: "start", inline: "start" });
708
+ }
709
+ });
710
+ });
711
+ };
712
+ if (loc === "shadow") {
713
+ if (!el.domEl.shadowRoot) el.domEl.attachShadow({ mode: "open" });
714
+ setupChildren(elements, el.domEl.shadowRoot);
715
+ executeScripts(el.domEl.shadowRoot);
716
+ performScroll(el.domEl.shadowRoot);
717
+ } else if (loc === "innerhtml") {
718
+ el.children = elements;
719
+ executeScripts(el.domEl);
720
+ performScroll(document);
721
+ } else {
722
+ insert(elements, el.domEl, loc, markerId, { element, setupChildren });
723
+ performScroll(document);
724
+ }
725
+ };
726
+ const handleSrcAttribute = async (el, src, tagName, { element, setupChildren }) => {
727
+ if (STANDARD_SRC_TAGS.includes(tagName)) return;
728
+ let elements = [], raw = "", targetHash = null;
729
+ if (isPath(src)) {
730
+ if (src.includes("#")) {
731
+ [src, targetHash] = src.split("#");
732
+ }
733
+ const result = await fetchContent(src);
734
+ if (result) {
735
+ elements = parseElements(result.content, result.isJson, result.isHtml, el, element, result.isCdom, result.ext);
736
+ raw = result.raw;
737
+ }
738
+ }
739
+ if (!elements.length) {
740
+ const result = elementsFromSelector(src, element);
741
+ if (result) {
742
+ elements = result.elements;
743
+ raw = result.raw;
744
+ }
745
+ }
746
+ if (!elements.length) return;
747
+ const loc = (el.domEl.getAttribute("location") || "innerhtml").toLowerCase();
748
+ const contentHash = hashContent(raw);
749
+ const track = getOrSet(insertedContentMap, el.domEl, () => ({}));
750
+ if (track[loc] === contentHash) {
751
+ if (targetHash) {
752
+ const root = loc === "shadow" ? el.domEl.shadowRoot : document;
753
+ if (root) {
754
+ requestAnimationFrame(() => {
755
+ requestAnimationFrame(() => {
756
+ var _a;
757
+ const id = targetHash.startsWith("#") ? targetHash.slice(1) : targetHash;
758
+ const target = root.getElementById ? root.getElementById(id) : (_a = root.querySelector) == null ? void 0 : _a.call(root, `#${id}`);
759
+ if (target) {
760
+ target.style.scrollMarginTop = "calc(var(--site-nav-height, 0px) + 2rem)";
761
+ target.scrollIntoView({ behavior: "smooth", block: "start", inline: "start" });
762
+ }
763
+ });
764
+ });
765
+ }
766
+ }
767
+ return;
768
+ }
769
+ updateTargetContent(el, elements, raw, loc, contentHash, { element, setupChildren }, targetHash);
770
+ };
771
+ const VALID_LOCATIONS = ["beforebegin", "afterbegin", "beforeend", "afterend", "innerhtml", "outerhtml", "shadow"];
772
+ const parseTargetWithLocation = (targetStr) => {
773
+ for (const loc of VALID_LOCATIONS) {
774
+ const suffix = ":" + loc;
775
+ if (targetStr.toLowerCase().endsWith(suffix)) {
776
+ return {
777
+ selector: targetStr.slice(0, -suffix.length),
778
+ location: loc
779
+ };
780
+ }
781
+ }
782
+ return { selector: targetStr, location: null };
783
+ };
784
+ const handleNonStandardHref = (e, { domToElement, wrapDomElement }) => {
785
+ var _a;
786
+ const clickedEl = e.target.closest("[href]");
787
+ if (!clickedEl) return;
788
+ const tagName = clickedEl.tagName.toLowerCase();
789
+ if (STANDARD_HREF_TAGS.includes(tagName)) return;
790
+ e.preventDefault();
791
+ const href = clickedEl.getAttribute("href");
792
+ const LV = globalThis.Lightview;
793
+ if (href && (isDangerousProtocol(href) || ((_a = LV == null ? void 0 : LV.hooks) == null ? void 0 : _a.validateUrl) && !LV.hooks.validateUrl(href))) {
794
+ console.warn(`[LightviewX] Navigation or fetch blocked by security policy: ${href}`);
795
+ return;
796
+ }
797
+ const targetAttr = clickedEl.getAttribute("target");
798
+ if (!targetAttr) {
799
+ let el = domToElement.get(clickedEl);
800
+ if (!el) {
801
+ const attrs = {};
802
+ for (let attr of clickedEl.attributes) attrs[attr.name] = attr.value;
803
+ el = wrapDomElement(clickedEl, tagName, attrs);
804
+ }
805
+ const newAttrs = { ...el.attributes, src: href };
806
+ el.attributes = newAttrs;
807
+ return;
808
+ }
809
+ if (targetAttr.startsWith("_")) {
810
+ switch (targetAttr) {
811
+ case "_self":
812
+ globalThis.location.href = href;
813
+ break;
814
+ case "_parent":
815
+ globalThis.parent.location.href = href;
816
+ break;
817
+ case "_top":
818
+ globalThis.top.location.href = href;
819
+ break;
820
+ case "_blank":
821
+ default:
822
+ globalThis.open(href, targetAttr);
823
+ break;
824
+ }
825
+ return;
826
+ }
827
+ const { selector, location } = parseTargetWithLocation(targetAttr);
828
+ try {
829
+ const targetElements = document.querySelectorAll(selector);
830
+ targetElements.forEach((targetEl) => {
831
+ let el = domToElement.get(targetEl);
832
+ if (!el) {
833
+ const attrs = {};
834
+ for (let attr of targetEl.attributes) attrs[attr.name] = attr.value;
835
+ el = wrapDomElement(targetEl, targetEl.tagName.toLowerCase(), attrs);
836
+ }
837
+ const newAttrs = { ...el.attributes, src: href };
838
+ if (location) {
839
+ newAttrs.location = location;
840
+ }
841
+ el.attributes = newAttrs;
842
+ });
843
+ } catch (err) {
844
+ console.warn("Invalid target selector:", selector, err);
845
+ }
846
+ };
847
+ const gateStates = /* @__PURE__ */ new WeakMap();
848
+ const BYPASS_FLAG = "__lv_passed";
849
+ const RESUME_FLAG = "__lv_resume";
850
+ const SENSIBLE_EVENTS = [
851
+ "click",
852
+ "dblclick",
853
+ "mousedown",
854
+ "mouseup",
855
+ "contextmenu",
856
+ "submit",
857
+ "reset",
858
+ "change",
859
+ "input",
860
+ "invalid",
861
+ "keydown",
862
+ "keyup",
863
+ "keypress",
864
+ "touchstart",
865
+ "touchend"
866
+ ];
867
+ const CAPTURE_EVENTS = ["focus", "blur"];
868
+ const getGateState = (el, key) => {
869
+ let elState = gateStates.get(el);
870
+ if (!elState) {
871
+ elState = /* @__PURE__ */ new Map();
872
+ gateStates.set(el, elState);
873
+ }
874
+ let state2 = elState.get(key);
875
+ if (!state2) {
876
+ state2 = {};
877
+ elState.set(key, state2);
878
+ }
879
+ return state2;
880
+ };
881
+ const gateThrottle = function(ms) {
882
+ const event = arguments[arguments.length - 1];
883
+ if (event == null ? void 0 : event[RESUME_FLAG]) return true;
884
+ const key = `throttle-${(event == null ? void 0 : event.type) || "all"}-${ms}`;
885
+ const state2 = getGateState(this, key);
886
+ const now = Date.now();
887
+ if (now - (state2.last || 0) >= ms) {
888
+ state2.last = now;
889
+ return true;
890
+ }
891
+ return false;
892
+ };
893
+ const gateDebounce = function(ms) {
894
+ const event = arguments[arguments.length - 1];
895
+ const key = `debounce-${(event == null ? void 0 : event.type) || "all"}-${ms}`;
896
+ const state2 = getGateState(this, key);
897
+ if (state2.timer) clearTimeout(state2.timer);
898
+ if ((event == null ? void 0 : event[RESUME_FLAG]) && state2.passed) {
899
+ state2.passed = false;
900
+ return true;
901
+ }
902
+ state2.timer = setTimeout(() => {
903
+ state2.passed = true;
904
+ const newEvent = new event.constructor(event.type, event);
905
+ newEvent[RESUME_FLAG] = true;
906
+ this.dispatchEvent(newEvent);
907
+ }, ms);
908
+ return false;
909
+ };
910
+ const parseBeforeAttribute = (attrValue) => {
911
+ const tokens = [];
912
+ let current = "", depth = 0, inQuote = null;
913
+ for (let i2 = 0; i2 < attrValue.length; i2++) {
914
+ const char = attrValue[i2];
915
+ if (inQuote) {
916
+ current += char;
917
+ if (char === inQuote && attrValue[i2 - 1] !== "\\") inQuote = null;
918
+ } else if (char === "'" || char === '"') {
919
+ inQuote = char;
920
+ current += char;
921
+ } else if (char === "(") {
922
+ depth++;
923
+ current += char;
924
+ } else if (char === ")") {
925
+ depth--;
926
+ current += char;
927
+ } else if (/\s/.test(char) && depth === 0) {
928
+ if (current) tokens.push(current);
929
+ current = "";
930
+ } else {
931
+ current += char;
932
+ }
933
+ }
934
+ if (current) tokens.push(current);
935
+ const events = [];
936
+ const exclusions = [];
937
+ const calls = [];
938
+ let i = 0;
939
+ while (i < tokens.length) {
940
+ const token = tokens[i];
941
+ if (!token || token.includes("(")) break;
942
+ if (token.startsWith("!")) exclusions.push(token.slice(1));
943
+ else events.push(token);
944
+ i++;
945
+ }
946
+ while (i < tokens.length) {
947
+ if (tokens[i]) calls.push(tokens[i]);
948
+ i++;
949
+ }
950
+ return { events, exclusions, calls };
951
+ };
952
+ const globalBeforeInterceptor = async (e) => {
953
+ var _a, _b;
954
+ if (e[BYPASS_FLAG]) return;
955
+ const target = (_b = (_a = e.target).closest) == null ? void 0 : _b.call(_a, "[lv-before]");
956
+ if (!target) return;
957
+ const { events, exclusions, calls } = parseBeforeAttribute(target.getAttribute("lv-before"));
958
+ const isExcluded = exclusions.includes(e.type);
959
+ const isIncluded = events.includes("*") || events.includes(e.type);
960
+ if (isExcluded || !isIncluded) return;
961
+ e.stopImmediatePropagation();
962
+ e.preventDefault();
963
+ for (const callStr of calls) {
964
+ try {
965
+ const match = callStr.match(/^([\w\.]+)\((.*)\)$/);
966
+ if (!match) continue;
967
+ const funcName = match[1];
968
+ const argsStr = match[2];
969
+ const LV = globalThis.Lightview;
970
+ const LVX = globalThis.LightviewX;
971
+ let fn = funcName.split(".").reduce((obj, key) => obj == null ? void 0 : obj[key], globalThis);
972
+ if (!fn && funcName === "throttle") fn = gateThrottle;
973
+ if (!fn && funcName === "debounce") fn = gateDebounce;
974
+ if (!fn && LVX && LVX[funcName]) fn = LVX[funcName];
975
+ if (typeof fn !== "function") {
976
+ console.warn(`LightviewX: lv-before function '${funcName}' not found`);
977
+ continue;
978
+ }
979
+ const evalArgs = new Function("event", "state", "signal", `return [${argsStr}]`);
980
+ const args = evalArgs.call(target, e, (LV == null ? void 0 : LV.state) || {}, (LV == null ? void 0 : LV.signal) || {});
981
+ args.push(e);
982
+ let result = fn.apply(target, args);
983
+ if (result instanceof Promise) result = await result;
984
+ if (result === false || result === null || result === void 0) return;
985
+ } catch (err) {
986
+ console.error(`LightviewX: Error executing lv-before gate '${callStr}':`, err);
987
+ return;
988
+ }
989
+ }
990
+ const finalEvent = new e.constructor(e.type, e);
991
+ finalEvent[BYPASS_FLAG] = true;
992
+ target.dispatchEvent(finalEvent);
993
+ };
994
+ const processSrcOnNode = (node, LV) => {
995
+ if (node.nodeType !== Node.ELEMENT_NODE) return;
996
+ const tagName = node.tagName.toLowerCase();
997
+ if (isStandardSrcTag(tagName)) return;
998
+ const src = node.getAttribute("src");
999
+ if (!src) return;
1000
+ let el = LV.internals.domToElement.get(node);
1001
+ if (!el) {
1002
+ const attrs = {};
1003
+ for (let attr of node.attributes) attrs[attr.name] = attr.value;
1004
+ el = LV.internals.wrapDomElement(node, tagName, attrs, []);
1005
+ }
1006
+ handleSrcAttribute(el, src, tagName, {
1007
+ element: LV.element,
1008
+ setupChildren: LV.internals.setupChildren
1009
+ });
1010
+ };
1011
+ const processedNodes = /* @__PURE__ */ new WeakSet();
1012
+ const activateReactiveSyntax = (root, LV) => {
1013
+ if (!root || !LV) return;
1014
+ const bindEffect = (node, codeStr, isAttr = false, attrName = null) => {
1015
+ if (processedNodes.has(node) && !isAttr) return;
1016
+ if (!isAttr) processedNodes.add(node);
1017
+ const fn = compileTemplate(codeStr);
1018
+ LV.effect(() => {
1019
+ try {
1020
+ const val = fn(LV.state, LV.signal);
1021
+ if (isAttr) {
1022
+ if (attrName.startsWith("cdom-")) {
1023
+ node[attrName] = val;
1024
+ } else {
1025
+ val === null || val === void 0 || val === false ? node.removeAttribute(attrName) : node.setAttribute(attrName, val);
1026
+ }
1027
+ } else node.textContent = val !== void 0 ? val : "";
1028
+ } catch (e) {
1029
+ }
1030
+ });
1031
+ };
1032
+ const textXPath = ".//text()[contains(., '${')]";
1033
+ const textResult = document.evaluate(
1034
+ textXPath,
1035
+ root,
1036
+ null,
1037
+ XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
1038
+ null
1039
+ );
1040
+ for (let i = 0; i < textResult.snapshotLength; i++) {
1041
+ const node = textResult.snapshotItem(i);
1042
+ if (node.parentElement && node.parentElement.closest("SCRIPT, STYLE, CODE, PRE, TEMPLATE, NOSCRIPT")) continue;
1043
+ bindEffect(node, node.textContent);
1044
+ }
1045
+ const attrXPath = ".//*[@*[contains(., '${')]]";
1046
+ const attrResult = document.evaluate(
1047
+ attrXPath,
1048
+ root,
1049
+ null,
1050
+ XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
1051
+ null
1052
+ );
1053
+ for (let i = 0; i < attrResult.snapshotLength; i++) {
1054
+ const element = attrResult.snapshotItem(i);
1055
+ if (["SCRIPT", "STYLE", "CODE", "PRE", "TEMPLATE", "NOSCRIPT"].includes(element.tagName)) continue;
1056
+ Array.from(element.attributes).forEach((attr) => {
1057
+ if (attr.value.includes("${")) {
1058
+ bindEffect(element, attr.value, true, attr.name);
1059
+ }
1060
+ });
1061
+ }
1062
+ if (root.nodeType === Node.ELEMENT_NODE && !["SCRIPT", "STYLE", "CODE", "PRE", "TEMPLATE", "NOSCRIPT"].includes(root.tagName)) {
1063
+ Array.from(root.attributes).forEach((attr) => {
1064
+ if (attr.value.includes("${")) {
1065
+ bindEffect(root, attr.value, true, attr.name);
1066
+ }
1067
+ });
1068
+ }
1069
+ };
1070
+ const processAddedNode = (node, nodesToProcess, nodesToActivate) => {
1071
+ if (node.nodeType === Node.ELEMENT_NODE || node.nodeType === Node.TEXT_NODE) {
1072
+ nodesToActivate.push(node);
1073
+ }
1074
+ if (node.nodeType !== Node.ELEMENT_NODE) return;
1075
+ nodesToProcess.push(node);
1076
+ const selector = "[src]:not(" + STANDARD_SRC_TAGS.join("):not(") + ")";
1077
+ const descendants = node.querySelectorAll(selector);
1078
+ for (const desc of descendants) {
1079
+ if (!desc.tagName.toLowerCase().startsWith("lv-")) {
1080
+ nodesToProcess.push(desc);
1081
+ }
1082
+ }
1083
+ };
1084
+ const collectNodesFromMutations = (mutations) => {
1085
+ const nodesToProcess = [];
1086
+ const nodesToActivate = [];
1087
+ for (const mutation of mutations) {
1088
+ if (mutation.type === "childList") {
1089
+ mutation.addedNodes.forEach((node) => processAddedNode(node, nodesToProcess, nodesToActivate));
1090
+ } else if (mutation.type === "attributes" && mutation.attributeName === "src") {
1091
+ nodesToProcess.push(mutation.target);
1092
+ }
1093
+ }
1094
+ return { nodesToProcess, nodesToActivate };
1095
+ };
1096
+ const setupSrcObserver = (LV) => {
1097
+ const observer = new MutationObserver((mutations) => {
1098
+ const { nodesToProcess, nodesToActivate } = collectNodesFromMutations(mutations);
1099
+ if (nodesToProcess.length > 0 || nodesToActivate.length > 0) {
1100
+ requestAnimationFrame(() => {
1101
+ nodesToActivate.forEach((node) => activateReactiveSyntax(node, LV));
1102
+ nodesToProcess.forEach((node) => processSrcOnNode(node, LV));
1103
+ });
1104
+ }
1105
+ });
1106
+ observer.observe(document.body, {
1107
+ childList: true,
1108
+ subtree: true,
1109
+ attributes: true,
1110
+ attributeFilter: ["src"]
1111
+ });
1112
+ return observer;
1113
+ };
1114
+ if (typeof window !== "undefined" && globalThis.Lightview) {
1115
+ const LV = globalThis.Lightview;
1116
+ if (document.readyState === "loading") {
1117
+ document.addEventListener("DOMContentLoaded", () => setupSrcObserver(LV));
1118
+ } else {
1119
+ setupSrcObserver(LV);
1120
+ }
1121
+ const initialScan = () => {
1122
+ requestAnimationFrame(() => {
1123
+ activateReactiveSyntax(document.body, LV);
1124
+ const selector = "[src]:not(" + STANDARD_SRC_TAGS.join("):not(") + ")";
1125
+ const nodes = document.querySelectorAll(selector);
1126
+ nodes.forEach((node) => {
1127
+ if (node.tagName.toLowerCase().startsWith("lv-")) return;
1128
+ processSrcOnNode(node, LV);
1129
+ });
1130
+ });
1131
+ };
1132
+ if (document.body) {
1133
+ initialScan();
1134
+ } else {
1135
+ document.addEventListener("DOMContentLoaded", initialScan);
1136
+ }
1137
+ LV.hooks.onNonStandardHref = (e) => {
1138
+ handleNonStandardHref(e, {
1139
+ domToElement: LV.internals.domToElement,
1140
+ wrapDomElement: LV.internals.wrapDomElement
1141
+ });
1142
+ };
1143
+ SENSIBLE_EVENTS.forEach((ev) => window.addEventListener(ev, globalBeforeInterceptor, true));
1144
+ CAPTURE_EVENTS.forEach((ev) => window.addEventListener(ev, globalBeforeInterceptor, true));
1145
+ LV.hooks.processChild = (child) => {
1146
+ if (!child) return child;
1147
+ if (typeof child === "object" && !Array.isArray(child) && !child.tag && !child.domEl) {
1148
+ child = convertObjectDOM(child);
1149
+ }
1150
+ if (typeof child === "string" && child.startsWith("$") && isNaN(parseInt(child[1]))) {
1151
+ const CDOM = globalThis.LightviewCDOM;
1152
+ if (CDOM) return CDOM.parseExpression(child);
1153
+ }
1154
+ if (typeof child === "string" && (child.trim().startsWith("{") || child.trim().startsWith("["))) {
1155
+ try {
1156
+ const parsed = new Function("return (" + child + ")")();
1157
+ if (typeof parsed === "object" && parsed !== null) {
1158
+ if (Array.isArray(parsed)) {
1159
+ return parsed;
1160
+ }
1161
+ if (parsed.tag || parsed.domEl) {
1162
+ return parsed;
1163
+ }
1164
+ return convertObjectDOM(parsed);
1165
+ }
1166
+ } catch (e) {
1167
+ }
1168
+ }
1169
+ return processTemplateChild(child, {
1170
+ state,
1171
+ signal: LV.signal
1172
+ });
1173
+ };
1174
+ }
1175
+ const createCustomElement = (Component, options = {}) => {
1176
+ return class extends HTMLElement {
1177
+ constructor() {
1178
+ super();
1179
+ this.attachShadow({ mode: "open" });
1180
+ }
1181
+ async connectedCallback() {
1182
+ const { cssUrl, styles } = options;
1183
+ this.themeWrapper = document.createElement("div");
1184
+ this.themeWrapper.style.display = "contents";
1185
+ const syncTheme = () => {
1186
+ const theme = document.documentElement.getAttribute("data-theme") || "light";
1187
+ this.themeWrapper.setAttribute("data-theme", theme);
1188
+ };
1189
+ syncTheme();
1190
+ this.themeObserver = new MutationObserver(syncTheme);
1191
+ this.themeObserver.observe(document.documentElement, {
1192
+ attributes: true,
1193
+ attributeFilter: ["data-theme"]
1194
+ });
1195
+ this.shadowRoot.appendChild(this.themeWrapper);
1196
+ const adoptedStyleSheets = getAdoptedStyleSheets(cssUrl, styles);
1197
+ try {
1198
+ const sheets = adoptedStyleSheets.filter((s) => s instanceof CSSStyleSheet);
1199
+ this.shadowRoot.adoptedStyleSheets = sheets;
1200
+ } catch (e) {
1201
+ }
1202
+ if (!componentConfig.daisyStyleSheet) {
1203
+ const link = document.createElement("link");
1204
+ link.rel = "stylesheet";
1205
+ link.href = DAISYUI_CDN;
1206
+ this.shadowRoot.appendChild(link);
1207
+ }
1208
+ adoptedStyleSheets.forEach((s) => {
1209
+ if (typeof s === "string") {
1210
+ const link = document.createElement("link");
1211
+ link.rel = "stylesheet";
1212
+ link.href = s;
1213
+ this.shadowRoot.appendChild(link);
1214
+ }
1215
+ });
1216
+ this.render = () => {
1217
+ const props = {};
1218
+ for (const attr of this.attributes) {
1219
+ const name = attr.name.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
1220
+ if (attr.value === "") {
1221
+ props[name] = true;
1222
+ } else {
1223
+ props[name] = attr.value;
1224
+ }
1225
+ }
1226
+ props.useShadow = false;
1227
+ const slot = globalThis.Lightview.tags.slot();
1228
+ const result = Component(props, slot);
1229
+ globalThis.Lightview.internals.setupChildren([result], this.themeWrapper);
1230
+ };
1231
+ if (typeof MutationObserver !== "undefined" && typeof HTMLElement !== "undefined") {
1232
+ this.attrObserver = new MutationObserver((mutations) => {
1233
+ this.render();
1234
+ });
1235
+ this.attrObserver.observe(this, {
1236
+ attributes: true
1237
+ });
1238
+ }
1239
+ this.render();
1240
+ }
1241
+ disconnectedCallback() {
1242
+ if (this.themeObserver) {
1243
+ this.themeObserver.disconnect();
1244
+ }
1245
+ if (this.attrObserver) {
1246
+ this.attrObserver.disconnect();
1247
+ }
1248
+ }
1249
+ };
1250
+ };
1251
+ const customElementWrapper = (Component, config = {}) => {
1252
+ const {
1253
+ attributeMap = {},
1254
+ childElements = {}
1255
+ } = config;
1256
+ return class extends HTMLElement {
1257
+ constructor() {
1258
+ super();
1259
+ this.attachShadow({ mode: "open" });
1260
+ }
1261
+ connectedCallback() {
1262
+ let adopted = false;
1263
+ if (componentConfig.daisyStyleSheet) {
1264
+ try {
1265
+ const sheets = [componentConfig.daisyStyleSheet];
1266
+ if (componentConfig.themeStyleSheet) {
1267
+ sheets.push(componentConfig.themeStyleSheet);
1268
+ }
1269
+ this.shadowRoot.adoptedStyleSheets = sheets;
1270
+ adopted = true;
1271
+ } catch (e) {
1272
+ }
1273
+ }
1274
+ if (!adopted) {
1275
+ const link = document.createElement("link");
1276
+ link.rel = "stylesheet";
1277
+ link.href = DAISYUI_CDN;
1278
+ this.shadowRoot.appendChild(link);
1279
+ }
1280
+ const themeWrapper = document.createElement("div");
1281
+ themeWrapper.setAttribute("data-theme", document.documentElement.getAttribute("data-theme") || "light");
1282
+ themeWrapper.style.display = "contents";
1283
+ this.shadowRoot.appendChild(themeWrapper);
1284
+ this.themeWrapper = themeWrapper;
1285
+ this.themeObserver = new MutationObserver(() => {
1286
+ const theme = document.documentElement.getAttribute("data-theme") || "light";
1287
+ this.themeWrapper.setAttribute("data-theme", theme);
1288
+ });
1289
+ this.themeObserver.observe(document.documentElement, {
1290
+ attributes: true,
1291
+ attributeFilter: ["data-theme"]
1292
+ });
1293
+ this.render();
1294
+ const attrs = Object.keys(attributeMap);
1295
+ if (attrs.length > 0) {
1296
+ this.attrObserver = new MutationObserver(() => this.render());
1297
+ this.attrObserver.observe(this, {
1298
+ attributes: true,
1299
+ attributeFilter: attrs
1300
+ });
1301
+ }
1302
+ if (Object.keys(childElements).length > 0) {
1303
+ this.childObserver = new MutationObserver(() => this.render());
1304
+ this.childObserver.observe(this, {
1305
+ childList: true,
1306
+ subtree: true,
1307
+ attributes: true
1308
+ });
1309
+ }
1310
+ }
1311
+ disconnectedCallback() {
1312
+ if (this.themeObserver) this.themeObserver.disconnect();
1313
+ if (this.attrObserver) this.attrObserver.disconnect();
1314
+ if (this.childObserver) this.childObserver.disconnect();
1315
+ }
1316
+ parseChildrenToVDOM() {
1317
+ return Array.from(this.children).map((child) => {
1318
+ const tagName = child.tagName.toLowerCase();
1319
+ const componentInfo = childElements[tagName];
1320
+ if (!componentInfo) return null;
1321
+ const { component, attributeMap: attributeMap2 = {} } = componentInfo;
1322
+ const attributes = {};
1323
+ for (const attr of child.attributes) {
1324
+ const name = attr.name.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
1325
+ const type = attributeMap2[name];
1326
+ const value = attr.value;
1327
+ if (type === Boolean) {
1328
+ attributes[name] = value === "true" || value === "";
1329
+ } else if (type === Number) {
1330
+ attributes[name] = Number(value);
1331
+ } else if (type === Array || type === Object) {
1332
+ try {
1333
+ attributes[name] = JSON.parse(value);
1334
+ } catch (e) {
1335
+ console.warn(`[Lightview] Failed to parse child attribute ${name} as JSON:`, value);
1336
+ attributes[name] = value;
1337
+ }
1338
+ } else {
1339
+ attributes[name] = value;
1340
+ }
1341
+ }
1342
+ if (child.onclick) attributes.onclick = child.onclick.bind(child);
1343
+ return {
1344
+ tag: component,
1345
+ attributes,
1346
+ children: Array.from(child.childNodes)
1347
+ };
1348
+ }).filter(Boolean);
1349
+ }
1350
+ render() {
1351
+ var _a, _b;
1352
+ const props = { useShadow: false };
1353
+ for (const attr of this.attributes) {
1354
+ const name = attr.name.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
1355
+ const type = attributeMap[name];
1356
+ const value = attr.value;
1357
+ if (type === Boolean) {
1358
+ props[name] = value === "true" || value === "";
1359
+ } else if (type === Number) {
1360
+ props[name] = Number(value);
1361
+ } else if (type === Array || type === Object) {
1362
+ try {
1363
+ props[name] = JSON.parse(value);
1364
+ } catch (e) {
1365
+ console.warn(`[Lightview] Failed to parse ${name} as JSON:`, value);
1366
+ props[name] = value;
1367
+ }
1368
+ } else {
1369
+ props[name] = value;
1370
+ }
1371
+ }
1372
+ const vdomChildren = this.parseChildrenToVDOM();
1373
+ const children = Object.keys(childElements).length > 0 ? vdomChildren : [{ tag: globalThis.Lightview.tags.slot }];
1374
+ const result = Component(props, ...children);
1375
+ if (((_b = (_a = globalThis.Lightview) == null ? void 0 : _a.internals) == null ? void 0 : _b.setupChildren) && this.themeWrapper) {
1376
+ this.themeWrapper.innerHTML = "";
1377
+ globalThis.Lightview.internals.setupChildren([result], this.themeWrapper);
1378
+ }
1379
+ }
1380
+ static get observedAttributes() {
1381
+ return Object.keys(attributeMap);
1382
+ }
1383
+ attributeChangedCallback() {
1384
+ this.render();
1385
+ }
1386
+ };
1387
+ };
1388
+ const LightviewX = {
1389
+ state,
1390
+ themeSignal,
1391
+ setTheme,
1392
+ registerStyleSheet,
1393
+ registerThemeSheet,
1394
+ // Gate modifiers
1395
+ throttle: gateThrottle,
1396
+ debounce: gateDebounce,
1397
+ // Component initialization
1398
+ initComponents,
1399
+ componentConfig,
1400
+ shouldUseShadow,
1401
+ getAdoptedStyleSheets,
1402
+ preloadComponentCSS,
1403
+ createCustomElement,
1404
+ customElementWrapper,
1405
+ internals: {
1406
+ handleSrcAttribute,
1407
+ parseElements
1408
+ }
1409
+ };
1410
+ if (typeof module !== "undefined" && module.exports) {
1411
+ module.exports = LightviewX;
1412
+ }
1413
+ if (typeof window !== "undefined") {
1414
+ globalThis.LightviewX = LightviewX;
1415
+ }
1416
+ if (typeof window !== "undefined") {
1417
+ try {
1418
+ const savedTheme = getSavedTheme();
1419
+ if (savedTheme) {
1420
+ setTheme(savedTheme);
1421
+ }
1422
+ } catch (e) {
1423
+ }
1424
+ if (typeof window !== "undefined" && globalThis.Lightview) {
1425
+ if (!globalThis.Lightview.hooks.validateUrl) {
1426
+ globalThis.Lightview.hooks.validateUrl = validateUrl;
1427
+ }
1428
+ }
1429
+ }
1430
+ if (typeof globalThis !== "undefined" && globalThis.Lightview) {
1431
+ if (!globalThis.Lightview.hooks.validateUrl) {
1432
+ globalThis.Lightview.hooks.validateUrl = validateUrl;
1433
+ }
1434
+ }
1435
+ })();