@hufe921/canvas-editor 0.9.29 → 0.9.31

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.
@@ -23,13 +23,18 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
  var index = "";
26
- const version = "0.9.29";
26
+ const version = "0.9.31";
27
27
  var MaxHeightRatio;
28
28
  (function(MaxHeightRatio2) {
29
29
  MaxHeightRatio2["HALF"] = "half";
30
30
  MaxHeightRatio2["ONE_THIRD"] = "one-third";
31
31
  MaxHeightRatio2["QUARTER"] = "quarter";
32
32
  })(MaxHeightRatio || (MaxHeightRatio = {}));
33
+ var NumberType;
34
+ (function(NumberType2) {
35
+ NumberType2["ARABIC"] = "arabic";
36
+ NumberType2["CHINESE"] = "chinese";
37
+ })(NumberType || (NumberType = {}));
33
38
  const ZERO = "\u200B";
34
39
  const WRAP = "\n";
35
40
  const PUNCTUATION_LIST = ["\xB7", "\u3001", ":", "\uFF1A", ",", "\uFF0C", ".", "\u3002", ";", "\uFF1B", "?", "\uFF1F", "!", "\uFF01"];
@@ -147,6 +152,26 @@ function nextTick(fn) {
147
152
  fn();
148
153
  }, 0);
149
154
  }
155
+ function convertNumberToChinese(num) {
156
+ const chineseNum = ["\u96F6", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D", "\u4E03", "\u516B", "\u4E5D"];
157
+ const chineseUnit = ["", "\u5341", "\u767E", "\u5343", "\u4E07", "\u5341", "\u767E", "\u5343", "\u4EBF", "\u5341", "\u767E", "\u5343", "\u4E07", "\u5341", "\u767E", "\u5343", "\u4EBF"];
158
+ if (!num || isNaN(num))
159
+ return "\u96F6";
160
+ const numStr = num.toString().split("");
161
+ let result = "";
162
+ for (let i = 0; i < numStr.length; i++) {
163
+ const desIndex = numStr.length - 1 - i;
164
+ result = `${chineseUnit[i]}${result}`;
165
+ result = `${chineseNum[Number(numStr[desIndex])]}${result}`;
166
+ }
167
+ result = result.replace(/零(千|百|十)/g, "\u96F6").replace(/十零/g, "\u5341");
168
+ result = result.replace(/零+/g, "\u96F6");
169
+ result = result.replace(/零亿/g, "\u4EBF").replace(/零万/g, "\u4E07");
170
+ result = result.replace(/亿万/g, "\u4EBF");
171
+ result = result.replace(/零+$/, "");
172
+ result = result.replace(/^一十/g, "\u5341");
173
+ return result;
174
+ }
150
175
  const CURSOR_AGENT_HEIGHT = 12;
151
176
  const defaultCursorOption = {
152
177
  width: 1,
@@ -172,6 +197,7 @@ var ElementType;
172
197
  ElementType2["TAB"] = "tab";
173
198
  ElementType2["DATE"] = "date";
174
199
  ElementType2["BLOCK"] = "block";
200
+ ElementType2["TITLE"] = "title";
175
201
  })(ElementType || (ElementType = {}));
176
202
  const EDITOR_ELEMENT_STYLE_ATTR = [
177
203
  "bold",
@@ -197,7 +223,9 @@ const EDITOR_ELEMENT_COPY_ATTR = [
197
223
  "url",
198
224
  "hyperlinkId",
199
225
  "dateId",
200
- "dateFormat"
226
+ "dateFormat",
227
+ "level",
228
+ "titleId"
201
229
  ];
202
230
  const EDITOR_ELEMENT_ZIP_ATTR = [
203
231
  "type",
@@ -222,7 +250,8 @@ const EDITOR_ELEMENT_ZIP_ATTR = [
222
250
  "control",
223
251
  "checkbox",
224
252
  "dateFormat",
225
- "block"
253
+ "block",
254
+ "level"
226
255
  ];
227
256
  const TEXTLIKE_ELEMENT_TYPE = [
228
257
  ElementType.TEXT,
@@ -238,6 +267,51 @@ const INLINE_ELEMENT_TYPE = [
238
267
  ElementType.SEPARATOR,
239
268
  ElementType.TABLE
240
269
  ];
270
+ const INLINE_NODE_NAME = [
271
+ "HR",
272
+ "TABLE"
273
+ ];
274
+ var TitleLevel;
275
+ (function(TitleLevel2) {
276
+ TitleLevel2["FIRST"] = "first";
277
+ TitleLevel2["SECOND"] = "second";
278
+ TitleLevel2["THIRD"] = "third";
279
+ TitleLevel2["FOURTH"] = "fourth";
280
+ TitleLevel2["FIFTH"] = "fifth";
281
+ TitleLevel2["SIXTH"] = "sixth";
282
+ })(TitleLevel || (TitleLevel = {}));
283
+ const defaultTitleOption = {
284
+ defaultFirstSize: 26,
285
+ defaultSecondSize: 24,
286
+ defaultThirdSize: 22,
287
+ defaultFourthSize: 20,
288
+ defaultFifthSize: 18,
289
+ defaultSixthSize: 16
290
+ };
291
+ const titleSizeMapping = {
292
+ [TitleLevel.FIRST]: "defaultFirstSize",
293
+ [TitleLevel.SECOND]: "defaultSecondSize",
294
+ [TitleLevel.THIRD]: "defaultThirdSize",
295
+ [TitleLevel.FOURTH]: "defaultFourthSize",
296
+ [TitleLevel.FIFTH]: "defaultFifthSize",
297
+ [TitleLevel.SIXTH]: "defaultSixthSize"
298
+ };
299
+ const titleOrderNumberMapping = {
300
+ [TitleLevel.FIRST]: 1,
301
+ [TitleLevel.SECOND]: 2,
302
+ [TitleLevel.THIRD]: 3,
303
+ [TitleLevel.FOURTH]: 4,
304
+ [TitleLevel.FIFTH]: 5,
305
+ [TitleLevel.SIXTH]: 6
306
+ };
307
+ const titleNodeNameMapping = {
308
+ "H1": TitleLevel.FIRST,
309
+ "H2": TitleLevel.SECOND,
310
+ "H3": TitleLevel.THIRD,
311
+ "H4": TitleLevel.FOURTH,
312
+ "H5": TitleLevel.FIFTH,
313
+ "H6": TitleLevel.SIXTH
314
+ };
241
315
  var ControlType;
242
316
  (function(ControlType2) {
243
317
  ControlType2["TEXT"] = "text";
@@ -3268,6 +3342,17 @@ const defaultControlOption = {
3268
3342
  prefix: "{",
3269
3343
  postfix: "}"
3270
3344
  };
3345
+ function unzipElementList(elementList) {
3346
+ const result = [];
3347
+ for (let v = 0; v < elementList.length; v++) {
3348
+ const valueItem = elementList[v];
3349
+ const textList = splitText(valueItem.value);
3350
+ for (let d = 0; d < textList.length; d++) {
3351
+ result.push(__spreadProps(__spreadValues({}, valueItem), { value: textList[d] }));
3352
+ }
3353
+ }
3354
+ return result;
3355
+ }
3271
3356
  function formatElementList(elementList, options) {
3272
3357
  var _a;
3273
3358
  const { isHandleFirstElement, editorOptions } = __spreadValues({
@@ -3292,6 +3377,9 @@ function formatElementList(elementList, options) {
3292
3377
  if (!tr.minHeight || tr.minHeight < editorOptions.defaultTrMinHeight) {
3293
3378
  tr.minHeight = editorOptions.defaultTrMinHeight;
3294
3379
  }
3380
+ if (tr.height < tr.minHeight) {
3381
+ tr.height = tr.minHeight;
3382
+ }
3295
3383
  for (let d = 0; d < tr.tdList.length; d++) {
3296
3384
  const td = tr.tdList[d];
3297
3385
  const tdId = getUUID();
@@ -3309,16 +3397,9 @@ function formatElementList(elementList, options) {
3309
3397
  }
3310
3398
  }
3311
3399
  } else if (el.type === ElementType.HYPERLINK) {
3312
- const valueList = el.valueList || [];
3313
3400
  elementList.splice(i, 1);
3401
+ const valueList = unzipElementList(el.valueList || []);
3314
3402
  if (valueList.length) {
3315
- if (valueList[0].value.length > 1) {
3316
- const deleteValue = valueList.splice(0, 1)[0];
3317
- const deleteTextList = splitText(deleteValue.value);
3318
- for (let d = 0; d < deleteTextList.length; d++) {
3319
- valueList.splice(d, 0, __spreadProps(__spreadValues({}, deleteValue), { value: deleteTextList[d] }));
3320
- }
3321
- }
3322
3403
  const hyperlinkId = getUUID();
3323
3404
  for (let v = 0; v < valueList.length; v++) {
3324
3405
  const value = valueList[v];
@@ -3331,16 +3412,9 @@ function formatElementList(elementList, options) {
3331
3412
  }
3332
3413
  i--;
3333
3414
  } else if (el.type === ElementType.DATE) {
3334
- const valueList = el.valueList || [];
3335
3415
  elementList.splice(i, 1);
3416
+ const valueList = unzipElementList(el.valueList || []);
3336
3417
  if (valueList.length) {
3337
- if (valueList[0].value.length > 1) {
3338
- const deleteValue = valueList.splice(0, 1)[0];
3339
- const deleteTextList = splitText(deleteValue.value);
3340
- for (let d = 0; d < deleteTextList.length; d++) {
3341
- valueList.splice(d, 0, __spreadProps(__spreadValues({}, deleteValue), { value: deleteTextList[d] }));
3342
- }
3343
- }
3344
3418
  const dateId = getUUID();
3345
3419
  for (let v = 0; v < valueList.length; v++) {
3346
3420
  const value = valueList[v];
@@ -3352,6 +3426,32 @@ function formatElementList(elementList, options) {
3352
3426
  }
3353
3427
  }
3354
3428
  i--;
3429
+ } else if (el.type === ElementType.TITLE) {
3430
+ elementList.splice(i, 1);
3431
+ const valueList = el.valueList || [];
3432
+ formatElementList(valueList, __spreadProps(__spreadValues({}, options), {
3433
+ isHandleFirstElement: false
3434
+ }));
3435
+ if (valueList.length) {
3436
+ const titleId = getUUID();
3437
+ const titleOptions = editorOptions.title;
3438
+ for (let v = 0; v < valueList.length; v++) {
3439
+ const value = valueList[v];
3440
+ value.titleId = titleId;
3441
+ value.level = el.level;
3442
+ if (isTextLikeElement(value)) {
3443
+ if (!value.size) {
3444
+ value.size = titleOptions[titleSizeMapping[value.level]];
3445
+ }
3446
+ if (value.bold === void 0) {
3447
+ value.bold = true;
3448
+ }
3449
+ }
3450
+ elementList.splice(i, 0, value);
3451
+ i++;
3452
+ }
3453
+ }
3454
+ i--;
3355
3455
  } else if (el.type === ElementType.CONTROL) {
3356
3456
  const { prefix, postfix, value, placeholder, code, type, valueSets } = el.control;
3357
3457
  const controlId = getUUID();
@@ -3591,6 +3691,27 @@ function zipElementList(payload) {
3591
3691
  }
3592
3692
  dateElement.valueList = zipElementList(valueList);
3593
3693
  element = dateElement;
3694
+ } else if (element.titleId && element.level) {
3695
+ const titleId = element.titleId;
3696
+ const level = element.level;
3697
+ const titleElement = {
3698
+ type: ElementType.TITLE,
3699
+ value: "",
3700
+ level
3701
+ };
3702
+ const valueList = [];
3703
+ while (e < elementList.length) {
3704
+ const titleE = elementList[e];
3705
+ if (titleId !== titleE.titleId) {
3706
+ e--;
3707
+ break;
3708
+ }
3709
+ delete titleE.level;
3710
+ valueList.push(titleE);
3711
+ e++;
3712
+ }
3713
+ titleElement.valueList = zipElementList(valueList);
3714
+ element = titleElement;
3594
3715
  } else if (element.type === ElementType.CONTROL) {
3595
3716
  const controlId = element.controlId;
3596
3717
  const control = element.control;
@@ -3652,6 +3773,9 @@ function getElementRowFlex(node) {
3652
3773
  return RowFlex.LEFT;
3653
3774
  }
3654
3775
  }
3776
+ function isTextLikeElement(element) {
3777
+ return !element.type || TEXTLIKE_ELEMENT_TYPE.includes(element.type);
3778
+ }
3655
3779
  function writeClipboardItem(text, html) {
3656
3780
  if (!text || !html)
3657
3781
  return;
@@ -3677,10 +3801,36 @@ function writeClipboardItem(text, html) {
3677
3801
  fakeElement.remove();
3678
3802
  }
3679
3803
  }
3804
+ function convertElementToDom(element, options) {
3805
+ const isBlock = element.rowFlex === RowFlex.CENTER || element.rowFlex === RowFlex.RIGHT;
3806
+ const dom = document.createElement(isBlock ? "p" : "span");
3807
+ dom.style.fontFamily = element.font || options.defaultFont;
3808
+ if (element.rowFlex) {
3809
+ const isAlignment = element.rowFlex === RowFlex.ALIGNMENT;
3810
+ dom.style.textAlign = isAlignment ? "justify" : element.rowFlex;
3811
+ }
3812
+ if (element.color) {
3813
+ dom.style.color = element.color;
3814
+ }
3815
+ if (element.bold) {
3816
+ dom.style.fontWeight = "600";
3817
+ }
3818
+ if (element.italic) {
3819
+ dom.style.fontStyle = "italic";
3820
+ }
3821
+ if (element.size) {
3822
+ dom.style.fontSize = `${element.size}px`;
3823
+ }
3824
+ if (element.highlight) {
3825
+ dom.style.backgroundColor = element.highlight;
3826
+ }
3827
+ dom.innerText = element.value.replace(new RegExp(`${ZERO}`, "g"), "\n");
3828
+ return dom;
3829
+ }
3680
3830
  function writeElementList(elementList, options) {
3681
- const clipboardDom = document.createElement("div");
3682
3831
  function buildDomFromElementList(payload) {
3683
3832
  var _a, _b, _c, _d, _e;
3833
+ const clipboardDom2 = document.createElement("div");
3684
3834
  for (let e = 0; e < payload.length; e++) {
3685
3835
  const element = payload[e];
3686
3836
  if (element.type === ElementType.TABLE) {
@@ -3695,19 +3845,25 @@ function writeElementList(elementList, options) {
3695
3845
  const td = tr.tdList[d];
3696
3846
  tdDom.colSpan = td.colspan;
3697
3847
  tdDom.rowSpan = td.rowspan;
3698
- tdDom.innerText = ((_a = td.value[0]) == null ? void 0 : _a.value) || "";
3848
+ const childDom = buildDomFromElementList(zipElementList(td.value));
3849
+ tdDom.innerHTML = childDom.innerHTML;
3699
3850
  trDom.append(tdDom);
3700
3851
  }
3701
3852
  tableDom.append(trDom);
3702
3853
  }
3703
- clipboardDom.append(tableDom);
3854
+ clipboardDom2.append(tableDom);
3704
3855
  } else if (element.type === ElementType.HYPERLINK) {
3705
3856
  const a = document.createElement("a");
3706
- a.innerText = element.valueList[0].value;
3857
+ a.innerText = element.valueList.map((v) => v.value).join("");
3707
3858
  if (element.url) {
3708
3859
  a.href = element.url;
3709
3860
  }
3710
- clipboardDom.append(a);
3861
+ clipboardDom2.append(a);
3862
+ } else if (element.type === ElementType.TITLE) {
3863
+ const h = document.createElement(`h${titleOrderNumberMapping[element.level]}`);
3864
+ const childDom = buildDomFromElementList(zipElementList(element.valueList));
3865
+ h.innerHTML = childDom.innerHTML;
3866
+ clipboardDom2.append(h);
3711
3867
  } else if (element.type === ElementType.IMAGE) {
3712
3868
  const img = document.createElement("img");
3713
3869
  if (element.value) {
@@ -3715,56 +3871,39 @@ function writeElementList(elementList, options) {
3715
3871
  img.width = element.width;
3716
3872
  img.height = element.height;
3717
3873
  }
3718
- clipboardDom.append(img);
3874
+ clipboardDom2.append(img);
3719
3875
  } else if (element.type === ElementType.SEPARATOR) {
3720
3876
  const hr = document.createElement("hr");
3721
- clipboardDom.append(hr);
3877
+ clipboardDom2.append(hr);
3722
3878
  } else if (element.type === ElementType.CHECKBOX) {
3723
3879
  const checkbox = document.createElement("input");
3724
3880
  checkbox.type = "checkbox";
3725
- if ((_b = element.checkbox) == null ? void 0 : _b.value) {
3881
+ if ((_a = element.checkbox) == null ? void 0 : _a.value) {
3726
3882
  checkbox.setAttribute("checked", "true");
3727
3883
  }
3728
- clipboardDom.append(checkbox);
3884
+ clipboardDom2.append(checkbox);
3729
3885
  } else if (!element.type || element.type === ElementType.LATEX || TEXTLIKE_ELEMENT_TYPE.includes(element.type)) {
3730
3886
  let text2 = "";
3731
3887
  if (element.type === ElementType.CONTROL) {
3732
- text2 = ((_d = (_c = element.control.value) == null ? void 0 : _c[0]) == null ? void 0 : _d.value) || "";
3888
+ text2 = ((_c = (_b = element.control.value) == null ? void 0 : _b[0]) == null ? void 0 : _c.value) || "";
3733
3889
  } else if (element.type === ElementType.DATE) {
3734
- text2 = ((_e = element.valueList) == null ? void 0 : _e.map((v) => v.value).join("")) || "";
3890
+ text2 = ((_d = element.valueList) == null ? void 0 : _d.map((v) => v.value).join("")) || "";
3735
3891
  } else {
3736
3892
  text2 = element.value;
3737
3893
  }
3738
3894
  if (!text2)
3739
3895
  continue;
3740
- const isBlock = element.rowFlex === RowFlex.CENTER || element.rowFlex === RowFlex.RIGHT;
3741
- const dom = document.createElement(isBlock ? "p" : "span");
3742
- dom.innerText = text2.replace(new RegExp(`${ZERO}`, "g"), "\n");
3743
- dom.style.fontFamily = element.font || options.defaultFont;
3744
- if (element.rowFlex) {
3745
- const isAlignment = element.rowFlex === RowFlex.ALIGNMENT;
3746
- dom.style.textAlign = isAlignment ? "justify" : element.rowFlex;
3747
- }
3748
- if (element.color) {
3749
- dom.style.color = element.color;
3750
- }
3751
- if (element.bold) {
3752
- dom.style.fontWeight = "600";
3753
- }
3754
- if (element.italic) {
3755
- dom.style.fontStyle = "italic";
3756
- }
3757
- if (element.size) {
3758
- dom.style.fontSize = `${element.size}px`;
3759
- }
3760
- if (element.highlight) {
3761
- dom.style.backgroundColor = element.highlight;
3896
+ if (((_e = payload[e - 1]) == null ? void 0 : _e.type) === ElementType.TITLE) {
3897
+ text2 = text2.replace(/^\n/, "");
3762
3898
  }
3763
- clipboardDom.append(dom);
3899
+ const dom = convertElementToDom(element, options);
3900
+ dom.innerText = text2.replace(new RegExp(`${ZERO}`, "g"), "\n");
3901
+ clipboardDom2.append(dom);
3764
3902
  }
3765
3903
  }
3904
+ return clipboardDom2;
3766
3905
  }
3767
- buildDomFromElementList(zipElementList(elementList));
3906
+ const clipboardDom = buildDomFromElementList(zipElementList(elementList));
3768
3907
  document.body.append(clipboardDom);
3769
3908
  const text = clipboardDom.innerText;
3770
3909
  clipboardDom.remove();
@@ -3818,6 +3957,20 @@ function getElementListByHTML(htmlText, options) {
3818
3957
  url: aElement.href
3819
3958
  });
3820
3959
  }
3960
+ } else if (/H[1-6]/.test(node.nodeName)) {
3961
+ const hElement = node;
3962
+ const valueList = getElementListByHTML(hElement.innerHTML, options);
3963
+ elementList.push({
3964
+ value: "",
3965
+ type: ElementType.TITLE,
3966
+ level: titleNodeNameMapping[node.nodeName],
3967
+ valueList
3968
+ });
3969
+ if (node.nextSibling && !INLINE_NODE_NAME.includes(node.nextSibling.nodeName)) {
3970
+ elementList.push({
3971
+ value: "\n"
3972
+ });
3973
+ }
3821
3974
  } else if (node.nodeName === "HR") {
3822
3975
  elementList.push({
3823
3976
  value: "\n",
@@ -3849,12 +4002,11 @@ function getElementListByHTML(htmlText, options) {
3849
4002
  };
3850
4003
  trElement.querySelectorAll("th,td").forEach((tdElement) => {
3851
4004
  const tableCell = tdElement;
4005
+ const valueList = getElementListByHTML(tableCell.innerHTML, options);
3852
4006
  const td = {
3853
4007
  colspan: tableCell.colSpan,
3854
4008
  rowspan: tableCell.rowSpan,
3855
- value: [{
3856
- value: tableCell.innerText
3857
- }]
4009
+ value: valueList
3858
4010
  };
3859
4011
  tr.tdList.push(td);
3860
4012
  });
@@ -5897,16 +6049,15 @@ class RangeManager {
5897
6049
  setRangeStyle() {
5898
6050
  if (!this.listener.rangeStyleChange)
5899
6051
  return;
5900
- let curElementList = this.getSelection();
5901
- if (!curElementList) {
5902
- const elementList = this.draw.getElementList();
5903
- const { endIndex } = this.range;
5904
- const index2 = ~endIndex ? endIndex : 0;
5905
- curElementList = [elementList[index2]];
5906
- }
5907
- const curElement = curElementList[curElementList.length - 1];
6052
+ const { endIndex } = this.range;
6053
+ const index2 = ~endIndex ? endIndex : 0;
6054
+ const elementList = this.draw.getElementList();
6055
+ const endElement = elementList[index2];
6056
+ const endNextElement = elementList[index2 + 1];
6057
+ const curElement = endElement.value === ZERO && endNextElement ? endNextElement : endElement;
5908
6058
  if (!curElement)
5909
6059
  return;
6060
+ const curElementList = this.getSelection() || [curElement];
5910
6061
  const type = curElement.type || ElementType.TEXT;
5911
6062
  const font = curElement.font || this.options.defaultFont;
5912
6063
  const size = curElement.size || this.options.defaultSize;
@@ -5919,6 +6070,7 @@ class RangeManager {
5919
6070
  const rowFlex = curElement.rowFlex || null;
5920
6071
  const rowMargin = curElement.rowMargin || this.options.defaultRowMargin;
5921
6072
  const dashArray = curElement.dashArray || [];
6073
+ const level = curElement.level || null;
5922
6074
  const painter = !!this.draw.getPainterStyle();
5923
6075
  const undo = this.historyManager.isCanUndo();
5924
6076
  const redo = this.historyManager.isCanRedo();
@@ -5937,7 +6089,8 @@ class RangeManager {
5937
6089
  highlight,
5938
6090
  rowFlex,
5939
6091
  rowMargin,
5940
- dashArray
6092
+ dashArray,
6093
+ level
5941
6094
  });
5942
6095
  }
5943
6096
  recoveryRangeStyle() {
@@ -5964,7 +6117,8 @@ class RangeManager {
5964
6117
  highlight: null,
5965
6118
  rowFlex: null,
5966
6119
  rowMargin,
5967
- dashArray: []
6120
+ dashArray: [],
6121
+ level: null
5968
6122
  });
5969
6123
  }
5970
6124
  shrinkBoundary() {
@@ -6500,6 +6654,19 @@ class TextParticle {
6500
6654
  this.ctx.restore();
6501
6655
  }
6502
6656
  }
6657
+ const FORMAT_PLACEHOLDER = {
6658
+ PAGE_NO: "{pageNo}",
6659
+ PAGE_COUNT: "{pageCount}"
6660
+ };
6661
+ const defaultPageNumberOption = {
6662
+ bottom: 60,
6663
+ size: 12,
6664
+ font: "Yahei",
6665
+ color: "#000000",
6666
+ rowFlex: RowFlex.CENTER,
6667
+ format: FORMAT_PLACEHOLDER.PAGE_NO,
6668
+ numberType: NumberType.ARABIC
6669
+ };
6503
6670
  class PageNumber {
6504
6671
  constructor(draw) {
6505
6672
  __publicField(this, "draw");
@@ -6508,8 +6675,20 @@ class PageNumber {
6508
6675
  this.options = draw.getOptions();
6509
6676
  }
6510
6677
  render(ctx, pageNo) {
6511
- const { pageNumber: { size, font, color, rowFlex }, scale, pageMode } = this.options;
6512
- const text = `${pageNo + 1}`;
6678
+ const { pageNumber: { size, font, color, rowFlex, numberType, format }, scale, pageMode } = this.options;
6679
+ let text = format;
6680
+ const pageNoReg = new RegExp(FORMAT_PLACEHOLDER.PAGE_NO);
6681
+ if (pageNoReg.test(text)) {
6682
+ const realPageNo = pageNo + 1;
6683
+ const pageNoText = numberType === NumberType.CHINESE ? convertNumberToChinese(realPageNo) : `${realPageNo}`;
6684
+ text = text.replace(pageNoReg, pageNoText);
6685
+ }
6686
+ const pageCountReg = new RegExp(FORMAT_PLACEHOLDER.PAGE_COUNT);
6687
+ if (pageCountReg.test(text)) {
6688
+ const pageCount = this.draw.getPageCount();
6689
+ const pageCountText = numberType === NumberType.CHINESE ? convertNumberToChinese(pageCount) : `${pageCount}`;
6690
+ text = text.replace(pageCountReg, pageCountText);
6691
+ }
6513
6692
  const width = this.draw.getWidth();
6514
6693
  const height = pageMode === PageMode.CONTINUITY ? this.draw.getCanvasHeight(pageNo) : this.draw.getHeight();
6515
6694
  const pageNumberBottom = this.draw.getPageNumberBottom();
@@ -9297,6 +9476,12 @@ class Zone {
9297
9476
  isCompute: false
9298
9477
  });
9299
9478
  this.drawZoneIndicator();
9479
+ nextTick(() => {
9480
+ const listener = this.draw.getListener();
9481
+ if (listener.zoneChange) {
9482
+ listener.zoneChange(payload);
9483
+ }
9484
+ });
9300
9485
  }
9301
9486
  drawZoneIndicator() {
9302
9487
  this._clearZoneIndicator();
@@ -9694,6 +9879,9 @@ class Draw {
9694
9879
  getPageList() {
9695
9880
  return this.pageList;
9696
9881
  }
9882
+ getPageCount() {
9883
+ return this.pageList.length;
9884
+ }
9697
9885
  getTableRowList(sourceElementList) {
9698
9886
  const positionContext = this.position.getPositionContext();
9699
9887
  const { index: index2, trIndex, tdIndex } = positionContext;
@@ -10688,6 +10876,7 @@ const _Command = class {
10688
10876
  _Command.subscript = adapt.subscript.bind(adapt);
10689
10877
  _Command.color = adapt.color.bind(adapt);
10690
10878
  _Command.highlight = adapt.highlight.bind(adapt);
10879
+ _Command.title = adapt.title.bind(adapt);
10691
10880
  _Command.left = adapt.rowFlex.bind(adapt);
10692
10881
  _Command.center = adapt.rowFlex.bind(adapt);
10693
10882
  _Command.right = adapt.rowFlex.bind(adapt);
@@ -10811,6 +11000,9 @@ const _Command = class {
10811
11000
  executeHighlight(payload) {
10812
11001
  return _Command.highlight(payload);
10813
11002
  }
11003
+ executeTitle(payload) {
11004
+ return _Command.title(payload);
11005
+ }
10814
11006
  executeLeft() {
10815
11007
  return _Command.left(RowFlex.LEFT);
10816
11008
  }
@@ -10987,6 +11179,7 @@ __publicField(Command, "superscript");
10987
11179
  __publicField(Command, "subscript");
10988
11180
  __publicField(Command, "color");
10989
11181
  __publicField(Command, "highlight");
11182
+ __publicField(Command, "title");
10990
11183
  __publicField(Command, "left");
10991
11184
  __publicField(Command, "center");
10992
11185
  __publicField(Command, "right");
@@ -11447,6 +11640,57 @@ class CommandAdapt {
11447
11640
  isCompute: false
11448
11641
  });
11449
11642
  }
11643
+ title(payload) {
11644
+ const isReadonly = this.draw.isReadonly();
11645
+ if (isReadonly)
11646
+ return;
11647
+ const { startIndex, endIndex } = this.range.getRange();
11648
+ if (!~startIndex && !~endIndex)
11649
+ return;
11650
+ let changeElementList = [];
11651
+ const elementList = this.draw.getElementList();
11652
+ if (startIndex === endIndex) {
11653
+ const rangeRow = this.range.getRangeRow();
11654
+ if (!rangeRow)
11655
+ return;
11656
+ const positionList = this.position.getPositionList();
11657
+ for (let p = 0; p < positionList.length; p++) {
11658
+ const position = positionList[p];
11659
+ const rowSet = rangeRow.get(position.pageNo);
11660
+ if (!rowSet)
11661
+ continue;
11662
+ if (rowSet.has(position.rowNo)) {
11663
+ changeElementList.push(elementList[p]);
11664
+ }
11665
+ }
11666
+ } else {
11667
+ changeElementList = elementList.slice(startIndex + 1, endIndex + 1);
11668
+ }
11669
+ const titleId = getUUID();
11670
+ const titleOptions = this.draw.getOptions().title;
11671
+ changeElementList.forEach((el) => {
11672
+ if (!el.type && el.value === ZERO)
11673
+ return;
11674
+ if (payload) {
11675
+ el.level = payload;
11676
+ el.titleId = titleId;
11677
+ if (isTextLikeElement(el)) {
11678
+ el.size = titleOptions[titleSizeMapping[payload]];
11679
+ el.bold = true;
11680
+ }
11681
+ } else {
11682
+ if (el.titleId) {
11683
+ delete el.titleId;
11684
+ delete el.level;
11685
+ delete el.size;
11686
+ delete el.bold;
11687
+ }
11688
+ }
11689
+ });
11690
+ const isSetCursor = startIndex === endIndex;
11691
+ const curIndex = isSetCursor ? endIndex : startIndex;
11692
+ this.draw.render({ curIndex, isSetCursor });
11693
+ }
11450
11694
  rowFlex(payload) {
11451
11695
  const isReadonly = this.draw.isReadonly();
11452
11696
  if (isReadonly)
@@ -12577,6 +12821,7 @@ class Listener {
12577
12821
  __publicField(this, "contentChange");
12578
12822
  __publicField(this, "controlChange");
12579
12823
  __publicField(this, "pageModeChange");
12824
+ __publicField(this, "zoneChange");
12580
12825
  this.rangeStyleChange = null;
12581
12826
  this.visiblePageNoListChange = null;
12582
12827
  this.intersectionPageNoChange = null;
@@ -12586,6 +12831,7 @@ class Listener {
12586
12831
  this.contentChange = null;
12587
12832
  this.controlChange = null;
12588
12833
  this.pageModeChange = null;
12834
+ this.zoneChange = null;
12589
12835
  }
12590
12836
  }
12591
12837
  class Register {
@@ -13298,13 +13544,6 @@ class Shortcut {
13298
13544
  }
13299
13545
  }
13300
13546
  }
13301
- const defaultPageNumberOption = {
13302
- bottom: 60,
13303
- size: 12,
13304
- font: "Yahei",
13305
- color: "#000000",
13306
- rowFlex: RowFlex.CENTER
13307
- };
13308
13547
  const defaultFooterOption = {
13309
13548
  bottom: 30,
13310
13549
  maxHeightRadio: MaxHeightRatio.HALF
@@ -13322,6 +13561,7 @@ class Editor {
13322
13561
  const controlOptions = __spreadValues(__spreadValues({}, defaultControlOption), options.control);
13323
13562
  const checkboxOptions = __spreadValues(__spreadValues({}, defaultCheckboxOption), options.checkbox);
13324
13563
  const cursorOptions = __spreadValues(__spreadValues({}, defaultCursorOption), options.cursor);
13564
+ const titleOptions = __spreadValues(__spreadValues({}, defaultTitleOption), options.title);
13325
13565
  const editorOptions = __spreadProps(__spreadValues({
13326
13566
  mode: EditorMode.EDIT,
13327
13567
  defaultType: "TEXT",
@@ -13363,7 +13603,8 @@ class Editor {
13363
13603
  watermark: waterMarkOptions,
13364
13604
  control: controlOptions,
13365
13605
  checkbox: checkboxOptions,
13366
- cursor: cursorOptions
13606
+ cursor: cursorOptions,
13607
+ title: titleOptions
13367
13608
  });
13368
13609
  let headerElementList = [];
13369
13610
  let mainElementList = [];
@@ -13401,5 +13642,5 @@ class Editor {
13401
13642
  };
13402
13643
  }
13403
13644
  }
13404
- export { BlockType, Command, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, ImageDisplay, KeyMap, MaxHeightRatio, PageMode, PaperDirection, RowFlex, TableBorder, VerticalAlign, Editor as default };
13645
+ export { BlockType, Command, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, ImageDisplay, KeyMap, MaxHeightRatio, NumberType, PageMode, PaperDirection, RowFlex, TableBorder, TitleLevel, VerticalAlign, Editor as default };
13405
13646
  //# sourceMappingURL=canvas-editor.es.js.map