@hufe921/canvas-editor 0.9.29 → 0.9.30

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.30";
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";
3896
+ if (((_e = payload[e - 1]) == null ? void 0 : _e.type) === ElementType.TITLE) {
3897
+ text2 = text2.replace(/^\n/, "");
3756
3898
  }
3757
- if (element.size) {
3758
- dom.style.fontSize = `${element.size}px`;
3759
- }
3760
- if (element.highlight) {
3761
- dom.style.backgroundColor = element.highlight;
3762
- }
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
  });
@@ -5919,6 +6071,7 @@ class RangeManager {
5919
6071
  const rowFlex = curElement.rowFlex || null;
5920
6072
  const rowMargin = curElement.rowMargin || this.options.defaultRowMargin;
5921
6073
  const dashArray = curElement.dashArray || [];
6074
+ const level = curElement.level || null;
5922
6075
  const painter = !!this.draw.getPainterStyle();
5923
6076
  const undo = this.historyManager.isCanUndo();
5924
6077
  const redo = this.historyManager.isCanRedo();
@@ -5937,7 +6090,8 @@ class RangeManager {
5937
6090
  highlight,
5938
6091
  rowFlex,
5939
6092
  rowMargin,
5940
- dashArray
6093
+ dashArray,
6094
+ level
5941
6095
  });
5942
6096
  }
5943
6097
  recoveryRangeStyle() {
@@ -5964,7 +6118,8 @@ class RangeManager {
5964
6118
  highlight: null,
5965
6119
  rowFlex: null,
5966
6120
  rowMargin,
5967
- dashArray: []
6121
+ dashArray: [],
6122
+ level: null
5968
6123
  });
5969
6124
  }
5970
6125
  shrinkBoundary() {
@@ -6500,6 +6655,19 @@ class TextParticle {
6500
6655
  this.ctx.restore();
6501
6656
  }
6502
6657
  }
6658
+ const FORMAT_PLACEHOLDER = {
6659
+ PAGE_NO: "{pageNo}",
6660
+ PAGE_COUNT: "{pageCount}"
6661
+ };
6662
+ const defaultPageNumberOption = {
6663
+ bottom: 60,
6664
+ size: 12,
6665
+ font: "Yahei",
6666
+ color: "#000000",
6667
+ rowFlex: RowFlex.CENTER,
6668
+ format: FORMAT_PLACEHOLDER.PAGE_NO,
6669
+ numberType: NumberType.ARABIC
6670
+ };
6503
6671
  class PageNumber {
6504
6672
  constructor(draw) {
6505
6673
  __publicField(this, "draw");
@@ -6508,8 +6676,20 @@ class PageNumber {
6508
6676
  this.options = draw.getOptions();
6509
6677
  }
6510
6678
  render(ctx, pageNo) {
6511
- const { pageNumber: { size, font, color, rowFlex }, scale, pageMode } = this.options;
6512
- const text = `${pageNo + 1}`;
6679
+ const { pageNumber: { size, font, color, rowFlex, numberType, format }, scale, pageMode } = this.options;
6680
+ let text = format;
6681
+ const pageNoReg = new RegExp(FORMAT_PLACEHOLDER.PAGE_NO);
6682
+ if (pageNoReg.test(text)) {
6683
+ const realPageNo = pageNo + 1;
6684
+ const pageNoText = numberType === NumberType.CHINESE ? convertNumberToChinese(realPageNo) : `${realPageNo}`;
6685
+ text = text.replace(pageNoReg, pageNoText);
6686
+ }
6687
+ const pageCountReg = new RegExp(FORMAT_PLACEHOLDER.PAGE_COUNT);
6688
+ if (pageCountReg.test(text)) {
6689
+ const pageCount = this.draw.getPageCount();
6690
+ const pageCountText = numberType === NumberType.CHINESE ? convertNumberToChinese(pageCount) : `${pageCount}`;
6691
+ text = text.replace(pageCountReg, pageCountText);
6692
+ }
6513
6693
  const width = this.draw.getWidth();
6514
6694
  const height = pageMode === PageMode.CONTINUITY ? this.draw.getCanvasHeight(pageNo) : this.draw.getHeight();
6515
6695
  const pageNumberBottom = this.draw.getPageNumberBottom();
@@ -9297,6 +9477,12 @@ class Zone {
9297
9477
  isCompute: false
9298
9478
  });
9299
9479
  this.drawZoneIndicator();
9480
+ nextTick(() => {
9481
+ const listener = this.draw.getListener();
9482
+ if (listener.zoneChange) {
9483
+ listener.zoneChange(payload);
9484
+ }
9485
+ });
9300
9486
  }
9301
9487
  drawZoneIndicator() {
9302
9488
  this._clearZoneIndicator();
@@ -9694,6 +9880,9 @@ class Draw {
9694
9880
  getPageList() {
9695
9881
  return this.pageList;
9696
9882
  }
9883
+ getPageCount() {
9884
+ return this.pageList.length;
9885
+ }
9697
9886
  getTableRowList(sourceElementList) {
9698
9887
  const positionContext = this.position.getPositionContext();
9699
9888
  const { index: index2, trIndex, tdIndex } = positionContext;
@@ -10688,6 +10877,7 @@ const _Command = class {
10688
10877
  _Command.subscript = adapt.subscript.bind(adapt);
10689
10878
  _Command.color = adapt.color.bind(adapt);
10690
10879
  _Command.highlight = adapt.highlight.bind(adapt);
10880
+ _Command.title = adapt.title.bind(adapt);
10691
10881
  _Command.left = adapt.rowFlex.bind(adapt);
10692
10882
  _Command.center = adapt.rowFlex.bind(adapt);
10693
10883
  _Command.right = adapt.rowFlex.bind(adapt);
@@ -10811,6 +11001,9 @@ const _Command = class {
10811
11001
  executeHighlight(payload) {
10812
11002
  return _Command.highlight(payload);
10813
11003
  }
11004
+ executeTitle(payload) {
11005
+ return _Command.title(payload);
11006
+ }
10814
11007
  executeLeft() {
10815
11008
  return _Command.left(RowFlex.LEFT);
10816
11009
  }
@@ -10987,6 +11180,7 @@ __publicField(Command, "superscript");
10987
11180
  __publicField(Command, "subscript");
10988
11181
  __publicField(Command, "color");
10989
11182
  __publicField(Command, "highlight");
11183
+ __publicField(Command, "title");
10990
11184
  __publicField(Command, "left");
10991
11185
  __publicField(Command, "center");
10992
11186
  __publicField(Command, "right");
@@ -11447,6 +11641,55 @@ class CommandAdapt {
11447
11641
  isCompute: false
11448
11642
  });
11449
11643
  }
11644
+ title(payload) {
11645
+ const isReadonly = this.draw.isReadonly();
11646
+ if (isReadonly)
11647
+ return;
11648
+ const { startIndex, endIndex } = this.range.getRange();
11649
+ if (!~startIndex && !~endIndex)
11650
+ return;
11651
+ let changeElementList = [];
11652
+ const elementList = this.draw.getElementList();
11653
+ if (startIndex === endIndex) {
11654
+ const rangeRow = this.range.getRangeRow();
11655
+ if (!rangeRow)
11656
+ return;
11657
+ const positionList = this.position.getPositionList();
11658
+ for (let p = 0; p < positionList.length; p++) {
11659
+ const position = positionList[p];
11660
+ const rowSet = rangeRow.get(position.pageNo);
11661
+ if (!rowSet)
11662
+ continue;
11663
+ if (rowSet.has(position.rowNo)) {
11664
+ changeElementList.push(elementList[p]);
11665
+ }
11666
+ }
11667
+ } else {
11668
+ changeElementList = elementList.slice(startIndex + 1, endIndex + 1);
11669
+ }
11670
+ const titleId = getUUID();
11671
+ const titleOptions = this.draw.getOptions().title;
11672
+ changeElementList.forEach((el) => {
11673
+ if (payload) {
11674
+ el.level = payload;
11675
+ el.titleId = titleId;
11676
+ if (isTextLikeElement(el)) {
11677
+ el.size = titleOptions[titleSizeMapping[payload]];
11678
+ el.bold = true;
11679
+ }
11680
+ } else {
11681
+ if (el.titleId) {
11682
+ delete el.titleId;
11683
+ delete el.level;
11684
+ delete el.size;
11685
+ delete el.bold;
11686
+ }
11687
+ }
11688
+ });
11689
+ const isSetCursor = startIndex === endIndex;
11690
+ const curIndex = isSetCursor ? endIndex : startIndex;
11691
+ this.draw.render({ curIndex, isSetCursor });
11692
+ }
11450
11693
  rowFlex(payload) {
11451
11694
  const isReadonly = this.draw.isReadonly();
11452
11695
  if (isReadonly)
@@ -12577,6 +12820,7 @@ class Listener {
12577
12820
  __publicField(this, "contentChange");
12578
12821
  __publicField(this, "controlChange");
12579
12822
  __publicField(this, "pageModeChange");
12823
+ __publicField(this, "zoneChange");
12580
12824
  this.rangeStyleChange = null;
12581
12825
  this.visiblePageNoListChange = null;
12582
12826
  this.intersectionPageNoChange = null;
@@ -12586,6 +12830,7 @@ class Listener {
12586
12830
  this.contentChange = null;
12587
12831
  this.controlChange = null;
12588
12832
  this.pageModeChange = null;
12833
+ this.zoneChange = null;
12589
12834
  }
12590
12835
  }
12591
12836
  class Register {
@@ -13298,13 +13543,6 @@ class Shortcut {
13298
13543
  }
13299
13544
  }
13300
13545
  }
13301
- const defaultPageNumberOption = {
13302
- bottom: 60,
13303
- size: 12,
13304
- font: "Yahei",
13305
- color: "#000000",
13306
- rowFlex: RowFlex.CENTER
13307
- };
13308
13546
  const defaultFooterOption = {
13309
13547
  bottom: 30,
13310
13548
  maxHeightRadio: MaxHeightRatio.HALF
@@ -13322,6 +13560,7 @@ class Editor {
13322
13560
  const controlOptions = __spreadValues(__spreadValues({}, defaultControlOption), options.control);
13323
13561
  const checkboxOptions = __spreadValues(__spreadValues({}, defaultCheckboxOption), options.checkbox);
13324
13562
  const cursorOptions = __spreadValues(__spreadValues({}, defaultCursorOption), options.cursor);
13563
+ const titleOptions = __spreadValues(__spreadValues({}, defaultTitleOption), options.title);
13325
13564
  const editorOptions = __spreadProps(__spreadValues({
13326
13565
  mode: EditorMode.EDIT,
13327
13566
  defaultType: "TEXT",
@@ -13363,7 +13602,8 @@ class Editor {
13363
13602
  watermark: waterMarkOptions,
13364
13603
  control: controlOptions,
13365
13604
  checkbox: checkboxOptions,
13366
- cursor: cursorOptions
13605
+ cursor: cursorOptions,
13606
+ title: titleOptions
13367
13607
  });
13368
13608
  let headerElementList = [];
13369
13609
  let mainElementList = [];
@@ -13401,5 +13641,5 @@ class Editor {
13401
13641
  };
13402
13642
  }
13403
13643
  }
13404
- export { BlockType, Command, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, ImageDisplay, KeyMap, MaxHeightRatio, PageMode, PaperDirection, RowFlex, TableBorder, VerticalAlign, Editor as default };
13644
+ 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
13645
  //# sourceMappingURL=canvas-editor.es.js.map