@nightshadeui/util 3.1.1 → 3.2.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/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # @nightshadeui/util
2
+
3
+ Framework-free helpers shared by the Nightshade packages: 2D vectors and boxes, math (`clamp`, `quantize`), DOM input state, and `readStored`/`writeStored` for `localStorage`.
4
+
5
+ ```bash
6
+ npm i @nightshadeui/util
7
+ ```
8
+
9
+ It's a dependency of the other packages; apps rarely need it directly.
package/out/index.d.ts CHANGED
@@ -2,7 +2,6 @@ export * from './box.js';
2
2
  export * from './css.js';
3
3
  export * from './dom/DomEventProxy.js';
4
4
  export * from './dom/InputStateManager.js';
5
- export * from './grid.js';
6
5
  export * from './math.js';
7
6
  export * from './point.js';
8
7
  export * from './storage.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,CAAC"}
package/out/index.js CHANGED
@@ -2,7 +2,6 @@ export * from './box.js';
2
2
  export * from './css.js';
3
3
  export * from './dom/DomEventProxy.js';
4
4
  export * from './dom/InputStateManager.js';
5
- export * from './grid.js';
6
5
  export * from './math.js';
7
6
  export * from './point.js';
8
7
  export * from './storage.js';
package/out/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nightshadeui/util",
3
- "version": "3.1.1",
3
+ "version": "3.2.0",
4
4
  "description": "Shared utility helpers for Nightshade packages",
5
5
  "author": "Boris Okunskiy",
6
6
  "license": "ISC",
package/src/index.ts CHANGED
@@ -2,7 +2,6 @@ export * from './box.js';
2
2
  export * from './css.js';
3
3
  export * from './dom/DomEventProxy.js';
4
4
  export * from './dom/InputStateManager.js';
5
- export * from './grid.js';
6
5
  export * from './math.js';
7
6
  export * from './point.js';
8
7
  export * from './storage.js';
package/src/grid.ts DELETED
@@ -1,76 +0,0 @@
1
- export function createGridLinesSvg(
2
- cellSize: number,
3
- subdivisions: number,
4
- majorColor: string,
5
- minorColor: string,
6
- ) {
7
- const subdivCoords = getSubdivCoords(cellSize, subdivisions)
8
- .map(_ => _ + 1);
9
- const lines = [
10
- `<svg xmlns="http://www.w3.org/2000/svg"
11
- width="${cellSize}"
12
- height="${cellSize}"
13
- viewBox="0 0 ${cellSize} ${cellSize}">`
14
- ];
15
- // Minor lines
16
- for (const c of subdivCoords) {
17
- lines.push(
18
- `<path d="M0,${c} H ${cellSize}" stroke="${minorColor}" stroke-width="1"/>`
19
- );
20
- lines.push(
21
- `<path d="M${c},0 V ${cellSize}" stroke="${minorColor}" stroke-width="1"/>`
22
- );
23
- }
24
- // Major lines
25
- lines.push(`<path d="M0,1 H ${cellSize}" stroke="${majorColor}" stroke-width="1"/>`);
26
- lines.push(`<path d="M1,0 V ${cellSize}" stroke="${majorColor}" stroke-width="1"/>`);
27
- lines.push('</svg>');
28
- return lines.join('');
29
- }
30
-
31
- export function createGridDotsSvg(
32
- cellSize: number,
33
- subdivisions: number,
34
- majorColor: string,
35
- majorRadius = 2,
36
- minorColor: string,
37
- minorRadius = 1,
38
- ) {
39
- const minorCoords = [0, ...getSubdivCoords(cellSize, subdivisions), cellSize];
40
- const majorCoords = [0, cellSize];
41
- const lines = [
42
- `<svg xmlns="http://www.w3.org/2000/svg"
43
- width="${cellSize}"
44
- height="${cellSize}"
45
- viewBox="0 0 ${cellSize} ${cellSize}">`,
46
- ];
47
- if (minorRadius) {
48
- for (const x of minorCoords) {
49
- for (const y of minorCoords) {
50
- lines.push(
51
- `<circle cx="${x}" cy="${y}" r="${minorRadius}" fill="${minorColor}"/>`
52
- );
53
- }
54
- }
55
- }
56
- if (majorRadius) {
57
- for (const x of majorCoords) {
58
- for (const y of majorCoords) {
59
- lines.push(
60
- `<circle cx="${x}" cy="${y}" r="${majorRadius}" fill="${majorColor}"/>`
61
- );
62
- }
63
- }
64
- }
65
- lines.push('</svg>');
66
- return lines.join('');
67
- }
68
-
69
- function getSubdivCoords(cellSize: number, subdivisions: number) {
70
- const subdivCoords: number[] = [];
71
- const k = Math.round(cellSize / subdivisions);
72
- for (let i = 1; i < subdivisions; i++) {
73
- subdivCoords.push(k * i);
74
- }
75
- return subdivCoords;
76
- }