@asterdoc/render 0.0.0-stage → 0.9.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.
@@ -0,0 +1,20 @@
1
+ import { SignaturePlaceholderValue, SignatureCapturedValue } from '@asterdoc/types';
2
+
3
+ interface DocxSignatureOptions {
4
+ placeholder?: {
5
+ signature?: SignaturePlaceholderValue;
6
+ initials?: SignaturePlaceholderValue;
7
+ signatureDate?: SignaturePlaceholderValue;
8
+ capacity?: SignaturePlaceholderValue;
9
+ printedName?: SignaturePlaceholderValue;
10
+ };
11
+ captured?: {
12
+ signature?: SignatureCapturedValue;
13
+ initials?: SignatureCapturedValue;
14
+ signatureDate?: SignatureCapturedValue;
15
+ capacity?: SignatureCapturedValue;
16
+ printedName?: SignatureCapturedValue;
17
+ };
18
+ }
19
+
20
+ export type { DocxSignatureOptions as D };
@@ -0,0 +1,27 @@
1
+ import { SignaturePlaceholderValue, SignatureCapturedValue } from '@asterdoc/types';
2
+
3
+ interface TextSignatureOptions {
4
+ /**
5
+ * How signing marks print. Defaults from the layer's MIME type: `html` for
6
+ * `text/html`, `markdown` for `text/markdown`, else `text`.
7
+ */
8
+ format?: 'text' | 'html' | 'markdown';
9
+ placeholder?: {
10
+ signature?: SignaturePlaceholderValue;
11
+ initials?: SignaturePlaceholderValue;
12
+ signatureDate?: SignaturePlaceholderValue;
13
+ capacity?: SignaturePlaceholderValue;
14
+ printedName?: SignaturePlaceholderValue;
15
+ };
16
+ captured?: {
17
+ signature?: SignatureCapturedValue;
18
+ initials?: SignatureCapturedValue;
19
+ signatureDate?: SignatureCapturedValue;
20
+ capacity?: SignatureCapturedValue;
21
+ printedName?: SignatureCapturedValue;
22
+ };
23
+ altText?: string;
24
+ cssClass?: string;
25
+ }
26
+
27
+ export type { TextSignatureOptions as T };
@@ -0,0 +1,46 @@
1
+ import { FormatIssue, FormatterProgressivePolicy, MoneyFormatOptions, Form, Formatter, Bindings, FormField } from '@asterdoc/types';
2
+
3
+ /** Explicit policy for rendering a value that is missing or incomplete. */
4
+ type ProgressiveFormattingOptions = FormatterProgressivePolicy;
5
+ interface FieldFormattingOptions {
6
+ /** Enable placeholders for missing/incomplete values for a progressive preview. */
7
+ progressive?: ProgressiveFormattingOptions;
8
+ /**
9
+ * What a choice prints: its option label (the default) or its option value.
10
+ * A PDF box writes the value, the code the form expects, such as "C" or "5".
11
+ */
12
+ choices?: 'label' | 'value';
13
+ /**
14
+ * Options for every money value, applied over the formatter's own policy.
15
+ * A PDF layer that declares `format.money` passes it here.
16
+ */
17
+ money?: MoneyFormatOptions;
18
+ }
19
+ type RecordValue = Record<string, unknown>;
20
+ /**
21
+ * A template value that keeps its source value for logic/property access while
22
+ * supplying the selected formatter's text for interpolation.
23
+ */
24
+ declare class FormattedFieldValue {
25
+ constructor(value: unknown, text: string);
26
+ get raw(): unknown;
27
+ toString(): string;
28
+ }
29
+ declare function unwrapFormattedValue(value: unknown): unknown;
30
+ /** Raised when a declared artifact value cannot be presented. */
31
+ declare class ArtifactFieldFormatError extends Error {
32
+ readonly path: string;
33
+ readonly fieldType: string;
34
+ readonly status: string;
35
+ readonly issues: readonly FormatIssue[];
36
+ constructor(path: string, fieldType: string, status: string, issues: readonly FormatIssue[], cause?: unknown);
37
+ }
38
+ declare function formatFieldValue(formatter: Formatter, field: FormField, value: unknown, path: string, options?: FieldFormattingOptions): unknown;
39
+ declare function formatDefinitionValue(formatter: Formatter, type: string, value: unknown, path: string, options?: FieldFormattingOptions): unknown;
40
+ declare function formatParties(formatter: Formatter, form: Form, value: unknown, path: string, options?: FieldFormattingOptions, role?: string): unknown;
41
+ /** Apply one formatter to all declared field-aware values in a text render payload. */
42
+ declare function formatFieldData(data: RecordValue, form: Form, formatter: Formatter, options?: FieldFormattingOptions): RecordValue;
43
+ /** Validate renderer binding sources against the declared artifact shape. */
44
+ declare function validateFieldBindings(form: Form, bindings: Bindings): void;
45
+
46
+ export { ArtifactFieldFormatError, type FieldFormattingOptions, FormattedFieldValue, type ProgressiveFormattingOptions, formatDefinitionValue, formatFieldData, formatFieldValue, formatParties, unwrapFormattedValue, validateFieldBindings };
@@ -0,0 +1,21 @@
1
+ import {
2
+ ArtifactFieldFormatError,
3
+ FormattedFieldValue,
4
+ formatDefinitionValue,
5
+ formatFieldData,
6
+ formatFieldValue,
7
+ formatParties,
8
+ unwrapFormattedValue,
9
+ validateFieldBindings
10
+ } from "../chunk-ICQLU4FL.js";
11
+ import "../chunk-4QVR6LUY.js";
12
+ export {
13
+ ArtifactFieldFormatError,
14
+ FormattedFieldValue,
15
+ formatDefinitionValue,
16
+ formatFieldData,
17
+ formatFieldValue,
18
+ formatParties,
19
+ unwrapFormattedValue,
20
+ validateFieldBindings
21
+ };
package/dist/text.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { Form, Formatter, FormatterProgressivePolicy, AsterdocRenderer, RendererLayer } from '@asterdoc/types';
2
+ import { FieldFormattingOptions } from './text/field-formatter.js';
3
+ export { ArtifactFieldFormatError, FormattedFieldValue, ProgressiveFormattingOptions, formatFieldData, unwrapFormattedValue, validateFieldBindings } from './text/field-formatter.js';
4
+ import { T as TextSignatureOptions } from './signatures-cS3V0yR3.js';
5
+ import { T as TemplateExpressionOptions } from './context-BmjDcc_j.js';
6
+ export { S as SigningDirectiveUse, T as TemplateDiagnostic, a as TemplateError, b as TemplatePosition, d as checkTextTemplate, t as textTemplateSigningDirectives } from './check-BA5xdYgi.js';
7
+ import '@asterdoc/expr';
8
+
9
+ /** Places a signing mark for a party at a location: `signature`, `initials`, and the related directives. */
10
+ type SigningDirective = (party: unknown, root: Record<string, unknown>, args: unknown[]) => unknown;
11
+
12
+ interface RenderTextOptions {
13
+ template: string;
14
+ data: Record<string, unknown>;
15
+ form?: Form;
16
+ formatter?: Formatter;
17
+ progressive?: FieldFormattingOptions['progressive'];
18
+ signatureOptions?: TextSignatureOptions;
19
+ /** The expression context and configured functions templates read. */
20
+ expressions?: TemplateExpressionOptions;
21
+ /** The layer key, named in template errors. */
22
+ layer?: string;
23
+ /**
24
+ * The output MIME type. `text/html` escapes interpolated values; plain text
25
+ * and Markdown print them unchanged.
26
+ */
27
+ mimeType?: string;
28
+ }
29
+ declare function renderText(options: RenderTextOptions): string;
30
+
31
+ interface TextRendererOptions {
32
+ formatter?: Formatter;
33
+ progressive?: FormatterProgressivePolicy;
34
+ signatureOptions?: TextSignatureOptions;
35
+ /** Configured functions templates can call when no artifact context is supplied. */
36
+ expressions?: Pick<TemplateExpressionOptions, 'functions' | 'signatures'>;
37
+ }
38
+ type TextLayer = RendererLayer & {
39
+ type: 'text';
40
+ content: string;
41
+ };
42
+ declare function textRenderer(options?: TextRendererOptions): AsterdocRenderer<TextLayer, string>;
43
+
44
+ export { FieldFormattingOptions, type RenderTextOptions, type SigningDirective, TemplateExpressionOptions, type TextRendererOptions, TextSignatureOptions, renderText, textRenderer };
package/dist/text.js ADDED
@@ -0,0 +1,77 @@
1
+ import {
2
+ TemplateError,
3
+ checkTextTemplate,
4
+ createTextSignatureDirectives,
5
+ escapeHtml,
6
+ renderTemplate,
7
+ requestExpressions,
8
+ templateData,
9
+ textTemplateSigningDirectives
10
+ } from "./chunk-PNYKTSIT.js";
11
+ import {
12
+ requestRenderData
13
+ } from "./chunk-U7LF3GN4.js";
14
+ import {
15
+ ArtifactFieldFormatError,
16
+ FormattedFieldValue,
17
+ formatFieldData,
18
+ unwrapFormattedValue,
19
+ validateFieldBindings
20
+ } from "./chunk-ICQLU4FL.js";
21
+ import "./chunk-4QVR6LUY.js";
22
+
23
+ // src/text/render.ts
24
+ import { defaultFormatter } from "@asterdoc/format";
25
+ function escapeFor(mimeType) {
26
+ return mimeType?.toLowerCase() === "text/html" ? escapeHtml : (value) => value;
27
+ }
28
+ function renderText(options) {
29
+ const formatter = options.formatter ?? defaultFormatter;
30
+ const formattingOptions = options.progressive === void 0 ? void 0 : { progressive: options.progressive };
31
+ const data = options.form ? formatFieldData(options.data, options.form, formatter, formattingOptions) : options.data;
32
+ const { context, resolveData } = templateData(options.data, data, options.form, options.expressions);
33
+ return renderTemplate(options.template, {
34
+ context,
35
+ resolveData,
36
+ root: data,
37
+ formatter,
38
+ directives: createTextSignatureDirectives(options.signatureOptions, options.mimeType),
39
+ layer: options.layer,
40
+ escape: escapeFor(options.mimeType)
41
+ });
42
+ }
43
+
44
+ // src/text/renderer.ts
45
+ import { defaultFormatter as defaultFormatter2 } from "@asterdoc/format";
46
+ function textRenderer(options = {}) {
47
+ const formatter = options.formatter ?? defaultFormatter2;
48
+ return {
49
+ id: "text",
50
+ render(request) {
51
+ const { data, form } = requestRenderData(request);
52
+ return renderText({
53
+ template: request.template.content,
54
+ data,
55
+ form,
56
+ formatter: request.ctx?.formatter ?? formatter,
57
+ progressive: request.ctx?.progressive ?? options.progressive,
58
+ signatureOptions: options.signatureOptions,
59
+ expressions: requestExpressions(options.expressions, request.ctx?.expressions),
60
+ layer: request.template.key,
61
+ mimeType: request.template.mimeType
62
+ });
63
+ }
64
+ };
65
+ }
66
+ export {
67
+ ArtifactFieldFormatError,
68
+ FormattedFieldValue,
69
+ TemplateError,
70
+ checkTextTemplate,
71
+ formatFieldData,
72
+ renderText,
73
+ textRenderer,
74
+ textTemplateSigningDirectives,
75
+ unwrapFormattedValue,
76
+ validateFieldBindings
77
+ };
package/package.json CHANGED
@@ -1,6 +1,106 @@
1
1
  {
2
2
  "name": "@asterdoc/render",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.9.0",
4
+ "description": "Focused text, PDF, and DOCX rendering for Asterdoc",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./text": {
16
+ "types": "./dist/text.d.ts",
17
+ "import": "./dist/text.js",
18
+ "default": "./dist/text.js"
19
+ },
20
+ "./text/field-formatter": {
21
+ "types": "./dist/text/field-formatter.d.ts",
22
+ "import": "./dist/text/field-formatter.js",
23
+ "default": "./dist/text/field-formatter.js"
24
+ },
25
+ "./pdf": {
26
+ "types": "./dist/pdf.d.ts",
27
+ "import": "./dist/pdf.js",
28
+ "default": "./dist/pdf.js"
29
+ },
30
+ "./docx": {
31
+ "types": "./dist/docx.d.ts",
32
+ "import": "./dist/docx.js",
33
+ "default": "./dist/docx.js"
34
+ }
35
+ },
36
+ "sideEffects": false,
37
+ "files": [
38
+ "dist",
39
+ "README.md",
40
+ "LICENSE"
41
+ ],
42
+ "keywords": [
43
+ "asterdoc",
44
+ "documents",
45
+ "rendering",
46
+ "pdf",
47
+ "docx",
48
+ "markdown"
49
+ ],
50
+ "license": "MIT",
51
+ "author": {
52
+ "name": "Asterdoc",
53
+ "url": "https://asterdoc.com"
54
+ },
55
+ "engines": {
56
+ "node": ">=18"
57
+ },
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "https://github.com/asterdoc/asterdoc.git",
61
+ "directory": "packages/render"
62
+ },
63
+ "homepage": "https://asterdoc.com",
64
+ "bugs": {
65
+ "url": "https://github.com/asterdoc/asterdoc/issues"
66
+ },
67
+ "publishConfig": {
68
+ "access": "public"
69
+ },
70
+ "peerDependencies": {
71
+ "@asterdoc/types": "^0.9.0"
72
+ },
73
+ "dependencies": {
74
+ "fflate": "^0.8.3",
75
+ "@asterdoc/expr": "^0.9.0",
76
+ "@asterdoc/format": "^0.9.0"
77
+ },
78
+ "devDependencies": {
79
+ "@types/node": "^22.15.3",
80
+ "@vitest/coverage-v8": "^2.1.8",
81
+ "esbuild": "^0.27.2",
82
+ "eslint": "^9.34.0",
83
+ "pdfjs-dist": "4.10.38",
84
+ "tsup": "^8.4.0",
85
+ "typescript": "5.9.2",
86
+ "vitest": "^2.1.8",
87
+ "@asterdoc/eslint-config": "0.1.0",
88
+ "@asterdoc/typescript-config": "0.1.0",
89
+ "@asterdoc/types": "^0.9.0"
90
+ },
91
+ "scripts": {
92
+ "build": "tsup",
93
+ "dev": "tsup --watch",
94
+ "clean": "rm -rf dist",
95
+ "prebuild": "pnpm run clean",
96
+ "pack:dry": "pnpm run build && npm pack --dry-run",
97
+ "lint": "eslint .",
98
+ "check-types": "tsc --noEmit",
99
+ "check": "pnpm lint && pnpm check-types",
100
+ "test": "vitest run",
101
+ "test:watch": "vitest",
102
+ "test:coverage": "vitest run --coverage",
103
+ "benchmark": "pnpm --silent run build >/dev/null && node scripts/benchmark.mjs",
104
+ "size-report": "pnpm --silent run build >/dev/null && node scripts/size-report.mjs"
105
+ }
6
106
  }