@ansonlai/docx-redline-js 0.7.2 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/AGENTS.md +15 -10
  2. package/ARCHITECTURE.md +30 -10
  3. package/CHANGELOG.md +539 -431
  4. package/README.md +331 -309
  5. package/adapters/xml-adapter.js +84 -56
  6. package/core/sha256.js +120 -0
  7. package/dist/docx-redline-js.esm.js +8982 -693
  8. package/dist/docx-redline-js.esm.js.map +4 -4
  9. package/dist/docx-redline-js.esm.min.js +102 -89
  10. package/dist/docx-redline-js.esm.min.js.map +4 -4
  11. package/dist/docx-redline.bundle.cjs +28305 -0
  12. package/dist/docx-redline.bundle.cjs.map +7 -0
  13. package/dist/docx-redline.bundle.js +28296 -0
  14. package/dist/docx-redline.bundle.js.map +7 -0
  15. package/docs/AGENT_FAST_START.md +2 -1
  16. package/docs/AGENT_KNOWLEDGE_BASE.md +480 -393
  17. package/docs/SKILL_AUTHORING.md +5 -2
  18. package/docs/TESTING.md +2 -1
  19. package/docs/schemas/document-operations.schema.json +29 -0
  20. package/document/docx-document.d.ts +39 -0
  21. package/document/docx-document.js +1010 -0
  22. package/document/zip-archive.js +258 -0
  23. package/engine/reconstruction-writer.js +18 -0
  24. package/index.d.ts +598 -531
  25. package/index.js +349 -340
  26. package/node/cli-help.js +5 -5
  27. package/node/cli.js +760 -754
  28. package/node/docx-document.js +11 -355
  29. package/node/index.d.ts +1 -1
  30. package/node/zip-archive.js +28 -38
  31. package/package.json +14 -11
  32. package/scripts/build.mjs +40 -5
  33. package/scripts/generate-word-comment-edge-case-fixture.ps1 +58 -0
  34. package/scripts/generate-word-comment-thread-fixture.ps1 +36 -0
  35. package/scripts/generate-word-header-footer-fixture.ps1 +32 -0
  36. package/scripts/generate-word-multi-section-fixture.ps1 +27 -0
  37. package/scripts/generate-word-package-integrity-cases.mjs +141 -0
  38. package/scripts/generate-word-thread-state-fixtures.ps1 +50 -0
  39. package/scripts/word-com-package-integrity.ps1 +98 -0
  40. package/services/batch-operation-orchestrator.js +262 -259
  41. package/services/comment-replies.js +96 -95
  42. package/services/comment-thread-parts.js +280 -0
  43. package/services/document-inspection.js +366 -365
  44. package/services/document-operation-applier.js +230 -202
  45. package/services/document-operation-contract.js +17 -2
  46. package/services/error-recovery.js +6 -0
  47. package/services/headers-footers.js +206 -0
  48. package/services/operation-batch-compiler.js +1 -0
  49. package/services/operation-preflight.js +231 -218
  50. package/services/package-parts.js +80 -0
  51. package/services/revision-token.js +11 -7
  52. package/services/standalone-docx-plumbing.js +631 -569
  53. package/services/standalone-operation-runner.d.ts +19 -3
@@ -5,6 +5,8 @@
5
5
  * revision tokens over package entries or document parts.
6
6
  */
7
7
 
8
+ import { sha256 } from '../core/sha256.js';
9
+
8
10
  const textEncoder = new TextEncoder();
9
11
 
10
12
  /**
@@ -145,6 +147,8 @@ export function buildRevisionTokenFraming({ scope, entries = [] }) {
145
147
  /**
146
148
  * Calculates a SHA-256 revision token asynchronously using Web Crypto or a custom digest function.
147
149
  *
150
+ * Defaults to the built-in pure-JS SHA-256 implementation when Web Crypto is unavailable.
151
+ *
148
152
  * @param {{ scope: string, entries: Array<any>, digestFn?: (bytes: Uint8Array) => Promise<string> }} options
149
153
  * @returns {Promise<{ algorithm: 'sha256', version: number, scope: string, value: string, coveredParts: string[] }>}
150
154
  */
@@ -159,7 +163,7 @@ export async function computeRevisionToken({ scope, entries = [], digestFn = nul
159
163
  const hashBytes = new Uint8Array(hashBuf);
160
164
  hashHex = Array.from(hashBytes).map(b => b.toString(16).padStart(2, '0')).join('');
161
165
  } else {
162
- throw new Error('No crypto provider available for SHA-256 revision token computation.');
166
+ hashHex = sha256(framing);
163
167
  }
164
168
 
165
169
  return {
@@ -172,17 +176,17 @@ export async function computeRevisionToken({ scope, entries = [], digestFn = nul
172
176
  }
173
177
 
174
178
  /**
175
- * Calculates a SHA-256 revision token synchronously using a provided digest function.
179
+ * Calculates a SHA-256 revision token synchronously using pure-JS SHA-256 or a custom digest function.
176
180
  *
177
- * @param {{ scope: string, entries: Array<any>, digestFn: (bytes: Uint8Array) => string }} options
181
+ * @param {{ scope: string, entries: Array<any>, digestFn?: (bytes: Uint8Array) => string }} options
178
182
  * @returns {{ algorithm: 'sha256', version: number, scope: string, value: string, coveredParts: string[] }}
179
183
  */
180
- export function computeRevisionTokenSync({ scope, entries = [], digestFn }) {
181
- if (typeof digestFn !== 'function') {
182
- throw new TypeError('computeRevisionTokenSync requires a synchronous digestFn.');
184
+ export function computeRevisionTokenSync({ scope, entries = [], digestFn = null }) {
185
+ if (digestFn != null && typeof digestFn !== 'function') {
186
+ throw new TypeError('computeRevisionTokenSync requires a synchronous digestFn when specified.');
183
187
  }
184
188
  const { framing, coveredParts, version } = buildRevisionTokenFraming({ scope, entries });
185
- const hashHex = digestFn(framing);
189
+ const hashHex = typeof digestFn === 'function' ? digestFn(framing) : sha256(framing);
186
190
  return {
187
191
  algorithm: 'sha256',
188
192
  version,