forge-terminal 0.1.0 → 0.2.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 (208) hide show
  1. package/README.md +305 -24
  2. package/dist/chunks/adm-zip-SQKLKBDP.js +3 -0
  3. package/dist/chunks/available-2VX7K7W6.js +3 -0
  4. package/dist/chunks/boot-ODZZHFUI.js +3 -0
  5. package/dist/chunks/cfb-V6M2PYOD.js +13 -0
  6. package/dist/chunks/chunk-2WYHI73Y.js +3 -0
  7. package/dist/chunks/chunk-4YHKTP7I.js +3 -0
  8. package/dist/chunks/chunk-5PYTOHLZ.js +3 -0
  9. package/dist/chunks/chunk-7YQR2MVH.js +3 -0
  10. package/dist/chunks/chunk-DRBA23IQ.js +3 -0
  11. package/dist/chunks/chunk-EOYBXOCV.js +4 -0
  12. package/dist/chunks/chunk-FQV57RMH.js +3 -0
  13. package/dist/chunks/chunk-IMKI5F4I.js +4 -0
  14. package/dist/chunks/chunk-J7FLFHQJ.js +3 -0
  15. package/dist/chunks/chunk-L2WK7CJG.js +3 -0
  16. package/dist/chunks/chunk-LFE3WRU4.js +3 -0
  17. package/dist/chunks/chunk-MHFY7HF6.js +10 -0
  18. package/dist/chunks/chunk-PBIS2ONZ.js +3 -0
  19. package/dist/chunks/chunk-QVACE4IE.js +3 -0
  20. package/dist/chunks/chunk-TMUK2DD3.js +3 -0
  21. package/dist/chunks/chunk-UNVHKJW4.js +41 -0
  22. package/dist/chunks/chunk-V4GHQGQM.js +4 -0
  23. package/dist/chunks/chunk-VB665HTV.js +3 -0
  24. package/dist/chunks/chunk-YHK5VE5R.js +3 -0
  25. package/dist/chunks/colour-QV2C3R7R.js +3 -0
  26. package/dist/chunks/config-command-UXJY623L.js +3 -0
  27. package/dist/chunks/dist-J2V6ITHG.js +29 -0
  28. package/dist/chunks/es-T2U7NBLD.js +3 -0
  29. package/dist/chunks/execute-4WJCUM7J.js +3 -0
  30. package/dist/chunks/extensions-command-6WZV2AES.js +3 -0
  31. package/dist/chunks/launch-2OI4ZLBQ.js +66 -0
  32. package/dist/chunks/lib-TPEJ5CJJ.js +46 -0
  33. package/dist/chunks/lock-R6GZXCCW.js +3 -0
  34. package/dist/chunks/manager-H52ENJOH.js +4 -0
  35. package/dist/chunks/paths-XY2345OS.js +3 -0
  36. package/dist/chunks/pdf-compress-IMRFBLZF.js +3 -0
  37. package/dist/chunks/react-devtools-core-UM4FS6CU.js +3 -0
  38. package/dist/chunks/run-N3F4EM7E.js +4 -0
  39. package/dist/chunks/server-5RWSVTOM.js +73 -0
  40. package/dist/chunks/theme-GW7CQPUO.js +3 -0
  41. package/dist/chunks/word-OGQ2KZAJ.js +24 -0
  42. package/dist/index.js +67 -95
  43. package/dist/third-party-licenses.txt +2856 -0
  44. package/package.json +28 -21
  45. package/skills/forge/SKILL.md +128 -0
  46. package/dist/cli/args.js +0 -278
  47. package/dist/cli/args.js.map +0 -1
  48. package/dist/cli/config-command.js +0 -55
  49. package/dist/cli/config-command.js.map +0 -1
  50. package/dist/cli/execute.js +0 -377
  51. package/dist/cli/execute.js.map +0 -1
  52. package/dist/cli/report.js +0 -123
  53. package/dist/cli/report.js.map +0 -1
  54. package/dist/cli/spinner.js +0 -60
  55. package/dist/cli/spinner.js.map +0 -1
  56. package/dist/cli/stdin.js +0 -47
  57. package/dist/cli/stdin.js.map +0 -1
  58. package/dist/config/preferences.js +0 -143
  59. package/dist/config/preferences.js.map +0 -1
  60. package/dist/core/actions/compress.js +0 -157
  61. package/dist/core/actions/compress.js.map +0 -1
  62. package/dist/core/actions/convert.js +0 -270
  63. package/dist/core/actions/convert.js.map +0 -1
  64. package/dist/core/actions/extract.js +0 -94
  65. package/dist/core/actions/extract.js.map +0 -1
  66. package/dist/core/actions/index.js +0 -23
  67. package/dist/core/actions/index.js.map +0 -1
  68. package/dist/core/actions/merge.js +0 -16
  69. package/dist/core/actions/merge.js.map +0 -1
  70. package/dist/core/actions/rotate.js +0 -36
  71. package/dist/core/actions/rotate.js.map +0 -1
  72. package/dist/core/actions/split.js +0 -65
  73. package/dist/core/actions/split.js.map +0 -1
  74. package/dist/core/atomic.js +0 -61
  75. package/dist/core/atomic.js.map +0 -1
  76. package/dist/core/capabilities.js +0 -59
  77. package/dist/core/capabilities.js.map +0 -1
  78. package/dist/core/compress.js +0 -76
  79. package/dist/core/compress.js.map +0 -1
  80. package/dist/core/describe.js +0 -49
  81. package/dist/core/describe.js.map +0 -1
  82. package/dist/core/errors.js +0 -469
  83. package/dist/core/errors.js.map +0 -1
  84. package/dist/core/execute-jobs.js +0 -122
  85. package/dist/core/execute-jobs.js.map +0 -1
  86. package/dist/core/formats.js +0 -108
  87. package/dist/core/formats.js.map +0 -1
  88. package/dist/core/order.js +0 -44
  89. package/dist/core/order.js.map +0 -1
  90. package/dist/core/output-path.js +0 -176
  91. package/dist/core/output-path.js.map +0 -1
  92. package/dist/core/pages.js +0 -107
  93. package/dist/core/pages.js.map +0 -1
  94. package/dist/core/pdf-compress.js +0 -206
  95. package/dist/core/pdf-compress.js.map +0 -1
  96. package/dist/core/plan.js +0 -42
  97. package/dist/core/plan.js.map +0 -1
  98. package/dist/core/resolve.js +0 -115
  99. package/dist/core/resolve.js.map +0 -1
  100. package/dist/core/run.js +0 -66
  101. package/dist/core/run.js.map +0 -1
  102. package/dist/core/suggest.js +0 -50
  103. package/dist/core/suggest.js.map +0 -1
  104. package/dist/core/types.js +0 -2
  105. package/dist/core/types.js.map +0 -1
  106. package/dist/core/units.js +0 -94
  107. package/dist/core/units.js.map +0 -1
  108. package/dist/core/write-safety.js +0 -128
  109. package/dist/core/write-safety.js.map +0 -1
  110. package/dist/engines/heic.js +0 -166
  111. package/dist/engines/heic.js.map +0 -1
  112. package/dist/engines/image.js +0 -342
  113. package/dist/engines/image.js.map +0 -1
  114. package/dist/engines/pdf.js +0 -444
  115. package/dist/engines/pdf.js.map +0 -1
  116. package/dist/engines/pdfium.js +0 -161
  117. package/dist/engines/pdfium.js.map +0 -1
  118. package/dist/engines/registry.js +0 -65
  119. package/dist/engines/registry.js.map +0 -1
  120. package/dist/engines/types.js +0 -2
  121. package/dist/engines/types.js.map +0 -1
  122. package/dist/engines/word.js +0 -385
  123. package/dist/engines/word.js.map +0 -1
  124. package/dist/index.js.map +0 -1
  125. package/dist/shell/App.js +0 -1972
  126. package/dist/shell/App.js.map +0 -1
  127. package/dist/shell/ClickTargets.js +0 -183
  128. package/dist/shell/ClickTargets.js.map +0 -1
  129. package/dist/shell/ThemeContext.js +0 -21
  130. package/dist/shell/ThemeContext.js.map +0 -1
  131. package/dist/shell/blocks.js +0 -160
  132. package/dist/shell/blocks.js.map +0 -1
  133. package/dist/shell/clipboard.js +0 -64
  134. package/dist/shell/clipboard.js.map +0 -1
  135. package/dist/shell/commands.js +0 -51
  136. package/dist/shell/commands.js.map +0 -1
  137. package/dist/shell/components/Banner.js +0 -73
  138. package/dist/shell/components/Banner.js.map +0 -1
  139. package/dist/shell/components/CommandPalette.js +0 -37
  140. package/dist/shell/components/CommandPalette.js.map +0 -1
  141. package/dist/shell/components/FileCard.js +0 -59
  142. package/dist/shell/components/FileCard.js.map +0 -1
  143. package/dist/shell/components/HintBar.js +0 -18
  144. package/dist/shell/components/HintBar.js.map +0 -1
  145. package/dist/shell/components/Hints.js +0 -21
  146. package/dist/shell/components/Hints.js.map +0 -1
  147. package/dist/shell/components/MergeList.js +0 -268
  148. package/dist/shell/components/MergeList.js.map +0 -1
  149. package/dist/shell/components/ModeHeader.js +0 -21
  150. package/dist/shell/components/ModeHeader.js.map +0 -1
  151. package/dist/shell/components/PageGrid.js +0 -324
  152. package/dist/shell/components/PageGrid.js.map +0 -1
  153. package/dist/shell/components/PathInput.js +0 -147
  154. package/dist/shell/components/PathInput.js.map +0 -1
  155. package/dist/shell/components/Progress.js +0 -43
  156. package/dist/shell/components/Progress.js.map +0 -1
  157. package/dist/shell/components/Prompt.js +0 -667
  158. package/dist/shell/components/Prompt.js.map +0 -1
  159. package/dist/shell/components/ResultLinks.js +0 -26
  160. package/dist/shell/components/ResultLinks.js.map +0 -1
  161. package/dist/shell/components/Select.js +0 -152
  162. package/dist/shell/components/Select.js.map +0 -1
  163. package/dist/shell/components/Slider.js +0 -48
  164. package/dist/shell/components/Slider.js.map +0 -1
  165. package/dist/shell/components/StagedFiles.js +0 -92
  166. package/dist/shell/components/StagedFiles.js.map +0 -1
  167. package/dist/shell/components/ThemePicker.js +0 -18
  168. package/dist/shell/components/ThemePicker.js.map +0 -1
  169. package/dist/shell/components/UnitRow.js +0 -30
  170. package/dist/shell/components/UnitRow.js.map +0 -1
  171. package/dist/shell/flows/pdf.js +0 -424
  172. package/dist/shell/flows/pdf.js.map +0 -1
  173. package/dist/shell/frame-geometry.js +0 -56
  174. package/dist/shell/frame-geometry.js.map +0 -1
  175. package/dist/shell/hyperlink.js +0 -27
  176. package/dist/shell/hyperlink.js.map +0 -1
  177. package/dist/shell/intro.js +0 -101
  178. package/dist/shell/intro.js.map +0 -1
  179. package/dist/shell/launch.js +0 -75
  180. package/dist/shell/launch.js.map +0 -1
  181. package/dist/shell/mark.js +0 -134
  182. package/dist/shell/mark.js.map +0 -1
  183. package/dist/shell/mouse.js +0 -209
  184. package/dist/shell/mouse.js.map +0 -1
  185. package/dist/shell/redraw.js +0 -36
  186. package/dist/shell/redraw.js.map +0 -1
  187. package/dist/shell/reveal.js +0 -24
  188. package/dist/shell/reveal.js.map +0 -1
  189. package/dist/shell/stage.js +0 -34
  190. package/dist/shell/stage.js.map +0 -1
  191. package/dist/shell/terminal-write.js +0 -16
  192. package/dist/shell/terminal-write.js.map +0 -1
  193. package/dist/shell/theme.js +0 -178
  194. package/dist/shell/theme.js.map +0 -1
  195. package/dist/shell/useFrameOrigin.js +0 -175
  196. package/dist/shell/useFrameOrigin.js.map +0 -1
  197. package/dist/shell/useKeys.js +0 -28
  198. package/dist/shell/useKeys.js.map +0 -1
  199. package/dist/shell/useMouse.js +0 -150
  200. package/dist/shell/useMouse.js.map +0 -1
  201. package/dist/shell/useMouseRouting.js +0 -69
  202. package/dist/shell/useMouseRouting.js.map +0 -1
  203. package/dist/shell/width.js +0 -62
  204. package/dist/shell/width.js.map +0 -1
  205. package/dist/utils/display-path.js +0 -31
  206. package/dist/utils/display-path.js.map +0 -1
  207. package/dist/utils/unescape-path.js +0 -68
  208. package/dist/utils/unescape-path.js.map +0 -1
@@ -1,377 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { basename, dirname, resolve } from 'node:path';
3
- import { ACTIONS, convertAction, unavailableReason } from '../core/actions/index.js';
4
- import { everyNCuts, everyPageCuts } from '../core/actions/split.js';
5
- import { rasterises } from '../core/capabilities.js';
6
- import { encryptedSource, invalidArguments, invalidPageRange, isForgeError, unsupportedCompress, } from '../core/errors.js';
7
- import { runPlan } from '../core/execute-jobs.js';
8
- import { looksLikeDirectory, resolveOutputPath } from '../core/output-path.js';
9
- import { buildPlan } from '../core/plan.js';
10
- import { resolveInputs } from '../core/resolve.js';
11
- import { openPdf } from '../engines/pdfium.js';
12
- import { reportBatch, reportFailures, reportFormats, reportPageOp, reportSingle } from './report.js';
13
- import { readPassword } from './stdin.js';
14
- /**
15
- * Turns a `PageOpIntent` into the `values` shape each action's `plan()`
16
- * expects (see `core/actions/*.ts`). This is the one place both of the
17
- * CLI's page-boundary conversions happen: `--split at=` is 1-based cut
18
- * points as the user typed them, `cuts` is 0-based as `Job` holds them;
19
- * `--separate` is a boolean flag, but `extractAction.plan` reads the string
20
- * 'many' (it was designed for the shell's select option, whose choices are
21
- * string values).
22
- */
23
- function pageOpValues(intent, sources) {
24
- if (intent.action === 'merge')
25
- return {};
26
- if (intent.action === 'rotate')
27
- return { degrees: intent.rotate };
28
- if (intent.action === 'extract') {
29
- return { pages: intent.pages, separate: intent.separate ? 'many' : 'one' };
30
- }
31
- if (intent.action === 'delete')
32
- return { pages: intent.pages };
33
- // action === 'split'
34
- const doc = sources.find((s) => s.kind === 'document');
35
- const pageCount = doc?.pages ?? 0;
36
- const spec = intent.split;
37
- if (!spec) {
38
- throw invalidArguments('--split needs a mode: every-page, every=N or at=N,N.');
39
- }
40
- if (spec.mode === 'every-page')
41
- return { cuts: everyPageCuts(pageCount) };
42
- if (spec.mode === 'every-n')
43
- return { cuts: everyNCuts(pageCount, spec.n) };
44
- // spec.mode === 'points' — validated here, the same way parseRanges
45
- // validates ranges: out of bounds is an error naming the page count, never
46
- // a silent clamp (cutsToRanges, downstream, would otherwise just drop it).
47
- const last = Math.max(pageCount - 1, 0);
48
- for (const n of spec.after) {
49
- if (!Number.isInteger(n) || n < 1 || n > last) {
50
- throw invalidPageRange(String(n), `"${n}" is outside 1 and ${last} — ${doc ? basename(doc.path) : 'the document'} has ${pageCount} pages.`, pageCount);
51
- }
52
- }
53
- return { cuts: spec.after.map((n) => n - 1) };
54
- }
55
- /**
56
- * Builds one rasterisation job for one encrypted-or-not document source:
57
- * prompts for a password only when the source is actually encrypted
58
- * (invariant 8 — never for a file that is not), then hands the actual
59
- * planning — page selection, resolution, and the per-page zero-padded
60
- * output names — to `convertAction.plan()`, the one place that logic lives
61
- * (`core/actions/convert.ts`, shared with the shell's own page/resolution
62
- * steps). This function's own job is the CLI-specific part `plan()` cannot
63
- * do itself: reading a password from the terminal or stdin, which `core/`
64
- * must never do (invariant 1), and folding the result into `options` —
65
- * `plan()` has no password field by design (there is no `--password` flag
66
- * to source one from, and the shell has none either, spec §8).
67
- *
68
- * Returns a failure instead of throwing for anything a user could cause
69
- * (a bad password, an out-of-range page): `execute()` collects these the
70
- * same way `resolveInputs` and `buildPlan` already report theirs, so one bad
71
- * PDF in a batch does not abort the rest.
72
- */
73
- async function buildRasterJob(source, intent,
74
- /**
75
- * The root this source was scanned under, when `--recursive` found it
76
- * inside one. Threaded through so `rasterOutputPaths` recreates the source
77
- * tree under `--output` the same way `buildPlan` already does for an image.
78
- */
79
- sourceRoot) {
80
- let password;
81
- if (source.encrypted) {
82
- // Never for an unencrypted file — asking would be a prompt nobody
83
- // expected and, worse, a password nothing is actually locked with.
84
- password = await readPassword({ stdin: intent.passwordStdin ?? false });
85
- let doc;
86
- try {
87
- doc = await openPdf(await readFile(source.path), password);
88
- }
89
- catch {
90
- // Any failure here becomes "wrong password", not just PDFium's own
91
- // PASSWORD error code — deliberately: gating this whole block on
92
- // `source.encrypted` already means a wrong password is overwhelmingly
93
- // the real cause, and the alternative (a genuinely malformed encrypted
94
- // PDF failing for some other reason) still gets a sensible message
95
- // rather than a raw parse error. Also discards whatever pdfium threw
96
- // rather than attaching it as `cause`: invariant 8 forbids the
97
- // attempted password from surfacing, and re-wrapping a message that
98
- // might echo caller input is a needless way to risk that. The existing
99
- // encrypted-source error already says what to do differently.
100
- return { failure: { path: source.path, error: encryptedSource(source.path) } };
101
- }
102
- // Outside the catch above, deliberately: this document only exists to
103
- // check the password, not to render anything, and the engine opens its
104
- // own copy below — so it is freed immediately (skipping it leaks a wasm
105
- // page buffer per encrypted file, which adds up on a long scan). A
106
- // failure *here* is not a wrong password, and reporting it as one would
107
- // send the user to re-type a password that was in fact correct.
108
- doc.destroy();
109
- }
110
- let planned;
111
- try {
112
- // `intent.pages` is the raw --pages text (or absent, meaning "all") —
113
- // exactly the shape `convertAction`'s own `resolvePages` already parses
114
- // for a typed range, so it is passed through unparsed rather than
115
- // reparsed here. `destination` is a bare directory, matching what the
116
- // shell's own path picker always hands `plan()`; the CLI's `--output`
117
- // can also name an exact file, but that has no meaning for a job that
118
- // writes more than one page, so it is used as a folder here too.
119
- planned = convertAction.plan([source], {
120
- target: intent.target,
121
- background: intent.options.background,
122
- keepMetadata: intent.options.keepMetadata,
123
- dpi: String(intent.dpi ?? 150),
124
- ...(intent.options.quality === undefined ? {} : { quality: intent.options.quality }),
125
- ...(intent.pages === undefined ? {} : { pages: intent.pages }),
126
- ...(intent.output === undefined ? {} : { destination: intent.output }),
127
- ...(sourceRoot === undefined ? {} : { sourceRoot }),
128
- });
129
- }
130
- catch (e) {
131
- if (!isForgeError(e))
132
- throw e;
133
- return { failure: { path: source.path, error: e } };
134
- }
135
- const job = planned[0];
136
- if (job?.op !== 'convert') {
137
- // A programmer error, not a user error: convertAction.plan() is
138
- // documented to return exactly one convert job for one document source.
139
- throw new Error(`convertAction.plan() did not return a convert job for ${source.path}`);
140
- }
141
- // plan() has no password field to fill in (see the note above) — this is
142
- // the one field this function adds on top of what it returned.
143
- if (password !== undefined)
144
- job.options.password = password;
145
- return { job };
146
- }
147
- export async function execute(intent, opts = {}) {
148
- // Routed here rather than in src/index.ts so there is exactly one place
149
- // that turns an Intent into an ExecuteResult. The import is lazy because a
150
- // plain conversion has no reason to touch the config layer at all.
151
- if (intent.kind === 'config') {
152
- const { runConfig } = await import('./config-command.js');
153
- const result = await runConfig(intent);
154
- return { exitCode: result.exitCode, stdout: result.stdout, stderr: [] };
155
- }
156
- if (intent.kind === 'formats') {
157
- return { exitCode: 0, stdout: reportFormats(), stderr: [] };
158
- }
159
- if (intent.kind === 'shell') {
160
- return { exitCode: 0, stdout: [], stderr: [] };
161
- }
162
- /**
163
- * A page operation is never a batch of separate conversions — it is one
164
- * `Action` (Task 10) turning a fixed set of sources into a `Job`, the same
165
- * way the shell hub does. Resolved and probed like every other path, so a
166
- * missing file or an unreadable PDF is reported the same way.
167
- */
168
- if (intent.kind === 'pageop') {
169
- const resolved = await resolveInputs(intent.inputs, { recursive: false });
170
- if (resolved.sources.length === 0) {
171
- return {
172
- exitCode: 1,
173
- stdout: [],
174
- stderr: reportFailures(resolved.failures, { debug: intent.debug }),
175
- };
176
- }
177
- const action = ACTIONS.find((a) => a.id === intent.action);
178
- if (!action)
179
- throw new Error(`no action registered for "${intent.action}"`);
180
- if (!action.appliesTo(resolved.sources)) {
181
- const reason = unavailableReason(action, resolved.sources) ?? 'not available for these files';
182
- throw invalidArguments(`Cannot ${intent.action}: ${reason}.`);
183
- }
184
- const values = pageOpValues(intent, resolved.sources);
185
- const planned = action.plan(resolved.sources, values);
186
- // `action.plan()` bypasses `buildPlan` — its one-source-one-target shape
187
- // does not fit merge's several sources or split's several outputs — but
188
- // `runPlan` is arity-agnostic, so the write-safety rules arrive for free
189
- // rather than having to be applied here by hand.
190
- const outcome = await runPlan(planned, { force: intent.force });
191
- const failures = [...resolved.failures, ...outcome.refusals, ...outcome.failures];
192
- const stdout = outcome.results.length === 0 ? [] : reportPageOp(outcome);
193
- return {
194
- exitCode: failures.length > 0 ? 1 : 0,
195
- stdout,
196
- stderr: reportFailures(failures, { debug: intent.debug }),
197
- };
198
- }
199
- const resolved = await resolveInputs(intent.inputs, { recursive: intent.recursive });
200
- /**
201
- * Compression keeps each file's own format, so there is no single target
202
- * for the whole batch — every source is its own. Planned per file and run
203
- * through the same `runPlan` every other path uses, so write safety, the
204
- * target-size search, concurrency and atomic writes are shared rather than
205
- * reimplemented — this path used to reimplement the search and skip write
206
- * safety entirely.
207
- */
208
- if (intent.kind === 'compress') {
209
- const { compressAction } = await import('../core/actions/index.js');
210
- const jobs = [];
211
- const refusals = [];
212
- for (const source of resolved.sources) {
213
- if (!compressAction.appliesTo([source])) {
214
- refusals.push({ path: source.path, error: unsupportedCompress(source) });
215
- continue;
216
- }
217
- /**
218
- * `--output` reads the way it does for a conversion. A directory gets
219
- * the action's own `-small` name, nested under `--recursive` exactly as
220
- * `resolveOutputPath` nests a conversion; anything else is the file to
221
- * write. Several sources aimed at one file collide in `runPlan`'s
222
- * write-safety pass, which already says so plainly.
223
- */
224
- const explicitFile = intent.output !== undefined && !looksLikeDirectory(intent.output)
225
- ? resolve(intent.output)
226
- : undefined;
227
- const destination = intent.output === undefined || explicitFile !== undefined
228
- ? dirname(source.path)
229
- : dirname(resolveOutputPath({
230
- sourcePath: source.path,
231
- target: source.format,
232
- output: intent.output,
233
- sourceRoot: resolved.roots.get(source.path),
234
- }));
235
- const [planned] = compressAction.plan([source], {
236
- mode: intent.maxBytes === undefined ? 'quality' : 'size',
237
- ...(intent.quality === undefined ? {} : { quality: intent.quality }),
238
- destination,
239
- });
240
- if (planned?.op !== 'convert')
241
- continue;
242
- if (explicitFile !== undefined)
243
- planned.outputs = [explicitFile];
244
- // A typed `--dpi` applies to both modes. It was originally threaded
245
- // only into the target-size search, so quality mode silently kept the
246
- // engine default and produced the same bytes whatever was passed.
247
- if (intent.dpi !== undefined)
248
- planned.options.dpi = intent.dpi;
249
- jobs.push(planned);
250
- }
251
- const batch = jobs.length > 1;
252
- if (batch)
253
- opts.onProgress?.({ completed: 0, total: jobs.length });
254
- const outcome = await runPlan(jobs, {
255
- force: intent.force,
256
- ...(intent.concurrency === undefined ? {} : { concurrency: intent.concurrency }),
257
- ...(intent.maxBytes === undefined ? {} : { targetBytes: intent.maxBytes }),
258
- onEvent: (event) => {
259
- if (event.type === 'search:attempt') {
260
- // The rung is named as well as the attempt: without it a search that
261
- // drops from 150 to 120 dpi looks like the counter simply restarting
262
- // for no reason.
263
- opts.onSearch?.(event.rung.dpi === undefined
264
- ? `attempt ${event.attempt} of ${event.of}`
265
- : `${event.rung.dpi} dpi · attempt ${event.attempt} of ${event.of}`);
266
- return;
267
- }
268
- if (batch && (event.type === 'job:done' || event.type === 'job:error')) {
269
- opts.onProgress?.({ completed: event.completed, total: event.total });
270
- }
271
- },
272
- });
273
- // `resolved.failures` first, as the conversion path below orders them.
274
- // It was missing here, so a file that did not exist was dropped silently
275
- // and the run exited 0 having done nothing.
276
- const failures = [
277
- ...resolved.failures,
278
- ...refusals,
279
- ...outcome.refusals,
280
- ...outcome.unreachable.map((u) => ({ path: u.job.sources[0].path, error: u.error })),
281
- ...outcome.failures,
282
- ];
283
- const stdout = outcome.results.length === 0
284
- ? []
285
- : outcome.results.length === 1
286
- ? reportSingle(outcome)
287
- : reportBatch(outcome, intent.output);
288
- return {
289
- exitCode: failures.length > 0 ? 1 : 0,
290
- stdout,
291
- stderr: reportFailures(failures, { debug: intent.debug }),
292
- };
293
- }
294
- /**
295
- * A document source only takes this rasterising path when the target is
296
- * one `pdfiumEngine` actually writes — `--to pdf` (embedding, not
297
- * rasterising) stays on `buildPlan`'s existing one-output-per-source path,
298
- * unchanged by this phase. `buildPlan` never sees these sources at all: it
299
- * cannot express "many outputs from one source", which is exactly what a
300
- * multi-page render is (see `Job`'s `convert` variant in `core/types.ts`).
301
- *
302
- * `format === 'pdf'` matters as much as `wantsRaster` does: pdfium only
303
- * ever reads `pdf`, so a docx/doc source can never actually be rasterised
304
- * regardless of the target. Without this, `forge report.docx --to jpeg`
305
- * was routed into `buildRasterJob` anyway and crashed with an uncaught
306
- * "requires at least one selected page" instead of the clean
307
- * `unsupported-target` refusal `buildPlan` already produces for it below.
308
- */
309
- const isDocument = (s) => s.kind === 'document' && s.format === 'pdf';
310
- const wantsRaster = rasterises(intent.target);
311
- const documentSources = wantsRaster ? resolved.sources.filter(isDocument) : [];
312
- const otherSources = wantsRaster
313
- ? resolved.sources.filter((s) => !isDocument(s))
314
- : resolved.sources;
315
- const documentJobs = [];
316
- const documentFailures = [];
317
- for (const source of documentSources) {
318
- const built = await buildRasterJob(source, intent, resolved.roots.get(source.path));
319
- if ('failure' in built)
320
- documentFailures.push(built.failure);
321
- else
322
- documentJobs.push(built.job);
323
- }
324
- const planRequest = {
325
- resolved: { sources: otherSources, failures: [], roots: resolved.roots },
326
- target: intent.target,
327
- options: intent.options,
328
- force: intent.force,
329
- ...(intent.output === undefined ? {} : { output: intent.output }),
330
- };
331
- const plan = await buildPlan(planRequest);
332
- /**
333
- * One write-safety pass over every job this run plans, whatever path
334
- * planned it — `runPlan` does it, over the union.
335
- *
336
- * Two independent passes — one over the raster jobs, one over the rest —
337
- * would each see only half the outputs, so a `doc.pdf` rasterising to
338
- * `doc-1.jpg` and a `doc-1.png` converting to the same name would collide
339
- * in neither. That is `outputCollision`'s exact case, and it is the one
340
- * refusal `--force` must never suppress: silently writing one file and
341
- * reporting two converted breaks invariant 6 (a multi-output job is
342
- * all-or-nothing) and invariant 7 (the summary never asserts something
343
- * untrue).
344
- *
345
- * Document jobs go last so an ordinary one-source-one-output conversion
346
- * keeps the name it would have had on its own, and the multi-output
347
- * rasterisation is the side told to go elsewhere.
348
- */
349
- const allJobs = [...plan.jobs, ...documentJobs];
350
- const isBatch = allJobs.length > 1;
351
- if (isBatch)
352
- opts.onProgress?.({ completed: 0, total: allJobs.length });
353
- const outcome = await runPlan(allJobs, {
354
- force: intent.force,
355
- ...(intent.concurrency === undefined ? {} : { concurrency: intent.concurrency }),
356
- onEvent: (event) => {
357
- if (isBatch && (event.type === 'job:done' || event.type === 'job:error')) {
358
- opts.onProgress?.({ completed: event.completed, total: event.total });
359
- }
360
- },
361
- });
362
- const failures = [
363
- ...resolved.failures,
364
- ...documentFailures,
365
- ...plan.failures,
366
- ...outcome.refusals,
367
- ...outcome.failures,
368
- ];
369
- const stdout = outcome.results.length === 0
370
- ? []
371
- : outcome.results.length === 1
372
- ? reportSingle(outcome)
373
- : reportBatch(outcome, intent.output);
374
- const stderr = reportFailures(failures, { debug: intent.debug });
375
- return { exitCode: failures.length > 0 ? 1 : 0, stdout, stderr };
376
- }
377
- //# sourceMappingURL=execute.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../src/cli/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AACpF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EACL,eAAe,EAEf,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,GACpB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CA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AS,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAA;YACvE,CAAC;QACH,CAAC;KACF,CAAC,CAAA;IAEF,MAAM,QAAQ,GAAG;QACf,GAAG,QAAQ,CAAC,QAAQ;QACpB,GAAG,gBAAgB;QACnB,GAAG,IAAI,CAAC,QAAQ;QAChB,GAAG,OAAO,CAAC,QAAQ;QACnB,GAAG,OAAO,CAAC,QAAQ;KACpB,CAAA;IAED,MAAM,MAAM,GACV,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;QAC1B,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;YAC5B,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC;YACvB,CAAC,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;IAE3C,MAAM,MAAM,GAAG,cAAc,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;IAEhE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;AAClE,CAAC"}
@@ -1,123 +0,0 @@
1
- import { basename, dirname } from 'node:path';
2
- import { readableFormats, writableFormats } from '../core/capabilities.js';
3
- import { renderError } from '../core/errors.js';
4
- import { FORMATS } from '../core/formats.js';
5
- import { formatBytes, percentChange } from '../core/units.js';
6
- import { displayPath } from '../utils/display-path.js';
7
- const placesFor = (where) => ({
8
- cwd: where.cwd ?? process.cwd(),
9
- ...(where.home === undefined ? {} : { home: where.home }),
10
- });
11
- /**
12
- * ` in <folder>/` for a set of outputs, or nothing when that folder is the
13
- * cwd — there, the folder goes without saying, exactly as a bare filename
14
- * does for a single output.
15
- */
16
- function inFolder(output, where) {
17
- const shown = displayPath(dirname(output), placesFor(where));
18
- if (shown === '.')
19
- return '';
20
- return ` in ${shown.endsWith('/') ? shown : `${shown}/`}`;
21
- }
22
- function changePhrase(from, to) {
23
- const { pct, direction } = percentChange(from, to);
24
- if (direction === 'same')
25
- return 'same size';
26
- return `${pct}% ${direction}`;
27
- }
28
- /**
29
- * One converted source. Usually one output too, but a single PDF rasterised
30
- * to several pages is still one *result* — one job, one source — with many
31
- * `outputs`. `summary.results.length === 1` is what routes execute() here
32
- * rather than to `reportBatch`, so this has to handle that shape itself
33
- * rather than assuming `outputs[0]` is the whole story (phase 4a's own
34
- * version of phase 3's worst defect: code that quietly only ever looked at
35
- * the first output).
36
- */
37
- export function reportSingle(summary, where = {}) {
38
- const result = summary.results[0];
39
- if (!result)
40
- return [];
41
- const source = result.job.sources[0];
42
- const outputs = result.job.outputs;
43
- if (outputs.length > 1) {
44
- const lines = [
45
- `✓ ${basename(source.path)} → ${outputs.length} files${inFolder(outputs[0], where)}`,
46
- ` ${outputs.map((o) => basename(o)).join(', ')}`,
47
- ` ${formatBytes(source.bytes)} → ${formatBytes(result.outputBytes)} total`,
48
- ];
49
- for (const warning of result.warnings)
50
- lines.push('', `⚠ ${warning.message}`);
51
- return lines;
52
- }
53
- // The output as a path, not a bare name: `-o out/` and `-o deep/dir/`
54
- // used to print byte-identical lines (audit #9). Inside cwd it is relative,
55
- // so the ordinary alongside-the-source case still reads `photo.png`.
56
- const lines = [
57
- `✓ ${basename(source.path)} → ${displayPath(outputs[0], placesFor(where))}`,
58
- ` ${formatBytes(source.bytes)} → ${formatBytes(result.outputBytes)} · ${changePhrase(source.bytes, result.outputBytes)}`,
59
- ];
60
- for (const warning of result.warnings)
61
- lines.push('', `⚠ ${warning.message}`);
62
- return lines;
63
- }
64
- export function reportBatch(summary, output) {
65
- const lines = [
66
- `✓ ${summary.results.length} converted`,
67
- ` ${formatBytes(summary.inputBytes)} → ${formatBytes(summary.outputBytes)} · ${changePhrase(summary.inputBytes, summary.outputBytes)}`,
68
- ];
69
- const warnings = summary.results.flatMap((r) => r.warnings);
70
- if (warnings.length > 0) {
71
- lines.push('');
72
- for (const w of warnings)
73
- lines.push(`⚠ ${w.message}`);
74
- }
75
- if (output)
76
- lines.push('', `Output: ${output}`);
77
- return lines;
78
- }
79
- /**
80
- * A page operation's result names its outputs instead of showing a size
81
- * change — "4.2 MB → 4.3 MB" says nothing useful for a split into 4 files,
82
- * unlike a conversion where the before/after size is the whole point.
83
- */
84
- export function reportPageOp(summary, where = {}) {
85
- const outputs = summary.results.flatMap((r) => r.job.outputs);
86
- const names = outputs.map((o) => basename(o)).join(', ');
87
- const noun = outputs.length === 1 ? 'file' : 'files';
88
- const folder = outputs[0] === undefined ? '' : inFolder(outputs[0], where);
89
- const lines = [`✓ ${outputs.length} ${noun} · ${names}${folder}`];
90
- const warnings = summary.results.flatMap((r) => r.warnings);
91
- for (const warning of warnings)
92
- lines.push('', `⚠ ${warning.message}`);
93
- return lines;
94
- }
95
- export function reportFailures(failures, opts) {
96
- if (failures.length === 0)
97
- return [];
98
- const lines = [];
99
- for (const failure of failures) {
100
- lines.push(...renderError(failure.error, { debug: opts.debug }), '');
101
- }
102
- return lines;
103
- }
104
- export function reportFormats() {
105
- const readable = new Set(readableFormats());
106
- const writable = new Set(writableFormats());
107
- const lines = ['Formats', ''];
108
- for (const id of readable) {
109
- const spec = FORMATS[id];
110
- const capability = writable.has(id) ? 'read and write' : 'read only';
111
- lines.push(` ${spec.label.padEnd(6)} ${spec.extensions.join(' ').padEnd(12)} ${capability}`);
112
- }
113
- // Derived from the capability table, not hardcoded — this would otherwise
114
- // become a lie the day any engine can encode a format it currently cannot.
115
- const readOnly = [...readable].filter((id) => !writable.has(id)).map((id) => FORMATS[id].label);
116
- if (readOnly.length > 0) {
117
- const names = readOnly.join(', ');
118
- const [verb, noun] = readOnly.length === 1 ? ['is', 'it'] : ['are', 'them'];
119
- lines.push('', `${names} ${verb} read only because Forge cannot yet write ${noun}.`);
120
- }
121
- return lines;
122
- }
123
- //# sourceMapp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AC,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC3E,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,KAAK,IAAI,IAAI,6CAA6C,IAAI,GAAG,CAAC,CAAA;IACtF,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -1,60 +0,0 @@
1
- /**
2
- * A one-line, redraw-in-place progress indicator for work that takes long
3
- * enough to look like a hang.
4
- *
5
- * The case it exists for: compressing a PDF to a target size runs a
6
- * two-dimensional search — a quality bisection at each of up to four
7
- * resolutions — which takes four to six seconds on a large scan. Silence for
8
- * that long reads as a crash.
9
- *
10
- * **The spinner supplies motion, never information.** Invariant 7 forbids
11
- * inventing progress, and a percentage here would be invented: the search
12
- * cannot know which resolution rung will succeed until it tries. What it does
13
- * know is its position inside the current rung — `attempt 3 of 8` is a real
14
- * index in a bounded sequence — so the caller passes that text in and this
15
- * only animates beside it. Nothing here computes a number.
16
- *
17
- * Writes to the stream it is handed, and only when that stream is a terminal:
18
- * a piped or CI run must stay byte-clean, since frames in captured output
19
- * would corrupt whatever is reading it.
20
- */
21
- /** Braille dots: one column wide in every terminal font that has them. */
22
- const FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
23
- export function startSpinner(stream, label) {
24
- // A non-terminal gets a spinner that does nothing at all, rather than a
25
- // conditional at every call site.
26
- if (stream.isTTY !== true) {
27
- return { update: () => { }, tick: () => { }, stop: () => { } };
28
- }
29
- let frame = 0;
30
- let text = '';
31
- let stopped = false;
32
- // Long enough to erase the previous line whatever it was; the frame, the
33
- // label and the longest status together stay well inside this.
34
- const WIDTH = 60;
35
- const draw = () => {
36
- if (stopped)
37
- return;
38
- stream.write(`\r${' '.repeat(WIDTH)}\r${FRAMES[frame % FRAMES.length]} ${label}${text}`);
39
- };
40
- return {
41
- update(next) {
42
- text = next === '' ? '' : ` · ${next}`;
43
- frame++;
44
- draw();
45
- },
46
- tick() {
47
- frame++;
48
- draw();
49
- },
50
- stop() {
51
- if (stopped)
52
- return;
53
- stopped = true;
54
- // Blank the line and return the cursor, so whatever prints next starts
55
- // at column zero with nothing in front of it.
56
- stream.write(`\r${' '.repeat(WIDTH)}\r`);
57
- },
58
- };
59
- }
60
- //# sourceMappingURL=spinner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spinner.js","sourceRoot":"","sources":["../../src/cli/spinner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,0EAA0E;AAC1E,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAgBjE,MAAM,UAAU,YAAY,CAAC,MAAgB,EAAE,KAAa;IAC1D,wEAAwE;IACxE,kCAAkC;IAClC,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;QAC1B,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAA;IAC7D,CAAC;IAED,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,IAAI,GAAG,EAAE,CAAA;IACb,IAAI,OAAO,GAAG,KAAK,CAAA;IACnB,yEAAyE;IACzE,+DAA+D;IAC/D,MAAM,KAAK,GAAG,EAAE,CAAA;IAEhB,MAAM,IAAI,GAAG,GAAG,EAAE;QAChB,IAAI,OAAO;YAAE,OAAM;QACnB,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,GAAG,IAAI,EAAE,CAAC,CAAA;IAC1F,CAAC,CAAA;IAED,OAAO;QACL,MAAM,CAAC,IAAY;YACjB,IAAI,GAAG,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAA;YACtC,KAAK,EAAE,CAAA;YACP,IAAI,EAAE,CAAA;QACR,CAAC;QACD,IAAI;YACF,KAAK,EAAE,CAAA;YACP,IAAI,EAAE,CAAA;QACR,CAAC;QACD,IAAI;YACF,IAAI,OAAO;gBAAE,OAAM;YACnB,OAAO,GAAG,IAAI,CAAA;YACd,uEAAuE;YACvE,8CAA8C;YAC9C,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC1C,CAAC;KACF,CAAA;AACH,CAAC"}
package/dist/cli/stdin.js DELETED
@@ -1,47 +0,0 @@
1
- import { createInterface } from 'node:readline';
2
- import { PassThrough } from 'node:stream';
3
- /**
4
- * A password, never from argv.
5
- *
6
- * An argument lands in shell history and in `ps` output, and PDF passwords
7
- * are reused often enough that leaking one leaks more than one file. Reading
8
- * stdin or prompting costs the same keystrokes and avoids both.
9
- */
10
- export async function readPassword(opts) {
11
- if (opts.stdin) {
12
- const chunks = [];
13
- for await (const chunk of process.stdin)
14
- chunks.push(Buffer.from(chunk));
15
- return Buffer.concat(chunks)
16
- .toString('utf8')
17
- .replace(/\r?\n$/, '');
18
- }
19
- // Use a null stream for readline's output to prevent echoing typed characters.
20
- // readline writes input echo to this stream, which we buffer but do not forward to
21
- // stderr. We write the prompt manually to stderr instead, and supply the newline
22
- // after the user presses Enter, since readline's line-submit writes to the buffered
23
- // output stream that never reaches the terminal.
24
- const nullOutput = new PassThrough();
25
- // CRITICAL: terminal:true engages raw mode on real TTYs, disabling OS line discipline
26
- // echo. Dropping this flag causes the kernel to echo typed characters in plaintext.
27
- // No test catches this regression — the test suite uses Readable.from() which is
28
- // never a TTY, so has no kernel echo to suppress. This only breaks on real terminals.
29
- const rl = createInterface({ input: process.stdin, output: nullOutput, terminal: true });
30
- try {
31
- process.stderr.write('Password: ');
32
- // Use empty string for prompt since we already wrote it; readline would
33
- // append it to the line but we've handled it separately.
34
- return await new Promise((resolve) => rl.question('', resolve));
35
- }
36
- finally {
37
- process.stderr.write('\n');
38
- // Releases stdin: readline removes its 'keypress' listener and pauses the stream.
39
- // The finally guarantees it runs whether the promise resolves or rejects.
40
- // Covered by 'releases stdin when the prompt completes' in tests/cli/stdin.test.ts,
41
- // which asserts no 'keypress' listener survives. That test must feed stdin from a
42
- // stream that stays open — Readable.from() ends immediately and readline auto-closes
43
- // on the input's 'end' event, which would mask this call and make the test hollow.
44
- rl.close();
45
- }
46
- }
47
- //# sourceMappingURL=stdin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stdin.js","sourceRoot":"","sources":["../../src/cli/stdin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAwB;IACzD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAa,EAAE,CAAA;QAC3B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,OAAO,CAAC,KAAK;YAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;QACxE,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;aACzB,QAAQ,CAAC,MAAM,CAAC;aAChB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAC1B,CAAC;IAED,+EAA+E;IAC/E,mFAAmF;IACnF,iFAAiF;IACjF,oFAAoF;IACpF,iDAAiD;IACjD,MAAM,UAAU,GAAG,IAAI,WAAW,EAAE,CAAA;IACpC,sFAA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