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/CHANGELOG.md +50 -3
- package/dist/browser.d.ts +13 -5
- package/dist/browser.js +229 -57
- package/dist/browser.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +155 -22
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +2 -2
- package/dist/node.js +155 -22
- package/dist/node.js.map +1 -1
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/{types-DnR8yhxj.d.ts → types-CZ0KxRlm.d.ts} +49 -7
- package/dist/types.d.ts +1 -1
- package/etc/pixiboardjs-browser.api.md +90 -22
- package/etc/pixiboardjs-node.api.md +87 -21
- package/etc/pixiboardjs-types.api.md +72 -21
- package/etc/pixiboardjs.api.md +87 -21
- package/package.json +4 -4
package/dist/node.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { AssetUnavailableError, BoardDestroyedError, CapabilityError, CapabilityUnavailableError, DocumentValidationError, NodeNotFoundError, NodeTypeNotRegisteredError, NodeValidationError, PermissionDeniedError, RESIZE_HANDLES, TransactionConflictError, createPixiBoard, resizeHandleAxes, resizeHandleCursor } from './index.js';
|
|
2
|
-
export {
|
|
1
|
+
export { AssetUnavailableError, BoardDestroyedError, CapabilityError, CapabilityUnavailableError, DocumentValidationError, NodeNotFoundError, NodeTypeNotRegisteredError, NodeValidationError, PermissionDeniedError, RESIZE_HANDLES, TransactionConflictError, createPixiBoard, isAssetVariant, resizeHandleAxes, resizeHandleCursor } from './index.js';
|
|
2
|
+
export { d as AssetRef, A as AssetVariant, 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, P as PixiBoard, S as PixiBoardOptions, 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, R as ResizeHandle, 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';
|
package/dist/node.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
|
}
|
|
@@ -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
|
-
|
|
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:
|
|
2986
|
-
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
|
|
3034
|
-
const
|
|
3035
|
-
const
|
|
3036
|
-
|
|
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
|
|
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:
|
|
3048
|
-
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 {
|
|
@@ -3807,6 +3940,6 @@ function scopeCapabilities(capabilities, instanceSignal, assertAlive) {
|
|
|
3807
3940
|
};
|
|
3808
3941
|
}
|
|
3809
3942
|
|
|
3810
|
-
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 };
|
|
3811
3944
|
//# sourceMappingURL=node.js.map
|
|
3812
3945
|
//# sourceMappingURL=node.js.map
|