n1paper 0.0.0-stage → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +98 -2
- package/dist/brush-material.d.ts +53 -0
- package/dist/brush.d.ts +8 -0
- package/dist/canvas-present.d.ts +30 -0
- package/dist/color.d.ts +2 -0
- package/dist/index.d.ts +17 -0
- package/dist/layer-compositor.d.ts +59 -0
- package/dist/layer-id.d.ts +3 -0
- package/dist/layer-manager.d.ts +45 -0
- package/dist/layer.d.ts +152 -0
- package/dist/n1paper-core.d.ts +68 -0
- package/dist/n1paper-core.wasm +0 -0
- package/dist/n1paper.d.ts +298 -0
- package/dist/n1paper.js +4220 -0
- package/dist/paper-animation.d.ts +22 -0
- package/dist/paper-file/container.d.ts +31 -0
- package/dist/paper-file/layer-file.d.ts +58 -0
- package/dist/paper-file/paper-file.d.ts +20 -0
- package/dist/paper-layer.d.ts +23 -0
- package/dist/paper-layers.d.ts +25 -0
- package/dist/pointer-state.d.ts +44 -0
- package/dist/render-context.d.ts +20 -0
- package/dist/render-scheduler.d.ts +48 -0
- package/dist/runtime-types.d.ts +14 -0
- package/dist/shader-abi.d.ts +126 -0
- package/dist/shader-api.md +450 -0
- package/dist/shader-parameter-recovery.d.ts +20 -0
- package/dist/shader-stage-uniform.d.ts +4 -0
- package/dist/spatial-gpu-object.d.ts +32 -0
- package/dist/strokes-gpu-object.d.ts +31 -0
- package/dist/viewer.d.ts +33 -0
- package/dist/webgpu-renderer.d.ts +93 -0
- package/dist/webgpu-unavailable-error.d.ts +24 -0
- package/package.json +67 -4
- package/src/brush-material.ts +244 -0
- package/src/brush.ts +15 -0
- package/src/canvas-present.ts +125 -0
- package/src/color.ts +13 -0
- package/src/index.ts +63 -0
- package/src/layer-compositor.ts +218 -0
- package/src/layer-id.ts +12 -0
- package/src/layer-manager.ts +168 -0
- package/src/layer.ts +1224 -0
- package/src/n1paper-core.ts +73 -0
- package/src/n1paper.ts +1280 -0
- package/src/paper-animation.ts +28 -0
- package/src/paper-file/container.ts +171 -0
- package/src/paper-file/layer-file.ts +199 -0
- package/src/paper-file/paper-file.ts +151 -0
- package/src/paper-layer.ts +88 -0
- package/src/paper-layers.ts +33 -0
- package/src/pointer-state.ts +78 -0
- package/src/render-context.ts +65 -0
- package/src/render-scheduler.ts +188 -0
- package/src/rollerball-pen.wgsl +392 -0
- package/src/runtime-types.ts +23 -0
- package/src/shader-abi-prelude.wgsl +237 -0
- package/src/shader-abi.ts +635 -0
- package/src/shader-api.md +450 -0
- package/src/shader-parameter-recovery.ts +67 -0
- package/src/shader-stage-uniform.ts +32 -0
- package/src/spatial-gpu-object.ts +162 -0
- package/src/strokes-gpu-object.ts +313 -0
- package/src/viewer.ts +86 -0
- package/src/wasm-core.d.ts +8 -0
- package/src/webgpu-renderer.ts +849 -0
- package/src/webgpu-unavailable-error.ts +33 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { WebGPURenderer } from './webgpu-renderer.js';
|
|
2
|
+
import type { PaperShaderParameterWarning } from './shader-parameter-recovery.js';
|
|
3
|
+
import { PaperLayers } from './paper-layers.js';
|
|
4
|
+
import { PaperAnimation } from './paper-animation.js';
|
|
5
|
+
import { PaperLayer } from './paper-layer.js';
|
|
6
|
+
import type { LayerId } from './layer-id.js';
|
|
7
|
+
import type { Brush } from './brush.js';
|
|
8
|
+
import type { WasmModule } from './runtime-types.js';
|
|
9
|
+
import type { N1PointerState } from './pointer-state.js';
|
|
10
|
+
/** Appearance of one Layer of a fresh Paper. Every field is optional. */
|
|
11
|
+
export interface PaperLayerOptions {
|
|
12
|
+
/** WGSL source applied to the Layer's Brush Material; parameters use its declared defaults. */
|
|
13
|
+
shaderSource?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The fresh-Paper description. `newPaper()` accepts exactly the same shape, so
|
|
17
|
+
* creating a runtime Paper and resetting it describe one document model.
|
|
18
|
+
*/
|
|
19
|
+
export interface NewPaperOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Layers in display and compositing order. Omitted means one plain Layer
|
|
22
|
+
* using the SDK default Stroke Material.
|
|
23
|
+
*/
|
|
24
|
+
layers?: readonly PaperLayerOptions[];
|
|
25
|
+
/** Zero-based index of the active Layer; defaults to 0. */
|
|
26
|
+
activeLayerIndex?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface N1PaperOptions extends NewPaperOptions {
|
|
29
|
+
canvas: HTMLCanvasElement;
|
|
30
|
+
wasmUrl: string;
|
|
31
|
+
}
|
|
32
|
+
export interface PaperShaderVersionWarning {
|
|
33
|
+
readonly layerId: LayerId;
|
|
34
|
+
readonly fileShaderApiVersion: number;
|
|
35
|
+
readonly materialShaderApiVersion: number;
|
|
36
|
+
}
|
|
37
|
+
export interface PaperImportResult {
|
|
38
|
+
readonly shaderVersionWarnings: readonly PaperShaderVersionWarning[];
|
|
39
|
+
/** Saved parameters ignored or replaced by declared defaults during this import. */
|
|
40
|
+
readonly shaderParameterWarnings: readonly PaperShaderParameterWarning[];
|
|
41
|
+
}
|
|
42
|
+
/** The operation selected once at the beginning of a Stroke gesture. */
|
|
43
|
+
export type ToolType = 'draw' | 'erase';
|
|
44
|
+
/** A Draw or Erase input; neither operation derives its radius from Brush. */
|
|
45
|
+
export interface StrokeSample {
|
|
46
|
+
/** Normalized view-space position. */
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
/** Final world-space radius, computed by the caller. */
|
|
50
|
+
radius: number;
|
|
51
|
+
}
|
|
52
|
+
export interface N1PaperDeviceLostInfo {
|
|
53
|
+
readonly reason: GPUDeviceLostReason;
|
|
54
|
+
readonly message: string;
|
|
55
|
+
}
|
|
56
|
+
export type PaperEventType = 'contentchange' | 'viewchange' | 'devicelost' | 'frame' | 'rendererror';
|
|
57
|
+
export type PaperEvent = {
|
|
58
|
+
type: 'contentchange' | 'viewchange';
|
|
59
|
+
source: string;
|
|
60
|
+
} | {
|
|
61
|
+
type: 'frame';
|
|
62
|
+
source: 'renderer';
|
|
63
|
+
realTimeUs: number;
|
|
64
|
+
animationTimeUs: number;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'rendererror';
|
|
67
|
+
source: 'renderer';
|
|
68
|
+
error: unknown;
|
|
69
|
+
} | {
|
|
70
|
+
type: 'devicelost';
|
|
71
|
+
source: 'device';
|
|
72
|
+
reason: GPUDeviceLostReason;
|
|
73
|
+
message: string;
|
|
74
|
+
};
|
|
75
|
+
export type PaperEventListener = (event: PaperEvent) => void | Promise<void>;
|
|
76
|
+
import type { RenderFrameReason } from './render-scheduler.js';
|
|
77
|
+
/**
|
|
78
|
+
* A DOM-independent PAPER editor.
|
|
79
|
+
*
|
|
80
|
+
* While an asynchronous newPaper() or importPaperFile() replacement is pending,
|
|
81
|
+
* drawing/erasing, history/view changes, Layer mutations (including Brush/Material
|
|
82
|
+
* updates), export, and further new/import/duplicate requests are rejected.
|
|
83
|
+
* Reads, resize(), pointer input, animation frame-rate configuration, and destroy() remain
|
|
84
|
+
* available. Replacement notifications run after the new collection is fully
|
|
85
|
+
* adopted and the protection is released, so listeners can export it.
|
|
86
|
+
*/
|
|
87
|
+
export declare class N1Paper {
|
|
88
|
+
static version: string;
|
|
89
|
+
canvas: HTMLCanvasElement;
|
|
90
|
+
wasmUrl: string;
|
|
91
|
+
wasmVersion?: string;
|
|
92
|
+
renderer: WebGPURenderer | null;
|
|
93
|
+
wasmModule: WasmModule | null;
|
|
94
|
+
private _layerManager;
|
|
95
|
+
private _paperLayers;
|
|
96
|
+
private _paperLayerStates;
|
|
97
|
+
readonly layers: PaperLayers;
|
|
98
|
+
readonly animation: PaperAnimation;
|
|
99
|
+
private _eventListeners;
|
|
100
|
+
private _deviceLostInfo;
|
|
101
|
+
private readonly _renderScheduler;
|
|
102
|
+
private readonly _compositor;
|
|
103
|
+
private _pointerState;
|
|
104
|
+
private _animationFrameRate;
|
|
105
|
+
private _animationClock;
|
|
106
|
+
private readonly _document;
|
|
107
|
+
private _continuousRenderSource;
|
|
108
|
+
private readonly _logId;
|
|
109
|
+
private _renderFailureCount;
|
|
110
|
+
private _activeTool;
|
|
111
|
+
private readonly _newPaperOptions;
|
|
112
|
+
private _viewLinked;
|
|
113
|
+
private _replacement;
|
|
114
|
+
destroyed: boolean;
|
|
115
|
+
static create(options: N1PaperOptions): Promise<N1Paper>;
|
|
116
|
+
constructor(options?: Partial<N1PaperOptions>);
|
|
117
|
+
init(): Promise<void>;
|
|
118
|
+
addEventListener(type: PaperEventType, listener: PaperEventListener): void;
|
|
119
|
+
removeEventListener(type: PaperEventType, listener: PaperEventListener): void;
|
|
120
|
+
private _notifyEvent;
|
|
121
|
+
private _createDeviceLostEvent;
|
|
122
|
+
private _handleDeviceLost;
|
|
123
|
+
_dispatchEvent(type: 'contentchange' | 'viewchange', source: string): void;
|
|
124
|
+
_dispatchEvent(type: 'devicelost', info: N1PaperDeviceLostInfo): void;
|
|
125
|
+
private _notifyListeners;
|
|
126
|
+
private _createLayer;
|
|
127
|
+
/** True throughout either a Draw or an Erase gesture, even if Erase has not hit anything. */
|
|
128
|
+
get isStrokeActive(): boolean;
|
|
129
|
+
/** Configure the Paper's single animation continuous-render source. */
|
|
130
|
+
private _setAnimationFrameRate;
|
|
131
|
+
/** Freeze the animation clock and request a final static-state frame. */
|
|
132
|
+
private _pauseAnimation;
|
|
133
|
+
/** A null anchor also protects a newly selected, not-yet-rendered position. */
|
|
134
|
+
private _freezeAnimationTime;
|
|
135
|
+
/** Allow playback when FPS, visible animated Layers and page visibility permit it. */
|
|
136
|
+
private _resumeAnimation;
|
|
137
|
+
/** Set shader microseconds, preserving paused/playing state and valid old output. */
|
|
138
|
+
private _setAnimationTime;
|
|
139
|
+
/** Current animation position; frame.animationTimeUs identifies successful output. */
|
|
140
|
+
private _readAnimationTime;
|
|
141
|
+
private _getAnimationTime;
|
|
142
|
+
private _assertAnimationControl;
|
|
143
|
+
private _createPaperLayer;
|
|
144
|
+
/** A fresh Paper with no description is one plain Layer, which is active. */
|
|
145
|
+
private _createDefaultLayers;
|
|
146
|
+
/** Fills a private collection; the replacement owns failure cleanup. */
|
|
147
|
+
private _populateLayers;
|
|
148
|
+
private _beginReplacement;
|
|
149
|
+
private _assertReplacement;
|
|
150
|
+
private _finishReplacement;
|
|
151
|
+
/** Performs fallible texture updates before changing the public collection. */
|
|
152
|
+
private _adoptLayerManager;
|
|
153
|
+
/** Builds a described collection, then adopts it; nothing is replaced on build failure. */
|
|
154
|
+
private _replaceLayersFromOptions;
|
|
155
|
+
private _isCommittedLayer;
|
|
156
|
+
private _createPaperLayers;
|
|
157
|
+
/** Only committed, enabled Layers participate in animation scheduling. */
|
|
158
|
+
private _syncDynamicLayerState;
|
|
159
|
+
private invalidateFrom;
|
|
160
|
+
private _invalidateLayer;
|
|
161
|
+
/** Shader playback configuration, independent of continuous-source eligibility. */
|
|
162
|
+
private _getEffectiveAnimationRate;
|
|
163
|
+
private _canPlayAnimation;
|
|
164
|
+
private readonly _visibilityChanged;
|
|
165
|
+
private _syncContinuousRenderSource;
|
|
166
|
+
/** State transitions only: these logs are intentionally available in release builds. */
|
|
167
|
+
private _logAnimation;
|
|
168
|
+
/** Log failures 1, 2, 4, 8... so even an indefinitely failing RAF chain stays bounded. */
|
|
169
|
+
private _logRenderFailure;
|
|
170
|
+
/** Static playback and resumed visibility still need a successfully submitted stable frame. */
|
|
171
|
+
private _requestPendingStableFrame;
|
|
172
|
+
private _requestPendingPointerFrame;
|
|
173
|
+
private _getDynamicLayerCount;
|
|
174
|
+
private _invalidatePaperLayer;
|
|
175
|
+
private _getPaperLayers;
|
|
176
|
+
private _getActivePaperLayer;
|
|
177
|
+
private _requireCurrentPaperLayer;
|
|
178
|
+
private _activeRuntimeLayer;
|
|
179
|
+
private _setLayerEnabled;
|
|
180
|
+
/**
|
|
181
|
+
* Owns the state checks and effects behind PaperLayer.clear. The handle may name
|
|
182
|
+
* an inactive or disabled Layer; only content that actually changed is invalidated
|
|
183
|
+
* and reported through contentchange 'clear'.
|
|
184
|
+
*/
|
|
185
|
+
private _clearLayer;
|
|
186
|
+
private _addLayer;
|
|
187
|
+
private _duplicateLayer;
|
|
188
|
+
private _removeLayer;
|
|
189
|
+
private _moveLayer;
|
|
190
|
+
private _activateLayer;
|
|
191
|
+
get activeBrush(): Brush | null;
|
|
192
|
+
set activeBrush(brush: Brush | null);
|
|
193
|
+
setBrush(brush: Brush): void;
|
|
194
|
+
/** Begins a gesture with a fixed tool; the caller supplies the final world-space radius. */
|
|
195
|
+
beginStroke(sample: StrokeSample, type?: ToolType): void;
|
|
196
|
+
addStrokePoint(sample: StrokeSample): void;
|
|
197
|
+
/** Replaces provisional Draw data without committing or changing the active gesture. */
|
|
198
|
+
replaceActiveStroke(samples: readonly StrokeSample[]): void;
|
|
199
|
+
/** Overwrites an existing provisional Draw range; x/y are view-space, radius is world-space. */
|
|
200
|
+
updateActiveStrokeRange(startIndex: number, samples: readonly StrokeSample[]): void;
|
|
201
|
+
/** Commits the active Draw or Erase gesture; an effective commit replaces the Redo branch. */
|
|
202
|
+
endStroke(): void;
|
|
203
|
+
/**
|
|
204
|
+
* Discards the active Draw or Erase preview without modifying content or Undo/Redo.
|
|
205
|
+
* Restores the displayed content without emitting a contentchange event.
|
|
206
|
+
*/
|
|
207
|
+
cancelStroke(): void;
|
|
208
|
+
private _assertStrokeSample;
|
|
209
|
+
private _inputStroke;
|
|
210
|
+
undo(): boolean;
|
|
211
|
+
redo(): boolean;
|
|
212
|
+
/** Whether the active Layer's committed history contains an Undo step, regardless of an active gesture. */
|
|
213
|
+
get canUndo(): boolean;
|
|
214
|
+
/** Whether the active Layer's committed history contains a Redo step, regardless of an active gesture. */
|
|
215
|
+
get canRedo(): boolean;
|
|
216
|
+
get viewLinked(): boolean;
|
|
217
|
+
setViewLinked(linked: boolean): void;
|
|
218
|
+
getView(): {
|
|
219
|
+
left: number;
|
|
220
|
+
top: number;
|
|
221
|
+
zoom: number;
|
|
222
|
+
};
|
|
223
|
+
pan(dx: number, dy: number): void;
|
|
224
|
+
zoomAt(zoom: number, x: number, y: number): void;
|
|
225
|
+
transformView({ zoom, anchorX, anchorY, targetX, targetY }?: {
|
|
226
|
+
zoom?: number;
|
|
227
|
+
anchorX?: number;
|
|
228
|
+
anchorY?: number;
|
|
229
|
+
targetX?: number;
|
|
230
|
+
targetY?: number;
|
|
231
|
+
}): void;
|
|
232
|
+
_updateView(next: Partial<{
|
|
233
|
+
left: number;
|
|
234
|
+
top: number;
|
|
235
|
+
zoom: number;
|
|
236
|
+
}>): void;
|
|
237
|
+
private _updateViews;
|
|
238
|
+
private _finishViewUpdate;
|
|
239
|
+
resize(width?: number, height?: number): void;
|
|
240
|
+
/**
|
|
241
|
+
* Replaces the current Paper with a fresh one and invalidates its old Layer handles.
|
|
242
|
+
* Returns synchronously when layers are omitted; otherwise await the returned
|
|
243
|
+
* Promise before using or exporting the new Paper. Invalid options throw
|
|
244
|
+
* synchronously; a failed asynchronous build rejects without replacing the old
|
|
245
|
+
* contents or handles, and emits no replacement notifications.
|
|
246
|
+
* Shader compilation diagnostics preserve the source with fallback rendering
|
|
247
|
+
* and do not reject the build. Success emits content/view changes with source 'new'.
|
|
248
|
+
* @see N1Paper for operations allowed while replacement is pending.
|
|
249
|
+
*/
|
|
250
|
+
newPaper(options?: NewPaperOptions): void | Promise<void>;
|
|
251
|
+
/** Current Layers whose persisted shader is rendered through the default fallback pipeline. */
|
|
252
|
+
getShaderFallbackLayers(): readonly PaperLayer[];
|
|
253
|
+
exportPaperFile(): Uint8Array<ArrayBufferLike>;
|
|
254
|
+
/**
|
|
255
|
+
* Imports a PAPER file, replacing the current contents only after the whole
|
|
256
|
+
* file is ready. A rejected import preserves the old contents and Layer handles
|
|
257
|
+
* and emits no replacement notifications. Invalid saved parameters are ignored
|
|
258
|
+
* or use declared defaults and are reported in the import result. Shader
|
|
259
|
+
* compilation diagnostics keep the stored source with fallback rendering and
|
|
260
|
+
* do not reject the import.
|
|
261
|
+
* Success invalidates old handles and emits a content change with source 'load';
|
|
262
|
+
* a view change with the same source is emitted only when the view changes.
|
|
263
|
+
* @see N1Paper for operations allowed while replacement is pending.
|
|
264
|
+
*/
|
|
265
|
+
importPaperFile(input: unknown): Promise<PaperImportResult>;
|
|
266
|
+
/**
|
|
267
|
+
* Updates transient input in canvas rendering pixels. Legal during strokes or
|
|
268
|
+
* document replacement; this does not modify or persist document contents.
|
|
269
|
+
* Only committed, enabled pointer-dependent shaders request an ordinary frame.
|
|
270
|
+
*/
|
|
271
|
+
setPointerState(state: N1PointerState): void;
|
|
272
|
+
/**
|
|
273
|
+
* Ends tracking by clearing the action and tool intent, retaining the last
|
|
274
|
+
* position and device. A cleared snapshot carries no tool, so a Shader that
|
|
275
|
+
* only reads the tool has nothing to act on.
|
|
276
|
+
*/
|
|
277
|
+
clearPointerState(): void;
|
|
278
|
+
requestRender(): void;
|
|
279
|
+
/**
|
|
280
|
+
* Copies the last valid, submitted viewport without rendering or waiting for a
|
|
281
|
+
* new frame. Dirty editor state can therefore still yield the previous image.
|
|
282
|
+
* Resolves to an independently owned bitmap; the caller must close() it.
|
|
283
|
+
* Rejects when no output is available, during replacement, or after device loss
|
|
284
|
+
* or destruction. The GPU copy is submitted before this method returns.
|
|
285
|
+
*/
|
|
286
|
+
captureImage(): Promise<ImageBitmap>;
|
|
287
|
+
_renderOnce(rafTimestamp: number, _reason: RenderFrameReason): void;
|
|
288
|
+
private _requireViewer;
|
|
289
|
+
private _assertNotDestroyed;
|
|
290
|
+
private _assertNoReplacement;
|
|
291
|
+
private _assertReady;
|
|
292
|
+
_assertIdle(): void;
|
|
293
|
+
/**
|
|
294
|
+
* Releases resources and invalidates Layer handles. An in-flight replacement
|
|
295
|
+
* cannot commit after destruction and its Promise rejects. Safe to call again.
|
|
296
|
+
*/
|
|
297
|
+
destroy(): void;
|
|
298
|
+
}
|