manim-web 0.29.0 → 0.30.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.
@@ -14,4 +14,5 @@ export { registerSerializableMobject, unregisterSerializableMobject, getSerializ
14
14
  export type { SerializedScene, SerializedMobject, SerializedTransform, SerializedStyle, MobjectSerializer, SceneLike, ContainerLike, Vec3, } from './types';
15
15
  export { encodeStateToHash, decodeStateFromHash, writeStateToUrl, readStateFromUrl, onUrlStateChange, bindStateToUrl, } from './urlState';
16
16
  export type { WriteStateOptions, BindUrlStateOptions, UrlStateBinding, UrlStateController, } from './urlState';
17
+ export { defineParametrizedScene, resolveProps, renderParametrized, propsFromUrl, type PropsRecord, type PropTypeTag, type PropsSchema, type DataFetcher, type SceneMetadata, type MetadataContext, type CalculateMetadataResult, type CalculateMetadata, type SceneBuilder, type ParametrizedSceneDefinition, type ResolvedMetadata, type ParametrizedRenderResult, type RenderParametrizedOptions, } from './parametrized';
17
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/serialization/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,2BAA2B,EAC3B,6BAA6B,EAC7B,aAAa,EACb,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,SAAS,EACT,aAAa,EACb,IAAI,GACL,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/serialization/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,2BAA2B,EAC3B,6BAA6B,EAC7B,aAAa,EACb,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,SAAS,EACT,aAAa,EACb,IAAI,GACL,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,uBAAuB,EACvB,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,2BAA2B,EAChC,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,GAC/B,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,152 @@
1
+ import { Scene, SceneOptions } from '../core/Scene';
2
+ /** A JSON-safe props bag. Each definition owns the shape of its own props. */
3
+ export type PropsRecord = Record<string, unknown>;
4
+ /** The runtime type tag a prop is validated and coerced against. */
5
+ export type PropTypeTag = 'number' | 'string' | 'boolean' | 'vec3' | 'array' | 'object';
6
+ /**
7
+ * Optional explicit schema: a type tag per prop key. When omitted, the tag of
8
+ * each prop is inferred from the type of its default value.
9
+ */
10
+ export type PropsSchema<P extends object> = Partial<Record<keyof P, PropTypeTag>>;
11
+ /**
12
+ * Fetches render-time data. The default implementation calls the global
13
+ * `fetch` and returns parsed JSON; tests inject a stub so they never touch the
14
+ * network. This is the dependency-injection seam for {@link renderParametrized}.
15
+ */
16
+ export type DataFetcher = (url: string, init?: RequestInit) => Promise<unknown>;
17
+ /** Scene config a {@link CalculateMetadata} hook may override before render. */
18
+ export interface SceneMetadata {
19
+ /** Clip duration in seconds, for downstream export. Carried through as-is. */
20
+ duration?: number;
21
+ /** Render width in pixels. */
22
+ width?: number;
23
+ /** Render height in pixels. */
24
+ height?: number;
25
+ /** Target frame rate in fps. */
26
+ fps?: number;
27
+ }
28
+ /** Context passed to {@link CalculateMetadata}: resolved props and the fetcher. */
29
+ export interface MetadataContext<P extends object> {
30
+ /** The props resolved from defaults + input (input wins). */
31
+ props: P;
32
+ /** The injected data fetcher (see {@link DataFetcher}). */
33
+ fetch: DataFetcher;
34
+ }
35
+ /**
36
+ * What {@link CalculateMetadata} returns: optional scene-config overrides, an
37
+ * optional patch of props (which wins over the input props), and the fetched
38
+ * `data` that reaches {@link SceneBuilder}.
39
+ */
40
+ export interface CalculateMetadataResult<P extends object, D> extends SceneMetadata {
41
+ /** Props to override after the fetch (e.g. values computed from the data). */
42
+ props?: Partial<P>;
43
+ /** Data to pass to the build step. */
44
+ data?: D;
45
+ }
46
+ /** The async pre-render hook. Runs once, before the scene is built. */
47
+ export type CalculateMetadata<P extends object, D> = (context: MetadataContext<P>) => CalculateMetadataResult<P, D> | Promise<CalculateMetadataResult<P, D>>;
48
+ /** Builds the scene from the resolved props and the fetched data. */
49
+ export type SceneBuilder<P extends object, D> = (scene: Scene, props: P, data: D | undefined) => void | Promise<void>;
50
+ /** A parametrized scene definition. See {@link defineParametrizedScene}. */
51
+ export interface ParametrizedSceneDefinition<P extends object, D = unknown> {
52
+ /** Optional stable id for logging or registry use. */
53
+ id?: string;
54
+ /** The default props. Also the source of the inferred prop schema. */
55
+ defaultProps: P;
56
+ /** Optional explicit per-prop type tags; inferred from defaults when absent. */
57
+ schema?: PropsSchema<P>;
58
+ /** Optional async hook that fetches data and overrides scene config. */
59
+ calculateMetadata?: CalculateMetadata<P, D>;
60
+ /** Builds the scene from resolved props + data. */
61
+ build: SceneBuilder<P, D>;
62
+ }
63
+ /** The resolved render metadata reported by {@link renderParametrized}. */
64
+ export interface ResolvedMetadata {
65
+ /** Duration in seconds, as returned by the metadata hook (may be undefined). */
66
+ duration?: number;
67
+ /** The scene's actual render width in pixels. */
68
+ width: number;
69
+ /** The scene's actual render height in pixels. */
70
+ height: number;
71
+ /** The scene's actual target fps. */
72
+ fps: number;
73
+ }
74
+ /** The result of {@link renderParametrized}. */
75
+ export interface ParametrizedRenderResult<P extends object, D> {
76
+ /** The built scene. */
77
+ scene: Scene;
78
+ /** The fully resolved props (defaults + input + metadata patch). */
79
+ props: P;
80
+ /** The data returned by the metadata hook, or undefined. */
81
+ data: D | undefined;
82
+ /** The resolved render metadata. */
83
+ metadata: ResolvedMetadata;
84
+ /** A shareable, URL-safe hash of the resolved props (reuses the URL codec). */
85
+ url: string;
86
+ }
87
+ /** Options for {@link renderParametrized}. */
88
+ export interface RenderParametrizedOptions {
89
+ /** Build into this scene instead of a fresh headless one. */
90
+ scene?: Scene;
91
+ /** Scene options for the created scene when `scene` is not supplied. */
92
+ sceneOptions?: SceneOptions;
93
+ /** Injected data fetcher. Defaults to the global `fetch` + JSON parse. */
94
+ fetch?: DataFetcher;
95
+ /** Write the resolved props to the URL hash (no-op headless). Default false. */
96
+ writeUrl?: boolean;
97
+ /** Use `history.replaceState` when writing the URL. Default true. */
98
+ urlReplace?: boolean;
99
+ }
100
+ /**
101
+ * Define a parametrized scene. This is a typed identity helper: it infers the
102
+ * props and data generics from the definition and returns it unchanged.
103
+ *
104
+ * @param definition - The scene definition (defaults, optional schema, optional
105
+ * metadata hook, build function).
106
+ * @returns The same definition, typed.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * const bar = defineParametrizedScene({
111
+ * defaultProps: { label: 'A', value: 1, color: '#58C4DD' },
112
+ * calculateMetadata: async ({ props, fetch }) => {
113
+ * const data = await fetch(`/api/series/${props.label}`);
114
+ * return { data, duration: 3, width: 1920, height: 1080, fps: 60 };
115
+ * },
116
+ * build: (scene, props, data) => {
117
+ * // ...assemble the scene from props + data
118
+ * },
119
+ * });
120
+ * ```
121
+ */
122
+ export declare function defineParametrizedScene<P extends object, D = unknown>(definition: ParametrizedSceneDefinition<P, D>): ParametrizedSceneDefinition<P, D>;
123
+ /**
124
+ * Resolve the effective props for a definition: a clone of the defaults with
125
+ * the input props merged over them (input wins). Each input value is coerced to
126
+ * the type of its default; an uncoercible or unknown key falls back to the
127
+ * default. Reused by {@link renderParametrized} and {@link propsFromUrl}.
128
+ *
129
+ * @param definition - The parametrized scene definition.
130
+ * @param inputProps - Partial input props (unknown keys are ignored).
131
+ * @returns The fully resolved props.
132
+ */
133
+ export declare function resolveProps<P extends object, D>(definition: ParametrizedSceneDefinition<P, D>, inputProps?: PropsRecord): P;
134
+ /** Read props from the current URL hash and resolve them against the defaults. */
135
+ export declare function propsFromUrl<P extends object, D>(definition: ParametrizedSceneDefinition<P, D>): P;
136
+ /**
137
+ * Render a parametrized scene: merge input props over defaults (input wins),
138
+ * run `calculateMetadata` (which may fetch data and override size/fps/duration),
139
+ * apply the metadata to the scene, build the scene, and expose the resolved
140
+ * props as a shareable URL hash.
141
+ *
142
+ * Headless-safe: with no `scene` and no DOM it builds a headless scene and the
143
+ * URL write is a no-op. The data fetch goes through the injectable
144
+ * {@link DataFetcher} seam, so tests never touch the network.
145
+ *
146
+ * @param definition - The parametrized scene definition.
147
+ * @param inputProps - Partial input props (merged over the defaults).
148
+ * @param options - Scene, fetcher and URL-write options.
149
+ * @returns The built scene, resolved props, data, metadata and shareable URL.
150
+ */
151
+ export declare function renderParametrized<P extends object, D = unknown>(definition: ParametrizedSceneDefinition<P, D>, inputProps?: PropsRecord, options?: RenderParametrizedOptions): Promise<ParametrizedRenderResult<P, D>>;
152
+ //# sourceMappingURL=parametrized.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parametrized.d.ts","sourceRoot":"","sources":["../../src/serialization/parametrized.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAKzD,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD,oEAAoE;AACpE,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAExF;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC;AAElF;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhF,gFAAgF;AAChF,MAAM,WAAW,aAAa;IAC5B,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,mFAAmF;AACnF,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM;IAC/C,6DAA6D;IAC7D,KAAK,EAAE,CAAC,CAAC;IACT,2DAA2D;IAC3D,KAAK,EAAE,WAAW,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM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