@texuli/deck 0.0.0-stage → 0.4.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 +182 -2
- package/dist/authoring/builder.d.ts +351 -0
- package/dist/authoring/builder.js +64 -0
- package/dist/authoring/index.d.ts +6 -0
- package/dist/authoring/index.js +6 -0
- package/dist/authoring/lint.d.ts +36 -0
- package/dist/authoring/lint.js +325 -0
- package/dist/authoring/outlines.d.ts +34 -0
- package/dist/authoring/outlines.js +255 -0
- package/dist/authoring/patch.d.ts +23 -0
- package/dist/authoring/patch.js +166 -0
- package/dist/authoring/select-layouts.d.ts +19 -0
- package/dist/authoring/select-layouts.js +90 -0
- package/dist/engine/auto-slide.d.ts +32 -0
- package/dist/engine/auto-slide.js +67 -0
- package/dist/engine/canvas.d.ts +56 -0
- package/dist/engine/canvas.js +48 -0
- package/dist/engine/controller.d.ts +126 -0
- package/dist/engine/controller.js +248 -0
- package/dist/engine/controls.d.ts +128 -0
- package/dist/engine/controls.js +460 -0
- package/dist/engine/hash.d.ts +42 -0
- package/dist/engine/hash.js +86 -0
- package/dist/engine/index.d.ts +88 -0
- package/dist/engine/index.js +88 -0
- package/dist/engine/messages.d.ts +138 -0
- package/dist/engine/messages.js +140 -0
- package/dist/engine/motion.d.ts +64 -0
- package/dist/engine/motion.js +112 -0
- package/dist/engine/navigation.d.ts +87 -0
- package/dist/engine/navigation.js +156 -0
- package/dist/engine/presenter.d.ts +58 -0
- package/dist/engine/presenter.js +157 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/markdown/attributes.d.ts +24 -0
- package/dist/markdown/attributes.js +94 -0
- package/dist/markdown/attrs-closed.d.ts +52 -0
- package/dist/markdown/attrs-closed.js +520 -0
- package/dist/markdown/blocks.d.ts +112 -0
- package/dist/markdown/blocks.js +766 -0
- package/dist/markdown/frontmatter.d.ts +30 -0
- package/dist/markdown/frontmatter.js +165 -0
- package/dist/markdown/index.d.ts +29 -0
- package/dist/markdown/index.js +29 -0
- package/dist/markdown/issues.d.ts +68 -0
- package/dist/markdown/issues.js +83 -0
- package/dist/markdown/json.d.ts +21 -0
- package/dist/markdown/json.js +236 -0
- package/dist/markdown/limits.d.ts +32 -0
- package/dist/markdown/limits.js +32 -0
- package/dist/markdown/parse.d.ts +31 -0
- package/dist/markdown/parse.js +283 -0
- package/dist/markdown/scan.d.ts +26 -0
- package/dist/markdown/scan.js +138 -0
- package/dist/markdown/slides.d.ts +32 -0
- package/dist/markdown/slides.js +854 -0
- package/dist/markdown/text.d.ts +76 -0
- package/dist/markdown/text.js +447 -0
- package/dist/markdown/twin.d.ts +41 -0
- package/dist/markdown/twin.js +374 -0
- package/dist/markdown/write.d.ts +17 -0
- package/dist/markdown/write.js +688 -0
- package/dist/math/index.d.ts +14 -0
- package/dist/math/index.js +14 -0
- package/dist/math/parse.d.ts +9 -0
- package/dist/math/parse.js +648 -0
- package/dist/math/symbols.d.ts +44 -0
- package/dist/math/symbols.js +333 -0
- package/dist/math/types.d.ts +59 -0
- package/dist/math/types.js +69 -0
- package/dist/model/backgrounds/contrast.d.ts +77 -0
- package/dist/model/backgrounds/contrast.js +186 -0
- package/dist/model/backgrounds/index.d.ts +7 -0
- package/dist/model/backgrounds/index.js +7 -0
- package/dist/model/backgrounds/resolve.d.ts +86 -0
- package/dist/model/backgrounds/resolve.js +215 -0
- package/dist/model/backgrounds/schema.d.ts +178 -0
- package/dist/model/backgrounds/schema.js +203 -0
- package/dist/model/codes.d.ts +73 -0
- package/dist/model/codes.js +67 -0
- package/dist/model/deck.d.ts +392 -0
- package/dist/model/deck.js +338 -0
- package/dist/model/index.d.ts +19 -0
- package/dist/model/index.js +19 -0
- package/dist/model/layouts/catalog.d.ts +433 -0
- package/dist/model/layouts/catalog.js +495 -0
- package/dist/model/layouts/index.d.ts +5 -0
- package/dist/model/layouts/index.js +5 -0
- package/dist/model/layouts/props.d.ts +302 -0
- package/dist/model/layouts/props.js +272 -0
- package/dist/model/loader.d.ts +37 -0
- package/dist/model/loader.js +317 -0
- package/dist/model/migrate.d.ts +34 -0
- package/dist/model/migrate.js +453 -0
- package/dist/model/motion/index.d.ts +6 -0
- package/dist/model/motion/index.js +6 -0
- package/dist/model/motion/transition.d.ts +96 -0
- package/dist/model/motion/transition.js +127 -0
- package/dist/model/parse.d.ts +57 -0
- package/dist/model/parse.js +307 -0
- package/dist/model/plain.d.ts +40 -0
- package/dist/model/plain.js +275 -0
- package/dist/model/shared.d.ts +63 -0
- package/dist/model/shared.js +86 -0
- package/dist/model/steps/index.d.ts +7 -0
- package/dist/model/steps/index.js +7 -0
- package/dist/model/steps/phase.d.ts +34 -0
- package/dist/model/steps/phase.js +50 -0
- package/dist/model/steps/slide-steps.d.ts +129 -0
- package/dist/model/steps/slide-steps.js +256 -0
- package/dist/model/style/index.d.ts +8 -0
- package/dist/model/style/index.js +8 -0
- package/dist/model/style/resolve.d.ts +87 -0
- package/dist/model/style/resolve.js +174 -0
- package/dist/model/style/schema.d.ts +85 -0
- package/dist/model/style/schema.js +53 -0
- package/dist/model/style/theme.d.ts +69 -0
- package/dist/model/style/theme.js +84 -0
- package/dist/schema/builders.d.ts +146 -0
- package/dist/schema/builders.js +285 -0
- package/dist/schema/diagnostics.d.ts +78 -0
- package/dist/schema/diagnostics.js +81 -0
- package/dist/schema/index.d.ts +15 -0
- package/dist/schema/index.js +14 -0
- package/dist/schema/internal.d.ts +40 -0
- package/dist/schema/internal.js +209 -0
- package/dist/schema/json-schema.d.ts +12 -0
- package/dist/schema/json-schema.js +213 -0
- package/dist/schema/types.d.ts +166 -0
- package/dist/schema/types.js +1 -0
- package/dist/schema/validate.d.ts +51 -0
- package/dist/schema/validate.js +765 -0
- package/dist/templates/index.d.ts +2 -0
- package/dist/templates/index.js +2 -0
- package/dist/templates/templates.d.ts +11 -0
- package/dist/templates/templates.js +47 -0
- package/package.json +60 -4
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema nodes are plain frozen data (`kind` plus options). These types give
|
|
3
|
+
* each node its output type through a phantom, type-only property, so
|
|
4
|
+
* `Infer<typeof S>` reads the TypeScript type straight off a schema value.
|
|
5
|
+
*/
|
|
6
|
+
import type { DiagnosticSeverity, PathSegment } from './diagnostics.js';
|
|
7
|
+
/** Type-only brand; it never exists at runtime. */
|
|
8
|
+
declare const OUTPUT: unique symbol;
|
|
9
|
+
export type SchemaKind = 'string' | 'number' | 'boolean' | 'null' | 'literal' | 'enum' | 'array' | 'object' | 'record' | 'union' | 'nullable' | 'optional' | 'lazy' | 'refine' | 'json';
|
|
10
|
+
/** Any schema whose validated output is `T`. */
|
|
11
|
+
export interface Schema<T = unknown> {
|
|
12
|
+
readonly kind: SchemaKind;
|
|
13
|
+
readonly description?: string;
|
|
14
|
+
readonly [OUTPUT]?: T;
|
|
15
|
+
}
|
|
16
|
+
/** The output type of a schema value: `type Deck = Infer<typeof DeckSchema>`. */
|
|
17
|
+
export type Infer<S> = S extends Schema<infer T> ? T : never;
|
|
18
|
+
/**
|
|
19
|
+
* Text safety for strings. `line` refuses C0/C1 controls (tab and newlines
|
|
20
|
+
* included), U+2028/U+2029 and the bidi overrides and isolates
|
|
21
|
+
* (U+202A–U+202E, U+2066–U+2069); `multiline` allows tab, LF and CR.
|
|
22
|
+
*/
|
|
23
|
+
export type TextMode = 'line' | 'multiline';
|
|
24
|
+
export interface StringSchema extends Schema<string> {
|
|
25
|
+
readonly kind: 'string';
|
|
26
|
+
/** Minimum length in Unicode code points (after trimming). */
|
|
27
|
+
readonly min?: number;
|
|
28
|
+
/** Maximum length in Unicode code points (after trimming). */
|
|
29
|
+
readonly max?: number;
|
|
30
|
+
/** An ECMAScript pattern source, compiled with the `u` flag. Anchor it yourself. */
|
|
31
|
+
readonly pattern?: string;
|
|
32
|
+
/** Values refused even when they match (`reserved`), e.g. `free` for catalog layout ids. */
|
|
33
|
+
readonly not?: readonly string[];
|
|
34
|
+
/** Trim on input and return the trimmed value (reported as a normalization). */
|
|
35
|
+
readonly trim?: boolean;
|
|
36
|
+
readonly text?: TextMode;
|
|
37
|
+
}
|
|
38
|
+
export interface NumberSchema extends Schema<number> {
|
|
39
|
+
readonly kind: 'number';
|
|
40
|
+
readonly int: boolean;
|
|
41
|
+
readonly min?: number;
|
|
42
|
+
readonly max?: number;
|
|
43
|
+
/** Refuse ±Infinity (default true). NaN is always refused. */
|
|
44
|
+
readonly finite: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface BooleanSchema extends Schema<boolean> {
|
|
47
|
+
readonly kind: 'boolean';
|
|
48
|
+
}
|
|
49
|
+
export interface NullSchema extends Schema<null> {
|
|
50
|
+
readonly kind: 'null';
|
|
51
|
+
}
|
|
52
|
+
export type LiteralValue = string | number | boolean | null;
|
|
53
|
+
export interface LiteralSchema<V extends LiteralValue = LiteralValue> extends Schema<V> {
|
|
54
|
+
readonly kind: 'literal';
|
|
55
|
+
readonly value: V;
|
|
56
|
+
/** The code a mismatch reports (default `enum`), e.g. `unsupported-version`. */
|
|
57
|
+
readonly code?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface EnumSchema<V extends string = string> extends Schema<V> {
|
|
60
|
+
readonly kind: 'enum';
|
|
61
|
+
readonly values: readonly V[];
|
|
62
|
+
/** The code a mismatch reports (default `enum`). */
|
|
63
|
+
readonly code?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface ArraySchema<I extends Schema = Schema> extends Schema<Infer<I>[]> {
|
|
66
|
+
readonly kind: 'array';
|
|
67
|
+
readonly item: I;
|
|
68
|
+
readonly min?: number;
|
|
69
|
+
/** Items past `max` are reported once (`too-many`) and not validated. */
|
|
70
|
+
readonly max?: number;
|
|
71
|
+
}
|
|
72
|
+
export type Shape = {
|
|
73
|
+
readonly [key: string]: Schema;
|
|
74
|
+
};
|
|
75
|
+
type Simplify<T> = {
|
|
76
|
+
[K in keyof T]: T[K];
|
|
77
|
+
} & {};
|
|
78
|
+
type OptionalKeys<S extends Shape> = {
|
|
79
|
+
[K in keyof S]: S[K] extends OptionalSchema<Schema, false> ? K : never;
|
|
80
|
+
}[keyof S];
|
|
81
|
+
/** Object output: optional fields without a default become optional keys. */
|
|
82
|
+
export type InferShape<S extends Shape> = Simplify<{
|
|
83
|
+
-readonly [K in Exclude<keyof S, OptionalKeys<S>>]: Infer<S[K]>;
|
|
84
|
+
} & {
|
|
85
|
+
-readonly [K in OptionalKeys<S>]?: Exclude<Infer<S[K]>, undefined>;
|
|
86
|
+
}>;
|
|
87
|
+
export interface ObjectSchema<S extends Shape = Shape> extends Schema<InferShape<S>> {
|
|
88
|
+
readonly kind: 'object';
|
|
89
|
+
readonly shape: S;
|
|
90
|
+
/** `true` (default): unknown keys are `unknown-key` issues; `false`: dropped. */
|
|
91
|
+
readonly strict: boolean;
|
|
92
|
+
}
|
|
93
|
+
export interface RecordSchema<V extends Schema = Schema> extends Schema<Record<string, Infer<V>>> {
|
|
94
|
+
readonly kind: 'record';
|
|
95
|
+
/** Validates each key (pattern, length); keys are never transformed. */
|
|
96
|
+
readonly key?: StringSchema;
|
|
97
|
+
readonly value: V;
|
|
98
|
+
readonly min?: number;
|
|
99
|
+
/** Entries past `max` are reported once (`too-many`) and not validated. */
|
|
100
|
+
readonly max?: number;
|
|
101
|
+
}
|
|
102
|
+
export interface UnionSchema<O extends readonly Schema[] = readonly Schema[]> extends Schema<Infer<O[number]>> {
|
|
103
|
+
readonly kind: 'union';
|
|
104
|
+
readonly options: O;
|
|
105
|
+
/** Every option is an object whose field of this name is a literal, an enum or a string. */
|
|
106
|
+
readonly discriminator?: string;
|
|
107
|
+
/** The code an unknown discriminator reports (default `unknown-kind`). */
|
|
108
|
+
readonly code?: string;
|
|
109
|
+
}
|
|
110
|
+
export interface NullableSchema<I extends Schema = Schema> extends Schema<Infer<I> | null> {
|
|
111
|
+
readonly kind: 'nullable';
|
|
112
|
+
readonly inner: I;
|
|
113
|
+
}
|
|
114
|
+
export interface OptionalSchema<I extends Schema = Schema, D extends boolean = boolean> extends Schema<D extends true ? Infer<I> : Infer<I> | undefined> {
|
|
115
|
+
readonly kind: 'optional';
|
|
116
|
+
readonly inner: I;
|
|
117
|
+
readonly hasDefault: D;
|
|
118
|
+
/** Applied (as a fresh copy) when the key is missing or `undefined`. */
|
|
119
|
+
readonly default?: Infer<I>;
|
|
120
|
+
}
|
|
121
|
+
export interface LazySchema<T = unknown> extends Schema<T> {
|
|
122
|
+
readonly kind: 'lazy';
|
|
123
|
+
get(): Schema<T>;
|
|
124
|
+
/** The `$defs` name in the JSON Schema export. */
|
|
125
|
+
readonly name?: string;
|
|
126
|
+
/** How many times this lazy schema may nest along one path (default: the validate depth). */
|
|
127
|
+
readonly maxDepth?: number;
|
|
128
|
+
}
|
|
129
|
+
export interface RefineIssue {
|
|
130
|
+
code?: string;
|
|
131
|
+
message: string;
|
|
132
|
+
/** Relative to the refined value. */
|
|
133
|
+
path?: readonly PathSegment[];
|
|
134
|
+
fix?: string;
|
|
135
|
+
severity?: DiagnosticSeverity;
|
|
136
|
+
}
|
|
137
|
+
export interface RefineContext {
|
|
138
|
+
/** The refined value's absolute path. */
|
|
139
|
+
readonly path: readonly PathSegment[];
|
|
140
|
+
issue(issue: RefineIssue): void;
|
|
141
|
+
}
|
|
142
|
+
export interface RefineSchema<I extends Schema = Schema> extends Schema<Infer<I>> {
|
|
143
|
+
readonly kind: 'refine';
|
|
144
|
+
readonly inner: I;
|
|
145
|
+
/** The default code of the issues this check raises. */
|
|
146
|
+
readonly code: string;
|
|
147
|
+
/** Runs only when the inner schema produced no error. */
|
|
148
|
+
check(value: Infer<I>, context: RefineContext): void;
|
|
149
|
+
}
|
|
150
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
151
|
+
[key: string]: JsonValue;
|
|
152
|
+
};
|
|
153
|
+
export interface JsonValueSchema extends Schema<JsonValue> {
|
|
154
|
+
readonly kind: 'json';
|
|
155
|
+
/** Nested containers allowed: `1` is `{a: 1}`, `2` is `{a: {b: 1}}`. */
|
|
156
|
+
readonly depth: number;
|
|
157
|
+
readonly maxKeys: number;
|
|
158
|
+
readonly maxItems: number;
|
|
159
|
+
/** Code points per string value. */
|
|
160
|
+
readonly maxString: number;
|
|
161
|
+
readonly maxKeyLength: number;
|
|
162
|
+
readonly text?: TextMode;
|
|
163
|
+
}
|
|
164
|
+
/** The closed set of node shapes the interpreters understand. */
|
|
165
|
+
export type SchemaNode = StringSchema | NumberSchema | BooleanSchema | NullSchema | LiteralSchema | EnumSchema | ArraySchema | ObjectSchema | RecordSchema | UnionSchema | NullableSchema | OptionalSchema | LazySchema | RefineSchema | JsonValueSchema;
|
|
166
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The validator: one walk over the input, driven by the schema data, that
|
|
3
|
+
* collects every issue (up to the cap) and builds a fresh plain-data copy.
|
|
4
|
+
*
|
|
5
|
+
* It never throws and does bounded work on hostile input: own data
|
|
6
|
+
* properties only (getters, throwing proxies and class instances are
|
|
7
|
+
* refused), prototype keys refused, cycles detected, nesting capped by
|
|
8
|
+
* `maxDepth`, every visited value counted against `maxNodes`, arrays and
|
|
9
|
+
* records validated only up to their `max`, and the walk stops once the issue
|
|
10
|
+
* cap is reached (`truncated`). Recursion depth is bounded by the schema tree
|
|
11
|
+
* plus `maxDepth`; `t.json` values are walked iteratively.
|
|
12
|
+
*/
|
|
13
|
+
import { type DeckDiagnostic, type PathSegment } from './diagnostics.js';
|
|
14
|
+
import type { Infer, Schema } from './types.js';
|
|
15
|
+
export interface ValidateOptions {
|
|
16
|
+
/** Diagnostics kept before the walk stops with `truncated: true` (default 200). */
|
|
17
|
+
maxIssues?: number;
|
|
18
|
+
/** Nested arrays, objects, records and lazy entries along one path (default 64). */
|
|
19
|
+
maxDepth?: number;
|
|
20
|
+
/** Values visited before the walk stops with `too-large` (default 1,000,000). */
|
|
21
|
+
maxNodes?: number;
|
|
22
|
+
/** A prefix for every reported path, e.g. `['slides', 3, 'props']`. */
|
|
23
|
+
path?: readonly PathSegment[];
|
|
24
|
+
}
|
|
25
|
+
/** A change the validator made to the input on the way to `value`. */
|
|
26
|
+
export interface SchemaNormalization {
|
|
27
|
+
kind: 'trim' | 'default';
|
|
28
|
+
path: PathSegment[];
|
|
29
|
+
jsonPath: string;
|
|
30
|
+
pointer: string;
|
|
31
|
+
}
|
|
32
|
+
export type ValidateResult<T> = {
|
|
33
|
+
ok: true;
|
|
34
|
+
value: T;
|
|
35
|
+
/** Warnings only (refinements may raise them). */
|
|
36
|
+
issues: DeckDiagnostic[];
|
|
37
|
+
normalized: SchemaNormalization[];
|
|
38
|
+
truncated: boolean;
|
|
39
|
+
} | {
|
|
40
|
+
ok: false;
|
|
41
|
+
value?: undefined;
|
|
42
|
+
issues: DeckDiagnostic[];
|
|
43
|
+
normalized: SchemaNormalization[];
|
|
44
|
+
truncated: boolean;
|
|
45
|
+
};
|
|
46
|
+
export declare const DEFAULT_MAX_DEPTH = 64;
|
|
47
|
+
export declare const DEFAULT_MAX_NODES = 1000000;
|
|
48
|
+
/** Validate `input` against `schema`: every issue, a fresh value, never a throw. */
|
|
49
|
+
export declare function validate<S extends Schema>(schema: S, input: unknown, options?: ValidateOptions): ValidateResult<Infer<S>>;
|
|
50
|
+
/** True when `input` validates without errors (a type guard). */
|
|
51
|
+
export declare function is<S extends Schema>(schema: S, input: unknown): input is Infer<S>;
|