elegance-js 2.1.36 → 3.0.0

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 (138) hide show
  1. package/bin/bootstrap.js +18 -0
  2. package/bin/run.js +2 -0
  3. package/dist/build/common.d.ts +147 -0
  4. package/dist/build/common.d.ts.map +1 -0
  5. package/dist/build/common.js +599 -0
  6. package/dist/build/dev.d.ts +2 -0
  7. package/dist/build/dev.d.ts.map +1 -0
  8. package/dist/build/dev.js +234 -0
  9. package/dist/build/prod.d.ts +2 -0
  10. package/dist/build/prod.d.ts.map +1 -0
  11. package/dist/build/prod.js +212 -0
  12. package/dist/build/render.d.ts +29 -0
  13. package/dist/build/render.d.ts.map +1 -0
  14. package/dist/build/render.js +234 -0
  15. package/dist/client.d.ts +13 -0
  16. package/dist/client.d.ts.map +1 -0
  17. package/dist/client.js +677 -0
  18. package/dist/config.d.ts +7 -0
  19. package/dist/config.d.ts.map +1 -0
  20. package/dist/config.js +80 -0
  21. package/dist/constants.d.ts +10 -0
  22. package/dist/constants.d.ts.map +1 -0
  23. package/dist/constants.js +20 -0
  24. package/dist/elements.d.ts +2 -0
  25. package/dist/elements.d.ts.map +1 -0
  26. package/dist/elements.js +14 -0
  27. package/dist/error.d.ts +20 -0
  28. package/dist/error.d.ts.map +1 -0
  29. package/dist/error.js +123 -0
  30. package/dist/globals.d.ts +6 -0
  31. package/dist/globals.d.ts.map +1 -0
  32. package/dist/globals.js +106 -0
  33. package/dist/logger.d.ts +32 -0
  34. package/dist/logger.d.ts.map +1 -0
  35. package/dist/logger.js +72 -0
  36. package/dist/page-tools.d.ts +19 -0
  37. package/dist/page-tools.d.ts.map +1 -0
  38. package/dist/page-tools.js +141 -0
  39. package/dist/processing/oxc.d.ts +17 -0
  40. package/dist/processing/oxc.d.ts.map +1 -0
  41. package/dist/processing/oxc.js +938 -0
  42. package/dist/processing/taglist.d.ts +2 -0
  43. package/dist/processing/taglist.d.ts.map +1 -0
  44. package/dist/processing/taglist.js +215 -0
  45. package/dist/processing/tsx.d.ts +2 -0
  46. package/dist/processing/tsx.d.ts.map +1 -0
  47. package/dist/processing/tsx.js +131 -0
  48. package/dist/run.d.ts +3 -0
  49. package/dist/run.d.ts.map +1 -0
  50. package/dist/run.js +147 -0
  51. package/dist/server/dev.d.ts +2 -0
  52. package/dist/server/dev.d.ts.map +1 -0
  53. package/dist/server/dev.js +10 -0
  54. package/dist/server/prod.d.ts +2 -0
  55. package/dist/server/prod.d.ts.map +1 -0
  56. package/dist/server/prod.js +42 -0
  57. package/dist/server/security.d.ts +64 -0
  58. package/dist/server/security.d.ts.map +1 -0
  59. package/dist/server/security.js +120 -0
  60. package/dist/server/server.d.ts +73 -99
  61. package/dist/server/server.d.ts.map +1 -0
  62. package/dist/server/server.js +830 -680
  63. package/dist/types/component.d.ts +85 -0
  64. package/dist/types/component.d.ts.map +1 -0
  65. package/dist/types/component.js +0 -0
  66. package/dist/types/config.d.ts +12 -0
  67. package/dist/types/config.d.ts.map +1 -0
  68. package/dist/types/config.js +0 -0
  69. package/dist/types/elements.d.ts +412 -0
  70. package/dist/types/elements.d.ts.map +1 -0
  71. package/dist/types/elements.js +0 -0
  72. package/dist/types/index.d.ts +9 -0
  73. package/dist/types/index.d.ts.map +1 -0
  74. package/dist/types/index.js +5 -0
  75. package/dist/types/jsx.d.ts +976 -0
  76. package/dist/types/jsx.d.ts.map +1 -0
  77. package/dist/types/jsx.js +0 -0
  78. package/dist/types/server-actions.d.ts +60 -0
  79. package/dist/types/server-actions.d.ts.map +1 -0
  80. package/dist/types/server-actions.js +0 -0
  81. package/dist/user-utils.d.ts +23 -0
  82. package/dist/user-utils.d.ts.map +1 -0
  83. package/dist/user-utils.js +61 -0
  84. package/package.json +47 -28
  85. package/README.md +0 -4
  86. package/dist/client/effect.d.ts +0 -27
  87. package/dist/client/effect.js +0 -37
  88. package/dist/client/eventListener.d.ts +0 -39
  89. package/dist/client/eventListener.js +0 -52
  90. package/dist/client/loadHook.d.ts +0 -34
  91. package/dist/client/loadHook.js +0 -52
  92. package/dist/client/observer.d.ts +0 -36
  93. package/dist/client/observer.js +0 -66
  94. package/dist/client/runtime.d.ts +0 -105
  95. package/dist/client/runtime.js +0 -624
  96. package/dist/client/state.d.ts +0 -40
  97. package/dist/client/state.js +0 -110
  98. package/dist/compilation/compiler.d.ts +0 -158
  99. package/dist/compilation/compiler.js +0 -1163
  100. package/dist/components/ClientComponent.d.ts +0 -22
  101. package/dist/components/ClientComponent.js +0 -55
  102. package/dist/components/Link.d.ts +0 -16
  103. package/dist/components/Link.js +0 -21
  104. package/dist/components/Portal.d.ts +0 -2
  105. package/dist/components/Portal.js +0 -2
  106. package/dist/elements/element.d.ts +0 -87
  107. package/dist/elements/element.js +0 -33
  108. package/dist/elements/element_list.d.ts +0 -7
  109. package/dist/elements/element_list.js +0 -65
  110. package/dist/elements/raw.d.ts +0 -14
  111. package/dist/elements/raw.js +0 -78
  112. package/dist/elements/specific_props.d.ts +0 -750
  113. package/dist/elements/specific_props.js +0 -1
  114. package/dist/global.d.ts +0 -229
  115. package/dist/global.js +0 -1
  116. package/dist/index.d.ts +0 -16
  117. package/dist/index.js +0 -12
  118. package/dist/server/layout.d.ts +0 -34
  119. package/dist/server/layout.js +0 -6
  120. package/dist/server/log.d.ts +0 -12
  121. package/dist/server/log.js +0 -64
  122. package/dist/server/page.d.ts +0 -32
  123. package/dist/server/page.js +0 -6
  124. package/dist/server/runtime.d.ts +0 -6
  125. package/dist/server/runtime.js +0 -86
  126. package/scripts/bootstrap.js +0 -95
  127. package/scripts/bootstrap_files/elegance.txt +0 -40
  128. package/scripts/bootstrap_files/index.txt +0 -3
  129. package/scripts/bootstrap_files/layout.txt +0 -46
  130. package/scripts/bootstrap_files/middleware.txt +0 -18
  131. package/scripts/bootstrap_files/page.txt +0 -123
  132. package/scripts/bootstrap_files/route.txt +0 -6
  133. package/scripts/elegance_dev.ts +0 -42
  134. package/scripts/elegance_prod.ts +0 -42
  135. package/scripts/elegance_static.ts +0 -26
  136. package/scripts/prod.js +0 -13
  137. package/scripts/run.js +0 -13
  138. package/scripts/static.js +0 -13
package/dist/client.js ADDED
@@ -0,0 +1,677 @@
1
+ {
2
+ const _s = document.querySelector('script[data-tag="iav"]');
3
+ if (_s) try {
4
+ globalThis.__initialAtomValues = JSON.parse(_s.textContent || "{}").atoms || {};
5
+ } catch {
6
+ }
7
+ }
8
+ const CHUNK_SIZE = 512;
9
+ let currentInst = null;
10
+ function atom(id, initial) {
11
+ let _v = initial;
12
+ const _L = /* @__PURE__ */ new Set();
13
+ const _C = /* @__PURE__ */ new Set();
14
+ const self = {
15
+ id,
16
+ get value() {
17
+ if (currentInst) {
18
+ _L.add(currentInst);
19
+ currentInst._deps.add(self);
20
+ }
21
+ return _v;
22
+ },
23
+ set value(n) {
24
+ if (!Object.is(_v, n)) {
25
+ _v = n;
26
+ _L.forEach((c) => c._markDirty());
27
+ _C.forEach((c) => c(n));
28
+ }
29
+ },
30
+ _removeListener(c) {
31
+ _L.delete(c);
32
+ },
33
+ _addUserCallback(c) {
34
+ _C.add(c);
35
+ },
36
+ _removeUserCallback(c) {
37
+ _C.delete(c);
38
+ }
39
+ };
40
+ return self;
41
+ }
42
+ const atomRegistry = /* @__PURE__ */ new Map();
43
+ function _getAtom(id, initial) {
44
+ if (atomRegistry.has(id)) return atomRegistry.get(id);
45
+ const sv = globalThis.__initialAtomValues?.[id];
46
+ const a = atom(id, sv !== void 0 ? sv : initial);
47
+ atomRegistry.set(id, a);
48
+ return a;
49
+ }
50
+ const track = (a, cb) => a._addUserCallback(cb);
51
+ const untrack = (a, cb) => a._removeUserCallback(cb);
52
+ const componentConfigs = /* @__PURE__ */ new Map();
53
+ const instanceMap = /* @__PURE__ */ new Map();
54
+ const rootInstanceIds = {};
55
+ const view = (fn) => fn;
56
+ ;
57
+ function component(cfg) {
58
+ const { __id, view: viewFn } = cfg;
59
+ if (!viewFn) {
60
+ console.error(`Component "${__id}": did not provide a view() method.`);
61
+ return;
62
+ }
63
+ componentConfigs.set(__id, cfg);
64
+ return (props, children) => {
65
+ const counters = currentInst ? currentInst._childCounters ??= {} : rootInstanceIds;
66
+ const idx = counters[__id] ?? 0;
67
+ counters[__id] = idx + 1;
68
+ return {
69
+ __type: "live",
70
+ __componentId: __id,
71
+ __instanceId: `${__id}#${idx}`,
72
+ props: props ?? {},
73
+ children
74
+ };
75
+ };
76
+ }
77
+ const rawHTML = (content) => ({ content, __rawHTML: true });
78
+ const pageLoadCallbacks = [];
79
+ const cleanupFns = /* @__PURE__ */ new Map();
80
+ let navigationCallbacks = [];
81
+ const onPageLoad = (cb, options = {}) => pageLoadCallbacks.push({ pathname: location.pathname, cb, options });
82
+ function runPageCleanup() {
83
+ for (const [scope, fns] of cleanupFns) {
84
+ if (!location.pathname.startsWith(scope)) {
85
+ fns.forEach((f) => f());
86
+ cleanupFns.delete(scope);
87
+ }
88
+ }
89
+ }
90
+ function runPageCallbacks() {
91
+ const current = location.pathname;
92
+ for (const { pathname, cb, options } of pageLoadCallbacks) {
93
+ const scoped = options?.type === "scoped";
94
+ const unscoped = !options?.type || options.type === "unscoped";
95
+ if (unscoped) {
96
+ const cleanup2 = cb();
97
+ if (typeof cleanup2 === "function") cleanupFns.get("/")?.push(cleanup2);
98
+ continue;
99
+ }
100
+ const scope = scoped ? pathname.slice(0, pathname.lastIndexOf("/")) || "/" : pathname;
101
+ if (!current.startsWith(scope)) continue;
102
+ if (scoped && cleanupFns.has(scope)) continue;
103
+ if (!cleanupFns.has(scope)) cleanupFns.set(scope, []);
104
+ const cleanup = cb();
105
+ if (typeof cleanup === "function") cleanupFns.get(scope).push(cleanup);
106
+ }
107
+ }
108
+ const delegatedHandlers = /* @__PURE__ */ new WeakMap();
109
+ function _delegatedListener(e) {
110
+ let target = e.target;
111
+ while (target && target instanceof Element) {
112
+ const meta = delegatedHandlers.get(target);
113
+ if (meta?.handlers[e.type]) {
114
+ Object.defineProperties(e, {
115
+ currentTarget: { configurable: true, value: target },
116
+ target: { configurable: true, value: target },
117
+ delegateTarget: { configurable: true, value: target }
118
+ });
119
+ meta.handlers[e.type].call(target, meta.inst?._self ?? null, e);
120
+ return;
121
+ }
122
+ target = target.parentElement;
123
+ }
124
+ }
125
+ const _registeredEventTypes = /* @__PURE__ */ new Set();
126
+ function ensureEventDelegated(eventType) {
127
+ if (_registeredEventTypes.has(eventType)) return;
128
+ _registeredEventTypes.add(eventType);
129
+ document.addEventListener(eventType, _delegatedListener, true);
130
+ }
131
+ for (const et of [
132
+ "click",
133
+ "input",
134
+ "change",
135
+ "submit",
136
+ "keydown",
137
+ "keyup",
138
+ "mousemove",
139
+ "mousedown",
140
+ "mouseup",
141
+ "mouseenter",
142
+ "mouseleave",
143
+ "mouseover",
144
+ "mouseout",
145
+ "focus",
146
+ "blur",
147
+ "pointerdown",
148
+ "pointerup",
149
+ "pointermove"
150
+ ]) {
151
+ ensureEventDelegated(et);
152
+ }
153
+ function applyOptions(el, options, owner, isHydrate = false) {
154
+ for (let [k, v] of Object.entries(options)) {
155
+ if (k === "className") k = "class";
156
+ if (k === "key") continue;
157
+ if (k.startsWith("on") && typeof v === "function") {
158
+ let m = delegatedHandlers.get(el);
159
+ if (!m) delegatedHandlers.set(el, m = { inst: owner, handlers: {} });
160
+ else m.inst = owner;
161
+ const eventType = k.slice(2).toLowerCase();
162
+ ensureEventDelegated(eventType);
163
+ m.handlers[eventType] = v;
164
+ } else if (!isHydrate) {
165
+ if (typeof v === "boolean") el.toggleAttribute(k, v);
166
+ else if (v !== "false") {
167
+ const s = String(v);
168
+ if (el.getAttribute(k) !== s) el.setAttribute(k, s);
169
+ }
170
+ }
171
+ }
172
+ }
173
+ function getVKey(vn) {
174
+ if (vn == null || typeof vn !== "object") return null;
175
+ if (vn.__type === "element" && vn.options?.key != null) return String(vn.options.key);
176
+ if (vn.__type === "live" && vn.props?.key != null) return String(vn.props.key);
177
+ return null;
178
+ }
179
+ function vnodeToDom(node, owner) {
180
+ if (typeof node === "string" || typeof node === "number") return document.createTextNode(String(node));
181
+ if (node === null || node === false || node === void 0) return document.createTextNode("");
182
+ if (node.__rawHTML) return document.createRange().createContextualFragment(node.content).firstElementChild;
183
+ if (node.__type === "element") {
184
+ const el = document.createElement(node.tag);
185
+ const k = getVKey(node);
186
+ if (k !== null) el.__vkey = k;
187
+ applyOptions(el, node.options ?? {}, owner, false);
188
+ for (const child of node.children ?? []) el.appendChild(vnodeToDom(child, owner));
189
+ return el;
190
+ }
191
+ if (node.__type === "live") return mount(node);
192
+ return document.createDocumentFragment();
193
+ }
194
+ function patchChildren(el, vc, owner) {
195
+ const hasKeys = vc.some((c) => getVKey(c) !== null);
196
+ if (hasKeys) {
197
+ const keyedDom = /* @__PURE__ */ new Map();
198
+ for (const child of Array.from(el.childNodes)) {
199
+ const k = child.__vkey;
200
+ if (k != null) keyedDom.set(k, child);
201
+ }
202
+ const newChildren = [];
203
+ for (const vchild of vc) {
204
+ const k = getVKey(vchild);
205
+ if (k !== null && keyedDom.has(k)) {
206
+ const existing = keyedDom.get(k);
207
+ keyedDom.delete(k);
208
+ newChildren.push(patch(existing, vchild, owner));
209
+ } else {
210
+ const fresh = vnodeToDom(vchild, owner);
211
+ if (k !== null) fresh.__vkey = k;
212
+ newChildren.push(fresh);
213
+ }
214
+ }
215
+ for (const stale of keyedDom.values()) stale.__instance?._destroy();
216
+ for (let i = 0; i < newChildren.length; i++) {
217
+ const desired = newChildren[i];
218
+ const current = el.childNodes[i] ?? null;
219
+ if (current !== desired) el.insertBefore(desired, current);
220
+ }
221
+ while (el.childNodes.length > newChildren.length) {
222
+ const last = el.lastChild;
223
+ last.__instance?._destroy();
224
+ el.removeChild(last);
225
+ }
226
+ } else {
227
+ const dc = Array.from(el.childNodes);
228
+ const common = Math.min(dc.length, vc.length);
229
+ for (let i = 0; i < common; i++) patch(dc[i], vc[i], owner);
230
+ for (let i = common; i < vc.length; i++) el.appendChild(vnodeToDom(vc[i], owner));
231
+ for (let i = dc.length - 1; i >= vc.length; i--) {
232
+ dc[i].__instance?._destroy();
233
+ el.removeChild(dc[i]);
234
+ }
235
+ }
236
+ }
237
+ function patch(dom, vn, owner) {
238
+ if (vn === null || vn === false) {
239
+ if (dom.nodeType === Node.TEXT_NODE && dom.nodeValue === "") return dom;
240
+ const t = document.createTextNode("");
241
+ dom.__instance?._destroy();
242
+ dom.parentNode?.replaceChild(t, dom);
243
+ return t;
244
+ }
245
+ if (typeof vn === "string" || typeof vn === "number") {
246
+ const s = String(vn);
247
+ if (dom.nodeType === Node.TEXT_NODE) {
248
+ if (dom.nodeValue !== s) dom.nodeValue = s;
249
+ return dom;
250
+ }
251
+ const t = document.createTextNode(s);
252
+ dom.parentNode?.replaceChild(t, dom);
253
+ return t;
254
+ }
255
+ if (vn.__rawHTML) return document.createRange().createContextualFragment(vn.content).firstElementChild;
256
+ if (vn.__type === "element") {
257
+ if (dom.nodeType === Node.ELEMENT_NODE && dom.tagName.toLowerCase() === vn.tag) {
258
+ const el = dom;
259
+ const normOptions = {};
260
+ for (const [k2, v] of Object.entries(vn.options ?? {})) normOptions[k2 === "className" ? "class" : k2] = v;
261
+ const k = getVKey(vn);
262
+ if (k !== null) el.__vkey = k;
263
+ for (const name of el.getAttributeNames()) if (!(name in normOptions)) el.removeAttribute(name);
264
+ applyOptions(el, normOptions, owner, false);
265
+ patchChildren(el, vn.children ?? [], owner);
266
+ return el;
267
+ }
268
+ const fresh = vnodeToDom(vn, owner);
269
+ dom.parentNode?.replaceChild(fresh, dom);
270
+ return fresh;
271
+ }
272
+ if (vn.__type === "live") {
273
+ const ex = instanceMap.get(vn.__componentId + "::" + vn.__instanceId);
274
+ if (ex?.root === dom) {
275
+ ex.props = vn.props;
276
+ ex.children = vn.children ?? [];
277
+ ex._markDirty();
278
+ return dom;
279
+ }
280
+ const old = dom.__instance;
281
+ const rendered = mount(vn);
282
+ dom.parentNode?.replaceChild(rendered, dom);
283
+ old?._destroy();
284
+ return rendered;
285
+ }
286
+ return dom;
287
+ }
288
+ const flatten = (a) => a.flat(Infinity).filter((c) => c != null && c !== false && c !== "");
289
+ function hydrateTree(vn, dom, owner) {
290
+ if (vn == null || vn === false || dom.nodeType === Node.TEXT_NODE || vn.__rawHTML) return;
291
+ if (Array.isArray(vn)) {
292
+ const flat = flatten(vn);
293
+ const dc = significantChildren(dom);
294
+ for (let i = 0; i < Math.min(flat.length, dc.length); i++) hydrateTree(flat[i], dc[i], owner);
295
+ return;
296
+ }
297
+ if (vn.__type === "element") {
298
+ applyOptions(dom, vn.options ?? {}, owner, true);
299
+ const dc = significantChildren(dom);
300
+ const vc = flatten(vn.children ?? []);
301
+ for (let i = 0; i < Math.min(dc.length, vc.length); i++) hydrateTree(vc[i], dc[i], owner);
302
+ return;
303
+ }
304
+ if (vn.__type === "live") bootstrapComponent(vn, dom);
305
+ }
306
+ function bootstrapComponent(desc, existingDom) {
307
+ const cid = desc.__componentId;
308
+ const instanceId = desc.__instanceId;
309
+ const cfg = componentConfigs.get(cid);
310
+ if (!cfg) return existingDom ?? document.createDocumentFragment();
311
+ const existing = instanceMap.get(instanceId);
312
+ if (existing && existingDom) {
313
+ existing.props = desc.props ?? {};
314
+ existing.children = desc.children ?? [];
315
+ existing.config = cfg;
316
+ existingDom.parentNode?.replaceChild(existing.root, existingDom);
317
+ existing._markDirty();
318
+ return existing;
319
+ }
320
+ const atomsObj = {};
321
+ if (cfg.atoms) for (const key in cfg.atoms) atomsObj[key] = _getAtom(`${cid}:${key}`, cfg.atoms[key]);
322
+ let inst;
323
+ const self = { get props() {
324
+ return inst.props;
325
+ }, get children() {
326
+ return inst.children;
327
+ } };
328
+ inst = {
329
+ cid,
330
+ instanceId,
331
+ config: cfg,
332
+ props: desc.props ?? {},
333
+ children: desc.children ?? [],
334
+ _deps: /* @__PURE__ */ new Set(),
335
+ _scheduled: false,
336
+ _self: self,
337
+ _atoms: atomsObj,
338
+ _navigationCallback: null,
339
+ root: existingDom || null,
340
+ _childCounters: {},
341
+ _markDirty() {
342
+ if (this._scheduled) return;
343
+ this._scheduled = true;
344
+ queueMicrotask(() => {
345
+ this._scheduled = false;
346
+ const vn2 = execView(this);
347
+ if (vn2 && typeof vn2 === "object" && (vn2.__type === "element" || vn2.__type === "live"))
348
+ this.root = patch(this.root, vn2, this);
349
+ });
350
+ },
351
+ _destroy() {
352
+ inst._onMountCleanup?.();
353
+ inst._onNavigateCleanup?.();
354
+ if (inst._navigationCallback)
355
+ navigationCallbacks.splice(navigationCallbacks.indexOf(inst._navigationCallback), 1);
356
+ cfg.onUnmount?.(self, atomsObj);
357
+ instanceMap.delete(instanceId);
358
+ for (const a of inst._deps) a._removeListener(inst);
359
+ inst._deps.clear();
360
+ inst.root?.remove();
361
+ }
362
+ };
363
+ instanceMap.set(instanceId, inst);
364
+ cfg.init?.(self, atomsObj);
365
+ const vn = execView(inst);
366
+ if (existingDom) {
367
+ hydrateTree(vn, existingDom, inst);
368
+ inst.root = existingDom;
369
+ existingDom.__instance = inst;
370
+ } else {
371
+ const dom = vnodeToDom(vn, inst);
372
+ inst.root = dom instanceof Element ? dom : document.createElement("div");
373
+ inst.root.__instance = inst;
374
+ }
375
+ if (cfg.onMount || cfg.onNavigate) queueMicrotask(() => {
376
+ const cleanup = cfg?.onMount?.(self, atomsObj);
377
+ if (typeof cleanup === "function") inst._onMountCleanup = cleanup;
378
+ const navigationCallback = () => {
379
+ if (typeof inst._onNavigateCleanup === "function") inst._onNavigateCleanup();
380
+ const cleanup2 = cfg?.onNavigate?.(self, atomsObj);
381
+ if (typeof cleanup2 === "function") inst._onNavigateCleanup = cleanup2;
382
+ };
383
+ inst._navigationCallback = navigationCallback;
384
+ navigationCallbacks.push(navigationCallback);
385
+ navigationCallback();
386
+ });
387
+ return inst;
388
+ }
389
+ function mount(desc) {
390
+ return bootstrapComponent(desc).root;
391
+ }
392
+ function execView(inst) {
393
+ inst._childCounters = {};
394
+ currentInst = inst;
395
+ for (const a of inst._deps) a._removeListener(inst);
396
+ inst._deps.clear();
397
+ try {
398
+ return inst.config.view({ self: inst._self, atoms: inst._atoms, children: inst.children });
399
+ } finally {
400
+ currentInst = null;
401
+ }
402
+ }
403
+ globalThis.__tags = new Proxy({}, {
404
+ get(_, tag) {
405
+ return (options, ...children) => {
406
+ const isOptions = options !== null && typeof options === "object" && !Array.isArray(options) && !options?.__type;
407
+ const kids = (isOptions ? children : [options, ...children]).flat(Infinity);
408
+ const merged = [];
409
+ for (const child of kids) {
410
+ if ((typeof child === "string" || typeof child === "number") && (typeof merged[merged.length - 1] === "string" || typeof merged[merged.length - 1] === "number")) {
411
+ merged[merged.length - 1] = String(merged[merged.length - 1]) + String(child);
412
+ } else {
413
+ merged.push(child);
414
+ }
415
+ }
416
+ return { __type: "element", tag, options: isOptions ? options : {}, children: merged };
417
+ };
418
+ }
419
+ });
420
+ const importBundle = (tag) => {
421
+ if (tag.src) return import(tag.src);
422
+ const blobCode = tag.textContent.replace(
423
+ /(['"])\/chunks\//g,
424
+ `$1${location.origin}/chunks/`
425
+ );
426
+ const blob = new Blob([blobCode], { type: "text/javascript" });
427
+ const url = URL.createObjectURL(blob);
428
+ return import(url);
429
+ };
430
+ async function drainBootstrapQueue(queue) {
431
+ let i = 0;
432
+ while (i < queue.length) {
433
+ const end = Math.min(i + CHUNK_SIZE, queue.length);
434
+ for (; i < end; i++) bootstrapComponent(queue[i].desc, queue[i].dom);
435
+ if (i < queue.length) await new Promise((r) => requestIdleCallback(r));
436
+ }
437
+ }
438
+ async function hydrateWithRegions(regions, handlers) {
439
+ const queue = [];
440
+ const instanceCounters = {};
441
+ for (const marker of document.body.querySelectorAll("template[data-region]")) {
442
+ const regionIdx = parseInt(marker.getAttribute("data-region"), 10);
443
+ if (isNaN(regionIdx)) continue;
444
+ const entries = regions[regionIdx];
445
+ if (!entries?.length) {
446
+ continue;
447
+ }
448
+ let sibling = marker.nextSibling;
449
+ for (const entry of entries) {
450
+ const cid = entry.__cid ?? entry.__componentId;
451
+ const count = entry.count ?? 1;
452
+ const props = entry.props ?? {};
453
+ for (let i = 0; i < count; i++) {
454
+ while (sibling?.nodeType === Node.TEXT_NODE && !(sibling.nodeValue ?? "").trim())
455
+ sibling = sibling.nextSibling;
456
+ const idx = instanceCounters[cid] ?? 0;
457
+ instanceCounters[cid] = idx + 1;
458
+ const syntheticDesc = { __type: "live", __componentId: cid, __instanceId: `${cid}#${idx}`, props };
459
+ if (sibling !== null) {
460
+ queue.push({ desc: syntheticDesc, dom: sibling });
461
+ sibling = sibling.nextSibling;
462
+ } else {
463
+ marker.parentNode?.insertBefore(mount(syntheticDesc), marker.nextSibling);
464
+ }
465
+ }
466
+ }
467
+ }
468
+ await drainBootstrapQueue(queue);
469
+ if (handlers) {
470
+ for (const { eid, h } of handlers) {
471
+ for (const { event } of h) ensureEventDelegated(event);
472
+ for (const el of document.querySelectorAll(`[e-id="${eid}"]`)) {
473
+ let m = delegatedHandlers.get(el);
474
+ if (!m) delegatedHandlers.set(el, m = { inst: null, handlers: {} });
475
+ for (const { event, fn } of h) {
476
+ if (typeof fn === "function") m.handlers[event] = fn;
477
+ }
478
+ }
479
+ }
480
+ }
481
+ }
482
+ function significantChildren(el) {
483
+ return Array.from(el.childNodes).filter(
484
+ (n) => !(n.nodeType === Node.TEXT_NODE && !(n.nodeValue ?? "").trim())
485
+ );
486
+ }
487
+ function detachNode(node) {
488
+ if (node.nodeType === Node.ELEMENT_NODE)
489
+ for (const child of Array.from(node.childNodes)) detachNode(child);
490
+ const inst = node.__instance;
491
+ if (inst) {
492
+ inst._destroy();
493
+ } else {
494
+ node.parentNode?.removeChild(node);
495
+ }
496
+ }
497
+ function syncOptions(from, to) {
498
+ const next = new Set(to.getAttributeNames());
499
+ for (const a of from.getAttributeNames()) if (!next.has(a)) from.removeAttribute(a);
500
+ for (const a of to.getAttributeNames()) {
501
+ const v = to.getAttribute(a);
502
+ if (from.getAttribute(a) !== v) from.setAttribute(a, v);
503
+ }
504
+ }
505
+ function morphKids(parent, incoming) {
506
+ const existing = significantChildren(parent);
507
+ const wanted = significantChildren(incoming);
508
+ const len = Math.max(existing.length, wanted.length);
509
+ for (let i = 0; i < len; i++) {
510
+ const cur = existing[i];
511
+ const want = wanted[i];
512
+ if (!want) {
513
+ detachNode(cur);
514
+ } else if (!cur) {
515
+ parent.appendChild(want.cloneNode(true));
516
+ } else if (cur.nodeType === Node.ELEMENT_NODE && want.nodeType === Node.ELEMENT_NODE && cur.tagName === want.tagName) {
517
+ const inst = cur.__instance;
518
+ if (!inst) {
519
+ syncOptions(cur, want);
520
+ morphKids(cur, want);
521
+ }
522
+ } else {
523
+ const inst = cur.__instance;
524
+ if (inst) {
525
+ inst._destroy();
526
+ } else {
527
+ parent.replaceChild(want.cloneNode(true), cur);
528
+ }
529
+ }
530
+ }
531
+ }
532
+ function patchHead(newHead) {
533
+ const newTitle = newHead.querySelector("title");
534
+ if (newTitle) {
535
+ let t = document.head.querySelector("title");
536
+ if (!t) {
537
+ t = document.createElement("title");
538
+ document.head.appendChild(t);
539
+ }
540
+ if (t.textContent !== newTitle.textContent) t.textContent = newTitle.textContent;
541
+ }
542
+ for (const nm of newHead.querySelectorAll("meta")) {
543
+ const name = nm.getAttribute("name");
544
+ const property = nm.getAttribute("property");
545
+ const equiv = nm.getAttribute("http-equiv");
546
+ const charset = nm.getAttribute("charset");
547
+ const sel = name ? `meta[name="${name}"]` : property ? `meta[property="${property}"]` : equiv ? `meta[http-equiv="${equiv}"]` : charset ? "meta[charset]" : null;
548
+ const existing = sel && document.head.querySelector(sel);
549
+ if (existing) {
550
+ for (const attr of nm.getAttributeNames()) existing.setAttribute(attr, nm.getAttribute(attr));
551
+ } else {
552
+ document.head.appendChild(nm.cloneNode(true));
553
+ }
554
+ }
555
+ const existingHrefs = new Set(
556
+ [...document.head.querySelectorAll("link[rel='stylesheet']")].map((l) => l.href)
557
+ );
558
+ for (const nl of newHead.querySelectorAll("link[rel='stylesheet']")) {
559
+ if (!existingHrefs.has(nl.href)) document.head.appendChild(nl.cloneNode(true));
560
+ }
561
+ const existingSrcs = new Set(
562
+ [...document.head.querySelectorAll("script[src]")].map((s) => s.src)
563
+ );
564
+ for (const ns of newHead.querySelectorAll("script[src]")) {
565
+ if (ns.getAttribute("data-bundle") === "true") continue;
566
+ if (existingSrcs.has(ns.src)) continue;
567
+ const s = document.createElement("script");
568
+ for (const attr of ns.getAttributeNames()) s.setAttribute(attr, ns.getAttribute(attr));
569
+ document.head.appendChild(s);
570
+ }
571
+ }
572
+ async function loadPage(url, regions, handlers, doc) {
573
+ if (!doc) {
574
+ doc = new DOMParser().parseFromString(
575
+ await (await fetch(url, { headers: { Accept: "text/html" } })).text(),
576
+ "text/html"
577
+ );
578
+ }
579
+ const hyd = doc.querySelector('script[data-tag="hydration"]');
580
+ if (hyd) try {
581
+ globalThis.__initialAtomValues = JSON.parse(hyd.textContent || "{}").atoms || {};
582
+ } catch {
583
+ }
584
+ patchHead(doc.head);
585
+ syncOptions(document.body, doc.body);
586
+ morphKids(document.body, doc.body);
587
+ await hydrateWithRegions(regions, handlers);
588
+ }
589
+ function scroll() {
590
+ if (location.hash) {
591
+ const el = document.querySelector(location.hash);
592
+ el?.scrollIntoView();
593
+ } else {
594
+ scrollTo(0, 0);
595
+ }
596
+ }
597
+ async function navigate(url, push = true) {
598
+ const { pathname } = new URL(url, location.href);
599
+ if (push && pathname === location.pathname) {
600
+ scroll();
601
+ return;
602
+ }
603
+ ;
604
+ if (push) history.pushState(null, "", url);
605
+ const bundleSelector = `script[data-bundle="true"][data-pathname="${pathname}"]`;
606
+ const localTag = document.querySelector(bundleSelector);
607
+ let mod;
608
+ let fetchedDoc;
609
+ if (localTag) {
610
+ mod = await importBundle(localTag);
611
+ } else {
612
+ const html = await (await fetch(url, { headers: { Accept: "text/html" } })).text();
613
+ fetchedDoc = new DOMParser().parseFromString(html, "text/html");
614
+ const remoteTag = fetchedDoc.querySelector(bundleSelector);
615
+ if (remoteTag) {
616
+ mod = await importBundle(remoteTag);
617
+ } else {
618
+ const bundlePath = (pathname === "/" ? "" : pathname) + "/bundle.js";
619
+ try {
620
+ mod = await import(bundlePath);
621
+ } catch {
622
+ console.error("navigate: no bundle found for this pathname.");
623
+ return;
624
+ }
625
+ }
626
+ }
627
+ runPageCleanup();
628
+ const result = (mod.default ?? (() => null))();
629
+ if (!Array.isArray(result?.regions)) {
630
+ console.error("navigate: target is not an Elegance page.");
631
+ return;
632
+ }
633
+ await loadPage(url, result.regions, result.handlers, fetchedDoc);
634
+ runPageCallbacks();
635
+ navigationCallbacks.forEach((f) => f());
636
+ scroll();
637
+ }
638
+ async function hydrate() {
639
+ const bundleTag = document.querySelector(
640
+ `script[data-bundle="true"][data-pathname="${location.pathname}"]`
641
+ );
642
+ if (!bundleTag) return;
643
+ const result = ((await importBundle(bundleTag)).default || (() => null))();
644
+ if (!Array.isArray(result?.regions)) return;
645
+ await hydrateWithRegions(result.regions, result.handlers);
646
+ runPageCallbacks();
647
+ scroll();
648
+ window.addEventListener("beforeunload", () => runPageCleanup());
649
+ }
650
+ window.addEventListener("popstate", () => navigate(location.pathname + location.search + location.hash, false));
651
+ async function _action(target, params) {
652
+ const targetURL = `${location.origin}/__action`;
653
+ const res = await fetch(targetURL, {
654
+ method: "POST",
655
+ body: JSON.stringify(params ?? {}),
656
+ headers: {
657
+ "Content-Type": "application/json",
658
+ "Elegance-Action": target
659
+ }
660
+ });
661
+ if (!res.ok) {
662
+ return null;
663
+ }
664
+ const resJSON = await res.json();
665
+ return resJSON;
666
+ }
667
+ Object.assign(globalThis, { view, component, onPageLoad, track, untrack, navigate, rawHTML, _getAtom, _action });
668
+ requestAnimationFrame(() => hydrate());
669
+ {
670
+ const source = new EventSource(`http://${location.hostname}:4000/__reload`);
671
+ source.onmessage = (msg) => {
672
+ if (msg.data === "connected") return;
673
+ window.location.reload();
674
+ };
675
+ source.onerror = () => {
676
+ };
677
+ }
@@ -0,0 +1,7 @@
1
+ type DeepRequired<T> = {
2
+ [P in keyof T]-?: T[P] extends (...args: any[]) => any ? T[P] : T[P] extends object ? DeepRequired<NonNullable<T[P]>> : NonNullable<T[P]>;
3
+ };
4
+ type SafeEleganceConfig = DeepRequired<EleganceConfig>;
5
+ export declare function getConfig(): Promise<SafeEleganceConfig>;
6
+ export {};
7
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA,KAAK,YAAY,CAAC,CAAC,IAAI;KAClB,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAChD,CAAC,CAAC,CAAC,CAAC,GACJ,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GACf,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC/B,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9B,CAAC;AAEF,KAAK,kBAAkB,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;AAiGvD,wBAAsB,SAAS,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAM7D"}