@adartem/adlib-attributes 0.1.4 → 0.1.5

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 (65) hide show
  1. package/attributes.js +957 -1
  2. package/attributes.js.map +4 -4
  3. package/dist/chunk-IEGIKJKW.js +5776 -0
  4. package/dist/chunk-IEGIKJKW.js.map +7 -0
  5. package/dist/chunk-M2KO765Q.js +43 -0
  6. package/dist/chunk-M2KO765Q.js.map +7 -0
  7. package/dist/chunk-NS2GB4WB.js +63 -0
  8. package/dist/chunk-NS2GB4WB.js.map +7 -0
  9. package/dist/dist-46N2ZXQQ.js +80 -0
  10. package/dist/dist-46N2ZXQQ.js.map +7 -0
  11. package/dist/dist-4EIQOOMJ.js +331 -0
  12. package/dist/dist-4EIQOOMJ.js.map +7 -0
  13. package/dist/dist-6YSNCGWO.js +227 -0
  14. package/dist/dist-6YSNCGWO.js.map +7 -0
  15. package/dist/dist-7GSHUMRU.js +60 -0
  16. package/dist/dist-7GSHUMRU.js.map +7 -0
  17. package/dist/dist-ALT6N2V6.js +165 -0
  18. package/dist/dist-ALT6N2V6.js.map +7 -0
  19. package/dist/dist-BXD5YEF3.js +290 -0
  20. package/dist/dist-BXD5YEF3.js.map +7 -0
  21. package/dist/dist-D2J4YZM6.js +52 -0
  22. package/dist/dist-D2J4YZM6.js.map +7 -0
  23. package/dist/dist-D2X7FLMD.js +126 -0
  24. package/dist/dist-D2X7FLMD.js.map +7 -0
  25. package/dist/dist-DOOWCYTM.js +92 -0
  26. package/dist/dist-DOOWCYTM.js.map +7 -0
  27. package/dist/dist-GLBAV2CS.js +202 -0
  28. package/dist/dist-GLBAV2CS.js.map +7 -0
  29. package/dist/dist-GQHJZHTH.js +73 -0
  30. package/dist/dist-GQHJZHTH.js.map +7 -0
  31. package/dist/dist-H4ILPDRU.js +59 -0
  32. package/dist/dist-H4ILPDRU.js.map +7 -0
  33. package/dist/dist-IDJRFWAH.js +71 -0
  34. package/dist/dist-IDJRFWAH.js.map +7 -0
  35. package/dist/dist-KDCRSMGT.js +63 -0
  36. package/dist/dist-KDCRSMGT.js.map +7 -0
  37. package/dist/dist-KF5AKQ52.js +740 -0
  38. package/dist/dist-KF5AKQ52.js.map +7 -0
  39. package/dist/dist-KU26ZFEG.js +169 -0
  40. package/dist/dist-KU26ZFEG.js.map +7 -0
  41. package/dist/dist-M6QCD7TL.js +4281 -0
  42. package/dist/dist-M6QCD7TL.js.map +7 -0
  43. package/dist/dist-MBFKX56S.js +482 -0
  44. package/dist/dist-MBFKX56S.js.map +7 -0
  45. package/dist/dist-NOIPAOTU.js +131 -0
  46. package/dist/dist-NOIPAOTU.js.map +7 -0
  47. package/dist/dist-QPNIGMZA.js +33028 -0
  48. package/dist/dist-QPNIGMZA.js.map +7 -0
  49. package/dist/dist-RAOZ6VUA.js +14416 -0
  50. package/dist/dist-RAOZ6VUA.js.map +7 -0
  51. package/dist/dist-RQZGUXDL.js +102 -0
  52. package/dist/dist-RQZGUXDL.js.map +7 -0
  53. package/dist/dist-T4V65O5X.js +54 -0
  54. package/dist/dist-T4V65O5X.js.map +7 -0
  55. package/dist/dist-UFMW7V6T.js +317 -0
  56. package/dist/dist-UFMW7V6T.js.map +7 -0
  57. package/dist/dist-V7I3FQX7.js +1419 -0
  58. package/dist/dist-V7I3FQX7.js.map +7 -0
  59. package/dist/dist-XTGERRGU.js +160 -0
  60. package/dist/dist-XTGERRGU.js.map +7 -0
  61. package/dist/dist-YAVVMJ7W.js +72 -0
  62. package/dist/dist-YAVVMJ7W.js.map +7 -0
  63. package/dist/dist-YGJKGMK6.js +137 -0
  64. package/dist/dist-YGJKGMK6.js.map +7 -0
  65. package/package.json +11 -11
package/attributes.js CHANGED
@@ -1 +1,957 @@
1
- import{M as v,Ma as E,ab as _,va as R}from"./dist/chunk-3XBROWKO.js";var S="0.1.4";var D=async t=>{switch(t){case"accordion":return import("./dist/dist-MJIZMTBO.js");case"autovideo":return import("./dist/dist-4KOXX7FX.js");case"codehighlight":return import("./dist/dist-FDVEU4NM.js");case"combobox":return import("./dist/dist-CYWMPADF.js");case"copyclip":return import("./dist/dist-G3CWGTZT.js");case"displayvalues":return import("./dist/dist-WE5HIYWJ.js");case"favcustom":return import("./dist/dist-I62SAT3A.js");case"formsubmit":return import("./dist/dist-N6RICZVA.js");case"inject":return import("./dist/dist-KJYLEW5G.js");case"inputactive":return import("./dist/dist-GCEMMGQC.js");case"inputcounter":return import("./dist/dist-KVCUHKEL.js");case"list":return import("./dist/dist-CYEP7ZYD.js");case"mirrorclick":return import("./dist/dist-XQCFKZZ4.js");case"mirrorinput":return import("./dist/dist-NTTQPHMC.js");case"modal":return import("./dist/dist-GIVVHNIU.js");case"numbercount":return import("./dist/dist-YGHHEKQY.js");case"queryparam":return import("./dist/dist-DCT2OKR6.js");case"rangeslider":return import("./dist/dist-KWNONO67.js");case"readtime":return import("./dist/dist-SPPDEZAG.js");case"removequery":return import("./dist/dist-NDUZI32X.js");case"scrolldisable":return import("./dist/dist-RPND2SFD.js");case"selectcustom":return import("./dist/dist-AZVF6KF7.js");case"sliderdots":return import("./dist/dist-45TZF6O6.js");case"smartlightbox":return import("./dist/dist-6YZ22CPE.js");case"socialshare":return import("./dist/src-EP63RPX3.js");case"starrating":return import("./dist/dist-3KKACNWT.js");case"toc":return import("./dist/dist-NGZXQFOC.js");case"videohls":return import("./dist/src-OO4DGOWA.js");default:throw`Adartem Attribute "${t}" is not supported.`}};function M(t){let r=t.search(/[?#]/);return r===-1?t:t.slice(0,r)}function K(t,r){try{return new URL(t,r)}catch{return null}}function j(t,r){return M(t.pathname).endsWith(M(r.pathname))}function k(t){if(typeof document>"u")return[];let r=Array.from(document.querySelectorAll('script[type="module"][src]')),o=document.baseURI||(typeof location<"u"?location.href:"http://localhost/"),e=K(t,o);if(!e)return[];let s=[];for(let n of r){let u=n.getAttribute("src");if(!u)continue;let m=K(u,o);m&&j(m,e)&&s.push(n)}return s}function L(t,r){let o=t.getAttribute(r);if(o!==null)return o===""||o.toLowerCase()==="true"?!0:o.toLowerCase()!=="false"}function C(t){let r={},o={};for(let e of t){let s=e.getAttribute("data-adlib-registry"),n=e.getAttribute("data-adlib-version"),u=e.getAttribute("data-adlib-base");s&&(r.registry=s),n&&(r.version=n),u&&(r.base=u);let m=L(e,"data-adlib-debug"),i=L(e,"data-adlib-auto"),d=L(e,"data-adlib-observe-attributes");m===!0&&(o.debug=!0),i===!0&&(o.auto=!0),d===!0&&(o.observeAttributes=!0)}return{config:r,flags:o}}var q=/^ad-[a-z0-9-]+$/i,Q=/^data-ad-[a-z0-9-]+$/i;function Y(t){return Q.test(t)?t.slice(8):q.test(t)?t.slice(3):null}function g(t){let r=new Set;for(let o of t)for(let{name:e}of Array.from(o.attributes)){if(e.startsWith("data-adlib-"))continue;let s=Y(e);s&&r.add(s)}return Array.from(r)}function x(t,r){r.config&&(t.config={...t.config,...r.config}),r.debug===!0&&(t.debug=!0),r.auto===!0&&(t.auto=!0),r.observeAttributes===!0&&(t.observeAttributes=!0)}var f=class extends Error{code;key;cause;meta;constructor(r){super(r.message),this.name="AdLibRuntimeError",this.code=r.code,this.key=r.key,this.cause=r.cause,this.meta=r.meta}};function y(t,r){return t instanceof f?t:new f({code:r.code,message:r.message,key:r.key,cause:t,meta:r.meta})}function T(t){let r=[];for(let[o,e]of Object.entries(t.modules)){if(!e)continue;let s=e.error instanceof f?e.error.code:void 0;r.push({key:o,status:e.status,errorCode:s})}return r.sort((o,e)=>o.key.localeCompare(e.key)),r}function z(t){let r=()=>({version:t.version,debug:t.debug,auto:t.auto,observeAttributes:t.observeAttributes,config:t.config,scriptsCount:t.scripts.length,modules:T(t)});return{runtime:t,snapshot:r,modules:()=>T(t),dump:()=>{let o=r();try{console.error("[AdLib] Runtime snapshot",o)}catch{}return o}}}function I(t){if(typeof window>"u")return;let r=window;r.__ADLIB_DEBUG__?.runtime!==t&&(r.__ADLIB_DEBUG__=z(t))}function h(){return typeof window<"u"&&typeof document<"u"}function O(t){if(h()){if(document.readyState==="interactive"||document.readyState==="complete"){t();return}document.addEventListener("DOMContentLoaded",()=>{t()},{once:!0})}}function G(t){return Array.isArray(t)}function H(t){return!!t&&typeof t=="object"&&"push"in t&&typeof t.push=="function"}function N(t){if(typeof window>"u")return;let r=window,o=r.AdLibAttributes;if(H(o)||!G(o)||o.__adlib_drained__===!0)return;let e=o.slice();o.length=0,o.__adlib_drained__=!0,e.length>0&&t.push(...e),r.AdLibAttributes=t}function A(t,r){if(!(typeof window>"u"))try{let o=new CustomEvent(t,{detail:r});window.dispatchEvent(o)}catch{}}function F(t,r){let o=r?.minDelayMs??50,e=!1,s=0,n;function u(){e=!1,n=void 0,s=Date.now(),t()}function m(){if(e)return;e=!0;let d=Date.now()-s,a=d>=o?0:o-d;if(a===0){queueMicrotask(()=>u());return}n=window.setTimeout(()=>u(),a)}function i(){e=!1,n!==void 0&&(clearTimeout(n),n=void 0)}return{schedule:m,cancel:i,isScheduled:()=>e}}var V=/^ad-[a-z0-9-]+$/i,X=/^data-ad-[a-z0-9-]+$/i;function J(t){return t.startsWith("data-adlib-")?null:X.test(t)?t.slice(8):V.test(t)?t.slice(3):null}function U(t,r){for(let{name:o}of Array.from(t.attributes)){let e=J(o);e&&r.add(e)}}function B(t){let r=new Set;for(let o of t){if(o.nodeType!==1)continue;let e=o;U(e,r);for(let s of Array.from(e.querySelectorAll("*")))U(s,r)}return Array.from(r)}var Z=/^ad-[a-z0-9-]+$/i,tt=/^data-ad-[a-z0-9-]+$/i;function et(t){return tt.test(t)?t.slice(8):Z.test(t)?t.slice(3):null}function W(t){let r=null,o=!1,e=null,s=[],n=[],u=F(()=>{let a=B(s);s.length=0;let l=new Set;if(t.observeAttributes)for(let c of n){if(c.startsWith("data-adlib-"))continue;let b=et(c);b&&l.add(b)}n.length=0;let p=Array.from(new Set([...a,...Array.from(l)]));(async()=>{for(let c of p)try{await t.load(c)}catch{}})()},{minDelayMs:50});function m(){return t.observeAttributes?"nodes+attrs":"nodes"}function i(a){for(let l of a){if(l.type==="childList"){for(let p of Array.from(l.addedNodes))s.push(p);continue}if(l.type==="attributes"){if(!t.observeAttributes)continue;let p=l.attributeName;if(!p)continue;n.push(p)}}(s.length>0||n.length>0)&&u.schedule()}function d(a){if(typeof document>"u")return;let l=document.body;if(!l||(r||(r=new MutationObserver(i)),o&&e===a))return;r.disconnect();let p={subtree:!0,childList:!0},c=a==="nodes+attrs"?{...p,attributes:!0,attributeOldValue:!1}:p;r.observe(l,c),o=!0,e=a}return{isActive:()=>o,ensureStarted:()=>{d(m())},stop:()=>{r&&(r.disconnect(),o=!1,e=null,u.cancel(),s.length=0,n.length=0)}}}var rt="ad-attributes",P=new Set(Object.values(R)),ot=t=>Array.isArray(t),it=()=>{let{AdLibAttributes:t}=window,r=t&&!Array.isArray(t)?t:void 0,o=r??{version:S,scripts:[],config:{},debug:!1,auto:!1,observeAttributes:!1,modules:{},process:new Set,utils:{fetchPage:E,attachExternalStylesheets:v},load:w,async reload(i,d){let a=this.modules[i]??await this.load(i);if(a.status==="ready"){let l=a.instance;if(l&&typeof l.restart=="function")try{return await l.restart({rescan:d?.rescan}),a}catch{return a.destroy(),await this.load(i)}}return a.destroy(),await this.load(i)},push(...i){for(let d of i){let[a,l]=ot(d)?d:[d.key,d.cb],p=a,c=this.modules[p];if(c&&(c.status==="ready"||c.status==="error")){l(c);continue}(!c||c.status!=="loading")&&(this.load(p),c=this.modules[p]),c&&(c.promise?c.promise.then(()=>l(c)).catch(()=>l(c)):l(c))}},applyLoaderConfig:()=>{},destroy(i){for(let d in this.modules)this.modules[d]?.destroy?.();e.stop(),i?.keepGlobal},getState(i){return i?this.modules[i]??{key:i,status:"idle",reload:d=>this.reload(i,d),destroy:()=>{this.process.delete(i)}}:this.modules},getErrors(){let i=[];for(let[d,a]of Object.entries(this.modules))a?.status==="error"&&a.error&&i.push({key:d,error:a.error});return i},isLoaded(i){return this.modules[i]?.status==="ready"},initFromScripts(i){let d=i?.scripts??[],a=new Set(this.scripts);for(let b of d)a.has(b)||(a.add(b),this.scripts.push(b));let l=g(this.scripts),p=i?.requestedKeys??[],c=Array.from(new Set([...p,...l]));this.auto&&(async()=>{for(let b of c)try{await this.load(b)}catch{}})()}},e=o.observerCtl??W(o);o.observerCtl=e,o.applyLoaderConfig=i=>{x(o,i),e.ensureStarted()},r||(window.AdLibAttributes=o),N(o),I(o);let s=k(import.meta.url),{config:n,flags:u}=C(s),m=g(s);o.applyLoaderConfig({config:n,debug:u.debug,auto:u.auto,observeAttributes:u.observeAttributes}),o.initFromScripts({scripts:s,requestedKeys:m}),nt()};function st(){h()&&O(()=>{it()})}var nt=()=>{let t=!1;for(let r of window.AdLibAttributes.scripts){t||=r.getAttribute(`${rt}-auto`)==="true";for(let o of P)r.hasAttribute(`ad-${o}`)&&w(o)}t&&_().then(()=>{let r=new Set,o=document.querySelectorAll("*");for(let e of o)for(let s of e.getAttributeNames()){let u=s.match(/^ad-([^-]+)/)?.[1];u&&P.has(u)&&r.add(u)}for(let e of r)w(e)})},w=async t=>{let r=n=>/^[a-z][a-z0-9-]*$/i.test(n),o=window.AdLibAttributes,e=o.modules[t]??={key:t,status:"idle",reload:n=>o.reload(t,n),destroy:()=>{o.process.delete(t)}};if(!r(String(t))){let n=new f({code:"UNKNOWN_MODULE_KEY",message:`Unknown module key: ${String(t)}`,key:t});return e.status="error",e.error=n,A("ad:module:error",{key:t,state:e,error:n}),e}if(o.process.has(t))return e;o.process.add(t),e.status="loading",A("ad:module:before",{key:t,state:e});let s=(async()=>{let n;try{n=await D(t)}catch(u){console.error(u);let m=y(u,{code:"MODULE_IMPORT_FAILED",message:`Failed to import module ${t}`,key:t,meta:{}});e.status="error",e.error=m,e.instance=void 0,A("ad:module:error",{key:t,state:e,error:m});return}try{let{init:u}=n,{result:m,destroy:i}=await u()||{};return e.instance=m,e.status="ready",e.error=void 0,A("ad:module:after",{key:t,state:e}),e.destroy=()=>{try{i?.(),o.process.delete(t),e.status="idle",e.instance=void 0,e.error=void 0,e.promise=void 0}catch(d){console.error(d);let a=y(d,{code:"MODULE_DESTROY_FAILED",message:`Failed to destroy module ${t}`,key:t,meta:{}});e.status="error",e.error=a,e.instance=void 0,A("ad:module:error",{key:t,state:e,error:a})}},m}catch(u){console.error(u);let m=y(u,{code:"MODULE_INIT_FAILED",message:`Failed to init module ${t}`,key:t,meta:{}});e.status="error",e.error=m,e.instance=void 0,A("ad:module:error",{key:t,state:e,error:m});return}})();return e.promise=s,await s,e};st();export{st as bootstrapAttributesLoader};
1
+ import {
2
+ Po,
3
+ de,
4
+ init_live_reload,
5
+ ir,
6
+ xn
7
+ } from "./dist/chunk-IEGIKJKW.js";
8
+
9
+ // src/attributes.ts
10
+ init_live_reload();
11
+
12
+ // package.json
13
+ var version = "0.1.5";
14
+
15
+ // src/load.ts
16
+ init_live_reload();
17
+ var loadAttribute = async (key) => {
18
+ switch (key) {
19
+ case "accordion": {
20
+ return import("./dist/dist-ALT6N2V6.js");
21
+ }
22
+ case "autovideo": {
23
+ return import("./dist/dist-7GSHUMRU.js");
24
+ }
25
+ case "codehighlight": {
26
+ return import("./dist/dist-RAOZ6VUA.js");
27
+ }
28
+ case "combobox": {
29
+ return import("./dist/dist-MBFKX56S.js");
30
+ }
31
+ case "copyclip": {
32
+ return import("./dist/dist-KF5AKQ52.js");
33
+ }
34
+ case "displayvalues": {
35
+ return import("./dist/dist-GQHJZHTH.js");
36
+ }
37
+ case "favcustom": {
38
+ return import("./dist/dist-T4V65O5X.js");
39
+ }
40
+ case "formsubmit": {
41
+ return import("./dist/dist-GLBAV2CS.js");
42
+ }
43
+ case "inject": {
44
+ return import("./dist/dist-XTGERRGU.js");
45
+ }
46
+ case "inputactive": {
47
+ return import("./dist/dist-IDJRFWAH.js");
48
+ }
49
+ case "inputcounter": {
50
+ return import("./dist/dist-YGJKGMK6.js");
51
+ }
52
+ case "list": {
53
+ return import("./dist/dist-M6QCD7TL.js");
54
+ }
55
+ case "mirrorclick": {
56
+ return import("./dist/dist-KDCRSMGT.js");
57
+ }
58
+ case "mirrorinput": {
59
+ return import("./dist/dist-YAVVMJ7W.js");
60
+ }
61
+ case "modal": {
62
+ return import("./dist/dist-V7I3FQX7.js");
63
+ }
64
+ case "numbercount": {
65
+ return import("./dist/dist-RQZGUXDL.js");
66
+ }
67
+ case "queryparam": {
68
+ return import("./dist/dist-46N2ZXQQ.js");
69
+ }
70
+ case "rangeslider": {
71
+ return import("./dist/dist-BXD5YEF3.js");
72
+ }
73
+ case "readtime": {
74
+ return import("./dist/dist-D2J4YZM6.js");
75
+ }
76
+ case "removequery": {
77
+ return import("./dist/dist-H4ILPDRU.js");
78
+ }
79
+ case "scrolldisable": {
80
+ return import("./dist/dist-UFMW7V6T.js");
81
+ }
82
+ case "selectcustom": {
83
+ return import("./dist/dist-6YSNCGWO.js");
84
+ }
85
+ case "sliderdots": {
86
+ return import("./dist/dist-NOIPAOTU.js");
87
+ }
88
+ case "smartlightbox": {
89
+ return import("./dist/dist-DOOWCYTM.js");
90
+ }
91
+ case "socialshare": {
92
+ return import("./dist/dist-KU26ZFEG.js");
93
+ }
94
+ case "starrating": {
95
+ return import("./dist/dist-D2X7FLMD.js");
96
+ }
97
+ case "toc": {
98
+ return import("./dist/dist-4EIQOOMJ.js");
99
+ }
100
+ case "videohls": {
101
+ return import("./dist/dist-QPNIGMZA.js");
102
+ }
103
+ default: {
104
+ throw `Adartem Attribute "${key}" is not supported.`;
105
+ }
106
+ }
107
+ };
108
+
109
+ // src/loader/discover-loader-scripts.ts
110
+ init_live_reload();
111
+ function stripHashAndQuery(u) {
112
+ const i = u.search(/[?#]/);
113
+ return i === -1 ? u : u.slice(0, i);
114
+ }
115
+ function safeToURL(u, base) {
116
+ try {
117
+ return new URL(u, base);
118
+ } catch {
119
+ return null;
120
+ }
121
+ }
122
+ function sameNormalizedPath(a, b) {
123
+ return stripHashAndQuery(a.pathname).endsWith(stripHashAndQuery(b.pathname));
124
+ }
125
+ function discoverLoaderScripts(currentImportMetaUrl) {
126
+ if (typeof document === "undefined") return [];
127
+ const scripts = Array.from(
128
+ document.querySelectorAll('script[type="module"][src]')
129
+ );
130
+ const base = document.baseURI || (typeof location !== "undefined" ? location.href : "http://localhost/");
131
+ const current = safeToURL(currentImportMetaUrl, base);
132
+ if (!current) return [];
133
+ const matches = [];
134
+ for (const s of scripts) {
135
+ const src = s.getAttribute("src");
136
+ if (!src) continue;
137
+ const u = safeToURL(src, base);
138
+ if (!u) continue;
139
+ if (sameNormalizedPath(u, current)) {
140
+ matches.push(s);
141
+ }
142
+ }
143
+ return matches;
144
+ }
145
+
146
+ // src/loader/read-loader-config.ts
147
+ init_live_reload();
148
+ function readBoolAttr(s, name) {
149
+ const v = s.getAttribute(name);
150
+ if (v === null) return void 0;
151
+ if (v === "" || v.toLowerCase() === "true") return true;
152
+ if (v.toLowerCase() === "false") return false;
153
+ return true;
154
+ }
155
+ function readLoaderConfigFromScripts(scripts) {
156
+ const config = {};
157
+ const flags = {};
158
+ for (const s of scripts) {
159
+ const registry = s.getAttribute("data-adlib-registry");
160
+ const version2 = s.getAttribute("data-adlib-version");
161
+ const base = s.getAttribute("data-adlib-base");
162
+ if (registry) config.registry = registry;
163
+ if (version2) config.version = version2;
164
+ if (base) config.base = base;
165
+ const debug = readBoolAttr(s, "data-adlib-debug");
166
+ const auto = readBoolAttr(s, "data-adlib-auto");
167
+ const observe = readBoolAttr(s, "data-adlib-observe-attributes");
168
+ if (debug === true) flags.debug = true;
169
+ if (auto === true) flags.auto = true;
170
+ if (observe === true) flags.observeAttributes = true;
171
+ const channels = s.getAttribute("data-adlib-debug-channels");
172
+ if (channels) flags.debugChannels = channels;
173
+ }
174
+ return { config, flags };
175
+ }
176
+
177
+ // src/loader/scan-script-keys.ts
178
+ init_live_reload();
179
+ var AD_KEY_RE = /^ad-[a-z0-9-]+$/i;
180
+ var DATA_AD_KEY_RE = /^data-ad-[a-z0-9-]+$/i;
181
+ function toModuleKey(attrName) {
182
+ if (DATA_AD_KEY_RE.test(attrName)) {
183
+ return attrName.slice("data-ad-".length);
184
+ }
185
+ if (AD_KEY_RE.test(attrName)) {
186
+ return attrName.slice("ad-".length);
187
+ }
188
+ return null;
189
+ }
190
+ function scanRequestedKeysFromScripts(scripts) {
191
+ const out = /* @__PURE__ */ new Set();
192
+ for (const s of scripts) {
193
+ for (const { name } of Array.from(s.attributes)) {
194
+ if (name.startsWith("data-adlib-")) continue;
195
+ const key = toModuleKey(name);
196
+ if (key) out.add(key);
197
+ }
198
+ }
199
+ return Array.from(out);
200
+ }
201
+
202
+ // src/runtime/apply-loader-config.ts
203
+ init_live_reload();
204
+ function applyLoaderConfigCumulative(runtime, patch) {
205
+ if (patch.config) {
206
+ runtime.config = {
207
+ ...runtime.config,
208
+ ...patch.config
209
+ };
210
+ }
211
+ if (patch.debug === true) runtime.debug = true;
212
+ if (patch.auto === true) runtime.auto = true;
213
+ if (patch.observeAttributes === true) runtime.observeAttributes = true;
214
+ }
215
+
216
+ // src/runtime/devtools.ts
217
+ init_live_reload();
218
+
219
+ // src/runtime/errors.ts
220
+ init_live_reload();
221
+ var AdLibRuntimeError = class extends Error {
222
+ code;
223
+ key;
224
+ cause;
225
+ meta;
226
+ constructor(args) {
227
+ super(args.message);
228
+ this.name = "AdLibRuntimeError";
229
+ this.code = args.code;
230
+ this.key = args.key;
231
+ this.cause = args.cause;
232
+ this.meta = args.meta;
233
+ }
234
+ };
235
+ function asRuntimeError(err, fallback) {
236
+ if (err instanceof AdLibRuntimeError) return err;
237
+ return new AdLibRuntimeError({
238
+ code: fallback.code,
239
+ message: fallback.message,
240
+ key: fallback.key,
241
+ cause: err,
242
+ meta: fallback.meta
243
+ });
244
+ }
245
+
246
+ // src/runtime/devtools.ts
247
+ function toSnapshotModules(runtime) {
248
+ const out = [];
249
+ for (const [key, state] of Object.entries(runtime.modules)) {
250
+ if (!state) continue;
251
+ const entry = {
252
+ key,
253
+ status: state.status
254
+ };
255
+ const errorCode = state.error instanceof AdLibRuntimeError ? state.error.code : void 0;
256
+ if (errorCode !== void 0) {
257
+ entry.errorCode = errorCode;
258
+ }
259
+ out.push(entry);
260
+ }
261
+ out.sort((a, b) => a.key.localeCompare(b.key));
262
+ return out;
263
+ }
264
+ function cleanDiagnostics(diag) {
265
+ const out = {
266
+ flushCount: diag.flushCount,
267
+ receivedMutations: diag.receivedMutations,
268
+ droppedMutations: diag.droppedMutations
269
+ };
270
+ if (diag.lastCapReason !== void 0) {
271
+ out.lastCapReason = diag.lastCapReason;
272
+ }
273
+ return out;
274
+ }
275
+ function createRuntimeDevtools(runtime, logger) {
276
+ function getObserverDiagnostics() {
277
+ const ctl = runtime.observerCtl;
278
+ return ctl?.getDiagnostics?.();
279
+ }
280
+ const snapshot = () => {
281
+ const s = {
282
+ version: runtime.version,
283
+ debug: runtime.debug,
284
+ auto: runtime.auto,
285
+ observeAttributes: runtime.observeAttributes,
286
+ config: runtime.config,
287
+ scriptsCount: runtime.scripts.length,
288
+ modules: toSnapshotModules(runtime)
289
+ };
290
+ const observerDiag = getObserverDiagnostics();
291
+ if (observerDiag) {
292
+ s.observer = cleanDiagnostics(observerDiag);
293
+ }
294
+ return s;
295
+ };
296
+ const devtoolsLog = logger?.child("devtools");
297
+ return {
298
+ runtime,
299
+ snapshot,
300
+ modules: () => toSnapshotModules(runtime),
301
+ dump: () => {
302
+ const s = snapshot();
303
+ try {
304
+ if (typeof console.groupCollapsed === "function") {
305
+ console.groupCollapsed("[adlib:devtools] Runtime snapshot");
306
+ console.info(
307
+ "version:",
308
+ s.version,
309
+ "| debug:",
310
+ s.debug,
311
+ "| auto:",
312
+ s.auto,
313
+ "| observeAttributes:",
314
+ s.observeAttributes
315
+ );
316
+ if (s.modules.length > 0 && typeof console.table === "function") {
317
+ console.table(s.modules);
318
+ }
319
+ if (s.observer) {
320
+ console.info("observer:", s.observer);
321
+ }
322
+ console.groupEnd();
323
+ } else {
324
+ console.info("[adlib:devtools] Runtime snapshot", s);
325
+ }
326
+ } catch {
327
+ }
328
+ devtoolsLog?.debug("dump", s);
329
+ return s;
330
+ }
331
+ };
332
+ }
333
+ function attachRuntimeDevtools(runtime) {
334
+ if (typeof window === "undefined") return;
335
+ const w = window;
336
+ if (w.__ADLIB_DEBUG__?.runtime === runtime) return;
337
+ const { logger } = runtime;
338
+ w.__ADLIB_DEBUG__ = createRuntimeDevtools(runtime, logger);
339
+ }
340
+
341
+ // src/runtime/dom-ready.ts
342
+ init_live_reload();
343
+
344
+ // src/runtime/env.ts
345
+ init_live_reload();
346
+ function isBrowser() {
347
+ return typeof window !== "undefined" && typeof document !== "undefined";
348
+ }
349
+
350
+ // src/runtime/dom-ready.ts
351
+ function onDOMReady(fn) {
352
+ if (!isBrowser()) return;
353
+ if (document.readyState === "interactive" || document.readyState === "complete") {
354
+ fn();
355
+ return;
356
+ }
357
+ document.addEventListener(
358
+ "DOMContentLoaded",
359
+ () => {
360
+ fn();
361
+ },
362
+ { once: true }
363
+ );
364
+ }
365
+
366
+ // src/runtime/drain-prequeue.ts
367
+ init_live_reload();
368
+ function isQueue(x) {
369
+ return Array.isArray(x);
370
+ }
371
+ function isRuntimeLike(x) {
372
+ return !!x && typeof x === "object" && "push" in x && typeof x.push === "function";
373
+ }
374
+ function drainPreLoaderQueueIntoRuntime(runtime) {
375
+ if (typeof window === "undefined") return;
376
+ const globalWindow = window;
377
+ const current = globalWindow.AdLibAttributes;
378
+ if (isRuntimeLike(current)) return;
379
+ if (!isQueue(current)) return;
380
+ if (current.__adlib_drained__ === true) return;
381
+ const items = current.slice();
382
+ current.length = 0;
383
+ current.__adlib_drained__ = true;
384
+ if (items.length > 0) {
385
+ runtime.push(...items);
386
+ }
387
+ globalWindow.AdLibAttributes = runtime;
388
+ }
389
+
390
+ // src/runtime/events.ts
391
+ init_live_reload();
392
+ function emitRuntimeEvent(name, detail) {
393
+ if (typeof window === "undefined") return;
394
+ try {
395
+ const ev = new CustomEvent(name, { detail });
396
+ window.dispatchEvent(ev);
397
+ } catch {
398
+ }
399
+ }
400
+
401
+ // src/runtime/logger.ts
402
+ init_live_reload();
403
+ var NOOP = () => {
404
+ };
405
+ var noopChild = {
406
+ debug: NOOP,
407
+ info: NOOP,
408
+ warn: NOOP,
409
+ error: NOOP
410
+ };
411
+ var noopLogger = {
412
+ enabled: false,
413
+ log: NOOP,
414
+ debug: NOOP,
415
+ info: NOOP,
416
+ warn: NOOP,
417
+ error: NOOP,
418
+ child: () => noopChild
419
+ };
420
+ var CONSOLE_METHOD = {
421
+ debug: "debug",
422
+ info: "info",
423
+ warn: "warn",
424
+ error: "error"
425
+ };
426
+ function createLogger(config) {
427
+ if (!config.enabled) return noopLogger;
428
+ const ns = config.namespace ?? "adlib";
429
+ const { channels } = config;
430
+ function log(level, channel, msg, data) {
431
+ if (channels && !channels.has(channel)) return;
432
+ const payload = {
433
+ ns,
434
+ ch: channel,
435
+ level,
436
+ msg,
437
+ time: Date.now()
438
+ };
439
+ if (data !== void 0) {
440
+ payload.data = data;
441
+ }
442
+ try {
443
+ const method = CONSOLE_METHOD[level];
444
+ console[method](`[${ns}:${channel}] ${msg}`, payload);
445
+ } catch {
446
+ }
447
+ }
448
+ return {
449
+ enabled: true,
450
+ channels,
451
+ log,
452
+ debug: (ch, msg, data) => log("debug", ch, msg, data),
453
+ info: (ch, msg, data) => log("info", ch, msg, data),
454
+ warn: (ch, msg, data) => log("warn", ch, msg, data),
455
+ error: (ch, msg, data) => log("error", ch, msg, data),
456
+ child(channel) {
457
+ return {
458
+ debug: (msg, data) => log("debug", channel, msg, data),
459
+ info: (msg, data) => log("info", channel, msg, data),
460
+ warn: (msg, data) => log("warn", channel, msg, data),
461
+ error: (msg, data) => log("error", channel, msg, data)
462
+ };
463
+ }
464
+ };
465
+ }
466
+ function parseDebugChannels(raw) {
467
+ if (!raw) return void 0;
468
+ const channels = raw.split(",").map((s) => s.trim()).filter(Boolean);
469
+ return channels.length > 0 ? new Set(channels) : void 0;
470
+ }
471
+
472
+ // src/runtime/observer.ts
473
+ init_live_reload();
474
+
475
+ // src/runtime/scan-dom-keys.ts
476
+ init_live_reload();
477
+ var AD_KEY_RE2 = /^ad-[a-z0-9-]+$/i;
478
+ var DATA_AD_KEY_RE2 = /^data-ad-[a-z0-9-]+$/i;
479
+ function attrNameToKey(name) {
480
+ if (name.startsWith("data-adlib-")) return null;
481
+ if (DATA_AD_KEY_RE2.test(name)) return name.slice("data-ad-".length);
482
+ if (AD_KEY_RE2.test(name)) return name.slice("ad-".length);
483
+ return null;
484
+ }
485
+ function scanElement(el, out) {
486
+ for (const { name } of Array.from(el.attributes)) {
487
+ const key = attrNameToKey(name);
488
+ if (key) out.add(key);
489
+ }
490
+ }
491
+ function scanKeysFromNodes(nodes) {
492
+ const out = /* @__PURE__ */ new Set();
493
+ for (const n of nodes) {
494
+ if (n.nodeType !== 1) continue;
495
+ const el = n;
496
+ scanElement(el, out);
497
+ for (const child of Array.from(el.querySelectorAll("*"))) {
498
+ scanElement(child, out);
499
+ }
500
+ }
501
+ return Array.from(out);
502
+ }
503
+
504
+ // src/runtime/observer.ts
505
+ var AD_KEY_RE3 = /^ad-[a-z0-9-]+$/i;
506
+ var DATA_AD_KEY_RE3 = /^data-ad-[a-z0-9-]+$/i;
507
+ function attrNameToKey2(name) {
508
+ if (DATA_AD_KEY_RE3.test(name)) return name.slice("data-ad-".length);
509
+ if (AD_KEY_RE3.test(name)) return name.slice("ad-".length);
510
+ return null;
511
+ }
512
+ var MAX_MUTATIONS_PER_FLUSH = 200;
513
+ var MAX_NODES_PER_FLUSH = 1e3;
514
+ var MAX_KEYS_PER_FLUSH = 50;
515
+ function scheduleMicrotask(fn) {
516
+ if (typeof queueMicrotask === "function") {
517
+ queueMicrotask(fn);
518
+ } else {
519
+ void Promise.resolve().then(fn);
520
+ }
521
+ }
522
+ function createRuntimeObserverController(runtime) {
523
+ let observer = null;
524
+ let observing = false;
525
+ let lastMode = null;
526
+ let backlog = [];
527
+ let flushScheduled = false;
528
+ const diagnostics = {
529
+ flushCount: 0,
530
+ receivedMutations: 0,
531
+ droppedMutations: 0,
532
+ lastCapReason: void 0
533
+ };
534
+ function log(level, msg, data) {
535
+ runtime.logger?.[level]("observer", msg, data);
536
+ }
537
+ function enqueue(mutations) {
538
+ diagnostics.receivedMutations += mutations.length;
539
+ for (const m of mutations) backlog.push(m);
540
+ log("debug", "enqueue", { count: mutations.length, backlog: backlog.length });
541
+ scheduleFlush();
542
+ }
543
+ function flush() {
544
+ flushScheduled = false;
545
+ if (backlog.length === 0) return;
546
+ diagnostics.flushCount++;
547
+ const mutationsToProcess = backlog.slice(0, MAX_MUTATIONS_PER_FLUSH);
548
+ const remaining = backlog.slice(MAX_MUTATIONS_PER_FLUSH);
549
+ let capReason;
550
+ if (remaining.length > 0) {
551
+ capReason = "MAX_MUTATIONS";
552
+ diagnostics.droppedMutations += remaining.length;
553
+ }
554
+ const addedNodes = [];
555
+ const attrNames = [];
556
+ let nodeCount = 0;
557
+ let nodeCapped = false;
558
+ for (const m of mutationsToProcess) {
559
+ if (m.type === "childList") {
560
+ for (const n of Array.from(m.addedNodes)) {
561
+ if (nodeCount >= MAX_NODES_PER_FLUSH) {
562
+ nodeCapped = true;
563
+ break;
564
+ }
565
+ addedNodes.push(n);
566
+ nodeCount++;
567
+ }
568
+ if (nodeCapped) break;
569
+ continue;
570
+ }
571
+ if (m.type === "attributes") {
572
+ if (!runtime.observeAttributes) continue;
573
+ const name = m.attributeName;
574
+ if (!name) continue;
575
+ attrNames.push(name);
576
+ }
577
+ }
578
+ if (nodeCapped && !capReason) {
579
+ capReason = "MAX_NODES";
580
+ }
581
+ const keysFromNodes = scanKeysFromNodes(addedNodes);
582
+ const keysFromAttrs = /* @__PURE__ */ new Set();
583
+ for (const name of attrNames) {
584
+ if (name.startsWith("data-adlib-")) continue;
585
+ const key = attrNameToKey2(name);
586
+ if (key) keysFromAttrs.add(key);
587
+ }
588
+ let allKeys = Array.from(/* @__PURE__ */ new Set([...keysFromNodes, ...Array.from(keysFromAttrs)]));
589
+ if (allKeys.length > MAX_KEYS_PER_FLUSH) {
590
+ if (!capReason) capReason = "MAX_KEYS";
591
+ allKeys = allKeys.slice(0, MAX_KEYS_PER_FLUSH);
592
+ }
593
+ if (capReason) {
594
+ diagnostics.lastCapReason = capReason;
595
+ }
596
+ log("debug", "flush", {
597
+ processed: mutationsToProcess.length,
598
+ keys: allKeys,
599
+ ...capReason ? { capReason } : {}
600
+ });
601
+ backlog = remaining;
602
+ if (allKeys.length > 0) {
603
+ void (async () => {
604
+ for (const key of allKeys) {
605
+ try {
606
+ await runtime.load(key);
607
+ } catch {
608
+ }
609
+ }
610
+ })();
611
+ }
612
+ if (backlog.length > 0) {
613
+ scheduleFlush();
614
+ }
615
+ }
616
+ function scheduleFlush() {
617
+ if (flushScheduled) return;
618
+ flushScheduled = true;
619
+ scheduleMicrotask(flush);
620
+ }
621
+ function handleMutations(mutations) {
622
+ enqueue(mutations);
623
+ }
624
+ function desiredMode() {
625
+ return runtime.observeAttributes ? "nodes+attrs" : "nodes";
626
+ }
627
+ function connect(mode) {
628
+ if (typeof document === "undefined") return;
629
+ const root = document.body;
630
+ if (!root) return;
631
+ if (!observer) observer = new MutationObserver(handleMutations);
632
+ if (observing && lastMode === mode) return;
633
+ observer.disconnect();
634
+ const base = {
635
+ subtree: true,
636
+ childList: true
637
+ };
638
+ const opts = mode === "nodes+attrs" ? { ...base, attributes: true, attributeOldValue: false } : base;
639
+ observer.observe(root, opts);
640
+ observing = true;
641
+ lastMode = mode;
642
+ }
643
+ return {
644
+ isActive: () => observing,
645
+ ensureStarted: () => {
646
+ connect(desiredMode());
647
+ },
648
+ stop: () => {
649
+ if (!observer) return;
650
+ observer.disconnect();
651
+ observing = false;
652
+ lastMode = null;
653
+ flushScheduled = false;
654
+ backlog = [];
655
+ },
656
+ getDiagnostics: () => ({ ...diagnostics })
657
+ };
658
+ }
659
+
660
+ // src/attributes.ts
661
+ var ATTRIBUTES_ATTRIBUTE_PREFIX = "ad-attributes";
662
+ var ATTRIBUTE_KEYS = new Set(Object.values(de));
663
+ var isQueueTuple = (value) => Array.isArray(value);
664
+ var init = () => {
665
+ const { AdLibAttributes } = window;
666
+ const existingRuntime = AdLibAttributes && !Array.isArray(AdLibAttributes) ? AdLibAttributes : void 0;
667
+ const runtime = existingRuntime ?? {
668
+ version,
669
+ scripts: [],
670
+ config: {},
671
+ debug: false,
672
+ auto: false,
673
+ observeAttributes: false,
674
+ modules: {},
675
+ process: /* @__PURE__ */ new Set(),
676
+ utils: {
677
+ fetchPage: Po,
678
+ attachExternalStylesheets: xn
679
+ },
680
+ load: initAttribute,
681
+ async reload(key, options) {
682
+ const state = this.modules[key] ?? await this.load(key);
683
+ if (state.status === "ready") {
684
+ const inst = state.instance;
685
+ if (inst && typeof inst.restart === "function") {
686
+ try {
687
+ await inst.restart({ rescan: options?.rescan });
688
+ return state;
689
+ } catch {
690
+ state.destroy();
691
+ return await this.load(key);
692
+ }
693
+ }
694
+ }
695
+ state.destroy();
696
+ return await this.load(key);
697
+ },
698
+ push(...items) {
699
+ for (const item of items) {
700
+ const [rawKey, callback] = isQueueTuple(item) ? item : [item.key, item.cb];
701
+ const key = rawKey;
702
+ let state = this.modules[key];
703
+ if (state && (state.status === "ready" || state.status === "error")) {
704
+ callback(state);
705
+ continue;
706
+ }
707
+ if (!state || state.status !== "loading") {
708
+ this.load(key);
709
+ state = this.modules[key];
710
+ }
711
+ if (!state) continue;
712
+ if (state.promise) {
713
+ state.promise.then(() => callback(state)).catch(() => callback(state));
714
+ } else {
715
+ callback(state);
716
+ }
717
+ }
718
+ },
719
+ applyLoaderConfig: () => {
720
+ },
721
+ destroy(options) {
722
+ for (const solution in this.modules) {
723
+ this.modules[solution]?.destroy?.();
724
+ }
725
+ observerCtl.stop();
726
+ if (!options?.keepGlobal) {
727
+ return;
728
+ }
729
+ },
730
+ getState(key) {
731
+ if (!key) {
732
+ return this.modules;
733
+ }
734
+ return this.modules[key] ?? {
735
+ key,
736
+ status: "idle",
737
+ reload: (options) => this.reload(key, options),
738
+ destroy: () => {
739
+ this.process.delete(key);
740
+ }
741
+ };
742
+ },
743
+ getErrors() {
744
+ const errors = [];
745
+ for (const [key, state] of Object.entries(this.modules)) {
746
+ if (state?.status === "error" && state.error) {
747
+ errors.push({ key, error: state.error });
748
+ }
749
+ }
750
+ return errors;
751
+ },
752
+ isLoaded(key) {
753
+ return this.modules[key]?.status === "ready";
754
+ },
755
+ initFromScripts(source) {
756
+ const nextScripts = source?.scripts ?? [];
757
+ const seen = new Set(this.scripts);
758
+ for (const s of nextScripts) {
759
+ if (!seen.has(s)) {
760
+ seen.add(s);
761
+ this.scripts.push(s);
762
+ }
763
+ }
764
+ const scanned = scanRequestedKeysFromScripts(this.scripts);
765
+ const provided = source?.requestedKeys ?? [];
766
+ const requestedKeys2 = Array.from(/* @__PURE__ */ new Set([...provided, ...scanned]));
767
+ if (!this.auto) return;
768
+ void (async () => {
769
+ for (const key of requestedKeys2) {
770
+ try {
771
+ await this.load(key);
772
+ } catch {
773
+ }
774
+ }
775
+ })();
776
+ }
777
+ };
778
+ const observerCtl = runtime.observerCtl ?? createRuntimeObserverController(runtime);
779
+ runtime.observerCtl = observerCtl;
780
+ runtime.applyLoaderConfig = (patch) => {
781
+ const wasDebug = runtime.debug;
782
+ applyLoaderConfigCumulative(runtime, patch);
783
+ if (!wasDebug && runtime.debug) {
784
+ const ir3 = runtime;
785
+ if (!ir3.logger?.enabled) {
786
+ ir3.logger = createLogger({
787
+ enabled: true,
788
+ channels: ir3.debugChannels
789
+ });
790
+ }
791
+ attachRuntimeDevtools(runtime);
792
+ }
793
+ observerCtl.ensureStarted();
794
+ };
795
+ if (!existingRuntime) {
796
+ window.AdLibAttributes = runtime;
797
+ }
798
+ drainPreLoaderQueueIntoRuntime(runtime);
799
+ const scripts = discoverLoaderScripts(import.meta.url);
800
+ const { config, flags } = readLoaderConfigFromScripts(scripts);
801
+ const requestedKeys = scanRequestedKeysFromScripts(scripts);
802
+ const ir2 = runtime;
803
+ ir2.debugChannels = parseDebugChannels(flags.debugChannels);
804
+ runtime.applyLoaderConfig({
805
+ config,
806
+ debug: flags.debug,
807
+ auto: flags.auto,
808
+ observeAttributes: flags.observeAttributes
809
+ });
810
+ if (!ir2.logger) {
811
+ ir2.logger = createLogger({ enabled: false });
812
+ }
813
+ ir2.logger.info("runtime", "boot", {
814
+ version: runtime.version,
815
+ debug: runtime.debug,
816
+ auto: runtime.auto
817
+ });
818
+ ir2.logger.debug("loader", "scripts discovered", {
819
+ count: scripts.length,
820
+ keys: requestedKeys
821
+ });
822
+ runtime.initFromScripts({ scripts, requestedKeys });
823
+ initAttributes();
824
+ };
825
+ function bootstrapAttributesLoader() {
826
+ if (!isBrowser()) return;
827
+ onDOMReady(() => {
828
+ init();
829
+ });
830
+ }
831
+ var initAttributes = () => {
832
+ let autoLoad = false;
833
+ for (const script of window.AdLibAttributes.scripts) {
834
+ autoLoad ||= script.getAttribute(`${ATTRIBUTES_ATTRIBUTE_PREFIX}-auto`) === "true";
835
+ for (const key of ATTRIBUTE_KEYS) {
836
+ const isDefined = script.hasAttribute(`ad-${key}`);
837
+ if (!isDefined) continue;
838
+ initAttribute(key);
839
+ }
840
+ }
841
+ if (!autoLoad) return;
842
+ ir().then(() => {
843
+ const usedAttributes = /* @__PURE__ */ new Set();
844
+ const allElements = document.querySelectorAll("*");
845
+ for (const element of allElements) {
846
+ for (const name of element.getAttributeNames()) {
847
+ const adMatch = name.match(/^ad-([^-]+)/);
848
+ const key = adMatch?.[1];
849
+ if (key && ATTRIBUTE_KEYS.has(key)) {
850
+ usedAttributes.add(key);
851
+ }
852
+ }
853
+ }
854
+ for (const attribute of usedAttributes) {
855
+ initAttribute(attribute);
856
+ }
857
+ });
858
+ };
859
+ var initAttribute = async (key) => {
860
+ const isModuleKey = (k) => /^[a-z][a-z0-9-]*$/i.test(k);
861
+ const runtime = window.AdLibAttributes;
862
+ const state = runtime.modules[key] ??= {
863
+ key,
864
+ status: "idle",
865
+ reload: (options) => runtime.reload(key, options),
866
+ destroy: () => {
867
+ runtime.process.delete(key);
868
+ }
869
+ };
870
+ if (!isModuleKey(String(key))) {
871
+ const err = new AdLibRuntimeError({
872
+ code: "UNKNOWN_MODULE_KEY",
873
+ message: `Unknown module key: ${String(key)}`,
874
+ key
875
+ });
876
+ state.status = "error";
877
+ state.error = err;
878
+ emitRuntimeEvent("ad:module:error", { key, state, error: err });
879
+ return state;
880
+ }
881
+ if (runtime.process.has(key)) return state;
882
+ runtime.process.add(key);
883
+ state.status = "loading";
884
+ runtime.logger?.debug("module", `loading ${key}`, { key });
885
+ emitRuntimeEvent("ad:module:before", { key, state });
886
+ const loadPromise = (async () => {
887
+ let mod;
888
+ try {
889
+ mod = await loadAttribute(key);
890
+ } catch (err) {
891
+ runtime.logger?.error("module", `Failed to import module ${key}`, { key, cause: err });
892
+ const runtimeError = asRuntimeError(err, {
893
+ code: "MODULE_IMPORT_FAILED",
894
+ message: `Failed to import module ${key}`,
895
+ key,
896
+ meta: {}
897
+ });
898
+ state.status = "error";
899
+ state.error = runtimeError;
900
+ state.instance = void 0;
901
+ emitRuntimeEvent("ad:module:error", { key, state, error: runtimeError });
902
+ return void 0;
903
+ }
904
+ try {
905
+ const { init: init2 } = mod;
906
+ const { result, destroy } = await init2() || {};
907
+ state.instance = result;
908
+ state.status = "ready";
909
+ state.error = void 0;
910
+ emitRuntimeEvent("ad:module:after", { key, state });
911
+ state.destroy = () => {
912
+ try {
913
+ destroy?.();
914
+ runtime.process.delete(key);
915
+ state.status = "idle";
916
+ state.instance = void 0;
917
+ state.error = void 0;
918
+ state.promise = void 0;
919
+ } catch (err) {
920
+ runtime.logger?.error("module", `Failed to destroy module ${key}`, { key, cause: err });
921
+ const runtimeError = asRuntimeError(err, {
922
+ code: "MODULE_DESTROY_FAILED",
923
+ message: `Failed to destroy module ${key}`,
924
+ key,
925
+ meta: {}
926
+ });
927
+ state.status = "error";
928
+ state.error = runtimeError;
929
+ state.instance = void 0;
930
+ emitRuntimeEvent("ad:module:error", { key, state, error: runtimeError });
931
+ }
932
+ };
933
+ return result;
934
+ } catch (err) {
935
+ runtime.logger?.error("module", `Failed to init module ${key}`, { key, cause: err });
936
+ const runtimeError = asRuntimeError(err, {
937
+ code: "MODULE_INIT_FAILED",
938
+ message: `Failed to init module ${key}`,
939
+ key,
940
+ meta: {}
941
+ });
942
+ state.status = "error";
943
+ state.error = runtimeError;
944
+ state.instance = void 0;
945
+ emitRuntimeEvent("ad:module:error", { key, state, error: runtimeError });
946
+ return void 0;
947
+ }
948
+ })();
949
+ state.promise = loadPromise;
950
+ await loadPromise;
951
+ return state;
952
+ };
953
+ bootstrapAttributesLoader();
954
+ export {
955
+ bootstrapAttributesLoader
956
+ };
957
+ //# sourceMappingURL=attributes.js.map