@borurio-print/print-designer 1.0.4 → 1.0.6

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,13 +1,26 @@
1
1
  import type { TextBoxDesignerElement } from './types';
2
+ export declare const DEFAULT_TEXT_BOX_PADDING_MM = 0.5;
2
3
  export interface TextBoxLayoutResult {
3
4
  lines: string[];
4
5
  fontSizePt: number;
5
6
  fontSizeMm: number;
6
7
  lineHeightMm: number;
7
8
  truncated: boolean;
9
+ textAnchor: 'start' | 'middle' | 'end';
10
+ textXOffsetMm: number;
11
+ textYOffsetMm: number;
12
+ }
13
+ export interface TextBoxInitialSize {
14
+ widthMm: number;
15
+ heightMm: number;
8
16
  }
9
17
  /**
10
18
  * 把运行时文字排入固定毫米矩形。设计画布和 PDF 共用该结果,避免预览与打印
11
19
  * 分别依赖 CSS/SVG 的隐式换行规则而产生差异。
12
20
  */
13
21
  export declare function layoutTextBox(element: TextBoxDesignerElement, content: string): TextBoxLayoutResult;
22
+ /**
23
+ * 根据设计时可见内容计算新建文字框的初始尺寸。尺寸只在创建时计算,之后用户
24
+ * 调整的宽高不会因为编辑内容或替换打印数据而被覆盖。
25
+ */
26
+ export declare function measureInitialTextBoxSize(element: Pick<TextBoxDesignerElement, 'content' | 'fontSizePt' | 'fontWeight' | 'lineHeight' | 'paddingMm'>, maximumWidthMm: number, maximumHeightMm: number): TextBoxInitialSize;
@@ -70,7 +70,7 @@ export interface BusinessFieldGroup {
70
70
  */
71
71
  export type DesignerElementType = 'text' | 'textBox' | 'rectangle' | 'horizontalLine' | 'verticalLine' | 'qrcode' | 'barcode' | 'image' | 'serialNumber' | 'pageNumber' | 'time' | 'table' | 'pdf';
72
72
  /** 右侧属性面板中可独立组合的属性编辑器标识。 */
73
- export type ElementPropertyKey = 'displayType' | 'content' | 'textBoxFitMode' | 'textBoxOverflowMode' | 'lineHeight' | 'minFontSize' | 'imageSource' | 'x' | 'y' | 'width' | 'height' | 'fontSize' | 'fontWeight' | 'strokeWidth' | 'rotation' | 'timeMode' | 'includeTime' | 'fixedTime' | 'tableConfig' | 'pdfSource' | 'pdfCropMode' | 'pdfCropRatio';
73
+ export type ElementPropertyKey = 'displayType' | 'content' | 'textHorizontalAlign' | 'textVerticalAlign' | 'textBoxFitMode' | 'textBoxOverflowMode' | 'lineHeight' | 'minFontSize' | 'imageSource' | 'x' | 'y' | 'width' | 'height' | 'fontSize' | 'fontWeight' | 'strokeWidth' | 'rotation' | 'timeMode' | 'includeTime' | 'fixedTime' | 'tableConfig' | 'pdfSource' | 'pdfCropMode' | 'pdfCropRatio';
74
74
  /**
75
75
  * 单个属性编辑器的能力与数值约束。
76
76
  * 数值范围跟随组件类型配置,输入框和 SVG 控制点共用,避免两处规则不一致。
@@ -84,6 +84,10 @@ export interface ElementPropertyConfig {
84
84
  /** 属性是否适用于元素当前状态,例如固定时间只在“固定”模式下展示。 */
85
85
  visibleWhen?: (element: DesignerElement) => boolean;
86
86
  }
87
+ /** 元素相对标签画布持续生效的水平对齐规则。 */
88
+ export type CanvasHorizontalAlign = 'left' | 'center' | 'right';
89
+ /** 元素相对标签画布持续生效的垂直对齐规则。 */
90
+ export type CanvasVerticalAlign = 'top' | 'center' | 'bottom';
87
91
  /**
88
92
  * 所有可编辑元素共用的布局数据。
89
93
  * 坐标和尺寸统一使用毫米,rotation 统一使用角度,避免保存屏幕像素后
@@ -98,6 +102,10 @@ export interface BaseDesignerElement {
98
102
  heightMm: number;
99
103
  rotation: number;
100
104
  zIndex: number;
105
+ /** 缺少时沿用模板保存的 xMm,不做运行时重排。 */
106
+ canvasHorizontalAlign?: CanvasHorizontalAlign;
107
+ /** 缺少时沿用模板保存的 yMm,不做运行时重排。 */
108
+ canvasVerticalAlign?: CanvasVerticalAlign;
101
109
  }
102
110
  /** 普通文字元素独有的排版属性。 */
103
111
  export interface TextDesignerElement extends BaseDesignerElement {
@@ -260,6 +268,10 @@ export interface TableDesignerElement extends BaseDesignerElement {
260
268
  export type TextBoxFitMode = 'fixed' | 'shrinkFont';
261
269
  /** 固定区域在最小字号下仍放不下内容时采用的溢出方式。 */
262
270
  export type TextBoxOverflowMode = 'clip' | 'ellipsis';
271
+ /** 文字框内容在固定区域内的水平对齐方式。 */
272
+ export type TextHorizontalAlign = 'left' | 'center' | 'right';
273
+ /** 文字框内容在固定区域内的垂直对齐方式。 */
274
+ export type TextVerticalAlign = 'top' | 'middle' | 'bottom';
263
275
  /**
264
276
  * 多行文字框使用固定毫米宽高进行排版。
265
277
  * 与普通文字不同,拖动控制点只改变文本框,不会同步缩放字号。
@@ -277,6 +289,12 @@ export interface TextBoxDesignerElement extends BaseDesignerElement {
277
289
  overflowMode: TextBoxOverflowMode;
278
290
  /** shrinkFont 模式允许缩小到的最小字号。 */
279
291
  minFontSizePt: number;
292
+ /** 新建文字框使用内边距;旧模板缺少该字段时按 0 处理。 */
293
+ paddingMm?: number;
294
+ /** 旧模板缺少该字段时按左对齐处理。 */
295
+ horizontalAlign?: TextHorizontalAlign;
296
+ /** 旧模板缺少该字段时按顶部对齐处理。 */
297
+ verticalAlign?: TextVerticalAlign;
280
298
  }
281
299
  /** 当前已经具备创建、属性编辑和 SVG 渲染能力的元素集合。 */
282
300
  export type DesignerElement = TextDesignerElement | TextBoxDesignerElement | RectangleDesignerElement | LineDesignerElement | QrcodeDesignerElement | BarcodeDesignerElement | ImageDesignerElement | SerialNumberDesignerElement | PageNumberDesignerElement | TimeDesignerElement | TableDesignerElement | PdfDesignerElement;