@quirekit/xlsx 0.0.0-stage → 0.3.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.
- package/LICENSE.md +21 -0
- package/THIRD_PARTY_NOTICES.md +150 -0
- package/dist/index.d.mts +122 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +19167 -0
- package/dist/index.mjs.map +1 -0
- package/licenses/saxes.LICENSE +64 -0
- package/licenses/xmlchars.LICENSE +18 -0
- package/package.json +52 -3
- package/src/bundle.ts +17 -0
- package/src/comments/legacy/read.ts +68 -0
- package/src/comments/legacy/write.ts +64 -0
- package/src/comments/package/ranges.ts +78 -0
- package/src/comments/package/read.ts +95 -0
- package/src/comments/package/roundtrip.test.ts +106 -0
- package/src/comments/package/write.ts +130 -0
- package/src/comments/thread/read.ts +69 -0
- package/src/comments/thread/write.ts +61 -0
- package/src/comments/types.ts +43 -0
- package/src/comments/xml.ts +50 -0
- package/src/create.ts +13 -0
- package/src/drawing/cache.ts +48 -0
- package/src/drawing/chart.test.ts +96 -0
- package/src/drawing/chart.ts +87 -0
- package/src/drawing/definition/plots.ts +76 -0
- package/src/drawing/definition/read.ts +65 -0
- package/src/drawing/definition/shape.ts +40 -0
- package/src/drawing/definition/types.ts +24 -0
- package/src/drawing/editable-picture.ts +80 -0
- package/src/drawing/graph.ts +148 -0
- package/src/drawing/identity.ts +22 -0
- package/src/drawing/import.ts +133 -0
- package/src/drawing/namespaces.ts +11 -0
- package/src/drawing/picture.test.ts +98 -0
- package/src/drawing/picture.ts +54 -0
- package/src/drawing/placement/anchor.ts +71 -0
- package/src/drawing/placement/axes.ts +113 -0
- package/src/drawing/placement/marker.ts +16 -0
- package/src/drawing/placement/transform.ts +132 -0
- package/src/drawing/placement/types.ts +20 -0
- package/src/drawing/presentation/cartesian/axes.ts +103 -0
- package/src/drawing/presentation/cartesian/plot.ts +109 -0
- package/src/drawing/presentation/cartesian/types.ts +9 -0
- package/src/drawing/presentation/layout.ts +29 -0
- package/src/drawing/presentation/paint.ts +56 -0
- package/src/drawing/presentation/properties.ts +31 -0
- package/src/drawing/read.ts +85 -0
- package/src/drawing/shapes/connector.ts +55 -0
- package/src/drawing/shapes/paint.ts +108 -0
- package/src/drawing/shapes/read.ts +89 -0
- package/src/drawing/shapes/text.ts +89 -0
- package/src/drawing/shapes/types.ts +13 -0
- package/src/drawing/sources.test.ts +27 -0
- package/src/drawing/sources.ts +43 -0
- package/src/drawing/types.ts +54 -0
- package/src/drawing/worksheet-connector.test.ts +135 -0
- package/src/drawing/worksheet-shape.test.ts +61 -0
- package/src/drawing/write/anchor.ts +17 -0
- package/src/drawing/write/axes.ts +23 -0
- package/src/drawing/write/chart.ts +56 -0
- package/src/drawing/write/drawing.ts +61 -0
- package/src/drawing/write/pictures.ts +68 -0
- package/src/drawing/write/series.ts +43 -0
- package/src/drawing/write/shapes.ts +113 -0
- package/src/drawing/write/text.ts +26 -0
- package/src/drawing/write/workbook.test.ts +199 -0
- package/src/drawing/write/workbook.ts +217 -0
- package/src/external-links/formulas.ts +21 -0
- package/src/external-links/read.test.ts +93 -0
- package/src/external-links/read.ts +104 -0
- package/src/external-links/types.ts +9 -0
- package/src/external-links/write.ts +120 -0
- package/src/image/excel.ts +122 -0
- package/src/image/native.ts +21 -0
- package/src/image/ownership.ts +77 -0
- package/src/image/parts.ts +45 -0
- package/src/image/raster.ts +25 -0
- package/src/image/read.test.ts +95 -0
- package/src/image/read.ts +66 -0
- package/src/image/relationships.ts +26 -0
- package/src/image/types.ts +48 -0
- package/src/image/wps.ts +43 -0
- package/src/image/write.test.ts +53 -0
- package/src/image/write.ts +118 -0
- package/src/index.ts +6 -0
- package/src/metadata/dynamic-array.ts +105 -0
- package/src/metadata/package.ts +75 -0
- package/src/metadata/types.ts +7 -0
- package/src/opc/archive.ts +26 -0
- package/src/opc/ownership.ts +40 -0
- package/src/opc/relationships.ts +98 -0
- package/src/opc/revision.ts +28 -0
- package/src/opc/shape.ts +23 -0
- package/src/opc/types.ts +13 -0
- package/src/opc/xml.test.ts +49 -0
- package/src/opc/xml.ts +128 -0
- package/src/optimization/blanks.ts +53 -0
- package/src/optimization/optimize.test.ts +117 -0
- package/src/optimization/optimize.ts +41 -0
- package/src/optimization/package.ts +65 -0
- package/src/optimization/rules.ts +46 -0
- package/src/optimization/styles.ts +76 -0
- package/src/optimization/types.ts +33 -0
- package/src/package/assembly.test.ts +117 -0
- package/src/package/calculation-metadata.test.ts +85 -0
- package/src/package/calculation-metadata.ts +88 -0
- package/src/package/checkboxes.ts +37 -0
- package/src/package/cleanup.test.ts +61 -0
- package/src/package/dashboard.test.ts +53 -0
- package/src/package/dashboard.ts +84 -0
- package/src/package/extensions.ts +16 -0
- package/src/package/merge-recipes.ts +84 -0
- package/src/package/names/conditional.ts +64 -0
- package/src/package/names/defined.test.ts +52 -0
- package/src/package/names/defined.ts +75 -0
- package/src/package/names/filter.ts +68 -0
- package/src/package/names/print-layout.ts +62 -0
- package/src/package/names/print.ts +62 -0
- package/src/package/new.ts +46 -0
- package/src/package/open/appearance.ts +46 -0
- package/src/package/open/directory.ts +61 -0
- package/src/package/open/restrictions.ts +27 -0
- package/src/package/open/snapshot.test.ts +48 -0
- package/src/package/open/snapshot.ts +34 -0
- package/src/package/open/source-write.ts +130 -0
- package/src/package/open/types.ts +73 -0
- package/src/package/open/worksheets.ts +149 -0
- package/src/package/positions.ts +40 -0
- package/src/package/read.ts +143 -0
- package/src/package/save/types.ts +57 -0
- package/src/package/save/worksheets.ts +126 -0
- package/src/package/selection-copy.test.ts +70 -0
- package/src/package/styles.ts +39 -0
- package/src/package/types.ts +52 -0
- package/src/package/workbook-views.ts +34 -0
- package/src/package/worksheets.test.ts +190 -0
- package/src/package/worksheets.ts +162 -0
- package/src/package/write.ts +175 -0
- package/src/pivot/cache/calculated.ts +34 -0
- package/src/pivot/cache/dates.ts +124 -0
- package/src/pivot/cache/groups.ts +11 -0
- package/src/pivot/cache/members.ts +99 -0
- package/src/pivot/cache/numbers.ts +63 -0
- package/src/pivot/cache/read.ts +131 -0
- package/src/pivot/cache/time.ts +20 -0
- package/src/pivot/cache/values.ts +43 -0
- package/src/pivot/cache/write.ts +117 -0
- package/src/pivot/definition/axes.ts +35 -0
- package/src/pivot/definition/dates.ts +87 -0
- package/src/pivot/definition/display.ts +86 -0
- package/src/pivot/definition/extension.ts +57 -0
- package/src/pivot/definition/field-settings/caption.ts +38 -0
- package/src/pivot/definition/field-settings/comparison.ts +47 -0
- package/src/pivot/definition/field-settings/field.ts +66 -0
- package/src/pivot/definition/field-settings/filters.ts +86 -0
- package/src/pivot/definition/field-settings/measure.ts +79 -0
- package/src/pivot/definition/field-settings/types.ts +19 -0
- package/src/pivot/definition/functions.ts +21 -0
- package/src/pivot/definition/items.ts +144 -0
- package/src/pivot/definition/members.ts +98 -0
- package/src/pivot/definition/numbers.ts +19 -0
- package/src/pivot/definition/presentation.ts +52 -0
- package/src/pivot/definition/read.ts +143 -0
- package/src/pivot/definition/report-layout.ts +39 -0
- package/src/pivot/definition/write.ts +157 -0
- package/src/pivot/package/calculated.test.ts +103 -0
- package/src/pivot/package/dates.test.ts +266 -0
- package/src/pivot/package/display.test.ts +133 -0
- package/src/pivot/package/field-settings.test.ts +59 -0
- package/src/pivot/package/layout.test.ts +148 -0
- package/src/pivot/package/measure-settings.test.ts +85 -0
- package/src/pivot/package/members.test.ts +167 -0
- package/src/pivot/package/numbers.test.ts +120 -0
- package/src/pivot/package/read.ts +93 -0
- package/src/pivot/package/roundtrip.test.ts +244 -0
- package/src/pivot/package/write.ts +103 -0
- package/src/pivot/types.ts +36 -0
- package/src/pivot/xml.ts +50 -0
- package/src/presentation.test.ts +186 -0
- package/src/roundtrip.test.ts +72 -0
- package/src/styles/checkbox/bags.ts +85 -0
- package/src/styles/checkbox/style.ts +45 -0
- package/src/styles/checkbox/types.ts +7 -0
- package/src/styles/color.ts +64 -0
- package/src/styles/differential-preview.ts +60 -0
- package/src/styles/differential.ts +119 -0
- package/src/styles/numbers.ts +9 -0
- package/src/styles/parts.ts +107 -0
- package/src/styles/read.ts +95 -0
- package/src/styles/reference.ts +14 -0
- package/src/styles/types.ts +9 -0
- package/src/styles/write.test.ts +88 -0
- package/src/styles/write.ts +162 -0
- package/src/table/conversion.test.ts +73 -0
- package/src/table/definition.ts +89 -0
- package/src/table/filter.ts +42 -0
- package/src/table/ownership.ts +112 -0
- package/src/table/read.test.ts +274 -0
- package/src/table/read.ts +117 -0
- package/src/table/remove.ts +55 -0
- package/src/table/sort.test.ts +79 -0
- package/src/table/styles/builtin.ts +40 -0
- package/src/table/styles/differential.ts +55 -0
- package/src/table/styles/preset-data.ts +17 -0
- package/src/table/styles/presets/dark.ts +104 -0
- package/src/table/styles/presets/light-grid.ts +68 -0
- package/src/table/styles/presets/light.ts +145 -0
- package/src/table/styles/presets/medium-edges.ts +131 -0
- package/src/table/styles/presets/medium.ts +131 -0
- package/src/table/styles/read.ts +70 -0
- package/src/table/styles/types.ts +27 -0
- package/src/table/totals.test.ts +77 -0
- package/src/table/totals.ts +79 -0
- package/src/table/types.ts +21 -0
- package/src/table/write.ts +189 -0
- package/src/types.ts +74 -0
- package/src/value/date.ts +21 -0
- package/src/worksheet/appearance.ts +55 -0
- package/src/worksheet/axis.test.ts +185 -0
- package/src/worksheet/axis.ts +131 -0
- package/src/worksheet/background/read.ts +41 -0
- package/src/worksheet/background/roundtrip.test.ts +77 -0
- package/src/worksheet/background/write.ts +96 -0
- package/src/worksheet/cell-shift.ts +44 -0
- package/src/worksheet/cells.ts +75 -0
- package/src/worksheet/checkbox/formats.ts +53 -0
- package/src/worksheet/checkbox/ranges.ts +112 -0
- package/src/worksheet/checkbox/write.test.ts +62 -0
- package/src/worksheet/conditional/color-scale.ts +61 -0
- package/src/worksheet/conditional/data-bar.ts +76 -0
- package/src/worksheet/conditional/extensions.ts +95 -0
- package/src/worksheet/conditional/icon-reference.ts +69 -0
- package/src/worksheet/conditional/icon-set.test.ts +60 -0
- package/src/worksheet/conditional/icon-set.ts +79 -0
- package/src/worksheet/conditional/preview.ts +44 -0
- package/src/worksheet/conditional/read.ts +185 -0
- package/src/worksheet/conditional/text.test.ts +71 -0
- package/src/worksheet/conditional/text.ts +122 -0
- package/src/worksheet/conditional/threshold.ts +47 -0
- package/src/worksheet/conditional/types.ts +20 -0
- package/src/worksheet/conditional/write-bar.ts +66 -0
- package/src/worksheet/conditional/write.test.ts +218 -0
- package/src/worksheet/conditional/write.ts +103 -0
- package/src/worksheet/copied-axis.ts +70 -0
- package/src/worksheet/data/rows.ts +59 -0
- package/src/worksheet/data/source.test.ts +68 -0
- package/src/worksheet/data/source.ts +31 -0
- package/src/worksheet/data/types.ts +9 -0
- package/src/worksheet/data.test.ts +314 -0
- package/src/worksheet/dimensions/columns.ts +87 -0
- package/src/worksheet/dimensions/write.test.ts +110 -0
- package/src/worksheet/dimensions/write.ts +36 -0
- package/src/worksheet/filters/advanced.test.ts +57 -0
- package/src/worksheet/filters/color.ts +105 -0
- package/src/worksheet/filters/icon.test.ts +83 -0
- package/src/worksheet/filters/icon.ts +39 -0
- package/src/worksheet/filters/read.ts +114 -0
- package/src/worksheet/filters/relative-dates.ts +47 -0
- package/src/worksheet/filters/restore-icons.ts +33 -0
- package/src/worksheet/filters/restore.ts +169 -0
- package/src/worksheet/filters/rules.ts +23 -0
- package/src/worksheet/filters/types.ts +23 -0
- package/src/worksheet/filters/visibility.ts +188 -0
- package/src/worksheet/filters/write.ts +121 -0
- package/src/worksheet/formula/cache.ts +29 -0
- package/src/worksheet/formula/external-results.test.ts +39 -0
- package/src/worksheet/formula/functions.ts +29 -0
- package/src/worksheet/formula/prefix.ts +27 -0
- package/src/worksheet/formula/shared/read.test.ts +121 -0
- package/src/worksheet/formula/shared/read.ts +94 -0
- package/src/worksheet/formula/shared/references.ts +100 -0
- package/src/worksheet/formula/shared/types.ts +21 -0
- package/src/worksheet/formula/spill-read.ts +54 -0
- package/src/worksheet/formula/spill-write.ts +32 -0
- package/src/worksheet/formula/spill.test.ts +101 -0
- package/src/worksheet/formula/write.test.ts +26 -0
- package/src/worksheet/hyperlinks/location.ts +59 -0
- package/src/worksheet/hyperlinks/model.ts +22 -0
- package/src/worksheet/hyperlinks/read.ts +70 -0
- package/src/worksheet/hyperlinks/types.ts +21 -0
- package/src/worksheet/hyperlinks/write.test.ts +203 -0
- package/src/worksheet/hyperlinks/write.ts +51 -0
- package/src/worksheet/merge.test.ts +58 -0
- package/src/worksheet/merge.ts +61 -0
- package/src/worksheet/outline/columns.ts +46 -0
- package/src/worksheet/outline/metadata.ts +68 -0
- package/src/worksheet/outline/native.ts +81 -0
- package/src/worksheet/outline/read.ts +50 -0
- package/src/worksheet/outline/roundtrip.test.ts +73 -0
- package/src/worksheet/outline/types.ts +37 -0
- package/src/worksheet/outline/write.ts +110 -0
- package/src/worksheet/positions.test.ts +46 -0
- package/src/worksheet/positions.ts +48 -0
- package/src/worksheet/print/breaks.ts +72 -0
- package/src/worksheet/print/elements.ts +16 -0
- package/src/worksheet/print/page-text.ts +139 -0
- package/src/worksheet/print/setup.test.ts +141 -0
- package/src/worksheet/print/setup.ts +116 -0
- package/src/worksheet/progress/read.ts +73 -0
- package/src/worksheet/progress/solid.ts +26 -0
- package/src/worksheet/progress/types.ts +11 -0
- package/src/worksheet/progress/write.test.ts +63 -0
- package/src/worksheet/progress/write.ts +46 -0
- package/src/worksheet/read.ts +197 -0
- package/src/worksheet/rich-text.test.ts +41 -0
- package/src/worksheet/rich-text.ts +76 -0
- package/src/worksheet/sort/read.ts +115 -0
- package/src/worksheet/sort/relocate.ts +62 -0
- package/src/worksheet/sort/roundtrip.test.ts +116 -0
- package/src/worksheet/sort/types.ts +11 -0
- package/src/worksheet/sort/write.ts +77 -0
- package/src/worksheet/template.ts +9 -0
- package/src/worksheet/text.ts +33 -0
- package/src/worksheet/validation/extended.ts +36 -0
- package/src/worksheet/validation/image.ts +7 -0
- package/src/worksheet/validation/list-options/portable.ts +90 -0
- package/src/worksheet/validation/list-options/types.ts +14 -0
- package/src/worksheet/validation/list-options/wps.ts +51 -0
- package/src/worksheet/validation/read.ts +162 -0
- package/src/worksheet/validation/text.ts +13 -0
- package/src/worksheet/validation/write.test.ts +259 -0
- package/src/worksheet/validation/write.ts +99 -0
- package/src/worksheet/view/coordinates.ts +39 -0
- package/src/worksheet/view/named/read.ts +116 -0
- package/src/worksheet/view/named/roundtrip.test.ts +136 -0
- package/src/worksheet/view/named/sort.ts +57 -0
- package/src/worksheet/view/named/types.ts +15 -0
- package/src/worksheet/view/named/write.ts +107 -0
- package/src/worksheet/view/named/xml.ts +33 -0
- package/src/worksheet/view/panes.ts +75 -0
- package/src/worksheet/view/read.ts +61 -0
- package/src/worksheet/view/relocate.ts +57 -0
- package/src/worksheet/view/write.test.ts +91 -0
- package/src/worksheet/view/write.ts +57 -0
- package/src/worksheet/write.ts +86 -0
- package/README.md +0 -3
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
The ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Contributors
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
15
|
+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
|
|
17
|
+
====
|
|
18
|
+
|
|
19
|
+
The following license is the one that governed sax, from which saxes
|
|
20
|
+
was forked. Isaac Schlueter is not *directly* involved with saxes so
|
|
21
|
+
don't go bugging him for saxes issues.
|
|
22
|
+
|
|
23
|
+
The ISC License
|
|
24
|
+
|
|
25
|
+
Copyright (c) Isaac Z. Schlueter and Contributors
|
|
26
|
+
|
|
27
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
28
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
29
|
+
copyright notice and this permission notice appear in all copies.
|
|
30
|
+
|
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
32
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
33
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
34
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
35
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
36
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
37
|
+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
38
|
+
|
|
39
|
+
====
|
|
40
|
+
|
|
41
|
+
`String.fromCodePoint` by Mathias Bynens is no longer used, but it can
|
|
42
|
+
still be found in old commits. It was once used according to terms of
|
|
43
|
+
MIT License, as follows:
|
|
44
|
+
|
|
45
|
+
Copyright Mathias Bynens <https://mathiasbynens.be/>
|
|
46
|
+
|
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
48
|
+
a copy of this software and associated documentation files (the
|
|
49
|
+
"Software"), to deal in the Software without restriction, including
|
|
50
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
51
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
52
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
53
|
+
the following conditions:
|
|
54
|
+
|
|
55
|
+
The above copyright notice and this permission notice shall be
|
|
56
|
+
included in all copies or substantial portions of the Software.
|
|
57
|
+
|
|
58
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
59
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
60
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
61
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
62
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
63
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
64
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Copyright Louis-Dominique Dubeau and contributors to xmlchars
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
5
|
+
the Software without restriction, including without limitation the rights to
|
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
8
|
+
subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quirekit/xlsx",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Wang Yishuai (王一帅)"
|
|
7
|
+
},
|
|
8
|
+
"contributors": [
|
|
9
|
+
{
|
|
10
|
+
"name": "上海轻书远行信息科技有限公司"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/quirekit/quirekit.git",
|
|
16
|
+
"directory": "packages/xlsx"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/quirekit/quirekit/tree/main/packages/xlsx#readme",
|
|
19
|
+
"bugs": "https://github.com/quirekit/quirekit/issues",
|
|
20
|
+
"description": "XLSX file exchange for QuireKit workbooks.",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"files": [
|
|
24
|
+
"LICENSE.md",
|
|
25
|
+
"THIRD_PARTY_NOTICES.md",
|
|
26
|
+
"licenses",
|
|
27
|
+
"dist",
|
|
28
|
+
"src"
|
|
29
|
+
],
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.mts",
|
|
33
|
+
"import": "./dist/index.mjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"types": "./dist/index.d.mts",
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@xmldom/xmldom": "0.9.12",
|
|
39
|
+
"fflate": "0.8.3",
|
|
40
|
+
"saxes": "5.0.1",
|
|
41
|
+
"uuid": "14.0.3",
|
|
42
|
+
"@quirekit/workbook": "0.3.0",
|
|
43
|
+
"@quirekit/chart": "0.3.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"tsdown": "0.22.3",
|
|
47
|
+
"typescript": "6.0.3",
|
|
48
|
+
"vitest": "4.1.9"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsdown src/index.ts --format esm --dts --clean --out-dir dist",
|
|
52
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
53
|
+
"test": "vitest run src"
|
|
54
|
+
}
|
|
6
55
|
}
|
package/src/bundle.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { zipSync } from "fflate";
|
|
2
|
+
import type { WorkbookSnapshot } from "@quirekit/workbook";
|
|
3
|
+
import { createXlsx } from "./create";
|
|
4
|
+
|
|
5
|
+
/** @param workbooks - Independent data workbooks. @returns ZIP with distinct, flat XLSX entries. */
|
|
6
|
+
export function createXlsxBundle(workbooks: readonly WorkbookSnapshot[]): Uint8Array {
|
|
7
|
+
const files: Record<string, Uint8Array> = Object.create(null);
|
|
8
|
+
const names = new Set<string>();
|
|
9
|
+
for (const workbook of workbooks) {
|
|
10
|
+
const base = workbook.name.replace(/\.xlsx$/iu, "").replace(/[\\/:*?"<>|\u0000-\u001f]/gu, " ").trim() || "Workbook";
|
|
11
|
+
let name = base + ".xlsx";
|
|
12
|
+
for (let index = 2; names.has(name.normalize().toUpperCase()); index++) name = base + " (" + index + ").xlsx";
|
|
13
|
+
names.add(name.normalize().toUpperCase());
|
|
14
|
+
files[name] = createXlsx(workbook);
|
|
15
|
+
}
|
|
16
|
+
return zipSync(files, { level: 0 });
|
|
17
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { workbookColumns, workbookRows } from "@quirekit/workbook";
|
|
2
|
+
import { child, children, parsePart, readIndex, rootOf, spreadNs } from "../../opc/xml";
|
|
3
|
+
import { hasKnownAttributes, hasKnownChildren } from "../../opc/shape";
|
|
4
|
+
import { decodeXlsxText } from "../../worksheet/text";
|
|
5
|
+
import type { XlsxLegacyComment } from "../types";
|
|
6
|
+
import { commentAddress, commentUuid, invalidXlsxComment, vmlExcelNs, vmlNs, vmlOfficeNs } from "../xml";
|
|
7
|
+
|
|
8
|
+
/** @param bytes - Legacy note part. @param path - Native package path. @param sheetId - Owning worksheet.
|
|
9
|
+
* @returns Plain notes in document order, including native placeholders. */
|
|
10
|
+
export function readXlsxLegacyComments(bytes: Uint8Array | undefined, path: string, sheetId: string): XlsxLegacyComment[] {
|
|
11
|
+
const root = rootOf(parsePart(bytes, path), spreadNs, "comments");
|
|
12
|
+
const authors = child(root, "authors"), list = child(root, "commentList");
|
|
13
|
+
if (!authors || !list || children(root).length !== 2) throw invalidXlsxComment();
|
|
14
|
+
const names = children(authors).map(node => {
|
|
15
|
+
if (node.namespaceURI !== spreadNs || node.localName !== "author" || children(node).length) throw invalidXlsxComment();
|
|
16
|
+
return decodeXlsxText(node.textContent ?? "").trim();
|
|
17
|
+
});
|
|
18
|
+
return children(list).map(node => {
|
|
19
|
+
if (node.namespaceURI !== spreadNs || node.localName !== "comment"
|
|
20
|
+
|| !hasKnownAttributes(node, ["ref", "authorId", "shapeId", "guid"])) throw invalidXlsxComment();
|
|
21
|
+
const author = names[readIndex(node, "authorId") ?? -1];
|
|
22
|
+
const cell = commentAddress(sheetId, node.getAttribute("ref") ?? "");
|
|
23
|
+
const id = commentUuid(node.getAttribute("guid"));
|
|
24
|
+
const body = child(node, "text");
|
|
25
|
+
if (!author || !body || body.namespaceURI !== spreadNs || children(node).length !== 1) throw invalidXlsxComment();
|
|
26
|
+
const atoms = children(body);
|
|
27
|
+
// A threaded placeholder's style is for older readers only. Its native discussion
|
|
28
|
+
// retains the text and attribution even when the compatibility body is styled.
|
|
29
|
+
const placeholder = /^tc=/iu.test(author);
|
|
30
|
+
const text = atoms.map(item => {
|
|
31
|
+
if (item.namespaceURI === spreadNs && item.localName === "t" && !children(item).length) return item.textContent ?? "";
|
|
32
|
+
const run = placeholder && item.namespaceURI === spreadNs && item.localName === "r" && child(item, "t");
|
|
33
|
+
if (run && !children(run).length) return run.textContent ?? "";
|
|
34
|
+
throw invalidXlsxComment();
|
|
35
|
+
}).join("");
|
|
36
|
+
return { cell, author, text: decodeXlsxText(text), ...(id && { id }) };
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** @param bytes - VML belonging to the worksheet. @param path - VML part name.
|
|
41
|
+
* @param notes - Structured comment entries. Rejects graphics and mismatched note anchors. */
|
|
42
|
+
export function verifyXlsxNoteDrawing(bytes: Uint8Array | undefined, path: string, notes: readonly XlsxLegacyComment[]): void {
|
|
43
|
+
const root = parsePart(bytes, path).documentElement;
|
|
44
|
+
if (!root || root.localName !== "xml") throw invalidXlsxComment();
|
|
45
|
+
const anchors = new Set(notes.map(({ cell: { row, column } }) => row + ":" + column));
|
|
46
|
+
if (anchors.size !== notes.length) throw invalidXlsxComment();
|
|
47
|
+
for (const node of children(root)) {
|
|
48
|
+
if (node.namespaceURI === vmlOfficeNs && node.localName === "shapelayout" || node.namespaceURI === vmlNs && node.localName === "shapetype") continue;
|
|
49
|
+
if (node.namespaceURI !== vmlNs || node.localName !== "shape"
|
|
50
|
+
|| !hasKnownChildren(node, ["fill", "stroke", "shadow", "path", "textbox", "ClientData"], vmlNs, { ClientData: vmlExcelNs })
|
|
51
|
+
|| child(node, "textbox")?.textContent?.trim() || /visibility\s*:\s*visible/iu.test(node.getAttribute("style") ?? "")) throw invalidXlsxComment();
|
|
52
|
+
const client = child(node, "ClientData");
|
|
53
|
+
if (client?.namespaceURI !== vmlExcelNs || client.getAttribute("ObjectType") !== "Note"
|
|
54
|
+
|| !hasKnownChildren(client, ["MoveWithCells", "SizeWithCells", "Anchor", "AutoFill", "Row", "Column"])) {
|
|
55
|
+
throw invalidXlsxComment();
|
|
56
|
+
}
|
|
57
|
+
const row = noteCoordinate(child(client, "Row")?.textContent), column = noteCoordinate(child(client, "Column")?.textContent);
|
|
58
|
+
if (!Number.isSafeInteger(row) || row >= workbookRows || !Number.isSafeInteger(column) || column >= workbookColumns) throw invalidXlsxComment();
|
|
59
|
+
if (!anchors.delete(row + ":" + column)) throw invalidXlsxComment();
|
|
60
|
+
}
|
|
61
|
+
if (anchors.size) throw invalidXlsxComment();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** @param text - VML zero-based position. @returns Number or an invalid sentinel. */
|
|
65
|
+
function noteCoordinate(text: string | null | undefined): number {
|
|
66
|
+
const value = text?.trim();
|
|
67
|
+
return value && /^\d+$/u.test(value) ? Number(value) : NaN;
|
|
68
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { maximumWorkbookCommentLength, workbookColumns, workbookRows, type WorkbookAddress, type WorkbookCommentThread } from "@quirekit/workbook";
|
|
2
|
+
import { strToU8 } from "fflate";
|
|
3
|
+
import { child, parsePart, rootOf, spreadNs, writePart } from "../../opc/xml";
|
|
4
|
+
import { encodeXlsxText, insertXlsxText } from "../../worksheet/text";
|
|
5
|
+
import { commentGuid, commentReference, vmlExcelNs, vmlNs, vmlOfficeNs } from "../xml";
|
|
6
|
+
|
|
7
|
+
/** @param path - Native legacy note part. @param discussions - Notes and thread roots on this sheet.
|
|
8
|
+
* @returns Legacy notes and compatibility placeholders readable by older clients. */
|
|
9
|
+
export function writeXlsxLegacyComments(path: string, discussions: readonly WorkbookCommentThread[]): Uint8Array {
|
|
10
|
+
const document = parsePart(strToU8('<comments xmlns="' + spreadNs + '"><authors/><commentList/></comments>'), path);
|
|
11
|
+
const root = rootOf(document, spreadNs, "comments"), authors = child(root, "authors")!, list = child(root, "commentList")!;
|
|
12
|
+
const names = new Map<string, number>();
|
|
13
|
+
for (const thread of discussions) {
|
|
14
|
+
const author = thread.kind === "note" ? thread.messages[0].author.name : "tc=" + commentGuid(thread.id);
|
|
15
|
+
let index = names.get(author);
|
|
16
|
+
if (index === undefined) {
|
|
17
|
+
index = names.size;
|
|
18
|
+
names.set(author, index);
|
|
19
|
+
insertXlsxText(document, authors, "author", encodeXlsxText(author));
|
|
20
|
+
}
|
|
21
|
+
const note = document.createElementNS(spreadNs, "comment");
|
|
22
|
+
note.setAttribute("ref", commentReference(thread.cell));
|
|
23
|
+
note.setAttribute("authorId", String(index));
|
|
24
|
+
note.setAttribute("guid", commentGuid(thread.id));
|
|
25
|
+
const text = document.createElementNS(spreadNs, "text");
|
|
26
|
+
insertXlsxText(document, text, "t", encodeXlsxText(legacyBody(thread)));
|
|
27
|
+
note.appendChild(text);
|
|
28
|
+
list.appendChild(note);
|
|
29
|
+
}
|
|
30
|
+
return writePart(document);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @param thread - Current note or discussion. @returns A readable note body within the legacy text limit. */
|
|
34
|
+
function legacyBody(thread: WorkbookCommentThread): string {
|
|
35
|
+
if (thread.kind === "note") return thread.messages[0].text;
|
|
36
|
+
let body = thread.resolved ? "已解决\n" : "";
|
|
37
|
+
for (const [index, { author, text }] of thread.messages.entries()) {
|
|
38
|
+
body += (index === 0 ? "" : "\n\n") + author.name + "\n" + text;
|
|
39
|
+
if (body.length > maximumWorkbookCommentLength) {
|
|
40
|
+
return body.slice(0, maximumWorkbookCommentLength - 1).replace(/[\uD800-\uDBFF]$/u, "") + "…";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return body;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @param discussions - Notes in the same order as the legacy entries. @returns Hidden note shapes anchored to their cells. */
|
|
47
|
+
export function writeXlsxNoteDrawing(discussions: readonly WorkbookCommentThread[]): Uint8Array {
|
|
48
|
+
const shapes = discussions.map(({ cell }, index) =>
|
|
49
|
+
`<v:shape id="_x0000_s${1025 + index}" type="#_x0000_t202" style="position:absolute;width:108pt;height:60pt;visibility:hidden;z-index:${index + 1}" fillcolor="#ffffe1" o:insetmode="auto">`
|
|
50
|
+
+ '<v:fill color2="#ffffe1"/><v:shadow color="black" obscured="t"/><v:path o:connecttype="none"/><v:textbox><div/></v:textbox>'
|
|
51
|
+
+ `<x:ClientData ObjectType="Note"><x:MoveWithCells/><x:SizeWithCells/><x:Anchor>${legacyAnchor(cell)}</x:Anchor><x:AutoFill>False</x:AutoFill>`
|
|
52
|
+
+ `<x:Row>${cell.row}</x:Row><x:Column>${cell.column}</x:Column></x:ClientData></v:shape>`);
|
|
53
|
+
return strToU8(`<xml xmlns:v="${vmlNs}" xmlns:o="${vmlOfficeNs}" xmlns:x="${vmlExcelNs}">`
|
|
54
|
+
+ '<o:shapelayout v:ext="edit"><o:idmap v:ext="edit" data="1"/></o:shapelayout>'
|
|
55
|
+
+ '<v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe">'
|
|
56
|
+
+ '<v:stroke joinstyle="miter"/><v:path gradientshapeok="t" o:connecttype="rect"/></v:shapetype>'
|
|
57
|
+
+ shapes.join("") + "</xml>");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** @param cell - Zero-based note position. @returns Default legacy tooltip rectangle within native sheet bounds. */
|
|
61
|
+
function legacyAnchor({ row, column }: WorkbookAddress): string {
|
|
62
|
+
const left = Math.min(workbookColumns - 3, column + 1), top = Math.min(workbookRows - 5, Math.max(0, row - 1));
|
|
63
|
+
return [left, 10, top, 4, left + 2, 10, top + 4, 4].join(", ");
|
|
64
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Element } from "@xmldom/xmldom";
|
|
2
|
+
import { formatWorkbookRange, parseWorkbookRange, workbookCommentCellRange, workbookRangesOverlap, workbookRangeSize,
|
|
3
|
+
type WorkbookCommentThread, type WorkbookRange } from "@quirekit/workbook";
|
|
4
|
+
import { hasKnownAttributes } from "../../opc/shape";
|
|
5
|
+
import { child, children, spreadNs } from "../../opc/xml";
|
|
6
|
+
import { commentReference, commentUuid, invalidXlsxComment } from "../xml";
|
|
7
|
+
|
|
8
|
+
const namespace = "urn:quirekit:spreadsheet:comment-ranges:1";
|
|
9
|
+
|
|
10
|
+
/** @param element - Worksheet extension. @returns Whether it is a recognized comment-range envelope. */
|
|
11
|
+
export function isXlsxCommentRangeExtension(element: Element): boolean {
|
|
12
|
+
const [body, ...other] = children(element);
|
|
13
|
+
return element.namespaceURI === spreadNs && element.localName === "ext" && element.getAttribute("uri") === namespace
|
|
14
|
+
&& body?.namespaceURI === namespace && body.localName === "ranges" && other.length === 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** @param worksheet - Original sheet. @param sheetId - Current canonical worksheet identity.
|
|
18
|
+
* @param threads - Threads established by native comments and legacy placeholders.
|
|
19
|
+
* @returns Native discussions with the associated ranges restored where the anchor still agrees. */
|
|
20
|
+
export function readXlsxCommentRanges(worksheet: Element, sheetId: string, threads: readonly WorkbookCommentThread[]): WorkbookCommentThread[] {
|
|
21
|
+
const list = child(worksheet, "extLst");
|
|
22
|
+
const records = list ? children(list).filter(isXlsxCommentRangeExtension) : [];
|
|
23
|
+
if (!records.length) return [...threads];
|
|
24
|
+
const payload = child(records[0]!, "ranges")!;
|
|
25
|
+
if (records.length !== 1 || !hasKnownAttributes(records[0]!, ["uri"]) || !hasKnownAttributes(payload, [])) throw invalidXlsxComment();
|
|
26
|
+
const known = new Map(threads.map(thread => [thread.id, thread]));
|
|
27
|
+
const seen = new Set<string>();
|
|
28
|
+
const valid = new Map<string, WorkbookRange>();
|
|
29
|
+
for (const node of children(payload)) {
|
|
30
|
+
const id = commentUuid(node.getAttribute("id"));
|
|
31
|
+
const reference = node.getAttribute("ref") ?? "";
|
|
32
|
+
const anchor = node.getAttribute("anchor") ?? "";
|
|
33
|
+
if (node.namespaceURI !== namespace || node.localName !== "range" || children(node).length
|
|
34
|
+
|| !hasKnownAttributes(node, ["id", "ref", "anchor"]) || !id || seen.has(id) || reference.length > 30 || anchor.length > 12) {
|
|
35
|
+
throw invalidXlsxComment();
|
|
36
|
+
}
|
|
37
|
+
seen.add(id);
|
|
38
|
+
const range = parseWorkbookRange(sheetId, reference);
|
|
39
|
+
const native = parseWorkbookRange(sheetId, anchor);
|
|
40
|
+
if (workbookRangeSize(range) <= 1 || workbookRangeSize(native) !== 1 || !workbookRangesOverlap(range, native)) throw invalidXlsxComment();
|
|
41
|
+
const thread = known.get(id);
|
|
42
|
+
// A different producer may move or delete the native comment while retaining the extension.
|
|
43
|
+
if (thread && commentReference(thread.cell) === formatWorkbookRange(native)) valid.set(id, range);
|
|
44
|
+
}
|
|
45
|
+
return threads.map(thread => {
|
|
46
|
+
const range = valid.get(thread.id);
|
|
47
|
+
return range ? { ...thread, range } : thread;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @param worksheet - Staged sheet. @param threads - Published native discussions for it. */
|
|
52
|
+
export function writeXlsxCommentRanges(worksheet: Element, threads: readonly WorkbookCommentThread[]): void {
|
|
53
|
+
let list = child(worksheet, "extLst");
|
|
54
|
+
const earlier = list && children(list).find(isXlsxCommentRangeExtension);
|
|
55
|
+
if (list && earlier) list.removeChild(earlier);
|
|
56
|
+
const regions = threads.filter(thread => thread.range !== undefined);
|
|
57
|
+
if (!regions.length) {
|
|
58
|
+
if (earlier && list && !children(list).length) worksheet.removeChild(list);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const document = worksheet.ownerDocument!;
|
|
62
|
+
if (!list) {
|
|
63
|
+
list = document.createElementNS(spreadNs, "extLst");
|
|
64
|
+
worksheet.appendChild(list);
|
|
65
|
+
}
|
|
66
|
+
const record = document.createElementNS(spreadNs, "ext");
|
|
67
|
+
record.setAttribute("uri", namespace);
|
|
68
|
+
const payload = document.createElementNS(namespace, "qkc:ranges");
|
|
69
|
+
for (const thread of regions) {
|
|
70
|
+
const node = document.createElementNS(namespace, "qkc:range");
|
|
71
|
+
node.setAttribute("id", thread.id);
|
|
72
|
+
node.setAttribute("anchor", formatWorkbookRange(workbookCommentCellRange(thread.cell)));
|
|
73
|
+
node.setAttribute("ref", formatWorkbookRange(thread.range!));
|
|
74
|
+
payload.appendChild(node);
|
|
75
|
+
}
|
|
76
|
+
record.appendChild(payload);
|
|
77
|
+
list.appendChild(record);
|
|
78
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { createWorkbookCommentStore, type WorkbookCommentThread } from "@quirekit/workbook";
|
|
2
|
+
import { v4 as uuidv4 } from "uuid";
|
|
3
|
+
import { verifyXlsxPartOwnership } from "../../opc/ownership";
|
|
4
|
+
import { readRelationships, relationshipsPath } from "../../opc/relationships";
|
|
5
|
+
import type { PackageRelationship } from "../../opc/types";
|
|
6
|
+
import { children, parsePart, parseWorksheetPart, relationshipNs } from "../../opc/xml";
|
|
7
|
+
import { readXlsxLegacyComments, verifyXlsxNoteDrawing } from "../legacy/read";
|
|
8
|
+
import { readXlsxCommentPeople, readXlsxCommentThreads } from "../thread/read";
|
|
9
|
+
import type { XlsxCommentImport, XlsxLegacyComment } from "../types";
|
|
10
|
+
import { commentContentTypes, commentRoles, commentUuid, invalidXlsxComment } from "../xml";
|
|
11
|
+
import { readXlsxCommentRanges } from "./ranges";
|
|
12
|
+
|
|
13
|
+
/** @param archive - Original ZIP parts. @param workbook - Native workbook path. @param related - Workbook relationships.
|
|
14
|
+
* @param sheets - Native worksheet paths by stable identity. @param restrictions - Read-only diagnostics.
|
|
15
|
+
* @returns Workbook comments whose native parts can safely be replaced. */
|
|
16
|
+
export function readXlsxCommentPackage(archive: Readonly<Record<string, Uint8Array>>, workbook: string,
|
|
17
|
+
related: ReadonlyMap<string, PackageRelationship>, sheets: ReadonlyMap<string, string>, restrictions: Set<string>): XlsxCommentImport {
|
|
18
|
+
try {
|
|
19
|
+
const owners = new Map<string, ReadonlySet<string>>();
|
|
20
|
+
const types = new Map<string, string>();
|
|
21
|
+
const worksheetRelations = new Map<string, ReadonlySet<string>>();
|
|
22
|
+
const legacyDrawings = new Set<string>();
|
|
23
|
+
/** @param relation - Candidate replacement part. @param owner - Declared owner. @param type - Expected media type.
|
|
24
|
+
* @returns Path of the owner-local part. */
|
|
25
|
+
function own(relation: PackageRelationship, owner: string, type: string): string {
|
|
26
|
+
const path = relation.path;
|
|
27
|
+
if (!path || owners.has(path) || !archive[path] || archive[relationshipsPath(path)]) throw invalidXlsxComment();
|
|
28
|
+
owners.set(path, new Set([owner]));
|
|
29
|
+
types.set(path, type);
|
|
30
|
+
return path;
|
|
31
|
+
}
|
|
32
|
+
const peopleRelation = uniqueCommentRole(related, commentRoles.people);
|
|
33
|
+
const peoplePath = peopleRelation && own(peopleRelation, workbook, commentContentTypes.people);
|
|
34
|
+
const people = peoplePath ? readXlsxCommentPeople(archive[peoplePath], peoplePath) : new Map();
|
|
35
|
+
const threads: WorkbookCommentThread[] = [];
|
|
36
|
+
const legacyPeople = new Map<string, string>();
|
|
37
|
+
for (const [sheetId, path] of sheets) {
|
|
38
|
+
const relsPath = relationshipsPath(path);
|
|
39
|
+
if (!archive[relsPath]) continue;
|
|
40
|
+
const links = readRelationships(parsePart(archive[relsPath], relsPath), path);
|
|
41
|
+
const modern = uniqueCommentRole(links, commentRoles.thread);
|
|
42
|
+
const legacy = uniqueCommentRole(links, commentRoles.legacy);
|
|
43
|
+
if (!modern && !legacy) continue;
|
|
44
|
+
if (!legacy) throw invalidXlsxComment();
|
|
45
|
+
const legacyPath = own(legacy, path, commentContentTypes.legacy);
|
|
46
|
+
const notes = readXlsxLegacyComments(archive[legacyPath], legacyPath, sheetId);
|
|
47
|
+
const worksheet = parseWorksheetPart(archive[path], path);
|
|
48
|
+
const drawings = children(worksheet, "legacyDrawing");
|
|
49
|
+
const drawing = links.get(drawings[0]?.getAttributeNS(relationshipNs, "id") ?? "");
|
|
50
|
+
if (drawings.length > 1 || drawings.length && drawing?.type !== commentRoles.drawing) throw invalidXlsxComment();
|
|
51
|
+
const ids = new Set([legacy.id]);
|
|
52
|
+
if (drawing) {
|
|
53
|
+
const target = own(drawing, path, commentContentTypes.drawing);
|
|
54
|
+
verifyXlsxNoteDrawing(archive[target], target, notes);
|
|
55
|
+
ids.add(drawing.id);
|
|
56
|
+
legacyDrawings.add(path);
|
|
57
|
+
}
|
|
58
|
+
const placeholders = new Map<string, XlsxLegacyComment>();
|
|
59
|
+
for (const note of notes) {
|
|
60
|
+
const id = note.author.toLowerCase().startsWith("tc=") && commentUuid(note.author.slice(3));
|
|
61
|
+
if (id) {
|
|
62
|
+
if (placeholders.has(id) || note.id && note.id !== id) throw invalidXlsxComment();
|
|
63
|
+
placeholders.set(id, note);
|
|
64
|
+
} else {
|
|
65
|
+
const authorId = legacyPeople.get(note.author) ?? uuidv4();
|
|
66
|
+
legacyPeople.set(note.author, authorId);
|
|
67
|
+
const message = { id: note.id ?? uuidv4(), author: { id: authorId, name: note.author }, text: note.text };
|
|
68
|
+
threads.push({ id: message.id, cell: note.cell, kind: "note", resolved: false, messages: [message] });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (modern) {
|
|
72
|
+
const part = own(modern, path, commentContentTypes.thread);
|
|
73
|
+
const native = readXlsxCommentThreads(archive[part], part, sheetId, people, placeholders);
|
|
74
|
+
threads.push(...readXlsxCommentRanges(worksheet, sheetId, native));
|
|
75
|
+
ids.add(modern.id);
|
|
76
|
+
} else if (placeholders.size) throw invalidXlsxComment();
|
|
77
|
+
worksheetRelations.set(path, ids);
|
|
78
|
+
}
|
|
79
|
+
if (!owners.size) return { threads };
|
|
80
|
+
verifyXlsxPartOwnership(archive, owners, types);
|
|
81
|
+
const discussions = createWorkbookCommentStore(threads, [...sheets.keys()].map(id => ({ id }))).list();
|
|
82
|
+
return { threads: discussions, graph: { peopleRelation: peopleRelation?.id, people, worksheetRelations, legacyDrawings, parts: new Set(owners.keys()) } };
|
|
83
|
+
} catch {
|
|
84
|
+
restrictions.add("存在无法安全写回的单元格评论或旧式批注");
|
|
85
|
+
return { threads: [] };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** @param relationships - Owner-scoped relationship table. @param role - Full native relationship URI.
|
|
90
|
+
* @returns The single part of that role, when present. */
|
|
91
|
+
function uniqueCommentRole(relationships: ReadonlyMap<string, PackageRelationship>, role: string): PackageRelationship | undefined {
|
|
92
|
+
const parts = [...relationships.values()].filter(relation => relation.type === role);
|
|
93
|
+
if (parts.length > 1) throw invalidXlsxComment();
|
|
94
|
+
return parts[0];
|
|
95
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { strFromU8, strToU8, unzipSync, zipSync } from "fflate";
|
|
2
|
+
import { v4 as uuidv4 } from "uuid";
|
|
3
|
+
import { openWorkbook, parseWorkbookRange, type WorkbookCommentThread, type WorkbookCommandCall, type WorkbookSession,
|
|
4
|
+
type WorkbookSnapshot } from "@quirekit/workbook";
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
import { createXlsx, openXlsx } from "../../index";
|
|
7
|
+
|
|
8
|
+
const seed: WorkbookSnapshot = { id: "review-workbook", version: 1, revision: 0, name: "审阅订单", sheets: [
|
|
9
|
+
{ id: "orders", name: "订单", cells: [{ row: 0, column: 0, input: { kind: "value", value: "订单号" } }] },
|
|
10
|
+
{ id: "summary", name: "汇总", cells: [] }
|
|
11
|
+
] };
|
|
12
|
+
const person = { id: uuidv4(), name: "巡检人" }, reviewer = { id: uuidv4(), name: "审阅人" }, id = uuidv4();
|
|
13
|
+
const thread: WorkbookCommentThread = { id, cell: { sheetId: "orders", row: 1, column: 1 }, kind: "thread", resolved: true, messages: [
|
|
14
|
+
{ id, author: person, text: "请核对 <金额> & 单位\n带字面值 _x0041_ 😀", createdAt: 1_800_000_000_000 },
|
|
15
|
+
{ id: uuidv4(), author: reviewer, text: "已核对结清" }
|
|
16
|
+
] };
|
|
17
|
+
|
|
18
|
+
/** @param workbook - Installed worksheet. @param commands - Requests at the current revision. @returns Confirmed receipt. */
|
|
19
|
+
function edit(workbook: WorkbookSession, ...commands: WorkbookCommandCall[]) {
|
|
20
|
+
const baseRevision = workbook.revision;
|
|
21
|
+
return workbook.commit(workbook.prepare({ baseRevision, operationId: "comment-" + baseRevision, commands }).id);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe("native worksheet comments", () => {
|
|
25
|
+
it("keeps both native threads and readable compatibility notes at the same location through a row insertion", async () => {
|
|
26
|
+
const bytes = createXlsx({ ...seed, commentThreads: [thread] });
|
|
27
|
+
const parts = unzipSync(bytes);
|
|
28
|
+
const modern = Object.keys(parts).find(path => path.includes("/threadedComments/"))!;
|
|
29
|
+
const note = Object.keys(parts).find(path => path.includes("/comments/"))!;
|
|
30
|
+
expect(strFromU8(parts[modern]!)).toContain('ref="B2"');
|
|
31
|
+
expect(strFromU8(parts[modern]!)).toContain('done="1"');
|
|
32
|
+
expect(strFromU8(parts[note]!)).toContain("tc={" + id.toUpperCase() + "}");
|
|
33
|
+
expect(strFromU8(parts[note]!)).toContain("已核对结清");
|
|
34
|
+
const file = openXlsx("审阅订单", bytes);
|
|
35
|
+
expect(file.restrictions).toEqual([]);
|
|
36
|
+
const sheet = file.snapshot.sheets[0]!.id;
|
|
37
|
+
expect(file.snapshot.commentThreads).toEqual([{ ...thread, cell: { ...thread.cell, sheetId: sheet } }]);
|
|
38
|
+
expect(file.write(file.snapshot)).toEqual(bytes);
|
|
39
|
+
const workbook = await openWorkbook(file.snapshot, { commentActor: () => person });
|
|
40
|
+
try {
|
|
41
|
+
await edit(workbook, { name: "insertRows", target: parseWorkbookRange(sheet, "B2"), params: { position: "before" } });
|
|
42
|
+
const result = openXlsx("移动后", file.write(workbook.snapshot()));
|
|
43
|
+
expect(result.restrictions).toEqual([]);
|
|
44
|
+
expect(result.snapshot.commentThreads?.[0]).toMatchObject({ id, cell: { row: 2, column: 1 }, resolved: true, messages: thread.messages });
|
|
45
|
+
await edit(workbook, { name: "removeCellComment", target: parseWorkbookRange(sheet, "B3"), params: { threadId: id, messageId: id } });
|
|
46
|
+
const cleared = unzipSync(file.write(workbook.snapshot()));
|
|
47
|
+
expect(Object.keys(cleared).filter(path => /threadedComments|\/comments\/|\/persons\/|\.vml$/u.test(path))).toEqual([]);
|
|
48
|
+
expect(strFromU8(cleared["xl/worksheets/sheet1.xml"]!)).not.toContain("legacyDrawing");
|
|
49
|
+
expect(cleared["xl/worksheets/sheet2.xml"]).toEqual(parts["xl/worksheets/sheet2.xml"]);
|
|
50
|
+
} finally { await workbook.close(); }
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("keeps legacy notes until a reply promotes them and protects an unsupported drawing", async () => {
|
|
54
|
+
const note: WorkbookCommentThread = { ...thread, kind: "note", resolved: false, messages: [thread.messages[0]] };
|
|
55
|
+
const bytes = createXlsx({ ...seed, commentThreads: [note] });
|
|
56
|
+
const file = openXlsx("旧式批注", bytes);
|
|
57
|
+
expect(file.restrictions).toEqual([]);
|
|
58
|
+
expect(file.snapshot.commentThreads?.[0]).toMatchObject({ id, kind: "note", messages: [{ text: note.messages[0].text, author: { name: person.name } }] });
|
|
59
|
+
const workbook = await openWorkbook(file.snapshot, { commentActor: () => reviewer });
|
|
60
|
+
try {
|
|
61
|
+
const target = parseWorkbookRange(file.snapshot.sheets[0]!.id, "B2");
|
|
62
|
+
await edit(workbook, { name: "replyToCellComment", target, params: { threadId: id, text: "转成线程" } });
|
|
63
|
+
const reopened = openXlsx("回复批注", file.write(workbook.snapshot()));
|
|
64
|
+
expect(reopened.restrictions).toEqual([]);
|
|
65
|
+
expect(reopened.snapshot.commentThreads?.[0]).toMatchObject({ id, kind: "thread", messages: [{ text: note.messages[0].text }, { text: "转成线程" }] });
|
|
66
|
+
} finally { await workbook.close(); }
|
|
67
|
+
const modified = unzipSync(bytes);
|
|
68
|
+
const drawing = Object.keys(modified).find(path => path.endsWith(".vml"))!;
|
|
69
|
+
modified[drawing] = strToU8(strFromU8(modified[drawing]!).replace('ObjectType="Note"', 'ObjectType="Button"'));
|
|
70
|
+
const unsupported = zipSync(modified);
|
|
71
|
+
const original = openXlsx("附加控件", unsupported);
|
|
72
|
+
expect(original.restrictions).toContain("存在无法安全写回的单元格评论或旧式批注");
|
|
73
|
+
expect(original.original()).toEqual(unsupported);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("preserves a range and its native anchor, with a single-cell fallback if the extension is removed", async () => {
|
|
77
|
+
const range = parseWorkbookRange("orders", "A2:D4");
|
|
78
|
+
const file = createXlsx({ ...seed, commentThreads: [{ ...thread, range }] });
|
|
79
|
+
const parts = unzipSync(file);
|
|
80
|
+
const path = "xl/worksheets/sheet1.xml";
|
|
81
|
+
const sheetXml = strFromU8(parts[path]!);
|
|
82
|
+
expect(sheetXml).toContain('anchor="B2" ref="A2:D4"');
|
|
83
|
+
const modern = Object.keys(parts).find(name => name.includes("/threadedComments/"))!;
|
|
84
|
+
const legacy = Object.keys(parts).find(name => name.includes("/comments/"))!;
|
|
85
|
+
expect(strFromU8(parts[modern]!)).toContain('ref="B2"');
|
|
86
|
+
expect(strFromU8(parts[legacy]!)).toContain('ref="B2"');
|
|
87
|
+
|
|
88
|
+
const opened = openXlsx("选区评论", file);
|
|
89
|
+
expect(opened.restrictions).toEqual([]);
|
|
90
|
+
const sheetId = opened.snapshot.sheets[0]!.id;
|
|
91
|
+
expect(opened.snapshot.commentThreads).toEqual([{ ...thread, cell: { ...thread.cell, sheetId }, range: { ...range, sheetId } }]);
|
|
92
|
+
const workbook = await openWorkbook(opened.snapshot, { commentActor: () => person });
|
|
93
|
+
try {
|
|
94
|
+
await edit(workbook, { name: "deleteRows", target: parseWorkbookRange(sheetId, "B2"), params: {} });
|
|
95
|
+
const moved = openXlsx("范围移动", opened.write(workbook.snapshot()));
|
|
96
|
+
expect(moved.restrictions).toEqual([]);
|
|
97
|
+
expect(moved.snapshot.commentThreads?.[0]).toMatchObject({ id, range: parseWorkbookRange(sheetId, "A2:D3"),
|
|
98
|
+
cell: { row: 1, column: 0 }, messages: thread.messages });
|
|
99
|
+
} finally { await workbook.close(); }
|
|
100
|
+
|
|
101
|
+
parts[path] = strToU8(sheetXml.replace(/<extLst>[\s\S]*?<\/extLst>/u, ""));
|
|
102
|
+
const compatible = openXlsx("兼容批注", zipSync(parts));
|
|
103
|
+
expect(compatible.restrictions).toEqual([]);
|
|
104
|
+
expect(compatible.snapshot.commentThreads).toEqual([{ ...thread, cell: { ...thread.cell, sheetId } }]);
|
|
105
|
+
});
|
|
106
|
+
});
|