@officedk/pptxdk 0.0.0-stage → 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 +48 -2
- package/dist/build.d.ts +94 -0
- package/dist/build.js +148 -0
- package/dist/capabilities/dist/all.js +32 -0
- package/dist/capabilities/dist/box/box-codegen.js +51 -0
- package/dist/capabilities/dist/box/box-declaration.js +31 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +138 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +77 -0
- package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
- package/dist/capabilities/dist/chart/chart-elements.js +12 -0
- package/dist/capabilities/dist/chart/chart-import.js +2272 -0
- package/dist/capabilities/dist/chart/chart-labels.js +86 -0
- package/dist/capabilities/dist/chart/chart-model.js +9 -0
- package/dist/capabilities/dist/chart/chart-schemas.js +1078 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1124 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +298 -0
- package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
- package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
- package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
- package/dist/capabilities/dist/chart/preview/index.js +190 -0
- package/dist/capabilities/dist/chart/preview/layout.js +519 -0
- package/dist/capabilities/dist/chart/preview/legend.js +273 -0
- package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
- package/dist/capabilities/dist/chart/preview/markers.js +100 -0
- package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
- package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
- package/dist/capabilities/dist/chart/preview/scales.js +365 -0
- package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
- package/dist/capabilities/dist/chart/preview/style.js +48 -0
- package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
- package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
- package/dist/capabilities/dist/chart/preview/types.js +5 -0
- package/dist/capabilities/dist/document.js +148 -0
- package/dist/capabilities/dist/font/font-embedding.js +289 -0
- package/dist/capabilities/dist/font/font-family.js +10 -0
- package/dist/capabilities/dist/font/font-import.js +302 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +25 -0
- package/dist/capabilities/dist/group/group-codegen.js +51 -0
- package/dist/capabilities/dist/group/group-declaration.js +42 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +319 -0
- package/dist/capabilities/dist/group/group-xml.js +7 -0
- package/dist/capabilities/dist/group/group.js +211 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +94 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +221 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +778 -0
- package/dist/capabilities/dist/image/image-schemas.js +149 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +472 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +685 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +21 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +527 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +340 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1033 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2189 -0
- package/dist/capabilities/dist/motion/motion-query.js +420 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +216 -0
- package/dist/capabilities/dist/motion/motion.js +1372 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +20 -0
- package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
- package/dist/capabilities/dist/notes/notes-elements.js +12 -0
- package/dist/capabilities/dist/notes/notes-import.js +292 -0
- package/dist/capabilities/dist/notes/notes-schemas.js +35 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +191 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +23 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +12 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +292 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +166 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +57 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +579 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +337 -0
- package/dist/capabilities/dist/shared/geometry.js +1423 -0
- package/dist/capabilities/dist/shared/identity.js +205 -0
- package/dist/capabilities/dist/shared/morph-api.js +11 -0
- package/dist/capabilities/dist/shared/placeholder-import.js +113 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +21390 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +166 -0
- package/dist/capabilities/dist/shared/style-parse.js +11 -0
- package/dist/capabilities/dist/shared/text-schemas.js +216 -0
- package/dist/capabilities/dist/shared/text-service.js +1883 -0
- package/dist/capabilities/dist/shared/visual.js +918 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +161 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +21 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +221 -0
- package/dist/capabilities/dist/table/table-codegen.js +81 -0
- package/dist/capabilities/dist/table/table-declaration.js +15 -0
- package/dist/capabilities/dist/table/table-elements.js +27 -0
- package/dist/capabilities/dist/table/table-import.js +539 -0
- package/dist/capabilities/dist/table/table-schemas.js +279 -0
- package/dist/capabilities/dist/table/table-xml.js +37 -0
- package/dist/capabilities/dist/table/table.js +662 -0
- package/dist/capabilities/dist/text/text-codegen.js +129 -0
- package/dist/capabilities/dist/text/text-declaration.js +19 -0
- package/dist/capabilities/dist/text/text-elements.js +38 -0
- package/dist/capabilities/dist/text/text-import.js +1077 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +335 -0
- package/dist/capabilities/dist/transition/transition-api.js +139 -0
- package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
- package/dist/capabilities/dist/transition/transition-import.js +477 -0
- package/dist/capabilities/dist/transition/transition.js +260 -0
- package/dist/capability-D_xeNVIw.d.ts +29496 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +78 -0
- package/dist/codegen/dist/codegen.js +611 -0
- package/dist/codegen/dist/identifiers.js +193 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +49 -0
- package/dist/core/dist/author-ids.js +48 -0
- package/dist/core/dist/author-schemas.js +313 -0
- package/dist/core/dist/block-flex-layout.js +749 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +13 -0
- package/dist/core/dist/declaration.js +15 -0
- package/dist/core/dist/diagnostics.js +21 -0
- package/dist/core/dist/document-internals.js +13 -0
- package/dist/core/dist/document.js +408 -0
- package/dist/core/dist/geometry-schemas.js +249 -0
- package/dist/core/dist/grid-layout.js +445 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +45 -0
- package/dist/core/dist/layout-protocol.js +66 -0
- package/dist/core/dist/layout-schemas.js +208 -0
- package/dist/core/dist/layout.js +299 -0
- package/dist/core/dist/masters.js +169 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +213 -0
- package/dist/core/dist/query.js +155 -0
- package/dist/core/dist/resolution.js +11 -0
- package/dist/core/dist/resolve.js +1827 -0
- package/dist/core/dist/stage-options.js +67 -0
- package/dist/core/dist/theme.js +931 -0
- package/dist/document-BHPUODPP.d.ts +27759 -0
- package/dist/emit/dist/emit.js +936 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +606 -0
- package/dist/emit/dist/shape-tree.js +12 -0
- package/dist/import/dist/alternate-content.js +54 -0
- package/dist/import/dist/diagnostics.js +153 -0
- package/dist/import/dist/fonts.js +250 -0
- package/dist/import/dist/import.js +504 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1153 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +60 -0
- package/dist/import/dist/notes-masters.js +300 -0
- package/dist/import/dist/opc.js +233 -0
- package/dist/import/dist/resources.js +166 -0
- package/dist/import/dist/sections.js +139 -0
- package/dist/import/dist/themes.js +671 -0
- package/dist/import/dist/visual.js +761 -0
- package/dist/import/dist/xml-fragments.js +36 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-B5m3hqjC.d.ts +7 -0
- package/dist/index-CCy-Yo8G.d.ts +1208 -0
- package/dist/index-DpxcZ4Gs.d.ts +725 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +70 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +194 -0
- package/dist/pptxdk/src/cli-commands.js +913 -0
- package/dist/pptxdk/src/compose.js +44 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +240 -0
- package/dist/preview/dist/options.js +53 -0
- package/dist/preview-Cfw0QdMM.d.ts +86 -0
- package/dist/preview.d.ts +3 -0
- package/dist/preview.js +27 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +65 -0
- package/dist/react/dist/elements.js +59 -0
- package/dist/react/dist/index.js +68 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +145 -0
- package/dist/react.js +27 -0
- package/dist/transition-Cips9wma.d.ts +82 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +14 -0
- package/package.json +78 -3
|
@@ -0,0 +1,2189 @@
|
|
|
1
|
+
import { CapabilityError } from "../../../core/dist/diagnostics.js";
|
|
2
|
+
import "../../../core/dist/capability.js";
|
|
3
|
+
import { maximumTimeNodeValue } from "./motion-schemas.js";
|
|
4
|
+
import "./motion-api.js";
|
|
5
|
+
import { createMotionQuery } from "./motion-query.js";
|
|
6
|
+
// ../capabilities/dist/motion/motion-plan.js
|
|
7
|
+
function planStartForGate(gate) {
|
|
8
|
+
switch (gate.kind) {
|
|
9
|
+
case "parent-start": return {
|
|
10
|
+
kind: "parent-start",
|
|
11
|
+
delayMs: gate.delayMs
|
|
12
|
+
};
|
|
13
|
+
case "end": return {
|
|
14
|
+
kind: "end",
|
|
15
|
+
dependency: gate.dependency
|
|
16
|
+
};
|
|
17
|
+
case "begin": return {
|
|
18
|
+
kind: "event",
|
|
19
|
+
dependency: gate.dependency
|
|
20
|
+
};
|
|
21
|
+
case "plan-start": return gate.start;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function gateSourceDependencies(gate) {
|
|
25
|
+
if (gate.kind === "end" || gate.kind === "begin") return [gate.dependency];
|
|
26
|
+
if (gate.kind !== "plan-start") return [];
|
|
27
|
+
if (gate.sourceDependency !== void 0) return [gate.sourceDependency];
|
|
28
|
+
const { base } = motionPlanStartLayers(gate.start);
|
|
29
|
+
return base.kind === "end" || base.kind === "event" ? [base.dependency] : [];
|
|
30
|
+
}
|
|
31
|
+
function motionPlanStartLayers(start) {
|
|
32
|
+
let base = start;
|
|
33
|
+
const reversedDelays = [];
|
|
34
|
+
while (base.kind === "delay-layer") {
|
|
35
|
+
reversedDelays.push(base.delayMs);
|
|
36
|
+
base = base.start;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
base,
|
|
40
|
+
delays: reversedDelays.reverse()
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function addMotionPlanStartDelay(start, delayMs) {
|
|
44
|
+
if (!Number.isSafeInteger(delayMs) || delayMs < 0) return void 0;
|
|
45
|
+
if (delayMs === 0) return start;
|
|
46
|
+
const { base, delays } = motionPlanStartLayers(start);
|
|
47
|
+
const baseValue = base.kind === "parent-start" ? base.delayMs : base.kind === "end" || base.kind === "event" ? base.dependency.offsetMs : base.kind === "condition-end" ? base.delayMs : 0;
|
|
48
|
+
const totalDelay = delays.reduce((total, delay) => total + delay, baseValue);
|
|
49
|
+
if (!Number.isSafeInteger(totalDelay + delayMs)) return void 0;
|
|
50
|
+
let lowered = start;
|
|
51
|
+
let remaining = delayMs;
|
|
52
|
+
while (remaining > 0) {
|
|
53
|
+
const fieldDelay = Math.min(remaining, maximumTimeNodeValue);
|
|
54
|
+
lowered = addMotionPlanStartDelayField(lowered, fieldDelay);
|
|
55
|
+
remaining -= fieldDelay;
|
|
56
|
+
}
|
|
57
|
+
return lowered;
|
|
58
|
+
}
|
|
59
|
+
function addMotionPlanStartDelayField(start, delayMs) {
|
|
60
|
+
if (start.kind === "delay-layer" || start.kind === "condition-join") return {
|
|
61
|
+
kind: "delay-layer",
|
|
62
|
+
start,
|
|
63
|
+
delayMs
|
|
64
|
+
};
|
|
65
|
+
let delayed;
|
|
66
|
+
if (start.kind === "parent-start") delayed = {
|
|
67
|
+
kind: start.kind,
|
|
68
|
+
delayMs: start.delayMs + delayMs
|
|
69
|
+
};
|
|
70
|
+
else if (start.kind === "end" || start.kind === "event") delayed = {
|
|
71
|
+
kind: start.kind,
|
|
72
|
+
dependency: {
|
|
73
|
+
...start.dependency,
|
|
74
|
+
offsetMs: start.dependency.offsetMs + delayMs
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
else delayed = {
|
|
78
|
+
...start,
|
|
79
|
+
delayMs: start.delayMs + delayMs
|
|
80
|
+
};
|
|
81
|
+
return (delayed.kind === "parent-start" ? delayed.delayMs : delayed.kind === "end" || delayed.kind === "event" ? delayed.dependency.offsetMs : delayed.kind === "condition-end" ? delayed.delayMs : 0) <= 4294967295 ? delayed : {
|
|
82
|
+
kind: "delay-layer",
|
|
83
|
+
start,
|
|
84
|
+
delayMs
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** Fold only local delays proven to preserve parent threshold; preserve real container layers otherwise. */
|
|
88
|
+
function composeMotionPlanStarts(inherited, child) {
|
|
89
|
+
if (child.kind === "delay-layer") {
|
|
90
|
+
const composedBase = composeMotionPlanStarts(inherited, child.start);
|
|
91
|
+
return composedBase === void 0 ? void 0 : addMotionPlanStartDelay(composedBase, child.delayMs);
|
|
92
|
+
}
|
|
93
|
+
if (child.kind === "condition-join") return inherited === void 0 ? child : void 0;
|
|
94
|
+
if (inherited === void 0) return child;
|
|
95
|
+
if (inherited.kind === "condition-join") return child.kind === "parent-start" ? {
|
|
96
|
+
kind: "condition-end",
|
|
97
|
+
id: inherited.id,
|
|
98
|
+
delayMs: child.delayMs
|
|
99
|
+
} : void 0;
|
|
100
|
+
if (child.kind === "end" || child.kind === "event") return inherited.kind === "parent-start" && inherited.delayMs === 0 ? child : void 0;
|
|
101
|
+
if (child.kind === "condition-end") return;
|
|
102
|
+
return addMotionPlanStartDelay(inherited, child.delayMs);
|
|
103
|
+
}
|
|
104
|
+
function fail(code, message, path) {
|
|
105
|
+
throw new CapabilityError(code, message, path);
|
|
106
|
+
}
|
|
107
|
+
function isRecord(value) {
|
|
108
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
109
|
+
}
|
|
110
|
+
function isMotionValue(value) {
|
|
111
|
+
return isRecord(value) && isRecord(value["target"]) && Array.isArray(value["scopes"]) && Array.isArray(value["effects"]);
|
|
112
|
+
}
|
|
113
|
+
function isScopeValue(value) {
|
|
114
|
+
return isRecord(value) && value["type"] === "scope" && isRecord(value["scope"]) && typeof value["scope"]["identity"] === "string";
|
|
115
|
+
}
|
|
116
|
+
function stepKey(step) {
|
|
117
|
+
if (step === void 0) return "slide-entry";
|
|
118
|
+
return step.mode === "explicit" ? `explicit:${step.number}` : `automatic:${step.identity}`;
|
|
119
|
+
}
|
|
120
|
+
function stepInfo(step) {
|
|
121
|
+
if (step === void 0) return {
|
|
122
|
+
key: "slide-entry",
|
|
123
|
+
trigger: "auto"
|
|
124
|
+
};
|
|
125
|
+
return step.mode === "explicit" ? {
|
|
126
|
+
key: stepKey(step),
|
|
127
|
+
trigger: "click",
|
|
128
|
+
number: step.number
|
|
129
|
+
} : {
|
|
130
|
+
key: stepKey(step),
|
|
131
|
+
trigger: "click"
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function momentKey(moment) {
|
|
135
|
+
return `${moment.scope}\u0000${moment.name ?? ""}`;
|
|
136
|
+
}
|
|
137
|
+
function timingParts(timing) {
|
|
138
|
+
return timing.type === "motion-offset" ? {
|
|
139
|
+
moment: timing.moment,
|
|
140
|
+
offsetMs: timing.offsetMs
|
|
141
|
+
} : {
|
|
142
|
+
moment: timing,
|
|
143
|
+
offsetMs: 0
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function eventSource(event) {
|
|
147
|
+
if ("scopeId" in event) return event.point === "start" ? `scope-start:${event.scopeId}` : `scope:${event.scopeId}`;
|
|
148
|
+
if ("group" in event) return `target:${event.targetId}`;
|
|
149
|
+
return `effect:${event.targetId}:${event.effectIndex}:${event.partIndex ?? ""}`;
|
|
150
|
+
}
|
|
151
|
+
function dependencyAtEvent(dependency, offsetMs = 0) {
|
|
152
|
+
return {
|
|
153
|
+
...dependency,
|
|
154
|
+
offsetMs
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function dependencyEventId(dependency) {
|
|
158
|
+
return eventSource(dependency);
|
|
159
|
+
}
|
|
160
|
+
function eventTime(eventId, state, timeMs, dependency, nativeStart, reportedStartAfter, reportedStartAfterAll, candidates) {
|
|
161
|
+
const candidate = {
|
|
162
|
+
eventId,
|
|
163
|
+
offsetMs: 0,
|
|
164
|
+
...dependency === void 0 ? {} : { dependency: dependencyAtEvent(dependency) }
|
|
165
|
+
};
|
|
166
|
+
if (state === "known") {
|
|
167
|
+
if (timeMs === void 0) throw new Error("Known moment lacks numeric value");
|
|
168
|
+
return {
|
|
169
|
+
state,
|
|
170
|
+
timeMs,
|
|
171
|
+
eventId,
|
|
172
|
+
candidates: candidates ?? [candidate],
|
|
173
|
+
...dependency === void 0 ? {} : { dependency },
|
|
174
|
+
...nativeStart === void 0 ? {} : { nativeStart },
|
|
175
|
+
...reportedStartAfter === void 0 ? {} : { reportedStartAfter },
|
|
176
|
+
...reportedStartAfterAll === void 0 ? {} : { reportedStartAfterAll }
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
state,
|
|
181
|
+
eventId,
|
|
182
|
+
candidates: candidates ?? [candidate],
|
|
183
|
+
...dependency === void 0 ? {} : { dependency },
|
|
184
|
+
...nativeStart === void 0 ? {} : { nativeStart },
|
|
185
|
+
...reportedStartAfter === void 0 ? {} : { reportedStartAfter },
|
|
186
|
+
...reportedStartAfterAll === void 0 ? {} : { reportedStartAfterAll }
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
var MotionTimingFacts = class {
|
|
190
|
+
successors = /* @__PURE__ */ new Map();
|
|
191
|
+
exactRelations = /* @__PURE__ */ new Map();
|
|
192
|
+
exactTimes = /* @__PURE__ */ new Map();
|
|
193
|
+
setExactTime(eventId, timeMs, path) {
|
|
194
|
+
const existing = this.exactTimes.get(eventId);
|
|
195
|
+
if (existing !== void 0 && existing !== timeMs) fail("motion-plan-conflict", "Conflicting numeric moments for the same choreography event", path);
|
|
196
|
+
this.exactTimes.set(eventId, timeMs);
|
|
197
|
+
}
|
|
198
|
+
exactTime(eventId) {
|
|
199
|
+
return this.exactTimes.get(eventId);
|
|
200
|
+
}
|
|
201
|
+
addExactOffset(before, after, offsetMs, path) {
|
|
202
|
+
const exactBefore = this.exactTime(before);
|
|
203
|
+
const exactAfter = this.exactTime(after);
|
|
204
|
+
if (exactBefore !== void 0 && exactAfter !== void 0 && exactAfter - exactBefore !== offsetMs) fail("motion-plan-conflict", "Exact choreography time difference conflicts with known moment", path);
|
|
205
|
+
const existing = this.exactRelations.get(before)?.get(after);
|
|
206
|
+
if (existing !== void 0 && existing !== offsetMs) fail("motion-plan-conflict", "Conflicting exact time differences for the same choreography event", path);
|
|
207
|
+
const existingReverse = this.exactRelations.get(after)?.get(before);
|
|
208
|
+
if (existingReverse !== void 0 && existingReverse !== -offsetMs) fail("motion-plan-conflict", "Conflicting exact time differences for the same choreography event", path);
|
|
209
|
+
const edges = this.exactRelations.get(before) ?? /* @__PURE__ */ new Map();
|
|
210
|
+
edges.set(after, offsetMs);
|
|
211
|
+
this.exactRelations.set(before, edges);
|
|
212
|
+
const reverseEdges = this.exactRelations.get(after) ?? /* @__PURE__ */ new Map();
|
|
213
|
+
reverseEdges.set(before, -offsetMs);
|
|
214
|
+
this.exactRelations.set(after, reverseEdges);
|
|
215
|
+
}
|
|
216
|
+
exactOffset(before, after) {
|
|
217
|
+
const exactBefore = this.exactTime(before);
|
|
218
|
+
const exactAfter = this.exactTime(after);
|
|
219
|
+
const exactDifference = exactBefore === void 0 || exactAfter === void 0 ? void 0 : exactAfter - exactBefore;
|
|
220
|
+
const relationDifference = this.exactPath(before, after);
|
|
221
|
+
if (exactDifference !== void 0 && relationDifference !== void 0 && exactDifference !== relationDifference) fail("motion-plan-conflict", "Exact choreography time difference conflicts with known moment");
|
|
222
|
+
return relationDifference ?? exactDifference;
|
|
223
|
+
}
|
|
224
|
+
addLowerBound(before, after, minimumMs, path) {
|
|
225
|
+
if (before === after) {
|
|
226
|
+
if (minimumMs > 0) fail("motion-cycle", "Choreography moment dependencies contain a cycle", path);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (this.hasPath(after, before)) fail("motion-cycle", "Choreography moment dependencies contain a cycle", path);
|
|
230
|
+
const beforeTime = this.exactTime(before);
|
|
231
|
+
const afterTime = this.exactTime(after);
|
|
232
|
+
if (beforeTime !== void 0 && afterTime !== void 0 && afterTime - beforeTime < minimumMs) fail("motion-plan-conflict", "Choreography time difference fact conflicts with known moment", path);
|
|
233
|
+
const edges = this.successors.get(before) ?? /* @__PURE__ */ new Map();
|
|
234
|
+
edges.set(after, Math.max(edges.get(after) ?? Number.NEGATIVE_INFINITY, minimumMs));
|
|
235
|
+
this.successors.set(before, edges);
|
|
236
|
+
}
|
|
237
|
+
lowerBound(before, after) {
|
|
238
|
+
const exactDifference = this.exactOffset(before, after);
|
|
239
|
+
const pathDifference = this.longestPath(before, after, /* @__PURE__ */ new Set());
|
|
240
|
+
if (exactDifference === void 0) return pathDifference;
|
|
241
|
+
if (pathDifference === void 0) return exactDifference;
|
|
242
|
+
if (pathDifference > exactDifference) fail("motion-plan-conflict", "Choreography time difference fact conflicts with exact time difference");
|
|
243
|
+
return Math.max(exactDifference, pathDifference);
|
|
244
|
+
}
|
|
245
|
+
earliestTime(eventId, originEventId) {
|
|
246
|
+
const exact = this.exactTime(eventId);
|
|
247
|
+
if (exact !== void 0) return exact;
|
|
248
|
+
return this.lowerBound(originEventId, eventId);
|
|
249
|
+
}
|
|
250
|
+
hasPath(from, to) {
|
|
251
|
+
if (from === to) return true;
|
|
252
|
+
const pending = [from];
|
|
253
|
+
const visited = /* @__PURE__ */ new Set();
|
|
254
|
+
while (pending.length > 0) {
|
|
255
|
+
const current = pending.pop();
|
|
256
|
+
if (current === void 0 || visited.has(current)) continue;
|
|
257
|
+
visited.add(current);
|
|
258
|
+
for (const next of this.successors.get(current)?.keys() ?? []) {
|
|
259
|
+
if (next === to) return true;
|
|
260
|
+
pending.push(next);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
longestPath(from, to, visited) {
|
|
266
|
+
if (from === to) return 0;
|
|
267
|
+
if (visited.has(from)) return void 0;
|
|
268
|
+
visited.add(from);
|
|
269
|
+
let longest;
|
|
270
|
+
for (const [next, weight] of this.successors.get(from) ?? []) {
|
|
271
|
+
const remaining = this.longestPath(next, to, visited);
|
|
272
|
+
if (remaining !== void 0) longest = Math.max(longest ?? Number.NEGATIVE_INFINITY, weight + remaining);
|
|
273
|
+
}
|
|
274
|
+
visited.delete(from);
|
|
275
|
+
return longest;
|
|
276
|
+
}
|
|
277
|
+
exactPath(from, to) {
|
|
278
|
+
if (from === to) return 0;
|
|
279
|
+
const offsets = /* @__PURE__ */ new Map([[from, 0]]);
|
|
280
|
+
const pending = [from];
|
|
281
|
+
for (let index = 0; index < pending.length; index += 1) {
|
|
282
|
+
const current = pending[index];
|
|
283
|
+
if (current === void 0) continue;
|
|
284
|
+
const currentOffset = offsets.get(current);
|
|
285
|
+
if (currentOffset === void 0) continue;
|
|
286
|
+
for (const [next, difference] of this.exactRelations.get(current) ?? []) {
|
|
287
|
+
const candidate = currentOffset + difference;
|
|
288
|
+
const existing = offsets.get(next);
|
|
289
|
+
if (existing !== void 0) {
|
|
290
|
+
if (existing !== candidate) fail("motion-plan-conflict", "Conflicting exact relations for the same choreography moment");
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
offsets.set(next, candidate);
|
|
294
|
+
pending.push(next);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return offsets.get(to);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
function asExpression(time) {
|
|
301
|
+
if (time.state === "no-natural-completion") return time;
|
|
302
|
+
const reference = {
|
|
303
|
+
eventId: time.eventId,
|
|
304
|
+
offsetMs: 0
|
|
305
|
+
};
|
|
306
|
+
return time.state === "known" ? {
|
|
307
|
+
state: "known",
|
|
308
|
+
timeMs: time.timeMs,
|
|
309
|
+
candidates: time.candidates,
|
|
310
|
+
references: [reference]
|
|
311
|
+
} : {
|
|
312
|
+
state: "unknown",
|
|
313
|
+
candidates: time.candidates,
|
|
314
|
+
references: [reference]
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
function add(time, offsetMs) {
|
|
318
|
+
if (time.state === "no-natural-completion") return time;
|
|
319
|
+
const candidates = time.candidates.map((candidate) => ({
|
|
320
|
+
...candidate,
|
|
321
|
+
offsetMs: candidate.offsetMs + offsetMs
|
|
322
|
+
}));
|
|
323
|
+
const shiftedReferences = ("references" in time ? time.references : [{
|
|
324
|
+
eventId: time.eventId,
|
|
325
|
+
offsetMs: 0
|
|
326
|
+
}]).map((reference) => ({
|
|
327
|
+
...reference,
|
|
328
|
+
offsetMs: reference.offsetMs + offsetMs
|
|
329
|
+
}));
|
|
330
|
+
return time.state === "known" ? {
|
|
331
|
+
state: "known",
|
|
332
|
+
timeMs: time.timeMs + offsetMs,
|
|
333
|
+
candidates,
|
|
334
|
+
references: shiftedReferences
|
|
335
|
+
} : {
|
|
336
|
+
state: "unknown",
|
|
337
|
+
candidates,
|
|
338
|
+
references: shiftedReferences
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function commonCandidateOffset(candidates, reference) {
|
|
342
|
+
if (candidates.length === 0 || candidates.length !== reference.length) return;
|
|
343
|
+
const referenceByEvent = new Map(reference.map((candidate) => [candidate.eventId, candidate]));
|
|
344
|
+
if (referenceByEvent.size !== reference.length) return void 0;
|
|
345
|
+
let commonOffset;
|
|
346
|
+
for (const candidate of candidates) {
|
|
347
|
+
const source = referenceByEvent.get(candidate.eventId);
|
|
348
|
+
if (source === void 0) return void 0;
|
|
349
|
+
const offset = candidate.offsetMs - source.offsetMs;
|
|
350
|
+
if (!Number.isSafeInteger(offset)) return void 0;
|
|
351
|
+
if (commonOffset !== void 0 && commonOffset !== offset) return;
|
|
352
|
+
commonOffset = offset;
|
|
353
|
+
}
|
|
354
|
+
return commonOffset;
|
|
355
|
+
}
|
|
356
|
+
function candidateDominates(earlier, later, facts) {
|
|
357
|
+
const difference = facts.lowerBound(earlier.eventId, later.eventId);
|
|
358
|
+
return difference !== void 0 && difference + later.offsetMs - earlier.offsetMs >= 0;
|
|
359
|
+
}
|
|
360
|
+
function maximum(times, facts) {
|
|
361
|
+
if (times.some(({ state }) => state === "no-natural-completion")) return { state: "no-natural-completion" };
|
|
362
|
+
const candidates = times.flatMap((time) => time.state === "no-natural-completion" ? [] : time.candidates);
|
|
363
|
+
const uniqueByEvent = /* @__PURE__ */ new Map();
|
|
364
|
+
for (const candidate of candidates) {
|
|
365
|
+
const current = uniqueByEvent.get(candidate.eventId);
|
|
366
|
+
if (current === void 0 || candidate.offsetMs > current.offsetMs) uniqueByEvent.set(candidate.eventId, candidate);
|
|
367
|
+
}
|
|
368
|
+
const unique = [...uniqueByEvent.values()];
|
|
369
|
+
const referencesByEvent = /* @__PURE__ */ new Map();
|
|
370
|
+
for (const time of times) {
|
|
371
|
+
if (time.state === "no-natural-completion") continue;
|
|
372
|
+
const references = "references" in time ? time.references : [{
|
|
373
|
+
eventId: time.eventId,
|
|
374
|
+
offsetMs: 0
|
|
375
|
+
}];
|
|
376
|
+
for (const reference of references) {
|
|
377
|
+
const current = referencesByEvent.get(reference.eventId);
|
|
378
|
+
if (current === void 0 || reference.offsetMs > current.offsetMs) referencesByEvent.set(reference.eventId, reference);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
const references = [...referencesByEvent.values()];
|
|
382
|
+
const exactCandidates = unique.map((candidate) => {
|
|
383
|
+
const timeMs = facts.exactTime(candidate.eventId);
|
|
384
|
+
return timeMs === void 0 ? void 0 : timeMs + candidate.offsetMs;
|
|
385
|
+
});
|
|
386
|
+
if (exactCandidates.every((timeMs) => timeMs !== void 0)) {
|
|
387
|
+
const latest = Math.max(0, ...exactCandidates.filter((timeMs) => timeMs !== void 0));
|
|
388
|
+
return {
|
|
389
|
+
state: "known",
|
|
390
|
+
timeMs: latest,
|
|
391
|
+
candidates: unique.filter((_candidate, index) => exactCandidates[index] === latest),
|
|
392
|
+
references
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
return {
|
|
396
|
+
state: "unknown",
|
|
397
|
+
candidates: unique.filter((candidate, index) => {
|
|
398
|
+
return !unique.some((other, otherIndex) => {
|
|
399
|
+
if (index === otherIndex) return false;
|
|
400
|
+
if (!candidateDominates(candidate, other, facts)) return false;
|
|
401
|
+
return !candidateDominates(other, candidate, facts) || otherIndex < index;
|
|
402
|
+
});
|
|
403
|
+
}),
|
|
404
|
+
references
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
function materializeEvent(expression, eventId, dependency, facts, path, nativeStart, reportedStartAfter, reportedStartAfterAll, preservedCandidates) {
|
|
408
|
+
if (expression.state === "no-natural-completion") return expression;
|
|
409
|
+
for (const candidate of expression.candidates) facts.addLowerBound(candidate.eventId, eventId, candidate.offsetMs, path);
|
|
410
|
+
if (expression.candidates.length === 1) {
|
|
411
|
+
const [candidate] = expression.candidates;
|
|
412
|
+
if (candidate !== void 0) facts.addExactOffset(candidate.eventId, eventId, candidate.offsetMs, path);
|
|
413
|
+
}
|
|
414
|
+
if (expression.state === "known") {
|
|
415
|
+
facts.setExactTime(eventId, expression.timeMs, path);
|
|
416
|
+
return eventTime(eventId, "known", expression.timeMs, dependency, nativeStart, reportedStartAfter, reportedStartAfterAll, preservedCandidates);
|
|
417
|
+
}
|
|
418
|
+
return eventTime(eventId, "unknown", void 0, dependency, nativeStart, reportedStartAfter, reportedStartAfterAll, preservedCandidates);
|
|
419
|
+
}
|
|
420
|
+
function completion(start, children, dependency, facts, path) {
|
|
421
|
+
if (start.state === "no-natural-completion" || children.some(({ state }) => state === "no-natural-completion")) return { state: "no-natural-completion" };
|
|
422
|
+
if (children.length === 0) return start;
|
|
423
|
+
const eventId = dependencyEventId(dependency);
|
|
424
|
+
for (const member of [start, ...children]) if (member.state !== "no-natural-completion") facts.addLowerBound(member.eventId, eventId, 0, path);
|
|
425
|
+
const end = maximum([start, ...children], facts);
|
|
426
|
+
if (end.state === "no-natural-completion") return end;
|
|
427
|
+
if (end.state === "known") facts.setExactTime(eventId, end.timeMs, path);
|
|
428
|
+
if (end.candidates.length === 1) {
|
|
429
|
+
const [winner] = end.candidates;
|
|
430
|
+
if (winner !== void 0) {
|
|
431
|
+
facts.addLowerBound(winner.eventId, eventId, winner.offsetMs, path);
|
|
432
|
+
facts.addExactOffset(winner.eventId, eventId, winner.offsetMs, path);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (end.state === "known") return eventTime(eventId, "known", end.timeMs, dependency);
|
|
436
|
+
return eventTime(eventId, "unknown", void 0, dependency);
|
|
437
|
+
}
|
|
438
|
+
function expansionFor(target, effect, path) {
|
|
439
|
+
if (effect.by === void 0 || typeof effect.by === "number") return {
|
|
440
|
+
type: "single",
|
|
441
|
+
count: 1
|
|
442
|
+
};
|
|
443
|
+
if (effect.by === "word" || effect.by === "letter") {
|
|
444
|
+
if (!target.textBody || !target.paragraphCount) fail("invalid-motion-granularity", `by: "${effect.by}" requires native object with text`, path);
|
|
445
|
+
return {
|
|
446
|
+
type: "iterate",
|
|
447
|
+
count: 1,
|
|
448
|
+
by: effect.by,
|
|
449
|
+
intervalMs: effect.intervalMs ?? Math.max(1, Math.round(effect.duration / 10))
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
if (effect.by === "paragraph") {
|
|
453
|
+
const count = target.paragraphCount ?? 0;
|
|
454
|
+
if (!target.textBody || count < 1) fail("invalid-motion-granularity", "by: \"paragraph\" requires native text object with paragraphs", path);
|
|
455
|
+
return {
|
|
456
|
+
type: "parts",
|
|
457
|
+
count,
|
|
458
|
+
ranges: Array.from({ length: count }, (_, index) => ({
|
|
459
|
+
type: "paragraph",
|
|
460
|
+
start: index,
|
|
461
|
+
end: index
|
|
462
|
+
}))
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
const pointCounts = target.chartSeriesPointCounts ?? [];
|
|
466
|
+
if (target.kind !== "chart") fail("invalid-motion-granularity", `by: "${effect.by}" requires native chart`, path);
|
|
467
|
+
const pointCount = Math.max(0, ...pointCounts);
|
|
468
|
+
let dataRanges;
|
|
469
|
+
if (effect.by === "series") dataRanges = pointCounts.map((_, seriesIndex) => ({
|
|
470
|
+
type: "chart",
|
|
471
|
+
step: "series",
|
|
472
|
+
seriesIndex,
|
|
473
|
+
categoryIndex: -4
|
|
474
|
+
}));
|
|
475
|
+
else if (effect.by === "category") dataRanges = Array.from({ length: pointCount }, (_, categoryIndex) => ({
|
|
476
|
+
type: "chart",
|
|
477
|
+
step: "category",
|
|
478
|
+
seriesIndex: -4,
|
|
479
|
+
categoryIndex
|
|
480
|
+
}));
|
|
481
|
+
else if (effect.by === "seriesElements") dataRanges = pointCounts.flatMap((count, seriesIndex) => Array.from({ length: count }, (_, categoryIndex) => ({
|
|
482
|
+
type: "chart",
|
|
483
|
+
step: "ptInSeries",
|
|
484
|
+
seriesIndex,
|
|
485
|
+
categoryIndex
|
|
486
|
+
})));
|
|
487
|
+
else dataRanges = Array.from({ length: pointCount }).flatMap((_, categoryIndex) => pointCounts.flatMap((count, seriesIndex) => categoryIndex < count ? [{
|
|
488
|
+
type: "chart",
|
|
489
|
+
step: "ptInCategory",
|
|
490
|
+
seriesIndex,
|
|
491
|
+
categoryIndex
|
|
492
|
+
}] : []));
|
|
493
|
+
const ranges = [{
|
|
494
|
+
type: "chart",
|
|
495
|
+
step: "gridLegend",
|
|
496
|
+
seriesIndex: -3,
|
|
497
|
+
categoryIndex: -3
|
|
498
|
+
}, ...dataRanges];
|
|
499
|
+
return {
|
|
500
|
+
type: "parts",
|
|
501
|
+
count: ranges.length,
|
|
502
|
+
ranges
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
function effectEnd(base, target, effect, effectIndex, expansion, facts) {
|
|
506
|
+
const partIndex = expansion.type === "parts" ? expansion.count - 1 : void 0;
|
|
507
|
+
return effectTimingAt(add(base, Math.round(effect.delay) + (partIndex === void 0 ? 0 : partIndex * Math.round(effect.duration))), target, effect, effectIndex, partIndex, expansion, facts).end;
|
|
508
|
+
}
|
|
509
|
+
function effectTimingAt(startExpression, target, effect, effectIndex, partIndex, expansion, facts) {
|
|
510
|
+
if (startExpression.state === "no-natural-completion") return {
|
|
511
|
+
start: startExpression,
|
|
512
|
+
end: startExpression
|
|
513
|
+
};
|
|
514
|
+
const startEventId = `effect-start:${target.id}:${effectIndex}:${partIndex ?? ""}`;
|
|
515
|
+
const start = materializeEvent(startExpression, startEventId, void 0, facts, target.path);
|
|
516
|
+
if (start.state === "no-natural-completion") return {
|
|
517
|
+
start,
|
|
518
|
+
end: start
|
|
519
|
+
};
|
|
520
|
+
if (effect.repeatCount === "forever") return {
|
|
521
|
+
start,
|
|
522
|
+
end: { state: "no-natural-completion" }
|
|
523
|
+
};
|
|
524
|
+
const rounds = effect.repeatCount ?? 1;
|
|
525
|
+
const durationMs = Math.round(effect.duration) * rounds;
|
|
526
|
+
if (start.state === "known" && !Number.isSafeInteger(start.timeMs + durationMs)) fail("invalid-motion-time", "Effect completion moment must be a safe integer in milliseconds", target.path);
|
|
527
|
+
const dependency = {
|
|
528
|
+
targetId: target.id,
|
|
529
|
+
effectIndex,
|
|
530
|
+
...partIndex === void 0 ? {} : { partIndex },
|
|
531
|
+
point: "end",
|
|
532
|
+
offsetMs: 0
|
|
533
|
+
};
|
|
534
|
+
const endEventId = dependencyEventId(dependency);
|
|
535
|
+
const existingEndTime = facts.exactTime(endEventId);
|
|
536
|
+
if (existingEndTime !== void 0 && !Number.isSafeInteger(existingEndTime)) return {
|
|
537
|
+
start,
|
|
538
|
+
end: eventTime(endEventId, "known", existingEndTime, dependency)
|
|
539
|
+
};
|
|
540
|
+
const minimumDuration = durationMs;
|
|
541
|
+
if (expansion.type === "iterate") facts.addLowerBound(startEventId, endEventId, minimumDuration, target.path);
|
|
542
|
+
else {
|
|
543
|
+
facts.addLowerBound(startEventId, endEventId, durationMs, target.path);
|
|
544
|
+
facts.addExactOffset(startEventId, endEventId, durationMs, target.path);
|
|
545
|
+
}
|
|
546
|
+
if (expansion.type !== "iterate" && start.state === "known") {
|
|
547
|
+
const endMs = start.timeMs + durationMs;
|
|
548
|
+
facts.setExactTime(endEventId, endMs, target.path);
|
|
549
|
+
return {
|
|
550
|
+
start,
|
|
551
|
+
end: eventTime(endEventId, "known", endMs, dependency)
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
return {
|
|
555
|
+
start,
|
|
556
|
+
end: eventTime(endEventId, "unknown", void 0, dependency)
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
function motionScope(value) {
|
|
560
|
+
return typeof value.identity === "string" && typeof value.mode === "string" && typeof value.delay === "number";
|
|
561
|
+
}
|
|
562
|
+
function motionPlan(contributions) {
|
|
563
|
+
const stepRootHostIdentity = "\0motion-step-root";
|
|
564
|
+
const scopes = /* @__PURE__ */ new Map();
|
|
565
|
+
const targets = /* @__PURE__ */ new Map();
|
|
566
|
+
const roots = [];
|
|
567
|
+
const effectExpansions = /* @__PURE__ */ new Map();
|
|
568
|
+
const getExpansion = (target, effectIndex) => {
|
|
569
|
+
const key = `${target.id}:${effectIndex}`;
|
|
570
|
+
const existing = effectExpansions.get(key);
|
|
571
|
+
if (existing !== void 0) return existing;
|
|
572
|
+
const effect = target.value.effects[effectIndex];
|
|
573
|
+
if (effect === void 0) fail("invalid-motion", "Motion effect index does not exist", target.path);
|
|
574
|
+
const expansion = expansionFor(target.value.target, effect, target.path);
|
|
575
|
+
effectExpansions.set(key, expansion);
|
|
576
|
+
return expansion;
|
|
577
|
+
};
|
|
578
|
+
for (const contribution of contributions) {
|
|
579
|
+
if (contribution.capability !== "motion") continue;
|
|
580
|
+
if (isScopeValue(contribution.value)) {
|
|
581
|
+
const declaration = contribution.value.scope;
|
|
582
|
+
if (!motionScope(declaration)) fail("invalid-scope", "Choreography scope declaration is invalid", contribution.path);
|
|
583
|
+
if (scopes.has(declaration.identity)) fail("duplicate-scope", "Same choreography scope identity cannot be declared twice", contribution.path);
|
|
584
|
+
scopes.set(declaration.identity, {
|
|
585
|
+
declaration,
|
|
586
|
+
path: contribution.path,
|
|
587
|
+
order: contribution.order,
|
|
588
|
+
members: []
|
|
589
|
+
});
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
if (!isMotionValue(contribution.value)) fail("invalid-motion", `motion annotation is invalid at ${contribution.path}`, contribution.path);
|
|
593
|
+
if (contribution.targetId === void 0) fail("invalid-motion", "Object motion lacks native object identity", contribution.path);
|
|
594
|
+
const trigger = stepInfo(contribution.value.step);
|
|
595
|
+
if (targets.has(contribution.targetId)) fail("invalid-motion", "Same native object repeatedly submitted motion declarations", contribution.path);
|
|
596
|
+
targets.set(contribution.targetId, {
|
|
597
|
+
id: contribution.targetId,
|
|
598
|
+
path: contribution.path,
|
|
599
|
+
order: contribution.order,
|
|
600
|
+
value: contribution.value,
|
|
601
|
+
stepKey: trigger.key,
|
|
602
|
+
trigger: trigger.trigger,
|
|
603
|
+
...trigger.number === void 0 ? {} : { number: trigger.number }
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
for (const target of targets.values()) {
|
|
607
|
+
const granularities = new Set(target.value.effects.map(({ by }) => by).filter((by) => typeof by === "string"));
|
|
608
|
+
const textGranularities = [...granularities].filter((by) => by === "paragraph" || by === "word" || by === "letter");
|
|
609
|
+
const chartGranularities = [...granularities].filter((by) => by === "series" || by === "category" || by === "seriesElements" || by === "categoryElements");
|
|
610
|
+
if (target.value.target.kind === "chart" ? chartGranularities.length > 1 : textGranularities.length > 1) fail("invalid-motion-granularity", "Parallel motions on the same native object cannot mix incompatible build granularities", target.path);
|
|
611
|
+
}
|
|
612
|
+
for (const scope of scopes.values()) {
|
|
613
|
+
const parentId = scope.declaration.parent;
|
|
614
|
+
if (parentId === void 0) continue;
|
|
615
|
+
const parent = scopes.get(parentId);
|
|
616
|
+
if (parent === void 0) fail("missing-scope", "Parent instance of choreography scope does not exist", scope.path);
|
|
617
|
+
parent.members.push({
|
|
618
|
+
kind: "scope",
|
|
619
|
+
id: scope.declaration.identity,
|
|
620
|
+
order: scope.order
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
for (const scope of scopes.values()) if (scope.declaration.parent === void 0) roots.push({
|
|
624
|
+
kind: "scope",
|
|
625
|
+
id: scope.declaration.identity,
|
|
626
|
+
order: scope.order
|
|
627
|
+
});
|
|
628
|
+
for (const target of targets.values()) {
|
|
629
|
+
let parent;
|
|
630
|
+
for (const declaration of target.value.scopes) {
|
|
631
|
+
if (!motionScope(declaration)) fail("invalid-scope", "Object contains invalid choreography scope path", target.path);
|
|
632
|
+
const scope = scopes.get(declaration.identity);
|
|
633
|
+
if (scope === void 0) fail("missing-scope", "Choreography scope instance referenced by object does not exist", target.path);
|
|
634
|
+
if (scope.declaration.parent !== parent) fail("invalid-scope", "Object's choreography scope path does not match host declaration", target.path);
|
|
635
|
+
parent = declaration.identity;
|
|
636
|
+
}
|
|
637
|
+
const member = {
|
|
638
|
+
kind: "object",
|
|
639
|
+
id: target.id,
|
|
640
|
+
order: target.order
|
|
641
|
+
};
|
|
642
|
+
if (parent === void 0) roots.push(member);
|
|
643
|
+
else scopes.get(parent)?.members.push(member);
|
|
644
|
+
}
|
|
645
|
+
roots.sort((left, right) => left.order - right.order);
|
|
646
|
+
for (const scope of scopes.values()) scope.members.sort((left, right) => left.order - right.order);
|
|
647
|
+
const queryDeclarationIndex = /* @__PURE__ */ new Map();
|
|
648
|
+
for (const scope of scopes.values()) queryDeclarationIndex.set(scope.declaration.identity, {
|
|
649
|
+
...scope.declaration.parent === void 0 ? {} : { parent: scope.declaration.parent },
|
|
650
|
+
members: scope.members
|
|
651
|
+
});
|
|
652
|
+
const activeSteps = /* @__PURE__ */ new Map();
|
|
653
|
+
const collectActiveSteps = (identity) => {
|
|
654
|
+
const cached = activeSteps.get(identity);
|
|
655
|
+
if (cached !== void 0) return cached;
|
|
656
|
+
const result = /* @__PURE__ */ new Set();
|
|
657
|
+
activeSteps.set(identity, result);
|
|
658
|
+
const scope = scopes.get(identity);
|
|
659
|
+
if (scope === void 0) return result;
|
|
660
|
+
for (const member of scope.members) if (member.kind === "object") {
|
|
661
|
+
const target = targets.get(member.id);
|
|
662
|
+
if (target !== void 0) result.add(target.stepKey);
|
|
663
|
+
} else for (const key of collectActiveSteps(member.id)) result.add(key);
|
|
664
|
+
return result;
|
|
665
|
+
};
|
|
666
|
+
const scopeSteps = (scope) => {
|
|
667
|
+
const active = [...collectActiveSteps(scope.declaration.identity)];
|
|
668
|
+
return active.length > 0 ? active : [stepKey(scope.declaration.step)];
|
|
669
|
+
};
|
|
670
|
+
const activeMemberSteps = (member) => member.kind === "object" ? [targets.get(member.id)?.stepKey ?? "slide-entry"] : [...collectActiveSteps(member.id)];
|
|
671
|
+
const memberExistsInStep = (member, key) => {
|
|
672
|
+
const memberSteps = activeMemberSteps(member);
|
|
673
|
+
if (memberSteps.length > 0) return memberSteps.includes(key);
|
|
674
|
+
if (member.kind !== "scope") return false;
|
|
675
|
+
const child = scopes.get(member.id);
|
|
676
|
+
return child !== void 0 && stepKey(child.declaration.step) === key;
|
|
677
|
+
};
|
|
678
|
+
const membersInStep = (scope, key) => scope.members.filter((member) => memberExistsInStep(member, key));
|
|
679
|
+
const memberIsActive = (member, key) => activeMemberSteps(member).includes(key);
|
|
680
|
+
const cuePublishers = /* @__PURE__ */ new Map();
|
|
681
|
+
for (const scope of scopes.values()) {
|
|
682
|
+
const keys = scopeSteps(scope);
|
|
683
|
+
if ((scope.declaration.publishStart !== void 0 || scope.declaration.publishEnd !== void 0) && keys.length !== 1) fail("cross-step-motion", "Scope spanning multiple click steps cannot publish a single moment", scope.path);
|
|
684
|
+
for (const [publisher, point] of [[scope.declaration.publishStart, "start"], [scope.declaration.publishEnd, "end"]]) {
|
|
685
|
+
if (publisher === void 0) continue;
|
|
686
|
+
const key = momentKey(publisher);
|
|
687
|
+
if (cuePublishers.has(key)) fail("duplicate-cue", "Same named moment cannot be published twice", scope.path);
|
|
688
|
+
cuePublishers.set(key, {
|
|
689
|
+
scope: scope.declaration.identity,
|
|
690
|
+
point,
|
|
691
|
+
path: scope.path
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const scopeObservations = [];
|
|
696
|
+
const stepStates = /* @__PURE__ */ new Map();
|
|
697
|
+
const registerStep = (key, trigger, number, order) => {
|
|
698
|
+
const existing = stepStates.get(key);
|
|
699
|
+
if (existing === void 0) stepStates.set(key, {
|
|
700
|
+
key,
|
|
701
|
+
trigger,
|
|
702
|
+
...number === void 0 ? {} : { number },
|
|
703
|
+
order
|
|
704
|
+
});
|
|
705
|
+
else existing.order = Math.min(existing.order, order);
|
|
706
|
+
};
|
|
707
|
+
for (const target of targets.values()) registerStep(target.stepKey, target.trigger, target.number, target.order);
|
|
708
|
+
for (const scope of scopes.values()) for (const key of scopeSteps(scope)) {
|
|
709
|
+
const number = key.startsWith("explicit:") ? Number(key.slice(9)) : void 0;
|
|
710
|
+
registerStep(key, key === "slide-entry" ? "auto" : "click", number, scope.order);
|
|
711
|
+
}
|
|
712
|
+
const allScheduledEffects = /* @__PURE__ */ new Map();
|
|
713
|
+
const allStepNodes = /* @__PURE__ */ new Map();
|
|
714
|
+
const querySourcesByStep = /* @__PURE__ */ new Map();
|
|
715
|
+
const allStepConditionDefinitions = /* @__PURE__ */ new Map();
|
|
716
|
+
const addStepEffect = (effect) => {
|
|
717
|
+
const items = allScheduledEffects.get(effect.stepKey) ?? [];
|
|
718
|
+
items.push(effect);
|
|
719
|
+
allScheduledEffects.set(effect.stepKey, items);
|
|
720
|
+
};
|
|
721
|
+
for (const step of stepStates.values()) {
|
|
722
|
+
const key = step.key;
|
|
723
|
+
const facts = new MotionTimingFacts();
|
|
724
|
+
const originEventId = `step-origin:${key}`;
|
|
725
|
+
facts.setExactTime(originEventId, 0, "");
|
|
726
|
+
const origin = eventTime(originEventId, "known", 0, void 0, {
|
|
727
|
+
kind: "parent-start",
|
|
728
|
+
delayMs: 0
|
|
729
|
+
});
|
|
730
|
+
const starts = /* @__PURE__ */ new Map();
|
|
731
|
+
const ends = /* @__PURE__ */ new Map();
|
|
732
|
+
const scopeStartExpressions = /* @__PURE__ */ new Map();
|
|
733
|
+
const scopeCompletionMembers = /* @__PURE__ */ new Map();
|
|
734
|
+
const scopeStartPlans = /* @__PURE__ */ new Map();
|
|
735
|
+
const conditionJoinsById = /* @__PURE__ */ new Map();
|
|
736
|
+
const conditionPlacementsByHost = /* @__PURE__ */ new Map();
|
|
737
|
+
const conditionStartsByEventId = /* @__PURE__ */ new Map();
|
|
738
|
+
const resolvingStarts = /* @__PURE__ */ new Set();
|
|
739
|
+
const resolvingEnds = /* @__PURE__ */ new Set();
|
|
740
|
+
const scheduledObjects = /* @__PURE__ */ new Set();
|
|
741
|
+
const queryScopes = [];
|
|
742
|
+
const queryEffectSources = /* @__PURE__ */ new Map();
|
|
743
|
+
const queryScopeIdentities = /* @__PURE__ */ new Set();
|
|
744
|
+
for (const scope of scopes.values()) {
|
|
745
|
+
if (!scopeSteps(scope).includes(key)) continue;
|
|
746
|
+
let identity = scope.declaration.identity;
|
|
747
|
+
while (identity !== void 0 && !queryScopeIdentities.has(identity)) {
|
|
748
|
+
queryScopeIdentities.add(identity);
|
|
749
|
+
identity = queryDeclarationIndex.get(identity)?.parent;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
const queryDeclarationMembers = (scope) => queryDeclarationIndex.get(scope.declaration.identity)?.members.filter((member) => member.kind === "scope" ? queryScopeIdentities.has(member.id) : memberIsActive(member, key)) ?? [];
|
|
753
|
+
const projectedNodeHosts = /* @__PURE__ */ new Map();
|
|
754
|
+
const projectedEndHosts = /* @__PURE__ */ new Map();
|
|
755
|
+
const preservedScopeStarts = /* @__PURE__ */ new Set();
|
|
756
|
+
let projectionChanged = false;
|
|
757
|
+
const directMemberForScope = (host, identity) => {
|
|
758
|
+
let current = scopes.get(identity);
|
|
759
|
+
if (current === void 0 || current.declaration.parent === void 0) return;
|
|
760
|
+
while (current.declaration.parent !== host.declaration.identity) {
|
|
761
|
+
const parentId = current.declaration.parent;
|
|
762
|
+
if (parentId === void 0) return void 0;
|
|
763
|
+
const parent = scopes.get(parentId);
|
|
764
|
+
if (parent === void 0 || parent.declaration.parent === void 0) return;
|
|
765
|
+
current = parent;
|
|
766
|
+
}
|
|
767
|
+
return host.members.findIndex((member) => member.kind === "scope" && member.id === current.declaration.identity);
|
|
768
|
+
};
|
|
769
|
+
const directMemberForDependency = (host, dependency) => {
|
|
770
|
+
if ("scopeId" in dependency) {
|
|
771
|
+
const source = [...scopes.values()].find((scope) => scopeId(scope.declaration.identity, scopes) === dependency.scopeId);
|
|
772
|
+
return source === void 0 ? void 0 : directMemberForScope(host, source.declaration.identity);
|
|
773
|
+
}
|
|
774
|
+
const source = targets.get(dependency.targetId);
|
|
775
|
+
if (source === void 0) return void 0;
|
|
776
|
+
const containingScope = source.value.scopes.at(-1)?.identity;
|
|
777
|
+
if (containingScope === host.declaration.identity) return host.members.findIndex((member) => member.kind === "object" && member.id === source.id);
|
|
778
|
+
return containingScope === void 0 ? void 0 : directMemberForScope(host, containingScope);
|
|
779
|
+
};
|
|
780
|
+
const rootMemberForScope = (identity) => {
|
|
781
|
+
let current = scopes.get(identity);
|
|
782
|
+
while (current?.declaration.parent !== void 0) current = scopes.get(current.declaration.parent);
|
|
783
|
+
if (current === void 0 || !scopeSteps(current).includes(key)) return;
|
|
784
|
+
return roots.find((member) => member.kind === "scope" && member.id === current?.declaration.identity);
|
|
785
|
+
};
|
|
786
|
+
const rootMemberForTarget = (target) => {
|
|
787
|
+
const containingScope = target.value.scopes.at(-1)?.identity;
|
|
788
|
+
if (containingScope !== void 0) return rootMemberForScope(containingScope);
|
|
789
|
+
return target.stepKey === key ? roots.find((member) => member.kind === "object" && member.id === target.id) : void 0;
|
|
790
|
+
};
|
|
791
|
+
const directRootMemberForDependency = (dependency) => {
|
|
792
|
+
if ("scopeId" in dependency) {
|
|
793
|
+
const source = scopeForPlanId(dependency.scopeId);
|
|
794
|
+
return source === void 0 ? void 0 : rootMemberForScope(source.declaration.identity);
|
|
795
|
+
}
|
|
796
|
+
const source = targets.get(dependency.targetId);
|
|
797
|
+
return source === void 0 ? void 0 : rootMemberForTarget(source);
|
|
798
|
+
};
|
|
799
|
+
const directRootMemberForConsumer = (consumer) => {
|
|
800
|
+
if (consumer.kind === "scope") return rootMemberForScope(consumer.id);
|
|
801
|
+
const target = targets.get(consumer.id);
|
|
802
|
+
return target === void 0 ? void 0 : rootMemberForTarget(target);
|
|
803
|
+
};
|
|
804
|
+
const memberNodeId = (member) => member.kind === "scope" ? `scope:${scopeId(member.id, scopes)}` : `target:${member.id}`;
|
|
805
|
+
const directConsumerAtHost = (candidateHost, actualParent, consumer) => {
|
|
806
|
+
if (candidateHost.declaration.identity === actualParent.declaration.identity) return consumer;
|
|
807
|
+
let current = consumer.kind === "scope" ? scopes.get(consumer.id) : actualParent;
|
|
808
|
+
while (current !== void 0 && current.declaration.parent !== candidateHost.declaration.identity) {
|
|
809
|
+
const parentId = current.declaration.parent;
|
|
810
|
+
if (parentId === void 0) return void 0;
|
|
811
|
+
current = scopes.get(parentId);
|
|
812
|
+
}
|
|
813
|
+
return current === void 0 ? void 0 : {
|
|
814
|
+
kind: "scope",
|
|
815
|
+
id: current.declaration.identity,
|
|
816
|
+
order: current.order
|
|
817
|
+
};
|
|
818
|
+
};
|
|
819
|
+
const strictlyAfterParentStart = (candidates, parentStart) => {
|
|
820
|
+
if (parentStart.state === "no-natural-completion") return false;
|
|
821
|
+
if (parentStart.state === "known") return candidates.some((candidate) => {
|
|
822
|
+
const earliestTime = facts.earliestTime(candidate.eventId, originEventId);
|
|
823
|
+
return earliestTime !== void 0 && earliestTime + candidate.offsetMs > parentStart.timeMs;
|
|
824
|
+
});
|
|
825
|
+
if (parentStart.candidates.length === 0) return false;
|
|
826
|
+
return parentStart.candidates.every((parentCandidate) => candidates.some((candidate) => {
|
|
827
|
+
const lowerBound = facts.lowerBound(parentCandidate.eventId, candidate.eventId);
|
|
828
|
+
return lowerBound !== void 0 && lowerBound + candidate.offsetMs - parentCandidate.offsetMs > 0;
|
|
829
|
+
}));
|
|
830
|
+
};
|
|
831
|
+
const resolveNativeStart = (expression, parentStart, path, eventId, hostScope, consumer) => {
|
|
832
|
+
if (expression.state === "no-natural-completion") fail("no-natural-completion", "Content without natural completion cannot start subsequent effects", path);
|
|
833
|
+
if (parentStart.state === "no-natural-completion") fail("no-natural-completion", "Parent scope without natural completion cannot start subsequent effects", path);
|
|
834
|
+
if (expression.state === "known") {
|
|
835
|
+
if (parentStart.state !== "known") fail("unknown-motion-start", "Numeric start after unknown parent start has no verifiable merge relation", path);
|
|
836
|
+
const delayMs = expression.timeMs - parentStart.timeMs;
|
|
837
|
+
if (delayMs < 0) fail("unknown-motion-start", "Child start is earlier than its containing scope", path);
|
|
838
|
+
const lowered = addMotionPlanStartDelay({
|
|
839
|
+
kind: "parent-start",
|
|
840
|
+
delayMs: 0
|
|
841
|
+
}, delayMs);
|
|
842
|
+
if (lowered === void 0) fail("invalid-motion-time", "Delay layer of known start cannot be preserved as safe integer in milliseconds", path);
|
|
843
|
+
return lowered;
|
|
844
|
+
}
|
|
845
|
+
const parentStartDelay = commonCandidateOffset(expression.candidates, parentStart.candidates);
|
|
846
|
+
if (parentStartDelay !== void 0 && parentStartDelay >= 0) {
|
|
847
|
+
const lowered = addMotionPlanStartDelay({
|
|
848
|
+
kind: "parent-start",
|
|
849
|
+
delayMs: 0
|
|
850
|
+
}, parentStartDelay);
|
|
851
|
+
if (lowered !== void 0) return lowered;
|
|
852
|
+
}
|
|
853
|
+
for (const reference of expression.references) {
|
|
854
|
+
const canonical = conditionStartsByEventId.get(reference.eventId);
|
|
855
|
+
if (canonical === void 0) continue;
|
|
856
|
+
const delayMs = commonCandidateOffset(expression.candidates, canonical.candidates);
|
|
857
|
+
if (delayMs === void 0 || delayMs !== reference.offsetMs) continue;
|
|
858
|
+
const canonicalDelay = canonical.delayLayers.reduce((total, delay) => total + delay, 0);
|
|
859
|
+
if (!Number.isSafeInteger(canonicalDelay)) continue;
|
|
860
|
+
if (!canonical.candidates.map((candidate) => ({
|
|
861
|
+
...candidate,
|
|
862
|
+
offsetMs: candidate.offsetMs - canonicalDelay
|
|
863
|
+
})).some((candidate) => {
|
|
864
|
+
if (parentStart.state === "known") {
|
|
865
|
+
const earliestTime = facts.earliestTime(candidate.eventId, originEventId);
|
|
866
|
+
return earliestTime !== void 0 && earliestTime + candidate.offsetMs > parentStart.timeMs;
|
|
867
|
+
}
|
|
868
|
+
return parentStart.candidates.length > 0 && parentStart.candidates.every((parentCandidate) => {
|
|
869
|
+
const lowerBound = facts.lowerBound(parentCandidate.eventId, candidate.eventId);
|
|
870
|
+
return lowerBound !== void 0 && lowerBound + candidate.offsetMs - parentCandidate.offsetMs > 0;
|
|
871
|
+
});
|
|
872
|
+
})) continue;
|
|
873
|
+
let conditionEndStart = {
|
|
874
|
+
kind: "condition-end",
|
|
875
|
+
id: canonical.id,
|
|
876
|
+
delayMs: 0
|
|
877
|
+
};
|
|
878
|
+
for (const delay of canonical.delayLayers) {
|
|
879
|
+
const next = addMotionPlanStartDelay(conditionEndStart, delay);
|
|
880
|
+
if (next === void 0) break;
|
|
881
|
+
conditionEndStart = next;
|
|
882
|
+
}
|
|
883
|
+
const lowered = addMotionPlanStartDelay(conditionEndStart, delayMs);
|
|
884
|
+
if (lowered !== void 0) return lowered;
|
|
885
|
+
}
|
|
886
|
+
if (expression.candidates.length !== 1) {
|
|
887
|
+
const startCandidates = expression.candidates.flatMap((candidate) => expandStartCandidate(candidate));
|
|
888
|
+
const unsupported = (reason) => fail("unknown-motion-start", `Multiple incomparable unknown starts do not satisfy verified condition collection prerequisites: ${reason}`, path);
|
|
889
|
+
if (consumer === void 0) return unsupported("Requires real consumer member in the same step");
|
|
890
|
+
const candidateHosts = [];
|
|
891
|
+
let currentHost = hostScope;
|
|
892
|
+
while (currentHost !== void 0) {
|
|
893
|
+
candidateHosts.push(currentHost);
|
|
894
|
+
const parentId = currentHost.declaration.parent;
|
|
895
|
+
currentHost = parentId === void 0 ? void 0 : scopes.get(parentId);
|
|
896
|
+
}
|
|
897
|
+
candidateHosts.push(void 0);
|
|
898
|
+
let lastReason = "No real host can define all sources beforehand";
|
|
899
|
+
for (const host of candidateHosts) {
|
|
900
|
+
const isStepRoot = host === void 0;
|
|
901
|
+
const hostIdentity = host?.declaration.identity ?? stepRootHostIdentity;
|
|
902
|
+
const rootMembers = roots.filter((member) => memberExistsInStep(member, key));
|
|
903
|
+
const consumerBranch = isStepRoot ? directRootMemberForConsumer(consumer) : hostScope === void 0 ? void 0 : directConsumerAtHost(host, hostScope, consumer);
|
|
904
|
+
if (consumerBranch === void 0) {
|
|
905
|
+
lastReason = "Cannot locate actual position of consumer member in candidate host";
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
const hostMembers = isStepRoot ? rootMembers : host.members;
|
|
909
|
+
const consumerIndex = hostMembers.findIndex((member) => member.kind === consumerBranch.kind && member.id === consumerBranch.id);
|
|
910
|
+
if (consumerIndex < 0) {
|
|
911
|
+
lastReason = "Cannot locate actual consumer member";
|
|
912
|
+
continue;
|
|
913
|
+
}
|
|
914
|
+
const hostStart = isStepRoot ? origin : resolveScopeStart(host);
|
|
915
|
+
if (hostStart.state === "no-natural-completion") {
|
|
916
|
+
lastReason = "Candidate host has no subscribable start";
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
const gates = [];
|
|
920
|
+
const subscribedSources = [];
|
|
921
|
+
let validHost = true;
|
|
922
|
+
let requiresProjection = false;
|
|
923
|
+
const appendGateStart = (start, sourceDependency) => {
|
|
924
|
+
if (start.kind === "delay-layer") {
|
|
925
|
+
gates.push({
|
|
926
|
+
kind: "plan-start",
|
|
927
|
+
start,
|
|
928
|
+
...sourceDependency === void 0 ? {} : { sourceDependency }
|
|
929
|
+
});
|
|
930
|
+
return true;
|
|
931
|
+
}
|
|
932
|
+
if (start.kind === "parent-start") {
|
|
933
|
+
gates.push({
|
|
934
|
+
kind: "parent-start",
|
|
935
|
+
delayMs: start.delayMs,
|
|
936
|
+
...sourceDependency === void 0 ? {} : { sourceDependency }
|
|
937
|
+
});
|
|
938
|
+
return true;
|
|
939
|
+
}
|
|
940
|
+
if (start.kind === "end") {
|
|
941
|
+
gates.push({
|
|
942
|
+
kind: "end",
|
|
943
|
+
dependency: start.dependency
|
|
944
|
+
});
|
|
945
|
+
return true;
|
|
946
|
+
}
|
|
947
|
+
if (start.kind === "event") {
|
|
948
|
+
gates.push({
|
|
949
|
+
kind: "begin",
|
|
950
|
+
dependency: start.dependency
|
|
951
|
+
});
|
|
952
|
+
return true;
|
|
953
|
+
}
|
|
954
|
+
return false;
|
|
955
|
+
};
|
|
956
|
+
for (const candidate of startCandidates) {
|
|
957
|
+
let dependency = candidate.dependency;
|
|
958
|
+
if (candidate.eventId === parentStart.eventId && !isStepRoot && hostScope !== void 0 && host.declaration.identity !== hostScope.declaration.identity) dependency = {
|
|
959
|
+
scopeId: scopeId(hostScope.declaration.identity, scopes),
|
|
960
|
+
point: "start",
|
|
961
|
+
offsetMs: candidate.offsetMs
|
|
962
|
+
};
|
|
963
|
+
if (!Number.isSafeInteger(candidate.offsetMs) || candidate.offsetMs < 0) {
|
|
964
|
+
lastReason = "Completion offset exceeds safe integer range";
|
|
965
|
+
validHost = false;
|
|
966
|
+
break;
|
|
967
|
+
}
|
|
968
|
+
if (candidate.eventId === hostStart.eventId) {
|
|
969
|
+
const lowered = addMotionPlanStartDelay({
|
|
970
|
+
kind: "parent-start",
|
|
971
|
+
delayMs: 0
|
|
972
|
+
}, candidate.offsetMs);
|
|
973
|
+
if (lowered === void 0 || !appendGateStart(lowered)) {
|
|
974
|
+
lastReason = "Parent start candidate cannot be preserved as safe integer delay layer";
|
|
975
|
+
validHost = false;
|
|
976
|
+
break;
|
|
977
|
+
}
|
|
978
|
+
continue;
|
|
979
|
+
}
|
|
980
|
+
const exactHostOffset = facts.exactOffset(hostStart.eventId, candidate.eventId);
|
|
981
|
+
if (exactHostOffset !== void 0) {
|
|
982
|
+
const delayMs = exactHostOffset + candidate.offsetMs;
|
|
983
|
+
if (!Number.isSafeInteger(delayMs)) {
|
|
984
|
+
lastReason = "Exact host cumulative offset exceeds safe integer range";
|
|
985
|
+
validHost = false;
|
|
986
|
+
break;
|
|
987
|
+
}
|
|
988
|
+
if (delayMs >= 0) {
|
|
989
|
+
const lowered = addMotionPlanStartDelay({
|
|
990
|
+
kind: "parent-start",
|
|
991
|
+
delayMs: 0
|
|
992
|
+
}, delayMs);
|
|
993
|
+
const sourceDependencyAtCandidate = dependency === void 0 ? void 0 : dependencyAtEvent(dependency, candidate.offsetMs);
|
|
994
|
+
if (lowered === void 0 || !appendGateStart(lowered, sourceDependencyAtCandidate)) {
|
|
995
|
+
lastReason = "Exact host cumulative offset cannot be preserved as safe integer delay layer";
|
|
996
|
+
validHost = false;
|
|
997
|
+
break;
|
|
998
|
+
}
|
|
999
|
+
continue;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
if (exactHostOffset !== void 0 && exactHostOffset < 0) {
|
|
1003
|
+
lastReason = "Candidate source is already earlier than host activation and cannot fold into a legal offset";
|
|
1004
|
+
validHost = false;
|
|
1005
|
+
break;
|
|
1006
|
+
}
|
|
1007
|
+
if (dependency === void 0) {
|
|
1008
|
+
const sourceStart = scopeForStartEvent(candidate.eventId);
|
|
1009
|
+
if (sourceStart !== void 0) dependency = {
|
|
1010
|
+
scopeId: scopeId(sourceStart.declaration.identity, scopes),
|
|
1011
|
+
point: "start",
|
|
1012
|
+
offsetMs: candidate.offsetMs
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
if (dependency === void 0 || !dependencyMatchesEvent(dependency, candidate.eventId)) {
|
|
1016
|
+
lastReason = "Sources outside candidate host start have no real subscribable events";
|
|
1017
|
+
validHost = false;
|
|
1018
|
+
break;
|
|
1019
|
+
}
|
|
1020
|
+
if ((isStepRoot ? (() => {
|
|
1021
|
+
const sourceBranch = directRootMemberForDependency(dependency);
|
|
1022
|
+
return sourceBranch === void 0 ? -1 : hostMembers.findIndex((member) => member.kind === sourceBranch.kind && member.id === sourceBranch.id);
|
|
1023
|
+
})() : directMemberForDependency(host, dependency)) === consumerIndex) requiresProjection = true;
|
|
1024
|
+
if ("scopeId" in dependency && dependency.point === "end") {
|
|
1025
|
+
const sourceScope = scopeForPlanId(dependency.scopeId);
|
|
1026
|
+
if (isStepRoot) {
|
|
1027
|
+
if (sourceScope !== void 0 && hostScope !== void 0 && isAncestorScope(sourceScope, hostScope)) {
|
|
1028
|
+
lastReason = "Overall completion of source would wait for its inner host to finish";
|
|
1029
|
+
validHost = false;
|
|
1030
|
+
break;
|
|
1031
|
+
}
|
|
1032
|
+
} else {
|
|
1033
|
+
let current = host;
|
|
1034
|
+
while (sourceScope !== void 0) {
|
|
1035
|
+
if (current.declaration.identity === sourceScope.declaration.identity) {
|
|
1036
|
+
lastReason = "Overall completion of source would wait for its inner host to finish";
|
|
1037
|
+
validHost = false;
|
|
1038
|
+
break;
|
|
1039
|
+
}
|
|
1040
|
+
const parentId = current.declaration.parent;
|
|
1041
|
+
if (parentId === void 0) break;
|
|
1042
|
+
const parent = scopes.get(parentId);
|
|
1043
|
+
if (parent === void 0) break;
|
|
1044
|
+
current = parent;
|
|
1045
|
+
}
|
|
1046
|
+
if (!validHost) break;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
const sourceAfterHost = facts.lowerBound(hostStart.eventId, candidate.eventId) ?? (hostStart.state === "known" ? (facts.earliestTime(candidate.eventId, originEventId) ?? Number.NEGATIVE_INFINITY) - hostStart.timeMs : void 0);
|
|
1050
|
+
if (sourceAfterHost === void 0 || sourceAfterHost <= 0) {
|
|
1051
|
+
lastReason = dependency.point === "end" ? "Cannot prove real source end is later than candidate host activation" : "Cannot prove real start event is later than candidate host activation";
|
|
1052
|
+
validHost = false;
|
|
1053
|
+
break;
|
|
1054
|
+
}
|
|
1055
|
+
const lowered = addMotionPlanStartDelay(dependency.point === "start" ? {
|
|
1056
|
+
kind: "event",
|
|
1057
|
+
dependency: dependencyAtEvent(dependency)
|
|
1058
|
+
} : {
|
|
1059
|
+
kind: "end",
|
|
1060
|
+
dependency: dependencyAtEvent(dependency)
|
|
1061
|
+
}, candidate.offsetMs);
|
|
1062
|
+
if (lowered === void 0 || !appendGateStart(lowered)) {
|
|
1063
|
+
lastReason = "Completion dependency cannot be preserved as safe integer delay layer";
|
|
1064
|
+
validHost = false;
|
|
1065
|
+
break;
|
|
1066
|
+
}
|
|
1067
|
+
subscribedSources.push({
|
|
1068
|
+
...candidate,
|
|
1069
|
+
offsetMs: 0
|
|
1070
|
+
});
|
|
1071
|
+
if (dependency.point === "start") {
|
|
1072
|
+
const sourceScope = scopeForPlanId(dependency.scopeId);
|
|
1073
|
+
if (sourceScope !== void 0) preservedScopeStarts.add(sourceScope.declaration.identity);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
if (!validHost) continue;
|
|
1077
|
+
if (!isStepRoot && hostScope !== void 0 && host.declaration.identity !== hostScope.declaration.identity && !strictlyAfterParentStart(startCandidates, parentStart)) requiresProjection = true;
|
|
1078
|
+
if (isStepRoot && hostScope !== void 0) requiresProjection = true;
|
|
1079
|
+
const consumerActivation = requiresProjection && (isStepRoot || hostScope !== void 0 && host.declaration.identity !== hostScope.declaration.identity) ? isStepRoot ? hostStart : memberStart(host, consumerBranch) : requiresProjection ? hostStart : parentStart;
|
|
1080
|
+
if (requiresProjection && subscribedSources.length > 0 && !strictlyAfterParentStart(subscribedSources, consumerActivation)) {
|
|
1081
|
+
lastReason = "Cannot prove condition collection completion is later than consumer member parent scope activation: real source occurred before actual condition host activation";
|
|
1082
|
+
continue;
|
|
1083
|
+
}
|
|
1084
|
+
if (!strictlyAfterParentStart(startCandidates, consumerActivation)) {
|
|
1085
|
+
lastReason = "Cannot prove condition collection completion is later than consumer member parent scope activation";
|
|
1086
|
+
continue;
|
|
1087
|
+
}
|
|
1088
|
+
const projectedConsumerId = memberNodeId(consumer);
|
|
1089
|
+
if (requiresProjection) {
|
|
1090
|
+
const previousHost = projectedNodeHosts.get(projectedConsumerId);
|
|
1091
|
+
if (previousHost !== void 0 && previousHost !== hostIdentity) {
|
|
1092
|
+
lastReason = "Same consumer node requires multiple physical early hosts";
|
|
1093
|
+
continue;
|
|
1094
|
+
}
|
|
1095
|
+
projectedNodeHosts.set(projectedConsumerId, hostIdentity);
|
|
1096
|
+
if (isStepRoot) {
|
|
1097
|
+
if (hostScope !== void 0) markProjectedAncestorsAtStepRoot(hostScope);
|
|
1098
|
+
} else if (hostScope !== void 0) markProjectedAncestors(hostScope, host);
|
|
1099
|
+
}
|
|
1100
|
+
const join = {
|
|
1101
|
+
kind: "condition-join",
|
|
1102
|
+
id: eventId,
|
|
1103
|
+
hostScopeId: isStepRoot ? stepRootHostIdentity : scopeId(host.declaration.identity, scopes),
|
|
1104
|
+
consumerParentScopeId: requiresProjection || hostScope === void 0 ? hostIdentity : scopeId(hostScope.declaration.identity, scopes),
|
|
1105
|
+
beforeNodeId: memberNodeId(requiresProjection ? consumer : consumerBranch),
|
|
1106
|
+
gates
|
|
1107
|
+
};
|
|
1108
|
+
conditionJoinsById.set(join.id, join);
|
|
1109
|
+
return join;
|
|
1110
|
+
}
|
|
1111
|
+
return unsupported(lastReason);
|
|
1112
|
+
}
|
|
1113
|
+
const [candidate] = expression.candidates;
|
|
1114
|
+
if (candidate === void 0) fail("unknown-motion-start", "Unknown start has no single native completion event to reference", path);
|
|
1115
|
+
if (candidate.eventId === parentStart.eventId) {
|
|
1116
|
+
const lowered = addMotionPlanStartDelay({
|
|
1117
|
+
kind: "parent-start",
|
|
1118
|
+
delayMs: 0
|
|
1119
|
+
}, candidate.offsetMs);
|
|
1120
|
+
if (lowered !== void 0) return lowered;
|
|
1121
|
+
}
|
|
1122
|
+
if (parentStart.nativeStart?.kind === "end" && dependencyEventId(parentStart.nativeStart.dependency) === candidate.eventId) {
|
|
1123
|
+
const delayMs = candidate.offsetMs - parentStart.nativeStart.dependency.offsetMs;
|
|
1124
|
+
if (delayMs >= 0) {
|
|
1125
|
+
const lowered = addMotionPlanStartDelay({
|
|
1126
|
+
kind: "parent-start",
|
|
1127
|
+
delayMs: 0
|
|
1128
|
+
}, delayMs);
|
|
1129
|
+
if (lowered !== void 0) return lowered;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
const sourceStart = scopeForStartEvent(candidate.eventId);
|
|
1133
|
+
if (sourceStart !== void 0 && candidate.dependency === void 0) {
|
|
1134
|
+
const dependency = {
|
|
1135
|
+
scopeId: scopeId(sourceStart.declaration.identity, scopes),
|
|
1136
|
+
point: "start",
|
|
1137
|
+
offsetMs: candidate.offsetMs
|
|
1138
|
+
};
|
|
1139
|
+
const eventAfterParent = facts.lowerBound(parentStart.eventId, candidate.eventId);
|
|
1140
|
+
if (eventAfterParent !== void 0 && eventAfterParent > 0) {
|
|
1141
|
+
preservedScopeStarts.add(sourceStart.declaration.identity);
|
|
1142
|
+
const lowered = addMotionPlanStartDelay({
|
|
1143
|
+
kind: "event",
|
|
1144
|
+
dependency: {
|
|
1145
|
+
...dependency,
|
|
1146
|
+
offsetMs: 0
|
|
1147
|
+
}
|
|
1148
|
+
}, candidate.offsetMs);
|
|
1149
|
+
if (lowered !== void 0) return lowered;
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
const eventAfterParent = parentStart.eventId === void 0 ? void 0 : facts.lowerBound(parentStart.eventId, candidate.eventId);
|
|
1153
|
+
const eventAfterKnownParent = parentStart.state === "known" ? facts.earliestTime(candidate.eventId, originEventId) : void 0;
|
|
1154
|
+
const knownParentTime = parentStart.state === "known" ? parentStart.timeMs : void 0;
|
|
1155
|
+
if (candidate.dependency !== void 0 && (eventAfterParent !== void 0 && eventAfterParent > 0 || eventAfterKnownParent !== void 0 && knownParentTime !== void 0 && eventAfterKnownParent > knownParentTime)) {
|
|
1156
|
+
const lowered = addMotionPlanStartDelay(candidate.dependency.point === "start" ? {
|
|
1157
|
+
kind: "event",
|
|
1158
|
+
dependency: {
|
|
1159
|
+
...candidate.dependency,
|
|
1160
|
+
offsetMs: 0
|
|
1161
|
+
}
|
|
1162
|
+
} : {
|
|
1163
|
+
kind: "end",
|
|
1164
|
+
dependency: {
|
|
1165
|
+
...candidate.dependency,
|
|
1166
|
+
offsetMs: 0
|
|
1167
|
+
}
|
|
1168
|
+
}, candidate.offsetMs);
|
|
1169
|
+
if (lowered !== void 0) return lowered;
|
|
1170
|
+
}
|
|
1171
|
+
const exactParentOffset = facts.exactOffset(candidate.eventId, parentStart.eventId);
|
|
1172
|
+
if (exactParentOffset !== void 0 && candidate.offsetMs >= exactParentOffset) {
|
|
1173
|
+
const lowered = addMotionPlanStartDelay({
|
|
1174
|
+
kind: "parent-start",
|
|
1175
|
+
delayMs: 0
|
|
1176
|
+
}, candidate.offsetMs - exactParentOffset);
|
|
1177
|
+
if (lowered !== void 0) return lowered;
|
|
1178
|
+
}
|
|
1179
|
+
fail("unknown-motion-start", "Unknown start has no provable parent activation or completion event source", path);
|
|
1180
|
+
};
|
|
1181
|
+
const reportedDependency = (nativeStart, parentStart) => {
|
|
1182
|
+
if (nativeStart.kind === "delay-layer") {
|
|
1183
|
+
const inherited = reportedDependency(nativeStart.start, parentStart);
|
|
1184
|
+
return inherited === void 0 ? void 0 : dependencyAtEvent(inherited, inherited.offsetMs + nativeStart.delayMs);
|
|
1185
|
+
}
|
|
1186
|
+
if (nativeStart.kind === "end" || nativeStart.kind === "event") return nativeStart.dependency;
|
|
1187
|
+
if (nativeStart.kind !== "parent-start") return void 0;
|
|
1188
|
+
if (parentStart.state === "no-natural-completion") return void 0;
|
|
1189
|
+
const inherited = parentStart.reportedStartAfter;
|
|
1190
|
+
return inherited === void 0 ? void 0 : dependencyAtEvent(inherited, inherited.offsetMs + nativeStart.delayMs);
|
|
1191
|
+
};
|
|
1192
|
+
const reportedDependencies = (nativeStart, parentStart) => {
|
|
1193
|
+
if (nativeStart.kind === "delay-layer") {
|
|
1194
|
+
const inherited = reportedDependencies(nativeStart.start, parentStart);
|
|
1195
|
+
return inherited === void 0 ? void 0 : Object.freeze(inherited.map((dependency) => dependencyAtEvent(dependency, dependency.offsetMs + nativeStart.delayMs)));
|
|
1196
|
+
}
|
|
1197
|
+
const expandStartDependency = (dependency, seen = /* @__PURE__ */ new Set()) => {
|
|
1198
|
+
if (!("scopeId" in dependency) || dependency.point !== "start") return [dependency];
|
|
1199
|
+
const source = scopeForPlanId(dependency.scopeId);
|
|
1200
|
+
if (source === void 0 || seen.has(source.declaration.identity)) return [dependency];
|
|
1201
|
+
const original = scopeStartExpressions.get(source.declaration.identity);
|
|
1202
|
+
if (original === void 0 || original.state === "no-natural-completion") return [dependency];
|
|
1203
|
+
const nextSeen = new Set(seen);
|
|
1204
|
+
nextSeen.add(source.declaration.identity);
|
|
1205
|
+
return original.candidates.flatMap((candidate) => {
|
|
1206
|
+
let sourceDependency = candidate.dependency;
|
|
1207
|
+
if (sourceDependency === void 0) {
|
|
1208
|
+
const sourceStart = scopeForStartEvent(candidate.eventId);
|
|
1209
|
+
if (sourceStart !== void 0) sourceDependency = {
|
|
1210
|
+
scopeId: scopeId(sourceStart.declaration.identity, scopes),
|
|
1211
|
+
point: "start",
|
|
1212
|
+
offsetMs: 0
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
if (sourceDependency === void 0) return [dependency];
|
|
1216
|
+
return expandStartDependency(dependencyAtEvent(sourceDependency, candidate.offsetMs + dependency.offsetMs), nextSeen);
|
|
1217
|
+
});
|
|
1218
|
+
};
|
|
1219
|
+
const reportedGateDependencies = (gate, hostScopeId) => {
|
|
1220
|
+
if (gate.kind === "end") return [gate.dependency];
|
|
1221
|
+
if (gate.kind === "begin") return expandStartDependency(gate.dependency);
|
|
1222
|
+
if (gate.kind === "parent-start") return gate.sourceDependency === void 0 ? [{
|
|
1223
|
+
scopeId: hostScopeId,
|
|
1224
|
+
point: "start",
|
|
1225
|
+
offsetMs: gate.delayMs
|
|
1226
|
+
}] : expandStartDependency(gate.sourceDependency);
|
|
1227
|
+
if (gate.sourceDependency !== void 0) return expandStartDependency(gate.sourceDependency);
|
|
1228
|
+
const { base, delays } = motionPlanStartLayers(gate.start);
|
|
1229
|
+
if (base.kind === "parent-start") return [{
|
|
1230
|
+
scopeId: hostScopeId,
|
|
1231
|
+
point: "start",
|
|
1232
|
+
offsetMs: base.delayMs + delays.reduce((total, delayMs) => total + delayMs, 0)
|
|
1233
|
+
}];
|
|
1234
|
+
return reportedDependencies(gate.start, parentStart) ?? [];
|
|
1235
|
+
};
|
|
1236
|
+
if (nativeStart.kind === "end" || nativeStart.kind === "event") return Object.freeze(expandStartDependency(nativeStart.dependency));
|
|
1237
|
+
if (nativeStart.kind === "condition-join") {
|
|
1238
|
+
const dependencies = nativeStart.gates.flatMap((gate) => reportedGateDependencies(gate, nativeStart.hostScopeId));
|
|
1239
|
+
return Object.freeze(dependencies);
|
|
1240
|
+
}
|
|
1241
|
+
if (nativeStart.kind === "condition-end") {
|
|
1242
|
+
const canonical = conditionJoinsById.get(nativeStart.id);
|
|
1243
|
+
if (canonical === void 0) throw new Error("MotionPlan condition alias lacks original condition collection");
|
|
1244
|
+
const dependencies = canonical.gates.flatMap((gate) => reportedGateDependencies(gate, canonical.hostScopeId));
|
|
1245
|
+
return Object.freeze(dependencies.map((dependency) => dependencyAtEvent(dependency, dependency.offsetMs + nativeStart.delayMs)));
|
|
1246
|
+
}
|
|
1247
|
+
if (nativeStart.kind !== "parent-start") return void 0;
|
|
1248
|
+
if (parentStart.state === "no-natural-completion") return void 0;
|
|
1249
|
+
const inherited = parentStart.reportedStartAfterAll;
|
|
1250
|
+
if (inherited === void 0) return void 0;
|
|
1251
|
+
return Object.freeze(inherited.map((dependency) => dependencyAtEvent(dependency, dependency.offsetMs + nativeStart.delayMs)));
|
|
1252
|
+
};
|
|
1253
|
+
const pointExpression = (point) => asExpression(point);
|
|
1254
|
+
const scopeStartEventId = (scope) => `scope-start:${scope.declaration.identity}`;
|
|
1255
|
+
const stepKeysOf = (scope) => scopeSteps(scope);
|
|
1256
|
+
const ensureSingleStep = (scope) => {
|
|
1257
|
+
if (stepKeysOf(scope).length !== 1) fail("cross-step-motion", "Moment of a single choreography scope cannot be determined across click steps", scope.path);
|
|
1258
|
+
};
|
|
1259
|
+
const resolveMoment = (reference, fromPath) => {
|
|
1260
|
+
const owner = scopes.get(reference.scope);
|
|
1261
|
+
if (owner === void 0) fail("missing-cue", "Choreography scope corresponding to moment handle does not exist", fromPath);
|
|
1262
|
+
ensureSingleStep(owner);
|
|
1263
|
+
if (scopeSteps(owner)[0] !== key) fail("cross-step-motion", "Moment dependencies cannot cross different click steps", fromPath);
|
|
1264
|
+
let sourceScope = owner;
|
|
1265
|
+
let point = reference.point === "end" ? "end" : "start";
|
|
1266
|
+
if (reference.point === "named") {
|
|
1267
|
+
const publisher = cuePublishers.get(momentKey(reference));
|
|
1268
|
+
if (publisher === void 0) fail("missing-cue", `No component published named moment ${reference.name ?? ""}`, fromPath);
|
|
1269
|
+
const publishedScope = scopes.get(publisher.scope);
|
|
1270
|
+
if (publishedScope === void 0) fail("missing-cue", "Publishing scope for named moment does not exist", publisher.path);
|
|
1271
|
+
ensureSingleStep(publishedScope);
|
|
1272
|
+
if (scopeSteps(publishedScope)[0] !== key) fail("cross-step-motion", "Named moment dependencies cannot cross different click steps", fromPath);
|
|
1273
|
+
sourceScope = publishedScope;
|
|
1274
|
+
point = publisher.point;
|
|
1275
|
+
}
|
|
1276
|
+
if (point === "start") {
|
|
1277
|
+
const expression = asExpression(resolveScopeStart(sourceScope));
|
|
1278
|
+
const original = scopeStartExpressions.get(sourceScope.declaration.identity);
|
|
1279
|
+
if (activeChildren(sourceScope).length === 0) {
|
|
1280
|
+
preservedScopeStarts.add(sourceScope.declaration.identity);
|
|
1281
|
+
return expression;
|
|
1282
|
+
}
|
|
1283
|
+
return expression.state === "no-natural-completion" || original?.state !== "unknown" ? expression : {
|
|
1284
|
+
...expression,
|
|
1285
|
+
candidates: original.candidates
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
return resolveScopeEnd(sourceScope);
|
|
1289
|
+
};
|
|
1290
|
+
const resolveCueTime = (timing, fromPath) => {
|
|
1291
|
+
const { moment, offsetMs } = timingParts(timing);
|
|
1292
|
+
return add(resolveMoment(moment, fromPath), offsetMs);
|
|
1293
|
+
};
|
|
1294
|
+
const activeChildren = (scope) => membersInStep(scope, key).filter((member) => memberIsActive(member, key));
|
|
1295
|
+
const directChildren = (scope) => membersInStep(scope, key);
|
|
1296
|
+
const memberEnd = (parent, member) => {
|
|
1297
|
+
if (member.kind === "scope") {
|
|
1298
|
+
const child = scopes.get(member.id);
|
|
1299
|
+
if (child === void 0) fail("missing-scope", "Member declaration of choreography scope does not exist", parent.path);
|
|
1300
|
+
return resolveScopeEnd(child);
|
|
1301
|
+
}
|
|
1302
|
+
const target = targets.get(member.id);
|
|
1303
|
+
if (target === void 0) fail("invalid-motion", "Object member declaration of choreography scope does not exist", parent.path);
|
|
1304
|
+
const base = memberStart(parent, member);
|
|
1305
|
+
const effectEnds = target.value.effects.map((effect, effectIndex) => effectEnd(base, target, effect, effectIndex, getExpansion(target, effectIndex), facts));
|
|
1306
|
+
if (target.value.effects.reduce((count, _effect, effectIndex) => {
|
|
1307
|
+
const expansion = getExpansion(target, effectIndex);
|
|
1308
|
+
return count + (expansion.type === "parts" ? expansion.count : 1);
|
|
1309
|
+
}, 0) > 1) return completion(materializeEvent(base, `target-start:${target.id}`, void 0, facts, target.path), effectEnds, {
|
|
1310
|
+
targetId: target.id,
|
|
1311
|
+
group: "effects",
|
|
1312
|
+
point: "end",
|
|
1313
|
+
offsetMs: 0
|
|
1314
|
+
}, facts, target.path);
|
|
1315
|
+
return effectEnds[0] ?? { state: "no-natural-completion" };
|
|
1316
|
+
};
|
|
1317
|
+
const memberStart = (parent, member) => {
|
|
1318
|
+
const parentStart = resolveScopeStart(parent);
|
|
1319
|
+
const activeIndex = activeChildren(parent).findIndex((candidate) => candidate.kind === member.kind && candidate.id === member.id);
|
|
1320
|
+
if (parent.declaration.mode === "parallel") return pointExpression(parentStart);
|
|
1321
|
+
if (parent.declaration.mode === "stagger") {
|
|
1322
|
+
if (activeIndex < 0) return pointExpression(parentStart);
|
|
1323
|
+
return add(parentStart, activeIndex * (parent.declaration.each ?? 0));
|
|
1324
|
+
}
|
|
1325
|
+
let cursor = pointExpression(parentStart);
|
|
1326
|
+
const direct = directChildren(parent);
|
|
1327
|
+
const directIndex = direct.findIndex((candidate) => candidate.kind === member.kind && candidate.id === member.id);
|
|
1328
|
+
for (const previous of direct.slice(0, directIndex)) {
|
|
1329
|
+
if (!memberIsActive(previous, key)) continue;
|
|
1330
|
+
const ended = memberEnd(parent, previous);
|
|
1331
|
+
if (ended.state === "no-natural-completion" && direct.slice(directIndex + 1).some((candidate) => memberIsActive(candidate, key))) return { state: "no-natural-completion" };
|
|
1332
|
+
cursor = pointExpression(ended);
|
|
1333
|
+
}
|
|
1334
|
+
return cursor;
|
|
1335
|
+
};
|
|
1336
|
+
const resolveScopeStart = (scope) => {
|
|
1337
|
+
const cached = starts.get(scope.declaration.identity);
|
|
1338
|
+
if (cached !== void 0) return cached;
|
|
1339
|
+
if (resolvingStarts.has(scope.declaration.identity)) fail("motion-cycle", "Choreography moment dependencies contain a cycle", scope.path);
|
|
1340
|
+
if (scope.declaration.delay > 4294967295) fail("invalid-motion-time", "Single scope delay field exceeds ST_TLTime range", scope.path);
|
|
1341
|
+
resolvingStarts.add(scope.declaration.identity);
|
|
1342
|
+
let parentStart = origin;
|
|
1343
|
+
let parentScope;
|
|
1344
|
+
let base = pointExpression(origin);
|
|
1345
|
+
if (scope.declaration.parent !== void 0) {
|
|
1346
|
+
const parent = scopes.get(scope.declaration.parent);
|
|
1347
|
+
if (parent === void 0) fail("missing-scope", "Parent instance of choreography scope does not exist", scope.path);
|
|
1348
|
+
parentScope = parent;
|
|
1349
|
+
parentStart = resolveScopeStart(parent);
|
|
1350
|
+
base = memberStart(parent, {
|
|
1351
|
+
kind: "scope",
|
|
1352
|
+
id: scope.declaration.identity,
|
|
1353
|
+
order: scope.order
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
if (scope.declaration.startAt !== void 0) {
|
|
1357
|
+
const fromCue = resolveCueTime(scope.declaration.startAt, scope.path);
|
|
1358
|
+
base = maximum([base, fromCue], facts);
|
|
1359
|
+
}
|
|
1360
|
+
const startExpression = add(base, scope.declaration.delay);
|
|
1361
|
+
if (startExpression.state === "no-natural-completion") fail("no-natural-completion", "Content without natural completion cannot start subsequent effects", scope.path);
|
|
1362
|
+
if (parentStart.state === "no-natural-completion") fail("no-natural-completion", "Parent scope without natural completion cannot start subsequent effects", scope.path);
|
|
1363
|
+
const nativeStartArguments = [
|
|
1364
|
+
parentStart,
|
|
1365
|
+
scope.path,
|
|
1366
|
+
scopeStartEventId(scope),
|
|
1367
|
+
parentScope,
|
|
1368
|
+
parentScope === void 0 ? void 0 : {
|
|
1369
|
+
kind: "scope",
|
|
1370
|
+
id: scope.declaration.identity,
|
|
1371
|
+
order: scope.order
|
|
1372
|
+
}
|
|
1373
|
+
];
|
|
1374
|
+
const nativeFieldWouldOverflow = scope.declaration.delay > 0 && (startExpression.state === "known" ? parentStart.state === "known" && startExpression.timeMs - parentStart.timeMs > 4294967295 : startExpression.candidates.some((candidate) => candidate.offsetMs > 4294967295));
|
|
1375
|
+
let nativeStart;
|
|
1376
|
+
if (nativeFieldWouldOverflow) nativeStart = addMotionPlanStartDelay(resolveNativeStart(base, ...nativeStartArguments), scope.declaration.delay);
|
|
1377
|
+
else nativeStart = resolveNativeStart(startExpression, ...nativeStartArguments);
|
|
1378
|
+
if (nativeStart === void 0) fail("invalid-motion-time", "Delay layer of scope start cannot be preserved as safe integer in milliseconds", scope.path);
|
|
1379
|
+
const start = materializeEvent(startExpression, scopeStartEventId(scope), void 0, facts, scope.path, nativeStart, reportedDependency(nativeStart, parentStart), reportedDependencies(nativeStart, parentStart), startExpression.candidates.length > 1 ? startExpression.candidates : void 0);
|
|
1380
|
+
if (nativeStart.kind === "parent-start") {
|
|
1381
|
+
facts.addLowerBound(parentStart.eventId, scopeStartEventId(scope), nativeStart.delayMs, scope.path);
|
|
1382
|
+
facts.addExactOffset(parentStart.eventId, scopeStartEventId(scope), nativeStart.delayMs, scope.path);
|
|
1383
|
+
} else if (nativeStart.kind === "condition-end") {
|
|
1384
|
+
facts.addLowerBound(nativeStart.id, scopeStartEventId(scope), nativeStart.delayMs, scope.path);
|
|
1385
|
+
facts.addExactOffset(nativeStart.id, scopeStartEventId(scope), nativeStart.delayMs, scope.path);
|
|
1386
|
+
} else if (nativeStart.kind === "event") {
|
|
1387
|
+
const sourceEventId = logicalEventId(nativeStart.dependency);
|
|
1388
|
+
facts.addLowerBound(sourceEventId, scopeStartEventId(scope), nativeStart.dependency.offsetMs, scope.path);
|
|
1389
|
+
facts.addExactOffset(sourceEventId, scopeStartEventId(scope), nativeStart.dependency.offsetMs, scope.path);
|
|
1390
|
+
}
|
|
1391
|
+
const { base: nativeStartBase, delays: nativeStartDelays } = motionPlanStartLayers(nativeStart);
|
|
1392
|
+
const localDelayMs = nativeStartDelays.reduce((total, delayMs) => total + delayMs, 0);
|
|
1393
|
+
if (!Number.isSafeInteger(localDelayMs)) fail("invalid-motion-time", "Accumulated delay of scope start must be a safe integer in milliseconds", scope.path);
|
|
1394
|
+
if (nativeStartBase.kind === "condition-join") conditionStartsByEventId.set(scopeStartEventId(scope), {
|
|
1395
|
+
id: nativeStartBase.id,
|
|
1396
|
+
candidates: startExpression.candidates,
|
|
1397
|
+
delayLayers: nativeStartDelays
|
|
1398
|
+
});
|
|
1399
|
+
else if (nativeStartBase.kind === "condition-end") conditionStartsByEventId.set(scopeStartEventId(scope), {
|
|
1400
|
+
id: nativeStartBase.id,
|
|
1401
|
+
candidates: startExpression.candidates,
|
|
1402
|
+
delayLayers: [nativeStartBase.delayMs, ...nativeStartDelays]
|
|
1403
|
+
});
|
|
1404
|
+
else if (nativeStartBase.kind === "parent-start") {
|
|
1405
|
+
const inherited = conditionStartsByEventId.get(parentStart.eventId);
|
|
1406
|
+
if (inherited !== void 0) conditionStartsByEventId.set(scopeStartEventId(scope), {
|
|
1407
|
+
id: inherited.id,
|
|
1408
|
+
candidates: startExpression.candidates,
|
|
1409
|
+
delayLayers: [
|
|
1410
|
+
...inherited.delayLayers,
|
|
1411
|
+
...nativeStartBase.delayMs === 0 ? [] : [nativeStartBase.delayMs],
|
|
1412
|
+
...nativeStartDelays
|
|
1413
|
+
]
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
scopeStartExpressions.set(scope.declaration.identity, startExpression);
|
|
1417
|
+
scopeStartPlans.set(scope.declaration.identity, nativeStart);
|
|
1418
|
+
starts.set(scope.declaration.identity, start);
|
|
1419
|
+
resolvingStarts.delete(scope.declaration.identity);
|
|
1420
|
+
return start;
|
|
1421
|
+
};
|
|
1422
|
+
const resolveScopeEnd = (scope) => {
|
|
1423
|
+
const cached = ends.get(scope.declaration.identity);
|
|
1424
|
+
if (cached !== void 0) return cached;
|
|
1425
|
+
if (resolvingEnds.has(scope.declaration.identity)) fail("motion-cycle", "Choreography moment dependencies contain a cycle", scope.path);
|
|
1426
|
+
resolvingEnds.add(scope.declaration.identity);
|
|
1427
|
+
const start = resolveScopeStart(scope);
|
|
1428
|
+
const memberEnds = activeChildren(scope).map((member) => memberEnd(scope, member));
|
|
1429
|
+
scopeCompletionMembers.set(scope.declaration.identity, memberEnds);
|
|
1430
|
+
const end = completion(start, memberEnds, {
|
|
1431
|
+
scopeId: scopeId(scope.declaration.identity, scopes),
|
|
1432
|
+
point: "end",
|
|
1433
|
+
offsetMs: 0
|
|
1434
|
+
}, facts, scope.path);
|
|
1435
|
+
ends.set(scope.declaration.identity, end);
|
|
1436
|
+
resolvingEnds.delete(scope.declaration.identity);
|
|
1437
|
+
return end;
|
|
1438
|
+
};
|
|
1439
|
+
for (const scope of scopes.values()) {
|
|
1440
|
+
if (!scopeSteps(scope).includes(key)) continue;
|
|
1441
|
+
if ((scope.declaration.mode === "sequence" || scope.declaration.mode === "stagger") && collectActiveSteps(scope.declaration.identity).size > 1) fail("cross-step-motion", "Sequence and stagger scopes cannot choreograph different click steps", scope.path);
|
|
1442
|
+
if (scope.declaration.startAt !== void 0 && collectActiveSteps(scope.declaration.identity).size > 1) fail("cross-step-motion", "Scope spanning multiple click steps cannot start from a single moment", scope.path);
|
|
1443
|
+
if (!scopeSteps(scope).includes(key)) continue;
|
|
1444
|
+
const start = resolveScopeStart(scope);
|
|
1445
|
+
const end = resolveScopeEnd(scope);
|
|
1446
|
+
const parent = scope.declaration.parent === void 0 ? void 0 : scopes.get(scope.declaration.parent);
|
|
1447
|
+
const id = scopeId(scope.declaration.identity, scopes);
|
|
1448
|
+
const parentId = parent === void 0 ? void 0 : scopeId(parent.declaration.identity, scopes);
|
|
1449
|
+
const observedMembers = directChildren(scope).map((member) => member.kind === "scope" ? {
|
|
1450
|
+
kind: "scope",
|
|
1451
|
+
id: scopeId(member.id, scopes)
|
|
1452
|
+
} : {
|
|
1453
|
+
kind: "object",
|
|
1454
|
+
id: member.id
|
|
1455
|
+
});
|
|
1456
|
+
scopeObservations.push({
|
|
1457
|
+
id,
|
|
1458
|
+
...parentId === void 0 ? {} : { parentId },
|
|
1459
|
+
mode: scope.declaration.mode,
|
|
1460
|
+
...scope.declaration.each === void 0 ? {} : { eachMs: Math.round(scope.declaration.each) },
|
|
1461
|
+
delayMs: Math.round(scope.declaration.delay),
|
|
1462
|
+
...start.state === "known" ? { startMs: start.timeMs } : {},
|
|
1463
|
+
...start.state === "unknown" && start.reportedStartAfter !== void 0 ? { startAfter: start.reportedStartAfter } : {},
|
|
1464
|
+
...start.state === "unknown" && start.reportedStartAfterAll !== void 0 ? { startAfterAll: start.reportedStartAfterAll } : {},
|
|
1465
|
+
...end.state === "known" ? { endMs: end.timeMs } : {},
|
|
1466
|
+
completion: end.state,
|
|
1467
|
+
members: observedMembers
|
|
1468
|
+
});
|
|
1469
|
+
queryScopes.push({
|
|
1470
|
+
identity: scope.declaration.identity,
|
|
1471
|
+
id,
|
|
1472
|
+
...scope.declaration.parent === void 0 ? {} : { parentIdentity: scope.declaration.parent },
|
|
1473
|
+
mode: scope.declaration.mode,
|
|
1474
|
+
...scope.declaration.each === void 0 ? {} : { eachMs: Math.round(scope.declaration.each) },
|
|
1475
|
+
delayMs: Math.round(scope.declaration.delay),
|
|
1476
|
+
members: queryDeclarationMembers(scope).map((member) => member.kind === "scope" ? {
|
|
1477
|
+
kind: "scope",
|
|
1478
|
+
identity: member.id
|
|
1479
|
+
} : {
|
|
1480
|
+
kind: "object",
|
|
1481
|
+
targetId: member.id
|
|
1482
|
+
}),
|
|
1483
|
+
start: queryMomentSource(start),
|
|
1484
|
+
end: queryMomentSource(end),
|
|
1485
|
+
declaration: scope.declaration
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
const targetsForStep = [...targets.values()].filter((target) => target.stepKey === key).sort((left, right) => left.order - right.order);
|
|
1489
|
+
for (const target of targetsForStep) {
|
|
1490
|
+
if (scheduledObjects.has(target.id)) continue;
|
|
1491
|
+
const containingScope = target.value.scopes.at(-1)?.identity;
|
|
1492
|
+
const parent = containingScope === void 0 ? void 0 : scopes.get(containingScope);
|
|
1493
|
+
const parentStart = parent === void 0 ? origin : resolveScopeStart(parent);
|
|
1494
|
+
const base = parent === void 0 ? pointExpression(origin) : memberStart(parent, {
|
|
1495
|
+
kind: "object",
|
|
1496
|
+
id: target.id,
|
|
1497
|
+
order: target.order
|
|
1498
|
+
});
|
|
1499
|
+
for (const [index, effect] of target.value.effects.entries()) {
|
|
1500
|
+
const expansion = getExpansion(target, index);
|
|
1501
|
+
const entries = expansion.type === "parts" ? expansion.ranges.map((range, partIndex) => ({
|
|
1502
|
+
range,
|
|
1503
|
+
partIndex
|
|
1504
|
+
})) : [expansion.type === "iterate" ? { iterate: expansion } : {}];
|
|
1505
|
+
for (const entry of entries) {
|
|
1506
|
+
const partIndex = "partIndex" in entry ? entry.partIndex : void 0;
|
|
1507
|
+
const start = add(base, Math.round(effect.delay) + (partIndex === void 0 ? 0 : partIndex * Math.round(effect.duration)));
|
|
1508
|
+
if (start.state === "no-natural-completion") fail("no-natural-completion", "Content without natural completion cannot start subsequent effects", target.path);
|
|
1509
|
+
const nativeStart = resolveNativeStart(start, parentStart, target.path, `effect-start:${target.id}:${index}:${partIndex ?? ""}`, parent, {
|
|
1510
|
+
kind: "object",
|
|
1511
|
+
id: target.id,
|
|
1512
|
+
order: target.order
|
|
1513
|
+
});
|
|
1514
|
+
const startAfter = start.state === "unknown" ? reportedDependency(nativeStart, parentStart) : void 0;
|
|
1515
|
+
const startAfterAll = start.state === "unknown" ? reportedDependencies(nativeStart, parentStart) : void 0;
|
|
1516
|
+
const timing = effectTimingAt(start, target, effect, index, partIndex, expansion, facts);
|
|
1517
|
+
const knownStart = timing.start.state === "known" ? timing.start.timeMs : void 0;
|
|
1518
|
+
const endMs = timing.end.state === "known" ? timing.end.timeMs : void 0;
|
|
1519
|
+
const from = typeof effect.from === "number" ? Math.round(effect.from * 6e4) / 6e4 : effect.from;
|
|
1520
|
+
const by = typeof effect.by === "number" ? Math.round(effect.by * 6e4) / 6e4 : effect.by;
|
|
1521
|
+
const easing = normalizedEasing(effect.easing);
|
|
1522
|
+
const scheduledEffect = {
|
|
1523
|
+
target: {
|
|
1524
|
+
id: target.id,
|
|
1525
|
+
name: target.value.target.name,
|
|
1526
|
+
...target.value.target.authorId === void 0 ? {} : { authorId: target.value.target.authorId },
|
|
1527
|
+
..."range" in entry ? { range: entry.range } : {}
|
|
1528
|
+
},
|
|
1529
|
+
kind: effect.kind,
|
|
1530
|
+
preset: effect.preset,
|
|
1531
|
+
durationMs: Math.round(effect.duration),
|
|
1532
|
+
...effect.repeatCount === void 0 ? {} : { repeatCount: effect.repeatCount },
|
|
1533
|
+
delayMs: Math.round(effect.delay),
|
|
1534
|
+
...by === void 0 ? {} : { by },
|
|
1535
|
+
...expansion.type === "iterate" ? { intervalMs: expansion.intervalMs } : {},
|
|
1536
|
+
...from === void 0 ? {} : { from },
|
|
1537
|
+
...easing === void 0 ? {} : { easing },
|
|
1538
|
+
...knownStart === void 0 ? {} : { startMs: knownStart },
|
|
1539
|
+
...effect.preset === "breathe" || effect.preset === "fillColor" ? {
|
|
1540
|
+
...effect.fromColor === void 0 ? {} : { fromColor: effect.fromColor },
|
|
1541
|
+
...effect.toColor === void 0 ? {} : { toColor: effect.toColor }
|
|
1542
|
+
} : {},
|
|
1543
|
+
...timing.end.state === "no-natural-completion" ? { completion: "no-natural-completion" } : endMs === void 0 ? { completion: "unknown" } : { endMs },
|
|
1544
|
+
...startAfter === void 0 ? {} : { startAfter },
|
|
1545
|
+
...startAfterAll === void 0 ? {} : { startAfterAll },
|
|
1546
|
+
stepKey: key,
|
|
1547
|
+
order: target.order + index,
|
|
1548
|
+
effectIndex: index,
|
|
1549
|
+
...partIndex === void 0 ? {} : { partIndex },
|
|
1550
|
+
targetKind: target.value.target.kind,
|
|
1551
|
+
targetTextBody: target.value.target.textBody,
|
|
1552
|
+
targetFilled: target.value.target.filled,
|
|
1553
|
+
...target.value.target.box === void 0 ? {} : { targetBox: target.value.target.box },
|
|
1554
|
+
...target.value.target.rotationDegrees === void 0 ? {} : { targetRotationDegrees: target.value.target.rotationDegrees },
|
|
1555
|
+
targetHasBackground: target.value.target.hasBackground ?? false,
|
|
1556
|
+
...target.value.target.paragraphCount === void 0 ? {} : { targetParagraphCount: target.value.target.paragraphCount },
|
|
1557
|
+
...target.value.target.members === void 0 ? {} : { targetMembers: target.value.target.members },
|
|
1558
|
+
...expansion.type === "iterate" ? { iterate: {
|
|
1559
|
+
type: expansion.by === "word" ? "wd" : "lt",
|
|
1560
|
+
intervalMs: expansion.intervalMs
|
|
1561
|
+
} } : {}
|
|
1562
|
+
};
|
|
1563
|
+
addStepEffect(scheduledEffect);
|
|
1564
|
+
queryEffectSources.set(motionEffectKey(target.id, index, partIndex), {
|
|
1565
|
+
observation: scheduledEffect,
|
|
1566
|
+
targetId: target.id,
|
|
1567
|
+
effectIndex: index,
|
|
1568
|
+
...partIndex === void 0 ? {} : { partIndex },
|
|
1569
|
+
start: queryMomentSource(timing.start),
|
|
1570
|
+
end: queryMomentSource(timing.end),
|
|
1571
|
+
scopeIdentities: target.value.scopes.map(({ identity }) => identity)
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
scheduledObjects.add(target.id);
|
|
1576
|
+
}
|
|
1577
|
+
const targetNode = (target, parent) => {
|
|
1578
|
+
const effects = (allScheduledEffects.get(key) ?? []).filter((effect) => effect.target.id === target.id);
|
|
1579
|
+
if (effects.length === 0) return void 0;
|
|
1580
|
+
const parentStart = parent === void 0 ? origin : resolveScopeStart(parent);
|
|
1581
|
+
const start = parent === void 0 ? pointExpression(origin) : memberStart(parent, {
|
|
1582
|
+
kind: "object",
|
|
1583
|
+
id: target.id,
|
|
1584
|
+
order: target.order
|
|
1585
|
+
});
|
|
1586
|
+
const nativeStart = resolveNativeStart(start, parentStart, target.path, `target-start:${target.id}`, parent, parent === void 0 ? void 0 : {
|
|
1587
|
+
kind: "object",
|
|
1588
|
+
id: target.id,
|
|
1589
|
+
order: target.order
|
|
1590
|
+
});
|
|
1591
|
+
recordStartCondition(nativeStart);
|
|
1592
|
+
return {
|
|
1593
|
+
kind: "target",
|
|
1594
|
+
targetId: target.id,
|
|
1595
|
+
nativeStart: consumerStart(nativeStart),
|
|
1596
|
+
effects
|
|
1597
|
+
};
|
|
1598
|
+
};
|
|
1599
|
+
function scopeForStartEvent(eventId) {
|
|
1600
|
+
return [...scopes.values()].find((scope) => `scope-start:${scope.declaration.identity}` === eventId);
|
|
1601
|
+
}
|
|
1602
|
+
function scopeForPlanId(id) {
|
|
1603
|
+
return [...scopes.values()].find((scope) => scopeId(scope.declaration.identity, scopes) === id);
|
|
1604
|
+
}
|
|
1605
|
+
function isAncestorScope(ancestor, descendant) {
|
|
1606
|
+
let current = descendant;
|
|
1607
|
+
while (current !== void 0) {
|
|
1608
|
+
if (current.declaration.identity === ancestor.declaration.identity) return true;
|
|
1609
|
+
const parentId = current.declaration.parent;
|
|
1610
|
+
current = parentId === void 0 ? void 0 : scopes.get(parentId);
|
|
1611
|
+
}
|
|
1612
|
+
return false;
|
|
1613
|
+
}
|
|
1614
|
+
function hasActiveMembers(scope) {
|
|
1615
|
+
return membersInStep(scope, key).some((member) => memberIsActive(member, key));
|
|
1616
|
+
}
|
|
1617
|
+
function expandStartCandidate(candidate, seen = /* @__PURE__ */ new Set()) {
|
|
1618
|
+
const source = scopeForStartEvent(candidate.eventId);
|
|
1619
|
+
if (source === void 0 || seen.has(source.declaration.identity)) return [candidate];
|
|
1620
|
+
if (!hasActiveMembers(source)) {
|
|
1621
|
+
preservedScopeStarts.add(source.declaration.identity);
|
|
1622
|
+
return [candidate];
|
|
1623
|
+
}
|
|
1624
|
+
const original = scopeStartExpressions.get(source.declaration.identity);
|
|
1625
|
+
if (original === void 0 || original.state === "no-natural-completion") return [candidate];
|
|
1626
|
+
const nextSeen = new Set(seen);
|
|
1627
|
+
nextSeen.add(source.declaration.identity);
|
|
1628
|
+
const expanded = [];
|
|
1629
|
+
for (const sourceCandidate of original.candidates) {
|
|
1630
|
+
const offsetMs = sourceCandidate.offsetMs + candidate.offsetMs;
|
|
1631
|
+
if (!Number.isSafeInteger(offsetMs) || offsetMs < 0 || offsetMs > 4294967295) {
|
|
1632
|
+
if (hasActiveMembers(source)) return [candidate];
|
|
1633
|
+
fail("invalid-motion-time", "Synthesized offset of empty scope start cannot be written to single ST_TLTime field", source.path);
|
|
1634
|
+
}
|
|
1635
|
+
expanded.push(...expandStartCandidate({
|
|
1636
|
+
...sourceCandidate,
|
|
1637
|
+
offsetMs
|
|
1638
|
+
}, nextSeen));
|
|
1639
|
+
}
|
|
1640
|
+
return expanded.length === 0 ? [candidate] : expanded;
|
|
1641
|
+
}
|
|
1642
|
+
function dependencyMatchesEvent(dependency, eventId) {
|
|
1643
|
+
if ("scopeId" in dependency && dependency.point === "start") {
|
|
1644
|
+
const source = scopeForPlanId(dependency.scopeId);
|
|
1645
|
+
return source !== void 0 && `scope-start:${source.declaration.identity}` === eventId;
|
|
1646
|
+
}
|
|
1647
|
+
return dependencyEventId(dependency) === eventId;
|
|
1648
|
+
}
|
|
1649
|
+
function logicalEventId(dependency) {
|
|
1650
|
+
if ("scopeId" in dependency && dependency.point === "start") {
|
|
1651
|
+
const source = scopeForPlanId(dependency.scopeId);
|
|
1652
|
+
if (source !== void 0) return `scope-start:${source.declaration.identity}`;
|
|
1653
|
+
}
|
|
1654
|
+
return dependencyEventId(dependency);
|
|
1655
|
+
}
|
|
1656
|
+
function markProjectedAncestors(actualParent, host) {
|
|
1657
|
+
let projectionHost = host;
|
|
1658
|
+
const existingHostId = projectedEndHosts.get(actualParent.declaration.identity);
|
|
1659
|
+
if (existingHostId === stepRootHostIdentity) return;
|
|
1660
|
+
const existingHost = existingHostId === void 0 ? void 0 : scopes.get(existingHostId);
|
|
1661
|
+
if (existingHost !== void 0 && isAncestorScope(existingHost, host)) projectionHost = existingHost;
|
|
1662
|
+
else if (existingHost !== void 0 && !isAncestorScope(host, existingHost)) fail("motion-plan-conflict", "Same logical completion cannot be projected to an unrelated physical host", actualParent.path);
|
|
1663
|
+
let current = actualParent;
|
|
1664
|
+
while (current !== void 0 && current.declaration.identity !== projectionHost.declaration.identity) {
|
|
1665
|
+
projectedEndHosts.set(current.declaration.identity, projectionHost.declaration.identity);
|
|
1666
|
+
const parentId = current.declaration.parent;
|
|
1667
|
+
current = parentId === void 0 ? void 0 : scopes.get(parentId);
|
|
1668
|
+
}
|
|
1669
|
+
if (current === void 0) fail("motion-plan-conflict", "Projection host is not an ancestor of consumer node", actualParent.path);
|
|
1670
|
+
}
|
|
1671
|
+
function markProjectedAncestorsAtStepRoot(actualParent) {
|
|
1672
|
+
let current = actualParent;
|
|
1673
|
+
while (current !== void 0) {
|
|
1674
|
+
projectedEndHosts.set(current.declaration.identity, stepRootHostIdentity);
|
|
1675
|
+
const parentId = current.declaration.parent;
|
|
1676
|
+
current = parentId === void 0 ? void 0 : scopes.get(parentId);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
const recordConditionPlacement = (join) => {
|
|
1680
|
+
const projectedHost = projectedNodeHosts.get(join.beforeNodeId);
|
|
1681
|
+
const placement = projectedHost === void 0 ? join : {
|
|
1682
|
+
...join,
|
|
1683
|
+
hostScopeId: projectedHost === stepRootHostIdentity ? stepRootHostIdentity : scopeId(projectedHost, scopes),
|
|
1684
|
+
consumerParentScopeId: projectedHost === stepRootHostIdentity ? stepRootHostIdentity : scopeId(projectedHost, scopes)
|
|
1685
|
+
};
|
|
1686
|
+
const placements = conditionPlacementsByHost.get(placement.hostScopeId) ?? [];
|
|
1687
|
+
const existingIndex = placements.findIndex(({ join: existing }) => existing.id === placement.id);
|
|
1688
|
+
if (existingIndex >= 0) {
|
|
1689
|
+
placements[existingIndex] = { join: placement };
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
placements.push({ join: placement });
|
|
1693
|
+
conditionPlacementsByHost.set(placement.hostScopeId, placements);
|
|
1694
|
+
};
|
|
1695
|
+
const recordStartCondition = (start) => {
|
|
1696
|
+
const { base } = motionPlanStartLayers(start);
|
|
1697
|
+
if (base.kind === "condition-join") recordConditionPlacement(base);
|
|
1698
|
+
else if (base.kind === "condition-end") {
|
|
1699
|
+
const join = conditionJoinsById.get(base.id);
|
|
1700
|
+
if (join !== void 0) recordConditionPlacement(join);
|
|
1701
|
+
}
|
|
1702
|
+
};
|
|
1703
|
+
const consumerStart = (start) => {
|
|
1704
|
+
if (start.kind === "condition-join") return {
|
|
1705
|
+
kind: "condition-end",
|
|
1706
|
+
id: start.id,
|
|
1707
|
+
delayMs: 0
|
|
1708
|
+
};
|
|
1709
|
+
if (start.kind === "delay-layer") return {
|
|
1710
|
+
...start,
|
|
1711
|
+
start: consumerStart(start.start)
|
|
1712
|
+
};
|
|
1713
|
+
return start;
|
|
1714
|
+
};
|
|
1715
|
+
const conditionEvent = (id) => `condition:${id}`;
|
|
1716
|
+
const planNodeId = (node) => node.kind === "scope" ? `scope:${node.id}` : node.kind === "completion-collector" ? `completion:${node.scopeId}` : `target:${node.targetId}`;
|
|
1717
|
+
const nodePath = (node) => node.kind === "scope" ? [...scopes.values()].find((scope) => scopeId(scope.declaration.identity, scopes) === node.id)?.path : node.kind === "completion-collector" ? [...scopes.values()].find((scope) => scopeId(scope.declaration.identity, scopes) === node.scopeId)?.path : targets.get(node.targetId)?.path;
|
|
1718
|
+
const sortNativeRoots = (rootNodes, conditionDefinitionsBefore = [], parentScope) => {
|
|
1719
|
+
const rootDefinitions = /* @__PURE__ */ new Map();
|
|
1720
|
+
const rootReferences = rootNodes.map(() => []);
|
|
1721
|
+
const collectStartDependency = (start, rootIndex, node) => {
|
|
1722
|
+
const collectDependency = (id) => rootReferences[rootIndex]?.push({
|
|
1723
|
+
id,
|
|
1724
|
+
node
|
|
1725
|
+
});
|
|
1726
|
+
if (start.kind === "delay-layer") collectStartDependency(start.start, rootIndex, node);
|
|
1727
|
+
else if (start.kind === "end" || start.kind === "event") collectDependency(eventSource(start.dependency));
|
|
1728
|
+
else if (start.kind === "condition-end") collectDependency(conditionEvent(start.id));
|
|
1729
|
+
else if (start.kind === "condition-join") {
|
|
1730
|
+
rootDefinitions.set(conditionEvent(start.id), rootIndex);
|
|
1731
|
+
for (const gate of start.gates) collectStartDependency(planStartForGate(gate), rootIndex, node);
|
|
1732
|
+
}
|
|
1733
|
+
};
|
|
1734
|
+
const collectRootDependencies = (node, rootIndex) => {
|
|
1735
|
+
if (node.kind === "scope") {
|
|
1736
|
+
rootDefinitions.set(`scope-start:${node.id}`, rootIndex);
|
|
1737
|
+
if (node.splitCompletion !== true) rootDefinitions.set(`scope:${node.id}`, rootIndex);
|
|
1738
|
+
} else if (node.kind === "completion-collector") {
|
|
1739
|
+
rootDefinitions.set(`scope:${node.scopeId}`, rootIndex);
|
|
1740
|
+
for (const gate of node.gates) collectStartDependency(planStartForGate(gate), rootIndex, node);
|
|
1741
|
+
} else {
|
|
1742
|
+
if (node.effects.length > 1) rootDefinitions.set(`target:${node.targetId}`, rootIndex);
|
|
1743
|
+
for (const effect of node.effects) rootDefinitions.set(eventSource({
|
|
1744
|
+
targetId: effect.target.id,
|
|
1745
|
+
effectIndex: effect.effectIndex,
|
|
1746
|
+
...effect.partIndex === void 0 ? {} : { partIndex: effect.partIndex },
|
|
1747
|
+
point: "end",
|
|
1748
|
+
offsetMs: 0
|
|
1749
|
+
}), rootIndex);
|
|
1750
|
+
}
|
|
1751
|
+
collectStartDependency(node.nativeStart, rootIndex, node);
|
|
1752
|
+
if (node.kind === "scope") {
|
|
1753
|
+
for (const placement of node.conditionDefinitionsBefore ?? []) {
|
|
1754
|
+
rootDefinitions.set(conditionEvent(placement.join.id), rootIndex);
|
|
1755
|
+
for (const gate of placement.join.gates) collectStartDependency(planStartForGate(gate), rootIndex, node);
|
|
1756
|
+
}
|
|
1757
|
+
for (const child of node.children) collectRootDependencies(child, rootIndex);
|
|
1758
|
+
}
|
|
1759
|
+
};
|
|
1760
|
+
rootNodes.forEach((node, index) => collectRootDependencies(node, index));
|
|
1761
|
+
for (const placement of conditionDefinitionsBefore) {
|
|
1762
|
+
const consumerIndex = rootNodes.findIndex((node) => planNodeId(node) === placement.join.beforeNodeId);
|
|
1763
|
+
if (consumerIndex < 0) continue;
|
|
1764
|
+
rootDefinitions.set(conditionEvent(placement.join.id), consumerIndex);
|
|
1765
|
+
for (const gate of placement.join.gates) {
|
|
1766
|
+
const consumer = rootNodes[consumerIndex];
|
|
1767
|
+
if (consumer !== void 0) collectStartDependency(planStartForGate(gate), consumerIndex, consumer);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
const nextRootNodes = rootNodes.map(() => /* @__PURE__ */ new Set());
|
|
1771
|
+
const rootIndegrees = rootNodes.map(() => 0);
|
|
1772
|
+
for (const [consumerIndex, references] of rootReferences.entries()) for (const reference of references) {
|
|
1773
|
+
const definitionIndex = rootDefinitions.get(reference.id);
|
|
1774
|
+
if (definitionIndex === void 0) continue;
|
|
1775
|
+
if (definitionIndex !== consumerIndex && !nextRootNodes[definitionIndex]?.has(consumerIndex)) {
|
|
1776
|
+
nextRootNodes[definitionIndex]?.add(consumerIndex);
|
|
1777
|
+
rootIndegrees[consumerIndex] = (rootIndegrees[consumerIndex] ?? 0) + 1;
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
const readyRootNodes = rootIndegrees.flatMap((indegree, index) => indegree === 0 ? [index] : []);
|
|
1781
|
+
const rootOrder = [];
|
|
1782
|
+
while (readyRootNodes.length > 0) {
|
|
1783
|
+
readyRootNodes.sort((left, right) => left - right);
|
|
1784
|
+
const current = readyRootNodes.shift();
|
|
1785
|
+
if (current === void 0) continue;
|
|
1786
|
+
rootOrder.push(current);
|
|
1787
|
+
for (const following of nextRootNodes[current] ?? []) {
|
|
1788
|
+
const remaining = (rootIndegrees[following] ?? 0) - 1;
|
|
1789
|
+
rootIndegrees[following] = remaining;
|
|
1790
|
+
if (remaining === 0) readyRootNodes.push(following);
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
if (rootOrder.length !== rootNodes.length) {
|
|
1794
|
+
const reachableFrom = (start) => {
|
|
1795
|
+
const reached = /* @__PURE__ */ new Set();
|
|
1796
|
+
const pending = [...nextRootNodes[start] ?? []];
|
|
1797
|
+
while (pending.length > 0) {
|
|
1798
|
+
const current = pending.pop();
|
|
1799
|
+
if (current === void 0 || reached.has(current)) continue;
|
|
1800
|
+
reached.add(current);
|
|
1801
|
+
pending.push(...nextRootNodes[current] ?? []);
|
|
1802
|
+
}
|
|
1803
|
+
return reached;
|
|
1804
|
+
};
|
|
1805
|
+
const reachable = rootNodes.map((_, index) => reachableFrom(index));
|
|
1806
|
+
const cycleRootIndices = /* @__PURE__ */ new Set();
|
|
1807
|
+
for (let left = 0; left < rootNodes.length; left += 1) for (let right = left + 1; right < rootNodes.length; right += 1) if (reachable[left]?.has(right) && reachable[right]?.has(left)) {
|
|
1808
|
+
cycleRootIndices.add(left);
|
|
1809
|
+
cycleRootIndices.add(right);
|
|
1810
|
+
}
|
|
1811
|
+
const placementsIn = (node) => node.kind === "scope" ? [...node.conditionDefinitionsBefore ?? [], ...node.children.flatMap(placementsIn)] : [];
|
|
1812
|
+
const parentForConsumer = (consumerId) => {
|
|
1813
|
+
if (consumerId.startsWith("scope:")) {
|
|
1814
|
+
const parentId = scopeForPlanId(consumerId.slice(6))?.declaration.parent;
|
|
1815
|
+
return parentId === void 0 ? void 0 : scopes.get(parentId);
|
|
1816
|
+
}
|
|
1817
|
+
if (consumerId.startsWith("target:")) {
|
|
1818
|
+
const parentId = targets.get(Number(consumerId.slice(7)))?.value.scopes.at(-1)?.identity;
|
|
1819
|
+
return parentId === void 0 ? void 0 : scopes.get(parentId);
|
|
1820
|
+
}
|
|
1821
|
+
};
|
|
1822
|
+
if (parentScope !== void 0) for (const rootIndex of cycleRootIndices) {
|
|
1823
|
+
const root = rootNodes[rootIndex];
|
|
1824
|
+
if (root === void 0) continue;
|
|
1825
|
+
for (const { join } of placementsIn(root)) {
|
|
1826
|
+
if (!join.gates.some((gate) => {
|
|
1827
|
+
return gateSourceDependencies(gate).some((dependency) => {
|
|
1828
|
+
const sourceRoot = rootDefinitions.get(eventSource(dependency));
|
|
1829
|
+
return sourceRoot !== void 0 && sourceRoot !== rootIndex && cycleRootIndices.has(sourceRoot);
|
|
1830
|
+
});
|
|
1831
|
+
})) continue;
|
|
1832
|
+
const consumerId = join.beforeNodeId;
|
|
1833
|
+
const actualParent = parentForConsumer(consumerId);
|
|
1834
|
+
if (actualParent === void 0 || !isAncestorScope(parentScope, actualParent)) continue;
|
|
1835
|
+
if (projectedNodeHosts.get(consumerId) === parentScope.declaration.identity) continue;
|
|
1836
|
+
projectedNodeHosts.set(consumerId, parentScope.declaration.identity);
|
|
1837
|
+
markProjectedAncestors(actualParent, parentScope);
|
|
1838
|
+
projectionChanged = true;
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
if (projectionChanged) return [...rootNodes];
|
|
1842
|
+
fail("unknown-motion-start", "Node cycles that cannot be defined by real timeline still exist after recursive projection", parentScope?.path);
|
|
1843
|
+
}
|
|
1844
|
+
return rootOrder.length === rootNodes.length ? rootOrder.flatMap((index) => {
|
|
1845
|
+
const node = rootNodes[index];
|
|
1846
|
+
return node === void 0 ? [] : [node];
|
|
1847
|
+
}) : [...rootNodes];
|
|
1848
|
+
};
|
|
1849
|
+
const projectedNodesByHost = /* @__PURE__ */ new Map();
|
|
1850
|
+
const collectorForProjectedScope = (scope, hostStart) => {
|
|
1851
|
+
const end = ends.get(scope.declaration.identity);
|
|
1852
|
+
const memberEnds = scopeCompletionMembers.get(scope.declaration.identity);
|
|
1853
|
+
if (end === void 0 || end.state === "no-natural-completion" || memberEnds === void 0 || memberEnds.length !== activeChildren(scope).length || hostStart.state === "no-natural-completion") return;
|
|
1854
|
+
const gates = memberEnds.map((memberEnd) => {
|
|
1855
|
+
if (memberEnd.state === "no-natural-completion") fail("motion-plan-conflict", "Finite scope completion collection contains member without natural completion", scope.path);
|
|
1856
|
+
let dependency = memberEnd.dependency;
|
|
1857
|
+
if (dependency === void 0) {
|
|
1858
|
+
const startSource = scopeForStartEvent(memberEnd.eventId);
|
|
1859
|
+
if (startSource !== void 0) dependency = {
|
|
1860
|
+
scopeId: scopeId(startSource.declaration.identity, scopes),
|
|
1861
|
+
point: "start",
|
|
1862
|
+
offsetMs: 0
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1865
|
+
const exactOffset = facts.exactOffset(hostStart.eventId, memberEnd.eventId) ?? (hostStart.state === "known" && memberEnd.state === "known" ? memberEnd.timeMs - hostStart.timeMs : void 0);
|
|
1866
|
+
if (exactOffset !== void 0 && exactOffset >= 0) {
|
|
1867
|
+
if (exactOffset <= 4294967295) return {
|
|
1868
|
+
kind: "parent-start",
|
|
1869
|
+
delayMs: exactOffset,
|
|
1870
|
+
...dependency === void 0 ? {} : { sourceDependency: dependency }
|
|
1871
|
+
};
|
|
1872
|
+
if (dependency === void 0) fail("invalid-motion-time", "Exact member start of completion collection cannot be preserved as a legal delay layer", scope.path);
|
|
1873
|
+
}
|
|
1874
|
+
if (dependency === void 0 || !strictlyAfterParentStart(memberEnd.candidates, hostStart)) fail("unknown-motion-start", "Cannot prove real member END is later than early host activation and can be collected entirely", scope.path);
|
|
1875
|
+
return {
|
|
1876
|
+
kind: dependency.point === "start" ? "begin" : "end",
|
|
1877
|
+
dependency
|
|
1878
|
+
};
|
|
1879
|
+
});
|
|
1880
|
+
return {
|
|
1881
|
+
kind: "completion-collector",
|
|
1882
|
+
scopeId: scopeId(scope.declaration.identity, scopes),
|
|
1883
|
+
nativeStart: {
|
|
1884
|
+
kind: "parent-start",
|
|
1885
|
+
delayMs: 0
|
|
1886
|
+
},
|
|
1887
|
+
gates
|
|
1888
|
+
};
|
|
1889
|
+
};
|
|
1890
|
+
const scopeNode = (scope) => {
|
|
1891
|
+
const children = activeChildren(scope).flatMap((member) => {
|
|
1892
|
+
if (member.kind === "scope") {
|
|
1893
|
+
const childScope = scopes.get(member.id);
|
|
1894
|
+
if (childScope === void 0) fail("missing-scope", "Member declaration of choreography scope does not exist", scope.path);
|
|
1895
|
+
return scopeNode(childScope);
|
|
1896
|
+
}
|
|
1897
|
+
const target = targets.get(member.id);
|
|
1898
|
+
if (target === void 0) fail("invalid-motion", "Object member declaration of choreography scope does not exist", scope.path);
|
|
1899
|
+
const node = targetNode(target, scope);
|
|
1900
|
+
if (node === void 0) return [];
|
|
1901
|
+
const projectedHost = projectedNodeHosts.get(`target:${target.id}`);
|
|
1902
|
+
if (projectedHost !== void 0 && projectedHost !== scope.declaration.identity) {
|
|
1903
|
+
const lifted = projectedNodesByHost.get(projectedHost) ?? [];
|
|
1904
|
+
lifted.push(node);
|
|
1905
|
+
projectedNodesByHost.set(projectedHost, lifted);
|
|
1906
|
+
return [];
|
|
1907
|
+
}
|
|
1908
|
+
return [node];
|
|
1909
|
+
});
|
|
1910
|
+
const identity = scope.declaration.identity;
|
|
1911
|
+
const hostIdentity = projectedNodeHosts.get(`scope:${scopeId(identity, scopes)}`);
|
|
1912
|
+
if (hostIdentity !== void 0 && hostIdentity !== identity) {
|
|
1913
|
+
const lifted = projectedNodesByHost.get(hostIdentity) ?? [];
|
|
1914
|
+
const node = createScopeNode(scope, children);
|
|
1915
|
+
lifted.push(node);
|
|
1916
|
+
projectedNodesByHost.set(hostIdentity, lifted);
|
|
1917
|
+
return [];
|
|
1918
|
+
}
|
|
1919
|
+
const hostLifted = projectedNodesByHost.get(identity) ?? [];
|
|
1920
|
+
const hostScopes = [...projectedEndHosts.entries()].filter(([, host]) => host === identity).map(([scopeIdentity]) => scopes.get(scopeIdentity)).filter((candidate) => candidate !== void 0).sort((left, right) => left.order - right.order);
|
|
1921
|
+
for (const projectedScope of hostScopes) {
|
|
1922
|
+
const collector = collectorForProjectedScope(projectedScope, resolveScopeStart(scope));
|
|
1923
|
+
if (collector !== void 0) hostLifted.push(collector);
|
|
1924
|
+
}
|
|
1925
|
+
const allChildren = [...children, ...hostLifted];
|
|
1926
|
+
projectedNodesByHost.delete(identity);
|
|
1927
|
+
const preserveStart = preservedScopeStarts.has(identity);
|
|
1928
|
+
if (allChildren.length === 0 && !preserveStart) return [];
|
|
1929
|
+
return [createScopeNode(scope, allChildren, preserveStart)];
|
|
1930
|
+
};
|
|
1931
|
+
const createScopeNode = (scope, children, preserveStart = preservedScopeStarts.has(scope.declaration.identity)) => {
|
|
1932
|
+
const nativeStart = scopeStartPlans.get(scope.declaration.identity);
|
|
1933
|
+
if (nativeStart === void 0) fail("motion-plan-conflict", "Scope lacks resolved start", scope.path);
|
|
1934
|
+
recordStartCondition(nativeStart);
|
|
1935
|
+
const id = scopeId(scope.declaration.identity, scopes);
|
|
1936
|
+
const conditionDefinitionsBefore = conditionPlacementsByHost.get(id) ?? [];
|
|
1937
|
+
return {
|
|
1938
|
+
kind: "scope",
|
|
1939
|
+
id,
|
|
1940
|
+
nativeStart: consumerStart(nativeStart),
|
|
1941
|
+
children: sortNativeRoots(children, conditionDefinitionsBefore, scope),
|
|
1942
|
+
...projectedEndHosts.has(scope.declaration.identity) ? { splitCompletion: true } : {},
|
|
1943
|
+
...preserveStart ? { preserveStart: true } : {},
|
|
1944
|
+
...conditionDefinitionsBefore.length === 0 ? {} : { conditionDefinitionsBefore }
|
|
1945
|
+
};
|
|
1946
|
+
};
|
|
1947
|
+
let rootNodes = [];
|
|
1948
|
+
let nodes = [];
|
|
1949
|
+
let rootConditionDefinitionsBefore = [];
|
|
1950
|
+
while (true) {
|
|
1951
|
+
projectionChanged = false;
|
|
1952
|
+
conditionPlacementsByHost.clear();
|
|
1953
|
+
projectedNodesByHost.clear();
|
|
1954
|
+
rootNodes = roots.flatMap((member) => {
|
|
1955
|
+
if (member.kind === "scope") {
|
|
1956
|
+
const scope = scopes.get(member.id);
|
|
1957
|
+
if (scope === void 0 || !scopeSteps(scope).includes(key)) return [];
|
|
1958
|
+
return scopeNode(scope);
|
|
1959
|
+
}
|
|
1960
|
+
const target = targets.get(member.id);
|
|
1961
|
+
if (target === void 0 || target.stepKey !== key) return [];
|
|
1962
|
+
const node = targetNode(target);
|
|
1963
|
+
return node === void 0 ? [] : [node];
|
|
1964
|
+
});
|
|
1965
|
+
if (projectionChanged) continue;
|
|
1966
|
+
rootNodes.push(...projectedNodesByHost.get(stepRootHostIdentity) ?? []);
|
|
1967
|
+
projectedNodesByHost.delete(stepRootHostIdentity);
|
|
1968
|
+
const projectedRootScopes = [...projectedEndHosts.entries()].filter(([, host]) => host === stepRootHostIdentity).map(([scopeIdentity]) => scopes.get(scopeIdentity)).filter((candidate) => candidate !== void 0 && scopeSteps(candidate).includes(key)).sort((left, right) => left.order - right.order);
|
|
1969
|
+
for (const projectedScope of projectedRootScopes) {
|
|
1970
|
+
const collector = collectorForProjectedScope(projectedScope, origin);
|
|
1971
|
+
if (collector !== void 0) rootNodes.push(collector);
|
|
1972
|
+
}
|
|
1973
|
+
rootConditionDefinitionsBefore = conditionPlacementsByHost.get(stepRootHostIdentity) ?? [];
|
|
1974
|
+
nodes = sortNativeRoots(rootNodes, rootConditionDefinitionsBefore);
|
|
1975
|
+
if (!projectionChanged) break;
|
|
1976
|
+
}
|
|
1977
|
+
const definedEvents = /* @__PURE__ */ new Set();
|
|
1978
|
+
const definedConditions = /* @__PURE__ */ new Set();
|
|
1979
|
+
const verifyEventReference = (id, node) => {
|
|
1980
|
+
if (!definedEvents.has(id)) fail("unknown-motion-start", `Native completion source ${id} must be defined before its condition reference`, nodePath(node));
|
|
1981
|
+
};
|
|
1982
|
+
const verifyConditionJoins = (start, node) => {
|
|
1983
|
+
if (start.kind === "delay-layer") verifyConditionJoins(start.start, node);
|
|
1984
|
+
else if (start.kind === "condition-join") {
|
|
1985
|
+
for (const gate of start.gates) verifyGate(gate, node);
|
|
1986
|
+
definedConditions.add(conditionEvent(start.id));
|
|
1987
|
+
}
|
|
1988
|
+
};
|
|
1989
|
+
const verifyStartDependencies = (start, node) => {
|
|
1990
|
+
if (start.kind === "delay-layer") verifyStartDependencies(start.start, node);
|
|
1991
|
+
else if (start.kind === "end" || start.kind === "event") verifyEventReference(eventSource(start.dependency), node);
|
|
1992
|
+
else if (start.kind === "condition-end" && !definedConditions.has(conditionEvent(start.id))) fail("unknown-motion-start", "Condition collection must be defined before its consumers", nodePath(node));
|
|
1993
|
+
};
|
|
1994
|
+
const verifyGate = (gate, node) => {
|
|
1995
|
+
const start = planStartForGate(gate);
|
|
1996
|
+
verifyConditionJoins(start, node);
|
|
1997
|
+
verifyStartDependencies(start, node);
|
|
1998
|
+
};
|
|
1999
|
+
const verifyNodeOrder = (node) => {
|
|
2000
|
+
verifyConditionJoins(node.nativeStart, node);
|
|
2001
|
+
if (node.kind === "completion-collector") {
|
|
2002
|
+
for (const gate of node.gates) verifyGate(gate, node);
|
|
2003
|
+
const eventId = `scope:${node.scopeId}`;
|
|
2004
|
+
if (definedEvents.has(eventId)) fail("motion-plan-conflict", "Same scope repeatedly defined completion event", nodePath(node));
|
|
2005
|
+
definedEvents.add(eventId);
|
|
2006
|
+
} else if (node.kind === "scope") {
|
|
2007
|
+
definedEvents.add(`scope-start:${node.id}`);
|
|
2008
|
+
if (node.splitCompletion !== true) definedEvents.add(`scope:${node.id}`);
|
|
2009
|
+
} else {
|
|
2010
|
+
if (node.effects.length > 1) definedEvents.add(`target:${node.targetId}`);
|
|
2011
|
+
for (const effect of node.effects) definedEvents.add(eventSource({
|
|
2012
|
+
targetId: effect.target.id,
|
|
2013
|
+
effectIndex: effect.effectIndex,
|
|
2014
|
+
...effect.partIndex === void 0 ? {} : { partIndex: effect.partIndex },
|
|
2015
|
+
point: "end",
|
|
2016
|
+
offsetMs: 0
|
|
2017
|
+
}));
|
|
2018
|
+
}
|
|
2019
|
+
verifyStartDependencies(node.nativeStart, node);
|
|
2020
|
+
if (node.kind === "scope") {
|
|
2021
|
+
const placements = node.conditionDefinitionsBefore ?? [];
|
|
2022
|
+
const remaining = new Set(placements);
|
|
2023
|
+
for (const child of node.children) {
|
|
2024
|
+
const childId = planNodeId(child);
|
|
2025
|
+
for (const placement of placements) {
|
|
2026
|
+
if (placement.join.beforeNodeId !== childId) continue;
|
|
2027
|
+
for (const gate of placement.join.gates) verifyGate(gate, node);
|
|
2028
|
+
if (definedConditions.has(conditionEvent(placement.join.id))) fail("motion-plan-conflict", "Same step repeatedly defined condition collection", nodePath(node));
|
|
2029
|
+
definedConditions.add(conditionEvent(placement.join.id));
|
|
2030
|
+
remaining.delete(placement);
|
|
2031
|
+
}
|
|
2032
|
+
verifyNodeOrder(child);
|
|
2033
|
+
}
|
|
2034
|
+
if (remaining.size > 0) fail("motion-plan-conflict", "Condition collection host lacks actual insertion position", nodePath(node));
|
|
2035
|
+
}
|
|
2036
|
+
};
|
|
2037
|
+
const remainingRootPlacements = new Set(rootConditionDefinitionsBefore);
|
|
2038
|
+
for (const node of nodes) {
|
|
2039
|
+
const nodeId = planNodeId(node);
|
|
2040
|
+
for (const placement of rootConditionDefinitionsBefore) {
|
|
2041
|
+
if (placement.join.beforeNodeId !== nodeId) continue;
|
|
2042
|
+
for (const gate of placement.join.gates) verifyGate(gate, node);
|
|
2043
|
+
if (definedConditions.has(conditionEvent(placement.join.id))) fail("motion-plan-conflict", "Same step repeatedly defined condition collection", nodePath(node));
|
|
2044
|
+
definedConditions.add(conditionEvent(placement.join.id));
|
|
2045
|
+
remainingRootPlacements.delete(placement);
|
|
2046
|
+
}
|
|
2047
|
+
verifyNodeOrder(node);
|
|
2048
|
+
}
|
|
2049
|
+
if (remainingRootPlacements.size > 0) fail("motion-plan-conflict", "Root with-group lacks actual consumer node for condition collection");
|
|
2050
|
+
const queryScopesByIdentity = new Map(queryScopes.map((scope) => [scope.identity, scope]));
|
|
2051
|
+
for (const scope of scopes.values()) {
|
|
2052
|
+
const identity = scope.declaration.identity;
|
|
2053
|
+
if (!queryScopeIdentities.has(identity) || queryScopesByIdentity.has(identity)) continue;
|
|
2054
|
+
const start = resolveScopeStart(scope);
|
|
2055
|
+
const end = resolveScopeEnd(scope);
|
|
2056
|
+
queryScopesByIdentity.set(identity, {
|
|
2057
|
+
identity,
|
|
2058
|
+
id: scopeId(identity, scopes),
|
|
2059
|
+
...scope.declaration.parent === void 0 ? {} : { parentIdentity: scope.declaration.parent },
|
|
2060
|
+
mode: scope.declaration.mode,
|
|
2061
|
+
...scope.declaration.each === void 0 ? {} : { eachMs: Math.round(scope.declaration.each) },
|
|
2062
|
+
delayMs: Math.round(scope.declaration.delay),
|
|
2063
|
+
members: queryDeclarationMembers(scope).map((member) => member.kind === "scope" ? {
|
|
2064
|
+
kind: "scope",
|
|
2065
|
+
identity: member.id
|
|
2066
|
+
} : {
|
|
2067
|
+
kind: "object",
|
|
2068
|
+
targetId: member.id
|
|
2069
|
+
}),
|
|
2070
|
+
start: queryMomentSource(start),
|
|
2071
|
+
end: queryMomentSource(end),
|
|
2072
|
+
declaration: scope.declaration
|
|
2073
|
+
});
|
|
2074
|
+
}
|
|
2075
|
+
queryScopes.length = 0;
|
|
2076
|
+
for (const scope of scopes.values()) {
|
|
2077
|
+
const queryScope = queryScopesByIdentity.get(scope.declaration.identity);
|
|
2078
|
+
if (queryScope !== void 0) queryScopes.push(queryScope);
|
|
2079
|
+
}
|
|
2080
|
+
allStepNodes.set(key, nodes);
|
|
2081
|
+
const queryCues = [];
|
|
2082
|
+
for (const [cueKey, publisher] of cuePublishers) {
|
|
2083
|
+
const publisherScope = scopes.get(publisher.scope);
|
|
2084
|
+
if (publisherScope === void 0 || !scopeSteps(publisherScope).includes(key)) continue;
|
|
2085
|
+
const declaration = publisher.point === "start" ? publisherScope.declaration.publishStart : publisherScope.declaration.publishEnd;
|
|
2086
|
+
if (declaration?.point !== "named" || declaration.name === void 0) continue;
|
|
2087
|
+
queryCues.push({
|
|
2088
|
+
key: cueKey,
|
|
2089
|
+
name: declaration.name,
|
|
2090
|
+
scopeIdentity: publisher.scope,
|
|
2091
|
+
point: publisher.point
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2094
|
+
querySourcesByStep.set(key, {
|
|
2095
|
+
key,
|
|
2096
|
+
trigger: step.trigger,
|
|
2097
|
+
...step.number === void 0 ? {} : { number: step.number },
|
|
2098
|
+
facts: {
|
|
2099
|
+
exactOffset: (from, to) => facts.exactOffset(from, to),
|
|
2100
|
+
lowerBound: (from, to) => facts.lowerBound(from, to)
|
|
2101
|
+
},
|
|
2102
|
+
effectSources: queryEffectSources,
|
|
2103
|
+
scopes: queryScopes,
|
|
2104
|
+
cues: queryCues
|
|
2105
|
+
});
|
|
2106
|
+
allStepConditionDefinitions.set(key, rootConditionDefinitionsBefore);
|
|
2107
|
+
}
|
|
2108
|
+
const plans = [...stepStates.values()].sort((left, right) => {
|
|
2109
|
+
if (left.trigger !== right.trigger) return left.trigger === "auto" ? -1 : 1;
|
|
2110
|
+
return left.order - right.order;
|
|
2111
|
+
}).map((step) => {
|
|
2112
|
+
const effects = (allScheduledEffects.get(step.key) ?? []).slice().sort((left, right) => (left.startMs ?? Number.MAX_SAFE_INTEGER) - (right.startMs ?? Number.MAX_SAFE_INTEGER) || left.target.id - right.target.id || left.order - right.order);
|
|
2113
|
+
const conditionDefinitionsBefore = allStepConditionDefinitions.get(step.key) ?? [];
|
|
2114
|
+
return {
|
|
2115
|
+
key: step.key,
|
|
2116
|
+
trigger: step.trigger,
|
|
2117
|
+
...step.number === void 0 ? {} : { number: step.number },
|
|
2118
|
+
order: step.order,
|
|
2119
|
+
effects,
|
|
2120
|
+
nodes: allStepNodes.get(step.key) ?? [],
|
|
2121
|
+
...conditionDefinitionsBefore.length === 0 ? {} : { conditionDefinitionsBefore }
|
|
2122
|
+
};
|
|
2123
|
+
});
|
|
2124
|
+
const querySources = plans.map((step) => {
|
|
2125
|
+
const source = querySourcesByStep.get(step.key);
|
|
2126
|
+
if (source === void 0) throw new Error("MotionPlan query step is missing");
|
|
2127
|
+
const effects = step.effects.map((effect) => {
|
|
2128
|
+
const effectSource = source.effectSources.get(motionEffectKey(effect.target.id, effect.effectIndex, effect.partIndex));
|
|
2129
|
+
if (effectSource === void 0) throw new Error("MotionPlan query effect is missing");
|
|
2130
|
+
return effectSource;
|
|
2131
|
+
});
|
|
2132
|
+
return {
|
|
2133
|
+
key: source.key,
|
|
2134
|
+
trigger: source.trigger,
|
|
2135
|
+
...source.number === void 0 ? {} : { number: source.number },
|
|
2136
|
+
facts: source.facts,
|
|
2137
|
+
effects,
|
|
2138
|
+
scopes: source.scopes,
|
|
2139
|
+
cues: source.cues
|
|
2140
|
+
};
|
|
2141
|
+
});
|
|
2142
|
+
const scopesObservation = scopeObservations.sort((left, right) => {
|
|
2143
|
+
const leftScope = [...scopes.values()].find((scope) => scopeId(scope.declaration.identity, scopes) === left.id);
|
|
2144
|
+
const rightScope = [...scopes.values()].find((scope) => scopeId(scope.declaration.identity, scopes) === right.id);
|
|
2145
|
+
return (leftScope?.order ?? 0) - (rightScope?.order ?? 0);
|
|
2146
|
+
});
|
|
2147
|
+
return {
|
|
2148
|
+
steps: plans,
|
|
2149
|
+
observation: Object.freeze({
|
|
2150
|
+
steps: Object.freeze(plans.map(({ effects, trigger, number }) => ({
|
|
2151
|
+
trigger,
|
|
2152
|
+
...number === void 0 ? {} : { number },
|
|
2153
|
+
effects: Object.freeze(effects.map(({ stepKey: _stepKey, order: _order, targetKind: _targetKind, targetTextBody: _targetTextBody, targetFilled: _targetFilled, targetBox: _targetBox, targetRotationDegrees: _targetRotationDegrees, targetHasBackground: _targetHasBackground, targetParagraphCount: _targetParagraphCount, targetMembers: _targetMembers, effectIndex: _effectIndex, partIndex: _partIndex, iterate: _iterate, ...effect }) => Object.freeze(effect)))
|
|
2154
|
+
}))),
|
|
2155
|
+
...scopesObservation.length === 0 ? {} : { scopes: Object.freeze(scopesObservation) }
|
|
2156
|
+
}),
|
|
2157
|
+
query: createMotionQuery(querySources)
|
|
2158
|
+
};
|
|
2159
|
+
}
|
|
2160
|
+
function queryMomentSource(time) {
|
|
2161
|
+
if (time.state === "no-natural-completion") return { time: { state: "no-natural-completion" } };
|
|
2162
|
+
return {
|
|
2163
|
+
eventId: time.eventId,
|
|
2164
|
+
time: time.state === "known" ? {
|
|
2165
|
+
state: "known",
|
|
2166
|
+
ms: time.timeMs
|
|
2167
|
+
} : { state: "unknown" }
|
|
2168
|
+
};
|
|
2169
|
+
}
|
|
2170
|
+
function motionEffectKey(targetId, effectIndex, partIndex) {
|
|
2171
|
+
return `${targetId}:${effectIndex}:${partIndex ?? ""}`;
|
|
2172
|
+
}
|
|
2173
|
+
function scopeId(identity, scopes) {
|
|
2174
|
+
return `scope-${[...scopes.values()].sort((left, right) => left.order - right.order).findIndex((scope) => scope.declaration.identity === identity) + 1}`;
|
|
2175
|
+
}
|
|
2176
|
+
function normalizedEasing(easing) {
|
|
2177
|
+
if (easing === void 0) return void 0;
|
|
2178
|
+
const accelerate = easing.accelerate === void 0 ? void 0 : Math.round(easing.accelerate * 1e5) / 1e5;
|
|
2179
|
+
const decelerate = easing.decelerate === void 0 ? void 0 : Math.round(easing.decelerate * 1e5) / 1e5;
|
|
2180
|
+
if ((accelerate === void 0 || accelerate === 0) && (decelerate === void 0 || decelerate === 0)) return;
|
|
2181
|
+
return Object.freeze({
|
|
2182
|
+
...accelerate === void 0 || accelerate === 0 ? {} : { accelerate },
|
|
2183
|
+
...decelerate === void 0 || decelerate === 0 ? {} : { decelerate }
|
|
2184
|
+
});
|
|
2185
|
+
}
|
|
2186
|
+
function compileMotionPlan(contributions) {
|
|
2187
|
+
return motionPlan(contributions);
|
|
2188
|
+
}
|
|
2189
|
+
export { addMotionPlanStartDelay, compileMotionPlan, composeMotionPlanStarts, motionPlanStartLayers };
|