@telperion/elements 1.0.0 → 1.1.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 (115) hide show
  1. package/.build-manifest.json +58 -0
  2. package/README.md +14 -8
  3. package/drag-drop/drag-element.cjs +59 -60
  4. package/drag-drop/drag-element.cjs.map +1 -0
  5. package/drag-drop/drag-element.js +8 -8
  6. package/drag-drop/drag-element.js.map +1 -1
  7. package/drag-drop/drag-handle-element.cjs +19 -19
  8. package/drag-drop/drag-handle-element.cjs.map +1 -0
  9. package/drag-drop/drag-handle-element.js +8 -7
  10. package/drag-drop/drag-handle-element.js.map +1 -1
  11. package/drag-drop/dropzone-element.cjs +32 -32
  12. package/drag-drop/dropzone-element.cjs.map +1 -0
  13. package/drag-drop/dropzone-element.js +6 -5
  14. package/drag-drop/dropzone-element.js.map +1 -1
  15. package/drag-drop/index.cjs +23 -11
  16. package/drag-drop/index.cjs.map +1 -0
  17. package/drag-drop/{drag-element.d.ts → index.d.cts} +73 -5
  18. package/drag-drop/index.d.ts +172 -6
  19. package/drag-drop/index.js +4 -5
  20. package/drag-drop/index.js.map +1 -1
  21. package/drag-drop/private-props.cjs +10 -6
  22. package/drag-drop/private-props.cjs.map +1 -0
  23. package/drag-drop/private-props.js +4 -3
  24. package/drag-drop/private-props.js.map +1 -1
  25. package/drag-drop/tha-drag-event.cjs +8 -6
  26. package/drag-drop/tha-drag-event.cjs.map +1 -0
  27. package/drag-drop/tha-drag-event.js +4 -2
  28. package/drag-drop/tha-drag-event.js.map +1 -1
  29. package/fesm/elements.mjs +1939 -0
  30. package/fesm/elements.mjs.map +1 -0
  31. package/icon/icon-element.cjs +136 -37
  32. package/icon/icon-element.cjs.map +1 -0
  33. package/icon/icon-element.js +105 -5
  34. package/icon/icon-element.js.map +1 -1
  35. package/icon/index.cjs +16 -5
  36. package/icon/index.cjs.map +1 -0
  37. package/icon/index.d.cts +89 -0
  38. package/icon/index.d.ts +89 -1
  39. package/icon/index.js +2 -2
  40. package/icon/index.js.map +1 -1
  41. package/icon/simple-icons-sprite.cjs +129 -0
  42. package/icon/simple-icons-sprite.cjs.map +1 -0
  43. package/icon/simple-icons-sprite.js +124 -0
  44. package/icon/simple-icons-sprite.js.map +1 -0
  45. package/iife/elements.js +180 -0
  46. package/iife/elements.js.map +1 -0
  47. package/index.cjs +53 -11
  48. package/index.cjs.map +1 -0
  49. package/index.d.cts +6 -0
  50. package/index.d.ts +6 -6
  51. package/index.js +10 -9
  52. package/index.js.map +1 -1
  53. package/package.json +41 -83
  54. package/router/history-managed.cjs +22 -18
  55. package/router/history-managed.cjs.map +1 -0
  56. package/router/history-managed.js +9 -7
  57. package/router/history-managed.js.map +1 -1
  58. package/router/history.cjs +20 -16
  59. package/router/history.cjs.map +1 -0
  60. package/router/history.js +8 -6
  61. package/router/history.js.map +1 -1
  62. package/router/index.cjs +36 -15
  63. package/router/index.cjs.map +1 -0
  64. package/router/index.d.cts +895 -0
  65. package/router/index.d.ts +895 -6
  66. package/router/index.js +6 -7
  67. package/router/index.js.map +1 -1
  68. package/router/signal-watcher-lit-element.cjs +9 -6
  69. package/router/signal-watcher-lit-element.cjs.map +1 -0
  70. package/router/signal-watcher-lit-element.js +5 -3
  71. package/router/signal-watcher-lit-element.js.map +1 -1
  72. package/router/tha-route.cjs +25 -22
  73. package/router/tha-route.cjs.map +1 -0
  74. package/router/tha-route.js +8 -7
  75. package/router/tha-route.js.map +1 -1
  76. package/router/tha-router-config.cjs +17 -17
  77. package/router/tha-router-config.cjs.map +1 -0
  78. package/router/tha-router-config.js +8 -7
  79. package/router/tha-router-config.js.map +1 -1
  80. package/router/tha-router-link.cjs +36 -36
  81. package/router/tha-router-link.cjs.map +1 -0
  82. package/router/tha-router-link.js +9 -8
  83. package/router/tha-router-link.js.map +1 -1
  84. package/router/tha-router-outlet.cjs +51 -48
  85. package/router/tha-router-outlet.cjs.map +1 -0
  86. package/router/tha-router-outlet.js +12 -11
  87. package/router/tha-router-outlet.js.map +1 -1
  88. package/router/tha-router-param.cjs +21 -21
  89. package/router/tha-router-param.cjs.map +1 -0
  90. package/router/tha-router-param.js +7 -6
  91. package/router/tha-router-param.js.map +1 -1
  92. package/router/tha-router.cjs +33 -33
  93. package/router/tha-router.cjs.map +1 -0
  94. package/router/tha-router.js +11 -10
  95. package/router/tha-router.js.map +1 -1
  96. package/bundle.js +0 -164
  97. package/bundle.mjs +0 -2630
  98. package/drag-drop/drag-handle-element.d.ts +0 -12
  99. package/drag-drop/dropzone-element.d.ts +0 -17
  100. package/drag-drop/private-props.d.ts +0 -3
  101. package/drag-drop/tha-drag-event.d.ts +0 -19
  102. package/icon/icon-element.d.ts +0 -40
  103. package/router/history-managed.d.ts +0 -76
  104. package/router/history.d.ts +0 -48
  105. package/router/signal-watcher-lit-element.d.ts +0 -25
  106. package/router/tha-route.d.ts +0 -90
  107. package/router/tha-router-config.d.ts +0 -223
  108. package/router/tha-router-link.d.ts +0 -95
  109. package/router/tha-router-outlet.d.ts +0 -112
  110. package/router/tha-router-param.d.ts +0 -226
  111. package/router/tha-router.d.ts +0 -69
  112. package/tha-url-output.cjs +0 -79
  113. package/tha-url-output.d.ts +0 -41
  114. package/tha-url-output.js +0 -78
  115. package/tha-url-output.js.map +0 -1
@@ -0,0 +1,1939 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { LitElement, css, html as html$1 } from 'lit';
3
+ import { property, customElement, state } from 'lit/decorators.js';
4
+ import { signal, SignalWatcher, computed, html } from '@lit-labs/signals';
5
+ import { noop } from '@telperion/js-utils/function/noop';
6
+ import { createMemoryHistory, createHashHistory, createBrowserHistory } from 'history';
7
+ import { defer } from '@telperion/js-utils/function/defer';
8
+ import { compact } from '@telperion/js-utils/array/compact';
9
+ import { getParents } from '@thalesrc/dom-utils/get-parents';
10
+
11
+ var _a$2, _b;
12
+ /**
13
+ * Symbol used to access the route's template fragment signal.
14
+ * @internal
15
+ */
16
+ const FRAGMENT = Symbol('ThaRoute:fragment');
17
+ /**
18
+ * Symbol used to access the route's URLPattern instance.
19
+ * @internal
20
+ */
21
+ const PATH_PATTERN = Symbol('ThaRoute:path-pattern');
22
+ /**
23
+ * A custom element that defines a route in the router.
24
+ *
25
+ * Each route contains a template element with the content to render when
26
+ * the route matches the current URL. The router watches for changes to
27
+ * the template content and automatically updates the outlet.
28
+ *
29
+ * The `path` attribute uses URLPattern syntax and supports:
30
+ * - Static paths: `/about`, `/users`
31
+ * - Dynamic segments: `/users/:id`, `/posts/:category/:slug`
32
+ * - Wildcards: `/blog/*`, `/docs/**`
33
+ *
34
+ * @example
35
+ * ```html
36
+ * <tha-router>
37
+ * <tha-route path="/">
38
+ * <template><h1>Home Page</h1></template>
39
+ * </tha-route>
40
+ * <tha-route path="/users/:id">
41
+ * <template><h1>User Profile</h1></template>
42
+ * </tha-route>
43
+ * <tha-router-outlet></tha-router-outlet>
44
+ * </tha-router>
45
+ * ```
46
+ */
47
+ let ThaRoute = class ThaRoute extends LitElement {
48
+ constructor() {
49
+ super(...arguments);
50
+ /**
51
+ * Signal containing weak reference to the template's DocumentFragment.
52
+ * Automatically updates when the template content changes.
53
+ * @internal
54
+ */
55
+ this[_a$2] = signal(this.#getTemplateFragment());
56
+ /**
57
+ * URLPattern instance for matching the current URL against this route's path.
58
+ * @internal
59
+ */
60
+ this[_b] = null;
61
+ /**
62
+ * The URL pattern to match for this route.
63
+ * Uses URLPattern syntax with support for dynamic segments and wildcards.
64
+ *
65
+ * @attr path
66
+ * @example "/users/:id"
67
+ * @example "/blog/*"
68
+ */
69
+ this.path = null;
70
+ /** Observes changes to child elements to detect template updates */
71
+ this.#templateObserver = new MutationObserver(() => {
72
+ this[FRAGMENT].set(this.#getTemplateFragment());
73
+ });
74
+ }
75
+ static { _a$2 = FRAGMENT, _b = PATH_PATTERN; }
76
+ /** Observes changes to child elements to detect template updates */
77
+ #templateObserver;
78
+ /**
79
+ * Lifecycle callback when the element is connected to the DOM.
80
+ * Sets up observer to watch for template content changes.
81
+ */
82
+ connectedCallback() {
83
+ super.connectedCallback();
84
+ this.#templateObserver.observe(this, { childList: true });
85
+ }
86
+ /**
87
+ * Lifecycle callback when an attribute changes.
88
+ * Updates the URLPattern when the path attribute changes.
89
+ *
90
+ * @param name - The attribute name that changed
91
+ * @param _old - The old attribute value
92
+ * @param value - The new attribute value
93
+ */
94
+ attributeChangedCallback(name, _old, value) {
95
+ super.attributeChangedCallback(name, _old, value);
96
+ switch (name) {
97
+ case 'path':
98
+ this[PATH_PATTERN] = value ? new URLPattern({ pathname: value }) : null;
99
+ break;
100
+ }
101
+ }
102
+ /**
103
+ * Extracts the DocumentFragment from the template element.
104
+ * Returns a weak reference to prevent memory leaks.
105
+ *
106
+ * @returns Weak reference to the template fragment, or null if no template found
107
+ */
108
+ #getTemplateFragment() {
109
+ const template = this.querySelector('template');
110
+ return template ? new WeakRef(template.content) : null;
111
+ }
112
+ /**
113
+ * Lifecycle callback when the element is disconnected from the DOM.
114
+ * Cleans up the template observer.
115
+ */
116
+ disconnectedCallback() {
117
+ super.disconnectedCallback();
118
+ this.#templateObserver.disconnect();
119
+ }
120
+ };
121
+ __decorate([
122
+ property({ type: String }),
123
+ __metadata("design:type", Object)
124
+ ], ThaRoute.prototype, "path", void 0);
125
+ ThaRoute = __decorate([
126
+ customElement('tha-route')
127
+ ], ThaRoute);
128
+
129
+ /**
130
+ * A LitElement base class extended with SignalWatcher capabilities.
131
+ *
132
+ * This class allows LitElement components to reactively watch for changes
133
+ */
134
+ const SignalWatcherLitElement = SignalWatcher(LitElement);
135
+
136
+ /**
137
+ * Global registry mapping history types to their singleton instances.
138
+ * Ensures that the same history object is reused across all routers of the same type.
139
+ */
140
+ const HISTORY_MAP = {};
141
+ /**
142
+ * Default history type used when no explicit type is specified.
143
+ * Uses browser history (HTML5 History API).
144
+ */
145
+ const DEFAULT_HISTORY_TYPE = "browser";
146
+ /**
147
+ * Reactive signal containing the currently active global history type.
148
+ * Changing this signal will cause all routers using the global history to switch types.
149
+ */
150
+ const GLOBAL_HISTORY_TYPE = signal(DEFAULT_HISTORY_TYPE);
151
+ /**
152
+ * Computed signal that returns the History instance for the current global history type.
153
+ * Automatically updates when GLOBAL_HISTORY_TYPE changes.
154
+ */
155
+ computed(() => getHistoryByType(GLOBAL_HISTORY_TYPE.get()));
156
+ /**
157
+ * Retrieves or creates a History instance for the specified type.
158
+ *
159
+ * History instances are cached in HISTORY_MAP as singletons, so multiple
160
+ * calls with the same type will return the same instance. This ensures
161
+ * that navigation state is shared across all routers using the same history type.
162
+ *
163
+ * @param type - The type of history to retrieve ("browser", "hash", "memory", or "memory:name")
164
+ * @returns The History instance for the specified type
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * // Get browser history
169
+ * const browserHistory = getHistoryByType('browser');
170
+ *
171
+ * // Get hash-based history
172
+ * const hashHistory = getHistoryByType('hash');
173
+ *
174
+ * // Get isolated memory history for testing
175
+ * const testHistory = getHistoryByType('memory:test-suite-1');
176
+ * ```
177
+ */
178
+ function getHistoryByType(type) {
179
+ let history = HISTORY_MAP[type];
180
+ if (!history) {
181
+ switch (type) {
182
+ case 'browser':
183
+ history = createBrowserHistory();
184
+ break;
185
+ case 'hash':
186
+ history = createHashHistory();
187
+ break;
188
+ default:
189
+ history = createMemoryHistory();
190
+ }
191
+ HISTORY_MAP[type] = history;
192
+ }
193
+ return history;
194
+ }
195
+
196
+ /**
197
+ * @fileoverview History management mixin for Lit elements
198
+ *
199
+ * Hierarchical resolution: own history → parent history → global history
200
+ *
201
+ * @module router/history-managed
202
+ */
203
+ /**
204
+ * Symbol for accessing the resolved history instance.
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * const history = this[HISTORY].get();
209
+ * history.push('/path');
210
+ * ```
211
+ */
212
+ const HISTORY = Symbol('HistoryManaged:history');
213
+ /**
214
+ * Symbol for accessing the resolved history type.
215
+ * @internal
216
+ */
217
+ const HISTORY_TYPE = Symbol('HistoryManaged:historyType');
218
+ /**
219
+ * Mixin that adds hierarchical history management to Lit elements.
220
+ *
221
+ * Provides reactive history resolution: own → parent → global
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * class MyRouter extends HistoryManaged(LitElement) {
226
+ * connectedCallback() {
227
+ * super.connectedCallback();
228
+ * const history = this[HISTORY].get();
229
+ * history.listen(({ location }) => this.updateRoutes());
230
+ * }
231
+ * }
232
+ * ```
233
+ *
234
+ * @template T - Base class (must extend LitElement)
235
+ * @param superClass - The class to extend
236
+ * @returns Extended class with history management
237
+ */
238
+ const HistoryManaged = (superClass) => {
239
+ var _a, _b;
240
+ class HistoryManagedLitElement extends superClass {
241
+ constructor() {
242
+ super(...arguments);
243
+ /**
244
+ * History strategy: "browser" | "hash" | "memory" | "memory:name"
245
+ * If undefined, inherits from parent or uses global default.
246
+ *
247
+ * @attr history
248
+ */
249
+ this.history = undefined;
250
+ /** Signal for own history type */
251
+ this.#ownHistoryType = signal(this.history);
252
+ /** Computed signal for parent history type */
253
+ this.#parentHistoryType = computed(() => {
254
+ const parent = this.closest('tha-router-config, tha-router-outlet');
255
+ return parent?.[HISTORY_TYPE]?.get();
256
+ });
257
+ /** Resolved history type: own → parent → global */
258
+ this[_a] = computed(() => this.#ownHistoryType.get() ?? this.#parentHistoryType.get() ?? GLOBAL_HISTORY_TYPE.get());
259
+ /** Resolved history instance: own → parent → global */
260
+ this[_b] = computed(() => getHistoryByType(this[HISTORY_TYPE].get()));
261
+ }
262
+ static { _a = HISTORY_TYPE, _b = HISTORY; }
263
+ /** Signal for own history type */
264
+ #ownHistoryType;
265
+ /** Computed signal for parent history type */
266
+ #parentHistoryType;
267
+ /**
268
+ * Handles attribute changes, updating history signals when needed.
269
+ */
270
+ attributeChangedCallback(name, _old, value) {
271
+ super.attributeChangedCallback(name, _old, value);
272
+ switch (name) {
273
+ case 'history':
274
+ this.#ownHistoryType.set(value);
275
+ break;
276
+ }
277
+ }
278
+ }
279
+ __decorate([
280
+ property({ type: String }),
281
+ __metadata("design:type", Object)
282
+ ], HistoryManagedLitElement.prototype, "history", void 0);
283
+ return HistoryManagedLitElement;
284
+ };
285
+
286
+ var _a$1;
287
+ /**
288
+ * Symbol used by the router to call the internal render method on the outlet.
289
+ * @internal
290
+ */
291
+ const RENDER_ROUTE = Symbol('ThaRouterOutlet:renderRoute');
292
+ const PARAMS = Symbol('ThaRouterOutlet:params');
293
+ /**
294
+ * A custom element that serves as a rendering target for router content.
295
+ *
296
+ * The outlet automatically binds to its parent tha-router or to a specific router
297
+ * identified by the `for` attribute. When the router's active route changes,
298
+ * the outlet clones and renders the route's template content.
299
+ *
300
+ * @example
301
+ * ```html
302
+ * <tha-router>
303
+ * <tha-route path="/"><template><h1>Home</h1></template></tha-route>
304
+ * <tha-router-outlet></tha-router-outlet>
305
+ * </tha-router>
306
+ * ```
307
+ *
308
+ * @example
309
+ * ```html
310
+ * <!-- Bind to a specific router by ID -->
311
+ * <tha-router id="main-router">
312
+ * <tha-route path="/"><template><h1>Home</h1></template></tha-route>
313
+ * </tha-router>
314
+ * <tha-router-outlet for="main-router"></tha-router-outlet>
315
+ * ```
316
+ */
317
+ let ThaRouterOutlet = class ThaRouterOutlet extends SignalWatcherLitElement {
318
+ constructor() {
319
+ super(...arguments);
320
+ /** Weak reference to the bound router instance */
321
+ this.#boundRouter = signal(undefined);
322
+ /** Signal containing weak reference to the route to render */
323
+ this.#routeToRender = signal(null);
324
+ /** Computed signal that extracts the fragment from the route to render */
325
+ this.#fragmentToRender = computed(() => this.#routeToRender.get()?.deref()?.[FRAGMENT].get() ?? null);
326
+ this.#ownParams = computed(() => {
327
+ const router = this.#boundRouter.get()?.deref();
328
+ const route = this.#routeToRender.get()?.deref();
329
+ const pattern = route?.[PATH_PATTERN];
330
+ if (!router || !pattern)
331
+ return null;
332
+ const { location: { pathname } } = router[HISTORY].get();
333
+ return pattern.exec(pathname, 'http://dummy.base')?.pathname.groups ?? null;
334
+ });
335
+ this[_a$1] = computed(() => {
336
+ const ownParams = this.#ownParams.get() ?? {};
337
+ const parent = this.parentElement?.closest('tha-router-outlet');
338
+ const parentParams = parent?.[PARAMS].get() ?? {};
339
+ return Object.freeze({ ...parentParams, ...ownParams });
340
+ });
341
+ this.params = {};
342
+ /** Cleanup function for the fragment update effect */
343
+ this.#fragmentUpdateCleaner = noop;
344
+ /** Cleanup function for the attribute update effect */
345
+ this.#attrUpdateCleaner = noop;
346
+ this.#paramsUpdateCleaner = noop;
347
+ /**
348
+ * The ID of a specific tha-router element to bind to.
349
+ * If not set, binds to the nearest parent tha-router.
350
+ *
351
+ * @attr for
352
+ */
353
+ this.for = null;
354
+ /**
355
+ * Reflects the path attribute of the currently active route.
356
+ * Automatically updated when the active route changes.
357
+ *
358
+ * @attr routepath
359
+ * @readonly
360
+ */
361
+ this.routePath = null;
362
+ /**
363
+ * Reflects the ID of the currently active route.
364
+ * Automatically updated when the active route changes.
365
+ *
366
+ * @attr routeid
367
+ * @readonly
368
+ */
369
+ this.routeID = undefined;
370
+ }
371
+ /** Weak reference to the bound router instance */
372
+ #boundRouter;
373
+ /** Signal containing weak reference to the route to render */
374
+ #routeToRender;
375
+ /** Computed signal that extracts the fragment from the route to render */
376
+ #fragmentToRender;
377
+ #ownParams;
378
+ /** Cleanup function for the fragment update effect */
379
+ #fragmentUpdateCleaner;
380
+ /** Cleanup function for the attribute update effect */
381
+ #attrUpdateCleaner;
382
+ #paramsUpdateCleaner;
383
+ /**
384
+ * Lifecycle callback when the element is connected to the DOM.
385
+ * Initializes the outlet and binds to a router.
386
+ */
387
+ connectedCallback() {
388
+ super.connectedCallback();
389
+ defer(() => {
390
+ this.bindToRouter();
391
+ });
392
+ this.#fragmentUpdateCleaner = this.updateEffect(() => {
393
+ Array.from(this.renderRoot.children).forEach(child => child.remove());
394
+ const fragment = this.#fragmentToRender.get()?.deref() ?? null;
395
+ if (!fragment)
396
+ return;
397
+ this.renderRoot.appendChild(fragment.cloneNode(true));
398
+ });
399
+ this.#attrUpdateCleaner = this.updateEffect(() => {
400
+ const route = this.#routeToRender.get()?.deref() ?? null;
401
+ this.routePath = route?.getAttribute('path') ?? null;
402
+ this.routeID = route?.id ? route?.id : undefined;
403
+ });
404
+ this.#paramsUpdateCleaner = this.updateEffect(() => {
405
+ const params = this[PARAMS].get();
406
+ Array.from(this.attributes)
407
+ .filter(attr => attr.name.startsWith('param-'))
408
+ .filter(attr => !(attr.name.slice(6) in params))
409
+ .forEach(attr => {
410
+ this.removeAttribute(attr.name);
411
+ });
412
+ for (const [key, value] of Object.entries(params)) {
413
+ this.setAttribute(`param-${key}`, value ?? '');
414
+ }
415
+ this.params = params;
416
+ });
417
+ }
418
+ bindToRouter(router) {
419
+ if (!router) {
420
+ if (this.for) {
421
+ const root = this.getRootNode();
422
+ router = root.querySelector(`tha-router#${this.for}`) ?? undefined;
423
+ }
424
+ else {
425
+ router = this.closest('tha-router') ?? undefined;
426
+ }
427
+ }
428
+ const prevRouter = this.#boundRouter?.get()?.deref() ?? null;
429
+ if (prevRouter === router)
430
+ return prevRouter;
431
+ prevRouter?.assignOutlet(null);
432
+ router?.assignOutlet(this);
433
+ this.#boundRouter.set(router ? new WeakRef(router) : undefined);
434
+ return router ?? null;
435
+ }
436
+ /**
437
+ * Internal method called by the router to set the active route.
438
+ * Updates the routeToRender signal which triggers re-rendering.
439
+ *
440
+ * @param route - The route to render, or null to clear
441
+ * @internal
442
+ */
443
+ [(_a$1 = PARAMS, RENDER_ROUTE)](route) {
444
+ this.#routeToRender.set(route ? new WeakRef(route) : null);
445
+ }
446
+ /**
447
+ * Lifecycle callback when the element is disconnected from the DOM.
448
+ * Unbinds from the router and cleans up effects.
449
+ */
450
+ disconnectedCallback() {
451
+ super.disconnectedCallback();
452
+ this.#boundRouter?.get()?.deref()?.assignOutlet(null);
453
+ try {
454
+ this.#fragmentUpdateCleaner();
455
+ this.#attrUpdateCleaner();
456
+ this.#paramsUpdateCleaner();
457
+ }
458
+ catch { /* no-op */ }
459
+ }
460
+ /**
461
+ * Creates the render root for the element.
462
+ * Returns the element itself to render content in light DOM.
463
+ *
464
+ * @returns The element itself (not a shadow root)
465
+ */
466
+ createRenderRoot() {
467
+ return this;
468
+ }
469
+ };
470
+ __decorate([
471
+ state(),
472
+ __metadata("design:type", Object)
473
+ ], ThaRouterOutlet.prototype, "params", void 0);
474
+ __decorate([
475
+ property({ type: String }),
476
+ __metadata("design:type", Object)
477
+ ], ThaRouterOutlet.prototype, "for", void 0);
478
+ __decorate([
479
+ property({ type: String, reflect: true }),
480
+ __metadata("design:type", Object)
481
+ ], ThaRouterOutlet.prototype, "routePath", void 0);
482
+ __decorate([
483
+ property({ type: String, reflect: true }),
484
+ __metadata("design:type", Object)
485
+ ], ThaRouterOutlet.prototype, "routeID", void 0);
486
+ ThaRouterOutlet = __decorate([
487
+ customElement("tha-router-outlet")
488
+ ], ThaRouterOutlet);
489
+
490
+ /**
491
+ * A custom element that manages client-side routing for single-page applications.
492
+ *
493
+ * The router watches for navigation events and matches the current URL against
494
+ * registered routes (tha-route elements), rendering the matching route's content
495
+ * in a tha-router-outlet element.
496
+ *
497
+ * @example
498
+ * ```html
499
+ * <tha-router history="browser">
500
+ * <tha-route path="/">
501
+ * <template><h1>Home</h1></template>
502
+ * </tha-route>
503
+ * <tha-route path="/about">
504
+ * <template><h1>About</h1></template>
505
+ * </tha-route>
506
+ * <tha-router-outlet></tha-router-outlet>
507
+ * </tha-router>
508
+ * ```
509
+ */
510
+ let ThaRouter = class ThaRouter extends HistoryManaged(SignalWatcherLitElement) {
511
+ /**
512
+ * Injects global styles for tha-router elements to hide non-outlet children.
513
+ * Ensures that only tha-router-outlet elements are visible within the router.
514
+ */
515
+ static {
516
+ const styleEl = document.createElement("style");
517
+ styleEl.setAttribute("type", "text/css");
518
+ styleEl.setAttribute("data-id", "tha-router-styles");
519
+ styleEl.textContent = css `
520
+ tha-router {
521
+ & > :not(tha-router-outlet) {
522
+ display: none;
523
+ }
524
+ }
525
+ `.toString();
526
+ document.head.appendChild(styleEl);
527
+ }
528
+ /**
529
+ * Observes changes to child elements to detect when routes are added or removed.
530
+ * Updates the #routeEls signal whenever tha-route children change.
531
+ */
532
+ #routeChildObserver = new MutationObserver((mutations) => {
533
+ const childListMutations = mutations.filter(mutation => mutation.type === 'childList');
534
+ if (!childListMutations.length)
535
+ return;
536
+ this.#routeEls.set(Array.from(this.children).filter(child => child instanceof ThaRoute).map(routeEl => new WeakRef(routeEl)));
537
+ });
538
+ /** Cleanup function for the route children rendering effect */
539
+ #routeChildrenEffectCleaner = noop;
540
+ /** Cleanup function for the history type change effect */
541
+ #historyTypeEffectCleaner = noop;
542
+ /** Cleanup function to remove history listener */
543
+ #historyListenerRemover = noop;
544
+ /** Signal containing weak references to all tha-route children */
545
+ #routeEls = signal([]);
546
+ /** Signal containing weak reference to the currently active route */
547
+ #activeRoute = signal(null);
548
+ /** Signal containing weak reference to the assigned outlet element */
549
+ #outlet = signal(null);
550
+ /**
551
+ * Lifecycle callback when the element is connected to the DOM.
552
+ * Sets up observers, effects, and history listeners.
553
+ */
554
+ connectedCallback() {
555
+ super.connectedCallback();
556
+ // Start observing child route elements
557
+ this.#routeChildObserver.observe(this, { childList: true });
558
+ // Effect to render the active route in the assigned outlet
559
+ this.#routeChildrenEffectCleaner = this.updateEffect(() => {
560
+ const activeRoute = this.#activeRoute.get()?.deref() ?? null;
561
+ const outlet = this.#outlet.get()?.deref() ?? null;
562
+ outlet?.[RENDER_ROUTE](activeRoute);
563
+ });
564
+ // Effect to handle history type changes
565
+ this.#historyTypeEffectCleaner = this.updateEffect(() => {
566
+ const history = this[HISTORY].get();
567
+ this.#historyListenerRemover();
568
+ this.#handleRouteChange({
569
+ location: this[HISTORY].get().location,
570
+ action: 'POP',
571
+ });
572
+ // Set up listener for navigation events
573
+ this.#historyListenerRemover = history ? history.listen(this.#handleRouteChange) : noop;
574
+ });
575
+ // Initial route matching on connect
576
+ defer(() => {
577
+ this.#handleRouteChange({
578
+ location: this[HISTORY].get().location,
579
+ action: 'POP',
580
+ });
581
+ });
582
+ }
583
+ /**
584
+ * Assigns a router outlet to this router.
585
+ * The outlet will be used to render the active route's content.
586
+ *
587
+ * @param outlet - The outlet element to assign, or null to unassign
588
+ * @internal
589
+ */
590
+ assignOutlet(outlet) {
591
+ this.#outlet.set(outlet ? new WeakRef(outlet) : null);
592
+ }
593
+ /**
594
+ * Handles navigation events by matching the new URL against registered routes.
595
+ * Updates the active route signal when a match is found.
596
+ *
597
+ * @param update - The history update containing the new location
598
+ */
599
+ #handleRouteChange = (update) => {
600
+ const routes = this.#routeEls.get()
601
+ .map(weakRef => weakRef.deref())
602
+ .filter(Boolean);
603
+ for (const route of routes) {
604
+ const pathPattern = route[PATH_PATTERN];
605
+ if (pathPattern?.test({ pathname: update.location.pathname })) {
606
+ this.#activeRoute.set(new WeakRef(route));
607
+ return;
608
+ }
609
+ }
610
+ this.#activeRoute.set(null);
611
+ };
612
+ /**
613
+ * Lifecycle callback when the element is disconnected from the DOM.
614
+ * Cleans up all observers, effects, and listeners.
615
+ */
616
+ disconnectedCallback() {
617
+ super.disconnectedCallback();
618
+ try {
619
+ this.#routeChildrenEffectCleaner();
620
+ this.#historyTypeEffectCleaner();
621
+ }
622
+ catch { /* no-op */ }
623
+ this.#routeChildObserver.disconnect();
624
+ this.#historyListenerRemover();
625
+ }
626
+ /**
627
+ * Creates the render root for the element.
628
+ * Returns the element itself to render children in light DOM.
629
+ *
630
+ * @returns The element itself (not a shadow root)
631
+ */
632
+ createRenderRoot() {
633
+ return this;
634
+ }
635
+ };
636
+ ThaRouter = __decorate([
637
+ customElement("tha-router")
638
+ ], ThaRouter);
639
+
640
+ /**
641
+ * A custom element that provides navigation links for client-side routing.
642
+ *
643
+ * The link handles click events to navigate using the History API, preventing
644
+ * full page reloads. It supports absolute paths, relative paths, and special
645
+ * symbols ('back', 'forward') for browser history navigation.
646
+ *
647
+ * The `active` attribute automatically reflects whether the link's path
648
+ * matches the current route, useful for styling active navigation items.
649
+ *
650
+ * @example
651
+ * ```html
652
+ * <!-- Absolute path -->
653
+ * <tha-router-link to="/about">About</tha-router-link>
654
+ *
655
+ * <!-- Relative path -->
656
+ * <tha-router-link to="./details">Details</tha-router-link>
657
+ * <tha-router-link to="../users">Back to Users</tha-router-link>
658
+ *
659
+ * <!-- History navigation -->
660
+ * <tha-router-link to="back">← Back</tha-router-link>
661
+ * <tha-router-link to="forward">Forward →</tha-router-link>
662
+ * ```
663
+ */
664
+ let ThaRouterLink = class ThaRouterLink extends HistoryManaged(SignalWatcherLitElement) {
665
+ constructor() {
666
+ super(...arguments);
667
+ /**
668
+ * The navigation target. Can be:
669
+ * - Absolute path: `/users`, `/about`
670
+ * - Relative path: `./details`, `../users`
671
+ * - History symbol: `back`, `forward`
672
+ *
673
+ * @attr to
674
+ */
675
+ this.to = null;
676
+ /**
677
+ * Reflects whether this link matches the current route.
678
+ * Automatically updated when the route changes.
679
+ *
680
+ * @attr active
681
+ * @readonly
682
+ */
683
+ this.active = false;
684
+ /** Cleanup function for the active state effect */
685
+ this.#activeStateEffectCleaner = noop;
686
+ /** Cleanup function to remove history listener */
687
+ this.#historyListenerRemover = noop;
688
+ /** Signal containing the current 'to' value */
689
+ this.#to = signal(null);
690
+ /** Computed URLPattern for matching against the current route */
691
+ this.#urlPattern = computed(() => {
692
+ const to = this.#to.get();
693
+ if (!to || to === 'back' || to === 'forward')
694
+ return null;
695
+ try {
696
+ return new URLPattern({ pathname: to });
697
+ }
698
+ catch {
699
+ return null;
700
+ }
701
+ });
702
+ /**
703
+ * Handles click events to perform navigation.
704
+ *
705
+ * - For 'back'/'forward', calls the corresponding history method
706
+ * - For relative paths, resolves them against the current location
707
+ * - For absolute paths, navigates directly
708
+ *
709
+ * Prevents default link behavior to avoid full page reloads.
710
+ *
711
+ * @param event - The click event
712
+ */
713
+ this.#handleClick = (event) => {
714
+ const history = this[HISTORY].get();
715
+ console.log(this[HISTORY_TYPE].get());
716
+ if (this.to === 'back')
717
+ return history.back();
718
+ if (this.to === 'forward')
719
+ return history.forward();
720
+ const currentPath = history.location.pathname + history.location.search + history.location.hash;
721
+ let link = this.to;
722
+ if (link?.startsWith('.')) {
723
+ const segments = compact(currentPath.split('/'));
724
+ const linkSegments = compact(link.split('/'));
725
+ for (const segment of linkSegments) {
726
+ if (segment === '..') {
727
+ segments.pop();
728
+ }
729
+ else if (segment !== '.') {
730
+ segments.push(segment);
731
+ }
732
+ }
733
+ link = '/' + segments.join('/');
734
+ }
735
+ link = link?.replaceAll('//', '/');
736
+ this[HISTORY].get()?.push(link || '/');
737
+ };
738
+ }
739
+ /** Injects global styles for tha-router-link elements to show pointer cursor */
740
+ static {
741
+ const styleEl = document.createElement("style");
742
+ styleEl.setAttribute("type", "text/css");
743
+ styleEl.setAttribute("data-id", "tha-router-link-styles");
744
+ styleEl.textContent = css `
745
+ tha-router-link {
746
+ cursor: pointer;
747
+ }
748
+ `.toString();
749
+ document.head.appendChild(styleEl);
750
+ }
751
+ /** Cleanup function for the active state effect */
752
+ #activeStateEffectCleaner;
753
+ /** Cleanup function to remove history listener */
754
+ #historyListenerRemover;
755
+ /** Signal containing the current 'to' value */
756
+ #to;
757
+ /** Computed URLPattern for matching against the current route */
758
+ #urlPattern;
759
+ /**
760
+ * Lifecycle callback when the element is connected to the DOM.
761
+ * Sets up click listener and active state tracking effect.
762
+ */
763
+ connectedCallback() {
764
+ super.connectedCallback();
765
+ this.addEventListener('click', this.#handleClick);
766
+ this.#activeStateEffectCleaner = this.updateEffect(() => {
767
+ const history = this[HISTORY].get();
768
+ const pattern = this.#urlPattern.get();
769
+ this.active = pattern?.test({ pathname: history?.location.pathname ?? '' }) ?? false;
770
+ this.#historyListenerRemover = history?.listen(() => {
771
+ this.active = pattern?.test({ pathname: history.location.pathname }) ?? false;
772
+ }) ?? noop;
773
+ });
774
+ }
775
+ /**
776
+ * Lifecycle callback when an attribute changes.
777
+ * Updates signals when history or to attributes change.
778
+ *
779
+ * @param name - The attribute name that changed
780
+ * @param _old - The old attribute value
781
+ * @param value - The new attribute value
782
+ */
783
+ attributeChangedCallback(name, _old, value) {
784
+ super.attributeChangedCallback(name, _old, value);
785
+ switch (name) {
786
+ case 'to':
787
+ this.#to.set(value);
788
+ break;
789
+ }
790
+ }
791
+ /**
792
+ * Handles click events to perform navigation.
793
+ *
794
+ * - For 'back'/'forward', calls the corresponding history method
795
+ * - For relative paths, resolves them against the current location
796
+ * - For absolute paths, navigates directly
797
+ *
798
+ * Prevents default link behavior to avoid full page reloads.
799
+ *
800
+ * @param event - The click event
801
+ */
802
+ #handleClick;
803
+ /**
804
+ * Lifecycle callback when the element is disconnected from the DOM.
805
+ * Cleans up effects, listeners, and event handlers.
806
+ */
807
+ disconnectedCallback() {
808
+ super.disconnectedCallback();
809
+ try {
810
+ this.#activeStateEffectCleaner();
811
+ }
812
+ catch { }
813
+ this.#historyListenerRemover();
814
+ this.removeEventListener('click', this.#handleClick);
815
+ }
816
+ /**
817
+ * Creates the render root for the element.
818
+ * Returns the element itself to render content in light DOM.
819
+ *
820
+ * @returns The element itself (not a shadow root)
821
+ */
822
+ createRenderRoot() {
823
+ return this;
824
+ }
825
+ };
826
+ __decorate([
827
+ property({ type: String }),
828
+ __metadata("design:type", Object)
829
+ ], ThaRouterLink.prototype, "to", void 0);
830
+ __decorate([
831
+ property({ type: Boolean, reflect: true }),
832
+ __metadata("design:type", Object)
833
+ ], ThaRouterLink.prototype, "active", void 0);
834
+ ThaRouterLink = __decorate([
835
+ customElement("tha-router-link")
836
+ ], ThaRouterLink);
837
+
838
+ /**
839
+ * A custom element for configuring router history settings.
840
+ *
841
+ * This element serves dual purposes depending on its placement in the DOM:
842
+ *
843
+ * ## Global Configuration (placed in `<head>`)
844
+ *
845
+ * When placed in the `<head>` element, it sets the **global default history**
846
+ * for all routers in the application that don't specify their own history or
847
+ * inherit from a parent.
848
+ *
849
+ * ```html
850
+ * <head>
851
+ * <!-- All routers will use hash routing by default -->
852
+ * <tha-router-config history="hash"></tha-router-config>
853
+ * </head>
854
+ * <body>
855
+ * <tha-router>
856
+ * <!-- Uses hash history (global default) -->
857
+ * <tha-route path="/home">...</tha-route>
858
+ * </tha-router>
859
+ * </body>
860
+ * ```
861
+ *
862
+ * ## Local Configuration (placed in `<body>`)
863
+ *
864
+ * When placed in the `<body>` element, it provides history configuration
865
+ * for its **descendant routers only**. This allows different sections of
866
+ * your application to use different history strategies.
867
+ *
868
+ * ```html
869
+ * <body>
870
+ * <!-- Section 1: Hash routing -->
871
+ * <tha-router-config history="hash">
872
+ * <tha-router>
873
+ * <!-- Uses hash history from parent config -->
874
+ * <tha-route path="/dashboard">...</tha-route>
875
+ * </tha-router>
876
+ * </tha-router-config>
877
+ *
878
+ * <!-- Section 2: Memory routing (isolated) -->
879
+ * <tha-router-config history="memory">
880
+ * <tha-router>
881
+ * <!-- Uses memory history from parent config -->
882
+ * <tha-route path="/preview">...</tha-route>
883
+ * </tha-router>
884
+ * </tha-router-config>
885
+ * </body>
886
+ * ```
887
+ *
888
+ * ## Usage Patterns
889
+ *
890
+ * ### Set Global Default
891
+ *
892
+ * Place in `<head>` to configure all routers:
893
+ *
894
+ * ```html
895
+ * <!DOCTYPE html>
896
+ * <html>
897
+ * <head>
898
+ * <tha-router-config history="browser"></tha-router-config>
899
+ * </head>
900
+ * <body>
901
+ * <!-- All routers use browser history -->
902
+ * </body>
903
+ * </html>
904
+ * ```
905
+ *
906
+ * ### Override for Specific Section
907
+ *
908
+ * Use local config to override global default:
909
+ *
910
+ * ```html
911
+ * <head>
912
+ * <!-- Global: browser history -->
913
+ * <tha-router-config history="browser"></tha-router-config>
914
+ * </head>
915
+ * <body>
916
+ * <!-- Main app uses browser history -->
917
+ * <tha-router>...</tha-router>
918
+ *
919
+ * <!-- Admin section uses hash history -->
920
+ * <tha-router-config history="hash">
921
+ * <tha-router>...</tha-router>
922
+ * </tha-router-config>
923
+ * </body>
924
+ * ```
925
+ *
926
+ * ### Isolate Components with Memory History
927
+ *
928
+ * Use named memory history for component isolation:
929
+ *
930
+ * ```html
931
+ * <body>
932
+ * <!-- Each component has independent navigation -->
933
+ * <tha-router-config history="memory:component1">
934
+ * <my-widget>
935
+ * <tha-router>...</tha-router>
936
+ * </my-widget>
937
+ * </tha-router-config>
938
+ *
939
+ * <tha-router-config history="memory:component2">
940
+ * <my-widget>
941
+ * <tha-router>...</tha-router>
942
+ * </my-widget>
943
+ * </tha-router-config>
944
+ * </body>
945
+ * ```
946
+ *
947
+ * ### Testing with Memory History
948
+ *
949
+ * Use memory history to avoid affecting browser URL during tests:
950
+ *
951
+ * ```typescript
952
+ * import { fixture, html } from '@open-wc/testing';
953
+ *
954
+ * it('should navigate', async () => {
955
+ * const el = await fixture(html`
956
+ * <tha-router-config history="memory:test">
957
+ * <tha-router>
958
+ * <tha-route path="/test">Test Page</tha-route>
959
+ * </tha-router>
960
+ * </tha-router-config>
961
+ * `);
962
+ *
963
+ * // Test navigation without affecting browser URL
964
+ * });
965
+ * ```
966
+ *
967
+ * ## History Resolution
968
+ *
969
+ * Router components resolve their history in this order:
970
+ *
971
+ * 1. **Own `history` attribute** (highest priority)
972
+ * 2. **Parent `tha-router-config`** (local configuration)
973
+ * 3. **Global `tha-router-config`** (in `<head>`)
974
+ * 4. **Default** (`"browser"`)
975
+ *
976
+ * ## Best Practices
977
+ *
978
+ * ✅ **DO**: Place one `tha-router-config` in `<head>` for global settings
979
+ *
980
+ * ```html
981
+ * <head>
982
+ * <tha-router-config history="browser"></tha-router-config>
983
+ * </head>
984
+ * ```
985
+ *
986
+ * ✅ **DO**: Use local configs for sections with different routing needs
987
+ *
988
+ * ```html
989
+ * <tha-router-config history="memory">
990
+ * <component-preview>...</component-preview>
991
+ * </tha-router-config>
992
+ * ```
993
+ *
994
+ * ✅ **DO**: Use named memory history for isolated components
995
+ *
996
+ * ```html
997
+ * <tha-router-config history="memory:sidebar">
998
+ * <sidebar-nav>...</sidebar-nav>
999
+ * </tha-router-config>
1000
+ * ```
1001
+ *
1002
+ * ❌ **DON'T**: Place multiple configs in `<head>` (last one wins)
1003
+ *
1004
+ * ```html
1005
+ * <head>
1006
+ * <tha-router-config history="browser"></tha-router-config>
1007
+ * <tha-router-config history="hash"></tha-router-config> <!-- Overrides above -->
1008
+ * </head>
1009
+ * ```
1010
+ *
1011
+ * ❌ **DON'T**: Nest configs unnecessarily (inner configs take precedence)
1012
+ *
1013
+ * ```html
1014
+ * <tha-router-config history="browser">
1015
+ * <tha-router-config history="hash">
1016
+ * <!-- Uses hash, not browser -->
1017
+ * </tha-router-config>
1018
+ * </tha-router-config>
1019
+ * ```
1020
+ */
1021
+ let ThaRouterConfig = class ThaRouterConfig extends HistoryManaged(SignalWatcherLitElement) {
1022
+ /**
1023
+ * Cleanup function for the global history effect.
1024
+ * Only used when the element is placed in `<head>`.
1025
+ * @private
1026
+ */
1027
+ #globalHistoryUnsubscribe = noop;
1028
+ /**
1029
+ * Called when the element is connected to the DOM.
1030
+ *
1031
+ * - If in `<head>`: Sets up a reactive effect to update global history
1032
+ * - If in `<body>`: Only provides history to descendants (no special setup)
1033
+ */
1034
+ connectedCallback() {
1035
+ super.connectedCallback();
1036
+ if (!document.head.contains(this))
1037
+ return;
1038
+ console.log('ThaRouterConfig: Setting global history type to', this[HISTORY_TYPE].get());
1039
+ // Set the global history type when this element is connected in <head>
1040
+ this.#globalHistoryUnsubscribe = this.updateEffect(() => {
1041
+ GLOBAL_HISTORY_TYPE.set(this[HISTORY_TYPE].get());
1042
+ });
1043
+ }
1044
+ /**
1045
+ * Called when the element is disconnected from the DOM.
1046
+ *
1047
+ * Cleans up the global history effect if it was set up.
1048
+ */
1049
+ disconnectedCallback() {
1050
+ super.disconnectedCallback();
1051
+ try {
1052
+ this.#globalHistoryUnsubscribe();
1053
+ }
1054
+ catch { }
1055
+ }
1056
+ /**
1057
+ * Creates the render root for the element.
1058
+ * Returns the element itself to render children in light DOM.
1059
+ *
1060
+ * @returns The element itself (not a shadow root)
1061
+ */
1062
+ createRenderRoot() {
1063
+ return this;
1064
+ }
1065
+ };
1066
+ ThaRouterConfig = __decorate([
1067
+ customElement('tha-router-config')
1068
+ ], ThaRouterConfig);
1069
+
1070
+ /**
1071
+ * @fileoverview Router parameter display component
1072
+ *
1073
+ * Provides a declarative way to display dynamic route parameter values
1074
+ * directly in HTML templates without requiring JavaScript.
1075
+ *
1076
+ * @module router/tha-router-param
1077
+ */
1078
+ /**
1079
+ * Custom element for displaying dynamic route parameter values.
1080
+ *
1081
+ * This component provides a declarative way to access and display URL
1082
+ * parameters extracted from dynamic route segments without writing JavaScript.
1083
+ * It must be used inside a `<tha-router-outlet>` element.
1084
+ *
1085
+ * ## Features
1086
+ *
1087
+ * - **Declarative**: Access params directly in HTML
1088
+ * - **Reactive**: Automatically updates when route changes
1089
+ * - **Hierarchical**: Inherits params from parent outlets
1090
+ * - **Type-safe**: Integrated with TypeScript definitions
1091
+ *
1092
+ * ## Usage
1093
+ *
1094
+ * ### Basic Parameter Display
1095
+ *
1096
+ * ```html
1097
+ * <tha-router>
1098
+ * <tha-route path="/users/:id">
1099
+ * <template>
1100
+ * <h1>User Profile</h1>
1101
+ * <p>User ID: <tha-router-param name="id"></tha-router-param></p>
1102
+ * </template>
1103
+ * </tha-route>
1104
+ * <tha-router-outlet></tha-router-outlet>
1105
+ * </tha-router>
1106
+ * ```
1107
+ *
1108
+ * When navigating to `/users/123`, the component renders: `User ID: 123`
1109
+ *
1110
+ * ### Multiple Parameters
1111
+ *
1112
+ * ```html
1113
+ * <tha-route path="/blog/:year/:month/:slug">
1114
+ * <template>
1115
+ * <article>
1116
+ * <header>
1117
+ * <time>
1118
+ * <tha-router-param name="year"></tha-router-param>-
1119
+ * <tha-router-param name="month"></tha-router-param>
1120
+ * </time>
1121
+ * <h1><tha-router-param name="slug"></tha-router-param></h1>
1122
+ * </header>
1123
+ * </article>
1124
+ * </template>
1125
+ * </tha-route>
1126
+ * ```
1127
+ *
1128
+ * For `/blog/2024/12/hello-world`, renders:
1129
+ * ```html
1130
+ * <time>2024-12</time>
1131
+ * <h1>hello-world</h1>
1132
+ * ```
1133
+ *
1134
+ * ### Nested Routes with Parameter Inheritance
1135
+ *
1136
+ * ```html
1137
+ * <tha-router>
1138
+ * <tha-route path="/projects/:projectId">
1139
+ * <template>
1140
+ * <h1>Project <tha-router-param name="projectId"></tha-router-param></h1>
1141
+ *
1142
+ * <!-- Nested outlet inherits projectId parameter -->
1143
+ * <tha-router-outlet>
1144
+ * <tha-route path="/tasks/:taskId">
1145
+ * <template>
1146
+ * <!-- Both params are available -->
1147
+ * <h2>Task Details</h2>
1148
+ * <p>Project: <tha-router-param name="projectId"></tha-router-param></p>
1149
+ * <p>Task: <tha-router-param name="taskId"></tha-router-param></p>
1150
+ * </template>
1151
+ * </tha-route>
1152
+ * </tha-router-outlet>
1153
+ * </template>
1154
+ * </tha-route>
1155
+ * <tha-router-outlet></tha-router-outlet>
1156
+ * </tha-router>
1157
+ * ```
1158
+ *
1159
+ * ### With Styling
1160
+ *
1161
+ * ```html
1162
+ * <style>
1163
+ * tha-router-param {
1164
+ * font-weight: bold;
1165
+ * color: var(--primary-color);
1166
+ * }
1167
+ *
1168
+ * tha-router-param[name="id"] {
1169
+ * font-family: monospace;
1170
+ * }
1171
+ * </style>
1172
+ *
1173
+ * <tha-route path="/users/:id">
1174
+ * <template>
1175
+ * <span>User: <tha-router-param name="id"></tha-router-param></span>
1176
+ * </template>
1177
+ * </tha-route>
1178
+ * ```
1179
+ *
1180
+ * ## How It Works
1181
+ *
1182
+ * 1. On connection, finds the nearest parent `<tha-router-outlet>`
1183
+ * 2. Accesses the outlet's PARAMS signal containing all route parameters
1184
+ * 3. Computes and displays the value for the specified parameter name
1185
+ * 4. Automatically re-renders when the route (and thus params) change
1186
+ *
1187
+ * ## Error Handling
1188
+ *
1189
+ * Throws an error if not placed within a `<tha-router-outlet>`:
1190
+ *
1191
+ * ```javascript
1192
+ * // ✗ Wrong - not inside outlet
1193
+ * <tha-router-param name="id"></tha-router-param>
1194
+ *
1195
+ * // ✓ Correct - inside outlet
1196
+ * <tha-router-outlet>
1197
+ * <tha-router-param name="id"></tha-router-param>
1198
+ * </tha-router-outlet>
1199
+ * ```
1200
+ *
1201
+ * ## Alternative: Using Attributes
1202
+ *
1203
+ * The parent `<tha-router-outlet>` also exposes parameters as `param-*` attributes,
1204
+ * which can be used as an alternative approach:
1205
+ *
1206
+ * ```html
1207
+ * <tha-router-outlet id="outlet">
1208
+ * <script>
1209
+ * const outlet = document.getElementById('outlet');
1210
+ * // Params available as: outlet.getAttribute('param-id')
1211
+ * </script>
1212
+ * </tha-router-outlet>
1213
+ * ```
1214
+ *
1215
+ * However, `<tha-router-param>` is preferred for declarative templates.
1216
+ *
1217
+ * @example Basic usage
1218
+ * ```html
1219
+ * <tha-router>
1220
+ * <tha-route path="/product/:sku">
1221
+ * <template>
1222
+ * <h1>Product: <tha-router-param name="sku"></tha-router-param></h1>
1223
+ * </template>
1224
+ * </tha-route>
1225
+ * <tha-router-outlet></tha-router-outlet>
1226
+ * </tha-router>
1227
+ * ```
1228
+ *
1229
+ * @example Multiple params with formatting
1230
+ * ```html
1231
+ * <tha-route path="/user/:username/post/:postId">
1232
+ * <template>
1233
+ * <article>
1234
+ * <p>@<tha-router-param name="username"></tha-router-param></p>
1235
+ * <p>Post #<tha-router-param name="postId"></tha-router-param></p>
1236
+ * </article>
1237
+ * </template>
1238
+ * </tha-route>
1239
+ * ```
1240
+ */
1241
+ let ThaRouterParam = class ThaRouterParam extends SignalWatcherLitElement {
1242
+ constructor() {
1243
+ super(...arguments);
1244
+ /**
1245
+ * Signal holding reference to the parent outlet.
1246
+ * Set during connectedCallback.
1247
+ */
1248
+ this.#outlet = signal(null);
1249
+ /**
1250
+ * Signal tracking the parameter name to display.
1251
+ * Updated when the 'name' attribute changes.
1252
+ */
1253
+ this.#name = signal('');
1254
+ /**
1255
+ * Computed signal that extracts the parameter value.
1256
+ * Reactively updates when the outlet's params or name changes.
1257
+ */
1258
+ this.#value = computed(() => this.#outlet.get()?.[PARAMS]?.get()[this.#name.get()]);
1259
+ /**
1260
+ * The name of the route parameter to display.
1261
+ *
1262
+ * Must match a parameter name defined in the route's path pattern.
1263
+ * For example, for path `/users/:id`, use `name="id"`.
1264
+ *
1265
+ * @attr name
1266
+ * @type {string}
1267
+ */
1268
+ this.name = '';
1269
+ }
1270
+ /**
1271
+ * Signal holding reference to the parent outlet.
1272
+ * Set during connectedCallback.
1273
+ */
1274
+ #outlet;
1275
+ /**
1276
+ * Signal tracking the parameter name to display.
1277
+ * Updated when the 'name' attribute changes.
1278
+ */
1279
+ #name;
1280
+ /**
1281
+ * Computed signal that extracts the parameter value.
1282
+ * Reactively updates when the outlet's params or name changes.
1283
+ */
1284
+ #value;
1285
+ /**
1286
+ * Lifecycle callback when element is connected to the DOM.
1287
+ *
1288
+ * Finds the parent `<tha-router-outlet>` and stores a reference.
1289
+ * Throws an error if not used within an outlet.
1290
+ *
1291
+ * @throws {Error} If no parent tha-router-outlet is found
1292
+ */
1293
+ connectedCallback() {
1294
+ super.connectedCallback();
1295
+ const outlet = this.closest('tha-router-outlet');
1296
+ if (!outlet) {
1297
+ throw new Error('<tha-router-param> must be used within a <tha-router-outlet>.');
1298
+ }
1299
+ this.#outlet.set(outlet);
1300
+ }
1301
+ /**
1302
+ * Lifecycle callback when observed attributes change.
1303
+ *
1304
+ * Updates the internal name signal when the 'name' attribute changes,
1305
+ * which triggers the computed value signal to recalculate and re-render.
1306
+ *
1307
+ * @param name - The attribute name that changed
1308
+ * @param _old - Previous attribute value (unused)
1309
+ * @param value - New attribute value
1310
+ */
1311
+ attributeChangedCallback(name, _old, value) {
1312
+ super.attributeChangedCallback(name, _old, value);
1313
+ switch (name) {
1314
+ case 'name':
1315
+ this.#name.set(value ?? '');
1316
+ break;
1317
+ }
1318
+ }
1319
+ /**
1320
+ * Renders the parameter value.
1321
+ *
1322
+ * The value is extracted from the outlet's params signal and
1323
+ * displayed as text content. Automatically updates when the
1324
+ * route changes.
1325
+ *
1326
+ * @returns The parameter value as a template result
1327
+ */
1328
+ render() {
1329
+ return html `${this.#value}`;
1330
+ }
1331
+ };
1332
+ __decorate([
1333
+ property({ type: String }),
1334
+ __metadata("design:type", String)
1335
+ ], ThaRouterParam.prototype, "name", void 0);
1336
+ ThaRouterParam = __decorate([
1337
+ customElement('tha-router-param')
1338
+ ], ThaRouterParam);
1339
+
1340
+ const ACCEPT_DROP_PROP = Symbol('Accept Drop');
1341
+ const REGISTER_HANDLE_PROP = Symbol('Register Handle');
1342
+ const UNREGISTER_HANDLE_PROP = Symbol('Unregister Handle');
1343
+
1344
+ var _a;
1345
+ class ThaDragEvent extends DragEvent {
1346
+ static #DragElementEvents = ['thadrag', 'thadragstart', 'thadragend', 'thadropzoneenter', 'thadropzoneleave', 'thadropzoneover', 'thadropped'];
1347
+ static #DropElementEvents = ['thadrop', 'thadropend', 'thadragenter', 'thadragleave', 'thadragover'];
1348
+ get #target() {
1349
+ if (_a.#DropElementEvents.includes(this.type)) {
1350
+ return this.dropzoneTarget;
1351
+ }
1352
+ else if (_a.#DragElementEvents.includes(this.type)) {
1353
+ return this.dragTarget;
1354
+ }
1355
+ return new WeakRef(this.target);
1356
+ }
1357
+ get name() {
1358
+ return this.#target.deref()?.name;
1359
+ }
1360
+ get dragData() {
1361
+ return this.dragTarget.deref()?.dragData;
1362
+ }
1363
+ constructor(type, { dragTarget, dropzoneTarget }, eventInitDict) {
1364
+ super(type, eventInitDict);
1365
+ this.dragTarget = dragTarget;
1366
+ this.dropzoneTarget = dropzoneTarget;
1367
+ }
1368
+ acceptDrop(rect) {
1369
+ this.dragTarget.deref()?.[ACCEPT_DROP_PROP](this.dropzoneTarget, rect);
1370
+ }
1371
+ }
1372
+ _a = ThaDragEvent;
1373
+
1374
+ var DragElement_1;
1375
+ let DragElement = class DragElement extends LitElement {
1376
+ constructor() {
1377
+ super(...arguments);
1378
+ /**
1379
+ * A record of drag-related data attributes.
1380
+ */
1381
+ this.dragData = {};
1382
+ /**
1383
+ * Pre-drag data used to store the initial state of the element before dragging starts.
1384
+ */
1385
+ this.preDragData = {
1386
+ boundingRect: null,
1387
+ dragStartEvent: null,
1388
+ styles: {
1389
+ pointerEvents: ''
1390
+ }
1391
+ };
1392
+ /**
1393
+ * A weak reference to the currently accepted drop zone.
1394
+ * This is used to track which drop zone the element is currently accepted in.
1395
+ */
1396
+ this.#acceptedDropzone = null;
1397
+ /**
1398
+ * A weak reference to the clone of the element created during dragging.
1399
+ * This is used to manage the clone's lifecycle and properties.
1400
+ */
1401
+ this.#clone = null;
1402
+ /**
1403
+ * A set of drag handles associated with the element.
1404
+ */
1405
+ this.#handles = new Set();
1406
+ /**
1407
+ * The dragging strategy to use for the element.
1408
+ * This determines how the element is dragged (e.g., move or copy).
1409
+ */
1410
+ this.draggingStrategy = 'move';
1411
+ /**
1412
+ * Indicates whether the element is currently being dragged.
1413
+ */
1414
+ this.dragging = false;
1415
+ /**
1416
+ * Indicates whether the drag operation has ended.
1417
+ * This is used to manage the state of the element after dragging.
1418
+ */
1419
+ this.dragend = false;
1420
+ /**
1421
+ * The ID of the drop zone the element is currently over.
1422
+ */
1423
+ this.draggedOver = null;
1424
+ /**
1425
+ * Indicates whether the element has been accepted by a drop zone.
1426
+ * This is used to manage the state of the element during drag-and-drop operations.
1427
+ */
1428
+ this.dropAccepted = false;
1429
+ /**
1430
+ * Handles the drag start event.
1431
+ * @param event The drag event.
1432
+ */
1433
+ this.#handleDragStart = (event) => {
1434
+ if (!this.#shouldHandleEvent(event))
1435
+ return event.preventDefault();
1436
+ // Stop propagation to prevent parent draggable elements from interfering.
1437
+ event.stopPropagation();
1438
+ // Modify base event properties to prevent default behavior and set up drag image.
1439
+ event.dataTransfer?.setDragImage(DragElement_1.TRANSPARENT_IMAGE, 0, 0);
1440
+ event.dataTransfer.effectAllowed = this.draggingStrategy;
1441
+ document.addEventListener('dragover', this.#preventDragOver);
1442
+ // Prepare pre-drag data and styles.
1443
+ this.#preparePreDragData(event);
1444
+ this.#prepareDraggingStyles();
1445
+ defer().then(() => {
1446
+ this.style.pointerEvents = 'none';
1447
+ this.dragging = true;
1448
+ if (this.replaceClone) {
1449
+ const clone = this.#createClone();
1450
+ this.#clone = new WeakRef(clone);
1451
+ this.parentElement.insertBefore(clone, this.nextSibling);
1452
+ }
1453
+ this.dispatchEvent(new ThaDragEvent('thadragstart', { dragTarget: new WeakRef(this) }, event));
1454
+ });
1455
+ };
1456
+ /**
1457
+ * Handles the drag end event.
1458
+ * @param event The drag event.
1459
+ */
1460
+ this.#handleDragEnd = (event) => {
1461
+ document.removeEventListener('dragover', this.#preventDragOver);
1462
+ this.dragend = true;
1463
+ const hasTransition = getComputedStyle(this).transitionDuration.match(/\d*\.?\d+/g)?.map(Number).some(num => num > 0);
1464
+ const clear = () => {
1465
+ if (this.replaceClone)
1466
+ this.clone?.remove();
1467
+ this.style.pointerEvents = this.preDragData.styles.pointerEvents;
1468
+ ['--tha-width', '--tha-height', '--tha-left', '--tha-top', '--tha-x', '--tha-y', '--tha-cx', '--tha-cy'].forEach(prop => {
1469
+ this.style.removeProperty(prop);
1470
+ });
1471
+ ['width', 'height', 'left', 'right', 'top', 'bottom'].forEach(prop => {
1472
+ this.style.removeProperty(`--tha-target-${prop}`);
1473
+ });
1474
+ const acceptedDropzone = this.#acceptedDropzone;
1475
+ const dropAccepted = this.dropAccepted;
1476
+ this.dragging = false;
1477
+ this.dragend = false;
1478
+ this.draggedOver = null;
1479
+ this.dropAccepted = false;
1480
+ this.#acceptedDropzone = null;
1481
+ if (dropAccepted && acceptedDropzone) {
1482
+ acceptedDropzone.deref()?.dispatchEvent(new ThaDragEvent('thadropend', { dragTarget: new WeakRef(this), dropzoneTarget: acceptedDropzone }, event));
1483
+ }
1484
+ this.dispatchEvent(new ThaDragEvent('thadragend', { dragTarget: new WeakRef(this) }, event));
1485
+ };
1486
+ if (hasTransition)
1487
+ this.addEventListener('transitionend', clear, { once: true });
1488
+ else
1489
+ clear();
1490
+ };
1491
+ /**
1492
+ * Handles the drag event.
1493
+ * This updates the position of the element during dragging.
1494
+ * @param event The drag event.
1495
+ */
1496
+ this.#handleDrag = (event) => {
1497
+ const { x, y } = event;
1498
+ this.style.setProperty('--tha-cx', `${x}px`);
1499
+ this.style.setProperty('--tha-cy', `${y}px`);
1500
+ };
1501
+ /**
1502
+ * Handles the drop zone enter event.
1503
+ * This updates the draggedOver property to indicate which drop zone the element is currently over.
1504
+ * @param event The ThaDragEvent for the drop zone enter.
1505
+ */
1506
+ this.#handleDropZoneEnter = (event) => {
1507
+ this.draggedOver = event.dropzoneTarget?.deref()?.name ?? '';
1508
+ };
1509
+ /**
1510
+ * Handles the drop zone leave event.
1511
+ * This clears the draggedOver property when the element leaves a drop zone.
1512
+ * @param event The ThaDragEvent for the drop zone leave.
1513
+ */
1514
+ this.#handleDropZoneLeave = () => {
1515
+ this.draggedOver = null;
1516
+ };
1517
+ }
1518
+ static { DragElement_1 = this; }
1519
+ /**
1520
+ * An observer for monitoring changes to drag-related attributes.
1521
+ */
1522
+ static { this.DRAG_DATA_OBSERVER = new MutationObserver(records => {
1523
+ for (const { attributeName, target } of records) {
1524
+ if (!attributeName?.startsWith('data-drag-'))
1525
+ continue;
1526
+ const element = target;
1527
+ element.dragData[attributeName.replace('data-drag-', '')] = element.getAttribute(attributeName);
1528
+ }
1529
+ }); }
1530
+ static { this.styles = css `
1531
+ :host {
1532
+ --tha-diff-x: calc(var(--tha-cx) - var(--tha-x));
1533
+ --tha-diff-y: calc(var(--tha-cy) - var(--tha-y));
1534
+ }
1535
+
1536
+ :host([draggingstrategy="move"]),
1537
+ :host([draggingstrategy="copyMove"]) {
1538
+ transition-duration: .2s;
1539
+ transition-timing-function: ease-out;
1540
+ transition-property: none;
1541
+ }
1542
+
1543
+ :host([draggingstrategy="move"][dragging]),
1544
+ :host([draggingstrategy="copyMove"][dragging]) {
1545
+ position: fixed;
1546
+ width: var(--tha-width);
1547
+ height: var(--tha-height);
1548
+ left: calc(var(--tha-left) + var(--tha-diff-x) + var(--tha-offset-x));
1549
+ top: calc(var(--tha-top) + var(--tha-diff-y) + var(--tha-offset-y));
1550
+ transform-origin: calc(var(--tha-x) - var(--tha-left)) calc(var(--tha-y) - var(--tha-top));
1551
+ z-index: 100;
1552
+ }
1553
+
1554
+ :host([draggingstrategy="move"][dragend]),
1555
+ :host([draggingstrategy="copyMove"][dragend]) {
1556
+ left: var(--tha-left);
1557
+ top: var(--tha-top);
1558
+ transition-property: all;
1559
+ }
1560
+
1561
+ :host([draggingstrategy="move"][dragend][dropaccepted]),
1562
+ :host([draggingstrategy="copyMove"][dragend][dropaccepted]) {
1563
+ left: var(--tha-target-left);
1564
+ top: var(--tha-target-top);
1565
+ width: var(--tha-target-width);
1566
+ height: var(--tha-target-height);
1567
+ }
1568
+ `; }
1569
+ static {
1570
+ this.TRANSPARENT_IMAGE = new Image(1, 1);
1571
+ this.TRANSPARENT_IMAGE.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==';
1572
+ const style = this.GLOBAL_STYLE = document.createElement('style');
1573
+ style.innerHTML = `
1574
+ @property --tha-offset-x {
1575
+ syntax: '<length>';
1576
+ initial-value: 0px;
1577
+ inherits: true;
1578
+ }
1579
+
1580
+ @property --tha-offset-y {
1581
+ syntax: '<length>';
1582
+ initial-value: 0px;
1583
+ inherits: true;
1584
+ }
1585
+ `;
1586
+ document.head.appendChild(style);
1587
+ }
1588
+ /**
1589
+ * A weak reference to the currently accepted drop zone.
1590
+ * This is used to track which drop zone the element is currently accepted in.
1591
+ */
1592
+ #acceptedDropzone;
1593
+ /**
1594
+ * A weak reference to the clone of the element created during dragging.
1595
+ * This is used to manage the clone's lifecycle and properties.
1596
+ */
1597
+ #clone;
1598
+ /**
1599
+ * A set of drag handles associated with the element.
1600
+ */
1601
+ #handles;
1602
+ /**
1603
+ * Returns the clone of the element if it exists.
1604
+ * This is used to access the clone during drag operations.
1605
+ */
1606
+ get clone() { return this.#clone.deref(); }
1607
+ connectedCallback() {
1608
+ super.connectedCallback();
1609
+ // Set the draggable attribute to true to enable dragging.
1610
+ this.draggable = true;
1611
+ // Set up the drag data attributes observer to monitor changes to drag-related attributes.
1612
+ this.#setUpDragDataAttrs();
1613
+ // Add event listeners for drag events.
1614
+ this.addEventListener('dragstart', this.#handleDragStart);
1615
+ this.addEventListener('dragend', this.#handleDragEnd);
1616
+ this.addEventListener('drag', this.#handleDrag);
1617
+ this.addEventListener('thadropzoneenter', this.#handleDropZoneEnter);
1618
+ this.addEventListener('thadropzoneleave', this.#handleDropZoneLeave);
1619
+ }
1620
+ disconnectedCallback() {
1621
+ super.disconnectedCallback();
1622
+ // Clean up the drag data attributes observer.
1623
+ this.removeEventListener('dragstart', this.#handleDragStart);
1624
+ this.removeEventListener('dragend', this.#handleDragEnd);
1625
+ this.removeEventListener('drag', this.#handleDrag);
1626
+ this.removeEventListener('thadropzoneenter', this.#handleDropZoneEnter);
1627
+ this.removeEventListener('thadropzoneleave', this.#handleDropZoneLeave);
1628
+ }
1629
+ render() {
1630
+ return html$1 `<slot></slot>`;
1631
+ }
1632
+ /**
1633
+ * Accepts a drop zone and an optional rectangle for the drop area.
1634
+ * @param dropzone The drop zone element being accepted.
1635
+ * @param rect The bounding rectangle of the drop area.
1636
+ * @returns
1637
+ */
1638
+ [ACCEPT_DROP_PROP](dropzone, rect) {
1639
+ this.dropAccepted = true;
1640
+ this.#acceptedDropzone = dropzone;
1641
+ if (!rect)
1642
+ return;
1643
+ const { width, height, left, right, top, bottom } = rect;
1644
+ for (const prop in { width, height, left, right, top, bottom }) {
1645
+ this.style.setProperty(`--tha-target-${prop}`, `${rect[prop]}px`);
1646
+ }
1647
+ }
1648
+ /**
1649
+ * Registers a drag handle element.
1650
+ * @param handle The drag handle element to register.
1651
+ */
1652
+ [REGISTER_HANDLE_PROP](handle) {
1653
+ this.#handles.add(handle);
1654
+ }
1655
+ /**
1656
+ * Unregisters a drag handle element.
1657
+ * @param handle The drag handle element to unregister.
1658
+ */
1659
+ [UNREGISTER_HANDLE_PROP](handle) {
1660
+ this.#handles.delete(handle);
1661
+ }
1662
+ /**
1663
+ * Sets up the drag data attributes observer to monitor changes to drag-related attributes.
1664
+ * This allows the element to transfer custom data during drag-and-drop operations.
1665
+ */
1666
+ #setUpDragDataAttrs() {
1667
+ DragElement_1.DRAG_DATA_OBSERVER.observe(this, { attributes: true });
1668
+ for (const { name, value } of Object.values(this.attributes).filter(attr => attr.name.startsWith('data-drag-'))) {
1669
+ this.dragData[name.replace('data-drag-', '')] = value;
1670
+ }
1671
+ }
1672
+ /**
1673
+ * Handles the drag start event.
1674
+ * @param event The drag event.
1675
+ */
1676
+ #handleDragStart;
1677
+ /**
1678
+ * Handles the drag end event.
1679
+ * @param event The drag event.
1680
+ */
1681
+ #handleDragEnd;
1682
+ /**
1683
+ * Handles the drag event.
1684
+ * This updates the position of the element during dragging.
1685
+ * @param event The drag event.
1686
+ */
1687
+ #handleDrag;
1688
+ /**
1689
+ * Handles the drop zone enter event.
1690
+ * This updates the draggedOver property to indicate which drop zone the element is currently over.
1691
+ * @param event The ThaDragEvent for the drop zone enter.
1692
+ */
1693
+ #handleDropZoneEnter;
1694
+ /**
1695
+ * Handles the drop zone leave event.
1696
+ * This clears the draggedOver property when the element leaves a drop zone.
1697
+ * @param event The ThaDragEvent for the drop zone leave.
1698
+ */
1699
+ #handleDropZoneLeave;
1700
+ /**
1701
+ * Creates a clone of the element for dragging.
1702
+ * This clone is used to visually represent the element during drag operations.
1703
+ * @returns The cloned element.
1704
+ */
1705
+ #createClone() {
1706
+ const container = document.createElement('tha-drag-clone');
1707
+ Object.values(this.attributes)
1708
+ .filter(attr => !['dragging', 'replaceclone', 'draggable'].includes(attr.name))
1709
+ .forEach(attr => {
1710
+ container.attributes.setNamedItem(attr.cloneNode());
1711
+ });
1712
+ this.childNodes.forEach(node => {
1713
+ container.appendChild(node.cloneNode(true));
1714
+ });
1715
+ return container;
1716
+ }
1717
+ /**
1718
+ * Prepares the pre-drag data, including the bounding rectangle and styles.
1719
+ * This data is used to restore the element's state after dragging.
1720
+ * @param event The drag event.
1721
+ */
1722
+ #preparePreDragData(event) {
1723
+ this.preDragData.boundingRect = this.getBoundingClientRect();
1724
+ this.preDragData.dragStartEvent = event;
1725
+ this.preDragData.styles.pointerEvents = this.style.pointerEvents;
1726
+ }
1727
+ /**
1728
+ * Prepares the styles for dragging, including the position and size of the element.
1729
+ * This is used to update the element's position during drag operations.
1730
+ */
1731
+ #prepareDraggingStyles() {
1732
+ const { boundingRect: { width, height, left, top }, dragStartEvent: { x, y } } = this.preDragData;
1733
+ const props = { width, height, left, top, x, y };
1734
+ for (const prop in props) {
1735
+ this.style.setProperty(`--tha-${prop}`, `${props[prop]}px`);
1736
+ }
1737
+ }
1738
+ /**
1739
+ * Prevents the default dragover behavior to allow custom drag-and-drop handling.
1740
+ * @param event The drag event.
1741
+ */
1742
+ #preventDragOver(event) {
1743
+ event.preventDefault();
1744
+ }
1745
+ /**
1746
+ * Checks if the element should handle the drag event based on the target.
1747
+ * If there are no handles, it returns true to allow the event.
1748
+ * If there are handles, it checks if the event target is one of the handles.
1749
+ * @param event The drag event.
1750
+ * @returns True if the element should handle the event, false otherwise.
1751
+ */
1752
+ #shouldHandleEvent(event) {
1753
+ if (this.disabled)
1754
+ return false;
1755
+ if (!this.#handles.size)
1756
+ return true;
1757
+ if (this.#handles.has(event.target))
1758
+ return true;
1759
+ return false;
1760
+ }
1761
+ };
1762
+ __decorate([
1763
+ property({ type: String }),
1764
+ __metadata("design:type", String)
1765
+ ], DragElement.prototype, "name", void 0);
1766
+ __decorate([
1767
+ property({ type: String, reflect: true }),
1768
+ __metadata("design:type", String)
1769
+ ], DragElement.prototype, "draggingStrategy", void 0);
1770
+ __decorate([
1771
+ property({ type: String }),
1772
+ __metadata("design:type", String)
1773
+ ], DragElement.prototype, "dragGroup", void 0);
1774
+ __decorate([
1775
+ property({ type: Boolean }),
1776
+ __metadata("design:type", Boolean)
1777
+ ], DragElement.prototype, "replaceClone", void 0);
1778
+ __decorate([
1779
+ property({ type: Boolean, reflect: true }),
1780
+ __metadata("design:type", Object)
1781
+ ], DragElement.prototype, "dragging", void 0);
1782
+ __decorate([
1783
+ property({ type: Boolean, reflect: true }),
1784
+ __metadata("design:type", Object)
1785
+ ], DragElement.prototype, "dragend", void 0);
1786
+ __decorate([
1787
+ property({ type: String, reflect: true }),
1788
+ __metadata("design:type", Object)
1789
+ ], DragElement.prototype, "draggedOver", void 0);
1790
+ __decorate([
1791
+ property({ type: Boolean, reflect: true }),
1792
+ __metadata("design:type", Object)
1793
+ ], DragElement.prototype, "dropAccepted", void 0);
1794
+ __decorate([
1795
+ property({ type: Boolean, reflect: true }),
1796
+ __metadata("design:type", Boolean)
1797
+ ], DragElement.prototype, "disabled", void 0);
1798
+ DragElement = DragElement_1 = __decorate([
1799
+ customElement('tha-drag')
1800
+ ], DragElement);
1801
+
1802
+ let LAST_DRAG_EVENT;
1803
+ document.addEventListener('thadragstart', event => {
1804
+ LAST_DRAG_EVENT = event;
1805
+ });
1806
+ let DropZoneElement = class DropZoneElement extends LitElement {
1807
+ constructor() {
1808
+ super(...arguments);
1809
+ this.#enterCount = 0;
1810
+ this.accept = [];
1811
+ this.name = '';
1812
+ this.itemDragged = null;
1813
+ this.acceptableDrag = false;
1814
+ this.#handleGlobalDragStart = (event) => {
1815
+ if (!this.accept.length || this.accept.includes(event.name)) {
1816
+ this.acceptableDrag = true;
1817
+ }
1818
+ };
1819
+ this.#handleGlobalDragEnd = () => {
1820
+ this.itemDragged = null;
1821
+ this.acceptableDrag = false;
1822
+ this.#enterCount = 0;
1823
+ };
1824
+ this.#handleDragEnter = (event) => {
1825
+ if (!this.#isAcceptableDrag())
1826
+ return;
1827
+ if (++this.#enterCount > 1)
1828
+ return;
1829
+ this.itemDragged = LAST_DRAG_EVENT.name ?? '';
1830
+ this.#dispatchEventWithCounter('thadragenter', 'thadropzoneenter', event);
1831
+ };
1832
+ this.#handleDragLeave = (event) => {
1833
+ if (!this.#isAcceptableDrag())
1834
+ return;
1835
+ if (--this.#enterCount > 0)
1836
+ return;
1837
+ this.itemDragged = null;
1838
+ this.#dispatchEventWithCounter('thadragleave', 'thadropzoneleave', event);
1839
+ };
1840
+ this.#handleDragOver = (event) => {
1841
+ if (!this.#isAcceptableDrag())
1842
+ return;
1843
+ this.#dispatchEventWithCounter('thadragover', 'thadropzoneover', event);
1844
+ };
1845
+ this.#handleDrop = (event) => {
1846
+ if (!this.#isAcceptableDrag())
1847
+ return;
1848
+ this.#dispatchEventWithCounter('thadrop', 'thadropped', event);
1849
+ };
1850
+ }
1851
+ static { this.styles = css ``; }
1852
+ #enterCount;
1853
+ render() {
1854
+ return html$1 `<slot></slot>`;
1855
+ }
1856
+ connectedCallback() {
1857
+ super.connectedCallback();
1858
+ document.addEventListener('thadragstart', this.#handleGlobalDragStart);
1859
+ document.addEventListener('thadragend', this.#handleGlobalDragEnd);
1860
+ document.addEventListener('thadropend', this.#handleGlobalDragEnd);
1861
+ this.addEventListener('dragenter', this.#handleDragEnter);
1862
+ this.addEventListener('dragleave', this.#handleDragLeave);
1863
+ this.addEventListener('dragover', this.#handleDragOver);
1864
+ this.addEventListener('drop', this.#handleDrop);
1865
+ }
1866
+ disconnectedCallback() {
1867
+ super.disconnectedCallback();
1868
+ document.removeEventListener('thadragstart', this.#handleGlobalDragStart);
1869
+ document.removeEventListener('thadragend', this.#handleGlobalDragEnd);
1870
+ document.removeEventListener('thadropend', this.#handleGlobalDragEnd);
1871
+ this.removeEventListener('dragenter', this.#handleDragEnter);
1872
+ this.removeEventListener('dragleave', this.#handleDragLeave);
1873
+ this.removeEventListener('dragover', this.#handleDragOver);
1874
+ this.removeEventListener('drop', this.#handleDrop);
1875
+ }
1876
+ #handleGlobalDragStart;
1877
+ #handleGlobalDragEnd;
1878
+ #handleDragEnter;
1879
+ #handleDragLeave;
1880
+ #handleDragOver;
1881
+ #handleDrop;
1882
+ #isAcceptableDrag() {
1883
+ return !LAST_DRAG_EVENT.name || !this.accept.length || this.accept.includes(LAST_DRAG_EVENT.name);
1884
+ }
1885
+ #dispatchEventWithCounter(eventName, counterEventName, event) {
1886
+ const { dragTarget } = LAST_DRAG_EVENT;
1887
+ const dropzoneTarget = new WeakRef(this);
1888
+ this.dispatchEvent(new ThaDragEvent(eventName, { dragTarget, dropzoneTarget }, event));
1889
+ dragTarget.deref()?.dispatchEvent(new ThaDragEvent(counterEventName, { dragTarget, dropzoneTarget }, event));
1890
+ }
1891
+ };
1892
+ __decorate([
1893
+ property({ converter: value => (value ?? '').split(',').map(str => str.trim()) }),
1894
+ __metadata("design:type", Array)
1895
+ ], DropZoneElement.prototype, "accept", void 0);
1896
+ __decorate([
1897
+ property({ type: String }),
1898
+ __metadata("design:type", Object)
1899
+ ], DropZoneElement.prototype, "name", void 0);
1900
+ __decorate([
1901
+ property({ type: String, reflect: true }),
1902
+ __metadata("design:type", Object)
1903
+ ], DropZoneElement.prototype, "itemDragged", void 0);
1904
+ __decorate([
1905
+ property({ type: Boolean, reflect: true }),
1906
+ __metadata("design:type", Object)
1907
+ ], DropZoneElement.prototype, "acceptableDrag", void 0);
1908
+ DropZoneElement = __decorate([
1909
+ customElement('tha-dropzone')
1910
+ ], DropZoneElement);
1911
+
1912
+ let DragHandleElement = class DragHandleElement extends LitElement {
1913
+ get #parent() {
1914
+ for (const parent of getParents(this)) {
1915
+ if (parent instanceof DragElement) {
1916
+ return parent;
1917
+ }
1918
+ }
1919
+ return null;
1920
+ }
1921
+ connectedCallback() {
1922
+ super.connectedCallback();
1923
+ this.draggable = true;
1924
+ this.#parent?.[REGISTER_HANDLE_PROP](this);
1925
+ }
1926
+ disconnectedCallback() {
1927
+ super.disconnectedCallback();
1928
+ this.#parent?.[UNREGISTER_HANDLE_PROP](this);
1929
+ }
1930
+ render() {
1931
+ return html$1 `<slot></slot>`;
1932
+ }
1933
+ };
1934
+ DragHandleElement = __decorate([
1935
+ customElement("tha-drag-handle")
1936
+ ], DragHandleElement);
1937
+
1938
+ export { DragElement, DragHandleElement, DropZoneElement, ThaDragEvent, ThaRoute, ThaRouter, ThaRouterConfig, ThaRouterLink, ThaRouterOutlet, ThaRouterParam };
1939
+ //# sourceMappingURL=elements.mjs.map