@latex-kit/template 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/jsonschema.js ADDED
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ANY = void 0;
4
+ exports.schemaAt = schemaAt;
5
+ exports.itemSchema = itemSchema;
6
+ /** "anything goes" from here down: no further checking is possible. */
7
+ exports.ANY = true;
8
+ function deref(node, root, depth = 0) {
9
+ if (typeof node === 'boolean' || !node.$ref || depth > 32)
10
+ return node;
11
+ const m = /^#\/(\$defs|definitions)\/(.+)$/.exec(node.$ref);
12
+ if (!m || typeof root === 'boolean')
13
+ return exports.ANY;
14
+ const table = root[m[1]];
15
+ const target = table?.[decodeURIComponent(m[2]).replace(/~1/g, '/').replace(/~0/g, '~')];
16
+ return target === undefined ? exports.ANY : deref(target, root, depth + 1);
17
+ }
18
+ function variants(node) {
19
+ if (typeof node === 'boolean')
20
+ return null;
21
+ return node.anyOf ?? node.oneOf ?? null;
22
+ }
23
+ function isPermissive(node) {
24
+ if (node === true)
25
+ return true;
26
+ if (node === false)
27
+ return false;
28
+ const keys = Object.keys(node).filter((k) => !['$schema', 'description', 'title', 'default', 'examples', '$id'].includes(k));
29
+ return keys.length === 0;
30
+ }
31
+ /**
32
+ * The sub-schema at `segments`, or `undefined` when the path cannot exist.
33
+ * Unions are walked branch by branch; a path is valid if any branch has it.
34
+ */
35
+ function schemaAt(node, segments, root = node) {
36
+ node = deref(node, root);
37
+ if (segments.length === 0)
38
+ return node;
39
+ if (typeof node === 'boolean')
40
+ return node ? exports.ANY : undefined;
41
+ if (isPermissive(node))
42
+ return exports.ANY;
43
+ const alts = variants(node);
44
+ if (alts) {
45
+ const found = alts.map((a) => schemaAt(a, segments, root)).filter((x) => x !== undefined);
46
+ if (found.length === 0)
47
+ return undefined;
48
+ return found.length === 1 ? found[0] : { anyOf: found };
49
+ }
50
+ if (node.allOf) {
51
+ for (const part of node.allOf) {
52
+ const found = schemaAt(part, segments, root);
53
+ if (found !== undefined)
54
+ return found;
55
+ }
56
+ return undefined;
57
+ }
58
+ const [seg, ...rest] = segments;
59
+ const types = node.type === undefined ? [] : Array.isArray(node.type) ? node.type : [node.type];
60
+ if (types.includes('array') || node.items !== undefined || node.prefixItems !== undefined) {
61
+ if (!/^\d+$/.test(seg))
62
+ return undefined;
63
+ const i = Number(seg);
64
+ const item = node.prefixItems?.[i] ?? (Array.isArray(node.items) ? node.items[i] : node.items) ?? exports.ANY;
65
+ return schemaAt(item, rest, root);
66
+ }
67
+ if (types.includes('object') || node.properties || node.additionalProperties !== undefined) {
68
+ const prop = node.properties?.[seg];
69
+ if (prop !== undefined)
70
+ return schemaAt(prop, rest, root);
71
+ const extra = node.additionalProperties;
72
+ if (extra === undefined || extra === true)
73
+ return types.includes('object') && node.properties ? undefined : exports.ANY;
74
+ if (extra === false)
75
+ return undefined;
76
+ return schemaAt(extra, rest, root);
77
+ }
78
+ return undefined;
79
+ }
80
+ /** The schema for one element of a list, for \each. `undefined` if not a list. */
81
+ function itemSchema(node, root) {
82
+ node = deref(node, root);
83
+ if (isPermissive(node))
84
+ return exports.ANY;
85
+ if (typeof node === 'boolean')
86
+ return undefined;
87
+ const alts = variants(node);
88
+ if (alts) {
89
+ const found = alts.map((a) => itemSchema(a, root)).filter((x) => x !== undefined);
90
+ return found.length === 0 ? undefined : found.length === 1 ? found[0] : { anyOf: found };
91
+ }
92
+ const types = node.type === undefined ? [] : Array.isArray(node.type) ? node.type : [node.type];
93
+ if (types.includes('array') || node.items !== undefined) {
94
+ return Array.isArray(node.items) ? exports.ANY : (node.items ?? exports.ANY);
95
+ }
96
+ if (types.length > 0)
97
+ return undefined; // a known non-list type
98
+ return exports.ANY;
99
+ }
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@latex-kit/template",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "The latex-kit template language: fill-in macros inside real .tex files, checked and escaped",
5
+ "author": "Constructive <developers@constructive.io>",
6
+ "main": "index.js",
7
+ "module": "esm/index.js",
8
+ "types": "index.d.ts",
9
+ "homepage": "https://github.com/constructive-io/latex-kit",
10
+ "license": "MIT",
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "directory": "dist"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/constructive-io/latex-kit"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/constructive-io/latex-kit/issues"
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": "jest",
30
+ "test:watch": "jest --watch"
31
+ },
32
+ "devDependencies": {
33
+ "makage": "^0.8.0"
34
+ },
35
+ "keywords": [
36
+ "latex",
37
+ "template",
38
+ "unified-latex",
39
+ "documents"
40
+ ],
41
+ "dependencies": {
42
+ "@latex-kit/escape": "0.3.0",
43
+ "@unified-latex/unified-latex-util-parse": "^1.8.4"
44
+ },
45
+ "gitHead": "0da7d546606627d73d38647b02b29cd4df4addd4"
46
+ }
package/path.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /** Values every template can read. */
2
+ export declare const GLOBAL_SPECIALS: readonly ["$variant", "$locale", "$docid", "$template"];
3
+ /** Values only readable inside \each. */
4
+ export declare const LOOP_SPECIALS: readonly ["$index", "$first", "$last"];
5
+ export declare function isPath(text: string): boolean;
6
+ export declare function isName(text: string): boolean;
7
+ export declare function splitPath(path: string): string[];
package/path.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LOOP_SPECIALS = exports.GLOBAL_SPECIALS = void 0;
4
+ exports.isPath = isPath;
5
+ exports.isName = isName;
6
+ exports.splitPath = splitPath;
7
+ const IDENT = '[A-Za-z_][A-Za-z0-9_]*';
8
+ const PATH_RE = new RegExp(`^\\$?${IDENT}(?:\\.(?:${IDENT}|\\d+))*$`);
9
+ const NAME_RE = new RegExp(`^${IDENT}$`);
10
+ /** Values every template can read. */
11
+ exports.GLOBAL_SPECIALS = ['$variant', '$locale', '$docid', '$template'];
12
+ /** Values only readable inside \each. */
13
+ exports.LOOP_SPECIALS = ['$index', '$first', '$last'];
14
+ function isPath(text) {
15
+ return PATH_RE.test(text);
16
+ }
17
+ function isName(text) {
18
+ return NAME_RE.test(text) && !text.startsWith('$');
19
+ }
20
+ function splitPath(path) {
21
+ return path.split('.');
22
+ }
package/sty.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * latex-kit.sty, the LaTeX side of the template language. Written next to
3
+ * every generated document; `latex-kit sty <dir>` writes it for previewing
4
+ * templates in an editor.
5
+ */
6
+ export declare const LATEX_KIT_STY = "% latex-kit.sty: support for latex-kit templates.\n%\n% Load it in a template with \\usepackage{latex-kit}. Compiled directly, a\n% template previews as a blank form: every \\field becomes a labelled line.\n% When latex-kit renders a document it passes the `rendered` option and the\n% variant (draft, blank, final, signed); the template macros are gone by then.\n%\n% https://github.com/constructive-io/latex-kit (MIT)\n\\NeedsTeXFormat{LaTeX2e}\n\\ProvidesPackage{latex-kit}[2026/11/25 v0.3 latex-kit template support]\n\n\\newif\\iflk@rendered\n\\newif\\iflk@draft\n\\DeclareOption{rendered}{\\lk@renderedtrue}\n\\DeclareOption{draft}{\\lk@drafttrue}\n\\DeclareOption{blank}{}\n\\DeclareOption{final}{}\n\\DeclareOption{signed}{}\n\\ProcessOptions\\relax\n\n\\RequirePackage{xcolor}\n\\definecolor{lkmeta}{gray}{0.55}\n\\providecommand\\lkstamp{}\n\n% A labelled blank line: \\lkblank{party.name}\n\\newlength\\lkblankwidth\n\\setlength\\lkblankwidth{3.5cm}\n\\newcommand\\lkblank[1]{\\leavevmode\\underline{\\makebox[\\lkblankwidth][l]{\\color{lkmeta}\\tiny\\ttfamily\\detokenize{#1}}}}\n\n% A value the data does not have yet (draft builds only).\n\\newcommand\\lkmissing[1]{\\leavevmode{\\color{red}\\fbox{\\scriptsize\\ttfamily missing: \\detokenize{#1}}}}\n\n\\iflk@draft\n \\RequirePackage{draftwatermark}\n \\SetWatermarkText{DRAFT}\n \\SetWatermarkScale{1}\n \\SetWatermarkColor[gray]{0.9}\n \\RequirePackage{eso-pic}\n \\AddToShipoutPictureFG{%\n \\AtPageLowerLeft{\\raisebox{6mm}{\\hspace{10mm}\\color{lkmeta}\\scriptsize\\ttfamily DRAFT \\lkstamp}}}\n\\fi\n\n\\iflk@rendered\\else\n % Previewing the template itself: show its structure.\n \\newcommand\\field[1]{\\lkblank{#1}}\n \\newcommand\\raw[1]{\\lkblank{#1}}\n \\newcommand\\docid{\\lkblank{docid}}\n \\newcommand\\when[2]{{\\color{lkmeta}\\tiny[if \\detokenize{#1}]}#2}\n \\newcommand\\otherwise[1]{{\\color{lkmeta}\\tiny[otherwise]}#1}\n \\newcommand\\each[3]{{\\color{lkmeta}\\tiny[each \\detokenize{#2} in \\detokenize{#1}]}#3}\n \\newcommand\\sep[1]{#1}\n \\newcommand\\snippet[1]{\\InputIfFileExists{#1}{}{\\lkblank{snippet #1}}}\n \\newcommand\\clauseref[1]{\\lkblank{clause #1}}\n\\fi\n\n\\endinput\n";
package/sty.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LATEX_KIT_STY = void 0;
4
+ /**
5
+ * latex-kit.sty, the LaTeX side of the template language. Written next to
6
+ * every generated document; `latex-kit sty <dir>` writes it for previewing
7
+ * templates in an editor.
8
+ */
9
+ exports.LATEX_KIT_STY = `% latex-kit.sty: support for latex-kit templates.
10
+ %
11
+ % Load it in a template with \\usepackage{latex-kit}. Compiled directly, a
12
+ % template previews as a blank form: every \\field becomes a labelled line.
13
+ % When latex-kit renders a document it passes the \`rendered\` option and the
14
+ % variant (draft, blank, final, signed); the template macros are gone by then.
15
+ %
16
+ % https://github.com/constructive-io/latex-kit (MIT)
17
+ \\NeedsTeXFormat{LaTeX2e}
18
+ \\ProvidesPackage{latex-kit}[2026/11/25 v0.3 latex-kit template support]
19
+
20
+ \\newif\\iflk@rendered
21
+ \\newif\\iflk@draft
22
+ \\DeclareOption{rendered}{\\lk@renderedtrue}
23
+ \\DeclareOption{draft}{\\lk@drafttrue}
24
+ \\DeclareOption{blank}{}
25
+ \\DeclareOption{final}{}
26
+ \\DeclareOption{signed}{}
27
+ \\ProcessOptions\\relax
28
+
29
+ \\RequirePackage{xcolor}
30
+ \\definecolor{lkmeta}{gray}{0.55}
31
+ \\providecommand\\lkstamp{}
32
+
33
+ % A labelled blank line: \\lkblank{party.name}
34
+ \\newlength\\lkblankwidth
35
+ \\setlength\\lkblankwidth{3.5cm}
36
+ \\newcommand\\lkblank[1]{\\leavevmode\\underline{\\makebox[\\lkblankwidth][l]{\\color{lkmeta}\\tiny\\ttfamily\\detokenize{#1}}}}
37
+
38
+ % A value the data does not have yet (draft builds only).
39
+ \\newcommand\\lkmissing[1]{\\leavevmode{\\color{red}\\fbox{\\scriptsize\\ttfamily missing: \\detokenize{#1}}}}
40
+
41
+ \\iflk@draft
42
+ \\RequirePackage{draftwatermark}
43
+ \\SetWatermarkText{DRAFT}
44
+ \\SetWatermarkScale{1}
45
+ \\SetWatermarkColor[gray]{0.9}
46
+ \\RequirePackage{eso-pic}
47
+ \\AddToShipoutPictureFG{%
48
+ \\AtPageLowerLeft{\\raisebox{6mm}{\\hspace{10mm}\\color{lkmeta}\\scriptsize\\ttfamily DRAFT \\lkstamp}}}
49
+ \\fi
50
+
51
+ \\iflk@rendered\\else
52
+ % Previewing the template itself: show its structure.
53
+ \\newcommand\\field[1]{\\lkblank{#1}}
54
+ \\newcommand\\raw[1]{\\lkblank{#1}}
55
+ \\newcommand\\docid{\\lkblank{docid}}
56
+ \\newcommand\\when[2]{{\\color{lkmeta}\\tiny[if \\detokenize{#1}]}#2}
57
+ \\newcommand\\otherwise[1]{{\\color{lkmeta}\\tiny[otherwise]}#1}
58
+ \\newcommand\\each[3]{{\\color{lkmeta}\\tiny[each \\detokenize{#2} in \\detokenize{#1}]}#3}
59
+ \\newcommand\\sep[1]{#1}
60
+ \\newcommand\\snippet[1]{\\InputIfFileExists{#1}{}{\\lkblank{snippet #1}}}
61
+ \\newcommand\\clauseref[1]{\\lkblank{clause #1}}
62
+ \\fi
63
+
64
+ \\endinput
65
+ `;