@ramstack/alpinegear-main 1.0.0-preview.1

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.
@@ -0,0 +1,659 @@
1
+ function create_getter(evaluate_later, ...args) {
2
+ const evaluate = evaluate_later(...args);
3
+ return () => {
4
+ let result;
5
+ evaluate(v => result = v);
6
+ return has_getter(result) ? result.get() : result;
7
+ };
8
+ }
9
+
10
+ function create_setter(evaluate_later, ...args) {
11
+ const evaluate = evaluate_later(...args);
12
+ args[args.length - 1] = `${ args.at(-1) } = __val`;
13
+ const set = evaluate_later(...args);
14
+
15
+ return value => {
16
+ let result;
17
+ evaluate(v => result = v);
18
+
19
+ if (has_setter(result)) {
20
+ result.set(value);
21
+ }
22
+ else {
23
+ set(() => { }, {
24
+ scope: {
25
+ __val: value
26
+ }
27
+ });
28
+ }
29
+ };
30
+ }
31
+
32
+ function has_getter(value) {
33
+ return typeof value?.get === "function";
34
+ }
35
+
36
+ function has_setter(value) {
37
+ return typeof value?.set === "function";
38
+ }
39
+
40
+ const key = Symbol();
41
+ let observable;
42
+
43
+ function observe_resize(el, listener) {
44
+ observable ??= new ResizeObserver(entries => {
45
+ for (const e of entries) {
46
+ for (const callback of e.target[key]?.values() ?? []) {
47
+ callback(e);
48
+ }
49
+ }
50
+ });
51
+
52
+ el[key] ??= new Set();
53
+ el[key].add(listener);
54
+
55
+ observable.observe(el);
56
+
57
+ return () => {
58
+ el[key].delete(listener);
59
+
60
+ if (!el[key].size) {
61
+ observable.unobserve(el);
62
+ el[key] = null;
63
+ }
64
+ };
65
+ }
66
+
67
+ const warn = (...args) => console.warn("alpine-gear.js:", ...args);
68
+ const is_array = Array.isArray;
69
+ const is_nullish = value => value === null || value === undefined;
70
+ const is_checkable_input = el => el.type === "checkbox" || el.type === "radio";
71
+ const is_numeric_input = el => el.type === "number" || el.type === "range";
72
+ const is_template = el => el instanceof HTMLTemplateElement;
73
+ const is_element = el => el.nodeType === Node.ELEMENT_NODE;
74
+ const as_array = value => is_array(value) ? value : [value];
75
+ const loose_equal = (a, b) => a == b;
76
+ const loose_index_of = (array, value) => array.findIndex(v => v == value);
77
+ const has_modifier = (modifiers, modifier) => modifiers.includes(modifier);
78
+
79
+ function assert(value, message) {
80
+ if (!value) {
81
+ throw new Error(message);
82
+ }
83
+ }
84
+
85
+ const listen = (target, type, listener, options) => {
86
+ target.addEventListener(type, listener, options);
87
+ return () => target.removeEventListener(type, listener, options);
88
+ };
89
+
90
+ const clone = value =>
91
+ typeof value === "object"
92
+ ? JSON.parse(JSON.stringify(value))
93
+ : value;
94
+
95
+ const closest = (el, callback) => {
96
+ while (el && !callback(el)) {
97
+ el = (el._x_teleportBack ?? el).parentElement;
98
+ }
99
+
100
+ return el;
101
+ };
102
+
103
+ const create_map = keys => new Map(
104
+ keys.split(",").map(v => [v.trim().toLowerCase(), v.trim()]));
105
+
106
+ function watch(get_value, callback, options = null) {
107
+ assert(Alpine, "Alpine is not defined.");
108
+
109
+ const {
110
+ effect,
111
+ release
112
+ } = Alpine;
113
+
114
+ let new_value;
115
+ let old_value;
116
+ let initialized = false;
117
+
118
+ const handle = effect(() => {
119
+ new_value = get_value();
120
+
121
+ if (!initialized) {
122
+ options?.deep && JSON.stringify(new_value);
123
+ old_value = new_value;
124
+ }
125
+
126
+ if (initialized || (options?.immediate ?? true)) {
127
+
128
+ setTimeout(() => {
129
+ callback(new_value, old_value);
130
+ old_value = new_value;
131
+ }, 0);
132
+ }
133
+
134
+ initialized = true;
135
+ });
136
+
137
+ return () => release(handle);
138
+ }
139
+
140
+ const canonical_names = create_map(
141
+ "value,checked,files," +
142
+ "innerHTML,innerText,textContent," +
143
+ "videoHeight,videoWidth," +
144
+ "naturalHeight,naturalWidth," +
145
+ "clientHeight,clientWidth,offsetHeight,offsetWidth," +
146
+ "open," +
147
+ "group");
148
+
149
+ function plugin$5({ directive, entangle, evaluateLater, mapAttributes, mutateDom, prefixed }) {
150
+
151
+
152
+
153
+
154
+ mapAttributes(attr => ({
155
+ name: attr.name.replace(/^&/, prefixed("bound:")),
156
+ value: attr.value
157
+ }));
158
+
159
+ directive("bound", (el, { expression, value, modifiers }, { effect, cleanup }) => {
160
+ if (!value) {
161
+ warn("x-bound directive expects the presence of a bound property name.");
162
+ return;
163
+ }
164
+
165
+ const tag_name = el.tagName.toUpperCase();
166
+
167
+ expression = expression?.trim();
168
+
169
+
170
+
171
+ const property_name = canonical_names.get(value.trim().replace("-", "").toLowerCase());
172
+
173
+ // if the expression is omitted, then we assume it corresponds
174
+ // to the bound property name, allowing us to write expressions more concisely,
175
+ // and write &value instead of &value="value"
176
+ expression ||= property_name;
177
+
178
+ const get_value = create_getter(evaluateLater, el, expression);
179
+ const set_value = create_setter(evaluateLater, el, expression);
180
+
181
+ const update_property = () => loose_equal(el[property_name], get_value()) || mutateDom(() => el[property_name] = get_value());
182
+ const update_variable = () => set_value(is_numeric_input(el) ? to_number(el[property_name]) : el[property_name]);
183
+
184
+ let processed;
185
+
186
+ switch (property_name) {
187
+ case "value":
188
+ process_value();
189
+ break;
190
+
191
+ case "checked":
192
+ process_checked();
193
+ break;
194
+
195
+ case "files":
196
+ process_files();
197
+ break;
198
+
199
+ case "innerHTML":
200
+ case "innerText":
201
+ case "textContent":
202
+ process_contenteditable();
203
+ break;
204
+
205
+ case "videoHeight":
206
+ case "videoWidth":
207
+ process_media_resize("VIDEO", "resize");
208
+ break;
209
+
210
+ case "naturalHeight":
211
+ case "naturalWidth":
212
+ process_media_resize("IMG", "load");
213
+ break;
214
+
215
+ case "clientHeight":
216
+ case "clientWidth":
217
+ case "offsetHeight":
218
+ case "offsetWidth":
219
+ process_dimensions();
220
+ break;
221
+
222
+ case "open":
223
+ process_details();
224
+ break;
225
+
226
+ case "group":
227
+ process_group();
228
+ break;
229
+ }
230
+
231
+ if (!processed) {
232
+ const modifier =
233
+ has_modifier(modifiers, "in") ? "in" :
234
+ has_modifier(modifiers, "out") ? "out" : "inout";
235
+
236
+ const source_el = expression === value
237
+ ? closest(el.parentNode, node => node._x_dataStack)
238
+ : el;
239
+
240
+ if (!el._x_dataStack) {
241
+ warn("x-bound directive requires the presence of the x-data directive to bind component properties.");
242
+ return;
243
+ }
244
+
245
+ if (!source_el) {
246
+ warn(`x-bound directive cannot find the parent scope where the '${ value }' property is defined.`);
247
+ return;
248
+ }
249
+
250
+ const source = {
251
+ get: create_getter(evaluateLater, source_el, expression),
252
+ set: create_setter(evaluateLater, source_el, expression),
253
+ };
254
+
255
+ const target = {
256
+ get: create_getter(evaluateLater, el, value),
257
+ set: create_setter(evaluateLater, el, value),
258
+ };
259
+
260
+ switch (modifier) {
261
+ case "in":
262
+ cleanup(watch(() => source.get(), v => target.set(clone(v))));
263
+ break;
264
+ case "out":
265
+ cleanup(watch(() => target.get(), v => source.set(clone(v))));
266
+ break;
267
+ default:
268
+ cleanup(entangle(source, target));
269
+ break;
270
+ }
271
+ }
272
+
273
+ function process_value() {
274
+ switch (tag_name) {
275
+ case "INPUT":
276
+ case "TEXTAREA":
277
+
278
+
279
+ is_nullish(get_value()) && update_variable();
280
+
281
+ effect(update_property);
282
+ cleanup(listen(el, "input", update_variable));
283
+
284
+ processed = true;
285
+ break;
286
+
287
+ case "SELECT":
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+ queueMicrotask(() => {
296
+
297
+
298
+ is_nullish(get_value()) && update_variable();
299
+
300
+ effect(() => apply_select_values(el, as_array(get_value() ?? [])));
301
+ cleanup(listen(el, "change", () => set_value(collect_selected_values(el))));
302
+ });
303
+
304
+ processed = true;
305
+ break;
306
+ }
307
+ }
308
+
309
+ function process_checked() {
310
+ if (is_checkable_input(el)) {
311
+ effect(update_property);
312
+ cleanup(listen(el, "change", update_variable));
313
+ processed = true;
314
+ }
315
+ }
316
+
317
+ function process_files() {
318
+ if (el.type === "file") {
319
+ cleanup(listen(el, "input", update_variable));
320
+ processed = true;
321
+ }
322
+ }
323
+
324
+ function process_contenteditable() {
325
+ if (el.contentEditable === "true") {
326
+ is_nullish(get_value()) && update_variable();
327
+
328
+ effect(update_property);
329
+ cleanup(listen(el, "input", update_variable));
330
+ processed = true;
331
+ }
332
+ }
333
+
334
+ function process_media_resize(name, event_name) {
335
+ if (tag_name === name) {
336
+ update_variable();
337
+ cleanup(listen(el, event_name, update_variable));
338
+ processed = true;
339
+ }
340
+ }
341
+
342
+ function process_dimensions() {
343
+ cleanup(observe_resize(el, update_variable));
344
+ processed = true;
345
+ }
346
+
347
+ function process_details() {
348
+ if (tag_name === "DETAILS") {
349
+
350
+
351
+ is_nullish(get_value()) && update_variable();
352
+
353
+ effect(update_property);
354
+ cleanup(listen(el, "toggle", update_variable));
355
+ processed = true;
356
+ }
357
+ }
358
+
359
+ function process_group() {
360
+ if (is_checkable_input(el)) {
361
+ el.name || mutateDom(() => el.name = expression);
362
+
363
+ effect(() =>
364
+ mutateDom(() =>
365
+ apply_group_values(el, get_value() ?? [])));
366
+
367
+ cleanup(listen(el, "input", () => set_value(collect_group_values(el, get_value()))));
368
+ processed = true;
369
+ }
370
+ }
371
+ });
372
+ }
373
+
374
+ function to_number(value) {
375
+ return value === "" ? null : +value;
376
+ }
377
+
378
+ function apply_select_values(el, values) {
379
+ for (const option of el.options) {
380
+ option.selected = loose_index_of(values, option.value) >= 0;
381
+ }
382
+ }
383
+
384
+ function collect_selected_values(el) {
385
+ if (el.multiple) {
386
+ return [...el.selectedOptions].map(o => o.value);
387
+ }
388
+
389
+ return el.value;
390
+ }
391
+
392
+ function apply_group_values(el, values) {
393
+ el.checked = is_array(values)
394
+ ? loose_index_of(values, el.value) >= 0
395
+ : loose_equal(el.value, values);
396
+ }
397
+
398
+ function collect_group_values(el, values) {
399
+ if (el.type === "radio") {
400
+ return el.value;
401
+ }
402
+
403
+ values = as_array(values);
404
+ const index = loose_index_of(values, el.value);
405
+
406
+ if (el.checked) {
407
+ index >= 0 || values.push(el.value);
408
+ }
409
+ else {
410
+ index >= 0 && values.splice(index, 1);
411
+ }
412
+
413
+ return values;
414
+ }
415
+
416
+ function plugin$4({ directive, mutateDom }) {
417
+ directive("format", (el, { modifiers }, { effect, evaluateLater }) => {
418
+ const cache = new Map;
419
+ const placeholder_regex = /{{(?<expr>.+?)}}/g;
420
+ const is_once = has_modifier(modifiers, "once");
421
+
422
+ process(el);
423
+
424
+ function get_eval_fn(expression) {
425
+ let getter = cache.get(expression);
426
+ if (is_nullish(getter)) {
427
+ getter = create_getter(evaluateLater, expression);
428
+ cache.set(expression, getter);
429
+ }
430
+
431
+ return getter;
432
+ }
433
+
434
+ function update(callback) {
435
+ if (is_once) {
436
+ mutateDom(() => callback());
437
+ cache.clear();
438
+ }
439
+ else {
440
+ effect(() => mutateDom(() => callback()));
441
+ }
442
+ }
443
+
444
+ function process(node) {
445
+ switch (node.nodeType) {
446
+ case Node.TEXT_NODE:
447
+ process_text_node(node);
448
+ break;
449
+
450
+ case Node.ELEMENT_NODE:
451
+ process_nodes(node);
452
+ process_attributes(node);
453
+ break;
454
+ }
455
+ }
456
+
457
+ function process_text_node(node) {
458
+ const tokens = node.textContent.split(placeholder_regex);
459
+
460
+ if (tokens.length > 1) {
461
+ const fragment = new DocumentFragment();
462
+
463
+ for (let i = 0; i < tokens.length; i++) {
464
+ if ((i % 2) === 0) {
465
+ fragment.appendChild(document.createTextNode(tokens[i]));
466
+ }
467
+ else {
468
+ const get_value = get_eval_fn(tokens[i]);
469
+ const text = document.createTextNode("");
470
+
471
+ fragment.append(text);
472
+ update(() => text.textContent = get_value());
473
+ }
474
+ }
475
+
476
+ mutateDom(() =>
477
+ node.parentElement.replaceChild(fragment, node));
478
+ }
479
+ }
480
+
481
+ function process_attributes(node) {
482
+ for (let attr of node.attributes) {
483
+ const matches = [...attr.value.matchAll(placeholder_regex)];
484
+ if (matches.length) {
485
+ const template = attr.value;
486
+ update(() => attr.value = template.replace(placeholder_regex, (_, expr) => get_eval_fn(expr)()));
487
+ }
488
+ }
489
+ }
490
+
491
+ function process_nodes(node) {
492
+ for (let child of node.childNodes) {
493
+ process(child);
494
+ }
495
+ }
496
+ });
497
+ }
498
+
499
+ function anchor_block(el, template, { addScopeToNode, cleanup, initTree, mutateDom, scope = {} }) {
500
+ if (el._r_block) {
501
+ return;
502
+ }
503
+
504
+ initialize();
505
+
506
+ let nodes = is_template(template)
507
+ ? [...template.content.cloneNode(true).childNodes]
508
+ : [template.cloneNode(true)];
509
+
510
+ mutateDom(() => {
511
+ for (let node of nodes) {
512
+ is_element(node) && addScopeToNode(node, scope, el);
513
+ el.parentElement.insertBefore(node, el);
514
+ is_element(node) && initTree(node);
515
+ }
516
+ });
517
+
518
+ el._r_block = {
519
+ template,
520
+ update() {
521
+ mutateDom(() => {
522
+ for (let node of nodes ?? []) {
523
+ el.parentElement.insertBefore(node, el);
524
+ }
525
+ });
526
+ },
527
+ delete() {
528
+ el._r_block = null;
529
+ for (let node of nodes ?? []) {
530
+ node.remove();
531
+ }
532
+ nodes = null;
533
+ }
534
+ };
535
+
536
+ cleanup(() => el._r_block?.delete());
537
+ }
538
+
539
+ function initialize() {
540
+ document.body._r_block ??= (() => {
541
+ const observer = new MutationObserver(mutations => {
542
+ for (let mutation of mutations) {
543
+ for (let node of mutation.addedNodes) {
544
+ node._r_block?.update();
545
+ }
546
+ }
547
+ });
548
+
549
+ observer.observe(document.body, { childList: true, subtree: true });
550
+ return observer;
551
+ })();
552
+ }
553
+
554
+ function plugin$3({ addScopeToNode, directive, initTree, mutateDom }) {
555
+ directive("fragment", (el, {}, { cleanup }) => {
556
+ if (!is_template(el)) {
557
+ warn("x-fragment can only be used on a 'template' tag.");
558
+ return;
559
+ }
560
+
561
+ anchor_block(el, el, { addScopeToNode, cleanup, initTree, mutateDom });
562
+ });
563
+ }
564
+
565
+ function plugin$2({ addScopeToNode, directive, initTree, mutateDom }) {
566
+ directive("match", (el, { }, { cleanup, effect, evaluateLater }) => {
567
+ if (!is_template(el)) {
568
+ warn("x-match can only be used on a 'template' tag.");
569
+ return;
570
+ }
571
+
572
+ const branches = [];
573
+ const has_default_case = () => branches.some(b => b.default);
574
+
575
+ for (let node of el.content.children) {
576
+ const expr = node.getAttribute("x-case");
577
+ if (expr !== null) {
578
+ has_default_case() && warn("The x-case directive cannot be appear after x-default.");
579
+ branches.push({ el: node, get_value: create_getter(evaluateLater, expr) });
580
+ }
581
+ else if (node.hasAttribute("x-default")) {
582
+ has_default_case() && warn("Only one x-default directive is allowed.");
583
+ branches.push({ el: node, get_value: () => true, default: true });
584
+ }
585
+ else {
586
+ warn("Element has no x-case or x-default directive and will be ignored.", node);
587
+ }
588
+ }
589
+
590
+ const activate = branch => {
591
+ if (el._r_block?.template !== branch.el) {
592
+ clear();
593
+ anchor_block(el, branch.el, {
594
+ addScopeToNode,
595
+ cleanup,
596
+ initTree,
597
+ mutateDom
598
+ });
599
+ }
600
+ };
601
+
602
+ const clear = () => el._r_block?.delete();
603
+
604
+ effect(() => {
605
+ let active;
606
+
607
+ for (let branch of branches) {
608
+ if (branch.get_value() && !active) {
609
+ active = branch;
610
+ }
611
+ }
612
+
613
+ active ? activate(active) : clear();
614
+ });
615
+ });
616
+ }
617
+
618
+ function plugin$1(alpine) {
619
+ alpine.directive("template", (el, { expression }) => {
620
+ if (is_template(el)) {
621
+ warn("x-template cannot be used on a 'template' tag.");
622
+ return;
623
+ }
624
+
625
+ const tpl = document.getElementById(expression);
626
+
627
+ if (!is_template(tpl)) {
628
+ warn("x-template directive can only reference the template tag.");
629
+ return;
630
+ }
631
+
632
+
633
+
634
+
635
+
636
+
637
+ queueMicrotask(() => {
638
+ el.innerHTML = "";
639
+ el.append(tpl.content.cloneNode(true));
640
+ });
641
+ });
642
+ }
643
+
644
+ function plugin({ addScopeToNode, directive, initTree, mutateDom }) {
645
+ directive("when", (el, { expression }, { cleanup, effect, evaluateLater }) => {
646
+ if (!is_template(el)) {
647
+ warn("x-when can only be used on a 'template' tag.");
648
+ return;
649
+ }
650
+
651
+ const activate = () => anchor_block(el, el, { addScopeToNode, cleanup, initTree, mutateDom });
652
+ const clear = () => el._r_block?.delete();
653
+
654
+ const get = create_getter(evaluateLater, expression);
655
+ effect(() => get() ? activate() : clear());
656
+ });
657
+ }
658
+
659
+ export { plugin$5 as bound, plugin$4 as format, plugin$3 as fragment, plugin$2 as match, plugin$1 as template, plugin as when };
@@ -0,0 +1 @@
1
+ function e(e,...t){const n=e(...t);return()=>{let e;return n((t=>e=t)),t=e,"function"==typeof t?.get?e.get():e;var t}}function t(e,...t){const n=e(...t);t[t.length-1]=`${t.at(-1)} = __val`;const o=e(...t);return e=>{let t;n((e=>t=e)),function(e){return"function"==typeof e?.set}(t)?t.set(e):o((()=>{}),{scope:{__val:e}})}}const n=Symbol();let o;const a=(...e)=>console.warn("alpine-gear.js:",...e),r=Array.isArray,c=e=>null==e,i=e=>"checkbox"===e.type||"radio"===e.type,l=e=>e instanceof HTMLTemplateElement,u=e=>e.nodeType===Node.ELEMENT_NODE,s=e=>r(e)?e:[e],d=(e,t)=>e==t,f=(e,t)=>e.findIndex((e=>e==t)),p=(e,t)=>e.includes(t),m=(e,t,n,o)=>(e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)),v=e=>"object"==typeof e?JSON.parse(JSON.stringify(e)):e;function h(e,t,n=null){const{effect:o,release:a}=Alpine;let r,c,i=!1;const l=o((()=>{r=e(),i||(n?.deep&&JSON.stringify(r),c=r),(i||(n?.immediate??1))&&setTimeout((()=>{t(r,c),c=r}),0),i=!0}));return()=>a(l)}const b=new Map("value,checked,files,innerHTML,innerText,textContent,videoHeight,videoWidth,naturalHeight,naturalWidth,clientHeight,clientWidth,offsetHeight,offsetWidth,open,group".split(",").map((e=>[e.trim().toLowerCase(),e.trim()])));function g({directive:l,entangle:u,evaluateLater:g,mapAttributes:T,mutateDom:_,prefixed:k}){T((e=>({name:e.name.replace(/^&/,k("bound:")),value:e.value}))),l("bound",((l,{expression:T,value:k,modifiers:x},{effect:N,cleanup:y})=>{if(!k)return void a("x-bound directive expects the presence of a bound property name.");const E=l.tagName.toUpperCase();T=T?.trim();const w=b.get(k.trim().replace("-","").toLowerCase());T||=w;const L=e(g,l,T),S=t(g,l,T),D=()=>d(l[w],L())||_((()=>l[w]=L())),H=()=>S((e=>"number"===e.type||"range"===e.type)(l)?function(e){return""===e?null:+e}(l[w]):l[w]);let M;switch(w){case"value":!function(){switch(E){case"INPUT":case"TEXTAREA":c(L())&&H(),N(D),y(m(l,"input",H)),M=!0;break;case"SELECT":queueMicrotask((()=>{c(L())&&H(),N((()=>function(e,t){for(const n of e.options)n.selected=f(t,n.value)>=0}(l,s(L()??[])))),y(m(l,"change",(()=>S(function(e){return e.multiple?[...e.selectedOptions].map((e=>e.value)):e.value}(l)))))})),M=!0}}();break;case"checked":i(l)&&(N(D),y(m(l,"change",H)),M=!0);break;case"files":"file"===l.type&&(y(m(l,"input",H)),M=!0);break;case"innerHTML":case"innerText":case"textContent":"true"===l.contentEditable&&(c(L())&&H(),N(D),y(m(l,"input",H)),M=!0);break;case"videoHeight":case"videoWidth":A("VIDEO","resize");break;case"naturalHeight":case"naturalWidth":A("IMG","load");break;case"clientHeight":case"clientWidth":case"offsetHeight":case"offsetWidth":y(function(e,t){return o??=new ResizeObserver((e=>{for(const t of e)for(const e of t.target[n]?.values()??[])e(t)})),e[n]??=new Set,e[n].add(t),o.observe(e),()=>{e[n].delete(t),e[n].size||(o.unobserve(e),e[n]=null)}}(l,H)),M=!0;break;case"open":"DETAILS"===E&&(c(L())&&H(),N(D),y(m(l,"toggle",H)),M=!0);break;case"group":i(l)&&(l.name||_((()=>l.name=T)),N((()=>_((()=>function(e,t){e.checked=r(t)?f(t,e.value)>=0:d(e.value,t)}(l,L()??[]))))),y(m(l,"input",(()=>S(function(e,t){if("radio"===e.type)return e.value;t=s(t);const n=f(t,e.value);return e.checked?n>=0||t.push(e.value):n>=0&&t.splice(n,1),t}(l,L()))))),M=!0)}if(!M){const n=p(x,"in")?"in":p(x,"out")?"out":"inout",o=T===k?(e=>{for(;e&&!e._x_dataStack;)e=(e._x_teleportBack??e).parentElement;return e})(l.parentNode):l;if(!l._x_dataStack)return void a("x-bound directive requires the presence of the x-data directive to bind component properties.");if(!o)return void a(`x-bound directive cannot find the parent scope where the '${k}' property is defined.`);const r={get:e(g,o,T),set:t(g,o,T)},c={get:e(g,l,k),set:t(g,l,k)};switch(n){case"in":y(h((()=>r.get()),(e=>c.set(v(e)))));break;case"out":y(h((()=>c.get()),(e=>r.set(v(e)))));break;default:y(u(r,c))}}function A(e,t){E===e&&(H(),y(m(l,t,H)),M=!0)}}))}function T({directive:t,mutateDom:n}){t("format",((t,{modifiers:o},{effect:a,evaluateLater:r})=>{const i=new Map,l=/{{(?<expr>.+?)}}/g,u=p(o,"once");function s(t){let n=i.get(t);return c(n)&&(n=e(r,t),i.set(t,n)),n}function d(e){u?(n((()=>e())),i.clear()):a((()=>n((()=>e()))))}!function e(t){switch(t.nodeType){case Node.TEXT_NODE:!function(e){const t=e.textContent.split(l);if(t.length>1){const o=new DocumentFragment;for(let e=0;t.length>e;e++)if(e%2==0)o.appendChild(document.createTextNode(t[e]));else{const n=s(t[e]),a=document.createTextNode("");o.append(a),d((()=>a.textContent=n()))}n((()=>e.parentElement.replaceChild(o,e)))}}(t);break;case Node.ELEMENT_NODE:!function(t){for(let n of t.childNodes)e(n)}(t),function(e){for(let t of e.attributes)if([...t.value.matchAll(l)].length){const e=t.value;d((()=>t.value=e.replace(l,((e,t)=>s(t)()))))}}(t)}}(t)}))}function _(e,t,{addScopeToNode:n,cleanup:o,initTree:a,mutateDom:r,scope:c={}}){if(e._r_block)return;document.body._r_block??=(()=>{const e=new MutationObserver((e=>{for(let t of e)for(let e of t.addedNodes)e._r_block?.update()}));return e.observe(document.body,{childList:!0,subtree:!0}),e})();let i=l(t)?[...t.content.cloneNode(!0).childNodes]:[t.cloneNode(!0)];r((()=>{for(let t of i)u(t)&&n(t,c,e),e.parentElement.insertBefore(t,e),u(t)&&a(t)})),e._r_block={template:t,update(){r((()=>{for(let t of i??[])e.parentElement.insertBefore(t,e)}))},delete(){e._r_block=null;for(let e of i??[])e.remove();i=null}},o((()=>e._r_block?.delete()))}function k({addScopeToNode:e,directive:t,initTree:n,mutateDom:o}){t("fragment",((t,{},{cleanup:r})=>{l(t)?_(t,t,{addScopeToNode:e,cleanup:r,initTree:n,mutateDom:o}):a("x-fragment can only be used on a 'template' tag.")}))}function x({addScopeToNode:t,directive:n,initTree:o,mutateDom:r}){n("match",((n,{},{cleanup:c,effect:i,evaluateLater:u})=>{if(!l(n))return void a("x-match can only be used on a 'template' tag.");const s=[];for(let t of n.content.children){const n=t.getAttribute("x-case");null!==n?s.push({el:t,get_value:e(u,n)}):t.hasAttribute("x-default")&&s.push({el:t,get_value:()=>!0,default:!0})}const d=()=>n._r_block?.delete();i((()=>{let e;for(let t of s)t.get_value()&&!e&&(e=t);var a;e?(a=e,n._r_block?.template!==a.el&&(d(),_(n,a.el,{addScopeToNode:t,cleanup:c,initTree:o,mutateDom:r}))):d()}))}))}function N(e){e.directive("template",((e,{expression:t})=>{if(l(e))return void a("x-template cannot be used on a 'template' tag.");const n=document.getElementById(t);l(n)?queueMicrotask((()=>{e.innerHTML="",e.append(n.content.cloneNode(!0))})):a("x-template directive can only reference the template tag.")}))}function y({addScopeToNode:t,directive:n,initTree:o,mutateDom:r}){n("when",((n,{expression:c},{cleanup:i,effect:u,evaluateLater:s})=>{if(!l(n))return void a("x-when can only be used on a 'template' tag.");const d=e(s,c);u((()=>d()?_(n,n,{addScopeToNode:t,cleanup:i,initTree:o,mutateDom:r}):n._r_block?.delete()))}))}export{g as bound,T as format,k as fragment,x as match,N as template,y as when};