ooxml-core 0.8.0 → 0.10.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/README.md +21 -13
- package/dist/chart/blank-display.d.ts +37 -0
- package/dist/chart/blank-display.d.ts.map +1 -0
- package/dist/chart/box-stats.d.ts +28 -0
- package/dist/chart/box-stats.d.ts.map +1 -0
- package/dist/chart/index.cjs +229 -0
- package/dist/chart/index.d.ts +6 -0
- package/dist/chart/index.d.ts.map +1 -0
- package/dist/chart/index.mjs +220 -0
- package/dist/chart/regression.d.ts +40 -0
- package/dist/chart/regression.d.ts.map +1 -0
- package/dist/chart/stacked-series.d.ts +39 -0
- package/dist/chart/stacked-series.d.ts.map +1 -0
- package/dist/crypto/aes-ecb.d.ts +13 -0
- package/dist/crypto/aes-ecb.d.ts.map +1 -0
- package/dist/crypto/decrypt.d.ts +63 -0
- package/dist/crypto/decrypt.d.ts.map +1 -0
- package/dist/crypto/detect.d.ts +56 -0
- package/dist/crypto/detect.d.ts.map +1 -0
- package/dist/crypto/encrypt.d.ts +27 -0
- package/dist/crypto/encrypt.d.ts.map +1 -0
- package/dist/crypto/encryption-info-write.d.ts +46 -0
- package/dist/crypto/encryption-info-write.d.ts.map +1 -0
- package/dist/crypto/encryption-info.d.ts +22 -0
- package/dist/crypto/encryption-info.d.ts.map +1 -0
- package/dist/crypto/errors.d.ts +39 -0
- package/dist/crypto/errors.d.ts.map +1 -0
- package/dist/crypto/index.cjs +1805 -0
- package/dist/crypto/index.d.ts +26 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.mjs +1774 -0
- package/dist/crypto/key-derivation.d.ts +73 -0
- package/dist/crypto/key-derivation.d.ts.map +1 -0
- package/dist/crypto/types.d.ts +104 -0
- package/dist/crypto/types.d.ts.map +1 -0
- package/dist/docx/embedded.cjs +2 -0
- package/dist/docx/embedded.mjs +2 -0
- package/dist/docx/index.cjs +2 -0
- package/dist/docx/index.mjs +2 -0
- package/dist/docx/load/detect.d.ts +14 -2
- package/dist/docx/load/detect.d.ts.map +1 -1
- package/dist/docx/load/index.cjs +8995 -7728
- package/dist/docx/load/index.d.ts +3 -1
- package/dist/docx/load/index.d.ts.map +1 -1
- package/dist/docx/load/index.mjs +8990 -7729
- package/dist/docx/load/legacy-doc.d.ts.map +1 -1
- package/dist/geometry/index.cjs +192 -0
- package/dist/geometry/index.d.ts +1 -0
- package/dist/geometry/index.d.ts.map +1 -1
- package/dist/geometry/index.mjs +192 -1
- package/dist/geometry/svg-path-curves.d.ts +11 -0
- package/dist/geometry/svg-path-curves.d.ts.map +1 -0
- package/dist/geometry/svg-path-flatten.d.ts +26 -0
- package/dist/geometry/svg-path-flatten.d.ts.map +1 -0
- package/dist/geometry/svg-path-types.d.ts +6 -0
- package/dist/geometry/svg-path-types.d.ts.map +1 -0
- package/dist/index.cjs +1303 -22
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1302 -23
- package/dist/opc/index.cjs +797 -1
- package/dist/opc/index.d.ts +2 -0
- package/dist/opc/index.d.ts.map +1 -1
- package/dist/opc/index.mjs +784 -3
- package/dist/opc/properties/app.d.ts +10 -0
- package/dist/opc/properties/app.d.ts.map +1 -0
- package/dist/opc/properties/core.d.ts +13 -0
- package/dist/opc/properties/core.d.ts.map +1 -0
- package/dist/opc/properties/custom.d.ts +15 -0
- package/dist/opc/properties/custom.d.ts.map +1 -0
- package/dist/opc/properties/index.d.ts +5 -0
- package/dist/opc/properties/index.d.ts.map +1 -0
- package/dist/opc/properties/types.d.ts +114 -0
- package/dist/opc/properties/types.d.ts.map +1 -0
- package/dist/opc/relationship-types.d.ts +1 -0
- package/dist/opc/relationship-types.d.ts.map +1 -1
- package/dist/opc/safe-href.d.ts +34 -0
- package/dist/opc/safe-href.d.ts.map +1 -1
- package/dist/opc/signature/constants.d.ts +42 -0
- package/dist/opc/signature/constants.d.ts.map +1 -0
- package/dist/opc/signature/detection.d.ts +97 -0
- package/dist/opc/signature/detection.d.ts.map +1 -0
- package/dist/opc/signature/digest.d.ts +16 -0
- package/dist/opc/signature/digest.d.ts.map +1 -0
- package/dist/opc/signature/index.d.ts +8 -0
- package/dist/opc/signature/index.d.ts.map +1 -0
- package/dist/opc/signature/inspection-status.d.ts +24 -0
- package/dist/opc/signature/inspection-status.d.ts.map +1 -0
- package/dist/opc/signature/reference-utils.d.ts +12 -0
- package/dist/opc/signature/reference-utils.d.ts.map +1 -0
- package/dist/opc/signature/types.d.ts +90 -0
- package/dist/opc/signature/types.d.ts.map +1 -0
- package/dist/opc/signature/xml-utils.d.ts +35 -0
- package/dist/opc/signature/xml-utils.d.ts.map +1 -0
- package/dist/pptx/chunks/{index-CojJtI77.d.ts → index-BWUBPGgv.d.ts} +9 -11
- package/dist/pptx/chunks/index-BWUBPGgv.d.ts.map +1 -0
- package/dist/pptx/chunks/{signature-inspection-status-Bh2oap7B.d.ts → inspection-status-B2E-jSpG.d.ts} +8 -8
- package/dist/pptx/chunks/inspection-status-B2E-jSpG.d.ts.map +1 -0
- package/dist/pptx/cli/index.cjs +1409 -895
- package/dist/pptx/cli/index.mjs +1409 -895
- package/dist/pptx/converter/index.d.ts +1 -1
- package/dist/pptx/index.cjs +1933 -1391
- package/dist/pptx/index.d.ts +20 -67
- package/dist/pptx/index.d.ts.map +1 -1
- package/dist/pptx/index.mjs +1933 -1391
- package/dist/pptx/signature-node/index.cjs +5 -5
- package/dist/pptx/signature-node/index.d.ts +1 -1
- package/dist/pptx/signature-node/index.mjs +5 -5
- package/dist/text/index.cjs +122 -0
- package/dist/text/index.d.ts +3 -0
- package/dist/text/index.d.ts.map +1 -0
- package/dist/text/index.mjs +117 -0
- package/dist/text/unicode-script-detection.d.ts +54 -0
- package/dist/text/unicode-script-detection.d.ts.map +1 -0
- package/dist/visio/edit-master-index.d.ts +10 -0
- package/dist/visio/edit-master-index.d.ts.map +1 -0
- package/dist/visio/edit-master-scope.d.ts +7 -0
- package/dist/visio/edit-master-scope.d.ts.map +1 -0
- package/dist/visio/edit-scope.d.ts.map +1 -1
- package/dist/visio/formula-arithmetic.d.ts +8 -0
- package/dist/visio/formula-arithmetic.d.ts.map +1 -0
- package/dist/visio/formula-evaluate.d.ts.map +1 -1
- package/dist/visio/formula-master.d.ts +13 -0
- package/dist/visio/formula-master.d.ts.map +1 -0
- package/dist/visio/formula-numeric-functions.d.ts +8 -0
- package/dist/visio/formula-numeric-functions.d.ts.map +1 -0
- package/dist/visio/formula.d.ts +1 -1
- package/dist/visio/formula.d.ts.map +1 -1
- package/dist/visio/index.cjs +540 -61
- package/dist/visio/index.mjs +540 -61
- package/dist/xlsx/edit/annotations.d.ts +5 -1
- package/dist/xlsx/edit/annotations.d.ts.map +1 -1
- package/dist/xlsx/edit/cell-values.d.ts +7 -2
- package/dist/xlsx/edit/cell-values.d.ts.map +1 -1
- package/dist/xlsx/edit/clipboard.d.ts.map +1 -1
- package/dist/xlsx/edit/doc-properties.d.ts +14 -0
- package/dist/xlsx/edit/doc-properties.d.ts.map +1 -0
- package/dist/xlsx/edit/fill-series.d.ts.map +1 -1
- package/dist/xlsx/edit/find.d.ts +2 -1
- package/dist/xlsx/edit/find.d.ts.map +1 -1
- package/dist/xlsx/edit/format-lines.d.ts +22 -0
- package/dist/xlsx/edit/format-lines.d.ts.map +1 -0
- package/dist/xlsx/edit/format.d.ts +2 -1
- package/dist/xlsx/edit/format.d.ts.map +1 -1
- package/dist/xlsx/edit/history-refs.d.ts +51 -0
- package/dist/xlsx/edit/history-refs.d.ts.map +1 -0
- package/dist/xlsx/edit/history.d.ts +40 -5
- package/dist/xlsx/edit/history.d.ts.map +1 -1
- package/dist/xlsx/edit/index.d.ts +3 -0
- package/dist/xlsx/edit/index.d.ts.map +1 -1
- package/dist/xlsx/edit/input-text.d.ts +13 -0
- package/dist/xlsx/edit/input-text.d.ts.map +1 -0
- package/dist/xlsx/edit/merge.d.ts +10 -2
- package/dist/xlsx/edit/merge.d.ts.map +1 -1
- package/dist/xlsx/edit/session.d.ts.map +1 -1
- package/dist/xlsx/edit/sheets.d.ts.map +1 -1
- package/dist/xlsx/edit/shift-formulas.d.ts +2 -1
- package/dist/xlsx/edit/shift-formulas.d.ts.map +1 -1
- package/dist/xlsx/edit/shift-preserved.d.ts +17 -0
- package/dist/xlsx/edit/shift-preserved.d.ts.map +1 -0
- package/dist/xlsx/edit/shift-sheet.d.ts +2 -2
- package/dist/xlsx/edit/shift-sheet.d.ts.map +1 -1
- package/dist/xlsx/edit/structure.d.ts.map +1 -1
- package/dist/xlsx/edit/types.d.ts +7 -0
- package/dist/xlsx/edit/types.d.ts.map +1 -1
- package/dist/xlsx/edit/validation-list.d.ts +24 -0
- package/dist/xlsx/edit/validation-list.d.ts.map +1 -0
- package/dist/xlsx/edit/validation.d.ts +2 -1
- package/dist/xlsx/edit/validation.d.ts.map +1 -1
- package/dist/xlsx/formula/area-index.d.ts +18 -0
- package/dist/xlsx/formula/area-index.d.ts.map +1 -0
- package/dist/xlsx/formula/array-context.d.ts.map +1 -1
- package/dist/xlsx/formula/ast.d.ts +5 -1
- package/dist/xlsx/formula/ast.d.ts.map +1 -1
- package/dist/xlsx/formula/call.d.ts.map +1 -1
- package/dist/xlsx/formula/coerce.d.ts.map +1 -1
- package/dist/xlsx/formula/context.d.ts +5 -0
- package/dist/xlsx/formula/context.d.ts.map +1 -1
- package/dist/xlsx/formula/date-serial.d.ts +11 -4
- package/dist/xlsx/formula/date-serial.d.ts.map +1 -1
- package/dist/xlsx/formula/engine-core.d.ts +6 -0
- package/dist/xlsx/formula/engine-core.d.ts.map +1 -1
- package/dist/xlsx/formula/engine-host.d.ts +35 -3
- package/dist/xlsx/formula/engine-host.d.ts.map +1 -1
- package/dist/xlsx/formula/engine-util.d.ts.map +1 -1
- package/dist/xlsx/formula/engine.d.ts.map +1 -1
- package/dist/xlsx/formula/evaluator.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/array-shape.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/array.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/criteria-index.d.ts +12 -0
- package/dist/xlsx/formula/functions/criteria-index.d.ts.map +1 -0
- package/dist/xlsx/formula/functions/criteria.d.ts +24 -16
- package/dist/xlsx/formula/functions/criteria.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/date-calc.d.ts +4 -0
- package/dist/xlsx/formula/functions/date-calc.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/depreciation.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/financial.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/helpers.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/logical.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/lookup-core.d.ts +14 -2
- package/dist/xlsx/formula/functions/lookup-core.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/lookup.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/math-mod.d.ts +8 -0
- package/dist/xlsx/formula/functions/math-mod.d.ts.map +1 -0
- package/dist/xlsx/formula/functions/math-sum.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/math.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/statistical-count.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/statistical.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/stats-core.d.ts +6 -0
- package/dist/xlsx/formula/functions/stats-core.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/text-case.d.ts +14 -0
- package/dist/xlsx/formula/functions/text-case.d.ts.map +1 -0
- package/dist/xlsx/formula/functions/text.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/workdays.d.ts.map +1 -1
- package/dist/xlsx/formula/graph-index.d.ts +15 -0
- package/dist/xlsx/formula/graph-index.d.ts.map +1 -0
- package/dist/xlsx/formula/graph.d.ts +13 -18
- package/dist/xlsx/formula/graph.d.ts.map +1 -1
- package/dist/xlsx/formula/operators.d.ts +9 -0
- package/dist/xlsx/formula/operators.d.ts.map +1 -1
- package/dist/xlsx/formula/parser.d.ts +2 -0
- package/dist/xlsx/formula/parser.d.ts.map +1 -1
- package/dist/xlsx/formula/references.d.ts +4 -1
- package/dist/xlsx/formula/references.d.ts.map +1 -1
- package/dist/xlsx/formula/text-number.d.ts.map +1 -1
- package/dist/xlsx/formula/transform.d.ts.map +1 -1
- package/dist/xlsx/formula/values.d.ts +44 -3
- package/dist/xlsx/formula/values.d.ts.map +1 -1
- package/dist/xlsx/index.cjs +4698 -1322
- package/dist/xlsx/index.mjs +4688 -1323
- package/dist/xlsx/layout/anchors.d.ts +47 -0
- package/dist/xlsx/layout/anchors.d.ts.map +1 -0
- package/dist/xlsx/layout/cf-evaluator.d.ts +1 -2
- package/dist/xlsx/layout/cf-evaluator.d.ts.map +1 -1
- package/dist/xlsx/layout/cf-helpers.d.ts +8 -1
- package/dist/xlsx/layout/cf-helpers.d.ts.map +1 -1
- package/dist/xlsx/layout/index.d.ts +1 -0
- package/dist/xlsx/layout/index.d.ts.map +1 -1
- package/dist/xlsx/load/csv.d.ts +24 -3
- package/dist/xlsx/load/csv.d.ts.map +1 -1
- package/dist/xlsx/load/detect.d.ts +39 -7
- package/dist/xlsx/load/detect.d.ts.map +1 -1
- package/dist/xlsx/load/errors.d.ts +10 -0
- package/dist/xlsx/load/errors.d.ts.map +1 -0
- package/dist/xlsx/load/index.cjs +16220 -12163
- package/dist/xlsx/load/index.d.ts +5 -2
- package/dist/xlsx/load/index.d.ts.map +1 -1
- package/dist/xlsx/load/index.mjs +16213 -12164
- package/dist/xlsx/load/text-decode.d.ts +7 -0
- package/dist/xlsx/load/text-decode.d.ts.map +1 -0
- package/dist/xlsx/model.d.ts +121 -17
- package/dist/xlsx/model.d.ts.map +1 -1
- package/dist/xlsx/numfmt/date.d.ts +7 -0
- package/dist/xlsx/numfmt/date.d.ts.map +1 -1
- package/dist/xlsx/numfmt/format.d.ts.map +1 -1
- package/dist/xlsx/numfmt/fraction.d.ts +5 -1
- package/dist/xlsx/numfmt/fraction.d.ts.map +1 -1
- package/dist/xlsx/numfmt/input-date.d.ts.map +1 -1
- package/dist/xlsx/numfmt/input.d.ts.map +1 -1
- package/dist/xlsx/numfmt/number.d.ts.map +1 -1
- package/dist/xlsx/read/conditional.d.ts.map +1 -1
- package/dist/xlsx/read/drawing.d.ts +2 -2
- package/dist/xlsx/read/drawing.d.ts.map +1 -1
- package/dist/xlsx/read/load.d.ts.map +1 -1
- package/dist/xlsx/read/package.d.ts +18 -2
- package/dist/xlsx/read/package.d.ts.map +1 -1
- package/dist/xlsx/read/sheet-data.d.ts.map +1 -1
- package/dist/xlsx/read/sheet-props.d.ts +15 -1
- package/dist/xlsx/read/sheet-props.d.ts.map +1 -1
- package/dist/xlsx/read/smart-art.d.ts +12 -0
- package/dist/xlsx/read/smart-art.d.ts.map +1 -0
- package/dist/xlsx/read/styles.d.ts.map +1 -1
- package/dist/xlsx/read/workbook-part.d.ts +5 -2
- package/dist/xlsx/read/workbook-part.d.ts.map +1 -1
- package/dist/xlsx/read/worksheet.d.ts.map +1 -1
- package/dist/xlsx/write/attr-merge.d.ts +10 -0
- package/dist/xlsx/write/attr-merge.d.ts.map +1 -0
- package/dist/xlsx/write/carried-refs.d.ts +61 -0
- package/dist/xlsx/write/carried-refs.d.ts.map +1 -0
- package/dist/xlsx/write/comments.d.ts +12 -2
- package/dist/xlsx/write/comments.d.ts.map +1 -1
- package/dist/xlsx/write/conditional.d.ts.map +1 -1
- package/dist/xlsx/write/doc-props.d.ts +30 -0
- package/dist/xlsx/write/doc-props.d.ts.map +1 -0
- package/dist/xlsx/write/drawing.d.ts +5 -0
- package/dist/xlsx/write/drawing.d.ts.map +1 -1
- package/dist/xlsx/write/metadata.d.ts +23 -0
- package/dist/xlsx/write/metadata.d.ts.map +1 -0
- package/dist/xlsx/write/package-writer.d.ts +6 -0
- package/dist/xlsx/write/package-writer.d.ts.map +1 -1
- package/dist/xlsx/write/page-setup.d.ts +8 -0
- package/dist/xlsx/write/page-setup.d.ts.map +1 -0
- package/dist/xlsx/write/save.d.ts.map +1 -1
- package/dist/xlsx/write/sheet-data.d.ts +8 -0
- package/dist/xlsx/write/sheet-data.d.ts.map +1 -1
- package/dist/xlsx/write/sheet-parts.d.ts +6 -0
- package/dist/xlsx/write/sheet-parts.d.ts.map +1 -1
- package/dist/xlsx/write/sheet-props.d.ts +0 -6
- package/dist/xlsx/write/sheet-props.d.ts.map +1 -1
- package/dist/xlsx/write/styles.d.ts.map +1 -1
- package/dist/xlsx/write/table-patch.d.ts +12 -0
- package/dist/xlsx/write/table-patch.d.ts.map +1 -0
- package/dist/xlsx/write/tables.d.ts +9 -0
- package/dist/xlsx/write/tables.d.ts.map +1 -1
- package/dist/xlsx/write/vml-ids.d.ts +29 -0
- package/dist/xlsx/write/vml-ids.d.ts.map +1 -0
- package/dist/xlsx/write/workbook-part.d.ts +1 -4
- package/dist/xlsx/write/workbook-part.d.ts.map +1 -1
- package/dist/xlsx/write/worksheet.d.ts.map +1 -1
- package/dist/xml/index.cjs +4 -0
- package/dist/xml/index.mjs +4 -0
- package/dist/xml/namespaces.d.ts +4 -0
- package/dist/xml/namespaces.d.ts.map +1 -1
- package/package.json +16 -1
- package/dist/pptx/chunks/index-CojJtI77.d.ts.map +0 -1
- package/dist/pptx/chunks/signature-inspection-status-Bh2oap7B.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -188,6 +188,363 @@ function linearToSrgb255(linear) {
|
|
|
188
188
|
return 255 * (c <= 31308e-7 ? c * 12.92 : 1.055 * c ** (1 / 2.4) - 0.055);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
// src/chart/index.ts
|
|
192
|
+
var chart_exports = {};
|
|
193
|
+
__export(chart_exports, {
|
|
194
|
+
computeBoxStats: () => computeBoxStats,
|
|
195
|
+
computeLinearRegression: () => computeLinearRegression,
|
|
196
|
+
computeRSquared: () => computeRSquared,
|
|
197
|
+
computeStackedSeriesPlots: () => computeStackedSeriesPlots,
|
|
198
|
+
fitPolynomial: () => fitPolynomial,
|
|
199
|
+
groupRowsByCategory: () => groupRowsByCategory,
|
|
200
|
+
resolveBlankDisplay: () => resolveBlankDisplay,
|
|
201
|
+
visibleRuns: () => visibleRuns
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// src/chart/regression.ts
|
|
205
|
+
function computeLinearRegression(xVals, yVals) {
|
|
206
|
+
const n = xVals.length;
|
|
207
|
+
if (n < 2) {
|
|
208
|
+
return { slope: 0, intercept: 0, rSquared: 0 };
|
|
209
|
+
}
|
|
210
|
+
let sumX = 0;
|
|
211
|
+
let sumY = 0;
|
|
212
|
+
let sumXY = 0;
|
|
213
|
+
let sumXX = 0;
|
|
214
|
+
for (let i = 0; i < n; i++) {
|
|
215
|
+
sumX += xVals[i];
|
|
216
|
+
sumY += yVals[i];
|
|
217
|
+
sumXY += xVals[i] * yVals[i];
|
|
218
|
+
sumXX += xVals[i] * xVals[i];
|
|
219
|
+
}
|
|
220
|
+
const denom = n * sumXX - sumX * sumX;
|
|
221
|
+
if (Math.abs(denom) < 1e-12) {
|
|
222
|
+
return { slope: 0, intercept: sumY / n, rSquared: 0 };
|
|
223
|
+
}
|
|
224
|
+
const slope = (n * sumXY - sumX * sumY) / denom;
|
|
225
|
+
const intercept = (sumY - slope * sumX) / n;
|
|
226
|
+
const ssRes = yVals.reduce((s, y, i) => s + (y - (slope * xVals[i] + intercept)) ** 2, 0);
|
|
227
|
+
const meanY = sumY / n;
|
|
228
|
+
const ssTot = yVals.reduce((s, y) => s + (y - meanY) ** 2, 0);
|
|
229
|
+
const rSquared = ssTot > 0 ? 1 - ssRes / ssTot : 0;
|
|
230
|
+
return { slope, intercept, rSquared };
|
|
231
|
+
}
|
|
232
|
+
function fitPolynomial(xVals, yVals, order) {
|
|
233
|
+
const n = xVals.length;
|
|
234
|
+
const m = order + 1;
|
|
235
|
+
const matrix = Array.from({ length: m }, () => Array(m + 1).fill(0));
|
|
236
|
+
for (let i = 0; i < m; i++) {
|
|
237
|
+
for (let j = 0; j < m; j++) {
|
|
238
|
+
let sum2 = 0;
|
|
239
|
+
for (let k = 0; k < n; k++) {
|
|
240
|
+
sum2 += xVals[k] ** (i + j);
|
|
241
|
+
}
|
|
242
|
+
matrix[i][j] = sum2;
|
|
243
|
+
}
|
|
244
|
+
let sum = 0;
|
|
245
|
+
for (let k = 0; k < n; k++) {
|
|
246
|
+
sum += yVals[k] * xVals[k] ** i;
|
|
247
|
+
}
|
|
248
|
+
matrix[i][m] = sum;
|
|
249
|
+
}
|
|
250
|
+
for (let i = 0; i < m; i++) {
|
|
251
|
+
let maxRow = i;
|
|
252
|
+
for (let k = i + 1; k < m; k++) {
|
|
253
|
+
if (Math.abs(matrix[k][i]) > Math.abs(matrix[maxRow][i])) {
|
|
254
|
+
maxRow = k;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
[matrix[i], matrix[maxRow]] = [matrix[maxRow], matrix[i]];
|
|
258
|
+
const pivot = matrix[i][i];
|
|
259
|
+
if (Math.abs(pivot) < 1e-12) {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
for (let j = i; j <= m; j++) {
|
|
263
|
+
matrix[i][j] = matrix[i][j] / pivot;
|
|
264
|
+
}
|
|
265
|
+
for (let k = 0; k < m; k++) {
|
|
266
|
+
if (k === i) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
const factor = matrix[k][i];
|
|
270
|
+
for (let j = i; j <= m; j++) {
|
|
271
|
+
matrix[k][j] = matrix[k][j] - factor * matrix[i][j];
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return matrix.map((row) => row[m]);
|
|
276
|
+
}
|
|
277
|
+
function computeRSquared(xVals, yVals, evalFn) {
|
|
278
|
+
const n = xVals.length;
|
|
279
|
+
if (n === 0) {
|
|
280
|
+
return 0;
|
|
281
|
+
}
|
|
282
|
+
const meanY = yVals.reduce((s, y) => s + y, 0) / n;
|
|
283
|
+
let ssRes = 0;
|
|
284
|
+
let ssTot = 0;
|
|
285
|
+
for (let i = 0; i < n; i++) {
|
|
286
|
+
ssRes += (yVals[i] - evalFn(xVals[i])) ** 2;
|
|
287
|
+
ssTot += (yVals[i] - meanY) ** 2;
|
|
288
|
+
}
|
|
289
|
+
return ssTot > 0 ? 1 - ssRes / ssTot : 0;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// src/chart/box-stats.ts
|
|
293
|
+
function groupRowsByCategory(rawCategories) {
|
|
294
|
+
const uniqueCategories = [];
|
|
295
|
+
const rowIndexesByCategory = /* @__PURE__ */ new Map();
|
|
296
|
+
rawCategories.forEach((rawLabel, rowIndex) => {
|
|
297
|
+
const label = rawLabel ?? "";
|
|
298
|
+
let rows = rowIndexesByCategory.get(label);
|
|
299
|
+
if (!rows) {
|
|
300
|
+
rows = [];
|
|
301
|
+
rowIndexesByCategory.set(label, rows);
|
|
302
|
+
uniqueCategories.push(label);
|
|
303
|
+
}
|
|
304
|
+
rows.push(rowIndex);
|
|
305
|
+
});
|
|
306
|
+
return { uniqueCategories, rowIndexesByCategory };
|
|
307
|
+
}
|
|
308
|
+
function percentile(sorted, p, method) {
|
|
309
|
+
const rank = method === "inclusive" ? (sorted.length - 1) * p : (sorted.length + 1) * p - 1;
|
|
310
|
+
const clamped = Math.max(0, Math.min(rank, sorted.length - 1));
|
|
311
|
+
const lower = Math.floor(clamped);
|
|
312
|
+
const upper = Math.ceil(clamped);
|
|
313
|
+
const fraction = clamped - lower;
|
|
314
|
+
return sorted[lower] + (sorted[upper] - sorted[lower]) * fraction;
|
|
315
|
+
}
|
|
316
|
+
function computeBoxStats(values, method) {
|
|
317
|
+
if (values.length < 2) {
|
|
318
|
+
return void 0;
|
|
319
|
+
}
|
|
320
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
321
|
+
if (!method) {
|
|
322
|
+
return {
|
|
323
|
+
min: sorted[0],
|
|
324
|
+
q1: sorted[Math.floor(sorted.length * 0.25)],
|
|
325
|
+
median: sorted[Math.floor(sorted.length * 0.5)],
|
|
326
|
+
q3: sorted[Math.floor(sorted.length * 0.75)],
|
|
327
|
+
max: sorted[sorted.length - 1]
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
min: sorted[0],
|
|
332
|
+
q1: percentile(sorted, 0.25, method),
|
|
333
|
+
median: percentile(sorted, 0.5, method),
|
|
334
|
+
q3: percentile(sorted, 0.75, method),
|
|
335
|
+
max: sorted[sorted.length - 1]
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// src/chart/blank-display.ts
|
|
340
|
+
function interpolate(values, blank) {
|
|
341
|
+
const out = [...values];
|
|
342
|
+
for (let i = 0; i < out.length; i++) {
|
|
343
|
+
if (!blank[i]) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
let prev = i - 1;
|
|
347
|
+
while (prev >= 0 && blank[prev]) {
|
|
348
|
+
prev--;
|
|
349
|
+
}
|
|
350
|
+
let next = i + 1;
|
|
351
|
+
while (next < out.length && blank[next]) {
|
|
352
|
+
next++;
|
|
353
|
+
}
|
|
354
|
+
const hasPrev = prev >= 0;
|
|
355
|
+
const hasNext = next < out.length;
|
|
356
|
+
if (hasPrev && hasNext) {
|
|
357
|
+
const t = (i - prev) / (next - prev);
|
|
358
|
+
out[i] = values[prev] + (values[next] - values[prev]) * t;
|
|
359
|
+
} else if (hasPrev) {
|
|
360
|
+
out[i] = values[prev];
|
|
361
|
+
} else if (hasNext) {
|
|
362
|
+
out[i] = values[next];
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return out;
|
|
366
|
+
}
|
|
367
|
+
function resolveBlankDisplay(values, blanks, mode) {
|
|
368
|
+
const visible = values.map(() => true);
|
|
369
|
+
if (!blanks || !blanks.some(Boolean) || mode === void 0 || mode === "zero") {
|
|
370
|
+
return { values: [...values], visible };
|
|
371
|
+
}
|
|
372
|
+
if (mode === "span") {
|
|
373
|
+
return { values: interpolate(values, blanks), visible };
|
|
374
|
+
}
|
|
375
|
+
return {
|
|
376
|
+
values: [...values],
|
|
377
|
+
visible: values.map((_v, i) => !blanks[i])
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
function visibleRuns(visible) {
|
|
381
|
+
const runs = [];
|
|
382
|
+
let current = [];
|
|
383
|
+
for (let i = 0; i < visible.length; i++) {
|
|
384
|
+
if (visible[i]) {
|
|
385
|
+
current.push(i);
|
|
386
|
+
} else if (current.length > 0) {
|
|
387
|
+
runs.push(current);
|
|
388
|
+
current = [];
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (current.length > 0) {
|
|
392
|
+
runs.push(current);
|
|
393
|
+
}
|
|
394
|
+
return runs;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/chart/stacked-series.ts
|
|
398
|
+
function categoryAbsTotals(seriesValues, catCount) {
|
|
399
|
+
return Array.from(
|
|
400
|
+
{ length: catCount },
|
|
401
|
+
(_, ci) => seriesValues.reduce((sum, values) => sum + Math.abs(values[ci] ?? 0), 0)
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
function computeStackedSeriesPlots(seriesValues, catCount, percent) {
|
|
405
|
+
const totals = percent ? categoryAbsTotals(seriesValues, catCount) : void 0, posRunning = new Array(catCount).fill(0), negRunning = new Array(catCount).fill(0);
|
|
406
|
+
return seriesValues.map((values) => {
|
|
407
|
+
const cumulative = [], base = [], own = [];
|
|
408
|
+
for (let ci = 0; ci < catCount; ci++) {
|
|
409
|
+
const raw = values[ci] ?? 0, total = totals?.[ci] ?? 0, val2 = percent ? total > 0 ? raw / total * 100 : 0 : raw, isNeg = val2 < 0, from = isNeg ? negRunning[ci] : posRunning[ci], to = from + val2;
|
|
410
|
+
base.push(from);
|
|
411
|
+
cumulative.push(to);
|
|
412
|
+
own.push(val2);
|
|
413
|
+
if (isNeg) {
|
|
414
|
+
negRunning[ci] = to;
|
|
415
|
+
} else {
|
|
416
|
+
posRunning[ci] = to;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return { cumulative, base, own };
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// src/text/index.ts
|
|
424
|
+
var text_exports = {};
|
|
425
|
+
__export(text_exports, {
|
|
426
|
+
detectFontScript: () => detectFontScript,
|
|
427
|
+
hasDistinctScriptFonts: () => hasDistinctScriptFonts,
|
|
428
|
+
resolveFontForScript: () => resolveFontForScript,
|
|
429
|
+
segmentByScript: () => segmentByScript
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
// src/text/unicode-script-detection.ts
|
|
433
|
+
function detectFontScript(codePoint) {
|
|
434
|
+
if (codePoint >= 11904 && codePoint <= 40959 || // CJK radicals, unified ideographs
|
|
435
|
+
codePoint >= 44032 && codePoint <= 55215 || // Hangul syllables
|
|
436
|
+
codePoint >= 63744 && codePoint <= 64255 || // CJK compatibility ideographs
|
|
437
|
+
codePoint >= 65072 && codePoint <= 65103 || // CJK compatibility forms
|
|
438
|
+
codePoint >= 131072 && codePoint <= 195103 || // CJK extension B-F
|
|
439
|
+
codePoint >= 12288 && codePoint <= 12351 || // CJK symbols & punctuation
|
|
440
|
+
codePoint >= 12352 && codePoint <= 12447 || // Hiragana
|
|
441
|
+
codePoint >= 12448 && codePoint <= 12543 || // Katakana
|
|
442
|
+
codePoint >= 12784 && codePoint <= 12799 || // Katakana extensions
|
|
443
|
+
codePoint >= 65280 && codePoint <= 65519) {
|
|
444
|
+
return "eastAsia";
|
|
445
|
+
}
|
|
446
|
+
if (codePoint >= 1424 && codePoint <= 1535 || // Hebrew
|
|
447
|
+
codePoint >= 1536 && codePoint <= 1791 || // Arabic
|
|
448
|
+
codePoint >= 1792 && codePoint <= 1871 || // Syriac
|
|
449
|
+
codePoint >= 1872 && codePoint <= 1919 || // Arabic Supplement
|
|
450
|
+
codePoint >= 1920 && codePoint <= 1983 || // Thaana
|
|
451
|
+
codePoint >= 1984 && codePoint <= 2047 || // NKo
|
|
452
|
+
codePoint >= 2048 && codePoint <= 2111 || // Samaritan
|
|
453
|
+
codePoint >= 2304 && codePoint <= 2431 || // Devanagari
|
|
454
|
+
codePoint >= 2432 && codePoint <= 2559 || // Bengali
|
|
455
|
+
codePoint >= 2560 && codePoint <= 2687 || // Gurmukhi
|
|
456
|
+
codePoint >= 2688 && codePoint <= 2815 || // Gujarati
|
|
457
|
+
codePoint >= 2816 && codePoint <= 2943 || // Oriya
|
|
458
|
+
codePoint >= 2944 && codePoint <= 3071 || // Tamil
|
|
459
|
+
codePoint >= 3072 && codePoint <= 3199 || // Telugu
|
|
460
|
+
codePoint >= 3200 && codePoint <= 3327 || // Kannada
|
|
461
|
+
codePoint >= 3328 && codePoint <= 3455 || // Malayalam
|
|
462
|
+
codePoint >= 3456 && codePoint <= 3583 || // Sinhala
|
|
463
|
+
codePoint >= 3584 && codePoint <= 3711 || // Thai
|
|
464
|
+
codePoint >= 3712 && codePoint <= 3839 || // Lao
|
|
465
|
+
codePoint >= 3840 && codePoint <= 4095 || // Tibetan
|
|
466
|
+
codePoint >= 4096 && codePoint <= 4255 || // Myanmar
|
|
467
|
+
codePoint >= 4256 && codePoint <= 4351 || // Georgian
|
|
468
|
+
codePoint >= 6016 && codePoint <= 6143 || // Khmer
|
|
469
|
+
codePoint >= 64336 && codePoint <= 65023 || // Arabic Presentation Forms-A
|
|
470
|
+
codePoint >= 65136 && codePoint <= 65279) {
|
|
471
|
+
return "complexScript";
|
|
472
|
+
}
|
|
473
|
+
if (codePoint >= 8592 && codePoint <= 8703 || // Arrows
|
|
474
|
+
codePoint >= 8704 && codePoint <= 8959 || // Mathematical operators
|
|
475
|
+
codePoint >= 8960 && codePoint <= 9215 || // Misc technical
|
|
476
|
+
codePoint >= 9472 && codePoint <= 9599 || // Box drawing
|
|
477
|
+
codePoint >= 9600 && codePoint <= 9631 || // Block elements
|
|
478
|
+
codePoint >= 9632 && codePoint <= 9727 || // Geometric shapes
|
|
479
|
+
codePoint >= 9728 && codePoint <= 9983 || // Misc symbols
|
|
480
|
+
codePoint >= 9984 && codePoint <= 10175 || // Dingbats
|
|
481
|
+
codePoint >= 57344 && codePoint <= 63743 || // Private Use Area
|
|
482
|
+
codePoint >= 126976 && codePoint <= 129535) {
|
|
483
|
+
return "symbol";
|
|
484
|
+
}
|
|
485
|
+
return "latin";
|
|
486
|
+
}
|
|
487
|
+
function segmentByScript(text) {
|
|
488
|
+
if (!text) {
|
|
489
|
+
return [];
|
|
490
|
+
}
|
|
491
|
+
const runs = [];
|
|
492
|
+
let currentScript = null;
|
|
493
|
+
let currentStart = 0;
|
|
494
|
+
let currentText = "";
|
|
495
|
+
for (let i = 0; i < text.length; i++) {
|
|
496
|
+
const codePoint = text.codePointAt(i);
|
|
497
|
+
if (codePoint === void 0) {
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
const charLength = codePoint > 65535 ? 2 : 1;
|
|
501
|
+
const char = text.substring(i, i + charLength);
|
|
502
|
+
const isNeutral = codePoint <= 127 && !/[a-zA-Z0-9]/u.test(char);
|
|
503
|
+
const script = isNeutral ? currentScript ?? "latin" : detectFontScript(codePoint);
|
|
504
|
+
if (script !== currentScript && currentScript !== null) {
|
|
505
|
+
runs.push({
|
|
506
|
+
text: currentText,
|
|
507
|
+
script: currentScript,
|
|
508
|
+
startIndex: currentStart
|
|
509
|
+
});
|
|
510
|
+
currentStart = i;
|
|
511
|
+
currentText = "";
|
|
512
|
+
}
|
|
513
|
+
currentScript = script;
|
|
514
|
+
currentText += char;
|
|
515
|
+
if (charLength === 2) {
|
|
516
|
+
i++;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
if (currentText && currentScript) {
|
|
520
|
+
runs.push({
|
|
521
|
+
text: currentText,
|
|
522
|
+
script: currentScript,
|
|
523
|
+
startIndex: currentStart
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
return runs;
|
|
527
|
+
}
|
|
528
|
+
function resolveFontForScript(script, fonts) {
|
|
529
|
+
switch (script) {
|
|
530
|
+
case "latin":
|
|
531
|
+
return fonts.latin;
|
|
532
|
+
case "eastAsia":
|
|
533
|
+
return fonts.eastAsia || fonts.latin;
|
|
534
|
+
case "complexScript":
|
|
535
|
+
return fonts.complexScript || fonts.latin;
|
|
536
|
+
case "symbol":
|
|
537
|
+
return fonts.symbol || fonts.latin;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
function hasDistinctScriptFonts(fonts) {
|
|
541
|
+
const base = fonts.latin;
|
|
542
|
+
if (!base) {
|
|
543
|
+
return false;
|
|
544
|
+
}
|
|
545
|
+
return Boolean(fonts.eastAsia) && fonts.eastAsia !== base || Boolean(fonts.complexScript) && fonts.complexScript !== base || Boolean(fonts.symbol) && fonts.symbol !== base;
|
|
546
|
+
}
|
|
547
|
+
|
|
191
548
|
// src/diagram/index.ts
|
|
192
549
|
var diagram_exports = {};
|
|
193
550
|
__export(diagram_exports, {
|
|
@@ -343,7 +700,12 @@ function resolveDiagramLayoutCategory(uniqueId, categories) {
|
|
|
343
700
|
// src/opc/index.ts
|
|
344
701
|
var opc_exports = {};
|
|
345
702
|
__export(opc_exports, {
|
|
703
|
+
CORE_PROPERTY_FIELDS: () => CORE_PROPERTY_FIELDS,
|
|
704
|
+
CUSTOM_PROPERTIES_FMTID: () => CUSTOM_PROPERTIES_FMTID,
|
|
705
|
+
PROPERTY_CONTENT_TYPES: () => PROPERTY_CONTENT_TYPES,
|
|
706
|
+
PROPERTY_PART_NAMES: () => PROPERTY_PART_NAMES,
|
|
346
707
|
RELATIONSHIP_TYPES: () => RELATIONSHIP_TYPES,
|
|
708
|
+
allocateCustomPropertyIds: () => allocateCustomPropertyIds,
|
|
347
709
|
buildContentTypesXml: () => buildContentTypesXml,
|
|
348
710
|
buildRelationshipsXml: () => buildRelationshipsXml,
|
|
349
711
|
contentTypeForPart: () => contentTypeForPart,
|
|
@@ -352,12 +714,22 @@ __export(opc_exports, {
|
|
|
352
714
|
ensureRelationship: () => ensureRelationship,
|
|
353
715
|
findOfficeDocumentPart: () => findOfficeDocumentPart,
|
|
354
716
|
getRelationshipId: () => getRelationshipId,
|
|
717
|
+
hyperlinkPolicy: () => hyperlinkPolicy,
|
|
718
|
+
isOpenableHyperlinkHref: () => isOpenableHyperlinkHref,
|
|
355
719
|
isSafeHyperlinkHref: () => isSafeHyperlinkHref,
|
|
720
|
+
isStorableHyperlinkHref: () => isStorableHyperlinkHref,
|
|
356
721
|
nextRelationshipId: () => nextRelationshipId,
|
|
722
|
+
parseAppProperties: () => parseAppProperties,
|
|
357
723
|
parseContentTypes: () => parseContentTypes,
|
|
724
|
+
parseCoreProperties: () => parseCoreProperties,
|
|
725
|
+
parseCustomProperties: () => parseCustomProperties,
|
|
358
726
|
parseRelationships: () => parseRelationships,
|
|
359
727
|
relationshipsPartFor: () => relationshipsPartFor,
|
|
360
|
-
resolvePartPath: () => resolvePartPath
|
|
728
|
+
resolvePartPath: () => resolvePartPath,
|
|
729
|
+
signature: () => signature_exports,
|
|
730
|
+
writeAppProperties: () => writeAppProperties,
|
|
731
|
+
writeCoreProperties: () => writeCoreProperties,
|
|
732
|
+
writeCustomProperties: () => writeCustomProperties
|
|
361
733
|
});
|
|
362
734
|
|
|
363
735
|
// src/opc/relationship-types.ts
|
|
@@ -391,6 +763,7 @@ var RELATIONSHIP_TYPES = {
|
|
|
391
763
|
diagramDrawing: "http://schemas.microsoft.com/office/2007/relationships/diagramDrawing",
|
|
392
764
|
coreProperties: "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties",
|
|
393
765
|
extendedProperties: `${BASE}/extended-properties`,
|
|
766
|
+
customProperties: `${BASE}/custom-properties`,
|
|
394
767
|
customXml: `${BASE}/customXml`,
|
|
395
768
|
worksheet: `${BASE}/worksheet`,
|
|
396
769
|
chartsheet: `${BASE}/chartsheet`,
|
|
@@ -486,6 +859,10 @@ var NS = {
|
|
|
486
859
|
extendedProperties: "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties",
|
|
487
860
|
/** Dublin Core terms (`dcterms:created`). */
|
|
488
861
|
dcterms: "http://purl.org/dc/terms/",
|
|
862
|
+
/** Custom document properties (`docProps/custom.xml`). */
|
|
863
|
+
customProperties: "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties",
|
|
864
|
+
/** Document property variant types (`vt:lpwstr`, `vt:vector`). */
|
|
865
|
+
vt: "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes",
|
|
489
866
|
/** XML itself (`xml:space`). */
|
|
490
867
|
xml: "http://www.w3.org/XML/1998/namespace"
|
|
491
868
|
};
|
|
@@ -664,6 +1041,716 @@ function isSafeHyperlinkHref(href) {
|
|
|
664
1041
|
const scheme = /^([a-z][a-z0-9+.-]*:)/i.exec(href.trim())?.[1];
|
|
665
1042
|
return scheme !== void 0 && SAFE_SCHEMES.has(scheme.toLowerCase());
|
|
666
1043
|
}
|
|
1044
|
+
var OPEN_SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto"]);
|
|
1045
|
+
var STORE_SCHEMES = /* @__PURE__ */ new Set([...OPEN_SCHEMES, "ftp", "file"]);
|
|
1046
|
+
var SCRIPT_SCHEMES = /* @__PURE__ */ new Set([
|
|
1047
|
+
"javascript",
|
|
1048
|
+
"vbscript",
|
|
1049
|
+
"livescript",
|
|
1050
|
+
"jscript",
|
|
1051
|
+
"mocha",
|
|
1052
|
+
"data",
|
|
1053
|
+
"mhtml",
|
|
1054
|
+
"ms-its",
|
|
1055
|
+
"mk",
|
|
1056
|
+
"x-javascript",
|
|
1057
|
+
"blob"
|
|
1058
|
+
]);
|
|
1059
|
+
var IGNORABLE = new RegExp(
|
|
1060
|
+
"[\\u0000-\\u0020\\u007f\\u00ad\\u200b-\\u200f\\u202a-\\u202e\\u2060-\\u2064\\ufeff]",
|
|
1061
|
+
"gu"
|
|
1062
|
+
);
|
|
1063
|
+
var CONTROL = new RegExp("[\\u0000-\\u001f\\u007f]", "u");
|
|
1064
|
+
var SCHEME = /^([a-z][a-z0-9+.-]*):/;
|
|
1065
|
+
var STORE_ONLY = { store: true, open: false, reason: "not-openable" };
|
|
1066
|
+
var reject = (reason) => ({
|
|
1067
|
+
store: false,
|
|
1068
|
+
open: false,
|
|
1069
|
+
reason
|
|
1070
|
+
});
|
|
1071
|
+
function hyperlinkPolicy(href) {
|
|
1072
|
+
if (typeof href !== "string") return reject("empty");
|
|
1073
|
+
const trimmed = href.trim();
|
|
1074
|
+
const normalized = trimmed.replace(IGNORABLE, "").toLowerCase();
|
|
1075
|
+
if (normalized.length === 0) return reject("empty");
|
|
1076
|
+
const scheme = SCHEME.exec(normalized)?.[1];
|
|
1077
|
+
if (scheme !== void 0 && SCRIPT_SCHEMES.has(scheme)) return reject("script-scheme");
|
|
1078
|
+
if (scheme !== void 0 && !trimmed.toLowerCase().startsWith(`${scheme}:`))
|
|
1079
|
+
return reject("obfuscated-scheme");
|
|
1080
|
+
if (CONTROL.test(trimmed)) return reject("control-characters");
|
|
1081
|
+
if (scheme === void 0 || scheme.length === 1) return STORE_ONLY;
|
|
1082
|
+
if (OPEN_SCHEMES.has(scheme)) return { store: true, open: true };
|
|
1083
|
+
if (STORE_SCHEMES.has(scheme)) return STORE_ONLY;
|
|
1084
|
+
return reject("unsupported-scheme");
|
|
1085
|
+
}
|
|
1086
|
+
function isStorableHyperlinkHref(href) {
|
|
1087
|
+
return hyperlinkPolicy(href).store;
|
|
1088
|
+
}
|
|
1089
|
+
function isOpenableHyperlinkHref(href) {
|
|
1090
|
+
return hyperlinkPolicy(href).open;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// src/opc/properties/types.ts
|
|
1094
|
+
var CUSTOM_PROPERTIES_FMTID = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}";
|
|
1095
|
+
var PROPERTY_PART_NAMES = {
|
|
1096
|
+
core: "docProps/core.xml",
|
|
1097
|
+
app: "docProps/app.xml",
|
|
1098
|
+
custom: "docProps/custom.xml"
|
|
1099
|
+
};
|
|
1100
|
+
var PROPERTY_CONTENT_TYPES = {
|
|
1101
|
+
core: "application/vnd.openxmlformats-package.core-properties+xml",
|
|
1102
|
+
app: "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
|
1103
|
+
custom: "application/vnd.openxmlformats-officedocument.custom-properties+xml"
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
// src/opc/properties/core.ts
|
|
1107
|
+
var XSI = "http://www.w3.org/2001/XMLSchema-instance";
|
|
1108
|
+
var FIELDS = [
|
|
1109
|
+
["title", "dc", false],
|
|
1110
|
+
["subject", "dc", false],
|
|
1111
|
+
["creator", "dc", false],
|
|
1112
|
+
["keywords", "cp", false],
|
|
1113
|
+
["description", "dc", false],
|
|
1114
|
+
["lastModifiedBy", "cp", false],
|
|
1115
|
+
["created", "dcterms", true],
|
|
1116
|
+
["modified", "dcterms", true],
|
|
1117
|
+
["category", "cp", false],
|
|
1118
|
+
["contentStatus", "cp", false],
|
|
1119
|
+
["revision", "cp", false],
|
|
1120
|
+
["language", "dc", false],
|
|
1121
|
+
["identifier", "dc", false],
|
|
1122
|
+
["lastPrinted", "cp", false],
|
|
1123
|
+
["version", "cp", false]
|
|
1124
|
+
];
|
|
1125
|
+
var CORE_PROPERTY_FIELDS = FIELDS.map(([field]) => field);
|
|
1126
|
+
var EMPTY_CORE = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
1127
|
+
<cp:coreProperties xmlns:cp="${NS.cp}" xmlns:dc="${NS.dc}" xmlns:dcterms="${NS.dcterms}" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="${XSI}"/>`;
|
|
1128
|
+
function parseCoreProperties(xml) {
|
|
1129
|
+
const out = {};
|
|
1130
|
+
if (!xml) return out;
|
|
1131
|
+
const root = parseXml(xml, { label: "core properties" }).documentElement;
|
|
1132
|
+
for (const [field, prefix] of FIELDS) {
|
|
1133
|
+
const text = first(root, field, NS[prefix])?.textContent ?? "";
|
|
1134
|
+
if (text !== "") out[field] = text;
|
|
1135
|
+
}
|
|
1136
|
+
return out;
|
|
1137
|
+
}
|
|
1138
|
+
function writeCoreProperties(props, sourceXml) {
|
|
1139
|
+
const doc = parseXml(sourceXml ?? EMPTY_CORE, { label: "core properties" });
|
|
1140
|
+
const root = doc.documentElement;
|
|
1141
|
+
for (const [field, prefix, isDate] of FIELDS) {
|
|
1142
|
+
const ns = NS[prefix];
|
|
1143
|
+
const value = props[field];
|
|
1144
|
+
let element = first(root, field, ns);
|
|
1145
|
+
if (value === void 0 || value === "") {
|
|
1146
|
+
if (element && (element.textContent ?? "") !== "") root.removeChild(element);
|
|
1147
|
+
continue;
|
|
1148
|
+
}
|
|
1149
|
+
if (!element) {
|
|
1150
|
+
element = doc.createElementNS(ns, `${prefix}:${field}`);
|
|
1151
|
+
if (isDate) element.setAttributeNS(XSI, "xsi:type", "dcterms:W3CDTF");
|
|
1152
|
+
root.appendChild(element);
|
|
1153
|
+
}
|
|
1154
|
+
if (element.textContent !== value) element.textContent = value;
|
|
1155
|
+
}
|
|
1156
|
+
const out = buildXml(doc);
|
|
1157
|
+
return out.startsWith("<?xml") ? out : `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
1158
|
+
${out}`;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
// src/opc/properties/app.ts
|
|
1162
|
+
var FIELDS2 = [
|
|
1163
|
+
["template", "Template", "text"],
|
|
1164
|
+
["totalTime", "TotalTime", "int"],
|
|
1165
|
+
["application", "Application", "text"],
|
|
1166
|
+
["docSecurity", "DocSecurity", "int"],
|
|
1167
|
+
["scaleCrop", "ScaleCrop", "bool"],
|
|
1168
|
+
["headingPairs", "HeadingPairs", "pairs"],
|
|
1169
|
+
["titlesOfParts", "TitlesOfParts", "titles"],
|
|
1170
|
+
["manager", "Manager", "text"],
|
|
1171
|
+
["company", "Company", "text"],
|
|
1172
|
+
["linksUpToDate", "LinksUpToDate", "bool"],
|
|
1173
|
+
["sharedDoc", "SharedDoc", "bool"],
|
|
1174
|
+
["hyperlinkBase", "HyperlinkBase", "text"],
|
|
1175
|
+
["hyperlinksChanged", "HyperlinksChanged", "bool"],
|
|
1176
|
+
["appVersion", "AppVersion", "text"]
|
|
1177
|
+
];
|
|
1178
|
+
var EMPTY_APP = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
1179
|
+
<Properties xmlns="${NS.extendedProperties}" xmlns:vt="${NS.vt}"/>`;
|
|
1180
|
+
function vectorItems(element) {
|
|
1181
|
+
const vector = first(element, "vector", NS.vt);
|
|
1182
|
+
return vector ? elements(vector) : [];
|
|
1183
|
+
}
|
|
1184
|
+
function readPairs(element) {
|
|
1185
|
+
const variants = vectorItems(element).map((variant) => elements(variant)[0]);
|
|
1186
|
+
const out = [];
|
|
1187
|
+
for (let i = 0; i + 1 < variants.length; i += 2) {
|
|
1188
|
+
const name = variants[i]?.textContent ?? "";
|
|
1189
|
+
const count = Number.parseInt(variants[i + 1]?.textContent ?? "", 10);
|
|
1190
|
+
out.push({ name, count: Number.isFinite(count) ? count : 0 });
|
|
1191
|
+
}
|
|
1192
|
+
return out;
|
|
1193
|
+
}
|
|
1194
|
+
function readField(element, kind) {
|
|
1195
|
+
const text = element.textContent ?? "";
|
|
1196
|
+
if (kind === "pairs") return readPairs(element);
|
|
1197
|
+
if (kind === "titles") return vectorItems(element).map((item) => item.textContent ?? "");
|
|
1198
|
+
if (kind === "bool") return text.trim() === "true" || text.trim() === "1";
|
|
1199
|
+
if (kind === "int") {
|
|
1200
|
+
const value = Number.parseInt(text, 10);
|
|
1201
|
+
return Number.isFinite(value) ? value : void 0;
|
|
1202
|
+
}
|
|
1203
|
+
return text === "" ? void 0 : text;
|
|
1204
|
+
}
|
|
1205
|
+
function parseAppProperties(xml) {
|
|
1206
|
+
const out = {};
|
|
1207
|
+
if (!xml) return out;
|
|
1208
|
+
const root = parseXml(xml, { label: "app properties" }).documentElement;
|
|
1209
|
+
for (const [field, local, kind] of FIELDS2) {
|
|
1210
|
+
const element = first(root, local, NS.extendedProperties);
|
|
1211
|
+
if (!element) continue;
|
|
1212
|
+
const value = readField(element, kind);
|
|
1213
|
+
if (value !== void 0) out[field] = value;
|
|
1214
|
+
}
|
|
1215
|
+
return out;
|
|
1216
|
+
}
|
|
1217
|
+
var same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
1218
|
+
function fill(doc, element, kind, value) {
|
|
1219
|
+
while (element.firstChild) element.removeChild(element.firstChild);
|
|
1220
|
+
const vt = (local, text) => {
|
|
1221
|
+
const node = doc.createElementNS(NS.vt, `vt:${local}`);
|
|
1222
|
+
if (text !== void 0) node.textContent = text;
|
|
1223
|
+
return node;
|
|
1224
|
+
};
|
|
1225
|
+
if (kind === "pairs" || kind === "titles") {
|
|
1226
|
+
const items = kind === "pairs" ? value.flatMap((pair) => [
|
|
1227
|
+
vt("lpstr", pair.name),
|
|
1228
|
+
vt("i4", String(Math.trunc(pair.count)))
|
|
1229
|
+
]) : value.map((title) => vt("lpstr", title));
|
|
1230
|
+
const vector = vt("vector");
|
|
1231
|
+
vector.setAttribute("size", String(items.length));
|
|
1232
|
+
vector.setAttribute("baseType", kind === "pairs" ? "variant" : "lpstr");
|
|
1233
|
+
for (const item of items) {
|
|
1234
|
+
if (kind === "pairs") {
|
|
1235
|
+
const variant = vt("variant");
|
|
1236
|
+
variant.appendChild(item);
|
|
1237
|
+
vector.appendChild(variant);
|
|
1238
|
+
} else vector.appendChild(item);
|
|
1239
|
+
}
|
|
1240
|
+
element.appendChild(vector);
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
element.textContent = kind === "bool" ? value ? "true" : "false" : String(value);
|
|
1244
|
+
}
|
|
1245
|
+
function writeAppProperties(props, sourceXml) {
|
|
1246
|
+
const doc = parseXml(sourceXml ?? EMPTY_APP, { label: "app properties" });
|
|
1247
|
+
const root = doc.documentElement;
|
|
1248
|
+
const prior = parseAppProperties(sourceXml);
|
|
1249
|
+
FIELDS2.forEach(([field, local, kind], index) => {
|
|
1250
|
+
const value = props[field];
|
|
1251
|
+
const existing = first(root, local, NS.extendedProperties);
|
|
1252
|
+
if (value === void 0 || kind === "text" && value === "") {
|
|
1253
|
+
if (existing && (existing.textContent ?? "") !== "") root.removeChild(existing);
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1256
|
+
if (existing && same(prior[field], value)) return;
|
|
1257
|
+
let element = existing;
|
|
1258
|
+
if (!element) {
|
|
1259
|
+
element = doc.createElementNS(NS.extendedProperties, local);
|
|
1260
|
+
const next = FIELDS2.slice(index + 1).map(([, name]) => first(root, name, NS.extendedProperties)).find((node) => node !== void 0);
|
|
1261
|
+
root.insertBefore(element, next ?? null);
|
|
1262
|
+
}
|
|
1263
|
+
fill(doc, element, kind, value);
|
|
1264
|
+
});
|
|
1265
|
+
const out = buildXml(doc);
|
|
1266
|
+
return out.startsWith("<?xml") ? out : `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
1267
|
+
${out}`;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
// src/opc/properties/custom.ts
|
|
1271
|
+
var escape = (text, attribute = false) => {
|
|
1272
|
+
const out = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
1273
|
+
return attribute ? out.replace(/"/g, """) : out;
|
|
1274
|
+
};
|
|
1275
|
+
var isVt = (element) => element.namespaceURI === NS.vt || element.prefix === "vt";
|
|
1276
|
+
function readValue(variant) {
|
|
1277
|
+
const text = variant.textContent ?? "";
|
|
1278
|
+
switch (isVt(variant) ? variant.localName : "") {
|
|
1279
|
+
case "lpwstr":
|
|
1280
|
+
return { name: "", type: "lpwstr", value: text };
|
|
1281
|
+
case "i4":
|
|
1282
|
+
case "int": {
|
|
1283
|
+
const value = Number.parseInt(text, 10);
|
|
1284
|
+
return Number.isFinite(value) ? { name: "", type: "i4", value } : void 0;
|
|
1285
|
+
}
|
|
1286
|
+
case "r8": {
|
|
1287
|
+
const value = Number(text);
|
|
1288
|
+
return text.trim() !== "" && Number.isFinite(value) ? { name: "", type: "r8", value } : void 0;
|
|
1289
|
+
}
|
|
1290
|
+
case "bool":
|
|
1291
|
+
return { name: "", type: "bool", value: text.trim() === "true" || text.trim() === "1" };
|
|
1292
|
+
case "filetime":
|
|
1293
|
+
return { name: "", type: "filetime", value: text };
|
|
1294
|
+
default:
|
|
1295
|
+
return void 0;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
function parseCustomProperties(xml) {
|
|
1299
|
+
if (!xml) return [];
|
|
1300
|
+
const root = parseXml(xml, { label: "custom properties" }).documentElement;
|
|
1301
|
+
const out = [];
|
|
1302
|
+
for (const property of children(root, "property", NS.customProperties)) {
|
|
1303
|
+
const name = property.getAttribute("name") ?? "";
|
|
1304
|
+
const variant = elements(property)[0];
|
|
1305
|
+
if (!name || !variant) continue;
|
|
1306
|
+
const value = readValue(variant) ?? {
|
|
1307
|
+
name,
|
|
1308
|
+
type: "raw",
|
|
1309
|
+
xml: buildXml(variant)
|
|
1310
|
+
};
|
|
1311
|
+
const pid = Number.parseInt(property.getAttribute("pid") ?? "", 10);
|
|
1312
|
+
const linkTarget = property.getAttribute("linkTarget");
|
|
1313
|
+
out.push({
|
|
1314
|
+
...value,
|
|
1315
|
+
name,
|
|
1316
|
+
...Number.isFinite(pid) ? { pid } : {},
|
|
1317
|
+
...linkTarget ? { linkTarget } : {}
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
return out;
|
|
1321
|
+
}
|
|
1322
|
+
function allocateCustomPropertyIds(properties) {
|
|
1323
|
+
const used = /* @__PURE__ */ new Set();
|
|
1324
|
+
const kept = properties.map((property) => {
|
|
1325
|
+
const pid = property.pid;
|
|
1326
|
+
if (pid === void 0 || !Number.isInteger(pid) || pid < 2 || used.has(pid)) return void 0;
|
|
1327
|
+
used.add(pid);
|
|
1328
|
+
return pid;
|
|
1329
|
+
});
|
|
1330
|
+
let next = Math.max(1, ...used) + 1;
|
|
1331
|
+
return kept.map((pid) => pid ?? next++);
|
|
1332
|
+
}
|
|
1333
|
+
function variantXml(property) {
|
|
1334
|
+
switch (property.type) {
|
|
1335
|
+
case "raw":
|
|
1336
|
+
return property.xml;
|
|
1337
|
+
case "lpwstr":
|
|
1338
|
+
return `<vt:lpwstr>${escape(property.value)}</vt:lpwstr>`;
|
|
1339
|
+
case "i4":
|
|
1340
|
+
return `<vt:i4>${Math.trunc(property.value)}</vt:i4>`;
|
|
1341
|
+
case "r8":
|
|
1342
|
+
return `<vt:r8>${String(property.value)}</vt:r8>`;
|
|
1343
|
+
case "bool":
|
|
1344
|
+
return `<vt:bool>${property.value ? "true" : "false"}</vt:bool>`;
|
|
1345
|
+
case "filetime":
|
|
1346
|
+
return `<vt:filetime>${escape(property.value)}</vt:filetime>`;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
function writeCustomProperties(properties) {
|
|
1350
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1351
|
+
const unique = properties.filter((property) => {
|
|
1352
|
+
const key = property.name.toLowerCase();
|
|
1353
|
+
if (!property.name || seen.has(key)) return false;
|
|
1354
|
+
seen.add(key);
|
|
1355
|
+
return true;
|
|
1356
|
+
});
|
|
1357
|
+
if (!unique.length) return void 0;
|
|
1358
|
+
const pids = allocateCustomPropertyIds(unique);
|
|
1359
|
+
const body = unique.map((property, index) => {
|
|
1360
|
+
const link = property.linkTarget ? ` linkTarget="${escape(property.linkTarget, true)}"` : "";
|
|
1361
|
+
return `<property fmtid="${CUSTOM_PROPERTIES_FMTID}" pid="${pids[index] ?? index + 2}" name="${escape(property.name, true)}"${link}>${variantXml(property)}</property>`;
|
|
1362
|
+
}).join("");
|
|
1363
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
1364
|
+
<Properties xmlns="${NS.customProperties}" xmlns:vt="${NS.vt}">${body}</Properties>`;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
// src/opc/signature/index.ts
|
|
1368
|
+
var signature_exports = {};
|
|
1369
|
+
__export(signature_exports, {
|
|
1370
|
+
DIGEST_ALGORITHM_TO_HASH: () => DIGEST_ALGORITHM_TO_HASH,
|
|
1371
|
+
DIGEST_ALGORITHM_TO_WEB_CRYPTO: () => DIGEST_ALGORITHM_TO_WEB_CRYPTO,
|
|
1372
|
+
DIGITAL_SIGNATURE_ORIGIN_REL_TYPE: () => DIGITAL_SIGNATURE_ORIGIN_REL_TYPE,
|
|
1373
|
+
DIGITAL_SIGNATURE_REL_TYPE: () => DIGITAL_SIGNATURE_REL_TYPE,
|
|
1374
|
+
ENTERPRISE_FAIL_ON_REVOCATION_UNKNOWN_ENV: () => ENTERPRISE_FAIL_ON_REVOCATION_UNKNOWN_ENV,
|
|
1375
|
+
ENTERPRISE_REQUIRE_REVOCATION_ENV: () => ENTERPRISE_REQUIRE_REVOCATION_ENV,
|
|
1376
|
+
ENTERPRISE_REQUIRE_TIMESTAMP_ENV: () => ENTERPRISE_REQUIRE_TIMESTAMP_ENV,
|
|
1377
|
+
ENTERPRISE_TRUST_ROOTS_FILE_ENV: () => ENTERPRISE_TRUST_ROOTS_FILE_ENV,
|
|
1378
|
+
ENTERPRISE_TRUST_ROOTS_PEM_ENV: () => ENTERPRISE_TRUST_ROOTS_PEM_ENV,
|
|
1379
|
+
OPC_RELATIONSHIP_TRANSFORM: () => OPC_RELATIONSHIP_TRANSFORM,
|
|
1380
|
+
PPTX_VIEWER_MANIFEST_NS: () => PPTX_VIEWER_MANIFEST_NS,
|
|
1381
|
+
SIGNATURE_PART_PREFIX: () => SIGNATURE_PART_PREFIX,
|
|
1382
|
+
SUPPORTED_XML_CANON_TRANSFORMS: () => SUPPORTED_XML_CANON_TRANSFORMS,
|
|
1383
|
+
XMLDSIG_NS: () => XMLDSIG_NS,
|
|
1384
|
+
XML_TRANSFORM_ENVELOPED_SIGNATURE: () => XML_TRANSFORM_ENVELOPED_SIGNATURE,
|
|
1385
|
+
computeDetailStatus: () => computeDetailStatus,
|
|
1386
|
+
computeDigestBase64: () => computeDigestBase64,
|
|
1387
|
+
computeVerificationStatus: () => computeVerificationStatus,
|
|
1388
|
+
detectDigitalSignatures: () => detectDigitalSignatures,
|
|
1389
|
+
escapeXmlAttr: () => escapeXmlAttr,
|
|
1390
|
+
escapeXmlText: () => escapeXmlText,
|
|
1391
|
+
extractAllTagText: () => extractAllTagText,
|
|
1392
|
+
extractFirstTagText: () => extractFirstTagText,
|
|
1393
|
+
extractTagAttribute: () => extractTagAttribute,
|
|
1394
|
+
getSignaturePathsToStrip: () => getSignaturePathsToStrip,
|
|
1395
|
+
isSignaturePart: () => isSignaturePart,
|
|
1396
|
+
isValidBase64: () => isValidBase64,
|
|
1397
|
+
normalizePartPath: () => normalizePartPath,
|
|
1398
|
+
parseSignatureXml: () => parseSignatureXml,
|
|
1399
|
+
resolveReferenceUriToPart: () => resolveReferenceUriToPart,
|
|
1400
|
+
verifySignatureDigests: () => verifySignatureDigests
|
|
1401
|
+
});
|
|
1402
|
+
|
|
1403
|
+
// src/opc/signature/detection.ts
|
|
1404
|
+
var SIGNATURE_PART_PREFIX = "_xmlsignatures/";
|
|
1405
|
+
var SIGNATURE_PREFIX = SIGNATURE_PART_PREFIX;
|
|
1406
|
+
function isSignaturePart(path) {
|
|
1407
|
+
return path.replace(/^\//, "").toLowerCase().startsWith(SIGNATURE_PART_PREFIX);
|
|
1408
|
+
}
|
|
1409
|
+
function detectDigitalSignatures(zipEntryPaths) {
|
|
1410
|
+
const sigPaths = zipEntryPaths.filter(
|
|
1411
|
+
(p) => p.startsWith(SIGNATURE_PREFIX) && p.endsWith(".xml")
|
|
1412
|
+
);
|
|
1413
|
+
return {
|
|
1414
|
+
hasSignatures: sigPaths.length > 0,
|
|
1415
|
+
signatureCount: sigPaths.length,
|
|
1416
|
+
signaturePaths: sigPaths
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
function getSignaturePathsToStrip(zipEntryPaths) {
|
|
1420
|
+
return zipEntryPaths.filter((p) => p.startsWith(SIGNATURE_PREFIX));
|
|
1421
|
+
}
|
|
1422
|
+
function findByLocalName(parent, localName) {
|
|
1423
|
+
if (!parent) {
|
|
1424
|
+
return void 0;
|
|
1425
|
+
}
|
|
1426
|
+
if (parent[localName] !== void 0 && typeof parent[localName] === "object") {
|
|
1427
|
+
return parent[localName];
|
|
1428
|
+
}
|
|
1429
|
+
for (const key of Object.keys(parent)) {
|
|
1430
|
+
const parts = key.split(":");
|
|
1431
|
+
if (parts[parts.length - 1] === localName && typeof parent[key] === "object") {
|
|
1432
|
+
return parent[key];
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
return void 0;
|
|
1436
|
+
}
|
|
1437
|
+
function findScalarByLocalName(parent, localName) {
|
|
1438
|
+
if (!parent) {
|
|
1439
|
+
return void 0;
|
|
1440
|
+
}
|
|
1441
|
+
if (parent[localName] !== void 0) {
|
|
1442
|
+
const v = parent[localName];
|
|
1443
|
+
if (typeof v === "string") {
|
|
1444
|
+
return v;
|
|
1445
|
+
}
|
|
1446
|
+
if (typeof v === "number" || typeof v === "boolean") {
|
|
1447
|
+
return String(v);
|
|
1448
|
+
}
|
|
1449
|
+
if (typeof v === "object" && v !== null && "#text" in v) {
|
|
1450
|
+
return String(v["#text"]);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
for (const key of Object.keys(parent)) {
|
|
1454
|
+
const parts = key.split(":");
|
|
1455
|
+
if (parts[parts.length - 1] === localName) {
|
|
1456
|
+
const v = parent[key];
|
|
1457
|
+
if (typeof v === "string") {
|
|
1458
|
+
return v;
|
|
1459
|
+
}
|
|
1460
|
+
if (typeof v === "number" || typeof v === "boolean") {
|
|
1461
|
+
return String(v);
|
|
1462
|
+
}
|
|
1463
|
+
if (typeof v === "object" && v !== null && "#text" in v) {
|
|
1464
|
+
return String(v["#text"]);
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
return void 0;
|
|
1469
|
+
}
|
|
1470
|
+
function findAllByLocalName(parent, localName) {
|
|
1471
|
+
if (!parent) {
|
|
1472
|
+
return [];
|
|
1473
|
+
}
|
|
1474
|
+
for (const key of Object.keys(parent)) {
|
|
1475
|
+
const parts = key.split(":");
|
|
1476
|
+
if (parts[parts.length - 1] === localName) {
|
|
1477
|
+
const v = parent[key];
|
|
1478
|
+
if (Array.isArray(v)) {
|
|
1479
|
+
return v;
|
|
1480
|
+
}
|
|
1481
|
+
if (typeof v === "object" && v !== null) {
|
|
1482
|
+
return [v];
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
return [];
|
|
1487
|
+
}
|
|
1488
|
+
function parseSignatureXml(signatureXml, signaturePath) {
|
|
1489
|
+
const signature = findByLocalName(signatureXml, "Signature");
|
|
1490
|
+
const signedInfo = findByLocalName(signature, "SignedInfo");
|
|
1491
|
+
const sigMethodNode = findByLocalName(signedInfo, "SignatureMethod");
|
|
1492
|
+
const signatureMethod = sigMethodNode?.["@_Algorithm"];
|
|
1493
|
+
const signatureValue = findScalarByLocalName(signature, "SignatureValue")?.replace(/\s+/g, "");
|
|
1494
|
+
const references = [];
|
|
1495
|
+
const refNodes = findAllByLocalName(signedInfo, "Reference");
|
|
1496
|
+
for (const ref of refNodes) {
|
|
1497
|
+
const uri = String(ref["@_URI"] || "");
|
|
1498
|
+
const dmNode = findByLocalName(ref, "DigestMethod");
|
|
1499
|
+
const digestMethod2 = dmNode?.["@_Algorithm"];
|
|
1500
|
+
const digestValue = findScalarByLocalName(ref, "DigestValue")?.replace(/\s+/g, "");
|
|
1501
|
+
references.push({
|
|
1502
|
+
uri,
|
|
1503
|
+
...digestMethod2 === void 0 ? {} : { digestMethod: digestMethod2 },
|
|
1504
|
+
...digestValue === void 0 ? {} : { digestValue }
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
const digestMethod = references[0]?.digestMethod;
|
|
1508
|
+
const keyInfo = findByLocalName(signature, "KeyInfo");
|
|
1509
|
+
const x509Data = findByLocalName(keyInfo, "X509Data");
|
|
1510
|
+
let certificate;
|
|
1511
|
+
if (x509Data) {
|
|
1512
|
+
const certBase64 = findScalarByLocalName(x509Data, "X509Certificate")?.replace(/\s+/g, "");
|
|
1513
|
+
if (certBase64) {
|
|
1514
|
+
const issuerSerial = findByLocalName(x509Data, "X509IssuerSerial");
|
|
1515
|
+
const issuer = findScalarByLocalName(issuerSerial, "X509IssuerName");
|
|
1516
|
+
const serialNumber = findScalarByLocalName(issuerSerial, "X509SerialNumber");
|
|
1517
|
+
const subject = findScalarByLocalName(x509Data, "X509SubjectName");
|
|
1518
|
+
certificate = {
|
|
1519
|
+
certificateBase64: certBase64,
|
|
1520
|
+
...issuer ? { issuer } : {},
|
|
1521
|
+
...subject ? { subject } : {},
|
|
1522
|
+
...serialNumber ? { serialNumber } : {}
|
|
1523
|
+
};
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
let status = "unverified";
|
|
1527
|
+
if (certificate?.validTo) {
|
|
1528
|
+
const expiry = new Date(certificate.validTo);
|
|
1529
|
+
if (expiry < /* @__PURE__ */ new Date()) {
|
|
1530
|
+
status = "expired";
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
return {
|
|
1534
|
+
signaturePath,
|
|
1535
|
+
...signatureMethod === void 0 ? {} : { signatureMethod },
|
|
1536
|
+
...digestMethod === void 0 ? {} : { digestMethod },
|
|
1537
|
+
...signatureValue === void 0 ? {} : { signatureValue },
|
|
1538
|
+
...certificate === void 0 ? {} : { certificate },
|
|
1539
|
+
status,
|
|
1540
|
+
references
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
async function verifySignatureDigests(signature, getPartContent) {
|
|
1544
|
+
if (!signature.references.length) {
|
|
1545
|
+
return "unverified";
|
|
1546
|
+
}
|
|
1547
|
+
if (typeof globalThis.crypto?.subtle === "undefined") {
|
|
1548
|
+
return "unverified";
|
|
1549
|
+
}
|
|
1550
|
+
for (const ref of signature.references) {
|
|
1551
|
+
if (!ref.digestValue || !ref.uri) {
|
|
1552
|
+
continue;
|
|
1553
|
+
}
|
|
1554
|
+
const algo = ref.digestMethod?.toLowerCase() || "";
|
|
1555
|
+
let hashAlgo;
|
|
1556
|
+
if (algo.includes("sha256") || algo.includes("sha-256")) {
|
|
1557
|
+
hashAlgo = "SHA-256";
|
|
1558
|
+
} else if (algo.includes("sha512") || algo.includes("sha-512")) {
|
|
1559
|
+
hashAlgo = "SHA-512";
|
|
1560
|
+
} else if (algo.includes("sha1") || algo.includes("sha-1")) {
|
|
1561
|
+
hashAlgo = "SHA-1";
|
|
1562
|
+
} else {
|
|
1563
|
+
continue;
|
|
1564
|
+
}
|
|
1565
|
+
const content = await getPartContent(ref.uri);
|
|
1566
|
+
if (!content) {
|
|
1567
|
+
continue;
|
|
1568
|
+
}
|
|
1569
|
+
try {
|
|
1570
|
+
const digest = await crypto.subtle.digest(hashAlgo, content);
|
|
1571
|
+
const digestBase64 = arrayBufferToBase64(digest);
|
|
1572
|
+
if (digestBase64 !== ref.digestValue) {
|
|
1573
|
+
return "invalid";
|
|
1574
|
+
}
|
|
1575
|
+
} catch {
|
|
1576
|
+
return "unverified";
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
return signature.certificate ? "valid" : "unknownCA";
|
|
1580
|
+
}
|
|
1581
|
+
function arrayBufferToBase64(buffer) {
|
|
1582
|
+
const bytes = new Uint8Array(buffer);
|
|
1583
|
+
let binary = "";
|
|
1584
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
1585
|
+
binary += String.fromCharCode(bytes[i]);
|
|
1586
|
+
}
|
|
1587
|
+
return btoa(binary);
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
// src/opc/signature/constants.ts
|
|
1591
|
+
var DIGITAL_SIGNATURE_ORIGIN_REL_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin";
|
|
1592
|
+
var DIGITAL_SIGNATURE_REL_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature";
|
|
1593
|
+
var PPTX_VIEWER_MANIFEST_NS = "urn:pptx-viewer:ooxml-signature:v1";
|
|
1594
|
+
var XMLDSIG_NS = "http://www.w3.org/2000/09/xmldsig#";
|
|
1595
|
+
var OPC_RELATIONSHIP_TRANSFORM = "http://schemas.openxmlformats.org/package/2006/RelationshipTransform";
|
|
1596
|
+
var XML_TRANSFORM_ENVELOPED_SIGNATURE = "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
|
|
1597
|
+
var SUPPORTED_XML_CANON_TRANSFORMS = /* @__PURE__ */ new Set([
|
|
1598
|
+
"http://www.w3.org/TR/2001/REC-xml-c14n-20010315",
|
|
1599
|
+
"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments",
|
|
1600
|
+
"http://www.w3.org/2001/10/xml-exc-c14n#",
|
|
1601
|
+
"http://www.w3.org/2001/10/xml-exc-c14n#WithComments",
|
|
1602
|
+
XML_TRANSFORM_ENVELOPED_SIGNATURE
|
|
1603
|
+
]);
|
|
1604
|
+
var ENTERPRISE_TRUST_ROOTS_FILE_ENV = "PPTX_VIEWER_TRUST_ROOTS_FILE";
|
|
1605
|
+
var ENTERPRISE_TRUST_ROOTS_PEM_ENV = "PPTX_VIEWER_TRUST_ROOTS_PEM";
|
|
1606
|
+
var ENTERPRISE_REQUIRE_REVOCATION_ENV = "PPTX_VIEWER_REQUIRE_REVOCATION_CHECK";
|
|
1607
|
+
var ENTERPRISE_FAIL_ON_REVOCATION_UNKNOWN_ENV = "PPTX_VIEWER_FAIL_ON_REVOCATION_UNKNOWN";
|
|
1608
|
+
var ENTERPRISE_REQUIRE_TIMESTAMP_ENV = "PPTX_VIEWER_REQUIRE_TIMESTAMP";
|
|
1609
|
+
var DIGEST_ALGORITHM_TO_HASH = {
|
|
1610
|
+
"http://www.w3.org/2000/09/xmldsig#sha1": "sha1",
|
|
1611
|
+
"http://www.w3.org/2001/04/xmlenc#sha256": "sha256",
|
|
1612
|
+
"http://www.w3.org/2001/04/xmlenc#sha384": "sha384",
|
|
1613
|
+
"http://www.w3.org/2001/04/xmlenc#sha512": "sha512"
|
|
1614
|
+
};
|
|
1615
|
+
var DIGEST_ALGORITHM_TO_WEB_CRYPTO = {
|
|
1616
|
+
"http://www.w3.org/2000/09/xmldsig#sha1": "SHA-1",
|
|
1617
|
+
"http://www.w3.org/2001/04/xmlenc#sha256": "SHA-256",
|
|
1618
|
+
"http://www.w3.org/2001/04/xmlenc#sha384": "SHA-384",
|
|
1619
|
+
"http://www.w3.org/2001/04/xmlenc#sha512": "SHA-512"
|
|
1620
|
+
};
|
|
1621
|
+
|
|
1622
|
+
// src/opc/signature/xml-utils.ts
|
|
1623
|
+
function escapeXmlAttr(value) {
|
|
1624
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1625
|
+
}
|
|
1626
|
+
function escapeXmlText(value) {
|
|
1627
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
1628
|
+
}
|
|
1629
|
+
function isValidBase64(value) {
|
|
1630
|
+
return typeof value === "string" && value.length > 0 && /^[A-Za-z0-9+/=\s]+$/.test(value);
|
|
1631
|
+
}
|
|
1632
|
+
function extractTagAttribute(xml, tagName, attributeName) {
|
|
1633
|
+
const pattern = new RegExp(
|
|
1634
|
+
`<${tagName}\\b[^>]*\\b${attributeName}="(?<attributeValue>[^"]+)"`,
|
|
1635
|
+
"i"
|
|
1636
|
+
);
|
|
1637
|
+
const match = xml.match(pattern);
|
|
1638
|
+
return match?.groups?.["attributeValue"]?.trim();
|
|
1639
|
+
}
|
|
1640
|
+
function extractFirstTagText(xml, localName) {
|
|
1641
|
+
const pattern = new RegExp(
|
|
1642
|
+
`<([\\w.-]+:)?${localName}\\b[^>]*>([\\s\\S]*?)<\\/([\\w.-]+:)?${localName}>`,
|
|
1643
|
+
"i"
|
|
1644
|
+
);
|
|
1645
|
+
const match = xml.match(pattern);
|
|
1646
|
+
return match?.[2]?.replace(/\s+/g, "").trim() || void 0;
|
|
1647
|
+
}
|
|
1648
|
+
function extractAllTagText(xml, localName) {
|
|
1649
|
+
const result = [];
|
|
1650
|
+
const regex = new RegExp(
|
|
1651
|
+
`<([\\w.-]+:)?${localName}\\b[^>]*>([\\s\\S]*?)<\\/([\\w.-]+:)?${localName}>`,
|
|
1652
|
+
"gi"
|
|
1653
|
+
);
|
|
1654
|
+
let match = regex.exec(xml);
|
|
1655
|
+
while (match) {
|
|
1656
|
+
const value = match[2]?.replace(/\s+/g, "").trim();
|
|
1657
|
+
if (value) {
|
|
1658
|
+
result.push(value);
|
|
1659
|
+
}
|
|
1660
|
+
match = regex.exec(xml);
|
|
1661
|
+
}
|
|
1662
|
+
return result;
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
// src/opc/signature/reference-utils.ts
|
|
1666
|
+
function normalizePartPath(partPath) {
|
|
1667
|
+
return partPath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
1668
|
+
}
|
|
1669
|
+
function resolveReferenceUriToPart(uri) {
|
|
1670
|
+
const trimmed = uri.trim();
|
|
1671
|
+
if (trimmed.length === 0 || trimmed.startsWith("#")) {
|
|
1672
|
+
return void 0;
|
|
1673
|
+
}
|
|
1674
|
+
const decoded = decodeURIComponent(trimmed);
|
|
1675
|
+
return normalizePartPath(decoded.startsWith("/") ? decoded.slice(1) : decoded);
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
// src/opc/signature/digest.ts
|
|
1679
|
+
async function computeDigestBase64(content, digestAlgorithmUri) {
|
|
1680
|
+
const webCryptoAlgo = DIGEST_ALGORITHM_TO_WEB_CRYPTO[digestAlgorithmUri];
|
|
1681
|
+
if (!webCryptoAlgo) {
|
|
1682
|
+
return void 0;
|
|
1683
|
+
}
|
|
1684
|
+
if (typeof globalThis.crypto?.subtle === "undefined") {
|
|
1685
|
+
return void 0;
|
|
1686
|
+
}
|
|
1687
|
+
const buf = new ArrayBuffer(content.byteLength);
|
|
1688
|
+
new Uint8Array(buf).set(content);
|
|
1689
|
+
const digest = await globalThis.crypto.subtle.digest(webCryptoAlgo, buf);
|
|
1690
|
+
return uint8ArrayToBase64(new Uint8Array(digest));
|
|
1691
|
+
}
|
|
1692
|
+
function uint8ArrayToBase64(bytes) {
|
|
1693
|
+
let binary = "";
|
|
1694
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
1695
|
+
binary += String.fromCharCode(bytes[i]);
|
|
1696
|
+
}
|
|
1697
|
+
return btoa(binary);
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
// src/opc/signature/inspection-status.ts
|
|
1701
|
+
function computeDetailStatus(detail, policy) {
|
|
1702
|
+
const hasDigestMismatch = detail.referenceChecks.some(
|
|
1703
|
+
(check) => check.digestStatus === "mismatch"
|
|
1704
|
+
);
|
|
1705
|
+
const hasMissingPart = detail.missingPartReferences.length > 0;
|
|
1706
|
+
const hasVerifiedDigest = detail.referenceChecks.some(
|
|
1707
|
+
(check) => check.digestStatus === "verified"
|
|
1708
|
+
);
|
|
1709
|
+
const revocationUnknown = detail.certificateRevocationStatus === "unknown" || detail.certificateRevocationStatus === "not-checked" || detail.certificateRevocationStatus === "error";
|
|
1710
|
+
const timestampMissingOrUntrusted = detail.timestampAuthorityStatus === "not-present" || detail.timestampAuthorityStatus === "not-checked" || detail.timestampAuthorityStatus === "error" || detail.timestampAuthorityStatus === "untrusted";
|
|
1711
|
+
if (detail.signatureValueStatus === "invalid") {
|
|
1712
|
+
return "signature-invalid";
|
|
1713
|
+
}
|
|
1714
|
+
if (hasMissingPart) {
|
|
1715
|
+
return "reference-missing";
|
|
1716
|
+
}
|
|
1717
|
+
if (hasDigestMismatch) {
|
|
1718
|
+
return "digest-mismatch";
|
|
1719
|
+
}
|
|
1720
|
+
if (detail.certificateRevocationStatus === "revoked") {
|
|
1721
|
+
return "certificate-revoked";
|
|
1722
|
+
}
|
|
1723
|
+
if (policy.requireRevocationCheck && (policy.failOnRevocationUnknown ? revocationUnknown : detail.certificateRevocationStatus !== "good")) {
|
|
1724
|
+
return "certificate-untrusted";
|
|
1725
|
+
}
|
|
1726
|
+
if (detail.timestampAuthorityStatus === "invalid") {
|
|
1727
|
+
return "timestamp-invalid";
|
|
1728
|
+
}
|
|
1729
|
+
if (policy.requireTimestamp && timestampMissingOrUntrusted) {
|
|
1730
|
+
return "timestamp-untrusted";
|
|
1731
|
+
}
|
|
1732
|
+
if (detail.timestampAuthorityStatus === "untrusted") {
|
|
1733
|
+
return "timestamp-untrusted";
|
|
1734
|
+
}
|
|
1735
|
+
if (detail.certificateTrustStatus === "untrusted" && detail.signatureValueStatus === "verified") {
|
|
1736
|
+
return "certificate-untrusted";
|
|
1737
|
+
}
|
|
1738
|
+
if (hasVerifiedDigest && detail.signatureValueStatus === "verified") {
|
|
1739
|
+
return "verified";
|
|
1740
|
+
}
|
|
1741
|
+
return "structural-only";
|
|
1742
|
+
}
|
|
1743
|
+
function computeVerificationStatus(details) {
|
|
1744
|
+
const hasInvalidSignature = details.some((detail) => detail.status === "signature-invalid");
|
|
1745
|
+
const hasMissing = details.some((detail) => detail.status === "reference-missing");
|
|
1746
|
+
const hasMismatch = details.some((detail) => detail.status === "digest-mismatch");
|
|
1747
|
+
const hasUntrusted = details.some((detail) => detail.status === "certificate-untrusted");
|
|
1748
|
+
const hasRevoked = details.some((detail) => detail.status === "certificate-revoked");
|
|
1749
|
+
const hasTimestampInvalid = details.some((detail) => detail.status === "timestamp-invalid");
|
|
1750
|
+
const hasTimestampUntrusted = details.some((detail) => detail.status === "timestamp-untrusted");
|
|
1751
|
+
const allVerified = details.every((detail) => detail.status === "verified");
|
|
1752
|
+
return hasInvalidSignature ? "signature-invalid" : hasRevoked ? "certificate-revoked" : hasTimestampInvalid ? "timestamp-invalid" : hasTimestampUntrusted ? "timestamp-untrusted" : hasMissing ? "reference-missing" : hasMismatch ? "digest-mismatch" : allVerified ? "verified-trusted" : hasUntrusted ? "verified-untrusted" : "present-not-verified";
|
|
1753
|
+
}
|
|
667
1754
|
|
|
668
1755
|
// src/diagram/relationships.ts
|
|
669
1756
|
function diagramRelationshipsPart(partPath) {
|
|
@@ -1071,11 +2158,11 @@ function styleRef(element) {
|
|
|
1071
2158
|
function parseStyleReferences(style) {
|
|
1072
2159
|
const refs = {};
|
|
1073
2160
|
const line2 = styleRef(first(style, "lnRef", NS.a));
|
|
1074
|
-
const
|
|
2161
|
+
const fill2 = styleRef(first(style, "fillRef", NS.a));
|
|
1075
2162
|
const effect = styleRef(first(style, "effectRef", NS.a));
|
|
1076
2163
|
const font = styleRef(first(style, "fontRef", NS.a));
|
|
1077
2164
|
if (line2) refs.line = line2;
|
|
1078
|
-
if (
|
|
2165
|
+
if (fill2) refs.fill = fill2;
|
|
1079
2166
|
if (effect) refs.effect = effect;
|
|
1080
2167
|
if (font) refs.font = font;
|
|
1081
2168
|
return refs;
|
|
@@ -1127,23 +2214,23 @@ function fillElementOf(properties) {
|
|
|
1127
2214
|
) : void 0;
|
|
1128
2215
|
}
|
|
1129
2216
|
function parseDrawingFill(properties) {
|
|
1130
|
-
const
|
|
1131
|
-
if (!
|
|
1132
|
-
switch (
|
|
2217
|
+
const fill2 = fillElementOf(properties);
|
|
2218
|
+
if (!fill2) return void 0;
|
|
2219
|
+
switch (fill2.localName) {
|
|
1133
2220
|
case "noFill":
|
|
1134
2221
|
return { kind: "none" };
|
|
1135
2222
|
case "solidFill": {
|
|
1136
|
-
const color = parseDrawingColorIn(
|
|
2223
|
+
const color = parseDrawingColorIn(fill2);
|
|
1137
2224
|
return color ? { kind: "solid", color } : { kind: "unsupported", element: "solidFill" };
|
|
1138
2225
|
}
|
|
1139
2226
|
case "gradFill": {
|
|
1140
|
-
const stops = children(first(
|
|
2227
|
+
const stops = children(first(fill2, "gsLst", NS.a) ?? fill2, "gs", NS.a).flatMap((stop) => {
|
|
1141
2228
|
const color = parseDrawingColorIn(stop);
|
|
1142
2229
|
const position = Number.parseInt(stop.getAttribute("pos") ?? "", 10);
|
|
1143
2230
|
return color && Number.isFinite(position) ? [{ position: position / 1e3, color }] : [];
|
|
1144
2231
|
});
|
|
1145
|
-
const angle = Number.parseInt(first(
|
|
1146
|
-
const path = first(
|
|
2232
|
+
const angle = Number.parseInt(first(fill2, "lin", NS.a)?.getAttribute("ang") ?? "", 10);
|
|
2233
|
+
const path = first(fill2, "path", NS.a)?.getAttribute("path");
|
|
1147
2234
|
return {
|
|
1148
2235
|
kind: "gradient",
|
|
1149
2236
|
stops,
|
|
@@ -1152,22 +2239,22 @@ function parseDrawingFill(properties) {
|
|
|
1152
2239
|
};
|
|
1153
2240
|
}
|
|
1154
2241
|
case "pattFill": {
|
|
1155
|
-
const foreground = parseDrawingColorIn(first(
|
|
1156
|
-
const background = parseDrawingColorIn(first(
|
|
2242
|
+
const foreground = parseDrawingColorIn(first(fill2, "fgClr", NS.a));
|
|
2243
|
+
const background = parseDrawingColorIn(first(fill2, "bgClr", NS.a));
|
|
1157
2244
|
return {
|
|
1158
2245
|
kind: "pattern",
|
|
1159
|
-
preset:
|
|
2246
|
+
preset: fill2.getAttribute("prst") ?? "",
|
|
1160
2247
|
...foreground ? { foreground } : {},
|
|
1161
2248
|
...background ? { background } : {}
|
|
1162
2249
|
};
|
|
1163
2250
|
}
|
|
1164
2251
|
case "blipFill": {
|
|
1165
|
-
const blip = first(
|
|
2252
|
+
const blip = first(fill2, "blip", NS.a);
|
|
1166
2253
|
const relId = blip?.getAttributeNS(NS.r, "embed") || blip?.getAttribute("r:embed") || void 0;
|
|
1167
2254
|
return { kind: "picture", ...relId ? { relId } : {} };
|
|
1168
2255
|
}
|
|
1169
2256
|
default:
|
|
1170
|
-
return { kind: "unsupported", element:
|
|
2257
|
+
return { kind: "unsupported", element: fill2.localName };
|
|
1171
2258
|
}
|
|
1172
2259
|
}
|
|
1173
2260
|
function parseDrawingLine(ln) {
|
|
@@ -1175,8 +2262,8 @@ function parseDrawingLine(ln) {
|
|
|
1175
2262
|
const line2 = {};
|
|
1176
2263
|
const width = Number.parseInt(ln.getAttribute("w") ?? "", 10);
|
|
1177
2264
|
if (Number.isFinite(width)) line2.widthEmu = width;
|
|
1178
|
-
const
|
|
1179
|
-
if (
|
|
2265
|
+
const fill2 = parseDrawingFill(ln);
|
|
2266
|
+
if (fill2) line2.fill = fill2;
|
|
1180
2267
|
const dash = first(ln, "prstDash", NS.a)?.getAttribute("val");
|
|
1181
2268
|
if (dash) line2.dash = dash;
|
|
1182
2269
|
const cap = ln.getAttribute("cap");
|
|
@@ -1396,8 +2483,8 @@ function parseShape(sp, index, group, issues) {
|
|
|
1396
2483
|
if (transform.flipVertical) shape.flipVertical = true;
|
|
1397
2484
|
if (adjustments) shape.adjustments = adjustments;
|
|
1398
2485
|
if (paths) shape.paths = paths;
|
|
1399
|
-
const
|
|
1400
|
-
if (
|
|
2486
|
+
const fill2 = parseDrawingFill(spPr);
|
|
2487
|
+
if (fill2) shape.fill = fill2;
|
|
1401
2488
|
const line2 = parseDrawingLine(first(spPr, "ln", NS.a));
|
|
1402
2489
|
if (line2) shape.line = line2;
|
|
1403
2490
|
const style = first(sp, "style", NS.dsp);
|
|
@@ -2214,6 +3301,7 @@ __export(geometry_exports, {
|
|
|
2214
3301
|
evaluateFormula: () => evaluateFormula,
|
|
2215
3302
|
evaluateGuides: () => evaluateGuides,
|
|
2216
3303
|
findAllIntersections: () => findAllIntersections,
|
|
3304
|
+
flattenSvgPath: () => flattenSvgPath,
|
|
2217
3305
|
fmtNum: () => fmtNum,
|
|
2218
3306
|
fragmentShapes: () => fragmentShapes,
|
|
2219
3307
|
gd: () => gd,
|
|
@@ -17161,6 +18249,197 @@ function subtractSvgPaths(path1, path2) {
|
|
|
17161
18249
|
return subtractShapes(path1, path2);
|
|
17162
18250
|
}
|
|
17163
18251
|
|
|
18252
|
+
// src/geometry/svg-path-curves.ts
|
|
18253
|
+
function sampleCubic(p0, p1, p2, p3, segments, out) {
|
|
18254
|
+
for (let i = 1; i <= segments; i++) {
|
|
18255
|
+
const t = i / segments;
|
|
18256
|
+
const mt = 1 - t;
|
|
18257
|
+
const x = mt * mt * mt * p0.x + 3 * mt * mt * t * p1.x + 3 * mt * t * t * p2.x + t * t * t * p3.x;
|
|
18258
|
+
const y = mt * mt * mt * p0.y + 3 * mt * mt * t * p1.y + 3 * mt * t * t * p2.y + t * t * t * p3.y;
|
|
18259
|
+
out.push({ x, y });
|
|
18260
|
+
}
|
|
18261
|
+
}
|
|
18262
|
+
function sampleQuadratic(p0, p1, p2, segments, out) {
|
|
18263
|
+
for (let i = 1; i <= segments; i++) {
|
|
18264
|
+
const t = i / segments;
|
|
18265
|
+
const mt = 1 - t;
|
|
18266
|
+
const x = mt * mt * p0.x + 2 * mt * t * p1.x + t * t * p2.x;
|
|
18267
|
+
const y = mt * mt * p0.y + 2 * mt * t * p1.y + t * t * p2.y;
|
|
18268
|
+
out.push({ x, y });
|
|
18269
|
+
}
|
|
18270
|
+
}
|
|
18271
|
+
function sampleArc(start, rxIn, ryIn, xAxisRotationDeg, largeArcFlag, sweepFlag, end, segments, out) {
|
|
18272
|
+
if (rxIn === 0 || ryIn === 0 || start.x === end.x && start.y === end.y) {
|
|
18273
|
+
out.push(end);
|
|
18274
|
+
return;
|
|
18275
|
+
}
|
|
18276
|
+
const phi = xAxisRotationDeg * Math.PI / 180;
|
|
18277
|
+
const cosPhi = Math.cos(phi);
|
|
18278
|
+
const sinPhi = Math.sin(phi);
|
|
18279
|
+
let rx = Math.abs(rxIn);
|
|
18280
|
+
let ry = Math.abs(ryIn);
|
|
18281
|
+
const dx2 = (start.x - end.x) / 2;
|
|
18282
|
+
const dy2 = (start.y - end.y) / 2;
|
|
18283
|
+
const x1p = cosPhi * dx2 + sinPhi * dy2;
|
|
18284
|
+
const y1p = -sinPhi * dx2 + cosPhi * dy2;
|
|
18285
|
+
const lambda = x1p * x1p / (rx * rx) + y1p * y1p / (ry * ry);
|
|
18286
|
+
if (lambda > 1) {
|
|
18287
|
+
const scale = Math.sqrt(lambda);
|
|
18288
|
+
rx *= scale;
|
|
18289
|
+
ry *= scale;
|
|
18290
|
+
}
|
|
18291
|
+
const sign = largeArcFlag !== sweepFlag ? 1 : -1;
|
|
18292
|
+
const num = rx * rx * ry * ry - rx * rx * y1p * y1p - ry * ry * x1p * x1p;
|
|
18293
|
+
const den = rx * rx * y1p * y1p + ry * ry * x1p * x1p;
|
|
18294
|
+
const coef = sign * Math.sqrt(Math.max(0, num / den));
|
|
18295
|
+
const cxp = coef * (rx * y1p) / ry;
|
|
18296
|
+
const cyp = coef * -(ry * x1p) / rx;
|
|
18297
|
+
const cx = cosPhi * cxp - sinPhi * cyp + (start.x + end.x) / 2;
|
|
18298
|
+
const cy = sinPhi * cxp + cosPhi * cyp + (start.y + end.y) / 2;
|
|
18299
|
+
const angle = (ux, uy, vx, vy) => {
|
|
18300
|
+
const sign2 = ux * vy - uy * vx < 0 ? -1 : 1;
|
|
18301
|
+
const dot = Math.max(
|
|
18302
|
+
-1,
|
|
18303
|
+
Math.min(1, (ux * vx + uy * vy) / (Math.hypot(ux, uy) * Math.hypot(vx, vy)))
|
|
18304
|
+
);
|
|
18305
|
+
return sign2 * Math.acos(dot);
|
|
18306
|
+
};
|
|
18307
|
+
const theta1 = angle(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
|
|
18308
|
+
let deltaTheta = angle((x1p - cxp) / rx, (y1p - cyp) / ry, (-x1p - cxp) / rx, (-y1p - cyp) / ry);
|
|
18309
|
+
if (!sweepFlag && deltaTheta > 0) {
|
|
18310
|
+
deltaTheta -= 2 * Math.PI;
|
|
18311
|
+
} else if (sweepFlag && deltaTheta < 0) {
|
|
18312
|
+
deltaTheta += 2 * Math.PI;
|
|
18313
|
+
}
|
|
18314
|
+
const steps = Math.max(2, Math.round(segments * (Math.abs(deltaTheta) / (Math.PI / 2))));
|
|
18315
|
+
for (let i = 1; i <= steps; i++) {
|
|
18316
|
+
const theta = theta1 + deltaTheta * i / steps;
|
|
18317
|
+
const x = cx + rx * Math.cos(theta) * cosPhi - ry * Math.sin(theta) * sinPhi;
|
|
18318
|
+
const y = cy + rx * Math.cos(theta) * sinPhi + ry * Math.sin(theta) * cosPhi;
|
|
18319
|
+
out.push({ x, y });
|
|
18320
|
+
}
|
|
18321
|
+
}
|
|
18322
|
+
|
|
18323
|
+
// src/geometry/svg-path-flatten.ts
|
|
18324
|
+
var COMMAND_RE = /[MLCQZAHVSmlcqzahvs][^MLCQZAHVSmlcqzahvs]*/gu;
|
|
18325
|
+
var NUMBER_RE = /-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/gu;
|
|
18326
|
+
function tokenize(d) {
|
|
18327
|
+
const tokens = [];
|
|
18328
|
+
const matches = d.match(COMMAND_RE);
|
|
18329
|
+
if (!matches) {
|
|
18330
|
+
return tokens;
|
|
18331
|
+
}
|
|
18332
|
+
for (const raw of matches) {
|
|
18333
|
+
const type = raw.charAt(0);
|
|
18334
|
+
const nums = raw.slice(1).match(NUMBER_RE);
|
|
18335
|
+
tokens.push({ type, values: nums ? nums.map((n) => Number.parseFloat(n)) : [] });
|
|
18336
|
+
}
|
|
18337
|
+
return tokens;
|
|
18338
|
+
}
|
|
18339
|
+
function flattenSvgPath(d, curveSegments = 16) {
|
|
18340
|
+
if (!Number.isFinite(curveSegments) || curveSegments < 1) curveSegments = 16;
|
|
18341
|
+
curveSegments = Math.min(4096, Math.floor(curveSegments));
|
|
18342
|
+
const tokens = tokenize(d);
|
|
18343
|
+
const loops = [];
|
|
18344
|
+
let current = [];
|
|
18345
|
+
let cursor = { x: 0, y: 0 };
|
|
18346
|
+
let subpathStart = { x: 0, y: 0 };
|
|
18347
|
+
let lastControl;
|
|
18348
|
+
let lastCommand = "";
|
|
18349
|
+
const closeLoop = () => {
|
|
18350
|
+
if (current.length > 0) {
|
|
18351
|
+
loops.push(current);
|
|
18352
|
+
}
|
|
18353
|
+
current = [];
|
|
18354
|
+
};
|
|
18355
|
+
for (const token of tokens) {
|
|
18356
|
+
const type = token.type;
|
|
18357
|
+
const upper = type.toUpperCase();
|
|
18358
|
+
const relative = type !== upper;
|
|
18359
|
+
const v = token.values;
|
|
18360
|
+
if (v.some((value) => !Number.isFinite(value)) || upper === "M" && v.length < 2) continue;
|
|
18361
|
+
if (upper === "M") {
|
|
18362
|
+
closeLoop();
|
|
18363
|
+
const x = relative ? cursor.x + at(v, 0) : at(v, 0);
|
|
18364
|
+
const y = relative ? cursor.y + at(v, 1) : at(v, 1);
|
|
18365
|
+
cursor = { x, y };
|
|
18366
|
+
subpathStart = cursor;
|
|
18367
|
+
current.push(cursor);
|
|
18368
|
+
for (let i = 2; i + 1 < v.length; i += 2) {
|
|
18369
|
+
const lx = relative ? cursor.x + at(v, i) : at(v, i);
|
|
18370
|
+
const ly = relative ? cursor.y + at(v, i + 1) : at(v, i + 1);
|
|
18371
|
+
cursor = { x: lx, y: ly };
|
|
18372
|
+
current.push(cursor);
|
|
18373
|
+
}
|
|
18374
|
+
} else if (upper === "L") {
|
|
18375
|
+
for (let i = 0; i + 1 < v.length; i += 2) {
|
|
18376
|
+
const x = relative ? cursor.x + at(v, i) : at(v, i);
|
|
18377
|
+
const y = relative ? cursor.y + at(v, i + 1) : at(v, i + 1);
|
|
18378
|
+
cursor = { x, y };
|
|
18379
|
+
current.push(cursor);
|
|
18380
|
+
}
|
|
18381
|
+
} else if (upper === "H") {
|
|
18382
|
+
for (const value of v) {
|
|
18383
|
+
const x = relative ? cursor.x + value : value;
|
|
18384
|
+
cursor = { x, y: cursor.y };
|
|
18385
|
+
current.push(cursor);
|
|
18386
|
+
}
|
|
18387
|
+
} else if (upper === "V") {
|
|
18388
|
+
for (const value of v) {
|
|
18389
|
+
const y = relative ? cursor.y + value : value;
|
|
18390
|
+
cursor = { x: cursor.x, y };
|
|
18391
|
+
current.push(cursor);
|
|
18392
|
+
}
|
|
18393
|
+
} else if (upper === "C") {
|
|
18394
|
+
for (let i = 0; i + 5 < v.length; i += 6) {
|
|
18395
|
+
const p1 = relative ? { x: cursor.x + at(v, i), y: cursor.y + at(v, i + 1) } : { x: at(v, i), y: at(v, i + 1) };
|
|
18396
|
+
const p2 = relative ? { x: cursor.x + at(v, i + 2), y: cursor.y + at(v, i + 3) } : { x: at(v, i + 2), y: at(v, i + 3) };
|
|
18397
|
+
const p3 = relative ? { x: cursor.x + at(v, i + 4), y: cursor.y + at(v, i + 5) } : { x: at(v, i + 4), y: at(v, i + 5) };
|
|
18398
|
+
sampleCubic(cursor, p1, p2, p3, curveSegments, current);
|
|
18399
|
+
cursor = p3;
|
|
18400
|
+
lastControl = p2;
|
|
18401
|
+
}
|
|
18402
|
+
} else if (upper === "S") {
|
|
18403
|
+
for (let i = 0; i + 3 < v.length; i += 4) {
|
|
18404
|
+
const p1 = lastCommand === "C" || lastCommand === "S" ? {
|
|
18405
|
+
x: 2 * cursor.x - (lastControl?.x ?? cursor.x),
|
|
18406
|
+
y: 2 * cursor.y - (lastControl?.y ?? cursor.y)
|
|
18407
|
+
} : cursor;
|
|
18408
|
+
const p2 = relative ? { x: cursor.x + at(v, i), y: cursor.y + at(v, i + 1) } : { x: at(v, i), y: at(v, i + 1) };
|
|
18409
|
+
const p3 = relative ? { x: cursor.x + at(v, i + 2), y: cursor.y + at(v, i + 3) } : { x: at(v, i + 2), y: at(v, i + 3) };
|
|
18410
|
+
sampleCubic(cursor, p1, p2, p3, curveSegments, current);
|
|
18411
|
+
cursor = p3;
|
|
18412
|
+
lastControl = p2;
|
|
18413
|
+
}
|
|
18414
|
+
} else if (upper === "Q") {
|
|
18415
|
+
for (let i = 0; i + 3 < v.length; i += 4) {
|
|
18416
|
+
const p1 = relative ? { x: cursor.x + at(v, i), y: cursor.y + at(v, i + 1) } : { x: at(v, i), y: at(v, i + 1) };
|
|
18417
|
+
const p2 = relative ? { x: cursor.x + at(v, i + 2), y: cursor.y + at(v, i + 3) } : { x: at(v, i + 2), y: at(v, i + 3) };
|
|
18418
|
+
sampleQuadratic(cursor, p1, p2, curveSegments, current);
|
|
18419
|
+
cursor = p2;
|
|
18420
|
+
lastControl = p1;
|
|
18421
|
+
}
|
|
18422
|
+
} else if (upper === "A") {
|
|
18423
|
+
for (let i = 0; i + 6 < v.length; i += 7) {
|
|
18424
|
+
const rx = at(v, i);
|
|
18425
|
+
const ry = at(v, i + 1);
|
|
18426
|
+
const rot = at(v, i + 2);
|
|
18427
|
+
const largeArc = at(v, i + 3) !== 0;
|
|
18428
|
+
const sweep = at(v, i + 4) !== 0;
|
|
18429
|
+
const end = relative ? { x: cursor.x + at(v, i + 5), y: cursor.y + at(v, i + 6) } : { x: at(v, i + 5), y: at(v, i + 6) };
|
|
18430
|
+
sampleArc(cursor, rx, ry, rot, largeArc, sweep, end, curveSegments, current);
|
|
18431
|
+
cursor = end;
|
|
18432
|
+
}
|
|
18433
|
+
} else if (upper === "Z") {
|
|
18434
|
+
cursor = subpathStart;
|
|
18435
|
+
current.push(cursor);
|
|
18436
|
+
}
|
|
18437
|
+
lastCommand = upper;
|
|
18438
|
+
}
|
|
18439
|
+
closeLoop();
|
|
18440
|
+
return loops;
|
|
18441
|
+
}
|
|
18442
|
+
|
|
17164
18443
|
// src/units/index.ts
|
|
17165
18444
|
var units_exports = {};
|
|
17166
18445
|
__export(units_exports, {
|
|
@@ -17304,7 +18583,7 @@ __export(math_exports, {
|
|
|
17304
18583
|
readRunText: () => readRunText,
|
|
17305
18584
|
rowsToLatex: () => rowsToLatex,
|
|
17306
18585
|
soleChild: () => soleChild,
|
|
17307
|
-
tokenize: () =>
|
|
18586
|
+
tokenize: () => tokenize2,
|
|
17308
18587
|
tryParseScripts: () => tryParseScripts,
|
|
17309
18588
|
wrapDelimited: () => wrapDelimited
|
|
17310
18589
|
});
|
|
@@ -17320,7 +18599,7 @@ function stripXmlOrderSuffix(tagName) {
|
|
|
17320
18599
|
// src/math/latex-omml-siblings.ts
|
|
17321
18600
|
var LETTER_RE = /[a-zA-Z]/u;
|
|
17322
18601
|
var WHITESPACE_RE = /\s/u;
|
|
17323
|
-
function
|
|
18602
|
+
function tokenize2(latex) {
|
|
17324
18603
|
const tokens = [];
|
|
17325
18604
|
let i = 0;
|
|
17326
18605
|
while (i < latex.length) {
|
|
@@ -18675,7 +19954,7 @@ function convertLatexToOmml(latex) {
|
|
|
18675
19954
|
if (trimmed.length === 0) {
|
|
18676
19955
|
return {};
|
|
18677
19956
|
}
|
|
18678
|
-
const tokens =
|
|
19957
|
+
const tokens = tokenize2(trimmed);
|
|
18679
19958
|
const parser = new LatexParser(tokens);
|
|
18680
19959
|
const nodes = parser.parseAll();
|
|
18681
19960
|
if (nodes.length === 0) {
|
|
@@ -19268,11 +20547,13 @@ function parseOmml(xml) {
|
|
|
19268
20547
|
return ommlFromElement(parseXml(xml, { label: "OMML" }).documentElement);
|
|
19269
20548
|
}
|
|
19270
20549
|
|
|
20550
|
+
exports.chart = chart_exports;
|
|
19271
20551
|
exports.color = color_exports;
|
|
19272
20552
|
exports.diagram = diagram_exports;
|
|
19273
20553
|
exports.digest = digest_exports;
|
|
19274
20554
|
exports.geometry = geometry_exports;
|
|
19275
20555
|
exports.math = math_exports;
|
|
19276
20556
|
exports.opc = opc_exports;
|
|
20557
|
+
exports.text = text_exports;
|
|
19277
20558
|
exports.units = units_exports;
|
|
19278
20559
|
exports.xml = xml_exports;
|