json-canvas-viewer 3.2.0 → 3.2.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.
@@ -1,12 +1,11 @@
1
1
  import type { Container } from '@needle-di/core';
2
- import type { DefaultOptions, Empty, GeneralFunction, GeneralObject, Utilities } from './declarations';
3
- export type BaseArgs = [Container, GeneralObject, Utilities];
2
+ import type { DefaultOptions, Empty, GeneralFunction, GeneralObject } from './declarations';
3
+ export type BaseArgs = [Container, GeneralObject];
4
4
  export type GeneralModuleCtor = typeof BaseModule<GeneralObject>;
5
5
  export type GeneralModule = InstanceType<GeneralModuleCtor>;
6
6
  export declare class BaseModule<O extends GeneralObject = Empty> {
7
7
  protected container: Container;
8
- protected utilities: Utilities;
9
- constructor(container: Container, options: GeneralObject, utilities: Utilities);
8
+ constructor(container: Container, options: GeneralObject);
10
9
  options: DefaultOptions & O;
11
10
  dispose?: GeneralFunction;
12
11
  }
@@ -12,11 +12,14 @@ type InternalModules = [
12
12
  typeof InteractionHandler,
13
13
  typeof Renderer
14
14
  ];
15
- export declare class JSONCanvasViewer<M extends ModuleInput = []> {
15
+ export default class JSONCanvasViewer<M extends ModuleInput = []> {
16
16
  private options;
17
17
  private allModules;
18
+ private IO;
18
19
  container: Container;
19
20
  constructor(options: Options<[...InternalModules, ...M]>, modules?: M);
21
+ private load;
22
+ private onVisibilityCheck;
20
23
  dispose: () => void;
21
24
  }
22
25
  export {};
@@ -6,6 +6,7 @@ export default class Controller extends BaseModule<Options> {
6
6
  private animationId;
7
7
  private resizeAnimationId;
8
8
  private DM;
9
+ private resizeObserver;
9
10
  private perFrame;
10
11
  private lastResizeCenter;
11
12
  hooks: {
@@ -27,7 +28,6 @@ export default class Controller extends BaseModule<Options> {
27
28
  private draw;
28
29
  private refresh;
29
30
  private onResize;
30
- private resizeObserver;
31
31
  dispose: () => void;
32
32
  }
33
33
  export {};
@@ -20,7 +20,7 @@ export default class Controls extends BaseModule<Options> {
20
20
  private get zoomInBtn();
21
21
  private get resetViewBtn();
22
22
  constructor(...args: BaseArgs);
23
- toggleCollapse: () => boolean;
23
+ toggleCollapse: () => void;
24
24
  private zoomIn;
25
25
  private zoomOut;
26
26
  private slide;
@@ -1,5 +1,5 @@
1
- import type { Coordinates, NodeBounds } from './declarations';
2
1
  import { BaseModule } from './baseModule';
2
+ import type { Coordinates, NodeBounds } from './declarations';
3
3
  export default class DataManager extends BaseModule {
4
4
  private spatialGrid;
5
5
  hooks: {
@@ -17,7 +17,7 @@ export default class DataManager extends BaseModule {
17
17
  };
18
18
  };
19
19
  data: {
20
- canvasData: JSONCanvas;
20
+ canvasData: Required<JSONCanvas>;
21
21
  nodeMap: Record<string, JSONCanvasNode>;
22
22
  canvasBaseDir: string;
23
23
  nodeBounds: NodeBounds;
@@ -27,7 +27,6 @@ export default class DataManager extends BaseModule {
27
27
  container: HTMLDivElement;
28
28
  };
29
29
  loadCanvas: () => Promise<void>;
30
- private resolvePath;
31
30
  findNodeAt: (screenCoords: Coordinates) => JSONCanvasNode | null;
32
31
  private judgeInteract;
33
32
  private calculateNodeBounds;
@@ -1,23 +1,40 @@
1
- import type { GeneralModuleCtor } from './baseModule';
2
- import type utilities from './utilities';
1
+ import type { BaseModule, GeneralModule, GeneralModuleCtor } from './baseModule';
2
+ import type Controller from './controller';
3
+ import type DataManager from './dataManager';
4
+ import type InteractionHandler from './interactionHandler';
5
+ import type OverlayManager from './overlayManager';
6
+ import type Renderer from './renderer';
3
7
  declare global {
4
- interface JSONCanvasNode {
8
+ interface JSONCanvasGenericNode {
5
9
  id: string;
6
10
  type: 'group' | 'file' | 'text' | 'link';
7
11
  x: number;
8
12
  y: number;
9
13
  width: number;
10
14
  height: number;
15
+ styleAttributes?: Record<string, string>;
16
+ color?: string;
17
+ }
18
+ interface JSONCanvasGroupNode extends JSONCanvasGenericNode {
19
+ type: 'group';
11
20
  label?: string;
12
21
  background?: string;
13
22
  backgroundStyle?: 'cover' | 'ratio' | 'repeat';
14
- styleAttributes?: Record<string, string>;
15
- color?: string;
16
- text?: string;
17
- file?: string;
23
+ }
24
+ interface JSONCanvasFileNode extends JSONCanvasGenericNode {
25
+ type: 'file';
26
+ file: string;
18
27
  subpath?: string;
19
- url?: string;
20
28
  }
29
+ interface JSONCanvasTextNode extends JSONCanvasGenericNode {
30
+ type: 'text';
31
+ text: string;
32
+ }
33
+ interface JSONCanvasLinkNode extends JSONCanvasGenericNode {
34
+ type: 'link';
35
+ url: string;
36
+ }
37
+ type JSONCanvasNode = JSONCanvasGroupNode | JSONCanvasFileNode | JSONCanvasTextNode | JSONCanvasLinkNode;
21
38
  interface JSONCanvasEdge {
22
39
  id: string;
23
40
  fromNode: string;
@@ -30,12 +47,12 @@ declare global {
30
47
  color?: string;
31
48
  }
32
49
  interface JSONCanvas {
33
- nodes: Array<JSONCanvasNode>;
34
- edges: Array<JSONCanvasEdge>;
35
- metadata: {
36
- version: string;
37
- frontmatter: Record<string, string>;
38
- };
50
+ nodes?: Array<JSONCanvasNode>;
51
+ edges?: Array<JSONCanvasEdge>;
52
+ }
53
+ module '*.scss?inline' {
54
+ const content: string;
55
+ export default content;
39
56
  }
40
57
  }
41
58
  export type Coordinates = {
@@ -72,8 +89,12 @@ type AllModuleInstances<T extends ModuleInput> = InstanceType<T[number]>;
72
89
  export type DefaultOptions = {
73
90
  container: HTMLElement;
74
91
  canvasPath: string;
92
+ lazyLoad?: boolean;
75
93
  };
76
- export type Utilities = typeof utilities;
77
94
  export type ModuleInput = Array<GeneralModuleCtor>;
78
- export type Options<T extends ModuleInput> = Omit<UnionToIntersection<AllModuleInstances<T>['options']>, keyof DefaultOptions> & DefaultOptions;
95
+ export type Options<T extends ModuleInput = []> = Omit<UnionToIntersection<AllModuleInstances<T>['options']>, keyof DefaultOptions> & DefaultOptions;
96
+ type Ctors<T extends Array<BaseModule> | BaseModule> = T extends Array<BaseModule> ? {
97
+ [K in keyof T]: new (...args: GeneralArguments) => T[K];
98
+ } : [new (...args: GeneralArguments) => T];
99
+ export type UserOptions<T extends Array<GeneralModule> = []> = Options<Ctors<[Controller, InteractionHandler, DataManager, OverlayManager, Renderer, ...T]>>;
79
100
  export {};
@@ -1,9 +1,12 @@
1
1
  export { type BaseArgs, BaseModule } from './baseModule';
2
- export { JSONCanvasViewer } from './canvasViewer';
2
+ export { default as JSONCanvasViewer } from './canvasViewer';
3
3
  export { default as Controls } from './controls';
4
4
  export { default as DebugPanel } from './debugPanel';
5
+ export type { UserOptions as Options } from './declarations';
5
6
  export { default as Minimap } from './minimap';
6
7
  export { default as MistouchPreventer } from './mistouchPreventer';
8
+ export { default as renderToString } from './renderToString';
9
+ export { default as canvasUtils } from './utilities';
7
10
  import Controller from './controller';
8
11
  import DataManager from './dataManager';
9
12
  import InteractionHandler from './interactionHandler';
@@ -1,16 +1,11 @@
1
- import { Pointeract } from 'pointeract';
1
+ import { Click, type Ctors, Drag, MultitouchPanZoom, Pointeract, type Options as PointeractOptions, PreventDefault, WheelPanZoom } from 'pointeract';
2
2
  import { type BaseArgs, BaseModule } from './baseModule';
3
3
  type Options = {
4
- interactions?: {
5
- proControlSchema?: boolean;
6
- zoomFactor?: number;
7
- lockControlSchema?: boolean;
8
- };
4
+ pointeract?: PointeractOptions<Ctors<[Click, Drag, WheelPanZoom, PreventDefault, MultitouchPanZoom]>>;
9
5
  };
10
6
  export default class InteractionHandler extends BaseModule<Options> {
11
7
  private pointeract;
12
8
  private DM;
13
- private OM;
14
9
  onClick: {
15
10
  (args_0: string | null): void;
16
11
  subs: Set<(args_0: string | null) => unknown>;
@@ -1,12 +1,16 @@
1
+ import { micromark } from 'micromark';
1
2
  import { type BaseArgs, BaseModule } from './baseModule';
2
- export default class OverlayManager extends BaseModule {
3
+ type Options = {
4
+ micromark?: Parameters<typeof micromark>[1];
5
+ };
6
+ export default class OverlayManager extends BaseModule<Options> {
3
7
  private _overlaysLayer;
4
8
  private overlays;
5
9
  private selectedId;
6
10
  private eventListeners;
7
11
  private DM;
8
12
  private IH;
9
- private parser;
13
+ private parse;
10
14
  private get overlaysLayer();
11
15
  hooks: {
12
16
  onInteractionStart: {
@@ -27,7 +31,8 @@ export default class OverlayManager extends BaseModule {
27
31
  private select;
28
32
  private loadMarkdownForNode;
29
33
  private updateOverlays;
30
- private updateOrCreateOverlay;
34
+ private updateOverlay;
31
35
  private constructOverlay;
32
36
  dispose: () => void;
33
37
  }
38
+ export {};
@@ -0,0 +1,2 @@
1
+ import { micromark } from 'micromark';
2
+ export default function (path: string, micromarkOptions?: Parameters<typeof micromark>[1]): Promise<string>;
@@ -1,3 +1,4 @@
1
+ import type { GeneralArguments } from './declarations';
1
2
  declare const _default: {
2
3
  round: typeof round;
3
4
  resizeCanvasForDPR: typeof resizeCanvasForDPR;
@@ -5,8 +6,11 @@ declare const _default: {
5
6
  drawRoundRect: typeof drawRoundRect;
6
7
  getAnchorCoord: typeof getAnchorCoord;
7
8
  getColor: typeof getColor;
9
+ resolvePath: typeof resolvePath;
10
+ makeHook: typeof makeHook;
8
11
  };
9
12
  export default _default;
13
+ export declare const destroyError: Error;
10
14
  declare function applyStyles(container: HTMLElement | ShadowRoot, styleString: string): void;
11
15
  declare function drawRoundRect(ctx: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, radius: number): void;
12
16
  declare function getAnchorCoord(node: JSONCanvasNode, side: 'top' | 'bottom' | 'left' | 'right'): number[];
@@ -17,3 +21,10 @@ declare function getColor(colorIndex?: string): {
17
21
  };
18
22
  declare function resizeCanvasForDPR(canvas: HTMLCanvasElement, width: number, height: number): void;
19
23
  declare function round(roundedNum: number, digits: number): number;
24
+ declare function resolvePath(path: string): string;
25
+ declare function makeHook<Args extends GeneralArguments = []>(): {
26
+ (...args: Args): void;
27
+ subs: Set<(...args: Args) => unknown>;
28
+ subscribe(callback: (...args: Args) => unknown): void;
29
+ unsubscribe(callback: (...args: Args) => unknown): void;
30
+ };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "json-canvas-viewer",
3
- "version": "3.2.0",
3
+ "version": "3.2.2",
4
4
  "description": "An extensible TypeScript-based viewer for JSON Canvas, easy to embed into websites.",
5
5
  "type": "module",
6
- "types": "dist/types/src/index.d.ts",
6
+ "types": "dist/types/index.d.ts",
7
7
  "main": "dist/index.cjs",
8
8
  "module": "dist/index.js",
9
9
  "repository": {
@@ -25,6 +25,7 @@
25
25
  "name": "Hēsperus",
26
26
  "email": "hesprs@outlook.com"
27
27
  },
28
+ "sideEffects": false,
28
29
  "publishConfig": {
29
30
  "provenance": true,
30
31
  "access": "public"
@@ -33,6 +34,7 @@
33
34
  "devDependencies": {
34
35
  "@biomejs/biome": "^2.3.10",
35
36
  "@types/node": "^25.0.3",
37
+ "micromark-extension-gfm": "^3.0.0",
36
38
  "sass": "^1.97.1",
37
39
  "tsc-alias": "^1.8.16",
38
40
  "typescript": "^5.9.3",
@@ -43,9 +45,7 @@
43
45
  ],
44
46
  "dependencies": {
45
47
  "@needle-di/core": "^1.1.0",
46
- "dompurify": "^3.3.1",
47
48
  "micromark": "^4.0.2",
48
- "micromark-extension-gfm": "^3.0.0",
49
49
  "pointeract": "^1.0.1"
50
50
  },
51
51
  "scripts": {
@@ -1,13 +0,0 @@
1
- import type { GeneralArguments } from './declarations';
2
- export declare const unexpectedError: Error;
3
- export declare const destroyError: Error;
4
- export interface RuntimeJSONCanvasNode extends JSONCanvasNode {
5
- mdContent?: string;
6
- mdFrontmatter?: Record<string, string>;
7
- }
8
- export declare function makeHook<Args extends GeneralArguments = []>(): {
9
- (...args: Args): void;
10
- subs: Set<(...args: Args) => unknown>;
11
- subscribe(callback: (...args: Args) => unknown): void;
12
- unsubscribe(callback: (...args: Args) => unknown): void;
13
- };