pixiboardjs 0.1.0-alpha.1 → 0.1.0-alpha.3
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/CHANGELOG.md +14 -0
- package/dist/browser.d.ts +5 -5
- package/dist/browser.js +124 -36
- package/dist/browser.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +79 -8
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +2 -2
- package/dist/node.js +79 -8
- package/dist/node.js.map +1 -1
- package/dist/{types-DhluAalJ.d.ts → types-CZ0KxRlm.d.ts} +45 -6
- package/dist/types.d.ts +1 -1
- package/etc/pixiboardjs-browser.api.md +84 -21
- package/etc/pixiboardjs-node.api.md +83 -20
- package/etc/pixiboardjs-types.api.md +68 -20
- package/etc/pixiboardjs.api.md +83 -20
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.0-alpha.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix the official site generic host import dispatch so imported assets are routed through the configured host preview flow.
|
|
8
|
+
|
|
9
|
+
Keep local model content-addressed variants in isolated copies so preview variant updates do not mutate shared asset data.
|
|
10
|
+
|
|
11
|
+
## 0.1.0-alpha.2
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- Add validated content-addressed preview variants, shared preview state and stable viewport/reset sizing helpers, and a host-configurable preview lifecycle in the site. The site accepts arbitrary files, classifies ZIP model archives by their directory, preserves preview state, and guards stale texture decodes. Hosts can supply preview jobs without coupling the SDK to a transport or renderer service.
|
|
16
|
+
|
|
3
17
|
## 0.1.0-alpha.1
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { AssetUnavailableError, BoardDestroyedError, CapabilityError, CapabilityUnavailableError, DocumentValidationError, NodeNotFoundError, NodeTypeNotRegisteredError, NodeValidationError, PermissionDeniedError, RESIZE_HANDLES, TransactionConflictError, createPixiBoard, resizeHandleAxes, resizeHandleCursor } from './index.js';
|
|
2
|
-
import { R as ResizeHandle, P as PixiBoard, B as BoardNode, J as JsonValue, W as WorldBounds, a as Point, V as ViewportSnapshot, b as BoardDocument,
|
|
3
|
-
export {
|
|
1
|
+
export { AssetUnavailableError, BoardDestroyedError, CapabilityError, CapabilityUnavailableError, DocumentValidationError, NodeNotFoundError, NodeTypeNotRegisteredError, NodeValidationError, PermissionDeniedError, RESIZE_HANDLES, TransactionConflictError, createPixiBoard, isAssetVariant, resizeHandleAxes, resizeHandleCursor } from './index.js';
|
|
2
|
+
import { R as ResizeHandle, P as PixiBoard, B as BoardNode, J as JsonValue, W as WorldBounds, a as Point, V as ViewportSnapshot, A as AssetVariant, b as BoardDocument, c as AssetRecord } from './types-CZ0KxRlm.js';
|
|
3
|
+
export { d as AssetRef, e as BoardCapabilities, f as BoardChangeEvent, g as BoardDocumentUpdate, h as BoardLifecycleState, i as BoardNodeCreateInput, j as BoardNodePatch, k as BoardRuntimePorts, l as BrowserEventPort, C as CaptureInput, m as CaptureResult, n as ChangeOrigin, o as CustomDisplayFactory, p as CustomDisplayObject, q as CustomNodeDataDefinition, r as CustomNodeDefinition, s as CustomNodeRenderer, t as CustomNodeRendererContext, u as CustomNodeRendererRegistry, v as CustomNodeView, w as CustomResizePolicy, x as CustomTextureLease, D as DocumentLoadOptions, y as DocumentPersistence, H as HistoryChangeEvent, N as NodeGeometry, z as NodeHandle, E as NodeHandleEventMap, F as NodeInput, G as NodeListFilter, I as NodePatch, K as NodeQuery, L as NodeResizeRequest, M as NodeTypeDefinition, O as NodeTypeRegistrationDisposer, Q as NodeTypeRegistrationOptions, S as PixiBoardOptions, T as PixiBoardRendererOptions, U as PreviewNode, X as PreviewQuality, Y as PreviewSpec, Z as PreviewSpecOptions, _ as PreviewState, $ as PreviewStatus, a0 as PublicBoardEventMap, a1 as PublicNodeTypeDefinition, a2 as PublicRendererOptions, a3 as RenderCompleteEvent, a4 as RendererApplyResult, a5 as ResizeObserverPort, a6 as RuntimeRenderer, a7 as SelectionChangeEvent, a8 as TickerPort, a9 as TransactionOptions, aa as TransactionOrigin, ab as TransformBounds, ac as TransformHandlePlacement, ad as TransformSession, ae as ViewportChangeEvent, af as createPreviewSpec, ag as isDocumentPreviewType, ah as isPreviewNodeType, ai as previewStatusLabel } from './types-CZ0KxRlm.js';
|
|
4
4
|
|
|
5
5
|
type DomTransformerOptions = {
|
|
6
6
|
/**
|
|
@@ -315,7 +315,7 @@ type AssetStorageLocation = {
|
|
|
315
315
|
kind: "opfs";
|
|
316
316
|
key: string;
|
|
317
317
|
};
|
|
318
|
-
type AssetBinaryVariant =
|
|
318
|
+
type AssetBinaryVariant = AssetVariant;
|
|
319
319
|
type StoredAssetBinary = {
|
|
320
320
|
storage: AssetStorageLocation;
|
|
321
321
|
size: number;
|
|
@@ -662,4 +662,4 @@ declare function indexedDbPersistence(options?: {
|
|
|
662
662
|
database?: string;
|
|
663
663
|
}): BrowserPersistenceAdapter;
|
|
664
664
|
|
|
665
|
-
export { type AdapterOperationOptions, type AssetBinaryVariant, type AssetGcOptions, type AssetGcResult, type AssetGcRoots, type AssetStorageLocation, BoardDocument, BoardNode, type BrowserAdapterCapabilities, type BrowserAdapterContractEvidence, type BrowserAdapterContractHarness, type BrowserAsset, BrowserAssetBinaryMissingError, type BrowserAssetExport, BrowserAssetNotFoundError, type BrowserCleanupError, type BrowserCleanupOperation, type BrowserCommitImportOptions, BrowserDocumentConflictError, type BrowserDocumentMetadata, type BrowserDocumentRecord, type BrowserDownloadRequest, type BrowserExportOptions, type BrowserImportOptions, type BrowserImportResult, type BrowserImportSourceType, BrowserPersistenceAbortError, BrowserPersistenceAdapter, type BrowserPersistenceAdapterOptions, BrowserPersistenceDestroyedError, BrowserPersistenceError, type BrowserPrepareImportOptions, type BrowserPreparedImport, BrowserStorageCapabilityError, BrowserStorageKeyCollisionError, BrowserStorageQuotaError, DEFAULT_OPFS_THRESHOLD_BYTES, type DomTransformer, type DomTransformerOptions, type DownloadPort, type GetAssetOptions, type IndexedDbPort, JsonValue, type LabelOverlayOptions, NativeDownloadPort, type NativeDownloadPortOptions, NativeIndexedDbPort, type NativeIndexedDbPortOptions, NativeObjectUrlPort, NativeOpfsPort, type NativeOpfsPortOptions, type ObjectUrlLease, type ObjectUrlPort, type OpfsPort, type OverlayAnchor, type OverlayBoundsResolver, type OverlayDeclutter, type OverlayItem, type OverlayLayer, type OverlayLayerOptions, type OverlayPlacement, type OverlayRenderContext, type OverlayScaleMode, PixiBoard, Point, type PortLifecycle, type PutAssetOptions, ResizeHandle, type SaveBrowserDocumentInput, type SaveBrowserDocumentOptions, type SelectionOverlayOptions, type StoredAssetBinary, type StoredAssetEntry, ViewportSnapshot, WorldBounds, anchorRatio, anchorWorldPoint, attachDomTransformer, attachLabelOverlay, attachOverlayLayer, attachSelectionOverlay, indexedDbPersistence, isBrowserQuotaError, projectOverlayItem, resolveOverlayBounds, resolveScale, runBrowserAdapterContract };
|
|
665
|
+
export { type AdapterOperationOptions, type AssetBinaryVariant, type AssetGcOptions, type AssetGcResult, type AssetGcRoots, type AssetStorageLocation, AssetVariant, BoardDocument, BoardNode, type BrowserAdapterCapabilities, type BrowserAdapterContractEvidence, type BrowserAdapterContractHarness, type BrowserAsset, BrowserAssetBinaryMissingError, type BrowserAssetExport, BrowserAssetNotFoundError, type BrowserCleanupError, type BrowserCleanupOperation, type BrowserCommitImportOptions, BrowserDocumentConflictError, type BrowserDocumentMetadata, type BrowserDocumentRecord, type BrowserDownloadRequest, type BrowserExportOptions, type BrowserImportOptions, type BrowserImportResult, type BrowserImportSourceType, BrowserPersistenceAbortError, BrowserPersistenceAdapter, type BrowserPersistenceAdapterOptions, BrowserPersistenceDestroyedError, BrowserPersistenceError, type BrowserPrepareImportOptions, type BrowserPreparedImport, BrowserStorageCapabilityError, BrowserStorageKeyCollisionError, BrowserStorageQuotaError, DEFAULT_OPFS_THRESHOLD_BYTES, type DomTransformer, type DomTransformerOptions, type DownloadPort, type GetAssetOptions, type IndexedDbPort, JsonValue, type LabelOverlayOptions, NativeDownloadPort, type NativeDownloadPortOptions, NativeIndexedDbPort, type NativeIndexedDbPortOptions, NativeObjectUrlPort, NativeOpfsPort, type NativeOpfsPortOptions, type ObjectUrlLease, type ObjectUrlPort, type OpfsPort, type OverlayAnchor, type OverlayBoundsResolver, type OverlayDeclutter, type OverlayItem, type OverlayLayer, type OverlayLayerOptions, type OverlayPlacement, type OverlayRenderContext, type OverlayScaleMode, PixiBoard, Point, type PortLifecycle, type PutAssetOptions, ResizeHandle, type SaveBrowserDocumentInput, type SaveBrowserDocumentOptions, type SelectionOverlayOptions, type StoredAssetBinary, type StoredAssetEntry, ViewportSnapshot, WorldBounds, anchorRatio, anchorWorldPoint, attachDomTransformer, attachLabelOverlay, attachOverlayLayer, attachSelectionOverlay, indexedDbPersistence, isBrowserQuotaError, projectOverlayItem, resolveOverlayBounds, resolveScale, runBrowserAdapterContract };
|
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
|
|
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(
|
|
271
|
-
const value =
|
|
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(
|
|
278
|
-
const value =
|
|
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(
|
|
285
|
-
const value =
|
|
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
|
}
|
|
@@ -4346,7 +4417,9 @@ function attachLabelOverlay(board, options) {
|
|
|
4346
4417
|
data: { text: value, icon: options.icon?.(node) }
|
|
4347
4418
|
};
|
|
4348
4419
|
},
|
|
4349
|
-
render: ({ element, placement }) => {
|
|
4420
|
+
render: ({ element, placement, node }) => {
|
|
4421
|
+
const previewError = node.props?.previewError;
|
|
4422
|
+
element.title = typeof previewError === "string" ? previewError : "";
|
|
4350
4423
|
let parts = labelParts.get(element);
|
|
4351
4424
|
if (!parts) {
|
|
4352
4425
|
parts = {
|
|
@@ -4384,6 +4457,11 @@ function screenSize(board, node) {
|
|
|
4384
4457
|
};
|
|
4385
4458
|
}
|
|
4386
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
|
+
|
|
4387
4465
|
// ../adapter-browser/src/errors.ts
|
|
4388
4466
|
var BrowserPersistenceError = class extends Error {
|
|
4389
4467
|
cause;
|
|
@@ -4566,7 +4644,7 @@ var BrowserPersistenceAdapter = class {
|
|
|
4566
4644
|
return this.#destroyed;
|
|
4567
4645
|
}
|
|
4568
4646
|
get cleanupErrors() {
|
|
4569
|
-
return this.#cleanupErrors.map((
|
|
4647
|
+
return this.#cleanupErrors.map((record2) => ({ ...record2 }));
|
|
4570
4648
|
}
|
|
4571
4649
|
async capabilities(options = {}) {
|
|
4572
4650
|
return this.#run(options.signal, async (signal) => ({
|
|
@@ -4588,20 +4666,20 @@ var BrowserPersistenceAdapter = class {
|
|
|
4588
4666
|
}
|
|
4589
4667
|
async loadDocument(options = {}) {
|
|
4590
4668
|
return this.#run(options.signal, async (signal) => {
|
|
4591
|
-
const
|
|
4669
|
+
const record2 = await this.#indexedDb.loadDocument(signal);
|
|
4592
4670
|
this.#throwIfAborted(signal);
|
|
4593
|
-
return
|
|
4671
|
+
return record2 === void 0 ? null : cloneValue2(record2);
|
|
4594
4672
|
});
|
|
4595
4673
|
}
|
|
4596
4674
|
async saveDocument(input, options = {}) {
|
|
4597
4675
|
await this.#run(options.signal, async (signal) => {
|
|
4598
|
-
const
|
|
4676
|
+
const record2 = {
|
|
4599
4677
|
snapshot: cloneValue2(input.snapshot),
|
|
4600
4678
|
metadata: cloneValue2(input.metadata ?? {}),
|
|
4601
4679
|
savedAt: this.#now()
|
|
4602
4680
|
};
|
|
4603
4681
|
this.#throwIfAborted(signal);
|
|
4604
|
-
await this.#indexedDb.saveDocument(
|
|
4682
|
+
await this.#indexedDb.saveDocument(record2, signal, {
|
|
4605
4683
|
expectedRevision: input.expectedRevision
|
|
4606
4684
|
});
|
|
4607
4685
|
});
|
|
@@ -4689,14 +4767,14 @@ var BrowserPersistenceAdapter = class {
|
|
|
4689
4767
|
];
|
|
4690
4768
|
document2.nodes.push(node);
|
|
4691
4769
|
const current = options.documentMetadata === void 0 ? await this.#indexedDb.loadDocument(signal) : void 0;
|
|
4692
|
-
const
|
|
4770
|
+
const record2 = {
|
|
4693
4771
|
snapshot: document2,
|
|
4694
4772
|
metadata: cloneValue2(options.documentMetadata ?? current?.metadata ?? {}),
|
|
4695
4773
|
savedAt: now
|
|
4696
4774
|
};
|
|
4697
4775
|
try {
|
|
4698
4776
|
await this.#indexedDb.commitAssetAndDocument(
|
|
4699
|
-
|
|
4777
|
+
record2,
|
|
4700
4778
|
entry,
|
|
4701
4779
|
{ variant: "original", blob: prepared.blob },
|
|
4702
4780
|
signal,
|
|
@@ -4742,10 +4820,11 @@ var BrowserPersistenceAdapter = class {
|
|
|
4742
4820
|
async importUrl(url, options) {
|
|
4743
4821
|
return this.commitImport(await this.prepareUrl(url, options), options);
|
|
4744
4822
|
}
|
|
4745
|
-
async putAsset(
|
|
4823
|
+
async putAsset(record2, blob, options = {}) {
|
|
4746
4824
|
return this.#run(options.signal, async (signal) => {
|
|
4747
|
-
const variant = options.variant
|
|
4748
|
-
|
|
4825
|
+
const variant = options.variant === void 0 ? "original" : options.variant;
|
|
4826
|
+
assertAssetVariant(variant);
|
|
4827
|
+
const previous = await this.#indexedDb.getAssetEntry(record2.id, signal);
|
|
4749
4828
|
const previousBinary = previous?.binaries[variant];
|
|
4750
4829
|
this.#throwIfAborted(signal);
|
|
4751
4830
|
const now = this.#now();
|
|
@@ -4754,14 +4833,14 @@ var BrowserPersistenceAdapter = class {
|
|
|
4754
4833
|
this.#throwIfAborted(signal);
|
|
4755
4834
|
let entry;
|
|
4756
4835
|
if (useOpfs && this.#opfs !== void 0) {
|
|
4757
|
-
const key = this.#storageKeyFactory(
|
|
4836
|
+
const key = this.#storageKeyFactory(record2.id, variant);
|
|
4758
4837
|
if (previousBinary?.storage.kind === "opfs" && previousBinary.storage.key === key) {
|
|
4759
4838
|
throw new BrowserStorageKeyCollisionError(key);
|
|
4760
4839
|
}
|
|
4761
4840
|
if (await this.#opfs.get(key, signal) !== void 0) {
|
|
4762
4841
|
throw new BrowserStorageKeyCollisionError(key);
|
|
4763
4842
|
}
|
|
4764
|
-
entry = this.#createEntry(cloneValue2(
|
|
4843
|
+
entry = this.#createEntry(cloneValue2(record2), variant, blob, { kind: "opfs", key }, previous, now);
|
|
4765
4844
|
await this.#opfs.put(key, blob, signal);
|
|
4766
4845
|
try {
|
|
4767
4846
|
this.#throwIfAborted(signal);
|
|
@@ -4769,23 +4848,23 @@ var BrowserPersistenceAdapter = class {
|
|
|
4769
4848
|
} catch (error) {
|
|
4770
4849
|
await this.#cleanup(
|
|
4771
4850
|
"metadata-compensation",
|
|
4772
|
-
{ assetId:
|
|
4851
|
+
{ assetId: record2.id, variant, key },
|
|
4773
4852
|
() => this.#opfs?.delete(key, new AbortController().signal)
|
|
4774
4853
|
);
|
|
4775
4854
|
throw error;
|
|
4776
4855
|
}
|
|
4777
4856
|
} else {
|
|
4778
|
-
entry = this.#createEntry(cloneValue2(
|
|
4857
|
+
entry = this.#createEntry(cloneValue2(record2), variant, blob, { kind: "indexeddb" }, previous, now);
|
|
4779
4858
|
this.#throwIfAborted(signal);
|
|
4780
4859
|
await this.#indexedDb.putAssetEntry(entry, { variant, blob }, signal);
|
|
4781
4860
|
}
|
|
4782
|
-
this.#revokeAssetLeases(
|
|
4861
|
+
this.#revokeAssetLeases(record2.id, variant);
|
|
4783
4862
|
const binary = entry.binaries[variant];
|
|
4784
4863
|
if (previousBinary?.storage.kind === "opfs" && (binary.storage.kind !== "opfs" || binary.storage.key !== previousBinary.storage.key)) {
|
|
4785
4864
|
const previousKey = previousBinary.storage.key;
|
|
4786
4865
|
await this.#cleanup(
|
|
4787
4866
|
"replace-old-opfs",
|
|
4788
|
-
{ assetId:
|
|
4867
|
+
{ assetId: record2.id, variant, key: previousKey },
|
|
4789
4868
|
() => this.#opfs?.delete(previousKey, new AbortController().signal)
|
|
4790
4869
|
);
|
|
4791
4870
|
}
|
|
@@ -4793,13 +4872,15 @@ var BrowserPersistenceAdapter = class {
|
|
|
4793
4872
|
});
|
|
4794
4873
|
}
|
|
4795
4874
|
async putDerivative(assetId, variant, blob, options = {}) {
|
|
4875
|
+
assertAssetVariant(variant);
|
|
4796
4876
|
const entry = await this.#run(options.signal, (signal) => this.#indexedDb.getAssetEntry(assetId, signal));
|
|
4797
4877
|
if (entry === void 0) throw new BrowserAssetNotFoundError(assetId);
|
|
4798
4878
|
return this.putAsset(entry.record, blob, { ...options, variant });
|
|
4799
4879
|
}
|
|
4800
4880
|
async getAsset(id, options = {}) {
|
|
4801
4881
|
return this.#run(options.signal, async (signal) => {
|
|
4802
|
-
const variant = options.variant
|
|
4882
|
+
const variant = options.variant === void 0 ? "original" : options.variant;
|
|
4883
|
+
assertAssetVariant(variant);
|
|
4803
4884
|
const entry = await this.#indexedDb.getAssetEntry(id, signal);
|
|
4804
4885
|
this.#throwIfAborted(signal);
|
|
4805
4886
|
if (entry === void 0) return null;
|
|
@@ -4844,7 +4925,8 @@ var BrowserPersistenceAdapter = class {
|
|
|
4844
4925
|
}
|
|
4845
4926
|
async leaseObjectUrl(id, options = {}) {
|
|
4846
4927
|
return this.#run(options.signal, async (signal) => {
|
|
4847
|
-
const variant = options.variant
|
|
4928
|
+
const variant = options.variant === void 0 ? "original" : options.variant;
|
|
4929
|
+
assertAssetVariant(variant);
|
|
4848
4930
|
const asset = await this.getAsset(id, { signal, variant });
|
|
4849
4931
|
this.#throwIfAborted(signal);
|
|
4850
4932
|
if (asset === null) throw new BrowserAssetNotFoundError(id);
|
|
@@ -4876,7 +4958,8 @@ var BrowserPersistenceAdapter = class {
|
|
|
4876
4958
|
}
|
|
4877
4959
|
async exportAsset(id, options = {}) {
|
|
4878
4960
|
return this.#run(options.signal, async (signal) => {
|
|
4879
|
-
const variant = options.variant
|
|
4961
|
+
const variant = options.variant === void 0 ? "original" : options.variant;
|
|
4962
|
+
assertAssetVariant(variant);
|
|
4880
4963
|
const asset = await this.getAsset(id, { signal, variant });
|
|
4881
4964
|
if (asset === null) throw new BrowserAssetNotFoundError(id);
|
|
4882
4965
|
const storedName = asset.entry.record.metadata?.fileName;
|
|
@@ -4994,10 +5077,10 @@ var BrowserPersistenceAdapter = class {
|
|
|
4994
5077
|
})).then(() => void 0);
|
|
4995
5078
|
return this.#destroyPromise;
|
|
4996
5079
|
}
|
|
4997
|
-
#createEntry(
|
|
5080
|
+
#createEntry(record2, variant, blob, storage, previous, now) {
|
|
4998
5081
|
return {
|
|
4999
|
-
id:
|
|
5000
|
-
record,
|
|
5082
|
+
id: record2.id,
|
|
5083
|
+
record: record2,
|
|
5001
5084
|
binaries: {
|
|
5002
5085
|
...previous?.binaries,
|
|
5003
5086
|
[variant]: {
|
|
@@ -5081,15 +5164,15 @@ var BrowserPersistenceAdapter = class {
|
|
|
5081
5164
|
try {
|
|
5082
5165
|
await cleanup();
|
|
5083
5166
|
} catch (error) {
|
|
5084
|
-
const
|
|
5167
|
+
const record2 = {
|
|
5085
5168
|
operation,
|
|
5086
5169
|
error,
|
|
5087
5170
|
timestamp: this.#now(),
|
|
5088
5171
|
...context
|
|
5089
5172
|
};
|
|
5090
|
-
this.#cleanupErrors.push(
|
|
5173
|
+
this.#cleanupErrors.push(record2);
|
|
5091
5174
|
try {
|
|
5092
|
-
this.#onCleanupError({ ...
|
|
5175
|
+
this.#onCleanupError({ ...record2 });
|
|
5093
5176
|
} catch (observerError) {
|
|
5094
5177
|
this.#cleanupErrors.push({
|
|
5095
5178
|
operation: "cleanup-observer",
|
|
@@ -5284,6 +5367,7 @@ var ASSET_STORE = "asset-metadata";
|
|
|
5284
5367
|
var BLOB_STORE = "asset-blobs";
|
|
5285
5368
|
var DOCUMENT_KEY = "current";
|
|
5286
5369
|
function blobKey(id, variant) {
|
|
5370
|
+
assertAssetVariant(variant);
|
|
5287
5371
|
return [id, variant];
|
|
5288
5372
|
}
|
|
5289
5373
|
function abortError2(signal) {
|
|
@@ -5329,7 +5413,7 @@ var NativeIndexedDbPort = class {
|
|
|
5329
5413
|
async loadDocument(signal) {
|
|
5330
5414
|
return this.#read(DOCUMENT_STORE, DOCUMENT_KEY, signal);
|
|
5331
5415
|
}
|
|
5332
|
-
async saveDocument(
|
|
5416
|
+
async saveDocument(record2, signal, options = {}) {
|
|
5333
5417
|
const database = await this.#open(signal);
|
|
5334
5418
|
if (signal.aborted) throw abortError2(signal);
|
|
5335
5419
|
const transaction = database.transaction(DOCUMENT_STORE, "readwrite");
|
|
@@ -5346,7 +5430,7 @@ var NativeIndexedDbPort = class {
|
|
|
5346
5430
|
throw new BrowserDocumentConflictError(options.expectedRevision, actualRevision);
|
|
5347
5431
|
}
|
|
5348
5432
|
}
|
|
5349
|
-
transaction.objectStore(DOCUMENT_STORE).put(
|
|
5433
|
+
transaction.objectStore(DOCUMENT_STORE).put(record2, DOCUMENT_KEY);
|
|
5350
5434
|
await done;
|
|
5351
5435
|
} catch (error) {
|
|
5352
5436
|
try {
|
|
@@ -5374,6 +5458,8 @@ var NativeIndexedDbPort = class {
|
|
|
5374
5458
|
return this.#read(BLOB_STORE, blobKey(id, variant), signal);
|
|
5375
5459
|
}
|
|
5376
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);
|
|
5377
5463
|
await this.#write([ASSET_STORE, BLOB_STORE], signal, (transaction) => {
|
|
5378
5464
|
transaction.objectStore(ASSET_STORE).put(entry, entry.id);
|
|
5379
5465
|
if (binaryWrite !== void 0) {
|
|
@@ -5389,6 +5475,8 @@ var NativeIndexedDbPort = class {
|
|
|
5389
5475
|
});
|
|
5390
5476
|
}
|
|
5391
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);
|
|
5392
5480
|
const database = await this.#open(signal);
|
|
5393
5481
|
if (signal.aborted) throw abortError2(signal);
|
|
5394
5482
|
const transaction = database.transaction(
|
|
@@ -5592,6 +5680,6 @@ function indexedDbPersistence(options = {}) {
|
|
|
5592
5680
|
});
|
|
5593
5681
|
}
|
|
5594
5682
|
|
|
5595
|
-
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 };
|
|
5596
5684
|
//# sourceMappingURL=browser.js.map
|
|
5597
5685
|
//# sourceMappingURL=browser.js.map
|