@hprint/plugins 0.0.1 → 0.0.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/dist/index.js +76 -76
- package/dist/index.mjs +7397 -7275
- package/dist/src/plugins/BarCodePlugin.d.ts +10 -0
- package/dist/src/plugins/BarCodePlugin.d.ts.map +1 -1
- package/dist/src/plugins/CreateElementPlugin.d.ts +1 -0
- package/dist/src/plugins/CreateElementPlugin.d.ts.map +1 -1
- package/dist/src/plugins/UnitPlugin.d.ts +1 -1
- package/dist/src/plugins/UnitPlugin.d.ts.map +1 -1
- package/dist/src/utils/units.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/plugins/BarCodePlugin.ts +69 -3
- package/src/plugins/CreateElementPlugin.ts +182 -16
- package/src/plugins/UnitPlugin.ts +27 -5
- package/src/utils/units.ts +10 -0
|
@@ -44,6 +44,11 @@ declare class BarCodePlugin implements IPluginTempl {
|
|
|
44
44
|
width: number;
|
|
45
45
|
height: number;
|
|
46
46
|
boxWidth: number;
|
|
47
|
+
fontWeight: string;
|
|
48
|
+
fontStyle: string;
|
|
49
|
+
underline: boolean;
|
|
50
|
+
linethrough: boolean;
|
|
51
|
+
isShowText: boolean;
|
|
47
52
|
};
|
|
48
53
|
private _mergeBarcodeOptions;
|
|
49
54
|
private _setImageScale;
|
|
@@ -63,6 +68,11 @@ declare class BarCodePlugin implements IPluginTempl {
|
|
|
63
68
|
displayValue?: boolean;
|
|
64
69
|
margin?: number;
|
|
65
70
|
width?: number;
|
|
71
|
+
fontWeight?: string;
|
|
72
|
+
fontStyle?: string;
|
|
73
|
+
underline?: boolean;
|
|
74
|
+
linethrough?: boolean;
|
|
75
|
+
isShowText?: boolean;
|
|
66
76
|
}, dpi?: number): Promise<fabric.Image>;
|
|
67
77
|
setBarcode(option: any): Promise<void>;
|
|
68
78
|
getBarcodeTypes(): CodeType[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BarCodePlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/BarCodePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI7D,KAAK,OAAO,GAAG,IAAI,CACf,aAAa,EACb,YAAY,GAAG,YAAY,GAAG,iBAAiB,CAClD,CAAC;AAEF,OAAO,QAAQ,cAAc,CAAC;IAE1B,UAAU,OAAQ,SAAQ,OAAO;KAAI;CACxC;AAKD,aAAK,QAAQ;IACT,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,UAAU,eAAe;CAC5B;AAED,cAAM,aAAc,YAAW,YAAY;IAI5B,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IAJ1B,MAAM,CAAC,UAAU,SAAmB;IACpC,MAAM,CAAC,IAAI,WAAmD;gBAEnD,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,MAAM,EAAE,OAAO;IAGpB,aAAa,CAAC,MAAM,EAAE,GAAG;IAezB,sBAAsB,CAAC,EAAE,YAAY,EAAE,YAAY,EAAE,EAAE;QAAE,YAAY,EAAE,GAAG,CAAC;QAAC,YAAY,EAAE,GAAG,CAAA;KAAE;IAOrG,OAAO,CAAC,kBAAkB;IA2D1B,eAAe;IA2Df,cAAc;IAoCR,aAAa,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"BarCodePlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/BarCodePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI7D,KAAK,OAAO,GAAG,IAAI,CACf,aAAa,EACb,YAAY,GAAG,YAAY,GAAG,iBAAiB,CAClD,CAAC;AAEF,OAAO,QAAQ,cAAc,CAAC;IA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,EACD,GAAG,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAQxB,OAAO;CAGV;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -33,7 +33,7 @@ declare class UnitPlugin implements IPluginTempl {
|
|
|
33
33
|
_toPrecisionValue(value: number): number;
|
|
34
34
|
_formatOriginUnitValues<T extends {
|
|
35
35
|
[k: string]: number | undefined;
|
|
36
|
-
}>(vals: T): T;
|
|
36
|
+
}>(vals: T, obj?: fabric.Object, unit?: 'mm' | 'inch'): T;
|
|
37
37
|
applyObjectPx(obj: fabric.Object, opts: {
|
|
38
38
|
left?: number;
|
|
39
39
|
top?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnitPlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/UnitPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG1D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,KAAK,OAAO,GAAG,IAAI,CACf,UAAU,EACR,SAAS,GACT,SAAS,GACT,eAAe,GACf,eAAe,GACf,eAAe,GACf,sBAAsB,GACtB,eAAe,GACf,eAAe,GACf,iBAAiB,GACjB,mBAAmB,CACxB,CAAC;AAEF,KAAK,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;AAElC,OAAO,QAAQ,cAAc,CAAC;IAE1B,UAAU,OAAQ,SAAQ,OAAO;KAAI;CACxC;AAED,cAAM,UAAW,YAAW,YAAY;IAoBzB,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IApB1B,MAAM,CAAC,UAAU,SAAgB;IAEjC,MAAM,CAAC,IAAI,WAYT;IACF,IAAI,EAAE,KAAK,CAAQ;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE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AM,CAAC,EAAE,OAAO,CAAA;KAAE;IAcvF,aAAa,CAAC,GAAG,CAAC,EAAE,MAAM;eAhNW,MAAM;gBAAU,MAAM;;IAgP3D,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAQ/C,oBAAoB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAcpD,WAAW;IAmCX,OAAO;CAGV;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../../src/utils/units.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG/C,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,CAAC,MAAM,EAClB,EAAE,EAAE,SAAS,EACb,GAAG,CAAC,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../../src/utils/units.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG/C,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB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2
2
|
"name": "@hprint/plugins",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"qs": "~6.12.3",
|
|
23
23
|
"socket.io-client": "^4.8.1",
|
|
24
24
|
"uuid": "~8.3.2",
|
|
25
|
-
"@hprint/core": "0.0.
|
|
26
|
-
"@hprint/shared": "0.0.
|
|
25
|
+
"@hprint/core": "0.0.2",
|
|
26
|
+
"@hprint/shared": "0.0.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/bwip-js": "^3.2.3",
|
|
@@ -252,6 +252,11 @@ class BarCodePlugin implements IPluginTempl {
|
|
|
252
252
|
charSpacing,
|
|
253
253
|
lineHeight,
|
|
254
254
|
fontFamily,
|
|
255
|
+
fontWeight,
|
|
256
|
+
fontStyle,
|
|
257
|
+
underline,
|
|
258
|
+
linethrough,
|
|
259
|
+
isShowText,
|
|
255
260
|
...barcodeOptions
|
|
256
261
|
} = option;
|
|
257
262
|
|
|
@@ -272,7 +277,9 @@ class BarCodePlugin implements IPluginTempl {
|
|
|
272
277
|
const svgUrl = `data:image/svg+xml;base64,` + btoa(svgStr);
|
|
273
278
|
|
|
274
279
|
// 如果不需要显示文本,直接返回 SVG URL
|
|
275
|
-
|
|
280
|
+
// 优先使用 isShowText,如果没有定义则使用 displayValue
|
|
281
|
+
const shouldShowText = isShowText !== undefined ? isShowText : displayValue;
|
|
282
|
+
if (!shouldShowText) {
|
|
276
283
|
return svgUrl;
|
|
277
284
|
}
|
|
278
285
|
|
|
@@ -299,6 +306,10 @@ class BarCodePlugin implements IPluginTempl {
|
|
|
299
306
|
: (option as any).textSpacing ?? 0,
|
|
300
307
|
lineHeight: lineHeight || 1, // 传递行高
|
|
301
308
|
fontFamily: fontFamily || 'Arial', // 传递字体
|
|
309
|
+
fontWeight: fontWeight || 'normal', // 传递字体粗细
|
|
310
|
+
fontStyle: fontStyle || 'normal', // 传递字体样式
|
|
311
|
+
underline: underline || false, // 传递下划线参数
|
|
312
|
+
linethrough: linethrough || false, // 传递删除线参数
|
|
302
313
|
});
|
|
303
314
|
|
|
304
315
|
// 合并条形码和文本,使用高分辨率
|
|
@@ -381,6 +392,10 @@ class BarCodePlugin implements IPluginTempl {
|
|
|
381
392
|
fontFamily?: string;
|
|
382
393
|
charSpacing?: number; // 字符间距
|
|
383
394
|
lineHeight?: number; // 行高
|
|
395
|
+
fontWeight?: string;
|
|
396
|
+
fontStyle?: string;
|
|
397
|
+
underline?: boolean;
|
|
398
|
+
linethrough?: boolean;
|
|
384
399
|
}
|
|
385
400
|
): HTMLCanvasElement {
|
|
386
401
|
const canvas = document.createElement('canvas');
|
|
@@ -396,7 +411,19 @@ class BarCodePlugin implements IPluginTempl {
|
|
|
396
411
|
const lines = String(text).split('\n');
|
|
397
412
|
const scaledLineHeight = scaledFontSize * lineHeight;
|
|
398
413
|
const totalTextHeight = scaledLineHeight * lines.length;
|
|
399
|
-
|
|
414
|
+
|
|
415
|
+
const hasUnderline = options.underline;
|
|
416
|
+
const hasLineThrough = options.linethrough;
|
|
417
|
+
|
|
418
|
+
// 计算需要的额外高度(如下划线)
|
|
419
|
+
let extraHeight = 0;
|
|
420
|
+
if (hasUnderline) {
|
|
421
|
+
const lineWidth = Math.max(1, options.fontSize / 15);
|
|
422
|
+
// 确保有足够的空间绘制下划线
|
|
423
|
+
extraHeight = lineWidth * options.scale * 1.5;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const canvasHeight = totalTextHeight + extraHeight;
|
|
400
427
|
|
|
401
428
|
// 设置 canvas 的实际尺寸(高分辨率)
|
|
402
429
|
canvas.width = scaledWidth;
|
|
@@ -410,7 +437,9 @@ class BarCodePlugin implements IPluginTempl {
|
|
|
410
437
|
ctx.scale(options.scale, options.scale);
|
|
411
438
|
|
|
412
439
|
// 设置字体(使用原始尺寸,因为已经通过 scale 缩放)
|
|
413
|
-
|
|
440
|
+
const fontWeight = options.fontWeight || 'normal';
|
|
441
|
+
const fontStyle = options.fontStyle || 'normal';
|
|
442
|
+
ctx.font = `${fontStyle} ${fontWeight} ${options.fontSize}px ${options.fontFamily || 'Arial'}`;
|
|
414
443
|
ctx.textAlign = 'left';
|
|
415
444
|
ctx.textBaseline = 'top';
|
|
416
445
|
ctx.fillStyle = '#000';
|
|
@@ -453,6 +482,33 @@ class BarCodePlugin implements IPluginTempl {
|
|
|
453
482
|
cursorX += w + charSpacing / options.scale;
|
|
454
483
|
}
|
|
455
484
|
}
|
|
485
|
+
|
|
486
|
+
// 绘制装饰线
|
|
487
|
+
if (hasUnderline || hasLineThrough) {
|
|
488
|
+
ctx.beginPath();
|
|
489
|
+
// 线的宽度
|
|
490
|
+
const lineWidth = Math.max(1, options.fontSize / 15);
|
|
491
|
+
ctx.lineWidth = lineWidth;
|
|
492
|
+
ctx.strokeStyle = '#000';
|
|
493
|
+
|
|
494
|
+
// 绘制下划线
|
|
495
|
+
if (hasUnderline) {
|
|
496
|
+
// 通常下划线在 baseline 之下,但这里是 top baseline
|
|
497
|
+
// 简单估算:lineY + fontSize + offset
|
|
498
|
+
const underlineY = lineY + options.fontSize + lineWidth;
|
|
499
|
+
ctx.moveTo(lineX, underlineY);
|
|
500
|
+
ctx.lineTo(lineX + rawLineWidth, underlineY);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// 绘制删除线
|
|
504
|
+
if (hasLineThrough) {
|
|
505
|
+
// 删除线在中间
|
|
506
|
+
const lineThroughY = lineY + options.fontSize / 2;
|
|
507
|
+
ctx.moveTo(lineX, lineThroughY);
|
|
508
|
+
ctx.lineTo(lineX + rawLineWidth, lineThroughY);
|
|
509
|
+
}
|
|
510
|
+
ctx.stroke();
|
|
511
|
+
}
|
|
456
512
|
});
|
|
457
513
|
|
|
458
514
|
return canvas;
|
|
@@ -642,6 +698,11 @@ class BarCodePlugin implements IPluginTempl {
|
|
|
642
698
|
width: 1,
|
|
643
699
|
height: 30,
|
|
644
700
|
boxWidth: 60,
|
|
701
|
+
fontWeight: 'normal',
|
|
702
|
+
fontStyle: 'normal',
|
|
703
|
+
underline: false,
|
|
704
|
+
linethrough: false,
|
|
705
|
+
isShowText: true,
|
|
645
706
|
};
|
|
646
707
|
}
|
|
647
708
|
|
|
@@ -761,6 +822,11 @@ class BarCodePlugin implements IPluginTempl {
|
|
|
761
822
|
displayValue?: boolean;
|
|
762
823
|
margin?: number;
|
|
763
824
|
width?: number;
|
|
825
|
+
fontWeight?: string;
|
|
826
|
+
fontStyle?: string;
|
|
827
|
+
underline?: boolean;
|
|
828
|
+
linethrough?: boolean;
|
|
829
|
+
isShowText?: boolean;
|
|
764
830
|
},
|
|
765
831
|
dpi?: number
|
|
766
832
|
): Promise<fabric.Image> {
|
|
@@ -92,10 +92,22 @@ class CreateElementPlugin implements IPluginTempl {
|
|
|
92
92
|
const mergedUnit = { ...(prev[unit] || {}), ...formatted };
|
|
93
93
|
target._originSize = { ...prev, [unit]: mergedUnit };
|
|
94
94
|
};
|
|
95
|
+
const applyStrokeDashArrayFromOrigin = (target: any) => {
|
|
96
|
+
const unit = getUnit(editorRef);
|
|
97
|
+
const originUnit = (target._originSize?.[unit] || {}) as Record<string, any>;
|
|
98
|
+
const strokeDashArray = originUnit.strokeDashArray;
|
|
99
|
+
if (Array.isArray(strokeDashArray) && strokeDashArray.length > 0) {
|
|
100
|
+
const strokeWidth = target.get('strokeWidth') || 1;
|
|
101
|
+
const actualDashArray = strokeDashArray.map((v: number) => v * strokeWidth);
|
|
102
|
+
(originalSet as any)('strokeDashArray', actualDashArray);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
95
105
|
(obj as any).setByUnit = function (key: any, value?: any) {
|
|
96
106
|
const unit = getUnit(editorRef);
|
|
97
107
|
const dpi = 96;
|
|
98
108
|
const isTransforming = !!(this.canvas && (this.canvas as any)._currentTransform);
|
|
109
|
+
const isLineObject = this.type === 'line' || this.type === 'arrow' || this.type === 'thinTailArrow';
|
|
110
|
+
|
|
99
111
|
if (typeof key === 'string') {
|
|
100
112
|
const field = key as keyof fabric.Object;
|
|
101
113
|
if (singleFields.includes(field)) {
|
|
@@ -105,27 +117,99 @@ class CreateElementPlugin implements IPluginTempl {
|
|
|
105
117
|
if (value !== undefined) {
|
|
106
118
|
const processedVal = convertSingle(value, unit, dpi);
|
|
107
119
|
mergeOrigin(this, unit, { [field]: value });
|
|
120
|
+
|
|
121
|
+
// Special handling for Line objects - width/height changes should update coordinates
|
|
122
|
+
if (isLineObject && (field === 'width' || field === 'height')) {
|
|
123
|
+
const currentWidth = Math.abs((this as any).x2 - (this as any).x1);
|
|
124
|
+
const currentHeight = Math.abs((this as any).y2 - (this as any).y1);
|
|
125
|
+
|
|
126
|
+
if (field === 'width' && currentWidth > 0) {
|
|
127
|
+
// Keep first point (x1) fixed, only update x2
|
|
128
|
+
const x1 = (this as any).x1;
|
|
129
|
+
const x2 = (this as any).x2;
|
|
130
|
+
const left = (this as any).left;
|
|
131
|
+
const top = (this as any).top;
|
|
132
|
+
const direction = Math.sign(x2 - x1);
|
|
133
|
+
const newX2 = x1 + processedVal * direction;
|
|
134
|
+
|
|
135
|
+
// Calculate new bounding box to maintain position
|
|
136
|
+
const oldMinX = Math.min(x1, x2);
|
|
137
|
+
const newMinX = Math.min(x1, newX2);
|
|
138
|
+
const offsetX = oldMinX - newMinX;
|
|
139
|
+
|
|
140
|
+
(originalSet as any)('x2', newX2);
|
|
141
|
+
// Adjust left to compensate for coordinate change
|
|
142
|
+
if (offsetX !== 0) {
|
|
143
|
+
const newLeft = left + offsetX;
|
|
144
|
+
(originalSet as any)('left', newLeft);
|
|
145
|
+
// Update _originSize with new left position
|
|
146
|
+
const originLeft = editorRef.getSizeByUnit(newLeft);
|
|
147
|
+
mergeOrigin(this, unit, { left: originLeft });
|
|
148
|
+
}
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (field === 'height' && currentHeight > 0) {
|
|
153
|
+
// Keep first point (y1) fixed, only update y2
|
|
154
|
+
const y1 = (this as any).y1;
|
|
155
|
+
const y2 = (this as any).y2;
|
|
156
|
+
const left = (this as any).left;
|
|
157
|
+
const top = (this as any).top;
|
|
158
|
+
const direction = Math.sign(y2 - y1);
|
|
159
|
+
const newY2 = y1 + processedVal * direction;
|
|
160
|
+
|
|
161
|
+
// Calculate new bounding box to maintain position
|
|
162
|
+
const oldMinY = Math.min(y1, y2);
|
|
163
|
+
const newMinY = Math.min(y1, newY2);
|
|
164
|
+
const offsetY = oldMinY - newMinY;
|
|
165
|
+
|
|
166
|
+
(originalSet as any)('y2', newY2);
|
|
167
|
+
// Adjust top to compensate for coordinate change
|
|
168
|
+
if (offsetY !== 0) {
|
|
169
|
+
const newTop = top + offsetY;
|
|
170
|
+
(originalSet as any)('top', newTop);
|
|
171
|
+
// Update _originSize with new top position
|
|
172
|
+
const originTop = editorRef.getSizeByUnit(newTop);
|
|
173
|
+
mergeOrigin(this, unit, { top: originTop });
|
|
174
|
+
}
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
108
179
|
if (this.type === 'image' && (field === 'width' || field === 'height')) {
|
|
109
180
|
if (field === 'width') {
|
|
110
181
|
return originalSet('scaleX', processedVal / (this.width || 1));
|
|
111
182
|
}
|
|
112
183
|
return originalSet('scaleY', processedVal / (this.height || 1));
|
|
113
184
|
}
|
|
114
|
-
|
|
185
|
+
const result = originalSet(field, processedVal);
|
|
186
|
+
if (field === 'strokeWidth') {
|
|
187
|
+
applyStrokeDashArrayFromOrigin(this);
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (field === 'strokeDashArray' && Array.isArray(value)) {
|
|
193
|
+
if (isTransforming) {
|
|
194
|
+
return (originalSet as any)(field, value);
|
|
115
195
|
}
|
|
196
|
+
mergeOrigin(this, unit, { strokeDashArray: value });
|
|
197
|
+
const strokeWidth = this.get('strokeWidth') || 1;
|
|
198
|
+
const actualDashArray = value.map((v: number) => v * strokeWidth);
|
|
199
|
+
return (originalSet as any)(field, actualDashArray);
|
|
116
200
|
}
|
|
117
201
|
if (field === 'points' && hasPointsField && Array.isArray(value)) {
|
|
118
202
|
if (isTransforming) {
|
|
119
|
-
return originalSet(field, value);
|
|
203
|
+
return (originalSet as any)(field, value);
|
|
120
204
|
}
|
|
121
205
|
const pts = (value as Array<{ x: number; y: number }>).map((p) => ({
|
|
122
206
|
x: convertSingle(p.x, unit, dpi),
|
|
123
207
|
y: convertSingle(p.y, unit, dpi),
|
|
124
208
|
}));
|
|
125
209
|
mergeOrigin(this, unit, { points: value });
|
|
126
|
-
return originalSet(field, pts);
|
|
210
|
+
return (originalSet as any)(field, pts);
|
|
127
211
|
}
|
|
128
|
-
return originalSet(key, value);
|
|
212
|
+
return (originalSet as any)(key, value);
|
|
129
213
|
}
|
|
130
214
|
if (key && typeof key === 'object') {
|
|
131
215
|
const opts = { ...key } as Record<string, any>;
|
|
@@ -145,8 +229,67 @@ class CreateElementPlugin implements IPluginTempl {
|
|
|
145
229
|
}
|
|
146
230
|
const { processed, originByUnit } = processOptions(opts, unit, dpi, singleFields);
|
|
147
231
|
const originUnit = originByUnit[unit] || {};
|
|
232
|
+
if (Array.isArray(opts.strokeDashArray)) {
|
|
233
|
+
originUnit.strokeDashArray = opts.strokeDashArray;
|
|
234
|
+
}
|
|
148
235
|
if (Object.keys(originUnit).length) mergeOrigin(this, unit, originUnit);
|
|
149
236
|
const finalProps = { ...opts, ...processed };
|
|
237
|
+
|
|
238
|
+
// Special handling for Line objects - width/height changes should update coordinates
|
|
239
|
+
if (isLineObject) {
|
|
240
|
+
const left = (this as any).left;
|
|
241
|
+
const top = (this as any).top;
|
|
242
|
+
let offsetX = 0;
|
|
243
|
+
let offsetY = 0;
|
|
244
|
+
|
|
245
|
+
if (finalProps.width !== undefined) {
|
|
246
|
+
const currentWidth = Math.abs((this as any).x2 - (this as any).x1);
|
|
247
|
+
if (currentWidth > 0) {
|
|
248
|
+
// Keep first point (x1) fixed, only update x2
|
|
249
|
+
const x1 = (this as any).x1;
|
|
250
|
+
const x2 = (this as any).x2;
|
|
251
|
+
const direction = Math.sign(x2 - x1);
|
|
252
|
+
const newX2 = x1 + finalProps.width * direction;
|
|
253
|
+
|
|
254
|
+
// Calculate offset to maintain position
|
|
255
|
+
const oldMinX = Math.min(x1, x2);
|
|
256
|
+
const newMinX = Math.min(x1, newX2);
|
|
257
|
+
offsetX = oldMinX - newMinX;
|
|
258
|
+
|
|
259
|
+
finalProps.x2 = newX2;
|
|
260
|
+
delete finalProps.width;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (finalProps.height !== undefined) {
|
|
264
|
+
const currentHeight = Math.abs((this as any).y2 - (this as any).y1);
|
|
265
|
+
if (currentHeight > 0) {
|
|
266
|
+
// Keep first point (y1) fixed, only update y2
|
|
267
|
+
const y1 = (this as any).y1;
|
|
268
|
+
const y2 = (this as any).y2;
|
|
269
|
+
const direction = Math.sign(y2 - y1);
|
|
270
|
+
const newY2 = y1 + finalProps.height * direction;
|
|
271
|
+
|
|
272
|
+
// Calculate offset to maintain position
|
|
273
|
+
const oldMinY = Math.min(y1, y2);
|
|
274
|
+
const newMinY = Math.min(y1, newY2);
|
|
275
|
+
offsetY = oldMinY - newMinY;
|
|
276
|
+
|
|
277
|
+
finalProps.y2 = newY2;
|
|
278
|
+
delete finalProps.height;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Adjust left/top to compensate for coordinate changes
|
|
283
|
+
if (offsetX !== 0) {
|
|
284
|
+
finalProps.left = left + offsetX;
|
|
285
|
+
originUnit.left = editorRef.getSizeByUnit(finalProps.left);
|
|
286
|
+
}
|
|
287
|
+
if (offsetY !== 0) {
|
|
288
|
+
finalProps.top = top + offsetY;
|
|
289
|
+
originUnit.top = editorRef.getSizeByUnit(finalProps.top);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
150
293
|
if (this.type === 'image') {
|
|
151
294
|
if (finalProps.width !== undefined) {
|
|
152
295
|
finalProps.scaleX = finalProps.width / (this.width || 1);
|
|
@@ -157,7 +300,15 @@ class CreateElementPlugin implements IPluginTempl {
|
|
|
157
300
|
delete finalProps.height;
|
|
158
301
|
}
|
|
159
302
|
}
|
|
160
|
-
|
|
303
|
+
if (Array.isArray(finalProps.strokeDashArray)) {
|
|
304
|
+
const strokeWidth = finalProps.strokeWidth ?? this.get('strokeWidth') ?? 1;
|
|
305
|
+
finalProps.strokeDashArray = finalProps.strokeDashArray.map((v: number) => v * strokeWidth);
|
|
306
|
+
}
|
|
307
|
+
const result = originalSet(finalProps);
|
|
308
|
+
if (finalProps.strokeWidth !== undefined) {
|
|
309
|
+
applyStrokeDashArrayFromOrigin(this);
|
|
310
|
+
}
|
|
311
|
+
return result;
|
|
161
312
|
}
|
|
162
313
|
return originalSet(key, value);
|
|
163
314
|
};
|
|
@@ -169,6 +320,7 @@ class CreateElementPlugin implements IPluginTempl {
|
|
|
169
320
|
const ratio = convertSingle(1, unit, dpiVal) || 1;
|
|
170
321
|
const origin: Record<string, any> = {};
|
|
171
322
|
const isImageObject = (this as any).type === 'image';
|
|
323
|
+
const isLineObject = (this as any).type === 'line' || (this as any).type === 'arrow' || (this as any).type === 'thinTailArrow';
|
|
172
324
|
const targetFields: string[] =
|
|
173
325
|
hasFieldsArray && (fieldsOrDpi as string[])?.length ? (fieldsOrDpi as string[]) : singleFields;
|
|
174
326
|
targetFields.forEach((field) => {
|
|
@@ -180,6 +332,13 @@ class CreateElementPlugin implements IPluginTempl {
|
|
|
180
332
|
} else {
|
|
181
333
|
currentVal = (this as any).getScaledHeight?.();
|
|
182
334
|
}
|
|
335
|
+
} else if (isLineObject && (field === 'width' || field === 'height')) {
|
|
336
|
+
// For line objects, calculate width/height from coordinates
|
|
337
|
+
if (field === 'width') {
|
|
338
|
+
currentVal = Math.abs((this as any).x2 - (this as any).x1);
|
|
339
|
+
} else {
|
|
340
|
+
currentVal = Math.abs((this as any).y2 - (this as any).y1);
|
|
341
|
+
}
|
|
183
342
|
} else {
|
|
184
343
|
currentVal = (this as any).get ? (this as any).get(field) : (this as any)[field];
|
|
185
344
|
}
|
|
@@ -279,7 +438,7 @@ class CreateElementPlugin implements IPluginTempl {
|
|
|
279
438
|
|
|
280
439
|
createLine(
|
|
281
440
|
points: Array<{ x: number; y: number }>,
|
|
282
|
-
opts?: { strokeWidth?: number; stroke?: string },
|
|
441
|
+
opts?: { strokeWidth?: number; stroke?: string; strokeDashArray?: number[] },
|
|
283
442
|
dpi?: number
|
|
284
443
|
): fabric.Line {
|
|
285
444
|
const unit = getUnit(this.editor);
|
|
@@ -291,16 +450,18 @@ class CreateElementPlugin implements IPluginTempl {
|
|
|
291
450
|
const { processed: optProcessed, originByUnit: originOpts } =
|
|
292
451
|
processOptions(opts || {}, unit, dpi, singleFields);
|
|
293
452
|
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
453
|
+
const strokeWidth = optProcessed.strokeWidth ?? (opts?.strokeWidth !== undefined ? convertSingle(opts.strokeWidth, unit, dpi) : 1);
|
|
454
|
+
const lineOpts: any = {
|
|
455
|
+
...opts,
|
|
456
|
+
strokeWidth: optProcessed.strokeWidth !== undefined ? optProcessed.strokeWidth : undefined,
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
if (Array.isArray(opts?.strokeDashArray)) {
|
|
460
|
+
const actualDashArray = opts.strokeDashArray.map((v) => v * strokeWidth);
|
|
461
|
+
lineOpts.strokeDashArray = actualDashArray;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
const line = new fabric.Line([pts[0].x, pts[0].y, pts[1].x, pts[1].y], lineOpts);
|
|
304
465
|
|
|
305
466
|
const precision = (this.editor as any).getPrecision?.();
|
|
306
467
|
const mergedOrigin = {
|
|
@@ -309,6 +470,11 @@ class CreateElementPlugin implements IPluginTempl {
|
|
|
309
470
|
...formatOriginValues(originPoints[unit] || {}, precision),
|
|
310
471
|
},
|
|
311
472
|
} as Record<string, any>;
|
|
473
|
+
|
|
474
|
+
if (Array.isArray(opts?.strokeDashArray)) {
|
|
475
|
+
mergedOrigin[unit].strokeDashArray = formatOriginValues({ arr: opts.strokeDashArray }, precision).arr;
|
|
476
|
+
}
|
|
477
|
+
|
|
312
478
|
(line as any)._originSize = mergedOrigin;
|
|
313
479
|
this.addSetAndSyncByUnit(line);
|
|
314
480
|
return line;
|
|
@@ -103,12 +103,28 @@ class UnitPlugin implements IPluginTempl {
|
|
|
103
103
|
return Math.round(value * factor) / factor;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
_formatOriginUnitValues<T extends { [k: string]: number | undefined }>(
|
|
106
|
+
_formatOriginUnitValues<T extends { [k: string]: number | undefined }>(
|
|
107
|
+
vals: T,
|
|
108
|
+
obj?: fabric.Object,
|
|
109
|
+
unit?: 'mm' | 'inch'
|
|
110
|
+
): T {
|
|
107
111
|
const result: Record<string, number | undefined> = {};
|
|
108
112
|
for (const key in vals) {
|
|
109
113
|
const v = vals[key];
|
|
110
114
|
result[key] = v === undefined ? undefined : this._toPrecisionValue(v);
|
|
111
115
|
}
|
|
116
|
+
|
|
117
|
+
// Preserve ALL existing fields from _originSize[unit] to prevent data loss
|
|
118
|
+
if (obj && unit) {
|
|
119
|
+
const existingUnit = (obj as any)._originSize?.[unit] || {};
|
|
120
|
+
// Merge existing fields with new values, new values take precedence
|
|
121
|
+
Object.keys(existingUnit).forEach((key) => {
|
|
122
|
+
if (!(key in result)) {
|
|
123
|
+
result[key] = existingUnit[key];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
112
128
|
return result as T;
|
|
113
129
|
}
|
|
114
130
|
|
|
@@ -155,8 +171,11 @@ class UnitPlugin implements IPluginTempl {
|
|
|
155
171
|
strokeWidth: toPx(mm.strokeWidth),
|
|
156
172
|
fontSize: toPx(mm.fontSize),
|
|
157
173
|
});
|
|
158
|
-
const formatted = this._formatOriginUnitValues(mm);
|
|
159
|
-
(obj as any)._originSize = {
|
|
174
|
+
const formatted = this._formatOriginUnitValues(mm, obj, 'mm');
|
|
175
|
+
(obj as any)._originSize = {
|
|
176
|
+
...(obj as any)._originSize,
|
|
177
|
+
mm: formatted
|
|
178
|
+
};
|
|
160
179
|
}
|
|
161
180
|
|
|
162
181
|
applyObjectInch(
|
|
@@ -185,8 +204,11 @@ class UnitPlugin implements IPluginTempl {
|
|
|
185
204
|
},
|
|
186
205
|
dpi
|
|
187
206
|
);
|
|
188
|
-
const formatted = this._formatOriginUnitValues(inch);
|
|
189
|
-
(obj as any)._originSize = {
|
|
207
|
+
const formatted = this._formatOriginUnitValues(inch, obj, 'inch');
|
|
208
|
+
(obj as any)._originSize = {
|
|
209
|
+
...(obj as any)._originSize,
|
|
210
|
+
inch: formatted
|
|
211
|
+
};
|
|
190
212
|
}
|
|
191
213
|
|
|
192
214
|
applyObjectByUnit(
|
package/src/utils/units.ts
CHANGED
|
@@ -31,9 +31,14 @@ export function applyMmToObject(
|
|
|
31
31
|
if (strokeWidthPx !== undefined) obj.set('strokeWidth', strokeWidthPx);
|
|
32
32
|
if (fontSizePx !== undefined) (obj as any).fontSize = fontSizePx;
|
|
33
33
|
|
|
34
|
+
// Preserve ALL existing fields from _originSize.mm to prevent data loss
|
|
35
|
+
const existingMm = (obj as any)._originSize?.mm || {};
|
|
36
|
+
|
|
34
37
|
(obj as any)._originSize = {
|
|
35
38
|
...(obj as any)._originSize,
|
|
36
39
|
mm: {
|
|
40
|
+
...existingMm, // Preserve all existing fields first
|
|
41
|
+
// Then update only the provided fields
|
|
37
42
|
left: mm.left,
|
|
38
43
|
top: mm.top,
|
|
39
44
|
width: mm.width,
|
|
@@ -56,9 +61,14 @@ export function syncMmFromObject(obj: fabric.Object, dpi?: number, precision?: n
|
|
|
56
61
|
const strokeWidth = obj.strokeWidth as number | undefined;
|
|
57
62
|
const fontSize = (obj as any).fontSize as number | undefined;
|
|
58
63
|
|
|
64
|
+
// Preserve ALL existing fields from _originSize.mm to prevent data loss
|
|
65
|
+
const existingMm = (obj as any)._originSize?.mm || {};
|
|
66
|
+
|
|
59
67
|
(obj as any)._originSize = {
|
|
60
68
|
...(obj as any)._originSize,
|
|
61
69
|
mm: {
|
|
70
|
+
...existingMm, // Preserve all existing fields first
|
|
71
|
+
// Then update only the synced fields
|
|
62
72
|
left: toMm(left),
|
|
63
73
|
top: toMm(top),
|
|
64
74
|
width: toMm(width),
|