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