onionskin-cli 0.0.0-stage → 0.0.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.
- package/CHANGELOG.md +136 -0
- package/INSTALL.md +17 -0
- package/LICENSE +21 -0
- package/NOTICE +46 -0
- package/README.md +88 -2
- package/docs/contracts/batch.schema.json +839 -0
- package/docs/contracts/history.schema.json +126 -0
- package/docs/contracts/ops.schema.json +541 -0
- package/package.json +54 -4
- package/scripts/checker/check.py +411 -0
- package/scripts/checker/requirements.txt +5 -0
- package/scripts/install-check.mjs +9 -0
- package/scripts/requirements.txt +5 -0
- package/scripts/rewriter/apple/main.swift +135 -0
- package/scripts/rewriter/apple/onionskin-fm +0 -0
- package/scripts/rewriter/apple/onionskin-fm.json +6 -0
- package/skills/onionskin/SKILL.md +117 -0
- package/skills/onionskin/reference/batch.md +94 -0
- package/skills/onionskin/reference/formats.md +15 -0
- package/skills/onionskin/reference/ops.md +253 -0
- package/skills/onionskin/reference/troubleshooting.md +73 -0
- package/skills/onionskin/reference/voice-guide.md +86 -0
- package/skills/onionskin/voice.example.md +51 -0
- package/src/agent-detect.js +149 -0
- package/src/agent-events.js +159 -0
- package/src/agent-prompt.js +27 -0
- package/src/agent-runner.js +593 -0
- package/src/analyze.js +17 -0
- package/src/anchors.js +190 -0
- package/src/apply.js +387 -0
- package/src/auth.js +130 -0
- package/src/batch.js +322 -0
- package/src/check-worker.js +8 -0
- package/src/checker.js +293 -0
- package/src/cli.js +516 -0
- package/src/constants.js +20 -0
- package/src/diff.js +267 -0
- package/src/doctor.js +247 -0
- package/src/docx.js +438 -0
- package/src/fmt.js +30 -0
- package/src/fsutil.js +348 -0
- package/src/history-worker.js +16 -0
- package/src/history.js +576 -0
- package/src/lease.js +79 -0
- package/src/local.js +242 -0
- package/src/merge-pptx.js +198 -0
- package/src/merge-xlsx.js +453 -0
- package/src/merge.js +410 -0
- package/src/offload.js +34 -0
- package/src/ops/common.js +48 -0
- package/src/ops/docx-table.js +323 -0
- package/src/ops/docx.js +503 -0
- package/src/ops/engine.js +41 -0
- package/src/ops/pptx.js +336 -0
- package/src/ops/run.js +115 -0
- package/src/ops/runs.js +127 -0
- package/src/ops/schema.js +109 -0
- package/src/ops/xlsx.js +277 -0
- package/src/package.js +189 -0
- package/src/paths.js +64 -0
- package/src/person.js +66 -0
- package/src/pptx.js +194 -0
- package/src/question.js +47 -0
- package/src/quick-plan.js +107 -0
- package/src/quick.js +164 -0
- package/src/redline-check.js +251 -0
- package/src/redline-worker.js +29 -0
- package/src/redline.js +438 -0
- package/src/reply.js +410 -0
- package/src/review.js +274 -0
- package/src/rewrite-check.js +1014 -0
- package/src/rewriter-cleanup.js +105 -0
- package/src/rewriter-setup.js +104 -0
- package/src/rewriter.js +396 -0
- package/src/sanitize.js +42 -0
- package/src/sentence-span.js +25 -0
- package/src/server-entry.js +13 -0
- package/src/server.js +576 -0
- package/src/session.js +1910 -0
- package/src/settings.js +161 -0
- package/src/setup.js +160 -0
- package/src/stamp-words.js +10 -0
- package/src/stamps.js +59 -0
- package/src/style.js +110 -0
- package/src/suggest-reply.js +84 -0
- package/src/suggest.js +261 -0
- package/src/text.js +31 -0
- package/src/tracked-words.js +43 -0
- package/src/voice-guide.js +182 -0
- package/src/voice-learn.js +314 -0
- package/src/voice-sample-worker.js +95 -0
- package/src/voice-samples.js +329 -0
- package/src/voice-store.js +305 -0
- package/src/voice-worker.js +28 -0
- package/src/voice.js +297 -0
- package/src/xlsx.js +454 -0
- package/src/xml-tree.js +118 -0
- package/src/xml.js +127 -0
- package/src/zip-write.js +74 -0
- package/src/zip.js +88 -0
- package/vendor/engine/DocViewer-BZLXUcxJ.js +15137 -0
- package/vendor/engine/THIRD_PARTY_LICENSES.txt +79 -0
- package/vendor/engine/collab-BVynXMqc.js +2591 -0
- package/vendor/engine/collab.js +2 -0
- package/vendor/engine/core.js +4 -0
- package/vendor/engine/default-worker-DogNT09A.js +35625 -0
- package/vendor/engine/embed.js +107 -0
- package/vendor/engine/index.js +5 -0
- package/vendor/engine/office-engine.embed.js +184 -0
- package/vendor/engine/office-engine.worker.js +36030 -0
- package/vendor/engine/xlsx-ops-SYAv6V0f.js +939 -0
- package/vendor/engine-node/LICENSE +21 -0
- package/vendor/engine-node/engine-node.mjs +46618 -0
- package/vendor/engine.lock.json +26 -0
- package/web/dist/assets/index-CFISATkn.js +197 -0
- package/web/dist/assets/index-spXE4oTz.css +1 -0
- package/web/dist/index.html +14 -0
package/src/ops/pptx.js
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { partRels } from "../package.js";
|
|
2
|
+
import { openZip } from "../zip.js";
|
|
3
|
+
import { checkExpect, engineFailure, excerpt, fail, refused } from "./common.js";
|
|
4
|
+
import { openEngine } from "./engine.js";
|
|
5
|
+
import { findAll, partialWords, pickMatches } from "./runs.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* PPTX driver (headless Engine: pptx.slide to read a slide model, pptx.setText to write one shape's paragraphs, pptx.slides to
|
|
9
|
+
* duplicate, delete and move slides: the editor's own slide path). Shapes are addressed by p:sldId id + cNvPr id, slides by p:sldId id;
|
|
10
|
+
* a slide's position is looked up when an op runs, because an earlier slide op of the same file may have moved it.
|
|
11
|
+
* A paragraph the engine marks `ro` is protected and never rewritten.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export async function open({ bytes, name, anchors = new Map() }) {
|
|
15
|
+
const h = await openEngine(bytes, name);
|
|
16
|
+
return { h, slides: h.info.pptx.slides, name, anchors, bytes };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** `{slide_id, shape_id}` as written, or `{anchor_id}` resolved through the delivered batch (the locator carries exactly those two fields). */
|
|
20
|
+
function shapeTarget(st, target) {
|
|
21
|
+
if (!("anchor_id" in target)) return { target };
|
|
22
|
+
const a = st.anchors.get(target.anchor_id);
|
|
23
|
+
if (!a) return { error: `anchor ${target.anchor_id} is not in the batch (pass --batch batch.json, or run inside the session that delivered it)` };
|
|
24
|
+
if (a.locator?.slide_id == null || a.locator?.shape_id == null) return { error: `anchor ${target.anchor_id} does not name a shape (it is a slide-level anchor)` };
|
|
25
|
+
return { target: { slide_id: String(a.locator.slide_id), shape_id: a.locator.shape_id } };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** All shapes with text on a slide model, groups flattened, in document order */
|
|
29
|
+
function shapesOf(els, out = []) {
|
|
30
|
+
for (const el of els || []) {
|
|
31
|
+
if (el.text?.paras) out.push(el);
|
|
32
|
+
if (el.children) shapesOf(el.children, out);
|
|
33
|
+
if (el.els) shapesOf(el.els, out);
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const runText = (r) => (r.br ? "\n" : r.text || "");
|
|
39
|
+
const paraText = (p) => p.runs.map(runText).join("");
|
|
40
|
+
const shapeText = (el) => el.text.paras.map(paraText).join("\n");
|
|
41
|
+
|
|
42
|
+
async function slideModel(st, index) {
|
|
43
|
+
return st.h.engine.call("pptx.slide", [index]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const slideText = (m) => shapesOf(m.els).map(shapeText).join("\n");
|
|
47
|
+
const indexOf = (st, id) => st.slides.findIndex((s) => String(s.id) === String(id));
|
|
48
|
+
|
|
49
|
+
// ---- the package around a slide (read from the file as delivered: only slide ops change it, and they are checked here) ----------------
|
|
50
|
+
// what a copy may share with the slide it was made from: its layout, pictures and links (notes and comments are not copied)
|
|
51
|
+
const COPY_SHARES = new Set(["slideLayout", "image", "hyperlink", "slide", "notesSlide", "comments"]);
|
|
52
|
+
const KIND_NAMES = { chart: "a chart", chartUserShapes: "a chart", diagramData: "a SmartArt diagram", diagramLayout: "a SmartArt diagram", diagramQuickStyle: "a SmartArt diagram", diagramColors: "a SmartArt diagram", diagramDrawing: "a SmartArt diagram", oleObject: "an embedded object", package: "an embedded object", video: "a video", audio: "a sound", media: "media", tags: "tags", vmlDrawing: "a legacy drawing", control: "a control", ink: "ink" };
|
|
53
|
+
|
|
54
|
+
/** Refusals that hold for every slide op of a deck: what the engine would leave out of step. Null when the deck is fine. */
|
|
55
|
+
function deckRefusal(st) {
|
|
56
|
+
const zip = (st.zip ??= openZip(st.bytes));
|
|
57
|
+
const pres = zip.readText("ppt/presentation.xml") || "";
|
|
58
|
+
if (/<(?:\w+:)?section\b/.test(pres)) return refused("deck_has_sections", "the deck has sections; adding, deleting or moving slides would leave the section list out of step");
|
|
59
|
+
if (/<(?:\w+:)?custShow\b/.test(pres)) return refused("deck_has_custom_shows", "the deck has custom shows; adding, deleting or moving slides would leave them out of step");
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
function slidePart(st, id) {
|
|
63
|
+
return st.slides.find((s) => String(s.id) === String(id))?.path || null;
|
|
64
|
+
}
|
|
65
|
+
/** a part of the deck other than the presentation and the slide's own notes that links to the slide (a "go to slide" link, a summary zoom) */
|
|
66
|
+
function linkedFrom(st, part) {
|
|
67
|
+
const zip = st.zip;
|
|
68
|
+
const own = new Set([part, ...partRels(zip, part).filter((r) => r.type === "notesSlide").map((r) => r.target)]);
|
|
69
|
+
for (const name of zip.names) {
|
|
70
|
+
if (!name.endsWith(".rels") || name === "ppt/_rels/presentation.xml.rels") continue;
|
|
71
|
+
const src = name.replace(/_rels\/([^/]+)\.rels$/, "$1");
|
|
72
|
+
if (own.has(src)) continue;
|
|
73
|
+
if (partRels(zip, src).some((r) => !r.external && r.target === part)) return src;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function findShape(st, rawTarget) {
|
|
79
|
+
const t = shapeTarget(st, rawTarget);
|
|
80
|
+
if (t.error) return fail("anchor_not_found", t.error);
|
|
81
|
+
const target = t.target;
|
|
82
|
+
const slide = st.slides.find((s) => String(s.id) === target.slide_id);
|
|
83
|
+
if (!slide) return fail("anchor_not_found", `no slide with id ${target.slide_id}`);
|
|
84
|
+
const m = await slideModel(st, slide.index);
|
|
85
|
+
const hits = shapesOf(m.els).filter((e) => e.sid === target.shape_id);
|
|
86
|
+
if (hits.length !== 1) return fail("anchor_not_found", hits.length ? `shape id ${target.shape_id} is ambiguous on slide ${target.slide_id}` : `no shape with text and id ${target.shape_id} on slide ${target.slide_id}`);
|
|
87
|
+
return { slide, el: hits[0] };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function bind(st, op) {
|
|
91
|
+
switch (op.op) {
|
|
92
|
+
case "set_shape_text":
|
|
93
|
+
case "replace_text_in_shape": {
|
|
94
|
+
const f = await findShape(st, op.target);
|
|
95
|
+
if (!f.el) return f;
|
|
96
|
+
const bad = checkExpect(op.expect, shapeText(f.el), "contains");
|
|
97
|
+
if (bad) return bad;
|
|
98
|
+
const ro = f.el.text.paras.filter((p) => p.ro);
|
|
99
|
+
if (ro.length && op.op === "set_shape_text") return fail("skipped_protected", `${ro.length} paragraph(s) of this shape are protected (equations, unmodeled fields); not rewritten`);
|
|
100
|
+
if (op.op === "set_shape_text" && f.el.text.paras.some((p) => p.runs.some((r) => r.fld))) return refused("shape_has_fields", "the shape holds a field (slide number, date); use replace_text_in_shape");
|
|
101
|
+
return { ok: true, op, slide: f.slide.index, sid: f.el.sid, target: { slide_id: String(f.slide.id), shape_id: f.el.sid } };
|
|
102
|
+
}
|
|
103
|
+
case "replace_all_text": {
|
|
104
|
+
const hits = [];
|
|
105
|
+
for (const s of st.slides) {
|
|
106
|
+
const m = await slideModel(st, s.index);
|
|
107
|
+
for (const el of shapesOf(m.els)) {
|
|
108
|
+
el.text.paras.forEach((p, pi) => {
|
|
109
|
+
const text = paraText(p);
|
|
110
|
+
const n = findAll(text, op.find, op.match_case !== false).length;
|
|
111
|
+
if (n) hits.push({ slideId: String(s.id), sid: el.sid, pi, n, ro: !!p.ro, text });
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const total = hits.reduce((n, x) => n + x.n, 0);
|
|
116
|
+
const extra = { partial_words: hits.reduce((n, x) => n + partialWords(x.text, op.find, op.match_case !== false), 0), protected: hits.reduce((n, x) => n + (x.ro ? x.n : 0), 0) };
|
|
117
|
+
if (total !== op.expect.count) return fail("expect_mismatch", `found ${total} occurrence(s), expected ${op.expect.count}`, { found: total, ...extra });
|
|
118
|
+
return { ok: true, op, hits, total, ...extra };
|
|
119
|
+
}
|
|
120
|
+
case "duplicate_slide":
|
|
121
|
+
case "delete_slide":
|
|
122
|
+
case "move_slide":
|
|
123
|
+
return bindSlide(st, op);
|
|
124
|
+
default:
|
|
125
|
+
return refused("unsupported_op", `${op.op} does not apply to a .pptx`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A slide by id, its `expect` against the text of its shapes (joined by LF), and what the deck or the slide cannot take. */
|
|
130
|
+
async function bindSlide(st, op) {
|
|
131
|
+
const i = indexOf(st, op.target.slide_id);
|
|
132
|
+
if (i < 0) return fail("anchor_not_found", `no slide with id ${op.target.slide_id}`);
|
|
133
|
+
const m = await slideModel(st, i);
|
|
134
|
+
const bad = checkExpect(op.expect, slideText(m), "contains");
|
|
135
|
+
if (bad) return bad;
|
|
136
|
+
const deck = deckRefusal(st);
|
|
137
|
+
if (deck) return deck;
|
|
138
|
+
if (op.to) {
|
|
139
|
+
if (indexOf(st, op.to.slide_id) < 0) return fail("anchor_not_found", `no slide with id ${op.to.slide_id} (to)`);
|
|
140
|
+
if (op.op === "move_slide" && op.to.slide_id === op.target.slide_id) return refused("move_onto_itself", "a slide cannot be moved next to itself");
|
|
141
|
+
}
|
|
142
|
+
const part = slidePart(st, op.target.slide_id);
|
|
143
|
+
if (op.op === "delete_slide") {
|
|
144
|
+
if (st.slides.length <= 1) return refused("last_slide", "the deck has only this slide");
|
|
145
|
+
const from = linkedFrom(st, part);
|
|
146
|
+
if (from) return refused("slide_is_linked", `another part of the deck links to this slide (${from}); remove the link first`);
|
|
147
|
+
}
|
|
148
|
+
if (op.op === "duplicate_slide") {
|
|
149
|
+
const other = partRels(st.zip, part).filter((r) => !COPY_SHARES.has(r.type));
|
|
150
|
+
if (other.length) {
|
|
151
|
+
const what = [...new Set(other.map((r) => KIND_NAMES[r.type] || `a part of type ${r.type}`))].join(", ");
|
|
152
|
+
return refused(other.some((r) => r.type === "chart") ? "slide_has_chart" : "slide_has_shared_parts", `the slide holds ${what}, which a copy would share with it; slides with charts or embedded parts cannot be duplicated here`);
|
|
153
|
+
}
|
|
154
|
+
for (const sh of op.shapes || []) {
|
|
155
|
+
const hits = shapesOf(m.els).filter((e) => e.sid === sh.shape_id);
|
|
156
|
+
if (hits.length !== 1) return fail("anchor_not_found", hits.length ? `shape id ${sh.shape_id} is ambiguous on slide ${op.target.slide_id}` : `no shape with text and id ${sh.shape_id} on slide ${op.target.slide_id}`);
|
|
157
|
+
const ro = hits[0].text.paras.filter((p) => p.ro);
|
|
158
|
+
if (ro.length) return fail("skipped_protected", `${ro.length} paragraph(s) of shape ${sh.shape_id} are protected (equations, unmodeled fields); not rewritten`);
|
|
159
|
+
if (hits[0].text.paras.some((p) => p.runs.some((r) => r.fld))) return refused("shape_has_fields", `shape ${sh.shape_id} holds a field (slide number, date); its text cannot be set here`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return { ok: true, op };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** PParaSpec[] for the shape as it is now; `edit(paraIndex, runs)` may change one paragraph's runs (specs for the rest echo the model) */
|
|
166
|
+
function specsOf(el, edit) {
|
|
167
|
+
return el.text.paras.map((p, pi) => {
|
|
168
|
+
const runs = p.runs.map((r) => (r.fld ? { text: r.text, src: r.src, fld: true } : { text: runText(r), src: r.src }));
|
|
169
|
+
return { k: p.k ?? pi, runs: edit?.(pi, runs) ?? runs };
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** set_shape_text's specs: one paragraph per string; existing paragraphs keep their formatting, extra ones copy the last */
|
|
174
|
+
function textSpecs(el, paragraphs) {
|
|
175
|
+
const cur = specsOf(el);
|
|
176
|
+
const first = el.text.paras[0]?.runs.find((r) => !r.fld && !r.br);
|
|
177
|
+
return paragraphs.map((text, i) => {
|
|
178
|
+
const base = cur[Math.min(i, cur.length - 1)];
|
|
179
|
+
const src = (el.text.paras[Math.min(i, cur.length - 1)]?.runs.find((r) => !r.fld && !r.br) || first)?.src;
|
|
180
|
+
return { ...(i < cur.length ? { k: base.k } : { k: undefined }), ...(base?.algn ? { algn: base.algn } : {}), runs: [{ text, src }] };
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* One slide op through the engine's pptx.slides, by slide id. The engine skips an op it cannot do without saying so, so the slide list it
|
|
186
|
+
* returns is checked against what the op must leave (one more slide right where asked, one fewer, the same set in a new order).
|
|
187
|
+
*/
|
|
188
|
+
async function execSlide(st, op) {
|
|
189
|
+
const before = st.slides.map((s) => String(s.id));
|
|
190
|
+
const from = before.indexOf(op.target.slide_id);
|
|
191
|
+
if (from < 0) return fail("anchor_not_found", `slide ${op.target.slide_id} was deleted by an earlier op of this file`);
|
|
192
|
+
const call = async (args) => (st.slides = (await st.h.engine.call("pptx.slides", [args])).slides);
|
|
193
|
+
/** the engine's `move` index for "before/after `to`": it takes the slide out first, then inserts it at that index of the rest */
|
|
194
|
+
const moveTo = (ids, moving, to, where) => {
|
|
195
|
+
const rest = ids.filter((x) => x !== moving);
|
|
196
|
+
const at = rest.indexOf(to);
|
|
197
|
+
return at < 0 ? -1 : where === "after" ? at + 1 : at;
|
|
198
|
+
};
|
|
199
|
+
const same = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
|
|
200
|
+
if (op.op === "delete_slide") {
|
|
201
|
+
if (before.length <= 1) return refused("last_slide", "the deck has only this slide");
|
|
202
|
+
await call({ op: "delete", index: from });
|
|
203
|
+
if (!same(st.slides.map((s) => String(s.id)), before.filter((x) => x !== op.target.slide_id))) return { ...refused("slide_op_not_applied", "the engine did not delete the slide"), dirty: true };
|
|
204
|
+
return { status: "applied" };
|
|
205
|
+
}
|
|
206
|
+
if (op.op === "move_slide") {
|
|
207
|
+
const to = moveTo(before, op.target.slide_id, op.to.slide_id, op.where);
|
|
208
|
+
if (to < 0) return fail("anchor_not_found", `slide ${op.to.slide_id} (to) was deleted by an earlier op of this file`);
|
|
209
|
+
await call({ op: "move", from, to });
|
|
210
|
+
const want = before.filter((x) => x !== op.target.slide_id);
|
|
211
|
+
want.splice(to, 0, op.target.slide_id);
|
|
212
|
+
if (!same(st.slides.map((s) => String(s.id)), want)) return { ...refused("slide_op_not_applied", "the engine did not move the slide"), dirty: true };
|
|
213
|
+
return { status: "applied" };
|
|
214
|
+
}
|
|
215
|
+
// duplicate: the copy lands right after its slide; then, when asked, it moves; then its shapes get their text
|
|
216
|
+
if (op.to && !before.includes(op.to.slide_id)) return fail("anchor_not_found", `slide ${op.to.slide_id} (to) was deleted by an earlier op of this file`);
|
|
217
|
+
await call({ op: "duplicate", index: from });
|
|
218
|
+
const ids = st.slides.map((s) => String(s.id));
|
|
219
|
+
const copy = ids[from + 1];
|
|
220
|
+
if (ids.length !== before.length + 1 || before.includes(copy) || !same(ids.filter((x) => x !== copy), before)) return { ...refused("slide_op_not_applied", "the engine did not duplicate the slide"), dirty: true };
|
|
221
|
+
if (op.to) {
|
|
222
|
+
const to = moveTo(ids, copy, op.to.slide_id, op.where);
|
|
223
|
+
await call({ op: "move", from: from + 1, to });
|
|
224
|
+
if (st.slides.map((s) => String(s.id)).indexOf(copy) !== to) return { ...refused("slide_op_not_applied", "the engine did not move the copy"), dirty: true };
|
|
225
|
+
}
|
|
226
|
+
const at = indexOf(st, copy);
|
|
227
|
+
for (const sh of op.shapes || []) {
|
|
228
|
+
const el = shapesOf((await slideModel(st, at)).els).find((e) => e.sid === sh.shape_id);
|
|
229
|
+
if (!el) return { ...fail("anchor_not_found", `shape ${sh.shape_id} is not on the copy`), dirty: true };
|
|
230
|
+
await st.h.engine.call("pptx.setText", [at, el.sid, textSpecs(el, sh.paragraphs)]);
|
|
231
|
+
}
|
|
232
|
+
return { status: "applied", detail: { slide_id: copy } }; // the copy's id: its position may change with a later op of this file
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** replaces [s,e) of a paragraph's concatenated run texts; the first run in range carries the replacement and the formatting */
|
|
236
|
+
function replaceInRuns(runs, s, e, replacement) {
|
|
237
|
+
let pos = 0;
|
|
238
|
+
const out = runs.map((r) => ({ ...r }));
|
|
239
|
+
let first = -1;
|
|
240
|
+
out.forEach((r, i) => {
|
|
241
|
+
const a = pos;
|
|
242
|
+
const b = pos + r.text.length;
|
|
243
|
+
pos = b;
|
|
244
|
+
if (b <= s || a >= e) return;
|
|
245
|
+
if (r.fld) throw new RangeError("the match is inside a field");
|
|
246
|
+
const head = r.text.slice(0, Math.max(0, s - a));
|
|
247
|
+
const tail = r.text.slice(Math.min(r.text.length, e - a));
|
|
248
|
+
if (first < 0) {
|
|
249
|
+
first = i;
|
|
250
|
+
r.text = head + replacement + (e <= b ? tail : "");
|
|
251
|
+
} else r.text = e <= b ? tail : "";
|
|
252
|
+
});
|
|
253
|
+
return out.filter((r, i) => r.text !== "" || i === first || r.fld);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export async function exec(st, b) {
|
|
257
|
+
const { op } = b;
|
|
258
|
+
try {
|
|
259
|
+
if (op.op === "set_shape_text") {
|
|
260
|
+
const f = await findShape(st, b.target);
|
|
261
|
+
if (!f.el) return f;
|
|
262
|
+
const specs = textSpecs(f.el, op.paragraphs);
|
|
263
|
+
await st.h.engine.call("pptx.setText", [f.slide.index, f.el.sid, specs]);
|
|
264
|
+
return { status: "applied", detail: { paragraphs: specs.length } };
|
|
265
|
+
}
|
|
266
|
+
if (op.op === "duplicate_slide" || op.op === "delete_slide" || op.op === "move_slide") return await execSlide(st, op);
|
|
267
|
+
if (op.op === "replace_text_in_shape") {
|
|
268
|
+
const f = await findShape(st, b.target);
|
|
269
|
+
if (!f.el) return f;
|
|
270
|
+
const slideIndex = f.slide.index;
|
|
271
|
+
const hits = [];
|
|
272
|
+
f.el.text.paras.forEach((p, pi) => findAll(paraText(p), op.find, op.match_case !== false).forEach((at) => hits.push({ pi, at })));
|
|
273
|
+
const pick = pickMatches(hits.map((_, i) => i), op);
|
|
274
|
+
if (pick.error) return fail("anchor_not_found", pick.error);
|
|
275
|
+
const chosen = pick.starts.map((i) => hits[i]);
|
|
276
|
+
const blocked = chosen.filter((h) => f.el.text.paras[h.pi].ro);
|
|
277
|
+
if (blocked.length) return fail("skipped_protected", "the match is in a protected paragraph", { detail: { skipped_protected: blocked.map((h) => ({ paragraph: h.pi, excerpt: excerpt(paraText(f.el.text.paras[h.pi])) })) } });
|
|
278
|
+
const byPara = new Map();
|
|
279
|
+
for (const h of chosen) byPara.set(h.pi, [...(byPara.get(h.pi) || []), h.at]);
|
|
280
|
+
const specs = specsOf(f.el, (pi, runs) => {
|
|
281
|
+
const ats = byPara.get(pi);
|
|
282
|
+
if (!ats) return null;
|
|
283
|
+
for (const at of [...ats].sort((x, y) => y - x)) runs = replaceInRuns(runs, at, at + op.find.length, op.replace);
|
|
284
|
+
return runs;
|
|
285
|
+
});
|
|
286
|
+
await st.h.engine.call("pptx.setText", [slideIndex, f.el.sid, specs]);
|
|
287
|
+
return { status: "applied", detail: { replaced: chosen.length } };
|
|
288
|
+
}
|
|
289
|
+
if (op.op === "replace_all_text") {
|
|
290
|
+
const skipped = [];
|
|
291
|
+
let n = 0;
|
|
292
|
+
let skippedMatches = 0;
|
|
293
|
+
const bySlide = new Map();
|
|
294
|
+
for (const h of b.hits) bySlide.set(`${h.slideId}:${h.sid}`, [...(bySlide.get(`${h.slideId}:${h.sid}`) || []), h]);
|
|
295
|
+
for (const [key, hs] of bySlide) {
|
|
296
|
+
const [slideId, sid] = key.split(":");
|
|
297
|
+
const slide = indexOf(st, slideId); // by id: an earlier slide op of this file may have moved or removed it
|
|
298
|
+
const m = slide >= 0 ? await slideModel(st, slide) : { els: [] };
|
|
299
|
+
const el = shapesOf(m.els).find((e) => e.sid === Number(sid));
|
|
300
|
+
if (!el) {
|
|
301
|
+
skippedMatches += hs.reduce((a, h) => a + h.n, 0);
|
|
302
|
+
skipped.push({ slide: slideId, shape_id: Number(sid), reason: slide < 0 ? "the slide is gone" : "the shape is gone" });
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
const todo = new Set(hs.filter((h) => !h.ro).map((h) => h.pi));
|
|
306
|
+
for (const h of hs.filter((x) => x.ro)) {
|
|
307
|
+
skipped.push({ slide: slideId, shape_id: Number(sid), paragraph: h.pi, excerpt: excerpt(paraText(el.text.paras[h.pi])) });
|
|
308
|
+
skippedMatches += h.n;
|
|
309
|
+
}
|
|
310
|
+
if (!todo.size) continue;
|
|
311
|
+
const specs = specsOf(el, (pi, runs) => {
|
|
312
|
+
if (!todo.has(pi)) return null;
|
|
313
|
+
const ats = findAll(runs.map((r) => r.text).join(""), op.find, op.match_case !== false);
|
|
314
|
+
for (const at of [...ats].sort((x, y) => y - x)) runs = replaceInRuns(runs, at, at + op.find.length, op.replace);
|
|
315
|
+
n += ats.length;
|
|
316
|
+
return runs;
|
|
317
|
+
});
|
|
318
|
+
await st.h.engine.call("pptx.setText", [slide, Number(sid), specs]);
|
|
319
|
+
}
|
|
320
|
+
if (n + skippedMatches !== b.total) return { ...refused("incomplete_replace", `replaced ${n} and listed ${skippedMatches} of ${b.total} match(es)`), dirty: true };
|
|
321
|
+
if (!n && skipped.length) return { status: "skipped_protected", reason: "every shape with a match is protected", detail: { skipped_protected: skipped } };
|
|
322
|
+
return { status: "applied", detail: { replaced: n, ...(skipped.length ? { skipped_protected: skipped } : {}) } };
|
|
323
|
+
}
|
|
324
|
+
} catch (err) {
|
|
325
|
+
if (err instanceof RangeError) return refused("match_in_field", err.message);
|
|
326
|
+
return engineFailure(err);
|
|
327
|
+
}
|
|
328
|
+
return refused("unsupported_op", op.op);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export async function save(st) {
|
|
332
|
+
const blob = await st.h.engine.call("save", []);
|
|
333
|
+
return Buffer.from(await blob.arrayBuffer());
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export const close = (st) => st.h.engine.dispose();
|
package/src/ops/run.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { nodeChecks } from "../package.js";
|
|
2
|
+
import * as docx from "./docx.js";
|
|
3
|
+
import * as pptx from "./pptx.js";
|
|
4
|
+
import * as xlsx from "./xlsx.js";
|
|
5
|
+
|
|
6
|
+
const DRIVERS = { docx, xlsx, pptx };
|
|
7
|
+
// ops whose job is to remove or rewrite content: a lower count of drawings/links/bookmarks is then expected, not damage
|
|
8
|
+
const REWRITES = new Set(["delete_paragraph", "set_table_cell_text", "set_shape_text", "delete_rows", "delete_columns", "delete_table_row", "delete_table_column", "delete_slide"]);
|
|
9
|
+
const BLOCKING = new Set(["invalid_package", "part_removed", "relationship_target_missing"]);
|
|
10
|
+
|
|
11
|
+
/** The package-check flags that stop a write. Fewer elements are fine only after a rewrite; a slide may only go when an op deleted one. */
|
|
12
|
+
export const blockingFlags = (flags, { rewrites, slideDeleted }) => flags.filter((f) => BLOCKING.has(f.code) || (f.code === "count_decreased" && !rewrites) || (f.code === "slide_removed" && !slideDeleted));
|
|
13
|
+
|
|
14
|
+
const shape = (i, op, r) => {
|
|
15
|
+
const { ok, dirty, ...rest } = r; // `dirty` is the runner's own signal, not part of the report
|
|
16
|
+
return { index: i, op: op.op, ...(op.id ? { id: op.id } : {}), ...rest };
|
|
17
|
+
};
|
|
18
|
+
/** Nothing reached disk: an op must not read `applied`. Keeps what the op did as `would_have` for the agent. */
|
|
19
|
+
export function demote(results, reason) {
|
|
20
|
+
return results.map((r) => (r.status === "applied" ? { index: r.index, op: r.op, ...(r.id ? { id: r.id } : {}), status: "not_applied", reason, ...(r.detail ? { would_have: r.detail } : {}) } : r));
|
|
21
|
+
}
|
|
22
|
+
const notApplied = (i, op, why) => ({ index: i, op: op.op, ...(op.id ? { id: op.id } : {}), status: "not_applied", reason: why });
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Runs `ops` against `bytes`. Phase 1 binds every op (anchor + expect) against the untouched file; phase 2 executes in order.
|
|
26
|
+
* The engine cannot roll back, so nothing is saved unless the set is acceptable: atomic mode stops at the first op that
|
|
27
|
+
* does not apply; partial mode restarts from the original bytes without an op whose execution threw, then keeps the rest.
|
|
28
|
+
* Returns {results, bytes (null = nothing to write), warnings, blocked}.
|
|
29
|
+
*/
|
|
30
|
+
export async function runOps({ bytes, format, name, ops, partial = false, anchors = new Map() }) {
|
|
31
|
+
const driver = DRIVERS[format];
|
|
32
|
+
const excluded = new Map();
|
|
33
|
+
for (let pass = 0; pass <= ops.length; pass++) {
|
|
34
|
+
const st = await driver.open({ bytes, name, anchors });
|
|
35
|
+
try {
|
|
36
|
+
const results = new Array(ops.length);
|
|
37
|
+
const bound = new Array(ops.length);
|
|
38
|
+
for (const [i, op] of ops.entries()) {
|
|
39
|
+
if (excluded.has(i)) results[i] = shape(i, op, excluded.get(i));
|
|
40
|
+
else {
|
|
41
|
+
const b = await driver.bind(st, op);
|
|
42
|
+
if (b.ok) bound[i] = b;
|
|
43
|
+
else results[i] = shape(i, op, b);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const bindFailed = results.some(Boolean);
|
|
47
|
+
let stop = bindFailed && !partial;
|
|
48
|
+
let restart = false;
|
|
49
|
+
for (let i = 0; i < ops.length && !restart; i++) {
|
|
50
|
+
if (!bound[i]) continue;
|
|
51
|
+
if (stop) {
|
|
52
|
+
results[i] = notApplied(i, ops[i], "atomic mode: another op did not apply, so nothing was written");
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const r = await driver.exec(st, bound[i]);
|
|
56
|
+
// document-wide ops are COUNTED against the file as delivered (bind) but run after the earlier ops of this file: say so when that bites
|
|
57
|
+
if (r.code === "incomplete_replace" && results.some((x) => x?.status === "applied")) r.reason += ". An earlier op of this file changed text this op matches: put document-wide ops (replace_all_text, format_all) first in the ops file";
|
|
58
|
+
results[i] = shape(i, ops[i], r);
|
|
59
|
+
if (r.status === "applied") continue;
|
|
60
|
+
if (!partial) stop = true;
|
|
61
|
+
else if (r.dirty) {
|
|
62
|
+
excluded.set(i, r);
|
|
63
|
+
restart = true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (restart) continue;
|
|
67
|
+
if (stop) {
|
|
68
|
+
ops.forEach((op, i) => results[i] ||= notApplied(i, op, "atomic mode: another op did not apply, so nothing was written"));
|
|
69
|
+
return { results: demote(results, "atomic mode: another op did not apply, so nothing was written"), bytes: null, warnings: [], blocked: null };
|
|
70
|
+
}
|
|
71
|
+
const applied = results.filter((r) => r.status === "applied").length;
|
|
72
|
+
if (!applied) return { results, bytes: null, warnings: [], blocked: null };
|
|
73
|
+
const out = await driver.save(st);
|
|
74
|
+
// the writer is checked before anything leaves this function: a lossy save blocks the whole write
|
|
75
|
+
const flags = nodeChecks(bytes, out, format);
|
|
76
|
+
const rewrites = ops.some((op, i) => results[i].status === "applied" && (REWRITES.has(op.op) || (op.op === "replace_text" && "text" in op)));
|
|
77
|
+
const slideDeleted = ops.some((op, i) => results[i].status === "applied" && op.op === "delete_slide");
|
|
78
|
+
const blocking = blockingFlags(flags, { rewrites, slideDeleted });
|
|
79
|
+
const warnings = flags.filter((f) => !blocking.includes(f));
|
|
80
|
+
if (blocking.length) return { results: demote(results, "blocked by the package check: nothing was written"), bytes: null, warnings, blocked: blocking };
|
|
81
|
+
return { results, bytes: out, warnings, blocked: null };
|
|
82
|
+
} finally {
|
|
83
|
+
driver.close(st);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
throw new Error("apply could not settle on a set of ops"); // unreachable: every restart excludes one op
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Read-only count for a document-wide op (replace_all_text, format_all), before anyone has confirmed a number.
|
|
91
|
+
* Binds once with expect.count 0 and reads what was found; nothing is executed or saved.
|
|
92
|
+
* Returns {ok:true, count, protected, partial_words?, in_formulas?} or {ok:false, status, reason, code?}.
|
|
93
|
+
* `partial_words` (replace_all_text) is the number of matches that sit inside a longer word; `in_formulas` (XLSX) the number inside a formula.
|
|
94
|
+
*/
|
|
95
|
+
export async function previewAll(bytes, format, op, { name = `preview.${format}`, anchors = new Map() } = {}) {
|
|
96
|
+
const driver = DRIVERS[format];
|
|
97
|
+
if (!driver) return { ok: false, status: "refused", reason: `unsupported format ${format}` };
|
|
98
|
+
if (op?.op !== "replace_all_text" && op?.op !== "format_all") return { ok: false, status: "refused", reason: `${op?.op} is not a document-wide op` };
|
|
99
|
+
const st = await driver.open({ bytes, name, anchors });
|
|
100
|
+
try {
|
|
101
|
+
const b = await driver.bind(st, { ...op, expect: { count: 0 } });
|
|
102
|
+
// count 0 matches the file when nothing is found (b.ok); any other count is the expect_mismatch that carries `found`
|
|
103
|
+
if (!b.ok && b.status !== "expect_mismatch") return { ok: false, status: b.status, reason: b.reason, ...(b.code ? { code: b.code } : {}) };
|
|
104
|
+
const count = b.ok ? 0 : b.found;
|
|
105
|
+
return { ok: true, count, protected: b.protected ?? 0, ...("partial_words" in b ? { partial_words: b.partial_words } : {}), ...("in_formulas" in b ? { in_formulas: b.in_formulas } : {}) };
|
|
106
|
+
} finally {
|
|
107
|
+
driver.close(st);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const summarize = (results) => {
|
|
112
|
+
const counts = { applied: 0, skipped_protected: 0, refused: 0, anchor_not_found: 0, expect_mismatch: 0, not_applied: 0 };
|
|
113
|
+
for (const r of results) counts[r.status] = (counts[r.status] || 0) + 1;
|
|
114
|
+
return counts;
|
|
115
|
+
};
|
package/src/ops/runs.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Pure helpers over engine text runs: find text across runs, replace it, split runs for formatting.
|
|
2
|
+
// A "run" here is an engine Inline ({t:'text', text, ...}) or any other inline (counts as one object character).
|
|
3
|
+
// Tracked-deletion runs ({tc:{k:'del'}}) are not part of the visible text and are never touched.
|
|
4
|
+
|
|
5
|
+
export const OBJ = "";
|
|
6
|
+
const isVisible = (r) => !(r.tc && r.tc.k === "del");
|
|
7
|
+
const isText = (r) => r.t === "text";
|
|
8
|
+
|
|
9
|
+
/** visible text plus, per visible run, its [start,end) offsets (objects take one character) */
|
|
10
|
+
export function layout(runs) {
|
|
11
|
+
let text = "";
|
|
12
|
+
const segs = [];
|
|
13
|
+
runs.forEach((r, i) => {
|
|
14
|
+
if (!isVisible(r)) return;
|
|
15
|
+
const s = text.length;
|
|
16
|
+
text += isText(r) ? r.text : OBJ;
|
|
17
|
+
segs.push({ i, start: s, end: text.length, text: isText(r) });
|
|
18
|
+
});
|
|
19
|
+
return { text, segs };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Non-overlapping start offsets of `find` in `text`. */
|
|
23
|
+
export function findAll(text, find, matchCase = true) {
|
|
24
|
+
const hay = matchCase ? text : text.toLowerCase();
|
|
25
|
+
const needle = matchCase ? find : find.toLowerCase();
|
|
26
|
+
const out = [];
|
|
27
|
+
for (let at = hay.indexOf(needle); at >= 0; at = hay.indexOf(needle, at + needle.length)) out.push(at);
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const WORD = /[\p{L}\p{N}]/u;
|
|
32
|
+
/** How many matches of `find` in `text` touch a letter or digit on either side (part of a longer word, "he" in "the"). Same matches as findAll. */
|
|
33
|
+
export function partialWords(text, find, matchCase = true) {
|
|
34
|
+
let n = 0;
|
|
35
|
+
for (const at of findAll(text, find, matchCase)) {
|
|
36
|
+
const before = [...text.slice(Math.max(0, at - 2), at)].pop();
|
|
37
|
+
const after = [...text.slice(at + find.length, at + find.length + 2)][0];
|
|
38
|
+
if ((before && WORD.test(before)) || (after && WORD.test(after))) n++;
|
|
39
|
+
}
|
|
40
|
+
return n;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Picks the matches an op addresses: all, the nth (1-based), or the only one. Returns {starts} or {error}. */
|
|
44
|
+
export function pickMatches(starts, { occurrence, all }) {
|
|
45
|
+
if (!starts.length) return { error: "the text to find does not occur in the target" };
|
|
46
|
+
if (all) return { starts };
|
|
47
|
+
if (occurrence) return occurrence <= starts.length ? { starts: [starts[occurrence - 1]] } : { error: `occurrence ${occurrence} requested but the text occurs ${starts.length} time(s)` };
|
|
48
|
+
if (starts.length > 1) return { error: `ambiguous: the text occurs ${starts.length} times; give "occurrence" or "all"` };
|
|
49
|
+
return { starts };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Replaces [s,e) of the visible text with `replacement`, keeping the formatting of the run the range starts in. Throws RangeError if it crosses an object. */
|
|
53
|
+
export function replaceRange(runs, s, e, replacement) {
|
|
54
|
+
const { segs } = layout(runs);
|
|
55
|
+
const hit = segs.filter((g) => g.end > s && g.start < e);
|
|
56
|
+
if (!hit.length || hit.some((g) => !g.text)) throw new RangeError("the range crosses an image or other object");
|
|
57
|
+
const out = runs.map((r) => ({ ...r }));
|
|
58
|
+
const first = hit[0];
|
|
59
|
+
const last = hit[hit.length - 1];
|
|
60
|
+
const head = out[first.i].text.slice(0, s - first.start);
|
|
61
|
+
const tail = out[last.i].text.slice(e - last.start);
|
|
62
|
+
for (const g of hit) out[g.i].text = "";
|
|
63
|
+
out[first.i].text = head + replacement + (first === last ? tail : "");
|
|
64
|
+
if (first !== last) out[last.i].text = tail;
|
|
65
|
+
return dropEmpty(out, first.i);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Removes emptied text runs, but keeps `keep` if nothing else would carry the paragraph. */
|
|
69
|
+
function dropEmpty(runs, keep) {
|
|
70
|
+
const res = runs.filter((r, i) => !(isText(r) && isVisible(r) && r.text === "" && i !== keep));
|
|
71
|
+
return res;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Splits runs at the ends of [s,e) so the range is covered by whole runs. Returns {runs, covered:[indexes in new runs]}. */
|
|
75
|
+
export function splitForRange(runs, s, e) {
|
|
76
|
+
const out = [];
|
|
77
|
+
const covered = [];
|
|
78
|
+
let pos = 0;
|
|
79
|
+
for (const r of runs) {
|
|
80
|
+
if (!isVisible(r)) {
|
|
81
|
+
out.push(r);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const len = isText(r) ? r.text.length : 1;
|
|
85
|
+
const a = pos;
|
|
86
|
+
const b = pos + len;
|
|
87
|
+
pos = b;
|
|
88
|
+
if (b <= s || a >= e || !isText(r)) {
|
|
89
|
+
if (!isText(r) && b > s && a < e) covered.push(out.length); // objects inside the range are covered whole
|
|
90
|
+
out.push(r);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const from = Math.max(s, a) - a;
|
|
94
|
+
const to = Math.min(e, b) - a;
|
|
95
|
+
for (const [t, inside] of [[r.text.slice(0, from), false], [r.text.slice(from, to), true], [r.text.slice(to), false]]) {
|
|
96
|
+
if (!t) continue;
|
|
97
|
+
if (inside) covered.push(out.length);
|
|
98
|
+
out.push({ ...r, text: t });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return { runs: out, covered };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Merges a run-property patch into the `d` (direct formatting) of the covered text runs. */
|
|
105
|
+
export function applySet(runs, covered, patch) {
|
|
106
|
+
return runs.map((r, i) => (covered.includes(i) && isText(r) ? { ...r, d: { ...(r.d || {}), ...patch } } : r));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Sets the text of a whole paragraph: the first visible text run carries it, the other visible text runs go. Objects stay where they are (callers refuse those). */
|
|
110
|
+
export function setAllText(runs, text) {
|
|
111
|
+
const out = runs.map((r) => ({ ...r }));
|
|
112
|
+
let placed = false;
|
|
113
|
+
const kept = [];
|
|
114
|
+
for (const r of out) {
|
|
115
|
+
if (isText(r) && isVisible(r)) {
|
|
116
|
+
if (!placed) {
|
|
117
|
+
r.text = text;
|
|
118
|
+
placed = true;
|
|
119
|
+
kept.push(r);
|
|
120
|
+
}
|
|
121
|
+
} else kept.push(r);
|
|
122
|
+
}
|
|
123
|
+
if (!placed) kept.push({ t: "text", text, s: {} });
|
|
124
|
+
return kept;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const hasObjects = (runs) => runs.some((r) => isVisible(r) && !isText(r));
|