@unseenco/theatre-core 0.1.17 → 0.2.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/dist/index.d.ts CHANGED
@@ -225,6 +225,11 @@ type Keyframe = {
225
225
  handles: [leftX: number, leftY: number, rightX: number, rightY: number];
226
226
  connectedRight: boolean;
227
227
  type?: KeyframeType;
228
+ /**
229
+ * Optional label for the tween to the right of this keyframe.
230
+ * Only meaningful when {@link connectedRight} is true.
231
+ */
232
+ tweenLabel?: string;
228
233
  };
229
234
  type TrackDataCommon<TypeName extends string> = {
230
235
  type: TypeName;
@@ -376,6 +381,9 @@ declare const image: (defaultValue: Asset['id'], opts?: {
376
381
  * // With custom nudging
377
382
  * const x = t.number(0, {nudgeMultiplier: 0.1}) // nudging will happen in 0.1 increments
378
383
  *
384
+ * // With custom precision (decimal places shown/stored in Studio)
385
+ * const x = t.number(0, {precision: 2})
386
+ *
379
387
  * // With custom nudging function
380
388
  * const x = t.number({
381
389
  * nudgeFn: (
@@ -401,6 +409,7 @@ declare const number: (defaultValue: number, opts?: {
401
409
  nudgeFn?: PropTypeConfig_Number['nudgeFn'];
402
410
  range?: PropTypeConfig_Number['range'];
403
411
  nudgeMultiplier?: number;
412
+ precision?: number;
404
413
  label?: string;
405
414
  }) => PropTypeConfig_Number;
406
415
  declare const rgba: (defaultValue?: Rgba, opts?: CommonOpts) => PropTypeConfig_Rgba;
@@ -572,6 +581,11 @@ interface PropTypeConfig_Number extends ISimplePropType<'number', number> {
572
581
  * See {@link defaultNumberNudgeFn} to see how `nudgeMultiplier` is treated.
573
582
  */
574
583
  nudgeMultiplier: number | undefined;
584
+ /**
585
+ * The number of decimal places to use for this prop in the Studio.
586
+ * Falls back to the project's `numberPrecision` config, then to 3.
587
+ */
588
+ precision?: number;
575
589
  }
576
590
  type NumberNudgeFn = (p: {
577
591
  deltaX: number;
@@ -1415,6 +1429,13 @@ type IProjectConfig = {
1415
1429
  assets?: {
1416
1430
  baseUrl?: string;
1417
1431
  };
1432
+ /**
1433
+ * The default number of decimal places to use for number props in the Studio.
1434
+ * Can be overridden per prop via `types.number(defaultValue, {precision})`.
1435
+ *
1436
+ * @defaultValue 3
1437
+ */
1438
+ numberPrecision?: number;
1418
1439
  };
1419
1440
  /**
1420
1441
  * A Theatre.js project
package/dist/index.js CHANGED
@@ -3455,6 +3455,15 @@ var number = (defaultValue, opts = {}) => {
3455
3455
  );
3456
3456
  }
3457
3457
  }
3458
+ if (Object.prototype.hasOwnProperty.call(opts, "precision")) {
3459
+ if (typeof opts.precision !== "number" || !isFinite(opts.precision) || opts.precision < 0 || Math.floor(opts.precision) !== opts.precision) {
3460
+ throw new Error(
3461
+ "opts.precision in t.number(defaultValue, opts) must be a non-negative integer. ".concat(userReadableTypeOfValue_default(
3462
+ opts.precision
3463
+ ), " given.")
3464
+ );
3465
+ }
3466
+ }
3458
3467
  }
3459
3468
  }
3460
3469
  return {
@@ -3466,6 +3475,7 @@ var number = (defaultValue, opts = {}) => {
3466
3475
  label: opts.label,
3467
3476
  nudgeFn: opts.nudgeFn ?? defaultNumberNudgeFn,
3468
3477
  nudgeMultiplier: typeof opts.nudgeMultiplier === "number" ? opts.nudgeMultiplier : void 0,
3478
+ precision: typeof opts.precision === "number" ? opts.precision : void 0,
3469
3479
  interpolate: _interpolateNumber,
3470
3480
  deserializeAndSanitize: numberDeserializer(opts.range)
3471
3481
  };
@@ -5069,6 +5079,69 @@ function registerObjectPropConfig(projectId, sheetId, objectKey, config) {
5069
5079
  );
5070
5080
  }
5071
5081
 
5082
+ // shared/src/propTypes/numberPrecision.ts
5083
+ var DEFAULT_NUMBER_PRECISION = 3;
5084
+ function resolveNumberPrecision(propPrecision, projectPrecision) {
5085
+ if (propPrecision !== void 0)
5086
+ return propPrecision;
5087
+ if (projectPrecision !== void 0)
5088
+ return projectPrecision;
5089
+ return DEFAULT_NUMBER_PRECISION;
5090
+ }
5091
+ function applyNumberPrecisionDefaultsToPropConfig(config, projectNumberPrecision) {
5092
+ const defaultPrecision = resolveNumberPrecision(
5093
+ void 0,
5094
+ projectNumberPrecision
5095
+ );
5096
+ if (config.type === "number") {
5097
+ if (config.precision !== void 0)
5098
+ return config;
5099
+ return {
5100
+ ...config,
5101
+ precision: defaultPrecision
5102
+ };
5103
+ }
5104
+ if (config.type === "compound") {
5105
+ return {
5106
+ ...config,
5107
+ props: mapCompoundProps(
5108
+ config,
5109
+ (subConfig) => applyNumberPrecisionDefaultsToPropConfig(
5110
+ subConfig,
5111
+ projectNumberPrecision
5112
+ )
5113
+ )
5114
+ };
5115
+ }
5116
+ if (config.type === "enum") {
5117
+ return {
5118
+ ...config,
5119
+ cases: mapEnumCases(
5120
+ config,
5121
+ (subConfig) => applyNumberPrecisionDefaultsToPropConfig(
5122
+ subConfig,
5123
+ projectNumberPrecision
5124
+ )
5125
+ )
5126
+ };
5127
+ }
5128
+ return config;
5129
+ }
5130
+ function mapCompoundProps(config, fn2) {
5131
+ const props = {};
5132
+ for (const [key, subConfig] of Object.entries(config.props)) {
5133
+ props[key] = fn2(subConfig);
5134
+ }
5135
+ return props;
5136
+ }
5137
+ function mapEnumCases(config, fn2) {
5138
+ const cases = {};
5139
+ for (const [key, subConfig] of Object.entries(config.cases)) {
5140
+ cases[key] = fn2(subConfig);
5141
+ }
5142
+ return cases;
5143
+ }
5144
+
5072
5145
  // core/src/sheetObjects/SheetObjectTemplate.ts
5073
5146
  function isObjectEmpty(obj) {
5074
5147
  return typeof obj === "object" && obj !== null && Object.keys(obj).length === 0;
@@ -5095,7 +5168,11 @@ var SheetObjectTemplate = class {
5095
5168
  __publicField(this, "_staticPropPaths", /* @__PURE__ */ new Set());
5096
5169
  __publicField(this, "_visibleInOutline", true);
5097
5170
  this.address = { ...sheetTemplate.address, objectKey };
5098
- this._config = new import_theatre_dataverse7.Atom(config);
5171
+ const configWithPrecisionDefaults = this._withNumberPrecisionDefaults(
5172
+ config,
5173
+ sheetTemplate.project
5174
+ );
5175
+ this._config = new import_theatre_dataverse7.Atom(configWithPrecisionDefaults);
5099
5176
  this._temp_actions_atom = new import_theatre_dataverse7.Atom(_temp_actions);
5100
5177
  this.showPropsOf_atom = new import_theatre_dataverse7.Atom([]);
5101
5178
  this._transientPropPaths = normalizeTransientPropPaths(
@@ -5119,7 +5196,7 @@ var SheetObjectTemplate = class {
5119
5196
  this.address.projectId,
5120
5197
  this.address.sheetId,
5121
5198
  objectKey,
5122
- config
5199
+ configWithPrecisionDefaults
5123
5200
  );
5124
5201
  this.pointerToSheetState = this.sheetTemplate.project.pointers.historic.sheetsById[this.address.sheetId];
5125
5202
  this.pointerToStaticOverrides = this.pointerToSheetState.staticOverrides.byObject[this.address.objectKey];
@@ -5132,6 +5209,12 @@ var SheetObjectTemplate = class {
5132
5209
  get staticConfig() {
5133
5210
  return this._config.get();
5134
5211
  }
5212
+ _withNumberPrecisionDefaults(config, project = this.project) {
5213
+ return applyNumberPrecisionDefaultsToPropConfig(
5214
+ config,
5215
+ project.config.numberPrecision
5216
+ );
5217
+ }
5135
5218
  get configPointer() {
5136
5219
  return this._config.pointer;
5137
5220
  }
@@ -5179,16 +5262,17 @@ var SheetObjectTemplate = class {
5179
5262
  );
5180
5263
  }
5181
5264
  createInstance(sheet, nativeObject, config) {
5182
- this._config.set(config);
5265
+ this._config.set(this._withNumberPrecisionDefaults(config));
5183
5266
  return new SheetObject(sheet, this, nativeObject);
5184
5267
  }
5185
5268
  reconfigure(config) {
5186
- this._config.set(config);
5269
+ const configWithPrecisionDefaults = this._withNumberPrecisionDefaults(config);
5270
+ this._config.set(configWithPrecisionDefaults);
5187
5271
  this._stripNonPersistingPropsFromAhistoricState();
5188
5272
  this.project._stripPropsMissingFromConfig(
5189
5273
  this.address.sheetId,
5190
5274
  this.address.objectKey,
5191
- config
5275
+ configWithPrecisionDefaults
5192
5276
  );
5193
5277
  }
5194
5278
  addProps(config) {
@@ -5201,10 +5285,12 @@ var SheetObjectTemplate = class {
5201
5285
  );
5202
5286
  }
5203
5287
  }
5204
- const merged = compoundFromSanitizedProps({
5205
- ...existing.props,
5206
- ...additional.props
5207
- });
5288
+ const merged = this._withNumberPrecisionDefaults(
5289
+ compoundFromSanitizedProps({
5290
+ ...existing.props,
5291
+ ...additional.props
5292
+ })
5293
+ );
5208
5294
  this._config.set(merged);
5209
5295
  registerObjectPropConfig(
5210
5296
  this.address.projectId,
@@ -8388,6 +8474,9 @@ function getProject(id, config = {}) {
8388
8474
  } else {
8389
8475
  plogger._debug("no config.state");
8390
8476
  }
8477
+ if (process.env.NODE_ENV !== "production") {
8478
+ validateProjectNumberPrecisionOrThrow(config.numberPrecision);
8479
+ }
8391
8480
  return new TheatreProject(id, config);
8392
8481
  }
8393
8482
  var shallowValidateOnDiskState = (projectId, s2) => {
@@ -8402,6 +8491,17 @@ var shallowValidateOnDiskState = (projectId, s2) => {
8402
8491
  var deepValidateOnDiskState = (projectId, s2) => {
8403
8492
  shallowValidateOnDiskState(projectId, s2);
8404
8493
  };
8494
+ var validateProjectNumberPrecisionOrThrow = (numberPrecision) => {
8495
+ if (numberPrecision === void 0)
8496
+ return;
8497
+ if (typeof numberPrecision !== "number" || !isFinite(numberPrecision) || numberPrecision < 0 || Math.floor(numberPrecision) !== numberPrecision) {
8498
+ throw new InvalidArgumentError(
8499
+ "Argument config.numberPrecision in Theatre.getProject(projectId, config) must be a non-negative integer. ".concat(userReadableTypeOfValue_default(
8500
+ numberPrecision
8501
+ ), " given.")
8502
+ );
8503
+ }
8504
+ };
8405
8505
  var validateProjectIdOrThrow = (value) => {
8406
8506
  if (typeof value !== "string") {
8407
8507
  throw new InvalidArgumentError(
@@ -8452,7 +8552,7 @@ var CoreBundle = class {
8452
8552
  return "Theatre_CoreBundle";
8453
8553
  }
8454
8554
  get version() {
8455
- return "0.1.17";
8555
+ return "0.2.0";
8456
8556
  }
8457
8557
  getBitsForStudio(studio, callback) {
8458
8558
  if (this._studio) {