@oscarpalmer/toretto 0.43.0 → 0.44.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/data.mjs +1 -1
- package/dist/index.mjs +23 -19
- package/dist/internal/attribute.mjs +2 -1
- package/dist/internal/element-value.mjs +6 -1
- package/dist/internal/get-value.mjs +1 -1
- package/dist/style.mjs +3 -2
- package/package.json +1 -1
- package/src/internal/attribute.ts +2 -1
- package/src/internal/element-value.ts +11 -2
- package/src/style.ts +3 -2
package/dist/data.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isHTMLOrSVGElement } from "./internal/is.mjs";
|
|
2
2
|
import { setElementValues, updateElementValue } from "./internal/element-value.mjs";
|
|
3
3
|
import { EXPRESSION_DATA_PREFIX } from "./internal/get-value.mjs";
|
|
4
|
-
import { camelCase, kebabCase } from "@oscarpalmer/atoms/string/case";
|
|
5
4
|
import { parse } from "@oscarpalmer/atoms/string";
|
|
5
|
+
import { camelCase, kebabCase } from "@oscarpalmer/atoms/string/case";
|
|
6
6
|
//#region src/data.ts
|
|
7
7
|
function getData(element, keys, parseValues) {
|
|
8
8
|
if (!isHTMLOrSVGElement(element)) return;
|
package/dist/index.mjs
CHANGED
|
@@ -105,6 +105,21 @@ function isNullableOrWhitespace(value) {
|
|
|
105
105
|
}
|
|
106
106
|
const EXPRESSION_WHITESPACE$1 = /^\s*$/;
|
|
107
107
|
//#endregion
|
|
108
|
+
//#region node_modules/@oscarpalmer/atoms/dist/string/index.mjs
|
|
109
|
+
/**
|
|
110
|
+
* Parse a JSON string into its proper value _(or `undefined` if it fails)_
|
|
111
|
+
* @param value JSON string to parse
|
|
112
|
+
* @param reviver Reviver function to transform the parsed values
|
|
113
|
+
* @returns Parsed value or `undefined` if parsing fails
|
|
114
|
+
*/
|
|
115
|
+
function parse(value, reviver) {
|
|
116
|
+
try {
|
|
117
|
+
return JSON.parse(value, reviver);
|
|
118
|
+
} catch {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
108
123
|
//#region node_modules/@oscarpalmer/atoms/dist/internal/number.mjs
|
|
109
124
|
/**
|
|
110
125
|
* Clamp a number between a minimum and maximum value
|
|
@@ -406,6 +421,10 @@ const CHILD_NODE_TYPES = new Set([
|
|
|
406
421
|
]);
|
|
407
422
|
//#endregion
|
|
408
423
|
//#region src/internal/element-value.ts
|
|
424
|
+
function ignoreSetAttribute(element, name) {
|
|
425
|
+
if (element instanceof HTMLTextAreaElement && name === "value") return true;
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
409
428
|
function normalizeKey(key, style) {
|
|
410
429
|
return style && key.startsWith(CSS_VARIABLE_PREFIX$1) ? key : kebabCase(key);
|
|
411
430
|
}
|
|
@@ -435,7 +454,7 @@ function setElementValues(element, first, second, third, callback, style) {
|
|
|
435
454
|
}
|
|
436
455
|
function updateElementValue(element, key, value, set, remove, isBoolean, json) {
|
|
437
456
|
if (isBoolean ? value == null : isNullableOrWhitespace(value)) remove.call(element, key);
|
|
438
|
-
else set.call(element, key, json ? JSON.stringify(value) :
|
|
457
|
+
else if (!ignoreSetAttribute(element, key)) set.call(element, key, json ? JSON.stringify(value) : getString(value));
|
|
439
458
|
}
|
|
440
459
|
const CSS_VARIABLE_PREFIX$1 = "--";
|
|
441
460
|
//#endregion
|
|
@@ -485,7 +504,7 @@ function handleAttribute(callback, decode, first, second) {
|
|
|
485
504
|
let value;
|
|
486
505
|
if (isAttribute(first)) {
|
|
487
506
|
name = first.name;
|
|
488
|
-
value =
|
|
507
|
+
value = getString(first.value);
|
|
489
508
|
} else if (typeof first === "string" && typeof second === "string") {
|
|
490
509
|
name = first;
|
|
491
510
|
value = second;
|
|
@@ -562,21 +581,6 @@ const dispatchedAttributes = new Set([
|
|
|
562
581
|
const formElement = document.createElement("form");
|
|
563
582
|
let textArea;
|
|
564
583
|
//#endregion
|
|
565
|
-
//#region node_modules/@oscarpalmer/atoms/dist/string/index.mjs
|
|
566
|
-
/**
|
|
567
|
-
* Parse a JSON string into its proper value _(or `undefined` if it fails)_
|
|
568
|
-
* @param value JSON string to parse
|
|
569
|
-
* @param reviver Reviver function to transform the parsed values
|
|
570
|
-
* @returns Parsed value or `undefined` if parsing fails
|
|
571
|
-
*/
|
|
572
|
-
function parse(value, reviver) {
|
|
573
|
-
try {
|
|
574
|
-
return JSON.parse(value, reviver);
|
|
575
|
-
} catch {
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
//#endregion
|
|
580
584
|
//#region src/internal/get-value.ts
|
|
581
585
|
function getBoolean(value, defaultValue) {
|
|
582
586
|
return typeof value === "boolean" ? value : defaultValue ?? false;
|
|
@@ -725,8 +729,8 @@ function toggleStyles(element, styles) {
|
|
|
725
729
|
}
|
|
726
730
|
function updateStyleProperty(element, key, value) {
|
|
727
731
|
updateElementValue(element, key, value, function(property, style) {
|
|
728
|
-
if (property.startsWith(VARIABLE_PREFIX)) this.style.setProperty(property,
|
|
729
|
-
else this.style[property] =
|
|
732
|
+
if (property.startsWith(VARIABLE_PREFIX)) this.style.setProperty(property, getString(style));
|
|
733
|
+
else this.style[property] = getString(style);
|
|
730
734
|
}, function(property) {
|
|
731
735
|
if (property.startsWith(VARIABLE_PREFIX)) this.style.removeProperty(property);
|
|
732
736
|
else this.style[property] = "";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { updateElementValue } from "./element-value.mjs";
|
|
2
2
|
import { updateProperty } from "./property.mjs";
|
|
3
3
|
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
4
|
+
import { getString } from "@oscarpalmer/atoms/string";
|
|
4
5
|
import { kebabCase } from "@oscarpalmer/atoms/string/case";
|
|
5
6
|
//#region src/internal/attribute.ts
|
|
6
7
|
function badAttributeHandler(name, value) {
|
|
@@ -26,7 +27,7 @@ function handleAttribute(callback, decode, first, second) {
|
|
|
26
27
|
let value;
|
|
27
28
|
if (isAttribute(first)) {
|
|
28
29
|
name = first.name;
|
|
29
|
-
value =
|
|
30
|
+
value = getString(first.value);
|
|
30
31
|
} else if (typeof first === "string" && typeof second === "string") {
|
|
31
32
|
name = first;
|
|
32
33
|
value = second;
|
|
@@ -2,8 +2,13 @@ import { isHTMLOrSVGElement } from "./is.mjs";
|
|
|
2
2
|
import "../is.mjs";
|
|
3
3
|
import { isAttribute } from "./attribute.mjs";
|
|
4
4
|
import { isNullableOrWhitespace } from "@oscarpalmer/atoms/is";
|
|
5
|
+
import { getString } from "@oscarpalmer/atoms/string";
|
|
5
6
|
import { kebabCase } from "@oscarpalmer/atoms/string/case";
|
|
6
7
|
//#region src/internal/element-value.ts
|
|
8
|
+
function ignoreSetAttribute(element, name) {
|
|
9
|
+
if (element instanceof HTMLTextAreaElement && name === "value") return true;
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
7
12
|
function normalizeKey(key, style) {
|
|
8
13
|
return style && key.startsWith(CSS_VARIABLE_PREFIX) ? key : kebabCase(key);
|
|
9
14
|
}
|
|
@@ -33,7 +38,7 @@ function setElementValues(element, first, second, third, callback, style) {
|
|
|
33
38
|
}
|
|
34
39
|
function updateElementValue(element, key, value, set, remove, isBoolean, json) {
|
|
35
40
|
if (isBoolean ? value == null : isNullableOrWhitespace(value)) remove.call(element, key);
|
|
36
|
-
else set.call(element, key, json ? JSON.stringify(value) :
|
|
41
|
+
else if (!ignoreSetAttribute(element, key)) set.call(element, key, json ? JSON.stringify(value) : getString(value));
|
|
37
42
|
}
|
|
38
43
|
const CSS_VARIABLE_PREFIX = "--";
|
|
39
44
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { camelCase, kebabCase } from "@oscarpalmer/atoms/string/case";
|
|
2
1
|
import { parse } from "@oscarpalmer/atoms/string";
|
|
2
|
+
import { camelCase, kebabCase } from "@oscarpalmer/atoms/string/case";
|
|
3
3
|
//#region src/internal/get-value.ts
|
|
4
4
|
function getBoolean(value, defaultValue) {
|
|
5
5
|
return typeof value === "boolean" ? value : defaultValue ?? false;
|
package/dist/style.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isHTMLOrSVGElement } from "./internal/is.mjs";
|
|
2
2
|
import { setElementValues, updateElementValue } from "./internal/element-value.mjs";
|
|
3
3
|
import { getStyleValue } from "./internal/get-value.mjs";
|
|
4
|
+
import { getString } from "@oscarpalmer/atoms/string";
|
|
4
5
|
//#region src/style.ts
|
|
5
6
|
/**
|
|
6
7
|
* Get a style from an element
|
|
@@ -89,8 +90,8 @@ function toggleStyles(element, styles) {
|
|
|
89
90
|
}
|
|
90
91
|
function updateStyleProperty(element, key, value) {
|
|
91
92
|
updateElementValue(element, key, value, function(property, style) {
|
|
92
|
-
if (property.startsWith(VARIABLE_PREFIX)) this.style.setProperty(property,
|
|
93
|
-
else this.style[property] =
|
|
93
|
+
if (property.startsWith(VARIABLE_PREFIX)) this.style.setProperty(property, getString(style));
|
|
94
|
+
else this.style[property] = getString(style);
|
|
94
95
|
}, function(property) {
|
|
95
96
|
if (property.startsWith(VARIABLE_PREFIX)) this.style.removeProperty(property);
|
|
96
97
|
else this.style[property] = "";
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {isPlainObject} from '@oscarpalmer/atoms/is';
|
|
2
2
|
import type {PlainObject} from '@oscarpalmer/atoms/models';
|
|
3
|
+
import {getString} from '@oscarpalmer/atoms/string';
|
|
3
4
|
import {kebabCase} from '@oscarpalmer/atoms/string/case';
|
|
4
5
|
import type {Attribute} from '../models';
|
|
5
6
|
import {updateElementValue} from './element-value';
|
|
@@ -65,7 +66,7 @@ function handleAttribute(
|
|
|
65
66
|
|
|
66
67
|
if (isAttribute(first)) {
|
|
67
68
|
name = first.name;
|
|
68
|
-
value =
|
|
69
|
+
value = getString(first.value);
|
|
69
70
|
} else if (typeof first === 'string' && typeof second === 'string') {
|
|
70
71
|
name = first;
|
|
71
72
|
value = second;
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import {isNullableOrWhitespace} from '@oscarpalmer/atoms/is';
|
|
2
|
+
import {getString} from '@oscarpalmer/atoms/string';
|
|
2
3
|
import {kebabCase} from '@oscarpalmer/atoms/string/case';
|
|
3
4
|
import {isHTMLOrSVGElement} from '../is';
|
|
4
5
|
import {isAttribute} from './attribute';
|
|
5
6
|
|
|
6
7
|
// #region Functions
|
|
7
8
|
|
|
9
|
+
function ignoreSetAttribute(element: Element, name: string): boolean {
|
|
10
|
+
if (element instanceof HTMLTextAreaElement && name === 'value') {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
8
17
|
function normalizeKey(key: string, style?: boolean): string {
|
|
9
18
|
return style && key.startsWith(CSS_VARIABLE_PREFIX) ? key : kebabCase(key);
|
|
10
19
|
}
|
|
@@ -77,8 +86,8 @@ export function updateElementValue(
|
|
|
77
86
|
): void {
|
|
78
87
|
if (isBoolean ? value == null : isNullableOrWhitespace(value)) {
|
|
79
88
|
remove.call(element, key);
|
|
80
|
-
} else {
|
|
81
|
-
set.call(element, key, json ? JSON.stringify(value) :
|
|
89
|
+
} else if (!ignoreSetAttribute(element, key)) {
|
|
90
|
+
set.call(element, key, json ? JSON.stringify(value) : getString(value));
|
|
82
91
|
}
|
|
83
92
|
}
|
|
84
93
|
|
package/src/style.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {getString} from '@oscarpalmer/atoms/string';
|
|
1
2
|
import {setElementValues, updateElementValue} from './internal/element-value';
|
|
2
3
|
import {getStyleValue} from './internal/get-value';
|
|
3
4
|
import {isHTMLOrSVGElement} from './internal/is';
|
|
@@ -187,9 +188,9 @@ function updateStyleProperty(element: Element, key: string, value: unknown): voi
|
|
|
187
188
|
value,
|
|
188
189
|
function (this: Element, property: string, style: unknown) {
|
|
189
190
|
if (property.startsWith(VARIABLE_PREFIX)) {
|
|
190
|
-
(this as HTMLElement).style.setProperty(property,
|
|
191
|
+
(this as HTMLElement).style.setProperty(property, getString(style));
|
|
191
192
|
} else {
|
|
192
|
-
(this as HTMLElement).style[property as never] =
|
|
193
|
+
(this as HTMLElement).style[property as never] = getString(style);
|
|
193
194
|
}
|
|
194
195
|
},
|
|
195
196
|
function (this: Element, property: string) {
|