documonster 0.20.2 → 0.21.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.
Files changed (144) hide show
  1. package/README.md +1 -1
  2. package/README_zh.md +1 -1
  3. package/THIRD_PARTY_NOTICES.md +34 -2
  4. package/dist/esm/modules/archive/core/byte-queue.js +2 -1
  5. package/dist/esm/modules/archive/unzip/stream.browser.js +6 -0
  6. package/dist/esm/modules/csv/parse/async.js +2 -1
  7. package/dist/esm/modules/excel/bridge/csv-bridge.js +1 -1
  8. package/dist/esm/modules/excel/core/xlsx-io.browser.js +5 -9
  9. package/dist/esm/modules/excel/core/xlsx-io.js +1 -3
  10. package/dist/esm/modules/excel/core/xlsx-stream.js +3 -1
  11. package/dist/esm/modules/excel/stream/workbook-reader.browser.js +10 -10
  12. package/dist/esm/modules/excel/stream/workbook-reader.js +30 -6
  13. package/dist/esm/modules/stream/browser/collector.js +3 -5
  14. package/dist/esm/modules/stream/browser/compose.js +13 -228
  15. package/dist/esm/modules/stream/browser/duplex-pair.js +71 -0
  16. package/dist/esm/modules/stream/browser/factories.js +35 -217
  17. package/dist/esm/modules/stream/browser/pipeline.js +43 -478
  18. package/dist/esm/modules/stream/browser/utils.js +21 -247
  19. package/dist/esm/modules/stream/browser/web.js +25 -0
  20. package/dist/esm/modules/stream/buffered-stream.js +8 -6
  21. package/dist/esm/modules/stream/core/factories.js +166 -0
  22. package/dist/esm/modules/stream/core/pipeline-api.js +32 -0
  23. package/dist/esm/modules/stream/core/sink-adapter.js +94 -24
  24. package/dist/esm/modules/stream/core/stream-helpers.js +160 -0
  25. package/dist/esm/modules/stream/core/utils.js +0 -23
  26. package/dist/esm/modules/stream/core/web-conversions.js +31 -0
  27. package/dist/esm/modules/stream/core/web-pipeline.js +90 -0
  28. package/dist/esm/modules/stream/index.base.js +2 -2
  29. package/dist/esm/modules/stream/index.browser.js +13 -19
  30. package/dist/esm/modules/stream/index.js +6 -10
  31. package/dist/esm/modules/stream/kernel/classes.js +618 -0
  32. package/dist/esm/modules/stream/kernel/compose-impl.js +225 -0
  33. package/dist/esm/modules/stream/kernel/destroy.js +255 -0
  34. package/dist/esm/modules/stream/kernel/duplexify.js +355 -0
  35. package/dist/esm/modules/stream/kernel/end-of-stream.js +212 -0
  36. package/dist/esm/modules/stream/kernel/errors.js +215 -0
  37. package/dist/esm/modules/stream/kernel/from.js +202 -0
  38. package/dist/esm/modules/stream/kernel/legacy.js +35 -0
  39. package/dist/esm/modules/stream/kernel/operators.js +285 -0
  40. package/dist/esm/modules/stream/kernel/pipeline-impl.js +561 -0
  41. package/dist/esm/modules/stream/kernel/readable-impl.js +963 -0
  42. package/dist/esm/modules/stream/kernel/state.js +253 -0
  43. package/dist/esm/modules/stream/kernel/stream-utils.js +212 -0
  44. package/dist/esm/modules/stream/kernel/web-adapters.js +584 -0
  45. package/dist/esm/modules/stream/kernel/writable.js +651 -0
  46. package/dist/esm/modules/stream/node/collector.js +7 -1
  47. package/dist/esm/modules/stream/node/compose.js +21 -206
  48. package/dist/esm/modules/stream/node/factories.js +34 -238
  49. package/dist/esm/modules/stream/node/pipeline.js +40 -94
  50. package/dist/esm/modules/stream/node/utils.js +15 -239
  51. package/dist/esm/modules/stream/node/web.js +27 -0
  52. package/dist/esm/modules/stream/pull-stream.js +15 -9
  53. package/dist/esm/modules/word/writer/streaming-writer.js +3 -0
  54. package/dist/iife/THIRD_PARTY_NOTICES.md +34 -2
  55. package/dist/iife/documonster.archive.iife.min.js +4 -4
  56. package/dist/iife/documonster.csv.iife.min.js +19 -19
  57. package/dist/iife/documonster.draw.iife.min.js +1 -1
  58. package/dist/iife/documonster.excel.iife.min.js +50 -50
  59. package/dist/iife/documonster.formula.iife.min.js +1 -1
  60. package/dist/iife/documonster.markdown.iife.min.js +1 -1
  61. package/dist/iife/documonster.mermaid.iife.min.js +1 -1
  62. package/dist/iife/documonster.pdf.iife.min.js +1 -1
  63. package/dist/iife/documonster.stream.iife.min.js +2 -2
  64. package/dist/iife/documonster.word.iife.min.js +60 -60
  65. package/dist/iife/documonster.xml.iife.min.js +1 -1
  66. package/dist/types/modules/excel/core/xlsx-io.browser.d.ts +5 -9
  67. package/dist/types/modules/excel/core/xlsx-io.d.ts +1 -3
  68. package/dist/types/modules/excel/core/xlsx-stream.d.ts +3 -2
  69. package/dist/types/modules/excel/stream/workbook-reader.browser.d.ts +2 -1
  70. package/dist/types/modules/excel/stream/workbook-reader.d.ts +2 -1
  71. package/dist/types/modules/stream/browser/collector.d.ts +1 -1
  72. package/dist/types/modules/stream/browser/compose.d.ts +14 -15
  73. package/dist/types/modules/stream/browser/duplex-pair.d.ts +10 -0
  74. package/dist/types/modules/stream/browser/factories.d.ts +22 -79
  75. package/dist/types/modules/stream/browser/pipeline.d.ts +8 -40
  76. package/dist/types/modules/stream/browser/utils.d.ts +6 -47
  77. package/dist/types/modules/stream/browser/web.d.ts +18 -0
  78. package/dist/types/modules/stream/core/add-abort-signal.d.ts +2 -1
  79. package/dist/types/modules/stream/core/consumers.d.ts +1 -1
  80. package/dist/types/modules/stream/core/event-utils.d.ts +2 -1
  81. package/dist/types/modules/stream/core/factories.d.ts +129 -0
  82. package/dist/types/modules/stream/core/pipeline-api.d.ts +10 -0
  83. package/dist/types/modules/stream/core/sink-adapter.d.ts +18 -1
  84. package/dist/types/modules/stream/core/stream-helpers.d.ts +76 -0
  85. package/dist/types/modules/stream/core/utils.d.ts +0 -9
  86. package/dist/types/modules/stream/core/web-conversions.d.ts +68 -0
  87. package/dist/types/modules/stream/core/web-pipeline.d.ts +27 -0
  88. package/dist/types/modules/stream/index.base.d.ts +6 -4
  89. package/dist/types/modules/stream/index.browser.d.ts +13 -14
  90. package/dist/types/modules/stream/index.d.ts +7 -10
  91. package/dist/types/modules/stream/kernel/classes.d.ts +220 -0
  92. package/dist/types/modules/stream/kernel/compose-impl.d.ts +10 -0
  93. package/dist/types/modules/stream/kernel/destroy.d.ts +21 -0
  94. package/dist/types/modules/stream/kernel/duplexify.d.ts +31 -0
  95. package/dist/types/modules/stream/kernel/end-of-stream.d.ts +28 -0
  96. package/dist/types/modules/stream/kernel/errors.d.ts +42 -0
  97. package/dist/types/modules/stream/kernel/from.d.ts +17 -0
  98. package/dist/types/modules/stream/kernel/legacy.d.ts +20 -0
  99. package/dist/types/modules/stream/kernel/operators.d.ts +44 -0
  100. package/dist/types/modules/stream/kernel/pipeline-impl.d.ts +32 -0
  101. package/dist/types/modules/stream/kernel/readable-impl.d.ts +34 -0
  102. package/dist/types/modules/stream/kernel/state.d.ts +223 -0
  103. package/dist/types/modules/stream/kernel/stream-utils.d.ts +34 -0
  104. package/dist/types/modules/stream/kernel/web-adapters.d.ts +65 -0
  105. package/dist/types/modules/stream/kernel/writable.d.ts +107 -0
  106. package/dist/types/modules/stream/node/collector.d.ts +7 -2
  107. package/dist/types/modules/stream/node/compose.d.ts +31 -5
  108. package/dist/types/modules/stream/node/factories.d.ts +22 -85
  109. package/dist/types/modules/stream/node/pipeline.d.ts +4 -15
  110. package/dist/types/modules/stream/node/utils.d.ts +9 -49
  111. package/dist/types/modules/stream/node/web.d.ts +18 -0
  112. package/dist/types/modules/stream/pull-stream.d.ts +2 -2
  113. package/dist/types/modules/stream/types.d.ts +24 -6
  114. package/package.json +5 -3
  115. package/dist/esm/modules/stream/browser/_lazy.js +0 -30
  116. package/dist/esm/modules/stream/browser/chunk-buffer.js +0 -223
  117. package/dist/esm/modules/stream/browser/duplex.js +0 -979
  118. package/dist/esm/modules/stream/browser/helpers.js +0 -44
  119. package/dist/esm/modules/stream/browser/microtask-context.js +0 -60
  120. package/dist/esm/modules/stream/browser/passthrough.js +0 -16
  121. package/dist/esm/modules/stream/browser/pipe-manager.js +0 -161
  122. package/dist/esm/modules/stream/browser/readable.js +0 -2208
  123. package/dist/esm/modules/stream/browser/transform.js +0 -1241
  124. package/dist/esm/modules/stream/browser/writable.js +0 -1316
  125. package/dist/esm/modules/stream/core/end-args.js +0 -24
  126. package/dist/esm/modules/stream/node/writable.js +0 -125
  127. package/dist/esm/modules/stream/utils.base.js +0 -126
  128. package/dist/esm/modules/stream/utils.browser.js +0 -80
  129. package/dist/esm/modules/stream/utils.js +0 -81
  130. package/dist/types/modules/stream/browser/_lazy.d.ts +0 -20
  131. package/dist/types/modules/stream/browser/chunk-buffer.d.ts +0 -61
  132. package/dist/types/modules/stream/browser/duplex.d.ts +0 -299
  133. package/dist/types/modules/stream/browser/helpers.d.ts +0 -13
  134. package/dist/types/modules/stream/browser/microtask-context.d.ts +0 -44
  135. package/dist/types/modules/stream/browser/passthrough.d.ts +0 -11
  136. package/dist/types/modules/stream/browser/pipe-manager.d.ts +0 -38
  137. package/dist/types/modules/stream/browser/readable.d.ts +0 -379
  138. package/dist/types/modules/stream/browser/transform.d.ts +0 -314
  139. package/dist/types/modules/stream/browser/writable.d.ts +0 -238
  140. package/dist/types/modules/stream/core/end-args.d.ts +0 -20
  141. package/dist/types/modules/stream/node/writable.d.ts +0 -53
  142. package/dist/types/modules/stream/utils.base.d.ts +0 -63
  143. package/dist/types/modules/stream/utils.browser.d.ts +0 -23
  144. package/dist/types/modules/stream/utils.d.ts +0 -24
@@ -1,44 +0,0 @@
1
- /**
2
- * Browser Stream - Shared event listener helpers
3
- */
4
- // =============================================================================
5
- // Shared event listener helpers
6
- // =============================================================================
7
- export function removeEmitterListener(emitter, event, listener) {
8
- if (typeof emitter.off === "function") {
9
- emitter.off(event, listener);
10
- }
11
- else if (typeof emitter.removeListener === "function") {
12
- emitter.removeListener(event, listener);
13
- }
14
- }
15
- export function addEmitterListener(emitter, event, listener, options) {
16
- if (options?.once) {
17
- if (typeof emitter.once === "function") {
18
- emitter.once(event, listener);
19
- }
20
- // If .once() is not available, silently skip — matching Node.js
21
- // optional-chaining behavior: (emitter as any).once?.(event, listener)
22
- }
23
- else if (typeof emitter.on === "function") {
24
- emitter.on(event, listener);
25
- }
26
- return () => removeEmitterListener(emitter, event, listener);
27
- }
28
- export function createListenerRegistry() {
29
- const listeners = [];
30
- return {
31
- add: (emitter, event, listener) => {
32
- listeners.push(addEmitterListener(emitter, event, listener));
33
- },
34
- once: (emitter, event, listener) => {
35
- listeners.push(addEmitterListener(emitter, event, listener, { once: true }));
36
- },
37
- cleanup: () => {
38
- for (let i = listeners.length - 1; i >= 0; i--) {
39
- listeners[i]();
40
- }
41
- listeners.length = 0;
42
- }
43
- };
44
- }
@@ -1,60 +0,0 @@
1
- /**
2
- * Browser Stream - Deferred task context tracking
3
- *
4
- * Tracks whether code is currently executing inside a stream-internal
5
- * deferred callback (queueMicrotask). This allows destroy() to decide
6
- * whether to synchronously emit error/close events (when already in a
7
- * deferred context) or to schedule another queueMicrotask (when called
8
- * from synchronous user code).
9
- *
10
- * Why this matters:
11
- *
12
- * In Node.js, process.nextTick callbacks that schedule more nextTick
13
- * callbacks form a chain that runs to completion before any Promise.then
14
- * callbacks execute. For example:
15
- *
16
- * process.nextTick(() => { // tick A
17
- * emit("finish");
18
- * destroy(); // internally does:
19
- * process.nextTick(() => { // tick B — runs before Promises
20
- * emit("close");
21
- * });
22
- * });
23
- * Promise.resolve().then(...) // runs AFTER tick B
24
- *
25
- * In the browser, queueMicrotask and Promise.then share a single FIFO
26
- * microtask queue, so tick B would be appended after the Promise callback,
27
- * allowing it to interleave between "finish" and "close".
28
- *
29
- * This module solves the problem by tracking a depth counter. When
30
- * destroy() detects it is already inside a deferTask callback (depth > 0),
31
- * it emits error/close synchronously instead of scheduling another
32
- * queueMicrotask — collapsing the two-level nesting into one level.
33
- */
34
- // =============================================================================
35
- // Context tracking
36
- // =============================================================================
37
- let _depth = 0;
38
- /**
39
- * Schedule `fn` via queueMicrotask, tracking the execution context.
40
- * Use this instead of raw queueMicrotask in stream implementation code.
41
- */
42
- export function deferTask(fn) {
43
- queueMicrotask(() => {
44
- _depth++;
45
- try {
46
- fn();
47
- }
48
- finally {
49
- _depth--;
50
- }
51
- });
52
- }
53
- /**
54
- * Returns true if the current call stack is inside a deferTask callback.
55
- * Used by destroy() to decide whether afterDestroy should emit
56
- * synchronously (already deferred) or schedule a new microtask.
57
- */
58
- export function inDeferredContext() {
59
- return _depth > 0;
60
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * Browser Stream - PassThrough
3
- */
4
- import { Transform } from "./transform.js";
5
- // =============================================================================
6
- // PassThrough Stream
7
- // =============================================================================
8
- /**
9
- * A passthrough stream that passes data through unchanged.
10
- * Uses a prototype _transform override (matching Node.js PassThrough behavior).
11
- */
12
- export class PassThrough extends Transform {
13
- _transform(chunk, _encoding, callback) {
14
- callback(null, chunk);
15
- }
16
- }
@@ -1,161 +0,0 @@
1
- /**
2
- * Browser Stream - PipeManager
3
- *
4
- * Encapsulates pipe/unpipe logic for Readable streams.
5
- * Owns the destination list and the per-destination listener bookkeeping,
6
- * so Readable doesn't need to know anything about piping internals.
7
- */
8
- import { removeEmitterListener } from "./helpers.js";
9
- import { StreamTypeError } from "../errors.js";
10
- // =============================================================================
11
- // PipeManager
12
- // =============================================================================
13
- export class PipeManager {
14
- constructor(_source) {
15
- this._source = _source;
16
- this._destinations = [];
17
- this._listeners = new Map();
18
- this._sourceOverride = null;
19
- }
20
- /**
21
- * Override the source identity used when emitting "pipe" and "unpipe" events
22
- * on destinations. This allows Transform/Duplex wrappers to present
23
- * themselves (rather than their internal Readable) as the pipe source.
24
- */
25
- setSource(source) {
26
- this._sourceOverride = source;
27
- }
28
- /** The identity to emit in "pipe"/"unpipe" events. */
29
- get _emitSource() {
30
- return this._sourceOverride ?? this._source;
31
- }
32
- /** Pipe source data to `destination`. Returns `destination` for chaining. */
33
- pipe(destination, options) {
34
- // IMPORTANT:
35
- // Do not rely on `instanceof` here.
36
- // In bundled/minified builds, multiple copies of this module can exist,
37
- // causing `instanceof Transform/Writable/Duplex` to fail even when the object
38
- // is a valid destination.
39
- const dest = destination;
40
- // Boundary: treat the destination as a duck-typed emitter. It may be any
41
- // writable-like object (see the note above on avoiding `instanceof`), so
42
- // its on/once/off/emit are probed and called dynamically.
43
- const eventTarget = dest;
44
- const hasWrite = typeof dest?.write === "function";
45
- const hasEnd = typeof dest?.end === "function";
46
- const hasOn = typeof eventTarget?.on === "function";
47
- const hasOnce = typeof eventTarget?.once === "function";
48
- const hasOff = typeof eventTarget?.off === "function";
49
- if (!hasWrite || !hasEnd || (!hasOnce && !hasOn) || (!hasOff && !eventTarget?.removeListener)) {
50
- throw new StreamTypeError("Writable", typeof dest);
51
- }
52
- this._destinations.push(dest);
53
- // Create listeners that we can later remove
54
- let drainListener;
55
- const removeDrainListener = () => {
56
- if (!drainListener) {
57
- return;
58
- }
59
- removeEmitterListener(eventTarget, "drain", drainListener);
60
- drainListener = undefined;
61
- };
62
- const dataListener = (chunk) => {
63
- const canWrite = dest.write(chunk);
64
- if (!canWrite) {
65
- this._source.pause();
66
- if (!drainListener) {
67
- drainListener = () => {
68
- removeDrainListener();
69
- this._source.resume();
70
- };
71
- eventTarget.on("drain", drainListener);
72
- const entry = this._listeners.get(dest);
73
- if (entry) {
74
- entry.drain = drainListener;
75
- }
76
- }
77
- }
78
- };
79
- const endEnabled = options?.end !== false;
80
- const endListener = endEnabled
81
- ? () => {
82
- dest.end();
83
- }
84
- : undefined;
85
- // Auto-unpipe when destination closes or finishes (Node.js compatibility).
86
- // Node.js internally listens for 'finish' and 'close' on the destination
87
- // and calls unpipe() so the source stops pushing data.
88
- const onDestCleanup = () => {
89
- this.unpipe(dest);
90
- };
91
- // Use once() if available, otherwise fall back to on() + manual removal
92
- const onceFn = typeof eventTarget.once === "function" ? "once" : "on";
93
- eventTarget[onceFn]("close", onDestCleanup);
94
- eventTarget[onceFn]("finish", onDestCleanup);
95
- this._listeners.set(dest, {
96
- data: dataListener,
97
- end: endListener,
98
- destClose: onDestCleanup,
99
- destFinish: onDestCleanup,
100
- eventTarget
101
- });
102
- this._source.on("data", dataListener);
103
- if (endListener) {
104
- this._source.once("end", endListener);
105
- }
106
- // Node.js pipe() does NOT forward errors from source to destination.
107
- // Users must handle errors on each stream independently.
108
- // Emit 'pipe' event on destination (Node.js compatibility)
109
- eventTarget.emit?.("pipe", this._emitSource);
110
- this._source.resume();
111
- return destination;
112
- }
113
- /** Unpipe from a specific destination, or all destinations if none given. */
114
- unpipe(destination) {
115
- if (destination) {
116
- const idx = this._destinations.indexOf(destination);
117
- if (idx !== -1) {
118
- this._destinations.splice(idx, 1);
119
- this._removeListeners(destination);
120
- // Pause source when no destinations remain (match Node.js behavior)
121
- if (this._destinations.length === 0) {
122
- this._source.pause();
123
- }
124
- }
125
- }
126
- else {
127
- const hadDestinations = this._destinations.length > 0;
128
- for (const target of this._destinations) {
129
- this._removeListeners(target);
130
- }
131
- this._destinations = [];
132
- // Only pause if we actually had destinations to remove
133
- if (hadDestinations) {
134
- this._source.pause();
135
- }
136
- }
137
- }
138
- _removeListeners(destination) {
139
- const listeners = this._listeners.get(destination);
140
- if (!listeners) {
141
- return;
142
- }
143
- this._source.off("data", listeners.data);
144
- if (listeners.end) {
145
- this._source.off("end", listeners.end);
146
- }
147
- if (listeners.drain) {
148
- removeEmitterListener(listeners.eventTarget, "drain", listeners.drain);
149
- }
150
- // Remove destination close/finish listeners
151
- if (listeners.destClose) {
152
- removeEmitterListener(listeners.eventTarget, "close", listeners.destClose);
153
- }
154
- if (listeners.destFinish) {
155
- removeEmitterListener(listeners.eventTarget, "finish", listeners.destFinish);
156
- }
157
- // Emit 'unpipe' event on destination (Node.js compatibility)
158
- listeners.eventTarget.emit?.("unpipe", this._emitSource);
159
- this._listeners.delete(destination);
160
- }
161
- }