pseudo-dom 0.9.0 → 0.10.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.
@@ -1,10 +1,10 @@
1
- /**
2
- * A live DOMStringMap-like object for an element's data-* attributes.
3
- * @memberOf module:factories
4
- * @param {*} element The element whose data-* attributes this reflects
5
- * @returns {Object.<string, string>}
6
- */
7
- declare const createDataset: (element: any) => {
8
- [key: string]: string;
9
- };
10
- export default createDataset;
1
+ /**
2
+ * A live DOMStringMap-like object for an element's data-* attributes.
3
+ * @memberOf module:factories
4
+ * @param {*} element The element whose data-* attributes this reflects
5
+ * @returns {Object.<string, string>}
6
+ */
7
+ declare const createDataset: (element: any) => {
8
+ [key: string]: string;
9
+ };
10
+ export default createDataset;
@@ -1,78 +1,78 @@
1
- 'use strict'
2
-
3
- require('core-js/modules/esnext.iterator.constructor.js')
4
- require('core-js/modules/esnext.iterator.map.js')
5
- Object.defineProperty(exports, '__esModule', {
6
- value: true
7
- })
8
- /**
9
- * @file Wraps an element in a Proxy which behaves like the DOM's DOMStringMap (element.dataset): a live view of its
10
- * data-* attributes, under their camelCase names, backed by the element's own getAttribute / setAttribute /
11
- * hasAttribute / removeAttribute (nothing is stored separately, so it can never fall out of sync with the
12
- * attributes).
13
- * @author Joshua Heagle <joshuaheagle@gmail.com>
14
- * @version 1.0.0
15
- */
16
- const createStyleDeclaration_1 = require('./createStyleDeclaration')
17
- const DATA_PREFIX = 'data-'
18
- const attributeName = property => `${DATA_PREFIX}${(0, createStyleDeclaration_1.camelToKebab)(property)}`
19
- /**
20
- * Every data-* attribute name currently on the element, as [attributeName, camelCaseName] pairs.
21
- * @param {*} element
22
- * @returns {Array<Array<string>>}
23
- */
24
- const dataAttributes = element => {
25
- const names = []
26
- for (let index = 0; index < element.attributes.length; index++) {
27
- const name = element.attributes.item(index).name
28
- if (name.indexOf(DATA_PREFIX) === 0 && name.length > DATA_PREFIX.length) {
29
- names.push([name, (0, createStyleDeclaration_1.kebabToCamel)(name.slice(DATA_PREFIX.length))])
30
- }
31
- }
32
- return names
33
- }
34
- /**
35
- * A live DOMStringMap-like object for an element's data-* attributes.
36
- * @memberOf module:factories
37
- * @param {*} element The element whose data-* attributes this reflects
38
- * @returns {Object.<string, string>}
39
- */
40
- const createDataset = element => new Proxy({}, {
41
- get (_target, property) {
42
- if (typeof property !== 'string') {
43
- return undefined
44
- }
45
- const value = element.getAttribute(attributeName(property))
46
- return value === null ? undefined : value
47
- },
48
- set (_target, property, value) {
49
- if (typeof property !== 'string') {
50
- return false
51
- }
52
- element.setAttribute(attributeName(property), String(value))
53
- return true
54
- },
55
- deleteProperty (_target, property) {
56
- if (typeof property === 'string') {
57
- element.removeAttribute(attributeName(property))
58
- }
59
- return true
60
- },
61
- has (_target, property) {
62
- return typeof property === 'string' && element.hasAttribute(attributeName(property))
63
- },
64
- ownKeys () {
65
- return dataAttributes(element).map(([, camelCaseName]) => camelCaseName)
66
- },
67
- getOwnPropertyDescriptor (_target, property) {
68
- if (typeof property !== 'string' || !element.hasAttribute(attributeName(property))) {
69
- return undefined
70
- }
71
- return {
72
- enumerable: true,
73
- configurable: true,
74
- value: element.getAttribute(attributeName(property))
75
- }
76
- }
77
- })
78
- exports.default = createDataset
1
+ 'use strict'
2
+
3
+ require('core-js/modules/esnext.iterator.constructor.js')
4
+ require('core-js/modules/esnext.iterator.map.js')
5
+ Object.defineProperty(exports, '__esModule', {
6
+ value: true
7
+ })
8
+ /**
9
+ * @file Wraps an element in a Proxy which behaves like the DOM's DOMStringMap (element.dataset): a live view of its
10
+ * data-* attributes, under their camelCase names, backed by the element's own getAttribute / setAttribute /
11
+ * hasAttribute / removeAttribute (nothing is stored separately, so it can never fall out of sync with the
12
+ * attributes).
13
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
14
+ * @version 1.0.0
15
+ */
16
+ const createStyleDeclaration_1 = require('./createStyleDeclaration')
17
+ const DATA_PREFIX = 'data-'
18
+ const attributeName = property => `${DATA_PREFIX}${(0, createStyleDeclaration_1.camelToKebab)(property)}`
19
+ /**
20
+ * Every data-* attribute name currently on the element, as [attributeName, camelCaseName] pairs.
21
+ * @param {*} element
22
+ * @returns {Array<Array<string>>}
23
+ */
24
+ const dataAttributes = element => {
25
+ const names = []
26
+ for (let index = 0; index < element.attributes.length; index++) {
27
+ const name = element.attributes.item(index).name
28
+ if (name.indexOf(DATA_PREFIX) === 0 && name.length > DATA_PREFIX.length) {
29
+ names.push([name, (0, createStyleDeclaration_1.kebabToCamel)(name.slice(DATA_PREFIX.length))])
30
+ }
31
+ }
32
+ return names
33
+ }
34
+ /**
35
+ * A live DOMStringMap-like object for an element's data-* attributes.
36
+ * @memberOf module:factories
37
+ * @param {*} element The element whose data-* attributes this reflects
38
+ * @returns {Object.<string, string>}
39
+ */
40
+ const createDataset = element => new Proxy({}, {
41
+ get (_target, property) {
42
+ if (typeof property !== 'string') {
43
+ return undefined
44
+ }
45
+ const value = element.getAttribute(attributeName(property))
46
+ return value === null ? undefined : value
47
+ },
48
+ set (_target, property, value) {
49
+ if (typeof property !== 'string') {
50
+ return false
51
+ }
52
+ element.setAttribute(attributeName(property), String(value))
53
+ return true
54
+ },
55
+ deleteProperty (_target, property) {
56
+ if (typeof property === 'string') {
57
+ element.removeAttribute(attributeName(property))
58
+ }
59
+ return true
60
+ },
61
+ has (_target, property) {
62
+ return typeof property === 'string' && element.hasAttribute(attributeName(property))
63
+ },
64
+ ownKeys () {
65
+ return dataAttributes(element).map(([, camelCaseName]) => camelCaseName)
66
+ },
67
+ getOwnPropertyDescriptor (_target, property) {
68
+ if (typeof property !== 'string' || !element.hasAttribute(attributeName(property))) {
69
+ return undefined
70
+ }
71
+ return {
72
+ enumerable: true,
73
+ configurable: true,
74
+ value: element.getAttribute(attributeName(property))
75
+ }
76
+ }
77
+ })
78
+ exports.default = createDataset
@@ -1,30 +1,30 @@
1
- /**
2
- * @file Wraps a CSSStyleDeclarationService in a Proxy so arbitrary camelCase CSS properties (element.style.
3
- * backgroundColor) work like the DOM's, on top of its real methods (getPropertyValue, setProperty, cssText, ...).
4
- * @author Joshua Heagle <joshuaheagle@gmail.com>
5
- * @version 1.0.0
6
- */
7
- import { CSSStyleDeclarationService } from '../services/CSSStyleDeclarationService';
8
- /**
9
- * kebab-case -> camelCase ("background-color" -> "backgroundColor").
10
- * @param {string} name
11
- * @returns {string}
12
- */
13
- declare const kebabToCamel: (name: string) => string;
14
- /**
15
- * camelCase -> kebab-case ("backgroundColor" -> "background-color").
16
- * @param {string} name
17
- * @returns {string}
18
- */
19
- declare const camelToKebab: (name: string) => string;
20
- /**
21
- * A live CSSStyleDeclaration-like object: its real methods (cssText, getPropertyValue, setProperty, ...) work as
22
- * declared, and any other property name is treated as a camelCase CSS property (declaration.backgroundColor reads /
23
- * writes the "background-color" declaration), matching what a real element.style supports.
24
- * @memberOf module:factories
25
- * @param {string} [cssText=''] Initial declarations
26
- * @returns {CSSStyleDeclarationService}
27
- */
28
- declare const createStyleDeclaration: (cssText?: string) => CSSStyleDeclarationService;
29
- export { kebabToCamel, camelToKebab };
30
- export default createStyleDeclaration;
1
+ /**
2
+ * @file Wraps a CSSStyleDeclarationService in a Proxy so arbitrary camelCase CSS properties (element.style.
3
+ * backgroundColor) work like the DOM's, on top of its real methods (getPropertyValue, setProperty, cssText, ...).
4
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
5
+ * @version 1.0.0
6
+ */
7
+ import { CSSStyleDeclarationService } from '../services/CSSStyleDeclarationService';
8
+ /**
9
+ * kebab-case -> camelCase ("background-color" -> "backgroundColor").
10
+ * @param {string} name
11
+ * @returns {string}
12
+ */
13
+ declare const kebabToCamel: (name: string) => string;
14
+ /**
15
+ * camelCase -> kebab-case ("backgroundColor" -> "background-color").
16
+ * @param {string} name
17
+ * @returns {string}
18
+ */
19
+ declare const camelToKebab: (name: string) => string;
20
+ /**
21
+ * A live CSSStyleDeclaration-like object: its real methods (cssText, getPropertyValue, setProperty, ...) work as
22
+ * declared, and any other property name is treated as a camelCase CSS property (declaration.backgroundColor reads /
23
+ * writes the "background-color" declaration), matching what a real element.style supports.
24
+ * @memberOf module:factories
25
+ * @param {string} [cssText=''] Initial declarations
26
+ * @returns {CSSStyleDeclarationService}
27
+ */
28
+ declare const createStyleDeclaration: (cssText?: string) => CSSStyleDeclarationService;
29
+ export { kebabToCamel, camelToKebab };
30
+ export default createStyleDeclaration;
@@ -1,64 +1,64 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- })
6
- exports.camelToKebab = exports.kebabToCamel = void 0
7
- /**
8
- * @file Wraps a CSSStyleDeclarationService in a Proxy so arbitrary camelCase CSS properties (element.style.
9
- * backgroundColor) work like the DOM's, on top of its real methods (getPropertyValue, setProperty, cssText, ...).
10
- * @author Joshua Heagle <joshuaheagle@gmail.com>
11
- * @version 1.0.0
12
- */
13
- const CSSStyleDeclarationService_1 = require('../services/CSSStyleDeclarationService')
14
- const isIndex = property => /^\d+$/.test(property)
15
- /**
16
- * kebab-case -> camelCase ("background-color" -> "backgroundColor").
17
- * @param {string} name
18
- * @returns {string}
19
- */
20
- const kebabToCamel = name => name.replace(/-([a-z0-9])/gi, (_match, letter) => letter.toUpperCase())
21
- exports.kebabToCamel = kebabToCamel
22
- /**
23
- * camelCase -> kebab-case ("backgroundColor" -> "background-color").
24
- * @param {string} name
25
- * @returns {string}
26
- */
27
- const camelToKebab = name => name.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)
28
- exports.camelToKebab = camelToKebab
29
- /**
30
- * A live CSSStyleDeclaration-like object: its real methods (cssText, getPropertyValue, setProperty, ...) work as
31
- * declared, and any other property name is treated as a camelCase CSS property (declaration.backgroundColor reads /
32
- * writes the "background-color" declaration), matching what a real element.style supports.
33
- * @memberOf module:factories
34
- * @param {string} [cssText=''] Initial declarations
35
- * @returns {CSSStyleDeclarationService}
36
- */
37
- const createStyleDeclaration = (cssText = '') => {
38
- const target = new CSSStyleDeclarationService_1.CSSStyleDeclarationService(cssText)
39
- return new Proxy(target, {
40
- get (declaration, property, receiver) {
41
- if (typeof property !== 'string') {
42
- return Reflect.get(declaration, property, receiver)
43
- }
44
- if (isIndex(property)) {
45
- return declaration.item(Number(property))
46
- }
47
- if (property in declaration) {
48
- return Reflect.get(declaration, property, receiver)
49
- }
50
- return declaration.getPropertyValue(camelToKebab(property))
51
- },
52
- set (declaration, property, value) {
53
- if (typeof property !== 'string' || property === 'cssText') {
54
- return Reflect.set(declaration, property, value)
55
- }
56
- declaration.setProperty(camelToKebab(property), value === null || typeof value === 'undefined' ? '' : String(value))
57
- return true
58
- },
59
- has (declaration, property) {
60
- return typeof property === 'string' && (property in declaration || declaration.getPropertyValue(camelToKebab(property)) !== '')
61
- }
62
- })
63
- }
64
- exports.default = createStyleDeclaration
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
6
+ exports.camelToKebab = exports.kebabToCamel = void 0
7
+ /**
8
+ * @file Wraps a CSSStyleDeclarationService in a Proxy so arbitrary camelCase CSS properties (element.style.
9
+ * backgroundColor) work like the DOM's, on top of its real methods (getPropertyValue, setProperty, cssText, ...).
10
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
11
+ * @version 1.0.0
12
+ */
13
+ const CSSStyleDeclarationService_1 = require('../services/CSSStyleDeclarationService')
14
+ const isIndex = property => /^\d+$/.test(property)
15
+ /**
16
+ * kebab-case -> camelCase ("background-color" -> "backgroundColor").
17
+ * @param {string} name
18
+ * @returns {string}
19
+ */
20
+ const kebabToCamel = name => name.replace(/-([a-z0-9])/gi, (_match, letter) => letter.toUpperCase())
21
+ exports.kebabToCamel = kebabToCamel
22
+ /**
23
+ * camelCase -> kebab-case ("backgroundColor" -> "background-color").
24
+ * @param {string} name
25
+ * @returns {string}
26
+ */
27
+ const camelToKebab = name => name.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)
28
+ exports.camelToKebab = camelToKebab
29
+ /**
30
+ * A live CSSStyleDeclaration-like object: its real methods (cssText, getPropertyValue, setProperty, ...) work as
31
+ * declared, and any other property name is treated as a camelCase CSS property (declaration.backgroundColor reads /
32
+ * writes the "background-color" declaration), matching what a real element.style supports.
33
+ * @memberOf module:factories
34
+ * @param {string} [cssText=''] Initial declarations
35
+ * @returns {CSSStyleDeclarationService}
36
+ */
37
+ const createStyleDeclaration = (cssText = '') => {
38
+ const target = new CSSStyleDeclarationService_1.CSSStyleDeclarationService(cssText)
39
+ return new Proxy(target, {
40
+ get (declaration, property, receiver) {
41
+ if (typeof property !== 'string') {
42
+ return Reflect.get(declaration, property, receiver)
43
+ }
44
+ if (isIndex(property)) {
45
+ return declaration.item(Number(property))
46
+ }
47
+ if (property in declaration) {
48
+ return Reflect.get(declaration, property, receiver)
49
+ }
50
+ return declaration.getPropertyValue(camelToKebab(property))
51
+ },
52
+ set (declaration, property, value) {
53
+ if (typeof property !== 'string' || property === 'cssText') {
54
+ return Reflect.set(declaration, property, value)
55
+ }
56
+ declaration.setProperty(camelToKebab(property), value === null || typeof value === 'undefined' ? '' : String(value))
57
+ return true
58
+ },
59
+ has (declaration, property) {
60
+ return typeof property === 'string' && (property in declaration || declaration.getPropertyValue(camelToKebab(property)) !== '')
61
+ }
62
+ })
63
+ }
64
+ exports.default = createStyleDeclaration
@@ -1,14 +1,14 @@
1
- /**
2
- * @file Substitute for the DOM CSSStyleDeclaration Class. Real instances (from createStyleDeclaration) also accept
3
- * arbitrary camelCase CSS property names (declaration.backgroundColor), which cannot be expressed in an interface.
4
- */
5
- export interface PseudoCSSStyleDeclaration {
6
- get length(): number;
7
- get cssText(): string;
8
- set cssText(cssText: string);
9
- item(index: number): string;
10
- getPropertyValue(property: string): string;
11
- getPropertyPriority(property: string): string;
12
- setProperty(property: string, value: string, priority: string): void;
13
- removeProperty(property: string): string;
14
- }
1
+ /**
2
+ * @file Substitute for the DOM CSSStyleDeclaration Class. Real instances (from createStyleDeclaration) also accept
3
+ * arbitrary camelCase CSS property names (declaration.backgroundColor), which cannot be expressed in an interface.
4
+ */
5
+ export interface PseudoCSSStyleDeclaration {
6
+ get length(): number;
7
+ get cssText(): string;
8
+ set cssText(cssText: string);
9
+ item(index: number): string;
10
+ getPropertyValue(property: string): string;
11
+ getPropertyPriority(property: string): string;
12
+ setProperty(property: string, value: string, priority: string): void;
13
+ removeProperty(property: string): string;
14
+ }
@@ -1,5 +1,5 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- })
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })