@yh-ui/flow 0.1.56 → 1.0.4

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 (70) hide show
  1. package/dist/__tests__/bpmn-engine.test.cjs +357 -0
  2. package/dist/__tests__/bpmn-engine.test.d.ts +1 -0
  3. package/dist/__tests__/bpmn-engine.test.mjs +406 -0
  4. package/dist/__tests__/bpmn-utils.test.cjs +268 -0
  5. package/dist/__tests__/bpmn-utils.test.d.ts +1 -0
  6. package/dist/__tests__/bpmn-utils.test.mjs +227 -0
  7. package/dist/__tests__/bpmn-xml.test.cjs +150 -0
  8. package/dist/__tests__/bpmn-xml.test.d.ts +1 -0
  9. package/dist/__tests__/bpmn-xml.test.mjs +112 -0
  10. package/dist/__tests__/collaboration.test.cjs +487 -0
  11. package/dist/__tests__/collaboration.test.d.ts +1 -0
  12. package/dist/__tests__/collaboration.test.mjs +424 -0
  13. package/dist/__tests__/edge-types.test.cjs +275 -0
  14. package/dist/__tests__/edge-types.test.d.ts +1 -0
  15. package/dist/__tests__/edge-types.test.mjs +234 -0
  16. package/dist/__tests__/edge-utils.test.cjs +375 -0
  17. package/dist/__tests__/edge-utils.test.d.ts +1 -0
  18. package/dist/__tests__/edge-utils.test.mjs +376 -0
  19. package/dist/__tests__/events-types.test.cjs +184 -0
  20. package/dist/__tests__/events-types.test.d.ts +1 -0
  21. package/dist/__tests__/events-types.test.mjs +184 -0
  22. package/dist/__tests__/export-image-plugin.test.cjs +142 -0
  23. package/dist/__tests__/export-image-plugin.test.d.ts +1 -0
  24. package/dist/__tests__/export-image-plugin.test.mjs +118 -0
  25. package/dist/__tests__/export.test.cjs +237 -0
  26. package/dist/__tests__/export.test.d.ts +1 -0
  27. package/dist/__tests__/export.test.mjs +171 -0
  28. package/dist/__tests__/flow-context.test.cjs +16 -0
  29. package/dist/__tests__/flow-context.test.d.ts +1 -0
  30. package/dist/__tests__/flow-context.test.mjs +16 -0
  31. package/dist/__tests__/flow-props.test.cjs +94 -0
  32. package/dist/__tests__/flow-props.test.d.ts +1 -0
  33. package/dist/__tests__/flow-props.test.mjs +92 -0
  34. package/dist/__tests__/layout-plugin.test.cjs +233 -0
  35. package/dist/__tests__/layout-plugin.test.d.ts +1 -0
  36. package/dist/__tests__/layout-plugin.test.mjs +215 -0
  37. package/dist/__tests__/node-types.test.cjs +368 -0
  38. package/dist/__tests__/node-types.test.d.ts +1 -0
  39. package/dist/__tests__/node-types.test.mjs +292 -0
  40. package/dist/__tests__/performance.test.cjs +313 -0
  41. package/dist/__tests__/performance.test.d.ts +1 -0
  42. package/dist/__tests__/performance.test.mjs +218 -0
  43. package/dist/__tests__/plugin-advanced.test.cjs +301 -0
  44. package/dist/__tests__/plugin-advanced.test.d.ts +1 -0
  45. package/dist/__tests__/plugin-advanced.test.mjs +225 -0
  46. package/dist/__tests__/plugins.test.cjs +412 -0
  47. package/dist/__tests__/plugins.test.d.ts +1 -0
  48. package/dist/__tests__/plugins.test.mjs +402 -0
  49. package/dist/__tests__/screenshot-capture.test.cjs +183 -0
  50. package/dist/__tests__/screenshot-capture.test.d.ts +1 -0
  51. package/dist/__tests__/screenshot-capture.test.mjs +124 -0
  52. package/dist/__tests__/screenshot.test.cjs +74 -0
  53. package/dist/__tests__/screenshot.test.d.ts +1 -0
  54. package/dist/__tests__/screenshot.test.mjs +69 -0
  55. package/dist/__tests__/theme.test.cjs +185 -0
  56. package/dist/__tests__/theme.test.d.ts +1 -0
  57. package/dist/__tests__/theme.test.mjs +191 -0
  58. package/dist/__tests__/transform.test.cjs +376 -50
  59. package/dist/__tests__/transform.test.mjs +229 -28
  60. package/dist/__tests__/useAlignment.test.cjs +37 -0
  61. package/dist/__tests__/useAlignment.test.mjs +20 -0
  62. package/dist/__tests__/useNodeDistribution.test.cjs +643 -0
  63. package/dist/__tests__/useNodeDistribution.test.d.ts +1 -0
  64. package/dist/__tests__/useNodeDistribution.test.mjs +297 -0
  65. package/dist/__tests__/viewport-types.test.cjs +324 -0
  66. package/dist/__tests__/viewport-types.test.d.ts +1 -0
  67. package/dist/__tests__/viewport-types.test.mjs +207 -0
  68. package/dist/utils/bpmn.cjs +27 -16
  69. package/dist/utils/bpmn.mjs +27 -19
  70. package/package.json +3 -3
@@ -0,0 +1,402 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import { ref } from "vue";
3
+ import { createControlsPlugin } from "../plugins/plugins/controls.mjs";
4
+ import { createGridPlugin } from "../plugins/plugins/grid.mjs";
5
+ import { createKeyboardPlugin } from "../plugins/plugins/keyboard.mjs";
6
+ import { createMiniMapPlugin } from "../plugins/plugins/minimap.mjs";
7
+ import { createSnapPlugin } from "../plugins/plugins/snap.mjs";
8
+ function createMockFlowInstance() {
9
+ const nodes = ref([]);
10
+ const edges = ref([]);
11
+ const viewport = ref({ x: 0, y: 0, zoom: 1 });
12
+ const draggingNodeId = ref(null);
13
+ return {
14
+ nodes,
15
+ edges,
16
+ viewport,
17
+ draggingNodeId,
18
+ addNode: vi.fn(),
19
+ removeNode: vi.fn(),
20
+ updateNode: vi.fn(),
21
+ getNode: vi.fn(),
22
+ addEdge: vi.fn(),
23
+ removeEdge: vi.fn(),
24
+ updateEdge: vi.fn(),
25
+ getEdge: vi.fn(),
26
+ setViewport: vi.fn(),
27
+ fitView: vi.fn(),
28
+ zoomIn: vi.fn(),
29
+ zoomOut: vi.fn(),
30
+ centerView: vi.fn(),
31
+ selectNode: vi.fn(),
32
+ selectEdge: vi.fn(),
33
+ clearSelection: vi.fn(),
34
+ getNodes: vi.fn(() => nodes.value),
35
+ getEdges: vi.fn(() => edges.value),
36
+ getViewport: vi.fn(() => viewport.value),
37
+ screenToCanvas: vi.fn(),
38
+ canvasToScreen: vi.fn(),
39
+ on: vi.fn(),
40
+ off: vi.fn(),
41
+ emit: vi.fn(),
42
+ isValidConnection: vi.fn(() => true),
43
+ $el: void 0,
44
+ usePlugin: vi.fn(),
45
+ removePlugin: vi.fn()
46
+ };
47
+ }
48
+ describe("flow/plugins/plugins/controls", () => {
49
+ let consoleLogSpy;
50
+ beforeEach(() => {
51
+ consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {
52
+ });
53
+ });
54
+ afterEach(() => {
55
+ consoleLogSpy.mockRestore();
56
+ });
57
+ describe("createControlsPlugin", () => {
58
+ it("should create plugin with correct id and name", () => {
59
+ const plugin = createControlsPlugin();
60
+ expect(plugin.id).toBe("controls");
61
+ expect(plugin.name).toBe("Controls");
62
+ expect(plugin.version).toBe("1.0.0");
63
+ expect(plugin.description).toBe("Displays a set of controls for zooming and fitting the view");
64
+ });
65
+ it("should have a component", () => {
66
+ const plugin = createControlsPlugin();
67
+ expect(plugin.component).toBeDefined();
68
+ });
69
+ it("should install with default options", () => {
70
+ const flow = createMockFlowInstance();
71
+ const plugin = createControlsPlugin();
72
+ plugin.install(flow);
73
+ expect(consoleLogSpy).toHaveBeenCalledWith("[Controls Plugin] Installed");
74
+ });
75
+ it("should merge custom options", () => {
76
+ const plugin = createControlsPlugin({
77
+ enabled: true,
78
+ position: "top-right",
79
+ showZoom: true,
80
+ showFitView: false,
81
+ showInteractive: false
82
+ });
83
+ expect(plugin.componentProps).toEqual({
84
+ position: "top-right",
85
+ showZoom: true,
86
+ showFitView: false,
87
+ showInteractive: false
88
+ });
89
+ });
90
+ it("should use default position when not provided", () => {
91
+ const plugin = createControlsPlugin();
92
+ expect(plugin.componentProps?.position).toBe("bottom-left");
93
+ });
94
+ it("should use default show options", () => {
95
+ const plugin = createControlsPlugin();
96
+ expect(plugin.componentProps?.showZoom).toBe(true);
97
+ expect(plugin.componentProps?.showFitView).toBe(true);
98
+ expect(plugin.componentProps?.showInteractive).toBe(true);
99
+ });
100
+ it("should support all position options", () => {
101
+ const positions = [
102
+ "top-left",
103
+ "top-right",
104
+ "bottom-left",
105
+ "bottom-right"
106
+ ];
107
+ for (const pos of positions) {
108
+ const plugin = createControlsPlugin({ position: pos });
109
+ expect(plugin.componentProps?.position).toBe(pos);
110
+ }
111
+ });
112
+ });
113
+ });
114
+ describe("flow/plugins/plugins/grid", () => {
115
+ let consoleLogSpy;
116
+ beforeEach(() => {
117
+ consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {
118
+ });
119
+ });
120
+ afterEach(() => {
121
+ consoleLogSpy.mockRestore();
122
+ });
123
+ describe("createGridPlugin", () => {
124
+ it("should create plugin with correct id and name", () => {
125
+ const plugin = createGridPlugin();
126
+ expect(plugin.id).toBe("grid");
127
+ expect(plugin.name).toBe("Grid");
128
+ expect(plugin.version).toBe("1.0.0");
129
+ expect(plugin.description).toBe("Displays a grid or dots background");
130
+ });
131
+ it("should have a component", () => {
132
+ const plugin = createGridPlugin();
133
+ expect(plugin.component).toBeDefined();
134
+ });
135
+ it("should install with default options", () => {
136
+ const flow = createMockFlowInstance();
137
+ const plugin = createGridPlugin();
138
+ plugin.install(flow);
139
+ expect(consoleLogSpy).toHaveBeenCalledWith("[Grid Plugin] Installed");
140
+ });
141
+ it("should merge custom options", () => {
142
+ const plugin = createGridPlugin({
143
+ enabled: true,
144
+ type: "grid",
145
+ color: "#ff0000",
146
+ gap: 30
147
+ });
148
+ expect(plugin.componentProps).toEqual({
149
+ type: "grid",
150
+ color: "#ff0000",
151
+ gap: 30
152
+ });
153
+ });
154
+ it("should use default type dots", () => {
155
+ const plugin = createGridPlugin();
156
+ expect(plugin.componentProps?.type).toBe("dots");
157
+ });
158
+ it("should use default gap", () => {
159
+ const plugin = createGridPlugin();
160
+ expect(plugin.componentProps?.gap).toBe(20);
161
+ });
162
+ it("should use default color", () => {
163
+ const plugin = createGridPlugin();
164
+ expect(plugin.componentProps?.color).toBe("#e5e5e5");
165
+ });
166
+ it("should support grid type", () => {
167
+ const plugin = createGridPlugin({ type: "grid" });
168
+ expect(plugin.componentProps?.type).toBe("grid");
169
+ });
170
+ });
171
+ });
172
+ describe("flow/plugins/plugins/keyboard", () => {
173
+ let consoleLogSpy;
174
+ beforeEach(() => {
175
+ consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {
176
+ });
177
+ });
178
+ afterEach(() => {
179
+ consoleLogSpy.mockRestore();
180
+ });
181
+ describe("createKeyboardPlugin", () => {
182
+ it("should create plugin with correct id and name", () => {
183
+ const plugin = createKeyboardPlugin();
184
+ expect(plugin.id).toBe("keyboard");
185
+ expect(plugin.name).toBe("Keyboard");
186
+ });
187
+ it("should install with default options", () => {
188
+ const flow = createMockFlowInstance();
189
+ const plugin = createKeyboardPlugin();
190
+ plugin.install(flow);
191
+ expect(consoleLogSpy).toHaveBeenCalledWith("Keyboard plugin installed", {
192
+ enabled: true,
193
+ delete: true,
194
+ backspace: true,
195
+ ctrlZ: true,
196
+ ctrlY: true,
197
+ escape: true
198
+ });
199
+ });
200
+ it("should merge custom options", () => {
201
+ const plugin = createKeyboardPlugin({
202
+ enabled: false,
203
+ delete: false,
204
+ backspace: false,
205
+ ctrlZ: false,
206
+ ctrlY: false,
207
+ escape: false
208
+ });
209
+ plugin.install(createMockFlowInstance());
210
+ expect(consoleLogSpy).toHaveBeenCalledWith("Keyboard plugin installed", {
211
+ enabled: false,
212
+ delete: false,
213
+ backspace: false,
214
+ ctrlZ: false,
215
+ ctrlY: false,
216
+ escape: false
217
+ });
218
+ });
219
+ it("should accept partial options", () => {
220
+ const plugin = createKeyboardPlugin({ delete: false });
221
+ expect(plugin.id).toBe("keyboard");
222
+ });
223
+ it("should override individual options", () => {
224
+ const plugin = createKeyboardPlugin({
225
+ ctrlZ: false,
226
+ ctrlY: false
227
+ });
228
+ plugin.install(createMockFlowInstance());
229
+ expect(consoleLogSpy).toHaveBeenCalledWith("Keyboard plugin installed", {
230
+ enabled: true,
231
+ delete: true,
232
+ backspace: true,
233
+ ctrlZ: false,
234
+ ctrlY: false,
235
+ escape: true
236
+ });
237
+ });
238
+ });
239
+ });
240
+ describe("flow/plugins/plugins/minimap", () => {
241
+ let consoleLogSpy;
242
+ beforeEach(() => {
243
+ consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {
244
+ });
245
+ });
246
+ afterEach(() => {
247
+ consoleLogSpy.mockRestore();
248
+ });
249
+ describe("createMiniMapPlugin", () => {
250
+ it("should create plugin with correct id and name", () => {
251
+ const plugin = createMiniMapPlugin();
252
+ expect(plugin.id).toBe("minimap");
253
+ expect(plugin.name).toBe("Minimap");
254
+ expect(plugin.version).toBe("1.0.0");
255
+ expect(plugin.description).toBe("Displays a minimap for navigation");
256
+ });
257
+ it("should have a component", () => {
258
+ const plugin = createMiniMapPlugin();
259
+ expect(plugin.component).toBeDefined();
260
+ });
261
+ it("should install with default options", () => {
262
+ const flow = createMockFlowInstance();
263
+ const plugin = createMiniMapPlugin();
264
+ plugin.install(flow);
265
+ expect(consoleLogSpy).toHaveBeenCalled();
266
+ });
267
+ it("should use default position bottom-right", () => {
268
+ const plugin = createMiniMapPlugin();
269
+ expect(plugin.componentProps?.position).toBe("bottom-right");
270
+ });
271
+ it("should use default dimensions", () => {
272
+ const plugin = createMiniMapPlugin();
273
+ expect(plugin.componentProps?.width).toBe(200);
274
+ expect(plugin.componentProps?.height).toBe(150);
275
+ });
276
+ it("should use default mask colors", () => {
277
+ const plugin = createMiniMapPlugin();
278
+ expect(plugin.componentProps?.maskColor).toBe("rgba(240, 240, 240, 0.6)");
279
+ expect(plugin.componentProps?.maskStrokeColor).toBe("#ddd");
280
+ expect(plugin.componentProps?.maskStrokeWidth).toBe(1);
281
+ });
282
+ it("should use default pannable and zoomable", () => {
283
+ const plugin = createMiniMapPlugin();
284
+ expect(plugin.componentProps?.pannable).toBe(true);
285
+ expect(plugin.componentProps?.zoomable).toBe(true);
286
+ });
287
+ it("should support custom position", () => {
288
+ const positions = [
289
+ "top-left",
290
+ "top-right",
291
+ "bottom-left",
292
+ "bottom-right"
293
+ ];
294
+ for (const pos of positions) {
295
+ const plugin = createMiniMapPlugin({ position: pos });
296
+ expect(plugin.componentProps?.position).toBe(pos);
297
+ }
298
+ });
299
+ it("should support custom dimensions", () => {
300
+ const plugin = createMiniMapPlugin({ width: 300, height: 200 });
301
+ expect(plugin.componentProps?.width).toBe(300);
302
+ expect(plugin.componentProps?.height).toBe(200);
303
+ });
304
+ it("should support custom node color functions", () => {
305
+ const customNodeColor = (node) => "#ff0000";
306
+ const customNodeStrokeColor = (node) => "#00ff00";
307
+ const plugin = createMiniMapPlugin({
308
+ nodeColor: customNodeColor,
309
+ nodeStrokeColor: customNodeStrokeColor
310
+ });
311
+ expect(plugin.componentProps?.nodeColor).toBe(customNodeColor);
312
+ expect(plugin.componentProps?.nodeStrokeColor).toBe(customNodeStrokeColor);
313
+ });
314
+ it("should support interactive option", () => {
315
+ const pluginEnabled = createMiniMapPlugin({ interactive: true });
316
+ const pluginDisabled = createMiniMapPlugin({ interactive: false });
317
+ expect(pluginEnabled.componentProps?.interactive).toBe(true);
318
+ expect(pluginDisabled.componentProps?.interactive).toBe(false);
319
+ });
320
+ it("should support layout controls options", () => {
321
+ const plugin = createMiniMapPlugin({
322
+ showLayoutControls: true,
323
+ layoutType: "dagre",
324
+ layoutDirection: "LR"
325
+ });
326
+ expect(plugin.componentProps?.showLayoutControls).toBe(true);
327
+ expect(plugin.componentProps?.layoutType).toBe("dagre");
328
+ expect(plugin.componentProps?.layoutDirection).toBe("LR");
329
+ });
330
+ it("should support all layout directions", () => {
331
+ const directions = ["TB", "BT", "LR", "RL"];
332
+ for (const dir of directions) {
333
+ const plugin = createMiniMapPlugin({ layoutDirection: dir });
334
+ expect(plugin.componentProps?.layoutDirection).toBe(dir);
335
+ }
336
+ });
337
+ it("should support all layout types", () => {
338
+ const types = [
339
+ "dagre",
340
+ "elk",
341
+ "force",
342
+ "grid",
343
+ "none"
344
+ ];
345
+ for (const type of types) {
346
+ const plugin = createMiniMapPlugin({ layoutType: type });
347
+ expect(plugin.componentProps?.layoutType).toBe(type);
348
+ }
349
+ });
350
+ });
351
+ });
352
+ describe("flow/plugins/plugins/snap", () => {
353
+ let consoleLogSpy;
354
+ beforeEach(() => {
355
+ consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {
356
+ });
357
+ });
358
+ afterEach(() => {
359
+ consoleLogSpy.mockRestore();
360
+ });
361
+ describe("createSnapPlugin", () => {
362
+ it("should create plugin with correct id and name", () => {
363
+ const plugin = createSnapPlugin();
364
+ expect(plugin.id).toBe("snap");
365
+ expect(plugin.name).toBe("Snap");
366
+ expect(plugin.version).toBe("1.0.0");
367
+ expect(plugin.description).toBe("Enables grid snapping and alignment lines");
368
+ });
369
+ it("should have a component when showAlignmentLines is true", () => {
370
+ const plugin = createSnapPlugin({ showAlignmentLines: true });
371
+ expect(plugin.component).toBeDefined();
372
+ });
373
+ it("should not have a component when showAlignmentLines is false", () => {
374
+ const plugin = createSnapPlugin({ showAlignmentLines: false });
375
+ expect(plugin.component).toBeUndefined();
376
+ });
377
+ it("should install with default options", () => {
378
+ const flow = createMockFlowInstance();
379
+ const plugin = createSnapPlugin();
380
+ plugin.install(flow);
381
+ expect(consoleLogSpy).toHaveBeenCalled();
382
+ });
383
+ it("should not install when enabled is false", () => {
384
+ const flow = createMockFlowInstance();
385
+ const plugin = createSnapPlugin({ enabled: false });
386
+ plugin.install(flow);
387
+ expect(consoleLogSpy).not.toHaveBeenCalled();
388
+ });
389
+ it("should use default snap options", () => {
390
+ const plugin = createSnapPlugin();
391
+ expect(plugin.componentProps?.snapThreshold).toBe(10);
392
+ });
393
+ it("should support custom snap options", () => {
394
+ const plugin = createSnapPlugin({
395
+ snapToGrid: true,
396
+ gridSize: 20,
397
+ snapThreshold: 15
398
+ });
399
+ expect(plugin.componentProps?.snapThreshold).toBe(15);
400
+ });
401
+ });
402
+ });
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _screenshot = require("../utils/screenshot.cjs");
5
+ (0, _vitest.describe)("flow/utils/screenshot - captureElement", () => {
6
+ let mockToPng;
7
+ let mockToJpeg;
8
+ let mockToWebp;
9
+ let mockFetch;
10
+ (0, _vitest.beforeEach)(() => {
11
+ _vitest.vi.stubGlobal("fetch", mockFetch = _vitest.vi.fn().mockResolvedValue(new Response(new Blob(["test"], {
12
+ type: "image/png"
13
+ }))));
14
+ });
15
+ (0, _vitest.afterEach)(() => {
16
+ _vitest.vi.restoreAllMocks();
17
+ });
18
+ const createMockHtmlToImage = () => {
19
+ mockToPng = _vitest.vi.fn().mockResolvedValue("data:image/png;base64,test");
20
+ mockToJpeg = _vitest.vi.fn().mockResolvedValue("data:image/jpeg;base64,test");
21
+ mockToWebp = _vitest.vi.fn().mockResolvedValue("data:image/webp;base64,test");
22
+ return {
23
+ toPng: mockToPng,
24
+ toJpeg: mockToJpeg,
25
+ toWebp: mockToWebp
26
+ };
27
+ };
28
+ const createMockElement = () => {
29
+ const el = document.createElement("div");
30
+ Object.defineProperty(el, "offsetWidth", {
31
+ value: 100,
32
+ configurable: true
33
+ });
34
+ Object.defineProperty(el, "offsetHeight", {
35
+ value: 200,
36
+ configurable: true
37
+ });
38
+ return el;
39
+ };
40
+ const defaultOptions = {
41
+ imageType: "png",
42
+ imageQuality: 1,
43
+ pixelRatio: 2,
44
+ backgroundColor: "#ffffff"
45
+ };
46
+ (0, _vitest.describe)("png capture", () => {
47
+ (0, _vitest.it)("should capture as png", async () => {
48
+ _vitest.vi.doMock("html-to-image", () => createMockHtmlToImage(), {
49
+ virtual: true
50
+ });
51
+ const mod = await Promise.resolve().then(() => require("html-to-image"));
52
+ const htmlToImage = mod.toPng ? mod : mod.default;
53
+ const el = createMockElement();
54
+ const result = await (0, _screenshot.captureElement)(el, {
55
+ ...defaultOptions,
56
+ imageType: "png"
57
+ });
58
+ (0, _vitest.expect)(result.extension).toBe("png");
59
+ (0, _vitest.expect)(result.mimeType).toBe("image/png");
60
+ });
61
+ });
62
+ (0, _vitest.describe)("jpeg capture", () => {
63
+ (0, _vitest.it)("should capture as jpeg", async () => {
64
+ const htmlToImage = createMockHtmlToImage();
65
+ _vitest.vi.doMock("html-to-image", () => htmlToImage, {
66
+ virtual: true
67
+ });
68
+ const el = createMockElement();
69
+ const result = await (0, _screenshot.captureElement)(el, {
70
+ ...defaultOptions,
71
+ imageType: "jpeg"
72
+ });
73
+ (0, _vitest.expect)(result.extension).toBe("jpeg");
74
+ (0, _vitest.expect)(result.mimeType).toBe("image/jpeg");
75
+ });
76
+ });
77
+ (0, _vitest.describe)("webp capture", () => {
78
+ (0, _vitest.it)("should capture as webp when supported", async () => {
79
+ const htmlToImage = createMockHtmlToImage();
80
+ _vitest.vi.doMock("html-to-image", () => htmlToImage, {
81
+ virtual: true
82
+ });
83
+ const el = createMockElement();
84
+ const result = await (0, _screenshot.captureElement)(el, {
85
+ ...defaultOptions,
86
+ imageType: "webp"
87
+ });
88
+ (0, _vitest.expect)(result.extension).toBe("webp");
89
+ (0, _vitest.expect)(result.mimeType).toBe("image/webp");
90
+ });
91
+ (0, _vitest.it)("should fall back to png when webp not supported", async () => {
92
+ const htmlToImage = {
93
+ toPng: _vitest.vi.fn().mockResolvedValue("data:image/png;base64,test"),
94
+ toJpeg: _vitest.vi.fn().mockResolvedValue("data:image/jpeg;base64,test"),
95
+ toWebp: void 0
96
+ };
97
+ _vitest.vi.doMock("html-to-image", () => htmlToImage, {
98
+ virtual: true
99
+ });
100
+ const el = createMockElement();
101
+ const result = await (0, _screenshot.captureElement)(el, {
102
+ ...defaultOptions,
103
+ imageType: "webp"
104
+ });
105
+ (0, _vitest.expect)(result.extension).toBe("png");
106
+ });
107
+ });
108
+ (0, _vitest.describe)("dimensions", () => {
109
+ (0, _vitest.it)("should calculate dimensions with pixel ratio", async () => {
110
+ const htmlToImage = createMockHtmlToImage();
111
+ _vitest.vi.doMock("html-to-image", () => htmlToImage, {
112
+ virtual: true
113
+ });
114
+ const el = createMockElement();
115
+ const result = await (0, _screenshot.captureElement)(el, {
116
+ ...defaultOptions,
117
+ pixelRatio: 3
118
+ });
119
+ (0, _vitest.expect)(result.width).toBe(300);
120
+ (0, _vitest.expect)(result.height).toBe(600);
121
+ });
122
+ });
123
+ (0, _vitest.describe)("image quality", () => {
124
+ (0, _vitest.it)("should pass quality option for jpeg", async () => {
125
+ const htmlToImage = createMockHtmlToImage();
126
+ _vitest.vi.doMock("html-to-image", () => htmlToImage, {
127
+ virtual: true
128
+ });
129
+ const el = createMockElement();
130
+ await (0, _screenshot.captureElement)(el, {
131
+ ...defaultOptions,
132
+ imageType: "jpeg",
133
+ imageQuality: 0.8
134
+ });
135
+ (0, _vitest.expect)(mockToJpeg).toHaveBeenCalledWith(el, _vitest.expect.objectContaining({
136
+ quality: 0.8
137
+ }));
138
+ });
139
+ (0, _vitest.it)("should pass quality option for webp", async () => {
140
+ const htmlToImage = createMockHtmlToImage();
141
+ _vitest.vi.doMock("html-to-image", () => htmlToImage, {
142
+ virtual: true
143
+ });
144
+ const el = createMockElement();
145
+ await (0, _screenshot.captureElement)(el, {
146
+ ...defaultOptions,
147
+ imageType: "webp",
148
+ imageQuality: 0.9
149
+ });
150
+ (0, _vitest.expect)(mockToWebp).toHaveBeenCalledWith(el, _vitest.expect.objectContaining({
151
+ quality: 0.9
152
+ }));
153
+ });
154
+ });
155
+ (0, _vitest.describe)("background color", () => {
156
+ (0, _vitest.it)("should pass background color option", async () => {
157
+ const htmlToImage = createMockHtmlToImage();
158
+ _vitest.vi.doMock("html-to-image", () => htmlToImage, {
159
+ virtual: true
160
+ });
161
+ const el = createMockElement();
162
+ await (0, _screenshot.captureElement)(el, {
163
+ ...defaultOptions,
164
+ backgroundColor: "#ff0000"
165
+ });
166
+ (0, _vitest.expect)(mockToPng).toHaveBeenCalledWith(el, _vitest.expect.objectContaining({
167
+ backgroundColor: "#ff0000"
168
+ }));
169
+ });
170
+ });
171
+ (0, _vitest.describe)("data URL to blob conversion", () => {
172
+ (0, _vitest.it)("should convert data URL to blob", async () => {
173
+ const htmlToImage = createMockHtmlToImage();
174
+ _vitest.vi.doMock("html-to-image", () => htmlToImage, {
175
+ virtual: true
176
+ });
177
+ const el = createMockElement();
178
+ const result = await (0, _screenshot.captureElement)(el, defaultOptions);
179
+ (0, _vitest.expect)(result.blob).toBeInstanceOf(Blob);
180
+ (0, _vitest.expect)(mockFetch).toHaveBeenCalled();
181
+ });
182
+ });
183
+ });
@@ -0,0 +1 @@
1
+ export {};