@pooder/kit 6.2.1 → 6.2.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/.test-dist/src/extensions/dieline/renderBuilder.js +19 -2
- package/.test-dist/src/extensions/image/ImageTool.js +46 -348
- package/.test-dist/src/extensions/image/sessionOverlay.js +148 -0
- package/.test-dist/src/extensions/ruler/RulerTool.js +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +2 -5
- package/dist/index.d.ts +2 -5
- package/dist/index.js +1104 -1252
- package/dist/index.mjs +1103 -1251
- package/package.json +1 -1
- package/src/extensions/dieline/renderBuilder.ts +26 -4
- package/src/extensions/image/ImageTool.ts +57 -412
- package/src/extensions/image/sessionOverlay.ts +206 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { Pattern } from "fabric";
|
|
2
|
+
import type { RenderObjectSpec } from "../../services";
|
|
3
|
+
import type {
|
|
4
|
+
SceneGeometrySnapshot,
|
|
5
|
+
SceneLayoutSnapshot,
|
|
6
|
+
SceneRect,
|
|
7
|
+
} from "../../shared/scene/sceneLayoutModel";
|
|
8
|
+
import { generateDielinePath } from "../geometry";
|
|
9
|
+
|
|
10
|
+
export interface ImageSessionOverlayVisualConfig {
|
|
11
|
+
strokeColor: string;
|
|
12
|
+
strokeWidth: number;
|
|
13
|
+
strokeStyle: "solid" | "dashed" | "hidden";
|
|
14
|
+
dashLength: number;
|
|
15
|
+
innerBackground: string;
|
|
16
|
+
outerBackground: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ImageSessionOverlayViewport {
|
|
20
|
+
left: number;
|
|
21
|
+
top: number;
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface BuiltinShapeOverlayPaths {
|
|
27
|
+
hatchPathData: string;
|
|
28
|
+
shapePathData: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const EPSILON = 0.0001;
|
|
32
|
+
const SHAPE_OUTLINE_COLOR = "rgba(255, 0, 0, 0.9)";
|
|
33
|
+
const DEFAULT_HATCH_FILL = "rgba(255, 0, 0, 0.22)";
|
|
34
|
+
|
|
35
|
+
function buildRectPath(width: number, height: number): string {
|
|
36
|
+
return `M 0 0 L ${width} 0 L ${width} ${height} L 0 ${height} Z`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function buildViewportMaskPath(
|
|
40
|
+
viewport: ImageSessionOverlayViewport,
|
|
41
|
+
cutRect: SceneRect,
|
|
42
|
+
): string {
|
|
43
|
+
const cutLeft = cutRect.left - viewport.left;
|
|
44
|
+
const cutTop = cutRect.top - viewport.top;
|
|
45
|
+
return [
|
|
46
|
+
buildRectPath(viewport.width, viewport.height),
|
|
47
|
+
`M ${cutLeft} ${cutTop} L ${cutLeft + cutRect.width} ${cutTop} L ${
|
|
48
|
+
cutLeft + cutRect.width
|
|
49
|
+
} ${cutTop + cutRect.height} L ${cutLeft} ${cutTop + cutRect.height} Z`,
|
|
50
|
+
].join(" ");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function resolveCutShapeRadiusPx(
|
|
54
|
+
geometry: SceneGeometrySnapshot,
|
|
55
|
+
cutRect: SceneRect,
|
|
56
|
+
): number {
|
|
57
|
+
const visualRadius = Number.isFinite(geometry.radius)
|
|
58
|
+
? Math.max(0, geometry.radius)
|
|
59
|
+
: 0;
|
|
60
|
+
const visualOffset = Number.isFinite(geometry.offset) ? geometry.offset : 0;
|
|
61
|
+
const rawCutRadius =
|
|
62
|
+
visualRadius === 0 ? 0 : Math.max(0, visualRadius + visualOffset);
|
|
63
|
+
const maxRadius = Math.max(0, Math.min(cutRect.width, cutRect.height) / 2);
|
|
64
|
+
return Math.max(0, Math.min(maxRadius, rawCutRadius));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function buildBuiltinShapeOverlayPaths(
|
|
68
|
+
cutRect: SceneRect,
|
|
69
|
+
geometry: SceneGeometrySnapshot | null,
|
|
70
|
+
): BuiltinShapeOverlayPaths | null {
|
|
71
|
+
if (!geometry || geometry.shape === "custom") {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const radius = resolveCutShapeRadiusPx(geometry, cutRect);
|
|
76
|
+
if (geometry.shape === "rect" && radius <= EPSILON) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const shapePathData = generateDielinePath({
|
|
81
|
+
shape: geometry.shape,
|
|
82
|
+
shapeStyle: geometry.shapeStyle,
|
|
83
|
+
width: Math.max(1, cutRect.width),
|
|
84
|
+
height: Math.max(1, cutRect.height),
|
|
85
|
+
radius,
|
|
86
|
+
x: cutRect.width / 2,
|
|
87
|
+
y: cutRect.height / 2,
|
|
88
|
+
features: [],
|
|
89
|
+
canvasWidth: Math.max(1, cutRect.width),
|
|
90
|
+
canvasHeight: Math.max(1, cutRect.height),
|
|
91
|
+
});
|
|
92
|
+
if (!shapePathData) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
shapePathData,
|
|
98
|
+
hatchPathData: `${buildRectPath(cutRect.width, cutRect.height)} ${shapePathData}`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function buildImageSessionOverlaySpecs(args: {
|
|
103
|
+
viewport: ImageSessionOverlayViewport;
|
|
104
|
+
layout: SceneLayoutSnapshot;
|
|
105
|
+
geometry: SceneGeometrySnapshot | null;
|
|
106
|
+
visual: ImageSessionOverlayVisualConfig;
|
|
107
|
+
hatchPattern?: Pattern;
|
|
108
|
+
}): RenderObjectSpec[] {
|
|
109
|
+
const { viewport, layout, geometry, visual, hatchPattern } = args;
|
|
110
|
+
const cutRect = layout.cutRect;
|
|
111
|
+
const specs: RenderObjectSpec[] = [];
|
|
112
|
+
|
|
113
|
+
specs.push({
|
|
114
|
+
id: "image.cropMask.rect",
|
|
115
|
+
type: "path",
|
|
116
|
+
space: "screen",
|
|
117
|
+
data: { id: "image.cropMask.rect", zIndex: 1 },
|
|
118
|
+
props: {
|
|
119
|
+
pathData: buildViewportMaskPath(viewport, cutRect),
|
|
120
|
+
left: viewport.left,
|
|
121
|
+
top: viewport.top,
|
|
122
|
+
originX: "left",
|
|
123
|
+
originY: "top",
|
|
124
|
+
fill: visual.outerBackground,
|
|
125
|
+
stroke: null,
|
|
126
|
+
fillRule: "evenodd",
|
|
127
|
+
selectable: false,
|
|
128
|
+
evented: false,
|
|
129
|
+
excludeFromExport: true,
|
|
130
|
+
objectCaching: false,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const shapeOverlay = buildBuiltinShapeOverlayPaths(cutRect, geometry);
|
|
135
|
+
if (shapeOverlay) {
|
|
136
|
+
specs.push({
|
|
137
|
+
id: "image.cropShapeHatch",
|
|
138
|
+
type: "path",
|
|
139
|
+
space: "screen",
|
|
140
|
+
data: { id: "image.cropShapeHatch", zIndex: 5 },
|
|
141
|
+
props: {
|
|
142
|
+
pathData: shapeOverlay.hatchPathData,
|
|
143
|
+
left: cutRect.left,
|
|
144
|
+
top: cutRect.top,
|
|
145
|
+
originX: "left",
|
|
146
|
+
originY: "top",
|
|
147
|
+
fill: hatchPattern || DEFAULT_HATCH_FILL,
|
|
148
|
+
opacity: hatchPattern ? 1 : 0.8,
|
|
149
|
+
stroke: null,
|
|
150
|
+
fillRule: "evenodd",
|
|
151
|
+
selectable: false,
|
|
152
|
+
evented: false,
|
|
153
|
+
excludeFromExport: true,
|
|
154
|
+
objectCaching: false,
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
specs.push({
|
|
158
|
+
id: "image.cropShapeOutline",
|
|
159
|
+
type: "path",
|
|
160
|
+
space: "screen",
|
|
161
|
+
data: { id: "image.cropShapeOutline", zIndex: 6 },
|
|
162
|
+
props: {
|
|
163
|
+
pathData: shapeOverlay.shapePathData,
|
|
164
|
+
left: cutRect.left,
|
|
165
|
+
top: cutRect.top,
|
|
166
|
+
originX: "left",
|
|
167
|
+
originY: "top",
|
|
168
|
+
fill: "transparent",
|
|
169
|
+
stroke: SHAPE_OUTLINE_COLOR,
|
|
170
|
+
strokeWidth: 1,
|
|
171
|
+
selectable: false,
|
|
172
|
+
evented: false,
|
|
173
|
+
excludeFromExport: true,
|
|
174
|
+
objectCaching: false,
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
specs.push({
|
|
180
|
+
id: "image.cropFrame",
|
|
181
|
+
type: "rect",
|
|
182
|
+
space: "screen",
|
|
183
|
+
data: { id: "image.cropFrame", zIndex: 7 },
|
|
184
|
+
props: {
|
|
185
|
+
left: cutRect.left,
|
|
186
|
+
top: cutRect.top,
|
|
187
|
+
width: cutRect.width,
|
|
188
|
+
height: cutRect.height,
|
|
189
|
+
originX: "left",
|
|
190
|
+
originY: "top",
|
|
191
|
+
fill: visual.innerBackground,
|
|
192
|
+
stroke:
|
|
193
|
+
visual.strokeStyle === "hidden" ? "rgba(0,0,0,0)" : visual.strokeColor,
|
|
194
|
+
strokeWidth: visual.strokeStyle === "hidden" ? 0 : visual.strokeWidth,
|
|
195
|
+
strokeDashArray:
|
|
196
|
+
visual.strokeStyle === "dashed"
|
|
197
|
+
? [visual.dashLength, visual.dashLength]
|
|
198
|
+
: undefined,
|
|
199
|
+
selectable: false,
|
|
200
|
+
evented: false,
|
|
201
|
+
excludeFromExport: true,
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
return specs;
|
|
206
|
+
}
|