pixiboardjs 0.1.0-alpha.0 → 0.1.0-alpha.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.
package/dist/browser.js CHANGED
@@ -24,9 +24,14 @@ __export(src_exports, {
24
24
  ViewportController: () => ViewportController,
25
25
  assertWorldBounds: () => assertWorldBounds,
26
26
  createBoardCore: () => createBoardCore,
27
+ createPreviewSpec: () => createPreviewSpec,
28
+ isAssetVariant: () => isAssetVariant,
29
+ isDocumentPreviewType: () => isDocumentPreviewType,
30
+ isPreviewNodeType: () => isPreviewNodeType,
27
31
  isResizeHandle: () => isResizeHandle,
28
32
  mergeBounds: () => mergeBounds,
29
33
  nodeGeometry: () => nodeGeometry,
34
+ previewStatusLabel: () => previewStatusLabel,
30
35
  resizeHandleAxes: () => resizeHandleAxes,
31
36
  resizeHandleCursor: () => resizeHandleCursor,
32
37
  resolveResize: () => resolveResize,
@@ -34,6 +39,72 @@ __export(src_exports, {
34
39
  rotatedRectBounds: () => rotatedRectBounds
35
40
  });
36
41
 
42
+ // ../core/src/asset-variant.ts
43
+ function isAssetVariant(value) {
44
+ return value === "original" || value === "preview" || value === "waveform" || typeof value === "string" && value.length === 72 && /^preview-[a-f0-9]{64}$/.test(value);
45
+ }
46
+
47
+ // ../core/src/asset-previews.ts
48
+ function isDocumentPreviewType(type) {
49
+ return type === "html" || type === "markdown" || type === "text-file" || type === "file";
50
+ }
51
+ function isPreviewNodeType(type) {
52
+ return isDocumentPreviewType(type) || type === "model";
53
+ }
54
+ function record(value) {
55
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
56
+ }
57
+ function positiveNumber(value, fallback) {
58
+ const number = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? Number(value) : NaN;
59
+ return Number.isFinite(number) && number > 0 ? number : fallback;
60
+ }
61
+ function createPreviewSpec(node, options = {}) {
62
+ const saved = record(record(node.props).previewSpec);
63
+ const defaultHeight = node.type === "model" ? 768 : 704;
64
+ let width = positiveNumber(saved.width, 1024);
65
+ let height = positiveNumber(saved.height, defaultHeight);
66
+ let mode = saved.mode === "fixed-viewport" ? "fixed-viewport" : "viewport";
67
+ let quality = options.quality === "detail" || options.quality === "thumbnail" ? options.quality : saved.quality === "detail" ? "detail" : "thumbnail";
68
+ if (options.reason === "reset" || options.reason === "refresh") {
69
+ const ratio = typeof node.width === "number" && Number.isFinite(node.width) && node.width > 0 && typeof node.height === "number" && Number.isFinite(node.height) && node.height > 0 ? node.height / node.width : defaultHeight / 1024;
70
+ height = positiveNumber(width * ratio, defaultHeight);
71
+ mode = "fixed-viewport";
72
+ quality = options.quality === "thumbnail" ? "thumbnail" : "detail";
73
+ }
74
+ if (options.width !== void 0) width = positiveNumber(options.width, 1024);
75
+ if (options.height !== void 0) height = positiveNumber(options.height, defaultHeight);
76
+ const sideScale = Math.min(1, 4096 / width, 4096 / height);
77
+ width *= sideScale;
78
+ height *= sideScale;
79
+ const areaScale = Math.min(1, Math.sqrt(8e6 / (width * height)));
80
+ width = Math.max(1, Math.min(4096, Math.round(width * areaScale)));
81
+ height = Math.max(1, Math.min(4096, Math.round(height * areaScale)));
82
+ if (width * height > 8e6) height = Math.max(1, Math.floor(8e6 / width));
83
+ const pageValue = options.page === void 0 ? saved.page : options.page;
84
+ const page = Math.min(Number.MAX_SAFE_INTEGER, Math.max(1, Math.round(positiveNumber(pageValue, 1))));
85
+ return { width, height, page, mode, quality };
86
+ }
87
+ function previewStatusLabel(node, typeLabel) {
88
+ const props = record(node.props);
89
+ const name = typeof props.name === "string" ? props.name : node.name ?? "";
90
+ const isZip = typeof props.fileExtension === "string" && props.fileExtension.toLowerCase() === "zip" || /\.zip$/i.test(name);
91
+ if (isZip && (node.type !== "model" || typeof props.previewError === "string" && /ZIP_NO_MODEL/.test(props.previewError))) {
92
+ typeLabel = "ZIP";
93
+ }
94
+ switch (props.previewStatus) {
95
+ case "pending":
96
+ case "queued":
97
+ case "running":
98
+ return `${typeLabel}:\u9884\u89C8\u751F\u6210\u4E2D`;
99
+ case "error":
100
+ case "failed":
101
+ case "unsupported":
102
+ return `${typeLabel}:\u6682\u65E0\u9884\u89C8`;
103
+ default:
104
+ return typeLabel;
105
+ }
106
+ }
107
+
37
108
  // ../core/src/errors.ts
38
109
  var PixiBoardCoreError = class extends Error {
39
110
  constructor(message) {
@@ -251,7 +322,7 @@ function validateAssetRefs(input, path) {
251
322
  for (const [name, ref] of Object.entries(input)) {
252
323
  if (!name || !isRecord(ref)) throw new DocumentValidationError(`${path}.${name} is invalid`);
253
324
  readString(ref, "assetId", `${path}.${name}`);
254
- if (ref.variant !== void 0 && ref.variant !== "original" && ref.variant !== "preview" && ref.variant !== "waveform") {
325
+ if (ref.variant !== void 0 && !isAssetVariant(ref.variant)) {
255
326
  throw new DocumentValidationError(`${path}.${name}.variant is invalid`);
256
327
  }
257
328
  }
@@ -267,22 +338,22 @@ function parseInput(input) {
267
338
  function isRecord(value) {
268
339
  return value !== null && typeof value === "object" && !Array.isArray(value);
269
340
  }
270
- function readString(record, key, path) {
271
- const value = record[key];
341
+ function readString(record2, key, path) {
342
+ const value = record2[key];
272
343
  if (typeof value !== "string" || !value.trim()) {
273
344
  throw new DocumentValidationError(`${path}.${key} must be a non-empty string`);
274
345
  }
275
346
  return value;
276
347
  }
277
- function readInteger(record, key, path) {
278
- const value = record[key];
348
+ function readInteger(record2, key, path) {
349
+ const value = record2[key];
279
350
  if (!Number.isInteger(value)) {
280
351
  throw new DocumentValidationError(`${path}.${key} must be an integer`);
281
352
  }
282
353
  return value;
283
354
  }
284
- function readFiniteNumber(record, key, path) {
285
- const value = record[key];
355
+ function readFiniteNumber(record2, key, path) {
356
+ const value = record2[key];
286
357
  if (typeof value !== "number" || !Number.isFinite(value)) {
287
358
  throw new DocumentValidationError(`${path}.${key} must be a finite number`);
288
359
  }
@@ -2907,7 +2978,8 @@ var TransformController = class {
2907
2978
  if (!bounds) return [];
2908
2979
  const cos = Math.cos(bounds.rotation);
2909
2980
  const sin = Math.sin(bounds.rotation);
2910
- return RESIZE_HANDLES.map((handle) => {
2981
+ const allowed = new Set(this.options.handles ?? RESIZE_HANDLES);
2982
+ return RESIZE_HANDLES.filter((handle) => allowed.has(handle)).map((handle) => {
2911
2983
  const local = handleLocalPoint(handle, bounds.width, bounds.height);
2912
2984
  return {
2913
2985
  handle,
@@ -2970,7 +3042,7 @@ var ActiveSession = class {
2970
3042
  onEnd;
2971
3043
  done = false;
2972
3044
  origins;
2973
- update(deltaWorld) {
3045
+ update(deltaWorld, options = {}) {
2974
3046
  if (this.done) return;
2975
3047
  if (!Number.isFinite(deltaWorld.x) || !Number.isFinite(deltaWorld.y)) return;
2976
3048
  this.host.transaction(
@@ -2978,16 +3050,19 @@ var ActiveSession = class {
2978
3050
  () => {
2979
3051
  if (this.origins.length === 1) {
2980
3052
  const [only] = this.origins;
3053
+ const policy = this.host.resizePolicy(only.type);
3054
+ const adjustedDelta = options.preserveAspectRatio ? preserveAspectDelta(deltaWorld, this.handle, only.geometry) : deltaWorld;
3055
+ const limits = options.preserveAspectRatio && (!policy || policy.mode === "free") ? proportionalMinimums(only.geometry, this.limits) : this.limits;
2981
3056
  this.host.resize(only.id, {
2982
3057
  handle: this.handle,
2983
- deltaWorld,
3058
+ deltaWorld: adjustedDelta,
2984
3059
  origin: only.geometry,
2985
- minWidth: this.limits.minWidth,
2986
- minHeight: this.limits.minHeight
3060
+ minWidth: limits.minWidth,
3061
+ minHeight: limits.minHeight
2987
3062
  });
2988
3063
  return;
2989
3064
  }
2990
- this.scaleGroup(deltaWorld);
3065
+ this.scaleGroup(deltaWorld, options.preserveAspectRatio === true);
2991
3066
  },
2992
3067
  { origin: "ui", coalesceKey: this.coalesceKey }
2993
3068
  );
@@ -3027,25 +3102,58 @@ var ActiveSession = class {
3027
3102
  * nodes.resize(), which would re-anchor each node against its own origin
3028
3103
  * and tear the group apart.
3029
3104
  */
3030
- scaleGroup(deltaWorld) {
3105
+ scaleGroup(deltaWorld, preserveAspectRatio) {
3031
3106
  const box = this.groupOrigin;
3032
3107
  const axes = resizeHandleAxes(this.handle);
3033
- const width = Math.max(box.width + axes.horizontal * deltaWorld.x, this.limits.minWidth);
3034
- const height = Math.max(box.height + axes.vertical * deltaWorld.y, this.limits.minHeight);
3035
- const scaleX = box.width > 0 ? width / box.width : 1;
3036
- const scaleY = box.height > 0 ? height / box.height : 1;
3108
+ const gestureDelta = preserveAspectRatio ? preserveAspectDelta(deltaWorld, this.handle, { x: box.x, y: box.y, width: box.width, height: box.height, rotation: 0 }) : deltaWorld;
3109
+ const width = Math.max(box.width + axes.horizontal * gestureDelta.x, this.limits.minWidth);
3110
+ const height = Math.max(box.height + axes.vertical * gestureDelta.y, this.limits.minHeight);
3111
+ let scaleX = box.width > 0 ? width / box.width : 1;
3112
+ let scaleY = box.height > 0 ? height / box.height : 1;
3113
+ if (preserveAspectRatio && axes.horizontal !== 0 && axes.vertical !== 0) {
3114
+ let minimumScale = Math.max(
3115
+ box.width > 0 ? this.limits.minWidth / box.width : 1,
3116
+ box.height > 0 ? this.limits.minHeight / box.height : 1
3117
+ );
3118
+ for (const { type, geometry } of this.origins) {
3119
+ const policy = this.host.resizePolicy(type);
3120
+ if (policy && policy.mode !== "free") continue;
3121
+ if (geometry.width <= 0 || geometry.height <= 0) {
3122
+ minimumScale = Math.max(
3123
+ minimumScale,
3124
+ geometry.width > 0 ? this.limits.minWidth / geometry.width : 0,
3125
+ geometry.height > 0 ? this.limits.minHeight / geometry.height : 0
3126
+ );
3127
+ continue;
3128
+ }
3129
+ const minimums = proportionalMinimums(geometry, this.limits);
3130
+ minimumScale = Math.max(
3131
+ minimumScale,
3132
+ minimums.minWidth / geometry.width,
3133
+ minimums.minHeight / geometry.height
3134
+ );
3135
+ }
3136
+ const scale = Math.max(scaleX, scaleY, minimumScale);
3137
+ scaleX = scale;
3138
+ scaleY = scale;
3139
+ }
3037
3140
  const anchorX = axes.horizontal === -1 ? box.x + box.width : box.x;
3038
3141
  const anchorY = axes.vertical === -1 ? box.y + box.height : box.y;
3039
3142
  for (const { id, type, geometry } of this.origins) {
3040
3143
  const node = this.host.getNode(id);
3041
3144
  if (!node) continue;
3042
- const resolved = resolveResizeSize(node, this.host.resizePolicy(type), {
3145
+ const policy = this.host.resizePolicy(type);
3146
+ const limits = preserveAspectRatio && (!policy || policy.mode === "free") ? geometry.width <= 0 || geometry.height <= 0 ? {
3147
+ minWidth: geometry.width > 0 ? this.limits.minWidth : 0,
3148
+ minHeight: geometry.height > 0 ? this.limits.minHeight : 0
3149
+ } : proportionalMinimums(geometry, this.limits) : this.limits;
3150
+ const resolved = resolveResizeSize(node, policy, {
3043
3151
  handle: this.handle,
3044
3152
  width: geometry.width * scaleX,
3045
3153
  height: geometry.height * scaleY,
3046
3154
  origin: geometry,
3047
- minWidth: this.limits.minWidth,
3048
- minHeight: this.limits.minHeight
3155
+ minWidth: limits.minWidth,
3156
+ minHeight: limits.minHeight
3049
3157
  });
3050
3158
  if (!resolved) continue;
3051
3159
  this.host.update(id, {
@@ -3058,6 +3166,31 @@ var ActiveSession = class {
3058
3166
  }
3059
3167
  }
3060
3168
  };
3169
+ function proportionalMinimums(geometry, limits) {
3170
+ const ratio = geometry.width / geometry.height;
3171
+ if (!Number.isFinite(ratio) || ratio <= 0) return limits;
3172
+ return {
3173
+ minWidth: Math.max(limits.minWidth, limits.minHeight * ratio),
3174
+ minHeight: Math.max(limits.minHeight, limits.minWidth / ratio)
3175
+ };
3176
+ }
3177
+ function preserveAspectDelta(deltaWorld, handle, origin) {
3178
+ const axes = resizeHandleAxes(handle);
3179
+ if (axes.horizontal === 0 || axes.vertical === 0 || origin.width <= 0 || origin.height <= 0) return deltaWorld;
3180
+ const ratio = origin.width / origin.height;
3181
+ const cos = Math.cos(origin.rotation);
3182
+ const sin = Math.sin(origin.rotation);
3183
+ const localDelta = { x: deltaWorld.x * cos + deltaWorld.y * sin, y: -deltaWorld.x * sin + deltaWorld.y * cos };
3184
+ const widthDelta = axes.horizontal * localDelta.x;
3185
+ const heightDelta = axes.vertical * localDelta.y;
3186
+ let localResult;
3187
+ if (Math.abs(widthDelta) >= Math.abs(heightDelta) * ratio) {
3188
+ localResult = { x: localDelta.x, y: axes.vertical * (widthDelta / ratio) };
3189
+ } else {
3190
+ localResult = { x: axes.horizontal * (heightDelta * ratio), y: localDelta.y };
3191
+ }
3192
+ return { x: localResult.x * cos - localResult.y * sin, y: localResult.x * sin + localResult.y * cos };
3193
+ }
3061
3194
  function handleLocalPoint(handle, width, height) {
3062
3195
  const axes = resizeHandleAxes(handle);
3063
3196
  return {
@@ -3820,6 +3953,11 @@ function attachDomTransformer(board, options) {
3820
3953
  let captureElement;
3821
3954
  let startScreen = { x: 0, y: 0 };
3822
3955
  let interactive = true;
3956
+ const allowedHandles = new Set(options.handles ?? ["nw", "n", "ne", "e", "se", "s", "sw", "w"]);
3957
+ let allowFreeResize = false;
3958
+ const hasAspectModifier = (event) => {
3959
+ return event.metaKey || event.ctrlKey || event.getModifierState("Meta") || event.getModifierState("Control");
3960
+ };
3823
3961
  const applyInteractivity = () => {
3824
3962
  for (const element of elements.values()) element.style.pointerEvents = interactive ? "auto" : "none";
3825
3963
  };
@@ -3877,6 +4015,7 @@ function attachDomTransformer(board, options) {
3877
4015
  if (event.button !== 0 || session) return;
3878
4016
  event.preventDefault();
3879
4017
  event.stopPropagation();
4018
+ allowFreeResize = hasAspectModifier(event);
3880
4019
  const started = board.transform.begin(handle);
3881
4020
  if (!started) return;
3882
4021
  session = started;
@@ -3892,7 +4031,10 @@ function attachDomTransformer(board, options) {
3892
4031
  const screen = toSurfacePoint(event);
3893
4032
  const from = board.viewport.toWorld(startScreen);
3894
4033
  const to = board.viewport.toWorld(screen);
3895
- session.update({ x: to.x - from.x, y: to.y - from.y });
4034
+ session.update(
4035
+ { x: to.x - from.x, y: to.y - from.y },
4036
+ { preserveAspectRatio: !(allowFreeResize || hasAspectModifier(event)) }
4037
+ );
3896
4038
  refresh();
3897
4039
  };
3898
4040
  const onPointerUp = (event) => {
@@ -3918,11 +4060,9 @@ function attachDomTransformer(board, options) {
3918
4060
  return element;
3919
4061
  };
3920
4062
  const refresh = () => {
3921
- const placements = board.transform.handles();
3922
- if (placements.length === 0) {
3923
- for (const element of elements.values()) element.style.display = "none";
3924
- return;
3925
- }
4063
+ const placements = board.transform.handles().filter((placement) => allowedHandles.has(placement.handle));
4064
+ for (const element of elements.values()) element.style.display = "none";
4065
+ if (placements.length === 0) return;
3926
4066
  for (const placement of placements) {
3927
4067
  const element = handleFor(placement.handle);
3928
4068
  const screen = board.viewport.toScreen(placement.world);
@@ -3933,13 +4073,24 @@ function attachDomTransformer(board, options) {
3933
4073
  }
3934
4074
  };
3935
4075
  const onKeyDown = (event) => {
4076
+ if (event.key === "Meta" || event.key === "Control" || event.code === "MetaLeft" || event.code === "MetaRight" || event.code === "ControlLeft" || event.code === "ControlRight") allowFreeResize = hasAspectModifier(event);
3936
4077
  if (event.key === "Escape" && session) {
3937
4078
  event.preventDefault();
3938
4079
  endSession("cancel");
3939
4080
  }
3940
4081
  };
4082
+ const onKeyUp = (event) => {
4083
+ if (event.key === "Meta" || event.key === "Control" || event.code === "MetaLeft" || event.code === "MetaRight" || event.code === "ControlLeft" || event.code === "ControlRight") allowFreeResize = hasAspectModifier(event);
4084
+ };
4085
+ const onWindowBlur = () => {
4086
+ allowFreeResize = false;
4087
+ };
3941
4088
  window.addEventListener("keydown", onKeyDown);
4089
+ window.addEventListener("keyup", onKeyUp);
4090
+ window.addEventListener("blur", onWindowBlur);
3942
4091
  disposers.push(() => window.removeEventListener("keydown", onKeyDown));
4092
+ disposers.push(() => window.removeEventListener("keyup", onKeyUp));
4093
+ disposers.push(() => window.removeEventListener("blur", onWindowBlur));
3943
4094
  for (const event of ["selection:change", "change", "viewport:change"]) {
3944
4095
  disposers.push(board.on(event, refresh));
3945
4096
  }
@@ -4174,6 +4325,7 @@ function attachSelectionOverlay(board, options) {
4174
4325
  const prefix = options.classPrefix ?? "pixiboard";
4175
4326
  const padding = options.groupBoxPadding ?? 6;
4176
4327
  const groupBox = options.groupBox ?? true;
4328
+ const nodeOutlines = options.nodeOutlines ?? true;
4177
4329
  const outlineClass = `${prefix}-selection-outline`;
4178
4330
  const groupClass = `${prefix}-selection-bbox`;
4179
4331
  let groupElement;
@@ -4218,7 +4370,10 @@ function attachSelectionOverlay(board, options) {
4218
4370
  // Selection outlines follow the selection, not the viewport: a selected
4219
4371
  // node scrolled just off screen must keep its outline, so this
4220
4372
  // deliberately opts out of visible-set culling.
4221
- candidates: () => board.selection.get(),
4373
+ candidates: () => {
4374
+ const selected = board.selection.get();
4375
+ return nodeOutlines === true || nodeOutlines === "single" && selected.length === 1 ? selected : [];
4376
+ },
4222
4377
  item: () => ({ anchor: "top-left" }),
4223
4378
  render: ({ element, node }) => {
4224
4379
  const size = screenSize(board, node);
@@ -4262,7 +4417,9 @@ function attachLabelOverlay(board, options) {
4262
4417
  data: { text: value, icon: options.icon?.(node) }
4263
4418
  };
4264
4419
  },
4265
- render: ({ element, placement }) => {
4420
+ render: ({ element, placement, node }) => {
4421
+ const previewError = node.props?.previewError;
4422
+ element.title = typeof previewError === "string" ? previewError : "";
4266
4423
  let parts = labelParts.get(element);
4267
4424
  if (!parts) {
4268
4425
  parts = {
@@ -4300,6 +4457,11 @@ function screenSize(board, node) {
4300
4457
  };
4301
4458
  }
4302
4459
 
4460
+ // ../adapter-browser/src/asset-variant.ts
4461
+ function assertAssetVariant(value) {
4462
+ if (!isAssetVariant(value)) throw new TypeError("Invalid asset binary variant");
4463
+ }
4464
+
4303
4465
  // ../adapter-browser/src/errors.ts
4304
4466
  var BrowserPersistenceError = class extends Error {
4305
4467
  cause;
@@ -4482,7 +4644,7 @@ var BrowserPersistenceAdapter = class {
4482
4644
  return this.#destroyed;
4483
4645
  }
4484
4646
  get cleanupErrors() {
4485
- return this.#cleanupErrors.map((record) => ({ ...record }));
4647
+ return this.#cleanupErrors.map((record2) => ({ ...record2 }));
4486
4648
  }
4487
4649
  async capabilities(options = {}) {
4488
4650
  return this.#run(options.signal, async (signal) => ({
@@ -4504,20 +4666,20 @@ var BrowserPersistenceAdapter = class {
4504
4666
  }
4505
4667
  async loadDocument(options = {}) {
4506
4668
  return this.#run(options.signal, async (signal) => {
4507
- const record = await this.#indexedDb.loadDocument(signal);
4669
+ const record2 = await this.#indexedDb.loadDocument(signal);
4508
4670
  this.#throwIfAborted(signal);
4509
- return record === void 0 ? null : cloneValue2(record);
4671
+ return record2 === void 0 ? null : cloneValue2(record2);
4510
4672
  });
4511
4673
  }
4512
4674
  async saveDocument(input, options = {}) {
4513
4675
  await this.#run(options.signal, async (signal) => {
4514
- const record = {
4676
+ const record2 = {
4515
4677
  snapshot: cloneValue2(input.snapshot),
4516
4678
  metadata: cloneValue2(input.metadata ?? {}),
4517
4679
  savedAt: this.#now()
4518
4680
  };
4519
4681
  this.#throwIfAborted(signal);
4520
- await this.#indexedDb.saveDocument(record, signal, {
4682
+ await this.#indexedDb.saveDocument(record2, signal, {
4521
4683
  expectedRevision: input.expectedRevision
4522
4684
  });
4523
4685
  });
@@ -4605,14 +4767,14 @@ var BrowserPersistenceAdapter = class {
4605
4767
  ];
4606
4768
  document2.nodes.push(node);
4607
4769
  const current = options.documentMetadata === void 0 ? await this.#indexedDb.loadDocument(signal) : void 0;
4608
- const record = {
4770
+ const record2 = {
4609
4771
  snapshot: document2,
4610
4772
  metadata: cloneValue2(options.documentMetadata ?? current?.metadata ?? {}),
4611
4773
  savedAt: now
4612
4774
  };
4613
4775
  try {
4614
4776
  await this.#indexedDb.commitAssetAndDocument(
4615
- record,
4777
+ record2,
4616
4778
  entry,
4617
4779
  { variant: "original", blob: prepared.blob },
4618
4780
  signal,
@@ -4658,10 +4820,11 @@ var BrowserPersistenceAdapter = class {
4658
4820
  async importUrl(url, options) {
4659
4821
  return this.commitImport(await this.prepareUrl(url, options), options);
4660
4822
  }
4661
- async putAsset(record, blob, options = {}) {
4823
+ async putAsset(record2, blob, options = {}) {
4662
4824
  return this.#run(options.signal, async (signal) => {
4663
- const variant = options.variant ?? "original";
4664
- const previous = await this.#indexedDb.getAssetEntry(record.id, signal);
4825
+ const variant = options.variant === void 0 ? "original" : options.variant;
4826
+ assertAssetVariant(variant);
4827
+ const previous = await this.#indexedDb.getAssetEntry(record2.id, signal);
4665
4828
  const previousBinary = previous?.binaries[variant];
4666
4829
  this.#throwIfAborted(signal);
4667
4830
  const now = this.#now();
@@ -4670,14 +4833,14 @@ var BrowserPersistenceAdapter = class {
4670
4833
  this.#throwIfAborted(signal);
4671
4834
  let entry;
4672
4835
  if (useOpfs && this.#opfs !== void 0) {
4673
- const key = this.#storageKeyFactory(record.id, variant);
4836
+ const key = this.#storageKeyFactory(record2.id, variant);
4674
4837
  if (previousBinary?.storage.kind === "opfs" && previousBinary.storage.key === key) {
4675
4838
  throw new BrowserStorageKeyCollisionError(key);
4676
4839
  }
4677
4840
  if (await this.#opfs.get(key, signal) !== void 0) {
4678
4841
  throw new BrowserStorageKeyCollisionError(key);
4679
4842
  }
4680
- entry = this.#createEntry(cloneValue2(record), variant, blob, { kind: "opfs", key }, previous, now);
4843
+ entry = this.#createEntry(cloneValue2(record2), variant, blob, { kind: "opfs", key }, previous, now);
4681
4844
  await this.#opfs.put(key, blob, signal);
4682
4845
  try {
4683
4846
  this.#throwIfAborted(signal);
@@ -4685,23 +4848,23 @@ var BrowserPersistenceAdapter = class {
4685
4848
  } catch (error) {
4686
4849
  await this.#cleanup(
4687
4850
  "metadata-compensation",
4688
- { assetId: record.id, variant, key },
4851
+ { assetId: record2.id, variant, key },
4689
4852
  () => this.#opfs?.delete(key, new AbortController().signal)
4690
4853
  );
4691
4854
  throw error;
4692
4855
  }
4693
4856
  } else {
4694
- entry = this.#createEntry(cloneValue2(record), variant, blob, { kind: "indexeddb" }, previous, now);
4857
+ entry = this.#createEntry(cloneValue2(record2), variant, blob, { kind: "indexeddb" }, previous, now);
4695
4858
  this.#throwIfAborted(signal);
4696
4859
  await this.#indexedDb.putAssetEntry(entry, { variant, blob }, signal);
4697
4860
  }
4698
- this.#revokeAssetLeases(record.id, variant);
4861
+ this.#revokeAssetLeases(record2.id, variant);
4699
4862
  const binary = entry.binaries[variant];
4700
4863
  if (previousBinary?.storage.kind === "opfs" && (binary.storage.kind !== "opfs" || binary.storage.key !== previousBinary.storage.key)) {
4701
4864
  const previousKey = previousBinary.storage.key;
4702
4865
  await this.#cleanup(
4703
4866
  "replace-old-opfs",
4704
- { assetId: record.id, variant, key: previousKey },
4867
+ { assetId: record2.id, variant, key: previousKey },
4705
4868
  () => this.#opfs?.delete(previousKey, new AbortController().signal)
4706
4869
  );
4707
4870
  }
@@ -4709,13 +4872,15 @@ var BrowserPersistenceAdapter = class {
4709
4872
  });
4710
4873
  }
4711
4874
  async putDerivative(assetId, variant, blob, options = {}) {
4875
+ assertAssetVariant(variant);
4712
4876
  const entry = await this.#run(options.signal, (signal) => this.#indexedDb.getAssetEntry(assetId, signal));
4713
4877
  if (entry === void 0) throw new BrowserAssetNotFoundError(assetId);
4714
4878
  return this.putAsset(entry.record, blob, { ...options, variant });
4715
4879
  }
4716
4880
  async getAsset(id, options = {}) {
4717
4881
  return this.#run(options.signal, async (signal) => {
4718
- const variant = options.variant ?? "original";
4882
+ const variant = options.variant === void 0 ? "original" : options.variant;
4883
+ assertAssetVariant(variant);
4719
4884
  const entry = await this.#indexedDb.getAssetEntry(id, signal);
4720
4885
  this.#throwIfAborted(signal);
4721
4886
  if (entry === void 0) return null;
@@ -4760,7 +4925,8 @@ var BrowserPersistenceAdapter = class {
4760
4925
  }
4761
4926
  async leaseObjectUrl(id, options = {}) {
4762
4927
  return this.#run(options.signal, async (signal) => {
4763
- const variant = options.variant ?? "original";
4928
+ const variant = options.variant === void 0 ? "original" : options.variant;
4929
+ assertAssetVariant(variant);
4764
4930
  const asset = await this.getAsset(id, { signal, variant });
4765
4931
  this.#throwIfAborted(signal);
4766
4932
  if (asset === null) throw new BrowserAssetNotFoundError(id);
@@ -4792,7 +4958,8 @@ var BrowserPersistenceAdapter = class {
4792
4958
  }
4793
4959
  async exportAsset(id, options = {}) {
4794
4960
  return this.#run(options.signal, async (signal) => {
4795
- const variant = options.variant ?? "original";
4961
+ const variant = options.variant === void 0 ? "original" : options.variant;
4962
+ assertAssetVariant(variant);
4796
4963
  const asset = await this.getAsset(id, { signal, variant });
4797
4964
  if (asset === null) throw new BrowserAssetNotFoundError(id);
4798
4965
  const storedName = asset.entry.record.metadata?.fileName;
@@ -4910,10 +5077,10 @@ var BrowserPersistenceAdapter = class {
4910
5077
  })).then(() => void 0);
4911
5078
  return this.#destroyPromise;
4912
5079
  }
4913
- #createEntry(record, variant, blob, storage, previous, now) {
5080
+ #createEntry(record2, variant, blob, storage, previous, now) {
4914
5081
  return {
4915
- id: record.id,
4916
- record,
5082
+ id: record2.id,
5083
+ record: record2,
4917
5084
  binaries: {
4918
5085
  ...previous?.binaries,
4919
5086
  [variant]: {
@@ -4997,15 +5164,15 @@ var BrowserPersistenceAdapter = class {
4997
5164
  try {
4998
5165
  await cleanup();
4999
5166
  } catch (error) {
5000
- const record = {
5167
+ const record2 = {
5001
5168
  operation,
5002
5169
  error,
5003
5170
  timestamp: this.#now(),
5004
5171
  ...context
5005
5172
  };
5006
- this.#cleanupErrors.push(record);
5173
+ this.#cleanupErrors.push(record2);
5007
5174
  try {
5008
- this.#onCleanupError({ ...record });
5175
+ this.#onCleanupError({ ...record2 });
5009
5176
  } catch (observerError) {
5010
5177
  this.#cleanupErrors.push({
5011
5178
  operation: "cleanup-observer",
@@ -5200,6 +5367,7 @@ var ASSET_STORE = "asset-metadata";
5200
5367
  var BLOB_STORE = "asset-blobs";
5201
5368
  var DOCUMENT_KEY = "current";
5202
5369
  function blobKey(id, variant) {
5370
+ assertAssetVariant(variant);
5203
5371
  return [id, variant];
5204
5372
  }
5205
5373
  function abortError2(signal) {
@@ -5245,7 +5413,7 @@ var NativeIndexedDbPort = class {
5245
5413
  async loadDocument(signal) {
5246
5414
  return this.#read(DOCUMENT_STORE, DOCUMENT_KEY, signal);
5247
5415
  }
5248
- async saveDocument(record, signal, options = {}) {
5416
+ async saveDocument(record2, signal, options = {}) {
5249
5417
  const database = await this.#open(signal);
5250
5418
  if (signal.aborted) throw abortError2(signal);
5251
5419
  const transaction = database.transaction(DOCUMENT_STORE, "readwrite");
@@ -5262,7 +5430,7 @@ var NativeIndexedDbPort = class {
5262
5430
  throw new BrowserDocumentConflictError(options.expectedRevision, actualRevision);
5263
5431
  }
5264
5432
  }
5265
- transaction.objectStore(DOCUMENT_STORE).put(record, DOCUMENT_KEY);
5433
+ transaction.objectStore(DOCUMENT_STORE).put(record2, DOCUMENT_KEY);
5266
5434
  await done;
5267
5435
  } catch (error) {
5268
5436
  try {
@@ -5290,6 +5458,8 @@ var NativeIndexedDbPort = class {
5290
5458
  return this.#read(BLOB_STORE, blobKey(id, variant), signal);
5291
5459
  }
5292
5460
  async putAssetEntry(entry, binaryWrite, signal) {
5461
+ for (const variant of Object.keys(entry.binaries)) assertAssetVariant(variant);
5462
+ if (binaryWrite !== void 0) assertAssetVariant(binaryWrite.variant);
5293
5463
  await this.#write([ASSET_STORE, BLOB_STORE], signal, (transaction) => {
5294
5464
  transaction.objectStore(ASSET_STORE).put(entry, entry.id);
5295
5465
  if (binaryWrite !== void 0) {
@@ -5305,6 +5475,8 @@ var NativeIndexedDbPort = class {
5305
5475
  });
5306
5476
  }
5307
5477
  async commitAssetAndDocument(document2, entry, binaryWrite, signal, options = {}) {
5478
+ for (const variant of Object.keys(entry.binaries)) assertAssetVariant(variant);
5479
+ if (binaryWrite !== void 0) assertAssetVariant(binaryWrite.variant);
5308
5480
  const database = await this.#open(signal);
5309
5481
  if (signal.aborted) throw abortError2(signal);
5310
5482
  const transaction = database.transaction(
@@ -5508,6 +5680,6 @@ function indexedDbPersistence(options = {}) {
5508
5680
  });
5509
5681
  }
5510
5682
 
5511
- export { AssetUnavailableError, BoardDestroyedError, BrowserAssetBinaryMissingError, BrowserAssetNotFoundError, BrowserDocumentConflictError, BrowserPersistenceAbortError, BrowserPersistenceAdapter, BrowserPersistenceDestroyedError, BrowserPersistenceError, BrowserStorageCapabilityError, BrowserStorageKeyCollisionError, BrowserStorageQuotaError, CapabilityError, CapabilityUnavailableError, DEFAULT_OPFS_THRESHOLD_BYTES, DocumentValidationError, NativeDownloadPort, NativeIndexedDbPort, NativeObjectUrlPort, NativeOpfsPort, NodeNotFoundError, NodeTypeNotRegisteredError, NodeValidationError, PermissionDeniedError, RESIZE_HANDLES, TransactionConflictError, anchorRatio, anchorWorldPoint, attachDomTransformer, attachLabelOverlay, attachOverlayLayer, attachSelectionOverlay, createPixiBoard, indexedDbPersistence, isBrowserQuotaError, projectOverlayItem, resizeHandleAxes, resizeHandleCursor, resolveOverlayBounds, resolveScale, runBrowserAdapterContract };
5683
+ export { AssetUnavailableError, BoardDestroyedError, BrowserAssetBinaryMissingError, BrowserAssetNotFoundError, BrowserDocumentConflictError, BrowserPersistenceAbortError, BrowserPersistenceAdapter, BrowserPersistenceDestroyedError, BrowserPersistenceError, BrowserStorageCapabilityError, BrowserStorageKeyCollisionError, BrowserStorageQuotaError, CapabilityError, CapabilityUnavailableError, DEFAULT_OPFS_THRESHOLD_BYTES, DocumentValidationError, NativeDownloadPort, NativeIndexedDbPort, NativeObjectUrlPort, NativeOpfsPort, NodeNotFoundError, NodeTypeNotRegisteredError, NodeValidationError, PermissionDeniedError, RESIZE_HANDLES, TransactionConflictError, anchorRatio, anchorWorldPoint, attachDomTransformer, attachLabelOverlay, attachOverlayLayer, attachSelectionOverlay, createPixiBoard, createPreviewSpec, indexedDbPersistence, isAssetVariant, isBrowserQuotaError, isDocumentPreviewType, isPreviewNodeType, previewStatusLabel, projectOverlayItem, resizeHandleAxes, resizeHandleCursor, resolveOverlayBounds, resolveScale, runBrowserAdapterContract };
5512
5684
  //# sourceMappingURL=browser.js.map
5513
5685
  //# sourceMappingURL=browser.js.map