@hprint/plugins 0.0.8 → 0.0.9-alpha.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAwC5D,QAAA,MAAM,aAAa,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;CAqCjD,CAAC;AAGF,QAAA,MAAM,WAAW,EAAE,YAAY,EAqC9B,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AA0C5D,QAAA,MAAM,aAAa,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;CAuCjD,CAAC;AAGF,QAAA,MAAM,WAAW,EAAE,YAAY,EAuC9B,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { fabric, IEditor, IPluginTempl } from '@hprint/core';
2
+ export interface ActualContentLayoutSettings {
3
+ actualContentLayout?: boolean;
4
+ overflowMode?: 'clip' | 'expand';
5
+ }
6
+ type IPlugin = Pick<ActualContentLayoutPlugin, 'applyActualContentLayout'>;
7
+ declare module '@hprint/core' {
8
+ interface IEditor extends IPlugin {
9
+ }
10
+ }
11
+ declare class ActualContentLayoutPlugin implements IPluginTempl {
12
+ canvas: fabric.Canvas;
13
+ editor: IEditor;
14
+ static pluginName: string;
15
+ static apis: string[];
16
+ constructor(canvas: fabric.Canvas, editor: IEditor);
17
+ private layoutOrigins;
18
+ hookTransformObjectEnd(...args: unknown[]): Promise<void>;
19
+ applyActualContentLayout(templateContent: any, templateHeight: number): number;
20
+ private getOriginalTop;
21
+ private getOriginalHeight;
22
+ private getTemplateSourceObjects;
23
+ private getSourceObject;
24
+ private getOriginMmValue;
25
+ private preparePrintLayoutObject;
26
+ private isPrintableObject;
27
+ private isEmptyLayoutObject;
28
+ private hasVisibleImageSource;
29
+ private getActualLayoutHeight;
30
+ }
31
+ export default ActualContentLayoutPlugin;
32
+ //# sourceMappingURL=ActualContentLayoutPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ActualContentLayoutPlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/ActualContentLayoutPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE1D,MAAM,WAAW,2BAA2B;IACxC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;CACpC;AAED,KAAK,OAAO,GAAG,IAAI,CAAC,yBAAyB,EAAE,0BAA0B,CAAC,CAAC;AAE3E,OAAO,QAAQ,cAAc,CAAC;IAC1B,UAAU,OAAQ,SAAQ,OAAO;KAAG;CACvC;AASD,cAAM,yBAA0B,YAAW,YAAY;IAKxC,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IAL1B,MAAM,CAAC,UAAU,SAA+B;IAChD,MAAM,CAAC,IAAI,WAAgC;gBAGhC,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,MAAM,EAAE,OAAO;IAG1B,OAAO,CAAC,aAAa,CAGjB;IAEE,sBAAsB,CAAC,GAAG,I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WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,aAAa;IAiB/C,WAAW;;;;;;IAcX,OAAO;IAKP,SAAS;IAIH,aAAa,CAAC,KAAK,EAAE,GAAG;CAwHjC;AAED,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"CopyPlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/CopyPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE1D,KAAK,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAEzC,OAAO,QAAQ,cAAc,CAAC;IAE1B,UAAU,OAAQ,SAAQ,OAAO;KAAG;CACvC;AAED,cAAM,UAAW,YAAW,YAAY;IAMzB,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IAN1B,MAAM,CAAC,UAAU,SAAgB;IACjC,MAAM,CAAC,IAAI,WAAa;IACxB,OAAO,EAAE,MAAM,EAAE,CAAwB;IACzC,OAAO,CAAC,KAAK,CAAuD;gBAEzD,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,MAAM,EAAE,OAAO;IAM1B,oBAAoB,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM;IAiChD,WAAW,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM;IA8BvC,KAAK,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,MAAM;IAYlE,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,aAAa;IAiB/C,WAAW;;;;;;IAcX,OAAO;IAKP,SAAS;IAIH,aAAa,CAAC,KAAK,EAAE,GAAG;CAwHjC;AAED,eAAe,UAAU,CAAC"}
@@ -17,6 +17,7 @@ declare class HistoryPlugin implements IPluginTempl {
17
17
  private getCurrentState;
18
18
  private saveState;
19
19
  private _loadState;
20
+ private restoreActiveObjects;
20
21
  private getState;
21
22
  private clear;
22
23
  historyUpdate(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"HistoryPlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/HistoryPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,KAAK,OAAO,GAAG,MAAM,CAAC;AAGtB,cAAM,aAAc,YAAW,YAAY;IAqB5B,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IArB1B,MAAM,CAAC,UAAU,SAAmB;IACpC,MAAM,CAAC,IAAI,WAMT;IACF,MAAM,CAAC,MAAM,UAAM;IAGnB,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,SAAS,CAAO;IACxB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,SAAS,CAAS;IAE1B,OAAO,EAAE,MAAM,EAAE,CAAkD;gBAGxD,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,MAAM,EAAE,OAAO;IAK1B,OAAO,CAAC,KAAK;IA+Bb,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,SAAS;IAiBjB,OAAO,CAAC,UAAU;IAuBlB,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,KAAK;IAOb,aAAa;IAKb,eAAe;IAMf,IAAI;IAWJ,IAAI;IAWJ,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,aAAa;IAe/C,iBAAiB;CAMpB;AAED,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"HistoryPlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/HistoryPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,KAAK,OAAO,GAAG,MAAM,CAAC;AAGtB,cAAM,aAAc,YAAW,YAAY;IAqB5B,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IArB1B,MAAM,CAAC,UAAU,SAAmB;IACpC,MAAM,CAAC,IAAI,WAMT;IACF,MAAM,CAAC,MAAM,UAAM;IAGnB,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,SAAS,CAAO;IACxB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,SAAS,CAAS;IAE1B,OAAO,EAAE,MAAM,EAAE,CAAkD;gBAGxD,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,MAAM,EAAE,OAAO;IAK1B,OAAO,CAAC,KAAK;IA+Bb,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,SAAS;IAiBjB,OAAO,CAAC,UAAU;IA2ClB,OAAO,CAAC,oBAAoB;IAoB5B,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,KAAK;IAOb,aAAa;IAKb,eAAe;IAMf,IAAI;IAWJ,IAAI;IAWJ,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,aAAa;IAe/C,iBAAiB;CAMpB;AAED,eAAe,aAAa,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { fabric, IEditor, IPluginTempl } from '@hprint/core';
2
+ export type ImageTextListLayout = 'item-vertical' | 'icon-text-split' | 'icon-only' | 'text-only';
3
+ export interface ImageTextListItem {
4
+ src: string;
5
+ name: string;
6
+ }
7
+ export interface ImageTextListOptions {
8
+ items?: ImageTextListItem[];
9
+ _renderItems?: ImageTextListItem[];
10
+ _clipContent?: boolean;
11
+ layout?: ImageTextListLayout;
12
+ width?: number;
13
+ height?: number;
14
+ iconSize?: number;
15
+ horizontalGap?: number;
16
+ verticalGap?: number;
17
+ itemGap?: number;
18
+ fontFamily?: string;
19
+ fontSize?: number;
20
+ fontWeight?: string;
21
+ fontStyle?: string;
22
+ underline?: boolean | string;
23
+ linethrough?: boolean | string;
24
+ textAlign?: 'left' | 'center' | 'right' | 'justify';
25
+ textWrap?: boolean;
26
+ lineHeight?: number;
27
+ charSpacing?: number;
28
+ color?: string;
29
+ [key: string]: any;
30
+ }
31
+ type ImageTextListGroup = fabric.Group & {
32
+ extensionType?: string;
33
+ extension?: ImageTextListOptions;
34
+ _originSize?: Record<string, any>;
35
+ setExtension?: (fields: Record<string, any>) => Promise<void>;
36
+ setExtensionByUnit?: (fields: Record<string, any>) => Promise<void>;
37
+ setByUnit?: (field: string, value: any) => Promise<any>;
38
+ __imageTextListModified?: () => void;
39
+ };
40
+ type IPlugin = Pick<ImageTextListPlugin, 'createImageTextList' | 'initImageTextListEvents' | 'refreshImageTextList'>;
41
+ declare module '@hprint/core' {
42
+ interface IEditor extends IPlugin {
43
+ }
44
+ }
45
+ declare class ImageTextListPlugin implements IPluginTempl {
46
+ canvas: fabric.Canvas;
47
+ editor: IEditor;
48
+ static pluginName: string;
49
+ static apis: string[];
50
+ constructor(canvas: fabric.Canvas, editor: IEditor);
51
+ hookTransform(object: any): Promise<void>;
52
+ hookTransformObjectEnd(...args: unknown[]): Promise<void>;
53
+ createImageTextList(items: ImageTextListItem[], options?: ImageTextListOptions): Promise<ImageTextListGroup>;
54
+ initImageTextListEvents(group: ImageTextListGroup): void;
55
+ refreshImageTextList(group: ImageTextListGroup): Promise<void>;
56
+ private normalizeOptions;
57
+ private toPx;
58
+ private getItems;
59
+ private createText;
60
+ private loadImage;
61
+ private buildGroup;
62
+ private createGroup;
63
+ private flowRows;
64
+ private updateOriginSize;
65
+ destroy(): void;
66
+ }
67
+ export default ImageTextListPlugin;
68
+ //# sourceMappingURL=ImageTextListPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImageTextListPlugin.d.ts","sourceRoot":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KAAK,EAAE,kBAAkB;IAuD3C,oBAAoB,CAAC,KAAK,EAAE,kBAAkB;IAqCpD,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,IAAI;IAIZ,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,UAAU;IA+BlB,OAAO,CAAC,SAAS;YAqBH,UAAU;IAgIxB,OAAO,CAAC,WAAW;IAgDnB,OAAO,CAAC,QAAQ;IAsBhB,OAAO,CAAC,gBAAgB;IAuBxB,OAAO;CACV;AAED,eAAe,mBAAmB,CAAC"}
@@ -15,6 +15,7 @@ declare class QrCodePlugin implements IPluginTempl {
15
15
  originObject: any;
16
16
  fabricObject: any;
17
17
  }): Promise<void>;
18
+ hookImportAfter(): Promise<void>;
18
19
  _getQrCodeResult(options: any): Promise<{
19
20
  url: string;
20
21
  width: number;
@@ -1 +1 @@
1
- {"version":3,"file":"QrCodePlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/QrCodePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE1D,KAAK,OAAO,GAAG,IAAI,CAAC,YAAY,EAAE,WAAW,GAAG,WAAW,GAAG,kBAAkB,CAAC,CAAC;AAElF,OAAO,QAAQ,cAAc,CAAC;IAE1B,UAAU,OAAQ,SAAQ,OAAO;KAAI;CACxC;AAED,cAAM,YAAa,YAAW,YAAY;IAI3B,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IAJ1B,MAAM,CAAC,UAAU,SAAkB;IACnC,MAAM,CAAC,IAAI,WAAkD;gBAElD,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,MAAM,EAAE,OAAO;IAGpB,aAAa,CAAC,MAAM,EAAE,GAAG;IA0BzB,sBAAsB,CAAC,EAAE,YAAY,EAAE,YAAY,EAAE,EAAE;QAAE,YAAY,EAAE,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MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;KACnB,EACD,GAAG,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAwDlB,SAAS,CAAC,MAAM,EAAE,GAAG;IA2B3B,OAAO;CAGV;AAED,eAAe,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hprint/plugins",
3
- "version": "0.0.8",
3
+ "version": "0.0.9-alpha.1",
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.8",
26
- "@hprint/shared": "0.0.8"
25
+ "@hprint/core": "0.0.9-alpha.1",
26
+ "@hprint/shared": "0.0.9-alpha.1"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/bwip-js": "^3.2.3",
package/src/index.ts CHANGED
@@ -36,7 +36,9 @@ import ResizePlugin from './plugins/ResizePlugin';
36
36
  import LockPlugin from './plugins/LockPlugin';
37
37
  import AddBaseTypePlugin from './plugins/AddBaseTypePlugin';
38
38
  import PrintPlugin from './plugins/PrintPlugin';
39
- import CreateElementPlugin from './plugins/CreateElementPlugin';
39
+ import CreateElementPlugin from './plugins/CreateElementPlugin';
40
+ import ImageTextListPlugin from './plugins/ImageTextListPlugin';
41
+ import ActualContentLayoutPlugin from './plugins/ActualContentLayoutPlugin';
40
42
 
41
43
  // 对象形式导出所有插件
42
44
  const pluginsObject: { [key: string]: IPluginTempl } = {
@@ -75,8 +77,10 @@ const pluginsObject: { [key: string]: IPluginTempl } = {
75
77
  LockPlugin,
76
78
  AddBaseTypePlugin,
77
79
  PrintPlugin,
78
- CreateElementPlugin,
79
- };
80
+ CreateElementPlugin,
81
+ ImageTextListPlugin,
82
+ ActualContentLayoutPlugin,
83
+ };
80
84
 
81
85
  // 数组形式导出所有插件
82
86
  const pluginsList: IPluginTempl[] = [
@@ -115,7 +119,9 @@ const pluginsList: IPluginTempl[] = [
115
119
  LockPlugin,
116
120
  AddBaseTypePlugin,
117
121
  PrintPlugin,
118
- CreateElementPlugin,
119
- ];
122
+ CreateElementPlugin,
123
+ ImageTextListPlugin,
124
+ ActualContentLayoutPlugin,
125
+ ];
120
126
 
121
127
  export { pluginsObject, pluginsList, SelectEvent, SelectMode };
@@ -0,0 +1,309 @@
1
+ import { fabric } from '@hprint/core';
2
+ import type { IEditor, IPluginTempl } from '@hprint/core';
3
+
4
+ export interface ActualContentLayoutSettings {
5
+ actualContentLayout?: boolean;
6
+ overflowMode?: 'clip' | 'expand';
7
+ }
8
+
9
+ type IPlugin = Pick<ActualContentLayoutPlugin, 'applyActualContentLayout'>;
10
+
11
+ declare module '@hprint/core' {
12
+ interface IEditor extends IPlugin {}
13
+ }
14
+
15
+ type LayoutEntry = {
16
+ object: fabric.Object;
17
+ index: number;
18
+ originalTop: number;
19
+ originalBottom: number;
20
+ };
21
+
22
+ class ActualContentLayoutPlugin implements IPluginTempl {
23
+ static pluginName = 'ActualContentLayoutPlugin';
24
+ static apis = ['applyActualContentLayout'];
25
+
26
+ constructor(
27
+ public canvas: fabric.Canvas,
28
+ public editor: IEditor
29
+ ) {}
30
+
31
+ private layoutOrigins = new WeakMap<
32
+ fabric.Object,
33
+ { top: number; height: number }
34
+ >();
35
+
36
+ async hookTransformObjectEnd(...args: unknown[]) {
37
+ const { originObject, fabricObject } = args[0] as {
38
+ originObject: any;
39
+ fabricObject: fabric.Object;
40
+ };
41
+ if (!this.isPrintableObject(originObject)) return;
42
+
43
+ const mmPerPx = Number(this.editor.getSizeByUnit?.(1, 'mm')) || 1;
44
+ this.layoutOrigins.set(fabricObject, {
45
+ top: this.getOriginalTop(originObject, fabricObject, mmPerPx),
46
+ height: this.getOriginalHeight(
47
+ originObject,
48
+ fabricObject,
49
+ mmPerPx
50
+ ),
51
+ });
52
+ }
53
+
54
+ applyActualContentLayout(templateContent: any, templateHeight: number) {
55
+ const settings = (templateContent?.templateSettings ||
56
+ {}) as ActualContentLayoutSettings;
57
+ if (!settings.actualContentLayout) return templateHeight;
58
+
59
+ const fabricObjects = this.canvas
60
+ .getObjects()
61
+ .filter(this.isPrintableObject);
62
+ const mmPerPx = Number(this.editor.getSizeByUnit?.(1, 'mm')) || 1;
63
+ const sourceObjects = this.getTemplateSourceObjects(templateContent);
64
+
65
+ fabricObjects.forEach((object) => this.preparePrintLayoutObject(object));
66
+
67
+ const entries = fabricObjects.map((object, index) => {
68
+ const origin = this.layoutOrigins.get(object);
69
+ const source = this.getSourceObject(object, sourceObjects);
70
+ const originalTop =
71
+ origin?.top ??
72
+ this.getOriginalTop(source, object, mmPerPx);
73
+ const originalHeight =
74
+ origin?.height ??
75
+ this.getOriginalHeight(source, object, mmPerPx);
76
+ return {
77
+ object,
78
+ index,
79
+ originalTop,
80
+ originalBottom: originalTop + originalHeight,
81
+ };
82
+ }) as LayoutEntry[];
83
+
84
+ entries.sort(
85
+ (a, b) => a.originalTop - b.originalTop || a.index - b.index
86
+ );
87
+ const rows: LayoutEntry[][] = [];
88
+ const sameRowTolerance = 0.01;
89
+ entries.forEach((entry) => {
90
+ const row = rows[rows.length - 1];
91
+ if (
92
+ row &&
93
+ Math.abs(row[0].originalTop - entry.originalTop) <=
94
+ sameRowTolerance
95
+ ) {
96
+ row.push(entry);
97
+ } else {
98
+ rows.push([entry]);
99
+ }
100
+ });
101
+
102
+ let previousOriginalBottom: number | undefined;
103
+ let previousActualBottom: number | undefined;
104
+ let pendingGap = 0;
105
+ let lastVisibleOriginalBottom = 0;
106
+
107
+ rows.forEach((row) => {
108
+ const rowOriginalTop = row[0].originalTop;
109
+ const rowOriginalBottom = Math.max(
110
+ ...row.map((entry) => entry.originalBottom)
111
+ );
112
+ if (previousOriginalBottom !== undefined) {
113
+ pendingGap += Math.max(
114
+ 0,
115
+ rowOriginalTop - previousOriginalBottom
116
+ );
117
+ }
118
+ previousOriginalBottom = rowOriginalBottom;
119
+
120
+ const visibleEntries = row.filter(
121
+ (entry) => !this.isEmptyLayoutObject(entry.object)
122
+ );
123
+ if (!visibleEntries.length) return;
124
+
125
+ const targetTop =
126
+ previousActualBottom === undefined
127
+ ? rowOriginalTop
128
+ : previousActualBottom + pendingGap;
129
+ visibleEntries.forEach((entry) => {
130
+ entry.object.set('top', targetTop / mmPerPx);
131
+ entry.object.setCoords();
132
+ });
133
+ previousActualBottom = Math.max(
134
+ ...visibleEntries.map(
135
+ (entry) =>
136
+ (Number(entry.object.top || 0) +
137
+ this.getActualLayoutHeight(entry.object)) *
138
+ mmPerPx
139
+ )
140
+ );
141
+ lastVisibleOriginalBottom = rowOriginalBottom;
142
+ pendingGap = 0;
143
+ });
144
+
145
+ this.canvas.requestRenderAll();
146
+ if (
147
+ settings.overflowMode !== 'expand' ||
148
+ previousActualBottom === undefined
149
+ ) {
150
+ return templateHeight;
151
+ }
152
+ const bottomSpace = Math.max(
153
+ 0,
154
+ templateHeight - lastVisibleOriginalBottom
155
+ );
156
+ return Math.max(
157
+ templateHeight,
158
+ previousActualBottom + bottomSpace
159
+ );
160
+ }
161
+
162
+ private getOriginalTop(
163
+ source: any,
164
+ object: fabric.Object,
165
+ mmPerPx: number
166
+ ) {
167
+ const top = Number(source?.top);
168
+ if (Number.isFinite(top)) return top * mmPerPx;
169
+ return this.getOriginMmValue(
170
+ source,
171
+ 'top',
172
+ Number(object.top || 0) * mmPerPx
173
+ );
174
+ }
175
+
176
+ private getOriginalHeight(
177
+ source: any,
178
+ object: fabric.Object,
179
+ mmPerPx: number
180
+ ) {
181
+ const height = Number(source?.height);
182
+ const scaleY = Number(source?.scaleY ?? 1);
183
+ if (Number.isFinite(height) && Number.isFinite(scaleY)) {
184
+ return Math.abs(height * scaleY) * mmPerPx;
185
+ }
186
+ return this.getOriginMmValue(
187
+ source,
188
+ 'height',
189
+ Number(object.getScaledHeight?.() || object.height || 0) *
190
+ mmPerPx
191
+ );
192
+ }
193
+
194
+ private getTemplateSourceObjects(templateContent: any) {
195
+ const sourceObjects = new Map<string, any>();
196
+ if (!Array.isArray(templateContent?.objects)) return sourceObjects;
197
+ templateContent.objects.forEach((source: any, index: number) => {
198
+ if (source?.id) sourceObjects.set(`id:${source.id}`, source);
199
+ sourceObjects.set(`index:${index}`, source);
200
+ });
201
+ return sourceObjects;
202
+ }
203
+
204
+ private getSourceObject(
205
+ object: any,
206
+ sourceObjects: Map<string, any>
207
+ ) {
208
+ if (object?.id) {
209
+ const source = sourceObjects.get(`id:${object.id}`);
210
+ if (source) return source;
211
+ }
212
+ const objects = this.canvas.getObjects().filter(this.isPrintableObject);
213
+ const index = objects.indexOf(object);
214
+ return sourceObjects.get(`index:${index}`);
215
+ }
216
+
217
+ private getOriginMmValue(
218
+ source: any,
219
+ field: 'top' | 'height',
220
+ fallback: number
221
+ ) {
222
+ const originalValue = source?._originSize?.mm?.[field];
223
+ if (
224
+ originalValue === undefined ||
225
+ originalValue === null ||
226
+ originalValue === ''
227
+ ) {
228
+ return fallback;
229
+ }
230
+ const value = Number(originalValue);
231
+ return Number.isFinite(value) ? value : fallback;
232
+ }
233
+
234
+ private preparePrintLayoutObject(object: any) {
235
+ if (object?.extensionType !== 'imageTextList') return;
236
+ if (object.extension?._clipContent === true) return;
237
+
238
+ // Design canvases can opt into clipping, but print/layout canvases should
239
+ // measure and render the natural image-text content height.
240
+ if (object.clipPath) object.set('clipPath', undefined);
241
+ object.set({
242
+ objectCaching: false,
243
+ dirty: true,
244
+ });
245
+ }
246
+
247
+ private isPrintableObject(object: any) {
248
+ return (
249
+ object?.id !== 'workspace' &&
250
+ object?.id !== 'coverMask' &&
251
+ object?.type !== 'GuideLine'
252
+ );
253
+ }
254
+
255
+ private isEmptyLayoutObject(object: any) {
256
+ if (object?.visible === false) return true;
257
+ const field = object?.extension?._field_;
258
+ if (!field) return false;
259
+ if (object.type === 'textbox') {
260
+ return String(object.text ?? '') === '';
261
+ }
262
+ if (['barcode', 'qrcode'].includes(object.extensionType)) {
263
+ return (
264
+ String(object.extension?.value ?? '') === '' &&
265
+ !this.hasVisibleImageSource(object)
266
+ );
267
+ }
268
+ if (object.extensionType === 'imageTextList') {
269
+ return (
270
+ !Array.isArray(object.extension?.items) ||
271
+ object.extension.items.length === 0
272
+ );
273
+ }
274
+ return false;
275
+ }
276
+
277
+ private hasVisibleImageSource(object: any) {
278
+ const src = String(object?.getSrc?.() ?? object?.src ?? '');
279
+ return src !== '' && /^data:image\//i.test(src);
280
+ }
281
+
282
+ private getActualLayoutHeight(object: any) {
283
+ if (object?.extensionType !== 'imageTextList') {
284
+ return Number(
285
+ object.getScaledHeight?.() || object.height || 0
286
+ );
287
+ }
288
+
289
+ const children = object.getObjects?.() || object._objects || [];
290
+ const contentChildren = children.slice(1);
291
+ if (!contentChildren.length) return 0;
292
+
293
+ const groupHeight = Number(object.height || 0);
294
+ const groupScaleY = Math.abs(Number(object.scaleY ?? 1));
295
+ const contentBottom = Math.max(
296
+ ...contentChildren.map(
297
+ (child: any) =>
298
+ Number(child.top || 0) +
299
+ groupHeight / 2 +
300
+ Number(
301
+ child.getScaledHeight?.() || child.height || 0
302
+ )
303
+ )
304
+ );
305
+ return Math.max(0, contentBottom) * groupScaleY;
306
+ }
307
+ }
308
+
309
+ export default ActualContentLayoutPlugin;
@@ -74,9 +74,11 @@ class CopyPlugin implements IPluginTempl {
74
74
  this.editor.addSetAndSyncByUnit(cloned);
75
75
  if (cloned.extensionType === 'barcode') {
76
76
  this.editor.initBarcodeEvents(cloned)
77
- } else if (cloned.extensionType === 'qrcode') {
78
- this.editor.initQrcodeEvents(cloned);
79
- }
77
+ } else if (cloned.extensionType === 'qrcode') {
78
+ this.editor.initQrcodeEvents(cloned);
79
+ } else if (cloned.extensionType === 'imageTextList') {
80
+ this.editor.initImageTextListEvents(cloned);
81
+ }
80
82
  canvas.add(cloned);
81
83
  canvas.setActiveObject(cloned);
82
84
  canvas.requestRenderAll();
@@ -86,7 +86,11 @@ class HistoryPlugin implements IPluginTempl {
86
86
  // 加载状态
87
87
  private _loadState(state: string, eventName: string, callback?: callback) {
88
88
  this.isLoading = true;
89
- this.isProcessing = true;
89
+ this.isProcessing = true;
90
+ const activeIds = this.canvas
91
+ .getActiveObjects()
92
+ .map((object: any) => object?.id)
93
+ .filter(Boolean);
90
94
 
91
95
  // 处理 workspace 的特殊情况
92
96
  const parsedState = JSON.parse(state);
@@ -97,17 +101,53 @@ class HistoryPlugin implements IPluginTempl {
97
101
  workspace.evented = false;
98
102
  }
99
103
 
100
- this.canvas.loadFromJSON(state, () => {
101
- this.canvas.renderAll();
102
- this.canvas.fire(eventName);
103
- this.isProcessing = false;
104
- this.isLoading = false;
105
- callback?.();
106
- });
107
- }
108
-
109
- // 获取历史记录状态
110
- private getState() {
104
+ const hookPromises: Promise<void>[] = [];
105
+ this.canvas.loadFromJSON(
106
+ state,
107
+ () => {
108
+ Promise.all(hookPromises).then(() => {
109
+ this.restoreActiveObjects(activeIds);
110
+ this.canvas.renderAll();
111
+ this.canvas.fire(eventName);
112
+ this.isProcessing = false;
113
+ this.isLoading = false;
114
+ callback?.();
115
+ });
116
+ },
117
+ (originObject: any, fabricObject: fabric.Object) => {
118
+ hookPromises.push(
119
+ new Promise((resolve) => {
120
+ this.editor.hooksEntity.hookTransformObjectEnd.callAsync(
121
+ { originObject, fabricObject },
122
+ () => resolve()
123
+ );
124
+ })
125
+ );
126
+ }
127
+ );
128
+ }
129
+
130
+ private restoreActiveObjects(activeIds: string[]) {
131
+ this.canvas.discardActiveObject();
132
+ if (!activeIds.length) return;
133
+
134
+ const objects = this.canvas
135
+ .getObjects()
136
+ .filter((object: any) => activeIds.includes(object?.id));
137
+ if (objects.length === 1) {
138
+ this.canvas.setActiveObject(objects[0]);
139
+ return;
140
+ }
141
+ if (objects.length > 1) {
142
+ const selection = new fabric.ActiveSelection(objects, {
143
+ canvas: this.canvas,
144
+ });
145
+ this.canvas.setActiveObject(selection);
146
+ }
147
+ }
148
+
149
+ // 获取历史记录状态
150
+ private getState() {
111
151
  return {
112
152
  undoCount: this.currentIndex - 1,
113
153
  redoCount: this.stack.length - this.currentIndex,