@routevn/creator-model 1.1.0 → 1.1.2

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 +2 -0
  2. package/package.json +1 -1
  3. package/src/model.js +29 -25
package/README.md CHANGED
@@ -85,6 +85,8 @@ Design rules:
85
85
  this package
86
86
  - `project` may start empty; fields like `resolution` are optional until the
87
87
  model starts owning them
88
+ - random ids across RouteVN should use `nanoid` with the RouteVN base58 variant;
89
+ deterministic derived tokens such as partition hashes are a separate case
88
90
 
89
91
  ## File Structure
90
92
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routevn/creator-model",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/model.js CHANGED
@@ -54,7 +54,7 @@ const normalizeStateCollections = (state) => {
54
54
  const isString = (value) => typeof value === "string";
55
55
  const isHexColor = (value) =>
56
56
  typeof value === "string" && /^#[0-9a-fA-F]{6}$/.test(value);
57
- const LIVE_TWEEN_PROPERTY_KEYS = [
57
+ const UPDATE_TWEEN_PROPERTY_KEYS = [
58
58
  "alpha",
59
59
  "x",
60
60
  "y",
@@ -62,7 +62,7 @@ const LIVE_TWEEN_PROPERTY_KEYS = [
62
62
  "scaleY",
63
63
  "rotation",
64
64
  ];
65
- const REPLACE_TWEEN_PROPERTY_KEYS = [
65
+ const TRANSITION_TWEEN_PROPERTY_KEYS = [
66
66
  "translateX",
67
67
  "translateY",
68
68
  "alpha",
@@ -1325,14 +1325,14 @@ const validateAnimationDefinition = ({ animation, path, errorFactory }) => {
1325
1325
  );
1326
1326
  }
1327
1327
 
1328
- if (animation.type !== "live" && animation.type !== "replace") {
1328
+ if (animation.type !== "update" && animation.type !== "transition") {
1329
1329
  return invalidFromErrorFactory(
1330
1330
  errorFactory,
1331
- `${path}.type must be 'live' or 'replace'`,
1331
+ `${path}.type must be 'update' or 'transition'`,
1332
1332
  );
1333
1333
  }
1334
1334
 
1335
- if (animation.type === "live") {
1335
+ if (animation.type === "update") {
1336
1336
  if (
1337
1337
  animation.prev !== undefined ||
1338
1338
  animation.next !== undefined ||
@@ -1340,23 +1340,23 @@ const validateAnimationDefinition = ({ animation, path, errorFactory }) => {
1340
1340
  ) {
1341
1341
  return invalidFromErrorFactory(
1342
1342
  errorFactory,
1343
- `${path}.live animations cannot define prev, next, or mask`,
1343
+ `${path}.update animations cannot define prev, next, or mask`,
1344
1344
  );
1345
1345
  }
1346
1346
 
1347
1347
  if (animation.tween === undefined) {
1348
1348
  return invalidFromErrorFactory(
1349
1349
  errorFactory,
1350
- `${path}.tween is required when ${path}.type is 'live'`,
1350
+ `${path}.tween is required when ${path}.type is 'update'`,
1351
1351
  );
1352
1352
  }
1353
1353
 
1354
1354
  {
1355
1355
  const result = validateTweenDefinition({
1356
1356
  tween: animation.tween,
1357
- allowedProperties: LIVE_TWEEN_PROPERTY_KEYS,
1357
+ allowedProperties: UPDATE_TWEEN_PROPERTY_KEYS,
1358
1358
  path: `${path}.tween`,
1359
- unsupportedMessage: "is not a supported live tween property",
1359
+ unsupportedMessage: "is not a supported update tween property",
1360
1360
  errorFactory,
1361
1361
  });
1362
1362
  if (result?.valid === false) {
@@ -1370,7 +1370,7 @@ const validateAnimationDefinition = ({ animation, path, errorFactory }) => {
1370
1370
  if (animation.tween !== undefined) {
1371
1371
  return invalidFromErrorFactory(
1372
1372
  errorFactory,
1373
- `${path}.replace animations cannot define tween`,
1373
+ `${path}.transition animations cannot define tween`,
1374
1374
  );
1375
1375
  }
1376
1376
 
@@ -1381,7 +1381,7 @@ const validateAnimationDefinition = ({ animation, path, errorFactory }) => {
1381
1381
  ) {
1382
1382
  return invalidFromErrorFactory(
1383
1383
  errorFactory,
1384
- `${path} must define at least one of prev, next, or mask when ${path}.type is 'replace'`,
1384
+ `${path} must define at least one of prev, next, or mask when ${path}.type is 'transition'`,
1385
1385
  );
1386
1386
  }
1387
1387
 
@@ -1405,9 +1405,9 @@ const validateAnimationDefinition = ({ animation, path, errorFactory }) => {
1405
1405
  {
1406
1406
  const result = validateTweenDefinition({
1407
1407
  tween: animation[side].tween,
1408
- allowedProperties: REPLACE_TWEEN_PROPERTY_KEYS,
1408
+ allowedProperties: TRANSITION_TWEEN_PROPERTY_KEYS,
1409
1409
  path: `${path}.${side}.tween`,
1410
- unsupportedMessage: "is not a supported replace tween property",
1410
+ unsupportedMessage: "is not a supported transition tween property",
1411
1411
  errorFactory,
1412
1412
  });
1413
1413
  if (result?.valid === false) {
@@ -2095,10 +2095,14 @@ const validateCharacterSpriteItems = ({ items, path, errorFactory }) => {
2095
2095
  }
2096
2096
  };
2097
2097
 
2098
- const validateLayoutElementStyle = ({ style, path, errorFactory }) => {
2098
+ const validateLayoutElementTextStyle = ({
2099
+ textStyle,
2100
+ path,
2101
+ errorFactory,
2102
+ }) => {
2099
2103
  {
2100
2104
  const result = validateAllowedKeys({
2101
- value: style,
2105
+ value: textStyle,
2102
2106
  allowedKeys: ["align", "wordWrapWidth"],
2103
2107
  path,
2104
2108
  errorFactory,
@@ -2109,8 +2113,8 @@ const validateLayoutElementStyle = ({ style, path, errorFactory }) => {
2109
2113
  }
2110
2114
 
2111
2115
  if (
2112
- style.align !== undefined &&
2113
- !LAYOUT_ELEMENT_TEXT_STYLE_ALIGN_KEYS.includes(style.align)
2116
+ textStyle.align !== undefined &&
2117
+ !LAYOUT_ELEMENT_TEXT_STYLE_ALIGN_KEYS.includes(textStyle.align)
2114
2118
  ) {
2115
2119
  return invalidFromErrorFactory(
2116
2120
  errorFactory,
@@ -2119,8 +2123,8 @@ const validateLayoutElementStyle = ({ style, path, errorFactory }) => {
2119
2123
  }
2120
2124
 
2121
2125
  if (
2122
- style.wordWrapWidth !== undefined &&
2123
- !isFiniteNumber(style.wordWrapWidth)
2126
+ textStyle.wordWrapWidth !== undefined &&
2127
+ !isFiniteNumber(textStyle.wordWrapWidth)
2124
2128
  ) {
2125
2129
  return invalidFromErrorFactory(
2126
2130
  errorFactory,
@@ -2196,7 +2200,7 @@ const validateLayoutElementData = ({
2196
2200
  "fill",
2197
2201
  "border",
2198
2202
  "text",
2199
- "style",
2203
+ "textStyle",
2200
2204
  "displaySpeed",
2201
2205
  "imageId",
2202
2206
  "hoverImageId",
@@ -2359,11 +2363,11 @@ const validateLayoutElementData = ({
2359
2363
  );
2360
2364
  }
2361
2365
 
2362
- if (data.style !== undefined) {
2366
+ if (data.textStyle !== undefined) {
2363
2367
  {
2364
- const result = validateLayoutElementStyle({
2365
- style: data.style,
2366
- path: `${path}.style`,
2368
+ const result = validateLayoutElementTextStyle({
2369
+ textStyle: data.textStyle,
2370
+ path: `${path}.textStyle`,
2367
2371
  errorFactory,
2368
2372
  });
2369
2373
  if (result?.valid === false) {
@@ -2438,7 +2442,7 @@ const validateLayoutElementItems = ({ items, path, errorFactory }) => {
2438
2442
  "fill",
2439
2443
  "border",
2440
2444
  "text",
2441
- "style",
2445
+ "textStyle",
2442
2446
  "displaySpeed",
2443
2447
  "imageId",
2444
2448
  "hoverImageId",