@hufe921/canvas-editor 0.9.136 → 1.0.0

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +11 -8
  3. package/dist/assets/catalog-B-cbxN0s.js.map +1 -1
  4. package/dist/assets/value-B0aX9J3d.js.map +1 -0
  5. package/dist/assets/wordCount-BWZRHbSB.js.map +1 -0
  6. package/dist/canvas-editor.js +5105 -2340
  7. package/dist/canvas-editor.js.map +1 -1
  8. package/dist/canvas-editor.umd.cjs +41 -37
  9. package/dist/canvas-editor.umd.cjs.map +1 -1
  10. package/dist/src/editor/core/cascade/CascadeManager.d.ts +28 -0
  11. package/dist/src/editor/core/cascade/expression/evaluator.d.ts +14 -0
  12. package/dist/src/editor/core/cascade/expression/parser.d.ts +36 -0
  13. package/dist/src/editor/core/cascade/expression/tokenizer.d.ts +19 -0
  14. package/dist/src/editor/core/command/Command.d.ts +12 -0
  15. package/dist/src/editor/core/command/CommandAdapt.d.ts +14 -2
  16. package/dist/src/editor/core/draw/Draw.d.ts +33 -0
  17. package/dist/src/editor/core/draw/column/ColumnManager.d.ts +14 -0
  18. package/dist/src/editor/core/draw/control/Control.d.ts +3 -0
  19. package/dist/src/editor/core/draw/interactive/Area.d.ts +2 -0
  20. package/dist/src/editor/core/draw/interactive/Search.d.ts +1 -0
  21. package/dist/src/editor/core/draw/particle/ListParticle.d.ts +10 -0
  22. package/dist/src/editor/core/draw/particle/TraceParticle.d.ts +40 -0
  23. package/dist/src/editor/core/draw/particle/table/TableOperate.d.ts +3 -0
  24. package/dist/src/editor/core/draw/particle/table/TablePaging.d.ts +13 -0
  25. package/dist/src/editor/core/draw/particle/table/TableParticle.d.ts +19 -2
  26. package/dist/src/editor/core/draw/particle/table/TableTool.d.ts +2 -0
  27. package/dist/src/editor/core/draw/ruler/Ruler.d.ts +43 -0
  28. package/dist/src/editor/core/macro/MacroManager.d.ts +25 -0
  29. package/dist/src/editor/core/position/Position.d.ts +9 -1
  30. package/dist/src/editor/core/validate/Validate.d.ts +19 -0
  31. package/dist/src/editor/dataset/constant/Column.d.ts +2 -0
  32. package/dist/src/editor/dataset/constant/ContextMenu.d.ts +2 -0
  33. package/dist/src/editor/dataset/constant/Element.d.ts +1 -0
  34. package/dist/src/editor/dataset/constant/Ruler.d.ts +2 -0
  35. package/dist/src/editor/dataset/constant/Trace.d.ts +2 -0
  36. package/dist/src/editor/dataset/enum/Editor.d.ts +2 -1
  37. package/dist/src/editor/dataset/enum/Macro.d.ts +4 -0
  38. package/dist/src/editor/dataset/enum/Trace.d.ts +4 -0
  39. package/dist/src/editor/index.d.ts +4 -1
  40. package/dist/src/editor/interface/Area.d.ts +6 -0
  41. package/dist/src/editor/interface/Column.d.ts +14 -0
  42. package/dist/src/editor/interface/Compare.d.ts +5 -0
  43. package/dist/src/editor/interface/Control.d.ts +46 -0
  44. package/dist/src/editor/interface/Draw.d.ts +1 -0
  45. package/dist/src/editor/interface/Editor.d.ts +7 -1
  46. package/dist/src/editor/interface/Element.d.ts +24 -3
  47. package/dist/src/editor/interface/Macro.d.ts +19 -0
  48. package/dist/src/editor/interface/Print.d.ts +6 -0
  49. package/dist/src/editor/interface/Row.d.ts +9 -1
  50. package/dist/src/editor/interface/Ruler.d.ts +4 -0
  51. package/dist/src/editor/interface/Trace.d.ts +11 -0
  52. package/dist/src/editor/interface/i18n/I18n.d.ts +4 -0
  53. package/dist/src/editor/interface/i18n/Trace.d.ts +7 -0
  54. package/dist/src/editor/interface/i18n/Validate.d.ts +15 -0
  55. package/dist/src/editor/utils/diff.d.ts +7 -0
  56. package/dist/src/editor/utils/element.d.ts +21 -2
  57. package/dist/src/editor/utils/print.d.ts +2 -1
  58. package/dist/src/editor/utils/table.d.ts +4 -0
  59. package/package.json +1 -1
  60. package/dist/assets/value-By4_Dx3W.js.map +0 -1
  61. package/dist/assets/wordCount-Osi0e4qK.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,55 @@
1
+ # [1.0.0](https://github.com/Hufe921/canvas-editor/compare/v0.9.137...v1.0.0) (2026-08-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * collapse row height for hidden elements #1447 ([efe9cc1](https://github.com/Hufe921/canvas-editor/commit/efe9cc1794bc39954eeddfe5310e0af429082b1e)), closes [#1447](https://github.com/Hufe921/canvas-editor/issues/1447)
7
+ * control member state sync for cascade restore and select highlight ([56fdf60](https://github.com/Hufe921/canvas-editor/commit/56fdf609eea8066ac52e8812b20aaded00b28b66))
8
+ * re-activate control before input when inactive #1443 ([a92a406](https://github.com/Hufe921/canvas-editor/commit/a92a4061788a0917fd5e1ac3c983363501edbdfb)), closes [#1443](https://github.com/Hufe921/canvas-editor/issues/1443)
9
+ * table row height adaptation for row-spanning cell with tall content ([9e54b8c](https://github.com/Hufe921/canvas-editor/commit/9e54b8c2eb8972fb9dba2636fee55086d6fae759))
10
+
11
+
12
+ ### Documentation
13
+
14
+ * update README.md ([cb10612](https://github.com/Hufe921/canvas-editor/commit/cb106129fda44a102c3a4e304af6523244bc56df))
15
+ * update start.md ([53f6ca8](https://github.com/Hufe921/canvas-editor/commit/53f6ca8a221ee4b7ff7a27c90ff9846a7b6d09cb))
16
+
17
+
18
+ ### Features
19
+
20
+ * add compare api #1024 ([eba1d10](https://github.com/Hufe921/canvas-editor/commit/eba1d10861366881b00dbd85e3b5fcc34b4f80aa)), closes [#1024](https://github.com/Hufe921/canvas-editor/issues/1024)
21
+ * add macro recording and playback #478 ([e25e05b](https://github.com/Hufe921/canvas-editor/commit/e25e05bd49a2dcd86661967726c6fba51ede424c)), closes [#478](https://github.com/Hufe921/canvas-editor/issues/478)
22
+ * add ruler option #438 ([d5bad24](https://github.com/Hufe921/canvas-editor/commit/d5bad2449c6dea4a2f574724647fbd2fa7fd8c6d)), closes [#438](https://github.com/Hufe921/canvas-editor/issues/438)
23
+ * add trace mode #312 ([bf51518](https://github.com/Hufe921/canvas-editor/commit/bf51518eb317e598a634065470772062ab16346f)), closes [#312](https://github.com/Hufe921/canvas-editor/issues/312)
24
+ * control cascade and validation #671 ([342dea6](https://github.com/Hufe921/canvas-editor/commit/342dea669d1e39124b4e4d72b24352b9091dd044)), closes [#671](https://github.com/Hufe921/canvas-editor/issues/671)
25
+ * improve trace line visibility ([bc703b7](https://github.com/Hufe921/canvas-editor/commit/bc703b7edc540b98470a0d7722ba04b952dc3808))
26
+ * optimize table pagination #41 ([17794dd](https://github.com/Hufe921/canvas-editor/commit/17794dd78ec7de55fea823900bd626514479ab71)), closes [#41](https://github.com/Hufe921/canvas-editor/issues/41)
27
+ * support control nesting #425 ([732b985](https://github.com/Hufe921/canvas-editor/commit/732b985995183784cfc77a102a209cfc4c689c46)), closes [#425](https://github.com/Hufe921/canvas-editor/issues/425)
28
+ * support nested ordered list level handling #440 ([56a51c4](https://github.com/Hufe921/canvas-editor/commit/56a51c42e629706720673ad549b8bdd0a66986d5)), closes [#440](https://github.com/Hufe921/canvas-editor/issues/440)
29
+ * table width autofit to content and page #1387 #1453 ([66c9b94](https://github.com/Hufe921/canvas-editor/commit/66c9b940dec71ed74c887c2f3ee0b8b1e068a610)), closes [#1387](https://github.com/Hufe921/canvas-editor/issues/1387) [#1453](https://github.com/Hufe921/canvas-editor/issues/1453)
30
+
31
+
32
+
33
+ ## [0.9.137](https://github.com/Hufe921/canvas-editor/compare/v0.9.136...v0.9.137) (2026-07-10)
34
+
35
+
36
+ ### Bug Fixes
37
+
38
+ * allow table insertion after control ([3a223a9](https://github.com/Hufe921/canvas-editor/commit/3a223a9f08b09d8bbd5638fc6b30ec379fc52b2b))
39
+ * cursor jumps to wrong column when clicking empty area #1439 ([a77fd75](https://github.com/Hufe921/canvas-editor/commit/a77fd750821310683882b8a555559dcbb43b3618)), closes [#1439](https://github.com/Hufe921/canvas-editor/issues/1439)
40
+ * recompute column layout on scale and dimension change #1440 ([6c3ce1f](https://github.com/Hufe921/canvas-editor/commit/6c3ce1f99ace95a91c6281fc681d2c4e11de0653)), closes [#1440](https://github.com/Hufe921/canvas-editor/issues/1440)
41
+ * sync column option after setColumns #1438 ([712779e](https://github.com/Hufe921/canvas-editor/commit/712779e33c91ed3e6b45eb76546d8e02778d98a7)), closes [#1438](https://github.com/Hufe921/canvas-editor/issues/1438)
42
+
43
+
44
+ ### Features
45
+
46
+ * add areaHideDisabled print mode rule #1429 ([0268cca](https://github.com/Hufe921/canvas-editor/commit/0268cca4fe2b3c2187f5876a245c27142692909e)), closes [#1429](https://github.com/Hufe921/canvas-editor/issues/1429)
47
+ * add offscreen print option #1429 ([5486385](https://github.com/Hufe921/canvas-editor/commit/548638538acced50156c625ef038be6a3d2a960b)), closes [#1429](https://github.com/Hufe921/canvas-editor/issues/1429)
48
+ * support area elements in table cells #1317 ([0bdecc8](https://github.com/Hufe921/canvas-editor/commit/0bdecc86b80ae14b6bcc40f6f23b23d0dacbb46c)), closes [#1317](https://github.com/Hufe921/canvas-editor/issues/1317)
49
+ * support multi-column layout #1237 ([d53d194](https://github.com/Hufe921/canvas-editor/commit/d53d194262b98855639999fc5da6d48851ae1195)), closes [#1237](https://github.com/Hufe921/canvas-editor/issues/1237)
50
+
51
+
52
+
1
53
  ## [0.9.136](https://github.com/Hufe921/canvas-editor/compare/v0.9.135...v0.9.136) (2026-06-20)
2
54
 
3
55
 
package/README.md CHANGED
@@ -36,6 +36,10 @@
36
36
  English · <a href="https://hufe.club/canvas-editor-docs">中文文档</a>
37
37
  </p>
38
38
 
39
+ <p align="center">
40
+ 🎉 <strong>Canvas Editor 1.0.0 is released!</strong> See the <a href="https://github.com/Hufe921/canvas-editor/blob/main/docs/RELEASE_NOTES_1.0.0.md"><strong>1.0 Release Notes</strong></a> for highlights and upgrade notes.
41
+ </p>
42
+
39
43
  ---
40
44
 
41
45
  ## Overview
@@ -104,14 +108,13 @@ For complete API documentation, see the [official docs](https://hufe.club/canvas
104
108
 
105
109
  ## Ecosystem
106
110
 
107
- | Project | Description |
108
- | ---------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
109
- | [canvas-editor-plugin](https://github.com/Hufe921/canvas-editor-plugin) | Official plugin collection |
110
- | [feature/svg](https://github.com/Hufe921/canvas-editor/tree/feature/svg) | SVG render layer (in development) |
111
- | [feature/pdf](https://github.com/Hufe921/canvas-editor/tree/feature/pdf) | PDF export feature |
112
- | [feature/ai](https://github.com/Hufe921/canvas-editor/tree/feature/ai) | AI-powered text processing demo |
113
- | [poc/table-paging](https://github.com/Hufe921/canvas-editor/tree/poc/table-paging) | Table pagination POC ([demo](https://hufe.club/canvas-editor-table/)) |
114
- | [feature/CRDT](https://github.com/Hufe921/canvas-editor/tree/feature/CRDT) | CRDT-based collaboration (experimental) |
111
+ | Project | Description |
112
+ | -------------------------------------------------------------------------- | --------------------------------------- |
113
+ | [canvas-editor-plugin](https://github.com/Hufe921/canvas-editor-plugin) | Official plugin collection |
114
+ | [feature/svg](https://github.com/Hufe921/canvas-editor/tree/feature/svg) | SVG render layer (in development) |
115
+ | [feature/pdf](https://github.com/Hufe921/canvas-editor/tree/feature/pdf) | PDF export feature |
116
+ | [feature/ai](https://github.com/Hufe921/canvas-editor/tree/feature/ai) | AI-powered text processing demo |
117
+ | [feature/CRDT](https://github.com/Hufe921/canvas-editor/tree/feature/CRDT) | CRDT-based collaboration (experimental) |
115
118
 
116
119
  ## Development
117
120
 
@@ -1 +1 @@
1
- {"version":3,"file":"catalog-B-cbxN0s.js","names":[],"sources":["../../src/editor/core/worker/works/catalog.ts"],"sourcesContent":["import { ICatalog, ICatalogItem } from '../../../interface/Catalog'\nimport { IElement, IElementPosition } from '../../../interface/Element'\n\ninterface IGetCatalogPayload {\n elementList: IElement[]\n positionList: IElementPosition[]\n}\n\ntype ICatalogElement = IElement & {\n pageNo: number\n}\n\nenum ElementType {\n TEXT = 'text',\n IMAGE = 'image',\n TABLE = 'table',\n HYPERLINK = 'hyperlink',\n SUPERSCRIPT = 'superscript',\n SUBSCRIPT = 'subscript',\n SEPARATOR = 'separator',\n PAGE_BREAK = 'pageBreak',\n CONTROL = 'control',\n CHECKBOX = 'checkbox',\n RADIO = 'radio',\n LATEX = 'latex',\n TAB = 'tab',\n DATE = 'date',\n BLOCK = 'block',\n TITLE = 'title',\n AREA = 'area',\n LIST = 'list',\n LABEL = 'label'\n}\n\nenum TitleLevel {\n FIRST = 'first',\n SECOND = 'second',\n THIRD = 'third',\n FOURTH = 'fourth',\n FIFTH = 'fifth',\n SIXTH = 'sixth'\n}\n\nconst titleOrderNumberMapping: Record<TitleLevel, number> = {\n [TitleLevel.FIRST]: 1,\n [TitleLevel.SECOND]: 2,\n [TitleLevel.THIRD]: 3,\n [TitleLevel.FOURTH]: 4,\n [TitleLevel.FIFTH]: 5,\n [TitleLevel.SIXTH]: 6\n}\n\nconst TEXTLIKE_ELEMENT_TYPE: ElementType[] = [\n ElementType.TEXT,\n ElementType.HYPERLINK,\n ElementType.SUBSCRIPT,\n ElementType.SUPERSCRIPT,\n ElementType.CONTROL,\n ElementType.DATE,\n ElementType.LABEL\n]\n\nconst ZERO = '\\u200B'\n\nfunction isTextLikeElement(element: IElement): boolean {\n return !element.type || TEXTLIKE_ELEMENT_TYPE.includes(element.type)\n}\n\nfunction getCatalog(payload: IGetCatalogPayload): ICatalog | null {\n const { elementList, positionList } = payload\n // 筛选标题\n const titleElementList: ICatalogElement[] = []\n let t = 0\n while (t < elementList.length) {\n const element = elementList[t]\n const getElementInfo = (\n element: IElement,\n elementList: IElement[],\n position: number\n ) => {\n const titleId = element.titleId\n const level = element.level\n const titleElement: ICatalogElement = {\n type: ElementType.TITLE,\n value: '',\n level,\n titleId,\n pageNo: positionList[t].pageNo\n }\n const valueList: IElement[] = []\n while (position < elementList.length) {\n const titleE = elementList[position]\n if (titleId !== titleE.titleId) {\n position--\n break\n }\n valueList.push(titleE)\n position++\n }\n titleElement.value = valueList\n .filter(el => isTextLikeElement(el))\n .map(el => el.value)\n .join('')\n .replace(new RegExp(ZERO, 'g'), '')\n return { position, titleElement }\n }\n if (element.titleId) {\n const { position, titleElement } = getElementInfo(element, elementList, t)\n t = position\n titleElementList.push(titleElement)\n }\n if (element.type === ElementType.TABLE) {\n const trList = element.trList!\n for (let r = 0; r < trList.length; r++) {\n const tr = trList[r]\n for (let d = 0; d < tr.tdList.length; d++) {\n const td = tr.tdList[d]\n const value = td.value\n if (value.length > 1) {\n let index = 1\n while (index < value.length) {\n if (value[index]?.titleId) {\n const { titleElement, position } = getElementInfo(\n value[index],\n value,\n index\n )\n titleElementList.push(titleElement)\n index = position\n }\n index++\n }\n }\n }\n }\n }\n t++\n }\n if (!titleElementList.length) return null\n // 查找到比最新元素大的标题时终止\n const recursiveInsert = (\n title: ICatalogElement,\n catalogItem: ICatalogItem\n ) => {\n const subCatalogItem =\n catalogItem.subCatalog[catalogItem.subCatalog.length - 1]\n const catalogItemLevel = titleOrderNumberMapping[subCatalogItem?.level]\n const titleLevel = titleOrderNumberMapping[title.level!]\n if (subCatalogItem && titleLevel > catalogItemLevel) {\n recursiveInsert(title, subCatalogItem)\n } else {\n catalogItem.subCatalog.push({\n id: title.titleId!,\n name: title.value,\n level: title.level!,\n pageNo: title.pageNo,\n subCatalog: []\n })\n }\n }\n // 循环标题组\n // 如果当前列表级别小于标题组最新标题级别:则递归查找最小级别并追加\n // 如果大于:则直接追加至当前标题组\n const catalog: ICatalog = []\n for (let e = 0; e < titleElementList.length; e++) {\n const title = titleElementList[e]\n const catalogItem = catalog[catalog.length - 1]\n const catalogItemLevel = titleOrderNumberMapping[catalogItem?.level]\n const titleLevel = titleOrderNumberMapping[title.level!]\n if (catalogItem && titleLevel > catalogItemLevel) {\n recursiveInsert(title, catalogItem)\n } else {\n catalog.push({\n id: title.titleId!,\n name: title.value,\n level: title.level!,\n pageNo: title.pageNo,\n subCatalog: []\n })\n }\n }\n return catalog\n}\n\nonmessage = evt => {\n const payload = <IGetCatalogPayload>evt.data\n const catalog = getCatalog(payload)\n postMessage(catalog)\n}\n"],"mappings":"YA2CA,IAAM,EAA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,EAAM,IAAQ,QAAS,CACzB,GAAM,CAAE,eAAc,YAAa,EACjC,EAAM,GACN,EACA,CACF,EACA,EAAiB,KAAK,CAAY,EAClC,EAAQ,CACV,CACA,GACF,CACF,CACF,CACF,CACF,CACA,GACF,CACA,GAAI,CAAC,EAAiB,OAAQ,OAAO,KAErC,IAAM,GACJ,EACA,IACG,CACH,IAAM,EACJ,EAAY,WAAW,EAAY,WAAW,OAAS,GACnD,EAAmB,EAAwB,GAAgB,OAC3D,EAAa,EAAwB,EAAM,OAC7C,GAAkB,EAAa,EACjC,EAAgB,EAAO,CAAc,EAErC,EAAY,WAAW,KAAK,CAC1B,GAAI,EAAM,QACV,KAAM,EAAM,MACZ,MAAO,EAAM,MACb,OAAQ,EAAM,OACd,WAAY,CAAC,CACf,CAAC,CAEL,EAIM,EAAoB,CAAC,EAC3B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAiB,OAAQ,IAAK,CAChD,IAAM,EAAQ,EAAiB,GACzB,EAAc,EAAQ,EAAQ,OAAS,GACvC,EAAmB,EAAwB,GAAa,OACxD,EAAa,EAAwB,EAAM,OAC7C,GAAe,EAAa,EAC9B,EAAgB,EAAO,CAAW,EAElC,EAAQ,KAAK,CACX,GAAI,EAAM,QACV,KAAM,EAAM,MACZ,MAAO,EAAM,MACb,OAAQ,EAAM,OACd,WAAY,CAAC,CACf,CAAC,CAEL,CACA,OAAO,CACT,CAEA,UAAY,GAAO,CACjB,IAAM,EAA8B,EAAI,KAClC,EAAU,EAAW,CAAO,EAClC,YAAY,CAAO,CACrB"}
1
+ {"version":3,"file":"catalog-B-cbxN0s.js","names":[],"sources":["../../src/editor/core/worker/works/catalog.ts"],"sourcesContent":["import { ICatalog, ICatalogItem } from '../../../interface/Catalog'\nimport { IElement, IElementPosition } from '../../../interface/Element'\n\ninterface IGetCatalogPayload {\n elementList: IElement[]\n positionList: IElementPosition[]\n}\n\ntype ICatalogElement = IElement & {\n pageNo: number\n}\n\nenum ElementType {\n TEXT = 'text',\n IMAGE = 'image',\n TABLE = 'table',\n HYPERLINK = 'hyperlink',\n SUPERSCRIPT = 'superscript',\n SUBSCRIPT = 'subscript',\n SEPARATOR = 'separator',\n PAGE_BREAK = 'pageBreak',\n CONTROL = 'control',\n CHECKBOX = 'checkbox',\n RADIO = 'radio',\n LATEX = 'latex',\n TAB = 'tab',\n DATE = 'date',\n BLOCK = 'block',\n TITLE = 'title',\n AREA = 'area',\n LIST = 'list',\n LABEL = 'label'\n}\n\nenum TitleLevel {\n FIRST = 'first',\n SECOND = 'second',\n THIRD = 'third',\n FOURTH = 'fourth',\n FIFTH = 'fifth',\n SIXTH = 'sixth'\n}\n\nconst titleOrderNumberMapping: Record<TitleLevel, number> = {\n [TitleLevel.FIRST]: 1,\n [TitleLevel.SECOND]: 2,\n [TitleLevel.THIRD]: 3,\n [TitleLevel.FOURTH]: 4,\n [TitleLevel.FIFTH]: 5,\n [TitleLevel.SIXTH]: 6\n}\n\nconst TEXTLIKE_ELEMENT_TYPE: ElementType[] = [\n ElementType.TEXT,\n ElementType.HYPERLINK,\n ElementType.SUBSCRIPT,\n ElementType.SUPERSCRIPT,\n ElementType.CONTROL,\n ElementType.DATE,\n ElementType.LABEL\n]\n\nconst ZERO = '\\u200B'\n\nfunction isTextLikeElement(element: IElement): boolean {\n return !element.type || TEXTLIKE_ELEMENT_TYPE.includes(element.type)\n}\n\nfunction getCatalog(payload: IGetCatalogPayload): ICatalog | null {\n const { elementList, positionList } = payload\n // 筛选标题\n const titleElementList: ICatalogElement[] = []\n let t = 0\n while (t < elementList.length) {\n const element = elementList[t]\n const getElementInfo = (\n element: IElement,\n elementList: IElement[],\n position: number\n ) => {\n const titleId = element.titleId\n const level = element.level\n const titleElement: ICatalogElement = {\n type: ElementType.TITLE,\n value: '',\n level,\n titleId,\n pageNo: positionList[t].pageNo\n }\n const valueList: IElement[] = []\n while (position < elementList.length) {\n const titleE = elementList[position]\n if (titleId !== titleE.titleId) {\n position--\n break\n }\n valueList.push(titleE)\n position++\n }\n titleElement.value = valueList\n .filter(el => isTextLikeElement(el))\n .map(el => el.value)\n .join('')\n .replace(new RegExp(ZERO, 'g'), '')\n return { position, titleElement }\n }\n if (element.titleId) {\n const { position, titleElement } = getElementInfo(element, elementList, t)\n t = position\n titleElementList.push(titleElement)\n }\n if (element.type === ElementType.TABLE) {\n const trList = element.trList!\n for (let r = 0; r < trList.length; r++) {\n const tr = trList[r]\n for (let d = 0; d < tr.tdList.length; d++) {\n const td = tr.tdList[d]\n const value = td.value\n if (value.length > 1) {\n let index = 1\n while (index < value.length) {\n if (value[index]?.titleId) {\n const { titleElement, position } = getElementInfo(\n value[index],\n value,\n index\n )\n titleElementList.push(titleElement)\n index = position\n }\n index++\n }\n }\n }\n }\n }\n t++\n }\n if (!titleElementList.length) return null\n // 查找到比最新元素大的标题时终止\n const recursiveInsert = (\n title: ICatalogElement,\n catalogItem: ICatalogItem\n ) => {\n const subCatalogItem =\n catalogItem.subCatalog[catalogItem.subCatalog.length - 1]\n const catalogItemLevel = titleOrderNumberMapping[subCatalogItem?.level]\n const titleLevel = titleOrderNumberMapping[title.level!]\n if (subCatalogItem && titleLevel > catalogItemLevel) {\n recursiveInsert(title, subCatalogItem)\n } else {\n catalogItem.subCatalog.push({\n id: title.titleId!,\n name: title.value,\n level: title.level!,\n pageNo: title.pageNo,\n subCatalog: []\n })\n }\n }\n // 循环标题组\n // 如果当前列表级别小于标题组最新标题级别:则递归查找最小级别并追加\n // 如果大于:则直接追加至当前标题组\n const catalog: ICatalog = []\n for (let e = 0; e < titleElementList.length; e++) {\n const title = titleElementList[e]\n const catalogItem = catalog[catalog.length - 1]\n const catalogItemLevel = titleOrderNumberMapping[catalogItem?.level]\n const titleLevel = titleOrderNumberMapping[title.level!]\n if (catalogItem && titleLevel > catalogItemLevel) {\n recursiveInsert(title, catalogItem)\n } else {\n catalog.push({\n id: title.titleId!,\n name: title.value,\n level: title.level!,\n pageNo: title.pageNo,\n subCatalog: []\n })\n }\n }\n return catalog\n}\n\nonmessage = evt => {\n const payload = <IGetCatalogPayload>evt.data\n const catalog = getCatalog(payload)\n postMessage(catalog)\n}\n"],"mappings":"YA2CA,IAAM,EAAsD,OACtC,SACC,QACD,SACC,QACD,QACA,CACtB,EAEM,EAAuC,sEAQ7C,EAIA,SAAS,EAAkB,EAA4B,CACrD,MAAO,CAAC,EAAQ,MAAQ,EAAsB,SAAS,EAAQ,IAAI,CACrE,CAEA,SAAS,EAAW,EAA8C,CAChE,GAAM,CAAE,cAAa,gBAAiB,EAEhC,EAAsC,CAAC,EACzC,EAAI,EACR,KAAO,EAAI,EAAY,QAAQ,CAC7B,IAAM,EAAU,EAAY,GACtB,GACJ,EACA,EACA,IACG,CACH,IAAM,EAAU,EAAQ,QAElB,EAAgC,CACpC,KAAA,QACA,MAAO,GACP,MAJY,EAAQ,MAKpB,UACA,OAAQ,EAAa,EAAE,CAAC,MAC1B,EACM,EAAwB,CAAC,EAC/B,KAAO,EAAW,EAAY,QAAQ,CACpC,IAAM,EAAS,EAAY,GAC3B,GAAI,IAAY,EAAO,QAAS,CAC9B,IACA,KACF,CACA,EAAU,KAAK,CAAM,EACrB,GACF,CAMA,MALA,GAAa,MAAQ,EAClB,OAAO,GAAM,EAAkB,CAAE,CAAC,CAAC,CACnC,IAAI,GAAM,EAAG,KAAK,CAAC,CACnB,KAAK,EAAE,CAAC,CACR,QAAY,OAAO,IAAM,GAAG,EAAG,EAAE,EAC7B,CAAE,WAAU,cAAa,CAClC,EACA,GAAI,EAAQ,QAAS,CACnB,GAAM,CAAE,WAAU,gBAAiB,EAAe,EAAS,EAAa,CAAC,EACzE,EAAI,EACJ,EAAiB,KAAK,CAAY,CACpC,CACA,GAAI,EAAQ,OAAA,QAA4B,CACtC,IAAM,EAAS,EAAQ,OACvB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,OAAQ,IAAK,CACtC,IAAM,EAAK,EAAO,GAClB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,OAAO,OAAQ,IAA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