@d3plus/dom 3.1.0 → 3.1.2
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 +17 -14
- package/es/index.js +2 -0
- package/es/index.js.map +1 -0
- package/es/src/D3Selection.js +2 -0
- package/es/src/D3Selection.js.map +1 -0
- package/es/src/assign.js +2 -0
- package/es/src/assign.js.map +1 -0
- package/es/src/attrize.js +2 -0
- package/es/src/attrize.js.map +1 -0
- package/es/src/backgroundColor.js +2 -0
- package/es/src/backgroundColor.js.map +1 -0
- package/es/src/date.js +2 -0
- package/es/src/date.js.map +1 -0
- package/es/src/elem.js +2 -0
- package/es/src/elem.js.map +1 -0
- package/es/src/fontExists.js +2 -0
- package/es/src/fontExists.js.map +1 -0
- package/es/src/getSize.js +2 -0
- package/es/src/getSize.js.map +1 -0
- package/es/src/inViewport.js +2 -0
- package/es/src/inViewport.js.map +1 -0
- package/es/src/isObject.js +2 -0
- package/es/src/isObject.js.map +1 -0
- package/es/src/parseSides.js +2 -0
- package/es/src/parseSides.js.map +1 -0
- package/es/src/rtl.js +2 -0
- package/es/src/rtl.js.map +1 -0
- package/es/src/stylize.js +2 -0
- package/es/src/stylize.js.map +1 -0
- package/es/src/textWidth.js +2 -0
- package/es/src/textWidth.js.map +1 -0
- package/package.json +4 -3
- package/umd/d3plus-dom.full.js +4155 -501
- package/umd/d3plus-dom.full.js.map +1 -1
- package/umd/d3plus-dom.full.min.js +71 -44
- package/umd/d3plus-dom.js +1 -1
- package/umd/d3plus-dom.min.js +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# @d3plus/dom
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@d3plus/dom)
|
|
4
|
+
[](https://codecov.io/gh/d3plus/d3plus/flags)
|
|
5
|
+
|
|
3
6
|
JavaScript functions for manipulating and analyzing DOM elements.
|
|
4
7
|
|
|
5
8
|
## Installing
|
|
@@ -52,7 +55,7 @@ Live examples can be found on [d3plus.org](https://d3plus.org/), which includes
|
|
|
52
55
|
|
|
53
56
|
> **assign**(...`objects`: `Record`\<`string`, `unknown`\>[]): `Record`\<`string`, `unknown`\>
|
|
54
57
|
|
|
55
|
-
Defined in: [assign.ts:21](https://github.com/d3plus/d3plus/blob/
|
|
58
|
+
Defined in: [assign.ts:21](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/dom/src/assign.ts#L21)
|
|
56
59
|
|
|
57
60
|
A deeply recursive version of `Object.assign`.
|
|
58
61
|
|
|
@@ -84,7 +87,7 @@ assign({id: "foo", deep: {group: "A"}}, {id: "bar", deep: {value: 20}}));
|
|
|
84
87
|
|
|
85
88
|
> **attrize**(`e`: `Attrable`, `a?`: `Record`\<`string`, `string` \| `number` \| `boolean` \| `null`\>): `void`
|
|
86
89
|
|
|
87
|
-
Defined in: [attrize.ts:8](https://github.com/d3plus/d3plus/blob/
|
|
90
|
+
Defined in: [attrize.ts:8](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/dom/src/attrize.ts#L8)
|
|
88
91
|
|
|
89
92
|
Applies each key/value in an object as an attr.
|
|
90
93
|
|
|
@@ -107,7 +110,7 @@ Applies each key/value in an object as an attr.
|
|
|
107
110
|
|
|
108
111
|
> **backgroundColor**(`elem`: `Element`): `string`
|
|
109
112
|
|
|
110
|
-
Defined in: [backgroundColor.ts:7](https://github.com/d3plus/d3plus/blob/
|
|
113
|
+
Defined in: [backgroundColor.ts:7](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/dom/src/backgroundColor.ts#L7)
|
|
111
114
|
|
|
112
115
|
Given a DOM element, returns its background color by walking up the
|
|
113
116
|
ancestor chain until a non-transparent background is found. Falls back
|
|
@@ -131,7 +134,7 @@ to "rgb(255, 255, 255)" (white) if every ancestor is transparent.
|
|
|
131
134
|
|
|
132
135
|
> **date**(`d`: `string` \| `number` \| `false` \| `undefined`): `false` \| `Date` \| `undefined`
|
|
133
136
|
|
|
134
|
-
Defined in: [date.ts:5](https://github.com/d3plus/d3plus/blob/
|
|
137
|
+
Defined in: [date.ts:5](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/dom/src/date.ts#L5)
|
|
135
138
|
|
|
136
139
|
Parses numbers and strings into valid JavaScript Date objects, supporting years, quarters, months, and ISO 8601 formats.
|
|
137
140
|
|
|
@@ -153,7 +156,7 @@ Parses numbers and strings into valid JavaScript Date objects, supporting years,
|
|
|
153
156
|
|
|
154
157
|
> **elem**(`selector`: `string`, `p?`: `ElemParams`): `Selection`
|
|
155
158
|
|
|
156
|
-
Defined in: [elem.ts:28](https://github.com/d3plus/d3plus/blob/
|
|
159
|
+
Defined in: [elem.ts:28](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/dom/src/elem.ts#L28)
|
|
157
160
|
|
|
158
161
|
Manages the enter/update/exit pattern for a single DOM element, applying enter, update, and exit attributes with optional transitions.
|
|
159
162
|
|
|
@@ -176,7 +179,7 @@ Manages the enter/update/exit pattern for a single DOM element, applying enter,
|
|
|
176
179
|
|
|
177
180
|
> **fontExists**(`font`: `string` \| `string`[]): `string` \| `false`
|
|
178
181
|
|
|
179
|
-
Defined in: [fontExists.ts:13](https://github.com/d3plus/d3plus/blob/
|
|
182
|
+
Defined in: [fontExists.ts:13](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/dom/src/fontExists.ts#L13)
|
|
180
183
|
|
|
181
184
|
Given either a single font-family or a list of fonts, returns the name of the first font that can be rendered, or `false` if none are installed on the user's machine.
|
|
182
185
|
|
|
@@ -198,7 +201,7 @@ Given either a single font-family or a list of fonts, returns the name of the fi
|
|
|
198
201
|
|
|
199
202
|
> **inViewport**(`elem`: `Element`, `buffer?`: `number`): `boolean`
|
|
200
203
|
|
|
201
|
-
Defined in: [inViewport.ts:6](https://github.com/d3plus/d3plus/blob/
|
|
204
|
+
Defined in: [inViewport.ts:6](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/dom/src/inViewport.ts#L6)
|
|
202
205
|
|
|
203
206
|
Determines whether a given DOM element is visible within the current viewport, with an optional pixel buffer.
|
|
204
207
|
|
|
@@ -221,7 +224,7 @@ Determines whether a given DOM element is visible within the current viewport, w
|
|
|
221
224
|
|
|
222
225
|
> **isObject**(`item`: `unknown`): `boolean`
|
|
223
226
|
|
|
224
|
-
Defined in: [isObject.ts:5](https://github.com/d3plus/d3plus/blob/
|
|
227
|
+
Defined in: [isObject.ts:5](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/dom/src/isObject.ts#L5)
|
|
225
228
|
|
|
226
229
|
Detects if a variable is a javascript Object.
|
|
227
230
|
|
|
@@ -243,7 +246,7 @@ Detects if a variable is a javascript Object.
|
|
|
243
246
|
|
|
244
247
|
> **parseSides**(`sides`: `string` \| `number`): `ParsedSides`
|
|
245
248
|
|
|
246
|
-
Defined in: [parseSides.ts:12](https://github.com/d3plus/d3plus/blob/
|
|
249
|
+
Defined in: [parseSides.ts:12](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/dom/src/parseSides.ts#L12)
|
|
247
250
|
|
|
248
251
|
Converts a string of directional CSS shorthand values into an object with the values expanded.
|
|
249
252
|
|
|
@@ -265,7 +268,7 @@ Converts a string of directional CSS shorthand values into an object with the va
|
|
|
265
268
|
|
|
266
269
|
> **rtl**(): `boolean`
|
|
267
270
|
|
|
268
|
-
Defined in: [rtl.ts:4](https://github.com/d3plus/d3plus/blob/
|
|
271
|
+
Defined in: [rtl.ts:4](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/dom/src/rtl.ts#L4)
|
|
269
272
|
|
|
270
273
|
Returns `true` if the HTML or body element has either the "dir" HTML attribute or the "direction" CSS property set to "rtl".
|
|
271
274
|
|
|
@@ -281,7 +284,7 @@ Returns `true` if the HTML or body element has either the "dir" HTML attribute o
|
|
|
281
284
|
|
|
282
285
|
> **stylize**(`e`: `Stylable`, `s?`: `Record`\<`string`, `string` \| `number` \| `boolean` \| `null`\>): `void`
|
|
283
286
|
|
|
284
|
-
Defined in: [stylize.ts:8](https://github.com/d3plus/d3plus/blob/
|
|
287
|
+
Defined in: [stylize.ts:8](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/dom/src/stylize.ts#L8)
|
|
285
288
|
|
|
286
289
|
Applies each key/value in an object as a style.
|
|
287
290
|
|
|
@@ -306,7 +309,7 @@ Applies each key/value in an object as a style.
|
|
|
306
309
|
|
|
307
310
|
> **textWidth**(`text`: `string`, `style?`: `Record`\<`string`, `string` \| `number`\>): `number`
|
|
308
311
|
|
|
309
|
-
Defined in: [textWidth.ts:49](https://github.com/d3plus/d3plus/blob/
|
|
312
|
+
Defined in: [textWidth.ts:49](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/dom/src/textWidth.ts#L49)
|
|
310
313
|
|
|
311
314
|
Given a text string, returns the predicted pixel width of the string when placed into DOM.
|
|
312
315
|
|
|
@@ -325,7 +328,7 @@ Given a text string, returns the predicted pixel width of the string when placed
|
|
|
325
328
|
|
|
326
329
|
> **textWidth**(`text`: `string`[], `style?`: `Record`\<`string`, `string` \| `number`\>): `number`[]
|
|
327
330
|
|
|
328
|
-
Defined in: [textWidth.ts:53](https://github.com/d3plus/d3plus/blob/
|
|
331
|
+
Defined in: [textWidth.ts:53](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/dom/src/textWidth.ts#L53)
|
|
329
332
|
|
|
330
333
|
##### Parameters
|
|
331
334
|
|
|
@@ -346,4 +349,4 @@ Defined in: [textWidth.ts:53](https://github.com/d3plus/d3plus/blob/e9db3c743521
|
|
|
346
349
|
|
|
347
350
|
> **D3Selection** = `ReturnType`\<*typeof* `select`\>
|
|
348
351
|
|
|
349
|
-
Defined in: [D3Selection.ts:12](https://github.com/d3plus/d3plus/blob/
|
|
352
|
+
Defined in: [D3Selection.ts:12](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/dom/src/D3Selection.ts#L12)
|
package/es/index.js
CHANGED
|
@@ -11,3 +11,5 @@ export { default as parseSides } from "./src/parseSides.js";
|
|
|
11
11
|
export { default as rtl } from "./src/rtl.js";
|
|
12
12
|
export { default as stylize } from "./src/stylize.js";
|
|
13
13
|
export { default as textWidth } from "./src/textWidth.js";
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
package/es/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["export type {D3Selection} from \"./src/D3Selection.js\";\nexport {default as assign} from \"./src/assign.js\";\nexport {default as backgroundColor} from \"./src/backgroundColor.js\";\nexport {default as attrize} from \"./src/attrize.js\";\nexport {default as date} from \"./src/date.js\";\nexport {default as elem} from \"./src/elem.js\";\nexport {default as fontExists} from \"./src/fontExists.js\";\nexport {default as getSize} from \"./src/getSize.js\";\nexport {default as inViewport} from \"./src/inViewport.js\";\nexport {default as isObject} from \"./src/isObject.js\";\nexport {default as parseSides} from \"./src/parseSides.js\";\nexport {default as rtl} from \"./src/rtl.js\";\nexport {default as stylize} from \"./src/stylize.js\";\nexport {default as textWidth} from \"./src/textWidth.js\";\n"],"names":["default","assign","backgroundColor","attrize","date","elem","fontExists","getSize","inViewport","isObject","parseSides","rtl","stylize","textWidth"],"mappings":"AACA,SAAQA,WAAWC,MAAM,QAAO,kBAAkB;AAClD,SAAQD,WAAWE,eAAe,QAAO,2BAA2B;AACpE,SAAQF,WAAWG,OAAO,QAAO,mBAAmB;AACpD,SAAQH,WAAWI,IAAI,QAAO,gBAAgB;AAC9C,SAAQJ,WAAWK,IAAI,QAAO,gBAAgB;AAC9C,SAAQL,WAAWM,UAAU,QAAO,sBAAsB;AAC1D,SAAQN,WAAWO,OAAO,QAAO,mBAAmB;AACpD,SAAQP,WAAWQ,UAAU,QAAO,sBAAsB;AAC1D,SAAQR,WAAWS,QAAQ,QAAO,oBAAoB;AACtD,SAAQT,WAAWU,UAAU,QAAO,sBAAsB;AAC1D,SAAQV,WAAWW,GAAG,QAAO,eAAe;AAC5C,SAAQX,WAAWY,OAAO,QAAO,mBAAmB;AACpD,SAAQZ,WAAWa,SAAS,QAAO,qBAAqB"}
|
package/es/src/D3Selection.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/D3Selection.ts"],"sourcesContent":["import {select} from \"d3-selection\";\nimport {transition} from \"d3-transition\";\n\n/**\n @type D3Selection\n A permissive D3 selection type that accepts any generic parameterisation.\n Uses `any` for the parent/datum generics because d3plus utility functions\n (attrize, stylize, elem) must work with every combination.\n*/\n \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type D3Selection = ReturnType<typeof select<any, any>>;\n\n/**\n @type D3Transition\n A D3 transition type derived from the return type of d3-transition's transition function.\n*/\nexport type D3Transition = ReturnType<typeof transition>;\n\n/**\n @interface Attrable\n Anything that supports `.attr(name, value)` — both Selection and Transition.\n*/\nexport interface Attrable {\n attr(name: string, value: string | number | boolean | null): this;\n}\n\n/**\n @interface Stylable\n Anything that supports `.style(name, value)` — both Selection and Transition.\n*/\nexport interface Stylable {\n style(name: string, value: string | number | boolean | null): this;\n}\n"],"names":[],"mappings":"AA2BA;;;AAGA,GACA,WAEC"}
|
package/es/src/assign.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/assign.ts"],"sourcesContent":["import isObject from \"./isObject.js\";\n\n/**\n Determines if the object passed is the document or window.\n @param obj @private\n*/\nfunction validObject(obj: Record<string, unknown>): boolean {\n if (typeof window === \"undefined\") return true;\n else return (obj as unknown) !== window && (obj as unknown) !== document;\n}\n\n/**\n A deeply recursive version of `Object.assign`.\n\n@example <caption>this</caption>\nassign({id: \"foo\", deep: {group: \"A\"}}, {id: \"bar\", deep: {value: 20}}));\n @example <caption>returns this</caption>\n{id: \"bar\", deep: {group: \"A\", value: 20}}\n @param objects The source objects to merge into the target.\n*/\nfunction assign(...objects: Record<string, unknown>[]): Record<string, unknown> {\n const target = objects[0];\n for (let i = 1; i < objects.length; i++) {\n const source = objects[i];\n if (!isObject(source)) continue;\n\n Object.keys(source).forEach(prop => {\n const value = source[prop];\n\n if (isObject(value) && validObject(value as Record<string, unknown>)) {\n if (\n Object.prototype.hasOwnProperty.call(target, prop) &&\n isObject(target[prop])\n )\n target[prop] = assign({}, target[prop] as Record<string, unknown>, value as Record<string, unknown>);\n else target[prop] = assign({}, value as Record<string, unknown>);\n } else if (Array.isArray(value)) target[prop] = value.slice();\n else target[prop] = value;\n });\n }\n\n return target;\n}\n\nexport default assign;\n"],"names":["isObject","validObject","obj","window","document","assign","source","objects","i","Object","keys","forEach","prop","value","prototype","hasOwnProperty","call","target","Array","isArray","slice","length"],"mappings":"AAAA,OAAOA,cAAc,gBAAgB;AAErC;;;AAGA,GACA,SAASC,YAAYC,GAA4B;IAC/C,IAAI,OAAOC,WAAW,aAAa,OAAO;SACrC,OAAO,AAACD,QAAoBC,UAAU,AAACD,QAAoBE;AAClE;AAEA;;;;;;;;AAQA,GACA,SAASC;;QAGL,IAAMC,SAASC,OAAO,CAACC,EAAE;QACzB,IAAI,CAACR,SAASM,SAAS,OAAA;QAEvBG,OAAOC,IAAI,CAACJ,QAAQK,OAAO,CAACC,SAAAA;YAC1B,IAAMC,QAAQP,MAAM,CAACM,KAAK;YAE1B,IAAIZ,SAASa,UAAUZ,YAAYY,QAAmC;gBACpE,IACEJ,OAAOK,SAAS,CAACC,cAAc,CAACC,IAAI,CAACC,QAAQL,SAC7CZ,SAASiB,MAAM,CAACL,KAAK,GAErBK,MAAM,CAACL,KAAK,GAAGP,OAAO,CAAC,GAAGY,MAAM,CAACL,KAAK,EAA6BC;qBAChEI,MAAM,CAACL,KAAK,GAAGP,OAAO,CAAC,GAAGQ;YACjC,OAAO,IAAIK,MAAMC,OAAO,CAACN,QAAQI,MAAM,CAACL,KAAK,GAAGC,MAAMO,KAAK;iBACtDH,MAAM,CAACL,KAAK,GAAGC;QACtB;IACF;IAnBc,IAAA,IAAA,OAAA,UAAA,QAAA,AAAGN,UAAH,UAAA,OAAA,OAAA,GAAA,OAAA,MAAA;QAAGA,QAAH,QAAA,SAAA,CAAA,KAAqC;;IACnD,IAAMU,SAASV,OAAO,CAAC,EAAE;IACzB,IAAK,IAAIC,IAAI,GAAGA,IAAID,QAAQc,MAAM,EAAEb;IAmBpC,OAAOS;AACT;AAEA,eAAeZ,OAAO"}
|
package/es/src/attrize.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/attrize.ts"],"sourcesContent":["import type {Attrable} from \"./D3Selection.js\";\n\n/**\n Applies each key/value in an object as an attr.\n @param e The d3 selection to apply attributes to.\n @param a An object of key/value attr pairs.\n*/\nexport default function (\n e: Attrable,\n a: Record<string, string | number | boolean | null> = {},\n): void {\n for (const k in a) if ({}.hasOwnProperty.call(a, k)) e.attr(k, a[k]);\n}\n"],"names":["e","a","k","hasOwnProperty","call","attr"],"mappings":"AAEA;;;;AAIA,GACA,eAAe,SACbA,CAAW;QACXC,IAAAA,iEAAsD,CAAC;IAEvD,IAAK,IAAMC,KAAKD,EAAG,IAAI,CAAA,CAAC,CAAA,EAAEE,cAAc,CAACC,IAAI,CAACH,GAAGC,IAAIF,EAAEK,IAAI,CAACH,GAAGD,CAAC,CAACC,EAAE;AACrE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/backgroundColor.ts"],"sourcesContent":["/**\n Given a DOM element, returns its background color by walking up the\n ancestor chain until a non-transparent background is found. Falls back\n to \"rgb(255, 255, 255)\" (white) if every ancestor is transparent.\n @param elem The DOM element to check.\n*/\nexport default function (elem: Element): string {\n let node: Element | null = elem;\n while (node) {\n const bg = getComputedStyle(node).backgroundColor;\n if (bg && bg !== \"transparent\" && bg !== \"rgba(0, 0, 0, 0)\") return bg;\n node = node.parentElement;\n }\n return \"rgb(255, 255, 255)\";\n}\n"],"names":["elem","node","bg","getComputedStyle","backgroundColor","parentElement"],"mappings":"AAAA;;;;;AAKA,GACA,eAAe,SAAUA,IAAa;IACpC,IAAIC,OAAuBD;IAC3B,MAAOC,KAAM;QACX,IAAMC,KAAKC,iBAAiBF,MAAMG,eAAe;QACjD,IAAIF,MAAMA,OAAO,iBAAiBA,OAAO,oBAAoB,OAAOA;QACpED,OAAOA,KAAKI,aAAa;IAC3B;IACA,OAAO;AACT"}
|
package/es/src/date.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/date.ts"],"sourcesContent":["/**\n Parses numbers and strings into valid JavaScript Date objects, supporting years, quarters, months, and ISO 8601 formats.\n @param d The date value to parse (number, string, or Date).\n*/\nexport default function (\n d: number | string | false | undefined,\n): Date | false | undefined {\n // returns if falsey or already Date object\n if (\n [false, undefined, NaN].includes(d as never) ||\n (d as unknown as {constructor: unknown}).constructor === Date\n )\n return d as Date | false | undefined;\n // detects if milliseconds\n else if (\n (d as unknown as {constructor: unknown}).constructor === Number &&\n `${d}`.length > 5 &&\n (d as number) % 1 === 0\n )\n return new Date(d as number);\n\n let s = `${d}`;\n\n // tests for MM/DD/YYYY and MM-DD-YYYY format\n const dayFormat = new RegExp(/^\\d{1,2}[./-]\\d{1,2}[./-](-*\\d{1,4})$/g).exec(\n s,\n );\n if (dayFormat) {\n const year = dayFormat[1];\n if (year.indexOf(\"-\") === 0) s = s.replace(year, year.substring(1));\n const date = new Date(s);\n date.setFullYear(year as unknown as number);\n return date;\n }\n\n // tests for full Date object string format\n const strFormat = new RegExp(\n /^[A-z]{1,3} [A-z]{1,3} \\d{1,2} (-*\\d{1,4}) \\d{1,2}:\\d{1,2}:\\d{1,2} [A-z]{1,3}-*\\d{1,4} \\([A-z]{1,3}\\)/g,\n ).exec(s);\n if (strFormat) {\n const year = strFormat[1];\n if (year.indexOf(\"-\") === 0) s = s.replace(year, year.substring(1));\n const date = new Date(s);\n date.setFullYear(year as unknown as number);\n return date;\n }\n\n // tests for quarterly formats (ie. \"QX YYYY\" and \"YYYY QX\")\n const quarterPrefix = new RegExp(\n /^([qQ]{1}[1-4]{1}|[1-4]{1}[qQ]{1})[\\s|-]{0,1}(-*\\d{1,4})$/g,\n ).exec(s);\n const quarterSuffix = new RegExp(\n /^(-*\\d{1,4})[\\s|-]{0,1}([qQ]{1}[1-4]{1}|[1-4]{1}[qQ]{1})$/g,\n ).exec(s);\n if (quarterPrefix || quarterSuffix) {\n const quarter = +(quarterPrefix ? quarterPrefix[1] : quarterSuffix![2])\n .toLowerCase()\n .replace(\"q\", \"\");\n const year = +(quarterPrefix ? quarterPrefix[2] : quarterSuffix![1]);\n const date = new Date(year, quarter * 3 - 3, 1);\n date.setFullYear(year);\n return date;\n }\n\n // tests for monthly formats (ie. \"MM-YYYY\" and \"YYYY-MM\")\n const monthPrefix = new RegExp(/^([-*\\d]{1,2})-(-*\\d{1,4})$/g).exec(s);\n const monthSuffix = new RegExp(/^(-*\\d{1,4})-([-*\\d]{1,2})$/g).exec(s);\n if (monthPrefix || monthSuffix) {\n const month = +(monthPrefix ? monthPrefix[1] : monthSuffix![2]);\n const year = +(monthPrefix ? monthPrefix[2] : monthSuffix![1]);\n const date = new Date(year, month - 1, 1);\n date.setFullYear(year);\n return date;\n }\n\n // detects if only passing a year value\n if (\n !s.includes(\"/\") &&\n !s.includes(\" \") &&\n (!s.includes(\"-\") || !s.indexOf(\"-\"))\n ) {\n const date = new Date(+s, 0, 1);\n date.setFullYear(d as number);\n return date;\n }\n\n const iso8601 = new RegExp(\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})?$/g,\n ).exec(s);\n if (iso8601) return new Date(s);\n\n // falls back to Date object, replacing hyphens with slashes\n return new Date(s.replace(/-/g, \"/\"));\n}\n"],"names":["d","undefined","NaN","includes","Date","Number","length","s","dayFormat","RegExp","exec","year","indexOf","replace","substring","date","setFullYear","strFormat","quarterPrefix","quarterSuffix","quarter","toLowerCase","monthPrefix","monthSuffix","month","iso8601"],"mappings":"AAAA;;;AAGA,GACA,eAAe,SACbA,CAAsC;IAEtC,2CAA2C;IAC3C,IACE;QAAC;QAAOC;QAAWC;KAAI,CAACC,QAAQ,CAACH,MACjC,AAACA,EAAwC,WAAW,KAAKI,MAEzD,OAAOJ;SAEJ,IACH,AAACA,EAAwC,WAAW,KAAKK,UACzD,AAAC,GAAI,OAAFL,GAAIM,MAAM,GAAG,KAChB,AAACN,IAAe,MAAM,GAEtB,OAAO,IAAII,KAAKJ;IAElB,IAAIO,IAAI,AAAC,GAAI,OAAFP;IAEX,6CAA6C;IAC7C,IAAMQ,YAAY,IAAIC,OAAO,0CAA0CC,IAAI,CACzEH;IAEF,IAAIC,WAAW;QACb,IAAMG,OAAOH,SAAS,CAAC,EAAE;QACzB,IAAIG,KAAKC,OAAO,CAAC,SAAS,GAAGL,IAAIA,EAAEM,OAAO,CAACF,MAAMA,KAAKG,SAAS,CAAC;QAChE,IAAMC,OAAO,IAAIX,KAAKG;QACtBQ,KAAKC,WAAW,CAACL;QACjB,OAAOI;IACT;IAEA,2CAA2C;IAC3C,IAAME,YAAY,IAAIR,OACpB,0GACAC,IAAI,CAACH;IACP,IAAIU,WAAW;QACb,IAAMN,QAAOM,SAAS,CAAC,EAAE;QACzB,IAAIN,MAAKC,OAAO,CAAC,SAAS,GAAGL,IAAIA,EAAEM,OAAO,CAACF,OAAMA,MAAKG,SAAS,CAAC;QAChE,IAAMC,QAAO,IAAIX,KAAKG;QACtBQ,MAAKC,WAAW,CAACL;QACjB,OAAOI;IACT;IAEA,4DAA4D;IAC5D,IAAMG,gBAAgB,IAAIT,OACxB,8DACAC,IAAI,CAACH;IACP,IAAMY,gBAAgB,IAAIV,OACxB,8DACAC,IAAI,CAACH;IACP,IAAIW,iBAAiBC,eAAe;QAClC,IAAMC,UAAU,CAAC,AAACF,CAAAA,gBAAgBA,aAAa,CAAC,EAAE,GAAGC,aAAc,CAAC,EAAE,AAAD,EAClEE,WAAW,GACXR,OAAO,CAAC,KAAK;QAChB,IAAMF,QAAO,CAAEO,CAAAA,gBAAgBA,aAAa,CAAC,EAAE,GAAGC,aAAc,CAAC,EAAE,AAAD;QAClE,IAAMJ,QAAO,IAAIX,KAAKO,OAAMS,UAAU,IAAI,GAAG;QAC7CL,MAAKC,WAAW,CAACL;QACjB,OAAOI;IACT;IAEA,0DAA0D;IAC1D,IAAMO,cAAc,IAAIb,OAAO,gCAAgCC,IAAI,CAACH;IACpE,IAAMgB,cAAc,IAAId,OAAO,gCAAgCC,IAAI,CAACH;IACpE,IAAIe,eAAeC,aAAa;QAC9B,IAAMC,QAAQ,CAAEF,CAAAA,cAAcA,WAAW,CAAC,EAAE,GAAGC,WAAY,CAAC,EAAE,AAAD;QAC7D,IAAMZ,QAAO,CAAEW,CAAAA,cAAcA,WAAW,CAAC,EAAE,GAAGC,WAAY,CAAC,EAAE,AAAD;QAC5D,IAAMR,QAAO,IAAIX,KAAKO,OAAMa,QAAQ,GAAG;QACvCT,MAAKC,WAAW,CAACL;QACjB,OAAOI;IACT;IAEA,uCAAuC;IACvC,IACE,CAACR,EAAEJ,QAAQ,CAAC,QACZ,CAACI,EAAEJ,QAAQ,CAAC,QACX,CAAA,CAACI,EAAEJ,QAAQ,CAAC,QAAQ,CAACI,EAAEK,OAAO,CAAC,IAAG,GACnC;QACA,IAAMG,QAAO,IAAIX,KAAK,CAACG,GAAG,GAAG;QAC7BQ,MAAKC,WAAW,CAAChB;QACjB,OAAOe;IACT;IAEA,IAAMU,UAAU,IAAIhB,OAClB,0EACAC,IAAI,CAACH;IACP,IAAIkB,SAAS,OAAO,IAAIrB,KAAKG;IAE7B,4DAA4D;IAC5D,OAAO,IAAIH,KAAKG,EAAEM,OAAO,CAAC,MAAM;AAClC"}
|
package/es/src/elem.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/elem.ts"],"sourcesContent":["import {select} from \"d3-selection\";\nimport {transition} from \"d3-transition\";\n\nimport {default as attrize} from \"./attrize.js\";\nimport type {D3Selection} from \"./D3Selection.js\";\n\n \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnySelection = ReturnType<typeof select<any, any>>;\n\ntype AttrMap = Record<string, string | number | boolean | null>;\n\nexport interface ElemParams {\n condition?: boolean;\n enter?: AttrMap;\n exit?: AttrMap;\n duration?: number;\n parent?: D3Selection;\n transition?: D3Selection;\n update?: AttrMap;\n}\n\n/**\n Manages the enter/update/exit pattern for a single DOM element, applying enter, update, and exit attributes with optional transitions.\n @param selector A CSS selector string for the element tag and classes.\n @param p Configuration object with enter, exit, update, and parent options.\n*/\nexport default function (selector: string, p?: ElemParams): D3Selection {\n // overrides default params\n const params = Object.assign(\n {},\n {\n condition: true,\n enter: {},\n exit: {},\n duration: 0,\n parent: select(\"body\") as unknown as D3Selection,\n update: {},\n },\n p,\n );\n\n const className = /\\.([^#]+)/g.exec(selector),\n id = /#([^.]+)/g.exec(selector),\n t = transition().duration(params.duration),\n tag = /^([^.^#]+)/g.exec(selector)![1];\n\n const elem = (params.parent as AnySelection)\n .selectAll(selector.includes(\":\") ? selector.split(\":\")[1] : selector)\n .data(params.condition ? [null] : []);\n\n const enter = elem.enter().append(tag).call(attrize, params.enter);\n\n if (id) enter.attr(\"id\", id[1]);\n if (className) enter.attr(\"class\", className[1]);\n\n if (params.duration)\n elem\n .exit()\n .transition(t)\n .call(attrize as never, params.exit)\n .remove();\n else elem.exit().call(attrize, params.exit).remove();\n\n const update = enter.merge(elem);\n if (params.duration)\n update.transition(t).call(attrize as never, params.update);\n else update.call(attrize, params.update);\n\n return update as unknown as D3Selection;\n}\n"],"names":["select","transition","default","attrize","selector","p","params","Object","assign","condition","enter","exit","duration","parent","update","className","exec","id","t","tag","elem","selectAll","includes","split","data","append","call","attr","remove","merge"],"mappings":"AAAA,SAAQA,MAAM,QAAO,eAAe;AACpC,SAAQC,UAAU,QAAO,gBAAgB;AAEzC,SAAQC,WAAWC,OAAO,QAAO,eAAe;AAmBhD;;;;AAIA,GACA,eAAe,SAAUC,QAAgB,EAAEC,CAAc;IACvD,2BAA2B;IAC3B,IAAMC,SAASC,OAAOC,MAAM,CAC1B,CAAC,GACD;QACEC,WAAW;QACXC,OAAO,CAAC;QACRC,MAAM,CAAC;QACPC,UAAU;QACVC,QAAQb,OAAO;QACfc,QAAQ,CAAC;IACX,GACAT;IAGF,IAAMU,YAAY,aAAaC,IAAI,CAACZ,WAClCa,KAAK,YAAYD,IAAI,CAACZ,WACtBc,IAAIjB,aAAaW,QAAQ,CAACN,OAAOM,QAAQ,GACzCO,MAAM,cAAcH,IAAI,CAACZ,SAAU,CAAC,EAAE;IAExC,IAAMgB,OAAO,AAACd,OAAOO,MAAM,CACxBQ,SAAS,CAACjB,SAASkB,QAAQ,CAAC,OAAOlB,SAASmB,KAAK,CAAC,IAAI,CAAC,EAAE,GAAGnB,UAC5DoB,IAAI,CAAClB,OAAOG,SAAS,GAAG;QAAC;KAAK,GAAG,EAAE;IAEtC,IAAMC,QAAQU,KAAKV,KAAK,GAAGe,MAAM,CAACN,KAAKO,IAAI,CAACvB,SAASG,OAAOI,KAAK;IAEjE,IAAIO,IAAIP,MAAMiB,IAAI,CAAC,MAAMV,EAAE,CAAC,EAAE;IAC9B,IAAIF,WAAWL,MAAMiB,IAAI,CAAC,SAASZ,SAAS,CAAC,EAAE;IAE/C,IAAIT,OAAOM,QAAQ,EACjBQ,KACGT,IAAI,GACJV,UAAU,CAACiB,GACXQ,IAAI,CAACvB,SAAkBG,OAAOK,IAAI,EAClCiB,MAAM;SACNR,KAAKT,IAAI,GAAGe,IAAI,CAACvB,SAASG,OAAOK,IAAI,EAAEiB,MAAM;IAElD,IAAMd,SAASJ,MAAMmB,KAAK,CAACT;IAC3B,IAAId,OAAOM,QAAQ,EACjBE,OAAOb,UAAU,CAACiB,GAAGQ,IAAI,CAACvB,SAAkBG,OAAOQ,MAAM;SACtDA,OAAOY,IAAI,CAACvB,SAASG,OAAOQ,MAAM;IAEvC,OAAOA;AACT"}
|
package/es/src/fontExists.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fontExists.ts"],"sourcesContent":["import {default as textWidth} from \"./textWidth.js\";\n\nconst alpha: string = \"abcdefghiABCDEFGHI_!@#$%^&*()_+1234567890\",\n checked: Record<string, boolean> = {},\n height: number = 32;\n\nlet dejavu: number, macos: number, monospace: number, proportional: number;\n\n/**\n Given either a single font-family or a list of fonts, returns the name of the first font that can be rendered, or `false` if none are installed on the user's machine.\n @param font Can be either a valid CSS font-family string (single or comma-separated names) or an Array of string names.\n*/\nconst fontExists = (font: string | string[]): string | false => {\n if (!dejavu) {\n dejavu = textWidth(alpha, {\n \"font-family\": \"DejaVuSans\",\n \"font-size\": height,\n }) as number;\n macos = textWidth(alpha, {\n \"font-family\": \"-apple-system\",\n \"font-size\": height,\n }) as number;\n monospace = textWidth(alpha, {\n \"font-family\": \"monospace\",\n \"font-size\": height,\n }) as number;\n proportional = textWidth(alpha, {\n \"font-family\": \"sans-serif\",\n \"font-size\": height,\n }) as number;\n }\n\n if (!(font instanceof Array)) font = font.split(\",\");\n font = font.map(f => f.trim());\n\n for (let i = 0; i < font.length; i++) {\n const fam = font[i];\n if (\n checked[fam] ||\n [\"-apple-system\", \"monospace\", \"sans-serif\", \"DejaVuSans\"].includes(fam)\n )\n return fam;\n else if (checked[fam] === false) continue;\n const width = textWidth(alpha, {\n \"font-family\": fam,\n \"font-size\": height,\n }) as number;\n checked[fam] = width !== monospace;\n if (checked[fam]) checked[fam] = width !== proportional;\n if (macos && checked[fam]) checked[fam] = width !== macos;\n if (dejavu && checked[fam]) checked[fam] = width !== dejavu;\n if (checked[fam]) return fam;\n }\n\n return false;\n};\n\nexport default fontExists;\n"],"names":["default","textWidth","alpha","checked","height","dejavu","macos","monospace","proportional","fontExists","font","Array","split","map","f","trim","i","length","fam","includes","width"],"mappings":";;;;;;;;AAAA,SAAQA,WAAWC,SAAS,QAAO,iBAAiB;AAEpD,IAAMC,QAAgB,6CACpBC,UAAmC,CAAC,GACpCC,SAAiB;AAEnB,IAAIC,QAAgBC,OAAeC,WAAmBC;AAEtD;;;AAGA,GACA,IAAMC,aAAa,oBAACC;IAClB,IAAI,CAACL,QAAQ;QACXA,SAASJ,UAAUC,OAAO;YACxB,eAAe;YACf,aAAaE;QACf;QACAE,QAAQL,UAAUC,OAAO;YACvB,eAAe;YACf,aAAaE;QACf;QACAG,YAAYN,UAAUC,OAAO;YAC3B,eAAe;YACf,aAAaE;QACf;QACAI,eAAeP,UAAUC,OAAO;YAC9B,eAAe;YACf,aAAaE;QACf;IACF;IAEA,IAAI,CAAEM,AAAI,YAAJA,MAAgBC,QAAQD,OAAOA,KAAKE,KAAK,CAAC;IAChDF,OAAOA,KAAKG,GAAG,CAACC,SAAAA;eAAKA,EAAEC,IAAI;;IAE3B,IAAK,IAAIC,IAAI,GAAGA,IAAIN,KAAKO,MAAM,EAAED,IAAK;QACpC,IAAME,MAAMR,IAAI,CAACM,EAAE;QACnB,IACEb,OAAO,CAACe,IAAI,IACZ;YAAC;YAAiB;YAAa;YAAc;SAAa,CAACC,QAAQ,CAACD,MAEpE,OAAOA;aACJ,IAAIf,OAAO,CAACe,IAAI,KAAK,OAAO;QACjC,IAAME,QAAQnB,UAAUC,OAAO;YAC7B,eAAegB;YACf,aAAad;QACf;QACAD,OAAO,CAACe,IAAI,GAAGE,UAAUb;QACzB,IAAIJ,OAAO,CAACe,IAAI,EAAEf,OAAO,CAACe,IAAI,GAAGE,UAAUZ;QAC3C,IAAIF,SAASH,OAAO,CAACe,IAAI,EAAEf,OAAO,CAACe,IAAI,GAAGE,UAAUd;QACpD,IAAID,UAAUF,OAAO,CAACe,IAAI,EAAEf,OAAO,CAACe,IAAI,GAAGE,UAAUf;QACrD,IAAIF,OAAO,CAACe,IAAI,EAAE,OAAOA;IAC3B;IAEA,OAAO;AACT;AAEA,eAAeT,WAAW"}
|
package/es/src/getSize.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getSize.ts"],"sourcesContent":["import {select} from \"d3-selection\";\n\n/**\n Given an HTMLElement and a \"width\" or \"height\" string, this function returns the current calculated size for the DOM element.\n @private\n*/\nfunction _elementSize(\n element: HTMLElement | null,\n s: \"width\" | \"height\",\n): number | undefined {\n if (!element) return undefined;\n\n if (\n (element as HTMLElement).tagName === undefined ||\n [\"BODY\", \"HTML\"].indexOf((element as HTMLElement).tagName) >= 0\n ) {\n let val = (window as any)[\n `inner${s.charAt(0).toUpperCase() + s.slice(1)}`\n ] as number;\n const elem = select(element);\n\n if (s === \"width\") {\n val -= parseFloat(elem.style(\"margin-left\"));\n val -= parseFloat(elem.style(\"margin-right\"));\n val -= parseFloat(elem.style(\"padding-left\"));\n val -= parseFloat(elem.style(\"padding-right\"));\n } else {\n val -= parseFloat(elem.style(\"margin-top\"));\n val -= parseFloat(elem.style(\"margin-bottom\"));\n val -= parseFloat(elem.style(\"padding-top\"));\n val -= parseFloat(elem.style(\"padding-bottom\"));\n }\n\n return val;\n } else {\n let val: number = element.getBoundingClientRect()[s];\n if (typeof val === \"number\" && val > 0) {\n if (s === \"height\") {\n val -= parseFloat(select(element).style(\"padding-top\"));\n val -= parseFloat(select(element).style(\"padding-bottom\"));\n val -= parseFloat(select(element).style(\"border-top\"));\n val -= parseFloat(select(element).style(\"border-bottom\"));\n } else {\n val -= parseFloat(select(element).style(\"padding-left\"));\n val -= parseFloat(select(element).style(\"padding-right\"));\n val -= parseFloat(select(element).style(\"border-left\"));\n val -= parseFloat(select(element).style(\"border-right\"));\n }\n return val;\n } else return _elementSize(element.parentNode as HTMLElement | null, s);\n }\n}\n\n/**\n Finds the available width and height for a specified HTMLElement, traversing it's parents until it finds something with constrained dimensions. Falls back to the inner dimensions of the browser window if none is found.\n @private\n*/\nexport default function (\n elem: HTMLElement,\n): [number | undefined, number | undefined] {\n return [_elementSize(elem, \"width\"), _elementSize(elem, \"height\")];\n}\n"],"names":["select","_elementSize","element","s","undefined","tagName","indexOf","val","window","charAt","toUpperCase","slice","elem","parseFloat","style","getBoundingClientRect","parentNode"],"mappings":"AAAA,SAAQA,MAAM,QAAO,eAAe;AAEpC;;;AAGA,GACA,SAASC,aACPC,OAA2B,EAC3BC,CAAqB;IAErB,IAAI,CAACD,SAAS,OAAOE;IAErB,IACE,AAACF,QAAwBG,OAAO,KAAKD,aACrC;QAAC;QAAQ;KAAO,CAACE,OAAO,CAAC,AAACJ,QAAwBG,OAAO,KAAK,GAC9D;QACA,IAAIE,MAAM,AAACC,MAAc,CACvB,AAAC,QAA8C,OAAvCL,EAAEM,MAAM,CAAC,GAAGC,WAAW,KAAKP,EAAEQ,KAAK,CAAC,IAC7C;QACD,IAAMC,OAAOZ,OAAOE;QAEpB,IAAIC,MAAM,SAAS;YACjBI,OAAOM,WAAWD,KAAKE,KAAK,CAAC;YAC7BP,OAAOM,WAAWD,KAAKE,KAAK,CAAC;YAC7BP,OAAOM,WAAWD,KAAKE,KAAK,CAAC;YAC7BP,OAAOM,WAAWD,KAAKE,KAAK,CAAC;QAC/B,OAAO;YACLP,OAAOM,WAAWD,KAAKE,KAAK,CAAC;YAC7BP,OAAOM,WAAWD,KAAKE,KAAK,CAAC;YAC7BP,OAAOM,WAAWD,KAAKE,KAAK,CAAC;YAC7BP,OAAOM,WAAWD,KAAKE,KAAK,CAAC;QAC/B;QAEA,OAAOP;IACT,OAAO;QACL,IAAIA,OAAcL,QAAQa,qBAAqB,EAAE,CAACZ,EAAE;QACpD,IAAI,OAAOI,SAAQ,YAAYA,OAAM,GAAG;YACtC,IAAIJ,MAAM,UAAU;gBAClBI,QAAOM,WAAWb,OAAOE,SAASY,KAAK,CAAC;gBACxCP,QAAOM,WAAWb,OAAOE,SAASY,KAAK,CAAC;gBACxCP,QAAOM,WAAWb,OAAOE,SAASY,KAAK,CAAC;gBACxCP,QAAOM,WAAWb,OAAOE,SAASY,KAAK,CAAC;YAC1C,OAAO;gBACLP,QAAOM,WAAWb,OAAOE,SAASY,KAAK,CAAC;gBACxCP,QAAOM,WAAWb,OAAOE,SAASY,KAAK,CAAC;gBACxCP,QAAOM,WAAWb,OAAOE,SAASY,KAAK,CAAC;gBACxCP,QAAOM,WAAWb,OAAOE,SAASY,KAAK,CAAC;YAC1C;YACA,OAAOP;QACT,OAAO,OAAON,aAAaC,QAAQc,UAAU,EAAwBb;IACvE;AACF;AAEA;;;AAGA,GACA,eAAe,SACbS,IAAiB;IAEjB,OAAO;QAACX,aAAaW,MAAM;QAAUX,aAAaW,MAAM;KAAU;AACpE"}
|
package/es/src/inViewport.js
CHANGED
|
@@ -10,3 +10,5 @@
|
|
|
10
10
|
var height = bounds.height, left = bounds.left + pageX, top = bounds.top + pageY, width = bounds.width;
|
|
11
11
|
return pageY + window.innerHeight > top + buffer && pageY + buffer < top + height && pageX + window.innerWidth > left + buffer && pageX + buffer < left + width;
|
|
12
12
|
}
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=inViewport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/inViewport.ts"],"sourcesContent":["/**\n Determines whether a given DOM element is visible within the current viewport, with an optional pixel buffer.\n @param elem The DOM element to check.\n @param buffer Extra pixel margin around the viewport boundary.\n*/\nexport default function (elem: Element, buffer: number = 0): boolean {\n const pageX = window.scrollX;\n const pageY = window.scrollY;\n\n const bounds = elem.getBoundingClientRect();\n const height = bounds.height,\n left = bounds.left + pageX,\n top = bounds.top + pageY,\n width = bounds.width;\n\n return (\n pageY + window.innerHeight > top + buffer &&\n pageY + buffer < top + height &&\n pageX + window.innerWidth > left + buffer &&\n pageX + buffer < left + width\n );\n}\n"],"names":["elem","buffer","pageX","window","scrollX","pageY","scrollY","bounds","getBoundingClientRect","height","left","top","width","innerHeight","innerWidth"],"mappings":"AAAA;;;;AAIA,GACA,eAAe,SAAUA,IAAa;QAAEC,SAAAA,iEAAiB;IACvD,IAAMC,QAAQC,OAAOC,OAAO;IAC5B,IAAMC,QAAQF,OAAOG,OAAO;IAE5B,IAAMC,SAASP,KAAKQ,qBAAqB;IACzC,IAAMC,SAASF,OAAOE,MAAM,EAC1BC,OAAOH,OAAOG,IAAI,GAAGR,OACrBS,MAAMJ,OAAOI,GAAG,GAAGN,OACnBO,QAAQL,OAAOK,KAAK;IAEtB,OACEP,QAAQF,OAAOU,WAAW,GAAGF,MAAMV,UACnCI,QAAQJ,SAASU,MAAMF,UACvBP,QAAQC,OAAOW,UAAU,GAAGJ,OAAOT,UACnCC,QAAQD,SAASS,OAAOE;AAE5B"}
|
package/es/src/isObject.js
CHANGED
|
@@ -16,3 +16,5 @@ function _type_of(obj) {
|
|
|
16
16
|
*/ export default function(item) {
|
|
17
17
|
return item && (typeof item === "undefined" ? "undefined" : _type_of(item)) === "object" && (typeof window === "undefined" || item !== window && item !== window.document && !_instanceof(item, Element)) && !Array.isArray(item) ? true : false;
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=isObject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/isObject.ts"],"sourcesContent":["/**\n Detects if a variable is a javascript Object.\n @param item The value to test.\n*/\nexport default function (item: unknown): boolean {\n return item &&\n typeof item === \"object\" &&\n (typeof window === \"undefined\" ||\n (item !== window &&\n item !== window.document &&\n !(item instanceof Element))) &&\n !Array.isArray(item)\n ? true\n : false;\n}\n"],"names":["item","window","document","Element","Array","isArray"],"mappings":";;;;;;;;;;;;AAAA;;;AAGA,GACA,eAAe,SAAUA,IAAa;IACpC,OAAOA,QACL,CAAA,OAAOA,qCAAP,SAAOA,KAAG,MAAM,YACf,CAAA,OAAOC,WAAW,eAChBD,SAASC,UACRD,SAASC,OAAOC,QAAQ,IACxB,CAAEF,AAAI,YAAJA,MAAgBG,QAAQ,KAC9B,CAACC,MAAMC,OAAO,CAACL,QACb,OACA;AACN"}
|
package/es/src/parseSides.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/parseSides.ts"],"sourcesContent":["export interface ParsedSides {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\n/**\n Converts a string of directional CSS shorthand values into an object with the values expanded.\n @param sides The CSS shorthand string to expand.\n */\nexport default function (sides: string | number): ParsedSides {\n let values: string[];\n if (typeof sides === \"number\") values = [`${sides}`];\n else values = sides.split(/\\s+/);\n\n if (values.length === 1)\n values = [values[0], values[0], values[0], values[0]];\n else if (values.length === 2) values = values.concat(values);\n else if (values.length === 3) values.push(values[1]);\n\n return [\"top\", \"right\", \"bottom\", \"left\"].reduce((acc, direction, i) => {\n const value = parseFloat(values[i]);\n acc[direction as keyof ParsedSides] = value || 0;\n return acc;\n }, {} as ParsedSides);\n}\n"],"names":["sides","values","split","length","concat","push","reduce","acc","direction","i","value","parseFloat"],"mappings":"AAOA;;;CAGC,GACD,eAAe,SAAUA,KAAsB;IAC7C,IAAIC;IACJ,IAAI,OAAOD,UAAU,UAAUC,SAAS;QAAE,GAAQ,OAAND;KAAQ;SAC/CC,SAASD,MAAME,KAAK,CAAC;IAE1B,IAAID,OAAOE,MAAM,KAAK,GACpBF,SAAS;QAACA,MAAM,CAAC,EAAE;QAAEA,MAAM,CAAC,EAAE;QAAEA,MAAM,CAAC,EAAE;QAAEA,MAAM,CAAC,EAAE;KAAC;SAClD,IAAIA,OAAOE,MAAM,KAAK,GAAGF,SAASA,OAAOG,MAAM,CAACH;SAChD,IAAIA,OAAOE,MAAM,KAAK,GAAGF,OAAOI,IAAI,CAACJ,MAAM,CAAC,EAAE;IAEnD,OAAO;QAAC;QAAO;QAAS;QAAU;KAAO,CAACK,MAAM,CAAC,SAACC,KAAKC,WAAWC;QAChE,IAAMC,QAAQC,WAAWV,MAAM,CAACQ,EAAE;QAClCF,GAAG,CAACC,UAA+B,GAAGE,SAAS;QAC/C,OAAOH;IACT,GAAG,CAAC;AACN"}
|
package/es/src/rtl.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/rtl.ts"],"sourcesContent":["/**\n Returns `true` if the HTML or body element has either the \"dir\" HTML attribute or the \"direction\" CSS property set to \"rtl\".\n*/\nexport default function (): boolean {\n return (\n document.documentElement.dir === \"rtl\" ||\n document.body.dir === \"rtl\" ||\n getComputedStyle(document.documentElement).direction === \"rtl\" ||\n getComputedStyle(document.body).direction === \"rtl\"\n );\n}\n"],"names":["document","documentElement","dir","body","getComputedStyle","direction"],"mappings":"AAAA;;AAEA,GACA,eAAe;IACb,OACEA,SAASC,eAAe,CAACC,GAAG,KAAK,SACjCF,SAASG,IAAI,CAACD,GAAG,KAAK,SACtBE,iBAAiBJ,SAASC,eAAe,EAAEI,SAAS,KAAK,SACzDD,iBAAiBJ,SAASG,IAAI,EAAEE,SAAS,KAAK;AAElD"}
|
package/es/src/stylize.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/stylize.ts"],"sourcesContent":["import type {Stylable} from \"./D3Selection.js\";\n\n/**\n Applies each key/value in an object as a style.\n @param e The d3 selection to apply styles to.\n @param s An object of key/value style pairs.\n*/\nexport default function (\n e: Stylable,\n s: Record<string, string | number | boolean | null> = {},\n): void {\n for (const k in s) if ({}.hasOwnProperty.call(s, k)) e.style(k, s[k]);\n}\n"],"names":["e","s","k","hasOwnProperty","call","style"],"mappings":"AAEA;;;;AAIA,GACA,eAAe,SACbA,CAAW;QACXC,IAAAA,iEAAsD,CAAC;IAEvD,IAAK,IAAMC,KAAKD,EAAG,IAAI,CAAA,CAAC,CAAA,EAAEE,cAAc,CAACC,IAAI,CAACH,GAAGC,IAAIF,EAAEK,KAAK,CAACH,GAAGD,CAAC,CAACC,EAAE;AACtE"}
|
package/es/src/textWidth.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/textWidth.ts"],"sourcesContent":["import {prepareWithSegments, layoutWithLines} from \"@chenglou/pretext\";\n\n/**\n * Strips HTML and \"un-escapes\" escape characters.\n * @param {String} input\n */\nfunction htmlDecode(input: string): string {\n if (input.replace(/\\s+/g, \"\") === \"\") return input;\n const doc = new DOMParser().parseFromString(\n input.replace(/<[^>]+>/g, \"\"),\n \"text/html\",\n );\n return doc.documentElement ? doc.documentElement.textContent! : input;\n}\n\n/**\n * Builds a CSS font shorthand string from a style object.\n * @param {Object} styleObj\n */\nfunction buildFont(styleObj: Record<string, string | number>): string {\n const style = styleObj[\"font-style\"] || \"normal\";\n const variant = styleObj[\"font-variant\"] || \"normal\";\n const weight = styleObj[\"font-weight\"] || 400;\n const size =\n typeof styleObj[\"font-size\"] === \"string\"\n ? styleObj[\"font-size\"]\n : `${styleObj[\"font-size\"] || 10}px`;\n const family = styleObj[\"font-family\"] || \"sans-serif\";\n return `${style} ${variant} ${weight} ${size} ${family}`;\n}\n\n/**\n * Measures the width of a single text string using pretext.\n * @param {String} text\n * @param {String} font CSS font shorthand\n */\nfunction measureWidth(text: string, font: string): number {\n if (!text) return 0;\n const prepared = prepareWithSegments(text, font);\n const result = layoutWithLines(prepared, Infinity, 20);\n return result.lines.length ? result.lines[0].width : 0;\n}\n\n/**\n Given a text string, returns the predicted pixel width of the string when placed into DOM.\n @param text The text string to measure.\n @param style CSS style properties to apply when measuring.\n*/\nexport default function (\n text: string,\n style?: Record<string, string | number>,\n): number;\nexport default function (\n text: string[],\n style?: Record<string, string | number>,\n): number[];\nexport default function (\n text: string | string[],\n style: Record<string, string | number> = {},\n): number | number[] {\n const font = buildFont(style);\n\n if (text instanceof Array)\n return text.map(t => measureWidth(htmlDecode(t), font));\n return measureWidth(htmlDecode(text), font);\n}\n"],"names":["prepareWithSegments","layoutWithLines","htmlDecode","input","replace","doc","DOMParser","parseFromString","documentElement","textContent","buildFont","styleObj","style","variant","weight","size","family","measureWidth","text","font","prepared","result","Infinity","lines","length","width","Array","map","t"],"mappings":";;;;;;;;AAAA,SAAQA,mBAAmB,EAAEC,eAAe,QAAO,oBAAoB;AAEvE;;;CAGC,GACD,SAASC,WAAWC,KAAa;IAC/B,IAAIA,MAAMC,OAAO,CAAC,QAAQ,QAAQ,IAAI,OAAOD;IAC7C,IAAME,MAAM,IAAIC,YAAYC,eAAe,CACzCJ,MAAMC,OAAO,CAAC,YAAY,KAC1B;IAEF,OAAOC,IAAIG,eAAe,GAAGH,IAAIG,eAAe,CAACC,WAAW,GAAIN;AAClE;AAEA;;;CAGC,GACD,SAASO,UAAUC,QAAyC;IAC1D,IAAMC,QAAQD,QAAQ,CAAC,aAAa,IAAI;IACxC,IAAME,UAAUF,QAAQ,CAAC,eAAe,IAAI;IAC5C,IAAMG,SAASH,QAAQ,CAAC,cAAc,IAAI;IAC1C,IAAMI,OACJ,OAAOJ,QAAQ,CAAC,YAAY,KAAK,WAC7BA,QAAQ,CAAC,YAAY,GACrB,AAAC,GAA8B,OAA5BA,QAAQ,CAAC,YAAY,IAAI,IAAG;IACrC,IAAMK,SAASL,QAAQ,CAAC,cAAc,IAAI;IAC1C,OAAO,AAAC,GAAWE,OAATD,OAAM,KAAcE,OAAXD,SAAQ,KAAaE,OAAVD,QAAO,KAAWE,OAARD,MAAK,KAAU,OAAPC;AAClD;AAEA;;;;CAIC,GACD,SAASC,aAAaC,IAAY,EAAEC,IAAY;IAC9C,IAAI,CAACD,MAAM,OAAO;IAClB,IAAME,WAAWpB,oBAAoBkB,MAAMC;IAC3C,IAAME,SAASpB,gBAAgBmB,UAAUE,UAAU;IACnD,OAAOD,OAAOE,KAAK,CAACC,MAAM,GAAGH,OAAOE,KAAK,CAAC,EAAE,CAACE,KAAK,GAAG;AACvD;AAeA,eAAe,SACbP,IAAuB;QACvBN,QAAAA,iEAAyC,CAAC;IAE1C,IAAMO,OAAOT,UAAUE;IAEvB,IAAIM,AAAI,YAAJA,MAAgBQ,QAClB,OAAOR,KAAKS,GAAG,CAACC,SAAAA;eAAKX,aAAaf,WAAW0B,IAAIT;;IACnD,OAAOF,aAAaf,WAAWgB,OAAOC;AACxC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d3plus/dom",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "JavaScript functions for manipulating and analyzing DOM elements.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"visualization"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@chenglou/pretext": "^0.0.
|
|
38
|
+
"@chenglou/pretext": "^0.0.5",
|
|
39
39
|
"d3-selection": "^3.0.0",
|
|
40
40
|
"d3-transition": "^3.0.1"
|
|
41
41
|
},
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"build:types": "tsc",
|
|
45
45
|
"build:umd": "node ../../scripts/build-umd.js",
|
|
46
46
|
"dev": "node ../../scripts/dev.js",
|
|
47
|
-
"test": "eslint index.ts src/**/*.ts && eslint --global=it test && mocha 'test/**/*-test.js'"
|
|
47
|
+
"test": "eslint index.ts src/**/*.ts && eslint --global=it test && mocha 'test/**/*-test.js'",
|
|
48
|
+
"test:coverage": "c8 -r text -r lcov --src src mocha 'test/**/*-test.js'"
|
|
48
49
|
}
|
|
49
50
|
}
|