@canvakit/plugin-template-document 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/LICENSE ADDED
@@ -0,0 +1,105 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 AGENTIK SAS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,17 @@
1
- # Temporary Holding Version
1
+ # @canvakit/plugin-template-document
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The `template_document` output-type plugin for @canvakit/agent: a declarative, structured fillable-document plugin (blanks, checkbox groups, tables, hints, image placeholders → paginated A4 PDF) that defines its own I/O + quality rubric and taps the shared refine engine. Registers the "template_document" type into a PluginSourceRegistry.
4
+
5
+ Part of [canvakit](https://github.com/openagentik/canvakit).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @canvakit/plugin-template-document
11
+ ```
12
+
13
+ ## License
14
+
15
+ [FSL-1.1-ALv2](./LICENSE), the Functional Source License with an Apache 2.0 future
16
+ license: free for any use except offering a competing product or service, and
17
+ each version becomes Apache-2.0 two years after its release. Copyright AGENTIK SAS.
@@ -0,0 +1,255 @@
1
+ import { PluginContext, CanvakitPlugin, PluginSourceRegistry } from '@canvakit/agent';
2
+ import { z } from 'zod';
3
+ import { ExportCanvasInput } from '@canvakit/export';
4
+
5
+ /**
6
+ * The five structured document primitives — the only vocabulary a
7
+ * `template_document` may be authored with. Deliberately no "cover page" or
8
+ * "footer" concept: a cover is just the first `section` (its fields are
9
+ * `blank`s like Subject/Candidate Name), and a running footer is a
10
+ * branding constant in the renderer, not authored input.
11
+ *
12
+ * Every fillable primitive also accepts an optional PRE-FILLED value so the
13
+ * same template renders either as a blank worksheet (value absent — dotted
14
+ * lines / empty boxes, for a student to complete by hand) or as a filled
15
+ * document (value present — the agent's generated content set on the same
16
+ * ruled layout). Filled rendering never changes the structure: a filled
17
+ * `blank` still sits on its dotted lines, a checked box is still the same
18
+ * box. `hint` is static by design and takes no value.
19
+ */
20
+
21
+ declare const blankFieldSchema: z.ZodObject<{
22
+ type: z.ZodLiteral<"blank">;
23
+ id: z.ZodOptional<z.ZodString>;
24
+ label: z.ZodString;
25
+ lines: z.ZodDefault<z.ZodNumber>;
26
+ hint: z.ZodOptional<z.ZodString>;
27
+ value: z.ZodOptional<z.ZodString>;
28
+ }, z.core.$strip>;
29
+ declare const checkboxGroupFieldSchema: z.ZodObject<{
30
+ type: z.ZodLiteral<"checkbox_group">;
31
+ id: z.ZodOptional<z.ZodString>;
32
+ label: z.ZodString;
33
+ options: z.ZodArray<z.ZodString>;
34
+ allowOther: z.ZodDefault<z.ZodBoolean>;
35
+ checked: z.ZodOptional<z.ZodArray<z.ZodString>>;
36
+ }, z.core.$strip>;
37
+ declare const tableFieldSchema: z.ZodObject<{
38
+ type: z.ZodLiteral<"table">;
39
+ id: z.ZodOptional<z.ZodString>;
40
+ label: z.ZodOptional<z.ZodString>;
41
+ headers: z.ZodArray<z.ZodString>;
42
+ rows: z.ZodNumber;
43
+ values: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodString>>>;
44
+ }, z.core.$strip>;
45
+ declare const hintFieldSchema: z.ZodObject<{
46
+ type: z.ZodLiteral<"hint">;
47
+ id: z.ZodOptional<z.ZodString>;
48
+ text: z.ZodString;
49
+ }, z.core.$strip>;
50
+ declare const imagePlaceholderFieldSchema: z.ZodObject<{
51
+ type: z.ZodLiteral<"image_placeholder">;
52
+ id: z.ZodOptional<z.ZodString>;
53
+ label: z.ZodString;
54
+ captionLabel: z.ZodDefault<z.ZodString>;
55
+ descriptionLabel: z.ZodOptional<z.ZodString>;
56
+ src: z.ZodOptional<z.ZodString>;
57
+ caption: z.ZodOptional<z.ZodString>;
58
+ description: z.ZodOptional<z.ZodString>;
59
+ }, z.core.$strip>;
60
+ declare const fieldSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
61
+ type: z.ZodLiteral<"blank">;
62
+ id: z.ZodOptional<z.ZodString>;
63
+ label: z.ZodString;
64
+ lines: z.ZodDefault<z.ZodNumber>;
65
+ hint: z.ZodOptional<z.ZodString>;
66
+ value: z.ZodOptional<z.ZodString>;
67
+ }, z.core.$strip>, z.ZodObject<{
68
+ type: z.ZodLiteral<"checkbox_group">;
69
+ id: z.ZodOptional<z.ZodString>;
70
+ label: z.ZodString;
71
+ options: z.ZodArray<z.ZodString>;
72
+ allowOther: z.ZodDefault<z.ZodBoolean>;
73
+ checked: z.ZodOptional<z.ZodArray<z.ZodString>>;
74
+ }, z.core.$strip>, z.ZodObject<{
75
+ type: z.ZodLiteral<"table">;
76
+ id: z.ZodOptional<z.ZodString>;
77
+ label: z.ZodOptional<z.ZodString>;
78
+ headers: z.ZodArray<z.ZodString>;
79
+ rows: z.ZodNumber;
80
+ values: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodString>>>;
81
+ }, z.core.$strip>, z.ZodObject<{
82
+ type: z.ZodLiteral<"hint">;
83
+ id: z.ZodOptional<z.ZodString>;
84
+ text: z.ZodString;
85
+ }, z.core.$strip>, z.ZodObject<{
86
+ type: z.ZodLiteral<"image_placeholder">;
87
+ id: z.ZodOptional<z.ZodString>;
88
+ label: z.ZodString;
89
+ captionLabel: z.ZodDefault<z.ZodString>;
90
+ descriptionLabel: z.ZodOptional<z.ZodString>;
91
+ src: z.ZodOptional<z.ZodString>;
92
+ caption: z.ZodOptional<z.ZodString>;
93
+ description: z.ZodOptional<z.ZodString>;
94
+ }, z.core.$strip>], "type">;
95
+ declare const sectionSchema: z.ZodObject<{
96
+ heading: z.ZodString;
97
+ purpose: z.ZodOptional<z.ZodString>;
98
+ fields: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
99
+ type: z.ZodLiteral<"blank">;
100
+ id: z.ZodOptional<z.ZodString>;
101
+ label: z.ZodString;
102
+ lines: z.ZodDefault<z.ZodNumber>;
103
+ hint: z.ZodOptional<z.ZodString>;
104
+ value: z.ZodOptional<z.ZodString>;
105
+ }, z.core.$strip>, z.ZodObject<{
106
+ type: z.ZodLiteral<"checkbox_group">;
107
+ id: z.ZodOptional<z.ZodString>;
108
+ label: z.ZodString;
109
+ options: z.ZodArray<z.ZodString>;
110
+ allowOther: z.ZodDefault<z.ZodBoolean>;
111
+ checked: z.ZodOptional<z.ZodArray<z.ZodString>>;
112
+ }, z.core.$strip>, z.ZodObject<{
113
+ type: z.ZodLiteral<"table">;
114
+ id: z.ZodOptional<z.ZodString>;
115
+ label: z.ZodOptional<z.ZodString>;
116
+ headers: z.ZodArray<z.ZodString>;
117
+ rows: z.ZodNumber;
118
+ values: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodString>>>;
119
+ }, z.core.$strip>, z.ZodObject<{
120
+ type: z.ZodLiteral<"hint">;
121
+ id: z.ZodOptional<z.ZodString>;
122
+ text: z.ZodString;
123
+ }, z.core.$strip>, z.ZodObject<{
124
+ type: z.ZodLiteral<"image_placeholder">;
125
+ id: z.ZodOptional<z.ZodString>;
126
+ label: z.ZodString;
127
+ captionLabel: z.ZodDefault<z.ZodString>;
128
+ descriptionLabel: z.ZodOptional<z.ZodString>;
129
+ src: z.ZodOptional<z.ZodString>;
130
+ caption: z.ZodOptional<z.ZodString>;
131
+ description: z.ZodOptional<z.ZodString>;
132
+ }, z.core.$strip>], "type">>;
133
+ }, z.core.$strip>;
134
+ declare const templateDocumentInputSchema: z.ZodObject<{
135
+ title: z.ZodString;
136
+ subtitle: z.ZodOptional<z.ZodString>;
137
+ sections: z.ZodArray<z.ZodObject<{
138
+ heading: z.ZodString;
139
+ purpose: z.ZodOptional<z.ZodString>;
140
+ fields: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
141
+ type: z.ZodLiteral<"blank">;
142
+ id: z.ZodOptional<z.ZodString>;
143
+ label: z.ZodString;
144
+ lines: z.ZodDefault<z.ZodNumber>;
145
+ hint: z.ZodOptional<z.ZodString>;
146
+ value: z.ZodOptional<z.ZodString>;
147
+ }, z.core.$strip>, z.ZodObject<{
148
+ type: z.ZodLiteral<"checkbox_group">;
149
+ id: z.ZodOptional<z.ZodString>;
150
+ label: z.ZodString;
151
+ options: z.ZodArray<z.ZodString>;
152
+ allowOther: z.ZodDefault<z.ZodBoolean>;
153
+ checked: z.ZodOptional<z.ZodArray<z.ZodString>>;
154
+ }, z.core.$strip>, z.ZodObject<{
155
+ type: z.ZodLiteral<"table">;
156
+ id: z.ZodOptional<z.ZodString>;
157
+ label: z.ZodOptional<z.ZodString>;
158
+ headers: z.ZodArray<z.ZodString>;
159
+ rows: z.ZodNumber;
160
+ values: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodString>>>;
161
+ }, z.core.$strip>, z.ZodObject<{
162
+ type: z.ZodLiteral<"hint">;
163
+ id: z.ZodOptional<z.ZodString>;
164
+ text: z.ZodString;
165
+ }, z.core.$strip>, z.ZodObject<{
166
+ type: z.ZodLiteral<"image_placeholder">;
167
+ id: z.ZodOptional<z.ZodString>;
168
+ label: z.ZodString;
169
+ captionLabel: z.ZodDefault<z.ZodString>;
170
+ descriptionLabel: z.ZodOptional<z.ZodString>;
171
+ src: z.ZodOptional<z.ZodString>;
172
+ caption: z.ZodOptional<z.ZodString>;
173
+ description: z.ZodOptional<z.ZodString>;
174
+ }, z.core.$strip>], "type">>;
175
+ }, z.core.$strip>>;
176
+ design: z.ZodOptional<z.ZodString>;
177
+ fontFamily: z.ZodOptional<z.ZodString>;
178
+ fontSize: z.ZodOptional<z.ZodString>;
179
+ pageMargin: z.ZodOptional<z.ZodString>;
180
+ }, z.core.$strip>;
181
+ type Field = z.infer<typeof fieldSchema>;
182
+ type Section = z.infer<typeof sectionSchema>;
183
+ type TemplateDocumentInput = z.infer<typeof templateDocumentInputSchema>;
184
+ /** The fillable patch a caller may set on one field, keyed by its `id`. */
185
+ declare const fieldValuePatchSchema: z.ZodObject<{
186
+ value: z.ZodOptional<z.ZodString>;
187
+ checked: z.ZodOptional<z.ZodArray<z.ZodString>>;
188
+ values: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodString>>>;
189
+ caption: z.ZodOptional<z.ZodString>;
190
+ description: z.ZodOptional<z.ZodString>;
191
+ }, z.core.$strip>;
192
+ type FieldValuePatch = z.infer<typeof fieldValuePatchSchema>;
193
+
194
+ /**
195
+ * The `template_document` output-type plugin — a DECLARATIVE canvakit plugin
196
+ * for structured, reusable fillable documents (forms, worksheets, project
197
+ * templates) built from a fixed vocabulary of five primitives (see
198
+ * `field-schema.ts`): blank fill-lines, checkbox groups, tables, hints, and
199
+ * image placeholders.
200
+ *
201
+ * Separates CONTENT (sections + fields — the document's structure) from
202
+ * PRESENTATION (design tokens, fonts, margins). The refine boundary enforces
203
+ * this: `apply` may touch presentation, never content.
204
+ *
205
+ * Renders to a paginated A4 PDF: a table of contents (heading text only, no
206
+ * page-number cross-referencing — unreliable in Chrome's native print
207
+ * pagination), one page per section, `page-break-inside: avoid` on tables.
208
+ */
209
+
210
+ declare function buildHtml(input: TemplateDocumentInput): string;
211
+ declare function buildExportInput(input: TemplateDocumentInput, ctx: PluginContext): Promise<ExportCanvasInput>;
212
+ declare const templateDocumentPlugin: CanvakitPlugin<TemplateDocumentInput>;
213
+
214
+ /**
215
+ * App-agnostic catalog registry for `template_document` entries: a
216
+ * Map<string, Config> with register + getters and lowercased app-name keys.
217
+ *
218
+ * Lives in the package that owns the schema it catalogs, so a host never has
219
+ * to depend on anything above this plugin to register its entries.
220
+ */
221
+
222
+ interface TemplateDocumentCatalogEntry {
223
+ id: string;
224
+ title: string;
225
+ description?: string;
226
+ document: TemplateDocumentInput;
227
+ }
228
+ interface AppTemplateDocumentConfig {
229
+ entries: Record<string, TemplateDocumentCatalogEntry>;
230
+ }
231
+ declare function registerAppTemplateDocuments(appName: string, config: AppTemplateDocumentConfig): void;
232
+ declare function getTemplateDocumentsForApp(appName: string): Record<string, TemplateDocumentCatalogEntry>;
233
+ declare function getTemplateDocumentForApp(id: string, appName: string): TemplateDocumentCatalogEntry | undefined;
234
+ declare function getRegisteredTemplateDocumentApps(): string[];
235
+
236
+ /**
237
+ * @canvakit/plugin-template-document — the declarative `template_document`
238
+ * output-type plugin for the @canvakit/agent engine.
239
+ *
240
+ * Usage:
241
+ * import { register } from "@canvakit/plugin-template-document"
242
+ * import { generate } from "@canvakit/agent"
243
+ * register() // adds "template_document" to defaultRegistry
244
+ * await generate("template_document", { title, sections }, { ctx: { cwd } })
245
+ */
246
+
247
+ /**
248
+ * Register the `template_document` plugin into a registry (the shared
249
+ * `defaultRegistry` by default). Idempotent per registry only in the sense
250
+ * that re-registering adds another source that resolves "template_document"
251
+ * identically — call once at startup.
252
+ */
253
+ declare function register(registry?: PluginSourceRegistry): void;
254
+
255
+ export { type AppTemplateDocumentConfig, type Field, type FieldValuePatch, type Section, type TemplateDocumentCatalogEntry, type TemplateDocumentInput, blankFieldSchema, buildExportInput, buildHtml, checkboxGroupFieldSchema, fieldSchema, fieldValuePatchSchema, getRegisteredTemplateDocumentApps, getTemplateDocumentForApp, getTemplateDocumentsForApp, hintFieldSchema, imagePlaceholderFieldSchema, register, registerAppTemplateDocuments, sectionSchema, tableFieldSchema, templateDocumentInputSchema, templateDocumentPlugin };
package/dist/index.mjs ADDED
@@ -0,0 +1,595 @@
1
+ import { defaultRegistry } from '@canvakit/agent';
2
+ import { z } from 'zod';
3
+ import { exportCanvas } from '@canvakit/export';
4
+ import { designkitExtension } from '@canvakit/designkit';
5
+ import { promises } from 'fs';
6
+ import * as path from 'path';
7
+
8
+ /**
9
+ * @canvakit/plugin-template-document v0.1.0
10
+ * The declarative `template_document` output-type plugin for @canvakit/agent.
11
+ */
12
+
13
+ function createNodeFs(baseDir) {
14
+ const abs = path.resolve(baseDir);
15
+ const resolve2 = (p) => path.resolve(abs, p.replace(/^\/+/, ""));
16
+ return {
17
+ async readFile(p) {
18
+ return promises.readFile(resolve2(p));
19
+ },
20
+ async writeFile(p, contents) {
21
+ const full = resolve2(p);
22
+ await promises.mkdir(path.dirname(full), { recursive: true });
23
+ await promises.writeFile(full, contents);
24
+ },
25
+ async exists(p) {
26
+ try {
27
+ await promises.access(resolve2(p));
28
+ return true;
29
+ } catch {
30
+ return false;
31
+ }
32
+ },
33
+ async readdir(p, opts) {
34
+ const root = resolve2(p);
35
+ if (opts?.recursive === true) {
36
+ const found2 = await promises.readdir(root, {
37
+ recursive: true,
38
+ withFileTypes: true
39
+ });
40
+ return found2.map((e) => ({
41
+ name: path.relative(root, path.join(e.parentPath ?? root, e.name)),
42
+ type: e.isDirectory() ? "directory" : "file"
43
+ }));
44
+ }
45
+ const found = await promises.readdir(root, { withFileTypes: true });
46
+ return found.map((e) => ({
47
+ name: e.name,
48
+ type: e.isDirectory() ? "directory" : "file"
49
+ }));
50
+ }
51
+ };
52
+ }
53
+ var blankFieldSchema = z.object({
54
+ type: z.literal("blank"),
55
+ id: z.string().optional(),
56
+ label: z.string(),
57
+ lines: z.number().int().positive().default(1),
58
+ hint: z.string().optional(),
59
+ value: z.string().optional()
60
+ });
61
+ var checkboxGroupFieldSchema = z.object({
62
+ type: z.literal("checkbox_group"),
63
+ id: z.string().optional(),
64
+ label: z.string(),
65
+ options: z.array(z.string()).min(1),
66
+ allowOther: z.boolean().default(false),
67
+ checked: z.array(z.string()).optional()
68
+ });
69
+ var tableFieldSchema = z.object({
70
+ type: z.literal("table"),
71
+ id: z.string().optional(),
72
+ label: z.string().optional(),
73
+ headers: z.array(z.string()).min(1),
74
+ rows: z.number().int().positive(),
75
+ values: z.array(z.array(z.string())).optional()
76
+ });
77
+ var hintFieldSchema = z.object({
78
+ type: z.literal("hint"),
79
+ id: z.string().optional(),
80
+ text: z.string()
81
+ });
82
+ var imagePlaceholderFieldSchema = z.object({
83
+ type: z.literal("image_placeholder"),
84
+ id: z.string().optional(),
85
+ label: z.string(),
86
+ captionLabel: z.string().default("Caption"),
87
+ descriptionLabel: z.string().optional(),
88
+ src: z.string().url().optional(),
89
+ caption: z.string().optional(),
90
+ description: z.string().optional()
91
+ });
92
+ var fieldSchema = z.discriminatedUnion("type", [
93
+ blankFieldSchema,
94
+ checkboxGroupFieldSchema,
95
+ tableFieldSchema,
96
+ hintFieldSchema,
97
+ imagePlaceholderFieldSchema
98
+ ]);
99
+ var sectionSchema = z.object({
100
+ heading: z.string(),
101
+ purpose: z.string().optional(),
102
+ fields: z.array(fieldSchema)
103
+ });
104
+ var templateDocumentInputSchema = z.object({
105
+ title: z.string(),
106
+ subtitle: z.string().optional(),
107
+ sections: z.array(sectionSchema).min(1),
108
+ design: z.string().optional(),
109
+ fontFamily: z.string().optional(),
110
+ fontSize: z.string().optional(),
111
+ pageMargin: z.string().optional()
112
+ });
113
+ var fieldValuePatchSchema = z.object({
114
+ value: z.string().optional(),
115
+ checked: z.array(z.string()).optional(),
116
+ values: z.array(z.array(z.string())).optional(),
117
+ caption: z.string().optional(),
118
+ description: z.string().optional()
119
+ });
120
+
121
+ // src/template-document-plugin.ts
122
+ function escapeHtml(s) {
123
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
124
+ }
125
+ function renderBlankLines(lines, value) {
126
+ const filledLines = value ? value.split("\n") : [];
127
+ const total = Math.max(lines, filledLines.length);
128
+ const rows = [];
129
+ for (let i = 0; i < total; i++) {
130
+ const text = filledLines[i];
131
+ rows.push(
132
+ text !== void 0 ? `<div class="blank-line filled">${escapeHtml(text)}</div>` : `<div class="blank-line"></div>`
133
+ );
134
+ }
135
+ return `<div class="blank-lines">${rows.join("\n")}</div>`;
136
+ }
137
+ function renderBlank(field) {
138
+ const parts = [
139
+ `<div class="field field-blank">`,
140
+ `<div class="field-label">${escapeHtml(field.label)}</div>`,
141
+ renderBlankLines(field.lines, field.value)
142
+ ];
143
+ if (field.hint) {
144
+ parts.push(`<p class="field-hint">${escapeHtml(field.hint)}</p>`);
145
+ }
146
+ parts.push(`</div>`);
147
+ return parts.join("\n");
148
+ }
149
+ function renderCheckboxGroup(field) {
150
+ const checked = new Set(field.checked ?? []);
151
+ const box = (isChecked) => `<span class="checkbox-box${isChecked ? " checked" : ""}"></span>`;
152
+ const options = field.options.map(
153
+ (opt) => `<span class="checkbox-option">${box(checked.has(opt))}${escapeHtml(opt)}</span>`
154
+ ).join("\n");
155
+ const otherValues = [...checked].filter((opt) => !field.options.includes(opt));
156
+ const other = otherValues.length > 0 ? otherValues.map(
157
+ (v) => `<span class="checkbox-option checkbox-other">${box(true)}Other: ${escapeHtml(v)}</span>`
158
+ ).join("\n") : field.allowOther ? `<span class="checkbox-option checkbox-other"><span class="checkbox-box"></span>Other: <span class="inline-blank"></span></span>` : "";
159
+ return `<div class="field field-checkbox-group">
160
+ <div class="field-label">${escapeHtml(field.label)}</div>
161
+ <div class="checkbox-row">
162
+ ${options}
163
+ ${other}
164
+ </div>
165
+ </div>`;
166
+ }
167
+ function renderTable(field) {
168
+ const ths = field.headers.map((h) => `<th>${escapeHtml(h)}</th>`).join("");
169
+ const emptyCells = field.headers.map(() => `<td>&nbsp;</td>`).join("");
170
+ const filled = field.values ?? [];
171
+ const rowCount = Math.max(field.rows, filled.length);
172
+ const rows = Array.from({ length: rowCount }, (_, i) => {
173
+ const row = filled[i];
174
+ if (!row) return `<tr>${emptyCells}</tr>`;
175
+ const cells = field.headers.map((_header, c) => `<td>${escapeHtml(row[c] ?? "") || "&nbsp;"}</td>`).join("");
176
+ return `<tr>${cells}</tr>`;
177
+ }).join("\n");
178
+ const label = field.label ? `<div class="field-label">${escapeHtml(field.label)}</div>` : "";
179
+ return `<div class="field field-table">
180
+ ${label}
181
+ <table>
182
+ <thead><tr>${ths}</tr></thead>
183
+ <tbody>
184
+ ${rows}
185
+ </tbody>
186
+ </table>
187
+ </div>`;
188
+ }
189
+ function renderHint(field) {
190
+ return `<p class="standalone-hint"><span class="hint-marker">e.g.</span> ${escapeHtml(field.text)}</p>`;
191
+ }
192
+ function renderImagePlaceholder(field) {
193
+ const imageBox = field.src ? `<div class="image-box has-image"><img src="${escapeHtml(field.src)}" alt="${escapeHtml(field.label)}"></div>` : `<div class="image-box"><span class="image-box-label">${escapeHtml(field.label)}</span></div>`;
194
+ const parts = [
195
+ `<div class="field field-image-placeholder">`,
196
+ `<div class="field-label">${escapeHtml(field.label)}</div>`,
197
+ imageBox,
198
+ renderBlank({
199
+ label: field.captionLabel,
200
+ lines: 1,
201
+ value: field.caption
202
+ })
203
+ ];
204
+ if (field.descriptionLabel) {
205
+ parts.push(
206
+ renderBlank({
207
+ label: field.descriptionLabel,
208
+ lines: 2,
209
+ value: field.description
210
+ })
211
+ );
212
+ }
213
+ parts.push(`</div>`);
214
+ return parts.join("\n");
215
+ }
216
+ function renderField(field) {
217
+ switch (field.type) {
218
+ case "blank":
219
+ return renderBlank(field);
220
+ case "checkbox_group":
221
+ return renderCheckboxGroup(field);
222
+ case "table":
223
+ return renderTable(field);
224
+ case "hint":
225
+ return renderHint(field);
226
+ case "image_placeholder":
227
+ return renderImagePlaceholder(field);
228
+ }
229
+ }
230
+ function renderSection(section, index) {
231
+ const parts = [
232
+ `<section class="tpl-section"${index > 0 ? ' style="page-break-before: always;"' : ""}>`,
233
+ `<h2>${escapeHtml(section.heading)}</h2>`
234
+ ];
235
+ if (section.purpose) {
236
+ parts.push(`<p class="section-purpose">${escapeHtml(section.purpose)}</p>`);
237
+ }
238
+ for (const field of section.fields) {
239
+ parts.push(renderField(field));
240
+ }
241
+ parts.push(`</section>`);
242
+ return parts.join("\n");
243
+ }
244
+ function renderToc(sections) {
245
+ const items = sections.map((s) => `<li>${escapeHtml(s.heading)}</li>`).join("\n");
246
+ return `<nav class="toc"><ol>${items}</ol></nav>`;
247
+ }
248
+ function buildHtml(input) {
249
+ const fontFamily = input.fontFamily ?? "'Inter', system-ui, -apple-system, sans-serif";
250
+ const fontSize = input.fontSize ?? "10.5pt";
251
+ const pageMargin = input.pageMargin ?? "2cm 2.2cm";
252
+ const sections = input.sections.map((section, i) => renderSection(section, i)).join("\n");
253
+ return `<!DOCTYPE html>
254
+ <html lang="en">
255
+ <head>
256
+ <meta charset="utf-8">
257
+ <style>
258
+ :root {
259
+ /* White, deliberately. Chrome never paints the canvas background into the
260
+ @page margin area, so any tint here renders as a coloured band inside a
261
+ white frame. Zeroing the @page margin fixes the bleed but kills the
262
+ @bottom-* margin boxes (page numbering), which a submitted ZIMSEC script
263
+ needs. Warmth is carried by --color-surface and the ruling instead. */
264
+ --color-background: #FFFFFF;
265
+ --color-surface: #F2F0EC;
266
+ --color-ink: #1C1B22;
267
+ --color-ink-muted: #6B6878;
268
+ --color-accent: #6E56CF;
269
+ --color-border: #E7E4DD;
270
+ --color-rule: #D9D5CC;
271
+ /* Writing-line pitch. Ruled blanks paint one rule per pitch and set
272
+ line-height to match, so a value that WRAPS still lands on a rule \u2014
273
+ see .blank-lines. Changing this re-flows every fillable field. */
274
+ --rule-pitch: 2.05em;
275
+ --font-h1-family: "Fraunces", Georgia, ui-serif, serif;
276
+ --font-body-family: "Inter", system-ui, -apple-system, sans-serif;
277
+ }
278
+
279
+ @page {
280
+ size: A4;
281
+ margin: ${pageMargin};
282
+ @bottom-center {
283
+ content: counter(page) " / " counter(pages);
284
+ font-size: 8.5pt;
285
+ color: var(--color-ink-muted, #6B6878);
286
+ }
287
+ @bottom-right {
288
+ content: "Template by Simone";
289
+ font-size: 8pt;
290
+ color: var(--color-ink-muted, #6B6878);
291
+ }
292
+ }
293
+
294
+ * { box-sizing: border-box; }
295
+ /* Chrome drops background paint in print by default: without this the page
296
+ tint AND the ruled-line gradients vanish from the PDF. */
297
+ *, html, body {
298
+ -webkit-print-color-adjust: exact;
299
+ print-color-adjust: exact;
300
+ }
301
+ /* The tint must sit on html, not just body: body's box stops at the @page
302
+ margin, which left the 2cm frame white against a cream content band. */
303
+ html, body { margin: 0; padding: 0; background: var(--color-background, #FBFAF8); }
304
+ body {
305
+ font-family: ${fontFamily};
306
+ font-size: ${fontSize};
307
+ color: var(--color-ink, #1C1B22);
308
+ line-height: 1.5;
309
+ }
310
+
311
+ h1.doc-title {
312
+ font-family: var(--font-h1-family, "Fraunces", Georgia, ui-serif, serif);
313
+ font-size: 22pt;
314
+ font-weight: 600;
315
+ margin: 0 0 0.25em;
316
+ color: var(--color-ink, #1C1B22);
317
+ }
318
+ p.doc-subtitle {
319
+ font-size: 12pt;
320
+ color: var(--color-ink-muted, #6B6878);
321
+ margin: 0 0 1.5em;
322
+ }
323
+
324
+ .toc {
325
+ margin: 1.5em 0 2em;
326
+ padding: 1em 1.25em;
327
+ border: 1px solid var(--color-border, #E7E4DD);
328
+ border-radius: 8px;
329
+ background: var(--color-surface, #F2F0EC);
330
+ }
331
+ .toc ol {
332
+ margin: 0;
333
+ padding-left: 1.25em;
334
+ }
335
+ .toc li {
336
+ margin: 0.2em 0;
337
+ }
338
+
339
+ .tpl-section h2 {
340
+ font-family: var(--font-h1-family, "Fraunces", Georgia, ui-serif, serif);
341
+ font-size: 15pt;
342
+ font-weight: 600;
343
+ /* Every section after the first starts a page (page-break-before), where a
344
+ top margin stacks on the @page margin. Spacing is carried by the section
345
+ instead, so a page opens flush against its own margin. */
346
+ margin: 0 0 0.4em;
347
+ padding-bottom: 0.2em;
348
+ border-bottom: 1.5px solid var(--color-accent, #6E56CF);
349
+ color: var(--color-ink, #1C1B22);
350
+ page-break-after: avoid;
351
+ }
352
+ .section-purpose {
353
+ color: var(--color-ink-muted, #6B6878);
354
+ font-style: italic;
355
+ margin: 0 0 1em;
356
+ }
357
+
358
+ .field {
359
+ margin: 0 0 1.25em;
360
+ page-break-inside: avoid;
361
+ }
362
+ .field-label {
363
+ font-weight: 600;
364
+ margin-bottom: 0.4em;
365
+ color: var(--color-ink, #1C1B22);
366
+ }
367
+ .field-hint {
368
+ font-style: italic;
369
+ color: var(--color-ink-muted, #6B6878);
370
+ font-size: 0.9em;
371
+ margin: 0.3em 0 0;
372
+ }
373
+
374
+ /* Ruled paper, not per-row borders. The rules are ONE repeating gradient on
375
+ the container, and every row is an exact multiple of the pitch, so a value
376
+ that wraps to N visual lines occupies N rules and stays on them. A
377
+ per-row border-bottom cannot do this: it draws one rule under a wrapped
378
+ two-line row, which is what made filled text float off the ruling. */
379
+ .blank-lines {
380
+ display: flex;
381
+ flex-direction: column;
382
+ background-image: repeating-linear-gradient(
383
+ to bottom,
384
+ transparent 0,
385
+ transparent calc(var(--rule-pitch) - 1.2px),
386
+ var(--color-rule, #D9D5CC) calc(var(--rule-pitch) - 1.2px),
387
+ var(--color-rule, #D9D5CC) var(--rule-pitch)
388
+ );
389
+ }
390
+ .blank-line {
391
+ min-height: var(--rule-pitch);
392
+ line-height: var(--rule-pitch);
393
+ }
394
+
395
+ .checkbox-row {
396
+ display: flex;
397
+ flex-wrap: wrap;
398
+ gap: 0.4em 1.5em;
399
+ }
400
+ .checkbox-option {
401
+ display: inline-flex;
402
+ align-items: center;
403
+ gap: 0.4em;
404
+ }
405
+ .checkbox-box {
406
+ display: inline-block;
407
+ width: 0.9em;
408
+ height: 0.9em;
409
+ border: 1.5px solid var(--color-ink, #1C1B22);
410
+ flex-shrink: 0;
411
+ }
412
+ .checkbox-box.checked {
413
+ background: var(--color-ink, #1C1B22);
414
+ box-shadow: inset 0 0 0 0.15em var(--color-background, #FBFAF8);
415
+ }
416
+ .checkbox-other { gap: 0.4em; }
417
+ .inline-blank {
418
+ display: inline-block;
419
+ width: 8em;
420
+ border-bottom: 1.5px dotted var(--color-border, #C9C5BB);
421
+ }
422
+
423
+ table {
424
+ width: 100%;
425
+ border-collapse: collapse;
426
+ margin: 0.5em 0;
427
+ page-break-inside: avoid;
428
+ }
429
+ th, td {
430
+ border: 1px solid var(--color-border, #E7E4DD);
431
+ padding: 0.5em 0.6em;
432
+ text-align: left;
433
+ }
434
+ th {
435
+ background: var(--color-surface, #F2F0EC);
436
+ font-weight: 600;
437
+ }
438
+ td { min-height: 2em; }
439
+
440
+ .standalone-hint {
441
+ font-style: italic;
442
+ color: var(--color-ink-muted, #6B6878);
443
+ /* Flush left with the field labels below it \u2014 the old 1em indent made the
444
+ "e.g." line hang right of every label on the page. */
445
+ margin: 0 0 1.25em;
446
+ }
447
+ .hint-marker {
448
+ font-weight: 600;
449
+ margin-right: 0.3em;
450
+ }
451
+
452
+ .image-box {
453
+ border: 2px dashed var(--color-border, #C9C5BB);
454
+ min-height: 10em;
455
+ display: flex;
456
+ align-items: center;
457
+ justify-content: center;
458
+ margin-bottom: 0.75em;
459
+ border-radius: 8px;
460
+ }
461
+ .image-box-label {
462
+ color: var(--color-ink-muted, #6B6878);
463
+ font-style: italic;
464
+ text-align: center;
465
+ padding: 0 1em;
466
+ }
467
+ .image-box.has-image {
468
+ border-style: solid;
469
+ border-color: var(--color-border, #E7E4DD);
470
+ }
471
+ .image-box img {
472
+ max-width: 100%;
473
+ max-height: 18em;
474
+ object-fit: contain;
475
+ border-radius: 6px;
476
+ }
477
+ </style>
478
+ </head>
479
+ <body>
480
+ <h1 class="doc-title">${escapeHtml(input.title)}</h1>
481
+ ${input.subtitle ? `<p class="doc-subtitle">${escapeHtml(input.subtitle)}</p>` : ""}
482
+ ${renderToc(input.sections)}
483
+ ${sections}
484
+ </body>
485
+ </html>`;
486
+ }
487
+ async function buildExportInput(input, ctx) {
488
+ const cwd = ctx.cwd ?? process.cwd();
489
+ const filesystem = createNodeFs(cwd);
490
+ const html = buildHtml(input);
491
+ const extensions = [
492
+ designkitExtension({
493
+ ...input.design ? { overrideDesign: input.design } : {}
494
+ })
495
+ ];
496
+ return {
497
+ template: html,
498
+ templatePath: "template-document.html",
499
+ filesystem,
500
+ variables: {},
501
+ extensions
502
+ };
503
+ }
504
+ var PLAIN = { medium: "web" };
505
+ function outputFilename(input) {
506
+ const slug = input.title.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
507
+ return `${slug || "template-document"}.pdf`;
508
+ }
509
+ var refine = {
510
+ rubric: [
511
+ {
512
+ id: "no-table-break",
513
+ criterion: "No table is split across a page boundary \u2014 every table starts and ends on the same page.",
514
+ weight: 3
515
+ },
516
+ {
517
+ id: "heading-attached",
518
+ criterion: "Every heading (Part, Section) has at least two paragraphs or one table below it on the same page \u2014 no orphaned headings at the bottom of a page.",
519
+ weight: 3
520
+ },
521
+ {
522
+ id: "legible",
523
+ criterion: "Body text stays readable (roughly >= 10pt); nothing is clipped, truncated, or overlapping.",
524
+ weight: 2
525
+ }
526
+ ],
527
+ editableScope: {
528
+ fields: ["design", "fontFamily", "fontSize", "pageMargin"],
529
+ notes: "Presentation only \u2014 design tokens, font, sizing, page margins. NEVER the document content (sections, fields, title, subtitle): the document structure is fixed input, not something to rewrite while tuning layout."
530
+ },
531
+ apply(input, edit) {
532
+ switch (edit.path) {
533
+ case "design":
534
+ return { ...input, design: z.string().min(1).parse(edit.value) };
535
+ case "fontFamily":
536
+ return { ...input, fontFamily: z.string().min(1).parse(edit.value) };
537
+ case "fontSize":
538
+ return { ...input, fontSize: z.string().min(1).parse(edit.value) };
539
+ case "pageMargin":
540
+ return { ...input, pageMargin: z.string().min(1).parse(edit.value) };
541
+ default:
542
+ throw new Error(
543
+ `[plugin-template-document] edit path "${edit.path}" is outside editableScope {design, fontFamily, fontSize, pageMargin}`
544
+ );
545
+ }
546
+ }
547
+ };
548
+ var templateDocumentPlugin = {
549
+ type: "template_document",
550
+ input: templateDocumentInputSchema,
551
+ output: "pdf",
552
+ async render(input, ctx) {
553
+ const res = await exportCanvas(await buildExportInput(input, ctx), {
554
+ ...PLAIN,
555
+ format: "pdf"
556
+ });
557
+ return {
558
+ bytes: Buffer.from(res.bytes),
559
+ format: "pdf",
560
+ filename: outputFilename(input)
561
+ };
562
+ },
563
+ async preview(input, ctx) {
564
+ const res = await exportCanvas(await buildExportInput(input, ctx), {
565
+ ...PLAIN,
566
+ format: "png"
567
+ });
568
+ return Buffer.from(res.bytes);
569
+ },
570
+ refine
571
+ };
572
+
573
+ // src/catalog.ts
574
+ var catalogRegistry = /* @__PURE__ */ new Map();
575
+ function registerAppTemplateDocuments(appName, config) {
576
+ catalogRegistry.set(appName.toLowerCase(), config);
577
+ }
578
+ function getTemplateDocumentsForApp(appName) {
579
+ return catalogRegistry.get(appName.toLowerCase())?.entries ?? {};
580
+ }
581
+ function getTemplateDocumentForApp(id, appName) {
582
+ return catalogRegistry.get(appName.toLowerCase())?.entries[id];
583
+ }
584
+ function getRegisteredTemplateDocumentApps() {
585
+ return Array.from(catalogRegistry.keys());
586
+ }
587
+
588
+ // src/index.ts
589
+ function register(registry = defaultRegistry) {
590
+ registry.registerPlugin(templateDocumentPlugin);
591
+ }
592
+
593
+ export { blankFieldSchema, buildExportInput, buildHtml, checkboxGroupFieldSchema, fieldSchema, fieldValuePatchSchema, getRegisteredTemplateDocumentApps, getTemplateDocumentForApp, getTemplateDocumentsForApp, hintFieldSchema, imagePlaceholderFieldSchema, register, registerAppTemplateDocuments, sectionSchema, tableFieldSchema, templateDocumentInputSchema, templateDocumentPlugin };
594
+ //# sourceMappingURL=index.mjs.map
595
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/node-fs.ts","../src/field-schema.ts","../src/template-document-plugin.ts","../src/catalog.ts","../src/index.ts"],"names":["resolve","fs","found","z"],"mappings":";;;;;;;;;;;;AAYO,SAAS,aAAa,OAAA,EAAiC;AAC5D,EAAA,MAAM,GAAA,GAAW,aAAQ,OAAO,CAAA;AAChC,EAAA,MAAMA,QAAAA,GAAU,CAAC,CAAA,KAAmB,IAAA,CAAA,OAAA,CAAQ,KAAK,CAAA,CAAE,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAC,CAAA;AAEtE,EAAA,OAAO;AAAA,IACL,MAAM,SAAS,CAAA,EAAG;AAChB,MAAA,OAAOC,QAAA,CAAG,QAAA,CAASD,QAAAA,CAAQ,CAAC,CAAC,CAAA;AAAA,IAC/B,CAAA;AAAA,IACA,MAAM,SAAA,CAAU,CAAA,EAAG,QAAA,EAAU;AAC3B,MAAA,MAAM,IAAA,GAAOA,SAAQ,CAAC,CAAA;AACtB,MAAA,MAAMC,QAAA,CAAG,MAAW,IAAA,CAAA,OAAA,CAAQ,IAAI,GAAG,EAAE,SAAA,EAAW,MAAM,CAAA;AACtD,MAAA,MAAMA,QAAA,CAAG,SAAA,CAAU,IAAA,EAAM,QAAQ,CAAA;AAAA,IACnC,CAAA;AAAA,IACA,MAAM,OAAO,CAAA,EAAG;AACd,MAAA,IAAI;AACF,QAAA,MAAMA,QAAA,CAAG,MAAA,CAAOD,QAAAA,CAAQ,CAAC,CAAC,CAAA;AAC1B,QAAA,OAAO,IAAA;AAAA,MACT,CAAA,CAAA,MAAQ;AACN,QAAA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AA,EAC8C;AAC9C,EAAA,OAAO,gBAAgB,GAAA,CAAI,OAAA,CAAQ,aAAa,CAAA,EAAG,WAAW,EAAC;AACjE;AAEO,SAAS,yBAAA,CACd,IACA,OAAA,EAC0C;AAC1C,EAAA,OAAO,gBAAgB,GAAA,CAAI,OAAA,CAAQ,aAAa,CAAA,EAAG,QAAQ,EAAE,CAAA;AAC/D;AAEO,SAAS,iCAAA,GAA8C;AAC5D,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,eAAA,CAAgB,IAAA,EAAM,CAAA;AAC1C;;;ACMO,SAAS,QAAA,CACd,WAAiC,eAAA,EAC3B;AACN,EAAA,QAAA,CAAS,eAAe,sBAAsB,CAAA;AAChD","file":"index.mjs","sourcesContent":["/**\n * A minimal Node-backed `FilesystemLike` for declarative plugins that render\n * from disk. Same four-method surface `@canvakit/core` defines; paths resolve\n * against a base dir so a plugin can render a template + its file sources from\n * wherever the caller's `cwd` points. Mirrors the CLI's own `createLocalFs`\n * (kept local here so the plugin doesn't depend on the CLI package).\n */\n\nimport { promises as fs } from \"node:fs\"\nimport * as path from \"node:path\"\nimport type { FilesystemEntry, FilesystemLike } from \"@canvakit/core\"\n\nexport function createNodeFs(baseDir: string): FilesystemLike {\n const abs = path.resolve(baseDir)\n const resolve = (p: string) => path.resolve(abs, p.replace(/^\\/+/, \"\"))\n\n return {\n async readFile(p) {\n return fs.readFile(resolve(p))\n },\n async writeFile(p, contents) {\n const full = resolve(p)\n await fs.mkdir(path.dirname(full), { recursive: true })\n await fs.writeFile(full, contents)\n },\n async exists(p) {\n try {\n await fs.access(resolve(p))\n return true\n } catch {\n return false\n }\n },\n async readdir(p, opts): Promise<FilesystemEntry[]> {\n const root = resolve(p)\n if (opts?.recursive === true) {\n const found = await fs.readdir(root, {\n recursive: true,\n withFileTypes: true,\n })\n return found.map(e => ({\n name: path.relative(root, path.join(e.parentPath ?? root, e.name)),\n type: e.isDirectory() ? \"directory\" : \"file\",\n }))\n }\n const found = await fs.readdir(root, { withFileTypes: true })\n return found.map(e => ({\n name: e.name,\n type: e.isDirectory() ? \"directory\" : \"file\",\n }))\n },\n }\n}\n","/**\n * The five structured document primitives — the only vocabulary a\n * `template_document` may be authored with. Deliberately no \"cover page\" or\n * \"footer\" concept: a cover is just the first `section` (its fields are\n * `blank`s like Subject/Candidate Name), and a running footer is a\n * branding constant in the renderer, not authored input.\n *\n * Every fillable primitive also accepts an optional PRE-FILLED value so the\n * same template renders either as a blank worksheet (value absent — dotted\n * lines / empty boxes, for a student to complete by hand) or as a filled\n * document (value present — the agent's generated content set on the same\n * ruled layout). Filled rendering never changes the structure: a filled\n * `blank` still sits on its dotted lines, a checked box is still the same\n * box. `hint` is static by design and takes no value.\n */\n\nimport { z } from \"zod\"\n\nexport const blankFieldSchema = z.object({\n type: z.literal(\"blank\"),\n id: z.string().optional(),\n label: z.string(),\n lines: z.number().int().positive().default(1),\n hint: z.string().optional(),\n value: z.string().optional(),\n})\n\nexport const checkboxGroupFieldSchema = z.object({\n type: z.literal(\"checkbox_group\"),\n id: z.string().optional(),\n label: z.string(),\n options: z.array(z.string()).min(1),\n allowOther: z.boolean().default(false),\n checked: z.array(z.string()).optional(),\n})\n\nexport const tableFieldSchema = z.object({\n type: z.literal(\"table\"),\n id: z.string().optional(),\n label: z.string().optional(),\n headers: z.array(z.string()).min(1),\n rows: z.number().int().positive(),\n values: z.array(z.array(z.string())).optional(),\n})\n\nexport const hintFieldSchema = z.object({\n type: z.literal(\"hint\"),\n id: z.string().optional(),\n text: z.string(),\n})\n\nexport const imagePlaceholderFieldSchema = z.object({\n type: z.literal(\"image_placeholder\"),\n id: z.string().optional(),\n label: z.string(),\n captionLabel: z.string().default(\"Caption\"),\n descriptionLabel: z.string().optional(),\n src: z.string().url().optional(),\n caption: z.string().optional(),\n description: z.string().optional(),\n})\n\nexport const fieldSchema = z.discriminatedUnion(\"type\", [\n blankFieldSchema,\n checkboxGroupFieldSchema,\n tableFieldSchema,\n hintFieldSchema,\n imagePlaceholderFieldSchema,\n])\n\nexport const sectionSchema = z.object({\n heading: z.string(),\n purpose: z.string().optional(),\n fields: z.array(fieldSchema),\n})\n\nexport const templateDocumentInputSchema = z.object({\n title: z.string(),\n subtitle: z.string().optional(),\n sections: z.array(sectionSchema).min(1),\n design: z.string().optional(),\n fontFamily: z.string().optional(),\n fontSize: z.string().optional(),\n pageMargin: z.string().optional(),\n})\n\nexport type Field = z.infer<typeof fieldSchema>\nexport type Section = z.infer<typeof sectionSchema>\nexport type TemplateDocumentInput = z.infer<typeof templateDocumentInputSchema>\n\n/** The fillable patch a caller may set on one field, keyed by its `id`. */\nexport const fieldValuePatchSchema = z.object({\n value: z.string().optional(),\n checked: z.array(z.string()).optional(),\n values: z.array(z.array(z.string())).optional(),\n caption: z.string().optional(),\n description: z.string().optional(),\n})\n\nexport type FieldValuePatch = z.infer<typeof fieldValuePatchSchema>\n","/**\n * The `template_document` output-type plugin — a DECLARATIVE canvakit plugin\n * for structured, reusable fillable documents (forms, worksheets, project\n * templates) built from a fixed vocabulary of five primitives (see\n * `field-schema.ts`): blank fill-lines, checkbox groups, tables, hints, and\n * image placeholders.\n *\n * Separates CONTENT (sections + fields — the document's structure) from\n * PRESENTATION (design tokens, fonts, margins). The refine boundary enforces\n * this: `apply` may touch presentation, never content.\n *\n * Renders to a paginated A4 PDF: a table of contents (heading text only, no\n * page-number cross-referencing — unreliable in Chrome's native print\n * pagination), one page per section, `page-break-inside: avoid` on tables.\n */\n\nimport { z } from \"zod\"\nimport type {\n Artifact,\n CanvakitPlugin,\n Edit,\n PluginContext,\n RefineCapability,\n} from \"@canvakit/agent\"\nimport {\n exportCanvas,\n type ExportCanvasInput,\n type ExportOptions,\n} from \"@canvakit/export\"\nimport { designkitExtension } from \"@canvakit/designkit\"\nimport { createNodeFs } from \"./node-fs.js\"\nimport {\n templateDocumentInputSchema,\n type Field,\n type Section,\n type TemplateDocumentInput,\n} from \"./field-schema.js\"\n\nfunction escapeHtml(s: string): string {\n return s\n .replace(/&/g, \"&amp;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\")\n .replace(/\"/g, \"&quot;\")\n}\n\nfunction renderBlankLines(lines: number, value?: string): string {\n // A filled value flows onto the same ruled lines: one rendered line per\n // source line, padded with empty rules up to the template's `lines` so a\n // short answer still shows the remaining writing space.\n const filledLines = value ? value.split(\"\\n\") : []\n const total = Math.max(lines, filledLines.length)\n const rows: string[] = []\n for (let i = 0; i < total; i++) {\n const text = filledLines[i]\n rows.push(\n text !== undefined\n ? `<div class=\"blank-line filled\">${escapeHtml(text)}</div>`\n : `<div class=\"blank-line\"></div>`\n )\n }\n return `<div class=\"blank-lines\">${rows.join(\"\\n\")}</div>`\n}\n\nfunction renderBlank(field: Extract<Field, { type: \"blank\" }>): string {\n const parts: string[] = [\n `<div class=\"field field-blank\">`,\n `<div class=\"field-label\">${escapeHtml(field.label)}</div>`,\n renderBlankLines(field.lines, field.value),\n ]\n if (field.hint) {\n parts.push(`<p class=\"field-hint\">${escapeHtml(field.hint)}</p>`)\n }\n parts.push(`</div>`)\n return parts.join(\"\\n\")\n}\n\nfunction renderCheckboxGroup(\n field: Extract<Field, { type: \"checkbox_group\" }>\n): string {\n const checked = new Set(field.checked ?? [])\n const box = (isChecked: boolean) =>\n `<span class=\"checkbox-box${isChecked ? \" checked\" : \"\"}\"></span>`\n const options = field.options\n .map(\n opt =>\n `<span class=\"checkbox-option\">${box(checked.has(opt))}${escapeHtml(opt)}</span>`\n )\n .join(\"\\n\")\n // A checked entry naming no declared option rides the \"Other:\" slot,\n // rendered as a filled Other line — the author's data is ground truth once\n // a value exists, `allowOther` only governs the blank form.\n const otherValues = [...checked].filter(opt => !field.options.includes(opt))\n const other =\n otherValues.length > 0\n ? otherValues\n .map(\n v =>\n `<span class=\"checkbox-option checkbox-other\">${box(true)}Other: ${escapeHtml(v)}</span>`\n )\n .join(\"\\n\")\n : field.allowOther\n ? `<span class=\"checkbox-option checkbox-other\"><span class=\"checkbox-box\"></span>Other: <span class=\"inline-blank\"></span></span>`\n : \"\"\n return `<div class=\"field field-checkbox-group\">\n<div class=\"field-label\">${escapeHtml(field.label)}</div>\n<div class=\"checkbox-row\">\n${options}\n${other}\n</div>\n</div>`\n}\n\nfunction renderTable(field: Extract<Field, { type: \"table\" }>): string {\n const ths = field.headers.map(h => `<th>${escapeHtml(h)}</th>`).join(\"\")\n const emptyCells = field.headers.map(() => `<td>&nbsp;</td>`).join(\"\")\n // Filled values replace the empty grid row-for-row: each provided row is\n // padded to the header count, and the grid grows past `rows` if the data\n // needs more space (the template's count is a floor, not a ceiling).\n const filled = field.values ?? []\n const rowCount = Math.max(field.rows, filled.length)\n const rows = Array.from({ length: rowCount }, (_, i) => {\n const row = filled[i]\n if (!row) return `<tr>${emptyCells}</tr>`\n const cells = field.headers\n .map((_header, c) => `<td>${escapeHtml(row[c] ?? \"\") || \"&nbsp;\"}</td>`)\n .join(\"\")\n return `<tr>${cells}</tr>`\n }).join(\"\\n\")\n const label = field.label\n ? `<div class=\"field-label\">${escapeHtml(field.label)}</div>`\n : \"\"\n return `<div class=\"field field-table\">\n${label}\n<table>\n<thead><tr>${ths}</tr></thead>\n<tbody>\n${rows}\n</tbody>\n</table>\n</div>`\n}\n\nfunction renderHint(field: Extract<Field, { type: \"hint\" }>): string {\n return `<p class=\"standalone-hint\"><span class=\"hint-marker\">e.g.</span> ${escapeHtml(field.text)}</p>`\n}\n\nfunction renderImagePlaceholder(\n field: Extract<Field, { type: \"image_placeholder\" }>\n): string {\n const imageBox = field.src\n ? `<div class=\"image-box has-image\"><img src=\"${escapeHtml(field.src)}\" alt=\"${escapeHtml(field.label)}\"></div>`\n : `<div class=\"image-box\"><span class=\"image-box-label\">${escapeHtml(field.label)}</span></div>`\n const parts: string[] = [\n `<div class=\"field field-image-placeholder\">`,\n `<div class=\"field-label\">${escapeHtml(field.label)}</div>`,\n imageBox,\n renderBlank({\n type: \"blank\",\n label: field.captionLabel,\n lines: 1,\n value: field.caption,\n }),\n ]\n if (field.descriptionLabel) {\n parts.push(\n renderBlank({\n type: \"blank\",\n label: field.descriptionLabel,\n lines: 2,\n value: field.description,\n })\n )\n }\n parts.push(`</div>`)\n return parts.join(\"\\n\")\n}\n\nfunction renderField(field: Field): string {\n switch (field.type) {\n case \"blank\":\n return renderBlank(field)\n case \"checkbox_group\":\n return renderCheckboxGroup(field)\n case \"table\":\n return renderTable(field)\n case \"hint\":\n return renderHint(field)\n case \"image_placeholder\":\n return renderImagePlaceholder(field)\n }\n}\n\nfunction renderSection(section: Section, index: number): string {\n const parts: string[] = [\n `<section class=\"tpl-section\"${index > 0 ? ' style=\"page-break-before: always;\"' : \"\"}>`,\n `<h2>${escapeHtml(section.heading)}</h2>`,\n ]\n if (section.purpose) {\n parts.push(`<p class=\"section-purpose\">${escapeHtml(section.purpose)}</p>`)\n }\n for (const field of section.fields) {\n parts.push(renderField(field))\n }\n parts.push(`</section>`)\n return parts.join(\"\\n\")\n}\n\nfunction renderToc(sections: Section[]): string {\n const items = sections\n .map(s => `<li>${escapeHtml(s.heading)}</li>`)\n .join(\"\\n\")\n return `<nav class=\"toc\"><ol>${items}</ol></nav>`\n}\n\nexport function buildHtml(input: TemplateDocumentInput): string {\n const fontFamily =\n input.fontFamily ?? \"'Inter', system-ui, -apple-system, sans-serif\"\n const fontSize = input.fontSize ?? \"10.5pt\"\n const pageMargin = input.pageMargin ?? \"2cm 2.2cm\"\n\n const sections = input.sections\n .map((section, i) => renderSection(section, i))\n .join(\"\\n\")\n\n return `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<style>\n:root {\n /* White, deliberately. Chrome never paints the canvas background into the\n @page margin area, so any tint here renders as a coloured band inside a\n white frame. Zeroing the @page margin fixes the bleed but kills the\n @bottom-* margin boxes (page numbering), which a submitted ZIMSEC script\n needs. Warmth is carried by --color-surface and the ruling instead. */\n --color-background: #FFFFFF;\n --color-surface: #F2F0EC;\n --color-ink: #1C1B22;\n --color-ink-muted: #6B6878;\n --color-accent: #6E56CF;\n --color-border: #E7E4DD;\n --color-rule: #D9D5CC;\n /* Writing-line pitch. Ruled blanks paint one rule per pitch and set\n line-height to match, so a value that WRAPS still lands on a rule —\n see .blank-lines. Changing this re-flows every fillable field. */\n --rule-pitch: 2.05em;\n --font-h1-family: \"Fraunces\", Georgia, ui-serif, serif;\n --font-body-family: \"Inter\", system-ui, -apple-system, sans-serif;\n}\n\n@page {\n size: A4;\n margin: ${pageMargin};\n @bottom-center {\n content: counter(page) \" / \" counter(pages);\n font-size: 8.5pt;\n color: var(--color-ink-muted, #6B6878);\n }\n @bottom-right {\n content: \"Template by Simone\";\n font-size: 8pt;\n color: var(--color-ink-muted, #6B6878);\n }\n}\n\n* { box-sizing: border-box; }\n/* Chrome drops background paint in print by default: without this the page\n tint AND the ruled-line gradients vanish from the PDF. */\n*, html, body {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n}\n/* The tint must sit on html, not just body: body's box stops at the @page\n margin, which left the 2cm frame white against a cream content band. */\nhtml, body { margin: 0; padding: 0; background: var(--color-background, #FBFAF8); }\nbody {\n font-family: ${fontFamily};\n font-size: ${fontSize};\n color: var(--color-ink, #1C1B22);\n line-height: 1.5;\n}\n\nh1.doc-title {\n font-family: var(--font-h1-family, \"Fraunces\", Georgia, ui-serif, serif);\n font-size: 22pt;\n font-weight: 600;\n margin: 0 0 0.25em;\n color: var(--color-ink, #1C1B22);\n}\np.doc-subtitle {\n font-size: 12pt;\n color: var(--color-ink-muted, #6B6878);\n margin: 0 0 1.5em;\n}\n\n.toc {\n margin: 1.5em 0 2em;\n padding: 1em 1.25em;\n border: 1px solid var(--color-border, #E7E4DD);\n border-radius: 8px;\n background: var(--color-surface, #F2F0EC);\n}\n.toc ol {\n margin: 0;\n padding-left: 1.25em;\n}\n.toc li {\n margin: 0.2em 0;\n}\n\n.tpl-section h2 {\n font-family: var(--font-h1-family, \"Fraunces\", Georgia, ui-serif, serif);\n font-size: 15pt;\n font-weight: 600;\n /* Every section after the first starts a page (page-break-before), where a\n top margin stacks on the @page margin. Spacing is carried by the section\n instead, so a page opens flush against its own margin. */\n margin: 0 0 0.4em;\n padding-bottom: 0.2em;\n border-bottom: 1.5px solid var(--color-accent, #6E56CF);\n color: var(--color-ink, #1C1B22);\n page-break-after: avoid;\n}\n.section-purpose {\n color: var(--color-ink-muted, #6B6878);\n font-style: italic;\n margin: 0 0 1em;\n}\n\n.field {\n margin: 0 0 1.25em;\n page-break-inside: avoid;\n}\n.field-label {\n font-weight: 600;\n margin-bottom: 0.4em;\n color: var(--color-ink, #1C1B22);\n}\n.field-hint {\n font-style: italic;\n color: var(--color-ink-muted, #6B6878);\n font-size: 0.9em;\n margin: 0.3em 0 0;\n}\n\n/* Ruled paper, not per-row borders. The rules are ONE repeating gradient on\n the container, and every row is an exact multiple of the pitch, so a value\n that wraps to N visual lines occupies N rules and stays on them. A\n per-row border-bottom cannot do this: it draws one rule under a wrapped\n two-line row, which is what made filled text float off the ruling. */\n.blank-lines {\n display: flex;\n flex-direction: column;\n background-image: repeating-linear-gradient(\n to bottom,\n transparent 0,\n transparent calc(var(--rule-pitch) - 1.2px),\n var(--color-rule, #D9D5CC) calc(var(--rule-pitch) - 1.2px),\n var(--color-rule, #D9D5CC) var(--rule-pitch)\n );\n}\n.blank-line {\n min-height: var(--rule-pitch);\n line-height: var(--rule-pitch);\n}\n\n.checkbox-row {\n display: flex;\n flex-wrap: wrap;\n gap: 0.4em 1.5em;\n}\n.checkbox-option {\n display: inline-flex;\n align-items: center;\n gap: 0.4em;\n}\n.checkbox-box {\n display: inline-block;\n width: 0.9em;\n height: 0.9em;\n border: 1.5px solid var(--color-ink, #1C1B22);\n flex-shrink: 0;\n}\n.checkbox-box.checked {\n background: var(--color-ink, #1C1B22);\n box-shadow: inset 0 0 0 0.15em var(--color-background, #FBFAF8);\n}\n.checkbox-other { gap: 0.4em; }\n.inline-blank {\n display: inline-block;\n width: 8em;\n border-bottom: 1.5px dotted var(--color-border, #C9C5BB);\n}\n\ntable {\n width: 100%;\n border-collapse: collapse;\n margin: 0.5em 0;\n page-break-inside: avoid;\n}\nth, td {\n border: 1px solid var(--color-border, #E7E4DD);\n padding: 0.5em 0.6em;\n text-align: left;\n}\nth {\n background: var(--color-surface, #F2F0EC);\n font-weight: 600;\n}\ntd { min-height: 2em; }\n\n.standalone-hint {\n font-style: italic;\n color: var(--color-ink-muted, #6B6878);\n /* Flush left with the field labels below it — the old 1em indent made the\n \"e.g.\" line hang right of every label on the page. */\n margin: 0 0 1.25em;\n}\n.hint-marker {\n font-weight: 600;\n margin-right: 0.3em;\n}\n\n.image-box {\n border: 2px dashed var(--color-border, #C9C5BB);\n min-height: 10em;\n display: flex;\n align-items: center;\n justify-content: center;\n margin-bottom: 0.75em;\n border-radius: 8px;\n}\n.image-box-label {\n color: var(--color-ink-muted, #6B6878);\n font-style: italic;\n text-align: center;\n padding: 0 1em;\n}\n.image-box.has-image {\n border-style: solid;\n border-color: var(--color-border, #E7E4DD);\n}\n.image-box img {\n max-width: 100%;\n max-height: 18em;\n object-fit: contain;\n border-radius: 6px;\n}\n</style>\n</head>\n<body>\n<h1 class=\"doc-title\">${escapeHtml(input.title)}</h1>\n${input.subtitle ? `<p class=\"doc-subtitle\">${escapeHtml(input.subtitle)}</p>` : \"\"}\n${renderToc(input.sections)}\n${sections}\n</body>\n</html>`\n}\n\nexport async function buildExportInput(\n input: TemplateDocumentInput,\n ctx: PluginContext\n): Promise<ExportCanvasInput> {\n const cwd = ctx.cwd ?? process.cwd()\n const filesystem = createNodeFs(cwd)\n const html = buildHtml(input)\n\n const extensions = [\n designkitExtension({\n ...(input.design ? { overrideDesign: input.design } : {}),\n }),\n ]\n\n return {\n template: html,\n templatePath: \"template-document.html\",\n filesystem,\n variables: {},\n extensions,\n }\n}\n\nconst PLAIN: Pick<ExportOptions, \"medium\"> = { medium: \"web\" }\n\nfunction outputFilename(input: TemplateDocumentInput): string {\n const slug = input.title\n .toLowerCase()\n .normalize(\"NFD\")\n .replace(/[̀-ͯ]/g, \"\")\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .slice(0, 60)\n return `${slug || \"template-document\"}.pdf`\n}\n\nconst refine: RefineCapability<TemplateDocumentInput> = {\n rubric: [\n {\n id: \"no-table-break\",\n criterion:\n \"No table is split across a page boundary — every table starts and ends on the same page.\",\n weight: 3,\n },\n {\n id: \"heading-attached\",\n criterion:\n \"Every heading (Part, Section) has at least two paragraphs or one table below it on the same page — no orphaned headings at the bottom of a page.\",\n weight: 3,\n },\n {\n id: \"legible\",\n criterion:\n \"Body text stays readable (roughly >= 10pt); nothing is clipped, truncated, or overlapping.\",\n weight: 2,\n },\n ],\n editableScope: {\n fields: [\"design\", \"fontFamily\", \"fontSize\", \"pageMargin\"],\n notes:\n \"Presentation only — design tokens, font, sizing, page margins. NEVER the document content (sections, fields, title, subtitle): the document structure is fixed input, not something to rewrite while tuning layout.\",\n },\n apply(input: TemplateDocumentInput, edit: Edit): TemplateDocumentInput {\n switch (edit.path) {\n case \"design\":\n return { ...input, design: z.string().min(1).parse(edit.value) }\n case \"fontFamily\":\n return { ...input, fontFamily: z.string().min(1).parse(edit.value) }\n case \"fontSize\":\n return { ...input, fontSize: z.string().min(1).parse(edit.value) }\n case \"pageMargin\":\n return { ...input, pageMargin: z.string().min(1).parse(edit.value) }\n default:\n throw new Error(\n `[plugin-template-document] edit path \"${edit.path}\" is outside editableScope {design, fontFamily, fontSize, pageMargin}`\n )\n }\n },\n}\n\nexport const templateDocumentPlugin: CanvakitPlugin<TemplateDocumentInput> = {\n type: \"template_document\",\n input: templateDocumentInputSchema,\n output: \"pdf\",\n async render(\n input: TemplateDocumentInput,\n ctx: PluginContext\n ): Promise<Artifact> {\n const res = await exportCanvas(await buildExportInput(input, ctx), {\n ...PLAIN,\n format: \"pdf\",\n })\n return {\n bytes: Buffer.from(res.bytes),\n format: \"pdf\",\n filename: outputFilename(input),\n }\n },\n async preview(\n input: TemplateDocumentInput,\n ctx: PluginContext\n ): Promise<Buffer> {\n const res = await exportCanvas(await buildExportInput(input, ctx), {\n ...PLAIN,\n format: \"png\",\n })\n return Buffer.from(res.bytes)\n },\n refine,\n}\n","/**\n * App-agnostic catalog registry for `template_document` entries: a\n * Map<string, Config> with register + getters and lowercased app-name keys.\n *\n * Lives in the package that owns the schema it catalogs, so a host never has\n * to depend on anything above this plugin to register its entries.\n */\n\nimport type { TemplateDocumentInput } from \"./field-schema.js\"\n\nexport interface TemplateDocumentCatalogEntry {\n id: string\n title: string\n description?: string\n document: TemplateDocumentInput\n}\n\nexport interface AppTemplateDocumentConfig {\n entries: Record<string, TemplateDocumentCatalogEntry>\n}\n\nconst catalogRegistry = new Map<string, AppTemplateDocumentConfig>()\n\nexport function registerAppTemplateDocuments(\n appName: string,\n config: AppTemplateDocumentConfig\n): void {\n catalogRegistry.set(appName.toLowerCase(), config)\n}\n\nexport function getTemplateDocumentsForApp(\n appName: string\n): Record<string, TemplateDocumentCatalogEntry> {\n return catalogRegistry.get(appName.toLowerCase())?.entries ?? {}\n}\n\nexport function getTemplateDocumentForApp(\n id: string,\n appName: string\n): TemplateDocumentCatalogEntry | undefined {\n return catalogRegistry.get(appName.toLowerCase())?.entries[id]\n}\n\nexport function getRegisteredTemplateDocumentApps(): string[] {\n return Array.from(catalogRegistry.keys())\n}\n","/**\n * @canvakit/plugin-template-document — the declarative `template_document`\n * output-type plugin for the @canvakit/agent engine.\n *\n * Usage:\n * import { register } from \"@canvakit/plugin-template-document\"\n * import { generate } from \"@canvakit/agent\"\n * register() // adds \"template_document\" to defaultRegistry\n * await generate(\"template_document\", { title, sections }, { ctx: { cwd } })\n */\n\nimport { defaultRegistry, type PluginSourceRegistry } from \"@canvakit/agent\"\nimport { templateDocumentPlugin } from \"./template-document-plugin.js\"\n\nexport {\n blankFieldSchema,\n checkboxGroupFieldSchema,\n tableFieldSchema,\n hintFieldSchema,\n imagePlaceholderFieldSchema,\n fieldSchema,\n fieldValuePatchSchema,\n sectionSchema,\n templateDocumentInputSchema,\n type Field,\n type FieldValuePatch,\n type Section,\n type TemplateDocumentInput,\n} from \"./field-schema.js\"\n\nexport {\n templateDocumentPlugin,\n buildHtml,\n buildExportInput,\n} from \"./template-document-plugin.js\"\n\nexport {\n registerAppTemplateDocuments,\n getTemplateDocumentsForApp,\n getTemplateDocumentForApp,\n getRegisteredTemplateDocumentApps,\n type TemplateDocumentCatalogEntry,\n type AppTemplateDocumentConfig,\n} from \"./catalog.js\"\n\n/**\n * Register the `template_document` plugin into a registry (the shared\n * `defaultRegistry` by default). Idempotent per registry only in the sense\n * that re-registering adds another source that resolves \"template_document\"\n * identically — call once at startup.\n */\nexport function register(\n registry: PluginSourceRegistry = defaultRegistry\n): void {\n registry.registerPlugin(templateDocumentPlugin)\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@canvakit/plugin-template-document",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "The `template_document` output-type plugin for @canvakit/agent — a declarative, structured fillable-document plugin (blanks, checkbox groups, tables, hints, image placeholders → paginated A4 PDF) that defines its own I/O + quality rubric and taps the shared refine engine. Registers the \"template_document\" type into a PluginSourceRegistry.",
5
+ "keywords": [
6
+ "canvakit",
7
+ "agent",
8
+ "plugin",
9
+ "template-document",
10
+ "fillable-form",
11
+ "declarative"
12
+ ],
13
+ "homepage": "https://canvakit.sh",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/openagentik/canvakit",
17
+ "directory": "packages/plugin-template-document"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/openagentik/canvakit/issues"
21
+ },
22
+ "license": "FSL-1.1-ALv2",
23
+ "type": "module",
24
+ "main": "dist/index.mjs",
25
+ "module": "dist/index.mjs",
26
+ "types": "dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.mjs",
31
+ "default": "./dist/index.mjs"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "README.md",
38
+ "LICENSE"
39
+ ],
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "dependencies": {
44
+ "@canvakit/agent": "^0.2.0",
45
+ "@canvakit/core": "^0.2.0",
46
+ "@canvakit/designkit": "^0.2.0",
47
+ "@canvakit/export": "^0.2.0",
48
+ "zod": "^4.4.3"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^25.6.2",
52
+ "tsup": "^8.5.1",
53
+ "typescript": "^5.9.3",
54
+ "vitest": "^3.2.4",
55
+ "@canvakit/tooling": "0.0.0"
56
+ },
57
+ "scripts": {
58
+ "dev": "tsup --watch",
59
+ "build": "tsup",
60
+ "clean": "rm -rf dist",
61
+ "check-types": "tsc --noEmit",
62
+ "test": "vitest run",
63
+ "test:watch": "vitest"
64
+ }
6
65
  }