@routevn/creator-model 1.10.0 → 1.10.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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/model.js +158 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routevn/creator-model",
3
- "version": "1.10.0",
3
+ "version": "1.10.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/model.js CHANGED
@@ -353,6 +353,7 @@ const LAYOUT_TYPE_KEYS = [
353
353
  ];
354
354
  const LAYOUT_ELEMENT_TEXT_STYLE_ALIGN_KEYS = ["left", "center", "right"];
355
355
  const LAYOUT_TEXT_REVEAL_EFFECT_KEYS = ["typewriter", "softWipe", "none"];
356
+ const LAYOUT_TEXT_REVEAL_SOUND_STOP_TIMING_KEYS = ["loopEnd", "immediate"];
356
357
  const LAYOUT_ELEMENT_BLUR_KERNEL_SIZE_OPTIONS = [5, 7, 9, 11, 13, 15];
357
358
  const CONTROL_KEYBOARD_KEYS = [
358
359
  "enter",
@@ -3066,6 +3067,60 @@ const validateVariableItems = ({ items, path, errorFactory }) => {
3066
3067
  }
3067
3068
  };
3068
3069
 
3070
+ const validateTextStyleShadow = ({ shadow, path, errorFactory }) => {
3071
+ if (!isPlainObject(shadow)) {
3072
+ return invalidFromErrorFactory(errorFactory, `${path} must be an object`);
3073
+ }
3074
+
3075
+ {
3076
+ const result = validateAllowedKeys({
3077
+ value: shadow,
3078
+ allowedKeys: ["colorId", "alpha", "blur", "offsetX", "offsetY"],
3079
+ path,
3080
+ errorFactory,
3081
+ });
3082
+ if (result?.valid === false) {
3083
+ return result;
3084
+ }
3085
+ }
3086
+
3087
+ if (!isNonEmptyString(shadow.colorId)) {
3088
+ return invalidFromErrorFactory(
3089
+ errorFactory,
3090
+ `${path}.colorId must be a non-empty string`,
3091
+ );
3092
+ }
3093
+
3094
+ if (
3095
+ shadow.alpha !== undefined &&
3096
+ (!isFiniteNumber(shadow.alpha) || shadow.alpha < 0 || shadow.alpha > 1)
3097
+ ) {
3098
+ return invalidFromErrorFactory(
3099
+ errorFactory,
3100
+ `${path}.alpha must be a finite number between 0 and 1 when provided`,
3101
+ );
3102
+ }
3103
+
3104
+ if (
3105
+ shadow.blur !== undefined &&
3106
+ (!isFiniteNumber(shadow.blur) || shadow.blur < 0)
3107
+ ) {
3108
+ return invalidFromErrorFactory(
3109
+ errorFactory,
3110
+ `${path}.blur must be a non-negative finite number when provided`,
3111
+ );
3112
+ }
3113
+
3114
+ for (const key of ["offsetX", "offsetY"]) {
3115
+ if (shadow[key] !== undefined && !isFiniteNumber(shadow[key])) {
3116
+ return invalidFromErrorFactory(
3117
+ errorFactory,
3118
+ `${path}.${key} must be a finite number when provided`,
3119
+ );
3120
+ }
3121
+ }
3122
+ };
3123
+
3069
3124
  const validateTextStyleItems = ({ items, path, errorFactory }) => {
3070
3125
  for (const [itemId, item] of Object.entries(items)) {
3071
3126
  const itemPath = `${path}.${itemId}`;
@@ -3103,6 +3158,7 @@ const validateTextStyleItems = ({ items, path, errorFactory }) => {
3103
3158
  "strokeColorId",
3104
3159
  "strokeAlpha",
3105
3160
  "strokeWidth",
3161
+ "shadow",
3106
3162
  ],
3107
3163
  path: itemPath,
3108
3164
  errorFactory,
@@ -3262,6 +3318,17 @@ const validateTextStyleItems = ({ items, path, errorFactory }) => {
3262
3318
  `${itemPath}.strokeWidth must be a finite number when provided`,
3263
3319
  );
3264
3320
  }
3321
+
3322
+ if (item.shadow !== undefined) {
3323
+ const result = validateTextStyleShadow({
3324
+ shadow: item.shadow,
3325
+ path: `${itemPath}.shadow`,
3326
+ errorFactory,
3327
+ });
3328
+ if (result?.valid === false) {
3329
+ return result;
3330
+ }
3331
+ }
3265
3332
  }
3266
3333
  }
3267
3334
  };
@@ -3819,6 +3886,7 @@ const validateLayoutElementData = ({
3819
3886
  "hoverSoundId",
3820
3887
  "clickSoundId",
3821
3888
  "revealSoundId",
3889
+ "revealSoundStopTiming",
3822
3890
  "textStyleId",
3823
3891
  "hoverTextStyleId",
3824
3892
  "clickTextStyleId",
@@ -4054,6 +4122,7 @@ const validateLayoutElementData = ({
4054
4122
  "hoverSoundId",
4055
4123
  "clickSoundId",
4056
4124
  "revealSoundId",
4125
+ "revealSoundStopTiming",
4057
4126
  "textStyleId",
4058
4127
  "hoverTextStyleId",
4059
4128
  "clickTextStyleId",
@@ -4332,6 +4401,18 @@ const validateLayoutElementData = ({
4332
4401
  );
4333
4402
  }
4334
4403
 
4404
+ if (
4405
+ data.revealSoundStopTiming !== undefined &&
4406
+ !LAYOUT_TEXT_REVEAL_SOUND_STOP_TIMING_KEYS.includes(
4407
+ data.revealSoundStopTiming,
4408
+ )
4409
+ ) {
4410
+ return invalidFromErrorFactory(
4411
+ errorFactory,
4412
+ `${path}.revealSoundStopTiming must be one of ${LAYOUT_TEXT_REVEAL_SOUND_STOP_TIMING_KEYS.join(", ")} when provided`,
4413
+ );
4414
+ }
4415
+
4335
4416
  if (data.formRole !== undefined && data.formRole !== "submit") {
4336
4417
  return invalidFromErrorFactory(
4337
4418
  errorFactory,
@@ -4574,6 +4655,7 @@ const validateLayoutElementItems = ({ items, path, errorFactory }) => {
4574
4655
  "hoverSoundId",
4575
4656
  "clickSoundId",
4576
4657
  "revealSoundId",
4658
+ "revealSoundStopTiming",
4577
4659
  "textStyleId",
4578
4660
  "hoverTextStyleId",
4579
4661
  "clickTextStyleId",
@@ -5207,6 +5289,22 @@ const applyTagIdsUpdate = ({ currentItem, data }) => {
5207
5289
  return nextItem;
5208
5290
  };
5209
5291
 
5292
+ const applyTextStyleUpdate = ({ currentItem, data }) => {
5293
+ const nextData = structuredClone(data);
5294
+ delete nextData.clearShadow;
5295
+
5296
+ const nextItem = applyTagIdsUpdate({
5297
+ currentItem,
5298
+ data: nextData,
5299
+ });
5300
+
5301
+ if (data.clearShadow === true) {
5302
+ delete nextItem.shadow;
5303
+ }
5304
+
5305
+ return nextItem;
5306
+ };
5307
+
5210
5308
  const applyCharacterUpdate = ({ currentItem, data }) => {
5211
5309
  const nextItem = applyTagIdsUpdate({
5212
5310
  currentItem,
@@ -7098,6 +7196,19 @@ export const assertInvariants = ({ state }) => {
7098
7196
  );
7099
7197
  }
7100
7198
  }
7199
+
7200
+ if (textStyle.shadow !== undefined) {
7201
+ const shadowColor = state.colors.items[textStyle.shadow.colorId];
7202
+ if (!isPlainObject(shadowColor) || shadowColor.type === "folder") {
7203
+ return invalidInvariant(
7204
+ "textStyle.shadow.colorId must reference an existing non-folder color",
7205
+ {
7206
+ textStyleId,
7207
+ colorId: textStyle.shadow.colorId,
7208
+ },
7209
+ );
7210
+ }
7211
+ }
7101
7212
  }
7102
7213
 
7103
7214
  for (const [imageId, image] of Object.entries(state.images.items)) {
@@ -11023,6 +11134,7 @@ const validateTextStyleCreateData = ({ data, errorFactory }) => {
11023
11134
  "strokeColorId",
11024
11135
  "strokeAlpha",
11025
11136
  "strokeWidth",
11137
+ "shadow",
11026
11138
  ],
11027
11139
  path: "payload.data",
11028
11140
  errorFactory,
@@ -11098,6 +11210,8 @@ const validateTextStyleUpdateData = ({ data, errorFactory }) => {
11098
11210
  "strokeColorId",
11099
11211
  "strokeAlpha",
11100
11212
  "strokeWidth",
11213
+ "shadow",
11214
+ "clearShadow",
11101
11215
  ],
11102
11216
  path: "payload.data",
11103
11217
  errorFactory,
@@ -11166,6 +11280,31 @@ const validateTextStyleUpdateData = ({ data, errorFactory }) => {
11166
11280
  }
11167
11281
  }
11168
11282
 
11283
+ if (data.shadow !== undefined) {
11284
+ const result = validateTextStyleShadow({
11285
+ shadow: data.shadow,
11286
+ path: "payload.data.shadow",
11287
+ errorFactory,
11288
+ });
11289
+ if (result?.valid === false) {
11290
+ return result;
11291
+ }
11292
+ }
11293
+
11294
+ if (data.clearShadow !== undefined && data.clearShadow !== true) {
11295
+ return invalidFromErrorFactory(
11296
+ errorFactory,
11297
+ "payload.data.clearShadow must be true when provided",
11298
+ );
11299
+ }
11300
+
11301
+ if (data.shadow !== undefined && data.clearShadow === true) {
11302
+ return invalidFromErrorFactory(
11303
+ errorFactory,
11304
+ "payload.data.shadow and payload.data.clearShadow cannot both be provided",
11305
+ );
11306
+ }
11307
+
11169
11308
  if (data.breakWords !== undefined && typeof data.breakWords !== "boolean") {
11170
11309
  return invalidFromErrorFactory(
11171
11310
  errorFactory,
@@ -18322,7 +18461,7 @@ const COMMAND_DEFINITIONS = [
18322
18461
  };
18323
18462
  },
18324
18463
  updateItem: ({ currentItem, payload }) =>
18325
- applyTagIdsUpdate({
18464
+ applyTextStyleUpdate({
18326
18465
  currentItem,
18327
18466
  data: payload.data,
18328
18467
  }),
@@ -18360,6 +18499,15 @@ const COMMAND_DEFINITIONS = [
18360
18499
  );
18361
18500
  }
18362
18501
  }
18502
+
18503
+ if (data.shadow !== undefined) {
18504
+ const shadowColor = state.colors.items[data.shadow.colorId];
18505
+ if (!isPlainObject(shadowColor) || shadowColor.type === "folder") {
18506
+ return invalidPrecondition(
18507
+ "payload.data.shadow.colorId must reference an existing non-folder color",
18508
+ );
18509
+ }
18510
+ }
18363
18511
  },
18364
18512
  validateUpdateState: ({ state, payload, currentItem }) => {
18365
18513
  if (
@@ -18403,6 +18551,15 @@ const COMMAND_DEFINITIONS = [
18403
18551
  );
18404
18552
  }
18405
18553
  }
18554
+
18555
+ if (payload.data.shadow !== undefined) {
18556
+ const shadowColor = state.colors.items[payload.data.shadow.colorId];
18557
+ if (!isPlainObject(shadowColor) || shadowColor.type === "folder") {
18558
+ return invalidPrecondition(
18559
+ "payload.data.shadow.colorId must reference an existing non-folder color",
18560
+ );
18561
+ }
18562
+ }
18406
18563
  },
18407
18564
  }),
18408
18565
  ...createFolderedCollectionCommandDefinitions({