@hilvana/recipes 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +10 -2
- package/dist/engine.d.ts +87 -0
- package/dist/engine.js +327 -0
- package/dist/i18n.d.ts +8 -0
- package/dist/i18n.js +184 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/schema.d.ts +407 -0
- package/dist/schema.js +103 -0
- package/package.json +48 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 gethilvana
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @hilvana/recipes
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Versioned JSON recipes for chained PDF and Word operations: validate against the real files before running (including page ranges after each step), require confirmation for destructive steps, run locally, and verify goals such as `maxBytes` or `pageCount`. Messages in Spanish and English. Exports a JSON Schema for agents.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import { plan, run } from '@hilvana/recipes';
|
|
7
|
+
const recipe = { version: 1, steps: [{ op: 'merge' }, { op: 'sign', image: 'firma.png' }, { op: 'compress' }], goals: { maxBytes: 2_000_000 } };
|
|
8
|
+
const result = await run(recipe, files, { lang: 'es' });
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
[Recipe reference](https://github.com/gethilvana/hilvana/blob/main/docs/recipes.md) · MIT
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as core from '@hilvana/core';
|
|
2
|
+
import { Recipe, type Goals } from './schema.js';
|
|
3
|
+
import { type Lang } from './i18n.js';
|
|
4
|
+
export type FileKind = 'pdf' | 'word' | 'image' | 'other';
|
|
5
|
+
/** Turns a .docx into PDF bytes. Surfaces choose the engine; the default is the built-in one. */
|
|
6
|
+
export type WordConverter = (docx: Uint8Array) => Promise<{
|
|
7
|
+
pdf: Uint8Array;
|
|
8
|
+
pageCount: number;
|
|
9
|
+
warnings: string[];
|
|
10
|
+
engine?: string;
|
|
11
|
+
}>;
|
|
12
|
+
export interface EngineOptions {
|
|
13
|
+
lang?: Lang;
|
|
14
|
+
word?: WordConverter;
|
|
15
|
+
/** Fonts for stamped text outside the standard PDF fonts. Defaults to the bundled open fonts (Node). */
|
|
16
|
+
textFonts?: core.FontSource;
|
|
17
|
+
}
|
|
18
|
+
/** An input file. Names are what recipes refer to; bytes never leave the caller's machine. */
|
|
19
|
+
export interface InputFile {
|
|
20
|
+
name: string;
|
|
21
|
+
bytes: Uint8Array;
|
|
22
|
+
}
|
|
23
|
+
export interface Issue {
|
|
24
|
+
code: string;
|
|
25
|
+
message: string;
|
|
26
|
+
step?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface Plan {
|
|
29
|
+
ok: boolean;
|
|
30
|
+
recipe?: Recipe;
|
|
31
|
+
issues: Issue[];
|
|
32
|
+
/** Human-readable steps in the requested language. */
|
|
33
|
+
steps: string[];
|
|
34
|
+
goals: string[];
|
|
35
|
+
/** 1-based indices of steps that drop content or overwrite information. */
|
|
36
|
+
destructiveSteps: number[];
|
|
37
|
+
/** Page count predicted after each step (when it could be computed). */
|
|
38
|
+
predictedPages?: number[];
|
|
39
|
+
/** Simplifications made while converting Word files, in plain language. */
|
|
40
|
+
warnings: string[];
|
|
41
|
+
}
|
|
42
|
+
export interface GoalResult {
|
|
43
|
+
goal: keyof Goals;
|
|
44
|
+
expected: unknown;
|
|
45
|
+
actual: unknown;
|
|
46
|
+
met: boolean;
|
|
47
|
+
message: string;
|
|
48
|
+
}
|
|
49
|
+
export interface RunResult {
|
|
50
|
+
bytes: Uint8Array;
|
|
51
|
+
filename: string;
|
|
52
|
+
pageCount: number;
|
|
53
|
+
byteLength: number;
|
|
54
|
+
goals: GoalResult[];
|
|
55
|
+
allGoalsMet: boolean;
|
|
56
|
+
steps: string[];
|
|
57
|
+
warnings: string[];
|
|
58
|
+
/** What some steps did, in plain language (e.g. compression results). */
|
|
59
|
+
notes: string[];
|
|
60
|
+
}
|
|
61
|
+
export declare function kindOf(bytes: Uint8Array): FileKind;
|
|
62
|
+
/**
|
|
63
|
+
* Validates a recipe against the actual inputs without running it:
|
|
64
|
+
* schema, file references, page ranges (by simulating page counts) and destructive steps.
|
|
65
|
+
* Only file names, kinds and page counts are read.
|
|
66
|
+
*/
|
|
67
|
+
export declare function plan(raw: unknown, files: InputFile[], langOrOpts?: Lang | EngineOptions): Promise<Plan>;
|
|
68
|
+
export declare class RecipeError extends Error {
|
|
69
|
+
readonly issues: Issue[];
|
|
70
|
+
constructor(issues: Issue[]);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Recipes can be shared, so their output name is only ever a file name: no folders, no "..",
|
|
74
|
+
* no characters Windows forbids, no leading dots.
|
|
75
|
+
*/
|
|
76
|
+
export declare function safeFilename(name: string): string;
|
|
77
|
+
/**
|
|
78
|
+
* Validates, then executes a recipe locally and verifies its goals.
|
|
79
|
+
* Recipes with destructive steps only run with `confirmed: true`.
|
|
80
|
+
* Input byte arrays are never modified.
|
|
81
|
+
*/
|
|
82
|
+
export declare function run(raw: unknown, files: InputFile[], opts?: EngineOptions & {
|
|
83
|
+
confirmed?: boolean;
|
|
84
|
+
}): Promise<RunResult>;
|
|
85
|
+
/** Checks the result against the recipe goals and explains each outcome. */
|
|
86
|
+
export declare function verify(goals: Goals | undefined, bytes: Uint8Array, info: core.PdfInfo, lang?: Lang): GoalResult[];
|
|
87
|
+
//# sourceMappingURL=engine.d.ts.map
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import * as core from '@hilvana/core';
|
|
2
|
+
import { HilvanaError, parsePageRange } from '@hilvana/core';
|
|
3
|
+
import { DocxError, fallbackTextFonts, isDocx, wordToPdf } from '@hilvana/office';
|
|
4
|
+
import { DESTRUCTIVE_OPS, Recipe } from './schema.js';
|
|
5
|
+
import { describeStep, formatBytes, localDate, t } from './i18n.js';
|
|
6
|
+
const defaultWord = (docx) => wordToPdf(docx);
|
|
7
|
+
// Each Word file is converted once per converter, even though plan() and run() both need it.
|
|
8
|
+
const conversions = new WeakMap();
|
|
9
|
+
function convertOnce(convert, bytes) {
|
|
10
|
+
let byBytes = conversions.get(convert);
|
|
11
|
+
if (!byBytes)
|
|
12
|
+
conversions.set(convert, (byBytes = new WeakMap()));
|
|
13
|
+
let p = byBytes.get(bytes);
|
|
14
|
+
if (!p)
|
|
15
|
+
byBytes.set(bytes, (p = convert(bytes)));
|
|
16
|
+
return p;
|
|
17
|
+
}
|
|
18
|
+
export function kindOf(bytes) {
|
|
19
|
+
if (bytes[0] === 0x25 && bytes[1] === 0x50 && bytes[2] === 0x44 && bytes[3] === 0x46)
|
|
20
|
+
return 'pdf';
|
|
21
|
+
if (bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47)
|
|
22
|
+
return 'image';
|
|
23
|
+
if (bytes[0] === 0xff && bytes[1] === 0xd8)
|
|
24
|
+
return 'image';
|
|
25
|
+
if (bytes[0] === 0x50 && bytes[1] === 0x4b && isDocx(bytes))
|
|
26
|
+
return 'word';
|
|
27
|
+
return 'other';
|
|
28
|
+
}
|
|
29
|
+
const SOURCE_OPS = new Set(['merge', 'fromImages']);
|
|
30
|
+
function issueFromError(err, lang, step) {
|
|
31
|
+
if (err instanceof HilvanaError)
|
|
32
|
+
return { code: err.code, message: t(lang, err.code, err.details), step };
|
|
33
|
+
return { code: 'UNKNOWN', message: String(err?.message ?? err), step };
|
|
34
|
+
}
|
|
35
|
+
/** Normalizes a recipe: if it does not start with a source step, prepend "merge all PDFs". */
|
|
36
|
+
function withSource(steps) {
|
|
37
|
+
return SOURCE_OPS.has(steps[0].op) ? steps : [{ op: 'merge' }, ...steps];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Validates a recipe against the actual inputs without running it:
|
|
41
|
+
* schema, file references, page ranges (by simulating page counts) and destructive steps.
|
|
42
|
+
* Only file names, kinds and page counts are read.
|
|
43
|
+
*/
|
|
44
|
+
export async function plan(raw, files, langOrOpts = 'es') {
|
|
45
|
+
const opts = typeof langOrOpts === 'string' ? { lang: langOrOpts } : langOrOpts;
|
|
46
|
+
const lang = opts.lang ?? 'es';
|
|
47
|
+
const convert = opts.word ?? defaultWord;
|
|
48
|
+
const parsed = Recipe.safeParse(raw);
|
|
49
|
+
if (!parsed.success) {
|
|
50
|
+
const issues = parsed.error.issues.map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`).join('; ');
|
|
51
|
+
return { ok: false, issues: [{ code: 'SCHEMA', message: t(lang, 'SCHEMA', { issues }) }], steps: [], goals: [], destructiveSteps: [], warnings: [] };
|
|
52
|
+
}
|
|
53
|
+
const recipe = parsed.data;
|
|
54
|
+
const issues = [];
|
|
55
|
+
const byName = new Map(files.map((f) => [f.name, f]));
|
|
56
|
+
const kinds = new Map(files.map((f) => [f.name, kindOf(f.bytes)]));
|
|
57
|
+
const docNames = files.filter((f) => ['pdf', 'word'].includes(kinds.get(f.name))).map((f) => f.name);
|
|
58
|
+
const imageNames = files.filter((f) => kinds.get(f.name) === 'image').map((f) => f.name);
|
|
59
|
+
const hasWord = docNames.some((n) => kinds.get(n) === 'word');
|
|
60
|
+
const pageCounts = new Map();
|
|
61
|
+
const warnings = [];
|
|
62
|
+
for (const name of docNames) {
|
|
63
|
+
try {
|
|
64
|
+
if (kinds.get(name) === 'word') {
|
|
65
|
+
const res = await convertOnce(convert, byName.get(name).bytes);
|
|
66
|
+
pageCounts.set(name, res.pageCount);
|
|
67
|
+
for (const w of res.warnings)
|
|
68
|
+
warnings.push(`${name}: ${t(lang, `word.${w}`)}`);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
pageCounts.set(name, (await core.inspect(byName.get(name).bytes)).pageCount);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
if (err instanceof DocxError)
|
|
76
|
+
issues.push({ code: err.code, message: t(lang, err.code, { name }) });
|
|
77
|
+
else
|
|
78
|
+
issues.push(issueFromError(err, lang));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const steps = withSource(recipe.steps);
|
|
82
|
+
const offset = steps.length - recipe.steps.length; // 1 when a merge was prepended
|
|
83
|
+
let pages;
|
|
84
|
+
const predicted = [];
|
|
85
|
+
steps.forEach((step, i) => {
|
|
86
|
+
const n = i + 1 - offset; // step number as the user wrote it (0 = implicit merge)
|
|
87
|
+
if (i > 0 && SOURCE_OPS.has(step.op))
|
|
88
|
+
issues.push({ code: 'SOURCE_NOT_FIRST', message: t(lang, 'SOURCE_NOT_FIRST', { index: n }), step: n });
|
|
89
|
+
const checkRange = (expr) => {
|
|
90
|
+
if (expr === undefined || pages === undefined)
|
|
91
|
+
return [];
|
|
92
|
+
try {
|
|
93
|
+
return parsePageRange(expr, pages);
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
issues.push(issueFromError(err, lang, n));
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
switch (step.op) {
|
|
101
|
+
case 'merge': {
|
|
102
|
+
const names = step.files ?? docNames;
|
|
103
|
+
if (names.length === 0)
|
|
104
|
+
issues.push({ code: 'NO_PDF_INPUTS', message: t(lang, 'NO_PDF_INPUTS'), step: n });
|
|
105
|
+
let total = 0;
|
|
106
|
+
for (const name of names) {
|
|
107
|
+
if (!byName.has(name))
|
|
108
|
+
issues.push({ code: 'UNKNOWN_INPUT', message: t(lang, 'UNKNOWN_INPUT', { name }), step: n });
|
|
109
|
+
else if (!['pdf', 'word'].includes(kinds.get(name)))
|
|
110
|
+
issues.push({ code: 'NOT_A_PDF', message: t(lang, 'NOT_A_PDF', { name }), step: n });
|
|
111
|
+
else
|
|
112
|
+
total += pageCounts.get(name) ?? 0;
|
|
113
|
+
}
|
|
114
|
+
pages = total || undefined;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case 'fromImages': {
|
|
118
|
+
const names = step.files ?? imageNames;
|
|
119
|
+
if (names.length === 0)
|
|
120
|
+
issues.push({ code: 'NO_INPUTS', message: t(lang, 'NO_INPUTS'), step: n });
|
|
121
|
+
for (const name of names) {
|
|
122
|
+
if (!byName.has(name))
|
|
123
|
+
issues.push({ code: 'UNKNOWN_INPUT', message: t(lang, 'UNKNOWN_INPUT', { name }), step: n });
|
|
124
|
+
else if (kinds.get(name) !== 'image')
|
|
125
|
+
issues.push({ code: 'NOT_AN_IMAGE', message: t(lang, 'NOT_AN_IMAGE', { name }), step: n });
|
|
126
|
+
}
|
|
127
|
+
pages = names.length || undefined;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
case 'select': {
|
|
131
|
+
const sel = pages === undefined ? [] : (() => { try {
|
|
132
|
+
return parsePageRange(step.pages, pages, true);
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
issues.push(issueFromError(err, lang, n));
|
|
136
|
+
return [];
|
|
137
|
+
} })();
|
|
138
|
+
if (sel.length)
|
|
139
|
+
pages = sel.length;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
case 'remove': {
|
|
143
|
+
const sel = checkRange(step.pages);
|
|
144
|
+
if (pages !== undefined && sel.length >= pages)
|
|
145
|
+
issues.push({ code: 'WOULD_REMOVE_ALL_PAGES', message: t(lang, 'WOULD_REMOVE_ALL_PAGES'), step: n });
|
|
146
|
+
else if (pages !== undefined)
|
|
147
|
+
pages -= sel.length;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case 'sign': {
|
|
151
|
+
if (!byName.has(step.image))
|
|
152
|
+
issues.push({ code: 'UNKNOWN_INPUT', message: t(lang, 'UNKNOWN_INPUT', { name: step.image }), step: n });
|
|
153
|
+
else if (kinds.get(step.image) !== 'image')
|
|
154
|
+
issues.push({ code: 'NOT_AN_IMAGE', message: t(lang, 'NOT_AN_IMAGE', { name: step.image }), step: n });
|
|
155
|
+
checkRange(step.pages ?? 'last');
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case 'rotate':
|
|
159
|
+
case 'stampText':
|
|
160
|
+
case 'watermark':
|
|
161
|
+
case 'numberPages':
|
|
162
|
+
checkRange(step.pages);
|
|
163
|
+
break;
|
|
164
|
+
default:
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
if (pages !== undefined)
|
|
168
|
+
predicted.push(pages);
|
|
169
|
+
});
|
|
170
|
+
const destructiveSteps = recipe.steps
|
|
171
|
+
.map((s, i) => (DESTRUCTIVE_OPS.has(s.op) ? i + 1 : 0))
|
|
172
|
+
.filter(Boolean);
|
|
173
|
+
return {
|
|
174
|
+
ok: issues.length === 0,
|
|
175
|
+
recipe,
|
|
176
|
+
issues,
|
|
177
|
+
steps: steps.map((s, i) => {
|
|
178
|
+
let text = describeStep(s, lang);
|
|
179
|
+
if (s.op === 'compress' && !s.level && s.targetBytes === undefined && recipe.goals?.maxBytes) {
|
|
180
|
+
text = t(lang, 'step.compressTarget', { target: formatBytes(recipe.goals.maxBytes) });
|
|
181
|
+
}
|
|
182
|
+
if (s.op === 'merge') {
|
|
183
|
+
const names = s.files ?? docNames;
|
|
184
|
+
if (names.length === 1 && kinds.get(names[0]) === 'word')
|
|
185
|
+
text = t(lang, 'step.convertWord', { file: names[0] });
|
|
186
|
+
else if (!s.files && hasWord)
|
|
187
|
+
text = t(lang, 'step.mergeAllDocs');
|
|
188
|
+
}
|
|
189
|
+
return `${i + 1}. ${text}${DESTRUCTIVE_OPS.has(s.op) ? ' ' + t(lang, 'destructive') : ''}`;
|
|
190
|
+
}),
|
|
191
|
+
warnings,
|
|
192
|
+
goals: describeGoals(recipe.goals, lang),
|
|
193
|
+
destructiveSteps,
|
|
194
|
+
predictedPages: predicted,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function describeGoals(goals, lang) {
|
|
198
|
+
if (!goals)
|
|
199
|
+
return [];
|
|
200
|
+
return Object.entries(goals)
|
|
201
|
+
.filter(([, v]) => v !== undefined && v !== false)
|
|
202
|
+
.map(([k, v]) => t(lang, `goal.${k}`, { expected: k === 'maxBytes' ? formatBytes(v) : v }));
|
|
203
|
+
}
|
|
204
|
+
export class RecipeError extends Error {
|
|
205
|
+
issues;
|
|
206
|
+
constructor(issues) {
|
|
207
|
+
super(issues.map((i) => i.message).join(' '));
|
|
208
|
+
this.name = 'RecipeError';
|
|
209
|
+
this.issues = issues;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const today = () => localDate();
|
|
213
|
+
/**
|
|
214
|
+
* Recipes can be shared, so their output name is only ever a file name: no folders, no "..",
|
|
215
|
+
* no characters Windows forbids, no leading dots.
|
|
216
|
+
*/
|
|
217
|
+
export function safeFilename(name) {
|
|
218
|
+
const base = name.split(/[\\/]+/).filter(Boolean).pop() ?? '';
|
|
219
|
+
const cleaned = base
|
|
220
|
+
.replace(/[<>:"|?*\u0000-\u001f]/g, '-')
|
|
221
|
+
.replace(/^\.+/, '')
|
|
222
|
+
.replace(/[. ]+$/, '')
|
|
223
|
+
.slice(0, 150);
|
|
224
|
+
return /^(con|prn|aux|nul|com\d|lpt\d)(\..*)?$/i.test(cleaned) || !cleaned ? 'documento-hilvana' : cleaned;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Validates, then executes a recipe locally and verifies its goals.
|
|
228
|
+
* Recipes with destructive steps only run with `confirmed: true`.
|
|
229
|
+
* Input byte arrays are never modified.
|
|
230
|
+
*/
|
|
231
|
+
export async function run(raw, files, opts = {}) {
|
|
232
|
+
const lang = opts.lang ?? 'es';
|
|
233
|
+
const convert = opts.word ?? defaultWord;
|
|
234
|
+
const p = await plan(raw, files, { lang, word: convert });
|
|
235
|
+
if (!p.ok || !p.recipe)
|
|
236
|
+
throw new RecipeError(p.issues);
|
|
237
|
+
if (p.destructiveSteps.length > 0 && !opts.confirmed) {
|
|
238
|
+
throw new RecipeError([{ code: 'CONFIRMATION_REQUIRED', message: t(lang, 'CONFIRMATION_REQUIRED', { steps: p.destructiveSteps.join(', ') }) }]);
|
|
239
|
+
}
|
|
240
|
+
const recipe = p.recipe;
|
|
241
|
+
// Word inputs become their converted PDF; everything downstream only sees PDFs.
|
|
242
|
+
const byName = new Map();
|
|
243
|
+
const docs = [];
|
|
244
|
+
for (const f of files) {
|
|
245
|
+
const kind = kindOf(f.bytes);
|
|
246
|
+
const bytes = kind === 'word' ? (await convertOnce(convert, f.bytes)).pdf : f.bytes;
|
|
247
|
+
byName.set(f.name, bytes);
|
|
248
|
+
if (kind === 'pdf' || kind === 'word')
|
|
249
|
+
docs.push({ name: f.name, bytes });
|
|
250
|
+
}
|
|
251
|
+
const pdfs = docs;
|
|
252
|
+
const images = files.filter((f) => kindOf(f.bytes) === 'image');
|
|
253
|
+
let doc;
|
|
254
|
+
const notes = [];
|
|
255
|
+
const steps = withSource(recipe.steps);
|
|
256
|
+
for (const [i, step] of steps.entries()) {
|
|
257
|
+
try {
|
|
258
|
+
doc = await apply(step, doc, { byName, pdfs, images, notes, lang, goals: recipe.goals, fonts: opts.textFonts ?? (() => fallbackTextFonts()) });
|
|
259
|
+
}
|
|
260
|
+
catch (err) {
|
|
261
|
+
throw new RecipeError([issueFromError(err, lang, i + 1)]);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const result = doc;
|
|
265
|
+
const info = await core.inspect(result);
|
|
266
|
+
const goals = verify(recipe.goals, result, info, lang);
|
|
267
|
+
const firstName = (files[0]?.name ?? 'documento').replace(/\.[^.]+$/, '');
|
|
268
|
+
const filename = safeFilename((recipe.output?.filename ?? '{name}-hilvana.pdf').replace('{date}', today()).replace('{name}', firstName));
|
|
269
|
+
return {
|
|
270
|
+
bytes: result,
|
|
271
|
+
filename: filename.toLowerCase().endsWith('.pdf') ? filename : `${filename}.pdf`,
|
|
272
|
+
pageCount: info.pageCount,
|
|
273
|
+
byteLength: result.byteLength,
|
|
274
|
+
goals,
|
|
275
|
+
allGoalsMet: goals.every((g) => g.met),
|
|
276
|
+
steps: p.steps,
|
|
277
|
+
warnings: p.warnings,
|
|
278
|
+
notes,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
async function apply(step, doc, ctx) {
|
|
282
|
+
const need = () => doc;
|
|
283
|
+
switch (step.op) {
|
|
284
|
+
case 'merge': return core.merge(step.files ? step.files.map((n) => ctx.byName.get(n)) : ctx.pdfs.map((f) => f.bytes));
|
|
285
|
+
case 'fromImages': return core.imagesToPdf(step.files ? step.files.map((n) => ctx.byName.get(n)) : ctx.images.map((f) => f.bytes), { pageSize: step.pageSize });
|
|
286
|
+
case 'select': return core.selectPages(need(), step.pages);
|
|
287
|
+
case 'remove': return core.removePages(need(), step.pages);
|
|
288
|
+
case 'rotate': return core.rotate(need(), step.angle, step.pages);
|
|
289
|
+
case 'stampText': return core.stampText(need(), { ...step, text: step.text.replace('{date}', today()), fonts: ctx.fonts });
|
|
290
|
+
case 'sign': return core.stampImage(need(), { image: ctx.byName.get(step.image), pages: step.pages, anchor: step.anchor, width: step.width });
|
|
291
|
+
case 'watermark': return core.watermark(need(), step.text, { ...step, fonts: ctx.fonts });
|
|
292
|
+
case 'numberPages': return core.numberPages(need(), { ...step, fonts: ctx.fonts });
|
|
293
|
+
case 'stripMetadata': return core.stripMetadata(need());
|
|
294
|
+
case 'setMetadata': return core.setMetadata(need(), step);
|
|
295
|
+
case 'optimize': return core.optimize(need());
|
|
296
|
+
case 'compress': {
|
|
297
|
+
// With no explicit level, aim for the recipe's size goal if there is one.
|
|
298
|
+
const target = step.targetBytes ?? (step.level ? undefined : ctx.goals?.maxBytes);
|
|
299
|
+
const { bytes, report } = await core.compress(need(), { level: step.level, targetBytes: target });
|
|
300
|
+
const { lang } = ctx;
|
|
301
|
+
if (report.level === 'none')
|
|
302
|
+
ctx.notes.push(t(lang, 'note.compressNone'));
|
|
303
|
+
else
|
|
304
|
+
ctx.notes.push(t(lang, 'note.compress', { before: formatBytes(report.before), after: formatBytes(report.after), level: t(lang, `level.${report.level}`), images: report.images.recompressed }));
|
|
305
|
+
if (report.targetMet === false)
|
|
306
|
+
ctx.notes.push(t(lang, 'note.targetMissed', { target: formatBytes(target), after: formatBytes(bytes.byteLength) }));
|
|
307
|
+
return bytes;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/** Checks the result against the recipe goals and explains each outcome. */
|
|
312
|
+
export function verify(goals, bytes, info, lang = 'es') {
|
|
313
|
+
if (!goals)
|
|
314
|
+
return [];
|
|
315
|
+
const out = [];
|
|
316
|
+
const add = (goal, expected, actual, met, fmt = (v) => v) => out.push({ goal, expected, actual, met, message: `${met ? '✓' : '✗'} ${t(lang, `goal.${goal}`, { expected: fmt ? fmt(expected) : expected })}${fmt ? ` (${fmt(actual)})` : ''}` });
|
|
317
|
+
if (goals.maxBytes !== undefined)
|
|
318
|
+
add('maxBytes', goals.maxBytes, bytes.byteLength, bytes.byteLength <= goals.maxBytes, (v) => formatBytes(v));
|
|
319
|
+
if (goals.pageCount !== undefined)
|
|
320
|
+
add('pageCount', goals.pageCount, info.pageCount, info.pageCount === goals.pageCount);
|
|
321
|
+
if (goals.maxPages !== undefined)
|
|
322
|
+
add('maxPages', goals.maxPages, info.pageCount, info.pageCount <= goals.maxPages);
|
|
323
|
+
if (goals.noMetadata)
|
|
324
|
+
add('noMetadata', true, !info.hasMetadata, !info.hasMetadata, null);
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
327
|
+
//# sourceMappingURL=engine.js.map
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Step } from './schema.js';
|
|
2
|
+
export type Lang = 'es' | 'en';
|
|
3
|
+
export declare function t(lang: Lang, key: string, vars?: Record<string, unknown>): string;
|
|
4
|
+
export declare function formatBytes(n: number): string;
|
|
5
|
+
export declare function describeStep(step: Step, lang: Lang): string;
|
|
6
|
+
/** Today's date as YYYY-MM-DD in the user's local time zone. */
|
|
7
|
+
export declare function localDate(d?: Date): string;
|
|
8
|
+
//# sourceMappingURL=i18n.d.ts.map
|
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
const messages = {
|
|
2
|
+
es: {
|
|
3
|
+
// core error codes
|
|
4
|
+
EMPTY_DOCUMENT: 'El documento no tiene páginas.',
|
|
5
|
+
INVALID_RANGE: 'El rango de páginas "{expr}" no es válido.',
|
|
6
|
+
PAGE_OUT_OF_RANGE: 'La página {page} no existe; el documento tiene {pageCount}.',
|
|
7
|
+
NO_INPUTS: 'No hay archivos de entrada.',
|
|
8
|
+
ENCRYPTED: 'El PDF está protegido con contraseña.',
|
|
9
|
+
INVALID_PDF: 'El archivo no es un PDF válido.',
|
|
10
|
+
UNSUPPORTED_IMAGE: 'La imagen debe ser PNG o JPEG.',
|
|
11
|
+
WOULD_REMOVE_ALL_PAGES: 'La operación eliminaría todas las páginas.',
|
|
12
|
+
INVALID_ARGUMENT: 'Hay un parámetro inválido.',
|
|
13
|
+
UNSUPPORTED_CHARACTERS: 'El texto tiene caracteres que la fuente estándar no puede dibujar: {chars}',
|
|
14
|
+
// recipe codes
|
|
15
|
+
SCHEMA: 'La receta no cumple el formato: {issues}',
|
|
16
|
+
UNKNOWN_INPUT: 'La receta usa "{name}", pero no hay un archivo con ese nombre.',
|
|
17
|
+
NOT_AN_IMAGE: '"{name}" debe ser una imagen PNG o JPEG.',
|
|
18
|
+
NOT_A_PDF: '"{name}" debe ser un PDF o un documento de Word (.docx).',
|
|
19
|
+
NOT_DOCX: '"{name}" no es un documento de Word (.docx).',
|
|
20
|
+
ENCRYPTED_DOCX: '"{name}" está protegido con contraseña; ábrelo en Word y guárdalo sin contraseña.',
|
|
21
|
+
CORRUPT_DOCX: '"{name}" está dañado o no se puede leer.',
|
|
22
|
+
'step.convertWord': 'Convertir {file} de Word a PDF',
|
|
23
|
+
'step.mergeAllDocs': 'Unir todos los documentos (PDF y Word) en el orden recibido',
|
|
24
|
+
'word.TEXTBOX_SKIPPED': 'se omitieron cuadros de texto',
|
|
25
|
+
'word.FLOATING_IMAGE_INLINED': 'las imágenes flotantes se ubicaron en línea con el texto',
|
|
26
|
+
'word.UNSUPPORTED_IMAGE_FORMAT': 'se omitieron imágenes en un formato no compatible (EMF/WMF/SVG)',
|
|
27
|
+
'word.LEGACY_SHAPE_SKIPPED': 'se omitieron formas antiguas (VML)',
|
|
28
|
+
'word.NOTES_SKIPPED': 'se omitieron las notas al pie',
|
|
29
|
+
'word.FIRST_PAGE_HEADER_IGNORED': 'se usó el encabezado general también en la primera página',
|
|
30
|
+
'word.PAGE_FIELD_IN_BODY': 'un número de página dentro del texto quedó vacío',
|
|
31
|
+
'word.CONTENT_TALLER_THAN_PAGE': 'hay contenido más alto que la página',
|
|
32
|
+
'word.MISSING_GLYPHS': 'algunos caracteres (por ejemplo, emojis) se reemplazaron por "?"',
|
|
33
|
+
'word.COLUMNS_IGNORED': 'el texto en varias columnas se puso en una sola',
|
|
34
|
+
NO_PDF_INPUTS: 'La receta necesita al menos un PDF de entrada.',
|
|
35
|
+
SOURCE_NOT_FIRST: 'El paso {index} crea un documento nuevo; solo puede ir de primero.',
|
|
36
|
+
CONFIRMATION_REQUIRED: 'La receta tiene pasos que eliminan contenido o información ({steps}). Confírmala para ejecutarla.',
|
|
37
|
+
// describe
|
|
38
|
+
'step.merge': 'Unir {files}',
|
|
39
|
+
'step.mergeAll': 'Unir todos los PDF en el orden recibido',
|
|
40
|
+
'step.fromImages': 'Crear un PDF con las imágenes {files}',
|
|
41
|
+
'step.fromImagesAll': 'Crear un PDF con todas las imágenes',
|
|
42
|
+
'step.select': 'Conservar solo {pages}',
|
|
43
|
+
'step.remove': 'Eliminar {pages}',
|
|
44
|
+
'step.rotate': 'Girar {angle}° {pages}',
|
|
45
|
+
'step.stampText': 'Escribir "{text}" en {pages}',
|
|
46
|
+
'step.sign': 'Firmar con "{image}" en {pages}',
|
|
47
|
+
'step.watermark': 'Agregar la marca de agua "{text}"',
|
|
48
|
+
'step.numberPages': 'Numerar las páginas',
|
|
49
|
+
'step.stripMetadata': 'Borrar los metadatos (autor, título, herramientas)',
|
|
50
|
+
'step.setMetadata': 'Cambiar los metadatos del documento',
|
|
51
|
+
'step.optimize': 'Optimizar la estructura del archivo',
|
|
52
|
+
'step.compress': 'Comprimir (nivel {level})',
|
|
53
|
+
'step.compressTarget': 'Comprimir hasta {target} como máximo',
|
|
54
|
+
'level.lossless': 'sin pérdida',
|
|
55
|
+
'level.balanced': 'equilibrado',
|
|
56
|
+
'level.strong': 'fuerte',
|
|
57
|
+
'level.max': 'máximo',
|
|
58
|
+
'level.none': 'sin cambios',
|
|
59
|
+
'note.compress': 'Compresión: {before} → {after} (nivel {level}; {images} imágenes optimizadas)',
|
|
60
|
+
'note.compressNone': 'La compresión no logró reducir el archivo; se dejó igual.',
|
|
61
|
+
'note.targetMissed': 'No se alcanzó {target}: lo más pequeño posible sin rasterizar el texto fue {after}.',
|
|
62
|
+
'goal.maxBytes': 'Pesa como máximo {expected}',
|
|
63
|
+
'goal.pageCount': 'Tiene exactamente {expected} páginas',
|
|
64
|
+
'goal.maxPages': 'Tiene como máximo {expected} páginas',
|
|
65
|
+
'goal.noMetadata': 'No contiene metadatos identificables',
|
|
66
|
+
destructive: '(borra contenido o información; requiere confirmación)',
|
|
67
|
+
'pages.all': 'todas las páginas',
|
|
68
|
+
'pages.last': 'la última página',
|
|
69
|
+
'pages.one': 'la página {p}',
|
|
70
|
+
'pages.many': 'las páginas {p}',
|
|
71
|
+
},
|
|
72
|
+
en: {
|
|
73
|
+
EMPTY_DOCUMENT: 'The document has no pages.',
|
|
74
|
+
INVALID_RANGE: 'The page range "{expr}" is not valid.',
|
|
75
|
+
PAGE_OUT_OF_RANGE: 'Page {page} does not exist; the document has {pageCount}.',
|
|
76
|
+
NO_INPUTS: 'There are no input files.',
|
|
77
|
+
ENCRYPTED: 'The PDF is password protected.',
|
|
78
|
+
INVALID_PDF: 'The file is not a valid PDF.',
|
|
79
|
+
UNSUPPORTED_IMAGE: 'The image must be PNG or JPEG.',
|
|
80
|
+
WOULD_REMOVE_ALL_PAGES: 'The operation would remove every page.',
|
|
81
|
+
INVALID_ARGUMENT: 'A parameter is invalid.',
|
|
82
|
+
UNSUPPORTED_CHARACTERS: 'The text has characters the standard font cannot draw: {chars}',
|
|
83
|
+
SCHEMA: 'The recipe does not match the format: {issues}',
|
|
84
|
+
UNKNOWN_INPUT: 'The recipe uses "{name}", but there is no file with that name.',
|
|
85
|
+
NOT_AN_IMAGE: '"{name}" must be a PNG or JPEG image.',
|
|
86
|
+
NOT_A_PDF: '"{name}" must be a PDF or a Word document (.docx).',
|
|
87
|
+
NOT_DOCX: '"{name}" is not a Word document (.docx).',
|
|
88
|
+
ENCRYPTED_DOCX: '"{name}" is password protected; open it in Word and save it without a password.',
|
|
89
|
+
CORRUPT_DOCX: '"{name}" is damaged or cannot be read.',
|
|
90
|
+
'step.convertWord': 'Convert {file} from Word to PDF',
|
|
91
|
+
'step.mergeAllDocs': 'Merge every document (PDF and Word) in the order received',
|
|
92
|
+
'word.TEXTBOX_SKIPPED': 'text boxes were skipped',
|
|
93
|
+
'word.FLOATING_IMAGE_INLINED': 'floating images were placed inline with the text',
|
|
94
|
+
'word.UNSUPPORTED_IMAGE_FORMAT': 'images in an unsupported format (EMF/WMF/SVG) were skipped',
|
|
95
|
+
'word.LEGACY_SHAPE_SKIPPED': 'legacy (VML) shapes were skipped',
|
|
96
|
+
'word.NOTES_SKIPPED': 'footnotes were skipped',
|
|
97
|
+
'word.FIRST_PAGE_HEADER_IGNORED': 'the default header was also used on the first page',
|
|
98
|
+
'word.PAGE_FIELD_IN_BODY': 'a page number inside the body was left empty',
|
|
99
|
+
'word.CONTENT_TALLER_THAN_PAGE': 'some content is taller than the page',
|
|
100
|
+
'word.MISSING_GLYPHS': 'some characters (for example, emoji) were replaced with "?"',
|
|
101
|
+
'word.COLUMNS_IGNORED': 'multi-column text was set in a single column',
|
|
102
|
+
NO_PDF_INPUTS: 'The recipe needs at least one PDF input.',
|
|
103
|
+
SOURCE_NOT_FIRST: 'Step {index} creates a new document; it can only come first.',
|
|
104
|
+
CONFIRMATION_REQUIRED: 'The recipe has steps that remove content or information ({steps}). Confirm it to run it.',
|
|
105
|
+
'step.merge': 'Merge {files}',
|
|
106
|
+
'step.mergeAll': 'Merge every PDF in the order received',
|
|
107
|
+
'step.fromImages': 'Build a PDF from the images {files}',
|
|
108
|
+
'step.fromImagesAll': 'Build a PDF from every image',
|
|
109
|
+
'step.select': 'Keep only {pages}',
|
|
110
|
+
'step.remove': 'Remove {pages}',
|
|
111
|
+
'step.rotate': 'Rotate {pages} by {angle}°',
|
|
112
|
+
'step.stampText': 'Write "{text}" on {pages}',
|
|
113
|
+
'step.sign': 'Sign with "{image}" on {pages}',
|
|
114
|
+
'step.watermark': 'Add the watermark "{text}"',
|
|
115
|
+
'step.numberPages': 'Number the pages',
|
|
116
|
+
'step.stripMetadata': 'Remove metadata (author, title, tools)',
|
|
117
|
+
'step.setMetadata': 'Change the document metadata',
|
|
118
|
+
'step.optimize': 'Optimize the file structure',
|
|
119
|
+
'step.compress': 'Compress ({level} level)',
|
|
120
|
+
'step.compressTarget': 'Compress to at most {target}',
|
|
121
|
+
'level.lossless': 'lossless',
|
|
122
|
+
'level.balanced': 'balanced',
|
|
123
|
+
'level.strong': 'strong',
|
|
124
|
+
'level.max': 'maximum',
|
|
125
|
+
'level.none': 'unchanged',
|
|
126
|
+
'note.compress': 'Compression: {before} → {after} ({level} level; {images} images optimized)',
|
|
127
|
+
'note.compressNone': 'Compression could not make the file smaller; it was left as is.',
|
|
128
|
+
'note.targetMissed': '{target} was not reached: the smallest possible without rasterizing text was {after}.',
|
|
129
|
+
'goal.maxBytes': 'Is at most {expected}',
|
|
130
|
+
'goal.pageCount': 'Has exactly {expected} pages',
|
|
131
|
+
'goal.maxPages': 'Has at most {expected} pages',
|
|
132
|
+
'goal.noMetadata': 'Contains no identifying metadata',
|
|
133
|
+
destructive: '(removes content or information; needs confirmation)',
|
|
134
|
+
'pages.all': 'all pages',
|
|
135
|
+
'pages.last': 'the last page',
|
|
136
|
+
'pages.one': 'page {p}',
|
|
137
|
+
'pages.many': 'pages {p}',
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
export function t(lang, key, vars = {}) {
|
|
141
|
+
const template = messages[lang][key] ?? messages.en[key] ?? key;
|
|
142
|
+
return template.replace(/\{(\w+)\}/g, (_, k) => (vars[k] === undefined ? `{${k}}` : String(vars[k])));
|
|
143
|
+
}
|
|
144
|
+
export function formatBytes(n) {
|
|
145
|
+
if (n < 1024)
|
|
146
|
+
return `${n} B`;
|
|
147
|
+
if (n < 1024 * 1024)
|
|
148
|
+
return `${(n / 1024).toFixed(1)} KB`;
|
|
149
|
+
return `${(n / 1024 / 1024).toFixed(2)} MB`;
|
|
150
|
+
}
|
|
151
|
+
export function describeStep(step, lang) {
|
|
152
|
+
const pages = (p, fallback) => {
|
|
153
|
+
const expr = (p ?? fallback).trim();
|
|
154
|
+
if (expr === 'all')
|
|
155
|
+
return t(lang, 'pages.all');
|
|
156
|
+
if (expr === 'last')
|
|
157
|
+
return t(lang, 'pages.last');
|
|
158
|
+
return t(lang, /^\d+$/.test(expr) ? 'pages.one' : 'pages.many', { p: expr });
|
|
159
|
+
};
|
|
160
|
+
switch (step.op) {
|
|
161
|
+
case 'merge': return step.files ? t(lang, 'step.merge', { files: step.files.join(', ') }) : t(lang, 'step.mergeAll');
|
|
162
|
+
case 'fromImages': return step.files ? t(lang, 'step.fromImages', { files: step.files.join(', ') }) : t(lang, 'step.fromImagesAll');
|
|
163
|
+
case 'select': return t(lang, 'step.select', { pages: pages(step.pages, 'all') });
|
|
164
|
+
case 'remove': return t(lang, 'step.remove', { pages: pages(step.pages, 'all') });
|
|
165
|
+
case 'rotate': return t(lang, 'step.rotate', { angle: step.angle, pages: pages(step.pages, 'all') });
|
|
166
|
+
case 'stampText': return t(lang, 'step.stampText', { text: step.text, pages: pages(step.pages, 'all') });
|
|
167
|
+
case 'sign': return t(lang, 'step.sign', { image: step.image, pages: pages(step.pages, 'last') });
|
|
168
|
+
case 'watermark': return t(lang, 'step.watermark', { text: step.text });
|
|
169
|
+
case 'numberPages': return t(lang, 'step.numberPages');
|
|
170
|
+
case 'stripMetadata': return t(lang, 'step.stripMetadata');
|
|
171
|
+
case 'setMetadata': return t(lang, 'step.setMetadata');
|
|
172
|
+
case 'optimize': return t(lang, 'step.optimize');
|
|
173
|
+
case 'compress':
|
|
174
|
+
return step.targetBytes !== undefined
|
|
175
|
+
? t(lang, 'step.compressTarget', { target: formatBytes(step.targetBytes) })
|
|
176
|
+
: t(lang, 'step.compress', { level: t(lang, `level.${step.level ?? 'balanced'}`) });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/** Today's date as YYYY-MM-DD in the user's local time zone. */
|
|
180
|
+
export function localDate(d = new Date()) {
|
|
181
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
182
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=i18n.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Source steps create the working document. If a recipe starts with any other step, all PDF inputs are merged first. */
|
|
3
|
+
export declare const MergeStep: z.ZodObject<{
|
|
4
|
+
op: z.ZodLiteral<"merge">;
|
|
5
|
+
files: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
6
|
+
}, z.core.$strict>;
|
|
7
|
+
export declare const FromImagesStep: z.ZodObject<{
|
|
8
|
+
op: z.ZodLiteral<"fromImages">;
|
|
9
|
+
files: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
10
|
+
pageSize: z.ZodOptional<z.ZodEnum<{
|
|
11
|
+
image: "image";
|
|
12
|
+
a4: "a4";
|
|
13
|
+
letter: "letter";
|
|
14
|
+
}>>;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
export declare const SelectStep: z.ZodObject<{
|
|
17
|
+
op: z.ZodLiteral<"select">;
|
|
18
|
+
pages: z.ZodString;
|
|
19
|
+
}, z.core.$strict>;
|
|
20
|
+
export declare const RemoveStep: z.ZodObject<{
|
|
21
|
+
op: z.ZodLiteral<"remove">;
|
|
22
|
+
pages: z.ZodString;
|
|
23
|
+
}, z.core.$strict>;
|
|
24
|
+
export declare const RotateStep: z.ZodObject<{
|
|
25
|
+
op: z.ZodLiteral<"rotate">;
|
|
26
|
+
angle: z.ZodUnion<readonly [z.ZodLiteral<90>, z.ZodLiteral<180>, z.ZodLiteral<270>, z.ZodLiteral<-90>]>;
|
|
27
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, z.core.$strict>;
|
|
29
|
+
export declare const StampTextStep: z.ZodObject<{
|
|
30
|
+
op: z.ZodLiteral<"stampText">;
|
|
31
|
+
text: z.ZodString;
|
|
32
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
33
|
+
anchor: z.ZodOptional<z.ZodEnum<{
|
|
34
|
+
"top-left": "top-left";
|
|
35
|
+
"top-right": "top-right";
|
|
36
|
+
"top-center": "top-center";
|
|
37
|
+
"bottom-left": "bottom-left";
|
|
38
|
+
"bottom-right": "bottom-right";
|
|
39
|
+
"bottom-center": "bottom-center";
|
|
40
|
+
center: "center";
|
|
41
|
+
}>>;
|
|
42
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
43
|
+
color: z.ZodOptional<z.ZodString>;
|
|
44
|
+
}, z.core.$strict>;
|
|
45
|
+
export declare const SignStep: z.ZodObject<{
|
|
46
|
+
op: z.ZodLiteral<"sign">;
|
|
47
|
+
image: z.ZodString;
|
|
48
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
49
|
+
anchor: z.ZodOptional<z.ZodEnum<{
|
|
50
|
+
"top-left": "top-left";
|
|
51
|
+
"top-right": "top-right";
|
|
52
|
+
"top-center": "top-center";
|
|
53
|
+
"bottom-left": "bottom-left";
|
|
54
|
+
"bottom-right": "bottom-right";
|
|
55
|
+
"bottom-center": "bottom-center";
|
|
56
|
+
center: "center";
|
|
57
|
+
}>>;
|
|
58
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
59
|
+
}, z.core.$strict>;
|
|
60
|
+
export declare const WatermarkStep: z.ZodObject<{
|
|
61
|
+
op: z.ZodLiteral<"watermark">;
|
|
62
|
+
text: z.ZodString;
|
|
63
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
64
|
+
opacity: z.ZodOptional<z.ZodNumber>;
|
|
65
|
+
color: z.ZodOptional<z.ZodString>;
|
|
66
|
+
}, z.core.$strict>;
|
|
67
|
+
export declare const NumberPagesStep: z.ZodObject<{
|
|
68
|
+
op: z.ZodLiteral<"numberPages">;
|
|
69
|
+
format: z.ZodOptional<z.ZodString>;
|
|
70
|
+
anchor: z.ZodOptional<z.ZodEnum<{
|
|
71
|
+
"top-left": "top-left";
|
|
72
|
+
"top-right": "top-right";
|
|
73
|
+
"top-center": "top-center";
|
|
74
|
+
"bottom-left": "bottom-left";
|
|
75
|
+
"bottom-right": "bottom-right";
|
|
76
|
+
"bottom-center": "bottom-center";
|
|
77
|
+
center: "center";
|
|
78
|
+
}>>;
|
|
79
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
80
|
+
}, z.core.$strict>;
|
|
81
|
+
export declare const StripMetadataStep: z.ZodObject<{
|
|
82
|
+
op: z.ZodLiteral<"stripMetadata">;
|
|
83
|
+
}, z.core.$strict>;
|
|
84
|
+
export declare const SetMetadataStep: z.ZodObject<{
|
|
85
|
+
op: z.ZodLiteral<"setMetadata">;
|
|
86
|
+
title: z.ZodOptional<z.ZodString>;
|
|
87
|
+
author: z.ZodOptional<z.ZodString>;
|
|
88
|
+
subject: z.ZodOptional<z.ZodString>;
|
|
89
|
+
}, z.core.$strict>;
|
|
90
|
+
export declare const OptimizeStep: z.ZodObject<{
|
|
91
|
+
op: z.ZodLiteral<"optimize">;
|
|
92
|
+
}, z.core.$strict>;
|
|
93
|
+
export declare const CompressStep: z.ZodObject<{
|
|
94
|
+
op: z.ZodLiteral<"compress">;
|
|
95
|
+
level: z.ZodOptional<z.ZodEnum<{
|
|
96
|
+
lossless: "lossless";
|
|
97
|
+
balanced: "balanced";
|
|
98
|
+
strong: "strong";
|
|
99
|
+
max: "max";
|
|
100
|
+
}>>;
|
|
101
|
+
targetBytes: z.ZodOptional<z.ZodNumber>;
|
|
102
|
+
}, z.core.$strict>;
|
|
103
|
+
export declare const Step: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
104
|
+
op: z.ZodLiteral<"merge">;
|
|
105
|
+
files: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
106
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
107
|
+
op: z.ZodLiteral<"fromImages">;
|
|
108
|
+
files: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
109
|
+
pageSize: z.ZodOptional<z.ZodEnum<{
|
|
110
|
+
image: "image";
|
|
111
|
+
a4: "a4";
|
|
112
|
+
letter: "letter";
|
|
113
|
+
}>>;
|
|
114
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
115
|
+
op: z.ZodLiteral<"select">;
|
|
116
|
+
pages: z.ZodString;
|
|
117
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
118
|
+
op: z.ZodLiteral<"remove">;
|
|
119
|
+
pages: z.ZodString;
|
|
120
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
121
|
+
op: z.ZodLiteral<"rotate">;
|
|
122
|
+
angle: z.ZodUnion<readonly [z.ZodLiteral<90>, z.ZodLiteral<180>, z.ZodLiteral<270>, z.ZodLiteral<-90>]>;
|
|
123
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
124
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
125
|
+
op: z.ZodLiteral<"stampText">;
|
|
126
|
+
text: z.ZodString;
|
|
127
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
128
|
+
anchor: z.ZodOptional<z.ZodEnum<{
|
|
129
|
+
"top-left": "top-left";
|
|
130
|
+
"top-right": "top-right";
|
|
131
|
+
"top-center": "top-center";
|
|
132
|
+
"bottom-left": "bottom-left";
|
|
133
|
+
"bottom-right": "bottom-right";
|
|
134
|
+
"bottom-center": "bottom-center";
|
|
135
|
+
center: "center";
|
|
136
|
+
}>>;
|
|
137
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
138
|
+
color: z.ZodOptional<z.ZodString>;
|
|
139
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
140
|
+
op: z.ZodLiteral<"sign">;
|
|
141
|
+
image: z.ZodString;
|
|
142
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
143
|
+
anchor: z.ZodOptional<z.ZodEnum<{
|
|
144
|
+
"top-left": "top-left";
|
|
145
|
+
"top-right": "top-right";
|
|
146
|
+
"top-center": "top-center";
|
|
147
|
+
"bottom-left": "bottom-left";
|
|
148
|
+
"bottom-right": "bottom-right";
|
|
149
|
+
"bottom-center": "bottom-center";
|
|
150
|
+
center: "center";
|
|
151
|
+
}>>;
|
|
152
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
153
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
154
|
+
op: z.ZodLiteral<"watermark">;
|
|
155
|
+
text: z.ZodString;
|
|
156
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
157
|
+
opacity: z.ZodOptional<z.ZodNumber>;
|
|
158
|
+
color: z.ZodOptional<z.ZodString>;
|
|
159
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
160
|
+
op: z.ZodLiteral<"numberPages">;
|
|
161
|
+
format: z.ZodOptional<z.ZodString>;
|
|
162
|
+
anchor: z.ZodOptional<z.ZodEnum<{
|
|
163
|
+
"top-left": "top-left";
|
|
164
|
+
"top-right": "top-right";
|
|
165
|
+
"top-center": "top-center";
|
|
166
|
+
"bottom-left": "bottom-left";
|
|
167
|
+
"bottom-right": "bottom-right";
|
|
168
|
+
"bottom-center": "bottom-center";
|
|
169
|
+
center: "center";
|
|
170
|
+
}>>;
|
|
171
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
172
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
173
|
+
op: z.ZodLiteral<"stripMetadata">;
|
|
174
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
175
|
+
op: z.ZodLiteral<"setMetadata">;
|
|
176
|
+
title: z.ZodOptional<z.ZodString>;
|
|
177
|
+
author: z.ZodOptional<z.ZodString>;
|
|
178
|
+
subject: z.ZodOptional<z.ZodString>;
|
|
179
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
180
|
+
op: z.ZodLiteral<"optimize">;
|
|
181
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
182
|
+
op: z.ZodLiteral<"compress">;
|
|
183
|
+
level: z.ZodOptional<z.ZodEnum<{
|
|
184
|
+
lossless: "lossless";
|
|
185
|
+
balanced: "balanced";
|
|
186
|
+
strong: "strong";
|
|
187
|
+
max: "max";
|
|
188
|
+
}>>;
|
|
189
|
+
targetBytes: z.ZodOptional<z.ZodNumber>;
|
|
190
|
+
}, z.core.$strict>], "op">;
|
|
191
|
+
export type Step = z.infer<typeof Step>;
|
|
192
|
+
export declare const Goals: z.ZodObject<{
|
|
193
|
+
maxBytes: z.ZodOptional<z.ZodNumber>;
|
|
194
|
+
pageCount: z.ZodOptional<z.ZodNumber>;
|
|
195
|
+
maxPages: z.ZodOptional<z.ZodNumber>;
|
|
196
|
+
noMetadata: z.ZodOptional<z.ZodBoolean>;
|
|
197
|
+
}, z.core.$strict>;
|
|
198
|
+
export type Goals = z.infer<typeof Goals>;
|
|
199
|
+
export declare const Recipe: z.ZodObject<{
|
|
200
|
+
version: z.ZodLiteral<1>;
|
|
201
|
+
name: z.ZodOptional<z.ZodString>;
|
|
202
|
+
description: z.ZodOptional<z.ZodString>;
|
|
203
|
+
steps: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
204
|
+
op: z.ZodLiteral<"merge">;
|
|
205
|
+
files: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
206
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
207
|
+
op: z.ZodLiteral<"fromImages">;
|
|
208
|
+
files: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
209
|
+
pageSize: z.ZodOptional<z.ZodEnum<{
|
|
210
|
+
image: "image";
|
|
211
|
+
a4: "a4";
|
|
212
|
+
letter: "letter";
|
|
213
|
+
}>>;
|
|
214
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
215
|
+
op: z.ZodLiteral<"select">;
|
|
216
|
+
pages: z.ZodString;
|
|
217
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
218
|
+
op: z.ZodLiteral<"remove">;
|
|
219
|
+
pages: z.ZodString;
|
|
220
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
221
|
+
op: z.ZodLiteral<"rotate">;
|
|
222
|
+
angle: z.ZodUnion<readonly [z.ZodLiteral<90>, z.ZodLiteral<180>, z.ZodLiteral<270>, z.ZodLiteral<-90>]>;
|
|
223
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
224
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
225
|
+
op: z.ZodLiteral<"stampText">;
|
|
226
|
+
text: z.ZodString;
|
|
227
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
228
|
+
anchor: z.ZodOptional<z.ZodEnum<{
|
|
229
|
+
"top-left": "top-left";
|
|
230
|
+
"top-right": "top-right";
|
|
231
|
+
"top-center": "top-center";
|
|
232
|
+
"bottom-left": "bottom-left";
|
|
233
|
+
"bottom-right": "bottom-right";
|
|
234
|
+
"bottom-center": "bottom-center";
|
|
235
|
+
center: "center";
|
|
236
|
+
}>>;
|
|
237
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
238
|
+
color: z.ZodOptional<z.ZodString>;
|
|
239
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
240
|
+
op: z.ZodLiteral<"sign">;
|
|
241
|
+
image: z.ZodString;
|
|
242
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
243
|
+
anchor: z.ZodOptional<z.ZodEnum<{
|
|
244
|
+
"top-left": "top-left";
|
|
245
|
+
"top-right": "top-right";
|
|
246
|
+
"top-center": "top-center";
|
|
247
|
+
"bottom-left": "bottom-left";
|
|
248
|
+
"bottom-right": "bottom-right";
|
|
249
|
+
"bottom-center": "bottom-center";
|
|
250
|
+
center: "center";
|
|
251
|
+
}>>;
|
|
252
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
253
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
254
|
+
op: z.ZodLiteral<"watermark">;
|
|
255
|
+
text: z.ZodString;
|
|
256
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
257
|
+
opacity: z.ZodOptional<z.ZodNumber>;
|
|
258
|
+
color: z.ZodOptional<z.ZodString>;
|
|
259
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
260
|
+
op: z.ZodLiteral<"numberPages">;
|
|
261
|
+
format: z.ZodOptional<z.ZodString>;
|
|
262
|
+
anchor: z.ZodOptional<z.ZodEnum<{
|
|
263
|
+
"top-left": "top-left";
|
|
264
|
+
"top-right": "top-right";
|
|
265
|
+
"top-center": "top-center";
|
|
266
|
+
"bottom-left": "bottom-left";
|
|
267
|
+
"bottom-right": "bottom-right";
|
|
268
|
+
"bottom-center": "bottom-center";
|
|
269
|
+
center: "center";
|
|
270
|
+
}>>;
|
|
271
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
272
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
273
|
+
op: z.ZodLiteral<"stripMetadata">;
|
|
274
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
275
|
+
op: z.ZodLiteral<"setMetadata">;
|
|
276
|
+
title: z.ZodOptional<z.ZodString>;
|
|
277
|
+
author: z.ZodOptional<z.ZodString>;
|
|
278
|
+
subject: z.ZodOptional<z.ZodString>;
|
|
279
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
280
|
+
op: z.ZodLiteral<"optimize">;
|
|
281
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
282
|
+
op: z.ZodLiteral<"compress">;
|
|
283
|
+
level: z.ZodOptional<z.ZodEnum<{
|
|
284
|
+
lossless: "lossless";
|
|
285
|
+
balanced: "balanced";
|
|
286
|
+
strong: "strong";
|
|
287
|
+
max: "max";
|
|
288
|
+
}>>;
|
|
289
|
+
targetBytes: z.ZodOptional<z.ZodNumber>;
|
|
290
|
+
}, z.core.$strict>], "op">>;
|
|
291
|
+
output: z.ZodOptional<z.ZodObject<{
|
|
292
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
293
|
+
}, z.core.$strict>>;
|
|
294
|
+
goals: z.ZodOptional<z.ZodObject<{
|
|
295
|
+
maxBytes: z.ZodOptional<z.ZodNumber>;
|
|
296
|
+
pageCount: z.ZodOptional<z.ZodNumber>;
|
|
297
|
+
maxPages: z.ZodOptional<z.ZodNumber>;
|
|
298
|
+
noMetadata: z.ZodOptional<z.ZodBoolean>;
|
|
299
|
+
}, z.core.$strict>>;
|
|
300
|
+
}, z.core.$strict>;
|
|
301
|
+
export type Recipe = z.infer<typeof Recipe>;
|
|
302
|
+
/** JSON Schema for agents and editors. */
|
|
303
|
+
export declare const recipeJsonSchema: () => z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
304
|
+
version: z.ZodLiteral<1>;
|
|
305
|
+
name: z.ZodOptional<z.ZodString>;
|
|
306
|
+
description: z.ZodOptional<z.ZodString>;
|
|
307
|
+
steps: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
308
|
+
op: z.ZodLiteral<"merge">;
|
|
309
|
+
files: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
310
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
311
|
+
op: z.ZodLiteral<"fromImages">;
|
|
312
|
+
files: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
313
|
+
pageSize: z.ZodOptional<z.ZodEnum<{
|
|
314
|
+
image: "image";
|
|
315
|
+
a4: "a4";
|
|
316
|
+
letter: "letter";
|
|
317
|
+
}>>;
|
|
318
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
319
|
+
op: z.ZodLiteral<"select">;
|
|
320
|
+
pages: z.ZodString;
|
|
321
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
322
|
+
op: z.ZodLiteral<"remove">;
|
|
323
|
+
pages: z.ZodString;
|
|
324
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
325
|
+
op: z.ZodLiteral<"rotate">;
|
|
326
|
+
angle: z.ZodUnion<readonly [z.ZodLiteral<90>, z.ZodLiteral<180>, z.ZodLiteral<270>, z.ZodLiteral<-90>]>;
|
|
327
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
328
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
329
|
+
op: z.ZodLiteral<"stampText">;
|
|
330
|
+
text: z.ZodString;
|
|
331
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
332
|
+
anchor: z.ZodOptional<z.ZodEnum<{
|
|
333
|
+
"top-left": "top-left";
|
|
334
|
+
"top-right": "top-right";
|
|
335
|
+
"top-center": "top-center";
|
|
336
|
+
"bottom-left": "bottom-left";
|
|
337
|
+
"bottom-right": "bottom-right";
|
|
338
|
+
"bottom-center": "bottom-center";
|
|
339
|
+
center: "center";
|
|
340
|
+
}>>;
|
|
341
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
342
|
+
color: z.ZodOptional<z.ZodString>;
|
|
343
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
344
|
+
op: z.ZodLiteral<"sign">;
|
|
345
|
+
image: z.ZodString;
|
|
346
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
347
|
+
anchor: z.ZodOptional<z.ZodEnum<{
|
|
348
|
+
"top-left": "top-left";
|
|
349
|
+
"top-right": "top-right";
|
|
350
|
+
"top-center": "top-center";
|
|
351
|
+
"bottom-left": "bottom-left";
|
|
352
|
+
"bottom-right": "bottom-right";
|
|
353
|
+
"bottom-center": "bottom-center";
|
|
354
|
+
center: "center";
|
|
355
|
+
}>>;
|
|
356
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
357
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
358
|
+
op: z.ZodLiteral<"watermark">;
|
|
359
|
+
text: z.ZodString;
|
|
360
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
361
|
+
opacity: z.ZodOptional<z.ZodNumber>;
|
|
362
|
+
color: z.ZodOptional<z.ZodString>;
|
|
363
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
364
|
+
op: z.ZodLiteral<"numberPages">;
|
|
365
|
+
format: z.ZodOptional<z.ZodString>;
|
|
366
|
+
anchor: z.ZodOptional<z.ZodEnum<{
|
|
367
|
+
"top-left": "top-left";
|
|
368
|
+
"top-right": "top-right";
|
|
369
|
+
"top-center": "top-center";
|
|
370
|
+
"bottom-left": "bottom-left";
|
|
371
|
+
"bottom-right": "bottom-right";
|
|
372
|
+
"bottom-center": "bottom-center";
|
|
373
|
+
center: "center";
|
|
374
|
+
}>>;
|
|
375
|
+
pages: z.ZodOptional<z.ZodString>;
|
|
376
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
377
|
+
op: z.ZodLiteral<"stripMetadata">;
|
|
378
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
379
|
+
op: z.ZodLiteral<"setMetadata">;
|
|
380
|
+
title: z.ZodOptional<z.ZodString>;
|
|
381
|
+
author: z.ZodOptional<z.ZodString>;
|
|
382
|
+
subject: z.ZodOptional<z.ZodString>;
|
|
383
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
384
|
+
op: z.ZodLiteral<"optimize">;
|
|
385
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
386
|
+
op: z.ZodLiteral<"compress">;
|
|
387
|
+
level: z.ZodOptional<z.ZodEnum<{
|
|
388
|
+
lossless: "lossless";
|
|
389
|
+
balanced: "balanced";
|
|
390
|
+
strong: "strong";
|
|
391
|
+
max: "max";
|
|
392
|
+
}>>;
|
|
393
|
+
targetBytes: z.ZodOptional<z.ZodNumber>;
|
|
394
|
+
}, z.core.$strict>], "op">>;
|
|
395
|
+
output: z.ZodOptional<z.ZodObject<{
|
|
396
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
397
|
+
}, z.core.$strict>>;
|
|
398
|
+
goals: z.ZodOptional<z.ZodObject<{
|
|
399
|
+
maxBytes: z.ZodOptional<z.ZodNumber>;
|
|
400
|
+
pageCount: z.ZodOptional<z.ZodNumber>;
|
|
401
|
+
maxPages: z.ZodOptional<z.ZodNumber>;
|
|
402
|
+
noMetadata: z.ZodOptional<z.ZodBoolean>;
|
|
403
|
+
}, z.core.$strict>>;
|
|
404
|
+
}, z.core.$strict>>;
|
|
405
|
+
/** Steps that drop content or overwrite information; running them requires explicit confirmation. */
|
|
406
|
+
export declare const DESTRUCTIVE_OPS: Set<"merge" | "fromImages" | "select" | "remove" | "rotate" | "stampText" | "sign" | "watermark" | "numberPages" | "stripMetadata" | "setMetadata" | "optimize" | "compress">;
|
|
407
|
+
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const pages = z.string().min(1).describe('Page range, 1-based: "1-3,5", "last", "last-1", "4-last", "odd", "even", "all".');
|
|
3
|
+
const anchor = z.enum(['top-left', 'top-right', 'top-center', 'bottom-left', 'bottom-right', 'bottom-center', 'center']);
|
|
4
|
+
const color = z.string().regex(/^#?[0-9a-fA-F]{6}$/).describe('Hex color, e.g. "#1f3864".');
|
|
5
|
+
/** Source steps create the working document. If a recipe starts with any other step, all PDF inputs are merged first. */
|
|
6
|
+
export const MergeStep = z.object({
|
|
7
|
+
op: z.literal('merge'),
|
|
8
|
+
files: z.array(z.string()).min(1).optional().describe('Input names to merge, in order. Defaults to every PDF input in the order given.'),
|
|
9
|
+
}).strict();
|
|
10
|
+
export const FromImagesStep = z.object({
|
|
11
|
+
op: z.literal('fromImages'),
|
|
12
|
+
files: z.array(z.string()).min(1).optional().describe('Image input names (PNG/JPEG). Defaults to every image input.'),
|
|
13
|
+
pageSize: z.enum(['image', 'a4', 'letter']).optional(),
|
|
14
|
+
}).strict();
|
|
15
|
+
export const SelectStep = z.object({ op: z.literal('select'), pages }).strict()
|
|
16
|
+
.describe('Keep only these pages, in this order. Drops the rest.');
|
|
17
|
+
export const RemoveStep = z.object({ op: z.literal('remove'), pages }).strict()
|
|
18
|
+
.describe('Delete these pages.');
|
|
19
|
+
export const RotateStep = z.object({
|
|
20
|
+
op: z.literal('rotate'),
|
|
21
|
+
angle: z.union([z.literal(90), z.literal(180), z.literal(270), z.literal(-90)]),
|
|
22
|
+
pages: pages.optional(),
|
|
23
|
+
}).strict();
|
|
24
|
+
export const StampTextStep = z.object({
|
|
25
|
+
op: z.literal('stampText'),
|
|
26
|
+
text: z.string().min(1).describe('Text to add. "{date}" is replaced by today\'s date (YYYY-MM-DD).'),
|
|
27
|
+
pages: pages.optional(),
|
|
28
|
+
anchor: anchor.optional(),
|
|
29
|
+
size: z.number().positive().max(200).optional(),
|
|
30
|
+
color: color.optional(),
|
|
31
|
+
}).strict();
|
|
32
|
+
export const SignStep = z.object({
|
|
33
|
+
op: z.literal('sign'),
|
|
34
|
+
image: z.string().describe('Name of the image input with the signature (PNG with transparency works best).'),
|
|
35
|
+
pages: pages.optional().describe('Defaults to "last".'),
|
|
36
|
+
anchor: anchor.optional(),
|
|
37
|
+
width: z.number().positive().max(600).optional(),
|
|
38
|
+
}).strict();
|
|
39
|
+
export const WatermarkStep = z.object({
|
|
40
|
+
op: z.literal('watermark'),
|
|
41
|
+
text: z.string().min(1),
|
|
42
|
+
pages: pages.optional(),
|
|
43
|
+
opacity: z.number().min(0.05).max(1).optional(),
|
|
44
|
+
color: color.optional(),
|
|
45
|
+
}).strict();
|
|
46
|
+
export const NumberPagesStep = z.object({
|
|
47
|
+
op: z.literal('numberPages'),
|
|
48
|
+
format: z.string().optional().describe('Supports {n} and {total}, e.g. "Página {n} de {total}".'),
|
|
49
|
+
anchor: anchor.optional(),
|
|
50
|
+
pages: pages.optional(),
|
|
51
|
+
}).strict();
|
|
52
|
+
export const StripMetadataStep = z.object({ op: z.literal('stripMetadata') }).strict();
|
|
53
|
+
export const SetMetadataStep = z.object({
|
|
54
|
+
op: z.literal('setMetadata'),
|
|
55
|
+
title: z.string().optional(),
|
|
56
|
+
author: z.string().optional(),
|
|
57
|
+
subject: z.string().optional(),
|
|
58
|
+
}).strict();
|
|
59
|
+
export const OptimizeStep = z.object({ op: z.literal('optimize') }).strict()
|
|
60
|
+
.describe('Lossless optimization (same as compress with level "lossless").');
|
|
61
|
+
export const CompressStep = z.object({
|
|
62
|
+
op: z.literal('compress'),
|
|
63
|
+
level: z.enum(['lossless', 'balanced', 'strong', 'max']).optional()
|
|
64
|
+
.describe('lossless: no image changes. balanced: images at 150 dpi (default). strong: 110 dpi. max: 72 dpi. Text and vectors are never rasterized.'),
|
|
65
|
+
targetBytes: z.number().int().positive().optional()
|
|
66
|
+
.describe('Try stronger levels until the file is at most this size. Defaults to goals.maxBytes when no level is given.'),
|
|
67
|
+
}).strict();
|
|
68
|
+
export const Step = z.discriminatedUnion('op', [
|
|
69
|
+
MergeStep,
|
|
70
|
+
FromImagesStep,
|
|
71
|
+
SelectStep,
|
|
72
|
+
RemoveStep,
|
|
73
|
+
RotateStep,
|
|
74
|
+
StampTextStep,
|
|
75
|
+
SignStep,
|
|
76
|
+
WatermarkStep,
|
|
77
|
+
NumberPagesStep,
|
|
78
|
+
StripMetadataStep,
|
|
79
|
+
SetMetadataStep,
|
|
80
|
+
OptimizeStep,
|
|
81
|
+
CompressStep,
|
|
82
|
+
]);
|
|
83
|
+
export const Goals = z.object({
|
|
84
|
+
maxBytes: z.number().int().positive().optional().describe('The result must be at most this many bytes.'),
|
|
85
|
+
pageCount: z.number().int().positive().optional().describe('The result must have exactly this many pages.'),
|
|
86
|
+
maxPages: z.number().int().positive().optional(),
|
|
87
|
+
noMetadata: z.boolean().optional().describe('The result must carry no identifying metadata.'),
|
|
88
|
+
}).strict();
|
|
89
|
+
export const Recipe = z.object({
|
|
90
|
+
version: z.literal(1),
|
|
91
|
+
name: z.string().max(120).optional(),
|
|
92
|
+
description: z.string().max(1000).optional(),
|
|
93
|
+
steps: z.array(Step).min(1).max(50),
|
|
94
|
+
output: z.object({
|
|
95
|
+
filename: z.string().max(200).optional().describe('Supports {date} and {name} (first input without extension).'),
|
|
96
|
+
}).strict().optional(),
|
|
97
|
+
goals: Goals.optional(),
|
|
98
|
+
}).strict();
|
|
99
|
+
/** JSON Schema for agents and editors. */
|
|
100
|
+
export const recipeJsonSchema = () => z.toJSONSchema(Recipe);
|
|
101
|
+
/** Steps that drop content or overwrite information; running them requires explicit confirmation. */
|
|
102
|
+
export const DESTRUCTIVE_OPS = new Set(['select', 'remove', 'stripMetadata', 'setMetadata']);
|
|
103
|
+
//# sourceMappingURL=schema.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hilvana/recipes",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Hilvana recipes: a versioned JSON format for chained PDF and Word operations, with validation, execution and goal verification.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pdf",
|
|
7
|
+
"workflow",
|
|
8
|
+
"recipes",
|
|
9
|
+
"agents",
|
|
10
|
+
"json-schema"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "Jorge Grajales (https://jorgegrajales.dev)",
|
|
14
|
+
"homepage": "https://github.com/gethilvana/hilvana#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/gethilvana/hilvana/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/gethilvana/hilvana",
|
|
21
|
+
"directory": "packages/recipes"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "dist/index.js",
|
|
25
|
+
"types": "dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"!dist/**/*.map",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"provenance": true
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@hilvana/core": "0.1.0",
|
|
47
|
+
"zod": "^4.1.0",
|
|
48
|
+
"@hilvana/office": "0.1.0"
|
|
49
|
+
}
|
|
50
|
+
}
|