json-canvas-viewer 4.1.1 → 4.2.1

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.
Files changed (54) hide show
  1. package/dist/chimp.js +6 -5
  2. package/dist/index.d.ts +5 -5
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/kernel/BaseModule.d.ts +1 -2
  6. package/dist/kernel/BaseModule.js.map +1 -1
  7. package/dist/kernel/Controller.d.ts +12 -12
  8. package/dist/kernel/Controller.js +1 -1
  9. package/dist/kernel/Controller.js.map +1 -1
  10. package/dist/kernel/DataManager.d.ts +15 -15
  11. package/dist/kernel/DataManager.js +1 -1
  12. package/dist/kernel/DataManager.js.map +1 -1
  13. package/dist/kernel/InteractionHandler.d.ts +16 -16
  14. package/dist/kernel/InteractionHandler.js +1 -1
  15. package/dist/kernel/InteractionHandler.js.map +1 -1
  16. package/dist/kernel/OverlayManager.d.ts +29 -22
  17. package/dist/kernel/OverlayManager.js +1 -1
  18. package/dist/kernel/OverlayManager.js.map +1 -1
  19. package/dist/kernel/Renderer.d.ts +23 -22
  20. package/dist/kernel/Renderer.js +2 -1
  21. package/dist/kernel/Renderer.js.map +1 -1
  22. package/dist/kernel/StyleManager.d.ts +34 -34
  23. package/dist/kernel/StyleManager.js +1 -1
  24. package/dist/kernel/StyleManager.js.map +1 -1
  25. package/dist/kernel/index.d.ts +7 -7
  26. package/dist/kernel/index.js +1 -1
  27. package/dist/kernel/index.js.map +1 -1
  28. package/dist/kernel/types.d.ts +1 -1
  29. package/dist/kernel/utilities.d.ts +1 -27
  30. package/dist/kernel/utilities.js +1 -1
  31. package/dist/kernel/utilities.js.map +1 -1
  32. package/dist/modules/Controls/index.d.ts +21 -21
  33. package/dist/modules/Controls/index.js +1 -1
  34. package/dist/modules/Controls/index.js.map +1 -1
  35. package/dist/modules/DebugPanel/index.d.ts +4 -4
  36. package/dist/modules/DebugPanel/index.js +1 -1
  37. package/dist/modules/DebugPanel/index.js.map +1 -1
  38. package/dist/modules/Minimap/index.d.ts +17 -17
  39. package/dist/modules/Minimap/index.js +1 -1
  40. package/dist/modules/Minimap/index.js.map +1 -1
  41. package/dist/modules/MistouchPreventer/index.d.ts +11 -11
  42. package/dist/modules/MistouchPreventer/index.js +1 -1
  43. package/dist/modules/MistouchPreventer/index.js.map +1 -1
  44. package/dist/shared/index.d.ts +14 -14
  45. package/dist/utilities/{fetchCanvas.d.ts → fetch-canvas.d.ts} +2 -2
  46. package/dist/utilities/{fetchCanvas.js → fetch-canvas.js} +1 -1
  47. package/dist/utilities/fetch-canvas.js.map +1 -0
  48. package/dist/utilities/{renderToString.d.ts → render-to-string.d.ts} +2 -2
  49. package/dist/utilities/render-to-string.js +2 -0
  50. package/dist/utilities/render-to-string.js.map +1 -0
  51. package/package.json +1 -1
  52. package/dist/utilities/fetchCanvas.js.map +0 -1
  53. package/dist/utilities/renderToString.js +0 -2
  54. package/dist/utilities/renderToString.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["style","utilities"],"sources":["../../../src/modules/Minimap/index.ts"],"sourcesContent":["import type { BaseOptions } from '$';\nimport type { JSONCanvasEdge, JSONCanvasNode } from '@repo/shared';\nimport { type BaseArgs, BaseModule } from '$/BaseModule';\nimport Controller from '$/Controller';\nimport DataManager from '$/DataManager';\nimport StyleManager from '$/StyleManager';\nimport utilities, { destroyError } from '$/utilities';\nimport style from './styles.scss?inline';\n\ninterface Options extends BaseOptions {\n\tminimapCollapsed?: boolean;\n}\n\ninterface Augmentation {\n\ttoggleMinimapCollapse: Minimap['toggleCollapse'];\n}\n\nconst toggleCollapseIcon =\n\t'<svg viewBox=\"-3.6 -3.6 31.2 31.2\" stroke-width=\".4\"><path d=\"M15.707 4.293a1 1 0 0 1 0 1.414L9.414 12l6.293 6.293a1 1 0 0 1-1.414 1.414l-7-7a1 1 0 0 1 0-1.414l7-7a1 1 0 0 1 1.414 0Z\" /></svg>';\n\nexport default class Minimap extends BaseModule<Options, Augmentation> {\n\tprivate _minimapCtx: CanvasRenderingContext2D | null = null;\n\tprivate _viewportRectangle: HTMLDivElement | null = null;\n\tprivate _minimap: HTMLDivElement | null = null;\n\tprivate _minimapContainer: HTMLDivElement | null = null;\n\tprivate _toggleMinimapBtn: HTMLButtonElement | null = null;\n\tprivate minimapCache: { scale: number; centerX: number; centerY: number } = {\n\t\tscale: 1,\n\t\tcenterX: 0,\n\t\tcenterY: 0,\n\t};\n\tprivate DM: DataManager;\n\tprivate SM: StyleManager;\n\tprivate collapsed: boolean;\n\n\tprivate get minimap() {\n\t\tif (this._minimap === null) throw destroyError;\n\t\treturn this._minimap;\n\t}\n\tprivate get minimapCtx() {\n\t\tif (this._minimapCtx === null) throw destroyError;\n\t\treturn this._minimapCtx;\n\t}\n\tprivate get viewportRectangle() {\n\t\tif (this._viewportRectangle === null) throw destroyError;\n\t\treturn this._viewportRectangle;\n\t}\n\tprivate get minimapContainer() {\n\t\tif (this._minimapContainer === null) throw destroyError;\n\t\treturn this._minimapContainer;\n\t}\n\tprivate get toggleMinimapBtn() {\n\t\tif (this._toggleMinimapBtn === null) throw destroyError;\n\t\treturn this._toggleMinimapBtn;\n\t}\n\n\tconstructor(...args: BaseArgs) {\n\t\tsuper(...args);\n\t\tthis.collapsed = this.options.minimapCollapsed ?? false;\n\t\tthis.container.get(Controller).onRefresh.subscribe(this.updateViewportRectangle);\n\t\tthis.DM = this.container.get(DataManager);\n\t\tthis.SM = this.container.get(StyleManager);\n\n\t\tthis._minimapContainer = document.createElement('div');\n\t\tthis._minimapContainer.className = 'JCV-minimap-container';\n\n\t\tutilities.applyStyles(this._minimapContainer, style);\n\n\t\tthis._toggleMinimapBtn = document.createElement('button');\n\t\tthis._toggleMinimapBtn.className =\n\t\t\t'JCV-button JCV-toggle-minimap JCV-collapse-button JCV-border-shadow-bg';\n\t\tthis._toggleMinimapBtn.innerHTML = toggleCollapseIcon;\n\t\tthis._minimapContainer.appendChild(this._toggleMinimapBtn);\n\n\t\tthis._minimap = document.createElement('div');\n\t\tthis._minimap.className = 'JCV-minimap JCV-border-shadow-bg';\n\t\tconst minimapCanvas = document.createElement('canvas');\n\t\tminimapCanvas.className = 'JCV-minimap-canvas';\n\t\tminimapCanvas.width = 200;\n\t\tminimapCanvas.height = 150;\n\n\t\tthis._minimap.appendChild(minimapCanvas);\n\t\tthis._minimapCtx = minimapCanvas.getContext('2d') as CanvasRenderingContext2D;\n\t\tthis._viewportRectangle = document.createElement('div');\n\t\tthis._viewportRectangle.className = 'JCV-viewport-rectangle';\n\t\tthis._minimap.appendChild(this._viewportRectangle);\n\t\tthis._minimapContainer.appendChild(this._minimap);\n\n\t\tthis.DM.data.container.appendChild(this._minimapContainer);\n\n\t\tthis._minimapContainer.classList.toggle('JCV-collapsed', this.collapsed);\n\n\t\tthis._toggleMinimapBtn.addEventListener('click', this.toggleCollapse);\n\t\tutilities.resizeCanvasForDPR(minimapCanvas, minimapCanvas.width, minimapCanvas.height);\n\n\t\tthis.augment({ toggleMinimapCollapse: this.toggleCollapse });\n\t\tthis.onStart(this.start);\n\t\tthis.onRestart(this.start);\n\t\tthis.onDispose(this.dispose);\n\t}\n\n\ttoggleCollapse = () => {\n\t\tthis.collapsed = !this.collapsed;\n\t\tthis.minimapContainer.classList.toggle('JCV-collapsed', this.collapsed);\n\t\tif (!this.collapsed) this.updateViewportRectangle();\n\t};\n\n\tprivate start = () => {\n\t\tconst bounds = this.DM.data.nodeBounds;\n\t\tif (!bounds) return;\n\t\tconst displayWidth = this.minimap.clientWidth;\n\t\tconst displayHeight = this.minimap.clientHeight;\n\t\tconst scaleX = displayWidth / bounds.width;\n\t\tconst scaleY = displayHeight / bounds.height;\n\t\tthis.minimapCache.scale = Math.min(scaleX, scaleY) * 0.9;\n\t\tthis.minimapCache.centerX = displayWidth / 2;\n\t\tthis.minimapCache.centerY = displayHeight / 2;\n\t\tthis.minimapCtx.clearRect(0, 0, displayWidth, displayHeight);\n\t\tthis.minimapCtx.save();\n\t\tthis.minimapCtx.translate(this.minimapCache.centerX, this.minimapCache.centerY);\n\t\tthis.minimapCtx.scale(this.minimapCache.scale, this.minimapCache.scale);\n\t\tthis.minimapCtx.translate(-bounds.centerX, -bounds.centerY);\n\t\tconst canvasData = this.DM.data.canvasData;\n\t\tfor (const edge of canvasData.edges) this.drawMinimapEdge(edge);\n\t\tfor (const node of canvasData.nodes) this.drawMinimapNode(node);\n\t\tthis.minimapCtx.restore();\n\t};\n\n\tprivate drawMinimapNode = (node: JSONCanvasNode) => {\n\t\tconst colors = this.SM.getColor(node.color);\n\t\tconst radius = 25;\n\t\tthis.minimapCtx.fillStyle = colors.border;\n\t\tutilities.drawRoundRect(this.minimapCtx, node.x, node.y, node.width, node.height, radius);\n\t\tthis.minimapCtx.fill();\n\t};\n\n\tprivate drawMinimapEdge = (edge: JSONCanvasEdge) => {\n\t\tconst canvasMap = this.DM.data.nodeMap;\n\t\tconst fromNode = canvasMap[edge.fromNode].ref;\n\t\tconst toNode = canvasMap[edge.toNode].ref;\n\t\tif (!fromNode || !toNode) return;\n\t\tconst { x: startX, y: startY } = utilities.getAnchorCoord(fromNode, edge.fromSide);\n\t\tconst { x: endX, y: endY } = utilities.getAnchorCoord(toNode, edge.toSide);\n\t\tthis.minimapCtx.beginPath();\n\t\tthis.minimapCtx.moveTo(startX, startY);\n\t\tthis.minimapCtx.lineTo(endX, endY);\n\t\tthis.minimapCtx.strokeStyle = this.SM.getColor(edge.color).active;\n\t\tthis.minimapCtx.lineWidth = 10;\n\t\tthis.minimapCtx.stroke();\n\t};\n\n\tprivate updateViewportRectangle = () => {\n\t\tif (this.collapsed) return;\n\t\tconst bounds = this.DM.data.nodeBounds;\n\t\tconst container = this.DM.data.container;\n\t\tconst scale = this.DM.data.scale;\n\t\tif (!bounds) return;\n\t\tconst viewWidth = container.clientWidth / scale;\n\t\tconst viewHeight = container.clientHeight / scale;\n\t\tconst viewportCenterX = -this.DM.data.offsetX / scale + container.clientWidth / (2 * scale);\n\t\tconst viewportCenterY =\n\t\t\t-this.DM.data.offsetY / scale + container.clientHeight / (2 * scale);\n\t\tconst viewRectX =\n\t\t\tthis.minimapCache.centerX +\n\t\t\t(viewportCenterX - viewWidth / 2 - bounds.centerX) * this.minimapCache.scale;\n\t\tconst viewRectY =\n\t\t\tthis.minimapCache.centerY +\n\t\t\t(viewportCenterY - viewHeight / 2 - bounds.centerY) * this.minimapCache.scale;\n\t\tconst viewRectWidth = viewWidth * this.minimapCache.scale;\n\t\tconst viewRectHeight = viewHeight * this.minimapCache.scale;\n\t\tthis.viewportRectangle.style.left = `${viewRectX}px`;\n\t\tthis.viewportRectangle.style.top = `${viewRectY}px`;\n\t\tthis.viewportRectangle.style.width = `${viewRectWidth}px`;\n\t\tthis.viewportRectangle.style.height = `${viewRectHeight}px`;\n\t};\n\n\tprivate dispose = () => {\n\t\tthis.toggleMinimapBtn.removeEventListener('click', this.toggleCollapse);\n\t\tthis.minimapCtx.clearRect(0, 0, this.minimap.clientWidth, this.minimap.clientHeight);\n\t\tthis.minimapContainer.remove();\n\t\tthis._minimapContainer = null;\n\t\tthis._toggleMinimapBtn = null;\n\t\tthis._viewportRectangle = null;\n\t\tthis._minimap = null;\n\t};\n}\n"],"mappings":"gRAoBA,IAAqB,EAArB,cAAqC,CAAkC,CACtE,YAAuD,KACvD,mBAAoD,KACpD,SAA0C,KAC1C,kBAAmD,KACnD,kBAAsD,KACtD,aAA4E,CAC3E,MAAO,EACP,QAAS,EACT,QAAS,EACT,CACD,GACA,GACA,UAEA,IAAY,SAAU,CACrB,GAAI,KAAK,WAAa,KAAM,MAAM,EAClC,OAAO,KAAK,SAEb,IAAY,YAAa,CACxB,GAAI,KAAK,cAAgB,KAAM,MAAM,EACrC,OAAO,KAAK,YAEb,IAAY,mBAAoB,CAC/B,GAAI,KAAK,qBAAuB,KAAM,MAAM,EAC5C,OAAO,KAAK,mBAEb,IAAY,kBAAmB,CAC9B,GAAI,KAAK,oBAAsB,KAAM,MAAM,EAC3C,OAA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ACvE,KAAK,WAAW,UAAU,EAAG,EAAG,KAAK,QAAQ,YAAa,KAAK,QAAQ,aAAa,CACpF,KAAK,iBAAiB,QAAQ,CAC9B,KAAK,kBAAoB,KACzB,KAAK,kBAAoB,KACzB,KAAK,mBAAqB,KAC1B,KAAK,SAAW"}
1
+ {"version":3,"file":"index.js","names":["style"],"sources":["../../../src/modules/Minimap/index.ts"],"sourcesContent":["import type { BaseOptions } from '$';\nimport type { BaseArgs } from '$/BaseModule';\nimport type { JSONCanvasEdge, JSONCanvasNode } from '@repo/shared';\nimport { BaseModule } from '$/BaseModule';\nimport Controller from '$/Controller';\nimport DataManager from '$/DataManager';\nimport StyleManager from '$/StyleManager';\nimport {\n\tapplyStyles,\n\tdestroyError,\n\tdrawRoundRect,\n\tgetAnchorCoord,\n\tresizeCanvasForDPR,\n} from '$/utilities';\nimport style from './styles.scss?inline';\n\ntype Options = {\n\tminimapCollapsed?: boolean;\n} & BaseOptions;\n\ntype Augmentation = {\n\ttoggleMinimapCollapse: Minimap['toggleCollapse'];\n};\n\nconst toggleCollapseIcon =\n\t'<svg viewBox=\"-3.6 -3.6 31.2 31.2\" stroke-width=\".4\"><path d=\"M15.707 4.293a1 1 0 0 1 0 1.414L9.414 12l6.293 6.293a1 1 0 0 1-1.414 1.414l-7-7a1 1 0 0 1 0-1.414l7-7a1 1 0 0 1 1.414 0Z\" /></svg>';\n\nexport default class Minimap extends BaseModule<Options, Augmentation> {\n\tprivate readonly _minimapCtx?: CanvasRenderingContext2D;\n\tprivate _viewportRectangle?: HTMLDivElement;\n\tprivate _minimap?: HTMLDivElement;\n\tprivate _minimapContainer?: HTMLDivElement;\n\tprivate _toggleMinimapBtn?: HTMLButtonElement;\n\tprivate readonly minimapCache: { scale: number; centerX: number; centerY: number } = {\n\t\tcenterX: 0,\n\t\tcenterY: 0,\n\t\tscale: 1,\n\t};\n\tprivate readonly DM: DataManager;\n\tprivate readonly SM: StyleManager;\n\tprivate collapsed: boolean;\n\n\tprivate get minimap() {\n\t\tif (!this._minimap) throw destroyError;\n\t\treturn this._minimap;\n\t}\n\tprivate get minimapCtx() {\n\t\tif (!this._minimapCtx) throw destroyError;\n\t\treturn this._minimapCtx;\n\t}\n\tprivate get viewportRectangle() {\n\t\tif (!this._viewportRectangle) throw destroyError;\n\t\treturn this._viewportRectangle;\n\t}\n\tprivate get minimapContainer() {\n\t\tif (!this._minimapContainer) throw destroyError;\n\t\treturn this._minimapContainer;\n\t}\n\tprivate get toggleMinimapBtn() {\n\t\tif (!this._toggleMinimapBtn) throw destroyError;\n\t\treturn this._toggleMinimapBtn;\n\t}\n\n\tconstructor(...args: BaseArgs) {\n\t\tsuper(...args);\n\t\tthis.collapsed = this.options.minimapCollapsed ?? false;\n\t\tthis.container.get(Controller).onRefresh.subscribe(this.updateViewportRectangle);\n\t\tthis.DM = this.container.get(DataManager);\n\t\tthis.SM = this.container.get(StyleManager);\n\n\t\tthis._minimapContainer = document.createElement('div');\n\t\tthis._minimapContainer.className = 'JCV-minimap-container';\n\n\t\tapplyStyles(this._minimapContainer, style);\n\n\t\tthis._toggleMinimapBtn = document.createElement('button');\n\t\tthis._toggleMinimapBtn.className =\n\t\t\t'JCV-button JCV-toggle-minimap JCV-collapse-button JCV-border-shadow-bg';\n\t\tthis._toggleMinimapBtn.innerHTML = toggleCollapseIcon;\n\t\tthis._minimapContainer.appendChild(this._toggleMinimapBtn);\n\n\t\tthis._minimap = document.createElement('div');\n\t\tthis._minimap.className = 'JCV-minimap JCV-border-shadow-bg';\n\t\tconst minimapCanvas = document.createElement('canvas');\n\t\tminimapCanvas.className = 'JCV-minimap-canvas';\n\t\tminimapCanvas.width = 200;\n\t\tminimapCanvas.height = 150;\n\n\t\tthis._minimap.appendChild(minimapCanvas);\n\t\tthis._minimapCtx = minimapCanvas.getContext('2d') as CanvasRenderingContext2D;\n\t\tthis._viewportRectangle = document.createElement('div');\n\t\tthis._viewportRectangle.className = 'JCV-viewport-rectangle';\n\t\tthis._minimap.appendChild(this._viewportRectangle);\n\t\tthis._minimapContainer.appendChild(this._minimap);\n\n\t\tthis.DM.data.container.appendChild(this._minimapContainer);\n\n\t\tthis._minimapContainer.classList.toggle('JCV-collapsed', this.collapsed);\n\n\t\tthis._toggleMinimapBtn.addEventListener('click', this.toggleCollapse);\n\t\tresizeCanvasForDPR(minimapCanvas, minimapCanvas.width, minimapCanvas.height);\n\n\t\tthis.augment({ toggleMinimapCollapse: this.toggleCollapse });\n\t\tthis.onStart(this.start);\n\t\tthis.onRestart(this.start);\n\t\tthis.onDispose(this.dispose);\n\t}\n\n\ttoggleCollapse = () => {\n\t\tthis.collapsed = !this.collapsed;\n\t\tthis.minimapContainer.classList.toggle('JCV-collapsed', this.collapsed);\n\t\tif (!this.collapsed) this.updateViewportRectangle();\n\t};\n\n\tprivate readonly start = () => {\n\t\tconst bounds = this.DM.data.nodeBounds;\n\t\tif (!bounds) return;\n\t\tconst displayWidth = this.minimap.clientWidth;\n\t\tconst displayHeight = this.minimap.clientHeight;\n\t\tconst scaleX = displayWidth / bounds.width;\n\t\tconst scaleY = displayHeight / bounds.height;\n\t\tthis.minimapCache.scale = Math.min(scaleX, scaleY) * 0.9;\n\t\tthis.minimapCache.centerX = displayWidth / 2;\n\t\tthis.minimapCache.centerY = displayHeight / 2;\n\t\tthis.minimapCtx.clearRect(0, 0, displayWidth, displayHeight);\n\t\tthis.minimapCtx.save();\n\t\tthis.minimapCtx.translate(this.minimapCache.centerX, this.minimapCache.centerY);\n\t\tthis.minimapCtx.scale(this.minimapCache.scale, this.minimapCache.scale);\n\t\tthis.minimapCtx.translate(-bounds.centerX, -bounds.centerY);\n\t\tconst canvasData = this.DM.data.canvasData;\n\t\tfor (const edge of canvasData.edges) this.drawMinimapEdge(edge);\n\t\tfor (const node of canvasData.nodes) this.drawMinimapNode(node);\n\t\tthis.minimapCtx.restore();\n\t};\n\n\tprivate readonly drawMinimapNode = (node: JSONCanvasNode) => {\n\t\tconst colors = this.SM.getColor(node.color);\n\t\tconst radius = 25;\n\t\tthis.minimapCtx.fillStyle = colors.border;\n\t\tdrawRoundRect(this.minimapCtx, node.x, node.y, node.width, node.height, radius);\n\t\tthis.minimapCtx.fill();\n\t};\n\n\tprivate readonly drawMinimapEdge = (edge: JSONCanvasEdge) => {\n\t\tconst canvasMap = this.DM.data.nodeMap;\n\t\tconst fromNode = canvasMap[edge.fromNode].ref;\n\t\tconst toNode = canvasMap[edge.toNode].ref;\n\t\tif (!fromNode || !toNode) return;\n\t\tconst { x: startX, y: startY } = getAnchorCoord(fromNode, edge.fromSide);\n\t\tconst { x: endX, y: endY } = getAnchorCoord(toNode, edge.toSide);\n\t\tthis.minimapCtx.beginPath();\n\t\tthis.minimapCtx.moveTo(startX, startY);\n\t\tthis.minimapCtx.lineTo(endX, endY);\n\t\tthis.minimapCtx.strokeStyle = this.SM.getColor(edge.color).active;\n\t\tthis.minimapCtx.lineWidth = 10;\n\t\tthis.minimapCtx.stroke();\n\t};\n\n\tprivate readonly updateViewportRectangle = () => {\n\t\tif (this.collapsed) return;\n\t\tconst bounds = this.DM.data.nodeBounds;\n\t\tconst container = this.DM.data.container;\n\t\tconst scale = this.DM.data.scale;\n\t\tif (!bounds) return;\n\t\tconst viewWidth = container.clientWidth / scale;\n\t\tconst viewHeight = container.clientHeight / scale;\n\t\tconst viewportCenterX = -this.DM.data.offsetX / scale + container.clientWidth / (2 * scale);\n\t\tconst viewportCenterY =\n\t\t\t-this.DM.data.offsetY / scale + container.clientHeight / (2 * scale);\n\t\tconst viewRectX =\n\t\t\tthis.minimapCache.centerX +\n\t\t\t(viewportCenterX - viewWidth / 2 - bounds.centerX) * this.minimapCache.scale;\n\t\tconst viewRectY =\n\t\t\tthis.minimapCache.centerY +\n\t\t\t(viewportCenterY - viewHeight / 2 - bounds.centerY) * this.minimapCache.scale;\n\t\tconst viewRectWidth = viewWidth * this.minimapCache.scale;\n\t\tconst viewRectHeight = viewHeight * this.minimapCache.scale;\n\t\tthis.viewportRectangle.style.left = `${viewRectX}px`;\n\t\tthis.viewportRectangle.style.top = `${viewRectY}px`;\n\t\tthis.viewportRectangle.style.width = `${viewRectWidth}px`;\n\t\tthis.viewportRectangle.style.height = `${viewRectHeight}px`;\n\t};\n\n\tprivate readonly dispose = () => {\n\t\tthis.toggleMinimapBtn.removeEventListener('click', this.toggleCollapse);\n\t\tthis.minimapCtx.clearRect(0, 0, this.minimap.clientWidth, this.minimap.clientHeight);\n\t\tthis.minimapContainer.remove();\n\t\tthis._minimapContainer = undefined;\n\t\tthis._toggleMinimapBtn = undefined;\n\t\tthis._viewportRectangle = undefined;\n\t\tthis._minimap = undefined;\n\t};\n}\n"],"mappings":"6VA2BA,IAAqB,EAArB,cAAqC,CAAkC,CACtE,YACA,mBACA,SACA,kBACA,kBACA,aAAqF,CACpF,QAAS,EACT,QAAS,EACT,MAAO,EACP,CACD,GACA,GACA,UAEA,IAAY,SAAU,CACrB,GAAI,CAAC,KAAK,SAAU,MAAM,EAC1B,OAAO,KAAK,SAEb,IAAY,YAAa,CACxB,GAAI,CAAC,KAAK,YAAa,MAAM,EAC7B,OAAO,KAAK,YAEb,IAAY,mBAAoB,CAC/B,GAAI,CAAC,KAAK,mBAAoB,MAAM,EACpC,OAAO,KAAK,mBAEb,IAAY,kBAAmB,CAC9B,GAAI,CAAC,KAAK,kBAAmB,MAAM,EACnC,OAAO,KAAK,kBAEb,IAAY,kBAAmB,CAC9B,GAAI,CAAC,KAAK,kBAAmB,MAAM,EACnC,OAAO,KAAK,kBAGb,YAAY,GAAG,EAAgB,CAC9B,MAAM,GAAG,EAAK,CACd,KAAK,UAAY,KAAK,QAAQ,kBAAoB,GAClD,KAAK,UAAU,IAAI,EAAW,CAAC,UAAU,UAAU,KAAK,wBAAwB,CAChF,KAAK,GAAK,KAAK,UAAU,IAAI,EAAY,CACzC,KAAK,GAAK,KAAK,UAAU,IAAI,EAAa,CAE1C,KAAK,kBAAoB,SAAS,cAAc,MAAM,CACtD,KAAK,kBAAkB,UAAY,wBAEnC,EAAY,K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AAiD,CAChD,GAAI,KAAK,UAAW,OACpB,IAAM,EAAS,KAAK,GAAG,KAAK,WACtB,EAAY,KAAK,GAAG,KAAK,UACzB,EAAQ,KAAK,GAAG,KAAK,MAC3B,GAAI,CAAC,EAAQ,OACb,IAAM,EAAY,EAAU,YAAc,EACpC,EAAa,EAAU,aAAe,EACtC,EAAkB,CAAC,KAAK,GAAG,KAAK,QAAU,EAAQ,EAAU,aAAe,EAAI,GAC/E,EACL,CAAC,KAAK,GAAG,KAAK,QAAU,EAAQ,EAAU,cAAgB,EAAI,GACzD,EACL,KAAK,aAAa,SACjB,EAAkB,EAAY,EAAI,EAAO,SAAW,KAAK,aAAa,MAClE,EACL,KAAK,aAAa,SACjB,EAAkB,EAAa,EAAI,EAAO,SAAW,KAAK,aAAa,MACnE,EAAgB,EAAY,KAAK,aAAa,MAC9C,EAAiB,EAAa,KAAK,aAAa,MACtD,KAAK,kBAAkB,MAAM,KAAO,GAAG,EAAU,IACjD,KAAK,kBAAkB,MAAM,IAAM,GAAG,EAAU,IAChD,KAAK,kBAAkB,MAAM,MAAQ,GAAG,EAAc,IACtD,KAAK,kBAAkB,MAAM,OAAS,GAAG,EAAe,KAGzD,YAAiC,CAChC,KAAK,iBAAiB,oBAAoB,QAAS,KAAK,eAAe,CACvE,KAAK,WAAW,UAAU,EAAG,EAAG,KAAK,QAAQ,YAAa,KAAK,QAAQ,aAAa,CACpF,KAAK,iBAAiB,QAAQ,CAC9B,KAAK,kBAAoB,IAAA,GACzB,KAAK,kBAAoB,IAAA,GACzB,KAAK,mBAAqB,IAAA,GAC1B,KAAK,SAAW,IAAA"}
@@ -2,27 +2,27 @@ import { BaseArgs, BaseModule } from "../../kernel/BaseModule.js";
2
2
  import { BaseOptions } from "../../kernel/index.js";
3
3
 
4
4
  //#region src/modules/MistouchPreventer/index.d.ts
5
- interface Options extends BaseOptions {
5
+ type Options = {
6
6
  preventMistouchAtStart?: boolean;
7
7
  mistouchPreventerBannerText?: string;
8
- }
9
- interface Augmentation {
8
+ } & BaseOptions;
9
+ type Augmentation = {
10
10
  startMistouchPrevention: MistouchPreventer['startPrevention'];
11
11
  endMistouchPrevention: MistouchPreventer['endPrevention'];
12
- }
12
+ };
13
13
  declare class MistouchPreventer extends BaseModule<Options, Augmentation> {
14
- private _preventionContainer;
14
+ private _preventionContainer?;
15
15
  private preventMt;
16
- private DM;
17
- private preventMistouch;
16
+ private readonly DM;
17
+ private readonly preventMistouch;
18
18
  private get preventionContainer();
19
19
  constructor(...args: BaseArgs);
20
- private onPointerDown;
21
- private onPointerMove;
22
- private onPointerUp;
20
+ private readonly onPointerDown;
21
+ private readonly onPointerMove;
22
+ private readonly onPointerUp;
23
23
  startPrevention: () => void;
24
24
  endPrevention: () => void;
25
- private dispose;
25
+ private readonly dispose;
26
26
  }
27
27
  //#endregion
28
28
  export { MistouchPreventer };
@@ -1,2 +1,2 @@
1
- import{BaseModule as e}from"../../kernel/BaseModule.js";import t,{destroyError as n}from"../../kernel/utilities.js";import r from"../../kernel/DataManager.js";import i from"./styles.js";var a=class extends e{_preventionContainer=null;preventMt=!1;DM;preventMistouch={record:!1,lastX:0,lastY:0,initialX:0,initialY:0};get preventionContainer(){if(this._preventionContainer===null)throw n;return this._preventionContainer}constructor(...e){super(...e);let n=document.createElement(`div`);n.className=`JCV-prevention-banner JCV-border-shadow-bg`,n.textContent=this.options.mistouchPreventerBannerText??`Click on to unlock.`,this.DM=this.container.get(r),this._preventionContainer=document.createElement(`div`),this._preventionContainer.className=`JCV-prevention-container JCV-hidden JCV-full JCV-flex-center`,t.applyStyles(this._preventionContainer,i),this._preventionContainer.appendChild(n),this.DM.data.container.appendChild(this._preventionContainer),this.options.preventMistouchAtStart&&this.startPrevention(),window.addEventListener(`pointerdown`,this.onPointerDown),window.addEventListener(`pointermove`,this.onPointerMove),window.addEventListener(`pointerup`,this.onPointerUp),this.augment({startMistouchPrevention:this.startPrevention,endMistouchPrevention:this.endPrevention}),this.onDispose(this.dispose)}onPointerDown=e=>{let t=this.DM.data.container.getBoundingClientRect();e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom?this.preventMt||this.startPrevention():this.preventMt&&(this.preventMistouch.initialX=e.clientX,this.preventMistouch.initialY=e.clientY,this.preventMistouch.lastX=e.clientX,this.preventMistouch.lastY=e.clientY,this.preventMistouch.record=!0)};onPointerMove=e=>{this.preventMistouch.record&&(this.preventMistouch.lastX=e.clientX,this.preventMistouch.lastY=e.clientY)};onPointerUp=()=>{this.preventMistouch.record&&(this.preventMistouch.record=!1,Math.abs(this.preventMistouch.lastX-this.preventMistouch.initialX)+Math.abs(this.preventMistouch.lastY-this.preventMistouch.initialY)<5&&this.endPrevention())};startPrevention=()=>{this.preventionContainer.classList.remove(`JCV-hidden`),this.DM.data.container.classList.add(`JCV-numb`),this.preventMt=!0};endPrevention=()=>{this.preventMt=!1,this.preventionContainer.classList.add(`JCV-hidden`),setTimeout(()=>this.DM.data.container.classList.remove(`JCV-numb`),50)};dispose=()=>{window.removeEventListener(`pointerdown`,this.onPointerDown),window.removeEventListener(`pointermove`,this.onPointerMove),window.removeEventListener(`pointerup`,this.onPointerUp),this.preventionContainer.remove(),this._preventionContainer=null}};export{a as default};
1
+ import{BaseModule as e}from"../../kernel/BaseModule.js";import{applyStyles as t,destroyError as n}from"../../kernel/utilities.js";import r from"../../kernel/DataManager.js";import i from"./styles.js";var a=class extends e{_preventionContainer;preventMt=!1;DM;preventMistouch={initialX:0,initialY:0,lastX:0,lastY:0,record:!1};get preventionContainer(){if(!this._preventionContainer)throw n;return this._preventionContainer}constructor(...e){super(...e);let n=document.createElement(`div`);n.className=`JCV-prevention-banner JCV-border-shadow-bg`,n.textContent=this.options.mistouchPreventerBannerText??`Click on to unlock.`,this.DM=this.container.get(r),this._preventionContainer=document.createElement(`div`),this._preventionContainer.className=`JCV-prevention-container JCV-hidden JCV-full JCV-flex-center`,t(this._preventionContainer,i),this._preventionContainer.appendChild(n),this.DM.data.container.appendChild(this._preventionContainer),this.options.preventMistouchAtStart&&this.startPrevention(),window.addEventListener(`pointerdown`,this.onPointerDown),window.addEventListener(`pointermove`,this.onPointerMove),window.addEventListener(`pointerup`,this.onPointerUp),this.augment({endMistouchPrevention:this.endPrevention,startMistouchPrevention:this.startPrevention}),this.onDispose(this.dispose)}onPointerDown=e=>{let t=this.DM.data.container.getBoundingClientRect();e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom?this.preventMt||this.startPrevention():this.preventMt&&(this.preventMistouch.initialX=e.clientX,this.preventMistouch.initialY=e.clientY,this.preventMistouch.lastX=e.clientX,this.preventMistouch.lastY=e.clientY,this.preventMistouch.record=!0)};onPointerMove=e=>{this.preventMistouch.record&&(this.preventMistouch.lastX=e.clientX,this.preventMistouch.lastY=e.clientY)};onPointerUp=()=>{this.preventMistouch.record&&(this.preventMistouch.record=!1,Math.abs(this.preventMistouch.lastX-this.preventMistouch.initialX)+Math.abs(this.preventMistouch.lastY-this.preventMistouch.initialY)<5&&this.endPrevention())};startPrevention=()=>{this.preventionContainer.classList.remove(`JCV-hidden`),this.DM.data.container.classList.add(`JCV-numb`),this.preventMt=!0};endPrevention=()=>{this.preventMt=!1,this.preventionContainer.classList.add(`JCV-hidden`),setTimeout(()=>this.DM.data.container.classList.remove(`JCV-numb`),50)};dispose=()=>{window.removeEventListener(`pointerdown`,this.onPointerDown),window.removeEventListener(`pointermove`,this.onPointerMove),window.removeEventListener(`pointerup`,this.onPointerUp),this.preventionContainer.remove(),this._preventionContainer=void 0}};export{a as default};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["style"],"sources":["../../../src/modules/MistouchPreventer/index.ts"],"sourcesContent":["import type { BaseOptions } from '$';\nimport { type BaseArgs, BaseModule } from '$/BaseModule';\nimport DataManager from '$/DataManager';\nimport utilities, { destroyError } from '$/utilities';\nimport style from './styles.scss?inline';\n\ninterface Options extends BaseOptions {\n\tpreventMistouchAtStart?: boolean;\n\tmistouchPreventerBannerText?: string;\n}\n\ninterface Augmentation {\n\tstartMistouchPrevention: MistouchPreventer['startPrevention'];\n\tendMistouchPrevention: MistouchPreventer['endPrevention'];\n}\n\nexport default class MistouchPreventer extends BaseModule<Options, Augmentation> {\n\tprivate _preventionContainer: HTMLDivElement | null = null;\n\tprivate preventMt: boolean = false;\n\tprivate DM: DataManager;\n\tprivate preventMistouch: {\n\t\trecord: boolean;\n\t\tlastX: number;\n\t\tlastY: number;\n\t\tinitialX: number;\n\t\tinitialY: number;\n\t} = {\n\t\trecord: false,\n\t\tlastX: 0,\n\t\tlastY: 0,\n\t\tinitialX: 0,\n\t\tinitialY: 0,\n\t};\n\n\tprivate get preventionContainer() {\n\t\tif (this._preventionContainer === null) throw destroyError;\n\t\treturn this._preventionContainer;\n\t}\n\n\tconstructor(...args: BaseArgs) {\n\t\tsuper(...args);\n\n\t\tconst preventionBanner = document.createElement('div');\n\t\tpreventionBanner.className = 'JCV-prevention-banner JCV-border-shadow-bg';\n\t\tpreventionBanner.textContent =\n\t\t\tthis.options.mistouchPreventerBannerText ?? 'Click on to unlock.';\n\t\tthis.DM = this.container.get(DataManager);\n\t\tthis._preventionContainer = document.createElement('div');\n\t\tthis._preventionContainer.className =\n\t\t\t'JCV-prevention-container JCV-hidden JCV-full JCV-flex-center';\n\n\t\tutilities.applyStyles(this._preventionContainer, style);\n\t\tthis._preventionContainer.appendChild(preventionBanner);\n\t\tthis.DM.data.container.appendChild(this._preventionContainer);\n\n\t\tif (this.options.preventMistouchAtStart) this.startPrevention();\n\n\t\twindow.addEventListener('pointerdown', this.onPointerDown);\n\t\twindow.addEventListener('pointermove', this.onPointerMove);\n\t\twindow.addEventListener('pointerup', this.onPointerUp);\n\n\t\tthis.augment({\n\t\t\tstartMistouchPrevention: this.startPrevention,\n\t\t\tendMistouchPrevention: this.endPrevention,\n\t\t});\n\t\tthis.onDispose(this.dispose);\n\t}\n\n\tprivate onPointerDown = (e: PointerEvent) => {\n\t\tconst bounds = this.DM.data.container.getBoundingClientRect();\n\t\tif (\n\t\t\te.clientX < bounds.left ||\n\t\t\te.clientX > bounds.right ||\n\t\t\te.clientY < bounds.top ||\n\t\t\te.clientY > bounds.bottom\n\t\t) {\n\t\t\tif (!this.preventMt) this.startPrevention();\n\t\t} else if (this.preventMt) {\n\t\t\tthis.preventMistouch.initialX = e.clientX;\n\t\t\tthis.preventMistouch.initialY = e.clientY;\n\t\t\tthis.preventMistouch.lastX = e.clientX;\n\t\t\tthis.preventMistouch.lastY = e.clientY;\n\t\t\tthis.preventMistouch.record = true;\n\t\t}\n\t};\n\n\tprivate onPointerMove = (e: PointerEvent) => {\n\t\tif (this.preventMistouch.record) {\n\t\t\tthis.preventMistouch.lastX = e.clientX;\n\t\t\tthis.preventMistouch.lastY = e.clientY;\n\t\t}\n\t};\n\n\tprivate onPointerUp = () => {\n\t\tif (this.preventMistouch.record) {\n\t\t\tthis.preventMistouch.record = false;\n\t\t\tif (\n\t\t\t\tMath.abs(this.preventMistouch.lastX - this.preventMistouch.initialX) +\n\t\t\t\t\tMath.abs(this.preventMistouch.lastY - this.preventMistouch.initialY) <\n\t\t\t\t5\n\t\t\t)\n\t\t\t\tthis.endPrevention();\n\t\t}\n\t};\n\n\tstartPrevention = () => {\n\t\tthis.preventionContainer.classList.remove('JCV-hidden');\n\t\tthis.DM.data.container.classList.add('JCV-numb');\n\t\tthis.preventMt = true;\n\t};\n\n\tendPrevention = () => {\n\t\tthis.preventMt = false;\n\t\tthis.preventionContainer.classList.add('JCV-hidden');\n\t\tsetTimeout(() => this.DM.data.container.classList.remove('JCV-numb'), 50); // minimum delay to prevent triggering undesired button touch\n\t};\n\n\tprivate dispose = () => {\n\t\twindow.removeEventListener('pointerdown', this.onPointerDown);\n\t\twindow.removeEventListener('pointermove', this.onPointerMove);\n\t\twindow.removeEventListener('pointerup', this.onPointerUp);\n\t\tthis.preventionContainer.remove();\n\t\tthis._preventionContainer = null;\n\t};\n}\n"],"mappings":"0LAgBA,IAAqB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AS,KAIhC,cAAyB,GAAoB,CACxC,KAAK,gBAAgB,SACxB,KAAK,gBAAgB,MAAQ,EAAE,QAC/B,KAAK,gBAAgB,MAAQ,EAAE,UAIjC,gBAA4B,CACvB,KAAK,gBAAgB,SACxB,KAAK,gBAAgB,OAAS,GAE7B,KAAK,IAAI,KAAK,gBAAgB,MAAQ,KAAK,gBAAgB,SAAS,CACnE,KAAK,IAAI,KAAK,gBAAgB,MAAQ,KAAK,gBAAgB,SAAS,CACrE,GAEA,KAAK,eAAe,GAIvB,oBAAwB,CACvB,KAAK,oBAAoB,UAAU,OAAO,aAAa,CACvD,KAAK,GAAG,KAAK,UAAU,UAAU,IAAI,WAAW,CAChD,KAAK,UAAY,IAGlB,kBAAsB,CACrB,KAAK,UAAY,GACjB,KAAK,oBAAoB,UAAU,IAAI,aAAa,CACpD,eAAiB,KAAK,GAAG,KAAK,UAAU,UAAU,OAAO,WAAW,CAAE,GAAG,EAG1E,YAAwB,CACvB,OAAO,oBAAoB,cAAe,KAAK,cAAc,CAC7D,OAAO,oBAAoB,cAAe,KAAK,cAAc,CAC7D,OAAO,oBAAoB,YAAa,KAAK,YAAY,CACzD,KAAK,oBAAoB,QAAQ,CACjC,KAAK,qBAAuB"}
1
+ {"version":3,"file":"index.js","names":["style"],"sources":["../../../src/modules/MistouchPreventer/index.ts"],"sourcesContent":["import type { BaseOptions } from '$';\nimport type { BaseArgs } from '$/BaseModule';\nimport { BaseModule } from '$/BaseModule';\nimport DataManager from '$/DataManager';\nimport { applyStyles, destroyError } from '$/utilities';\nimport style from './styles.scss?inline';\n\ntype Options = {\n\tpreventMistouchAtStart?: boolean;\n\tmistouchPreventerBannerText?: string;\n} & BaseOptions;\n\ntype Augmentation = {\n\tstartMistouchPrevention: MistouchPreventer['startPrevention'];\n\tendMistouchPrevention: MistouchPreventer['endPrevention'];\n};\n\nexport default class MistouchPreventer extends BaseModule<Options, Augmentation> {\n\tprivate _preventionContainer?: HTMLDivElement;\n\tprivate preventMt = false;\n\tprivate readonly DM: DataManager;\n\tprivate readonly preventMistouch: {\n\t\trecord: boolean;\n\t\tlastX: number;\n\t\tlastY: number;\n\t\tinitialX: number;\n\t\tinitialY: number;\n\t} = {\n\t\tinitialX: 0,\n\t\tinitialY: 0,\n\t\tlastX: 0,\n\t\tlastY: 0,\n\t\trecord: false,\n\t};\n\n\tprivate get preventionContainer() {\n\t\tif (!this._preventionContainer) throw destroyError;\n\t\treturn this._preventionContainer;\n\t}\n\n\tconstructor(...args: BaseArgs) {\n\t\tsuper(...args);\n\n\t\tconst preventionBanner = document.createElement('div');\n\t\tpreventionBanner.className = 'JCV-prevention-banner JCV-border-shadow-bg';\n\t\tpreventionBanner.textContent =\n\t\t\tthis.options.mistouchPreventerBannerText ?? 'Click on to unlock.';\n\t\tthis.DM = this.container.get(DataManager);\n\t\tthis._preventionContainer = document.createElement('div');\n\t\tthis._preventionContainer.className =\n\t\t\t'JCV-prevention-container JCV-hidden JCV-full JCV-flex-center';\n\n\t\tapplyStyles(this._preventionContainer, style);\n\t\tthis._preventionContainer.appendChild(preventionBanner);\n\t\tthis.DM.data.container.appendChild(this._preventionContainer);\n\n\t\tif (this.options.preventMistouchAtStart) this.startPrevention();\n\n\t\twindow.addEventListener('pointerdown', this.onPointerDown);\n\t\twindow.addEventListener('pointermove', this.onPointerMove);\n\t\twindow.addEventListener('pointerup', this.onPointerUp);\n\n\t\tthis.augment({\n\t\t\tendMistouchPrevention: this.endPrevention,\n\t\t\tstartMistouchPrevention: this.startPrevention,\n\t\t});\n\t\tthis.onDispose(this.dispose);\n\t}\n\n\tprivate readonly onPointerDown = (e: PointerEvent) => {\n\t\tconst bounds = this.DM.data.container.getBoundingClientRect();\n\t\tif (\n\t\t\te.clientX < bounds.left ||\n\t\t\te.clientX > bounds.right ||\n\t\t\te.clientY < bounds.top ||\n\t\t\te.clientY > bounds.bottom\n\t\t) {\n\t\t\tif (!this.preventMt) this.startPrevention();\n\t\t} else if (this.preventMt) {\n\t\t\tthis.preventMistouch.initialX = e.clientX;\n\t\t\tthis.preventMistouch.initialY = e.clientY;\n\t\t\tthis.preventMistouch.lastX = e.clientX;\n\t\t\tthis.preventMistouch.lastY = e.clientY;\n\t\t\tthis.preventMistouch.record = true;\n\t\t}\n\t};\n\n\tprivate readonly onPointerMove = (e: PointerEvent) => {\n\t\tif (this.preventMistouch.record) {\n\t\t\tthis.preventMistouch.lastX = e.clientX;\n\t\t\tthis.preventMistouch.lastY = e.clientY;\n\t\t}\n\t};\n\n\tprivate readonly onPointerUp = () => {\n\t\tif (this.preventMistouch.record) {\n\t\t\tthis.preventMistouch.record = false;\n\t\t\tif (\n\t\t\t\tMath.abs(this.preventMistouch.lastX - this.preventMistouch.initialX) +\n\t\t\t\t\tMath.abs(this.preventMistouch.lastY - this.preventMistouch.initialY) <\n\t\t\t\t5\n\t\t\t)\n\t\t\t\tthis.endPrevention();\n\t\t}\n\t};\n\n\tstartPrevention = () => {\n\t\tthis.preventionContainer.classList.remove('JCV-hidden');\n\t\tthis.DM.data.container.classList.add('JCV-numb');\n\t\tthis.preventMt = true;\n\t};\n\n\tendPrevention = () => {\n\t\tthis.preventMt = false;\n\t\tthis.preventionContainer.classList.add('JCV-hidden');\n\t\tsetTimeout(() => this.DM.data.container.classList.remove('JCV-numb'), 50); // Minimum delay to prevent triggering undesired button touch\n\t};\n\n\tprivate readonly dispose = () => {\n\t\twindow.removeEventListener('pointerdown', this.onPointerDown);\n\t\twindow.removeEventListener('pointermove', this.onPointerMove);\n\t\twindow.removeEventListener('pointerup', this.onPointerUp);\n\t\tthis.preventionContainer.remove();\n\t\tthis._preventionContainer = undefined;\n\t};\n}\n"],"mappings":"wMAiBA,IAAqB,EAArB,cAA+C,CAAkC,CAChF,qBACA,UAAoB,GACpB,GACA,gBAMI,CACH,SAAU,EACV,SAAU,EACV,MAAO,EACP,MAAO,EACP,OAAQ,GACR,CAED,IAAY,qBAAsB,CACjC,GAAI,CAAC,KAAK,qBAAsB,MAAM,EACtC,OAAO,KA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B,MAAQ,KAAK,gBAAgB,SAAS,CACnE,KAAK,IAAI,KAAK,gBAAgB,MAAQ,KAAK,gBAAgB,SAAS,CACrE,GAEA,KAAK,eAAe,GAIvB,oBAAwB,CACvB,KAAK,oBAAoB,UAAU,OAAO,aAAa,CACvD,KAAK,GAAG,KAAK,UAAU,UAAU,IAAI,WAAW,CAChD,KAAK,UAAY,IAGlB,kBAAsB,CACrB,KAAK,UAAY,GACjB,KAAK,oBAAoB,UAAU,IAAI,aAAa,CACpD,eAAiB,KAAK,GAAG,KAAK,UAAU,UAAU,OAAO,WAAW,CAAE,GAAG,EAG1E,YAAiC,CAChC,OAAO,oBAAoB,cAAe,KAAK,cAAc,CAC7D,OAAO,oBAAoB,cAAe,KAAK,cAAc,CAC7D,OAAO,oBAAoB,YAAa,KAAK,YAAY,CACzD,KAAK,oBAAoB,QAAQ,CACjC,KAAK,qBAAuB,IAAA"}
@@ -1,26 +1,26 @@
1
1
  //#region ../shared/index.d.ts
2
2
  type Parser = (markdown: string) => string | Promise<string>;
3
- interface JSONCanvasGroupNode extends JSONCanvasGenericNode {
3
+ type JSONCanvasGroupNode = {
4
4
  type: 'group';
5
5
  label?: string;
6
6
  background?: string;
7
7
  backgroundStyle?: 'cover' | 'ratio' | 'repeat';
8
- }
9
- interface JSONCanvasFileNode extends JSONCanvasGenericNode {
8
+ } & JSONCanvasGenericNode;
9
+ type JSONCanvasFileNode = {
10
10
  type: 'file';
11
11
  file: string;
12
12
  subpath?: string;
13
- }
14
- interface JSONCanvasTextNode extends JSONCanvasGenericNode {
13
+ } & JSONCanvasGenericNode;
14
+ type JSONCanvasTextNode = {
15
15
  type: 'text';
16
16
  text: string;
17
- }
18
- interface JSONCanvasLinkNode extends JSONCanvasGenericNode {
17
+ } & JSONCanvasGenericNode;
18
+ type JSONCanvasLinkNode = {
19
19
  type: 'link';
20
20
  url: string;
21
- }
21
+ } & JSONCanvasGenericNode;
22
22
  type JSONCanvasNode = JSONCanvasGroupNode | JSONCanvasFileNode | JSONCanvasTextNode | JSONCanvasLinkNode;
23
- interface JSONCanvasEdge {
23
+ type JSONCanvasEdge = {
24
24
  id: string;
25
25
  fromNode: string;
26
26
  toNode: string;
@@ -30,12 +30,12 @@ interface JSONCanvasEdge {
30
30
  label?: string;
31
31
  styleAttributes?: Record<string, string>;
32
32
  color?: string;
33
- }
34
- interface JSONCanvas {
33
+ };
34
+ type JSONCanvas = {
35
35
  nodes?: Array<JSONCanvasNode>;
36
36
  edges?: Array<JSONCanvasEdge>;
37
- }
38
- interface JSONCanvasGenericNode {
37
+ };
38
+ type JSONCanvasGenericNode = {
39
39
  id: string;
40
40
  type: 'group' | 'file' | 'text' | 'link';
41
41
  x: number;
@@ -44,7 +44,7 @@ interface JSONCanvasGenericNode {
44
44
  height: number;
45
45
  styleAttributes?: Record<string, string>;
46
46
  color?: string;
47
- }
47
+ };
48
48
  //#endregion
49
49
  export { JSONCanvas, JSONCanvasEdge, JSONCanvasFileNode, JSONCanvasGroupNode, JSONCanvasLinkNode, JSONCanvasNode, JSONCanvasTextNode, Parser };
50
50
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import { JSONCanvas } from "../shared/index.js";
2
2
 
3
- //#region src/utilities/fetchCanvas.d.ts
3
+ //#region src/utilities/fetch-canvas.d.ts
4
4
  declare function fetchCanvas(path: `${string}.canvas` | `${string}.json`): Promise<JSONCanvas>;
5
5
  //#endregion
6
6
  export { fetchCanvas };
7
- //# sourceMappingURL=fetchCanvas.d.ts.map
7
+ //# sourceMappingURL=fetch-canvas.d.ts.map
@@ -1,2 +1,2 @@
1
1
  async function e(e){return await fetch(e).then(e=>e.json())}export{e as default};
2
- //# sourceMappingURL=fetchCanvas.js.map
2
+ //# sourceMappingURL=fetch-canvas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-canvas.js","names":[],"sources":["../../src/utilities/fetch-canvas.ts"],"sourcesContent":["import type { JSONCanvas } from '@repo/shared';\n\nexport default async function fetchCanvas(path: `${string}.canvas` | `${string}.json`) {\n\treturn (await fetch(path).then((res) => res.json())) as JSONCanvas;\n}\n"],"mappings":"AAEA,eAA8B,EAAY,EAA6C,CACtF,OAAQ,MAAM,MAAM,EAAK,CAAC,KAAM,GAAQ,EAAI,MAAM,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { JSONCanvas, Parser } from "../shared/index.js";
2
2
 
3
- //#region src/utilities/renderToString.d.ts
3
+ //#region src/utilities/render-to-string.d.ts
4
4
  declare function renderToString(options: {
5
5
  canvas: JSONCanvas;
6
6
  attachments?: Record<string, string>;
@@ -9,4 +9,4 @@ declare function renderToString(options: {
9
9
  }): Promise<string>;
10
10
  //#endregion
11
11
  export { renderToString };
12
- //# sourceMappingURL=renderToString.d.ts.map
12
+ //# sourceMappingURL=render-to-string.d.ts.map
@@ -0,0 +1,2 @@
1
+ async function e(e){let n=async n=>await t(n,e.parser??(e=>e)),r=e.canvas.nodes??[],i=e.attachmentDir??`./`;r.forEach(t=>{if(t.type===`file`&&!t.file.startsWith(`http`)){let n=t.file.split(`/`).pop()??``;t.file=e.attachments?.[n]??i+n}});let a=[];return await Promise.all(r.map(async e=>a.push(await n(e)))),a.join(``)}async function t(e,t){switch(e.type){case`text`:return await t(e.text);case`file`:return await n(e,t);case`link`:return`<a href="${e.url}" target="_blank" rel="nofollow">${e.url}</a>`;default:return``}}async function n(e,t){return/\.md$/i.exec(e.file)?await r(e.file,t):/\.(png|jpg|jpeg|gif|svg|webp)$/i.exec(e.file)?`<img src="${e.file}" alt="${e.file.split(`/`).pop()}">`:/\.(mp3|wav)$/i.exec(e.file)?`<audio src="${e.file}" controls></audio>`:``}async function r(e,t){let n;try{let r=await(await fetch(e)).text(),i=/^---\n([\s\S]*?)\n---\n([\s\S]*)$/.exec(r);n=await t(i?i[2]:r)}catch{n=`Failed to load content.`}return n}export{e as default};
2
+ //# sourceMappingURL=render-to-string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-to-string.js","names":[],"sources":["../../src/utilities/render-to-string.ts"],"sourcesContent":["import type { JSONCanvas, JSONCanvasFileNode, JSONCanvasNode, Parser } from '@repo/shared';\n\nexport default async function renderToString(options: {\n\tcanvas: JSONCanvas;\n\tattachments?: Record<string, string>;\n\tattachmentDir?: string;\n\tparser?: Parser;\n}) {\n\tconst render = async (node: JSONCanvasNode) =>\n\t\tawait renderer(node, options.parser ?? ((markdown: string) => markdown));\n\tconst nodes = options.canvas.nodes ?? [];\n\tconst basePath = options.attachmentDir ?? './';\n\tnodes.forEach((node) => {\n\t\tif (node.type === 'file' && !node.file.startsWith('http')) {\n\t\t\tconst file = node.file.split('/');\n\t\t\tconst name = file.pop() ?? '';\n\t\t\tnode.file = options.attachments?.[name] ?? basePath + name;\n\t\t}\n\t});\n\tconst renderedContent: Array<string> = [];\n\tawait Promise.all(nodes.map(async (node) => renderedContent.push(await render(node))));\n\treturn renderedContent.join('');\n}\n\nasync function renderer(node: JSONCanvasNode, parse: Parser) {\n\tswitch (node.type) {\n\t\tcase 'text': {\n\t\t\treturn await parse(node.text);\n\t\t}\n\t\tcase 'file': {\n\t\t\treturn await fileProcessor(node, parse);\n\t\t}\n\t\tcase 'link': {\n\t\t\treturn `<a href=\"${node.url}\" target=\"_blank\" rel=\"nofollow\">${node.url}</a>`;\n\t\t}\n\t\tdefault: {\n\t\t\treturn '';\n\t\t}\n\t}\n}\n\nasync function fileProcessor(node: JSONCanvasFileNode, parse: Parser) {\n\tif (/\\.md$/i.exec(node.file)) return await loadMarkdown(node.file, parse);\n\telse if (/\\.(png|jpg|jpeg|gif|svg|webp)$/i.exec(node.file))\n\t\treturn `<img src=\"${node.file}\" alt=\"${node.file.split('/').pop()}\">`;\n\telse if (/\\.(mp3|wav)$/i.exec(node.file)) return `<audio src=\"${node.file}\" controls></audio>`;\n\treturn '';\n}\n\nasync function loadMarkdown(path: string, parse: Parser) {\n\tlet parsedContent: string;\n\ttry {\n\t\tconst response = await fetch(path);\n\t\tconst result = await response.text();\n\t\tconst frontmatterMatch = /^---\\n([\\s\\S]*?)\\n---\\n([\\s\\S]*)$/.exec(result);\n\t\tparsedContent = await parse(frontmatterMatch ? frontmatterMatch[2] : result);\n\t} catch {\n\t\tparsedContent = 'Failed to load content.';\n\t}\n\treturn parsedContent;\n}\n"],"mappings":"AAEA,eAA8B,EAAe,EAK1C,CACF,IAAM,EAAS,KAAO,IACrB,MAAM,EAAS,EAAM,EAAQ,SAAY,GAAqB,GAAU,CACnE,EAAQ,EAAQ,OAAO,OAAS,EAAE,CAClC,EAAW,EAAQ,eAAiB,KAC1C,EAAM,QAAS,GAAS,CACvB,GAAI,EAAK,OAAS,QAAU,CAAC,EAAK,KAAK,WAAW,OAAO,CAAE,CAE1D,IAAM,EADO,EAAK,KAAK,MAAM,IACZ,CAAC,KAAK,EAAI,GAC3B,EAAK,KAAO,EAAQ,cAAc,IAAS,EAAW,IAEtD,CACF,IAAM,EAAiC,EAAE,CAEzC,OADA,MAAM,QAAQ,IAAI,EAAM,IAAI,KAAO,IAAS,EAAgB,KAAK,MAAM,EAAO,EAAK,CAAC,CAAC,CAAC,CAC/E,EAAgB,KAAK,GAAG,CAGhC,eAAe,EAAS,EAAsB,EAAe,CAC5D,OAAQ,EAAK,KAAb,CACC,IAAK,OACJ,OAAO,MAAM,EAAM,EAAK,KAAK,CAE9B,IAAK,OACJ,OAAO,MAAM,EAAc,EAAM,EAAM,CAExC,IAAK,OACJ,MAAO,YAAY,EAAK,IAAI,mCAAmC,EAAK,IAAI,MAEzE,QACC,MAAO,IAKV,eAAe,EAAc,EAA0B,EAAe,CAKrE,MAJI,SAAS,KAAK,EAAK,KAAK,CAAS,MAAM,EAAa,EAAK,KAAM,EAAM,CAChE,kCAAkC,KAAK,EAAK,KAAK,CAClD,aAAa,EAAK,KAAK,SAAS,EAAK,KAAK,MAAM,IAAI,CAAC,KAAK,CAAC,IAC1D,gBAAgB,KAAK,EAAK,KAAK,CAAS,eAAe,EAAK,KAAK,qBACnE,GAGR,eAAe,EAAa,EAAc,EAAe,CACxD,IAAI,EACJ,GAAI,CAEH,IAAM,EAAS,MAAM,MADE,MAAM,EAAK,EACJ,MAAM,CAC9B,EAAmB,oCAAoC,KAAK,EAAO,CACzE,EAAgB,MAAM,EAAM,EAAmB,EAAiB,GAAK,EAAO,MACrE,CACP,EAAgB,0BAEjB,OAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-canvas-viewer",
3
- "version": "4.1.1",
3
+ "version": "4.2.1",
4
4
  "description": "An extensible web-based viewer for JSON Canvas, easy to embed into websites.",
5
5
  "keywords": [
6
6
  "frontend",
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetchCanvas.js","names":[],"sources":["../../src/utilities/fetchCanvas.ts"],"sourcesContent":["import type { JSONCanvas } from '@repo/shared';\n\nexport default async function fetchCanvas(path: `${string}.canvas` | `${string}.json`) {\n\treturn (await fetch(path).then((res) => res.json())) as JSONCanvas;\n}\n"],"mappings":"AAEA,eAA8B,EAAY,EAA6C,CACtF,OAAQ,MAAM,MAAM,EAAK,CAAC,KAAM,GAAQ,EAAI,MAAM,CAAC"}
@@ -1,2 +0,0 @@
1
- async function e(e){let n=async n=>await t(n,e.parser??(e=>e)),r=e.canvas.nodes??[],i=e.attachmentDir??`./`;r.forEach(t=>{if(t.type===`file`&&!t.file.startsWith(`http`)){let n=t.file.split(`/`).pop()??``;e.attachments?.[n]?t.file=e.attachments[n]:t.file=i+n}});let a=[];return await Promise.all(r.map(async e=>a.push(await n(e)))),a.join(``)}async function t(e,t){switch(e.type){case`text`:return await t(e.text);case`file`:return await n(e,t);case`link`:return`<a href="${e.url}" target="_blank" rel="nofollow">${e.url}</a>`;default:return``}}async function n(e,t){return e.file.match(/\.md$/i)?await r(e.file,t):e.file.match(/\.(png|jpg|jpeg|gif|svg|webp)$/i)?`<img src="${e.file}" alt="${e.file.split(`/`).pop()}">`:e.file.match(/\.(mp3|wav)$/i)?`<audio src="${e.file}" controls></audio>`:``}async function r(e,t){let n;try{let r=await(await fetch(e)).text(),i=r.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);n=i?await t(i[2]):await t(r)}catch{n=`Failed to load content.`}return n}export{e as default};
2
- //# sourceMappingURL=renderToString.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renderToString.js","names":[],"sources":["../../src/utilities/renderToString.ts"],"sourcesContent":["import type { JSONCanvas, JSONCanvasFileNode, JSONCanvasNode, Parser } from '@repo/shared';\n\nexport default async function renderToString(options: {\n\tcanvas: JSONCanvas;\n\tattachments?: Record<string, string>;\n\tattachmentDir?: string;\n\tparser?: Parser;\n}) {\n\tconst render = async (node: JSONCanvasNode) =>\n\t\tawait renderer(node, options.parser ?? ((markdown: string) => markdown));\n\tconst nodes = options.canvas.nodes ?? [];\n\tconst basePath = options.attachmentDir ?? './';\n\tnodes.forEach((node) => {\n\t\tif (node.type === 'file' && !node.file.startsWith('http')) {\n\t\t\tconst file = node.file.split('/');\n\t\t\tconst name = file.pop() ?? '';\n\t\t\tif (options.attachments?.[name]) node.file = options.attachments[name];\n\t\t\telse node.file = basePath + name;\n\t\t}\n\t});\n\tconst renderedContent: Array<string> = [];\n\tawait Promise.all(nodes.map(async (node) => renderedContent.push(await render(node))));\n\treturn renderedContent.join('');\n}\n\nasync function renderer(node: JSONCanvasNode, parse: Parser) {\n\tswitch (node.type) {\n\t\tcase 'text':\n\t\t\treturn await parse(node.text);\n\t\tcase 'file':\n\t\t\treturn await fileProcessor(node, parse);\n\t\tcase 'link':\n\t\t\treturn `<a href=\"${node.url}\" target=\"_blank\" rel=\"nofollow\">${node.url}</a>`;\n\t\tdefault:\n\t\t\treturn '';\n\t}\n}\n\nasync function fileProcessor(node: JSONCanvasFileNode, parse: Parser) {\n\tif (node.file.match(/\\.md$/i)) return await loadMarkdown(node.file, parse);\n\telse if (node.file.match(/\\.(png|jpg|jpeg|gif|svg|webp)$/i))\n\t\treturn `<img src=\"${node.file}\" alt=\"${node.file.split('/').pop()}\">`;\n\telse if (node.file.match(/\\.(mp3|wav)$/i)) return `<audio src=\"${node.file}\" controls></audio>`;\n\treturn '';\n}\n\nasync function loadMarkdown(path: string, parse: Parser) {\n\tlet parsedContent: string;\n\ttry {\n\t\tconst response = await fetch(path);\n\t\tconst result = await response.text();\n\t\tconst frontmatterMatch = result.match(/^---\\n([\\s\\S]*?)\\n---\\n([\\s\\S]*)$/);\n\t\tif (frontmatterMatch) parsedContent = await parse(frontmatterMatch[2]);\n\t\telse parsedContent = await parse(result);\n\t} catch {\n\t\tparsedContent = 'Failed to load content.';\n\t}\n\treturn parsedContent;\n}\n"],"mappings":"AAEA,eAA8B,EAAe,EAK1C,CACF,IAAM,EAAS,KAAO,IACrB,MAAM,EAAS,EAAM,EAAQ,SAAY,GAAqB,GAAU,CACnE,EAAQ,EAAQ,OAAO,OAAS,EAAE,CAClC,EAAW,EAAQ,eAAiB,KAC1C,EAAM,QAAS,GAAS,CACvB,GAAI,EAAK,OAAS,QAAU,CAAC,EAAK,KAAK,WAAW,OAAO,CAAE,CAE1D,IAAM,EADO,EAAK,KAAK,MAAM,IACZ,CAAC,KAAK,EAAI,GACvB,EAAQ,cAAc,GAAO,EAAK,KAAO,EAAQ,YAAY,GAC5D,EAAK,KAAO,EAAW,IAE5B,CACF,IAAM,EAAiC,EAAE,CAEzC,OADA,MAAM,QAAQ,IAAI,EAAM,IAAI,KAAO,IAAS,EAAgB,KAAK,MAAM,EAAO,EAAK,CAAC,CAAC,CAAC,CAC/E,EAAgB,KAAK,GAAG,CAGhC,eAAe,EAAS,EAAsB,EAAe,CAC5D,OAAQ,EAAK,KAAb,CACC,IAAK,OACJ,OAAO,MAAM,EAAM,EAAK,KAAK,CAC9B,IAAK,OACJ,OAAO,MAAM,EAAc,EAAM,EAAM,CACxC,IAAK,OACJ,MAAO,YAAY,EAAK,IAAI,mCAAmC,EAAK,IAAI,MACzE,QACC,MAAO,IAIV,eAAe,EAAc,EAA0B,EAAe,CAKrE,OAJI,EAAK,KAAK,M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