@yh-ui/flow 1.0.25 → 1.0.30

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 (143) hide show
  1. package/package.json +13 -11
  2. package/LICENSE +0 -21
  3. package/dist/__tests__/ai-workflow.ssr.test.cjs +0 -352
  4. package/dist/__tests__/ai-workflow.ssr.test.d.ts +0 -1
  5. package/dist/__tests__/ai-workflow.ssr.test.mjs +0 -283
  6. package/dist/__tests__/ai-workflow.test.cjs +0 -109
  7. package/dist/__tests__/ai-workflow.test.d.ts +0 -1
  8. package/dist/__tests__/ai-workflow.test.mjs +0 -112
  9. package/dist/__tests__/bpmn-engine.test.cjs +0 -357
  10. package/dist/__tests__/bpmn-engine.test.d.ts +0 -1
  11. package/dist/__tests__/bpmn-engine.test.mjs +0 -406
  12. package/dist/__tests__/bpmn-utils.test.cjs +0 -268
  13. package/dist/__tests__/bpmn-utils.test.d.ts +0 -1
  14. package/dist/__tests__/bpmn-utils.test.mjs +0 -227
  15. package/dist/__tests__/bpmn-xml.test.cjs +0 -150
  16. package/dist/__tests__/bpmn-xml.test.d.ts +0 -1
  17. package/dist/__tests__/bpmn-xml.test.mjs +0 -112
  18. package/dist/__tests__/bpmn.ssr.test.cjs +0 -278
  19. package/dist/__tests__/bpmn.ssr.test.d.ts +0 -1
  20. package/dist/__tests__/bpmn.ssr.test.mjs +0 -237
  21. package/dist/__tests__/bpmn.test.cjs +0 -103
  22. package/dist/__tests__/bpmn.test.d.ts +0 -1
  23. package/dist/__tests__/bpmn.test.mjs +0 -106
  24. package/dist/__tests__/collaboration.test.cjs +0 -487
  25. package/dist/__tests__/collaboration.test.d.ts +0 -1
  26. package/dist/__tests__/collaboration.test.mjs +0 -424
  27. package/dist/__tests__/custom-types.test.cjs +0 -300
  28. package/dist/__tests__/custom-types.test.d.ts +0 -1
  29. package/dist/__tests__/custom-types.test.mjs +0 -248
  30. package/dist/__tests__/edge-types.test.cjs +0 -275
  31. package/dist/__tests__/edge-types.test.d.ts +0 -1
  32. package/dist/__tests__/edge-types.test.mjs +0 -234
  33. package/dist/__tests__/edge-utils.test.cjs +0 -375
  34. package/dist/__tests__/edge-utils.test.d.ts +0 -1
  35. package/dist/__tests__/edge-utils.test.mjs +0 -376
  36. package/dist/__tests__/edge.test.cjs +0 -56
  37. package/dist/__tests__/edge.test.d.ts +0 -1
  38. package/dist/__tests__/edge.test.mjs +0 -69
  39. package/dist/__tests__/event-bus.test.cjs +0 -80
  40. package/dist/__tests__/event-bus.test.d.ts +0 -1
  41. package/dist/__tests__/event-bus.test.mjs +0 -51
  42. package/dist/__tests__/events-types.test.cjs +0 -184
  43. package/dist/__tests__/events-types.test.d.ts +0 -1
  44. package/dist/__tests__/events-types.test.mjs +0 -184
  45. package/dist/__tests__/export-image-plugin.test.cjs +0 -142
  46. package/dist/__tests__/export-image-plugin.test.d.ts +0 -1
  47. package/dist/__tests__/export-image-plugin.test.mjs +0 -118
  48. package/dist/__tests__/export.test.cjs +0 -237
  49. package/dist/__tests__/export.test.d.ts +0 -1
  50. package/dist/__tests__/export.test.mjs +0 -171
  51. package/dist/__tests__/flow-context.test.cjs +0 -16
  52. package/dist/__tests__/flow-context.test.d.ts +0 -1
  53. package/dist/__tests__/flow-context.test.mjs +0 -16
  54. package/dist/__tests__/flow-props.test.cjs +0 -94
  55. package/dist/__tests__/flow-props.test.d.ts +0 -1
  56. package/dist/__tests__/flow-props.test.mjs +0 -92
  57. package/dist/__tests__/flow.ssr.test.cjs +0 -156
  58. package/dist/__tests__/flow.ssr.test.d.ts +0 -1
  59. package/dist/__tests__/flow.ssr.test.mjs +0 -112
  60. package/dist/__tests__/geometry.test.cjs +0 -191
  61. package/dist/__tests__/geometry.test.d.ts +0 -1
  62. package/dist/__tests__/geometry.test.mjs +0 -105
  63. package/dist/__tests__/graph.test.cjs +0 -115
  64. package/dist/__tests__/graph.test.d.ts +0 -1
  65. package/dist/__tests__/graph.test.mjs +0 -85
  66. package/dist/__tests__/history-plugin.test.cjs +0 -191
  67. package/dist/__tests__/history-plugin.test.d.ts +0 -1
  68. package/dist/__tests__/history-plugin.test.mjs +0 -161
  69. package/dist/__tests__/history.test.cjs +0 -81
  70. package/dist/__tests__/history.test.d.ts +0 -1
  71. package/dist/__tests__/history.test.mjs +0 -43
  72. package/dist/__tests__/layout-plugin.test.cjs +0 -233
  73. package/dist/__tests__/layout-plugin.test.d.ts +0 -1
  74. package/dist/__tests__/layout-plugin.test.mjs +0 -215
  75. package/dist/__tests__/layout.test.cjs +0 -213
  76. package/dist/__tests__/layout.test.d.ts +0 -1
  77. package/dist/__tests__/layout.test.mjs +0 -170
  78. package/dist/__tests__/node-edit-panel.ssr.test.cjs +0 -168
  79. package/dist/__tests__/node-edit-panel.ssr.test.d.ts +0 -1
  80. package/dist/__tests__/node-edit-panel.ssr.test.mjs +0 -118
  81. package/dist/__tests__/node-group-plugin.test.cjs +0 -235
  82. package/dist/__tests__/node-group-plugin.test.d.ts +0 -1
  83. package/dist/__tests__/node-group-plugin.test.mjs +0 -187
  84. package/dist/__tests__/node-handles.test.cjs +0 -340
  85. package/dist/__tests__/node-handles.test.d.ts +0 -1
  86. package/dist/__tests__/node-handles.test.mjs +0 -230
  87. package/dist/__tests__/node-types.test.cjs +0 -368
  88. package/dist/__tests__/node-types.test.d.ts +0 -1
  89. package/dist/__tests__/node-types.test.mjs +0 -292
  90. package/dist/__tests__/performance.test.cjs +0 -313
  91. package/dist/__tests__/performance.test.d.ts +0 -1
  92. package/dist/__tests__/performance.test.mjs +0 -218
  93. package/dist/__tests__/plugin-advanced.test.cjs +0 -301
  94. package/dist/__tests__/plugin-advanced.test.d.ts +0 -1
  95. package/dist/__tests__/plugin-advanced.test.mjs +0 -225
  96. package/dist/__tests__/plugin.test.cjs +0 -151
  97. package/dist/__tests__/plugin.test.d.ts +0 -1
  98. package/dist/__tests__/plugin.test.mjs +0 -116
  99. package/dist/__tests__/plugins.test.cjs +0 -412
  100. package/dist/__tests__/plugins.test.d.ts +0 -1
  101. package/dist/__tests__/plugins.test.mjs +0 -402
  102. package/dist/__tests__/screenshot-capture.test.cjs +0 -183
  103. package/dist/__tests__/screenshot-capture.test.d.ts +0 -1
  104. package/dist/__tests__/screenshot-capture.test.mjs +0 -124
  105. package/dist/__tests__/screenshot.test.cjs +0 -74
  106. package/dist/__tests__/screenshot.test.d.ts +0 -1
  107. package/dist/__tests__/screenshot.test.mjs +0 -69
  108. package/dist/__tests__/theme.test.cjs +0 -185
  109. package/dist/__tests__/theme.test.d.ts +0 -1
  110. package/dist/__tests__/theme.test.mjs +0 -191
  111. package/dist/__tests__/transform.test.cjs +0 -384
  112. package/dist/__tests__/transform.test.d.ts +0 -1
  113. package/dist/__tests__/transform.test.mjs +0 -239
  114. package/dist/__tests__/useAlignment.test.cjs +0 -128
  115. package/dist/__tests__/useAlignment.test.d.ts +0 -1
  116. package/dist/__tests__/useAlignment.test.mjs +0 -72
  117. package/dist/__tests__/useEdges.test.cjs +0 -117
  118. package/dist/__tests__/useEdges.test.d.ts +0 -1
  119. package/dist/__tests__/useEdges.test.mjs +0 -80
  120. package/dist/__tests__/useKeyboard.test.cjs +0 -88
  121. package/dist/__tests__/useKeyboard.test.d.ts +0 -1
  122. package/dist/__tests__/useKeyboard.test.mjs +0 -56
  123. package/dist/__tests__/useNodeDistribution.test.cjs +0 -643
  124. package/dist/__tests__/useNodeDistribution.test.d.ts +0 -1
  125. package/dist/__tests__/useNodeDistribution.test.mjs +0 -297
  126. package/dist/__tests__/useNodes.test.cjs +0 -150
  127. package/dist/__tests__/useNodes.test.d.ts +0 -1
  128. package/dist/__tests__/useNodes.test.mjs +0 -80
  129. package/dist/__tests__/useSelection.test.cjs +0 -112
  130. package/dist/__tests__/useSelection.test.d.ts +0 -1
  131. package/dist/__tests__/useSelection.test.mjs +0 -76
  132. package/dist/__tests__/useViewport.test.cjs +0 -171
  133. package/dist/__tests__/useViewport.test.d.ts +0 -1
  134. package/dist/__tests__/useViewport.test.mjs +0 -82
  135. package/dist/__tests__/utils/ssr.cjs +0 -124
  136. package/dist/__tests__/utils/ssr.d.ts +0 -33
  137. package/dist/__tests__/utils/ssr.mjs +0 -129
  138. package/dist/__tests__/validation.test.cjs +0 -95
  139. package/dist/__tests__/validation.test.d.ts +0 -1
  140. package/dist/__tests__/validation.test.mjs +0 -36
  141. package/dist/__tests__/viewport-types.test.cjs +0 -324
  142. package/dist/__tests__/viewport-types.test.d.ts +0 -1
  143. package/dist/__tests__/viewport-types.test.mjs +0 -207
@@ -1,76 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { ref } from "vue";
3
- import { useSelection } from "../core/useSelection.mjs";
4
- const node = (id, x, y, w = 100, h = 50) => ({
5
- id,
6
- type: "default",
7
- position: { x, y },
8
- data: {},
9
- width: w,
10
- height: h,
11
- selected: false
12
- });
13
- const edge = (id, source, target) => ({
14
- id,
15
- source,
16
- target,
17
- type: "bezier",
18
- selected: false
19
- });
20
- describe("flow/core/useSelection", () => {
21
- it("should start and update selection rect", () => {
22
- const nodes = ref([node("1", 0, 0), node("2", 200, 100)]);
23
- const edges = ref([]);
24
- const s = useSelection({ nodes, edges });
25
- s.startSelection(10, 20);
26
- expect(s.isSelecting.value).toBe(true);
27
- expect(s.selectionRect.value).toEqual({ x: 10, y: 20, width: 0, height: 0 });
28
- s.updateSelection(50, 60);
29
- expect(s.selectionRect.value).toEqual({ x: 10, y: 20, width: 40, height: 40 });
30
- });
31
- it("should select nodes inside rect on updateSelection", () => {
32
- const nodes = ref([node("1", 20, 20, 50, 50), node("2", 100, 100, 50, 50)]);
33
- const edges = ref([]);
34
- const s = useSelection({ nodes, edges });
35
- s.startSelection(0, 0);
36
- s.updateSelection(80, 80);
37
- expect(nodes.value.find((n) => n.id === "1")?.selected).toBe(true);
38
- expect(nodes.value.find((n) => n.id === "2")?.selected).toBe(false);
39
- });
40
- it("should end selection and clear rect", () => {
41
- const nodes = ref([node("1", 0, 0)]);
42
- const edges = ref([]);
43
- const s = useSelection({ nodes, edges });
44
- s.startSelection(0, 0);
45
- s.updateSelection(10, 10);
46
- s.endSelection();
47
- expect(s.isSelecting.value).toBe(false);
48
- expect(s.selectionRect.value).toBeNull();
49
- });
50
- it("should clearSelection clear nodes and edges selected", () => {
51
- const nodes = ref([{ ...node("1", 0, 0), selected: true }]);
52
- const edges = ref([{ ...edge("e1", "1", "2"), selected: true }]);
53
- const s = useSelection({ nodes, edges });
54
- s.clearSelection();
55
- expect(nodes.value[0].selected).toBeFalsy();
56
- expect(edges.value[0].selected).toBeFalsy();
57
- });
58
- it("should call onSelectionChange on endSelection", () => {
59
- const nodes = ref([node("1", 20, 20, 50, 50)]);
60
- const edges = ref([]);
61
- let captured = null;
62
- const s = useSelection({
63
- nodes,
64
- edges,
65
- onSelectionChange: (selectedNodes, selectedEdges) => {
66
- captured = { nodes: selectedNodes, edges: selectedEdges };
67
- }
68
- });
69
- s.startSelection(0, 0);
70
- s.updateSelection(80, 80);
71
- s.endSelection();
72
- expect(captured).not.toBeNull();
73
- expect(Array.isArray(captured.nodes)).toBe(true);
74
- expect(Array.isArray(captured.edges)).toBe(true);
75
- });
76
- });
@@ -1,171 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _vue = require("vue");
5
- var _useViewport = require("../core/useViewport.cjs");
6
- (0, _vitest.describe)("flow/core/useViewport", () => {
7
- (0, _vitest.it)("should set viewport and clamp zoom to min/max", () => {
8
- const transform = (0, _vue.ref)({
9
- x: 0,
10
- y: 0,
11
- zoom: 1
12
- });
13
- const v = (0, _useViewport.useViewport)(transform, {
14
- minZoom: 0.2,
15
- maxZoom: 4
16
- });
17
- v.setViewport(10, 20, 2);
18
- (0, _vitest.expect)(transform.value).toEqual({
19
- x: 10,
20
- y: 20,
21
- zoom: 2
22
- });
23
- v.setViewport(0, 0, 0.1);
24
- (0, _vitest.expect)(transform.value.zoom).toBe(0.2);
25
- v.setViewport(0, 0, 10);
26
- (0, _vitest.expect)(transform.value.zoom).toBe(4);
27
- });
28
- (0, _vitest.it)("should zoom in and out", () => {
29
- const transform = (0, _vue.ref)({
30
- x: 0,
31
- y: 0,
32
- zoom: 1
33
- });
34
- const v = (0, _useViewport.useViewport)(transform, {
35
- minZoom: 0.1,
36
- maxZoom: 5
37
- });
38
- v.zoomIn(2);
39
- (0, _vitest.expect)(transform.value.zoom).toBe(2);
40
- v.zoomOut(2);
41
- (0, _vitest.expect)(transform.value.zoom).toBe(1);
42
- });
43
- (0, _vitest.it)("should pan", () => {
44
- const transform = (0, _vue.ref)({
45
- x: 0,
46
- y: 0,
47
- zoom: 1
48
- });
49
- const v = (0, _useViewport.useViewport)(transform);
50
- v.pan(50, 30);
51
- (0, _vitest.expect)(transform.value.x).toBe(50);
52
- (0, _vitest.expect)(transform.value.y).toBe(30);
53
- });
54
- (0, _vitest.it)("should panTo", () => {
55
- const transform = (0, _vue.ref)({
56
- x: 0,
57
- y: 0,
58
- zoom: 1
59
- });
60
- const v = (0, _useViewport.useViewport)(transform);
61
- v.panTo(100, 200);
62
- (0, _vitest.expect)(transform.value.x).toBe(100);
63
- (0, _vitest.expect)(transform.value.y).toBe(200);
64
- });
65
- (0, _vitest.it)("should fitView to contain nodes", () => {
66
- const transform = (0, _vue.ref)({
67
- x: 0,
68
- y: 0,
69
- zoom: 1
70
- });
71
- const v = (0, _useViewport.useViewport)(transform, {
72
- minZoom: 0.1,
73
- maxZoom: 5
74
- });
75
- const nodes = [{
76
- position: {
77
- x: 0,
78
- y: 0
79
- },
80
- width: 100,
81
- height: 50
82
- }, {
83
- position: {
84
- x: 200,
85
- y: 100
86
- },
87
- width: 100,
88
- height: 50
89
- }];
90
- v.fitView({
91
- width: 400,
92
- height: 300
93
- }, nodes, {
94
- padding: 20
95
- });
96
- (0, _vitest.expect)(transform.value.zoom).toBeLessThanOrEqual(1);
97
- (0, _vitest.expect)(typeof transform.value.x).toBe("number");
98
- (0, _vitest.expect)(typeof transform.value.y).toBe("number");
99
- });
100
- (0, _vitest.it)("should not fitView when nodes empty", () => {
101
- const transform = (0, _vue.ref)({
102
- x: 50,
103
- y: 50,
104
- zoom: 1
105
- });
106
- const v = (0, _useViewport.useViewport)(transform);
107
- v.fitView({
108
- width: 400,
109
- height: 300
110
- }, [], {
111
- padding: 20
112
- });
113
- (0, _vitest.expect)(transform.value).toEqual({
114
- x: 50,
115
- y: 50,
116
- zoom: 1
117
- });
118
- });
119
- (0, _vitest.it)("screenToCanvas and canvasToScreen should be inverse", () => {
120
- const transform = (0, _vue.ref)({
121
- x: 100,
122
- y: 50,
123
- zoom: 2
124
- });
125
- const v = (0, _useViewport.useViewport)(transform);
126
- const screen = {
127
- x: 300,
128
- y: 250
129
- };
130
- const canvas = v.screenToCanvas(screen.x, screen.y);
131
- const back = v.canvasToScreen(canvas.x, canvas.y);
132
- (0, _vitest.expect)(back.x).toBe(screen.x);
133
- (0, _vitest.expect)(back.y).toBe(screen.y);
134
- });
135
- (0, _vitest.it)("isNodeVisible should return true when node in view", () => {
136
- const transform = (0, _vue.ref)({
137
- x: 0,
138
- y: 0,
139
- zoom: 1
140
- });
141
- const v = (0, _useViewport.useViewport)(transform);
142
- const visible = v.isNodeVisible({
143
- x: 50,
144
- y: 50,
145
- width: 100,
146
- height: 50
147
- }, {
148
- width: 800,
149
- height: 600
150
- });
151
- (0, _vitest.expect)(visible).toBe(true);
152
- });
153
- (0, _vitest.it)("isNodeVisible should return false when node outside view", () => {
154
- const transform = (0, _vue.ref)({
155
- x: -2e3,
156
- y: 0,
157
- zoom: 1
158
- });
159
- const v = (0, _useViewport.useViewport)(transform);
160
- const visible = v.isNodeVisible({
161
- x: 50,
162
- y: 50,
163
- width: 100,
164
- height: 50
165
- }, {
166
- width: 800,
167
- height: 600
168
- });
169
- (0, _vitest.expect)(visible).toBe(false);
170
- });
171
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,82 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { ref } from "vue";
3
- import { useViewport } from "../core/useViewport.mjs";
4
- describe("flow/core/useViewport", () => {
5
- it("should set viewport and clamp zoom to min/max", () => {
6
- const transform = ref({ x: 0, y: 0, zoom: 1 });
7
- const v = useViewport(transform, { minZoom: 0.2, maxZoom: 4 });
8
- v.setViewport(10, 20, 2);
9
- expect(transform.value).toEqual({ x: 10, y: 20, zoom: 2 });
10
- v.setViewport(0, 0, 0.1);
11
- expect(transform.value.zoom).toBe(0.2);
12
- v.setViewport(0, 0, 10);
13
- expect(transform.value.zoom).toBe(4);
14
- });
15
- it("should zoom in and out", () => {
16
- const transform = ref({ x: 0, y: 0, zoom: 1 });
17
- const v = useViewport(transform, { minZoom: 0.1, maxZoom: 5 });
18
- v.zoomIn(2);
19
- expect(transform.value.zoom).toBe(2);
20
- v.zoomOut(2);
21
- expect(transform.value.zoom).toBe(1);
22
- });
23
- it("should pan", () => {
24
- const transform = ref({ x: 0, y: 0, zoom: 1 });
25
- const v = useViewport(transform);
26
- v.pan(50, 30);
27
- expect(transform.value.x).toBe(50);
28
- expect(transform.value.y).toBe(30);
29
- });
30
- it("should panTo", () => {
31
- const transform = ref({ x: 0, y: 0, zoom: 1 });
32
- const v = useViewport(transform);
33
- v.panTo(100, 200);
34
- expect(transform.value.x).toBe(100);
35
- expect(transform.value.y).toBe(200);
36
- });
37
- it("should fitView to contain nodes", () => {
38
- const transform = ref({ x: 0, y: 0, zoom: 1 });
39
- const v = useViewport(transform, { minZoom: 0.1, maxZoom: 5 });
40
- const nodes = [
41
- { position: { x: 0, y: 0 }, width: 100, height: 50 },
42
- { position: { x: 200, y: 100 }, width: 100, height: 50 }
43
- ];
44
- v.fitView({ width: 400, height: 300 }, nodes, { padding: 20 });
45
- expect(transform.value.zoom).toBeLessThanOrEqual(1);
46
- expect(typeof transform.value.x).toBe("number");
47
- expect(typeof transform.value.y).toBe("number");
48
- });
49
- it("should not fitView when nodes empty", () => {
50
- const transform = ref({ x: 50, y: 50, zoom: 1 });
51
- const v = useViewport(transform);
52
- v.fitView({ width: 400, height: 300 }, [], { padding: 20 });
53
- expect(transform.value).toEqual({ x: 50, y: 50, zoom: 1 });
54
- });
55
- it("screenToCanvas and canvasToScreen should be inverse", () => {
56
- const transform = ref({ x: 100, y: 50, zoom: 2 });
57
- const v = useViewport(transform);
58
- const screen = { x: 300, y: 250 };
59
- const canvas = v.screenToCanvas(screen.x, screen.y);
60
- const back = v.canvasToScreen(canvas.x, canvas.y);
61
- expect(back.x).toBe(screen.x);
62
- expect(back.y).toBe(screen.y);
63
- });
64
- it("isNodeVisible should return true when node in view", () => {
65
- const transform = ref({ x: 0, y: 0, zoom: 1 });
66
- const v = useViewport(transform);
67
- const visible = v.isNodeVisible(
68
- { x: 50, y: 50, width: 100, height: 50 },
69
- { width: 800, height: 600 }
70
- );
71
- expect(visible).toBe(true);
72
- });
73
- it("isNodeVisible should return false when node outside view", () => {
74
- const transform = ref({ x: -2e3, y: 0, zoom: 1 });
75
- const v = useViewport(transform);
76
- const visible = v.isNodeVisible(
77
- { x: 50, y: 50, width: 100, height: 50 },
78
- { width: 800, height: 600 }
79
- );
80
- expect(visible).toBe(false);
81
- });
82
- });
@@ -1,124 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.expectSSRContains = expectSSRContains;
7
- exports.expectSSRHasClass = expectSSRHasClass;
8
- exports.mockSSREnvironment = mockSSREnvironment;
9
- exports.normalizeHtml = normalizeHtml;
10
- exports.renderSSR = renderSSR;
11
- exports.testHydration = testHydration;
12
- var _vue = require("vue");
13
- var _serverRenderer = require("vue/server-renderer");
14
- async function renderSSR(component, props = {}, slots = {}) {
15
- const app = (0, _vue.createSSRApp)({
16
- render() {
17
- return (0, _vue.h)(component, props, slots);
18
- }
19
- });
20
- return await (0, _serverRenderer.renderToString)(app);
21
- }
22
- function expectSSRContains(html, text) {
23
- if (!html.includes(text)) {
24
- throw new Error(`Expected SSR output to contain "${text}", but got:
25
- ${html}`);
26
- }
27
- }
28
- function expectSSRHasClass(html, className) {
29
- const classRegex = new RegExp(`class="[^"]*${className}[^"]*"`);
30
- if (!classRegex.test(html)) {
31
- throw new Error(`Expected SSR output to have class "${className}", but got:
32
- ${html}`);
33
- }
34
- }
35
- function mockSSREnvironment() {
36
- const originalWindow = global.window;
37
- const originalDocument = global.document;
38
- delete global.window;
39
- delete global.document;
40
- return () => {
41
- ;
42
- global.window = originalWindow;
43
- global.document = originalDocument;
44
- };
45
- }
46
- function normalizeHtml(html) {
47
- return html.replace(/<!--[\s\S]*?-->/g, "").replace(/\s+/g, " ").replace(/>\s+</g, "><").replace(/<(\/?)([a-z0-9-]+)([^>]*?)(\/?)>/gi, (match, close, tag, attrs, selfClosing) => {
48
- tag = tag.toLowerCase();
49
- if (close) {
50
- return `</${tag}>`;
51
- }
52
- const attrRegex = /([^\s>=/]+)(?:="([^"]*)")?/gi;
53
- const foundAttrs = [];
54
- let m;
55
- while ((m = attrRegex.exec(attrs)) !== null) {
56
- const name = m[1].toLowerCase();
57
- let value = m[2] || "";
58
- if (name.startsWith("data-v-")) continue;
59
- value = value.replace(/\s+/g, " ").trim();
60
- if (value === "" || value === "false") continue;
61
- if (name === "style") {
62
- value = value.split(";").map(s => s.trim()).filter(Boolean).map(s => {
63
- const parts = s.split(":");
64
- if (parts.length < 2) return null;
65
- const prop = parts[0].trim().toLowerCase();
66
- let val = parts.slice(1).join(":").trim();
67
- val = val.replace(/^0(?:px|em|rem|%)$/, "0");
68
- if (val === "rgba(0,0,0,0)" || val === "rgba(0, 0, 0, 0)") val = "transparent";
69
- if (prop.startsWith("-webkit-") || prop.startsWith("-ms-") || prop.startsWith("-moz-") || prop.startsWith("webkit-") || prop.startsWith("ms-") || prop.startsWith("moz-") || prop === "mstransform") {
70
- return null;
71
- }
72
- return `${prop}:${val}`;
73
- }).filter(Boolean).sort().join(";");
74
- }
75
- if (name === "class") {
76
- value = value.split(" ").filter(c => !/-(enter|leave)-(from|active|to)$/.test(c)).sort().join(" ");
77
- if (!value) continue;
78
- }
79
- if (tag === "path" && name === "d") {
80
- value = value.replace(/([A-Z])/gi, " $1 ").replace(/,/g, " ").replace(/\s+/g, " ").trim();
81
- }
82
- const isAriaValue = ["aria-valuenow", "aria-valuemin", "aria-valuemax"].includes(name);
83
- if (name === "id" || name === "for" || name.startsWith("aria-") && !isAriaValue) {
84
- value = "__ID__";
85
- }
86
- if (name === "xmlns" || name.startsWith("xmlns:")) continue;
87
- if (value === "true") {
88
- value = "";
89
- }
90
- foundAttrs.push(`${name}${value ? `="${value}"` : ""}`);
91
- }
92
- foundAttrs.sort();
93
- const sortedAttrs = foundAttrs.join(" ");
94
- const voidElements = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"];
95
- const isVoid = voidElements.includes(tag);
96
- const normalizedTag = `<${tag}${sortedAttrs ? " " + sortedAttrs : ""}>`;
97
- return isVoid ? normalizedTag : selfClosing ? `${normalizedTag}</${tag}>` : normalizedTag;
98
- }).replace(/<textarea([^>]*)>[\s\S]*?<\/textarea>/gi, "<textarea$1>__TEXTAREA_CONTENT__</textarea>").trim();
99
- }
100
- async function testHydration(component, props = {}, slots = {}) {
101
- const ssrHtml = await renderSSR(component, props, slots);
102
- const {
103
- mount
104
- } = await Promise.resolve().then(() => require("@vue/test-utils"));
105
- const wrapper = mount(component, {
106
- props,
107
- slots,
108
- global: {
109
- stubs: {
110
- transition: false,
111
- "transition-group": false
112
- }
113
- }
114
- });
115
- const csrHtml = wrapper.html();
116
- const ssrNormalized = normalizeHtml(ssrHtml);
117
- const csrNormalized = normalizeHtml(csrHtml);
118
- const isMatch = ssrNormalized === csrNormalized;
119
- return {
120
- ssrHtml: ssrNormalized,
121
- csrHtml: csrNormalized,
122
- isMatch
123
- };
124
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * Flow Package SSR 测试工具函数
3
- * @description 用于测试 Flow 组件在 SSR 环境下的行为
4
- */
5
- import { type Component } from 'vue';
6
- /**
7
- * 渲染组件为 HTML 字符串(服务端)
8
- */
9
- export declare function renderSSR(component: Component, props?: Record<string, unknown>, slots?: Record<string, unknown>): Promise<string>;
10
- /**
11
- * 检查 SSR 渲染结果中是否包含特定文本
12
- */
13
- export declare function expectSSRContains(html: string, text: string): void;
14
- /**
15
- * 检查 SSR 渲染结果是否包含特定 class
16
- */
17
- export declare function expectSSRHasClass(html: string, className: string): void;
18
- /**
19
- * 模拟 SSR 环境
20
- */
21
- export declare function mockSSREnvironment(): () => void;
22
- /**
23
- * HTML 标准化,用于比较 SSR 和 CSR 结果
24
- */
25
- export declare function normalizeHtml(html: string): string;
26
- /**
27
- * Hydration 测试辅助函数
28
- */
29
- export declare function testHydration(component: Component, props?: Record<string, unknown>, slots?: Record<string, unknown>): Promise<{
30
- ssrHtml: string;
31
- csrHtml: string;
32
- isMatch: boolean;
33
- }>;
@@ -1,129 +0,0 @@
1
- import { createSSRApp, h } from "vue";
2
- import { renderToString } from "vue/server-renderer";
3
- export async function renderSSR(component, props = {}, slots = {}) {
4
- const app = createSSRApp({
5
- render() {
6
- return h(component, props, slots);
7
- }
8
- });
9
- return await renderToString(app);
10
- }
11
- export function expectSSRContains(html, text) {
12
- if (!html.includes(text)) {
13
- throw new Error(`Expected SSR output to contain "${text}", but got:
14
- ${html}`);
15
- }
16
- }
17
- export function expectSSRHasClass(html, className) {
18
- const classRegex = new RegExp(`class="[^"]*${className}[^"]*"`);
19
- if (!classRegex.test(html)) {
20
- throw new Error(`Expected SSR output to have class "${className}", but got:
21
- ${html}`);
22
- }
23
- }
24
- export function mockSSREnvironment() {
25
- const originalWindow = global.window;
26
- const originalDocument = global.document;
27
- delete global.window;
28
- delete global.document;
29
- return () => {
30
- ;
31
- global.window = originalWindow;
32
- global.document = originalDocument;
33
- };
34
- }
35
- export function normalizeHtml(html) {
36
- return html.replace(/<!--[\s\S]*?-->/g, "").replace(/\s+/g, " ").replace(/>\s+</g, "><").replace(/<(\/?)([a-z0-9-]+)([^>]*?)(\/?)>/gi, (match, close, tag, attrs, selfClosing) => {
37
- tag = tag.toLowerCase();
38
- if (close) {
39
- return `</${tag}>`;
40
- }
41
- const attrRegex = /([^\s>=/]+)(?:="([^"]*)")?/gi;
42
- const foundAttrs = [];
43
- let m;
44
- while ((m = attrRegex.exec(attrs)) !== null) {
45
- const name = m[1].toLowerCase();
46
- let value = m[2] || "";
47
- if (name.startsWith("data-v-")) continue;
48
- value = value.replace(/\s+/g, " ").trim();
49
- if (value === "" || value === "false") continue;
50
- if (name === "style") {
51
- value = value.split(";").map((s) => s.trim()).filter(Boolean).map((s) => {
52
- const parts = s.split(":");
53
- if (parts.length < 2) return null;
54
- const prop = parts[0].trim().toLowerCase();
55
- let val = parts.slice(1).join(":").trim();
56
- val = val.replace(/^0(?:px|em|rem|%)$/, "0");
57
- if (val === "rgba(0,0,0,0)" || val === "rgba(0, 0, 0, 0)") val = "transparent";
58
- if (prop.startsWith("-webkit-") || prop.startsWith("-ms-") || prop.startsWith("-moz-") || prop.startsWith("webkit-") || prop.startsWith("ms-") || prop.startsWith("moz-") || prop === "mstransform") {
59
- return null;
60
- }
61
- return `${prop}:${val}`;
62
- }).filter(Boolean).sort().join(";");
63
- }
64
- if (name === "class") {
65
- value = value.split(" ").filter((c) => !/-(enter|leave)-(from|active|to)$/.test(c)).sort().join(" ");
66
- if (!value) continue;
67
- }
68
- if (tag === "path" && name === "d") {
69
- value = value.replace(/([A-Z])/gi, " $1 ").replace(/,/g, " ").replace(/\s+/g, " ").trim();
70
- }
71
- const isAriaValue = ["aria-valuenow", "aria-valuemin", "aria-valuemax"].includes(name);
72
- if (name === "id" || name === "for" || name.startsWith("aria-") && !isAriaValue) {
73
- value = "__ID__";
74
- }
75
- if (name === "xmlns" || name.startsWith("xmlns:")) continue;
76
- if (value === "true") {
77
- value = "";
78
- }
79
- foundAttrs.push(`${name}${value ? `="${value}"` : ""}`);
80
- }
81
- foundAttrs.sort();
82
- const sortedAttrs = foundAttrs.join(" ");
83
- const voidElements = [
84
- "area",
85
- "base",
86
- "br",
87
- "col",
88
- "embed",
89
- "hr",
90
- "img",
91
- "input",
92
- "link",
93
- "meta",
94
- "param",
95
- "source",
96
- "track",
97
- "wbr"
98
- ];
99
- const isVoid = voidElements.includes(tag);
100
- const normalizedTag = `<${tag}${sortedAttrs ? " " + sortedAttrs : ""}>`;
101
- return isVoid ? normalizedTag : selfClosing ? `${normalizedTag}</${tag}>` : normalizedTag;
102
- }).replace(
103
- /<textarea([^>]*)>[\s\S]*?<\/textarea>/gi,
104
- "<textarea$1>__TEXTAREA_CONTENT__</textarea>"
105
- ).trim();
106
- }
107
- export async function testHydration(component, props = {}, slots = {}) {
108
- const ssrHtml = await renderSSR(component, props, slots);
109
- const { mount } = await import("@vue/test-utils");
110
- const wrapper = mount(component, {
111
- props,
112
- slots,
113
- global: {
114
- stubs: {
115
- transition: false,
116
- "transition-group": false
117
- }
118
- }
119
- });
120
- const csrHtml = wrapper.html();
121
- const ssrNormalized = normalizeHtml(ssrHtml);
122
- const csrNormalized = normalizeHtml(csrHtml);
123
- const isMatch = ssrNormalized === csrNormalized;
124
- return {
125
- ssrHtml: ssrNormalized,
126
- csrHtml: csrNormalized,
127
- isMatch
128
- };
129
- }