alpha2 0.2.2 → 0.3.1

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/dist/project.d.ts CHANGED
@@ -150,6 +150,15 @@ export type LintOwner = {
150
150
  readonly track: string;
151
151
  readonly index: number;
152
152
  };
153
+ /** The shapes generator a shape {@link LintIssue} is about. */
154
+ export type ShapeLintOwner = {
155
+ readonly type: "source";
156
+ readonly source: string;
157
+ } | {
158
+ readonly type: "node";
159
+ readonly composition: string;
160
+ readonly node: string;
161
+ };
153
162
  /**
154
163
  * Something in a valid project that is probably not meant. Every check is conservative: a reported
155
164
  * issue is certain.
@@ -198,6 +207,20 @@ export type LintIssue =
198
207
  | {
199
208
  readonly kind: "hdr_source";
200
209
  readonly source: string;
210
+ }
211
+ /** A path's subpath without vertices, which draws nothing. */
212
+ | {
213
+ readonly kind: "empty_subpath";
214
+ readonly owner: ShapeLintOwner;
215
+ /** Such as `items[0].path.subpaths[1]`. */
216
+ readonly at: string;
217
+ }
218
+ /** A fill or stroke with no geometry before it in its group, which paints nothing. */
219
+ | {
220
+ readonly kind: "paint_without_geometry";
221
+ readonly owner: ShapeLintOwner;
222
+ /** Such as `items[1].items[0]`. */
223
+ readonly at: string;
201
224
  };
202
225
  /** The part of `alpha2/wasm` {@link lintProject} uses. */
203
226
  export interface LintBinding {
@@ -205,8 +228,9 @@ export interface LintBinding {
205
228
  }
206
229
  /**
207
230
  * A valid project's non-fatal diagnostics, computed by the engine's own
208
- * `Project::lint`, in a fixed order: sources, then each track's clips,
209
- * transitions, and cues.
231
+ * `Project::lint`, in a fixed order: unused sources, then shapes generators
232
+ * (sources', then composition nodes'), then HDR sources, then each track's
233
+ * clips, transitions, and cues.
210
234
  *
211
235
  * Diagnostics never block a load or an export; they flag what is probably a
212
236
  * mistake in a project the engine accepts.
package/dist/project.js CHANGED
@@ -14,7 +14,7 @@
14
14
  * Timeline values are integer ticks at {@link TICKS_PER_SECOND}. Ranges are
15
15
  * half-open: `[start, end)`.
16
16
  */
17
- import { AUDIO_EFFECT_STATE_MARGIN_MS, MAX_CANVAS_DIMENSION, MAX_CANVAS_PIXELS, MAX_TEXT_CONTENT_BYTES, MAX_FONT_FAMILY_BYTES, MAX_COMPOSITIONS, MAX_COMPOSITION_NODES, MAX_COMPOSITION_CONTROLS, MAX_COMPOSITION_DEPTH, MAX_GROUP_INPUTS, MAX_FRAME_INLINED_NODES, MAX_INLINED_NODES, MAX_MERGE_LAYERS, MAX_CLIP_MASKS, MAX_GRADIENT_STOPS, MAX_CLIPS, MAX_CLIPS_PER_TRACK, MAX_AUDIO_DELAY_MS, MAX_AUDIO_EFFECTS, MAX_CAPTION_FONT_SIZE, MAX_TEXT_GENERATOR_FONT_SIZE, MAX_LINE_HEIGHT, MAX_TEXT_OUTLINE_WIDTH, MAX_TEXT_PADDING, MAX_CHAIN_EFFECTS, MAX_COMPRESSOR_RATIO, MAX_ENVELOPE_MS, MAX_EQ_BANDS, MAX_LOOKAHEAD_MS, MIN_LINE_HEIGHT, MIN_LEVEL_DB, MAX_EQ_FREQUENCY_HZ, MAX_EQ_GAIN_DB, MAX_EQ_Q, MAX_GAIN, MAX_PROJECT_JSON_BYTES, MAX_SAMPLE_RATE, MAX_TRACKS, MAX_TRANSITIONS_PER_TRACK, MIN_EQ_FREQUENCY_HZ, MIN_EQ_Q, MIN_SAMPLE_RATE, MIN_HDR_PEAK_NITS, MAX_HDR_PEAK_NITS, MAX_SEQUENCE_FRAMES, REVERB_DELAY_MS, TICKS_PER_SECOND, } from "./generated/project-schema.js";
17
+ import { AUDIO_EFFECT_STATE_MARGIN_MS, MAX_CANVAS_DIMENSION, MAX_CANVAS_PIXELS, MAX_TEXT_CONTENT_BYTES, MAX_FONT_FAMILY_BYTES, MAX_COMPOSITIONS, MAX_COMPOSITION_NODES, MAX_COMPOSITION_CONTROLS, MAX_COMPOSITION_DEPTH, MAX_GROUP_INPUTS, MAX_EFFECT_INPUTS, MAX_FRAME_INLINED_NODES, MAX_INLINED_NODES, MAX_MERGE_LAYERS, MAX_CLIP_MASKS, MAX_DASH_ENTRIES, MAX_GRADIENT_STOPS, MAX_PATH_SUBPATHS, MAX_PATH_VERTICES, MAX_POLYSTAR_POINTS, MAX_SHAPE_DEPTH, MAX_SHAPE_ITEMS, MIN_POLYSTAR_POINTS, MAX_CLIPS, MAX_CLIPS_PER_TRACK, MAX_AUDIO_DELAY_MS, MAX_AUDIO_EFFECTS, MAX_CAPTION_FONT_SIZE, MAX_TEXT_GENERATOR_FONT_SIZE, MAX_LINE_HEIGHT, MAX_TEXT_OUTLINE_WIDTH, MAX_TEXT_PADDING, MAX_CHAIN_EFFECTS, MAX_COMPRESSOR_RATIO, MAX_ENVELOPE_MS, MAX_EQ_BANDS, MAX_LOOKAHEAD_MS, MIN_LINE_HEIGHT, MIN_LEVEL_DB, MAX_EQ_FREQUENCY_HZ, MAX_EQ_GAIN_DB, MAX_EQ_Q, MAX_GAIN, MAX_PROJECT_JSON_BYTES, MAX_SAMPLE_RATE, MAX_TRACKS, MAX_TRANSITIONS_PER_TRACK, MIN_EQ_FREQUENCY_HZ, MIN_EQ_Q, MIN_SAMPLE_RATE, MIN_HDR_PEAK_NITS, MAX_HDR_PEAK_NITS, MAX_SEQUENCE_FRAMES, REVERB_DELAY_MS, TICKS_PER_SECOND, } from "./generated/project-schema.js";
18
18
  import { PROJECT_SHAPE } from "./generated/project-shape.js";
19
19
  import { MAX_JSON_DEPTH, hasLoneSurrogate, readJsonText, } from "./json-text.js";
20
20
  export * from "./generated/project-schema.js";
@@ -263,7 +263,11 @@ function catalogOf(sourceList, resourceList, compositionList) {
263
263
  problems.push(`source ${sourceId} is not a valid composition source`);
264
264
  }
265
265
  else if (source.kind === "generated") {
266
- if (!validGenerator(source.generator) ||
266
+ const issue = generatorShapeIssue(source.generator);
267
+ if (issue) {
268
+ problems.push(shapeProblem(`source ${sourceId}`, issue));
269
+ }
270
+ else if (!validGenerator(source.generator) ||
267
271
  text(source.locator).length > 0 ||
268
272
  source.color_metadata != null ||
269
273
  source.has_audio === true) {
@@ -445,9 +449,14 @@ function clipProblems(clip, trackKind, catalog) {
445
449
  }
446
450
  for (const problem of audioProblems(clipId, clip.audio))
447
451
  problems.push(problem);
448
- if (!validMasks(clip.masks, trackKind)) {
452
+ if (!validMaskCount(clip.masks, trackKind)) {
449
453
  problems.push(`clip ${clipId} has an invalid mask`);
450
454
  }
455
+ else {
456
+ const issue = masksIssue(clip.masks);
457
+ if (issue)
458
+ problems.push(shapeProblem(`clip ${clipId}`, issue));
459
+ }
451
460
  if (clip.matte != null && trackKind !== "video") {
452
461
  problems.push(`clip ${clipId} has an invalid matte`);
453
462
  }
@@ -1398,7 +1407,7 @@ function validVisual(visual) {
1398
1407
  return true;
1399
1408
  return (isRecord(visual) &&
1400
1409
  validVec2(visual.anchor) &&
1401
- validVec2Animation(visual.position) &&
1410
+ validPointAnimation(visual.position) &&
1402
1411
  validVec2Animation(visual.scale) &&
1403
1412
  visual.rotation_degrees !== undefined &&
1404
1413
  validScalarAnimation(visual.rotation_degrees) &&
@@ -1454,7 +1463,10 @@ function validEffectParam(param) {
1454
1463
  param.keyframes.every((keyframe) => isRecord(keyframe.interpolation) &&
1455
1464
  keyframe.interpolation.type === "hold"));
1456
1465
  }
1457
- /** A parameter or resource name an effect may bind: an ASCII identifier, as the model requires. */
1466
+ /**
1467
+ * A parameter, resource, or named input an effect may bind: an ASCII identifier, as the model
1468
+ * requires.
1469
+ */
1458
1470
  const EFFECT_BINDING_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
1459
1471
  function validClipEffect(effect) {
1460
1472
  if (!isRecord(effect))
@@ -1470,6 +1482,16 @@ function validClipEffect(effect) {
1470
1482
  Object.entries(params ?? {}).every(([name, value]) => EFFECT_BINDING_NAME.test(name) && validEffectParam(value)) &&
1471
1483
  Object.entries(resources ?? {}).every(([name, id]) => EFFECT_BINDING_NAME.test(name) && text(id).length > 0));
1472
1484
  }
1485
+ /** An effect node's named inputs: absent, or at most `MAX_EFFECT_INPUTS` well-named ones. */
1486
+ function validEffectInputs(inputs) {
1487
+ if (inputs === undefined)
1488
+ return true;
1489
+ if (!isRecord(inputs))
1490
+ return false;
1491
+ const names = Object.keys(inputs);
1492
+ return (names.length <= MAX_EFFECT_INPUTS &&
1493
+ names.every((name) => EFFECT_BINDING_NAME.test(name)));
1494
+ }
1473
1495
  function positiveMs(value) {
1474
1496
  return finiteNumber(value) && value > 0 && value <= MAX_ENVELOPE_MS;
1475
1497
  }
@@ -1837,41 +1859,294 @@ function positive(value) {
1837
1859
  return typeof value === "number" && value > 0;
1838
1860
  }
1839
1861
  /**
1840
- * A fill, or a shape with a fill or a stroke, whose paints are valid: colors in `0..=1`, gradients
1841
- * of two to {@link MAX_GRADIENT_STOPS} ordered stops, a linear gradient's ends distinct, a radial
1842
- * radius and a stroke width positive. Or text: non-empty, at most {@link MAX_TEXT_CONTENT_BYTES}
1843
- * bytes, in a valid style whose font size is at most {@link MAX_TEXT_GENERATOR_FONT_SIZE}.
1862
+ * A fill whose paint is valid: colors in `0..=1`, gradients of two to {@link MAX_GRADIENT_STOPS}
1863
+ * ordered stops, a linear gradient's ends distinct, a radial radius positive. Or shapes whose
1864
+ * content tree is valid ({@link shapeItemsIssue}). Or text: non-empty, at most
1865
+ * {@link MAX_TEXT_CONTENT_BYTES} bytes, in a valid style whose font size is at most
1866
+ * {@link MAX_TEXT_GENERATOR_FONT_SIZE}.
1844
1867
  */
1845
1868
  function validGenerator(generator) {
1846
1869
  if (!isRecord(generator))
1847
1870
  return false;
1848
1871
  if (generator.type === "fill")
1849
1872
  return validPaint(generator.paint);
1873
+ if (generator.type === "shapes")
1874
+ return shapeItemsIssue(generator.items) === undefined;
1850
1875
  if (generator.type === "text")
1851
1876
  return (typeof generator.text === "string" &&
1852
1877
  generator.text.length > 0 &&
1853
1878
  new TextEncoder().encode(generator.text).length <=
1854
1879
  MAX_TEXT_CONTENT_BYTES &&
1855
1880
  validTextStyle(generator.style ?? {}, MAX_TEXT_GENERATOR_FONT_SIZE));
1856
- if (generator.type !== "shape")
1857
- return false;
1858
- const shape = isRecord(generator.shape) ? generator.shape : {};
1859
- const radius = shape.corner_radius ?? 0;
1860
- const size = generator.size;
1861
- const stroke = generator.stroke;
1862
- return ((shape.type !== "rectangle" || (finiteNumber(radius) && radius >= 0)) &&
1863
- validVec2(generator.center) &&
1864
- validVec2(size) &&
1865
- size.x >= 0 &&
1866
- size.y >= 0 &&
1867
- finiteNumber(generator.rotation_degrees ?? 0) &&
1868
- (generator.fill != null || stroke != null) &&
1869
- (generator.fill == null || validPaint(generator.fill)) &&
1870
- (stroke == null ||
1871
- (isRecord(stroke) &&
1872
- finiteNumber(stroke.width) &&
1873
- stroke.width > 0 &&
1874
- validPaint(stroke.paint))));
1881
+ return false;
1882
+ }
1883
+ /** Mirrors `ShapeProblem`'s wording. */
1884
+ const SHAPE_PROBLEM = {
1885
+ tooManyItems: "has more items than a shapes generator may hold",
1886
+ tooDeep: "nests groups too deeply",
1887
+ pathTooLarge: "has more subpaths or vertices than a path may hold",
1888
+ invalidDash: "has an invalid dash pattern",
1889
+ invalidKeyframes: "has invalid keyframes",
1890
+ outOfRange: "has a value out of range",
1891
+ pathKeyframesDiffer: "has path keyframes that differ in structure",
1892
+ paintKeyframesDiffer: "has paint keyframes that differ in kind or stops",
1893
+ };
1894
+ /** A generator's shape problem, if it is a shapes generator with one. */
1895
+ function generatorShapeIssue(generator) {
1896
+ return isRecord(generator) && generator.type === "shapes"
1897
+ ? shapeItemsIssue(generator.items)
1898
+ : undefined;
1899
+ }
1900
+ /** `issue` as a problem of `owner` (`source s`, `clip c`, `node n of composition g`). */
1901
+ function shapeProblem(owner, issue) {
1902
+ return `${owner} has an invalid shape: ${issue.at} ${issue.problem}`;
1903
+ }
1904
+ /**
1905
+ * Mirrors `validate_shape_items`: the first problem of a content tree in document order. Its
1906
+ * limits ({@link MAX_SHAPE_ITEMS} items over every group, groups {@link MAX_SHAPE_DEPTH}
1907
+ * deep), every value's range, and keyframed paths and paints alike in structure.
1908
+ */
1909
+ function shapeItemsIssue(items) {
1910
+ const counted = { count: 0 };
1911
+ return shapeGroupIssue(items, "items", 1, counted);
1912
+ }
1913
+ function shapeGroupIssue(items, at, depth, counted) {
1914
+ if (depth > MAX_SHAPE_DEPTH)
1915
+ return { at, problem: SHAPE_PROBLEM.tooDeep };
1916
+ const list = Array.isArray(items) ? items : [];
1917
+ for (const [index, item] of list.entries()) {
1918
+ const here = `${at}[${index}]`;
1919
+ counted.count += 1;
1920
+ if (counted.count > MAX_SHAPE_ITEMS) {
1921
+ return { at: here, problem: SHAPE_PROBLEM.tooManyItems };
1922
+ }
1923
+ const issue = shapeItemIssue(item, here, depth, counted);
1924
+ if (issue)
1925
+ return issue;
1926
+ }
1927
+ return undefined;
1928
+ }
1929
+ function shapeItemIssue(item, at, depth, counted) {
1930
+ if (!isRecord(item))
1931
+ return { at, problem: SHAPE_PROBLEM.outOfRange };
1932
+ switch (item.type) {
1933
+ case "group":
1934
+ return (shapeTransformIssue(item.transform, `${at}.transform`) ??
1935
+ shapeGroupIssue(item.items, `${at}.items`, depth + 1, counted));
1936
+ case "rectangle":
1937
+ case "ellipse":
1938
+ case "polystar":
1939
+ case "path":
1940
+ return shapeGeometryIssue(item, at);
1941
+ case "fill":
1942
+ return (animatedPaintIssue(item.paint, `${at}.paint`) ??
1943
+ shapeScalarIssue(item.opacity, `${at}.opacity`, unitValue));
1944
+ case "stroke":
1945
+ return strokeIssue(item, at);
1946
+ case "trim":
1947
+ return (shapeScalarIssue(item.start, `${at}.start`, unitValue) ??
1948
+ shapeScalarIssue(item.end, `${at}.end`, unitValue) ??
1949
+ shapeScalarIssue(item.offset, `${at}.offset`, anyValue));
1950
+ default:
1951
+ return { at, problem: SHAPE_PROBLEM.outOfRange };
1952
+ }
1953
+ }
1954
+ const unitValue = (value) => value >= 0 && value <= 1;
1955
+ const nonNegativeValue = (value) => value >= 0;
1956
+ const anyValue = () => true;
1957
+ /**
1958
+ * An animated scalar's problem: keyframes empty, out of order, or with an unusable curve, then any
1959
+ * value not finite or failing `check`. A missing value takes its default, which is valid.
1960
+ */
1961
+ function shapeScalarIssue(animation, at, check) {
1962
+ if (animation === undefined)
1963
+ return undefined;
1964
+ const values = animationValues(animation);
1965
+ if (values === undefined) {
1966
+ return { at, problem: SHAPE_PROBLEM.invalidKeyframes };
1967
+ }
1968
+ return values.every((value) => finiteNumber(value) && check(value))
1969
+ ? undefined
1970
+ : { at, problem: SHAPE_PROBLEM.outOfRange };
1971
+ }
1972
+ function shapeVec2Issue(animation, at, check) {
1973
+ if (animation === undefined)
1974
+ return undefined;
1975
+ const values = animationValues(animation);
1976
+ if (values === undefined) {
1977
+ return { at, problem: SHAPE_PROBLEM.invalidKeyframes };
1978
+ }
1979
+ return values.every((value) => validVec2(value) && check(value))
1980
+ ? undefined
1981
+ : { at, problem: SHAPE_PROBLEM.outOfRange };
1982
+ }
1983
+ /** Mirrors `valid_point_animation`: keyframes as any animation's, values and tangents finite. */
1984
+ function validPointAnimation(animation) {
1985
+ return shapePointIssue(animation, "") === undefined;
1986
+ }
1987
+ function shapePointIssue(animation, at) {
1988
+ if (animation === undefined)
1989
+ return undefined;
1990
+ const values = animationValues(animation);
1991
+ if (values === undefined) {
1992
+ return { at, problem: SHAPE_PROBLEM.invalidKeyframes };
1993
+ }
1994
+ const keyframes = isRecord(animation) && Array.isArray(animation.keyframes)
1995
+ ? animation.keyframes
1996
+ : [];
1997
+ const tangents = keyframes.every((keyframe) => isRecord(keyframe) &&
1998
+ (keyframe.in_tangent === undefined || validVec2(keyframe.in_tangent)) &&
1999
+ (keyframe.out_tangent === undefined || validVec2(keyframe.out_tangent)));
2000
+ return tangents && values.every(validVec2)
2001
+ ? undefined
2002
+ : { at, problem: SHAPE_PROBLEM.outOfRange };
2003
+ }
2004
+ const nonNegativeSize = (value) => value.x >= 0 && value.y >= 0;
2005
+ /** Mirrors `ShapeGeometry::validate`: a mask's outline, or a content tree's geometry item. */
2006
+ function shapeGeometryIssue(geometry, at) {
2007
+ switch (geometry.type) {
2008
+ case "rectangle":
2009
+ return (shapePointIssue(geometry.center, `${at}.center`) ??
2010
+ shapeVec2Issue(geometry.size, `${at}.size`, nonNegativeSize) ??
2011
+ shapeScalarIssue(geometry.corner_radius, `${at}.corner_radius`, nonNegativeValue) ??
2012
+ shapeScalarIssue(geometry.rotation_degrees, `${at}.rotation_degrees`, anyValue));
2013
+ case "ellipse":
2014
+ return (shapePointIssue(geometry.center, `${at}.center`) ??
2015
+ shapeVec2Issue(geometry.size, `${at}.size`, nonNegativeSize) ??
2016
+ shapeScalarIssue(geometry.rotation_degrees, `${at}.rotation_degrees`, anyValue));
2017
+ case "polystar":
2018
+ return (shapePointIssue(geometry.center, `${at}.center`) ??
2019
+ shapeScalarIssue(geometry.points, `${at}.points`, (points) => points >= MIN_POLYSTAR_POINTS && points <= MAX_POLYSTAR_POINTS) ??
2020
+ shapeScalarIssue(geometry.outer_radius, `${at}.outer_radius`, nonNegativeValue) ??
2021
+ shapeScalarIssue(geometry.inner_radius, `${at}.inner_radius`, nonNegativeValue) ??
2022
+ shapeScalarIssue(geometry.outer_roundness, `${at}.outer_roundness`, unitValue) ??
2023
+ shapeScalarIssue(geometry.inner_roundness, `${at}.inner_roundness`, unitValue) ??
2024
+ shapeScalarIssue(geometry.rotation_degrees, `${at}.rotation_degrees`, anyValue));
2025
+ case "path":
2026
+ return animatedPathIssue(geometry.path, `${at}.path`);
2027
+ default:
2028
+ return { at, problem: SHAPE_PROBLEM.outOfRange };
2029
+ }
2030
+ }
2031
+ function shapeTransformIssue(transform, at) {
2032
+ if (!isRecord(transform))
2033
+ return undefined;
2034
+ return (shapeVec2Issue(transform.anchor, `${at}.anchor`, () => true) ??
2035
+ shapePointIssue(transform.position, `${at}.position`) ??
2036
+ shapeVec2Issue(transform.scale, `${at}.scale`, () => true) ??
2037
+ shapeScalarIssue(transform.rotation_degrees, `${at}.rotation_degrees`, anyValue) ??
2038
+ shapeScalarIssue(transform.opacity, `${at}.opacity`, unitValue));
2039
+ }
2040
+ function strokeIssue(stroke, at) {
2041
+ const issue = animatedPaintIssue(stroke.paint, `${at}.paint`) ??
2042
+ shapeScalarIssue(stroke.width, `${at}.width`, nonNegativeValue) ??
2043
+ shapeScalarIssue(stroke.opacity, `${at}.opacity`, unitValue);
2044
+ if (issue)
2045
+ return issue;
2046
+ const miter = stroke.miter_limit ?? 4;
2047
+ if (!finiteNumber(miter) || miter < 1) {
2048
+ return { at: `${at}.miter_limit`, problem: SHAPE_PROBLEM.outOfRange };
2049
+ }
2050
+ if (stroke.dash == null)
2051
+ return undefined;
2052
+ const dash = isRecord(stroke.dash) ? stroke.dash : {};
2053
+ const pattern = Array.isArray(dash.pattern)
2054
+ ? dash.pattern
2055
+ : [];
2056
+ const patternAt = `${at}.dash.pattern`;
2057
+ if (pattern.length === 0 || pattern.length > MAX_DASH_ENTRIES) {
2058
+ return { at: patternAt, problem: SHAPE_PROBLEM.invalidDash };
2059
+ }
2060
+ for (const [index, entry] of pattern.entries()) {
2061
+ const entryIssue = shapeScalarIssue(entry, `${patternAt}[${index}]`, nonNegativeValue);
2062
+ if (entryIssue)
2063
+ return entryIssue;
2064
+ }
2065
+ // Some entry positive at some keyframe: the pattern has a length to repeat over.
2066
+ const positive = pattern.some((entry) => (animationValues(entry) ?? []).some((value) => value > 0));
2067
+ if (!positive)
2068
+ return { at: patternAt, problem: SHAPE_PROBLEM.invalidDash };
2069
+ return shapeScalarIssue(dash.offset, `${at}.dash.offset`, anyValue);
2070
+ }
2071
+ /** A path's subpaths and vertex counts within the limits, every point and tangent finite. */
2072
+ function pathIssue(path, at) {
2073
+ const subpaths = isRecord(path) && Array.isArray(path.subpaths)
2074
+ ? path.subpaths
2075
+ : [];
2076
+ let vertices = 0;
2077
+ for (const subpath of subpaths) {
2078
+ if (isRecord(subpath) && Array.isArray(subpath.vertices)) {
2079
+ vertices += subpath.vertices.length;
2080
+ }
2081
+ }
2082
+ if (subpaths.length > MAX_PATH_SUBPATHS || vertices > MAX_PATH_VERTICES) {
2083
+ return { at, problem: SHAPE_PROBLEM.pathTooLarge };
2084
+ }
2085
+ const finite = subpaths.every((subpath) => isRecord(subpath) &&
2086
+ Array.isArray(subpath.vertices) &&
2087
+ subpath.vertices.every((vertex) => isRecord(vertex) &&
2088
+ validVec2(vertex.point) &&
2089
+ (vertex.in_tangent === undefined || validVec2(vertex.in_tangent)) &&
2090
+ (vertex.out_tangent === undefined || validVec2(vertex.out_tangent))));
2091
+ return finite ? undefined : { at, problem: SHAPE_PROBLEM.outOfRange };
2092
+ }
2093
+ /** What two path keyframes must share: each subpath's closing and vertex count. */
2094
+ function pathStructure(path) {
2095
+ const subpaths = isRecord(path) && Array.isArray(path.subpaths)
2096
+ ? path.subpaths
2097
+ : [];
2098
+ return subpaths
2099
+ .map((subpath) => {
2100
+ const record = isRecord(subpath) ? subpath : {};
2101
+ const count = Array.isArray(record.vertices) ? record.vertices.length : 0;
2102
+ return `${record.closed === true}:${count}`;
2103
+ })
2104
+ .join(",");
2105
+ }
2106
+ function animatedPathIssue(animation, at) {
2107
+ if (isRecord(animation) && animation.mode === "constant") {
2108
+ return pathIssue(animation.value, at);
2109
+ }
2110
+ const values = animationValues(animation);
2111
+ if (values === undefined) {
2112
+ return { at, problem: SHAPE_PROBLEM.invalidKeyframes };
2113
+ }
2114
+ for (const value of values) {
2115
+ const issue = pathIssue(value, at);
2116
+ if (issue)
2117
+ return issue;
2118
+ }
2119
+ const first = pathStructure(values[0]);
2120
+ return values.every((value) => pathStructure(value) === first)
2121
+ ? undefined
2122
+ : { at, problem: SHAPE_PROBLEM.pathKeyframesDiffer };
2123
+ }
2124
+ /** What two paint keyframes must share: kind, stop count, and a gradient's spread. */
2125
+ function paintStructure(paint) {
2126
+ const record = isRecord(paint) ? paint : {};
2127
+ const stops = Array.isArray(record.stops) ? record.stops.length : 1;
2128
+ const spread = record.type === "linear_gradient" || record.type === "radial_gradient"
2129
+ ? text(record.spread ?? "pad")
2130
+ : "";
2131
+ return `${text(record.type)}:${stops}:${spread}`;
2132
+ }
2133
+ function animatedPaintIssue(animation, at) {
2134
+ if (isRecord(animation) && animation.mode === "constant") {
2135
+ return validPaint(animation.value)
2136
+ ? undefined
2137
+ : { at, problem: SHAPE_PROBLEM.outOfRange };
2138
+ }
2139
+ const values = animationValues(animation);
2140
+ if (values === undefined) {
2141
+ return { at, problem: SHAPE_PROBLEM.invalidKeyframes };
2142
+ }
2143
+ if (!values.every(validPaint)) {
2144
+ return { at, problem: SHAPE_PROBLEM.outOfRange };
2145
+ }
2146
+ const first = paintStructure(values[0]);
2147
+ return values.every((value) => paintStructure(value) === first)
2148
+ ? undefined
2149
+ : { at, problem: SHAPE_PROBLEM.paintKeyframesDiffer };
1875
2150
  }
1876
2151
  function validPaint(paint) {
1877
2152
  if (!isRecord(paint))
@@ -1922,7 +2197,17 @@ function validRgba(color) {
1922
2197
  /** The inputs of a composition node's operation, named as diagnostics show them. */
1923
2198
  function nodeInputs(op) {
1924
2199
  switch (op.type) {
1925
- case "effect":
2200
+ case "effect": {
2201
+ // In name order, as the model's map keeps them; names are ASCII, so the default string
2202
+ // order is its byte order.
2203
+ const named = isRecord(op.inputs) ? op.inputs : {};
2204
+ return [
2205
+ ["input", op.input],
2206
+ ...Object.keys(named)
2207
+ .sort()
2208
+ .map((name) => [`inputs.${name}`, named[name]]),
2209
+ ];
2210
+ }
1926
2211
  case "transform":
1927
2212
  case "shape_mask":
1928
2213
  return [["input", op.input]];
@@ -2186,13 +2471,20 @@ function compositionProblems(composition, sources, effectResources, compositions
2186
2471
  }
2187
2472
  break;
2188
2473
  }
2189
- case "generator":
2190
- if (!validGenerator(op.generator))
2474
+ case "generator": {
2475
+ const issue = generatorShapeIssue(op.generator);
2476
+ if (issue) {
2477
+ problems.push(shapeProblem(`node ${nodeId} of composition ${id}`, issue));
2478
+ }
2479
+ else if (!validGenerator(op.generator)) {
2191
2480
  invalid();
2481
+ }
2192
2482
  break;
2483
+ }
2193
2484
  case "effect":
2194
- if (!validClipEffect(op.effect))
2485
+ if (!validClipEffect(op.effect) || !validEffectInputs(op.inputs)) {
2195
2486
  invalid();
2487
+ }
2196
2488
  break;
2197
2489
  case "transition":
2198
2490
  if (!validClipEffect(op.effect) || !unit(op.progress))
@@ -2210,10 +2502,16 @@ function compositionProblems(composition, sources, effectResources, compositions
2210
2502
  }
2211
2503
  break;
2212
2504
  }
2213
- case "shape_mask":
2214
- if (!validMasks(op.masks, "video"))
2505
+ case "shape_mask": {
2506
+ const issue = masksIssue(op.masks);
2507
+ if (issue) {
2508
+ problems.push(shapeProblem(`node ${nodeId} of composition ${id}`, issue));
2509
+ }
2510
+ else if (!validMaskCount(op.masks, "video")) {
2215
2511
  invalid();
2512
+ }
2216
2513
  break;
2514
+ }
2217
2515
  case "group": {
2218
2516
  const target = compositions.get(text(op.composition));
2219
2517
  if (!target) {
@@ -2282,32 +2580,36 @@ function compositionProblems(composition, sources, effectResources, compositions
2282
2580
  }
2283
2581
  return problems;
2284
2582
  }
2285
- /**
2286
- * At most {@link MAX_CLIP_MASKS} masks, on visual clips only, each with valid
2287
- * keyframes and a non-negative size, feather, and corner radius.
2288
- */
2289
- function validMasks(masks, trackKind) {
2583
+ /** At most {@link MAX_CLIP_MASKS} masks, and on visual clips only. */
2584
+ function validMaskCount(masks, trackKind) {
2290
2585
  if (masks === undefined)
2291
2586
  return true;
2292
2587
  if (!Array.isArray(masks))
2293
2588
  return false;
2294
2589
  if (masks.length === 0)
2295
2590
  return true;
2296
- if (trackKind !== "video" || masks.length > MAX_CLIP_MASKS)
2297
- return false;
2298
- const nonNegative = (animation) => validScalarAnimation(animation ?? { mode: "constant", value: 0 }, 0);
2299
- return masks.every((mask) => {
2591
+ return trackKind === "video" && masks.length <= MAX_CLIP_MASKS;
2592
+ }
2593
+ /**
2594
+ * Mirrors `validate_masks`: the first problem among the masks in order, each outline checked as
2595
+ * geometry is and each feather non-negative.
2596
+ */
2597
+ function masksIssue(masks) {
2598
+ if (!Array.isArray(masks))
2599
+ return undefined;
2600
+ for (const [index, mask] of masks.entries()) {
2601
+ const at = `masks[${index}]`;
2300
2602
  if (!isRecord(mask))
2301
- return false;
2302
- const sizes = animationValues(mask.size);
2303
- const shape = isRecord(mask.shape) ? mask.shape : {};
2304
- return (sizes !== undefined &&
2305
- sizes.every((size) => validVec2(size) && size.x >= 0 && size.y >= 0) &&
2306
- validVec2Animation(mask.center) &&
2307
- validScalarAnimation(mask.rotation_degrees) &&
2308
- nonNegative(mask.feather) &&
2309
- (shape.type !== "rectangle" || nonNegative(shape.corner_radius)));
2310
- });
2603
+ return { at, problem: SHAPE_PROBLEM.outOfRange };
2604
+ const outline = isRecord(mask.shape) ? mask.shape : {};
2605
+ const issue = shapeGeometryIssue(outline, `${at}.shape`);
2606
+ if (issue)
2607
+ return issue;
2608
+ if (mask.feather !== undefined && !validScalarAnimation(mask.feather, 0)) {
2609
+ return { at: `${at}.feather`, problem: SHAPE_PROBLEM.outOfRange };
2610
+ }
2611
+ }
2612
+ return undefined;
2311
2613
  }
2312
2614
  /**
2313
2615
  * A matte names a visual clip other than its own, which has no matte of its own and is in no
@@ -2390,8 +2692,9 @@ function duckingCycles(tracks) {
2390
2692
  }
2391
2693
  /**
2392
2694
  * A valid project's non-fatal diagnostics, computed by the engine's own
2393
- * `Project::lint`, in a fixed order: sources, then each track's clips,
2394
- * transitions, and cues.
2695
+ * `Project::lint`, in a fixed order: unused sources, then shapes generators
2696
+ * (sources', then composition nodes'), then HDR sources, then each track's
2697
+ * clips, transitions, and cues.
2395
2698
  *
2396
2699
  * Diagnostics never block a load or an export; they flag what is probably a
2397
2700
  * mistake in a project the engine accepts.
package/dist/worker.js CHANGED
@@ -292,6 +292,7 @@ class WasmRenderWorkerHost {
292
292
  missingSources: result.missingSources,
293
293
  missingFrames: result.missingFrames.map(missingFrame),
294
294
  repeated: result.repeated,
295
+ unchanged: result.unchanged,
295
296
  };
296
297
  }
297
298
  beginExport(timeTicks, codec, outputTimeTicks) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alpha2",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "license": "MIT",
5
5
  "description": "JavaScript bindings for the standalone alpha2 media engine.",
6
6
  "repository": {
@@ -81,6 +81,14 @@
81
81
  "types": "./dist/text.d.ts",
82
82
  "import": "./dist/text.js"
83
83
  },
84
+ "./geometry": {
85
+ "types": "./dist/geometry.d.ts",
86
+ "import": "./dist/geometry.js"
87
+ },
88
+ "./containers": {
89
+ "types": "./dist/containers.d.ts",
90
+ "import": "./dist/containers.js"
91
+ },
84
92
  "./rate-control": {
85
93
  "types": "./dist/rate-control.d.ts",
86
94
  "import": "./dist/rate-control.js"
Binary file