@canvakit/plugin-legal 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-legal
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 `legal` output-type plugin for @canvakit/agent: a declarative legal-submission plugin (numbered paragraphs, tables, annexes → paginated A4 PDF) that separates content from presentation. Registers the "legal" 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-legal
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,123 @@
1
+ import { CanvakitPlugin, PluginSourceRegistry } from '@canvakit/agent';
2
+ import { z } from 'zod';
3
+
4
+ /**
5
+ * The `legal` output-type plugin — a DECLARATIVE canvakit plugin for formal
6
+ * legal submissions (EU Commission style, numbered paragraphs, tables, annexes).
7
+ *
8
+ * Separates CONTENT (structured document data: parts, paragraphs, tables) from
9
+ * PRESENTATION (fonts, page margins, header style, confidentiality marking).
10
+ * The refine boundary enforces this: `apply` may touch presentation, never content.
11
+ *
12
+ * Renders to a paginated A4 PDF with `page-break-inside: avoid` on tables and
13
+ * `page-break-after: avoid` on headings — the two layout invariants for legal docs.
14
+ */
15
+
16
+ declare const FETCH_FONT_FACES_EXTRA_KEY = "legal.fetchFontFaces";
17
+ declare const legalInputSchema: z.ZodObject<{
18
+ title: z.ZodString;
19
+ caseReference: z.ZodString;
20
+ confidentiality: z.ZodOptional<z.ZodString>;
21
+ date: z.ZodOptional<z.ZodString>;
22
+ parts: z.ZodArray<z.ZodObject<{
23
+ title: z.ZodString;
24
+ sections: z.ZodOptional<z.ZodArray<z.ZodObject<{
25
+ heading: z.ZodString;
26
+ paragraphs: z.ZodArray<z.ZodObject<{
27
+ number: z.ZodNumber;
28
+ text: z.ZodString;
29
+ emphasis: z.ZodOptional<z.ZodBoolean>;
30
+ }, z.core.$strip>>;
31
+ tables: z.ZodOptional<z.ZodArray<z.ZodObject<{
32
+ headers: z.ZodArray<z.ZodString>;
33
+ rows: z.ZodArray<z.ZodObject<{
34
+ cells: z.ZodArray<z.ZodString>;
35
+ }, z.core.$strip>>;
36
+ }, z.core.$strip>>>;
37
+ }, z.core.$strip>>>;
38
+ paragraphs: z.ZodOptional<z.ZodArray<z.ZodObject<{
39
+ number: z.ZodNumber;
40
+ text: z.ZodString;
41
+ emphasis: z.ZodOptional<z.ZodBoolean>;
42
+ }, z.core.$strip>>>;
43
+ tables: z.ZodOptional<z.ZodArray<z.ZodObject<{
44
+ headers: z.ZodArray<z.ZodString>;
45
+ rows: z.ZodArray<z.ZodObject<{
46
+ cells: z.ZodArray<z.ZodString>;
47
+ }, z.core.$strip>>;
48
+ }, z.core.$strip>>>;
49
+ }, z.core.$strip>>;
50
+ annexes: z.ZodOptional<z.ZodArray<z.ZodObject<{
51
+ title: z.ZodString;
52
+ content: z.ZodString;
53
+ tables: z.ZodOptional<z.ZodArray<z.ZodObject<{
54
+ headers: z.ZodArray<z.ZodString>;
55
+ rows: z.ZodArray<z.ZodObject<{
56
+ cells: z.ZodArray<z.ZodString>;
57
+ }, z.core.$strip>>;
58
+ }, z.core.$strip>>>;
59
+ }, z.core.$strip>>>;
60
+ design: z.ZodOptional<z.ZodString>;
61
+ fonts: z.ZodOptional<z.ZodEnum<{
62
+ link: "link";
63
+ embed: "embed";
64
+ none: "none";
65
+ }>>;
66
+ fontFamily: z.ZodOptional<z.ZodString>;
67
+ fontSize: z.ZodOptional<z.ZodString>;
68
+ lineHeight: z.ZodOptional<z.ZodString>;
69
+ pageMargin: z.ZodOptional<z.ZodString>;
70
+ }, z.core.$strip>;
71
+ /**
72
+ * Markdown-first input: point to a .md file, the parser extracts structured
73
+ * content automatically. Presentation fields work identically.
74
+ */
75
+ declare const legalMarkdownInputSchema: z.ZodObject<{
76
+ contentPath: z.ZodString;
77
+ design: z.ZodOptional<z.ZodString>;
78
+ fonts: z.ZodOptional<z.ZodEnum<{
79
+ link: "link";
80
+ embed: "embed";
81
+ none: "none";
82
+ }>>;
83
+ fontFamily: z.ZodOptional<z.ZodString>;
84
+ fontSize: z.ZodOptional<z.ZodString>;
85
+ lineHeight: z.ZodOptional<z.ZodString>;
86
+ pageMargin: z.ZodOptional<z.ZodString>;
87
+ }, z.core.$strip>;
88
+ type LegalMarkdownInput = z.infer<typeof legalMarkdownInputSchema>;
89
+ type LegalInput = z.infer<typeof legalInputSchema>;
90
+ declare function buildHtml(input: LegalInput): string;
91
+ declare const legalPlugin: CanvakitPlugin<LegalInput>;
92
+
93
+ /**
94
+ * Parse a Commission-style markdown document into the structured `LegalInput`
95
+ * parts/sections/paragraphs/tables format.
96
+ *
97
+ * Convention:
98
+ * # Title → input.title
99
+ * **Case AT.41034 ...** → input.caseReference (first bold-only line)
100
+ * **CONFIDENTIAL** ... → input.confidentiality
101
+ * ## Part I -- ... → part
102
+ * ### A. Section → section within current part
103
+ * 1. Paragraph text → numbered paragraph
104
+ * | H1 | H2 | → table (standard markdown)
105
+ * ## Annex A -- ... → annex (## heading containing "Annex")
106
+ */
107
+
108
+ declare function parseMarkdownToLegalInput(markdown: string): Omit<LegalInput, "design" | "fonts" | "fontFamily" | "fontSize" | "lineHeight" | "pageMargin">;
109
+
110
+ /**
111
+ * @canvakit/plugin-legal — the declarative `legal` output-type plugin for the
112
+ * @canvakit/agent engine.
113
+ *
114
+ * Usage:
115
+ * import { register } from "@canvakit/plugin-legal"
116
+ * import { generate } from "@canvakit/agent"
117
+ * register() // adds "legal" to defaultRegistry
118
+ * await generate("legal", { title, caseReference, parts }, { ctx: { cwd } })
119
+ */
120
+
121
+ declare function register(registry?: PluginSourceRegistry): void;
122
+
123
+ export { FETCH_FONT_FACES_EXTRA_KEY, type LegalInput, type LegalMarkdownInput, buildHtml, legalInputSchema, legalMarkdownInputSchema, legalPlugin, parseMarkdownToLegalInput, register };
package/dist/index.mjs ADDED
@@ -0,0 +1,637 @@
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-legal v0.1.0
10
+ * The declarative `legal` 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
+
54
+ // src/legal-plugin.ts
55
+ var FETCH_FONT_FACES_EXTRA_KEY = "legal.fetchFontFaces";
56
+ function isFetchFontFaces(value) {
57
+ return typeof value === "function";
58
+ }
59
+ function extractFontFetcher(ctx) {
60
+ const raw = ctx.extra?.[FETCH_FONT_FACES_EXTRA_KEY];
61
+ return isFetchFontFaces(raw) ? raw : void 0;
62
+ }
63
+ var tableRowSchema = z.object({
64
+ cells: z.array(z.string())
65
+ });
66
+ var tableSchema = z.object({
67
+ headers: z.array(z.string()),
68
+ rows: z.array(tableRowSchema)
69
+ });
70
+ var paragraphSchema = z.object({
71
+ number: z.number().int().positive(),
72
+ text: z.string(),
73
+ emphasis: z.boolean().optional()
74
+ });
75
+ var sectionSchema = z.object({
76
+ heading: z.string(),
77
+ paragraphs: z.array(paragraphSchema),
78
+ tables: z.array(tableSchema).optional()
79
+ });
80
+ var partSchema = z.object({
81
+ title: z.string(),
82
+ sections: z.array(sectionSchema).optional(),
83
+ paragraphs: z.array(paragraphSchema).optional(),
84
+ tables: z.array(tableSchema).optional()
85
+ });
86
+ var annexSchema = z.object({
87
+ title: z.string(),
88
+ content: z.string(),
89
+ tables: z.array(tableSchema).optional()
90
+ });
91
+ var legalInputSchema = z.object({
92
+ /** Structured content (provide these OR contentPath, not both). */
93
+ title: z.string().min(1),
94
+ caseReference: z.string().min(1),
95
+ confidentiality: z.string().optional(),
96
+ date: z.string().optional(),
97
+ parts: z.array(partSchema),
98
+ annexes: z.array(annexSchema).optional(),
99
+ /** Presentation — safe for refine edits. */
100
+ design: z.string().min(1).optional(),
101
+ fonts: z.enum(["link", "embed", "none"]).optional(),
102
+ fontFamily: z.string().optional(),
103
+ fontSize: z.string().optional(),
104
+ lineHeight: z.string().optional(),
105
+ pageMargin: z.string().optional()
106
+ });
107
+ var legalMarkdownInputSchema = z.object({
108
+ contentPath: z.string().min(1),
109
+ design: z.string().min(1).optional(),
110
+ fonts: z.enum(["link", "embed", "none"]).optional(),
111
+ fontFamily: z.string().optional(),
112
+ fontSize: z.string().optional(),
113
+ lineHeight: z.string().optional(),
114
+ pageMargin: z.string().optional()
115
+ });
116
+ function escapeHtml(s) {
117
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
118
+ }
119
+ function renderTable(table) {
120
+ const ths = table.headers.map((h) => `<th>${escapeHtml(h)}</th>`).join("");
121
+ const rows = table.rows.map(
122
+ (r) => `<tr>${r.cells.map((c) => `<td>${escapeHtml(c)}</td>`).join("")}</tr>`
123
+ ).join("\n");
124
+ return `<table><thead><tr>${ths}</tr></thead><tbody>${rows}</tbody></table>`;
125
+ }
126
+ function renderParagraph(p) {
127
+ const text = p.emphasis ? `<strong>${escapeHtml(p.text)}</strong>` : escapeHtml(p.text);
128
+ return `<p><span class="para-num">${p.number}.</span> ${text}</p>`;
129
+ }
130
+ function renderSection(section) {
131
+ const parts = [`<h3>${escapeHtml(section.heading)}</h3>`];
132
+ for (const p of section.paragraphs) parts.push(renderParagraph(p));
133
+ if (section.tables) {
134
+ for (const t of section.tables) parts.push(renderTable(t));
135
+ }
136
+ return parts.join("\n");
137
+ }
138
+ function renderPart(part) {
139
+ const parts = [`<h2>${escapeHtml(part.title)}</h2>`];
140
+ if (part.paragraphs) {
141
+ for (const p of part.paragraphs) parts.push(renderParagraph(p));
142
+ }
143
+ if (part.tables) {
144
+ for (const t of part.tables) parts.push(renderTable(t));
145
+ }
146
+ if (part.sections) {
147
+ for (const s of part.sections) parts.push(renderSection(s));
148
+ }
149
+ return parts.join("\n");
150
+ }
151
+ function renderAnnex(annex) {
152
+ const parts = [
153
+ `<h2>${escapeHtml(annex.title)}</h2>`,
154
+ `<p>${escapeHtml(annex.content)}</p>`
155
+ ];
156
+ if (annex.tables) {
157
+ for (const t of annex.tables) parts.push(renderTable(t));
158
+ }
159
+ return parts.join("\n");
160
+ }
161
+ function buildHtml(input) {
162
+ const fontFamily = input.fontFamily ?? "'Times New Roman', Times, serif";
163
+ const fontSize = input.fontSize ?? "11.5pt";
164
+ const lineHeight = input.lineHeight ?? "1.5";
165
+ const pageMargin = input.pageMargin ?? "2.5cm 3cm 3cm 3cm";
166
+ const confidentialLabel = input.confidentiality ?? "";
167
+ const caseRef = escapeHtml(input.caseReference);
168
+ const cover = [];
169
+ cover.push(`<section class="cover">`);
170
+ cover.push(`<div class="cover-inner">`);
171
+ if (confidentialLabel) {
172
+ cover.push(`<p class="cover-marking">${escapeHtml(confidentialLabel)}</p>`);
173
+ }
174
+ cover.push(`<h1 class="cover-title">${escapeHtml(input.title)}</h1>`);
175
+ cover.push(`<p class="cover-case">${caseRef}</p>`);
176
+ if (input.date) {
177
+ cover.push(`<p class="cover-date">${escapeHtml(input.date)}</p>`);
178
+ }
179
+ cover.push(`</div>`);
180
+ cover.push(`</section>`);
181
+ const body = [];
182
+ for (const part of input.parts) body.push(renderPart(part));
183
+ if (input.annexes && input.annexes.length > 0) {
184
+ body.push(`<hr class="annex-rule">`);
185
+ for (const annex of input.annexes) body.push(renderAnnex(annex));
186
+ }
187
+ return `<!DOCTYPE html>
188
+ <html lang="en">
189
+ <head>
190
+ <meta charset="utf-8">
191
+ <style>
192
+ /* \u2500\u2500 Page geometry & running headers/footers (CSS Paged Media) \u2500\u2500 */
193
+ @page {
194
+ size: A4;
195
+ margin: ${pageMargin};
196
+
197
+ @top-left {
198
+ content: "${caseRef}";
199
+ font-family: ${fontFamily};
200
+ font-size: 8pt;
201
+ color: #888;
202
+ }
203
+ @top-right {
204
+ content: "${confidentialLabel ? escapeHtml(confidentialLabel).split(" ")[0] : ""}";
205
+ font-family: ${fontFamily};
206
+ font-size: 8pt;
207
+ font-weight: bold;
208
+ color: #c00;
209
+ }
210
+ @bottom-center {
211
+ content: counter(page) " / " counter(pages);
212
+ font-family: ${fontFamily};
213
+ font-size: 8.5pt;
214
+ color: #666;
215
+ }
216
+ @bottom-right {
217
+ content: "Agentik SAS";
218
+ font-family: ${fontFamily};
219
+ font-size: 8pt;
220
+ color: #aaa;
221
+ }
222
+ }
223
+
224
+ /* Cover page: no header/footer, centered content */
225
+ @page cover {
226
+ margin: 0;
227
+ @top-left { content: none; }
228
+ @top-right { content: none; }
229
+ @bottom-center { content: none; }
230
+ @bottom-right { content: none; }
231
+ }
232
+
233
+ /* \u2500\u2500 Base typography \u2500\u2500 */
234
+ body {
235
+ font-family: ${fontFamily};
236
+ font-size: ${fontSize};
237
+ line-height: ${lineHeight};
238
+ color: #1a1a1a;
239
+ max-width: 100%;
240
+ margin: 0;
241
+ padding: 0;
242
+ }
243
+
244
+ /* \u2500\u2500 Cover page \u2500\u2500 */
245
+ .cover {
246
+ page: cover;
247
+ page-break-after: always;
248
+ display: flex;
249
+ align-items: center;
250
+ justify-content: center;
251
+ min-height: 100vh;
252
+ background: #fafafa;
253
+ border-bottom: 4px solid #333;
254
+ }
255
+ .cover-inner {
256
+ text-align: center;
257
+ max-width: 80%;
258
+ padding: 4cm 2cm;
259
+ }
260
+ .cover-title {
261
+ font-size: 20pt;
262
+ font-weight: bold;
263
+ margin-bottom: 1em;
264
+ line-height: 1.3;
265
+ color: #111;
266
+ }
267
+ .cover-case {
268
+ font-size: 12pt;
269
+ color: #444;
270
+ margin-bottom: 0.5em;
271
+ font-style: italic;
272
+ }
273
+ .cover-date {
274
+ font-size: 11pt;
275
+ color: #666;
276
+ margin-top: 2em;
277
+ }
278
+ .cover-marking {
279
+ font-size: 13pt;
280
+ font-weight: bold;
281
+ color: #c00;
282
+ letter-spacing: 0.15em;
283
+ text-transform: uppercase;
284
+ margin-bottom: 3em;
285
+ padding: 0.3em 1em;
286
+ border: 2px solid #c00;
287
+ display: inline-block;
288
+ }
289
+
290
+ /* \u2500\u2500 Document body \u2500\u2500 */
291
+ h2 {
292
+ font-size: 13pt;
293
+ margin-top: 2em;
294
+ margin-bottom: 0.5em;
295
+ padding-bottom: 4px;
296
+ border-bottom: 1.5px solid #333;
297
+ page-break-after: avoid;
298
+ color: #111;
299
+ }
300
+ h3 {
301
+ font-size: 12pt;
302
+ margin-top: 1.5em;
303
+ margin-bottom: 0.3em;
304
+ font-style: italic;
305
+ page-break-after: avoid;
306
+ color: #222;
307
+ }
308
+ p {
309
+ text-align: justify;
310
+ margin: 0.5em 0;
311
+ orphans: 3;
312
+ widows: 3;
313
+ }
314
+ .para-num {
315
+ font-weight: bold;
316
+ margin-right: 0.3em;
317
+ color: #333;
318
+ }
319
+
320
+ /* \u2500\u2500 Tables \u2500\u2500 */
321
+ table {
322
+ width: 100%;
323
+ border-collapse: collapse;
324
+ margin: 1em 0;
325
+ font-size: 10pt;
326
+ page-break-inside: avoid;
327
+ }
328
+ thead { display: table-header-group; }
329
+ th {
330
+ border: 1px solid #555;
331
+ padding: 6px 8px;
332
+ text-align: left;
333
+ background: #eee;
334
+ font-weight: bold;
335
+ font-size: 9.5pt;
336
+ color: #222;
337
+ }
338
+ td {
339
+ border: 1px solid #999;
340
+ padding: 5px 8px;
341
+ text-align: left;
342
+ }
343
+ tr:nth-child(even) td { background: #fafafa; }
344
+
345
+ /* \u2500\u2500 Separators \u2500\u2500 */
346
+ hr {
347
+ border: none;
348
+ border-top: 1px solid #bbb;
349
+ margin: 2em 0;
350
+ }
351
+ .annex-rule {
352
+ border-top: 2px solid #333;
353
+ margin: 3em 0 2em;
354
+ }
355
+ </style>
356
+ </head>
357
+ <body>
358
+ ${cover.join("\n")}
359
+ ${body.join("\n")}
360
+ </body>
361
+ </html>`;
362
+ }
363
+ async function buildExportInput(input, ctx) {
364
+ const cwd = ctx.cwd ?? process.cwd();
365
+ const filesystem = createNodeFs(cwd);
366
+ const html = buildHtml(input);
367
+ const fetchFontFaces = extractFontFetcher(ctx);
368
+ const extensions = [
369
+ designkitExtension({
370
+ fonts: input.fonts ?? "embed",
371
+ ...input.design ? { overrideDesign: input.design } : {},
372
+ ...fetchFontFaces ? { fetchFontFaces } : {}
373
+ })
374
+ ];
375
+ return {
376
+ template: html,
377
+ templatePath: "legal-submission.html",
378
+ filesystem,
379
+ variables: {},
380
+ extensions
381
+ };
382
+ }
383
+ var PLAIN = { medium: "web" };
384
+ function outputFilename(input) {
385
+ const slug = input.caseReference.replace(/[^a-zA-Z0-9.-]+/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
386
+ return `${slug}_Observations.pdf`;
387
+ }
388
+ var refine = {
389
+ rubric: [
390
+ {
391
+ id: "no-table-break",
392
+ criterion: "No table is split across a page boundary \u2014 every table starts and ends on the same page.",
393
+ weight: 3
394
+ },
395
+ {
396
+ id: "heading-attached",
397
+ 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.",
398
+ weight: 3
399
+ },
400
+ {
401
+ id: "legible",
402
+ criterion: "Body text stays readable (roughly >= 10pt); nothing is clipped, truncated, or overlapping.",
403
+ weight: 2
404
+ },
405
+ {
406
+ id: "consistent-numbering",
407
+ criterion: "Paragraph numbers are sequential and rendered in bold before each paragraph text.",
408
+ weight: 1
409
+ }
410
+ ],
411
+ editableScope: {
412
+ fields: [
413
+ "design",
414
+ "fonts",
415
+ "fontFamily",
416
+ "fontSize",
417
+ "lineHeight",
418
+ "pageMargin"
419
+ ],
420
+ notes: "Presentation only \u2014 font, sizing, spacing, design tokens. NEVER the document content (parts, paragraphs, tables, annexes, title, caseReference, confidentiality): the legal substance is fixed input, not something to rewrite while tuning layout."
421
+ },
422
+ apply(input, edit) {
423
+ switch (edit.path) {
424
+ case "design":
425
+ return { ...input, design: z.string().min(1).parse(edit.value) };
426
+ case "fonts":
427
+ return {
428
+ ...input,
429
+ fonts: z.enum(["link", "embed", "none"]).parse(edit.value)
430
+ };
431
+ case "fontFamily":
432
+ return { ...input, fontFamily: z.string().min(1).parse(edit.value) };
433
+ case "fontSize":
434
+ return { ...input, fontSize: z.string().min(1).parse(edit.value) };
435
+ case "lineHeight":
436
+ return { ...input, lineHeight: z.string().min(1).parse(edit.value) };
437
+ case "pageMargin":
438
+ return { ...input, pageMargin: z.string().min(1).parse(edit.value) };
439
+ default:
440
+ throw new Error(
441
+ `[plugin-legal] edit path "${edit.path}" is outside editableScope {design, fonts, fontFamily, fontSize, lineHeight, pageMargin}`
442
+ );
443
+ }
444
+ }
445
+ };
446
+ var legalPlugin = {
447
+ type: "legal",
448
+ input: legalInputSchema,
449
+ output: "pdf",
450
+ async render(input, ctx) {
451
+ const res = await exportCanvas(await buildExportInput(input, ctx), {
452
+ ...PLAIN,
453
+ format: "pdf"
454
+ });
455
+ return {
456
+ bytes: Buffer.from(res.bytes),
457
+ format: "pdf",
458
+ filename: outputFilename(input)
459
+ };
460
+ },
461
+ async preview(input, ctx) {
462
+ const res = await exportCanvas(await buildExportInput(input, ctx), {
463
+ ...PLAIN,
464
+ format: "png"
465
+ });
466
+ return Buffer.from(res.bytes);
467
+ },
468
+ refine
469
+ };
470
+
471
+ // src/markdown-parser.ts
472
+ function stripBold(s) {
473
+ return s.replace(/\*\*(.+?)\*\*/g, "$1");
474
+ }
475
+ function parseTable(lines) {
476
+ const headerLine = lines[0] ?? "";
477
+ const dataLines = lines.slice(2);
478
+ const parseCells = (line) => line.split("|").slice(1, -1).map((c) => c.trim());
479
+ return {
480
+ headers: parseCells(headerLine),
481
+ rows: dataLines.map((l) => ({ cells: parseCells(l) }))
482
+ };
483
+ }
484
+ function parseMarkdownToLegalInput(markdown) {
485
+ const lines = markdown.split("\n");
486
+ let title = "";
487
+ let caseReference = "";
488
+ let confidentiality;
489
+ let date;
490
+ const parts = [];
491
+ const annexes = [];
492
+ let currentPart = null;
493
+ let currentSection = null;
494
+ let currentAnnex = null;
495
+ let tableBuffer = [];
496
+ let annexContentBuffer = [];
497
+ function flushTable() {
498
+ if (tableBuffer.length < 2) {
499
+ tableBuffer = [];
500
+ return;
501
+ }
502
+ const table = parseTable(tableBuffer);
503
+ tableBuffer = [];
504
+ if (currentAnnex) {
505
+ if (!currentAnnex.tables) currentAnnex.tables = [];
506
+ currentAnnex.tables.push(table);
507
+ } else if (currentSection) {
508
+ if (!currentSection.tables) currentSection.tables = [];
509
+ currentSection.tables.push(table);
510
+ } else if (currentPart) {
511
+ if (!currentPart.tables) currentPart.tables = [];
512
+ currentPart.tables.push(table);
513
+ }
514
+ }
515
+ function flushSection() {
516
+ if (currentSection && currentPart) {
517
+ if (!currentPart.sections) currentPart.sections = [];
518
+ currentPart.sections.push(currentSection);
519
+ }
520
+ currentSection = null;
521
+ }
522
+ function flushPart() {
523
+ flushTable();
524
+ flushSection();
525
+ if (currentPart) parts.push(currentPart);
526
+ currentPart = null;
527
+ }
528
+ function flushAnnex() {
529
+ flushTable();
530
+ if (currentAnnex) {
531
+ currentAnnex.content = annexContentBuffer.join("\n").trim();
532
+ annexes.push(currentAnnex);
533
+ }
534
+ currentAnnex = null;
535
+ annexContentBuffer = [];
536
+ }
537
+ function addParagraph(para) {
538
+ if (currentSection) {
539
+ currentSection.paragraphs.push(para);
540
+ } else if (currentPart) {
541
+ if (!currentPart.paragraphs) currentPart.paragraphs = [];
542
+ currentPart.paragraphs.push(para);
543
+ }
544
+ }
545
+ for (let i = 0; i < lines.length; i++) {
546
+ const line = lines[i] ?? "";
547
+ const trimmed = line.trim();
548
+ if (trimmed.startsWith("# ") && !trimmed.startsWith("## ")) {
549
+ title = trimmed.slice(2).trim();
550
+ continue;
551
+ }
552
+ if (trimmed.startsWith("## ")) {
553
+ flushTable();
554
+ const heading = trimmed.slice(3).trim();
555
+ if (/annex/i.test(heading)) {
556
+ flushPart();
557
+ flushAnnex();
558
+ currentAnnex = { title: heading, content: "", tables: [] };
559
+ } else {
560
+ flushAnnex();
561
+ flushPart();
562
+ currentPart = { title: heading };
563
+ }
564
+ continue;
565
+ }
566
+ if (trimmed.startsWith("### ")) {
567
+ flushTable();
568
+ flushSection();
569
+ currentSection = {
570
+ heading: trimmed.slice(4).trim(),
571
+ paragraphs: []
572
+ };
573
+ continue;
574
+ }
575
+ if (trimmed === "---") continue;
576
+ if (trimmed === "") continue;
577
+ if (trimmed.startsWith("|")) {
578
+ tableBuffer.push(trimmed);
579
+ continue;
580
+ } else if (tableBuffer.length > 0) {
581
+ flushTable();
582
+ }
583
+ if (currentAnnex) {
584
+ annexContentBuffer.push(trimmed);
585
+ continue;
586
+ }
587
+ const paraMatch = trimmed.match(/^(\d+)\.\s+(.+)/);
588
+ if (paraMatch) {
589
+ const num = parseInt(paraMatch[1], 10);
590
+ let text = paraMatch[2];
591
+ let emphasis = false;
592
+ if (text.startsWith("**") && text.endsWith("**")) {
593
+ text = text.slice(2, -2);
594
+ emphasis = true;
595
+ }
596
+ text = stripBold(text);
597
+ addParagraph({ number: num, text, emphasis: emphasis || void 0 });
598
+ continue;
599
+ }
600
+ if (!currentPart && !caseReference && /^\*\*.*\*\*$/.test(trimmed)) {
601
+ const inner = trimmed.slice(2, -2);
602
+ if (/case\s+at/i.test(inner) || /affaire/i.test(inner)) {
603
+ caseReference = inner;
604
+ continue;
605
+ }
606
+ }
607
+ if (!currentPart && !confidentiality && /confidential/i.test(trimmed)) {
608
+ confidentiality = stripBold(trimmed);
609
+ continue;
610
+ }
611
+ if (!currentPart && !date && /\b20\d{2}\b/.test(trimmed)) {
612
+ date = stripBold(trimmed);
613
+ continue;
614
+ }
615
+ }
616
+ flushTable();
617
+ flushSection();
618
+ if (currentPart) parts.push(currentPart);
619
+ flushAnnex();
620
+ return {
621
+ title,
622
+ caseReference,
623
+ confidentiality,
624
+ date,
625
+ parts,
626
+ annexes: annexes.length > 0 ? annexes : void 0
627
+ };
628
+ }
629
+
630
+ // src/index.ts
631
+ function register(registry = defaultRegistry) {
632
+ registry.registerPlugin(legalPlugin);
633
+ }
634
+
635
+ export { FETCH_FONT_FACES_EXTRA_KEY, buildHtml, legalInputSchema, legalMarkdownInputSchema, legalPlugin, parseMarkdownToLegalInput, register };
636
+ //# sourceMappingURL=index.mjs.map
637
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/node-fs.ts","../src/legal-plugin.ts","../src/markdown-parser.ts","../src/index.ts"],"names":["resolve","fs","found"],"mappings":";;;;;;;;;;;;AAIO,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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A,EAAA,UAAA,EAAW;AACX,EAAA,YAAA,EAAa;AACb,EAAA,IAAI,WAAA,EAAa,KAAA,CAAM,IAAA,CAAK,WAAW,CAAA;AACvC,EAAA,UAAA,EAAW;AAEX,EAAA,OAAO;AAAA,IACL,KAAA;AAAA,IACA,aAAA;AAAA,IACA,eAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,OAAA,EAAS,OAAA,CAAQ,MAAA,GAAS,CAAA,GAAI,OAAA,GAAU;AAAA,GAC1C;AACF;;;ACrOO,SAAS,QAAA,CACd,WAAiC,eAAA,EAC3B;AACN,EAAA,QAAA,CAAS,eAAe,WAAW,CAAA;AACrC","file":"index.mjs","sourcesContent":["import { 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 `legal` output-type plugin — a DECLARATIVE canvakit plugin for formal\n * legal submissions (EU Commission style, numbered paragraphs, tables, annexes).\n *\n * Separates CONTENT (structured document data: parts, paragraphs, tables) from\n * PRESENTATION (fonts, page margins, header style, confidentiality marking).\n * The refine boundary enforces this: `apply` may touch presentation, never content.\n *\n * Renders to a paginated A4 PDF with `page-break-inside: avoid` on tables and\n * `page-break-after: avoid` on headings — the two layout invariants for legal docs.\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 {\n designkitExtension,\n type FetchFontFaces,\n type FontMode,\n} from \"@canvakit/designkit\"\nimport { createNodeFs } from \"./node-fs.js\"\n\nexport const FETCH_FONT_FACES_EXTRA_KEY = \"legal.fetchFontFaces\"\n\nfunction isFetchFontFaces(value: unknown): value is FetchFontFaces {\n return typeof value === \"function\"\n}\n\nfunction extractFontFetcher(ctx: PluginContext): FetchFontFaces | undefined {\n const raw = ctx.extra?.[FETCH_FONT_FACES_EXTRA_KEY]\n return isFetchFontFaces(raw) ? raw : undefined\n}\n\nconst tableRowSchema = z.object({\n cells: z.array(z.string()),\n})\n\nconst tableSchema = z.object({\n headers: z.array(z.string()),\n rows: z.array(tableRowSchema),\n})\n\nconst paragraphSchema = z.object({\n number: z.number().int().positive(),\n text: z.string(),\n emphasis: z.boolean().optional(),\n})\n\nconst sectionSchema = z.object({\n heading: z.string(),\n paragraphs: z.array(paragraphSchema),\n tables: z.array(tableSchema).optional(),\n})\n\nconst partSchema = z.object({\n title: z.string(),\n sections: z.array(sectionSchema).optional(),\n paragraphs: z.array(paragraphSchema).optional(),\n tables: z.array(tableSchema).optional(),\n})\n\nconst annexSchema = z.object({\n title: z.string(),\n content: z.string(),\n tables: z.array(tableSchema).optional(),\n})\n\nexport const legalInputSchema = z.object({\n /** Structured content (provide these OR contentPath, not both). */\n title: z.string().min(1),\n caseReference: z.string().min(1),\n confidentiality: z.string().optional(),\n date: z.string().optional(),\n parts: z.array(partSchema),\n annexes: z.array(annexSchema).optional(),\n\n /** Presentation — safe for refine edits. */\n design: z.string().min(1).optional(),\n fonts: z.enum([\"link\", \"embed\", \"none\"]).optional(),\n fontFamily: z.string().optional(),\n fontSize: z.string().optional(),\n lineHeight: z.string().optional(),\n pageMargin: z.string().optional(),\n})\n\n/**\n * Markdown-first input: point to a .md file, the parser extracts structured\n * content automatically. Presentation fields work identically.\n */\nexport const legalMarkdownInputSchema = z.object({\n contentPath: z.string().min(1),\n\n design: z.string().min(1).optional(),\n fonts: z.enum([\"link\", \"embed\", \"none\"]).optional(),\n fontFamily: z.string().optional(),\n fontSize: z.string().optional(),\n lineHeight: z.string().optional(),\n pageMargin: z.string().optional(),\n})\n\nexport type LegalMarkdownInput = z.infer<typeof legalMarkdownInputSchema>\n\nexport type LegalInput = z.infer<typeof legalInputSchema>\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 renderTable(table: z.infer<typeof tableSchema>): string {\n const ths = table.headers.map(h => `<th>${escapeHtml(h)}</th>`).join(\"\")\n const rows = table.rows\n .map(\n r => `<tr>${r.cells.map(c => `<td>${escapeHtml(c)}</td>`).join(\"\")}</tr>`\n )\n .join(\"\\n\")\n return `<table><thead><tr>${ths}</tr></thead><tbody>${rows}</tbody></table>`\n}\n\nfunction renderParagraph(p: z.infer<typeof paragraphSchema>): string {\n const text = p.emphasis\n ? `<strong>${escapeHtml(p.text)}</strong>`\n : escapeHtml(p.text)\n return `<p><span class=\"para-num\">${p.number}.</span> ${text}</p>`\n}\n\nfunction renderSection(section: z.infer<typeof sectionSchema>): string {\n const parts: string[] = [`<h3>${escapeHtml(section.heading)}</h3>`]\n for (const p of section.paragraphs) parts.push(renderParagraph(p))\n if (section.tables) {\n for (const t of section.tables) parts.push(renderTable(t))\n }\n return parts.join(\"\\n\")\n}\n\nfunction renderPart(part: z.infer<typeof partSchema>): string {\n const parts: string[] = [`<h2>${escapeHtml(part.title)}</h2>`]\n if (part.paragraphs) {\n for (const p of part.paragraphs) parts.push(renderParagraph(p))\n }\n if (part.tables) {\n for (const t of part.tables) parts.push(renderTable(t))\n }\n if (part.sections) {\n for (const s of part.sections) parts.push(renderSection(s))\n }\n return parts.join(\"\\n\")\n}\n\nfunction renderAnnex(annex: z.infer<typeof annexSchema>): string {\n const parts: string[] = [\n `<h2>${escapeHtml(annex.title)}</h2>`,\n `<p>${escapeHtml(annex.content)}</p>`,\n ]\n if (annex.tables) {\n for (const t of annex.tables) parts.push(renderTable(t))\n }\n return parts.join(\"\\n\")\n}\n\nexport function buildHtml(input: LegalInput): string {\n const fontFamily = input.fontFamily ?? \"'Times New Roman', Times, serif\"\n const fontSize = input.fontSize ?? \"11.5pt\"\n const lineHeight = input.lineHeight ?? \"1.5\"\n const pageMargin = input.pageMargin ?? \"2.5cm 3cm 3cm 3cm\"\n const confidentialLabel = input.confidentiality ?? \"\"\n const caseRef = escapeHtml(input.caseReference)\n\n const cover: string[] = []\n cover.push(`<section class=\"cover\">`)\n cover.push(`<div class=\"cover-inner\">`)\n if (confidentialLabel) {\n cover.push(`<p class=\"cover-marking\">${escapeHtml(confidentialLabel)}</p>`)\n }\n cover.push(`<h1 class=\"cover-title\">${escapeHtml(input.title)}</h1>`)\n cover.push(`<p class=\"cover-case\">${caseRef}</p>`)\n if (input.date) {\n cover.push(`<p class=\"cover-date\">${escapeHtml(input.date)}</p>`)\n }\n cover.push(`</div>`)\n cover.push(`</section>`)\n\n const body: string[] = []\n for (const part of input.parts) body.push(renderPart(part))\n\n if (input.annexes && input.annexes.length > 0) {\n body.push(`<hr class=\"annex-rule\">`)\n for (const annex of input.annexes) body.push(renderAnnex(annex))\n }\n\n return `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<style>\n/* ── Page geometry & running headers/footers (CSS Paged Media) ── */\n@page {\n size: A4;\n margin: ${pageMargin};\n\n @top-left {\n content: \"${caseRef}\";\n font-family: ${fontFamily};\n font-size: 8pt;\n color: #888;\n }\n @top-right {\n content: \"${confidentialLabel ? escapeHtml(confidentialLabel).split(\" \")[0] : \"\"}\";\n font-family: ${fontFamily};\n font-size: 8pt;\n font-weight: bold;\n color: #c00;\n }\n @bottom-center {\n content: counter(page) \" / \" counter(pages);\n font-family: ${fontFamily};\n font-size: 8.5pt;\n color: #666;\n }\n @bottom-right {\n content: \"Agentik SAS\";\n font-family: ${fontFamily};\n font-size: 8pt;\n color: #aaa;\n }\n}\n\n/* Cover page: no header/footer, centered content */\n@page cover {\n margin: 0;\n @top-left { content: none; }\n @top-right { content: none; }\n @bottom-center { content: none; }\n @bottom-right { content: none; }\n}\n\n/* ── Base typography ── */\nbody {\n font-family: ${fontFamily};\n font-size: ${fontSize};\n line-height: ${lineHeight};\n color: #1a1a1a;\n max-width: 100%;\n margin: 0;\n padding: 0;\n}\n\n/* ── Cover page ── */\n.cover {\n page: cover;\n page-break-after: always;\n display: flex;\n align-items: center;\n justify-content: center;\n min-height: 100vh;\n background: #fafafa;\n border-bottom: 4px solid #333;\n}\n.cover-inner {\n text-align: center;\n max-width: 80%;\n padding: 4cm 2cm;\n}\n.cover-title {\n font-size: 20pt;\n font-weight: bold;\n margin-bottom: 1em;\n line-height: 1.3;\n color: #111;\n}\n.cover-case {\n font-size: 12pt;\n color: #444;\n margin-bottom: 0.5em;\n font-style: italic;\n}\n.cover-date {\n font-size: 11pt;\n color: #666;\n margin-top: 2em;\n}\n.cover-marking {\n font-size: 13pt;\n font-weight: bold;\n color: #c00;\n letter-spacing: 0.15em;\n text-transform: uppercase;\n margin-bottom: 3em;\n padding: 0.3em 1em;\n border: 2px solid #c00;\n display: inline-block;\n}\n\n/* ── Document body ── */\nh2 {\n font-size: 13pt;\n margin-top: 2em;\n margin-bottom: 0.5em;\n padding-bottom: 4px;\n border-bottom: 1.5px solid #333;\n page-break-after: avoid;\n color: #111;\n}\nh3 {\n font-size: 12pt;\n margin-top: 1.5em;\n margin-bottom: 0.3em;\n font-style: italic;\n page-break-after: avoid;\n color: #222;\n}\np {\n text-align: justify;\n margin: 0.5em 0;\n orphans: 3;\n widows: 3;\n}\n.para-num {\n font-weight: bold;\n margin-right: 0.3em;\n color: #333;\n}\n\n/* ── Tables ── */\ntable {\n width: 100%;\n border-collapse: collapse;\n margin: 1em 0;\n font-size: 10pt;\n page-break-inside: avoid;\n}\nthead { display: table-header-group; }\nth {\n border: 1px solid #555;\n padding: 6px 8px;\n text-align: left;\n background: #eee;\n font-weight: bold;\n font-size: 9.5pt;\n color: #222;\n}\ntd {\n border: 1px solid #999;\n padding: 5px 8px;\n text-align: left;\n}\ntr:nth-child(even) td { background: #fafafa; }\n\n/* ── Separators ── */\nhr {\n border: none;\n border-top: 1px solid #bbb;\n margin: 2em 0;\n}\n.annex-rule {\n border-top: 2px solid #333;\n margin: 3em 0 2em;\n}\n</style>\n</head>\n<body>\n${cover.join(\"\\n\")}\n${body.join(\"\\n\")}\n</body>\n</html>`\n}\n\nasync function buildExportInput(\n input: LegalInput,\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 fetchFontFaces = extractFontFetcher(ctx)\n const extensions = [\n designkitExtension({\n fonts: (input.fonts ?? \"embed\") as FontMode,\n ...(input.design ? { overrideDesign: input.design } : {}),\n ...(fetchFontFaces ? { fetchFontFaces } : {}),\n }),\n ]\n\n return {\n template: html,\n templatePath: \"legal-submission.html\",\n filesystem,\n variables: {},\n extensions,\n }\n}\n\nconst PLAIN: Pick<ExportOptions, \"medium\"> = { medium: \"web\" }\n\nfunction outputFilename(input: LegalInput): string {\n const slug = input.caseReference\n .replace(/[^a-zA-Z0-9.-]+/g, \"_\")\n .replace(/_+/g, \"_\")\n .replace(/^_|_$/g, \"\")\n return `${slug}_Observations.pdf`\n}\n\nconst refine: RefineCapability<LegalInput> = {\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 id: \"consistent-numbering\",\n criterion:\n \"Paragraph numbers are sequential and rendered in bold before each paragraph text.\",\n weight: 1,\n },\n ],\n editableScope: {\n fields: [\n \"design\",\n \"fonts\",\n \"fontFamily\",\n \"fontSize\",\n \"lineHeight\",\n \"pageMargin\",\n ],\n notes:\n \"Presentation only — font, sizing, spacing, design tokens. NEVER the document content (parts, paragraphs, tables, annexes, title, caseReference, confidentiality): the legal substance is fixed input, not something to rewrite while tuning layout.\",\n },\n apply(input: LegalInput, edit: Edit): LegalInput {\n switch (edit.path) {\n case \"design\":\n return { ...input, design: z.string().min(1).parse(edit.value) }\n case \"fonts\":\n return {\n ...input,\n fonts: z.enum([\"link\", \"embed\", \"none\"]).parse(edit.value),\n }\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 \"lineHeight\":\n return { ...input, lineHeight: 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-legal] edit path \"${edit.path}\" is outside editableScope {design, fonts, fontFamily, fontSize, lineHeight, pageMargin}`\n )\n }\n },\n}\n\nexport const legalPlugin: CanvakitPlugin<LegalInput> = {\n type: \"legal\",\n input: legalInputSchema,\n output: \"pdf\",\n async render(input: LegalInput, ctx: PluginContext): 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(input: LegalInput, ctx: PluginContext): 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 * Parse a Commission-style markdown document into the structured `LegalInput`\n * parts/sections/paragraphs/tables format.\n *\n * Convention:\n * # Title → input.title\n * **Case AT.41034 ...** → input.caseReference (first bold-only line)\n * **CONFIDENTIAL** ... → input.confidentiality\n * ## Part I -- ... → part\n * ### A. Section → section within current part\n * 1. Paragraph text → numbered paragraph\n * | H1 | H2 | → table (standard markdown)\n * ## Annex A -- ... → annex (## heading containing \"Annex\")\n */\n\nimport { z } from \"zod\"\nimport type { LegalInput } from \"./legal-plugin.js\"\n\ninterface Table {\n headers: string[]\n rows: Array<{ cells: string[] }>\n}\n\ninterface Paragraph {\n number: number\n text: string\n emphasis?: boolean\n}\n\ninterface Section {\n heading: string\n paragraphs: Paragraph[]\n tables?: Table[]\n}\n\ninterface Part {\n title: string\n sections?: Section[]\n paragraphs?: Paragraph[]\n tables?: Table[]\n}\n\ninterface Annex {\n title: string\n content: string\n tables?: Table[]\n}\n\nfunction stripBold(s: string): string {\n return s.replace(/\\*\\*(.+?)\\*\\*/g, \"$1\")\n}\n\nfunction parseTable(lines: string[]): Table {\n const headerLine = lines[0] ?? \"\"\n const dataLines = lines.slice(2)\n\n const parseCells = (line: string) =>\n line\n .split(\"|\")\n .slice(1, -1)\n .map(c => c.trim())\n\n return {\n headers: parseCells(headerLine),\n rows: dataLines.map(l => ({ cells: parseCells(l) })),\n }\n}\n\nexport function parseMarkdownToLegalInput(\n markdown: string\n): Omit<\n LegalInput,\n \"design\" | \"fonts\" | \"fontFamily\" | \"fontSize\" | \"lineHeight\" | \"pageMargin\"\n> {\n const lines = markdown.split(\"\\n\")\n\n let title = \"\"\n let caseReference = \"\"\n let confidentiality: string | undefined\n let date: string | undefined\n const parts: Part[] = []\n const annexes: Annex[] = []\n\n let currentPart: Part | null = null\n let currentSection: Section | null = null\n let currentAnnex: Annex | null = null\n let tableBuffer: string[] = []\n let annexContentBuffer: string[] = []\n\n function flushTable() {\n if (tableBuffer.length < 2) {\n tableBuffer = []\n return\n }\n const table = parseTable(tableBuffer)\n tableBuffer = []\n\n if (currentAnnex) {\n if (!currentAnnex.tables) currentAnnex.tables = []\n currentAnnex.tables.push(table)\n } else if (currentSection) {\n if (!currentSection.tables) currentSection.tables = []\n currentSection.tables.push(table)\n } else if (currentPart) {\n if (!currentPart.tables) currentPart.tables = []\n currentPart.tables.push(table)\n }\n }\n\n function flushSection() {\n if (currentSection && currentPart) {\n if (!currentPart.sections) currentPart.sections = []\n currentPart.sections.push(currentSection)\n }\n currentSection = null\n }\n\n function flushPart() {\n flushTable()\n flushSection()\n if (currentPart) parts.push(currentPart)\n currentPart = null\n }\n\n function flushAnnex() {\n flushTable()\n if (currentAnnex) {\n currentAnnex.content = annexContentBuffer.join(\"\\n\").trim()\n annexes.push(currentAnnex)\n }\n currentAnnex = null\n annexContentBuffer = []\n }\n\n function addParagraph(para: Paragraph) {\n if (currentSection) {\n currentSection.paragraphs.push(para)\n } else if (currentPart) {\n if (!currentPart.paragraphs) currentPart.paragraphs = []\n currentPart.paragraphs.push(para)\n }\n }\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i] ?? \"\"\n const trimmed = line.trim()\n\n // H1: title\n if (trimmed.startsWith(\"# \") && !trimmed.startsWith(\"## \")) {\n title = trimmed.slice(2).trim()\n continue\n }\n\n // H2: part or annex\n if (trimmed.startsWith(\"## \")) {\n flushTable()\n const heading = trimmed.slice(3).trim()\n\n if (/annex/i.test(heading)) {\n flushPart()\n flushAnnex()\n currentAnnex = { title: heading, content: \"\", tables: [] }\n } else {\n flushAnnex()\n flushPart()\n currentPart = { title: heading }\n }\n continue\n }\n\n // H3: section within current part\n if (trimmed.startsWith(\"### \")) {\n flushTable()\n flushSection()\n currentSection = {\n heading: trimmed.slice(4).trim(),\n paragraphs: [],\n }\n continue\n }\n\n // Horizontal rule\n if (trimmed === \"---\") continue\n\n // Empty line\n if (trimmed === \"\") continue\n\n // Table line\n if (trimmed.startsWith(\"|\")) {\n tableBuffer.push(trimmed)\n continue\n } else if (tableBuffer.length > 0) {\n flushTable()\n }\n\n // Inside an annex: collect as content\n if (currentAnnex) {\n annexContentBuffer.push(trimmed)\n continue\n }\n\n // Numbered paragraph: \"1. text\" or \"10. text\"\n const paraMatch = trimmed.match(/^(\\d+)\\.\\s+(.+)/)\n if (paraMatch) {\n const num = parseInt(paraMatch[1]!, 10)\n let text = paraMatch[2]!\n let emphasis = false\n\n if (text.startsWith(\"**\") && text.endsWith(\"**\")) {\n text = text.slice(2, -2)\n emphasis = true\n }\n text = stripBold(text)\n\n addParagraph({ number: num, text, emphasis: emphasis || undefined })\n continue\n }\n\n // Case reference: first bold-only line before any part\n if (!currentPart && !caseReference && /^\\*\\*.*\\*\\*$/.test(trimmed)) {\n const inner = trimmed.slice(2, -2)\n if (/case\\s+at/i.test(inner) || /affaire/i.test(inner)) {\n caseReference = inner\n continue\n }\n }\n\n // Confidentiality marking\n if (!currentPart && !confidentiality && /confidential/i.test(trimmed)) {\n confidentiality = stripBold(trimmed)\n continue\n }\n\n // Date line (before parts, contains a year)\n if (!currentPart && !date && /\\b20\\d{2}\\b/.test(trimmed)) {\n date = stripBold(trimmed)\n continue\n }\n }\n\n // Flush remaining\n flushTable()\n flushSection()\n if (currentPart) parts.push(currentPart)\n flushAnnex()\n\n return {\n title,\n caseReference,\n confidentiality,\n date,\n parts,\n annexes: annexes.length > 0 ? annexes : undefined,\n }\n}\n","/**\n * @canvakit/plugin-legal — the declarative `legal` output-type plugin for the\n * @canvakit/agent engine.\n *\n * Usage:\n * import { register } from \"@canvakit/plugin-legal\"\n * import { generate } from \"@canvakit/agent\"\n * register() // adds \"legal\" to defaultRegistry\n * await generate(\"legal\", { title, caseReference, parts }, { ctx: { cwd } })\n */\n\nimport { defaultRegistry, type PluginSourceRegistry } from \"@canvakit/agent\"\nimport { legalPlugin } from \"./legal-plugin.js\"\n\nexport {\n legalPlugin,\n legalInputSchema,\n legalMarkdownInputSchema,\n buildHtml,\n FETCH_FONT_FACES_EXTRA_KEY,\n type LegalInput,\n type LegalMarkdownInput,\n} from \"./legal-plugin.js\"\nexport { parseMarkdownToLegalInput } from \"./markdown-parser.js\"\n\nexport function register(\n registry: PluginSourceRegistry = defaultRegistry\n): void {\n registry.registerPlugin(legalPlugin)\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
2
  "name": "@canvakit/plugin-legal",
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 `legal` output-type plugin for @canvakit/agent — a declarative legal-submission plugin (numbered paragraphs, tables, annexes → paginated A4 PDF) that separates content from presentation. Registers the \"legal\" type into a PluginSourceRegistry.",
5
+ "keywords": [
6
+ "canvakit",
7
+ "agent",
8
+ "plugin",
9
+ "legal",
10
+ "submission",
11
+ "commission",
12
+ "declarative"
13
+ ],
14
+ "homepage": "https://canvakit.sh",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/openagentik/canvakit",
18
+ "directory": "packages/plugin-legal"
19
+ },
20
+ "license": "FSL-1.1-ALv2",
21
+ "type": "module",
22
+ "main": "dist/index.mjs",
23
+ "module": "dist/index.mjs",
24
+ "types": "dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.mjs",
29
+ "default": "./dist/index.mjs"
30
+ },
31
+ "./package.json": "./package.json"
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "README.md",
36
+ "LICENSE"
37
+ ],
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "dependencies": {
42
+ "@canvakit/agent": "^0.2.0",
43
+ "@canvakit/core": "^0.2.0",
44
+ "@canvakit/designkit": "^0.2.0",
45
+ "@canvakit/export": "^0.2.0",
46
+ "zod": "^4.4.3"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^25.6.2",
50
+ "tsup": "^8.5.1",
51
+ "typescript": "^5.9.3",
52
+ "vitest": "^3.2.4",
53
+ "@canvakit/tooling": "0.0.0"
54
+ },
55
+ "bugs": {
56
+ "url": "https://github.com/openagentik/canvakit/issues"
57
+ },
58
+ "scripts": {
59
+ "dev": "tsup --watch",
60
+ "build": "tsup",
61
+ "clean": "rm -rf dist",
62
+ "check-types": "tsc --noEmit",
63
+ "test": "vitest run",
64
+ "test:watch": "vitest"
65
+ }
6
66
  }