@oscarpalmer/toretto 0.31.0 → 0.33.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.
@@ -25,6 +25,9 @@ var touch_default = (() => {
25
25
  } });
26
26
  return instance;
27
27
  })();
28
+ function isNumber(value) {
29
+ return typeof value === "number" && !Number.isNaN(value);
30
+ }
28
31
  function isPlainObject(value) {
29
32
  if (value === null || typeof value !== "object") return false;
30
33
  if (Symbol.toStringTag in value || Symbol.iterator in value) return false;
@@ -46,12 +49,12 @@ new Set([
46
49
  ]);
47
50
  function compact(array, strict) {
48
51
  if (!Array.isArray(array)) return [];
52
+ if (strict === true) return array.filter(Boolean);
49
53
  const { length } = array;
50
- const isStrict = strict ?? false;
51
54
  const compacted = [];
52
55
  for (let index = 0; index < length; index += 1) {
53
56
  const item = array[index];
54
- if (isStrict && !!item || !isStrict && item != null) compacted.push(item);
57
+ if (item != null) compacted.push(item);
55
58
  }
56
59
  return compacted;
57
60
  }
@@ -63,75 +66,81 @@ function getString(value) {
63
66
  const asString = String(value.valueOf?.() ?? value);
64
67
  return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
65
68
  }
69
+ function ignoreKey(key) {
70
+ return EXPRESSION_IGNORED.test(key);
71
+ }
66
72
  function join(value, delimiter) {
67
73
  return compact(value).map(getString).join(typeof delimiter === "string" ? delimiter : "");
68
74
  }
69
75
  function words(value) {
70
76
  return typeof value === "string" ? value.match(EXPRESSION_WORDS) ?? [] : [];
71
77
  }
78
+ var EXPRESSION_IGNORED = /(^|\.)(__proto__|constructor|prototype)(\.|$)/i;
72
79
  var EXPRESSION_WORDS = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
73
80
  function isNullableOrWhitespace(value) {
74
81
  return value == null || EXPRESSION_WHITESPACE$1.test(getString(value));
75
82
  }
76
83
  var EXPRESSION_WHITESPACE$1 = /^\s*$/;
77
- function camelCase(value) {
78
- return toCase(value, "", true, false);
84
+ function isEventTarget(value) {
85
+ return typeof value === "object" && value != null && typeof value.addEventListener === "function" && typeof value.removeEventListener === "function" && typeof value.dispatchEvent === "function";
79
86
  }
80
- function capitalize(value) {
81
- if (typeof value !== "string" || value.length === 0) return "";
82
- return value.length === 1 ? value.toLocaleUpperCase() : `${value.charAt(0).toLocaleUpperCase()}${value.slice(1).toLocaleLowerCase()}`;
87
+ function isHTMLOrSVGElement(value) {
88
+ return value instanceof HTMLElement || value instanceof SVGElement;
83
89
  }
84
- function kebabCase(value) {
85
- return toCase(value, "-", false, false);
90
+ function isChildNode(value) {
91
+ return value instanceof Node && CHILD_NODE_TYPES.has(value.nodeType);
86
92
  }
87
- function toCase(value, delimiter, capitalizeAny, capitalizeFirst) {
88
- if (typeof value !== "string") return "";
89
- if (value.length < 1) return value;
90
- const parts = words(value);
91
- const partsLength = parts.length;
92
- const result = [];
93
- for (let partIndex = 0; partIndex < partsLength; partIndex += 1) {
94
- const items = parts[partIndex].replace(EXPRESSION_ACRONYM, (full, one, two, three) => three === "s" ? full : `${one}-${two}${three}`).replace(EXPRESSION_CAMEL_CASE, "$1-$2").split("-");
95
- const itemsLength = items.length;
96
- const partResult = [];
97
- let itemCount = 0;
98
- for (let itemIndex = 0; itemIndex < itemsLength; itemIndex += 1) {
99
- const item = items[itemIndex];
100
- if (item.length === 0) continue;
101
- if (!capitalizeAny || itemCount === 0 && partIndex === 0 && !capitalizeFirst) partResult.push(item.toLocaleLowerCase());
102
- else partResult.push(capitalize(item));
103
- itemCount += 1;
104
- }
105
- result.push(join(partResult, delimiter));
106
- }
107
- return join(result, delimiter);
93
+ function isInDocument(node, doc) {
94
+ if (!(node instanceof Node)) return false;
95
+ if (!(doc instanceof Document)) return node.ownerDocument?.contains(node) ?? true;
96
+ return node.ownerDocument == null ? node === doc : node.ownerDocument === doc && doc.contains(node);
108
97
  }
109
- var EXPRESSION_CAMEL_CASE = /(\p{Ll})(\p{Lu})/gu;
110
- var EXPRESSION_ACRONYM = /(\p{Lu}*)(\p{Lu})(\p{Ll}+)/gu;
111
- function parse(value, reviver) {
112
- try {
113
- return JSON.parse(value, reviver);
114
- } catch {
98
+ const CHILD_NODE_TYPES = new Set([
99
+ Node.ELEMENT_NODE,
100
+ Node.TEXT_NODE,
101
+ Node.PROCESSING_INSTRUCTION_NODE,
102
+ Node.COMMENT_NODE,
103
+ Node.DOCUMENT_TYPE_NODE
104
+ ]);
105
+ function setElementValue(element, first, second, third, callback) {
106
+ if (!isHTMLOrSVGElement(element)) return;
107
+ if (typeof first === "string") setElementValues(element, first, second, third, callback);
108
+ else if (isAttribute(first)) setElementValues(element, first.name, first.value, third, callback);
109
+ }
110
+ function setElementValues(element, first, second, third, callback) {
111
+ if (!isHTMLOrSVGElement(element)) return;
112
+ if (typeof first === "string") {
113
+ callback(element, first, second, third);
115
114
  return;
116
115
  }
116
+ const isArray = Array.isArray(first);
117
+ if (!isArray && !(typeof first === "object" && first !== null)) return;
118
+ const entries = isArray ? first : Object.entries(first).map(([name, value]) => ({
119
+ name,
120
+ value
121
+ }));
122
+ const { length } = entries;
123
+ for (let index = 0; index < length; index += 1) {
124
+ const entry = entries[index];
125
+ if (typeof entry === "object" && typeof entry?.name === "string") callback(element, entry.name, entry.value, third);
126
+ }
117
127
  }
118
- function isEventTarget(value) {
119
- return typeof value === "object" && value != null && typeof value.addEventListener === "function" && typeof value.removeEventListener === "function" && typeof value.dispatchEvent === "function";
120
- }
121
- function isHTMLOrSVGElement(value) {
122
- return value instanceof HTMLElement || value instanceof SVGElement;
128
+ function updateElementValue(element, key, value, set, remove, isBoolean, json) {
129
+ if (isBoolean ? value == null : isNullableOrWhitespace(value)) remove.call(element, key);
130
+ else set.call(element, key, json ? JSON.stringify(value) : String(value));
123
131
  }
124
132
  function badAttributeHandler(name, value) {
125
- if (name == null || value == null) return true;
133
+ if (typeof name !== "string" || name.trim().length === 0 || typeof value !== "string") return true;
126
134
  if (EXPRESSION_CLOBBERED_NAME.test(name) && (value in document || value in formElement) || EXPRESSION_EVENT_NAME.test(name)) return true;
127
135
  if (EXPRESSION_SKIP_NAME.test(name) || EXPRESSION_URI_VALUE.test(value) || isValidSourceAttribute(name, value)) return false;
128
136
  return EXPRESSION_DATA_OR_SCRIPT.test(value);
129
137
  }
130
138
  function booleanAttributeHandler(name, value) {
131
- if (name == null || value == null) return true;
132
- if (!booleanAttributesSet.has(name)) return false;
133
- const normalized = value.toLowerCase().trim();
134
- return !(normalized.length === 0 || normalized === name);
139
+ if (typeof name !== "string" || name.trim().length === 0 || typeof value !== "string") return true;
140
+ const normalizedName = name.toLowerCase();
141
+ if (!booleanAttributesSet.has(normalizedName)) return false;
142
+ const normalized = value.toLowerCase();
143
+ return !(normalized.length === 0 || normalized === normalizedName);
135
144
  }
136
145
  function decodeAttribute(value) {
137
146
  textArea ??= document.createElement("textarea");
@@ -152,7 +161,7 @@ function handleAttribute(callback, decode, first, second) {
152
161
  return callback(name, value?.replace(EXPRESSION_WHITESPACE, ""));
153
162
  }
154
163
  function isAttribute(value) {
155
- return value instanceof Attr || isPlainObject(value) && typeof value.name === "string" && typeof value.value === "string";
164
+ return value instanceof Attr || isPlainObject(value) && typeof value.name === "string" && "value" in value;
156
165
  }
157
166
  function _isBadAttribute(first, second, decode) {
158
167
  return handleAttribute(badAttributeHandler, decode, first, second);
@@ -166,26 +175,21 @@ function _isEmptyNonBooleanAttribute(first, second, decode) {
166
175
  function _isInvalidBooleanAttribute(first, second, decode) {
167
176
  return handleAttribute(booleanAttributeHandler, decode, first, second);
168
177
  }
169
- function isProperty(value) {
170
- return isPlainObject(value) && typeof value.name === "string";
171
- }
172
178
  function isValidSourceAttribute(name, value) {
173
179
  return EXPRESSION_SOURCE_NAME.test(name) && EXPRESSION_SOURCE_VALUE.test(value);
174
180
  }
175
- function updateAttribute(element, name, value) {
176
- const isBoolean = booleanAttributesSet.has(name.toLowerCase());
177
- if (isBoolean) updateProperty(element, name, value);
178
- if (isBoolean ? value !== true : value == null) element.removeAttribute(name);
179
- else element.setAttribute(name, isBoolean ? "" : getString(value));
180
- }
181
- function updateProperty(element, name, value) {
182
- const actual = name.toLowerCase();
183
- element[actual] = value === "" || typeof value === "string" && value.toLowerCase() === actual || value === true;
181
+ function updateAttribute(element, name, value, dispatch$1) {
182
+ const normalizedName = name.toLowerCase();
183
+ const isBoolean = booleanAttributesSet.has(normalizedName);
184
+ const next = isBoolean ? value === true || typeof value === "string" && (value === "" || value.toLowerCase() === normalizedName) : value == null ? "" : value;
185
+ if (name in element) updateProperty(element, normalizedName, next, dispatch$1);
186
+ updateElementValue(element, name, isBoolean ? next ? "" : null : value, element.setAttribute, element.removeAttribute, isBoolean, false);
184
187
  }
185
- function updateValue(element, first, second) {
186
- if (!isHTMLOrSVGElement(element)) return;
187
- if (isProperty(first)) updateAttribute(element, first.name, first.value);
188
- else if (typeof first === "string") updateAttribute(element, first, second);
188
+ function updateProperty(element, name, value, dispatch$1) {
189
+ if (Object.is(element[name], value)) return;
190
+ element[name] = value;
191
+ const event = dispatch$1 !== false && elementEvents[element.tagName]?.[name];
192
+ if (typeof event === "string") element.dispatchEvent(new Event(event, { bubbles: true }));
189
193
  }
190
194
  const EXPRESSION_CLOBBERED_NAME = /^(id|name)$/i;
191
195
  const EXPRESSION_DATA_OR_SCRIPT = /^(?:data|\w+script):/i;
@@ -222,8 +226,261 @@ const booleanAttributes = Object.freeze([
222
226
  "selected"
223
227
  ]);
224
228
  const booleanAttributesSet = new Set(booleanAttributes);
229
+ const elementEvents = {
230
+ DETAILS: { open: "toggle" },
231
+ INPUT: {
232
+ checked: "change",
233
+ value: "input"
234
+ },
235
+ SELECT: { value: "change" },
236
+ TEXTAREA: { value: "input" }
237
+ };
225
238
  const formElement = document.createElement("form");
226
239
  let textArea;
240
+ function noop() {}
241
+ function calculate() {
242
+ return new Promise((resolve) => {
243
+ const values = [];
244
+ let last;
245
+ function step(now) {
246
+ if (last != null) values.push(now - last);
247
+ last = now;
248
+ if (values.length >= TOTAL) resolve(values.sort().slice(TRIM_PART, -TRIM_PART).reduce((first, second) => first + second, 0) / (values.length - TRIM_TOTAL));
249
+ else requestAnimationFrame(step);
250
+ }
251
+ requestAnimationFrame(step);
252
+ });
253
+ }
254
+ var TOTAL = 10;
255
+ var TRIM_PART = 2;
256
+ var TRIM_TOTAL = 4;
257
+ await calculate();
258
+ function clamp(value, minimum, maximum, loop) {
259
+ if (![
260
+ value,
261
+ minimum,
262
+ maximum
263
+ ].every(isNumber)) return NaN;
264
+ if (value < minimum) return loop === true ? maximum : minimum;
265
+ return value > maximum ? loop === true ? minimum : maximum : value;
266
+ }
267
+ var SizedMap = class extends Map {
268
+ #maximumSize;
269
+ get full() {
270
+ return this.size >= this.#maximumSize;
271
+ }
272
+ get maximum() {
273
+ return this.#maximumSize;
274
+ }
275
+ constructor(first, second) {
276
+ const maximum = getMaximum(first, second);
277
+ super();
278
+ this.#maximumSize = maximum;
279
+ if (Array.isArray(first)) {
280
+ const { length } = first;
281
+ if (length <= maximum) for (let index = 0; index < length; index += 1) this.set(...first[index]);
282
+ else for (let index = 0; index < maximum; index += 1) this.set(...first[length - maximum + index]);
283
+ }
284
+ }
285
+ get(key) {
286
+ const value = super.get(key);
287
+ if (value !== void 0 || this.has(key)) this.set(key, value);
288
+ return value;
289
+ }
290
+ set(key, value) {
291
+ if (this.has(key)) this.delete(key);
292
+ else if (this.size >= this.#maximumSize) this.delete(this.keys().next().value);
293
+ return super.set(key, value);
294
+ }
295
+ };
296
+ function getMaximum(first, second) {
297
+ let actual;
298
+ if (typeof first === "number") actual = first;
299
+ else actual = typeof second === "number" ? second : MAXIMUM_DEFAULT;
300
+ return clamp(actual, 1, MAXIMUM_ABSOLUTE);
301
+ }
302
+ var MAXIMUM_ABSOLUTE = 16777216;
303
+ var MAXIMUM_DEFAULT = 1048576;
304
+ var Memoized = class {
305
+ #state;
306
+ get maximum() {
307
+ return this.#state.cache?.maximum ?? NaN;
308
+ }
309
+ get size() {
310
+ return this.#state.cache?.size ?? NaN;
311
+ }
312
+ constructor(callback, options) {
313
+ const cache = new SizedMap(options.cacheSize);
314
+ const getter = (...parameters) => {
315
+ const key = options.cacheKey?.(...parameters) ?? (parameters.length === 1 ? parameters[0] : join(parameters.map(getString), "_"));
316
+ if (cache.has(key)) return cache.get(key);
317
+ const value = callback(...parameters);
318
+ cache.set(key, value);
319
+ return value;
320
+ };
321
+ this.#state = {
322
+ cache,
323
+ getter
324
+ };
325
+ }
326
+ clear() {
327
+ this.#state.cache?.clear();
328
+ }
329
+ delete(key) {
330
+ return this.#state.cache?.delete(key) ?? false;
331
+ }
332
+ destroy() {
333
+ this.#state.cache?.clear();
334
+ this.#state.cache = void 0;
335
+ this.#state.getter = void 0;
336
+ }
337
+ get(key) {
338
+ return this.#state.cache?.get(key);
339
+ }
340
+ has(key) {
341
+ return this.#state.cache?.has(key) ?? false;
342
+ }
343
+ run(...parameters) {
344
+ if (this.#state.cache == null || this.#state.getter == null) throw new Error("The Memoized instance has been destroyed");
345
+ return this.#state.getter(...parameters);
346
+ }
347
+ };
348
+ function getMemoizationOptions(input) {
349
+ const { cacheKey, cacheSize } = isPlainObject(input) ? input : {};
350
+ return {
351
+ cacheKey: typeof cacheKey === "function" ? cacheKey : void 0,
352
+ cacheSize: typeof cacheSize === "number" && cacheSize > 0 ? cacheSize : DEFAULT_CACHE_SIZE
353
+ };
354
+ }
355
+ function memoize(callback, options) {
356
+ return new Memoized(callback, getMemoizationOptions(options));
357
+ }
358
+ var DEFAULT_CACHE_SIZE = 1024;
359
+ function camelCase(value) {
360
+ return toCase(TYPE_CAMEL, value, true, false);
361
+ }
362
+ function capitalize(value) {
363
+ if (typeof value !== "string" || value.length === 0) return "";
364
+ memoizedCapitalize ??= memoize((v) => v.length === 1 ? v.toLocaleUpperCase() : `${v.charAt(0).toLocaleUpperCase()}${v.slice(1).toLocaleLowerCase()}`);
365
+ return memoizedCapitalize.run(value);
366
+ }
367
+ function kebabCase(value) {
368
+ return toCase(TYPE_KEBAB, value, false, false);
369
+ }
370
+ function toCase(type, value, capitalizeAny, capitalizeFirst) {
371
+ memoizers[type] ??= memoize(toCaseCallback.bind({
372
+ type,
373
+ capitalizeAny,
374
+ capitalizeFirst
375
+ }));
376
+ return memoizers[type].run(value);
377
+ }
378
+ function toCaseCallback(value) {
379
+ if (typeof value !== "string") return "";
380
+ if (value.length < 1) return value;
381
+ const { capitalizeAny, capitalizeFirst, type } = this;
382
+ const parts = words(value);
383
+ const partsLength = parts.length;
384
+ const result = [];
385
+ for (let partIndex = 0; partIndex < partsLength; partIndex += 1) {
386
+ const items = parts[partIndex].replace(EXPRESSION_ACRONYM, (full, one, two, three) => three === "s" ? full : `${one}-${two}${three}`).replace(EXPRESSION_CAMEL_CASE, REPLACEMENT_CAMEL_CASE).split("-");
387
+ const itemsLength = items.length;
388
+ const partResult = [];
389
+ let itemCount = 0;
390
+ for (let itemIndex = 0; itemIndex < itemsLength; itemIndex += 1) {
391
+ const item = items[itemIndex];
392
+ if (item.length === 0) continue;
393
+ if (!capitalizeAny || itemCount === 0 && partIndex === 0 && !capitalizeFirst) partResult.push(item.toLocaleLowerCase());
394
+ else partResult.push(capitalize(item));
395
+ itemCount += 1;
396
+ }
397
+ result.push(join(partResult, delimiters[type]));
398
+ }
399
+ return join(result, delimiters[type]);
400
+ }
401
+ var EXPRESSION_CAMEL_CASE = /(\p{Ll})(\p{Lu})/gu;
402
+ var EXPRESSION_ACRONYM = /(\p{Lu}*)(\p{Lu})(\p{Ll}+)/gu;
403
+ var REPLACEMENT_CAMEL_CASE = "$1-$2";
404
+ var TYPE_CAMEL = "camel";
405
+ var TYPE_KEBAB = "kebab";
406
+ var TYPE_PASCAL = "pascal";
407
+ var TYPE_SNAKE = "snake";
408
+ var delimiters = {
409
+ [TYPE_CAMEL]: "",
410
+ [TYPE_KEBAB]: "-",
411
+ [TYPE_PASCAL]: "",
412
+ [TYPE_SNAKE]: "_"
413
+ };
414
+ var memoizers = {};
415
+ var memoizedCapitalize;
416
+ function parse(value, reviver) {
417
+ try {
418
+ return JSON.parse(value, reviver);
419
+ } catch {
420
+ return;
421
+ }
422
+ }
423
+ function findKey(needle, haystack) {
424
+ const keys = Object.keys(haystack);
425
+ const index = keys.map((key) => key.toLowerCase()).indexOf(needle.toLowerCase());
426
+ return index > -1 ? keys[index] : needle;
427
+ }
428
+ function getPaths(path, lowercase) {
429
+ const normalized = lowercase ? path.toLowerCase() : path;
430
+ if (!EXPRESSION_NESTED.test(normalized)) return normalized;
431
+ return normalized.replace(EXPRESSION_BRACKET, ".$1").replace(EXPRESSION_DOTS, "").split(".");
432
+ }
433
+ function handleValue(data, path, value, get, ignoreCase) {
434
+ if (typeof data === "object" && data !== null && !ignoreKey(path)) {
435
+ const key = ignoreCase ? findKey(path, data) : path;
436
+ if (get) return data[key];
437
+ data[key] = value;
438
+ }
439
+ }
440
+ var EXPRESSION_BRACKET = /\[(\w+)\]/g;
441
+ var EXPRESSION_DOTS = /^\.|\.$/g;
442
+ var EXPRESSION_NESTED = /\.|\[\w+\]/;
443
+ function getValue(data, path, ignoreCase) {
444
+ if (typeof data !== "object" || data === null || typeof path !== "string" || path.trim().length === 0) return;
445
+ const shouldIgnoreCase = ignoreCase === true;
446
+ const paths = getPaths(path, shouldIgnoreCase);
447
+ if (typeof paths === "string") return handleValue(data, paths, null, true, shouldIgnoreCase);
448
+ const { length } = paths;
449
+ let index = 0;
450
+ let value = data;
451
+ while (index < length && value != null) value = handleValue(value, paths[index++], null, true, shouldIgnoreCase);
452
+ return value;
453
+ }
454
+ function getTemplateOptions(input) {
455
+ const options = isPlainObject(input) ? input : {};
456
+ return {
457
+ ignoreCase: options.ignoreCase === true,
458
+ pattern: options.pattern instanceof RegExp ? options.pattern : EXPRESSION_VARIABLE
459
+ };
460
+ }
461
+ function handleTemplate(value, pattern, ignoreCase, variables) {
462
+ if (typeof value !== "string") return "";
463
+ if (typeof variables !== "object" || variables === null) return value;
464
+ const values = {};
465
+ return value.replace(pattern, (_, key) => {
466
+ if (values[key] == null) {
467
+ const templateValue = getValue(variables, key, ignoreCase);
468
+ values[key] = templateValue == null ? "" : getString(templateValue);
469
+ }
470
+ return values[key];
471
+ });
472
+ }
473
+ var template = ((value, variables, options) => {
474
+ const { ignoreCase, pattern } = getTemplateOptions(options);
475
+ return handleTemplate(value, pattern, ignoreCase, variables);
476
+ });
477
+ template.initialize = (options) => {
478
+ const { ignoreCase, pattern } = getTemplateOptions(options);
479
+ return (value, variables) => {
480
+ return handleTemplate(value, pattern, ignoreCase, variables);
481
+ };
482
+ };
483
+ var EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
227
484
  function getBoolean(value, defaultValue) {
228
485
  return typeof value === "boolean" ? value : defaultValue ?? false;
229
486
  }
@@ -232,8 +489,8 @@ function getStyleValue(element, property, computed) {
232
489
  return computed ? getComputedStyle(element)[name] : element.style[name];
233
490
  }
234
491
  const EXPRESSION_DATA_PREFIX = /^data-/i;
235
- function setAttribute(element, first, second) {
236
- updateValue(element, first, second);
492
+ function setAttribute(element, first, second, third) {
493
+ setElementValue(element, first, second, third, updateAttribute);
237
494
  }
238
495
  function isBadAttribute(first, second) {
239
496
  return _isBadAttribute(first, second, true);
@@ -247,36 +504,6 @@ function isEmptyNonBooleanAttribute(first, second) {
247
504
  function isInvalidBooleanAttribute(first, second) {
248
505
  return _isInvalidBooleanAttribute(first, second, true);
249
506
  }
250
- function isChildNode(value) {
251
- return value instanceof Node && CHILD_NODE_TYPES.has(value.nodeType);
252
- }
253
- function isInDocument(node, doc) {
254
- if (!(node instanceof Node)) return false;
255
- if (!(doc instanceof Document)) return node.ownerDocument?.contains(node) ?? true;
256
- return node.ownerDocument == null ? node === doc : node.ownerDocument === doc && doc.contains(node);
257
- }
258
- const CHILD_NODE_TYPES = new Set([
259
- Node.ELEMENT_NODE,
260
- Node.TEXT_NODE,
261
- Node.PROCESSING_INSTRUCTION_NODE,
262
- Node.COMMENT_NODE,
263
- Node.DOCUMENT_TYPE_NODE
264
- ]);
265
- function setElementValues(element, first, second, callback) {
266
- if (!isHTMLOrSVGElement(element)) return;
267
- if (isPlainObject(first)) {
268
- const entries = Object.entries(first);
269
- const { length } = entries;
270
- for (let index = 0; index < length; index += 1) {
271
- const [key, value] = entries[index];
272
- callback(element, key, value);
273
- }
274
- } else if (typeof first === "string") callback(element, first, second);
275
- }
276
- function updateElementValue(element, key, value, set, remove, json) {
277
- if (isNullableOrWhitespace(value)) remove.call(element, key);
278
- else set.call(element, key, json ? JSON.stringify(value) : String(value));
279
- }
280
507
  function getData(element, keys, parseValues) {
281
508
  if (!isHTMLOrSVGElement(element)) return;
282
509
  const shouldParse = parseValues !== false;
@@ -299,62 +526,47 @@ function getName(original) {
299
526
  return `${ATTRIBUTE_DATA_PREFIX}${kebabCase(original).replace(EXPRESSION_DATA_PREFIX, "")}`;
300
527
  }
301
528
  function setData(element, first, second) {
302
- setElementValues(element, first, second, updateDataAttribute);
529
+ setElementValues(element, first, second, null, updateDataAttribute);
303
530
  }
304
531
  function updateDataAttribute(element, key, value) {
305
- updateElementValue(element, getName(key), value, element.setAttribute, element.removeAttribute, true);
532
+ updateElementValue(element, getName(key), value, element.setAttribute, element.removeAttribute, false, true);
306
533
  }
307
534
  const ATTRIBUTE_DATA_PREFIX = "data-";
308
- function calculate() {
309
- return new Promise((resolve) => {
310
- const values = [];
311
- let last;
312
- function step(now) {
313
- if (last != null) values.push(now - last);
314
- last = now;
315
- if (values.length >= CALCULATION_TOTAL) resolve(values.sort().slice(2, -2).reduce((first, second) => first + second, 0) / (values.length - CALCULATION_TRIM));
316
- else requestAnimationFrame(step);
317
- }
318
- requestAnimationFrame(step);
319
- });
320
- }
321
- function noop() {}
322
- var CALCULATION_TOTAL = 10;
323
- var CALCULATION_TRIM = 4;
324
- calculate().then((value) => {});
325
535
  function addDelegatedHandler(doc, type, name, passive) {
326
- const count = `${name}${COUNT_SUFFIX}`;
327
- if (doc[count] != null) {
328
- doc[count] += 1;
329
- return;
330
- }
331
- doc[count] = 1;
536
+ if (DELEGATED.has(name)) return;
537
+ DELEGATED.add(name);
332
538
  doc.addEventListener(type, passive ? HANDLER_PASSIVE : HANDLER_ACTIVE, { passive });
333
539
  }
334
540
  function addDelegatedListener(target, type, name, listener, passive) {
335
541
  target[name] ??= /* @__PURE__ */ new Set();
336
- target[name]?.add(listener);
542
+ target[name].add(listener);
337
543
  addDelegatedHandler(document, type, name, passive);
338
544
  return () => {
339
- removeDelegatedListener(target, type, name, listener, passive);
545
+ removeDelegatedListener(target, name, listener);
340
546
  };
341
547
  }
342
548
  function delegatedEventHandler(event) {
343
549
  const key = `${EVENT_PREFIX}${event.type}${this ? EVENT_SUFFIX_PASSIVE : EVENT_SUFFIX_ACTIVE}`;
344
550
  const items = event.composedPath();
345
551
  const { length } = items;
346
- Object.defineProperty(event, "target", {
347
- configurable: true,
348
- value: items[0]
552
+ let target = items[0];
553
+ Object.defineProperties(event, {
554
+ currentTarget: {
555
+ configurable: true,
556
+ get() {
557
+ return target;
558
+ }
559
+ },
560
+ target: {
561
+ configurable: true,
562
+ value: target
563
+ }
349
564
  });
350
565
  for (let index = 0; index < length; index += 1) {
351
566
  const item = items[index];
352
567
  const listeners = item[key];
353
568
  if (item.disabled || listeners == null) continue;
354
- Object.defineProperty(event, "currentTarget", {
355
- configurable: true,
356
- value: item
357
- });
569
+ target = item;
358
570
  for (const listener of listeners) {
359
571
  listener.call(item, event);
360
572
  if (event.cancelBubble) return;
@@ -364,23 +576,14 @@ function delegatedEventHandler(event) {
364
576
  function getDelegatedName(target, type, options) {
365
577
  if (isEventTarget(target) && EVENT_TYPES.has(type) && !options.capture && !options.once && options.signal == null) return `${EVENT_PREFIX}${type}${options.passive ? EVENT_SUFFIX_PASSIVE : EVENT_SUFFIX_ACTIVE}`;
366
578
  }
367
- function removeDelegatedHandler(doc, type, name, passive) {
368
- const count = `${name}${COUNT_SUFFIX}`;
369
- doc[count] -= 1;
370
- if (doc[count] < 1) {
371
- doc[count] = void 0;
372
- doc.removeEventListener(type, passive ? HANDLER_PASSIVE : HANDLER_ACTIVE);
373
- }
374
- }
375
- function removeDelegatedListener(target, type, name, listener, passive) {
579
+ function removeDelegatedListener(target, name, listener) {
376
580
  const handlers = target[name];
377
581
  if (handlers == null || !handlers.has(listener)) return false;
378
582
  handlers.delete(listener);
379
583
  if (handlers.size === 0) target[name] = void 0;
380
- removeDelegatedHandler(document, type, name, passive);
381
584
  return true;
382
585
  }
383
- const COUNT_SUFFIX = ".count";
586
+ const DELEGATED = /* @__PURE__ */ new Set();
384
587
  const EVENT_PREFIX = "@";
385
588
  const EVENT_SUFFIX_ACTIVE = ":active";
386
589
  const EVENT_SUFFIX_PASSIVE = ":passive";
@@ -455,7 +658,7 @@ function off(target, type, listener, options) {
455
658
  if (!isEventTarget(target) || typeof type !== "string" || typeof listener !== "function") return;
456
659
  const extended = createEventOptions(options);
457
660
  const delegated = getDelegatedName(target, type, extended);
458
- if (delegated == null || !removeDelegatedListener(target, type, delegated, listener, extended.passive)) target.removeEventListener(type, listener, extended);
661
+ if (delegated == null || !removeDelegatedListener(target, delegated, listener)) target.removeEventListener(type, listener, extended);
459
662
  }
460
663
  function on(target, type, listener, options) {
461
664
  if (!isEventTarget(target) || typeof type !== "string" || typeof listener !== "function") return noop;
@@ -469,15 +672,6 @@ function on(target, type, listener, options) {
469
672
  };
470
673
  }
471
674
  const PROPERTY_DETAIL = "detail";
472
- function getDistanceBetweenElements(origin, target) {
473
- if (origin === target) return 0;
474
- if (origin.parentElement === target) return 1;
475
- const children = [...origin.parentElement?.children ?? []];
476
- if (children.includes(target)) return Math.abs(children.indexOf(origin) - children.indexOf(target));
477
- const comparison = origin.compareDocumentPosition(target);
478
- const beforeOrInside = Boolean(comparison & 2 || comparison & 8);
479
- if (beforeOrInside || Boolean(comparison & 4 || comparison & 16)) return traverse(beforeOrInside ? origin : target, beforeOrInside ? target : origin) ?? -1;
480
- }
481
675
  function findAncestor(origin, selector) {
482
676
  if (!(origin instanceof Element) || selector == null) return null;
483
677
  if (typeof selector === "string") {
@@ -502,8 +696,8 @@ function findRelatives(origin, selector, context) {
502
696
  let minimum;
503
697
  for (let index = 0; index < length; index += 1) {
504
698
  const element = elements[index];
505
- const distance = getDistanceBetweenElements(origin, element);
506
- if (distance != null && distance > 0) {
699
+ const distance = getDistance(origin, element);
700
+ if (distance > 0) {
507
701
  if (minimum == null || distance < minimum) minimum = distance;
508
702
  distances.push({
509
703
  distance,
@@ -511,19 +705,29 @@ function findRelatives(origin, selector, context) {
511
705
  });
512
706
  }
513
707
  }
514
- return distances.filter((found) => found.distance === minimum && found.element !== origin).map((found) => found.element);
708
+ return distances.filter((found) => found.distance === minimum).map((found) => found.element);
709
+ }
710
+ function getDistance(origin, target) {
711
+ if (origin === target) return 0;
712
+ if (origin.parentElement === target || target.parentElement === origin) return 1;
713
+ if (origin.parentElement != null && origin.parentElement === target.parentElement) {
714
+ const children = [...origin.parentElement.children];
715
+ return Math.abs(children.indexOf(origin) - children.indexOf(target));
716
+ }
717
+ const comparison = origin.compareDocumentPosition(target);
718
+ if (comparison & Node.DOCUMENT_POSITION_DISCONNECTED) return -1;
719
+ const preceding = comparison & Node.DOCUMENT_POSITION_PRECEDING;
720
+ return traverse(preceding ? origin : target, preceding ? target : origin) ?? -1;
515
721
  }
516
722
  function traverse(from, to) {
517
- let index = [...to.children].indexOf(from);
518
- if (index > -1) return 1;
519
723
  let current = from;
520
724
  let distance = 0;
521
725
  let parent = from.parentElement;
522
726
  while (parent != null) {
523
727
  if (parent === to) return distance + 1;
524
728
  const children = [...parent.children];
525
- if (children.includes(to)) return distance + Math.abs(children.indexOf(current) - children.indexOf(to));
526
- index = children.findIndex((child) => child.contains(to));
729
+ if (to.parentElement === parent) return distance + Math.abs(children.indexOf(current) - children.indexOf(to));
730
+ const index = children.findIndex((child) => child.contains(to));
527
731
  if (index > -1) {
528
732
  const traversed = traverse(current, children[index]);
529
733
  return traversed == null || traversed === -1 ? -1 : distance + Math.abs(index - children.indexOf(current)) + traversed;
@@ -795,18 +999,18 @@ function createHtml(value) {
795
999
  return parsed.body.innerHTML;
796
1000
  }
797
1001
  function createTemplate(value, options) {
798
- const template = document.createElement(TEMPLATE_TAG);
799
- template.innerHTML = createHtml(value);
800
- if (typeof value === "string" && options.cache) templates[value] = template;
801
- return template;
1002
+ const template$1 = document.createElement(TEMPLATE_TAG);
1003
+ template$1.innerHTML = createHtml(value);
1004
+ if (typeof value === "string" && options.cache) templates[value] = template$1;
1005
+ return template$1;
802
1006
  }
803
1007
  function getHtml(value) {
804
1008
  return `${TEMPORARY_ELEMENT}${typeof value === "string" ? value : value.innerHTML}${TEMPORARY_ELEMENT}`;
805
1009
  }
806
1010
  function getNodes(value, options) {
807
1011
  if (typeof value !== "string" && !(value instanceof HTMLTemplateElement)) return [];
808
- const template = getTemplate(value, options);
809
- return template == null ? [] : [...template.content.cloneNode(true).childNodes];
1012
+ const template$1 = getTemplate(value, options);
1013
+ return template$1 == null ? [] : [...template$1.content.cloneNode(true).childNodes];
810
1014
  }
811
1015
  function getOptions(input) {
812
1016
  const options = isPlainObject(input) ? input : {};
@@ -820,8 +1024,8 @@ function getParser() {
820
1024
  function getTemplate(value, options) {
821
1025
  if (value instanceof HTMLTemplateElement) return createTemplate(value, options);
822
1026
  if (value.trim().length === 0) return;
823
- let template = templates[value];
824
- if (template != null) return template;
1027
+ let template$1 = templates[value];
1028
+ if (template$1 != null) return template$1;
825
1029
  const element = EXPRESSION_ID.test(value) ? document.querySelector(`#${value}`) : null;
826
1030
  return createTemplate(element instanceof HTMLTemplateElement ? element : value, options);
827
1031
  }
@@ -831,14 +1035,14 @@ const html = ((value, options) => {
831
1035
  html.clear = () => {
832
1036
  templates = {};
833
1037
  };
834
- html.remove = (template) => {
835
- if (typeof template !== "string" || templates[template] == null) return;
1038
+ html.remove = (template$1) => {
1039
+ if (typeof template$1 !== "string" || templates[template$1] == null) return;
836
1040
  const keys = Object.keys(templates);
837
1041
  const { length } = keys;
838
1042
  const updated = {};
839
1043
  for (let index = 0; index < length; index += 1) {
840
1044
  const key = keys[index];
841
- if (key !== template) updated[key] = templates[key];
1045
+ if (key !== template$1) updated[key] = templates[key];
842
1046
  }
843
1047
  templates = updated;
844
1048
  };
@@ -873,10 +1077,10 @@ function getTextDirection(element, computed) {
873
1077
  return value === "rtl" ? value : "ltr";
874
1078
  }
875
1079
  function setStyle(element, property, value) {
876
- setElementValues(element, property, value, updateStyleProperty);
1080
+ setElementValues(element, property, value, null, updateStyleProperty);
877
1081
  }
878
1082
  function setStyles(element, styles) {
879
- setElementValues(element, styles, null, updateStyleProperty);
1083
+ setElementValues(element, styles, null, null, updateStyleProperty);
880
1084
  }
881
1085
  function toggleStyles(element, styles) {
882
1086
  function toggle(set) {
@@ -909,8 +1113,8 @@ function updateStyleProperty(element, key, value) {
909
1113
  this.style[property] = style;
910
1114
  }, function(property) {
911
1115
  this.style[property] = "";
912
- }, false);
1116
+ }, false, false);
913
1117
  }
914
1118
  const ATTRIBUTE_DIRECTION = "dir";
915
1119
  const EXPRESSION_DIRECTION = /^(ltr|rtl)$/i;
916
- export { findElement as $, findElement, findElements as $$, findElements, dispatch, findAncestor, findRelatives, getData, getElementUnderPointer, getFocusable, getPosition, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEmptyNonBooleanAttribute, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setData, setStyle, setStyles, touch_default as supportsTouch, toggleStyles };
1120
+ export { findElement as $, findElement, findElements as $$, findElements, dispatch, findAncestor, findRelatives, getData, getDistance, getElementUnderPointer, getFocusable, getPosition, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEmptyNonBooleanAttribute, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setData, setStyle, setStyles, touch_default as supportsTouch, toggleStyles };