Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

feat(spatial): add frame-exact region timelines

kashorinf5c82f36a92c
diff --git a/packages/spatial/README.md b/packages/spatial/README.md
index bdd008f0..f65cd252 100644
--- a/packages/spatial/README.md
+++ b/packages/spatial/README.md
@@ -1,8 +1,29 @@
# `@hypit/spatial`
-Shared video-domain geometry: explicit Canvas coordinates, Points, Frames, Paths, intrinsic extents
-and deterministic two-frame content fitting. It owns no timing, Paint, motion, media decoding,
+Shared video-domain geometry: explicit Canvas coordinates, Points, Frames, Paths, externally measured
+Region Timelines, intrinsic extents and deterministic two-frame content fitting. It owns no semantic
+timing, Paint, motion, media decoding,
renderer, Provider or Core behavior.
-The package exposes self-described `Canvas`, `Point`, `Path`, `Extent`, `Frame`, `AnchoredFrame` and
-`AspectFrame` author Surfaces plus pure geometry functions and fixed-port Producers.
+The package exposes self-described `Canvas`, `Point`, `Path`, `Extent`, `RegionTimeline`, `Frame`,
+`AnchoredFrame` and `AspectFrame` author Surfaces plus pure geometry functions and fixed-port Producers.
+
+`RegionTimeline` accepts already measured data rather than running a detector. One SVS Recipe holds
+the exact ProgramSpace frame count and named tracks whose array positions are Frames:
+
+```svs
+heads.default {
+ frame-count: 3;
+ tracks: [
+ {"id":"WIFE","regions":[[0.12,0.09,0.20,0.26],null,[0.13,0.10,0.20,0.26]]}
+ ];
+}
+```
+
+```svml
+<space:RegionTimeline id="heads" within={vertical} recipe={tracking.heads.default}/>
+```
+
+Every measured region is normalized `[x, y, width, height]`; `null` says that this track has no
+measured region on that Frame. The Surface converts measured regions to the selected Canvas's pixels
+at author time; it never fills missing Frames or interprets a track id.
diff --git a/packages/spatial/package.json b/packages/spatial/package.json
index 134147e2..91713327 100644
--- a/packages/spatial/package.json
+++ b/packages/spatial/package.json
@@ -14,7 +14,8 @@
"@hypit/component-kit": "workspace:*",
"@hypit/elaborator": "workspace:*",
"@hypit/protocol": "workspace:*",
- "@hypit/markup": "workspace:*"
+ "@hypit/markup": "workspace:*",
+ "@hypit/svs": "workspace:*"
},
"devDependencies": {
"@hypit/core": "workspace:*",
diff --git a/packages/spatial/src/activation.ts b/packages/spatial/src/activation.ts
index 1b89405a..24f107dd 100644
--- a/packages/spatial/src/activation.ts
+++ b/packages/spatial/src/activation.ts
@@ -8,6 +8,7 @@ import {
decodeFrameSurface,
decodePathSurface,
decodePointSurface,
+ decodeRegionTimelineSurface,
} from "./surface.js";
import {
spatialManifest,
@@ -30,6 +31,8 @@ export const hypitPackage = {
createMarkupSurfaceHostFacet({ module: spatialModuleRef,
declaration: spatialMarkupSurfaces.find((item) => item.name === "extent")!, handler: decodeExtentSurface }),
createMarkupSurfaceHostFacet({ module: spatialModuleRef,
+ declaration: spatialMarkupSurfaces.find((item) => item.name === "region-timeline")!, handler: decodeRegionTimelineSurface }),
+ createMarkupSurfaceHostFacet({ module: spatialModuleRef,
declaration: spatialMarkupSurfaces.find((item) => item.name === "frame")!, handler: decodeFrameSurface }),
createMarkupSurfaceHostFacet({ module: spatialModuleRef,
declaration: spatialMarkupSurfaces.find((item) => item.name === "anchored-frame")!, handler: decodeAnchoredFrameSurface }),
diff --git a/packages/spatial/src/component.ts b/packages/spatial/src/component.ts
index d5e11847..68353c5e 100644
--- a/packages/spatial/src/component.ts
+++ b/packages/spatial/src/component.ts
@@ -2,7 +2,7 @@ import type { ComponentPackage } from "@hypit/component-kit";
import { canonicalize } from "@hypit/protocol";
import type { StoredValue } from "@hypit/protocol";
-import { anchoredFrame, aspectFrame, assertCanvasSpace, assertContentFit, assertFittedContent, assertIntrinsicExtent, assertSpatialFrame, assertSpatialPath, assertSpatialPoint, canvasFrame, fitContent, frameFromEdges } from "./geometry.js";
+import { anchoredFrame, aspectFrame, assertCanvasSpace, assertContentFit, assertFittedContent, assertIntrinsicExtent, assertSpatialFrame, assertSpatialPath, assertSpatialPoint, assertSpatialRegionTimeline, canvasFrame, fitContent, frameFromEdges } from "./geometry.js";
import { spatialProducers, spatialTypes } from "./manifest.js";
import type {
AnchoredFrameProgram,
@@ -15,6 +15,7 @@ import type {
SpatialFrame,
SpatialPath,
SpatialPoint,
+ SpatialRegionTimeline,
} from "./types.js";
function inline<T>(value: StoredValue | undefined, label: string): T {
@@ -35,6 +36,7 @@ export const spatialComponent = {
{ type: spatialTypes.canvas, handler: ({ value }) => assertCanvasSpace(inline<CanvasSpace>(value, "CanvasSpace")) },
{ type: spatialTypes.point, handler: ({ value }) => assertSpatialPoint(inline<SpatialPoint>(value, "SpatialPoint")) },
{ type: spatialTypes.frame, handler: ({ value }) => assertSpatialFrame(inline<SpatialFrame>(value, "SpatialFrame")) },
+ { type: spatialTypes.regionTimeline, handler: ({ value }) => assertSpatialRegionTimeline(inline<SpatialRegionTimeline>(value, "SpatialRegionTimeline")) },
{ type: spatialTypes.path, handler: ({ value }) => assertSpatialPath(inline<SpatialPath>(value, "SpatialPath")) },
{ type: spatialTypes.extent, handler: ({ value }) => assertIntrinsicExtent(inline<IntrinsicExtent>(value, "IntrinsicExtent")) },
{ type: spatialTypes.fit, handler: ({ value }) => assertContentFit(inline<ContentFit>(value, "ContentFit")) },
diff --git a/packages/spatial/src/geometry.ts b/packages/spatial/src/geometry.ts
index a9267b21..d0b4d0d2 100644
--- a/packages/spatial/src/geometry.ts
+++ b/packages/spatial/src/geometry.ts
@@ -12,6 +12,7 @@ import type {
SpatialLength,
SpatialPath,
SpatialPoint,
+ SpatialRegionTimeline,
} from "./types.js";
function finite(value: number, label: string): void {
@@ -44,6 +45,24 @@ export function assertSpatialFrame(value: SpatialFrame): void {
positive(value.heightPx, "SpatialFrame.heightPx");
}
+export function assertSpatialRegionTimeline(value: SpatialRegionTimeline): void {
+ assertCanvasSpace(value.canvas);
+ if (!Number.isSafeInteger(value.frameCount) || value.frameCount <= 0 || value.tracks.length === 0) {
+ throw new Error("SpatialRegionTimeline is empty or has an invalid Frame count.");
+ }
+ const ids = new Set<string>();
+ for (const track of value.tracks) {
+ if (!track.id.trim() || ids.has(track.id)) throw new Error(`SpatialRegionTimeline repeats or omits Track id ${track.id}.`);
+ ids.add(track.id);
+ if (track.frames.length !== value.frameCount) {
+ throw new Error(`SpatialRegionTimeline Track ${track.id} does not cover every Frame.`);
+ }
+ for (const frame of track.frames) {
+ if (frame !== null) assertSpatialFrame(frame);
+ }
+ }
+}
+
export function assertIntrinsicExtent(value: IntrinsicExtent): void {
positive(value.widthPx, "IntrinsicExtent.widthPx");
positive(value.heightPx, "IntrinsicExtent.heightPx");
@@ -212,6 +231,7 @@ export function fitContent(frame: SpatialFrame, extent: IntrinsicExtent, fit: Co
export function sealCanvasSpace(value: CanvasSpace): CanvasSpace { assertCanvasSpace(value); return structuredClone(value); }
export function sealSpatialPoint(value: SpatialPoint): SpatialPoint { assertSpatialPoint(value); return structuredClone(value); }
export function sealSpatialFrame(value: SpatialFrame): SpatialFrame { assertSpatialFrame(value); return structuredClone(value); }
+export function sealSpatialRegionTimeline(value: SpatialRegionTimeline): SpatialRegionTimeline { assertSpatialRegionTimeline(value); return structuredClone(value); }
export function sealSpatialPath(value: SpatialPath): SpatialPath { assertSpatialPath(value); return structuredClone(value); }
export function sealIntrinsicExtent(value: IntrinsicExtent): IntrinsicExtent { assertIntrinsicExtent(value); return structuredClone(value); }
export function sealContentFit(value: ContentFit): ContentFit { assertContentFit(value); return structuredClone(value); }
diff --git a/packages/spatial/src/index.ts b/packages/spatial/src/index.ts
index a9cb3fc4..e3f1751e 100644
--- a/packages/spatial/src/index.ts
+++ b/packages/spatial/src/index.ts
@@ -19,6 +19,7 @@ export {
contentFitSchema,
intrinsicExtentSchema,
spatialFrameSchema,
+ spatialRegionTimelineSchema,
spatialPathSchema,
spatialPointSchema,
} from "./schema.js";
@@ -30,5 +31,7 @@ export {
decodeFrameSurface,
decodePathSurface,
decodePointSurface,
+ decodeRegionTimelineSurface,
} from "./surface.js";
+export { spatialRegionTimeline } from "./region-timeline.js";
export type * from "./types.js";
diff --git a/packages/spatial/src/manifest.ts b/packages/spatial/src/manifest.ts
index e84a9bcb..3e9ad74c 100644
--- a/packages/spatial/src/manifest.ts
+++ b/packages/spatial/src/manifest.ts
@@ -1,4 +1,5 @@
import type { ModuleManifest, ProducerRef, TypeRef } from "@hypit/protocol";
+import { svsRecipeType } from "@hypit/svs";
import {
anchoredFrameProgramSchema,
aspectFrameProgramSchema,
@@ -10,6 +11,7 @@ import {
spatialFrameSchema,
spatialPathSchema,
spatialPointSchema,
+ spatialRegionTimelineSchema,
} from "./schema.js";
export const spatialModuleRef = { name: "@hypit/spatial", version: "1" } as const;
@@ -17,6 +19,7 @@ export const spatialTypes = {
canvas: { module: spatialModuleRef, name: "CanvasSpace" },
point: { module: spatialModuleRef, name: "SpatialPoint" },
frame: { module: spatialModuleRef, name: "SpatialFrame" },
+ regionTimeline: { module: spatialModuleRef, name: "SpatialRegionTimeline" },
path: { module: spatialModuleRef, name: "SpatialPath" },
extent: { module: spatialModuleRef, name: "IntrinsicExtent" },
fit: { module: spatialModuleRef, name: "ContentFit" },
@@ -169,6 +172,33 @@ export const spatialMarkupSurfaces = [
],
},
},
+ {
+ name: "region-timeline", tag: "RegionTimeline", mode: "structured", outputs: [spatialTypes.regionTimeline],
+ vocabulary: {
+ summary: "Resolves externally measured, normalized AABB sequences into one frame-exact set of named Canvas-space region tracks.",
+ attributes: [
+ { name: "id", kind: "identifier", required: true,
+ summary: "Names the SpatialRegionTimeline Record this element publishes." },
+ { name: "within", kind: "reference", required: true, accepts: [spatialTypes.canvas],
+ summary: "Chooses the Canvas that normalized regions are measured inside." },
+ { name: "recipe", kind: "reference", required: true, accepts: [svsRecipeType],
+ summary: "Chooses the external frame-indexed region data.",
+ recipe: [
+ { name: "frame-count", required: true,
+ summary: "States the exact number of ProgramSpace Frames covered by every named track." },
+ { name: "tracks", required: true,
+ summary: "Lists objects shaped as {id, regions}; each regions array contains frame-count normalized [x, y, width, height] AABBs or null when the region is absent." },
+ ] },
+ ],
+ example: `<space:RegionTimeline id="heads" within={vertical} recipe={tracking.heads.default}/>` ,
+ notes: [
+ emptyNote,
+ "The array index is the ProgramSpace Frame; the Surface performs no timestamp conversion, interpolation, smoothing or identity inference.",
+ "Each normalized AABB lies inside [0, 1] and is resolved into Canvas pixels during author compilation; null remains explicit absence.",
+ "Track ids are ordinary external labels; a consumer may interpret them as Script Roles without Spatial knowing what a Role is.",
+ ],
+ },
+ },
{
name: "frame", tag: "Frame", mode: "structured", outputs: [spatialTypes.frame, spatialTypes.frameEdgesProgram],
vocabulary: {
@@ -284,11 +314,12 @@ export const spatialManifest: ModuleManifest = {
format: "hypit.module@1",
name: spatialModuleRef.name,
version: spatialModuleRef.version,
- dependencies: [],
+ dependencies: [{ module: svsRecipeType.module }],
types: [
{ name: spatialTypes.canvas.name },
{ name: spatialTypes.point.name },
{ name: spatialTypes.frame.name },
+ { name: spatialTypes.regionTimeline.name },
{ name: spatialTypes.path.name },
{ name: spatialTypes.extent.name },
{ name: spatialTypes.fit.name },
diff --git a/packages/spatial/src/region-timeline.ts b/packages/spatial/src/region-timeline.ts
new file mode 100644
index 00000000..bfe5abdd
--- /dev/null
+++ b/packages/spatial/src/region-timeline.ts
@@ -0,0 +1,69 @@
+import type { CanonicalValue } from "@hypit/protocol";
+import type { SvsRecipe } from "@hypit/svs";
+
+import { assertCanvasSpace, sealSpatialRegionTimeline } from "./geometry.js";
+import type { CanvasSpace, SpatialFrame, SpatialRegionTimeline } from "./types.js";
+
+type CanonicalRecord = Readonly<Record<string, CanonicalValue>>;
+
+function record(value: CanonicalValue, label: string): CanonicalRecord {
+ if (value === null || Array.isArray(value) || typeof value !== "object") throw new Error(`${label} must be a record.`);
+ return value as CanonicalRecord;
+}
+
+function exact(value: CanonicalRecord, allowed: readonly string[], label: string): void {
+ const unknown = Object.keys(value).find((name) => !allowed.includes(name));
+ if (unknown !== undefined) throw new Error(`${label} does not accept ${unknown}.`);
+}
+
+function positiveInteger(value: CanonicalValue | undefined, label: string): number {
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
+ throw new Error(`${label} must be a positive integer.`);
+ }
+ return value;
+}
+
+function normalizedRegion(value: CanonicalValue, canvas: CanvasSpace, label: string): SpatialFrame | null {
+ if (value === null) return null;
+ if (!Array.isArray(value) || value.length !== 4 || value.some((part) => typeof part !== "number" || !Number.isFinite(part))) {
+ throw new Error(`${label} must be null or [x, y, width, height].`);
+ }
+ const [x, y, width, height] = value as unknown as readonly [number, number, number, number];
+ if (x < 0 || y < 0 || width <= 0 || height <= 0 || x + width > 1 || y + height > 1) {
+ throw new Error(`${label} must be a positive normalized region inside the Canvas.`);
+ }
+ return {
+ xPx: x * canvas.widthPx,
+ yPx: y * canvas.heightPx,
+ widthPx: width * canvas.widthPx,
+ heightPx: height * canvas.heightPx,
+ };
+}
+
+/** Resolve normalized author data into frame-exact Canvas-pixel evidence. */
+export function spatialRegionTimeline(recipe: SvsRecipe, canvas: CanvasSpace): SpatialRegionTimeline {
+ assertCanvasSpace(canvas);
+ exact(recipe.properties, ["frame-count", "tracks"], `Spatial Region Timeline ${recipe.path}`);
+ const frameCount = positiveInteger(recipe.properties["frame-count"], `${recipe.path}.frame-count`);
+ const tracksValue = recipe.properties.tracks;
+ if (!Array.isArray(tracksValue) || tracksValue.length === 0) throw new Error(`${recipe.path}.tracks must be a non-empty list.`);
+ const tracks = tracksValue.map((value, trackIndex) => {
+ const item = record(value, `${recipe.path}.tracks.${trackIndex + 1}`);
+ exact(item, ["id", "regions"], `${recipe.path}.tracks.${trackIndex + 1}`);
+ const id = item.id;
+ if (typeof id !== "string" || !id.trim()) throw new Error(`${recipe.path}.tracks.${trackIndex + 1}.id must be non-empty text.`);
+ const regions = item.regions;
+ if (!Array.isArray(regions) || regions.length !== frameCount) {
+ throw new Error(`${recipe.path}.tracks.${trackIndex + 1}.regions must contain exactly ${frameCount} Frames.`);
+ }
+ return {
+ id,
+ frames: regions.map((region, frame) => normalizedRegion(
+ region,
+ canvas,
+ `${recipe.path}.${id}.regions.${frame}`,
+ )),
+ };
+ });
+ return sealSpatialRegionTimeline({ canvas, frameCount, tracks });
+}
diff --git a/packages/spatial/src/schema.ts b/packages/spatial/src/schema.ts
index 8f2c05ae..b272461d 100644
--- a/packages/spatial/src/schema.ts
+++ b/packages/spatial/src/schema.ts
@@ -16,6 +16,16 @@ export const canvasSpaceSchema = object({
});
export const spatialPointSchema = object({ xPx: { schema: number }, yPx: { schema: number } });
export const spatialFrameSchema = object({ xPx: { schema: number }, yPx: { schema: number }, widthPx: { schema: number }, heightPx: { schema: number } });
+export const spatialRegionTimelineSchema = object({
+ canvas: { schema: canvasSpaceSchema },
+ frameCount: { schema: positiveInteger },
+ tracks: { schema: { kind: "array", minItems: 1, items: object({
+ id: { schema: { kind: "string", minLength: 1 } },
+ frames: { schema: { kind: "array", minItems: 1, items: {
+ kind: "oneOf", variants: [spatialFrameSchema, { kind: "null" }],
+ } } },
+ }) } },
+});
const pathCommand: ValueSchema = { kind: "oneOf", variants: [
object({ kind: { schema: { kind: "literal", value: "move" } }, xPx: { schema: number }, yPx: { schema: number } }),
object({ kind: { schema: { kind: "literal", value: "line" } }, xPx: { schema: number }, yPx: { schema: number } }),
diff --git a/packages/spatial/src/surface.ts b/packages/spatial/src/surface.ts
index b87af889..ecef1540 100644
--- a/packages/spatial/src/surface.ts
+++ b/packages/spatial/src/surface.ts
@@ -1,5 +1,7 @@
import type { AuthorValueRef, GraphFragment } from "@hypit/elaborator";
import type { CanonicalValue } from "@hypit/protocol";
+import { svsRecipeType } from "@hypit/svs";
+import type { SvsRecipe } from "@hypit/svs";
import type {
SurfaceComponentDraft,
StructuredElement,
@@ -15,6 +17,7 @@ import {
frameEdgesFragment,
} from "./fragment.js";
import { spatialTypes } from "./manifest.js";
+import { spatialRegionTimeline } from "./region-timeline.js";
import { assertSpatialPath, sealCanvasSpace, sealIntrinsicExtent, sealSpatialPoint } from "./geometry.js";
import type {
AnchoredFrameProgram,
@@ -24,6 +27,7 @@ import type {
SpatialLength,
SpatialPath,
SpatialPathCommand,
+ CanvasSpace,
} from "./types.js";
function sameType(left: SurfaceResolvedReference["type"], right: SurfaceResolvedReference["type"]): boolean {
@@ -88,6 +92,11 @@ function reference(
return result;
}
+function inline<T>(value: SurfaceResolvedReference, label: string): T {
+ if (value.record?.value.kind !== "inline") throw new Error(`${label} must reference an authored inline Record.`);
+ return value.record.value.value as unknown as T;
+}
+
type ParentFrame = {
readonly ref: AuthorValueRef;
readonly components: readonly SurfaceComponentDraft[];
@@ -207,6 +216,23 @@ export const decodeExtentSurface: StructuredSurfaceHandler = ({ element }) => {
return { records: [{ id, type: spatialTypes.extent, value: { kind: "inline", value: extent as unknown as CanonicalValue }, range: element.range }], components: [], fragments: [] };
};
+export const decodeRegionTimelineSurface: StructuredSurfaceHandler = ({ element, resolveReference }) => {
+ exact(element, ["id", "within", "recipe"], ["id", "within", "recipe"]);
+ const id = text(element, "id");
+ const canvasReference = reference(element, "within", resolveReference);
+ if (!sameType(canvasReference.type, spatialTypes.canvas)) throw new Error(`${element.name}.within must reference CanvasSpace.`);
+ const recipeReference = reference(element, "recipe", resolveReference);
+ if (!sameType(recipeReference.type, svsRecipeType)) throw new Error(`${element.name}.recipe must reference an SVS Recipe.`);
+ const timeline = spatialRegionTimeline(
+ inline<SvsRecipe>(recipeReference, `${element.name}.recipe`),
+ inline<CanvasSpace>(canvasReference, `${element.name}.within`),
+ );
+ return {
+ records: [{ id, type: spatialTypes.regionTimeline, value: { kind: "inline", value: timeline as unknown as CanonicalValue }, range: element.range }],
+ components: [], fragments: [],
+ };
+};
+
function frameSurface(
element: StructuredElement,
resolveReference: (path: string) => SurfaceResolvedReference | undefined,
diff --git a/packages/spatial/src/types.ts b/packages/spatial/src/types.ts
index 6a56b7d2..9bf7797d 100644
--- a/packages/spatial/src/types.ts
+++ b/packages/spatial/src/types.ts
@@ -19,6 +19,19 @@ export type SpatialFrame = {
readonly heightPx: number;
};
+/** One named, frame-exact sequence of measured regions in one Canvas. */
+export type SpatialRegionTrack = {
+ readonly id: string;
+ readonly frames: readonly (SpatialFrame | null)[];
+};
+
+/** External spatial evidence indexed directly by ProgramSpace Frame. */
+export type SpatialRegionTimeline = {
+ readonly canvas: CanvasSpace;
+ readonly frameCount: number;
+ readonly tracks: readonly SpatialRegionTrack[];
+};
+
export type SpatialPathCommand =
| { readonly kind: "move"; readonly xPx: number; readonly yPx: number }
| { readonly kind: "line"; readonly xPx: number; readonly yPx: number }
diff --git a/packages/spatial/test/spatial.test.ts b/packages/spatial/test/spatial.test.ts
index ee3661f3..82a8f122 100644
--- a/packages/spatial/test/spatial.test.ts
+++ b/packages/spatial/test/spatial.test.ts
@@ -10,6 +10,7 @@ import {
createMarkupAuthorFrontend,
} from "@hypit/markup";
import { createRecordAdmitter, TypeValidatorRegistry } from "@hypit/validation";
+import { svsFrontend, svsManifest } from "@hypit/svs";
import {
anchoredFrame,
@@ -20,6 +21,7 @@ import {
decodeFrameSurface,
decodePathSurface,
decodePointSurface,
+ decodeRegionTimelineSurface,
fitContent,
frameFromEdges,
sealSpatialPath,
@@ -30,7 +32,7 @@ import {
spatialProducers,
spatialTypes,
} from "../src/index.js";
-import type { ContentFit, IntrinsicExtent, SpatialAnchor, SpatialFrame } from "../src/index.js";
+import type { ContentFit, IntrinsicExtent, SpatialAnchor, SpatialFrame, SpatialRegionTimeline } from "../src/index.js";
const parent: SpatialFrame = { xPx: 100, yPx: 200, widthPx: 800, heightPx: 1200 };
const portrait: IntrinsicExtent = { widthPx: 600, heightPx: 1000 };
@@ -193,8 +195,8 @@ function source(text: string): AuthorSourceUnit {
return { id: "/project/main.svml", name: "main.svml", text: `<?svml using="@hypit/markup@1"?>\n${text}` };
}
-test("self-described Spatial Surfaces produce an explicit Canvas edge and finite Frame graph", async () => {
- const closure = createResolvedClosure([spatialManifest]);
+test("self-described Spatial Surfaces produce explicit static geometry and measured Region data", async () => {
+ const closure = createResolvedClosure([spatialManifest, svsManifest]);
const surfaces = new MarkupSurfaceRegistry();
const register = (name: string, handler: Parameters<MarkupSurfaceRegistry["registerStructured"]>[0]["handler"]) => {
const declaration = spatialMarkupSurfaces.find((item) => item.name === name);
@@ -204,17 +206,21 @@ test("self-described Spatial Surfaces produce an explicit Canvas edge and finite
register("canvas", decodeCanvasSurface);
register("point", decodePointSurface);
register("path", decodePathSurface);
+ register("region-timeline", decodeRegionTimelineSurface);
register("frame", decodeFrameSurface);
register("anchored-frame", decodeAnchoredFrameSurface);
register("aspect-frame", decodeAspectFrameSurface);
const frontends = new AuthorFrontendRegistry();
frontends.register(createMarkupAuthorFrontend({ registry: surfaces, resolveModule: () => spatialModuleRef }));
+ frontends.register(svsFrontend);
const validators = new TypeValidatorRegistry();
registerTypeValidatorFacets(validators, spatialComponent.validators ?? []);
const compiled = await compileSourceClosure({
entry: source(`<svml>
<import as="space" from="@hypit/spatial@1"/>
+ <import as="tracking" source="./tracking.svs"/>
<space:Canvas id="vertical" width="1080" height="1920"/>
+ <space:RegionTimeline id="heads" within={vertical} recipe={tracking.heads.default}/>
<space:Point id="headline-origin" x="120" y="280"/>
<space:Path id="headline-path">
<space:Move x="120" y="280"/>
@@ -227,11 +233,33 @@ test("self-described Spatial Surfaces produce an explicit Canvas edge and finite
closure,
frontends,
admitRecord: createRecordAdmitter(validators),
- resolveSource() { throw new Error("Spatial fixture has no source imports."); },
+ resolveSource(_importer, request) {
+ if (request.from !== "./tracking.svs") throw new Error(`unknown Spatial fixture source ${request.from}`);
+ return {
+ id: "/project/tracking.svs",
+ name: "tracking.svs",
+ text: `<?svml using="@hypit/svs@1"?>
+<sheet version="1">
+heads.default {
+ frame-count: 3;
+ tracks: [{"id":"BOY","regions":[[0.5,0.1,0.2,0.3],null,[0.52,0.11,0.2,0.3]]}];
+}
+</sheet>`,
+ };
+ },
});
assert.equal(resolveCompiledSourceExport(compiled, "vertical", spatialTypes.canvas).ref.kind, "record");
assert.equal(resolveCompiledSourceExport(compiled, "headline-origin", spatialTypes.point).ref.kind, "record");
assert.equal(resolveCompiledSourceExport(compiled, "headline-path", spatialTypes.path).ref.kind, "record");
+ const regions = resolveCompiledSourceExport(compiled, "heads", spatialTypes.regionTimeline);
+ assert.equal(regions.ref.kind, "record");
+ const regionRecord = compiled.program.records.find((record) =>
+ regions.ref.kind === "record" && record.id === regions.ref.id);
+ const timeline = regionRecord?.value.kind === "inline"
+ ? regionRecord.value.value as unknown as SpatialRegionTimeline
+ : undefined;
+ assert.deepEqual(timeline?.tracks[0]?.frames[0], { xPx: 540, yPx: 192, widthPx: 216, heightPx: 576 });
+ assert.equal(timeline?.tracks[0]?.frames[1], null);
const sticker = resolveCompiledSourceExport(compiled, "sticker", spatialTypes.frame);
assert.equal(sticker.ref.kind, "logical-output");
const build = start(compiled.program, compiled.graph, sealBuildRequest({