json-canvas-viewer 3.4.3 → 4.1.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 +2 -2
- package/README.md +51 -107
- package/dist/chimp.js +1 -1
- package/dist/index.d.ts +619 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kernel/BaseModule.js +2 -0
- package/dist/kernel/BaseModule.js.map +1 -0
- package/dist/kernel/Controller.js +2 -0
- package/dist/kernel/Controller.js.map +1 -0
- package/dist/kernel/DataManager.js +2 -0
- package/dist/kernel/DataManager.js.map +1 -0
- package/dist/kernel/InteractionHandler.js +2 -0
- package/dist/kernel/InteractionHandler.js.map +1 -0
- package/dist/kernel/OverlayManager.js +2 -0
- package/dist/kernel/OverlayManager.js.map +1 -0
- package/dist/kernel/Renderer.js +2 -0
- package/dist/kernel/Renderer.js.map +1 -0
- package/dist/kernel/StyleManager.js +2 -0
- package/dist/kernel/StyleManager.js.map +1 -0
- package/dist/kernel/index.js +2 -0
- package/dist/kernel/index.js.map +1 -0
- package/dist/kernel/styles.scss.js +2 -0
- package/dist/kernel/styles.scss.js.map +1 -0
- package/dist/kernel/utilities.js +2 -0
- package/dist/kernel/utilities.js.map +1 -0
- package/dist/modules/Controls/index.js +2 -0
- package/dist/modules/Controls/index.js.map +1 -0
- package/dist/modules/Controls/styles.scss.js +2 -0
- package/dist/modules/Controls/styles.scss.js.map +1 -0
- package/dist/modules/DebugPanel/index.js +2 -0
- package/dist/modules/DebugPanel/index.js.map +1 -0
- package/dist/modules/DebugPanel/styles.scss.js +2 -0
- package/dist/modules/DebugPanel/styles.scss.js.map +1 -0
- package/dist/modules/Minimap/index.js +2 -0
- package/dist/modules/Minimap/index.js.map +1 -0
- package/dist/modules/Minimap/styles.scss.js +2 -0
- package/dist/modules/Minimap/styles.scss.js.map +1 -0
- package/dist/modules/MistouchPreventer/index.js +2 -0
- package/dist/modules/MistouchPreventer/index.js.map +1 -0
- package/dist/modules/MistouchPreventer/styles.scss.js +2 -0
- package/dist/modules/MistouchPreventer/styles.scss.js.map +1 -0
- package/dist/utilities/fetchCanvas.js +2 -0
- package/dist/utilities/fetchCanvas.js.map +1 -0
- package/dist/utilities/parser.js +2 -0
- package/dist/utilities/parser.js.map +1 -0
- package/dist/{renderToString-Dp8A-Rka.js → utilities/renderToString.js} +2 -2
- package/dist/utilities/renderToString.js.map +1 -0
- package/package.json +14 -46
- package/dist/bridges.js +0 -2
- package/dist/bridges.js.map +0 -1
- package/dist/dev.js +0 -2
- package/dist/dev.js.map +0 -1
- package/dist/index-BPBGNZi4.js +0 -2
- package/dist/index-BPBGNZi4.js.map +0 -1
- package/dist/interactionHandler-CrVH9u7P.js +0 -2
- package/dist/interactionHandler-CrVH9u7P.js.map +0 -1
- package/dist/modules.js +0 -2
- package/dist/modules.js.map +0 -1
- package/dist/react.js +0 -2
- package/dist/react.js.map +0 -1
- package/dist/renderToString-Dp8A-Rka.js.map +0 -1
- package/dist/renderer-BGA72dN1.js +0 -2
- package/dist/renderer-BGA72dN1.js.map +0 -1
- package/dist/types/bridges/reactComponent.d.ts +0 -12
- package/dist/types/bridges/renderToString.d.ts +0 -6
- package/dist/types/bridges/vitePlugin.d.ts +0 -8
- package/dist/types/bridges/vueComponent.vue.d.ts +0 -28
- package/dist/types/bridges/webpackPlugin.d.ts +0 -7
- package/dist/types/bridges.d.ts +0 -3
- package/dist/types/chimp.d.ts +0 -7
- package/dist/types/core/baseModule.d.ts +0 -19
- package/dist/types/core/controller.d.ts +0 -35
- package/dist/types/core/dataManager.d.ts +0 -59
- package/dist/types/core/declarations.d.ts +0 -105
- package/dist/types/core/index.d.ts +0 -25
- package/dist/types/core/interactionHandler.d.ts +0 -39
- package/dist/types/core/overlayManager.d.ts +0 -44
- package/dist/types/core/renderer.d.ts +0 -32
- package/dist/types/core/styleManager.d.ts +0 -49
- package/dist/types/core/utilities.d.ts +0 -25
- package/dist/types/dev.d.ts +0 -9
- package/dist/types/index.d.ts +0 -2
- package/dist/types/modules/controls/index.d.ts +0 -38
- package/dist/types/modules/debugPanel/index.d.ts +0 -9
- package/dist/types/modules/minimap/index.d.ts +0 -32
- package/dist/types/modules/mistouchPreventer/index.d.ts +0 -25
- package/dist/types/modules.d.ts +0 -4
- package/dist/vue.js +0 -2
- package/dist/vue.js.map +0 -1
- package/dist/webpackLoader.js +0 -33
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
import { Container } from '@needle-di/core';
|
|
2
|
+
import { Click, Drag, Lubricator, MultitouchPanZoom, Options as PointeractOptions, PointeractInterface, PreventDefault, WheelPanZoom } from 'pointeract';
|
|
3
|
+
|
|
4
|
+
type Coordinates = {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
};
|
|
8
|
+
type NodeBounds = {
|
|
9
|
+
minX: number;
|
|
10
|
+
minY: number;
|
|
11
|
+
maxX: number;
|
|
12
|
+
maxY: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
centerX: number;
|
|
16
|
+
centerY: number;
|
|
17
|
+
};
|
|
18
|
+
type Box = {
|
|
19
|
+
top: number;
|
|
20
|
+
right: number;
|
|
21
|
+
bottom: number;
|
|
22
|
+
left: number;
|
|
23
|
+
};
|
|
24
|
+
type General = any;
|
|
25
|
+
type GeneralArray = ReadonlyArray<General>;
|
|
26
|
+
type GeneralObject = object;
|
|
27
|
+
type GeneralConstructor = new (...args: General[]) => General;
|
|
28
|
+
type UnionToIntersection<U> = (U extends General ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
29
|
+
type GeneralModuleInput = ReadonlyArray<GeneralConstructor> | ReadonlyArray<GeneralObject>;
|
|
30
|
+
type ModuleInput<T extends GeneralConstructor> = ReadonlyArray<T> | ReadonlyArray<InstanceType<T>>;
|
|
31
|
+
type Instances<T extends GeneralModuleInput> = T extends ReadonlyArray<GeneralConstructor> ? InstanceType<T[number]> : T[number];
|
|
32
|
+
type Orchestratable<T extends GeneralModuleInput, K extends keyof Instances<T>> = UnionToIntersection<Instances<T>[K]>;
|
|
33
|
+
export type Parser = (markdown: string) => string | Promise<string>;
|
|
34
|
+
export interface JSONCanvasGroupNode extends JSONCanvasGenericNode {
|
|
35
|
+
type: "group";
|
|
36
|
+
label?: string;
|
|
37
|
+
background?: string;
|
|
38
|
+
backgroundStyle?: "cover" | "ratio" | "repeat";
|
|
39
|
+
}
|
|
40
|
+
export interface JSONCanvasFileNode extends JSONCanvasGenericNode {
|
|
41
|
+
type: "file";
|
|
42
|
+
file: string;
|
|
43
|
+
subpath?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface JSONCanvasTextNode extends JSONCanvasGenericNode {
|
|
46
|
+
type: "text";
|
|
47
|
+
text: string;
|
|
48
|
+
}
|
|
49
|
+
export interface JSONCanvasLinkNode extends JSONCanvasGenericNode {
|
|
50
|
+
type: "link";
|
|
51
|
+
url: string;
|
|
52
|
+
}
|
|
53
|
+
export type JSONCanvasNode = JSONCanvasGroupNode | JSONCanvasFileNode | JSONCanvasTextNode | JSONCanvasLinkNode;
|
|
54
|
+
export interface JSONCanvasEdge {
|
|
55
|
+
id: string;
|
|
56
|
+
fromNode: string;
|
|
57
|
+
toNode: string;
|
|
58
|
+
fromSide: "right" | "left" | "top" | "bottom";
|
|
59
|
+
toSide: "right" | "left" | "top" | "bottom";
|
|
60
|
+
toEnd?: "arrow" | "none";
|
|
61
|
+
label?: string;
|
|
62
|
+
styleAttributes?: Record<string, string>;
|
|
63
|
+
color?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface JSONCanvas {
|
|
66
|
+
nodes?: Array<JSONCanvasNode>;
|
|
67
|
+
edges?: Array<JSONCanvasEdge>;
|
|
68
|
+
}
|
|
69
|
+
export interface JSONCanvasGenericNode {
|
|
70
|
+
id: string;
|
|
71
|
+
type: "group" | "file" | "text" | "link";
|
|
72
|
+
x: number;
|
|
73
|
+
y: number;
|
|
74
|
+
width: number;
|
|
75
|
+
height: number;
|
|
76
|
+
styleAttributes?: Record<string, string>;
|
|
77
|
+
color?: string;
|
|
78
|
+
}
|
|
79
|
+
declare const _default: {
|
|
80
|
+
round: typeof round;
|
|
81
|
+
resizeCanvasForDPR: typeof resizeCanvasForDPR;
|
|
82
|
+
applyStyles: typeof applyStyles;
|
|
83
|
+
drawRoundRect: typeof drawRoundRect;
|
|
84
|
+
getAnchorCoord: typeof getAnchorCoord;
|
|
85
|
+
makeHook: typeof makeHook;
|
|
86
|
+
};
|
|
87
|
+
declare function applyStyles(container: HTMLElement | ShadowRoot, styleString: string): void;
|
|
88
|
+
declare function drawRoundRect(ctx: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, radius: number): void;
|
|
89
|
+
declare function getAnchorCoord(node: JSONCanvasNode, side: "top" | "bottom" | "left" | "right"): {
|
|
90
|
+
x: number;
|
|
91
|
+
y: number;
|
|
92
|
+
};
|
|
93
|
+
declare function resizeCanvasForDPR(canvas: HTMLCanvasElement, width: number, height: number): void;
|
|
94
|
+
declare function round(roundedNum: number, digits: number): number;
|
|
95
|
+
type MatchingFunc<Args extends GeneralArray> = (...args: Args) => void | Promise<void>;
|
|
96
|
+
export type Hook<Args extends GeneralArray = [
|
|
97
|
+
], Async extends boolean = false> = {
|
|
98
|
+
(...args: Args): Async extends true ? Promise<void> : void;
|
|
99
|
+
subs: Set<MatchingFunc<Args>>;
|
|
100
|
+
subscribe(callback: MatchingFunc<Args>): void;
|
|
101
|
+
unsubscribe(callback: MatchingFunc<Args>): void;
|
|
102
|
+
};
|
|
103
|
+
declare function makeHook<Args extends GeneralArray = [
|
|
104
|
+
], Async extends boolean = false>(reverse?: boolean, async?: Async): Hook<Args, Async>;
|
|
105
|
+
type Hook$1 = ReturnType<typeof _default.makeHook>;
|
|
106
|
+
export type GeneralModuleCtor = typeof BaseModule<General, General>;
|
|
107
|
+
export type GeneralModule = BaseModule<General, General>;
|
|
108
|
+
type ModuleInputCtor = Array<GeneralModuleCtor>;
|
|
109
|
+
type ModuleInput$1 = ModuleInput<GeneralModuleCtor>;
|
|
110
|
+
type Options<M extends ModuleInput$1> = Orchestratable<M, "options">;
|
|
111
|
+
type Augmentation<M extends ModuleInput$1> = Orchestratable<M, "_Augmentation">;
|
|
112
|
+
export type BaseArgs = ConstructorParameters<GeneralModuleCtor>;
|
|
113
|
+
export declare class BaseModule<O extends BaseOptions = BaseOptions, A extends GeneralObject = {}> {
|
|
114
|
+
protected container: Container;
|
|
115
|
+
protected augment: (aug: A) => void;
|
|
116
|
+
private static readonly _BaseModuleBrand;
|
|
117
|
+
_Augmentation: A;
|
|
118
|
+
onStart: Hook$1["subscribe"];
|
|
119
|
+
onRestart: Hook$1["subscribe"];
|
|
120
|
+
onDispose: Hook$1["subscribe"];
|
|
121
|
+
constructor(container: Container, options: GeneralObject, onStart: Hook$1, onDispose: Hook$1, onRestart: Hook$1, augment: (aug: A) => void);
|
|
122
|
+
options: O;
|
|
123
|
+
}
|
|
124
|
+
interface Augmentation$1 {
|
|
125
|
+
refresh: Controller["refresh"];
|
|
126
|
+
onRefresh: Controller["onRefresh"];
|
|
127
|
+
onResize: Controller["onResize"];
|
|
128
|
+
}
|
|
129
|
+
declare class Controller extends BaseModule<BaseOptions, Augmentation$1> {
|
|
130
|
+
private animationId;
|
|
131
|
+
private resizeAnimationId;
|
|
132
|
+
private DM;
|
|
133
|
+
private SM;
|
|
134
|
+
private resizeObserver;
|
|
135
|
+
private perFrame;
|
|
136
|
+
private lastResizeCenter;
|
|
137
|
+
onResize: Hook<[
|
|
138
|
+
number,
|
|
139
|
+
number
|
|
140
|
+
], false>;
|
|
141
|
+
onRefresh: Hook<[
|
|
142
|
+
], false>;
|
|
143
|
+
constructor(...args: BaseArgs);
|
|
144
|
+
private start;
|
|
145
|
+
private draw;
|
|
146
|
+
refresh: () => void;
|
|
147
|
+
private onResizeCallback;
|
|
148
|
+
private dispose;
|
|
149
|
+
}
|
|
150
|
+
interface Options$1 extends BaseOptions {
|
|
151
|
+
shadowed?: boolean;
|
|
152
|
+
canvas?: JSONCanvas;
|
|
153
|
+
attachmentDir?: string;
|
|
154
|
+
extraCSS?: string;
|
|
155
|
+
attachments?: Record<string, string>;
|
|
156
|
+
noAttachmentRelocation?: boolean;
|
|
157
|
+
}
|
|
158
|
+
interface Augmentation$2 {
|
|
159
|
+
resetView: DataManager["resetView"];
|
|
160
|
+
toggleFullscreen: DataManager["toggleFullscreen"];
|
|
161
|
+
onToggleFullscreen: DataManager["onToggleFullscreen"];
|
|
162
|
+
}
|
|
163
|
+
interface NodeItem {
|
|
164
|
+
ref: JSONCanvasNode;
|
|
165
|
+
box: Box;
|
|
166
|
+
fileName?: string;
|
|
167
|
+
onBeforeUnmount?: Hook;
|
|
168
|
+
onActive?: Hook;
|
|
169
|
+
onLoseActive?: Hook;
|
|
170
|
+
}
|
|
171
|
+
interface EdgeItem {
|
|
172
|
+
ref: JSONCanvasEdge;
|
|
173
|
+
box: Box;
|
|
174
|
+
controlPoints?: Array<number>;
|
|
175
|
+
}
|
|
176
|
+
type NodeMap = Record<string, NodeItem>;
|
|
177
|
+
type EdgeMap = Record<string, EdgeItem>;
|
|
178
|
+
declare class DataManager extends BaseModule<Options$1, Augmentation$2> {
|
|
179
|
+
onToggleFullscreen: Hook<[
|
|
180
|
+
"enter" | "exit"
|
|
181
|
+
], false>;
|
|
182
|
+
data: {
|
|
183
|
+
canvasData: Required<JSONCanvas>;
|
|
184
|
+
nodeMap: NodeMap;
|
|
185
|
+
edgeMap: EdgeMap;
|
|
186
|
+
canvasBaseDir: string;
|
|
187
|
+
nodeBounds: NodeBounds;
|
|
188
|
+
offsetX: number;
|
|
189
|
+
offsetY: number;
|
|
190
|
+
scale: number;
|
|
191
|
+
container: HTMLDivElement;
|
|
192
|
+
};
|
|
193
|
+
constructor(...args: BaseArgs);
|
|
194
|
+
private start;
|
|
195
|
+
private processBaseDir;
|
|
196
|
+
private getNodeBox;
|
|
197
|
+
private getEdgeBox;
|
|
198
|
+
private calculateNodeBounds;
|
|
199
|
+
toggleFullscreen: (option?: "enter" | "exit") => Promise<void>;
|
|
200
|
+
resetView: () => void;
|
|
201
|
+
middleViewer: () => {
|
|
202
|
+
x: number;
|
|
203
|
+
y: number;
|
|
204
|
+
width: number;
|
|
205
|
+
height: number;
|
|
206
|
+
};
|
|
207
|
+
private dispose;
|
|
208
|
+
}
|
|
209
|
+
type LoadedModules = [
|
|
210
|
+
Click,
|
|
211
|
+
Drag,
|
|
212
|
+
WheelPanZoom,
|
|
213
|
+
PreventDefault,
|
|
214
|
+
MultitouchPanZoom,
|
|
215
|
+
Lubricator
|
|
216
|
+
];
|
|
217
|
+
interface Options$2 extends BaseOptions {
|
|
218
|
+
pointeract?: PointeractOptions<LoadedModules>;
|
|
219
|
+
}
|
|
220
|
+
interface Augmentation$3 {
|
|
221
|
+
pan: InteractionHandler["pan"];
|
|
222
|
+
panToCoords: InteractionHandler["panToCoords"];
|
|
223
|
+
zoom: InteractionHandler["zoom"];
|
|
224
|
+
zoomToScale: InteractionHandler["zoomToScale"];
|
|
225
|
+
}
|
|
226
|
+
declare class InteractionHandler extends BaseModule<Options$2, Augmentation$3> {
|
|
227
|
+
pointeract: PointeractInterface<LoadedModules>;
|
|
228
|
+
private DM;
|
|
229
|
+
onClick: Hook<[
|
|
230
|
+
string | null
|
|
231
|
+
], false>;
|
|
232
|
+
constructor(...args: BaseArgs);
|
|
233
|
+
private start;
|
|
234
|
+
private startInteract;
|
|
235
|
+
private stopInteract;
|
|
236
|
+
private onPan;
|
|
237
|
+
private onZoom;
|
|
238
|
+
trueZoom: (_factor: number, origin: Coordinates) => void;
|
|
239
|
+
truePan: ({ x, y }: Coordinates) => void;
|
|
240
|
+
zoom: (_factor: number, origin: Coordinates) => void;
|
|
241
|
+
pan: ({ x, y }: Coordinates) => void;
|
|
242
|
+
zoomToScale: (newScale: number, origin: Coordinates) => void;
|
|
243
|
+
panToCoords: ({ x, y }: Coordinates) => void;
|
|
244
|
+
private C2C;
|
|
245
|
+
private onTrueClick;
|
|
246
|
+
private isUIControl;
|
|
247
|
+
private findNodeId;
|
|
248
|
+
private dispose;
|
|
249
|
+
}
|
|
250
|
+
interface Options$3 extends BaseOptions {
|
|
251
|
+
parser?: Parser;
|
|
252
|
+
nodeComponents?: Partial<ComponentDict>;
|
|
253
|
+
}
|
|
254
|
+
interface Augmentation$4 {
|
|
255
|
+
onNodeActive: OverlayManager["onNodeActive"];
|
|
256
|
+
onNodeLosesActive: OverlayManager["onNodeLosesActive"];
|
|
257
|
+
}
|
|
258
|
+
type NodeComponentHook<N extends JSONCanvasNode> = (container: HTMLDivElement, content: string, node: N, onBeforeUnmount: Hook, onActive: Hook, onLoseActive: Hook) => void | Promise<void>;
|
|
259
|
+
type ComponentNodeMap = {
|
|
260
|
+
text: JSONCanvasTextNode;
|
|
261
|
+
markdown: JSONCanvasFileNode;
|
|
262
|
+
image: JSONCanvasFileNode;
|
|
263
|
+
audio: JSONCanvasFileNode;
|
|
264
|
+
video: JSONCanvasFileNode;
|
|
265
|
+
link: JSONCanvasLinkNode;
|
|
266
|
+
};
|
|
267
|
+
type ComponentDict = {
|
|
268
|
+
[K in keyof ComponentNodeMap]: NodeComponentHook<ComponentNodeMap[K]>;
|
|
269
|
+
};
|
|
270
|
+
declare class OverlayManager extends BaseModule<Options$3, Augmentation$4> {
|
|
271
|
+
private _overlaysLayer;
|
|
272
|
+
private overlays;
|
|
273
|
+
private selectedId;
|
|
274
|
+
private aborted;
|
|
275
|
+
private eventListeners;
|
|
276
|
+
private DM;
|
|
277
|
+
private SM;
|
|
278
|
+
private parse;
|
|
279
|
+
private componentDict;
|
|
280
|
+
private get overlaysLayer();
|
|
281
|
+
onInteractionStart: Hook<[
|
|
282
|
+
], false>;
|
|
283
|
+
onInteractionEnd: Hook<[
|
|
284
|
+
], false>;
|
|
285
|
+
onNodeActive: Hook<[
|
|
286
|
+
JSONCanvasNode
|
|
287
|
+
], false>;
|
|
288
|
+
onNodeLosesActive: Hook<[
|
|
289
|
+
JSONCanvasNode
|
|
290
|
+
], false>;
|
|
291
|
+
constructor(...args: BaseArgs);
|
|
292
|
+
private start;
|
|
293
|
+
private restart;
|
|
294
|
+
private renderOverlays;
|
|
295
|
+
private themeChanged;
|
|
296
|
+
private select;
|
|
297
|
+
private updateOverlays;
|
|
298
|
+
private createOverlay;
|
|
299
|
+
private constructOverlay;
|
|
300
|
+
private setOverlayColor;
|
|
301
|
+
private clearOverlays;
|
|
302
|
+
private dispose;
|
|
303
|
+
}
|
|
304
|
+
interface Options$4 extends BaseOptions {
|
|
305
|
+
zoomInOptimization?: boolean;
|
|
306
|
+
}
|
|
307
|
+
declare class Renderer extends BaseModule<Options$4> {
|
|
308
|
+
private _canvas;
|
|
309
|
+
private ctx;
|
|
310
|
+
private DM;
|
|
311
|
+
private SM;
|
|
312
|
+
private zoomInOptimize;
|
|
313
|
+
private get canvas();
|
|
314
|
+
constructor(...args: BaseArgs);
|
|
315
|
+
private optimizeDPR;
|
|
316
|
+
private redraw;
|
|
317
|
+
private trueRedraw;
|
|
318
|
+
private fakeRedraw;
|
|
319
|
+
private isInside;
|
|
320
|
+
private isOutside;
|
|
321
|
+
private getCurrentViewport;
|
|
322
|
+
private drawLabelBar;
|
|
323
|
+
private drawNodeBackground;
|
|
324
|
+
private drawGroup;
|
|
325
|
+
private drawFile;
|
|
326
|
+
private drawEdge;
|
|
327
|
+
private getControlPoints;
|
|
328
|
+
private drawGridDots;
|
|
329
|
+
private drawCurvedPath;
|
|
330
|
+
private drawArrowhead;
|
|
331
|
+
private dispose;
|
|
332
|
+
}
|
|
333
|
+
type Color = {
|
|
334
|
+
border: string;
|
|
335
|
+
background: string;
|
|
336
|
+
active: string;
|
|
337
|
+
text: string;
|
|
338
|
+
card: string;
|
|
339
|
+
};
|
|
340
|
+
type ColorOptions = {
|
|
341
|
+
[K in keyof (StyleManager["definedColors"]["light"] & StyleManager["namedColors"]["light"])]?: string;
|
|
342
|
+
};
|
|
343
|
+
interface Options$5 extends BaseOptions {
|
|
344
|
+
theme?: "dark" | "light";
|
|
345
|
+
colors?: {
|
|
346
|
+
light?: ColorOptions;
|
|
347
|
+
dark?: ColorOptions;
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
interface Augmentation$5 {
|
|
351
|
+
changeTheme: StyleManager["changeTheme"];
|
|
352
|
+
onChangeTheme: StyleManager["onChangeTheme"];
|
|
353
|
+
}
|
|
354
|
+
declare class StyleManager extends BaseModule<Options$5, Augmentation$5> {
|
|
355
|
+
theme: "dark" | "light";
|
|
356
|
+
onChangeTheme: Hook<[
|
|
357
|
+
"light" | "dark"
|
|
358
|
+
], false>;
|
|
359
|
+
definedColors: {
|
|
360
|
+
light: {
|
|
361
|
+
"0": {
|
|
362
|
+
hue: number;
|
|
363
|
+
saturation: number;
|
|
364
|
+
lightness: number;
|
|
365
|
+
};
|
|
366
|
+
"1": {
|
|
367
|
+
hue: number;
|
|
368
|
+
saturation: number;
|
|
369
|
+
lightness: number;
|
|
370
|
+
};
|
|
371
|
+
"2": {
|
|
372
|
+
hue: number;
|
|
373
|
+
saturation: number;
|
|
374
|
+
lightness: number;
|
|
375
|
+
};
|
|
376
|
+
"3": {
|
|
377
|
+
hue: number;
|
|
378
|
+
saturation: number;
|
|
379
|
+
lightness: number;
|
|
380
|
+
};
|
|
381
|
+
"4": {
|
|
382
|
+
hue: number;
|
|
383
|
+
saturation: number;
|
|
384
|
+
lightness: number;
|
|
385
|
+
};
|
|
386
|
+
"5": {
|
|
387
|
+
hue: number;
|
|
388
|
+
saturation: number;
|
|
389
|
+
lightness: number;
|
|
390
|
+
};
|
|
391
|
+
"6": {
|
|
392
|
+
hue: number;
|
|
393
|
+
saturation: number;
|
|
394
|
+
lightness: number;
|
|
395
|
+
};
|
|
396
|
+
};
|
|
397
|
+
dark: {
|
|
398
|
+
"0": {
|
|
399
|
+
hue: number;
|
|
400
|
+
saturation: number;
|
|
401
|
+
lightness: number;
|
|
402
|
+
};
|
|
403
|
+
"1": {
|
|
404
|
+
hue: number;
|
|
405
|
+
saturation: number;
|
|
406
|
+
lightness: number;
|
|
407
|
+
};
|
|
408
|
+
"2": {
|
|
409
|
+
hue: number;
|
|
410
|
+
saturation: number;
|
|
411
|
+
lightness: number;
|
|
412
|
+
};
|
|
413
|
+
"3": {
|
|
414
|
+
hue: number;
|
|
415
|
+
saturation: number;
|
|
416
|
+
lightness: number;
|
|
417
|
+
};
|
|
418
|
+
"4": {
|
|
419
|
+
hue: number;
|
|
420
|
+
saturation: number;
|
|
421
|
+
lightness: number;
|
|
422
|
+
};
|
|
423
|
+
"5": {
|
|
424
|
+
hue: number;
|
|
425
|
+
saturation: number;
|
|
426
|
+
lightness: number;
|
|
427
|
+
};
|
|
428
|
+
"6": {
|
|
429
|
+
hue: number;
|
|
430
|
+
saturation: number;
|
|
431
|
+
lightness: number;
|
|
432
|
+
};
|
|
433
|
+
};
|
|
434
|
+
};
|
|
435
|
+
namedColors: {
|
|
436
|
+
light: {
|
|
437
|
+
dots: string;
|
|
438
|
+
text: string;
|
|
439
|
+
background: string;
|
|
440
|
+
"background-secondary": string;
|
|
441
|
+
shadow: string;
|
|
442
|
+
border: string;
|
|
443
|
+
};
|
|
444
|
+
dark: {
|
|
445
|
+
dots: string;
|
|
446
|
+
text: string;
|
|
447
|
+
background: string;
|
|
448
|
+
"background-secondary": string;
|
|
449
|
+
shadow: string;
|
|
450
|
+
border: string;
|
|
451
|
+
};
|
|
452
|
+
};
|
|
453
|
+
private colorCache;
|
|
454
|
+
constructor(...args: BaseArgs);
|
|
455
|
+
private hslProcessor;
|
|
456
|
+
private parseColor;
|
|
457
|
+
getColor: (colorIndex?: string) => Color;
|
|
458
|
+
getNamedColor: (name: keyof typeof StyleManager.namedColors.light) => string;
|
|
459
|
+
changeTheme: (theme?: "dark" | "light") => void;
|
|
460
|
+
}
|
|
461
|
+
export interface BaseOptions {
|
|
462
|
+
container: HTMLElement;
|
|
463
|
+
loading?: "normal" | "lazy" | "none";
|
|
464
|
+
}
|
|
465
|
+
declare const internalModules: (typeof DataManager | typeof StyleManager | typeof Controller | typeof OverlayManager | typeof InteractionHandler | typeof Renderer)[];
|
|
466
|
+
type InternalModules = typeof internalModules;
|
|
467
|
+
type AllOptions<M extends ModuleInput$1 = [
|
|
468
|
+
]> = Options<M> & Options<InternalModules>;
|
|
469
|
+
type AllAugmentation<M extends ModuleInput$1 = [
|
|
470
|
+
]> = Augmentation<M> & Augmentation<InternalModules>;
|
|
471
|
+
declare class JSONCanvasViewer<M extends ModuleInputCtor> {
|
|
472
|
+
private allModules;
|
|
473
|
+
private IO;
|
|
474
|
+
private started;
|
|
475
|
+
private disposed;
|
|
476
|
+
options: AllOptions<M>;
|
|
477
|
+
container: Container;
|
|
478
|
+
onDispose: Hook<[
|
|
479
|
+
], false>;
|
|
480
|
+
onStart: Hook<[
|
|
481
|
+
], false>;
|
|
482
|
+
onRestart: Hook<[
|
|
483
|
+
], false>;
|
|
484
|
+
constructor(options: AllOptions<M>, modules?: M);
|
|
485
|
+
private onVisibilityCheck;
|
|
486
|
+
private augment;
|
|
487
|
+
load: (options?: {
|
|
488
|
+
canvas?: JSONCanvas;
|
|
489
|
+
attachmentDir?: string;
|
|
490
|
+
attachments?: Record<string, string>;
|
|
491
|
+
}) => void;
|
|
492
|
+
dispose: () => void;
|
|
493
|
+
}
|
|
494
|
+
type JSONCanvasViewerType = new <M extends ModuleInputCtor = [
|
|
495
|
+
]>(...args: ConstructorParameters<typeof JSONCanvasViewer<M>>) => JSONCanvasViewer<M> & AllAugmentation<M>;
|
|
496
|
+
export type JSONCanvasViewerInterface<M extends ModuleInput$1 = [
|
|
497
|
+
]> = JSONCanvasViewer<never> & AllAugmentation<M>;
|
|
498
|
+
declare const _default$1: JSONCanvasViewerType;
|
|
499
|
+
declare function _default$2(options: {
|
|
500
|
+
canvas: JSONCanvas;
|
|
501
|
+
attachments?: Record<string, string>;
|
|
502
|
+
attachmentDir?: string;
|
|
503
|
+
parser?: Parser;
|
|
504
|
+
}): Promise<string>;
|
|
505
|
+
interface Options$6 extends BaseOptions {
|
|
506
|
+
controlsCollapsed?: boolean;
|
|
507
|
+
}
|
|
508
|
+
interface Augmentation$6 {
|
|
509
|
+
toggleControlsCollapse: Controls["toggleCollapse"];
|
|
510
|
+
}
|
|
511
|
+
export declare class Controls extends BaseModule<Options$6, Augmentation$6> {
|
|
512
|
+
private _controlsPanel;
|
|
513
|
+
private _toggleCollapseBtn;
|
|
514
|
+
private _toggleFullscreenBtn;
|
|
515
|
+
private _zoomOutBtn;
|
|
516
|
+
private _zoomSlider;
|
|
517
|
+
private _zoomInBtn;
|
|
518
|
+
private _resetViewBtn;
|
|
519
|
+
private DM;
|
|
520
|
+
private IH;
|
|
521
|
+
private collapsed;
|
|
522
|
+
private get controlsPanel();
|
|
523
|
+
private get toggleCollapseBtn();
|
|
524
|
+
private get toggleFullscreenBtn();
|
|
525
|
+
private get zoomOutBtn();
|
|
526
|
+
private get zoomSlider();
|
|
527
|
+
private get zoomInBtn();
|
|
528
|
+
private get resetViewBtn();
|
|
529
|
+
constructor(...args: BaseArgs);
|
|
530
|
+
toggleCollapse: () => void;
|
|
531
|
+
private zoomIn;
|
|
532
|
+
private zoomOut;
|
|
533
|
+
private slide;
|
|
534
|
+
private updateFullscreenBtn;
|
|
535
|
+
private toggleFullscreen;
|
|
536
|
+
private updateSlider;
|
|
537
|
+
private scaleToSlider;
|
|
538
|
+
private dispose;
|
|
539
|
+
}
|
|
540
|
+
export declare class DebugPanel extends BaseModule {
|
|
541
|
+
private _debugPanel;
|
|
542
|
+
private DM;
|
|
543
|
+
private get debugPanel();
|
|
544
|
+
constructor(...args: BaseArgs);
|
|
545
|
+
private update;
|
|
546
|
+
private dispose;
|
|
547
|
+
}
|
|
548
|
+
interface Options$7 extends BaseOptions {
|
|
549
|
+
minimapCollapsed?: boolean;
|
|
550
|
+
}
|
|
551
|
+
interface Augmentation$7 {
|
|
552
|
+
toggleMinimapCollapse: Minimap["toggleCollapse"];
|
|
553
|
+
}
|
|
554
|
+
export declare class Minimap extends BaseModule<Options$7, Augmentation$7> {
|
|
555
|
+
private _minimapCtx;
|
|
556
|
+
private _viewportRectangle;
|
|
557
|
+
private _minimap;
|
|
558
|
+
private _minimapContainer;
|
|
559
|
+
private _toggleMinimapBtn;
|
|
560
|
+
private minimapCache;
|
|
561
|
+
private DM;
|
|
562
|
+
private SM;
|
|
563
|
+
private collapsed;
|
|
564
|
+
private get minimap();
|
|
565
|
+
private get minimapCtx();
|
|
566
|
+
private get viewportRectangle();
|
|
567
|
+
private get minimapContainer();
|
|
568
|
+
private get toggleMinimapBtn();
|
|
569
|
+
constructor(...args: BaseArgs);
|
|
570
|
+
toggleCollapse: () => void;
|
|
571
|
+
private start;
|
|
572
|
+
private drawMinimapNode;
|
|
573
|
+
private drawMinimapEdge;
|
|
574
|
+
private updateViewportRectangle;
|
|
575
|
+
private dispose;
|
|
576
|
+
}
|
|
577
|
+
interface Options$8 extends BaseOptions {
|
|
578
|
+
preventMistouchAtStart?: boolean;
|
|
579
|
+
mistouchPreventerBannerText?: string;
|
|
580
|
+
}
|
|
581
|
+
interface Augmentation$8 {
|
|
582
|
+
startMistouchPrevention: MistouchPreventer["startPrevention"];
|
|
583
|
+
endMistouchPrevention: MistouchPreventer["endPrevention"];
|
|
584
|
+
}
|
|
585
|
+
export declare class MistouchPreventer extends BaseModule<Options$8, Augmentation$8> {
|
|
586
|
+
private _preventionContainer;
|
|
587
|
+
private preventMt;
|
|
588
|
+
private DM;
|
|
589
|
+
private preventMistouch;
|
|
590
|
+
private get preventionContainer();
|
|
591
|
+
constructor(...args: BaseArgs);
|
|
592
|
+
private onPointerDown;
|
|
593
|
+
private onPointerMove;
|
|
594
|
+
private onPointerUp;
|
|
595
|
+
startPrevention: () => void;
|
|
596
|
+
endPrevention: () => void;
|
|
597
|
+
private dispose;
|
|
598
|
+
}
|
|
599
|
+
declare function _default$3(path: `${string}.canvas` | `${string}.json`): Promise<JSONCanvas>;
|
|
600
|
+
declare function _default$4(markdown: string): Promise<string>;
|
|
601
|
+
export declare const internal: {
|
|
602
|
+
Controller: typeof Controller;
|
|
603
|
+
DataManager: typeof DataManager;
|
|
604
|
+
InteractionHandler: typeof InteractionHandler;
|
|
605
|
+
OverlayManager: typeof OverlayManager;
|
|
606
|
+
Renderer: typeof Renderer;
|
|
607
|
+
StyleManager: typeof StyleManager;
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
export {
|
|
611
|
+
AllOptions as Options,
|
|
612
|
+
_default as canvasUtils,
|
|
613
|
+
_default$1 as JSONCanvasViewer,
|
|
614
|
+
_default$2 as renderToString,
|
|
615
|
+
_default$3 as fetchCanvas,
|
|
616
|
+
_default$4 as parser,
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{default as e}from"./kernel/index.js";import{default as r}from"./utilities/renderToString.js";import{BaseModule as a}from"./kernel/BaseModule.js";import{default as t}from"./modules/Controls/index.js";import{default as s}from"./modules/DebugPanel/index.js";import{default as o}from"./modules/Minimap/index.js";import{default as n}from"./modules/MistouchPreventer/index.js";import{default as i}from"./kernel/utilities.js";import{default as l}from"./utilities/fetchCanvas.js";import{default as m}from"./utilities/parser.js";import f from"./kernel/Controller.js";import d from"./kernel/DataManager.js";import u from"./kernel/InteractionHandler.js";import p from"./kernel/OverlayManager.js";import j from"./kernel/Renderer.js";import M from"./kernel/StyleManager.js";const g={Controller:f,DataManager:d,InteractionHandler:u,OverlayManager:p,Renderer:j,StyleManager:M};export{a as BaseModule,t as Controls,s as DebugPanel,e as JSONCanvasViewer,o as Minimap,n as MistouchPreventer,i as canvasUtils,l as fetchCanvas,g as internal,m as parser,r as renderToString};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["export {\n\tdefault as JSONCanvasViewer,\n\ttype JSONCanvasViewerInterface,\n\ttype AllOptions as Options,\n} from '$';\nexport { default as renderToString } from '@/utilities/renderToString.ts';\nexport {\n\ttype GeneralModule,\n\ttype GeneralModuleCtor,\n\ttype BaseArgs,\n\tBaseModule,\n} from '$/BaseModule';\nexport type { BaseOptions } from '$';\nexport { default as Controls } from '@/modules/Controls';\nexport { default as DebugPanel } from '@/modules/DebugPanel';\nexport { default as Minimap } from '@/modules/Minimap';\nexport { default as MistouchPreventer } from '@/modules/MistouchPreventer';\nexport { default as canvasUtils, type Hook } from '$/utilities';\nexport { default as fetchCanvas } from '@/utilities/fetchCanvas';\nexport { default as parser } from '@/utilities/parser';\nexport type * from '@repo/shared';\n\nimport Controller from '$/Controller';\nimport DataManager from '$/DataManager';\nimport InteractionHandler from '$/InteractionHandler';\nimport OverlayManager from '$/OverlayManager';\nimport Renderer from '$/Renderer';\nimport StyleManager from '$/StyleManager';\nexport const internal = {\n\tController,\n\tDataManager,\n\tInteractionHandler,\n\tOverlayManager,\n\tRenderer,\n\tStyleManager,\n};\n\n// must import env.d.ts, otherwise dts bundler will throw at '*.scss?inline'\nimport './env.d.ts';\n"],"names":["internal","Controller","DataManager","InteractionHandler","OverlayManager","Renderer","StyleManager"],"mappings":"gwBA4BO,MAAMA,EAAW,CACvBC,aACAC,cACAC,qBACAC,iBACAC,WACAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseModule.js","sources":["../../src/kernel/BaseModule.ts"],"sourcesContent":["import type { BaseOptions } from '$';\nimport type { General, GeneralObject, ModuleInput as MI, Orchestratable } from '$/types';\nimport type utilities from '$/utilities';\nimport type { Container } from '@needle-di/core';\n\ntype Hook = ReturnType<typeof utilities.makeHook>;\n\nexport type GeneralModuleCtor = typeof BaseModule<General, General>;\nexport type GeneralModule = BaseModule<General, General>;\n\nexport type ModuleInputCtor = Array<GeneralModuleCtor>;\nexport type ModuleInput = MI<GeneralModuleCtor>;\nexport type Options<M extends ModuleInput> = Orchestratable<M, 'options'>;\nexport type Augmentation<M extends ModuleInput> = Orchestratable<M, '_Augmentation'>;\n\nexport type BaseArgs = ConstructorParameters<GeneralModuleCtor>;\n\nexport class BaseModule<O extends BaseOptions = BaseOptions, A extends GeneralObject = {}> {\n\t// https://github.com/timocov/dts-bundle-generator/issues/360\n\tdeclare private static readonly _BaseModuleBrand: unique symbol; // Nominal marker\n\tdeclare _Augmentation: A;\n\tonStart: Hook['subscribe'];\n\tonRestart: Hook['subscribe'];\n\tonDispose: Hook['subscribe'];\n\tconstructor(\n\t\tprotected container: Container,\n\t\toptions: GeneralObject,\n\t\tonStart: Hook,\n\t\tonDispose: Hook,\n\t\tonRestart: Hook,\n\t\tprotected augment: (aug: A) => void,\n\t) {\n\t\tthis.options = options as O;\n\t\tthis.onStart = onStart.subscribe;\n\t\tthis.onDispose = onDispose.subscribe;\n\t\tthis.onRestart = onRestart.subscribe;\n\t}\n\toptions: O;\n}\n"],"names":["BaseModule","constructor","container","options","onStart","onDispose","onRestart","augment","this","subscribe"],"mappings":"AAiBO,MAAMA,EAOZ,WAAAC,CACWC,EACVC,EACAC,EACAC,EACAC,EACUC,GALAC,KAAAN,UAAAA,EAKAM,KAAAD,QAAAA,EAEVC,KAAKL,QAAUA,EACfK,KAAKJ,QAAUA,EAAQK,UACvBD,KAAKH,UAAYA,EAAUI,UAC3BD,KAAKF,UAAYA,EAAUG,SAC5B,CAfAL,QACAE,UACAD,UAcAF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{BaseModule as e}from"./BaseModule.js";import s from"./DataManager.js";import t from"./StyleManager.js";import i from"./utilities.js";class a extends e{animationId=null;resizeAnimationId=null;DM;SM;resizeObserver;perFrame={lastScale:1,lastOffsets:{x:0,y:0}};lastResizeCenter={x:null,y:null};onResize=i.makeHook();onRefresh=i.makeHook();constructor(...e){super(...e),this.DM=this.container.get(s),this.SM=this.container.get(t),this.resizeObserver=new ResizeObserver(this.onResizeCallback),this.SM.onChangeTheme.subscribe(this.refresh),this.augment({refresh:this.refresh,onRefresh:this.onRefresh,onResize:this.onResize}),this.onStart(this.start),this.onRestart(this.refresh),this.onDispose(this.dispose)}start=()=>{this.resizeObserver.observe(this.DM.data.container),this.animationId=requestAnimationFrame(this.draw)};draw=()=>{this.perFrame.lastScale===this.DM.data.scale&&this.perFrame.lastOffsets.x===this.DM.data.offsetX&&this.perFrame.lastOffsets.y===this.DM.data.offsetY||this.refresh(),this.animationId=requestAnimationFrame(this.draw)};refresh=()=>{this.perFrame={lastScale:this.DM.data.scale,lastOffsets:{x:this.DM.data.offsetX,y:this.DM.data.offsetY}},this.onRefresh()};onResizeCallback=()=>{this.resizeAnimationId=requestAnimationFrame(()=>{const e=this.DM.middleViewer();this.lastResizeCenter.x&&this.lastResizeCenter.y&&(this.DM.data.offsetX=this.DM.data.offsetX+e.x-this.lastResizeCenter.x,this.DM.data.offsetY=this.DM.data.offsetY+e.y-this.lastResizeCenter.y),this.lastResizeCenter.x=e.x,this.lastResizeCenter.y=e.y,this.onResize(e.width,e.height),this.refresh()})};dispose=()=>{this.animationId&&cancelAnimationFrame(this.animationId),this.resizeAnimationId&&cancelAnimationFrame(this.resizeAnimationId),this.resizeObserver.disconnect()}}export{a as default};
|
|
2
|
+
//# sourceMappingURL=Controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Controller.js","sources":["../../src/kernel/Controller.ts"],"sourcesContent":["import type { BaseOptions } from '$';\nimport { type BaseArgs, BaseModule } from '$/BaseModule';\nimport DataManager from '$/DataManager';\nimport StyleManager from '$/StyleManager';\nimport utilities from '$/utilities';\n\ninterface Augmentation {\n\trefresh: Controller['refresh'];\n\tonRefresh: Controller['onRefresh'];\n\tonResize: Controller['onResize'];\n}\n\nexport default class Controller extends BaseModule<BaseOptions, Augmentation> {\n\tprivate animationId: null | number = null;\n\tprivate resizeAnimationId: null | number = null;\n\tprivate DM: DataManager;\n\tprivate SM: StyleManager;\n\tprivate resizeObserver: ResizeObserver;\n\tprivate perFrame: {\n\t\tlastScale: number;\n\t\tlastOffsets: { x: number; y: number };\n\t} = {\n\t\tlastScale: 1,\n\t\tlastOffsets: { x: 0, y: 0 },\n\t};\n\tprivate lastResizeCenter: {\n\t\tx: null | number;\n\t\ty: null | number;\n\t} = {\n\t\tx: null,\n\t\ty: null,\n\t};\n\n\tonResize = utilities.makeHook<[number, number]>();\n\tonRefresh = utilities.makeHook();\n\n\tconstructor(...args: BaseArgs) {\n\t\tsuper(...args);\n\t\tthis.DM = this.container.get(DataManager);\n\t\tthis.SM = this.container.get(StyleManager);\n\t\tthis.resizeObserver = new ResizeObserver(this.onResizeCallback);\n\t\tthis.SM.onChangeTheme.subscribe(this.refresh);\n\t\tthis.augment({\n\t\t\trefresh: this.refresh,\n\t\t\tonRefresh: this.onRefresh,\n\t\t\tonResize: this.onResize,\n\t\t});\n\t\tthis.onStart(this.start);\n\t\tthis.onRestart(this.refresh);\n\t\tthis.onDispose(this.dispose);\n\t}\n\n\tprivate start = () => {\n\t\tthis.resizeObserver.observe(this.DM.data.container);\n\t\tthis.animationId = requestAnimationFrame(this.draw);\n\t};\n\n\tprivate draw = () => {\n\t\tif (\n\t\t\tthis.perFrame.lastScale !== this.DM.data.scale ||\n\t\t\tthis.perFrame.lastOffsets.x !== this.DM.data.offsetX ||\n\t\t\tthis.perFrame.lastOffsets.y !== this.DM.data.offsetY\n\t\t)\n\t\t\tthis.refresh();\n\t\tthis.animationId = requestAnimationFrame(this.draw);\n\t};\n\n\trefresh = () => {\n\t\tthis.perFrame = {\n\t\t\tlastScale: this.DM.data.scale,\n\t\t\tlastOffsets: { x: this.DM.data.offsetX, y: this.DM.data.offsetY },\n\t\t};\n\t\tthis.onRefresh();\n\t};\n\n\tprivate onResizeCallback = () => {\n\t\tthis.resizeAnimationId = requestAnimationFrame(() => {\n\t\t\tconst center = this.DM.middleViewer();\n\t\t\tif (this.lastResizeCenter.x && this.lastResizeCenter.y) {\n\t\t\t\tthis.DM.data.offsetX = this.DM.data.offsetX + center.x - this.lastResizeCenter.x;\n\t\t\t\tthis.DM.data.offsetY = this.DM.data.offsetY + center.y - this.lastResizeCenter.y;\n\t\t\t}\n\t\t\tthis.lastResizeCenter.x = center.x;\n\t\t\tthis.lastResizeCenter.y = center.y;\n\t\t\tthis.onResize(center.width, center.height);\n\t\t\tthis.refresh();\n\t\t});\n\t};\n\n\tprivate dispose = () => {\n\t\tif (this.animationId) cancelAnimationFrame(this.animationId);\n\t\tif (this.resizeAnimationId) cancelAnimationFrame(this.resizeAnimationId);\n\t\tthis.resizeObserver.disconnect();\n\t};\n}\n"],"names":["Controller","BaseModule","animationId","resizeAnimationId","DM","SM","resizeObserver","perFrame","lastScale","lastOffsets","x","y","lastResizeCenter","onResize","utilities","makeHook","onRefresh","constructor","args","super","this","container","get","DataManager","StyleManager","ResizeObserver","onResizeCallback","onChangeTheme","subscribe","refresh","augment","onStart","start","onRestart","onDispose","dispose","observe","data","requestAnimationFrame","draw","scale","offsetX","offsetY","center","middleViewer","width","height","cancelAnimationFrame","disconnect"],"mappings":"4IAYA,MAAqBA,UAAmBC,EAC/BC,YAA6B,KAC7BC,kBAAmC,KACnCC,GACAC,GACAC,eACAC,SAGJ,CACHC,UAAW,EACXC,YAAa,CAAEC,EAAG,EAAGC,EAAG,IAEjBC,iBAGJ,CACHF,EAAG,KACHC,EAAG,MAGJE,SAAWC,EAAUC,WACrBC,UAAYF,EAAUC,WAEtB,WAAAE,IAAeC,GACdC,SAASD,GACTE,KAAKhB,GAAKgB,KAAKC,UAAUC,IAAIC,GAC7BH,KAAKf,GAAKe,KAAKC,UAAUC,IAAIE,GAC7BJ,KAAKd,eAAiB,IAAImB,eAAeL,KAAKM,kBAC9CN,KAAKf,GAAGsB,cAAcC,UAAUR,KAAKS,SACrCT,KAAKU,QAAQ,CACZD,QAAST,KAAKS,QACdb,UAAWI,KAAKJ,UAChBH,SAAUO,KAAKP,WAEhBO,KAAKW,QAAQX,KAAKY,OAClBZ,KAAKa,UAAUb,KAAKS,SACpBT,KAAKc,UAAUd,KAAKe,QACrB,CAEQH,MAAQ,KACfZ,KAAKd,eAAe8B,QAAQhB,KAAKhB,GAAGiC,KAAKhB,WACzCD,KAAKlB,YAAcoC,sBAAsBlB,KAAKmB,OAGvCA,KAAO,KAEbnB,KAAKb,SAASC,YAAcY,KAAKhB,GAAGiC,KAAKG,OACzCpB,KAAKb,SAASE,YAAYC,IAAMU,KAAKhB,GAAGiC,KAAKI,SAC7CrB,KAAKb,SAASE,YAAYE,IAAMS,KAAKhB,GAAGiC,KAAKK,SAE7CtB,KAAKS,UACNT,KAAKlB,YAAcoC,sBAAsBlB,KAAKmB,OAG/CV,QAAU,KACTT,KAAKb,SAAW,CACfC,UAAWY,KAAKhB,GAAGiC,KAAKG,MACxB/B,YAAa,CAAEC,EAAGU,KAAKhB,GAAGiC,KAAKI,QAAS9B,EAAGS,KAAKhB,GAAGiC,KAAKK,UAEzDtB,KAAKJ,aAGEU,iBAAmB,KAC1BN,KAAKjB,kBAAoBmC,sBAAsB,KAC9C,MAAMK,EAASvB,KAAKhB,GAAGwC,eACnBxB,KAAKR,iBAAiBF,GAAKU,KAAKR,iBAAiBD,IACpDS,KAAKhB,GAAGiC,KAAKI,QAAUrB,KAAKhB,GAAGiC,KAAKI,QAAUE,EAAOjC,EAAIU,KAAKR,iBAAiBF,EAC/EU,KAAKhB,GAAGiC,KAAKK,QAAUtB,KAAKhB,GAAGiC,KAAKK,QAAUC,EAAOhC,EAAIS,KAAKR,iBAAiBD,GAEhFS,KAAKR,iBAAiBF,EAAIiC,EAAOjC,EACjCU,KAAKR,iBAAiBD,EAAIgC,EAAOhC,EACjCS,KAAKP,SAAS8B,EAAOE,MAAOF,EAAOG,QACnC1B,KAAKS,aAICM,QAAU,KACbf,KAAKlB,aAAa6C,qBAAqB3B,KAAKlB,aAC5CkB,KAAKjB,mBAAmB4C,qBAAqB3B,KAAKjB,mBACtDiB,KAAKd,eAAe0C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{BaseModule as t}from"./BaseModule.js";import e from"./styles.scss.js";import s from"./utilities.js";class a extends t{onToggleFullscreen=s.makeHook();data={canvasData:{nodes:[],edges:[]},nodeMap:{},edgeMap:{},canvasBaseDir:"./",nodeBounds:{maxX:0,maxY:0,minX:0,minY:0,width:0,height:0,centerX:0,centerY:0},offsetX:0,offsetY:0,scale:1,container:document.createElement("div")};constructor(...t){super(...t);const a=this.options.container;for(;a.firstElementChild;)a.firstElementChild.remove();a.innerHTML="";const i=this.options.shadowed?a.attachShadow({mode:"open"}):a;s.applyStyles(i,e+this.options.extraCSS),this.data.container.classList.add("JSON-Canvas-Viewer"),i.appendChild(this.data.container),this.augment({resetView:this.resetView,toggleFullscreen:this.toggleFullscreen,onToggleFullscreen:this.onToggleFullscreen}),this.onStart(this.start),this.onRestart(this.start),this.onDispose(this.dispose)}start=()=>{const t=Object.assign({nodes:[],edges:[]},this.options.canvas);Object.assign(this.data,{canvasData:t,nodeMap:{},edgeMap:{},canvasBaseDir:this.processBaseDir(this.options.attachmentDir),nodeBounds:this.calculateNodeBounds(t),offsetX:0,offsetY:0,scale:1}),this.data.canvasData.nodes.forEach(t=>{const e={ref:t,box:this.getNodeBox(t)};if(this.data.nodeMap[t.id]=e,"file"===t.type){const s=t.file.split("/").pop()??"";if(e.fileName=s,!t.file.startsWith("http://")&&!t.file.startsWith("https://")){const e=this.options.attachments?.[s];e?t.file=e:this.options.noAttachmentRelocation||(t.file=this.data.canvasBaseDir+s)}}}),this.data.canvasData.edges.forEach(t=>{this.data.edgeMap[t.id]={ref:t,box:this.getEdgeBox(t)}}),this.resetView()};processBaseDir=t=>{if(!t)return"./";const e=t?.slice(-1);return"/"===e?t:`${t}/`};getNodeBox=t=>({left:t.x,top:"file"===t.type||"group"===t.type?t.y-40:t.y,right:t.width+t.x,bottom:t.y+t.height});getEdgeBox=t=>{const e=this.data.nodeMap,a=e[t.fromNode].ref,i=e[t.toNode].ref,o=s.getAnchorCoord(a,t.fromSide),n=s.getAnchorCoord(i,t.toSide),h=Math.min(o.x,n.x),r=Math.min(o.y,n.y),c=Math.max(o.x,n.x),d=Math.max(o.y,n.y),l=c-h,f=d-r,m=Math.min(l,f),g=0===m?1:m,p=Math.max(l,f),u=10*Math.log2(p/g);return{left:h-u,top:r-u,right:c+u,bottom:d+u}};calculateNodeBounds(t){let e=1/0,s=1/0,a=-1/0,i=-1/0;t.nodes.forEach(t=>{e=Math.min(e,t.x),s=Math.min(s,t.y),a=Math.max(a,t.x+t.width),i=Math.max(i,t.y+t.height)});const o=a-e,n=i-s;return{minX:e,minY:s,maxX:a,maxY:i,width:o,height:n,centerX:e+o/2,centerY:s+n/2}}toggleFullscreen=async t=>{document.fullscreenElement||t&&"enter"!==t?!document.fullscreenElement||t&&"exit"!==t||(await document.exitFullscreen(),this.onToggleFullscreen("exit")):(await this.data.container.requestFullscreen(),this.onToggleFullscreen("enter"))};resetView=()=>{const t=this.data.nodeBounds,e=this.data.container;if(!t||!e)return;const s=t.width+200,a=t.height+200,i=e.clientWidth,o=e.clientHeight,n=i/s,h=o/a,r=Math.round(1e3*Math.min(n,h))/1e3,c={scale:r,offsetX:i/2-t.centerX*r,offsetY:o/2-t.centerY*r};this.data.offsetX=c.offsetX,this.data.offsetY=c.offsetY,this.data.scale=c.scale};middleViewer=()=>{const t=this.data.container;return{x:t.clientWidth/2,y:t.clientHeight/2,width:t.clientWidth,height:t.clientHeight}};dispose=()=>{this.data.container.remove()}}export{a as default};
|
|
2
|
+
//# sourceMappingURL=DataManager.js.map
|