@oscarpalmer/abydon 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,45 +1,45 @@
1
1
  // node_modules/@oscarpalmer/atoms/dist/js/string/index.mjs
2
- var getString = function(value) {
3
- if (typeof value === "string") {
4
- return value;
2
+ function getString(value2) {
3
+ if (typeof value2 === "string") {
4
+ return value2;
5
5
  }
6
- if (typeof value !== "object" || value == null) {
7
- return String(value);
6
+ if (typeof value2 !== "object" || value2 == null) {
7
+ return String(value2);
8
8
  }
9
- const valueOff = value.valueOf?.() ?? value;
9
+ const valueOff = value2.valueOf?.() ?? value2;
10
10
  const asString = valueOff?.toString?.() ?? String(valueOff);
11
- return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
12
- };
11
+ return asString.startsWith("[object ") ? JSON.stringify(value2) : asString;
12
+ }
13
13
  // node_modules/@oscarpalmer/atoms/dist/js/is.mjs
14
- var isNullableOrWhitespace = function(value) {
15
- return value == null || /^\s*$/.test(getString(value));
16
- };
14
+ function isNullableOrWhitespace(value2) {
15
+ return value2 == null || /^\s*$/.test(getString(value2));
16
+ }
17
17
 
18
18
  // src/helpers/index.ts
19
- function isFragment(value) {
20
- return typeof value === "object" && value != null && "$fragment" in value && value.$fragment === true;
19
+ function isFragment(value2) {
20
+ return typeof value2 === "object" && value2 != null && "$fragment" in value2 && value2.$fragment === true;
21
21
  }
22
- function isFragmentElement(value) {
23
- return value instanceof HTMLElement || value instanceof SVGElement;
22
+ function isFragmentElement(value2) {
23
+ return value2 instanceof HTMLElement || value2 instanceof SVGElement;
24
24
  }
25
- function isFragmentNode(value) {
26
- return value instanceof Comment || value instanceof Element || value instanceof Text;
25
+ function isFragmentNode(value2) {
26
+ return value2 instanceof Comment || value2 instanceof Element || value2 instanceof Text;
27
27
  }
28
28
 
29
29
  // src/helpers/dom.ts
30
- function createNodes(value) {
31
- if (isFragmentNode(value)) {
32
- return [value];
30
+ function createNodes(value2) {
31
+ if (isFragmentNode(value2)) {
32
+ return [value2];
33
33
  }
34
- if (isFragment(value)) {
35
- return value.get();
34
+ if (isFragment(value2)) {
35
+ return value2.get();
36
36
  }
37
- return [new Text(getString(value))];
37
+ return [new Text(getString(value2))];
38
38
  }
39
39
  function createTemplate(html) {
40
- const template = document.createElement("template");
41
- template.innerHTML = html;
42
- const cloned = template.content.cloneNode(true);
40
+ const template2 = document.createElement("template");
41
+ template2.innerHTML = html;
42
+ const cloned = template2.content.cloneNode(true);
43
43
  const scripts = [
44
44
  ...cloned instanceof Element ? cloned.querySelectorAll("script") : []
45
45
  ];
@@ -65,7 +65,7 @@ function replaceNodes(from, to) {
65
65
  }
66
66
  }
67
67
 
68
- // node_modules/@oscarpalmer/sentinel/node_modules/@oscarpalmer/atoms/dist/js/queue.mjs
68
+ // node_modules/@oscarpalmer/atoms/dist/js/queue.mjs
69
69
  if (globalThis._atomic_queued == null) {
70
70
  const queued = new Set;
71
71
  Object.defineProperty(globalThis, "_atomic_queued", {
@@ -86,51 +86,52 @@ if (globalThis._sentinels == null) {
86
86
  }
87
87
 
88
88
  // node_modules/@oscarpalmer/sentinel/dist/effect.mjs
89
- var effect = function(callback) {
90
- const state = {
91
- callback,
92
- active: false,
93
- reactives: new Set
94
- };
95
- const instance = Object.create({
96
- start() {
97
- if (!state.active) {
98
- state.active = true;
99
- const index = globalThis._sentinels.push(state) - 1;
100
- state.callback();
101
- globalThis._sentinels.splice(index, 1);
102
- }
103
- },
104
- stop() {
105
- if (state.active) {
106
- state.active = false;
107
- for (const reactive of state.reactives) {
108
- reactive.callbacks.any.delete(state);
109
- for (const [key, keyed] of reactive.callbacks.values) {
110
- keyed.delete(state);
111
- if (keyed.size === 0) {
112
- reactive.callbacks.keys.delete(key);
113
- }
89
+ function effect(callback) {
90
+ return new Effect(callback);
91
+ }
92
+ class Effect {
93
+ $sentinel = "effect";
94
+ state;
95
+ constructor(callback) {
96
+ this.state = {
97
+ callback,
98
+ active: false,
99
+ reactives: new Set
100
+ };
101
+ this.start();
102
+ }
103
+ start() {
104
+ if (!this.state.active) {
105
+ this.state.active = true;
106
+ const index = globalThis._sentinels.push(this.state) - 1;
107
+ this.state.callback();
108
+ globalThis._sentinels.splice(index, 1);
109
+ }
110
+ }
111
+ stop() {
112
+ if (this.state.active) {
113
+ this.state.active = false;
114
+ for (const reactive of this.state.reactives) {
115
+ reactive.callbacks.any.delete(this.state);
116
+ for (const [key, keyed] of reactive.callbacks.values) {
117
+ keyed.delete(this.state);
118
+ if (keyed.size === 0) {
119
+ reactive.callbacks.keys.delete(key);
114
120
  }
115
121
  }
116
- state.reactives.clear();
117
122
  }
123
+ this.state.reactives.clear();
118
124
  }
119
- });
120
- Object.defineProperty(instance, "$sentinel", {
121
- value: "effect"
122
- });
123
- instance.start();
124
- return instance;
125
- };
125
+ }
126
+ }
126
127
 
127
128
  // node_modules/@oscarpalmer/sentinel/dist/helpers/is.mjs
128
- var isReactive = function(value) {
129
- return isSentinel(value, /^array|computed|signal|store$/i);
130
- };
131
- var isSentinel = function(value, expression) {
132
- return expression.test(value?.$sentinel ?? "");
133
- };
129
+ function isReactive(value2) {
130
+ return isSentinel(value2, /^array|computed|signal|store$/i);
131
+ }
132
+ function isSentinel(value2, expression) {
133
+ return expression.test(value2?.$sentinel ?? "");
134
+ }
134
135
 
135
136
  // node_modules/@oscarpalmer/sentinel/dist/helpers/value.mjs
136
137
  var arrayOperations = new Set([
@@ -148,49 +149,45 @@ var arrayOperations = new Set([
148
149
  // node_modules/@oscarpalmer/sentinel/dist/reactive/index.mjs
149
150
  var primitives = new Set(["boolean", "number", "string"]);
150
151
 
151
- // src/node/value.ts
152
- function setReactiveNode(comment, reactive3) {
153
- const text = new Text;
154
- let nodes;
155
- effect(() => {
156
- const value10 = reactive3.get();
157
- if (isFragment(value10) || isFragmentNode(value10)) {
158
- const next = createNodes(value10);
159
- if (nodes == null) {
160
- if (comment.parentNode != null) {
161
- replaceNodes([comment], next);
162
- } else if (text.parentNode != null) {
163
- replaceNodes([text], next);
164
- }
165
- } else {
166
- replaceNodes(nodes, next);
167
- }
168
- nodes = next;
169
- return;
170
- }
171
- const isNullable = isNullableOrWhitespace(value10);
172
- text.textContent = getString(value10);
173
- if (nodes != null) {
174
- replaceNodes(nodes, [isNullable ? comment : text]);
175
- } else if (isNullable && comment.parentNode == null) {
176
- text.replaceWith(comment);
177
- } else if (!isNullable && text.parentNode == null) {
178
- comment.replaceWith(text);
179
- }
180
- nodes = undefined;
181
- });
182
- }
183
-
184
152
  // src/node/event.ts
185
- function mapEvent(element, name, value10) {
153
+ function getOptions(options) {
154
+ const parts = options.split(":");
155
+ return {
156
+ capture: parts.includes("c") || parts.includes("capture"),
157
+ once: parts.includes("o") || parts.includes("once"),
158
+ passive: !parts.includes("a") && !parts.includes("active")
159
+ };
160
+ }
161
+ function mapEvent(element, name, value9) {
186
162
  element.removeAttribute(name);
187
- if (typeof value10 !== "function") {
188
- return;
163
+ const [, type, options] = /^@(\w+)(?::([a-z:]+))?$/.exec(name) ?? [];
164
+ if (typeof value9 === "function" && type != null) {
165
+ element.addEventListener(type, value9, getOptions(options ?? ""));
189
166
  }
190
167
  }
191
168
 
192
169
  // node_modules/@oscarpalmer/atoms/dist/js/element/closest.mjs
193
- var closest = function(origin, selector, context) {
170
+ function calculateDistance(origin, target) {
171
+ if (origin === target || origin.parentElement === target) {
172
+ return 0;
173
+ }
174
+ const comparison = origin.compareDocumentPosition(target);
175
+ const children = [...origin.parentElement?.children ?? []];
176
+ switch (true) {
177
+ case children.includes(target):
178
+ return Math.abs(children.indexOf(origin) - children.indexOf(target));
179
+ case !!(comparison & 2 || comparison & 8):
180
+ return traverse(origin, target);
181
+ case !!(comparison & 4 || comparison & 16):
182
+ return traverse(target, origin);
183
+ default:
184
+ return -1;
185
+ }
186
+ }
187
+ function closest(origin, selector, context) {
188
+ if (origin.matches(selector)) {
189
+ return [origin];
190
+ }
194
191
  const elements = [...(context ?? document).querySelectorAll(selector)];
195
192
  const { length } = elements;
196
193
  if (length === 0) {
@@ -213,22 +210,8 @@ var closest = function(origin, selector, context) {
213
210
  });
214
211
  }
215
212
  return minimum == null ? [] : distances.filter((found) => found.distance === minimum).map((found) => found.element);
216
- };
217
- var calculateDistance = function(origin, target) {
218
- const comparison = origin.compareDocumentPosition(target);
219
- const children = [...origin.parentElement?.children ?? []];
220
- switch (true) {
221
- case children.includes(target):
222
- return Math.abs(children.indexOf(origin) - children.indexOf(target));
223
- case !!(comparison & 2 || comparison & 8):
224
- return traverse(origin, target);
225
- case !!(comparison & 4 || comparison & 16):
226
- return traverse(target, origin);
227
- default:
228
- return -1;
229
- }
230
- };
231
- var traverse = function(from, to) {
213
+ }
214
+ function traverse(from, to) {
232
215
  const children = [...to.children];
233
216
  if (children.includes(from)) {
234
217
  return children.indexOf(from) + 1;
@@ -253,94 +236,94 @@ var traverse = function(from, to) {
253
236
  parent = parent.parentElement;
254
237
  }
255
238
  return -1e6;
256
- };
239
+ }
257
240
  // src/node/attribute/value.ts
258
- function setAttribute(element2, name, value10) {
241
+ function setAttribute(element2, name, value9) {
259
242
  element2.removeAttribute(name);
260
243
  switch (true) {
261
244
  case classPattern.test(name):
262
- setClasses(element2, name, value10);
245
+ setClasses(element2, name, value9);
263
246
  return;
264
247
  case stylePattern.test(name):
265
- setStyle(element2, name, value10);
248
+ setStyle(element2, name, value9);
266
249
  return;
267
250
  default:
268
- setValue2(element2, name, value10);
251
+ setValue3(element2, name, value9);
269
252
  break;
270
253
  }
271
254
  }
272
- var setClasses = function(element2, name, value10) {
273
- function update(value11) {
274
- if (/^(|true)$/.test(getString(value11))) {
255
+ function setClasses(element2, name, value9) {
256
+ function update(value10) {
257
+ if (/^(|true)$/.test(getString(value10))) {
275
258
  element2.classList.add(...classes);
276
259
  } else {
277
260
  element2.classList.remove(...classes);
278
261
  }
279
262
  }
280
263
  const classes = name.slice(6).split(".");
281
- if (isReactive(value10)) {
264
+ if (isReactive(value9)) {
282
265
  effect(() => {
283
- update(value10.get());
266
+ update(value9.get());
284
267
  });
285
268
  } else {
286
- update(value10);
269
+ update(value9);
287
270
  }
288
- };
289
- var setStyle = function(element2, name, value10) {
290
- function update(value11) {
291
- if (value11 == null || value11 === false || value11 === true && unit == null) {
271
+ }
272
+ function setStyle(element2, name, value9) {
273
+ function update(value10) {
274
+ if (value10 == null || value10 === false || value10 === true && unit == null) {
292
275
  element2.style.removeProperty(property);
293
276
  } else {
294
- element2.style.setProperty(property, value11 === true ? unit : getString(value11));
277
+ element2.style.setProperty(property, value10 === true ? unit : getString(value10));
295
278
  }
296
279
  }
297
280
  const [, property, unit] = /^\w+\.([a-z-]+)(?:\.(\w+))?$/i.exec(name) ?? [];
298
281
  if (property == null) {
299
282
  return;
300
283
  }
301
- if (isReactive(value10)) {
284
+ if (isReactive(value9)) {
302
285
  effect(() => {
303
- update(value10.get());
286
+ update(value9.get());
304
287
  });
305
288
  } else {
306
- update(value10);
289
+ update(value9);
307
290
  }
308
- };
309
- var setValue2 = function(element2, name, value10) {
291
+ }
292
+ function setValue3(element2, name, value9) {
310
293
  const callback = booleanAttributes.has(name) && name in element2 ? name === "selected" ? updateSelected(element2) : updateProperty : updateAttribute;
311
- if (isReactive(value10)) {
294
+ if (isReactive(value9)) {
312
295
  effect(() => {
313
- callback(element2, name, value10.get());
296
+ callback(element2, name, value9.get());
314
297
  });
315
298
  } else {
316
- callback(element2, name, value10);
299
+ callback(element2, name, value9);
317
300
  }
318
- };
319
- var triggerSelectChange = function(select) {
301
+ }
302
+ function triggerSelectChange(select) {
320
303
  if (select != null) {
321
304
  select.dispatchEvent(new Event("change", { bubbles: true }));
322
305
  }
323
- };
324
- var updateAttribute = function(element2, name, value10) {
325
- if (value10 == null) {
306
+ }
307
+ function updateAttribute(element2, name, value9) {
308
+ if (value9 == null) {
326
309
  element2.removeAttribute(name);
327
310
  } else {
328
- element2.setAttribute(name, getString(value10));
311
+ element2.setAttribute(name, getString(value9));
329
312
  }
330
- };
331
- var updateProperty = function(element2, name, value10) {
332
- element2[name] = /^(|true)$/.test(getString(value10));
333
- };
334
- var updateSelected = function(element2) {
313
+ }
314
+ function updateProperty(element2, name, value9) {
315
+ element2[name] = /^(|true)$/.test(getString(value9));
316
+ }
317
+ function updateSelected(element2) {
335
318
  const select = closest(element2, "select")[0];
336
319
  const options = [...select?.options ?? []];
337
- return (element3, name, value10) => {
320
+ return (element3, name, value9) => {
338
321
  if (select != null && options.includes(element3)) {
339
322
  triggerSelectChange(select);
340
323
  }
341
- updateProperty(element3, name, value10);
324
+ updateProperty(element3, name, value9);
342
325
  };
343
- };
326
+ }
344
327
  var booleanAttributes = new Set([
345
328
  "checked",
346
329
  "disabled",
@@ -356,23 +339,23 @@ var classPattern = /^class\./;
356
339
  var stylePattern = /^style\./;
357
340
 
358
341
  // src/node/attribute/index.ts
359
- var getValue2 = function(data2, original) {
342
+ function getValue3(data2, original) {
360
343
  const matches = commentExpression.exec(original ?? "");
361
344
  return matches == null ? original : data2.values[+matches[1]];
362
- };
363
- function isBadAttribute(name, value11) {
364
- return /^on/i.test(name) || /^(href|src|xlink:href)$/i.test(name) && /(data:text\/html|javascript:)/i.test(value11);
345
+ }
346
+ function isBadAttribute(name, value10) {
347
+ return /^on/i.test(name) || /^(href|src|xlink:href)$/i.test(name) && /(data:text\/html|javascript:)/i.test(value10);
365
348
  }
366
349
  function mapAttributes(data2, element2) {
367
350
  const attributes = [...element2.attributes];
368
351
  const { length } = attributes;
369
352
  for (let index = 0;index < length; index += 1) {
370
- const { name, value: value11 } = attributes[index];
371
- if (isBadAttribute(name, value11)) {
353
+ const { name, value: value10 } = attributes[index];
354
+ if (isBadAttribute(name, value10)) {
372
355
  element2.removeAttribute(name);
373
356
  continue;
374
357
  }
375
- const actual = getValue2(data2, value11);
358
+ const actual = getValue3(data2, value10);
376
359
  if (name.startsWith("@")) {
377
360
  mapEvent(element2, name, actual);
378
361
  } else if (name.includes(".") || isReactive(actual)) {
@@ -380,26 +363,59 @@ function mapAttributes(data2, element2) {
380
363
  }
381
364
  }
382
365
  }
383
- var mapValue = function(element2, name, value11) {
366
+ function mapValue(element2, name, value10) {
384
367
  switch (true) {
385
- case typeof value11 === "function":
386
- mapValue(element2, name, value11());
368
+ case typeof value10 === "function":
369
+ mapValue(element2, name, value10());
387
370
  return;
388
371
  default:
389
- setAttribute(element2, name, value11);
372
+ setAttribute(element2, name, value10);
390
373
  break;
391
374
  }
392
- };
375
+ }
393
376
  var commentExpression = /^<!--abydon\.(\d+)-->$/;
394
377
 
378
+ // src/node/value.ts
379
+ function setReactiveNode(comment, reactive3) {
380
+ const text = new Text;
381
+ let nodes;
382
+ effect(() => {
383
+ const value10 = reactive3.get();
384
+ if (isFragment(value10) || isFragmentNode(value10)) {
385
+ const next = createNodes(value10);
386
+ if (nodes == null) {
387
+ if (comment.parentNode != null) {
388
+ replaceNodes([comment], next);
389
+ } else if (text.parentNode != null) {
390
+ replaceNodes([text], next);
391
+ }
392
+ } else {
393
+ replaceNodes(nodes, next);
394
+ }
395
+ nodes = next;
396
+ return;
397
+ }
398
+ const isNullable = isNullableOrWhitespace(value10);
399
+ text.textContent = getString(value10);
400
+ if (nodes != null) {
401
+ replaceNodes(nodes, [isNullable ? comment : text]);
402
+ } else if (isNullable && comment.parentNode == null) {
403
+ text.replaceWith(comment);
404
+ } else if (!isNullable && text.parentNode == null) {
405
+ comment.replaceWith(text);
406
+ }
407
+ nodes = undefined;
408
+ });
409
+ }
410
+
395
411
  // src/node/index.ts
396
- var mapNode = function(data2, comment) {
412
+ function mapNode(data2, comment) {
397
413
  const matches = commentExpression2.exec(comment.textContent ?? "");
398
- const value12 = matches == null ? null : data2.values[+matches[1]];
399
- if (value12 != null) {
400
- mapValue2(comment, value12);
414
+ const value11 = matches == null ? null : data2.values[+matches[1]];
415
+ if (value11 != null) {
416
+ mapValue2(comment, value11);
401
417
  }
402
- };
418
+ }
403
419
  function mapNodes(data2, nodes) {
404
420
  const { length } = nodes;
405
421
  for (let index = 0;index < length; index += 1) {
@@ -416,59 +432,56 @@ function mapNodes(data2, nodes) {
416
432
  }
417
433
  }
418
434
  }
419
- var mapValue2 = function(comment, value12) {
435
+ function mapValue2(comment, value11) {
420
436
  switch (true) {
421
- case typeof value12 === "function":
422
- mapValue2(comment, value12());
437
+ case typeof value11 === "function":
438
+ mapValue2(comment, value11());
423
439
  return;
424
- case isReactive(value12):
425
- setReactiveNode(comment, value12);
440
+ case isReactive(value11):
441
+ setReactiveNode(comment, value11);
426
442
  break;
427
443
  default:
428
- comment.replaceWith(...createNodes(value12));
444
+ comment.replaceWith(...createNodes(value11));
429
445
  break;
430
446
  }
431
- };
447
+ }
432
448
  var commentExpression2 = /^abydon\.(\d+)$/;
433
449
 
434
450
  // src/fragment.ts
435
- function createFragment(strings, expressions) {
436
- const data2 = {
437
- expressions,
438
- strings,
439
- nodes: [],
440
- values: []
441
- };
442
- const instance = Object.create({
443
- appendTo(element2) {
444
- element2.append(...this.get());
445
- },
446
- get() {
447
- if (data2.nodes.length === 0) {
448
- const parsed = parse2(data2);
449
- const templated = createTemplate(parsed);
450
- data2.nodes.splice(0, data2.nodes.length, ...getNodes(templated));
451
- mapNodes(data2, data2.nodes);
452
- }
453
- return [...data2.nodes];
454
- },
455
- remove() {
456
- const { length } = data2.nodes;
457
- for (let index = 0;index < length; index += 1) {
458
- const node2 = data2.nodes[index];
459
- node2.parentNode?.removeChild(node2);
460
- }
461
- data2.nodes.splice(0, data2.nodes.length);
451
+ class Fragment {
452
+ data;
453
+ constructor(strings, expressions) {
454
+ this.data = {
455
+ expressions,
456
+ strings,
457
+ nodes: [],
458
+ values: []
459
+ };
460
+ }
461
+ appendTo(element2) {
462
+ element2.append(...this.get());
463
+ }
464
+ get() {
465
+ if (this.data.nodes.length === 0) {
466
+ const parsed = parse2(this.data);
467
+ const templated = createTemplate(parsed);
468
+ this.data.nodes.splice(0, this.data.nodes.length, ...getNodes(templated));
469
+ mapNodes(this.data, this.data.nodes);
462
470
  }
463
- });
464
- Object.defineProperty(instance, "$fragment", {
465
- value: true
466
- });
467
- return instance;
471
+ return [...this.data.nodes];
472
+ }
473
+ remove() {
474
+ const { length } = this.data.nodes;
475
+ for (let index = 0;index < length; index += 1) {
476
+ const node2 = this.data.nodes[index];
477
+ node2.parentNode?.removeChild(node2);
478
+ }
479
+ this.data.nodes.splice(0, length);
480
+ }
468
481
  }
469
482
 
470
483
  // src/html.ts
471
- var handleExpression = function(data2, prefix, expression) {
484
+ function handleExpression(data2, prefix, expression) {
472
485
  if (isNullableOrWhitespace(expression)) {
473
486
  return prefix;
474
487
  }
@@ -480,22 +493,22 @@ var handleExpression = function(data2, prefix, expression) {
480
493
  }
481
494
  return `${prefix}${expressions}`;
482
495
  }
483
- if (typeof expression === "object") {
496
+ if (typeof expression === "function" || typeof expression === "object") {
484
497
  const index = data2.values.push(expression) - 1;
485
498
  return `${prefix}<!--abydon.${index}-->`;
486
499
  }
487
500
  return `${prefix}${expression}`;
488
- };
501
+ }
489
502
  function html2(strings, ...values) {
490
- return createFragment(strings, values);
503
+ return new Fragment(strings, values);
491
504
  }
492
505
  function parse2(data2) {
493
506
  const { length } = data2.strings;
494
- let template = "";
507
+ let template2 = "";
495
508
  for (let index = 0;index < length; index += 1) {
496
- template += handleExpression(data2, data2.strings[index], data2.expressions[index]);
509
+ template2 += handleExpression(data2, data2.strings[index], data2.expressions[index]);
497
510
  }
498
- return template;
511
+ return template2;
499
512
  }
500
513
  export {
501
514
  html2 as html
package/dist/index.mjs ADDED
@@ -0,0 +1,5 @@
1
+ // src/index.ts
2
+ import {html} from "./html";
3
+ export {
4
+ html
5
+ };
File without changes