@oscarpalmer/abydon 0.7.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,58 +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
- var getOptions = function(options) {
153
+ function getOptions(options) {
186
154
  const parts = options.split(":");
187
155
  return {
188
156
  capture: parts.includes("c") || parts.includes("capture"),
189
157
  once: parts.includes("o") || parts.includes("once"),
190
158
  passive: !parts.includes("a") && !parts.includes("active")
191
159
  };
192
- };
193
- function mapEvent(element, name, value10) {
160
+ }
161
+ function mapEvent(element, name, value9) {
194
162
  element.removeAttribute(name);
195
163
  const [, type, options] = /^@(\w+)(?::([a-z:]+))?$/.exec(name) ?? [];
196
- if (typeof value10 === "function" && type != null) {
197
- element.addEventListener(type, value10, getOptions(options ?? ""));
164
+ if (typeof value9 === "function" && type != null) {
165
+ element.addEventListener(type, value9, getOptions(options ?? ""));
198
166
  }
199
167
  }
200
168
 
201
169
  // node_modules/@oscarpalmer/atoms/dist/js/element/closest.mjs
202
- 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
+ }
203
191
  const elements = [...(context ?? document).querySelectorAll(selector)];
204
192
  const { length } = elements;
205
193
  if (length === 0) {
@@ -222,22 +210,8 @@ var closest = function(origin, selector, context) {
222
210
  });
223
211
  }
224
212
  return minimum == null ? [] : distances.filter((found) => found.distance === minimum).map((found) => found.element);
225
- };
226
- var calculateDistance = function(origin, target) {
227
- const comparison = origin.compareDocumentPosition(target);
228
- const children = [...origin.parentElement?.children ?? []];
229
- switch (true) {
230
- case children.includes(target):
231
- return Math.abs(children.indexOf(origin) - children.indexOf(target));
232
- case !!(comparison & 2 || comparison & 8):
233
- return traverse(origin, target);
234
- case !!(comparison & 4 || comparison & 16):
235
- return traverse(target, origin);
236
- default:
237
- return -1;
238
- }
239
- };
240
- var traverse = function(from, to) {
213
+ }
214
+ function traverse(from, to) {
241
215
  const children = [...to.children];
242
216
  if (children.includes(from)) {
243
217
  return children.indexOf(from) + 1;
@@ -262,94 +236,94 @@ var traverse = function(from, to) {
262
236
  parent = parent.parentElement;
263
237
  }
264
238
  return -1e6;
265
- };
239
+ }
266
240
  // src/node/attribute/value.ts
267
- function setAttribute(element2, name, value10) {
241
+ function setAttribute(element2, name, value9) {
268
242
  element2.removeAttribute(name);
269
243
  switch (true) {
270
244
  case classPattern.test(name):
271
- setClasses(element2, name, value10);
245
+ setClasses(element2, name, value9);
272
246
  return;
273
247
  case stylePattern.test(name):
274
- setStyle(element2, name, value10);
248
+ setStyle(element2, name, value9);
275
249
  return;
276
250
  default:
277
- setValue2(element2, name, value10);
251
+ setValue3(element2, name, value9);
278
252
  break;
279
253
  }
280
254
  }
281
- var setClasses = function(element2, name, value10) {
282
- function update(value11) {
283
- if (/^(|true)$/.test(getString(value11))) {
255
+ function setClasses(element2, name, value9) {
256
+ function update(value10) {
257
+ if (/^(|true)$/.test(getString(value10))) {
284
258
  element2.classList.add(...classes);
285
259
  } else {
286
260
  element2.classList.remove(...classes);
287
261
  }
288
262
  }
289
263
  const classes = name.slice(6).split(".");
290
- if (isReactive(value10)) {
264
+ if (isReactive(value9)) {
291
265
  effect(() => {
292
- update(value10.get());
266
+ update(value9.get());
293
267
  });
294
268
  } else {
295
- update(value10);
269
+ update(value9);
296
270
  }
297
- };
298
- var setStyle = function(element2, name, value10) {
299
- function update(value11) {
300
- 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) {
301
275
  element2.style.removeProperty(property);
302
276
  } else {
303
- element2.style.setProperty(property, value11 === true ? unit : getString(value11));
277
+ element2.style.setProperty(property, value10 === true ? unit : getString(value10));
304
278
  }
305
279
  }
306
280
  const [, property, unit] = /^\w+\.([a-z-]+)(?:\.(\w+))?$/i.exec(name) ?? [];
307
281
  if (property == null) {
308
282
  return;
309
283
  }
310
- if (isReactive(value10)) {
284
+ if (isReactive(value9)) {
311
285
  effect(() => {
312
- update(value10.get());
286
+ update(value9.get());
313
287
  });
314
288
  } else {
315
- update(value10);
289
+ update(value9);
316
290
  }
317
- };
318
- var setValue2 = function(element2, name, value10) {
291
+ }
292
+ function setValue3(element2, name, value9) {
319
293
  const callback = booleanAttributes.has(name) && name in element2 ? name === "selected" ? updateSelected(element2) : updateProperty : updateAttribute;
320
- if (isReactive(value10)) {
294
+ if (isReactive(value9)) {
321
295
  effect(() => {
322
- callback(element2, name, value10.get());
296
+ callback(element2, name, value9.get());
323
297
  });
324
298
  } else {
325
- callback(element2, name, value10);
299
+ callback(element2, name, value9);
326
300
  }
327
- };
328
- var triggerSelectChange = function(select) {
301
+ }
302
+ function triggerSelectChange(select) {
329
303
  if (select != null) {
330
304
  select.dispatchEvent(new Event("change", { bubbles: true }));
331
305
  }
332
- };
333
- var updateAttribute = function(element2, name, value10) {
334
- if (value10 == null) {
306
+ }
307
+ function updateAttribute(element2, name, value9) {
308
+ if (value9 == null) {
335
309
  element2.removeAttribute(name);
336
310
  } else {
337
- element2.setAttribute(name, getString(value10));
311
+ element2.setAttribute(name, getString(value9));
338
312
  }
339
- };
340
- var updateProperty = function(element2, name, value10) {
341
- element2[name] = /^(|true)$/.test(getString(value10));
342
- };
343
- var updateSelected = function(element2) {
313
+ }
314
+ function updateProperty(element2, name, value9) {
315
+ element2[name] = /^(|true)$/.test(getString(value9));
316
+ }
317
+ function updateSelected(element2) {
344
318
  const select = closest(element2, "select")[0];
345
319
  const options = [...select?.options ?? []];
346
- return (element3, name, value10) => {
320
+ return (element3, name, value9) => {
347
321
  if (select != null && options.includes(element3)) {
348
322
  triggerSelectChange(select);
349
323
  }
350
- updateProperty(element3, name, value10);
324
+ updateProperty(element3, name, value9);
351
325
  };
352
- };
326
+ }
353
327
  var booleanAttributes = new Set([
354
328
  "checked",
355
329
  "disabled",
@@ -365,23 +339,23 @@ var classPattern = /^class\./;
365
339
  var stylePattern = /^style\./;
366
340
 
367
341
  // src/node/attribute/index.ts
368
- var getValue2 = function(data2, original) {
342
+ function getValue3(data2, original) {
369
343
  const matches = commentExpression.exec(original ?? "");
370
344
  return matches == null ? original : data2.values[+matches[1]];
371
- };
372
- function isBadAttribute(name, value11) {
373
- 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);
374
348
  }
375
349
  function mapAttributes(data2, element2) {
376
350
  const attributes = [...element2.attributes];
377
351
  const { length } = attributes;
378
352
  for (let index = 0;index < length; index += 1) {
379
- const { name, value: value11 } = attributes[index];
380
- if (isBadAttribute(name, value11)) {
353
+ const { name, value: value10 } = attributes[index];
354
+ if (isBadAttribute(name, value10)) {
381
355
  element2.removeAttribute(name);
382
356
  continue;
383
357
  }
384
- const actual = getValue2(data2, value11);
358
+ const actual = getValue3(data2, value10);
385
359
  if (name.startsWith("@")) {
386
360
  mapEvent(element2, name, actual);
387
361
  } else if (name.includes(".") || isReactive(actual)) {
@@ -389,26 +363,59 @@ function mapAttributes(data2, element2) {
389
363
  }
390
364
  }
391
365
  }
392
- var mapValue = function(element2, name, value11) {
366
+ function mapValue(element2, name, value10) {
393
367
  switch (true) {
394
- case typeof value11 === "function":
395
- mapValue(element2, name, value11());
368
+ case typeof value10 === "function":
369
+ mapValue(element2, name, value10());
396
370
  return;
397
371
  default:
398
- setAttribute(element2, name, value11);
372
+ setAttribute(element2, name, value10);
399
373
  break;
400
374
  }
401
- };
375
+ }
402
376
  var commentExpression = /^<!--abydon\.(\d+)-->$/;
403
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
+
404
411
  // src/node/index.ts
405
- var mapNode = function(data2, comment) {
412
+ function mapNode(data2, comment) {
406
413
  const matches = commentExpression2.exec(comment.textContent ?? "");
407
- const value12 = matches == null ? null : data2.values[+matches[1]];
408
- if (value12 != null) {
409
- mapValue2(comment, value12);
414
+ const value11 = matches == null ? null : data2.values[+matches[1]];
415
+ if (value11 != null) {
416
+ mapValue2(comment, value11);
410
417
  }
411
- };
418
+ }
412
419
  function mapNodes(data2, nodes) {
413
420
  const { length } = nodes;
414
421
  for (let index = 0;index < length; index += 1) {
@@ -425,59 +432,56 @@ function mapNodes(data2, nodes) {
425
432
  }
426
433
  }
427
434
  }
428
- var mapValue2 = function(comment, value12) {
435
+ function mapValue2(comment, value11) {
429
436
  switch (true) {
430
- case typeof value12 === "function":
431
- mapValue2(comment, value12());
437
+ case typeof value11 === "function":
438
+ mapValue2(comment, value11());
432
439
  return;
433
- case isReactive(value12):
434
- setReactiveNode(comment, value12);
440
+ case isReactive(value11):
441
+ setReactiveNode(comment, value11);
435
442
  break;
436
443
  default:
437
- comment.replaceWith(...createNodes(value12));
444
+ comment.replaceWith(...createNodes(value11));
438
445
  break;
439
446
  }
440
- };
447
+ }
441
448
  var commentExpression2 = /^abydon\.(\d+)$/;
442
449
 
443
450
  // src/fragment.ts
444
- function createFragment(strings, expressions) {
445
- const data2 = {
446
- expressions,
447
- strings,
448
- nodes: [],
449
- values: []
450
- };
451
- const instance = Object.create({
452
- appendTo(element2) {
453
- element2.append(...this.get());
454
- },
455
- get() {
456
- if (data2.nodes.length === 0) {
457
- const parsed = parse2(data2);
458
- const templated = createTemplate(parsed);
459
- data2.nodes.splice(0, data2.nodes.length, ...getNodes(templated));
460
- mapNodes(data2, data2.nodes);
461
- }
462
- return [...data2.nodes];
463
- },
464
- remove() {
465
- const { length } = data2.nodes;
466
- for (let index = 0;index < length; index += 1) {
467
- const node2 = data2.nodes[index];
468
- node2.parentNode?.removeChild(node2);
469
- }
470
- 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);
471
470
  }
472
- });
473
- Object.defineProperty(instance, "$fragment", {
474
- value: true
475
- });
476
- 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
+ }
477
481
  }
478
482
 
479
483
  // src/html.ts
480
- var handleExpression = function(data2, prefix, expression) {
484
+ function handleExpression(data2, prefix, expression) {
481
485
  if (isNullableOrWhitespace(expression)) {
482
486
  return prefix;
483
487
  }
@@ -494,17 +498,17 @@ var handleExpression = function(data2, prefix, expression) {
494
498
  return `${prefix}<!--abydon.${index}-->`;
495
499
  }
496
500
  return `${prefix}${expression}`;
497
- };
501
+ }
498
502
  function html2(strings, ...values) {
499
- return createFragment(strings, values);
503
+ return new Fragment(strings, values);
500
504
  }
501
505
  function parse2(data2) {
502
506
  const { length } = data2.strings;
503
- let template = "";
507
+ let template2 = "";
504
508
  for (let index = 0;index < length; index += 1) {
505
- template += handleExpression(data2, data2.strings[index], data2.expressions[index]);
509
+ template2 += handleExpression(data2, data2.strings[index], data2.expressions[index]);
506
510
  }
507
- return template;
511
+ return template2;
508
512
  }
509
513
  export {
510
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