jails.stdlib 1.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 (101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -0
  3. package/build.js +34 -0
  4. package/cancelable/README.md +41 -0
  5. package/cancelable/index.d.ts +1 -0
  6. package/cancelable/index.js +16 -0
  7. package/cancelable/index.ts +18 -0
  8. package/cancelable/index.umd.js +1 -0
  9. package/debounce/README.md +21 -0
  10. package/debounce/index.d.ts +1 -0
  11. package/debounce/index.js +11 -0
  12. package/debounce/index.ts +8 -0
  13. package/debounce/index.umd.js +1 -0
  14. package/delay/README.md +17 -0
  15. package/delay/index.d.ts +1 -0
  16. package/delay/index.js +6 -0
  17. package/delay/index.ts +6 -0
  18. package/delay/index.umd.js +1 -0
  19. package/form-validation/index.d.ts +18 -0
  20. package/form-validation/index.js +119 -0
  21. package/form-validation/index.ts +198 -0
  22. package/form-validation/index.umd.js +1 -0
  23. package/form-validation/readme.md +117 -0
  24. package/import-css/README.md +22 -0
  25. package/import-css/index.d.ts +1 -0
  26. package/import-css/index.js +7 -0
  27. package/import-css/index.ts +11 -0
  28. package/import-css/index.umd.js +1 -0
  29. package/import-html/README.md +18 -0
  30. package/import-html/index.d.ts +4 -0
  31. package/import-html/index.js +4 -0
  32. package/import-html/index.ts +4 -0
  33. package/import-html/index.umd.js +1 -0
  34. package/import-js/README.md +22 -0
  35. package/import-js/index.d.ts +5 -0
  36. package/import-js/index.js +7 -0
  37. package/import-js/index.ts +15 -0
  38. package/import-js/index.umd.js +1 -0
  39. package/is-touch/README.md +18 -0
  40. package/is-touch/index.d.ts +1 -0
  41. package/is-touch/index.js +4 -0
  42. package/is-touch/index.ts +4 -0
  43. package/is-touch/index.umd.js +1 -0
  44. package/is-visible/README.md +24 -0
  45. package/is-visible/index.d.ts +7 -0
  46. package/is-visible/index.js +11 -0
  47. package/is-visible/index.ts +20 -0
  48. package/is-visible/index.umd.js +1 -0
  49. package/lazyload-image/README.md +28 -0
  50. package/lazyload-image/index.d.ts +1 -0
  51. package/lazyload-image/index.js +235 -0
  52. package/lazyload-image/index.ts +3 -0
  53. package/lazyload-image/index.umd.js +1 -0
  54. package/messenger/README.md +109 -0
  55. package/messenger/index.d.ts +9 -0
  56. package/messenger/index.js +39 -0
  57. package/messenger/index.ts +38 -0
  58. package/messenger/index.umd.js +1 -0
  59. package/mfe/README.md +90 -0
  60. package/mfe/index.d.ts +11 -0
  61. package/mfe/index.js +99 -0
  62. package/mfe/index.ts +141 -0
  63. package/mfe/index.umd.js +1 -0
  64. package/outlet/README.md +46 -0
  65. package/outlet/index.d.ts +6 -0
  66. package/outlet/index.js +550 -0
  67. package/outlet/index.ts +101 -0
  68. package/outlet/index.umd.js +1 -0
  69. package/package.json +25 -0
  70. package/querystring/README.md +19 -0
  71. package/querystring/index.d.ts +1 -0
  72. package/querystring/index.js +9 -0
  73. package/querystring/index.ts +9 -0
  74. package/querystring/index.umd.js +1 -0
  75. package/router/README.md +23 -0
  76. package/router/index.d.ts +1 -0
  77. package/router/index.js +134 -0
  78. package/router/index.ts +3 -0
  79. package/router/index.umd.js +1 -0
  80. package/storage/README.md +34 -0
  81. package/storage/index.d.ts +12 -0
  82. package/storage/index.js +39 -0
  83. package/storage/index.ts +45 -0
  84. package/storage/index.umd.js +1 -0
  85. package/store/README.md +44 -0
  86. package/store/index.d.ts +1 -0
  87. package/store/index.js +50 -0
  88. package/store/index.ts +1 -0
  89. package/store/index.umd.js +1 -0
  90. package/third-party/README.md +44 -0
  91. package/third-party/index.d.ts +8 -0
  92. package/third-party/index.js +15 -0
  93. package/third-party/index.ts +30 -0
  94. package/third-party/index.umd.js +1 -0
  95. package/throttle/README.md +21 -0
  96. package/throttle/index.d.ts +1 -0
  97. package/throttle/index.js +9 -0
  98. package/throttle/index.ts +10 -0
  99. package/throttle/index.umd.js +1 -0
  100. package/tsconfig.json +14 -0
  101. package/vite-env.d.ts +1 -0
@@ -0,0 +1,550 @@
1
+ var B = (function() {
2
+ const h = () => {
3
+ }, y = {
4
+ morphStyle: "outerHTML",
5
+ callbacks: {
6
+ beforeNodeAdded: h,
7
+ afterNodeAdded: h,
8
+ beforeNodeMorphed: h,
9
+ afterNodeMorphed: h,
10
+ beforeNodeRemoved: h,
11
+ afterNodeRemoved: h,
12
+ beforeAttributeUpdated: h
13
+ },
14
+ head: {
15
+ style: "merge",
16
+ shouldPreserve: (a) => a.getAttribute("im-preserve") === "true",
17
+ shouldReAppend: (a) => a.getAttribute("im-re-append") === "true",
18
+ shouldRemove: h,
19
+ afterHeadMorphed: h
20
+ },
21
+ restoreFocus: !0
22
+ };
23
+ function g(a, m, c = {}) {
24
+ a = E(a);
25
+ const d = I(m), f = L(a, d, c), l = b(f, () => T(
26
+ f,
27
+ a,
28
+ d,
29
+ /** @param {MorphContext} ctx */
30
+ (r) => r.morphStyle === "innerHTML" ? (S(r, a, d), Array.from(a.childNodes)) : M(r, a, d)
31
+ ));
32
+ return f.pantry.remove(), l;
33
+ }
34
+ function M(a, m, c) {
35
+ const d = I(m);
36
+ return S(
37
+ a,
38
+ d,
39
+ c,
40
+ // these two optional params are the secret sauce
41
+ m,
42
+ // start point for iteration
43
+ m.nextSibling
44
+ // end point for iteration
45
+ ), Array.from(d.childNodes);
46
+ }
47
+ function b(a, m) {
48
+ var n;
49
+ if (!a.config.restoreFocus) return m();
50
+ let c = (
51
+ /** @type {HTMLInputElement|HTMLTextAreaElement|null} */
52
+ document.activeElement
53
+ );
54
+ if (!(c instanceof HTMLInputElement || c instanceof HTMLTextAreaElement))
55
+ return m();
56
+ const { id: d, selectionStart: f, selectionEnd: l } = c, r = m();
57
+ return d && d !== ((n = document.activeElement) == null ? void 0 : n.id) && (c = a.target.querySelector(`[id="${d}"]`), c == null || c.focus()), c && !c.selectionEnd && l && c.setSelectionRange(f, l), r;
58
+ }
59
+ const S = /* @__PURE__ */ (function() {
60
+ function a(e, t, s, i = null, o = null) {
61
+ t instanceof HTMLTemplateElement && s instanceof HTMLTemplateElement && (t = t.content, s = s.content), i || (i = t.firstChild);
62
+ for (const u of s.childNodes) {
63
+ if (i && i != o) {
64
+ const p = c(
65
+ e,
66
+ u,
67
+ i,
68
+ o
69
+ );
70
+ if (p) {
71
+ p !== i && f(e, i, p), H(p, u, e), i = p.nextSibling;
72
+ continue;
73
+ }
74
+ }
75
+ if (u instanceof Element && e.persistentIds.has(u.id)) {
76
+ const p = l(
77
+ t,
78
+ u.id,
79
+ i,
80
+ e
81
+ );
82
+ H(p, u, e), i = p.nextSibling;
83
+ continue;
84
+ }
85
+ const v = m(
86
+ t,
87
+ u,
88
+ i,
89
+ e
90
+ );
91
+ v && (i = v.nextSibling);
92
+ }
93
+ for (; i && i != o; ) {
94
+ const u = i;
95
+ i = i.nextSibling, d(e, u);
96
+ }
97
+ }
98
+ function m(e, t, s, i) {
99
+ if (i.callbacks.beforeNodeAdded(t) === !1) return null;
100
+ if (i.idMap.has(t)) {
101
+ const o = document.createElement(
102
+ /** @type {Element} */
103
+ t.tagName
104
+ );
105
+ return e.insertBefore(o, s), H(o, t, i), i.callbacks.afterNodeAdded(o), o;
106
+ } else {
107
+ const o = document.importNode(t, !0);
108
+ return e.insertBefore(o, s), i.callbacks.afterNodeAdded(o), o;
109
+ }
110
+ }
111
+ const c = /* @__PURE__ */ (function() {
112
+ function e(i, o, u, v) {
113
+ let p = null, k = o.nextSibling, R = 0, A = u;
114
+ for (; A && A != v; ) {
115
+ if (s(A, o)) {
116
+ if (t(i, A, o))
117
+ return A;
118
+ p === null && (i.idMap.has(A) || (p = A));
119
+ }
120
+ if (p === null && k && s(A, k) && (R++, k = k.nextSibling, R >= 2 && (p = void 0)), A.contains(document.activeElement)) break;
121
+ A = A.nextSibling;
122
+ }
123
+ return p || null;
124
+ }
125
+ function t(i, o, u) {
126
+ let v = i.idMap.get(o), p = i.idMap.get(u);
127
+ if (!p || !v) return !1;
128
+ for (const k of v)
129
+ if (p.has(k))
130
+ return !0;
131
+ return !1;
132
+ }
133
+ function s(i, o) {
134
+ const u = (
135
+ /** @type {Element} */
136
+ i
137
+ ), v = (
138
+ /** @type {Element} */
139
+ o
140
+ );
141
+ return u.nodeType === v.nodeType && u.tagName === v.tagName && // If oldElt has an `id` with possible state and it doesn't match newElt.id then avoid morphing.
142
+ // We'll still match an anonymous node with an IDed newElt, though, because if it got this far,
143
+ // its not persistent, and new nodes can't have any hidden state.
144
+ (!u.id || u.id === v.id);
145
+ }
146
+ return e;
147
+ })();
148
+ function d(e, t) {
149
+ var s;
150
+ if (e.idMap.has(t))
151
+ n(e.pantry, t, null);
152
+ else {
153
+ if (e.callbacks.beforeNodeRemoved(t) === !1) return;
154
+ (s = t.parentNode) == null || s.removeChild(t), e.callbacks.afterNodeRemoved(t);
155
+ }
156
+ }
157
+ function f(e, t, s) {
158
+ let i = t;
159
+ for (; i && i !== s; ) {
160
+ let o = (
161
+ /** @type {Node} */
162
+ i
163
+ );
164
+ i = i.nextSibling, d(e, o);
165
+ }
166
+ return i;
167
+ }
168
+ function l(e, t, s, i) {
169
+ const o = (
170
+ /** @type {Element} - will always be found */
171
+ i.target.id === t && i.target || i.target.querySelector(`[id="${t}"]`) || i.pantry.querySelector(`[id="${t}"]`)
172
+ );
173
+ return r(o, i), n(e, o, s), o;
174
+ }
175
+ function r(e, t) {
176
+ const s = e.id;
177
+ for (; e = e.parentNode; ) {
178
+ let i = t.idMap.get(e);
179
+ i && (i.delete(s), i.size || t.idMap.delete(e));
180
+ }
181
+ }
182
+ function n(e, t, s) {
183
+ if (e.moveBefore)
184
+ try {
185
+ e.moveBefore(t, s);
186
+ } catch (i) {
187
+ e.insertBefore(t, s);
188
+ }
189
+ else
190
+ e.insertBefore(t, s);
191
+ }
192
+ return a;
193
+ })(), H = /* @__PURE__ */ (function() {
194
+ function a(r, n, e) {
195
+ return e.ignoreActive && r === document.activeElement ? null : (e.callbacks.beforeNodeMorphed(r, n) === !1 || (r instanceof HTMLHeadElement && e.head.ignore || (r instanceof HTMLHeadElement && e.head.style !== "morph" ? N(
196
+ r,
197
+ /** @type {HTMLHeadElement} */
198
+ n,
199
+ e
200
+ ) : (m(r, n, e), l(r, e) || S(e, r, n))), e.callbacks.afterNodeMorphed(r, n)), r);
201
+ }
202
+ function m(r, n, e) {
203
+ let t = n.nodeType;
204
+ if (t === 1) {
205
+ const s = (
206
+ /** @type {Element} */
207
+ r
208
+ ), i = (
209
+ /** @type {Element} */
210
+ n
211
+ ), o = s.attributes, u = i.attributes;
212
+ for (const v of u)
213
+ f(v.name, s, "update", e) || s.getAttribute(v.name) !== v.value && s.setAttribute(v.name, v.value);
214
+ for (let v = o.length - 1; 0 <= v; v--) {
215
+ const p = o[v];
216
+ if (p && !i.hasAttribute(p.name)) {
217
+ if (f(p.name, s, "remove", e))
218
+ continue;
219
+ s.removeAttribute(p.name);
220
+ }
221
+ }
222
+ l(s, e) || c(s, i, e);
223
+ }
224
+ (t === 8 || t === 3) && r.nodeValue !== n.nodeValue && (r.nodeValue = n.nodeValue);
225
+ }
226
+ function c(r, n, e) {
227
+ if (r instanceof HTMLInputElement && n instanceof HTMLInputElement && n.type !== "file") {
228
+ let t = n.value, s = r.value;
229
+ d(r, n, "checked", e), d(r, n, "disabled", e), n.hasAttribute("value") ? s !== t && (f("value", r, "update", e) || (r.setAttribute("value", t), r.value = t)) : f("value", r, "remove", e) || (r.value = "", r.removeAttribute("value"));
230
+ } else if (r instanceof HTMLOptionElement && n instanceof HTMLOptionElement)
231
+ d(r, n, "selected", e);
232
+ else if (r instanceof HTMLTextAreaElement && n instanceof HTMLTextAreaElement) {
233
+ let t = n.value, s = r.value;
234
+ if (f("value", r, "update", e))
235
+ return;
236
+ t !== s && (r.value = t), r.firstChild && r.firstChild.nodeValue !== t && (r.firstChild.nodeValue = t);
237
+ }
238
+ }
239
+ function d(r, n, e, t) {
240
+ const s = n[e], i = r[e];
241
+ if (s !== i) {
242
+ const o = f(
243
+ e,
244
+ r,
245
+ "update",
246
+ t
247
+ );
248
+ o || (r[e] = n[e]), s ? o || r.setAttribute(e, "") : f(e, r, "remove", t) || r.removeAttribute(e);
249
+ }
250
+ }
251
+ function f(r, n, e, t) {
252
+ return r === "value" && t.ignoreActiveValue && n === document.activeElement ? !0 : t.callbacks.beforeAttributeUpdated(r, n, e) === !1;
253
+ }
254
+ function l(r, n) {
255
+ return !!n.ignoreActiveValue && r === document.activeElement && r !== document.body;
256
+ }
257
+ return a;
258
+ })();
259
+ function T(a, m, c, d) {
260
+ if (a.head.block) {
261
+ const f = m.querySelector("head"), l = c.querySelector("head");
262
+ if (f && l) {
263
+ const r = N(f, l, a);
264
+ return Promise.all(r).then(() => {
265
+ const n = Object.assign(a, {
266
+ head: {
267
+ block: !1,
268
+ ignore: !0
269
+ }
270
+ });
271
+ return d(n);
272
+ });
273
+ }
274
+ }
275
+ return d(a);
276
+ }
277
+ function N(a, m, c) {
278
+ let d = [], f = [], l = [], r = [], n = /* @__PURE__ */ new Map();
279
+ for (const t of m.children)
280
+ n.set(t.outerHTML, t);
281
+ for (const t of a.children) {
282
+ let s = n.has(t.outerHTML), i = c.head.shouldReAppend(t), o = c.head.shouldPreserve(t);
283
+ s || o ? i ? f.push(t) : (n.delete(t.outerHTML), l.push(t)) : c.head.style === "append" ? i && (f.push(t), r.push(t)) : c.head.shouldRemove(t) !== !1 && f.push(t);
284
+ }
285
+ r.push(...n.values());
286
+ let e = [];
287
+ for (const t of r) {
288
+ let s = (
289
+ /** @type {ChildNode} */
290
+ document.createRange().createContextualFragment(t.outerHTML).firstChild
291
+ );
292
+ if (c.callbacks.beforeNodeAdded(s) !== !1) {
293
+ if ("href" in s && s.href || "src" in s && s.src) {
294
+ let i, o = new Promise(function(u) {
295
+ i = u;
296
+ });
297
+ s.addEventListener("load", function() {
298
+ i();
299
+ }), e.push(o);
300
+ }
301
+ a.appendChild(s), c.callbacks.afterNodeAdded(s), d.push(s);
302
+ }
303
+ }
304
+ for (const t of f)
305
+ c.callbacks.beforeNodeRemoved(t) !== !1 && (a.removeChild(t), c.callbacks.afterNodeRemoved(t));
306
+ return c.head.afterHeadMorphed(a, {
307
+ added: d,
308
+ kept: l,
309
+ removed: f
310
+ }), e;
311
+ }
312
+ const L = /* @__PURE__ */ (function() {
313
+ function a(n, e, t) {
314
+ const { persistentIds: s, idMap: i } = l(n, e), o = m(t), u = o.morphStyle || "outerHTML";
315
+ if (!["innerHTML", "outerHTML"].includes(u))
316
+ throw `Do not understand how to morph style ${u}`;
317
+ return {
318
+ target: n,
319
+ newContent: e,
320
+ config: o,
321
+ morphStyle: u,
322
+ ignoreActive: o.ignoreActive,
323
+ ignoreActiveValue: o.ignoreActiveValue,
324
+ restoreFocus: o.restoreFocus,
325
+ idMap: i,
326
+ persistentIds: s,
327
+ pantry: c(),
328
+ callbacks: o.callbacks,
329
+ head: o.head
330
+ };
331
+ }
332
+ function m(n) {
333
+ let e = Object.assign({}, y);
334
+ return Object.assign(e, n), e.callbacks = Object.assign(
335
+ {},
336
+ y.callbacks,
337
+ n.callbacks
338
+ ), e.head = Object.assign({}, y.head, n.head), e;
339
+ }
340
+ function c() {
341
+ const n = document.createElement("div");
342
+ return n.hidden = !0, document.body.insertAdjacentElement("afterend", n), n;
343
+ }
344
+ function d(n) {
345
+ let e = Array.from(n.querySelectorAll("[id]"));
346
+ return n.id && e.push(n), e;
347
+ }
348
+ function f(n, e, t, s) {
349
+ for (const i of s)
350
+ if (e.has(i.id)) {
351
+ let o = i;
352
+ for (; o; ) {
353
+ let u = n.get(o);
354
+ if (u == null && (u = /* @__PURE__ */ new Set(), n.set(o, u)), u.add(i.id), o === t) break;
355
+ o = o.parentElement;
356
+ }
357
+ }
358
+ }
359
+ function l(n, e) {
360
+ const t = d(n), s = d(e), i = r(t, s);
361
+ let o = /* @__PURE__ */ new Map();
362
+ f(o, i, n, t);
363
+ const u = e.__idiomorphRoot || e;
364
+ return f(o, i, u, s), { persistentIds: i, idMap: o };
365
+ }
366
+ function r(n, e) {
367
+ let t = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Map();
368
+ for (const { id: o, tagName: u } of n)
369
+ s.has(o) ? t.add(o) : s.set(o, u);
370
+ let i = /* @__PURE__ */ new Set();
371
+ for (const { id: o, tagName: u } of e)
372
+ i.has(o) ? t.add(o) : s.get(o) === u && i.add(o);
373
+ for (const o of t)
374
+ i.delete(o);
375
+ return i;
376
+ }
377
+ return a;
378
+ })(), { normalizeElement: E, normalizeParent: I } = /* @__PURE__ */ (function() {
379
+ const a = /* @__PURE__ */ new WeakSet();
380
+ function m(l) {
381
+ return l instanceof Document ? l.documentElement : l;
382
+ }
383
+ function c(l) {
384
+ if (l == null)
385
+ return document.createElement("div");
386
+ if (typeof l == "string")
387
+ return c(f(l));
388
+ if (a.has(
389
+ /** @type {Element} */
390
+ l
391
+ ))
392
+ return (
393
+ /** @type {Element} */
394
+ l
395
+ );
396
+ if (l instanceof Node) {
397
+ if (l.parentNode)
398
+ return (
399
+ /** @type {any} */
400
+ new d(l)
401
+ );
402
+ {
403
+ const r = document.createElement("div");
404
+ return r.append(l), r;
405
+ }
406
+ } else {
407
+ const r = document.createElement("div");
408
+ for (const n of [...l])
409
+ r.append(n);
410
+ return r;
411
+ }
412
+ }
413
+ class d {
414
+ /** @param {Node} node */
415
+ constructor(r) {
416
+ this.originalNode = r, this.realParentNode = /** @type {Element} */
417
+ r.parentNode, this.previousSibling = r.previousSibling, this.nextSibling = r.nextSibling;
418
+ }
419
+ /** @returns {Node[]} */
420
+ get childNodes() {
421
+ const r = [];
422
+ let n = this.previousSibling ? this.previousSibling.nextSibling : this.realParentNode.firstChild;
423
+ for (; n && n != this.nextSibling; )
424
+ r.push(n), n = n.nextSibling;
425
+ return r;
426
+ }
427
+ /**
428
+ * @param {string} selector
429
+ * @returns {Element[]}
430
+ */
431
+ querySelectorAll(r) {
432
+ return this.childNodes.reduce(
433
+ (n, e) => {
434
+ if (e instanceof Element) {
435
+ e.matches(r) && n.push(e);
436
+ const t = e.querySelectorAll(r);
437
+ for (let s = 0; s < t.length; s++)
438
+ n.push(t[s]);
439
+ }
440
+ return n;
441
+ },
442
+ /** @type {Element[]} */
443
+ []
444
+ );
445
+ }
446
+ /**
447
+ * @param {Node} node
448
+ * @param {Node} referenceNode
449
+ * @returns {Node}
450
+ */
451
+ insertBefore(r, n) {
452
+ return this.realParentNode.insertBefore(r, n);
453
+ }
454
+ /**
455
+ * @param {Node} node
456
+ * @param {Node} referenceNode
457
+ * @returns {Node}
458
+ */
459
+ moveBefore(r, n) {
460
+ return this.realParentNode.moveBefore(r, n);
461
+ }
462
+ /**
463
+ * for later use with populateIdMapWithTree to halt upwards iteration
464
+ * @returns {Node}
465
+ */
466
+ get __idiomorphRoot() {
467
+ return this.originalNode;
468
+ }
469
+ }
470
+ function f(l) {
471
+ let r = new DOMParser(), n = l.replace(
472
+ /<svg(\s[^>]*>|>)([\s\S]*?)<\/svg>/gim,
473
+ ""
474
+ );
475
+ if (n.match(/<\/html>/) || n.match(/<\/head>/) || n.match(/<\/body>/)) {
476
+ let e = r.parseFromString(l, "text/html");
477
+ if (n.match(/<\/html>/))
478
+ return a.add(e), e;
479
+ {
480
+ let t = e.firstChild;
481
+ return t && a.add(t), t;
482
+ }
483
+ } else {
484
+ let t = (
485
+ /** @type {HTMLTemplateElement} */
486
+ r.parseFromString(
487
+ "<body><template>" + l + "</template></body>",
488
+ "text/html"
489
+ ).body.querySelector("template").content
490
+ );
491
+ return a.add(t), t;
492
+ }
493
+ }
494
+ return { normalizeElement: m, normalizeParent: c };
495
+ })();
496
+ return {
497
+ morph: g,
498
+ defaults: y
499
+ };
500
+ })();
501
+ const O = ({ target: h }) => {
502
+ V();
503
+ const y = document.head.cloneNode(!0), g = h.innerHTML;
504
+ return {
505
+ renderJS(M, b) {
506
+ if (!b && !M) {
507
+ const S = 'script[name="outlet-script"]';
508
+ return h.innerHTML = g, document.head.querySelector(S).remove(), Promise.resolve(h);
509
+ }
510
+ return h.innerHTML = `<${M}></${M}>`, new Promise((S, H) => {
511
+ const T = document.createElement("script");
512
+ T.setAttribute("name", "outlet-script"), T.src = b, T.onload = () => S(h), T.onerror = H, document.head.appendChild(T);
513
+ }).catch((S) => {
514
+ throw "TypeError: Failed to fetch";
515
+ });
516
+ },
517
+ render(M) {
518
+ return M ? fetch(M).then((b) => b.text()).then((b) => {
519
+ const S = [], H = new URL(M), N = new DOMParser().parseFromString(b, "text/html"), L = N.documentElement.querySelector("body"), E = L.querySelectorAll("script, link, style"), I = N.documentElement.querySelector("head");
520
+ return E.forEach((a) => {
521
+ I.appendChild(a);
522
+ }), B.morph(document.head, I, {
523
+ callbacks: {
524
+ beforeNodeAdded: q(S, H)
525
+ }
526
+ }), new Promise((a) => {
527
+ h.innerHTML = L == null ? void 0 : L.innerHTML, Promise.allSettled(S).then(() => a(h));
528
+ });
529
+ }).catch((b) => {
530
+ throw b;
531
+ }) : (B.morph(document.head, y), h.innerHTML = g, Promise.resolve(h));
532
+ }
533
+ };
534
+ }, V = () => {
535
+ document.head.querySelectorAll("script, link, style").forEach((h) => h.setAttribute("im-preserve", "true"));
536
+ }, q = (h, y) => (g) => {
537
+ if (g.src && g.getAttribute("src").startsWith("/")) {
538
+ const { pathname: M, search: b } = new URL(g.src);
539
+ g.src = y.origin + M + b;
540
+ } else if (g.href && g.getAttribute("href").startsWith("/")) {
541
+ const { pathname: M, search: b } = new URL(g.href);
542
+ g.href = y.origin + M + b;
543
+ }
544
+ return g.src && g.localName == "script" && h.push(new Promise((M, b) => {
545
+ g.addEventListener("load", M), g.addEventListener("error", b);
546
+ })), h;
547
+ };
548
+ export {
549
+ O as Outlet
550
+ };
@@ -0,0 +1,101 @@
1
+
2
+ import { Idiomorph } from 'idiomorph/dist/idiomorph.esm'
3
+
4
+ export const Outlet = ({ target: outlet }) => {
5
+
6
+ preserveScriptsAndCss()
7
+
8
+ const originalHead = document.head.cloneNode(true)
9
+ const originalOutlet = outlet.innerHTML
10
+
11
+ return {
12
+
13
+ renderJS( name, path? ) {
14
+
15
+ if( !path && !name ) {
16
+ const selector = 'script[name="outlet-script"]'
17
+ outlet.innerHTML = originalOutlet
18
+ document.head.querySelector(selector).remove()
19
+ return Promise.resolve(outlet)
20
+ }
21
+
22
+ outlet.innerHTML = `<${name}></${name}>`
23
+
24
+ return new Promise((resolve, reject) => {
25
+ const script = document.createElement('script')
26
+ script.setAttribute('name', 'outlet-script')
27
+ script.src = path
28
+ script.onload = () => resolve(outlet)
29
+ script.onerror = reject
30
+ document.head.appendChild(script)
31
+ })
32
+ .catch(err => {
33
+ throw 'TypeError: Failed to fetch'
34
+ })
35
+ },
36
+
37
+ render( path? ) {
38
+
39
+ if( !path ) {
40
+ Idiomorph.morph( document.head, originalHead )
41
+ outlet.innerHTML = originalOutlet
42
+ return Promise.resolve(outlet)
43
+ }
44
+
45
+ return fetch( path )
46
+ .then( res => res.text() )
47
+ .then( html => {
48
+ const promises = []
49
+ const url = new URL( path )
50
+ const parser = new DOMParser()
51
+ const doc = parser.parseFromString( html, 'text/html' )
52
+ const content = doc.documentElement.querySelector('body')
53
+ const all = content.querySelectorAll('script, link, style')
54
+ const head = doc.documentElement.querySelector('head')
55
+
56
+ all.forEach( node => { head.appendChild(node) })
57
+
58
+ Idiomorph.morph( document.head, head, {
59
+ callbacks: {
60
+ beforeNodeAdded: onBeforeNodeAdded( promises, url )
61
+ }
62
+ })
63
+
64
+ return new Promise((resolve) => {
65
+ outlet.innerHTML = content?.innerHTML
66
+ Promise.allSettled(promises).then(() => resolve(outlet))
67
+ })
68
+ })
69
+
70
+ .catch( err => {
71
+ throw err
72
+ })
73
+ }
74
+ }
75
+ }
76
+
77
+ const preserveScriptsAndCss = () => {
78
+ document.head
79
+ .querySelectorAll('script, link, style')
80
+ .forEach( element => element.setAttribute('im-preserve', 'true') )
81
+ }
82
+
83
+ const onBeforeNodeAdded = (promises, url) => (node) => {
84
+
85
+ if( node.src && node.getAttribute('src').startsWith('/') ) {
86
+ const { pathname, search } = new URL(node.src)
87
+ node.src = url.origin + pathname + search
88
+ } else if( node.href && node.getAttribute('href').startsWith('/') ) {
89
+ const { pathname, search } = new URL(node.href)
90
+ node.href = url.origin + pathname + search
91
+ }
92
+
93
+ if( node.src && node.localName == 'script' ) {
94
+ promises.push( new Promise((resolve, reject) => {
95
+ node.addEventListener('load', resolve)
96
+ node.addEventListener('error', reject)
97
+ }))
98
+ }
99
+
100
+ return promises
101
+ }
@@ -0,0 +1 @@
1
+ (function(L,k){typeof exports=="object"&&typeof module!="undefined"?k(exports):typeof define=="function"&&define.amd?define(["exports"],k):(L=typeof globalThis!="undefined"?globalThis:L||self,k(L.outlet={}))})(this,(function(L){"use strict";var k=(function(){const h=()=>{},A={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:h,afterNodeAdded:h,beforeNodeMorphed:h,afterNodeMorphed:h,beforeNodeRemoved:h,afterNodeRemoved:h,beforeAttributeUpdated:h},head:{style:"merge",shouldPreserve:a=>a.getAttribute("im-preserve")==="true",shouldReAppend:a=>a.getAttribute("im-re-append")==="true",shouldRemove:h,afterHeadMorphed:h},restoreFocus:!0};function g(a,m,c={}){a=B(a);const d=R(m),f=N(a,d,c),l=b(f,()=>T(f,a,d,r=>r.morphStyle==="innerHTML"?(S(r,a,d),Array.from(a.childNodes)):M(r,a,d)));return f.pantry.remove(),l}function M(a,m,c){const d=R(m);return S(a,d,c,m,m.nextSibling),Array.from(d.childNodes)}function b(a,m){var n;if(!a.config.restoreFocus)return m();let c=document.activeElement;if(!(c instanceof HTMLInputElement||c instanceof HTMLTextAreaElement))return m();const{id:d,selectionStart:f,selectionEnd:l}=c,r=m();return d&&d!==((n=document.activeElement)==null?void 0:n.id)&&(c=a.target.querySelector(`[id="${d}"]`),c==null||c.focus()),c&&!c.selectionEnd&&l&&c.setSelectionRange(f,l),r}const S=(function(){function a(e,t,s,i=null,o=null){t instanceof HTMLTemplateElement&&s instanceof HTMLTemplateElement&&(t=t.content,s=s.content),i||(i=t.firstChild);for(const u of s.childNodes){if(i&&i!=o){const p=c(e,u,i,o);if(p){p!==i&&f(e,i,p),H(p,u,e),i=p.nextSibling;continue}}if(u instanceof Element&&e.persistentIds.has(u.id)){const p=l(t,u.id,i,e);H(p,u,e),i=p.nextSibling;continue}const v=m(t,u,i,e);v&&(i=v.nextSibling)}for(;i&&i!=o;){const u=i;i=i.nextSibling,d(e,u)}}function m(e,t,s,i){if(i.callbacks.beforeNodeAdded(t)===!1)return null;if(i.idMap.has(t)){const o=document.createElement(t.tagName);return e.insertBefore(o,s),H(o,t,i),i.callbacks.afterNodeAdded(o),o}else{const o=document.importNode(t,!0);return e.insertBefore(o,s),i.callbacks.afterNodeAdded(o),o}}const c=(function(){function e(i,o,u,v){let p=null,I=o.nextSibling,V=0,y=u;for(;y&&y!=v;){if(s(y,o)){if(t(i,y,o))return y;p===null&&(i.idMap.has(y)||(p=y))}if(p===null&&I&&s(y,I)&&(V++,I=I.nextSibling,V>=2&&(p=void 0)),y.contains(document.activeElement))break;y=y.nextSibling}return p||null}function t(i,o,u){let v=i.idMap.get(o),p=i.idMap.get(u);if(!p||!v)return!1;for(const I of v)if(p.has(I))return!0;return!1}function s(i,o){const u=i,v=o;return u.nodeType===v.nodeType&&u.tagName===v.tagName&&(!u.id||u.id===v.id)}return e})();function d(e,t){var s;if(e.idMap.has(t))n(e.pantry,t,null);else{if(e.callbacks.beforeNodeRemoved(t)===!1)return;(s=t.parentNode)==null||s.removeChild(t),e.callbacks.afterNodeRemoved(t)}}function f(e,t,s){let i=t;for(;i&&i!==s;){let o=i;i=i.nextSibling,d(e,o)}return i}function l(e,t,s,i){const o=i.target.id===t&&i.target||i.target.querySelector(`[id="${t}"]`)||i.pantry.querySelector(`[id="${t}"]`);return r(o,i),n(e,o,s),o}function r(e,t){const s=e.id;for(;e=e.parentNode;){let i=t.idMap.get(e);i&&(i.delete(s),i.size||t.idMap.delete(e))}}function n(e,t,s){if(e.moveBefore)try{e.moveBefore(t,s)}catch(i){e.insertBefore(t,s)}else e.insertBefore(t,s)}return a})(),H=(function(){function a(r,n,e){return e.ignoreActive&&r===document.activeElement?null:(e.callbacks.beforeNodeMorphed(r,n)===!1||(r instanceof HTMLHeadElement&&e.head.ignore||(r instanceof HTMLHeadElement&&e.head.style!=="morph"?E(r,n,e):(m(r,n,e),l(r,e)||S(e,r,n))),e.callbacks.afterNodeMorphed(r,n)),r)}function m(r,n,e){let t=n.nodeType;if(t===1){const s=r,i=n,o=s.attributes,u=i.attributes;for(const v of u)f(v.name,s,"update",e)||s.getAttribute(v.name)!==v.value&&s.setAttribute(v.name,v.value);for(let v=o.length-1;0<=v;v--){const p=o[v];if(p&&!i.hasAttribute(p.name)){if(f(p.name,s,"remove",e))continue;s.removeAttribute(p.name)}}l(s,e)||c(s,i,e)}(t===8||t===3)&&r.nodeValue!==n.nodeValue&&(r.nodeValue=n.nodeValue)}function c(r,n,e){if(r instanceof HTMLInputElement&&n instanceof HTMLInputElement&&n.type!=="file"){let t=n.value,s=r.value;d(r,n,"checked",e),d(r,n,"disabled",e),n.hasAttribute("value")?s!==t&&(f("value",r,"update",e)||(r.setAttribute("value",t),r.value=t)):f("value",r,"remove",e)||(r.value="",r.removeAttribute("value"))}else if(r instanceof HTMLOptionElement&&n instanceof HTMLOptionElement)d(r,n,"selected",e);else if(r instanceof HTMLTextAreaElement&&n instanceof HTMLTextAreaElement){let t=n.value,s=r.value;if(f("value",r,"update",e))return;t!==s&&(r.value=t),r.firstChild&&r.firstChild.nodeValue!==t&&(r.firstChild.nodeValue=t)}}function d(r,n,e,t){const s=n[e],i=r[e];if(s!==i){const o=f(e,r,"update",t);o||(r[e]=n[e]),s?o||r.setAttribute(e,""):f(e,r,"remove",t)||r.removeAttribute(e)}}function f(r,n,e,t){return r==="value"&&t.ignoreActiveValue&&n===document.activeElement?!0:t.callbacks.beforeAttributeUpdated(r,n,e)===!1}function l(r,n){return!!n.ignoreActiveValue&&r===document.activeElement&&r!==document.body}return a})();function T(a,m,c,d){if(a.head.block){const f=m.querySelector("head"),l=c.querySelector("head");if(f&&l){const r=E(f,l,a);return Promise.all(r).then(()=>{const n=Object.assign(a,{head:{block:!1,ignore:!0}});return d(n)})}}return d(a)}function E(a,m,c){let d=[],f=[],l=[],r=[],n=new Map;for(const t of m.children)n.set(t.outerHTML,t);for(const t of a.children){let s=n.has(t.outerHTML),i=c.head.shouldReAppend(t),o=c.head.shouldPreserve(t);s||o?i?f.push(t):(n.delete(t.outerHTML),l.push(t)):c.head.style==="append"?i&&(f.push(t),r.push(t)):c.head.shouldRemove(t)!==!1&&f.push(t)}r.push(...n.values());let e=[];for(const t of r){let s=document.createRange().createContextualFragment(t.outerHTML).firstChild;if(c.callbacks.beforeNodeAdded(s)!==!1){if("href"in s&&s.href||"src"in s&&s.src){let i,o=new Promise(function(u){i=u});s.addEventListener("load",function(){i()}),e.push(o)}a.appendChild(s),c.callbacks.afterNodeAdded(s),d.push(s)}}for(const t of f)c.callbacks.beforeNodeRemoved(t)!==!1&&(a.removeChild(t),c.callbacks.afterNodeRemoved(t));return c.head.afterHeadMorphed(a,{added:d,kept:l,removed:f}),e}const N=(function(){function a(n,e,t){const{persistentIds:s,idMap:i}=l(n,e),o=m(t),u=o.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(u))throw`Do not understand how to morph style ${u}`;return{target:n,newContent:e,config:o,morphStyle:u,ignoreActive:o.ignoreActive,ignoreActiveValue:o.ignoreActiveValue,restoreFocus:o.restoreFocus,idMap:i,persistentIds:s,pantry:c(),callbacks:o.callbacks,head:o.head}}function m(n){let e=Object.assign({},A);return Object.assign(e,n),e.callbacks=Object.assign({},A.callbacks,n.callbacks),e.head=Object.assign({},A.head,n.head),e}function c(){const n=document.createElement("div");return n.hidden=!0,document.body.insertAdjacentElement("afterend",n),n}function d(n){let e=Array.from(n.querySelectorAll("[id]"));return n.id&&e.push(n),e}function f(n,e,t,s){for(const i of s)if(e.has(i.id)){let o=i;for(;o;){let u=n.get(o);if(u==null&&(u=new Set,n.set(o,u)),u.add(i.id),o===t)break;o=o.parentElement}}}function l(n,e){const t=d(n),s=d(e),i=r(t,s);let o=new Map;f(o,i,n,t);const u=e.__idiomorphRoot||e;return f(o,i,u,s),{persistentIds:i,idMap:o}}function r(n,e){let t=new Set,s=new Map;for(const{id:o,tagName:u}of n)s.has(o)?t.add(o):s.set(o,u);let i=new Set;for(const{id:o,tagName:u}of e)i.has(o)?t.add(o):s.get(o)===u&&i.add(o);for(const o of t)i.delete(o);return i}return a})(),{normalizeElement:B,normalizeParent:R}=(function(){const a=new WeakSet;function m(l){return l instanceof Document?l.documentElement:l}function c(l){if(l==null)return document.createElement("div");if(typeof l=="string")return c(f(l));if(a.has(l))return l;if(l instanceof Node){if(l.parentNode)return new d(l);{const r=document.createElement("div");return r.append(l),r}}else{const r=document.createElement("div");for(const n of[...l])r.append(n);return r}}class d{constructor(r){this.originalNode=r,this.realParentNode=r.parentNode,this.previousSibling=r.previousSibling,this.nextSibling=r.nextSibling}get childNodes(){const r=[];let n=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;n&&n!=this.nextSibling;)r.push(n),n=n.nextSibling;return r}querySelectorAll(r){return this.childNodes.reduce((n,e)=>{if(e instanceof Element){e.matches(r)&&n.push(e);const t=e.querySelectorAll(r);for(let s=0;s<t.length;s++)n.push(t[s])}return n},[])}insertBefore(r,n){return this.realParentNode.insertBefore(r,n)}moveBefore(r,n){return this.realParentNode.moveBefore(r,n)}get __idiomorphRoot(){return this.originalNode}}function f(l){let r=new DOMParser,n=l.replace(/<svg(\s[^>]*>|>)([\s\S]*?)<\/svg>/gim,"");if(n.match(/<\/html>/)||n.match(/<\/head>/)||n.match(/<\/body>/)){let e=r.parseFromString(l,"text/html");if(n.match(/<\/html>/))return a.add(e),e;{let t=e.firstChild;return t&&a.add(t),t}}else{let t=r.parseFromString("<body><template>"+l+"</template></body>","text/html").body.querySelector("template").content;return a.add(t),t}}return{normalizeElement:m,normalizeParent:c}})();return{morph:g,defaults:A}})();const O=({target:h})=>{q();const A=document.head.cloneNode(!0),g=h.innerHTML;return{renderJS(M,b){if(!b&&!M){const S='script[name="outlet-script"]';return h.innerHTML=g,document.head.querySelector(S).remove(),Promise.resolve(h)}return h.innerHTML=`<${M}></${M}>`,new Promise((S,H)=>{const T=document.createElement("script");T.setAttribute("name","outlet-script"),T.src=b,T.onload=()=>S(h),T.onerror=H,document.head.appendChild(T)}).catch(S=>{throw"TypeError: Failed to fetch"})},render(M){return M?fetch(M).then(b=>b.text()).then(b=>{const S=[],H=new URL(M),E=new DOMParser().parseFromString(b,"text/html"),N=E.documentElement.querySelector("body"),B=N.querySelectorAll("script, link, style"),R=E.documentElement.querySelector("head");return B.forEach(a=>{R.appendChild(a)}),k.morph(document.head,R,{callbacks:{beforeNodeAdded:w(S,H)}}),new Promise(a=>{h.innerHTML=N==null?void 0:N.innerHTML,Promise.allSettled(S).then(()=>a(h))})}).catch(b=>{throw b}):(k.morph(document.head,A),h.innerHTML=g,Promise.resolve(h))}}},q=()=>{document.head.querySelectorAll("script, link, style").forEach(h=>h.setAttribute("im-preserve","true"))},w=(h,A)=>g=>{if(g.src&&g.getAttribute("src").startsWith("/")){const{pathname:M,search:b}=new URL(g.src);g.src=A.origin+M+b}else if(g.href&&g.getAttribute("href").startsWith("/")){const{pathname:M,search:b}=new URL(g.href);g.href=A.origin+M+b}return g.src&&g.localName=="script"&&h.push(new Promise((M,b)=>{g.addEventListener("load",M),g.addEventListener("error",b)})),h};L.Outlet=O,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}));
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "jails.stdlib",
3
+ "version": "1.0.0",
4
+ "description": "The Jails Standard Library",
5
+ "types": "index.d.ts",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+ssh://git@github.com/jails-org/std.git"
9
+ },
10
+ "author": "Javiani <eduardo.ottaviani@gmail.com>",
11
+ "license": "MIT",
12
+ "scripts": {
13
+ "build": "node build && tsc"
14
+ },
15
+ "dependencies": {
16
+ "@javiani/onijs": "^1.0.7",
17
+ "@types/node": "^20.10.7",
18
+ "glob": "^10.3.10",
19
+ "grapnel": "0.6.4",
20
+ "idiomorph": "^0.7.2",
21
+ "typescript": "^5.8.3",
22
+ "vanilla-lazyload": "^19.1.3",
23
+ "vite": "^6.0.7"
24
+ }
25
+ }