snice 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.
package/dist/snice.js ADDED
@@ -0,0 +1,980 @@
1
+ function yt() {
2
+ return globalThis.snice || (globalThis.snice = {
3
+ controllerRegistry: /* @__PURE__ */ new Map(),
4
+ controllerIdCounter: 0,
5
+ symbols: /* @__PURE__ */ new Map()
6
+ }), globalThis.snice;
7
+ }
8
+ const x = yt();
9
+ function E(t) {
10
+ return x.symbols.has(t) || x.symbols.set(t, Symbol(t)), x.symbols.get(t);
11
+ }
12
+ const dt = E("is-controller-class"), ot = E("is-element-class"), J = E("channel-handlers"), F = E("ready-promise"), H = E("ready-resolve"), B = E("controller"), Q = E("on-handlers"), V = E("controller-key"), W = E("controller-name"), pt = E("controller-id"), rt = E("controller-operations"), et = E("native-controller"), k = E("cleanup"), nt = E("properties"), A = E("property-values");
13
+ function Ft(t, e) {
14
+ return function(n, o, c) {
15
+ return n[Q] || (n[Q] = []), n[Q].push({
16
+ eventName: t,
17
+ selector: e,
18
+ methodName: o,
19
+ method: c.value
20
+ }), c;
21
+ };
22
+ }
23
+ function st(t, e) {
24
+ const n = t.constructor.prototype[Q];
25
+ if (n) {
26
+ t[k] || (t[k] = { events: [], channels: [] });
27
+ for (const o of n) {
28
+ const c = o.method.bind(t), h = (u) => {
29
+ try {
30
+ return c(u);
31
+ } catch (f) {
32
+ console.error(`Error in event handler ${o.methodName}:`, f);
33
+ }
34
+ };
35
+ if (o.selector) {
36
+ const u = e.shadowRoot || e, f = (d) => {
37
+ const p = d.target;
38
+ (p.matches && p.matches(o.selector) || p.closest && p.closest(o.selector)) && h(d);
39
+ };
40
+ u.addEventListener(o.eventName, f), t[k].events.push(() => {
41
+ u.removeEventListener(o.eventName, f);
42
+ });
43
+ } else
44
+ e.addEventListener(o.eventName, h), t[k].events.push(() => {
45
+ e.removeEventListener(o.eventName, h);
46
+ });
47
+ }
48
+ }
49
+ }
50
+ function X(t) {
51
+ var e;
52
+ if ((e = t[k]) != null && e.events) {
53
+ for (const n of t[k].events)
54
+ n();
55
+ t[k].events = [];
56
+ }
57
+ }
58
+ function Ht(t, e) {
59
+ return function(n, o, c) {
60
+ const h = c.value;
61
+ return c.value = function(...u) {
62
+ const f = h.apply(this, u);
63
+ if (f instanceof Promise)
64
+ return f.then((p) => {
65
+ if (p === void 0 && (e == null ? void 0 : e.dispatchOnUndefined) === !1)
66
+ return p;
67
+ const b = new CustomEvent(t, {
68
+ bubbles: !0,
69
+ // Default to true for component events
70
+ composed: !0,
71
+ // Allow crossing shadow DOM boundaries
72
+ ...e,
73
+ // Spread all EventInit options
74
+ detail: p
75
+ });
76
+ return this.dispatchEvent(b), p;
77
+ });
78
+ if (f === void 0 && (e == null ? void 0 : e.dispatchOnUndefined) === !1)
79
+ return f;
80
+ const d = new CustomEvent(t, {
81
+ bubbles: !0,
82
+ // Default to true for component events
83
+ composed: !0,
84
+ // Allow crossing shadow DOM boundaries
85
+ ...e,
86
+ // Spread all EventInit options
87
+ detail: f
88
+ });
89
+ return this.dispatchEvent(d), f;
90
+ }, c;
91
+ };
92
+ }
93
+ function Vt(t, e) {
94
+ return function(n, o, c) {
95
+ const h = c.value;
96
+ return c.value = async function(...u) {
97
+ if (this instanceof HTMLElement) {
98
+ const f = (e == null ? void 0 : e.timeout) ?? 100, d = h.apply(this, u), { value: p, done: b } = await d.next();
99
+ if (b)
100
+ return p;
101
+ let v, s;
102
+ const r = new Promise((R, S) => {
103
+ v = R, s = S;
104
+ });
105
+ let i, l, a;
106
+ const y = new Promise((R, S) => {
107
+ i = R, l = S, a = setTimeout(() => {
108
+ S(new Error(`Channel timeout after ${f}ms`));
109
+ }, f);
110
+ }), L = `@channel:${t}`, m = new CustomEvent(L, {
111
+ bubbles: (e == null ? void 0 : e.bubbles) !== void 0 ? e.bubbles : !0,
112
+ cancelable: (e == null ? void 0 : e.cancelable) || !1,
113
+ composed: !0,
114
+ // Allow crossing shadow DOM boundaries
115
+ detail: {
116
+ payload: p,
117
+ timeout: {
118
+ resolve: () => {
119
+ clearTimeout(a), i();
120
+ },
121
+ reject: l
122
+ },
123
+ data: {
124
+ resolve: v,
125
+ reject: s
126
+ }
127
+ }
128
+ });
129
+ this.dispatchEvent(m);
130
+ try {
131
+ await y;
132
+ const R = await r, { value: S } = await d.next(R);
133
+ return S;
134
+ } catch (R) {
135
+ try {
136
+ await d.throw(R);
137
+ } catch (S) {
138
+ throw S;
139
+ }
140
+ }
141
+ } else
142
+ return h.apply(this, u);
143
+ }, n[J] || (n[J] = []), n[J].push({
144
+ channelName: t,
145
+ methodName: o,
146
+ method: h
147
+ }), c;
148
+ };
149
+ }
150
+ function mt(t, e) {
151
+ const n = t.constructor.prototype[J];
152
+ if (n) {
153
+ t[k] || (t[k] = { events: [], channels: [] });
154
+ for (const o of n) {
155
+ const c = o.method.bind(t), h = `@channel:${o.channelName}`, u = (f) => {
156
+ const { data: d, timeout: p, payload: b } = f.detail;
157
+ f.preventDefault(), f.stopImmediatePropagation(), f.stopPropagation(), Promise.resolve(c(b)).then((v) => {
158
+ p.resolve(), d.resolve(v);
159
+ }).catch((v) => {
160
+ p.resolve(), d.reject(v), console.error(`Error in channel handler ${o.methodName}:`, v);
161
+ });
162
+ };
163
+ e.addEventListener(h, u), t[k].channels.push(() => {
164
+ e.removeEventListener(h, u);
165
+ });
166
+ }
167
+ }
168
+ }
169
+ function gt(t) {
170
+ var e;
171
+ if ((e = t[k]) != null && e.channels) {
172
+ for (const n of t[k].channels)
173
+ n();
174
+ t[k].channels = [];
175
+ }
176
+ }
177
+ class vt {
178
+ constructor() {
179
+ this.cleanupFns = /* @__PURE__ */ new Map(), this.pendingOperations = /* @__PURE__ */ new Set();
180
+ }
181
+ register(e, n) {
182
+ this.cleanupFns.set(e, n);
183
+ }
184
+ unregister(e) {
185
+ this.cleanupFns.delete(e);
186
+ }
187
+ async cleanup() {
188
+ await Promise.all(this.pendingOperations);
189
+ for (const e of this.cleanupFns.values())
190
+ try {
191
+ await e();
192
+ } catch (n) {
193
+ console.error("Error during cleanup:", n);
194
+ }
195
+ this.cleanupFns.clear();
196
+ }
197
+ async runOperation(e) {
198
+ const n = e(), o = n.then(() => {
199
+ }, () => {
200
+ });
201
+ this.pendingOperations.add(o);
202
+ try {
203
+ const c = await n;
204
+ return this.pendingOperations.delete(o), c;
205
+ } catch (c) {
206
+ throw this.pendingOperations.delete(o), c;
207
+ }
208
+ }
209
+ }
210
+ function Dt(t) {
211
+ return function(e) {
212
+ return x.controllerRegistry.set(t, e), e.prototype[dt] = !0, e;
213
+ };
214
+ }
215
+ async function at(t, e) {
216
+ const n = t[V];
217
+ if (t[W] === e)
218
+ return;
219
+ n && await Z(t);
220
+ const c = x.controllerRegistry.get(e);
221
+ if (!c)
222
+ throw new Error(`Controller "${e}" not found in registry`);
223
+ const h = new c();
224
+ x.controllerIdCounter += 1;
225
+ const u = x.controllerIdCounter, f = new vt();
226
+ h[pt] = u, h.element = t, t[V] = h, t[W] = e, t[rt] = f, await t.ready, await f.runOperation(async () => {
227
+ await h.attach(t);
228
+ }), st(h, t), mt(h, t), t.dispatchEvent(new CustomEvent("controller.attached", {
229
+ detail: { name: e, controller: h }
230
+ }));
231
+ }
232
+ async function Z(t) {
233
+ const e = t[V], n = t[W], o = t[rt];
234
+ e && (o ? await o.runOperation(async () => {
235
+ await e.detach(t);
236
+ }) : await e.detach(t), e.element = null, X(e), gt(e), o && await o.cleanup(), delete t[V], delete t[W], delete t[rt], t.dispatchEvent(new CustomEvent("controller.detached", {
237
+ detail: { name: n, controller: e }
238
+ })));
239
+ }
240
+ function Ut(t) {
241
+ return t[V];
242
+ }
243
+ function Yt() {
244
+ if (globalThis.sniceNativeControllersInitialized)
245
+ return;
246
+ globalThis.sniceNativeControllersInitialized = !0;
247
+ function t(n) {
248
+ if (!(n instanceof HTMLElement) || n.tagName.includes("-") || n[ot]) return;
249
+ const o = n.getAttribute("controller"), c = n[et];
250
+ o && !c ? (n[et] = !0, n.ready || (n.ready = Promise.resolve()), at(n, o).catch((h) => {
251
+ console.error(`Failed to attach controller "${o}" to native element:`, h);
252
+ })) : !o && c && (delete n[et], Z(n).catch((h) => {
253
+ console.error("Failed to detach controller from native element:", h);
254
+ }));
255
+ }
256
+ const e = new MutationObserver((n) => {
257
+ for (const o of n)
258
+ o.type === "attributes" && o.attributeName === "controller" ? t(o.target) : o.type === "childList" && o.addedNodes.forEach((c) => {
259
+ c instanceof HTMLElement && (t(c), c.querySelectorAll('[controller]:not([class*="-"])').forEach(t));
260
+ });
261
+ });
262
+ document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", () => {
263
+ document.querySelectorAll('[controller]:not([class*="-"])').forEach(t), e.observe(document.body, {
264
+ attributes: !0,
265
+ attributeFilter: ["controller"],
266
+ childList: !0,
267
+ subtree: !0
268
+ });
269
+ }) : (document.querySelectorAll('[controller]:not([class*="-"])').forEach(t), e.observe(document.body, {
270
+ attributes: !0,
271
+ attributeFilter: ["controller"],
272
+ childList: !0,
273
+ subtree: !0
274
+ })), globalThis.sniceNativeControllerObserver = e;
275
+ }
276
+ function zt() {
277
+ const t = globalThis.sniceNativeControllerObserver;
278
+ t && (t.disconnect(), delete globalThis.sniceNativeControllerObserver, delete globalThis.sniceNativeControllersInitialized);
279
+ }
280
+ function bt(t) {
281
+ return function(e) {
282
+ e.prototype[ot] = !0;
283
+ const n = e.prototype.connectedCallback, o = e.prototype.disconnectedCallback, c = e.prototype.attributeChangedCallback, h = e.observedAttributes || [];
284
+ h.includes("controller") || h.push("controller"), Object.defineProperty(e, "observedAttributes", {
285
+ get() {
286
+ return h;
287
+ },
288
+ configurable: !0
289
+ }), Object.defineProperty(e.prototype, "ready", {
290
+ get() {
291
+ return this[F] || (this[F] = new Promise((u) => {
292
+ this[H] = u;
293
+ })), this[F];
294
+ },
295
+ enumerable: !0,
296
+ configurable: !0
297
+ }), Object.defineProperty(e.prototype, "controller", {
298
+ get() {
299
+ return this[B];
300
+ },
301
+ set(u) {
302
+ const f = this[B];
303
+ this[B] = u, u !== f && u ? at(this, u).catch((d) => {
304
+ console.error(`Failed to attach controller "${u}":`, d);
305
+ }) : !u && f && Z(this).catch((d) => {
306
+ console.error("Failed to detach controller:", d);
307
+ });
308
+ },
309
+ enumerable: !0,
310
+ configurable: !0
311
+ }), e.prototype.connectedCallback = async function() {
312
+ this[F] || (this[F] = new Promise((u) => {
313
+ this[H] = u;
314
+ }));
315
+ try {
316
+ X(this), this.shadowRoot || this.attachShadow({ mode: "open" });
317
+ let u = "";
318
+ if (this.html)
319
+ try {
320
+ const d = this.html(), p = d instanceof Promise ? await d : d;
321
+ p !== void 0 && (u += p);
322
+ } catch (d) {
323
+ console.error(`Error in html() method for ${this.tagName}:`, d);
324
+ }
325
+ if (this.css)
326
+ try {
327
+ const d = this.css(), p = d instanceof Promise ? await d : d;
328
+ if (p) {
329
+ const b = Array.isArray(p) ? p.join(`
330
+ `) : p;
331
+ u += `<style data-component-css>${b}</style>`;
332
+ }
333
+ } catch (d) {
334
+ console.error(`Error in css() method for ${this.tagName}:`, d);
335
+ }
336
+ u && (this.shadowRoot.innerHTML = u), n == null || n.call(this);
337
+ const f = this.getAttribute("controller");
338
+ f && (this.controller = f), st(this, this);
339
+ } finally {
340
+ this[H] && (this[H](), this[H] = null);
341
+ }
342
+ }, e.prototype.disconnectedCallback = function() {
343
+ o == null || o.call(this), this[B] && Z(this).catch((u) => {
344
+ console.error("Failed to detach controller:", u);
345
+ }), X(this);
346
+ }, e.prototype.attributeChangedCallback = function(u, f, d) {
347
+ c == null || c.call(this, u, f, d), u === "controller" && (this.controller = d);
348
+ }, customElements.define(t, e);
349
+ };
350
+ }
351
+ const Gt = bt;
352
+ function Bt(t) {
353
+ return function(e, n) {
354
+ const o = e.constructor;
355
+ o[nt] || (o[nt] = /* @__PURE__ */ new Map()), o[nt].set(n, t || {}), Object.defineProperty(e, n, {
356
+ get() {
357
+ return this[A] || (this[A] = {}), this[A][n];
358
+ },
359
+ set(h) {
360
+ this[A] || (this[A] = {});
361
+ const u = this[A][n];
362
+ u !== h && (this[A][n] = h, t != null && t.reflect && this.setAttribute && (h == null || h === !1 ? this.removeAttribute(t.attribute || n) : this.setAttribute(t.attribute || n, String(h))), this.requestUpdate && this.requestUpdate(n, u));
363
+ },
364
+ enumerable: !0,
365
+ configurable: !0
366
+ });
367
+ };
368
+ }
369
+ function Jt(t) {
370
+ return function(e, n) {
371
+ Object.defineProperty(e, n, {
372
+ get() {
373
+ const o = this.element || this;
374
+ return o.shadowRoot ? o.shadowRoot.querySelector(t) : o.querySelector(t);
375
+ },
376
+ enumerable: !0,
377
+ configurable: !0
378
+ });
379
+ };
380
+ }
381
+ function Qt(t) {
382
+ return function(e, n) {
383
+ Object.defineProperty(e, n, {
384
+ get() {
385
+ const o = this.element || this;
386
+ return o.shadowRoot ? o.shadowRoot.querySelectorAll(t) : o.querySelectorAll(t);
387
+ },
388
+ enumerable: !0,
389
+ configurable: !0
390
+ });
391
+ };
392
+ }
393
+ function _t(t) {
394
+ return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
395
+ }
396
+ function wt(t) {
397
+ throw new Error('Could not dynamically require "' + t + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
398
+ }
399
+ var lt = {};
400
+ (function(t) {
401
+ var e = function() {
402
+ var n = function(v, s, r, i) {
403
+ for (r = r || {}, i = v.length; i--; r[v[i]] = s) ;
404
+ return r;
405
+ }, o = [1, 9], c = [1, 10], h = [1, 11], u = [1, 12], f = [5, 11, 12, 13, 14, 15], d = {
406
+ trace: function() {
407
+ },
408
+ yy: {},
409
+ symbols_: { error: 2, root: 3, expressions: 4, EOF: 5, expression: 6, optional: 7, literal: 8, splat: 9, param: 10, "(": 11, ")": 12, LITERAL: 13, SPLAT: 14, PARAM: 15, $accept: 0, $end: 1 },
410
+ terminals_: { 2: "error", 5: "EOF", 11: "(", 12: ")", 13: "LITERAL", 14: "SPLAT", 15: "PARAM" },
411
+ productions_: [0, [3, 2], [3, 1], [4, 2], [4, 1], [6, 1], [6, 1], [6, 1], [6, 1], [7, 3], [8, 1], [9, 1], [10, 1]],
412
+ performAction: function(s, r, i, l, a, y, L) {
413
+ var m = y.length - 1;
414
+ switch (a) {
415
+ case 1:
416
+ return new l.Root({}, [y[m - 1]]);
417
+ case 2:
418
+ return new l.Root({}, [new l.Literal({ value: "" })]);
419
+ case 3:
420
+ this.$ = new l.Concat({}, [y[m - 1], y[m]]);
421
+ break;
422
+ case 4:
423
+ case 5:
424
+ this.$ = y[m];
425
+ break;
426
+ case 6:
427
+ this.$ = new l.Literal({ value: y[m] });
428
+ break;
429
+ case 7:
430
+ this.$ = new l.Splat({ name: y[m] });
431
+ break;
432
+ case 8:
433
+ this.$ = new l.Param({ name: y[m] });
434
+ break;
435
+ case 9:
436
+ this.$ = new l.Optional({}, [y[m - 1]]);
437
+ break;
438
+ case 10:
439
+ this.$ = s;
440
+ break;
441
+ case 11:
442
+ case 12:
443
+ this.$ = s.slice(1);
444
+ break;
445
+ }
446
+ },
447
+ table: [{ 3: 1, 4: 2, 5: [1, 3], 6: 4, 7: 5, 8: 6, 9: 7, 10: 8, 11: o, 13: c, 14: h, 15: u }, { 1: [3] }, { 5: [1, 13], 6: 14, 7: 5, 8: 6, 9: 7, 10: 8, 11: o, 13: c, 14: h, 15: u }, { 1: [2, 2] }, n(f, [2, 4]), n(f, [2, 5]), n(f, [2, 6]), n(f, [2, 7]), n(f, [2, 8]), { 4: 15, 6: 4, 7: 5, 8: 6, 9: 7, 10: 8, 11: o, 13: c, 14: h, 15: u }, n(f, [2, 10]), n(f, [2, 11]), n(f, [2, 12]), { 1: [2, 1] }, n(f, [2, 3]), { 6: 14, 7: 5, 8: 6, 9: 7, 10: 8, 11: o, 12: [1, 16], 13: c, 14: h, 15: u }, n(f, [2, 9])],
448
+ defaultActions: { 3: [2, 2], 13: [2, 1] },
449
+ parseError: function(s, r) {
450
+ if (r.recoverable)
451
+ this.trace(s);
452
+ else {
453
+ let i = function(l, a) {
454
+ this.message = l, this.hash = a;
455
+ };
456
+ throw i.prototype = Error, new i(s, r);
457
+ }
458
+ },
459
+ parse: function(s) {
460
+ var r = this, i = [0], l = [null], a = [], y = this.table, L = "", m = 0, R = 0, S = 2, N = 1, M = a.slice.call(arguments, 1), g = Object.create(this.lexer), _ = { yy: {} };
461
+ for (var T in this.yy)
462
+ Object.prototype.hasOwnProperty.call(this.yy, T) && (_.yy[T] = this.yy[T]);
463
+ g.setInput(s, _.yy), _.yy.lexer = g, _.yy.parser = this, typeof g.yylloc > "u" && (g.yylloc = {});
464
+ var q = g.yylloc;
465
+ a.push(q);
466
+ var U = g.options && g.options.ranges;
467
+ typeof _.yy.parseError == "function" ? this.parseError = _.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
468
+ for (var Y = function() {
469
+ var j;
470
+ return j = g.lex() || N, typeof j != "number" && (j = r.symbols_[j] || j), j;
471
+ }, w, C, O, K, I = {}, z, P, it, G; ; ) {
472
+ if (C = i[i.length - 1], this.defaultActions[C] ? O = this.defaultActions[C] : ((w === null || typeof w > "u") && (w = Y()), O = y[C] && y[C][w]), typeof O > "u" || !O.length || !O[0]) {
473
+ var tt = "";
474
+ G = [];
475
+ for (z in y[C])
476
+ this.terminals_[z] && z > S && G.push("'" + this.terminals_[z] + "'");
477
+ g.showPosition ? tt = "Parse error on line " + (m + 1) + `:
478
+ ` + g.showPosition() + `
479
+ Expecting ` + G.join(", ") + ", got '" + (this.terminals_[w] || w) + "'" : tt = "Parse error on line " + (m + 1) + ": Unexpected " + (w == N ? "end of input" : "'" + (this.terminals_[w] || w) + "'"), this.parseError(tt, {
480
+ text: g.match,
481
+ token: this.terminals_[w] || w,
482
+ line: g.yylineno,
483
+ loc: q,
484
+ expected: G
485
+ });
486
+ }
487
+ if (O[0] instanceof Array && O.length > 1)
488
+ throw new Error("Parse Error: multiple actions possible at state: " + C + ", token: " + w);
489
+ switch (O[0]) {
490
+ case 1:
491
+ i.push(w), l.push(g.yytext), a.push(g.yylloc), i.push(O[1]), w = null, R = g.yyleng, L = g.yytext, m = g.yylineno, q = g.yylloc;
492
+ break;
493
+ case 2:
494
+ if (P = this.productions_[O[1]][1], I.$ = l[l.length - P], I._$ = {
495
+ first_line: a[a.length - (P || 1)].first_line,
496
+ last_line: a[a.length - 1].last_line,
497
+ first_column: a[a.length - (P || 1)].first_column,
498
+ last_column: a[a.length - 1].last_column
499
+ }, U && (I._$.range = [
500
+ a[a.length - (P || 1)].range[0],
501
+ a[a.length - 1].range[1]
502
+ ]), K = this.performAction.apply(I, [
503
+ L,
504
+ R,
505
+ m,
506
+ _.yy,
507
+ O[1],
508
+ l,
509
+ a
510
+ ].concat(M)), typeof K < "u")
511
+ return K;
512
+ P && (i = i.slice(0, -1 * P * 2), l = l.slice(0, -1 * P), a = a.slice(0, -1 * P)), i.push(this.productions_[O[1]][0]), l.push(I.$), a.push(I._$), it = y[i[i.length - 2]][i[i.length - 1]], i.push(it);
513
+ break;
514
+ case 3:
515
+ return !0;
516
+ }
517
+ }
518
+ return !0;
519
+ }
520
+ }, p = /* @__PURE__ */ function() {
521
+ var v = {
522
+ EOF: 1,
523
+ parseError: function(r, i) {
524
+ if (this.yy.parser)
525
+ this.yy.parser.parseError(r, i);
526
+ else
527
+ throw new Error(r);
528
+ },
529
+ // resets the lexer, sets new input
530
+ setInput: function(s, r) {
531
+ return this.yy = r || this.yy || {}, this._input = s, this._more = this._backtrack = this.done = !1, this.yylineno = this.yyleng = 0, this.yytext = this.matched = this.match = "", this.conditionStack = ["INITIAL"], this.yylloc = {
532
+ first_line: 1,
533
+ first_column: 0,
534
+ last_line: 1,
535
+ last_column: 0
536
+ }, this.options.ranges && (this.yylloc.range = [0, 0]), this.offset = 0, this;
537
+ },
538
+ // consumes and returns one char from the input
539
+ input: function() {
540
+ var s = this._input[0];
541
+ this.yytext += s, this.yyleng++, this.offset++, this.match += s, this.matched += s;
542
+ var r = s.match(/(?:\r\n?|\n).*/g);
543
+ return r ? (this.yylineno++, this.yylloc.last_line++) : this.yylloc.last_column++, this.options.ranges && this.yylloc.range[1]++, this._input = this._input.slice(1), s;
544
+ },
545
+ // unshifts one char (or a string) into the input
546
+ unput: function(s) {
547
+ var r = s.length, i = s.split(/(?:\r\n?|\n)/g);
548
+ this._input = s + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - r), this.offset -= r;
549
+ var l = this.match.split(/(?:\r\n?|\n)/g);
550
+ this.match = this.match.substr(0, this.match.length - 1), this.matched = this.matched.substr(0, this.matched.length - 1), i.length - 1 && (this.yylineno -= i.length - 1);
551
+ var a = this.yylloc.range;
552
+ return this.yylloc = {
553
+ first_line: this.yylloc.first_line,
554
+ last_line: this.yylineno + 1,
555
+ first_column: this.yylloc.first_column,
556
+ last_column: i ? (i.length === l.length ? this.yylloc.first_column : 0) + l[l.length - i.length].length - i[0].length : this.yylloc.first_column - r
557
+ }, this.options.ranges && (this.yylloc.range = [a[0], a[0] + this.yyleng - r]), this.yyleng = this.yytext.length, this;
558
+ },
559
+ // When called from action, caches matched text and appends it on next action
560
+ more: function() {
561
+ return this._more = !0, this;
562
+ },
563
+ // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
564
+ reject: function() {
565
+ if (this.options.backtrack_lexer)
566
+ this._backtrack = !0;
567
+ else
568
+ return this.parseError("Lexical error on line " + (this.yylineno + 1) + `. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).
569
+ ` + this.showPosition(), {
570
+ text: "",
571
+ token: null,
572
+ line: this.yylineno
573
+ });
574
+ return this;
575
+ },
576
+ // retain first n characters of the match
577
+ less: function(s) {
578
+ this.unput(this.match.slice(s));
579
+ },
580
+ // displays already matched input, i.e. for error messages
581
+ pastInput: function() {
582
+ var s = this.matched.substr(0, this.matched.length - this.match.length);
583
+ return (s.length > 20 ? "..." : "") + s.substr(-20).replace(/\n/g, "");
584
+ },
585
+ // displays upcoming input, i.e. for error messages
586
+ upcomingInput: function() {
587
+ var s = this.match;
588
+ return s.length < 20 && (s += this._input.substr(0, 20 - s.length)), (s.substr(0, 20) + (s.length > 20 ? "..." : "")).replace(/\n/g, "");
589
+ },
590
+ // displays the character position where the lexing error occurred, i.e. for error messages
591
+ showPosition: function() {
592
+ var s = this.pastInput(), r = new Array(s.length + 1).join("-");
593
+ return s + this.upcomingInput() + `
594
+ ` + r + "^";
595
+ },
596
+ // test the lexed token: return FALSE when not a match, otherwise return token
597
+ test_match: function(s, r) {
598
+ var i, l, a;
599
+ if (this.options.backtrack_lexer && (a = {
600
+ yylineno: this.yylineno,
601
+ yylloc: {
602
+ first_line: this.yylloc.first_line,
603
+ last_line: this.last_line,
604
+ first_column: this.yylloc.first_column,
605
+ last_column: this.yylloc.last_column
606
+ },
607
+ yytext: this.yytext,
608
+ match: this.match,
609
+ matches: this.matches,
610
+ matched: this.matched,
611
+ yyleng: this.yyleng,
612
+ offset: this.offset,
613
+ _more: this._more,
614
+ _input: this._input,
615
+ yy: this.yy,
616
+ conditionStack: this.conditionStack.slice(0),
617
+ done: this.done
618
+ }, this.options.ranges && (a.yylloc.range = this.yylloc.range.slice(0))), l = s[0].match(/(?:\r\n?|\n).*/g), l && (this.yylineno += l.length), this.yylloc = {
619
+ first_line: this.yylloc.last_line,
620
+ last_line: this.yylineno + 1,
621
+ first_column: this.yylloc.last_column,
622
+ last_column: l ? l[l.length - 1].length - l[l.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + s[0].length
623
+ }, this.yytext += s[0], this.match += s[0], this.matches = s, this.yyleng = this.yytext.length, this.options.ranges && (this.yylloc.range = [this.offset, this.offset += this.yyleng]), this._more = !1, this._backtrack = !1, this._input = this._input.slice(s[0].length), this.matched += s[0], i = this.performAction.call(this, this.yy, this, r, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = !1), i)
624
+ return i;
625
+ if (this._backtrack) {
626
+ for (var y in a)
627
+ this[y] = a[y];
628
+ return !1;
629
+ }
630
+ return !1;
631
+ },
632
+ // return next match in input
633
+ next: function() {
634
+ if (this.done)
635
+ return this.EOF;
636
+ this._input || (this.done = !0);
637
+ var s, r, i, l;
638
+ this._more || (this.yytext = "", this.match = "");
639
+ for (var a = this._currentRules(), y = 0; y < a.length; y++)
640
+ if (i = this._input.match(this.rules[a[y]]), i && (!r || i[0].length > r[0].length)) {
641
+ if (r = i, l = y, this.options.backtrack_lexer) {
642
+ if (s = this.test_match(i, a[y]), s !== !1)
643
+ return s;
644
+ if (this._backtrack) {
645
+ r = !1;
646
+ continue;
647
+ } else
648
+ return !1;
649
+ } else if (!this.options.flex)
650
+ break;
651
+ }
652
+ return r ? (s = this.test_match(r, a[l]), s !== !1 ? s : !1) : this._input === "" ? this.EOF : this.parseError("Lexical error on line " + (this.yylineno + 1) + `. Unrecognized text.
653
+ ` + this.showPosition(), {
654
+ text: "",
655
+ token: null,
656
+ line: this.yylineno
657
+ });
658
+ },
659
+ // return next match that has a token
660
+ lex: function() {
661
+ var r = this.next();
662
+ return r || this.lex();
663
+ },
664
+ // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
665
+ begin: function(r) {
666
+ this.conditionStack.push(r);
667
+ },
668
+ // pop the previously active lexer condition state off the condition stack
669
+ popState: function() {
670
+ var r = this.conditionStack.length - 1;
671
+ return r > 0 ? this.conditionStack.pop() : this.conditionStack[0];
672
+ },
673
+ // produce the lexer rule set which is active for the currently active lexer condition state
674
+ _currentRules: function() {
675
+ return this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1] ? this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules : this.conditions.INITIAL.rules;
676
+ },
677
+ // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
678
+ topState: function(r) {
679
+ return r = this.conditionStack.length - 1 - Math.abs(r || 0), r >= 0 ? this.conditionStack[r] : "INITIAL";
680
+ },
681
+ // alias for begin(condition)
682
+ pushState: function(r) {
683
+ this.begin(r);
684
+ },
685
+ // return the number of states currently on the stack
686
+ stateStackSize: function() {
687
+ return this.conditionStack.length;
688
+ },
689
+ options: {},
690
+ performAction: function(r, i, l, a) {
691
+ switch (l) {
692
+ case 0:
693
+ return "(";
694
+ case 1:
695
+ return ")";
696
+ case 2:
697
+ return "SPLAT";
698
+ case 3:
699
+ return "PARAM";
700
+ case 4:
701
+ return "LITERAL";
702
+ case 5:
703
+ return "LITERAL";
704
+ case 6:
705
+ return "EOF";
706
+ }
707
+ },
708
+ rules: [/^(?:\()/, /^(?:\))/, /^(?:\*+\w+)/, /^(?::+\w+)/, /^(?:[\w%\-~\n]+)/, /^(?:.)/, /^(?:$)/],
709
+ conditions: { INITIAL: { rules: [0, 1, 2, 3, 4, 5, 6], inclusive: !0 } }
710
+ };
711
+ return v;
712
+ }();
713
+ d.lexer = p;
714
+ function b() {
715
+ this.yy = {};
716
+ }
717
+ return b.prototype = d, d.Parser = b, new b();
718
+ }();
719
+ typeof wt < "u" && (t.parser = e, t.Parser = e.Parser, t.parse = function() {
720
+ return e.parse.apply(e, arguments);
721
+ });
722
+ })(lt);
723
+ function $(t) {
724
+ return function(e, n) {
725
+ return {
726
+ displayName: t,
727
+ props: e,
728
+ children: n || []
729
+ };
730
+ };
731
+ }
732
+ var ct = {
733
+ Root: $("Root"),
734
+ Concat: $("Concat"),
735
+ Literal: $("Literal"),
736
+ Splat: $("Splat"),
737
+ Param: $("Param"),
738
+ Optional: $("Optional")
739
+ }, ht = lt.parser;
740
+ ht.yy = ct;
741
+ var Et = ht, Rt = Object.keys(ct);
742
+ function St(t) {
743
+ return Rt.forEach(function(e) {
744
+ if (typeof t[e] > "u")
745
+ throw new Error("No handler defined for " + e.displayName);
746
+ }), {
747
+ /**
748
+ * Call the given handler for this node type
749
+ * @param {Object} node the AST node
750
+ * @param {Object} context context to pass through to handlers
751
+ * @return {Object}
752
+ */
753
+ visit: function(e, n) {
754
+ return this.handlers[e.displayName].call(this, e, n);
755
+ },
756
+ handlers: t
757
+ };
758
+ }
759
+ var ut = St, kt = ut, Ot = /[\-{}\[\]+?.,\\\^$|#\s]/g;
760
+ function ft(t) {
761
+ this.captures = t.captures, this.re = t.re;
762
+ }
763
+ ft.prototype.match = function(t) {
764
+ var e = this.re.exec(t), n = {};
765
+ if (e)
766
+ return this.captures.forEach(function(o, c) {
767
+ typeof e[c + 1] > "u" ? n[o] = void 0 : n[o] = decodeURIComponent(e[c + 1]);
768
+ }), n;
769
+ };
770
+ var Lt = kt({
771
+ Concat: function(t) {
772
+ return t.children.reduce(
773
+ (function(e, n) {
774
+ var o = this.visit(n);
775
+ return {
776
+ re: e.re + o.re,
777
+ captures: e.captures.concat(o.captures)
778
+ };
779
+ }).bind(this),
780
+ { re: "", captures: [] }
781
+ );
782
+ },
783
+ Literal: function(t) {
784
+ return {
785
+ re: t.props.value.replace(Ot, "\\$&"),
786
+ captures: []
787
+ };
788
+ },
789
+ Splat: function(t) {
790
+ return {
791
+ re: "([^?]*?)",
792
+ captures: [t.props.name]
793
+ };
794
+ },
795
+ Param: function(t) {
796
+ return {
797
+ re: "([^\\/\\?]+)",
798
+ captures: [t.props.name]
799
+ };
800
+ },
801
+ Optional: function(t) {
802
+ var e = this.visit(t.children[0]);
803
+ return {
804
+ re: "(?:" + e.re + ")?",
805
+ captures: e.captures
806
+ };
807
+ },
808
+ Root: function(t) {
809
+ var e = this.visit(t.children[0]);
810
+ return new ft({
811
+ re: new RegExp("^" + e.re + "(?=\\?|$)"),
812
+ captures: e.captures
813
+ });
814
+ }
815
+ }), Pt = Lt, Ct = ut, At = Ct({
816
+ Concat: function(t, e) {
817
+ var n = t.children.map((function(o) {
818
+ return this.visit(o, e);
819
+ }).bind(this));
820
+ return n.some(function(o) {
821
+ return o === !1;
822
+ }) ? !1 : n.join("");
823
+ },
824
+ Literal: function(t) {
825
+ return decodeURI(t.props.value);
826
+ },
827
+ Splat: function(t, e) {
828
+ return e[t.props.name] ? e[t.props.name] : !1;
829
+ },
830
+ Param: function(t, e) {
831
+ return e[t.props.name] ? e[t.props.name] : !1;
832
+ },
833
+ Optional: function(t, e) {
834
+ var n = this.visit(t.children[0], e);
835
+ return n || "";
836
+ },
837
+ Root: function(t, e) {
838
+ e = e || {};
839
+ var n = this.visit(t.children[0], e);
840
+ return n ? encodeURI(n) : !1;
841
+ }
842
+ }), xt = At, Nt = Et, Tt = Pt, It = xt;
843
+ D.prototype = /* @__PURE__ */ Object.create(null);
844
+ D.prototype.match = function(t) {
845
+ var e = Tt.visit(this.ast), n = e.match(t);
846
+ return n || !1;
847
+ };
848
+ D.prototype.reverse = function(t) {
849
+ return It.visit(this.ast, t);
850
+ };
851
+ function D(t) {
852
+ var e;
853
+ if (this ? e = this : e = Object.create(D.prototype), typeof t > "u")
854
+ throw new Error("A route spec is required");
855
+ return e.spec = t, e.ast = Nt.parse(t), e;
856
+ }
857
+ var jt = D, $t = jt, Mt = $t;
858
+ const qt = /* @__PURE__ */ _t(Mt);
859
+ function Wt(t) {
860
+ const e = [];
861
+ let n = !1, o, c, h = null;
862
+ function u(s) {
863
+ return function(r) {
864
+ r.__transition = s.transition;
865
+ const i = r.prototype.connectedCallback, l = r.prototype.disconnectedCallback;
866
+ r.prototype.connectedCallback = function() {
867
+ this.shadowRoot || this.attachShadow({ mode: "open" });
868
+ let a = "";
869
+ if (this.html) {
870
+ const y = this.html();
871
+ y !== void 0 && (a += y);
872
+ }
873
+ if (this.css) {
874
+ const y = this.css();
875
+ if (y) {
876
+ const L = Array.isArray(y) ? y.join(`
877
+ `) : y;
878
+ a += `<style data-component-css>${L}</style>`;
879
+ }
880
+ }
881
+ a && (this.shadowRoot.innerHTML = a), i == null || i.call(this), st(this, this);
882
+ }, r.prototype.disconnectedCallback = function() {
883
+ l == null || l.call(this), X(this);
884
+ }, customElements.define(s.tag, r), s.routes.forEach((a) => f(a, s.tag));
885
+ };
886
+ }
887
+ function f(s, r, i) {
888
+ e.push({ route: new qt(s), tag: r, transition: i }), n = !1, s === "/404" && (o = r), s === "/" && (c = r);
889
+ }
890
+ function d() {
891
+ if (!document.querySelector(t.target))
892
+ throw new Error(`Target element not found: ${t.target}`);
893
+ switch (n || (e.sort((r, i) => i.route.spec.length - r.route.spec.length), n = !0), t.routing_type) {
894
+ case "hash":
895
+ window.addEventListener("hashchange", () => {
896
+ if (document.querySelector(t.target)) {
897
+ const r = p();
898
+ b(r);
899
+ }
900
+ });
901
+ break;
902
+ case "pushstate":
903
+ window.addEventListener("popstate", () => {
904
+ if (document.querySelector(t.target)) {
905
+ const r = p();
906
+ b(r);
907
+ }
908
+ });
909
+ break;
910
+ }
911
+ const s = p();
912
+ b(s);
913
+ }
914
+ function p() {
915
+ switch (t.routing_type) {
916
+ case "hash":
917
+ return window.location.hash.slice(1);
918
+ case "pushstate":
919
+ return window.location.pathname;
920
+ }
921
+ }
922
+ async function b(s) {
923
+ const r = document.querySelector(t.target);
924
+ if (!r)
925
+ throw new Error(`Target element not found: ${t.target}`);
926
+ let i = null, l;
927
+ if ((s.trim() === "" || s === "/") && c) {
928
+ i = document.createElement(c);
929
+ const a = customElements.get(c);
930
+ l = a == null ? void 0 : a.__transition;
931
+ } else
932
+ for (const a of e) {
933
+ const y = a.route.match(s);
934
+ if (y !== !1) {
935
+ i = document.createElement(a.tag), Object.keys(y).forEach((m) => i.setAttribute(m, y[m])), l = a.transition;
936
+ break;
937
+ }
938
+ }
939
+ if (!i)
940
+ if (o) {
941
+ i = document.createElement(o);
942
+ const a = customElements.get(o);
943
+ l = a == null ? void 0 : a.__transition;
944
+ } else {
945
+ const a = document.createElement("div");
946
+ a.className = "default-404", a.innerHTML = "<h1>404</h1><p>Page not found</p>", i = a;
947
+ }
948
+ l = l || t.transition, l && h && h.parentElement ? await v(r, h, i, l) : (r.innerHTML = "", i && r.appendChild(i)), h = i;
949
+ }
950
+ async function v(s, r, i, l) {
951
+ const a = l.outDuration || 300, y = l.inDuration || 300, L = l.mode || "sequential", m = (_) => {
952
+ const T = {};
953
+ return _.split(";").forEach((q) => {
954
+ const [U, Y] = q.split(":").map((w) => w.trim());
955
+ U && Y && (T[U] = Y);
956
+ }), T;
957
+ }, R = l.out ? m(l.out) : { opacity: "0" }, S = { opacity: "0" }, N = l.in ? m(l.in) : { opacity: "1" }, M = s.style, g = M.position;
958
+ M.position = "relative", r.style.position = "absolute", r.style.top = "0", r.style.left = "0", r.style.width = "100%", r.style.transition = `all ${a}ms ease-in-out`, i.style.position = "absolute", i.style.top = "0", i.style.left = "0", i.style.width = "100%", Object.assign(i.style, S), i.style.transition = `all ${y}ms ease-in-out`, s.appendChild(i), i.offsetHeight, L === "simultaneous" ? (Object.assign(r.style, R), Object.assign(i.style, N), await new Promise((_) => setTimeout(_, Math.max(a, y)))) : (Object.assign(r.style, R), await new Promise((_) => setTimeout(_, a)), Object.assign(i.style, N), await new Promise((_) => setTimeout(_, y))), r.remove(), i.style.position = "", i.style.top = "", i.style.left = "", i.style.width = "", i.style.transition = "", Object.keys({ ...S, ...N }).forEach((_) => {
959
+ i.style[_] = "";
960
+ }), M.position = g;
961
+ }
962
+ return { page: u, initialize: d, navigate: b, register: f };
963
+ }
964
+ export {
965
+ Wt as Router,
966
+ at as attachController,
967
+ Vt as channel,
968
+ zt as cleanupNativeElementControllers,
969
+ Dt as controller,
970
+ Gt as customElement,
971
+ Z as detachController,
972
+ Ht as dispatch,
973
+ bt as element,
974
+ Ut as getController,
975
+ Ft as on,
976
+ Bt as property,
977
+ Jt as query,
978
+ Qt as queryAll,
979
+ Yt as useNativeElementControllers
980
+ };