@latex-kit/template 0.0.0-stage → 0.3.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 +23 -0
- package/README.md +137 -2
- package/analyze.d.ts +38 -0
- package/analyze.js +144 -0
- package/clause.d.ts +23 -0
- package/clause.js +26 -0
- package/codemod.d.ts +25 -0
- package/codemod.js +67 -0
- package/compile.d.ts +74 -0
- package/compile.js +258 -0
- package/condition.d.ts +38 -0
- package/condition.js +201 -0
- package/diagnostics.d.ts +29 -0
- package/diagnostics.js +48 -0
- package/document.d.ts +15 -0
- package/document.js +25 -0
- package/esm/analyze.d.ts +38 -0
- package/esm/analyze.js +141 -0
- package/esm/clause.d.ts +23 -0
- package/esm/clause.js +21 -0
- package/esm/codemod.d.ts +25 -0
- package/esm/codemod.js +62 -0
- package/esm/compile.d.ts +74 -0
- package/esm/compile.js +253 -0
- package/esm/condition.d.ts +38 -0
- package/esm/condition.js +193 -0
- package/esm/diagnostics.d.ts +29 -0
- package/esm/diagnostics.js +40 -0
- package/esm/document.d.ts +15 -0
- package/esm/document.js +22 -0
- package/esm/evaluate.d.ts +40 -0
- package/esm/evaluate.js +235 -0
- package/esm/filters.d.ts +39 -0
- package/esm/filters.js +221 -0
- package/esm/index.d.ts +12 -0
- package/esm/index.js +12 -0
- package/esm/jsonschema.d.ts +24 -0
- package/esm/jsonschema.js +94 -0
- package/esm/path.d.ts +7 -0
- package/esm/path.js +16 -0
- package/esm/sty.d.ts +6 -0
- package/esm/sty.js +67 -0
- package/evaluate.d.ts +40 -0
- package/evaluate.js +239 -0
- package/filters.d.ts +39 -0
- package/filters.js +229 -0
- package/index.d.ts +12 -0
- package/index.js +28 -0
- package/jsonschema.d.ts +24 -0
- package/jsonschema.js +99 -0
- package/package.json +44 -4
- package/path.d.ts +7 -0
- package/path.js +22 -0
- package/sty.d.ts +6 -0
- package/sty.js +70 -0
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@latex-kit/template",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.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": "023ede48131a32e9250ec48b0dde17e71c6a1536"
|
|
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 clause from the library: \\lkclause{title}{label}. Numbered like a\n% section; with no title, a bold number. Redefine it to change the style.\n\\providecommand\\lkclause[2]{\\ifx\\relax#1\\relax\\par\\refstepcounter{section}\\label{#2}\\noindent\\textbf{\\thesection.}~\\else\\section{#1}\\label{#2}\\fi}\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\\clause[1]{\\par\\lkblank{clause #1}\\par}\n \\newcommand\\clauseref[1]{\\lkblank{ref #1}}\n\\fi\n\n\\endinput\n";
|
package/sty.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
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 clause from the library: \\lkclause{title}{label}. Numbered like a
|
|
39
|
+
% section; with no title, a bold number. Redefine it to change the style.
|
|
40
|
+
\\providecommand\\lkclause[2]{\\ifx\\relax#1\\relax\\par\\refstepcounter{section}\\label{#2}\\noindent\\textbf{\\thesection.}~\\else\\section{#1}\\label{#2}\\fi}
|
|
41
|
+
|
|
42
|
+
% A value the data does not have yet (draft builds only).
|
|
43
|
+
\\newcommand\\lkmissing[1]{\\leavevmode{\\color{red}\\fbox{\\scriptsize\\ttfamily missing: \\detokenize{#1}}}}
|
|
44
|
+
|
|
45
|
+
\\iflk@draft
|
|
46
|
+
\\RequirePackage{draftwatermark}
|
|
47
|
+
\\SetWatermarkText{DRAFT}
|
|
48
|
+
\\SetWatermarkScale{1}
|
|
49
|
+
\\SetWatermarkColor[gray]{0.9}
|
|
50
|
+
\\RequirePackage{eso-pic}
|
|
51
|
+
\\AddToShipoutPictureFG{%
|
|
52
|
+
\\AtPageLowerLeft{\\raisebox{6mm}{\\hspace{10mm}\\color{lkmeta}\\scriptsize\\ttfamily DRAFT \\lkstamp}}}
|
|
53
|
+
\\fi
|
|
54
|
+
|
|
55
|
+
\\iflk@rendered\\else
|
|
56
|
+
% Previewing the template itself: show its structure.
|
|
57
|
+
\\newcommand\\field[1]{\\lkblank{#1}}
|
|
58
|
+
\\newcommand\\raw[1]{\\lkblank{#1}}
|
|
59
|
+
\\newcommand\\docid{\\lkblank{docid}}
|
|
60
|
+
\\newcommand\\when[2]{{\\color{lkmeta}\\tiny[if \\detokenize{#1}]}#2}
|
|
61
|
+
\\newcommand\\otherwise[1]{{\\color{lkmeta}\\tiny[otherwise]}#1}
|
|
62
|
+
\\newcommand\\each[3]{{\\color{lkmeta}\\tiny[each \\detokenize{#2} in \\detokenize{#1}]}#3}
|
|
63
|
+
\\newcommand\\sep[1]{#1}
|
|
64
|
+
\\newcommand\\snippet[1]{\\InputIfFileExists{#1}{}{\\lkblank{snippet #1}}}
|
|
65
|
+
\\newcommand\\clause[1]{\\par\\lkblank{clause #1}\\par}
|
|
66
|
+
\\newcommand\\clauseref[1]{\\lkblank{ref #1}}
|
|
67
|
+
\\fi
|
|
68
|
+
|
|
69
|
+
\\endinput
|
|
70
|
+
`;
|