@routevn/creator-model 1.11.0 → 1.12.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.
Files changed (3) hide show
  1. package/README.md +4 -0
  2. package/package.json +1 -1
  3. package/src/model.js +114 -67
package/README.md CHANGED
@@ -294,6 +294,10 @@ Current animation update tween properties support either:
294
294
  - `keyframes`
295
295
  - `auto: { duration, easing }`
296
296
 
297
+ Transition animation `mask` accepts one mask object or a non-empty ordered
298
+ array. Each mask may define a non-negative safe-integer `delay` in
299
+ milliseconds.
300
+
297
301
  ## Current Scope
298
302
 
299
303
  Currently implemented command types:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routevn/creator-model",
3
- "version": "1.11.0",
3
+ "version": "1.12.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/model.js CHANGED
@@ -403,7 +403,7 @@ const SAVE_LOAD_DATE_FORMATS = new Set([
403
403
  "DD MMM YYYY",
404
404
  "YYYY年MM月DD日",
405
405
  ]);
406
- export const SCHEMA_VERSION = 11;
406
+ export const SCHEMA_VERSION = 12;
407
407
  const LAYOUT_CONTAINER_ELEMENT_TYPES = [
408
408
  "folder",
409
409
  "container",
@@ -1680,7 +1680,7 @@ const validateAnimationKeyframes = ({ keyframes, path, errorFactory }) => {
1680
1680
  {
1681
1681
  const result = validateAllowedKeys({
1682
1682
  value: keyframe,
1683
- allowedKeys: ["value", "duration", "easing", "relative"],
1683
+ allowedKeys: ["value", "duration", "delay", "easing", "relative"],
1684
1684
  path: keyframePath,
1685
1685
  errorFactory,
1686
1686
  });
@@ -1717,6 +1717,16 @@ const validateAnimationKeyframes = ({ keyframes, path, errorFactory }) => {
1717
1717
  );
1718
1718
  }
1719
1719
 
1720
+ if (
1721
+ keyframe.delay !== undefined &&
1722
+ (!isFiniteNumber(keyframe.delay) || keyframe.delay < 0)
1723
+ ) {
1724
+ return invalidFromErrorFactory(
1725
+ errorFactory,
1726
+ `${keyframePath}.delay must be a finite number >= 0 when provided`,
1727
+ );
1728
+ }
1729
+
1720
1730
  if (
1721
1731
  keyframe.easing !== undefined &&
1722
1732
  !ANIMATION_EASING_KEYS.includes(keyframe.easing)
@@ -1920,6 +1930,7 @@ const validateMaskDefinition = ({ mask, path, errorFactory }) => {
1920
1930
  "softness",
1921
1931
  "invert",
1922
1932
  "sample",
1933
+ "delay",
1923
1934
  "progress",
1924
1935
  "progressDuration",
1925
1936
  "progressEasing",
@@ -2098,6 +2109,16 @@ const validateMaskDefinition = ({ mask, path, errorFactory }) => {
2098
2109
  );
2099
2110
  }
2100
2111
 
2112
+ if (
2113
+ mask.delay !== undefined &&
2114
+ (!Number.isSafeInteger(mask.delay) || mask.delay < 0)
2115
+ ) {
2116
+ return invalidFromErrorFactory(
2117
+ errorFactory,
2118
+ `${path}.delay must be a non-negative safe integer when provided`,
2119
+ );
2120
+ }
2121
+
2101
2122
  if (mask.progress !== undefined) {
2102
2123
  {
2103
2124
  const result = validateTweenProperty({
@@ -2161,6 +2182,30 @@ const validateMaskDefinition = ({ mask, path, errorFactory }) => {
2161
2182
  }
2162
2183
  };
2163
2184
 
2185
+ const validateAnimationMasks = ({ mask, path, errorFactory }) => {
2186
+ if (!Array.isArray(mask)) {
2187
+ return validateMaskDefinition({ mask, path, errorFactory });
2188
+ }
2189
+
2190
+ if (mask.length === 0) {
2191
+ return invalidFromErrorFactory(
2192
+ errorFactory,
2193
+ `${path} must be a non-empty array when provided`,
2194
+ );
2195
+ }
2196
+
2197
+ for (const [index, maskDefinition] of mask.entries()) {
2198
+ const result = validateMaskDefinition({
2199
+ mask: maskDefinition,
2200
+ path: `${path}[${index}]`,
2201
+ errorFactory,
2202
+ });
2203
+ if (result?.valid === false) {
2204
+ return result;
2205
+ }
2206
+ }
2207
+ };
2208
+
2164
2209
  const validateAnimationDefinition = ({ animation, path, errorFactory }) => {
2165
2210
  {
2166
2211
  const result = validateAllowedKeys({
@@ -2266,7 +2311,7 @@ const validateAnimationDefinition = ({ animation, path, errorFactory }) => {
2266
2311
 
2267
2312
  if (animation.mask !== undefined) {
2268
2313
  {
2269
- const result = validateMaskDefinition({
2314
+ const result = validateAnimationMasks({
2270
2315
  mask: animation.mask,
2271
2316
  path: `${path}.mask`,
2272
2317
  errorFactory,
@@ -3380,10 +3425,7 @@ const validateComputedExpression = ({
3380
3425
  );
3381
3426
  }
3382
3427
 
3383
- if (
3384
- typeof expression === "string" ||
3385
- typeof expression === "boolean"
3386
- ) {
3428
+ if (typeof expression === "string" || typeof expression === "boolean") {
3387
3429
  return validComputedResult(typeof expression);
3388
3430
  }
3389
3431
 
@@ -3538,10 +3580,7 @@ const validateComputedCondition = ({
3538
3580
  );
3539
3581
  }
3540
3582
 
3541
- if (
3542
- typeof condition === "string" ||
3543
- typeof condition === "boolean"
3544
- ) {
3583
+ if (typeof condition === "string" || typeof condition === "boolean") {
3545
3584
  return validComputedResult(typeof condition);
3546
3585
  }
3547
3586
 
@@ -3845,18 +3884,11 @@ const validateVariableComputedConfig = ({
3845
3884
  });
3846
3885
  };
3847
3886
 
3848
- const validateComputedVariableGraph = ({
3849
- items,
3850
- path,
3851
- errorFactory,
3852
- }) => {
3887
+ const validateComputedVariableGraph = ({ items, path, errorFactory }) => {
3853
3888
  const dependencyGraph = new Map();
3854
3889
 
3855
3890
  for (const [variableId, variable] of Object.entries(items)) {
3856
- if (
3857
- variable?.type !== "variable" ||
3858
- !Object.hasOwn(variable, "computed")
3859
- ) {
3891
+ if (variable?.type !== "variable" || !Object.hasOwn(variable, "computed")) {
3860
3892
  continue;
3861
3893
  }
3862
3894
 
@@ -3908,9 +3940,7 @@ const validateComputedVariableGraph = ({
3908
3940
  const cycleStartIndex = activeIndexes.get(dependencyId);
3909
3941
  if (cycleStartIndex !== undefined) {
3910
3942
  const cycle = [
3911
- ...frames
3912
- .slice(cycleStartIndex)
3913
- .map(({ variableId }) => variableId),
3943
+ ...frames.slice(cycleStartIndex).map(({ variableId }) => variableId),
3914
3944
  dependencyId,
3915
3945
  ].join(" -> ");
3916
3946
  return invalidFromErrorFactory(
@@ -8124,43 +8154,41 @@ const validateAnimationMaskImageReferences = ({
8124
8154
  details = {},
8125
8155
  errorFactory = createPreconditionValidationError,
8126
8156
  }) => {
8127
- if (
8128
- !isPlainObject(animation) ||
8129
- animation.type !== "transition" ||
8130
- !isPlainObject(animation.mask)
8131
- ) {
8157
+ if (!isPlainObject(animation) || animation.type !== "transition") {
8132
8158
  return VALID_RESULT;
8133
8159
  }
8134
8160
 
8135
- const { mask } = animation;
8161
+ const maskDefinitions = Array.isArray(animation.mask)
8162
+ ? animation.mask.map((mask, index) => ({
8163
+ mask,
8164
+ path: `${path}.mask[${index}]`,
8165
+ fieldPrefix: `mask[${index}].`,
8166
+ }))
8167
+ : isPlainObject(animation.mask)
8168
+ ? [
8169
+ {
8170
+ mask: animation.mask,
8171
+ path: `${path}.mask`,
8172
+ fieldPrefix: "",
8173
+ },
8174
+ ]
8175
+ : [];
8136
8176
 
8137
- if (mask.imageId !== undefined) {
8138
- const result = validateImageReference({
8139
- state,
8140
- imageId: mask.imageId,
8141
- path: `${path}.mask.imageId`,
8142
- details: {
8143
- ...details,
8144
- field: "imageId",
8145
- imageId: mask.imageId,
8146
- },
8147
- errorFactory,
8148
- });
8149
- if (!result.valid) {
8150
- return result;
8177
+ for (const maskDefinition of maskDefinitions) {
8178
+ const { mask, path: maskPath, fieldPrefix } = maskDefinition;
8179
+ if (!isPlainObject(mask)) {
8180
+ continue;
8151
8181
  }
8152
- }
8153
8182
 
8154
- if (Array.isArray(mask.imageIds)) {
8155
- for (const [index, imageId] of mask.imageIds.entries()) {
8183
+ if (mask.imageId !== undefined) {
8156
8184
  const result = validateImageReference({
8157
8185
  state,
8158
- imageId,
8159
- path: `${path}.mask.imageIds[${index}]`,
8186
+ imageId: mask.imageId,
8187
+ path: `${maskPath}.imageId`,
8160
8188
  details: {
8161
8189
  ...details,
8162
- field: `imageIds[${index}]`,
8163
- imageId,
8190
+ field: `${fieldPrefix}imageId`,
8191
+ imageId: mask.imageId,
8164
8192
  },
8165
8193
  errorFactory,
8166
8194
  });
@@ -8168,27 +8196,46 @@ const validateAnimationMaskImageReferences = ({
8168
8196
  return result;
8169
8197
  }
8170
8198
  }
8171
- }
8172
8199
 
8173
- if (Array.isArray(mask.items)) {
8174
- for (const [index, item] of mask.items.entries()) {
8175
- if (item?.imageId === undefined) {
8176
- continue;
8200
+ if (Array.isArray(mask.imageIds)) {
8201
+ for (const [index, imageId] of mask.imageIds.entries()) {
8202
+ const result = validateImageReference({
8203
+ state,
8204
+ imageId,
8205
+ path: `${maskPath}.imageIds[${index}]`,
8206
+ details: {
8207
+ ...details,
8208
+ field: `${fieldPrefix}imageIds[${index}]`,
8209
+ imageId,
8210
+ },
8211
+ errorFactory,
8212
+ });
8213
+ if (!result.valid) {
8214
+ return result;
8215
+ }
8177
8216
  }
8217
+ }
8178
8218
 
8179
- const result = validateImageReference({
8180
- state,
8181
- imageId: item.imageId,
8182
- path: `${path}.mask.items[${index}].imageId`,
8183
- details: {
8184
- ...details,
8185
- field: `items[${index}].imageId`,
8219
+ if (Array.isArray(mask.items)) {
8220
+ for (const [index, item] of mask.items.entries()) {
8221
+ if (item?.imageId === undefined) {
8222
+ continue;
8223
+ }
8224
+
8225
+ const result = validateImageReference({
8226
+ state,
8186
8227
  imageId: item.imageId,
8187
- },
8188
- errorFactory,
8189
- });
8190
- if (!result.valid) {
8191
- return result;
8228
+ path: `${maskPath}.items[${index}].imageId`,
8229
+ details: {
8230
+ ...details,
8231
+ field: `${fieldPrefix}items[${index}].imageId`,
8232
+ imageId: item.imageId,
8233
+ },
8234
+ errorFactory,
8235
+ });
8236
+ if (!result.valid) {
8237
+ return result;
8238
+ }
8192
8239
  }
8193
8240
  }
8194
8241
  }