latex-kit 0.5.1 → 0.6.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/build.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Engine, EngineChoice } from '@latex-kit/render';
2
- import { Diagnostic, Variant } from '@latex-kit/template';
2
+ import { BlankStyle, Diagnostic, Variant } from '@latex-kit/template';
3
3
  import { Project } from './project';
4
4
  export interface BuildOptions {
5
5
  variant?: Variant;
@@ -21,6 +21,15 @@ export interface BuildOptions {
21
21
  platform?: string | null;
22
22
  /** Build twice and fail unless the PDFs are byte-identical. */
23
23
  verify?: boolean;
24
+ /** How blanks print in blank builds: `labelled` (default), `lines` to write on, or `names` in brackets. */
25
+ blanks?: BlankStyle;
26
+ /**
27
+ * Draft builds: print every filled-in value in red, to review what came from
28
+ * the record. Writes `<document>-highlight.pdf`.
29
+ */
30
+ highlight?: boolean;
31
+ /** Draft builds: print a missing value as a red marker (default) or as a blank to fill in. */
32
+ missing?: 'marker' | 'blank';
24
33
  /** Stop after writing the .tex (no TeX run). */
25
34
  texOnly?: boolean;
26
35
  /** Use this ID when the record has none, instead of minting one (for redlines). */
@@ -38,6 +47,8 @@ export interface BuildResult {
38
47
  pdf: string | null;
39
48
  sha256: string | null;
40
49
  docId: string | null;
50
+ /** `<document>.form.json`: where the spots to sign or fill in landed, when the template marks any. */
51
+ form: string | null;
41
52
  /** The ID was minted by this build and written to the record. */
42
53
  minted: boolean;
43
54
  sourceDateEpoch: number;
package/build.js CHANGED
@@ -13,6 +13,7 @@ const crypto_1 = require("crypto");
13
13
  const fs_1 = require("fs");
14
14
  const os_1 = require("os");
15
15
  const path_1 = require("path");
16
+ const form_1 = require("./form");
16
17
  class BuildError extends Error {
17
18
  diagnostics;
18
19
  constructor(message, diagnostics) {
@@ -102,7 +103,8 @@ async function run(job) {
102
103
  snippets.add((0, path_1.resolve)(s.file));
103
104
  return s;
104
105
  };
105
- const strict = options.strict ?? isCI();
106
+ // asking for blanks where values are missing means missing values are expected
107
+ const strict = options.strict ?? (options.missing === 'blank' ? false : isCI());
106
108
  const files = [...job.inputs, template.texFile, ...(template.schemaFile ? [template.schemaFile] : [])];
107
109
  const { epoch, reproducible } = buildEpoch(files);
108
110
  let docId = job.docId;
@@ -112,7 +114,11 @@ async function run(job) {
112
114
  minted = true;
113
115
  }
114
116
  const outDir = options.outDir ?? (0, path_1.join)(project.outDir, job.name);
115
- const job_ = variant === 'final' ? job.name : `${job.name}-${variant}`;
117
+ const blanks = variant === 'blank' ? (options.blanks ?? project.config.blanks) : undefined;
118
+ // the names view is its own file, so it can sit next to the form to fill in
119
+ const highlight = variant === 'draft' && Boolean(options.highlight);
120
+ const missingAs = variant === 'draft' ? options.missing : undefined;
121
+ const job_ = variant === 'final' ? job.name : blanks === 'names' ? `${job.name}-names` : highlight ? `${job.name}-highlight` : `${job.name}-${variant}`;
116
122
  // signed builds: copy signature images next to the .tex for this build only
117
123
  const stageDir = (0, path_1.join)(outDir, 'lk-signatures');
118
124
  const staged = [];
@@ -158,6 +164,7 @@ async function run(job) {
158
164
  docId,
159
165
  template: template.name,
160
166
  allowMissing: variant === 'draft' ? !strict : undefined,
167
+ markValues: highlight,
161
168
  loadSnippet,
162
169
  loadClause: project.loadClause,
163
170
  components: project.components,
@@ -176,7 +183,7 @@ async function run(job) {
176
183
  (0, fs_1.mkdirSync)(outDir, { recursive: true });
177
184
  const texPath = (0, path_1.join)(outDir, `${job_}.tex`);
178
185
  const stamp = `${new Date(finalEpoch.epoch * 1000).toISOString().slice(0, 10)} ${gitShortHead(project.root)}`;
179
- const tex = (0, template_1.wrapDocument)(evaluated.tex, { variant, stamp });
186
+ const tex = (0, template_1.wrapDocument)(evaluated.tex, { variant, stamp, blanks, missing: missingAs });
180
187
  (0, fs_1.writeFileSync)(texPath, tex);
181
188
  (0, fs_1.writeFileSync)((0, path_1.join)(outDir, 'latex-kit.sty'), template_1.LATEX_KIT_STY);
182
189
  const result = {
@@ -193,6 +200,7 @@ async function run(job) {
193
200
  engine: null,
194
201
  engineReason: null,
195
202
  cached: false,
203
+ form: null,
196
204
  diagnostics,
197
205
  };
198
206
  if (options.texOnly)
@@ -234,6 +242,7 @@ async function run(job) {
234
242
  const keyInputs = [...filesUnder(template.dir), ...staged].map((f) => [posixRel(project.root, f), sha256((0, fs_1.readFileSync)(f))]);
235
243
  const cacheKey = sha256(JSON.stringify({ v: 1, tex: sha256(tex), sty: sha256(template_1.LATEX_KIT_STY), engine, backend, image: backend === 'docker' ? (image ?? 'default') : null, platform: platform ?? null, epoch: finalEpoch.epoch, inputs: keyInputs }));
236
244
  const manifestPath = (0, path_1.join)(outDir, `${job_}.manifest.json`);
245
+ const formBase = (0, path_1.join)(outDir, job_);
237
246
  const pdfPath = (0, path_1.join)(outDir, `${job_}.pdf`);
238
247
  if (!options.force && !options.verify && (0, fs_1.existsSync)(manifestPath) && (0, fs_1.existsSync)(pdfPath)) {
239
248
  try {
@@ -243,6 +252,7 @@ async function run(job) {
243
252
  result.pdf = pdfPath;
244
253
  result.sha256 = pdfSha;
245
254
  result.cached = true;
255
+ result.form = (0, fs_1.existsSync)(formBase + '.form.json') ? formBase + '.form.json' : null;
246
256
  return result;
247
257
  }
248
258
  }
@@ -250,6 +260,8 @@ async function run(job) {
250
260
  // an unreadable manifest just means a rebuild
251
261
  }
252
262
  }
263
+ // TeX writes marked spots to <job>.form; a file from an earlier run must not survive
264
+ (0, fs_1.rmSync)(formBase + '.form', { force: true });
253
265
  let rendered;
254
266
  try {
255
267
  rendered = await (0, render_1.render)({ ...renderOpts, outDir: (0, path_1.relative)(project.root, outDir) });
@@ -265,6 +277,7 @@ async function run(job) {
265
277
  }
266
278
  result.pdf = rendered.pdf;
267
279
  result.sha256 = rendered.sha256;
280
+ result.form = (0, form_1.writeFormJson)(formBase);
268
281
  if (options.verify) {
269
282
  // same output path: some tools (Ghostscript) hash the path into the PDF ID
270
283
  const again = await (0, render_1.render)({ ...renderOpts, outDir: (0, path_1.relative)(project.root, outDir) });
package/cli.js CHANGED
@@ -20,8 +20,8 @@ const app = new inquirerer_1.CLI(commands_1.commands, {
20
20
  version: (0, commands_1.version)(),
21
21
  minimistOpts: {
22
22
  alias: { h: 'help', v: 'version', o: 'out', e: 'engine' },
23
- boolean: ['help', 'version', 'local', 'verify', 'json', 'final', 'strict', 'tex-only', 'force', 'schema', 'paper', 'check'],
24
- string: ['out', 'engine', 'image', 'root', 'platform', 'source-date-epoch', 'variant', 'template', 'name', 'against', 'only', 'locale', 'signatures', 'preset'],
23
+ boolean: ['help', 'version', 'local', 'verify', 'json', 'final', 'strict', 'tex-only', 'force', 'schema', 'paper', 'check', 'highlight'],
24
+ string: ['out', 'engine', 'image', 'root', 'platform', 'source-date-epoch', 'variant', 'template', 'name', 'against', 'only', 'locale', 'signatures', 'preset', 'blanks', 'missing'],
25
25
  default: { strict: undefined, schema: true },
26
26
  },
27
27
  });
package/config.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Backend, EngineChoice } from '@latex-kit/render';
2
+ import type { BlankStyle } from '@latex-kit/template';
2
3
  /** latex-kit.config.ts (or .js, .mjs, .cjs, .json) at the project root. */
3
4
  export interface LatexKitConfig {
4
5
  /** One folder per template: `<templates>/<name>/template.tex` and optional `schema.ts`. Default `templates`. */
@@ -25,11 +26,17 @@ export interface LatexKitConfig {
25
26
  * override it. A leading ~ is the home folder.
26
27
  */
27
28
  signatures?: string;
29
+ /**
30
+ * How blanks print in blank builds: `labelled` (default, the field's name on
31
+ * a line), `lines` (an empty line to write on) or `names` (the name in
32
+ * brackets). `--blanks` overrides it.
33
+ */
34
+ blanks?: BlankStyle;
28
35
  backend?: Backend;
29
36
  image?: string;
30
37
  platform?: string | null;
31
38
  }
32
- export type ResolvedConfig = Required<Pick<LatexKitConfig, 'templates' | 'snippets' | 'clauses' | 'components' | 'data' | 'documents' | 'out' | 'locale'>> & Pick<LatexKitConfig, 'engine' | 'backend' | 'image' | 'platform' | 'signatures'> & {
39
+ export type ResolvedConfig = Required<Pick<LatexKitConfig, 'templates' | 'snippets' | 'clauses' | 'components' | 'data' | 'documents' | 'out' | 'locale'>> & Pick<LatexKitConfig, 'engine' | 'backend' | 'image' | 'platform' | 'signatures' | 'blanks'> & {
33
40
  file: string | null;
34
41
  };
35
42
  export declare function defineConfig(config: LatexKitConfig): LatexKitConfig;
package/esm/build.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Engine, EngineChoice } from '@latex-kit/render';
2
- import { Diagnostic, Variant } from '@latex-kit/template';
2
+ import { BlankStyle, Diagnostic, Variant } from '@latex-kit/template';
3
3
  import { Project } from './project';
4
4
  export interface BuildOptions {
5
5
  variant?: Variant;
@@ -21,6 +21,15 @@ export interface BuildOptions {
21
21
  platform?: string | null;
22
22
  /** Build twice and fail unless the PDFs are byte-identical. */
23
23
  verify?: boolean;
24
+ /** How blanks print in blank builds: `labelled` (default), `lines` to write on, or `names` in brackets. */
25
+ blanks?: BlankStyle;
26
+ /**
27
+ * Draft builds: print every filled-in value in red, to review what came from
28
+ * the record. Writes `<document>-highlight.pdf`.
29
+ */
30
+ highlight?: boolean;
31
+ /** Draft builds: print a missing value as a red marker (default) or as a blank to fill in. */
32
+ missing?: 'marker' | 'blank';
24
33
  /** Stop after writing the .tex (no TeX run). */
25
34
  texOnly?: boolean;
26
35
  /** Use this ID when the record has none, instead of minting one (for redlines). */
@@ -38,6 +47,8 @@ export interface BuildResult {
38
47
  pdf: string | null;
39
48
  sha256: string | null;
40
49
  docId: string | null;
50
+ /** `<document>.form.json`: where the spots to sign or fill in landed, when the template marks any. */
51
+ form: string | null;
41
52
  /** The ID was minted by this build and written to the record. */
42
53
  minted: boolean;
43
54
  sourceDateEpoch: number;
package/esm/build.js CHANGED
@@ -6,6 +6,7 @@ import { createHash } from 'crypto';
6
6
  import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs';
7
7
  import { homedir } from 'os';
8
8
  import { basename, extname, isAbsolute, join, posix, relative, resolve, sep } from 'path';
9
+ import { writeFormJson } from './form';
9
10
  export class BuildError extends Error {
10
11
  diagnostics;
11
12
  constructor(message, diagnostics) {
@@ -94,7 +95,8 @@ async function run(job) {
94
95
  snippets.add(resolve(s.file));
95
96
  return s;
96
97
  };
97
- const strict = options.strict ?? isCI();
98
+ // asking for blanks where values are missing means missing values are expected
99
+ const strict = options.strict ?? (options.missing === 'blank' ? false : isCI());
98
100
  const files = [...job.inputs, template.texFile, ...(template.schemaFile ? [template.schemaFile] : [])];
99
101
  const { epoch, reproducible } = buildEpoch(files);
100
102
  let docId = job.docId;
@@ -104,7 +106,11 @@ async function run(job) {
104
106
  minted = true;
105
107
  }
106
108
  const outDir = options.outDir ?? join(project.outDir, job.name);
107
- const job_ = variant === 'final' ? job.name : `${job.name}-${variant}`;
109
+ const blanks = variant === 'blank' ? (options.blanks ?? project.config.blanks) : undefined;
110
+ // the names view is its own file, so it can sit next to the form to fill in
111
+ const highlight = variant === 'draft' && Boolean(options.highlight);
112
+ const missingAs = variant === 'draft' ? options.missing : undefined;
113
+ const job_ = variant === 'final' ? job.name : blanks === 'names' ? `${job.name}-names` : highlight ? `${job.name}-highlight` : `${job.name}-${variant}`;
108
114
  // signed builds: copy signature images next to the .tex for this build only
109
115
  const stageDir = join(outDir, 'lk-signatures');
110
116
  const staged = [];
@@ -150,6 +156,7 @@ async function run(job) {
150
156
  docId,
151
157
  template: template.name,
152
158
  allowMissing: variant === 'draft' ? !strict : undefined,
159
+ markValues: highlight,
153
160
  loadSnippet,
154
161
  loadClause: project.loadClause,
155
162
  components: project.components,
@@ -168,7 +175,7 @@ async function run(job) {
168
175
  mkdirSync(outDir, { recursive: true });
169
176
  const texPath = join(outDir, `${job_}.tex`);
170
177
  const stamp = `${new Date(finalEpoch.epoch * 1000).toISOString().slice(0, 10)} ${gitShortHead(project.root)}`;
171
- const tex = wrapDocument(evaluated.tex, { variant, stamp });
178
+ const tex = wrapDocument(evaluated.tex, { variant, stamp, blanks, missing: missingAs });
172
179
  writeFileSync(texPath, tex);
173
180
  writeFileSync(join(outDir, 'latex-kit.sty'), LATEX_KIT_STY);
174
181
  const result = {
@@ -185,6 +192,7 @@ async function run(job) {
185
192
  engine: null,
186
193
  engineReason: null,
187
194
  cached: false,
195
+ form: null,
188
196
  diagnostics,
189
197
  };
190
198
  if (options.texOnly)
@@ -226,6 +234,7 @@ async function run(job) {
226
234
  const keyInputs = [...filesUnder(template.dir), ...staged].map((f) => [posixRel(project.root, f), sha256(readFileSync(f))]);
227
235
  const cacheKey = sha256(JSON.stringify({ v: 1, tex: sha256(tex), sty: sha256(LATEX_KIT_STY), engine, backend, image: backend === 'docker' ? (image ?? 'default') : null, platform: platform ?? null, epoch: finalEpoch.epoch, inputs: keyInputs }));
228
236
  const manifestPath = join(outDir, `${job_}.manifest.json`);
237
+ const formBase = join(outDir, job_);
229
238
  const pdfPath = join(outDir, `${job_}.pdf`);
230
239
  if (!options.force && !options.verify && existsSync(manifestPath) && existsSync(pdfPath)) {
231
240
  try {
@@ -235,6 +244,7 @@ async function run(job) {
235
244
  result.pdf = pdfPath;
236
245
  result.sha256 = pdfSha;
237
246
  result.cached = true;
247
+ result.form = existsSync(formBase + '.form.json') ? formBase + '.form.json' : null;
238
248
  return result;
239
249
  }
240
250
  }
@@ -242,6 +252,8 @@ async function run(job) {
242
252
  // an unreadable manifest just means a rebuild
243
253
  }
244
254
  }
255
+ // TeX writes marked spots to <job>.form; a file from an earlier run must not survive
256
+ rmSync(formBase + '.form', { force: true });
245
257
  let rendered;
246
258
  try {
247
259
  rendered = await render({ ...renderOpts, outDir: relative(project.root, outDir) });
@@ -257,6 +269,7 @@ async function run(job) {
257
269
  }
258
270
  result.pdf = rendered.pdf;
259
271
  result.sha256 = rendered.sha256;
272
+ result.form = writeFormJson(formBase);
260
273
  if (options.verify) {
261
274
  // same output path: some tools (Ghostscript) hash the path into the PDF ID
262
275
  const again = await render({ ...renderOpts, outDir: relative(project.root, outDir) });
package/esm/cli.js CHANGED
@@ -18,8 +18,8 @@ const app = new CLI(commands, {
18
18
  version: version(),
19
19
  minimistOpts: {
20
20
  alias: { h: 'help', v: 'version', o: 'out', e: 'engine' },
21
- boolean: ['help', 'version', 'local', 'verify', 'json', 'final', 'strict', 'tex-only', 'force', 'schema', 'paper', 'check'],
22
- string: ['out', 'engine', 'image', 'root', 'platform', 'source-date-epoch', 'variant', 'template', 'name', 'against', 'only', 'locale', 'signatures', 'preset'],
21
+ boolean: ['help', 'version', 'local', 'verify', 'json', 'final', 'strict', 'tex-only', 'force', 'schema', 'paper', 'check', 'highlight'],
22
+ string: ['out', 'engine', 'image', 'root', 'platform', 'source-date-epoch', 'variant', 'template', 'name', 'against', 'only', 'locale', 'signatures', 'preset', 'blanks', 'missing'],
23
23
  default: { strict: undefined, schema: true },
24
24
  },
25
25
  });
package/esm/config.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Backend, EngineChoice } from '@latex-kit/render';
2
+ import type { BlankStyle } from '@latex-kit/template';
2
3
  /** latex-kit.config.ts (or .js, .mjs, .cjs, .json) at the project root. */
3
4
  export interface LatexKitConfig {
4
5
  /** One folder per template: `<templates>/<name>/template.tex` and optional `schema.ts`. Default `templates`. */
@@ -25,11 +26,17 @@ export interface LatexKitConfig {
25
26
  * override it. A leading ~ is the home folder.
26
27
  */
27
28
  signatures?: string;
29
+ /**
30
+ * How blanks print in blank builds: `labelled` (default, the field's name on
31
+ * a line), `lines` (an empty line to write on) or `names` (the name in
32
+ * brackets). `--blanks` overrides it.
33
+ */
34
+ blanks?: BlankStyle;
28
35
  backend?: Backend;
29
36
  image?: string;
30
37
  platform?: string | null;
31
38
  }
32
- export type ResolvedConfig = Required<Pick<LatexKitConfig, 'templates' | 'snippets' | 'clauses' | 'components' | 'data' | 'documents' | 'out' | 'locale'>> & Pick<LatexKitConfig, 'engine' | 'backend' | 'image' | 'platform' | 'signatures'> & {
39
+ export type ResolvedConfig = Required<Pick<LatexKitConfig, 'templates' | 'snippets' | 'clauses' | 'components' | 'data' | 'documents' | 'out' | 'locale'>> & Pick<LatexKitConfig, 'engine' | 'backend' | 'image' | 'platform' | 'signatures' | 'blanks'> & {
33
40
  file: string | null;
34
41
  };
35
42
  export declare function defineConfig(config: LatexKitConfig): LatexKitConfig;
package/esm/form.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A spot in a built PDF for someone to fill in: where a signing or form tool
3
+ * should put its box. Lengths are PDF points (1/72 inch); `x` and `y` are the
4
+ * box's bottom-left corner, measured from the bottom-left corner of the page.
5
+ */
6
+ export interface FormField {
7
+ /** signature, date, initials, text, or whatever the template called it. */
8
+ type: string;
9
+ /** The party that fills it in, as the template named it. */
10
+ who: string;
11
+ /** What to type here, when the template said (`label={Printed name}`). */
12
+ label?: string;
13
+ /** From 1. */
14
+ page: number;
15
+ x: number;
16
+ y: number;
17
+ width: number;
18
+ height: number;
19
+ }
20
+ /**
21
+ * Read what `\formfield` and `\signature` wrote while TeX ran: one line per
22
+ * spot, `type who page x y width height raise [label]`, lengths in scaled points.
23
+ * Lines that are not that shape are skipped.
24
+ */
25
+ export declare function parseFormFile(text: string): FormField[];
26
+ /**
27
+ * Turn `<base>.form` into `<base>.form.json`. Returns the JSON file, or null
28
+ * when the document marked no spots (a stale JSON file is then removed).
29
+ */
30
+ export declare function writeFormJson(base: string): string | null;
package/esm/form.js ADDED
@@ -0,0 +1,39 @@
1
+ import { existsSync, readFileSync, rmSync, writeFileSync } from 'fs';
2
+ /** TeX's scaled points (65536 to a TeX point, 72.27 TeX points to an inch) to PDF points. */
3
+ const bp = (sp) => Math.round((sp / 65536) * (72 / 72.27) * 100) / 100;
4
+ /**
5
+ * Read what `\formfield` and `\signature` wrote while TeX ran: one line per
6
+ * spot, `type who page x y width height raise [label]`, lengths in scaled points.
7
+ * Lines that are not that shape are skipped.
8
+ */
9
+ export function parseFormFile(text) {
10
+ const fields = [];
11
+ for (const line of text.split('\n')) {
12
+ const parts = line.trim().split(/\s+/);
13
+ if (parts.length < 8)
14
+ continue;
15
+ const [type, who, ...rest] = parts;
16
+ const n = rest.slice(0, 6).map(Number);
17
+ const label = rest.slice(6).join(' ');
18
+ if (!n.every(Number.isFinite) || n[0] < 1)
19
+ continue;
20
+ const [page, x, y, width, height, raise] = n;
21
+ fields.push({ type, who: who === '-' ? '' : who, ...(label ? { label } : {}), page, x: bp(x), y: bp(y + raise), width: bp(width), height: bp(height) });
22
+ }
23
+ return fields;
24
+ }
25
+ /**
26
+ * Turn `<base>.form` into `<base>.form.json`. Returns the JSON file, or null
27
+ * when the document marked no spots (a stale JSON file is then removed).
28
+ */
29
+ export function writeFormJson(base) {
30
+ const raw = `${base}.form`;
31
+ const out = `${base}.form.json`;
32
+ const fields = existsSync(raw) ? parseFormFile(readFileSync(raw, 'utf8')) : [];
33
+ if (!fields.length) {
34
+ rmSync(out, { force: true });
35
+ return null;
36
+ }
37
+ writeFileSync(out, JSON.stringify(fields, null, 2) + '\n');
38
+ return out;
39
+ }
package/esm/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from './build';
10
10
  export * from './check';
11
11
  export * from './config';
12
12
  export * from './diff';
13
+ export * from './form';
13
14
  export * from './import';
14
15
  export * from './lock';
15
16
  export * from './project';
package/esm/index.js CHANGED
@@ -10,6 +10,7 @@ export * from './build';
10
10
  export * from './check';
11
11
  export * from './config';
12
12
  export * from './diff';
13
+ export * from './form';
13
14
  export * from './import';
14
15
  export * from './lock';
15
16
  export * from './project';
@@ -1,6 +1,6 @@
1
1
  import { ENGINES } from '@latex-kit/render';
2
2
  import { documentJsonSchema, generateTypes, loadDocument } from '@latex-kit/schema';
3
- import { formatDiagnostic, LATEX_KIT_STY, VARIANTS } from '@latex-kit/template';
3
+ import { BLANK_STYLES, formatDiagnostic, LATEX_KIT_STY, VARIANTS } from '@latex-kit/template';
4
4
  import { existsSync, mkdirSync, rmSync, watch as fsWatch, writeFileSync } from 'fs';
5
5
  import { isAbsolute, join, relative } from 'path';
6
6
  import chalk from 'yanse';
@@ -49,6 +49,14 @@ export async function buildCommand(argv) {
49
49
  throw new UsageError(`--engine must be auto or one of ${ENGINES.join(', ')}`);
50
50
  if (argv.signatures !== undefined && variant !== 'signed')
51
51
  throw new UsageError('--signatures only applies to --variant signed');
52
+ if (argv.blanks !== undefined && !BLANK_STYLES.includes(argv.blanks))
53
+ throw new UsageError(`--blanks must be one of ${BLANK_STYLES.join(', ')}`);
54
+ if (argv.blanks !== undefined && variant !== 'blank')
55
+ throw new UsageError('--blanks only applies to --variant blank');
56
+ if (argv.missing !== undefined && !['marker', 'blank'].includes(argv.missing))
57
+ throw new UsageError('--missing must be marker or blank');
58
+ if ((argv.highlight || argv.missing !== undefined) && variant !== 'draft')
59
+ throw new UsageError('--highlight and --missing only apply to drafts');
52
60
  const only = onlyMatcher(argv.only);
53
61
  const project = await Project.open(argv.root);
54
62
  const options = {
@@ -63,6 +71,9 @@ export async function buildCommand(argv) {
63
71
  locale: checkLocale(argv.locale),
64
72
  force: Boolean(argv.force),
65
73
  signatures: argv.signatures,
74
+ blanks: argv.blanks,
75
+ highlight: Boolean(argv.highlight),
76
+ missing: argv.missing,
66
77
  };
67
78
  const json = Boolean(argv.json);
68
79
  const log = (s) => !json && console.error(s);
package/esm/usage.js CHANGED
@@ -83,6 +83,14 @@ Options
83
83
  comma-separated, * matches anything: --only 'nda-*'
84
84
  --locale <tag> Build in another locale (dates, numbers, bilingual
85
85
  order); writes <document>-<tag>.pdf
86
+ --blanks <style> How a blank prints, for --variant blank:
87
+ labelled (default) the field's name on a line
88
+ lines an empty line to write on
89
+ names the name in brackets; writes <name>-names.pdf
90
+ --highlight Drafts: print every filled-in value in red, to review
91
+ what came from the record; writes <name>-highlight.pdf
92
+ --missing <how> Drafts: a missing value prints as a red marker
93
+ (default) or as a blank to fill in: --missing blank
86
94
  --signatures <dir> Signature images for --variant signed
87
95
  --strict Fail on missing values in drafts too
88
96
  --force Rebuild even if the PDF is up to date
@@ -95,6 +103,10 @@ Options
95
103
  --json JSON results on stdout
96
104
  --root <dir> Project folder (default: current directory)
97
105
 
106
+ When a template marks spots to sign or fill in (\\signature blocks do, and
107
+ \\formfield[type=…,who=…]{…} marks your own), the build also writes
108
+ <document>.form.json: each spot's page and position, for signing tools.
109
+
98
110
  A build is skipped ("unchanged") when the last PDF came from exactly the
99
111
  same .tex, template folder, engine, image and build date.
100
112
  `;
package/form.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A spot in a built PDF for someone to fill in: where a signing or form tool
3
+ * should put its box. Lengths are PDF points (1/72 inch); `x` and `y` are the
4
+ * box's bottom-left corner, measured from the bottom-left corner of the page.
5
+ */
6
+ export interface FormField {
7
+ /** signature, date, initials, text, or whatever the template called it. */
8
+ type: string;
9
+ /** The party that fills it in, as the template named it. */
10
+ who: string;
11
+ /** What to type here, when the template said (`label={Printed name}`). */
12
+ label?: string;
13
+ /** From 1. */
14
+ page: number;
15
+ x: number;
16
+ y: number;
17
+ width: number;
18
+ height: number;
19
+ }
20
+ /**
21
+ * Read what `\formfield` and `\signature` wrote while TeX ran: one line per
22
+ * spot, `type who page x y width height raise [label]`, lengths in scaled points.
23
+ * Lines that are not that shape are skipped.
24
+ */
25
+ export declare function parseFormFile(text: string): FormField[];
26
+ /**
27
+ * Turn `<base>.form` into `<base>.form.json`. Returns the JSON file, or null
28
+ * when the document marked no spots (a stale JSON file is then removed).
29
+ */
30
+ export declare function writeFormJson(base: string): string | null;
package/form.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseFormFile = parseFormFile;
4
+ exports.writeFormJson = writeFormJson;
5
+ const fs_1 = require("fs");
6
+ /** TeX's scaled points (65536 to a TeX point, 72.27 TeX points to an inch) to PDF points. */
7
+ const bp = (sp) => Math.round((sp / 65536) * (72 / 72.27) * 100) / 100;
8
+ /**
9
+ * Read what `\formfield` and `\signature` wrote while TeX ran: one line per
10
+ * spot, `type who page x y width height raise [label]`, lengths in scaled points.
11
+ * Lines that are not that shape are skipped.
12
+ */
13
+ function parseFormFile(text) {
14
+ const fields = [];
15
+ for (const line of text.split('\n')) {
16
+ const parts = line.trim().split(/\s+/);
17
+ if (parts.length < 8)
18
+ continue;
19
+ const [type, who, ...rest] = parts;
20
+ const n = rest.slice(0, 6).map(Number);
21
+ const label = rest.slice(6).join(' ');
22
+ if (!n.every(Number.isFinite) || n[0] < 1)
23
+ continue;
24
+ const [page, x, y, width, height, raise] = n;
25
+ fields.push({ type, who: who === '-' ? '' : who, ...(label ? { label } : {}), page, x: bp(x), y: bp(y + raise), width: bp(width), height: bp(height) });
26
+ }
27
+ return fields;
28
+ }
29
+ /**
30
+ * Turn `<base>.form` into `<base>.form.json`. Returns the JSON file, or null
31
+ * when the document marked no spots (a stale JSON file is then removed).
32
+ */
33
+ function writeFormJson(base) {
34
+ const raw = `${base}.form`;
35
+ const out = `${base}.form.json`;
36
+ const fields = (0, fs_1.existsSync)(raw) ? parseFormFile((0, fs_1.readFileSync)(raw, 'utf8')) : [];
37
+ if (!fields.length) {
38
+ (0, fs_1.rmSync)(out, { force: true });
39
+ return null;
40
+ }
41
+ (0, fs_1.writeFileSync)(out, JSON.stringify(fields, null, 2) + '\n');
42
+ return out;
43
+ }
package/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from './build';
10
10
  export * from './check';
11
11
  export * from './config';
12
12
  export * from './diff';
13
+ export * from './form';
13
14
  export * from './import';
14
15
  export * from './lock';
15
16
  export * from './project';
package/index.js CHANGED
@@ -27,6 +27,7 @@ __exportStar(require("./build"), exports);
27
27
  __exportStar(require("./check"), exports);
28
28
  __exportStar(require("./config"), exports);
29
29
  __exportStar(require("./diff"), exports);
30
+ __exportStar(require("./form"), exports);
30
31
  __exportStar(require("./import"), exports);
31
32
  __exportStar(require("./lock"), exports);
32
33
  __exportStar(require("./project"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "latex-kit",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "Build typed, reproducible LaTeX documents from the command line",
5
5
  "author": "Constructive <developers@constructive.io>",
6
6
  "main": "index.js",
@@ -19,6 +19,16 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/constructive-io/latex-kit/issues"
21
21
  },
22
+ "scripts": {
23
+ "copy": "makage assets",
24
+ "clean": "makage clean",
25
+ "prepublishOnly": "npm run build",
26
+ "build": "makage build",
27
+ "build:dev": "makage build --dev",
28
+ "lint": "eslint . --fix",
29
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
30
+ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
31
+ },
22
32
  "devDependencies": {
23
33
  "@types/minimist": "^1.2.5",
24
34
  "makage": "^0.8.0"
@@ -34,21 +44,13 @@
34
44
  "latex-kit": "cli.js"
35
45
  },
36
46
  "dependencies": {
47
+ "@latex-kit/components": "0.3.0",
48
+ "@latex-kit/render": "0.5.1",
49
+ "@latex-kit/schema": "0.4.1",
50
+ "@latex-kit/template": "0.5.0",
37
51
  "inquirerer": "^4.9.5",
38
52
  "minimist": "^1.2.8",
39
- "yanse": "^0.2.3",
40
- "@latex-kit/schema": "0.4.1",
41
- "@latex-kit/components": "0.2.1",
42
- "@latex-kit/render": "0.5.1",
43
- "@latex-kit/template": "0.4.1"
53
+ "yanse": "^0.2.3"
44
54
  },
45
- "scripts": {
46
- "copy": "makage assets",
47
- "clean": "makage clean",
48
- "build": "makage build",
49
- "build:dev": "makage build --dev",
50
- "lint": "eslint . --fix",
51
- "test": "NODE_OPTIONS=--experimental-vm-modules jest",
52
- "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
53
- }
54
- }
55
+ "gitHead": "a117e69246e80a133c7ec027dd626b3815e6e45c"
56
+ }
@@ -67,6 +67,14 @@ async function buildCommand(argv) {
67
67
  throw new args_1.UsageError(`--engine must be auto or one of ${render_1.ENGINES.join(', ')}`);
68
68
  if (argv.signatures !== undefined && variant !== 'signed')
69
69
  throw new args_1.UsageError('--signatures only applies to --variant signed');
70
+ if (argv.blanks !== undefined && !template_1.BLANK_STYLES.includes(argv.blanks))
71
+ throw new args_1.UsageError(`--blanks must be one of ${template_1.BLANK_STYLES.join(', ')}`);
72
+ if (argv.blanks !== undefined && variant !== 'blank')
73
+ throw new args_1.UsageError('--blanks only applies to --variant blank');
74
+ if (argv.missing !== undefined && !['marker', 'blank'].includes(argv.missing))
75
+ throw new args_1.UsageError('--missing must be marker or blank');
76
+ if ((argv.highlight || argv.missing !== undefined) && variant !== 'draft')
77
+ throw new args_1.UsageError('--highlight and --missing only apply to drafts');
70
78
  const only = onlyMatcher(argv.only);
71
79
  const project = await project_1.Project.open(argv.root);
72
80
  const options = {
@@ -81,6 +89,9 @@ async function buildCommand(argv) {
81
89
  locale: checkLocale(argv.locale),
82
90
  force: Boolean(argv.force),
83
91
  signatures: argv.signatures,
92
+ blanks: argv.blanks,
93
+ highlight: Boolean(argv.highlight),
94
+ missing: argv.missing,
84
95
  };
85
96
  const json = Boolean(argv.json);
86
97
  const log = (s) => !json && console.error(s);
package/usage.js CHANGED
@@ -86,6 +86,14 @@ Options
86
86
  comma-separated, * matches anything: --only 'nda-*'
87
87
  --locale <tag> Build in another locale (dates, numbers, bilingual
88
88
  order); writes <document>-<tag>.pdf
89
+ --blanks <style> How a blank prints, for --variant blank:
90
+ labelled (default) the field's name on a line
91
+ lines an empty line to write on
92
+ names the name in brackets; writes <name>-names.pdf
93
+ --highlight Drafts: print every filled-in value in red, to review
94
+ what came from the record; writes <name>-highlight.pdf
95
+ --missing <how> Drafts: a missing value prints as a red marker
96
+ (default) or as a blank to fill in: --missing blank
89
97
  --signatures <dir> Signature images for --variant signed
90
98
  --strict Fail on missing values in drafts too
91
99
  --force Rebuild even if the PDF is up to date
@@ -98,6 +106,10 @@ Options
98
106
  --json JSON results on stdout
99
107
  --root <dir> Project folder (default: current directory)
100
108
 
109
+ When a template marks spots to sign or fill in (\\signature blocks do, and
110
+ \\formfield[type=…,who=…]{…} marks your own), the build also writes
111
+ <document>.form.json: each spot's page and position, for signing tools.
112
+
101
113
  A build is skipped ("unchanged") when the last PDF came from exactly the
102
114
  same .tex, template folder, engine, image and build date.
103
115
  `;