pixiboardjs 0.1.0-alpha.1 → 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/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
- import { R as ResizeHandle, O as PixiBoardOptions, P as PixiBoard } from './types-DhluAalJ.js';
2
- export { c as BoardCapabilities, d as BoardChangeEvent, b as BoardDocument, e as BoardDocumentUpdate, f as BoardLifecycleState, B as BoardNode, g as BoardNodeCreateInput, h as BoardNodePatch, i as BoardRuntimePorts, j as BrowserEventPort, C as CaptureInput, k as CaptureResult, l as ChangeOrigin, m as CustomDisplayFactory, n as CustomDisplayObject, o as CustomNodeDataDefinition, p as CustomNodeDefinition, q as CustomNodeRenderer, r as CustomNodeRendererContext, s as CustomNodeRendererRegistry, t as CustomNodeView, u as CustomResizePolicy, v as CustomTextureLease, D as DocumentLoadOptions, w as DocumentPersistence, H as HistoryChangeEvent, J as JsonValue, N as NodeGeometry, x as NodeHandle, y as NodeHandleEventMap, z as NodeInput, E as NodeListFilter, F as NodePatch, G as NodeQuery, I as NodeResizeRequest, K as NodeTypeDefinition, L as NodeTypeRegistrationDisposer, M as NodeTypeRegistrationOptions, Q as PixiBoardRendererOptions, a as Point, S as PublicBoardEventMap, T as PublicNodeTypeDefinition, U as PublicRendererOptions, X as RenderCompleteEvent, Y as RendererApplyResult, Z as ResizeObserverPort, _ as RuntimeRenderer, $ as SelectionChangeEvent, a0 as TickerPort, a1 as TransactionOptions, a2 as TransactionOrigin, a3 as TransformBounds, a4 as TransformHandlePlacement, a5 as TransformSession, a6 as ViewportChangeEvent, V as ViewportSnapshot, W as WorldBounds } from './types-DhluAalJ.js';
1
+ import { A as AssetVariant, R as ResizeHandle, S as PixiBoardOptions, P as PixiBoard } from './types-CZ0KxRlm.js';
2
+ export { d as AssetRef, e as BoardCapabilities, f as BoardChangeEvent, b as BoardDocument, g as BoardDocumentUpdate, h as BoardLifecycleState, B as BoardNode, 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, J as JsonValue, 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, T as PixiBoardRendererOptions, a as Point, 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, V as ViewportSnapshot, W as WorldBounds, af as createPreviewSpec, ag as isDocumentPreviewType, ah as isPreviewNodeType, ai as previewStatusLabel } from './types-CZ0KxRlm.js';
3
+
4
+ /** Legacy variants or a content-addressed preview with a lowercase SHA-256 digest. */
5
+ declare function isAssetVariant(value: unknown): value is AssetVariant;
3
6
 
4
7
  declare class PixiBoardCoreError extends Error {
5
8
  constructor(message: string);
@@ -70,4 +73,4 @@ declare class BoardDestroyedError extends CapabilityError {
70
73
 
71
74
  declare function createPixiBoard(options?: PixiBoardOptions): Promise<PixiBoard>;
72
75
 
73
- export { AssetUnavailableError, BoardDestroyedError, CapabilityError, CapabilityUnavailableError, DocumentValidationError, NodeNotFoundError, NodeTypeNotRegisteredError, NodeValidationError, PermissionDeniedError, PixiBoard, PixiBoardOptions, RESIZE_HANDLES, ResizeHandle, TransactionConflictError, createPixiBoard, resizeHandleAxes, resizeHandleCursor };
76
+ export { AssetUnavailableError, AssetVariant, BoardDestroyedError, CapabilityError, CapabilityUnavailableError, DocumentValidationError, NodeNotFoundError, NodeTypeNotRegisteredError, NodeValidationError, PermissionDeniedError, PixiBoard, PixiBoardOptions, RESIZE_HANDLES, ResizeHandle, TransactionConflictError, createPixiBoard, isAssetVariant, resizeHandleAxes, resizeHandleCursor };
package/dist/index.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
  }
@@ -3869,6 +3940,6 @@ function scopeCapabilities(capabilities, instanceSignal, assertAlive) {
3869
3940
  };
3870
3941
  }
3871
3942
 
3872
- export { AssetUnavailableError, BoardDestroyedError, CapabilityError, CapabilityUnavailableError, DocumentValidationError, NodeNotFoundError, NodeTypeNotRegisteredError, NodeValidationError, PermissionDeniedError, RESIZE_HANDLES, TransactionConflictError, createPixiBoard, resizeHandleAxes, resizeHandleCursor };
3943
+ export { AssetUnavailableError, BoardDestroyedError, CapabilityError, CapabilityUnavailableError, DocumentValidationError, NodeNotFoundError, NodeTypeNotRegisteredError, NodeValidationError, PermissionDeniedError, RESIZE_HANDLES, TransactionConflictError, createPixiBoard, createPreviewSpec, isAssetVariant, isDocumentPreviewType, isPreviewNodeType, previewStatusLabel, resizeHandleAxes, resizeHandleCursor };
3873
3944
  //# sourceMappingURL=index.js.map
3874
3945
  //# sourceMappingURL=index.js.map