@y14e/disclosure-css 2.0.8 → 2.0.9
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/README.md +3 -3
- package/dist/index.bundle.cjs +48 -10
- package/dist/index.bundle.js +48 -10
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -13,11 +13,11 @@ npm i @y14e/disclosure-css
|
|
|
13
13
|
import { Disclosure } from "@y14e/disclosure-css";
|
|
14
14
|
|
|
15
15
|
// CDNs
|
|
16
|
-
import { Disclosure } from "https://esm.sh/@y14e/disclosure-css@2.0.
|
|
16
|
+
import { Disclosure } from "https://esm.sh/@y14e/disclosure-css@2.0.9";
|
|
17
17
|
// or
|
|
18
|
-
import { Disclosure } from "https://cdn.jsdelivr.net/npm/@y14e/disclosure-css@2.0.
|
|
18
|
+
import { Disclosure } from "https://cdn.jsdelivr.net/npm/@y14e/disclosure-css@2.0.9/+esm";
|
|
19
19
|
// or
|
|
20
|
-
import { Disclosure } from "https://esm.unpkg.com/@y14e/disclosure-css@2.0.
|
|
20
|
+
import { Disclosure } from "https://esm.unpkg.com/@y14e/disclosure-css@2.0.9";
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Usage
|
package/dist/index.bundle.cjs
CHANGED
|
@@ -4,12 +4,11 @@
|
|
|
4
4
|
var DEFAULT_PARSER = (value) => value.split(/\s+/);
|
|
5
5
|
var DEFAULT_SERIALIZER = (tokens) => tokens.join(" ");
|
|
6
6
|
function addAttributeToken(element, name, token, options = {}) {
|
|
7
|
+
if (!isValid(element, name, token)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
7
10
|
const value = element.getAttribute(name)?.trim();
|
|
8
|
-
const {
|
|
9
|
-
caseInsensitive = false,
|
|
10
|
-
parse = DEFAULT_PARSER,
|
|
11
|
-
serialize = DEFAULT_SERIALIZER
|
|
12
|
-
} = options;
|
|
11
|
+
const { caseInsensitive, parse, serialize } = resolveOptions(options);
|
|
13
12
|
const tokens = value ? parse(value).filter(Boolean) : [];
|
|
14
13
|
if (caseInsensitive) {
|
|
15
14
|
const lower = token.toLowerCase();
|
|
@@ -49,6 +48,45 @@ function saveAttributes(element_or_elements, name_or_names) {
|
|
|
49
48
|
});
|
|
50
49
|
});
|
|
51
50
|
}
|
|
51
|
+
function isValid(element, name, token) {
|
|
52
|
+
if (!(element instanceof Element)) {
|
|
53
|
+
console.warn("Invalid element");
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (!element.hasAttribute(name)) {
|
|
57
|
+
console.warn("Invalid attribute name");
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if (typeof token !== "string" || !token.trim()) {
|
|
61
|
+
console.warn("Invalid token");
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
function resolveOptions(options) {
|
|
67
|
+
let {
|
|
68
|
+
caseInsensitive = false,
|
|
69
|
+
parse = DEFAULT_PARSER,
|
|
70
|
+
serialize = DEFAULT_SERIALIZER
|
|
71
|
+
} = options;
|
|
72
|
+
if (typeof caseInsensitive !== "boolean") {
|
|
73
|
+
console.warn("Invalid caseInsensitive option. Fallback: false.");
|
|
74
|
+
caseInsensitive = false;
|
|
75
|
+
}
|
|
76
|
+
if (typeof parse !== "function") {
|
|
77
|
+
console.warn(
|
|
78
|
+
"Invalid parser. Fallback: default parser (splits by whitespace)."
|
|
79
|
+
);
|
|
80
|
+
parse = DEFAULT_PARSER;
|
|
81
|
+
}
|
|
82
|
+
if (typeof serialize !== "function") {
|
|
83
|
+
console.warn(
|
|
84
|
+
"Invalid serializer. Fallback: default serializer (joins by whitespace)."
|
|
85
|
+
);
|
|
86
|
+
serialize = DEFAULT_SERIALIZER;
|
|
87
|
+
}
|
|
88
|
+
return { caseInsensitive, parse, serialize };
|
|
89
|
+
}
|
|
52
90
|
|
|
53
91
|
// node_modules/power-focusable/dist/index.js
|
|
54
92
|
var FOCUSABLE_SELECTOR = `:is(a[href], area[href], button, embed, iframe, input:not([type="hidden" i]), object, select, details > summary:first-of-type, textarea, [contenteditable]:not([contenteditable="false" i]), [controls], [tabindex]):not(:disabled, [hidden], [inert], [tabindex="-1"])`;
|
|
@@ -601,8 +639,8 @@ var Disclosure = class _Disclosure {
|
|
|
601
639
|
return;
|
|
602
640
|
}
|
|
603
641
|
this.#rootElement = root;
|
|
604
|
-
this.#defaults = this.#
|
|
605
|
-
this.#settings = this.#
|
|
642
|
+
this.#defaults = this.#resolveOptions(this.#defaults, _Disclosure.defaults);
|
|
643
|
+
this.#settings = this.#resolveOptions(this.#defaults, options);
|
|
606
644
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
607
645
|
this.#detailsElements = [
|
|
608
646
|
...this.#rootElement.querySelectorAll(
|
|
@@ -731,7 +769,7 @@ var Disclosure = class _Disclosure {
|
|
|
731
769
|
#isFocusable(element) {
|
|
732
770
|
return element.tabIndex >= 0;
|
|
733
771
|
}
|
|
734
|
-
#
|
|
772
|
+
#resolveOptions(target, source) {
|
|
735
773
|
const merged = { ...target, ...source };
|
|
736
774
|
if (typeof merged.collapsible !== "boolean") {
|
|
737
775
|
const collapsible = this.#defaults.collapsible;
|
|
@@ -746,7 +784,7 @@ var Disclosure = class _Disclosure {
|
|
|
746
784
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
747
785
|
* Using the <details> and <summary> element.
|
|
748
786
|
*
|
|
749
|
-
* @version 2.0.
|
|
787
|
+
* @version 2.0.9
|
|
750
788
|
* @author Yusuke Kamiyamane
|
|
751
789
|
* @license MIT
|
|
752
790
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -758,7 +796,7 @@ var Disclosure = class _Disclosure {
|
|
|
758
796
|
(**
|
|
759
797
|
* Attribute Utils
|
|
760
798
|
*
|
|
761
|
-
* @version 2.0.
|
|
799
|
+
* @version 2.0.6
|
|
762
800
|
* @author Yusuke Kamiyamane
|
|
763
801
|
* @license MIT
|
|
764
802
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.bundle.js
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
var DEFAULT_PARSER = (value) => value.split(/\s+/);
|
|
3
3
|
var DEFAULT_SERIALIZER = (tokens) => tokens.join(" ");
|
|
4
4
|
function addAttributeToken(element, name, token, options = {}) {
|
|
5
|
+
if (!isValid(element, name, token)) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
5
8
|
const value = element.getAttribute(name)?.trim();
|
|
6
|
-
const {
|
|
7
|
-
caseInsensitive = false,
|
|
8
|
-
parse = DEFAULT_PARSER,
|
|
9
|
-
serialize = DEFAULT_SERIALIZER
|
|
10
|
-
} = options;
|
|
9
|
+
const { caseInsensitive, parse, serialize } = resolveOptions(options);
|
|
11
10
|
const tokens = value ? parse(value).filter(Boolean) : [];
|
|
12
11
|
if (caseInsensitive) {
|
|
13
12
|
const lower = token.toLowerCase();
|
|
@@ -47,6 +46,45 @@ function saveAttributes(element_or_elements, name_or_names) {
|
|
|
47
46
|
});
|
|
48
47
|
});
|
|
49
48
|
}
|
|
49
|
+
function isValid(element, name, token) {
|
|
50
|
+
if (!(element instanceof Element)) {
|
|
51
|
+
console.warn("Invalid element");
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (!element.hasAttribute(name)) {
|
|
55
|
+
console.warn("Invalid attribute name");
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (typeof token !== "string" || !token.trim()) {
|
|
59
|
+
console.warn("Invalid token");
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
function resolveOptions(options) {
|
|
65
|
+
let {
|
|
66
|
+
caseInsensitive = false,
|
|
67
|
+
parse = DEFAULT_PARSER,
|
|
68
|
+
serialize = DEFAULT_SERIALIZER
|
|
69
|
+
} = options;
|
|
70
|
+
if (typeof caseInsensitive !== "boolean") {
|
|
71
|
+
console.warn("Invalid caseInsensitive option. Fallback: false.");
|
|
72
|
+
caseInsensitive = false;
|
|
73
|
+
}
|
|
74
|
+
if (typeof parse !== "function") {
|
|
75
|
+
console.warn(
|
|
76
|
+
"Invalid parser. Fallback: default parser (splits by whitespace)."
|
|
77
|
+
);
|
|
78
|
+
parse = DEFAULT_PARSER;
|
|
79
|
+
}
|
|
80
|
+
if (typeof serialize !== "function") {
|
|
81
|
+
console.warn(
|
|
82
|
+
"Invalid serializer. Fallback: default serializer (joins by whitespace)."
|
|
83
|
+
);
|
|
84
|
+
serialize = DEFAULT_SERIALIZER;
|
|
85
|
+
}
|
|
86
|
+
return { caseInsensitive, parse, serialize };
|
|
87
|
+
}
|
|
50
88
|
|
|
51
89
|
// node_modules/power-focusable/dist/index.js
|
|
52
90
|
var FOCUSABLE_SELECTOR = `:is(a[href], area[href], button, embed, iframe, input:not([type="hidden" i]), object, select, details > summary:first-of-type, textarea, [contenteditable]:not([contenteditable="false" i]), [controls], [tabindex]):not(:disabled, [hidden], [inert], [tabindex="-1"])`;
|
|
@@ -599,8 +637,8 @@ var Disclosure = class _Disclosure {
|
|
|
599
637
|
return;
|
|
600
638
|
}
|
|
601
639
|
this.#rootElement = root;
|
|
602
|
-
this.#defaults = this.#
|
|
603
|
-
this.#settings = this.#
|
|
640
|
+
this.#defaults = this.#resolveOptions(this.#defaults, _Disclosure.defaults);
|
|
641
|
+
this.#settings = this.#resolveOptions(this.#defaults, options);
|
|
604
642
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
605
643
|
this.#detailsElements = [
|
|
606
644
|
...this.#rootElement.querySelectorAll(
|
|
@@ -729,7 +767,7 @@ var Disclosure = class _Disclosure {
|
|
|
729
767
|
#isFocusable(element) {
|
|
730
768
|
return element.tabIndex >= 0;
|
|
731
769
|
}
|
|
732
|
-
#
|
|
770
|
+
#resolveOptions(target, source) {
|
|
733
771
|
const merged = { ...target, ...source };
|
|
734
772
|
if (typeof merged.collapsible !== "boolean") {
|
|
735
773
|
const collapsible = this.#defaults.collapsible;
|
|
@@ -744,7 +782,7 @@ var Disclosure = class _Disclosure {
|
|
|
744
782
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
745
783
|
* Using the <details> and <summary> element.
|
|
746
784
|
*
|
|
747
|
-
* @version 2.0.
|
|
785
|
+
* @version 2.0.9
|
|
748
786
|
* @author Yusuke Kamiyamane
|
|
749
787
|
* @license MIT
|
|
750
788
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -756,7 +794,7 @@ var Disclosure = class _Disclosure {
|
|
|
756
794
|
(**
|
|
757
795
|
* Attribute Utils
|
|
758
796
|
*
|
|
759
|
-
* @version 2.0.
|
|
797
|
+
* @version 2.0.6
|
|
760
798
|
* @author Yusuke Kamiyamane
|
|
761
799
|
* @license MIT
|
|
762
800
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.cjs
CHANGED
|
@@ -45,8 +45,8 @@ var Disclosure = class _Disclosure {
|
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
this.#rootElement = root;
|
|
48
|
-
this.#defaults = this.#
|
|
49
|
-
this.#settings = this.#
|
|
48
|
+
this.#defaults = this.#resolveOptions(this.#defaults, _Disclosure.defaults);
|
|
49
|
+
this.#settings = this.#resolveOptions(this.#defaults, options);
|
|
50
50
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
51
51
|
this.#detailsElements = [
|
|
52
52
|
...this.#rootElement.querySelectorAll(
|
|
@@ -175,7 +175,7 @@ var Disclosure = class _Disclosure {
|
|
|
175
175
|
#isFocusable(element) {
|
|
176
176
|
return element.tabIndex >= 0;
|
|
177
177
|
}
|
|
178
|
-
#
|
|
178
|
+
#resolveOptions(target, source) {
|
|
179
179
|
const merged = { ...target, ...source };
|
|
180
180
|
if (typeof merged.collapsible !== "boolean") {
|
|
181
181
|
const collapsible = this.#defaults.collapsible;
|
|
@@ -190,7 +190,7 @@ var Disclosure = class _Disclosure {
|
|
|
190
190
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
191
191
|
* Using the <details> and <summary> element.
|
|
192
192
|
*
|
|
193
|
-
* @version 2.0.
|
|
193
|
+
* @version 2.0.9
|
|
194
194
|
* @author Yusuke Kamiyamane
|
|
195
195
|
* @license MIT
|
|
196
196
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -23,8 +23,8 @@ var Disclosure = class _Disclosure {
|
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
this.#rootElement = root;
|
|
26
|
-
this.#defaults = this.#
|
|
27
|
-
this.#settings = this.#
|
|
26
|
+
this.#defaults = this.#resolveOptions(this.#defaults, _Disclosure.defaults);
|
|
27
|
+
this.#settings = this.#resolveOptions(this.#defaults, options);
|
|
28
28
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
29
29
|
this.#detailsElements = [
|
|
30
30
|
...this.#rootElement.querySelectorAll(
|
|
@@ -153,7 +153,7 @@ var Disclosure = class _Disclosure {
|
|
|
153
153
|
#isFocusable(element) {
|
|
154
154
|
return element.tabIndex >= 0;
|
|
155
155
|
}
|
|
156
|
-
#
|
|
156
|
+
#resolveOptions(target, source) {
|
|
157
157
|
const merged = { ...target, ...source };
|
|
158
158
|
if (typeof merged.collapsible !== "boolean") {
|
|
159
159
|
const collapsible = this.#defaults.collapsible;
|
|
@@ -168,7 +168,7 @@ var Disclosure = class _Disclosure {
|
|
|
168
168
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
169
169
|
* Using the <details> and <summary> element.
|
|
170
170
|
*
|
|
171
|
-
* @version 2.0.
|
|
171
|
+
* @version 2.0.9
|
|
172
172
|
* @author Yusuke Kamiyamane
|
|
173
173
|
* @license MIT
|
|
174
174
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/disclosure-css",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"description": "WAI-ARIA compliant disclosure pattern implementation in TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"esbuild": true
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@y14e/attribute-utils": "^2.0.
|
|
57
|
+
"@y14e/attribute-utils": "^2.0.6",
|
|
58
58
|
"@y14e/roving-tabindex": "^3.1.25"
|
|
59
59
|
}
|
|
60
60
|
}
|