skia-motion-runtime 3.0.0 → 3.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/package.json +34 -13
- package/runtime/asset-draw.ts +136 -32
- package/runtime/asset-image.ts +3 -20
- package/runtime/asset-layout.ts +27 -0
- package/runtime/asset-load.ts +70 -0
- package/runtime/asset.ts +255 -18
- package/runtime/base64.ts +19 -0
- package/runtime/expo-audio.ts +72 -0
- package/runtime/expo.ts +16 -0
- package/runtime/machine-schema.js +3 -3
- package/runtime/mobile.tsx +199 -94
- package/runtime/useMachine.ts +82 -12
- package/runtime/useMotionAsset.ts +107 -0
- package/templates/motion/machine.ts +6 -4
|
@@ -101,12 +101,13 @@ export function compile(m: Machine, clips: Clips): Compiled {
|
|
|
101
101
|
for (const name of Object.keys(m.values ?? {})) {
|
|
102
102
|
const v = m.values![name]!;
|
|
103
103
|
index[name] = values.length;
|
|
104
|
-
const def: Literal = v.default !== undefined ? v.default
|
|
104
|
+
const def: Literal = v.default !== undefined ? v.default
|
|
105
|
+
: v.type === 'number' ? 0 : v.type === 'enum' ? v.options![0]! : v.type === 'string' ? '' : false;
|
|
105
106
|
values.push({ name, type: v.type, def, bind: v.bind ?? 'in', options: v.options ?? [] });
|
|
106
107
|
}
|
|
107
108
|
// A string operand names a value unless it is an option of the enum it is compared with or written to.
|
|
108
109
|
const ref = (x: Literal, owner: string): number =>
|
|
109
|
-
(typeof x === 'string' && index
|
|
110
|
+
(typeof x === 'string' && Object.hasOwn(index, x) && !(m.values?.[owner]?.options ?? []).includes(x) ? index[x]! : -1);
|
|
110
111
|
const conds = (when: readonly Condition[] | undefined): CCond[] =>
|
|
111
112
|
(when ?? []).map(([name, op, rhs]): CCond => {
|
|
112
113
|
const owner = name as string;
|
|
@@ -273,13 +274,14 @@ function step(c: Compiled, s: Snapshot, li: number, t: number, clock: ClockRead,
|
|
|
273
274
|
*/
|
|
274
275
|
export function writeProblem(c: Compiled, name: string, to: Literal): string {
|
|
275
276
|
'worklet';
|
|
276
|
-
|
|
277
|
-
|
|
277
|
+
if (!Object.hasOwn(c.index, name)) return `the machine has no value "${name}"`;
|
|
278
|
+
const i = c.index[name]!;
|
|
278
279
|
const v = c.values[i]!;
|
|
279
280
|
if (v.bind === 'out') return `"${name}" is an out-value: the machine writes it, the app reads it`;
|
|
280
281
|
const fits = v.type === 'trigger' ? to === true
|
|
281
282
|
: v.type === 'boolean' ? typeof to === 'boolean'
|
|
282
283
|
: v.type === 'number' ? typeof to === 'number' && Number.isFinite(to)
|
|
284
|
+
: v.type === 'string' ? typeof to === 'string' && to.length <= 4096
|
|
283
285
|
: typeof to === 'string' && v.options.includes(to);
|
|
284
286
|
if (fits) return '';
|
|
285
287
|
const wanted = v.type === 'trigger' ? 'a fire (true)' : v.type === 'enum' ? `one of ${v.options.join(', ')}` : `a ${v.type}`;
|