@beyondwork/docx-react-component 1.0.29 → 1.0.31
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/package.json +65 -96
- package/src/README.md +85 -0
- package/src/api/README.md +26 -0
- package/src/api/public-types.ts +1952 -0
- package/src/api/session-state.ts +62 -0
- package/src/compare/diff-engine.ts +623 -0
- package/src/compare/export-redlines.ts +280 -0
- package/src/compare/index.ts +25 -0
- package/src/compare/snapshot.ts +97 -0
- package/src/component-inventory.md +99 -0
- package/src/core/README.md +10 -0
- package/src/core/commands/README.md +3 -0
- package/{dist/chunk-TJBP2K4T.js → src/core/commands/formatting-commands.ts} +536 -196
- package/src/core/commands/image-commands.ts +373 -0
- package/src/core/commands/index.ts +1879 -0
- package/src/core/commands/list-commands.ts +565 -0
- package/src/core/commands/paragraph-layout-commands.ts +339 -0
- package/src/core/commands/review-commands.ts +108 -0
- package/{dist/core/commands/section-layout-commands.cjs → src/core/commands/section-layout-commands.ts} +340 -137
- package/src/core/commands/structural-helpers.ts +309 -0
- package/{dist/core/commands/style-commands.cjs → src/core/commands/style-commands.ts} +113 -65
- package/src/core/commands/table-structure-commands.ts +854 -0
- package/{dist/chunk-UZXBISGO.js → src/core/commands/text-commands.ts} +142 -86
- package/src/core/schema/README.md +3 -0
- package/src/core/schema/text-schema.ts +516 -0
- package/src/core/search/search-text.ts +357 -0
- package/src/core/selection/README.md +3 -0
- package/src/core/selection/mapping.ts +289 -0
- package/src/core/selection/review-anchors.ts +183 -0
- package/src/core/state/README.md +3 -0
- package/src/core/state/editor-state.ts +892 -0
- package/src/core/state/text-transaction.ts +869 -0
- package/src/formats/xlsx/io/parse-shared-strings.ts +41 -0
- package/src/formats/xlsx/io/parse-sheet.ts +459 -0
- package/src/formats/xlsx/io/parse-styles.ts +59 -0
- package/src/formats/xlsx/io/parse-workbook.ts +75 -0
- package/src/formats/xlsx/io/serialize-shared-strings.ts +72 -0
- package/src/formats/xlsx/io/serialize-sheet.ts +333 -0
- package/src/formats/xlsx/io/serialize-styles.ts +98 -0
- package/src/formats/xlsx/io/serialize-workbook.ts +429 -0
- package/src/formats/xlsx/io/xlsx-session.ts +314 -0
- package/src/formats/xlsx/model/cell.ts +189 -0
- package/src/formats/xlsx/model/sheet.ts +326 -0
- package/src/formats/xlsx/model/styles.ts +118 -0
- package/src/formats/xlsx/model/workbook.ts +453 -0
- package/src/formats/xlsx/runtime/cell-commands.ts +567 -0
- package/src/formats/xlsx/runtime/sheet-commands.ts +206 -0
- package/src/formats/xlsx/runtime/workbook-runtime.ts +177 -0
- package/src/formats/xlsx/runtime/workbook-transaction.ts +822 -0
- package/src/index.ts +142 -0
- package/src/io/README.md +10 -0
- package/src/io/docx-session.ts +3175 -0
- package/src/io/export/README.md +3 -0
- package/src/io/export/export-session.ts +220 -0
- package/src/io/export/minimal-docx.ts +115 -0
- package/src/io/export/reattach-preserved-parts.ts +54 -0
- package/src/io/export/serialize-comments.ts +947 -0
- package/src/io/export/serialize-footnotes.ts +394 -0
- package/src/io/export/serialize-headers-footers.ts +368 -0
- package/src/io/export/serialize-main-document.ts +1342 -0
- package/src/io/export/serialize-numbering.ts +218 -0
- package/src/io/export/serialize-revisions.ts +389 -0
- package/src/io/export/serialize-runtime-revisions.ts +463 -0
- package/src/io/export/serialize-tables.ts +174 -0
- package/src/io/export/split-review-boundaries.ts +356 -0
- package/src/io/export/split-story-blocks-for-runtime-revisions.ts +252 -0
- package/src/io/export/table-properties-xml.ts +318 -0
- package/src/io/normalize/README.md +3 -0
- package/src/io/normalize/normalize-text.ts +670 -0
- package/src/io/ooxml/README.md +3 -0
- package/src/io/ooxml/highlight-colors.ts +39 -0
- package/src/io/ooxml/numbering-sentinels.ts +44 -0
- package/src/io/ooxml/parse-comments.ts +852 -0
- package/src/io/ooxml/parse-complex-content.ts +287 -0
- package/src/io/ooxml/parse-fields.ts +834 -0
- package/src/io/ooxml/parse-footnotes.ts +952 -0
- package/src/io/ooxml/parse-headers-footers.ts +1212 -0
- package/src/io/ooxml/parse-inline-media.ts +461 -0
- package/src/io/ooxml/parse-main-document.ts +2947 -0
- package/src/io/ooxml/parse-numbering.ts +747 -0
- package/src/io/ooxml/parse-revisions.ts +1045 -0
- package/src/io/ooxml/parse-settings.ts +184 -0
- package/src/io/ooxml/parse-shapes.ts +296 -0
- package/src/io/ooxml/parse-styles.ts +639 -0
- package/src/io/ooxml/parse-tables.ts +627 -0
- package/src/io/ooxml/parse-theme.ts +346 -0
- package/src/io/ooxml/part-manifest.ts +136 -0
- package/src/io/ooxml/revision-boundaries.ts +475 -0
- package/src/io/ooxml/workflow-payload.ts +544 -0
- package/src/io/opc/README.md +3 -0
- package/src/io/opc/corrupt-package.ts +166 -0
- package/src/io/opc/docx-package.ts +74 -0
- package/src/io/opc/package-reader.ts +325 -0
- package/src/io/opc/package-writer.ts +273 -0
- package/src/io/source-package-provenance.ts +241 -0
- package/{dist/chunk-RMH72RZI.js → src/legal/bookmarks.ts} +130 -44
- package/src/legal/cross-references.ts +414 -0
- package/src/legal/defined-terms.ts +203 -0
- package/src/legal/index.ts +32 -0
- package/src/legal/signature-blocks.ts +259 -0
- package/src/model/README.md +3 -0
- package/src/model/canonical-document.ts +2722 -0
- package/src/model/cds-1.0.0.ts +212 -0
- package/src/model/snapshot.ts +760 -0
- package/src/preservation/README.md +3 -0
- package/src/preservation/markup-compatibility.ts +48 -0
- package/src/preservation/opaque-fragment-store.ts +89 -0
- package/src/preservation/opaque-region.ts +233 -0
- package/src/preservation/package-preservation.ts +113 -0
- package/src/preservation/preserved-part-manifest.ts +56 -0
- package/src/preservation/relationship-retention.ts +57 -0
- package/src/preservation/store.ts +255 -0
- package/src/review/README.md +16 -0
- package/src/review/store/README.md +3 -0
- package/src/review/store/comment-anchors.ts +70 -0
- package/src/review/store/comment-remapping.ts +154 -0
- package/src/review/store/comment-store.ts +349 -0
- package/src/review/store/comment-thread.ts +109 -0
- package/src/review/store/revision-actions.ts +423 -0
- package/src/review/store/revision-store.ts +323 -0
- package/src/review/store/revision-types.ts +182 -0
- package/src/review/store/runtime-comment-store.ts +43 -0
- package/src/runtime/README.md +3 -0
- package/src/runtime/ai-action-policy.ts +764 -0
- package/src/runtime/context-analytics.ts +824 -0
- package/src/runtime/document-layout.ts +332 -0
- package/src/runtime/document-locations.ts +521 -0
- package/src/runtime/document-navigation.ts +616 -0
- package/src/runtime/document-outline.ts +440 -0
- package/src/runtime/document-runtime.ts +4055 -0
- package/src/runtime/document-search.ts +145 -0
- package/src/runtime/event-refresh-hints.ts +137 -0
- package/src/runtime/numbering-prefix.ts +244 -0
- package/src/runtime/page-layout-estimation.ts +305 -0
- package/src/runtime/read-only-diagnostics-runtime.ts +241 -0
- package/src/runtime/resolved-numbering-geometry.ts +293 -0
- package/src/runtime/review-runtime.ts +44 -0
- package/src/runtime/revision-runtime.ts +107 -0
- package/src/runtime/session-capabilities.ts +192 -0
- package/src/runtime/story-context.ts +164 -0
- package/src/runtime/story-targeting.ts +162 -0
- package/src/runtime/suggestions-snapshot.ts +137 -0
- package/src/runtime/surface-projection.ts +1553 -0
- package/src/runtime/table-commands.ts +173 -0
- package/src/runtime/table-schema.ts +309 -0
- package/src/runtime/table-style-resolver.ts +409 -0
- package/src/runtime/view-state.ts +493 -0
- package/src/runtime/virtualized-rendering.ts +258 -0
- package/src/runtime/workflow-markup.ts +393 -0
- package/src/ui/README.md +30 -0
- package/src/ui/WordReviewEditor.tsx +5268 -0
- package/src/ui/browser-export.ts +52 -0
- package/src/ui/comments/README.md +3 -0
- package/src/ui/compatibility/README.md +3 -0
- package/src/ui/editor-command-bag.ts +127 -0
- package/src/ui/editor-runtime-boundary.ts +1558 -0
- package/src/ui/editor-shell-view.tsx +144 -0
- package/src/ui/editor-surface/README.md +3 -0
- package/src/ui/editor-surface-controller.tsx +66 -0
- package/src/ui/headless/comment-decoration-model.ts +124 -0
- package/src/ui/headless/preserve-editor-selection.ts +5 -0
- package/src/ui/headless/revision-decoration-model.ts +128 -0
- package/src/ui/headless/selection-helpers.ts +54 -0
- package/src/ui/headless/selection-tool-context.ts +19 -0
- package/src/ui/headless/selection-tool-resolver.ts +752 -0
- package/src/ui/headless/selection-tool-types.ts +129 -0
- package/src/ui/headless/selection-toolbar-model.ts +11 -0
- package/src/ui/headless/use-editor-keyboard.ts +103 -0
- package/src/ui/review/README.md +3 -0
- package/src/ui/runtime-shortcut-dispatch.ts +365 -0
- package/src/ui/runtime-snapshot-selectors.ts +197 -0
- package/src/ui/shared/revision-filters.ts +31 -0
- package/src/ui/status/README.md +3 -0
- package/src/ui/theme/README.md +3 -0
- package/src/ui/toolbar/README.md +3 -0
- package/src/ui/workflow-surface-blocked-rails.ts +94 -0
- package/src/ui-tailwind/chrome/chrome-preset-model.ts +107 -0
- package/src/ui-tailwind/chrome/chrome-preset-toolbar.tsx +15 -0
- package/src/ui-tailwind/chrome/responsive-chrome.ts +46 -0
- package/src/ui-tailwind/chrome/review-queue-bar.tsx +97 -0
- package/src/ui-tailwind/chrome/tw-alert-banner.tsx +64 -0
- package/src/ui-tailwind/chrome/tw-context-analytics-summary.tsx +122 -0
- package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +121 -0
- package/src/ui-tailwind/chrome/tw-layout-panel.tsx +114 -0
- package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +30 -0
- package/src/ui-tailwind/chrome/tw-page-ruler.tsx +365 -0
- package/src/ui-tailwind/chrome/tw-selection-tool-blocked.tsx +23 -0
- package/src/ui-tailwind/chrome/tw-selection-tool-comment.tsx +35 -0
- package/src/ui-tailwind/chrome/tw-selection-tool-formatting.tsx +37 -0
- package/src/ui-tailwind/chrome/tw-selection-tool-host.tsx +303 -0
- package/src/ui-tailwind/chrome/tw-selection-tool-structure.tsx +116 -0
- package/src/ui-tailwind/chrome/tw-selection-tool-suggestion.tsx +29 -0
- package/src/ui-tailwind/chrome/tw-selection-tool-workflow.tsx +27 -0
- package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +186 -0
- package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +139 -0
- package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +250 -0
- package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +58 -0
- package/src/ui-tailwind/chrome/use-before-unload.ts +20 -0
- package/src/ui-tailwind/editor-surface/perf-probe.ts +179 -0
- package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +189 -0
- package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +31 -0
- package/src/ui-tailwind/editor-surface/pm-decorations.ts +411 -0
- package/src/ui-tailwind/editor-surface/pm-position-map.ts +123 -0
- package/src/ui-tailwind/editor-surface/pm-schema.ts +927 -0
- package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +567 -0
- package/src/ui-tailwind/editor-surface/search-plugin.ts +168 -0
- package/src/ui-tailwind/editor-surface/surface-build-keys.ts +63 -0
- package/src/ui-tailwind/editor-surface/tw-caret.tsx +12 -0
- package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +150 -0
- package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +129 -0
- package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +58 -0
- package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +151 -0
- package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +1047 -0
- package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +111 -0
- package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +503 -0
- package/src/ui-tailwind/index.ts +62 -0
- package/src/ui-tailwind/page-chrome-model.ts +27 -0
- package/src/ui-tailwind/review/tw-comment-sidebar.tsx +406 -0
- package/src/ui-tailwind/review/tw-health-panel.tsx +149 -0
- package/src/ui-tailwind/review/tw-review-rail.tsx +130 -0
- package/src/ui-tailwind/review/tw-revision-sidebar.tsx +164 -0
- package/src/ui-tailwind/status/tw-status-bar.tsx +65 -0
- package/{dist → src}/ui-tailwind/theme/editor-theme.css +58 -40
- package/src/ui-tailwind/toolbar/toolbar-layout.ts +47 -0
- package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +52 -0
- package/src/ui-tailwind/toolbar/tw-toolbar.tsx +1478 -0
- package/src/ui-tailwind/tw-review-workspace.tsx +1587 -0
- package/src/validation/README.md +3 -0
- package/src/validation/compatibility-engine.ts +878 -0
- package/src/validation/compatibility-report.ts +161 -0
- package/src/validation/diagnostics.ts +204 -0
- package/src/validation/docx-comment-proof.ts +720 -0
- package/src/validation/import-diagnostics.ts +128 -0
- package/src/validation/low-priority-word-surfaces.ts +373 -0
- package/dist/canonical-document-BLEbzL2J.d.cts +0 -844
- package/dist/canonical-document-BLEbzL2J.d.ts +0 -844
- package/dist/chunk-2FJS5GZM.js +0 -763
- package/dist/chunk-2FJS5GZM.js.map +0 -1
- package/dist/chunk-2OQBZS3F.js +0 -446
- package/dist/chunk-2OQBZS3F.js.map +0 -1
- package/dist/chunk-2S7W4KFO.js +0 -127
- package/dist/chunk-2S7W4KFO.js.map +0 -1
- package/dist/chunk-2TG72QSW.js +0 -3874
- package/dist/chunk-2TG72QSW.js.map +0 -1
- package/dist/chunk-36QNIZBO.js +0 -532
- package/dist/chunk-36QNIZBO.js.map +0 -1
- package/dist/chunk-4AQOYAW4.js +0 -3069
- package/dist/chunk-4AQOYAW4.js.map +0 -1
- package/dist/chunk-4D5EWJ3P.js +0 -77
- package/dist/chunk-4D5EWJ3P.js.map +0 -1
- package/dist/chunk-5FN54NDH.js +0 -2257
- package/dist/chunk-5FN54NDH.js.map +0 -1
- package/dist/chunk-BOYGQYRQ.js +0 -7306
- package/dist/chunk-BOYGQYRQ.js.map +0 -1
- package/dist/chunk-CN3XMECL.js +0 -212
- package/dist/chunk-CN3XMECL.js.map +0 -1
- package/dist/chunk-EBI3BX6U.js +0 -164
- package/dist/chunk-EBI3BX6U.js.map +0 -1
- package/dist/chunk-EILUG3VB.js +0 -1275
- package/dist/chunk-EILUG3VB.js.map +0 -1
- package/dist/chunk-FUDY333O.js +0 -70
- package/dist/chunk-FUDY333O.js.map +0 -1
- package/dist/chunk-GBVOWFIK.js +0 -1237
- package/dist/chunk-GBVOWFIK.js.map +0 -1
- package/dist/chunk-H4TQ3H3Y.js +0 -262
- package/dist/chunk-H4TQ3H3Y.js.map +0 -1
- package/dist/chunk-JGB3IXZO.js +0 -189
- package/dist/chunk-JGB3IXZO.js.map +0 -1
- package/dist/chunk-KD2QRQPY.js +0 -4342
- package/dist/chunk-KD2QRQPY.js.map +0 -1
- package/dist/chunk-KLMXQVYK.js +0 -369
- package/dist/chunk-KLMXQVYK.js.map +0 -1
- package/dist/chunk-KZUG5KFQ.js +0 -214
- package/dist/chunk-KZUG5KFQ.js.map +0 -1
- package/dist/chunk-QDAQ4CJU.js +0 -345
- package/dist/chunk-QDAQ4CJU.js.map +0 -1
- package/dist/chunk-RMH72RZI.js.map +0 -1
- package/dist/chunk-SWKWQZXM.js +0 -117
- package/dist/chunk-SWKWQZXM.js.map +0 -1
- package/dist/chunk-TJBP2K4T.js.map +0 -1
- package/dist/chunk-TLCEAQDQ.js +0 -542
- package/dist/chunk-TLCEAQDQ.js.map +0 -1
- package/dist/chunk-UZXBISGO.js.map +0 -1
- package/dist/chunk-WGBAKP3Q.js +0 -3220
- package/dist/chunk-WGBAKP3Q.js.map +0 -1
- package/dist/compare/index.cjs +0 -5475
- package/dist/compare/index.cjs.map +0 -1
- package/dist/compare/index.d.cts +0 -114
- package/dist/compare/index.d.ts +0 -114
- package/dist/compare/index.js +0 -731
- package/dist/compare/index.js.map +0 -1
- package/dist/core/commands/formatting-commands.cjs +0 -828
- package/dist/core/commands/formatting-commands.cjs.map +0 -1
- package/dist/core/commands/formatting-commands.d.cts +0 -63
- package/dist/core/commands/formatting-commands.d.ts +0 -63
- package/dist/core/commands/formatting-commands.js +0 -37
- package/dist/core/commands/formatting-commands.js.map +0 -1
- package/dist/core/commands/image-commands.cjs +0 -2023
- package/dist/core/commands/image-commands.cjs.map +0 -1
- package/dist/core/commands/image-commands.d.cts +0 -58
- package/dist/core/commands/image-commands.d.ts +0 -58
- package/dist/core/commands/image-commands.js +0 -18
- package/dist/core/commands/image-commands.js.map +0 -1
- package/dist/core/commands/section-layout-commands.cjs.map +0 -1
- package/dist/core/commands/section-layout-commands.d.cts +0 -62
- package/dist/core/commands/section-layout-commands.d.ts +0 -62
- package/dist/core/commands/section-layout-commands.js +0 -21
- package/dist/core/commands/section-layout-commands.js.map +0 -1
- package/dist/core/commands/style-commands.cjs.map +0 -1
- package/dist/core/commands/style-commands.d.cts +0 -13
- package/dist/core/commands/style-commands.d.ts +0 -13
- package/dist/core/commands/style-commands.js +0 -9
- package/dist/core/commands/style-commands.js.map +0 -1
- package/dist/core/commands/table-structure-commands.cjs +0 -1883
- package/dist/core/commands/table-structure-commands.cjs.map +0 -1
- package/dist/core/commands/table-structure-commands.d.cts +0 -59
- package/dist/core/commands/table-structure-commands.d.ts +0 -59
- package/dist/core/commands/table-structure-commands.js +0 -12
- package/dist/core/commands/table-structure-commands.js.map +0 -1
- package/dist/core/commands/text-commands.cjs +0 -2391
- package/dist/core/commands/text-commands.cjs.map +0 -1
- package/dist/core/commands/text-commands.d.cts +0 -24
- package/dist/core/commands/text-commands.d.ts +0 -24
- package/dist/core/commands/text-commands.js +0 -28
- package/dist/core/commands/text-commands.js.map +0 -1
- package/dist/core/selection/mapping.cjs +0 -200
- package/dist/core/selection/mapping.cjs.map +0 -1
- package/dist/core/selection/mapping.d.cts +0 -2
- package/dist/core/selection/mapping.d.ts +0 -2
- package/dist/core/selection/mapping.js +0 -31
- package/dist/core/selection/mapping.js.map +0 -1
- package/dist/core/state/editor-state.cjs +0 -2278
- package/dist/core/state/editor-state.cjs.map +0 -1
- package/dist/core/state/editor-state.d.cts +0 -2
- package/dist/core/state/editor-state.d.ts +0 -2
- package/dist/core/state/editor-state.js +0 -26
- package/dist/core/state/editor-state.js.map +0 -1
- package/dist/index.cjs +0 -38553
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -15
- package/dist/index.d.ts +0 -15
- package/dist/index.js +0 -7856
- package/dist/index.js.map +0 -1
- package/dist/io/docx-session.cjs +0 -16236
- package/dist/io/docx-session.cjs.map +0 -1
- package/dist/io/docx-session.d.cts +0 -21
- package/dist/io/docx-session.d.ts +0 -21
- package/dist/io/docx-session.js +0 -18
- package/dist/io/docx-session.js.map +0 -1
- package/dist/legal/index.cjs +0 -3900
- package/dist/legal/index.cjs.map +0 -1
- package/dist/legal/index.d.cts +0 -86
- package/dist/legal/index.d.ts +0 -86
- package/dist/legal/index.js +0 -616
- package/dist/legal/index.js.map +0 -1
- package/dist/public-types-7ZL_94cz.d.ts +0 -1573
- package/dist/public-types-CeMaDueh.d.cts +0 -1573
- package/dist/public-types.cjs +0 -19
- package/dist/public-types.cjs.map +0 -1
- package/dist/public-types.d.cts +0 -2
- package/dist/public-types.d.ts +0 -2
- package/dist/public-types.js +0 -1
- package/dist/public-types.js.map +0 -1
- package/dist/runtime/document-runtime.cjs +0 -11140
- package/dist/runtime/document-runtime.cjs.map +0 -1
- package/dist/runtime/document-runtime.d.cts +0 -231
- package/dist/runtime/document-runtime.d.ts +0 -231
- package/dist/runtime/document-runtime.js +0 -21
- package/dist/runtime/document-runtime.js.map +0 -1
- package/dist/structural-helpers-CilgOVhh.d.cts +0 -10
- package/dist/structural-helpers-q0Gd-eBN.d.ts +0 -10
- package/dist/ui-tailwind/editor-surface/search-plugin.cjs +0 -313
- package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +0 -1
- package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +0 -67
- package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +0 -67
- package/dist/ui-tailwind/editor-surface/search-plugin.js +0 -23
- package/dist/ui-tailwind/editor-surface/search-plugin.js.map +0 -1
- package/dist/ui-tailwind/index.cjs +0 -4833
- package/dist/ui-tailwind/index.cjs.map +0 -1
- package/dist/ui-tailwind/index.d.cts +0 -617
- package/dist/ui-tailwind/index.d.ts +0 -617
- package/dist/ui-tailwind/index.js +0 -575
- package/dist/ui-tailwind/index.js.map +0 -1
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CONTENT_TYPES_PATH,
|
|
3
|
+
OpcCompressionMethod,
|
|
4
|
+
OpcPackageManifest,
|
|
5
|
+
OpcPackagePart,
|
|
6
|
+
OpcRelationship,
|
|
7
|
+
PACKAGE_RELATIONSHIPS_PATH,
|
|
8
|
+
comparePartPaths,
|
|
9
|
+
getExtension,
|
|
10
|
+
getRelationshipsPartPath,
|
|
11
|
+
normalizePartPath,
|
|
12
|
+
} from "../ooxml/part-manifest.ts";
|
|
13
|
+
import type { OpcPackage } from "./package-reader.ts";
|
|
14
|
+
|
|
15
|
+
interface ZipEntryPayload {
|
|
16
|
+
path: string;
|
|
17
|
+
compression: OpcCompressionMethod;
|
|
18
|
+
uncompressedBytes: Uint8Array;
|
|
19
|
+
compressedBytes: Uint8Array;
|
|
20
|
+
crc32: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function writeOpcPackage(input: OpcPackage | { manifest: OpcPackageManifest; parts: Map<string, OpcPackagePart> }): Uint8Array {
|
|
24
|
+
const entries = collectZipEntries(input.manifest, input.parts);
|
|
25
|
+
return buildZipArchive(entries);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function collectZipEntries(
|
|
29
|
+
manifest: OpcPackageManifest,
|
|
30
|
+
parts: Map<string, OpcPackagePart>,
|
|
31
|
+
): ZipEntryPayload[] {
|
|
32
|
+
const entries: ZipEntryPayload[] = [];
|
|
33
|
+
const contentParts = [...parts.values()]
|
|
34
|
+
.filter((part) => part.surfaceKind === "content")
|
|
35
|
+
.sort((left, right) => comparePartPaths(left.path, right.path));
|
|
36
|
+
|
|
37
|
+
entries.push(createZipPayload(CONTENT_TYPES_PATH, "deflate", encodeXml(buildContentTypesXml(manifest, contentParts))));
|
|
38
|
+
entries.push(
|
|
39
|
+
createZipPayload(
|
|
40
|
+
PACKAGE_RELATIONSHIPS_PATH,
|
|
41
|
+
"deflate",
|
|
42
|
+
encodeXml(buildRelationshipsXml(manifest.packageRelationships)),
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
for (const part of contentParts) {
|
|
47
|
+
entries.push(createZipPayload(part.path, part.compression, part.bytes));
|
|
48
|
+
|
|
49
|
+
if (part.relationships.length > 0) {
|
|
50
|
+
entries.push(
|
|
51
|
+
createZipPayload(
|
|
52
|
+
getRelationshipsPartPath(part.path),
|
|
53
|
+
"deflate",
|
|
54
|
+
encodeXml(buildRelationshipsXml(part.relationships)),
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return entries.sort((left, right) => comparePartPaths(left.path, right.path));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function buildContentTypesXml(
|
|
64
|
+
manifest: OpcPackageManifest,
|
|
65
|
+
parts: OpcPackagePart[],
|
|
66
|
+
): string {
|
|
67
|
+
const defaults: Record<string, string> = {
|
|
68
|
+
...manifest.contentTypes.defaults,
|
|
69
|
+
rels: manifest.contentTypes.defaults.rels ?? "application/vnd.openxmlformats-package.relationships+xml",
|
|
70
|
+
xml: manifest.contentTypes.defaults.xml ?? "application/xml",
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const overrides = { ...manifest.contentTypes.overrides };
|
|
74
|
+
|
|
75
|
+
for (const part of parts) {
|
|
76
|
+
if (!part.contentType) {
|
|
77
|
+
throw new Error(`Cannot write OPC package: missing content type for ${part.path}.`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const extension = getExtension(part.path);
|
|
81
|
+
if (!extension) {
|
|
82
|
+
overrides[part.path] = part.contentType;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const defaultContentType = defaults[extension];
|
|
87
|
+
if (!defaultContentType) {
|
|
88
|
+
defaults[extension] = part.contentType;
|
|
89
|
+
delete overrides[part.path];
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (defaultContentType === part.contentType) {
|
|
94
|
+
delete overrides[part.path];
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
overrides[part.path] = part.contentType;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const defaultEntries = Object.entries(defaults).sort(([left], [right]) => left.localeCompare(right));
|
|
102
|
+
const overrideEntries = Object.entries(overrides).sort(([left], [right]) => comparePartPaths(left, right));
|
|
103
|
+
|
|
104
|
+
const defaultXml = defaultEntries
|
|
105
|
+
.map(([extension, contentType]) => ` <Default Extension="${escapeXml(extension)}" ContentType="${escapeXml(contentType)}"/>`)
|
|
106
|
+
.join("\n");
|
|
107
|
+
const overrideXml = overrideEntries
|
|
108
|
+
.map(([partName, contentType]) => ` <Override PartName="${escapeXml(partName)}" ContentType="${escapeXml(contentType)}"/>`)
|
|
109
|
+
.join("\n");
|
|
110
|
+
const body = [defaultXml, overrideXml].filter((value) => value.length > 0).join("\n");
|
|
111
|
+
|
|
112
|
+
return [
|
|
113
|
+
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>`,
|
|
114
|
+
`<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">`,
|
|
115
|
+
body,
|
|
116
|
+
`</Types>`,
|
|
117
|
+
].join("\n");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function buildRelationshipsXml(relationships: OpcRelationship[]): string {
|
|
121
|
+
const relationshipXml = [...relationships]
|
|
122
|
+
.sort((left, right) => left.id.localeCompare(right.id))
|
|
123
|
+
.map((relationship) => {
|
|
124
|
+
const targetMode =
|
|
125
|
+
relationship.targetMode === "external"
|
|
126
|
+
? ` TargetMode="External"`
|
|
127
|
+
: "";
|
|
128
|
+
return ` <Relationship Id="${escapeXml(relationship.id)}" Type="${escapeXml(relationship.type)}" Target="${escapeXml(relationship.target)}"${targetMode}/>`;
|
|
129
|
+
})
|
|
130
|
+
.join("\n");
|
|
131
|
+
|
|
132
|
+
return [
|
|
133
|
+
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>`,
|
|
134
|
+
`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">`,
|
|
135
|
+
relationshipXml,
|
|
136
|
+
`</Relationships>`,
|
|
137
|
+
].join("\n");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function createZipPayload(
|
|
141
|
+
path: string,
|
|
142
|
+
compression: OpcCompressionMethod,
|
|
143
|
+
bytes: Uint8Array,
|
|
144
|
+
): ZipEntryPayload {
|
|
145
|
+
const normalizedPath = normalizePartPath(path).slice(1);
|
|
146
|
+
const uncompressedBytes = new Uint8Array(bytes);
|
|
147
|
+
// Keep export browser-safe by storing entries without Node-only compression primitives.
|
|
148
|
+
const compressedBytes = uncompressedBytes;
|
|
149
|
+
const effectiveCompression: OpcCompressionMethod = "store";
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
path: normalizedPath,
|
|
153
|
+
compression: effectiveCompression,
|
|
154
|
+
uncompressedBytes,
|
|
155
|
+
compressedBytes,
|
|
156
|
+
crc32: calculateCrc32(uncompressedBytes),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function buildZipArchive(entries: ZipEntryPayload[]): Uint8Array {
|
|
161
|
+
const localChunks: Uint8Array[] = [];
|
|
162
|
+
const centralChunks: Uint8Array[] = [];
|
|
163
|
+
let localOffset = 0;
|
|
164
|
+
|
|
165
|
+
for (const entry of entries) {
|
|
166
|
+
const fileName = encodeUtf8(entry.path);
|
|
167
|
+
const localHeader = createByteBuffer(30 + fileName.length);
|
|
168
|
+
const localHeaderView = new DataView(localHeader.buffer);
|
|
169
|
+
localHeaderView.setUint32(0, 0x04034b50, true);
|
|
170
|
+
localHeaderView.setUint16(4, 20, true);
|
|
171
|
+
localHeaderView.setUint16(6, 0, true);
|
|
172
|
+
localHeaderView.setUint16(8, entry.compression === "store" ? 0 : 8, true);
|
|
173
|
+
localHeaderView.setUint16(10, 0, true);
|
|
174
|
+
localHeaderView.setUint16(12, 0, true);
|
|
175
|
+
localHeaderView.setUint32(14, entry.crc32 >>> 0, true);
|
|
176
|
+
localHeaderView.setUint32(18, entry.compressedBytes.byteLength, true);
|
|
177
|
+
localHeaderView.setUint32(22, entry.uncompressedBytes.byteLength, true);
|
|
178
|
+
localHeaderView.setUint16(26, fileName.length, true);
|
|
179
|
+
localHeaderView.setUint16(28, 0, true);
|
|
180
|
+
localHeader.set(fileName, 30);
|
|
181
|
+
|
|
182
|
+
localChunks.push(localHeader, entry.compressedBytes);
|
|
183
|
+
|
|
184
|
+
const centralHeader = createByteBuffer(46 + fileName.length);
|
|
185
|
+
const centralHeaderView = new DataView(centralHeader.buffer);
|
|
186
|
+
centralHeaderView.setUint32(0, 0x02014b50, true);
|
|
187
|
+
centralHeaderView.setUint16(4, 20, true);
|
|
188
|
+
centralHeaderView.setUint16(6, 20, true);
|
|
189
|
+
centralHeaderView.setUint16(8, 0, true);
|
|
190
|
+
centralHeaderView.setUint16(10, entry.compression === "store" ? 0 : 8, true);
|
|
191
|
+
centralHeaderView.setUint16(12, 0, true);
|
|
192
|
+
centralHeaderView.setUint16(14, 0, true);
|
|
193
|
+
centralHeaderView.setUint32(16, entry.crc32 >>> 0, true);
|
|
194
|
+
centralHeaderView.setUint32(20, entry.compressedBytes.byteLength, true);
|
|
195
|
+
centralHeaderView.setUint32(24, entry.uncompressedBytes.byteLength, true);
|
|
196
|
+
centralHeaderView.setUint16(28, fileName.length, true);
|
|
197
|
+
centralHeaderView.setUint16(30, 0, true);
|
|
198
|
+
centralHeaderView.setUint16(32, 0, true);
|
|
199
|
+
centralHeaderView.setUint16(34, 0, true);
|
|
200
|
+
centralHeaderView.setUint16(36, 0, true);
|
|
201
|
+
centralHeaderView.setUint32(38, 0, true);
|
|
202
|
+
centralHeaderView.setUint32(42, localOffset, true);
|
|
203
|
+
centralHeader.set(fileName, 46);
|
|
204
|
+
centralChunks.push(centralHeader);
|
|
205
|
+
|
|
206
|
+
localOffset += localHeader.byteLength + entry.compressedBytes.byteLength;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const centralDirectoryOffset = localOffset;
|
|
210
|
+
const centralDirectory = concatByteArrays(centralChunks);
|
|
211
|
+
const endOfCentralDirectory = createByteBuffer(22);
|
|
212
|
+
const endOfCentralDirectoryView = new DataView(endOfCentralDirectory.buffer);
|
|
213
|
+
endOfCentralDirectoryView.setUint32(0, 0x06054b50, true);
|
|
214
|
+
endOfCentralDirectoryView.setUint16(4, 0, true);
|
|
215
|
+
endOfCentralDirectoryView.setUint16(6, 0, true);
|
|
216
|
+
endOfCentralDirectoryView.setUint16(8, entries.length, true);
|
|
217
|
+
endOfCentralDirectoryView.setUint16(10, entries.length, true);
|
|
218
|
+
endOfCentralDirectoryView.setUint32(12, centralDirectory.byteLength, true);
|
|
219
|
+
endOfCentralDirectoryView.setUint32(16, centralDirectoryOffset, true);
|
|
220
|
+
endOfCentralDirectoryView.setUint16(20, 0, true);
|
|
221
|
+
|
|
222
|
+
return concatByteArrays([...localChunks, centralDirectory, endOfCentralDirectory]);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function encodeXml(xml: string): Uint8Array {
|
|
226
|
+
return encodeUtf8(xml);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function escapeXml(value: string): string {
|
|
230
|
+
return value
|
|
231
|
+
.replace(/&/g, "&")
|
|
232
|
+
.replace(/"/g, """)
|
|
233
|
+
.replace(/</g, "<")
|
|
234
|
+
.replace(/>/g, ">")
|
|
235
|
+
.replace(/'/g, "'");
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function calculateCrc32(bytes: Uint8Array): number {
|
|
239
|
+
let crc = 0xffffffff;
|
|
240
|
+
|
|
241
|
+
for (const byte of bytes) {
|
|
242
|
+
crc ^= byte;
|
|
243
|
+
for (let bit = 0; bit < 8; bit += 1) {
|
|
244
|
+
const mask = -(crc & 1);
|
|
245
|
+
crc = (crc >>> 1) ^ (0xedb88320 & mask);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function createByteBuffer(size: number): Uint8Array {
|
|
253
|
+
return new Uint8Array(size);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function concatByteArrays(chunks: readonly Uint8Array[]): Uint8Array {
|
|
257
|
+
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.byteLength, 0);
|
|
258
|
+
const combined = new Uint8Array(totalLength);
|
|
259
|
+
let offset = 0;
|
|
260
|
+
|
|
261
|
+
for (const chunk of chunks) {
|
|
262
|
+
combined.set(chunk, offset);
|
|
263
|
+
offset += chunk.byteLength;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return combined;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function encodeUtf8(value: string): Uint8Array {
|
|
270
|
+
return new TextEncoder().encode(value);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export { buildContentTypesXml, buildRelationshipsXml, calculateCrc32 };
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import type { PersistedSourcePackage } from "../model/snapshot.ts";
|
|
2
|
+
import { DOCX_MIME_TYPE } from "./opc/docx-package.ts";
|
|
3
|
+
|
|
4
|
+
const SHA256_INITIAL_STATE = [
|
|
5
|
+
0x6a09e667,
|
|
6
|
+
0xbb67ae85,
|
|
7
|
+
0x3c6ef372,
|
|
8
|
+
0xa54ff53a,
|
|
9
|
+
0x510e527f,
|
|
10
|
+
0x9b05688c,
|
|
11
|
+
0x1f83d9ab,
|
|
12
|
+
0x5be0cd19,
|
|
13
|
+
] as const;
|
|
14
|
+
|
|
15
|
+
const SHA256_CONSTANTS = [
|
|
16
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
|
17
|
+
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
18
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
19
|
+
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
20
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
|
21
|
+
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
22
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
|
23
|
+
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
24
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
25
|
+
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
26
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
|
27
|
+
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
28
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
|
29
|
+
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
30
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
31
|
+
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
32
|
+
] as const;
|
|
33
|
+
|
|
34
|
+
export function createPersistedSourcePackage(
|
|
35
|
+
bytes: Uint8Array | ArrayBuffer,
|
|
36
|
+
sourceLabel?: string,
|
|
37
|
+
): PersistedSourcePackage {
|
|
38
|
+
const normalizedBytes = toUint8Array(bytes);
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
format: "docx",
|
|
42
|
+
storage: "embedded-base64",
|
|
43
|
+
mimeType: DOCX_MIME_TYPE,
|
|
44
|
+
sourceLabel:
|
|
45
|
+
typeof sourceLabel === "string" && sourceLabel.trim().length > 0
|
|
46
|
+
? sourceLabel
|
|
47
|
+
: undefined,
|
|
48
|
+
sha256Hex: sha256Hex(normalizedBytes),
|
|
49
|
+
bytesBase64: encodeBytesBase64(normalizedBytes),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function decodePersistedSourcePackageBytes(
|
|
54
|
+
sourcePackage: PersistedSourcePackage,
|
|
55
|
+
): Uint8Array {
|
|
56
|
+
return decodeBytesBase64(sourcePackage.bytesBase64);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function hasValidPersistedSourcePackageDigest(
|
|
60
|
+
sourcePackage: PersistedSourcePackage,
|
|
61
|
+
bytes: Uint8Array,
|
|
62
|
+
): boolean {
|
|
63
|
+
return sha256Hex(bytes) === sourcePackage.sha256Hex;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function encodeBytesBase64(bytes: Uint8Array): string {
|
|
67
|
+
const bufferConstructor = getBufferConstructor();
|
|
68
|
+
if (bufferConstructor) {
|
|
69
|
+
return bufferConstructor.from(bytes).toString("base64");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let binary = "";
|
|
73
|
+
for (let offset = 0; offset < bytes.byteLength; offset += 0x8000) {
|
|
74
|
+
const chunk = bytes.subarray(offset, offset + 0x8000);
|
|
75
|
+
for (let index = 0; index < chunk.length; index += 1) {
|
|
76
|
+
binary += String.fromCharCode(chunk[index] ?? 0);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (typeof btoa !== "function") {
|
|
81
|
+
throw new Error("Base64 encoding is unavailable in this runtime.");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return btoa(binary);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function decodeBytesBase64(value: string): Uint8Array {
|
|
88
|
+
const bufferConstructor = getBufferConstructor();
|
|
89
|
+
if (bufferConstructor) {
|
|
90
|
+
return new Uint8Array(bufferConstructor.from(value, "base64"));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (typeof atob !== "function") {
|
|
94
|
+
throw new Error("Base64 decoding is unavailable in this runtime.");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const binary = atob(value);
|
|
98
|
+
const bytes = new Uint8Array(binary.length);
|
|
99
|
+
for (let index = 0; index < binary.length; index += 1) {
|
|
100
|
+
bytes[index] = binary.charCodeAt(index);
|
|
101
|
+
}
|
|
102
|
+
return bytes;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function sha256Hex(bytes: Uint8Array): string {
|
|
106
|
+
const padded = padSha256Message(bytes);
|
|
107
|
+
const state = Array.from(SHA256_INITIAL_STATE, (value) => value >>> 0);
|
|
108
|
+
const schedule = new Uint32Array(64);
|
|
109
|
+
|
|
110
|
+
for (let chunkOffset = 0; chunkOffset < padded.byteLength; chunkOffset += 64) {
|
|
111
|
+
for (let index = 0; index < 16; index += 1) {
|
|
112
|
+
const wordOffset = chunkOffset + index * 4;
|
|
113
|
+
schedule[index] =
|
|
114
|
+
(((padded[wordOffset] ?? 0) << 24) |
|
|
115
|
+
((padded[wordOffset + 1] ?? 0) << 16) |
|
|
116
|
+
((padded[wordOffset + 2] ?? 0) << 8) |
|
|
117
|
+
(padded[wordOffset + 3] ?? 0)) >>>
|
|
118
|
+
0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
for (let index = 16; index < 64; index += 1) {
|
|
122
|
+
schedule[index] = add32(
|
|
123
|
+
lowerSigma1(schedule[index - 2] ?? 0),
|
|
124
|
+
schedule[index - 7] ?? 0,
|
|
125
|
+
lowerSigma0(schedule[index - 15] ?? 0),
|
|
126
|
+
schedule[index - 16] ?? 0,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let [a, b, c, d, e, f, g, h] = state;
|
|
131
|
+
|
|
132
|
+
for (let index = 0; index < 64; index += 1) {
|
|
133
|
+
const t1 = add32(
|
|
134
|
+
h,
|
|
135
|
+
upperSigma1(e),
|
|
136
|
+
choose(e, f, g),
|
|
137
|
+
SHA256_CONSTANTS[index] ?? 0,
|
|
138
|
+
schedule[index] ?? 0,
|
|
139
|
+
);
|
|
140
|
+
const t2 = add32(upperSigma0(a), majority(a, b, c));
|
|
141
|
+
|
|
142
|
+
h = g;
|
|
143
|
+
g = f;
|
|
144
|
+
f = e;
|
|
145
|
+
e = add32(d, t1);
|
|
146
|
+
d = c;
|
|
147
|
+
c = b;
|
|
148
|
+
b = a;
|
|
149
|
+
a = add32(t1, t2);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
state[0] = add32(state[0] ?? 0, a);
|
|
153
|
+
state[1] = add32(state[1] ?? 0, b);
|
|
154
|
+
state[2] = add32(state[2] ?? 0, c);
|
|
155
|
+
state[3] = add32(state[3] ?? 0, d);
|
|
156
|
+
state[4] = add32(state[4] ?? 0, e);
|
|
157
|
+
state[5] = add32(state[5] ?? 0, f);
|
|
158
|
+
state[6] = add32(state[6] ?? 0, g);
|
|
159
|
+
state[7] = add32(state[7] ?? 0, h);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return state.map((word) => word.toString(16).padStart(8, "0")).join("");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function padSha256Message(bytes: Uint8Array): Uint8Array {
|
|
166
|
+
const bitLength = bytes.byteLength * 8;
|
|
167
|
+
const paddedLength = Math.ceil((bytes.byteLength + 9) / 64) * 64;
|
|
168
|
+
const padded = new Uint8Array(paddedLength);
|
|
169
|
+
padded.set(bytes);
|
|
170
|
+
padded[bytes.byteLength] = 0x80;
|
|
171
|
+
|
|
172
|
+
const lengthOffset = paddedLength - 8;
|
|
173
|
+
for (let index = 0; index < 8; index += 1) {
|
|
174
|
+
const shift = (7 - index) * 8;
|
|
175
|
+
padded[lengthOffset + index] = Math.floor(bitLength / 2 ** shift) & 0xff;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return padded;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function rotateRight(value: number, shift: number): number {
|
|
182
|
+
return ((value >>> shift) | (value << (32 - shift))) >>> 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function add32(...values: number[]): number {
|
|
186
|
+
let total = 0;
|
|
187
|
+
for (const value of values) {
|
|
188
|
+
total = (total + value) >>> 0;
|
|
189
|
+
}
|
|
190
|
+
return total;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function choose(x: number, y: number, z: number): number {
|
|
194
|
+
return ((x & y) ^ (~x & z)) >>> 0;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function majority(x: number, y: number, z: number): number {
|
|
198
|
+
return ((x & y) ^ (x & z) ^ (y & z)) >>> 0;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function upperSigma0(value: number): number {
|
|
202
|
+
return (rotateRight(value, 2) ^ rotateRight(value, 13) ^ rotateRight(value, 22)) >>> 0;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function upperSigma1(value: number): number {
|
|
206
|
+
return (rotateRight(value, 6) ^ rotateRight(value, 11) ^ rotateRight(value, 25)) >>> 0;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function lowerSigma0(value: number): number {
|
|
210
|
+
return (rotateRight(value, 7) ^ rotateRight(value, 18) ^ (value >>> 3)) >>> 0;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function lowerSigma1(value: number): number {
|
|
214
|
+
return (rotateRight(value, 17) ^ rotateRight(value, 19) ^ (value >>> 10)) >>> 0;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function toUint8Array(bytes: Uint8Array | ArrayBuffer): Uint8Array {
|
|
218
|
+
return bytes instanceof Uint8Array ? new Uint8Array(bytes) : new Uint8Array(bytes);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function getBufferConstructor():
|
|
222
|
+
| {
|
|
223
|
+
from(
|
|
224
|
+
value: Uint8Array | string,
|
|
225
|
+
byteOffsetOrEncoding?: number | string,
|
|
226
|
+
length?: number,
|
|
227
|
+
): Uint8Array & { toString(encoding: string): string };
|
|
228
|
+
}
|
|
229
|
+
| undefined {
|
|
230
|
+
const maybeBuffer = (globalThis as {
|
|
231
|
+
Buffer?: {
|
|
232
|
+
from(
|
|
233
|
+
value: Uint8Array | string,
|
|
234
|
+
byteOffsetOrEncoding?: number | string,
|
|
235
|
+
length?: number,
|
|
236
|
+
): Uint8Array & { toString(encoding: string): string };
|
|
237
|
+
};
|
|
238
|
+
}).Buffer;
|
|
239
|
+
|
|
240
|
+
return maybeBuffer;
|
|
241
|
+
}
|