@formfeed/engine 0.1.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 +21 -0
- package/README.md +54 -0
- package/index.cjs +3306 -0
- package/index.js +3273 -0
- package/package.json +70 -0
- package/types/index.d.cts +17 -0
- package/types/index.d.ts +17 -0
- package/types/lib/analysis/tags.d.cts +36 -0
- package/types/lib/analysis/tags.d.ts +36 -0
- package/types/lib/assemble.d.cts +147 -0
- package/types/lib/assemble.d.ts +147 -0
- package/types/lib/engines/handlebars.d.cts +3 -0
- package/types/lib/engines/handlebars.d.ts +3 -0
- package/types/lib/engines/index.d.cts +7 -0
- package/types/lib/engines/index.d.ts +7 -0
- package/types/lib/engines/jinja2.d.cts +5 -0
- package/types/lib/engines/jinja2.d.ts +5 -0
- package/types/lib/engines/liquid.d.cts +16 -0
- package/types/lib/engines/liquid.d.ts +16 -0
- package/types/lib/errors.d.cts +24 -0
- package/types/lib/errors.d.ts +24 -0
- package/types/lib/helpers/codes.d.cts +21 -0
- package/types/lib/helpers/codes.d.ts +21 -0
- package/types/lib/helpers/collections.d.cts +2 -0
- package/types/lib/helpers/collections.d.ts +2 -0
- package/types/lib/helpers/document.d.cts +29 -0
- package/types/lib/helpers/document.d.ts +29 -0
- package/types/lib/helpers/format.d.cts +5 -0
- package/types/lib/helpers/format.d.ts +5 -0
- package/types/lib/helpers/index.d.cts +17 -0
- package/types/lib/helpers/index.d.ts +17 -0
- package/types/lib/helpers/logic.d.cts +2 -0
- package/types/lib/helpers/logic.d.ts +2 -0
- package/types/lib/helpers/registry.d.cts +18 -0
- package/types/lib/helpers/registry.d.ts +18 -0
- package/types/lib/import/apitemplate.d.cts +45 -0
- package/types/lib/import/apitemplate.d.ts +45 -0
- package/types/lib/limits.d.cts +10 -0
- package/types/lib/limits.d.ts +10 -0
- package/types/lib/preview.d.cts +30 -0
- package/types/lib/preview.d.ts +30 -0
- package/types/lib/schema.d.cts +22 -0
- package/types/lib/schema.d.ts +22 -0
- package/types/lib/snippets.d.cts +22 -0
- package/types/lib/snippets.d.ts +22 -0
- package/types/lib/types.d.cts +140 -0
- package/types/lib/types.d.ts +140 -0
- package/types/types/modules.d.cts +85 -0
- package/types/types/modules.d.ts +85 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared contracts of `@formfeed/engine` (spec 05). Used by the Angular editor (browser) and the
|
|
3
|
+
* Fly.io render-worker (Node); nothing here may touch Node-only APIs.
|
|
4
|
+
*/
|
|
5
|
+
export type EngineId = 'jinja2' | 'liquid' | 'handlebars';
|
|
6
|
+
/** 1-based line and column, end exclusive. */
|
|
7
|
+
export interface Position {
|
|
8
|
+
line: number;
|
|
9
|
+
column: number;
|
|
10
|
+
}
|
|
11
|
+
export interface Range {
|
|
12
|
+
start: Position;
|
|
13
|
+
end: Position;
|
|
14
|
+
}
|
|
15
|
+
export type DiagnosticSeverity = 'error' | 'warning' | 'info';
|
|
16
|
+
export interface Diagnostic {
|
|
17
|
+
severity: DiagnosticSeverity;
|
|
18
|
+
message: string;
|
|
19
|
+
range: Range;
|
|
20
|
+
/** Stable code the editor keys quick-fixes and docs on, e.g. `unknown-filter`. */
|
|
21
|
+
code: string;
|
|
22
|
+
/** Optional quick-fix: replace the range with `replacement`. */
|
|
23
|
+
fix?: {
|
|
24
|
+
title: string;
|
|
25
|
+
replacement: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface VariableRef {
|
|
29
|
+
path: string[];
|
|
30
|
+
range: Range;
|
|
31
|
+
kind: 'read' | 'loop-var' | 'assigned';
|
|
32
|
+
}
|
|
33
|
+
export interface FilterRef {
|
|
34
|
+
name: string;
|
|
35
|
+
range: Range;
|
|
36
|
+
known: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface IncludeRef {
|
|
39
|
+
name: string;
|
|
40
|
+
range: Range;
|
|
41
|
+
}
|
|
42
|
+
export interface BlockRef {
|
|
43
|
+
type: 'for' | 'if' | 'block' | 'raw' | 'macro' | 'other';
|
|
44
|
+
open: Range;
|
|
45
|
+
close?: Range;
|
|
46
|
+
}
|
|
47
|
+
export interface Analysis {
|
|
48
|
+
variables: VariableRef[];
|
|
49
|
+
filters: FilterRef[];
|
|
50
|
+
includes: IncludeRef[];
|
|
51
|
+
blocks: BlockRef[];
|
|
52
|
+
diagnostics: Diagnostic[];
|
|
53
|
+
}
|
|
54
|
+
export interface AnalyzeOptions {
|
|
55
|
+
/** Sample data; when given, variable paths missing from it produce warnings. */
|
|
56
|
+
sampleData?: unknown;
|
|
57
|
+
/** Helper registry that decides which filter names are known. Defaults to the built-in set. */
|
|
58
|
+
helpers?: HelperRegistry;
|
|
59
|
+
}
|
|
60
|
+
/** Resolves a workspace partial by name to its source; `undefined` when it does not exist. */
|
|
61
|
+
export type PartialResolver = (name: string) => string | undefined;
|
|
62
|
+
export interface RenderLimits {
|
|
63
|
+
/** Wall-clock budget of one render in milliseconds. */
|
|
64
|
+
ms: number;
|
|
65
|
+
/** Maximum size of the rendered HTML in bytes. */
|
|
66
|
+
outputBytes: number;
|
|
67
|
+
/** Maximum nesting of includes and extends. */
|
|
68
|
+
includeDepth: number;
|
|
69
|
+
}
|
|
70
|
+
export interface RenderContext {
|
|
71
|
+
locale: string;
|
|
72
|
+
timezone: string;
|
|
73
|
+
currency: string;
|
|
74
|
+
partials: PartialResolver;
|
|
75
|
+
helpers: HelperRegistry;
|
|
76
|
+
limits: RenderLimits;
|
|
77
|
+
/** Template-level dictionaries for `t()`: locale → key → text (USP-8). */
|
|
78
|
+
i18n?: Record<string, Record<string, string>>;
|
|
79
|
+
/** Base URL for `asset()` (workspace asset root on the CDN). */
|
|
80
|
+
assetBaseUrl?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface CompileOptions {
|
|
83
|
+
/** Name used in error messages and as the root include name. */
|
|
84
|
+
name?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface CompiledTemplate {
|
|
87
|
+
engine: EngineId;
|
|
88
|
+
name: string;
|
|
89
|
+
source: string;
|
|
90
|
+
render(data: unknown, ctx: RenderContext): Promise<string>;
|
|
91
|
+
}
|
|
92
|
+
export interface Engine {
|
|
93
|
+
id: EngineId;
|
|
94
|
+
/** Parses and compiles; throws `EngineSyntaxError` with line and column. */
|
|
95
|
+
compile(source: string, opts?: CompileOptions): CompiledTemplate;
|
|
96
|
+
analyze(source: string, opts?: AnalyzeOptions): Analysis;
|
|
97
|
+
render(tpl: CompiledTemplate, data: unknown, ctx: RenderContext): Promise<string>;
|
|
98
|
+
}
|
|
99
|
+
export type HelperCategory = 'format' | 'text' | 'collection' | 'logic' | 'code' | 'document' | 'debug';
|
|
100
|
+
export interface HelperDoc {
|
|
101
|
+
signature: string;
|
|
102
|
+
description: string;
|
|
103
|
+
example: string;
|
|
104
|
+
category: HelperCategory;
|
|
105
|
+
}
|
|
106
|
+
export interface HelperDefinition {
|
|
107
|
+
name: string;
|
|
108
|
+
/** Other names the helper answers to (apitemplate.io compatibility aliases). */
|
|
109
|
+
aliases?: string[];
|
|
110
|
+
/** Result is HTML that must not be escaped by the engine. */
|
|
111
|
+
html?: boolean;
|
|
112
|
+
/** Emits a warning diagnostic pointing to the preferred name (deprecated aliases). */
|
|
113
|
+
deprecatedAlias?: Record<string, string>;
|
|
114
|
+
doc: HelperDoc;
|
|
115
|
+
/** Receives the render context first, then the template arguments. */
|
|
116
|
+
fn: (ctx: HelperContext, ...args: unknown[]) => unknown;
|
|
117
|
+
}
|
|
118
|
+
/** What helpers know about the current render without receiving the whole context. */
|
|
119
|
+
export interface HelperContext {
|
|
120
|
+
locale: string;
|
|
121
|
+
timezone: string;
|
|
122
|
+
currency: string;
|
|
123
|
+
i18n?: Record<string, Record<string, string>>;
|
|
124
|
+
assetBaseUrl?: string;
|
|
125
|
+
}
|
|
126
|
+
export interface HelperRegistry {
|
|
127
|
+
/** Registered helpers keyed by canonical name. */
|
|
128
|
+
readonly definitions: ReadonlyMap<string, HelperDefinition>;
|
|
129
|
+
/** Resolves a name or alias. */
|
|
130
|
+
get(name: string): HelperDefinition | undefined;
|
|
131
|
+
has(name: string): boolean;
|
|
132
|
+
/** Every name the engines know, aliases included. */
|
|
133
|
+
names(): string[];
|
|
134
|
+
/** Concrete functions bound to a render context, keyed by every name and alias. */
|
|
135
|
+
bind(ctx: HelperContext): Map<string, {
|
|
136
|
+
fn: (...args: unknown[]) => unknown;
|
|
137
|
+
html: boolean;
|
|
138
|
+
}>;
|
|
139
|
+
register(definition: HelperDefinition): void;
|
|
140
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/* Ambient typings for deep imports the engine relies on (browser-safe builds). */
|
|
2
|
+
|
|
3
|
+
declare module 'nunjucks/browser/nunjucks.js' {
|
|
4
|
+
import type * as N from 'nunjucks';
|
|
5
|
+
|
|
6
|
+
/** Nunjucks AST node; every node carries a 0-based `lineno`/`colno` and lists its child fields. */
|
|
7
|
+
export interface NunjucksNode {
|
|
8
|
+
typename: string;
|
|
9
|
+
lineno: number;
|
|
10
|
+
colno: number;
|
|
11
|
+
fields: string[];
|
|
12
|
+
children?: NunjucksNode[];
|
|
13
|
+
value?: unknown;
|
|
14
|
+
[field: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface NunjucksCompiler {
|
|
18
|
+
_emit(code: string): void;
|
|
19
|
+
compile(node: unknown, frame: unknown): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface NunjucksModule {
|
|
23
|
+
Environment: typeof N.Environment;
|
|
24
|
+
Template: typeof N.Template;
|
|
25
|
+
Loader: typeof N.Loader;
|
|
26
|
+
runtime: typeof N.runtime & {
|
|
27
|
+
memberLookup: (obj: unknown, val: unknown, ...rest: unknown[]) => unknown;
|
|
28
|
+
};
|
|
29
|
+
/** The code generator; patched for `not` precedence (engines/jinja2.ts). */
|
|
30
|
+
compiler: {
|
|
31
|
+
Compiler: {
|
|
32
|
+
prototype: {
|
|
33
|
+
compileNot(this: NunjucksCompiler, node: { target: unknown }, frame: unknown): void;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
lib: {
|
|
38
|
+
TemplateError: new (
|
|
39
|
+
message: string,
|
|
40
|
+
lineno?: number,
|
|
41
|
+
colno?: number,
|
|
42
|
+
) => Error;
|
|
43
|
+
};
|
|
44
|
+
installJinjaCompat: () => void;
|
|
45
|
+
parser: {
|
|
46
|
+
parse(
|
|
47
|
+
src: string,
|
|
48
|
+
extensions?: unknown[],
|
|
49
|
+
opts?: Record<string, unknown>,
|
|
50
|
+
): NunjucksNode;
|
|
51
|
+
};
|
|
52
|
+
nodes: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const nunjucks: NunjucksModule;
|
|
56
|
+
export default nunjucks;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare module 'qrcode/lib/renderer/svg-tag.js' {
|
|
60
|
+
import type { QRCode } from 'qrcode';
|
|
61
|
+
export function render(
|
|
62
|
+
qrData: QRCode,
|
|
63
|
+
options?: {
|
|
64
|
+
width?: number;
|
|
65
|
+
margin?: number;
|
|
66
|
+
scale?: number;
|
|
67
|
+
color?: { dark?: string; light?: string };
|
|
68
|
+
},
|
|
69
|
+
): string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare module 'bwip-js' {
|
|
73
|
+
/** Symbology rendering options; `bcid` and `text` are required. */
|
|
74
|
+
export interface RenderOptions {
|
|
75
|
+
bcid: string;
|
|
76
|
+
text: string;
|
|
77
|
+
scale?: number;
|
|
78
|
+
height?: number;
|
|
79
|
+
width?: number;
|
|
80
|
+
includetext?: boolean;
|
|
81
|
+
textxalign?: string;
|
|
82
|
+
[option: string]: unknown;
|
|
83
|
+
}
|
|
84
|
+
export function toSVG(options: RenderOptions): string;
|
|
85
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/* Ambient typings for deep imports the engine relies on (browser-safe builds). */
|
|
2
|
+
|
|
3
|
+
declare module 'nunjucks/browser/nunjucks.js' {
|
|
4
|
+
import type * as N from 'nunjucks';
|
|
5
|
+
|
|
6
|
+
/** Nunjucks AST node; every node carries a 0-based `lineno`/`colno` and lists its child fields. */
|
|
7
|
+
export interface NunjucksNode {
|
|
8
|
+
typename: string;
|
|
9
|
+
lineno: number;
|
|
10
|
+
colno: number;
|
|
11
|
+
fields: string[];
|
|
12
|
+
children?: NunjucksNode[];
|
|
13
|
+
value?: unknown;
|
|
14
|
+
[field: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface NunjucksCompiler {
|
|
18
|
+
_emit(code: string): void;
|
|
19
|
+
compile(node: unknown, frame: unknown): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface NunjucksModule {
|
|
23
|
+
Environment: typeof N.Environment;
|
|
24
|
+
Template: typeof N.Template;
|
|
25
|
+
Loader: typeof N.Loader;
|
|
26
|
+
runtime: typeof N.runtime & {
|
|
27
|
+
memberLookup: (obj: unknown, val: unknown, ...rest: unknown[]) => unknown;
|
|
28
|
+
};
|
|
29
|
+
/** The code generator; patched for `not` precedence (engines/jinja2.ts). */
|
|
30
|
+
compiler: {
|
|
31
|
+
Compiler: {
|
|
32
|
+
prototype: {
|
|
33
|
+
compileNot(this: NunjucksCompiler, node: { target: unknown }, frame: unknown): void;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
lib: {
|
|
38
|
+
TemplateError: new (
|
|
39
|
+
message: string,
|
|
40
|
+
lineno?: number,
|
|
41
|
+
colno?: number,
|
|
42
|
+
) => Error;
|
|
43
|
+
};
|
|
44
|
+
installJinjaCompat: () => void;
|
|
45
|
+
parser: {
|
|
46
|
+
parse(
|
|
47
|
+
src: string,
|
|
48
|
+
extensions?: unknown[],
|
|
49
|
+
opts?: Record<string, unknown>,
|
|
50
|
+
): NunjucksNode;
|
|
51
|
+
};
|
|
52
|
+
nodes: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const nunjucks: NunjucksModule;
|
|
56
|
+
export default nunjucks;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare module 'qrcode/lib/renderer/svg-tag.js' {
|
|
60
|
+
import type { QRCode } from 'qrcode';
|
|
61
|
+
export function render(
|
|
62
|
+
qrData: QRCode,
|
|
63
|
+
options?: {
|
|
64
|
+
width?: number;
|
|
65
|
+
margin?: number;
|
|
66
|
+
scale?: number;
|
|
67
|
+
color?: { dark?: string; light?: string };
|
|
68
|
+
},
|
|
69
|
+
): string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare module 'bwip-js' {
|
|
73
|
+
/** Symbology rendering options; `bcid` and `text` are required. */
|
|
74
|
+
export interface RenderOptions {
|
|
75
|
+
bcid: string;
|
|
76
|
+
text: string;
|
|
77
|
+
scale?: number;
|
|
78
|
+
height?: number;
|
|
79
|
+
width?: number;
|
|
80
|
+
includetext?: boolean;
|
|
81
|
+
textxalign?: string;
|
|
82
|
+
[option: string]: unknown;
|
|
83
|
+
}
|
|
84
|
+
export function toSVG(options: RenderOptions): string;
|
|
85
|
+
}
|