domotion-svg 0.1.1

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.
Files changed (119) hide show
  1. package/FEATURES.md +102 -0
  2. package/LICENSE +21 -0
  3. package/README.md +66 -0
  4. package/dist/animator.d.ts +158 -0
  5. package/dist/animator.js +424 -0
  6. package/dist/animator.test.d.ts +5 -0
  7. package/dist/animator.test.js +169 -0
  8. package/dist/border-radius.test.d.ts +1 -0
  9. package/dist/border-radius.test.js +148 -0
  10. package/dist/capture.d.ts +193 -0
  11. package/dist/capture.js +786 -0
  12. package/dist/chrome.d.ts +45 -0
  13. package/dist/chrome.js +107 -0
  14. package/dist/cli.d.ts +16 -0
  15. package/dist/cli.js +512 -0
  16. package/dist/client/dom.d.ts +10 -0
  17. package/dist/client/dom.js +17 -0
  18. package/dist/conic-raster.d.ts +58 -0
  19. package/dist/conic-raster.js +292 -0
  20. package/dist/conic-raster.test.d.ts +1 -0
  21. package/dist/conic-raster.test.js +187 -0
  22. package/dist/coretext-extractor.test.d.ts +1 -0
  23. package/dist/coretext-extractor.test.js +94 -0
  24. package/dist/coretext-helper.d.ts +60 -0
  25. package/dist/coretext-helper.js +205 -0
  26. package/dist/cross-origin-font-face.test.d.ts +1 -0
  27. package/dist/cross-origin-font-face.test.js +107 -0
  28. package/dist/cursor-overlay.d.ts +123 -0
  29. package/dist/cursor-overlay.js +207 -0
  30. package/dist/cursor-overlay.test.d.ts +1 -0
  31. package/dist/cursor-overlay.test.js +88 -0
  32. package/dist/dark-mode-capture.test.d.ts +1 -0
  33. package/dist/dark-mode-capture.test.js +158 -0
  34. package/dist/dark-mode-form-controls.test.d.ts +1 -0
  35. package/dist/dark-mode-form-controls.test.js +218 -0
  36. package/dist/dom-to-svg.d.ts +1016 -0
  37. package/dist/dom-to-svg.js +7717 -0
  38. package/dist/embed-remote-images.test.d.ts +1 -0
  39. package/dist/embed-remote-images.test.js +424 -0
  40. package/dist/form-controls.d.ts +70 -0
  41. package/dist/form-controls.js +1151 -0
  42. package/dist/frame-merge.d.ts +95 -0
  43. package/dist/frame-merge.js +374 -0
  44. package/dist/frame-merge.test.d.ts +6 -0
  45. package/dist/frame-merge.test.js +144 -0
  46. package/dist/gradients.d.ts +184 -0
  47. package/dist/gradients.js +937 -0
  48. package/dist/gradients.test.d.ts +1 -0
  49. package/dist/gradients.test.js +150 -0
  50. package/dist/index.d.ts +12 -0
  51. package/dist/index.js +7 -0
  52. package/dist/jsx-runtime.d.ts +27 -0
  53. package/dist/jsx-runtime.js +96 -0
  54. package/dist/jsx-runtime.test.d.ts +1 -0
  55. package/dist/jsx-runtime.test.js +41 -0
  56. package/dist/kerfjs-imports.test.d.ts +1 -0
  57. package/dist/kerfjs-imports.test.js +36 -0
  58. package/dist/mask.test.d.ts +1 -0
  59. package/dist/mask.test.js +206 -0
  60. package/dist/optimize.d.ts +12 -0
  61. package/dist/optimize.js +32 -0
  62. package/dist/preserve-aspect-ratio.test.d.ts +1 -0
  63. package/dist/preserve-aspect-ratio.test.js +38 -0
  64. package/dist/resize-embedded-images.d.ts +33 -0
  65. package/dist/resize-embedded-images.js +164 -0
  66. package/dist/resize-embedded-images.test.d.ts +9 -0
  67. package/dist/resize-embedded-images.test.js +255 -0
  68. package/dist/stacking-context.test.d.ts +1 -0
  69. package/dist/stacking-context.test.js +927 -0
  70. package/dist/text-renderer.d.ts +42 -0
  71. package/dist/text-renderer.js +608 -0
  72. package/dist/text-renderer.test.d.ts +1 -0
  73. package/dist/text-renderer.test.js +150 -0
  74. package/dist/text-to-path.d.ts +265 -0
  75. package/dist/text-to-path.js +1800 -0
  76. package/dist/text-to-path.test.d.ts +1 -0
  77. package/dist/text-to-path.test.js +570 -0
  78. package/dist/utils/escapeHtml.d.ts +2 -0
  79. package/dist/utils/escapeHtml.js +15 -0
  80. package/dist/webfont-unicode-range.test.d.ts +1 -0
  81. package/dist/webfont-unicode-range.test.js +174 -0
  82. package/package.json +55 -0
  83. package/src/animator.test.ts +179 -0
  84. package/src/animator.ts +660 -0
  85. package/src/border-radius.test.ts +160 -0
  86. package/src/capture.ts +810 -0
  87. package/src/cli.ts +582 -0
  88. package/src/conic-raster.test.ts +213 -0
  89. package/src/conic-raster.ts +309 -0
  90. package/src/coretext-extractor.test.ts +130 -0
  91. package/src/coretext-helper.ts +256 -0
  92. package/src/cross-origin-font-face.test.ts +119 -0
  93. package/src/cursor-overlay.test.ts +95 -0
  94. package/src/cursor-overlay.ts +297 -0
  95. package/src/dark-mode-capture.test.ts +177 -0
  96. package/src/dark-mode-form-controls.test.ts +228 -0
  97. package/src/dom-to-svg.ts +8376 -0
  98. package/src/embed-remote-images.test.ts +461 -0
  99. package/src/form-controls.ts +1174 -0
  100. package/src/frame-merge.test.ts +157 -0
  101. package/src/frame-merge.ts +447 -0
  102. package/src/globals.d.ts +2 -0
  103. package/src/gradients.test.ts +175 -0
  104. package/src/gradients.ts +955 -0
  105. package/src/index.ts +12 -0
  106. package/src/kerf-jsx-augmentation.d.ts +36 -0
  107. package/src/kerfjs-imports.test.tsx +45 -0
  108. package/src/mask.test.ts +274 -0
  109. package/src/optimize.ts +34 -0
  110. package/src/preserve-aspect-ratio.test.ts +49 -0
  111. package/src/resize-embedded-images.test.ts +292 -0
  112. package/src/resize-embedded-images.ts +180 -0
  113. package/src/stacking-context.test.ts +967 -0
  114. package/src/text-renderer.test.ts +162 -0
  115. package/src/text-renderer.ts +623 -0
  116. package/src/text-to-path.test.ts +639 -0
  117. package/src/text-to-path.ts +1810 -0
  118. package/src/utils/escapeHtml.ts +16 -0
  119. package/src/webfont-unicode-range.test.ts +207 -0
@@ -0,0 +1,228 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { stockPalette, type DefCtx } from "./form-controls.js";
3
+ import { elementTreeToSvg, type CapturedElement } from "./dom-to-svg.js";
4
+
5
+ // DM-553: form-control synthesizers consume `defCtx.colorScheme` to pick the
6
+ // stock palette. Tests verify (1) the `stockPalette(scheme)` dispatcher
7
+ // returns the right palette per scheme, (2) renderFormControl-driven SVG
8
+ // emission uses dark palette colors when the captured tree's root reports
9
+ // dark scheme, (3) light scheme + missing scheme stay byte-identical to
10
+ // today's output.
11
+
12
+ const STOCK_LIGHT_FILL = "rgb(255,255,255)";
13
+ const STOCK_LIGHT_BORDER = "rgb(118,118,118)";
14
+ const STOCK_LIGHT_ACCENT = "rgb(0,117,255)";
15
+ const STOCK_DARK_FILL = "rgb(59,59,59)";
16
+ const STOCK_DARK_BORDER = "rgb(59,59,59)";
17
+ const STOCK_DARK_ACCENT = "rgb(153,200,255)";
18
+ const STOCK_DARK_TRACK_BG = "rgb(59,59,59)";
19
+
20
+ describe("stockPalette dispatcher", () => {
21
+ it("returns the light palette for `light`", () => {
22
+ const p = stockPalette("light");
23
+ expect(p.fill).toBe(STOCK_LIGHT_FILL);
24
+ expect(p.border).toBe(STOCK_LIGHT_BORDER);
25
+ expect(p.accent).toBe(STOCK_LIGHT_ACCENT);
26
+ });
27
+
28
+ it("returns the dark palette for `dark`", () => {
29
+ const p = stockPalette("dark");
30
+ expect(p.fill).toBe(STOCK_DARK_FILL);
31
+ expect(p.border).toBe(STOCK_DARK_BORDER);
32
+ expect(p.accent).toBe(STOCK_DARK_ACCENT);
33
+ expect(p.trackBg).toBe(STOCK_DARK_TRACK_BG);
34
+ });
35
+
36
+ it("defaults to light when scheme is undefined / missing", () => {
37
+ expect(stockPalette(undefined).fill).toBe(STOCK_LIGHT_FILL);
38
+ });
39
+
40
+ it("defaults to light for any string other than 'dark'", () => {
41
+ expect(stockPalette("light").fill).toBe(STOCK_LIGHT_FILL);
42
+ expect(stockPalette(undefined).accent).toBe(STOCK_LIGHT_ACCENT);
43
+ });
44
+ });
45
+
46
+ void ({} as DefCtx); // type smoke
47
+
48
+ function makeBody(rootColorScheme?: "light" | "dark", children: CapturedElement[] = []): CapturedElement {
49
+ return {
50
+ tag: "body",
51
+ text: "",
52
+ x: 0, y: 0, width: 200, height: 200,
53
+ children,
54
+ styles: {
55
+ backgroundColor: "rgb(0,0,0)",
56
+ borderColor: "rgb(0,0,0)",
57
+ borderWidth: "0",
58
+ borderRadius: "0",
59
+ borderTopLeftRadius: "0",
60
+ borderTopRightRadius: "0",
61
+ borderBottomRightRadius: "0",
62
+ borderBottomLeftRadius: "0",
63
+ borderTopWidth: "0",
64
+ borderRightWidth: "0",
65
+ borderBottomWidth: "0",
66
+ borderLeftWidth: "0",
67
+ borderTopColor: "rgb(0,0,0)",
68
+ borderRightColor: "rgb(0,0,0)",
69
+ borderBottomColor: "rgb(0,0,0)",
70
+ borderLeftColor: "rgb(0,0,0)",
71
+ borderTopStyle: "none",
72
+ borderRightStyle: "none",
73
+ borderBottomStyle: "none",
74
+ borderLeftStyle: "none",
75
+ color: "rgb(255,255,255)",
76
+ fontSize: "16px",
77
+ fontFamily: "sans-serif",
78
+ fontWeight: "400",
79
+ fontStyle: "normal",
80
+ lineHeight: "20px",
81
+ letterSpacing: "normal",
82
+ textAlign: "left",
83
+ textTransform: "none",
84
+ textDecoration: "none",
85
+ textDecorationLine: "none",
86
+ textDecorationStyle: "solid",
87
+ textDecorationColor: "rgb(0,0,0)",
88
+ textDecorationThickness: "auto",
89
+ textIndent: "0",
90
+ textShadow: "none",
91
+ textWrap: "wrap",
92
+ whiteSpace: "normal",
93
+ wordBreak: "normal",
94
+ overflowWrap: "normal",
95
+ verticalAlign: "baseline",
96
+ backgroundImage: "none",
97
+ backgroundSize: "auto",
98
+ backgroundPosition: "0% 0%",
99
+ backgroundRepeat: "repeat",
100
+ backgroundAttachment: "scroll",
101
+ backgroundClip: "border-box",
102
+ backgroundOrigin: "padding-box",
103
+ opacity: "1",
104
+ position: "static",
105
+ top: "auto",
106
+ left: "auto",
107
+ right: "auto",
108
+ bottom: "auto",
109
+ display: "block",
110
+ flexDirection: "row",
111
+ visibility: "visible",
112
+ zIndex: "auto",
113
+ transform: "none",
114
+ transformOrigin: "50% 50%",
115
+ writingMode: "horizontal-tb",
116
+ textOrientation: "mixed",
117
+ cursor: "auto",
118
+ pointerEvents: "auto",
119
+ ...(rootColorScheme != null ? { rootColorScheme } : {}),
120
+ } as any,
121
+ };
122
+ }
123
+
124
+ function makeCheckbox(): CapturedElement {
125
+ const e = makeBody(undefined);
126
+ e.tag = "input";
127
+ e.x = 10; e.y = 10; e.width = 13; e.height = 13;
128
+ (e.styles as any).inputType = "checkbox";
129
+ return e;
130
+ }
131
+
132
+ function makeProgress(): CapturedElement {
133
+ const e = makeBody(undefined);
134
+ e.tag = "progress";
135
+ e.x = 10; e.y = 30; e.width = 100; e.height = 14;
136
+ (e.styles as any).progressValue = 0.5;
137
+ (e.styles as any).progressMax = 1;
138
+ return e;
139
+ }
140
+
141
+ function makeMeter(): CapturedElement {
142
+ const e = makeBody(undefined);
143
+ e.tag = "meter";
144
+ e.x = 10; e.y = 50; e.width = 100; e.height = 14;
145
+ (e.styles as any).meterValue = 0.5;
146
+ (e.styles as any).meterMin = 0;
147
+ (e.styles as any).meterMax = 1;
148
+ (e.styles as any).meterLow = 0.3;
149
+ (e.styles as any).meterHigh = 0.7;
150
+ (e.styles as any).meterOptimum = 0.5;
151
+ return e;
152
+ }
153
+
154
+ function makeRange(): CapturedElement {
155
+ const e = makeBody(undefined);
156
+ e.tag = "input";
157
+ e.x = 10; e.y = 70; e.width = 100; e.height = 14;
158
+ (e.styles as any).inputType = "range";
159
+ (e.styles as any).rangeMin = 0;
160
+ (e.styles as any).rangeMax = 100;
161
+ (e.styles as any).rangeValue = 50;
162
+ return e;
163
+ }
164
+
165
+ function emitForScheme(scheme: "light" | "dark" | undefined, control: CapturedElement): string {
166
+ const root = makeBody(scheme, [control]);
167
+ return elementTreeToSvg([root], 200, 200);
168
+ }
169
+
170
+ describe("renderCheckbox: scheme-aware palette (DM-553)", () => {
171
+ it("uses LIGHT fill + LIGHT border under default scheme", () => {
172
+ const out = emitForScheme(undefined, makeCheckbox());
173
+ expect(out).toContain(`fill="${STOCK_LIGHT_FILL}"`);
174
+ expect(out).toContain(`stroke="${STOCK_LIGHT_BORDER}"`);
175
+ });
176
+
177
+ it("uses LIGHT fill + LIGHT border when scheme is 'light'", () => {
178
+ const out = emitForScheme("light", makeCheckbox());
179
+ expect(out).toContain(`fill="${STOCK_LIGHT_FILL}"`);
180
+ expect(out).toContain(`stroke="${STOCK_LIGHT_BORDER}"`);
181
+ expect(out).not.toContain(`fill="${STOCK_DARK_FILL}"`);
182
+ });
183
+
184
+ it("uses DARK fill + DARK border when scheme is 'dark'", () => {
185
+ const out = emitForScheme("dark", makeCheckbox());
186
+ expect(out).toContain(`fill="${STOCK_DARK_FILL}"`);
187
+ expect(out).toContain(`stroke="${STOCK_DARK_BORDER}"`);
188
+ expect(out).not.toContain(`fill="${STOCK_LIGHT_FILL}"`);
189
+ });
190
+ });
191
+
192
+ describe("renderProgress: scheme-aware palette (DM-553)", () => {
193
+ it("uses LIGHT track + LIGHT accent under default scheme", () => {
194
+ const out = emitForScheme(undefined, makeProgress());
195
+ expect(out).toContain(STOCK_LIGHT_ACCENT);
196
+ });
197
+
198
+ it("uses DARK track + DARK accent when scheme is 'dark'", () => {
199
+ const out = emitForScheme("dark", makeProgress());
200
+ expect(out).toContain(STOCK_DARK_ACCENT);
201
+ expect(out).not.toContain(STOCK_LIGHT_ACCENT);
202
+ });
203
+ });
204
+
205
+ describe("renderMeter: scheme-aware palette (DM-553)", () => {
206
+ it("uses the LIGHT meter green at default scheme (value in optimum band)", () => {
207
+ const out = emitForScheme(undefined, makeMeter());
208
+ expect(out).toContain("rgb(16,124,16)"); // STOCK_LIGHT.meterGreen
209
+ });
210
+
211
+ it("uses the DARK meter green when scheme is 'dark'", () => {
212
+ const out = emitForScheme("dark", makeMeter());
213
+ expect(out).toContain("rgb(116,179,116)"); // STOCK_DARK.meterGreen
214
+ expect(out).not.toContain("rgb(16,124,16)");
215
+ });
216
+ });
217
+
218
+ describe("renderRange: scheme-aware UA-default palette (DM-553)", () => {
219
+ it("uses LIGHT accent at default scheme", () => {
220
+ const out = emitForScheme(undefined, makeRange());
221
+ expect(out).toContain(STOCK_LIGHT_ACCENT);
222
+ });
223
+
224
+ it("uses DARK accent when scheme is 'dark'", () => {
225
+ const out = emitForScheme("dark", makeRange());
226
+ expect(out).toContain(STOCK_DARK_ACCENT);
227
+ });
228
+ });