json-canvas-viewer 3.3.0 → 3.4.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.
Files changed (72) hide show
  1. package/README.md +145 -156
  2. package/dist/bridges.cjs +1 -1
  3. package/dist/bridges.cjs.map +1 -1
  4. package/dist/bridges.js +1 -1
  5. package/dist/bridges.js.map +1 -1
  6. package/dist/chimp.cjs +1 -1
  7. package/dist/chimp.js +1 -1
  8. package/dist/controller-BRBUPg_j.js +2 -0
  9. package/dist/controller-BRBUPg_j.js.map +1 -0
  10. package/dist/controller-Bc-S4ZVK.cjs +2 -0
  11. package/dist/controller-Bc-S4ZVK.cjs.map +1 -0
  12. package/dist/dev.cjs +1 -1
  13. package/dist/dev.js +1 -1
  14. package/dist/index-DJQyGIFX.js +2 -0
  15. package/dist/index-DJQyGIFX.js.map +1 -0
  16. package/dist/index-DwvIUSbr.cjs +2 -0
  17. package/dist/index-DwvIUSbr.cjs.map +1 -0
  18. package/dist/index.cjs +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/modules.cjs +1 -1
  21. package/dist/modules.cjs.map +1 -1
  22. package/dist/modules.js +1 -1
  23. package/dist/modules.js.map +1 -1
  24. package/dist/react.cjs +2 -0
  25. package/dist/react.cjs.map +1 -0
  26. package/dist/react.js +2 -0
  27. package/dist/react.js.map +1 -0
  28. package/dist/renderToString-ChykAKof.js +2 -0
  29. package/dist/renderToString-ChykAKof.js.map +1 -0
  30. package/dist/renderToString-Cxh5DtRo.cjs +2 -0
  31. package/dist/renderToString-Cxh5DtRo.cjs.map +1 -0
  32. package/dist/renderer-0RqgAOLH.js +2 -0
  33. package/dist/renderer-0RqgAOLH.js.map +1 -0
  34. package/dist/renderer-BEKV7hr3.cjs +2 -0
  35. package/dist/renderer-BEKV7hr3.cjs.map +1 -0
  36. package/dist/types/bridges/reactComponent.d.ts +12 -0
  37. package/dist/types/bridges/vueComponent.vue.d.ts +8 -3
  38. package/dist/types/bridges/webpackPlugin.d.ts +7 -0
  39. package/dist/types/bridges.d.ts +1 -1
  40. package/dist/types/core/baseModule.d.ts +13 -9
  41. package/dist/types/core/controller.d.ts +6 -1
  42. package/dist/types/core/dataManager.d.ts +29 -10
  43. package/dist/types/core/declarations.d.ts +20 -14
  44. package/dist/types/core/index.d.ts +16 -5
  45. package/dist/types/core/interactionHandler.d.ts +3 -1
  46. package/dist/types/core/overlayManager.d.ts +7 -1
  47. package/dist/types/core/renderer.d.ts +10 -4
  48. package/dist/types/core/styleManager.d.ts +48 -0
  49. package/dist/types/core/utilities.d.ts +3 -6
  50. package/dist/types/dev.d.ts +1 -0
  51. package/dist/types/index.d.ts +1 -1
  52. package/dist/types/modules/controls/index.d.ts +4 -1
  53. package/dist/types/modules/minimap/index.d.ts +5 -1
  54. package/dist/types/modules/mistouchPreventer/index.d.ts +7 -5
  55. package/dist/vue.cjs +2 -0
  56. package/dist/vue.cjs.map +1 -0
  57. package/dist/vue.js +2 -0
  58. package/dist/vue.js.map +1 -0
  59. package/dist/webpackLoader.js +33 -0
  60. package/package.json +57 -40
  61. package/dist/controller--Q72jFEw.cjs +0 -2
  62. package/dist/controller--Q72jFEw.cjs.map +0 -1
  63. package/dist/controller-siZ5v-SD.js +0 -2
  64. package/dist/controller-siZ5v-SD.js.map +0 -1
  65. package/dist/index-BSkMdAcV.cjs +0 -2
  66. package/dist/index-BSkMdAcV.cjs.map +0 -1
  67. package/dist/index-u8PUIMyl.js +0 -2
  68. package/dist/index-u8PUIMyl.js.map +0 -1
  69. package/dist/renderer-CZ85ZN6O.js +0 -2
  70. package/dist/renderer-CZ85ZN6O.js.map +0 -1
  71. package/dist/renderer-D9iInH9_.cjs +0 -2
  72. package/dist/renderer-D9iInH9_.cjs.map +0 -1
package/README.md CHANGED
@@ -1,156 +1,145 @@
1
- <h1 align="center">
2
- <img src="assets/logo.svg" alt="JSON Canvas Viewer logo" width="280px">
3
- <br />
4
- JSON Canvas Viewer
5
- <br />
6
- </h1>
7
-
8
- <h4 align="center">An extensible web-based viewer for JSON Canvas</h4>
9
-
10
- <p align="center">
11
- <a href="https://www.npmjs.com/package/json-canvas-viewer">
12
- <img src="https://img.shields.io/npm/v/json-canvas-viewer?logo=npm&labelColor=red&logoColor=white&color=333333" alt="npm">
13
- </a>
14
- <a href="https://bundlephobia.com/package/json-canvas-viewer">
15
- <img src="https://img.shields.io/bundlephobia/minzip/json-canvas-viewer?style=flat&logo=webpack&labelColor=orange&logoColor=white&color=333333&label=Minified%2bGzipped" alt="Gzipped + Minified Size">
16
- </a>
17
- <a href="https://github.com/hesprs/json-canvas-viewer/actions">
18
- <img src="https://img.shields.io/github/actions/workflow/status/hesprs/json-canvas-viewer/ci.yml?style=flat&logo=github&logoColor=white&label=CI&labelColor=d4ab00&color=333333" alt="ci">
19
- </a>
20
- <a href="https://www.codefactor.io/repository/github/hesprs/json-canvas-viewer">
21
- <img src="https://img.shields.io/codefactor/grade/github/hesprs/json-canvas-viewer?style=flat&logo=codefactor&logoColor=white&label=Code%20Quality&labelColor=17b37a&color=333333" alt="CodeFactor">
22
- </a>
23
- <img src="https://img.shields.io/badge/Types-Strict-333333?logo=typescript&labelColor=blue&logoColor=white" alt="TypeScript">
24
- <a href="https://snyk.io/test/npm/json-canvas-viewer">
25
- <img src="https://img.shields.io/badge/Snyk%20Security-Monitored-333333?logo=snyk&style=flat&labelColor=8A2BE2&logoColor=white" alt="Snyk Security">
26
- </a>
27
- <a href="https://github.com/hesprs/json-canvas-viewer/wiki">
28
- <img src="https://img.shields.io/badge/Documentation-Ready-333333?labelColor=5C73E7&logo=github&logoColor=white" alt="Documentation">
29
- </a>
30
- <img src="https://img.shields.io/badge/%F0%9F%96%90%EF%B8%8F%20Made%20by-Humans-333333?labelColor=25C260" alt="Made by Humans">
31
- </p>
32
-
33
- <p align="center">
34
- <a href="https://hesprs.github.io/json-canvas-viewer">
35
- <strong>Demo</strong>
36
- </a>
37
- <a href="https://github.com/hesprs/json-canvas-viewer/wiki">
38
- <strong>Documentation</strong>
39
- </a>
40
- <a href="https://jsoncanvas.org/">
41
- <strong>About JSON Canvas</strong>
42
- </a>
43
- </p>
44
-
45
- ## 🐶 Features
46
-
47
- - View JSON Canvas files (`.canvas`) in a web browser
48
- - Embed into websites easily
49
- - Interactive pan and zoom functionality
50
- - Can display 100% of canvas features described in the [official spec](https://jsoncanvas.org/spec/1.0/)
51
- - Responsive design with mobile and touchpad adaptation
52
- - Supports Lazy loading
53
- - TypeScript native
54
- - 🔥 More performant than rendering canvases in Obsidian!
55
- - 🧩 Out-of-the-box extensibility and tree-shaking, current optional modules include:
56
- - [`Minimap`](https://github.com/hesprs/json-canvas-viewer/wiki/3-%F0%9F%A7%A9-Modules#minimap) for easy navigation
57
- - [`Controls`](https://github.com/hesprs/json-canvas-viewer/wiki/3-%F0%9F%A7%A9-Modules#controls) displays zoom in/out and fullscreen buttons
58
- - [`MistouchPreventer`](https://github.com/hesprs/json-canvas-viewer/wiki/3-%F0%9F%A7%A9-Modules#mistouch-preventer) prevents the canvas from intercepting page scroll.
59
- - [`DebugPanel`](https://github.com/hesprs/json-canvas-viewer/wiki/3-%F0%9F%A7%A9-Modules#debug-panel) displays scale and position data.
60
-
61
- ## 🧩 Integration with Existing Paradigms
62
-
63
- JSON Canvas Viewer currently can work seamlessly with the following techstacks / technologies (including but not limited to):
64
-
65
- - Vanilla JS/TS: natural support
66
- - ✅ Server-side Rendering: [`RenderToString`](https://github.com/hesprs/json-canvas-viewer/wiki/4-%F0%9F%96%87%EF%B8%8F-SSR-and-Bridges#server-side-rendering)
67
- - Vite: [Vite Plugin](https://github.com/hesprs/json-canvas-viewer/wiki/1-%F0%9F%9A%80-Quick-Start#setup-1)
68
- - ✅ Vue: [Vue Component](https://github.com/hesprs/json-canvas-viewer/wiki/4-%F0%9F%96%87%EF%B8%8F-SSR-and-Bridges#vue-component)
69
- - 🟡 React: work in progress, yet it's simply a wrapper around the main `JSONCanvasViewer` class, you can create one in seconds.
70
-
71
- 🙌 Contributors are welcomed!
72
-
73
- ## 🚀 Quick Start
74
-
75
- ### Setup
76
-
77
- You firstly need a markdown-to-HTML parser, which is of the type below:
78
-
79
- ```TypeScript
80
- type MarkdownParser = (markdown: string) => string | Promise<string>;
81
- ```
82
-
83
- For demonstration only, we'll use [Marked](https://github.com/markedjs/marked). **Note that `marked` will be a development dependency, when configured correctly, markdown parsing will happen only at build time.**
84
-
85
- Then we recommend using your favourite package manager to install the package.
86
-
87
- ```sh
88
- # npm
89
- npm add json-canvas-viewer
90
- npm add marked -D
91
-
92
- # pnpm
93
- pnpm add json-canvas-viewer
94
- pnpm add marked -D
95
-
96
- # yarn
97
- yarn add json-canvas-viewer
98
- yarn add marked -D
99
- ```
100
-
101
- You also need to configure your bundler to support seamless canvas resolution. Currently, we only support Vite:
102
-
103
- ```TypeScript
104
- // vite.config.ts
105
- import { defineConfig } from 'vite';
106
- import { jsonCanvasVitePlugin } from 'json-canvas-viewer/bridges';
107
- import { marked } from 'marked';
108
-
109
- export default defineConfig({
110
- // ... your other config
111
- plugins: [
112
- jsonCanvasVitePlugin(marked),
113
- // ... your other plugins
114
- ]
115
- })
116
- ```
117
-
118
- The argument is any markdown parser, when empty, build-time parsing is disabled.
119
-
120
- The setup above gives you:
121
- - bundler resolution of `.canvas` file as modules
122
- - build-time parsing of `.canvas` files (less client-side overhead)
123
- - ease for later framework integration and SSR
124
-
125
- ### Instantiation
126
-
127
- Instantiate the viewer:
128
-
129
- ```TypeScript
130
- import { JSONCanvasViewer } from 'json-canvas-viewer';
131
- import { Minimap } from 'json-canvas-viewer/modules';
132
- import canvasData from 'path/to/your.canvas';
133
-
134
- new JSONCanvasViewer(
135
- {
136
- container: document.body, // The element to attach the viewer to
137
- canvas: canvasData, // The path to the canvas to load
138
- },
139
- [Minimap], // The modules to load
140
- );
141
- ```
142
-
143
- And the viewer should be right there, you can instantiate the viewer multiple times to render multiple canvases.
144
-
145
- ## 🤝 Get Involved
146
-
147
- This project welcomes anyone that have ideas to improve it.
148
-
149
- - [Open a pull request](https://github.com/hesprs/pointeract/compare) for a new module, documentation update, and so on.
150
- - [Open an issue](https://github.com/hesprs/pointeract/issues/new) if you find a bug.
151
- - [Start a new thread in Discussions](https://github.com/hesprs/pointeract/discussions/new) if you have feature requests or questions, please avoid posting them in Issues.
152
- - [Report a vulnerability](https://github.com/hesprs/pointeract/security/advisories/new) if you find one, please do not disclose it publicly.
153
-
154
- ## 📝 Copyright & License
155
-
156
- Copyright ©️ 2025-2026 Hesprs (Hēsperus) | [MIT License](https://mit-license.org/)
1
+ <h1 align="center">
2
+ <img src="assets/logo.svg" alt="JSON Canvas Viewer logo" width="280px">
3
+ <br />
4
+ JSON Canvas Viewer
5
+ <br />
6
+ </h1>
7
+
8
+ <h4 align="center">An extensible web-based viewer for JSON Canvas</h4>
9
+
10
+ <p align="center">
11
+ <a href="https://www.npmjs.com/package/json-canvas-viewer">
12
+ <img src="https://img.shields.io/npm/v/json-canvas-viewer?logo=npm&labelColor=red&logoColor=white&color=333333" alt="npm">
13
+ </a>
14
+ <a href="https://bundlephobia.com/package/json-canvas-viewer">
15
+ <img src="https://img.shields.io/bundlejs/size/json-canvas-viewer?format=minzip&style=flat&logo=webpack&logoColor=white&label=Minzipped%20Size&labelColor=orange&color=333333" alt="Gzipped + Minified Size">
16
+ </a>
17
+ <a href="https://github.com/hesprs/json-canvas-viewer/actions">
18
+ <img src="https://img.shields.io/github/actions/workflow/status/hesprs/json-canvas-viewer/ci.yml?style=flat&logo=github&logoColor=white&label=CI&labelColor=d4ab00&color=333333" alt="ci">
19
+ </a>
20
+ <a href="https://www.codefactor.io/repository/github/hesprs/json-canvas-viewer">
21
+ <img src="https://img.shields.io/codefactor/grade/github/hesprs/json-canvas-viewer?style=flat&logo=codefactor&logoColor=white&label=Code%20Quality&labelColor=17b37a&color=333333" alt="CodeFactor">
22
+ </a>
23
+ <img src="https://img.shields.io/badge/Types-Strict-333333?logo=typescript&labelColor=blue&logoColor=white" alt="TypeScript">
24
+ <a href="https://snyk.io/test/npm/json-canvas-viewer">
25
+ <img src="https://img.shields.io/badge/Snyk%20Security-Monitored-333333?logo=snyk&style=flat&labelColor=8A2BE2&logoColor=white" alt="Snyk Security">
26
+ </a>
27
+ <a href="https://github.com/hesprs/json-canvas-viewer/wiki">
28
+ <img src="https://img.shields.io/badge/Documentation-Ready-333333?labelColor=5C73E7&logo=github&logoColor=white" alt="Documentation">
29
+ </a>
30
+ <img src="https://img.shields.io/badge/%F0%9F%96%90%EF%B8%8F%20Made%20by-Humans-333333?labelColor=25C260" alt="Made by Humans">
31
+ </p>
32
+
33
+ <img align="center" src="./assets/preview.png" alt="preview image with light and dark theme">
34
+
35
+ <p align="center">
36
+ <a href="https://hesprs.github.io/json-canvas-viewer">
37
+ <strong>Demo</strong>
38
+ </a>
39
+ <a href="https://github.com/hesprs/json-canvas-viewer/wiki">
40
+ <strong>Documentation</strong>
41
+ </a>
42
+ <a href="https://jsoncanvas.org/">
43
+ <strong>About JSON Canvas</strong>
44
+ </a>
45
+ </p>
46
+
47
+ ## 🐶 Features
48
+
49
+ - View JSON Canvas files (`.canvas`) in a web browser
50
+ - Embed into websites easily
51
+ - Interactive pan and zoom functionality
52
+ - Can display 100% of canvas features described in the [official spec](https://jsoncanvas.org/spec/1.0/)
53
+ - Responsive design with mobile and touchpad adaptation
54
+ - Supports Lazy loading
55
+ - TypeScript native
56
+ - Modern aesthetics with light and dark mode support
57
+ - A [chimp version](https://github.com/hesprs/json-canvas-viewer/wiki/1-%F0%9F%9A%80-Quick-Start#-chimpanzee-version) specially designed for fast trial is available
58
+ - 🔥 More performant than rendering canvases in Obsidian!
59
+ - 🧩 Out-of-the-box extensibility and tree-shaking, current optional modules include:
60
+ - [`Minimap`](https://github.com/hesprs/json-canvas-viewer/wiki/3-%F0%9F%A7%A9-Modules#minimap) for easy navigation
61
+ - [`Controls`](https://github.com/hesprs/json-canvas-viewer/wiki/3-%F0%9F%A7%A9-Modules#controls) displays zoom in/out and fullscreen buttons
62
+ - [`MistouchPreventer`](https://github.com/hesprs/json-canvas-viewer/wiki/3-%F0%9F%A7%A9-Modules#mistouch-preventer) prevents the canvas from intercepting page scroll.
63
+ - [`DebugPanel`](https://github.com/hesprs/json-canvas-viewer/wiki/3-%F0%9F%A7%A9-Modules#debug-panel) displays scale and position data.
64
+
65
+ ## 🧩 Integration with Existing Paradigms
66
+
67
+ JSON Canvas Viewer currently can work seamlessly with the following techstacks / technologies (including but not limited to):
68
+
69
+ - Vanilla JS/TS: natural support
70
+ - ✅ Prerendering: [`renderToString`](https://github.com/hesprs/json-canvas-viewer/wiki/4-%F0%9F%96%87%EF%B8%8F-Prerendering-and-Bridges#prerendering)
71
+ - Vite: [Vite Plugin](https://github.com/hesprs/json-canvas-viewer/wiki/1-%F0%9F%9A%80-Quick-Start#vite)
72
+ - ✅ Webpack: [Webpack Loader & Plugin](https://github.com/hesprs/json-canvas-viewer/wiki/1-%F0%9F%9A%80-Quick-Start#webpack)
73
+ - Vue: [Vue Component](https://github.com/hesprs/json-canvas-viewer/wiki/4-%F0%9F%96%87%EF%B8%8F-Prerendering-and-Bridges#vue-component)
74
+ - ✅ React: [React Component](https://github.com/hesprs/json-canvas-viewer/wiki/4-%F0%9F%96%87%EF%B8%8F-Prerendering-and-Bridges#react-component)
75
+
76
+ 🙌 Contributions are welcomed!
77
+
78
+ ## 🦾 It's the Age of Agents
79
+
80
+ Your time is expensive, do not spend it on reading the lengthy docs of a niche library. Nowadays coding agents are smart enough to handle the viewer well.
81
+
82
+ Copy and paste the following prompt to OpenCode, ClaudeCode, Cursor or even a chat bot, let it handle everything for you:
83
+
84
+ ```markdown
85
+ I'm using `json-canvas-viewer`, a library to view JSON Canvas (from Obsidian) interactively in a browser. Read its documentations, figure out wether to use `chimp` version or `full` version, and help me with my requirements.
86
+
87
+ **Documentations**:
88
+
89
+ [Readme](https://github.com/hesprs/json-canvas-viewer/raw/refs/heads/main/README.md)
90
+ [Quick Start](https://github.com/hesprs/json-canvas-viewer/raw/refs/heads/main/docs/1-%F0%9F%9A%80-Quick-Start.md)
91
+ [Construction Details](https://github.com/hesprs/json-canvas-viewer/raw/refs/heads/main/docs/2-%F0%9F%8F%97%EF%B8%8F-Construction-Details.md)
92
+ [Modules](https://github.com/hesprs/json-canvas-viewer/raw/refs/heads/main/docs/3-%F0%9F%A7%A9-Modules.md)
93
+ [Prerendering, Vue, and React Integration](https://github.com/hesprs/json-canvas-viewer/raw/refs/heads/main/docs/4-%F0%9F%96%87%EF%B8%8F-Prerendering-and-Bridges.md)
94
+
95
+ **Requirements**:
96
+
97
+ <!-- your requirements here -->
98
+ ```
99
+
100
+ ## 🚀 Manual Trial in 5 Seconds
101
+
102
+ The HTML snippet below uses the `chimp` version of JSON Canvas Viewer. You also need to prepare a canvas file, if you don't have one, you can download one at [here](https://github.com/hesprs/json-canvas-viewer/blob/main/test/demo.canvas).
103
+
104
+ ```HTML
105
+ <!DOCTYPE html>
106
+ <html lang="en">
107
+ <head>
108
+ <meta charset="UTF-8" />
109
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
110
+ <title>🐒 Canvas Viewer</title>
111
+ <style>
112
+ body, html {
113
+ margin: 0;
114
+ padding: 0;
115
+ width: 100%;
116
+ height: 100%;
117
+ }
118
+ </style>
119
+ </head>
120
+ <body></body>
121
+ <script type="module">
122
+ import { JSONCanvasViewer, parser, loadCanvas } from 'https://unpkg.com/json-canvas-viewer/dist/chimp.js';
123
+ new JSONCanvasViewer({
124
+ container: document.body, // The element to attach the viewer to
125
+ canvas: loadCanvas('path/to/your.canvas'), // remember to prepare your canvas
126
+ markdownParser: parser,
127
+ });
128
+ </script>
129
+ </html>
130
+ ```
131
+
132
+ For full elaboration about the instantiation and APIs, please refer to [the documentation](https://github.com/hesprs/json-canvas-viewer/wiki).
133
+
134
+ ## 🤝 Get Involved
135
+
136
+ This project welcomes anyone that have ideas to improve it.
137
+
138
+ - [Open a pull request](https://github.com/hesprs/pointeract/compare) for a new module, documentation update, and so on.
139
+ - [Open an issue](https://github.com/hesprs/pointeract/issues/new) if you find a bug.
140
+ - [Start a new thread in Discussions](https://github.com/hesprs/pointeract/discussions/new) if you have feature requests or questions, please avoid posting them in Issues.
141
+ - [Report a vulnerability](https://github.com/hesprs/pointeract/security/advisories/new) if you find one, please do not disclose it publicly.
142
+
143
+ ## 📝 Copyright & License
144
+
145
+ Copyright ©️ 2025-2026 Hesprs (Hēsperus) | [MIT License](https://mit-license.org/)
package/dist/bridges.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("./index-BSkMdAcV.cjs");async function n(e){const t=t=>function(e,t){switch(e.type){case"text":return t(e.text);case"file":return function(e,t){if(e.file.match(/\.md$/i))return async function(e,t){let n;try{const a=await fetch(e),i=await a.text(),o=i.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);n=o?await t(o[2]):await t(i)}catch{n="Failed to load content."}return n}(e.file,t);if(e.file.match(/\.(png|jpg|jpeg|gif|svg|webp)$/i))return`<img src="${e.file}" alt="${e.file.split("/").pop()}">`;if(e.file.match(/\.(mp3|wav)$/i))return`<audio src="${e.file}" controls></audio>`}(e,t);case"link":return`<a href="${e.url}" target="_blank" rel="nofollow">${e.url}</a>`;default:return""}}(t,e.markdownParser||(e=>e)),n=e.canvas.nodes||[],a=e.attachmentDir||"./";n.forEach(e=>{if("file"===e.type&&!e.file.includes("http")){const t=e.file.split("/");e.file=a+t.pop()}});let i="";return n.forEach(e=>{i+=t(e)}),i}const a=["innerHTML"],i=e.defineComponent({__name:"vueComponent",props:{modules:{},options:{},isSSR:{type:Boolean}},async setup(i){let o,r;const s=i,l=s.isSSR||"undefined"==typeof window,c=e.useTemplateRef("viewerRef");let u=null;const f=l?([o,r]=e.withAsyncContext(()=>n(s.options)),o=await o,r(),o):"";return e.onMounted(()=>{c.value&&(u=new t.JSONCanvasViewer(Object.assign(s.options,{container:c.value}),s.modules))}),e.onUnmounted(()=>{u?.dispose(),u=null}),(t,n)=>(e.openBlock(),e.createElementBlock("section",{ref_key:"viewerRef",ref:c,innerHTML:e.unref(f),style:{"max-height":"100vh","max-width":"100vw"}},null,8,a))}});exports.JSONCanvasViewerVue=i,exports.jsonCanvasVitePlugin=function(e){return{name:"json-canvas-vite-plugin",async transform(t,n){if(!n.endsWith(".canvas"))return null;try{const n=JSON.parse(t);return e&&n.nodes&&await Promise.all(n.nodes.map(async t=>{"text"===t.type&&(t.text=await e(t.text))})),{code:`export default ${JSON.stringify(n)}`,map:null}}catch(a){throw console.error(`[json-canvas] Failed to parse: ${n}`),a}}}},exports.renderToString=n;
1
+ "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./renderToString-Cxh5DtRo.cjs");exports.renderToString=e.renderToString,exports.JSONCanvasWebpackPlugin=class{parser;constructor(e){this.parser=e}apply(e){const t=require.resolve("./webpackLoader");e.options.module.rules.unshift({test:/\.canvas$/,use:[{loader:t,options:{parser:this.parser}}],type:"javascript/auto"})}},exports.jsonCanvasVitePlugin=function(e){return{name:"json-canvas-vite-plugin",async transform(t,r){if(!r.endsWith(".canvas"))return null;try{const r=JSON.parse(t);return e&&r.nodes&&await Promise.all(r.nodes.map(async t=>{"text"===t.type&&(t.text=await e(t.text))})),{code:`export default ${JSON.stringify(r)}`,map:null}}catch(s){throw console.error(`[json-canvas-vite-plugin] Failed to parse: ${r}`),s}}}};
2
2
  //# sourceMappingURL=bridges.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"bridges.cjs","sources":["../src/bridges/renderToString.ts","../src/bridges/vueComponent.vue","../src/bridges/vitePlugin.ts"],"sourcesContent":["import type { MarkdownParser } from '$/declarations';\n\nexport default async function (options: {\n\tcanvas: JSONCanvas;\n\tattachmentDir?: string;\n\tmarkdownParser?: MarkdownParser;\n}) {\n\tconst render = (node: JSONCanvasNode) =>\n\t\trenderer(node, options.markdownParser || ((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.includes('http')) {\n\t\t\tconst file = node.file.split('/');\n\t\t\tnode.file = basePath + file.pop();\n\t\t}\n\t});\n\tlet result = '';\n\tnodes.forEach(node => {\n\t\tresult += render(node);\n\t});\n\treturn result;\n}\n\nfunction renderer(node: JSONCanvasNode, parse: MarkdownParser) {\n\tswitch (node.type) {\n\t\tcase 'text':\n\t\t\treturn parse(node.text);\n\t\tcase 'file':\n\t\t\treturn 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\nfunction fileProcessor(node: JSONCanvasFileNode, parse: MarkdownParser) {\n\tif (node.file.match(/\\.md$/i)) return 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}\n\nasync function loadMarkdown(path: string, parse: MarkdownParser) {\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","<script lang=\"ts\" generic=\"T extends ModuleInputCtor\" setup>\nimport { onMounted, onUnmounted, useTemplateRef } from 'vue';\nimport JSONCanvasViewer from '$';\nimport type { ModuleInputCtor, UserOptions } from '$/declarations';\nimport renderToString from './renderToString';\n\ntype ComponentOptions<T extends ModuleInputCtor> = {\n\tmodules?: T;\n\toptions: Omit<UserOptions<T>, 'container'>;\n\tisSSR?: boolean;\n};\n\nconst props = defineProps<ComponentOptions<T>>();\n\nconst isSSR = props.isSSR || typeof window === 'undefined';\nconst viewerRef = useTemplateRef('viewerRef');\nlet viewer: JSONCanvasViewer<ModuleInputCtor> | null = null;\nconst prerender = isSSR ? await renderToString(props.options) : '';\n\nonMounted(() => {\n\tif (!viewerRef.value) return;\n\tviewer = new JSONCanvasViewer(\n\t\tObject.assign(props.options, { container: viewerRef.value }) as UserOptions<T>,\n\t\tprops.modules,\n\t);\n});\n\nonUnmounted(() => {\n\tviewer?.dispose();\n\tviewer = null;\n});\n</script>\n\n<template>\n\t<section ref=\"viewerRef\" v-html=\"prerender\" style=\"max-height: 100vh; max-width: 100vw;\" />\n</template>\n","import type { MarkdownParser } from '$/declarations';\n\nexport default function (parser?: MarkdownParser) {\n\treturn {\n\t\tname: 'json-canvas-vite-plugin',\n\t\tasync transform(code: string, id: string) {\n\t\t\tif (!id.endsWith('.canvas')) return null;\n\t\t\ttry {\n\t\t\t\tconst json = JSON.parse(code) as JSONCanvas;\n\t\t\t\tif (parser && json.nodes)\n\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\tjson.nodes.map(async node => {\n\t\t\t\t\t\t\tif (node.type === 'text') node.text = await parser(node.text);\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tcode: `export default ${JSON.stringify(json)}`,\n\t\t\t\t\tmap: null,\n\t\t\t\t};\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(`[json-canvas] Failed to parse: ${id}`);\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t},\n\t};\n}\n"],"names":["async","renderToString","options","render","node","parse","type","text","file","match","path","parsedContent","response","fetch","result","frontmatterMatch","loadMarkdown","split","pop","fileProcessor","url","renderer","markdownParser","markdown","nodes","canvas","basePath","attachmentDir","forEach","includes","props","__props","isSSR","window","viewerRef","useTemplateRef","viewer","prerender","__temp","__restore","_withAsyncContext","onMounted","value","JSONCanvasViewer","Object","assign","container","modules","onUnmounted","dispose","_createElementBlock","ref","innerHTML","_unref","style","parser","name","transform","code","id","endsWith","json","JSON","Promise","all","map","stringify","e","console","error"],"mappings":"yIAEAA,eAAAC,EAA+BC,GAK9B,MAAMC,EAAUC,GAiBjB,SAAkBA,EAAsBC,GACvC,OAAQD,EAAKE,MACZ,IAAK,OACJ,OAAOD,EAAMD,EAAKG,MACnB,IAAK,OACJ,OAQH,SAAuBH,EAA0BC,GAChD,GAAID,EAAKI,KAAKC,MAAM,UAAW,OAMhCT,eAA4BU,EAAcL,GACzC,IAAIM,EACJ,IACC,MAAMC,QAAiBC,MAAMH,GACvBI,QAAeF,EAASL,OACxBQ,EAAmBD,EAAOL,MAAM,qCAChBE,EAAlBI,QAAwCV,EAAMU,EAAiB,UACxCV,EAAMS,EAClC,CAAA,MACCH,EAAgB,yBACjB,CACA,OAAOA,CACR,CAlBuCK,CAAaZ,EAAKI,KAAMH,GAAK,GAC1DD,EAAKI,KAAKC,MAAM,mCACxB,MAAO,aAAaL,EAAKI,cAAcJ,EAAKI,KAAKS,MAAM,KAAKC,UAAK,GACzDd,EAAKI,KAAKC,MAAM,iBAAkB,MAAO,eAAeL,EAAKI,yBACvE,CAbUW,CAAcf,EAAMC,GAC5B,IAAK,OACJ,MAAO,YAAYD,EAAKgB,uCAAuChB,EAAKgB,UACrE,QACC,MAAO,GAEV,CA3BEC,CAASjB,EAAMF,EAAQoB,gBAAA,CAAoBC,GAAqBA,IAC3DC,EAAQtB,EAAQuB,OAAOD,OAAS,GAChCE,EAAWxB,EAAQyB,eAAiB,KAC1CH,EAAMI,QAAQxB,IACb,GAAkB,SAAdA,EAAKE,OAAoBF,EAAKI,KAAKqB,SAAS,QAAS,CACxD,MAAMrB,EAAOJ,EAAKI,KAAKS,MAAM,KAC7Bb,EAAKI,KAAOkB,EAAWlB,EAAKU,KAC7B,IAED,IAAIJ,EAAS,GAIb,OAHAU,EAAMI,QAAQxB,IACbU,GAAUX,EAAOC,KAEXU,CACR,4ICVA,MAAMgB,EAAQC,EAERC,EAAQF,EAAME,OAA2B,oBAAXC,OAC9BC,EAAYC,EAAAA,eAAe,aACjC,IAAIC,EAAmD,KACvD,MAAMC,EAAYL,IAAQM,EAAAC,GAAAC,EAAAA,iBAAA,IAAMvC,EAAe6B,EAAM5B,2BAAW,UAEhEuC,EAAAA,UAAU,KACJP,EAAUQ,QACfN,EAAS,IAAIO,EAAAA,iBACZC,OAAOC,OAAOf,EAAM5B,QAAS,CAAE4C,UAAWZ,EAAUQ,QACpDZ,EAAMiB,YAIRC,EAAAA,YAAY,KACXZ,GAAQa,UACRb,EAAS,6BAKTc,EAAAA,mBAA2F,UAAA,SAA9E,YAAJC,IAAIjB,EAAYkB,UAAQC,EAAAA,MAAAhB,GAAWiB,MAAA,CAAA,aAAA,QAAA,YAAA,mFChC7C,SAAyBC,GACxB,MAAO,CACNC,KAAM,0BACN,eAAMC,CAAUC,EAAcC,GAC7B,IAAKA,EAAGC,SAAS,WAAY,OAAO,KACpC,IACC,MAAMC,EAAOC,KAAKzD,MAAMqD,GAOxB,OANIH,GAAUM,EAAKrC,aACZuC,QAAQC,IACbH,EAAKrC,MAAMyC,IAAIjE,MAAMI,IACF,SAAdA,EAAKE,OAAiBF,EAAKG,WAAagD,EAAOnD,EAAKG,UAGpD,CACNmD,KAAM,kBAAkBI,KAAKI,UAAUL,KACvCI,IAAK,KAEP,OAASE,GAER,MADAC,QAAQC,MAAM,kCAAkCV,KAC1CQ,CACP,CACD,EAEF"}
1
+ {"version":3,"file":"bridges.cjs","sources":["../src/bridges/webpackPlugin.ts","../src/bridges/vitePlugin.ts"],"sourcesContent":["import type { MarkdownParser } from '$/declarations';\nimport type { Compiler } from 'webpack';\n\nexport default class JsonCanvasWebpackPlugin {\n\tparser: MarkdownParser;\n\n\tconstructor(parser: MarkdownParser) {\n\t\tthis.parser = parser;\n\t}\n\n\tapply(compiler: Compiler) {\n\t\tconst loaderPath = require.resolve('./webpackLoader');\n\n\t\tcompiler.options.module.rules.unshift({\n\t\t\ttest: /\\.canvas$/,\n\t\t\tuse: [\n\t\t\t\t{\n\t\t\t\t\tloader: loaderPath,\n\t\t\t\t\toptions: { parser: this.parser },\n\t\t\t\t},\n\t\t\t],\n\t\t\t// Prevent Webpack's default JSON handling\n\t\t\ttype: 'javascript/auto',\n\t\t});\n\t}\n}\n","import type { MarkdownParser } from '$/declarations';\n\nexport default function (parser?: MarkdownParser) {\n\treturn {\n\t\tname: 'json-canvas-vite-plugin',\n\t\tasync transform(code: string, id: string) {\n\t\t\tif (!id.endsWith('.canvas')) return null;\n\t\t\ttry {\n\t\t\t\tconst json = JSON.parse(code) as JSONCanvas;\n\t\t\t\tif (parser && json.nodes)\n\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\tjson.nodes.map(async (node) => {\n\t\t\t\t\t\t\tif (node.type === 'text') node.text = await parser(node.text);\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tcode: `export default ${JSON.stringify(json)}`,\n\t\t\t\t\tmap: null,\n\t\t\t\t};\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(`[json-canvas-vite-plugin] Failed to parse: ${id}`);\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t},\n\t};\n}\n"],"names":["parser","constructor","this","apply","compiler","loaderPath","require","options","module","rules","unshift","test","use","loader","type","name","transform","code","id","endsWith","json","JSON","parse","nodes","Promise","all","map","async","node","text","stringify","e","console","error"],"mappings":"8VAGA,MACCA,OAEA,WAAAC,CAAYD,GACXE,KAAKF,OAASA,CACf,CAEA,KAAAG,CAAMC,GACL,MAAMC,EAAaC,gBAAgB,mBAEnCF,EAASG,QAAQC,OAAOC,MAAMC,QAAQ,CACrCC,KAAM,YACNC,IAAK,CACJ,CACCC,OAAQR,EACRE,QAAS,CAAEP,OAAQE,KAAKF,UAI1Bc,KAAM,mBAER,gCCtBD,SAAyBd,GACxB,MAAO,CACNe,KAAM,0BACN,eAAMC,CAAUC,EAAcC,GAC7B,IAAKA,EAAGC,SAAS,WAAY,OAAO,KACpC,IACC,MAAMC,EAAOC,KAAKC,MAAML,GAOxB,OANIjB,GAAUoB,EAAKG,aACZC,QAAQC,IACbL,EAAKG,MAAMG,IAAIC,MAAOC,IACH,SAAdA,EAAKd,OAAiBc,EAAKC,WAAa7B,EAAO4B,EAAKC,UAGpD,CACNZ,KAAM,kBAAkBI,KAAKS,UAAUV,KACvCM,IAAK,KAEP,OAASK,GAER,MADAC,QAAQC,MAAM,8CAA8Cf,KACtDa,CACP,CACD,EAEF"}
package/dist/bridges.js CHANGED
@@ -1,2 +1,2 @@
1
- import{defineComponent as e,useTemplateRef as t,withAsyncContext as n,onMounted as a,onUnmounted as i,createElementBlock as r,openBlock as o,unref as s}from"vue";import{J as l}from"./index-u8PUIMyl.js";async function c(e){const t=t=>function(e,t){switch(e.type){case"text":return t(e.text);case"file":return function(e,t){if(e.file.match(/\.md$/i))return async function(e,t){let n;try{const a=await fetch(e),i=await a.text(),r=i.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);n=r?await t(r[2]):await t(i)}catch{n="Failed to load content."}return n}(e.file,t);if(e.file.match(/\.(png|jpg|jpeg|gif|svg|webp)$/i))return`<img src="${e.file}" alt="${e.file.split("/").pop()}">`;if(e.file.match(/\.(mp3|wav)$/i))return`<audio src="${e.file}" controls></audio>`}(e,t);case"link":return`<a href="${e.url}" target="_blank" rel="nofollow">${e.url}</a>`;default:return""}}(t,e.markdownParser||(e=>e)),n=e.canvas.nodes||[],a=e.attachmentDir||"./";n.forEach(e=>{if("file"===e.type&&!e.file.includes("http")){const t=e.file.split("/");e.file=a+t.pop()}});let i="";return n.forEach(e=>{i+=t(e)}),i}function u(e){return{name:"json-canvas-vite-plugin",async transform(t,n){if(!n.endsWith(".canvas"))return null;try{const n=JSON.parse(t);return e&&n.nodes&&await Promise.all(n.nodes.map(async t=>{"text"===t.type&&(t.text=await e(t.text))})),{code:`export default ${JSON.stringify(n)}`,map:null}}catch(a){throw console.error(`[json-canvas] Failed to parse: ${n}`),a}}}}const f=["innerHTML"],p=/* @__PURE__ */e({__name:"vueComponent",props:{modules:{},options:{},isSSR:{type:Boolean}},async setup(e){let u,p;const m=e,d=m.isSSR||"undefined"==typeof window,w=t("viewerRef");let h=null;const v=d?([u,p]=n(()=>c(m.options)),u=await u,p(),u):"";return a(()=>{w.value&&(h=new l(Object.assign(m.options,{container:w.value}),m.modules))}),i(()=>{h?.dispose(),h=null}),(e,t)=>(o(),r("section",{ref_key:"viewerRef",ref:w,innerHTML:s(v),style:{"max-height":"100vh","max-width":"100vw"}},null,8,f))}});export{p as JSONCanvasViewerVue,u as jsonCanvasVitePlugin,c as renderToString};
1
+ import{r as e}from"./renderToString-ChykAKof.js";function a(e){return{name:"json-canvas-vite-plugin",async transform(a,r){if(!r.endsWith(".canvas"))return null;try{const r=JSON.parse(a);return e&&r.nodes&&await Promise.all(r.nodes.map(async a=>{"text"===a.type&&(a.text=await e(a.text))})),{code:`export default ${JSON.stringify(r)}`,map:null}}catch(s){throw console.error(`[json-canvas-vite-plugin] Failed to parse: ${r}`),s}}}}class r{parser;constructor(e){this.parser=e}apply(e){const a=require.resolve("./webpackLoader");e.options.module.rules.unshift({test:/\.canvas$/,use:[{loader:a,options:{parser:this.parser}}],type:"javascript/auto"})}}export{r as JSONCanvasWebpackPlugin,a as jsonCanvasVitePlugin,e as renderToString};
2
2
  //# sourceMappingURL=bridges.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bridges.js","sources":["../src/bridges/renderToString.ts","../src/bridges/vitePlugin.ts","../src/bridges/vueComponent.vue"],"sourcesContent":["import type { MarkdownParser } from '$/declarations';\n\nexport default async function (options: {\n\tcanvas: JSONCanvas;\n\tattachmentDir?: string;\n\tmarkdownParser?: MarkdownParser;\n}) {\n\tconst render = (node: JSONCanvasNode) =>\n\t\trenderer(node, options.markdownParser || ((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.includes('http')) {\n\t\t\tconst file = node.file.split('/');\n\t\t\tnode.file = basePath + file.pop();\n\t\t}\n\t});\n\tlet result = '';\n\tnodes.forEach(node => {\n\t\tresult += render(node);\n\t});\n\treturn result;\n}\n\nfunction renderer(node: JSONCanvasNode, parse: MarkdownParser) {\n\tswitch (node.type) {\n\t\tcase 'text':\n\t\t\treturn parse(node.text);\n\t\tcase 'file':\n\t\t\treturn 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\nfunction fileProcessor(node: JSONCanvasFileNode, parse: MarkdownParser) {\n\tif (node.file.match(/\\.md$/i)) return 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}\n\nasync function loadMarkdown(path: string, parse: MarkdownParser) {\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","import type { MarkdownParser } from '$/declarations';\n\nexport default function (parser?: MarkdownParser) {\n\treturn {\n\t\tname: 'json-canvas-vite-plugin',\n\t\tasync transform(code: string, id: string) {\n\t\t\tif (!id.endsWith('.canvas')) return null;\n\t\t\ttry {\n\t\t\t\tconst json = JSON.parse(code) as JSONCanvas;\n\t\t\t\tif (parser && json.nodes)\n\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\tjson.nodes.map(async node => {\n\t\t\t\t\t\t\tif (node.type === 'text') node.text = await parser(node.text);\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tcode: `export default ${JSON.stringify(json)}`,\n\t\t\t\t\tmap: null,\n\t\t\t\t};\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(`[json-canvas] Failed to parse: ${id}`);\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t},\n\t};\n}\n","<script lang=\"ts\" generic=\"T extends ModuleInputCtor\" setup>\nimport { onMounted, onUnmounted, useTemplateRef } from 'vue';\nimport JSONCanvasViewer from '$';\nimport type { ModuleInputCtor, UserOptions } from '$/declarations';\nimport renderToString from './renderToString';\n\ntype ComponentOptions<T extends ModuleInputCtor> = {\n\tmodules?: T;\n\toptions: Omit<UserOptions<T>, 'container'>;\n\tisSSR?: boolean;\n};\n\nconst props = defineProps<ComponentOptions<T>>();\n\nconst isSSR = props.isSSR || typeof window === 'undefined';\nconst viewerRef = useTemplateRef('viewerRef');\nlet viewer: JSONCanvasViewer<ModuleInputCtor> | null = null;\nconst prerender = isSSR ? await renderToString(props.options) : '';\n\nonMounted(() => {\n\tif (!viewerRef.value) return;\n\tviewer = new JSONCanvasViewer(\n\t\tObject.assign(props.options, { container: viewerRef.value }) as UserOptions<T>,\n\t\tprops.modules,\n\t);\n});\n\nonUnmounted(() => {\n\tviewer?.dispose();\n\tviewer = null;\n});\n</script>\n\n<template>\n\t<section ref=\"viewerRef\" v-html=\"prerender\" style=\"max-height: 100vh; max-width: 100vw;\" />\n</template>\n"],"names":["async","renderToString","options","render","node","parse","type","text","file","match","path","parsedContent","response","fetch","result","frontmatterMatch","loadMarkdown","split","pop","fileProcessor","url","renderer","markdownParser","markdown","nodes","canvas","basePath","attachmentDir","forEach","includes","vitePlugin","parser","name","transform","code","id","endsWith","json","JSON","Promise","all","map","stringify","e","console","error","props","__props","isSSR","window","viewerRef","useTemplateRef","viewer","prerender","__temp","__restore","_withAsyncContext","onMounted","value","JSONCanvasViewer","Object","assign","container","modules","onUnmounted","dispose","_createElementBlock","ref","innerHTML","_unref","style"],"mappings":"0MAEAA,eAAAC,EAA+BC,GAK9B,MAAMC,EAAUC,GAiBjB,SAAkBA,EAAsBC,GACvC,OAAQD,EAAKE,MACZ,IAAK,OACJ,OAAOD,EAAMD,EAAKG,MACnB,IAAK,OACJ,OAQH,SAAuBH,EAA0BC,GAChD,GAAID,EAAKI,KAAKC,MAAM,UAAW,OAMhCT,eAA4BU,EAAcL,GACzC,IAAIM,EACJ,IACC,MAAMC,QAAiBC,MAAMH,GACvBI,QAAeF,EAASL,OACxBQ,EAAmBD,EAAOL,MAAM,qCAChBE,EAAlBI,QAAwCV,EAAMU,EAAiB,UACxCV,EAAMS,EAClC,CAAA,MACCH,EAAgB,yBACjB,CACA,OAAOA,CACR,CAlBuCK,CAAaZ,EAAKI,KAAMH,GAAK,GAC1DD,EAAKI,KAAKC,MAAM,mCACxB,MAAO,aAAaL,EAAKI,cAAcJ,EAAKI,KAAKS,MAAM,KAAKC,UAAK,GACzDd,EAAKI,KAAKC,MAAM,iBAAkB,MAAO,eAAeL,EAAKI,yBACvE,CAbUW,CAAcf,EAAMC,GAC5B,IAAK,OACJ,MAAO,YAAYD,EAAKgB,uCAAuChB,EAAKgB,UACrE,QACC,MAAO,GAEV,CA3BEC,CAASjB,EAAMF,EAAQoB,gBAAA,CAAoBC,GAAqBA,IAC3DC,EAAQtB,EAAQuB,OAAOD,OAAS,GAChCE,EAAWxB,EAAQyB,eAAiB,KAC1CH,EAAMI,QAAQxB,IACb,GAAkB,SAAdA,EAAKE,OAAoBF,EAAKI,KAAKqB,SAAS,QAAS,CACxD,MAAMrB,EAAOJ,EAAKI,KAAKS,MAAM,KAC7Bb,EAAKI,KAAOkB,EAAWlB,EAAKU,KAC7B,IAED,IAAIJ,EAAS,GAIb,OAHAU,EAAMI,QAAQxB,IACbU,GAAUX,EAAOC,KAEXU,CACR,CCpBA,SAAAgB,EAAyBC,GACxB,MAAO,CACNC,KAAM,0BACN,eAAMC,CAAUC,EAAcC,GAC7B,IAAKA,EAAGC,SAAS,WAAY,OAAO,KACpC,IACC,MAAMC,EAAOC,KAAKjC,MAAM6B,GAOxB,OANIH,GAAUM,EAAKb,aACZe,QAAQC,IACbH,EAAKb,MAAMiB,IAAIzC,MAAMI,IACF,SAAdA,EAAKE,OAAiBF,EAAKG,WAAawB,EAAO3B,EAAKG,UAGpD,CACN2B,KAAM,kBAAkBI,KAAKI,UAAUL,KACvCI,IAAK,KAEP,OAASE,GAER,MADAC,QAAQC,MAAM,kCAAkCV,KAC1CQ,CACP,CACD,EAEF,2ICbA,MAAMG,EAAQC,EAERC,EAAQF,EAAME,OAA2B,oBAAXC,OAC9BC,EAAYC,EAAe,aACjC,IAAIC,EAAmD,KACvD,MAAMC,EAAYL,IAAQM,EAAAC,GAAAC,EAAA,IAAMvD,EAAe6C,EAAM5C,2BAAW,UAEhEuD,EAAU,KACJP,EAAUQ,QACfN,EAAS,IAAIO,EACZC,OAAOC,OAAOf,EAAM5C,QAAS,CAAE4D,UAAWZ,EAAUQ,QACpDZ,EAAMiB,YAIRC,EAAY,KACXZ,GAAQa,UACRb,EAAS,mBAKTc,EAA2F,UAAA,SAA9E,YAAJC,IAAIjB,EAAYkB,UAAQC,EAAAhB,GAAWiB,MAAA,CAAA,aAAA,QAAA,YAAA"}
1
+ {"version":3,"file":"bridges.js","sources":["../src/bridges/vitePlugin.ts","../src/bridges/webpackPlugin.ts"],"sourcesContent":["import type { MarkdownParser } from '$/declarations';\n\nexport default function (parser?: MarkdownParser) {\n\treturn {\n\t\tname: 'json-canvas-vite-plugin',\n\t\tasync transform(code: string, id: string) {\n\t\t\tif (!id.endsWith('.canvas')) return null;\n\t\t\ttry {\n\t\t\t\tconst json = JSON.parse(code) as JSONCanvas;\n\t\t\t\tif (parser && json.nodes)\n\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\tjson.nodes.map(async (node) => {\n\t\t\t\t\t\t\tif (node.type === 'text') node.text = await parser(node.text);\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tcode: `export default ${JSON.stringify(json)}`,\n\t\t\t\t\tmap: null,\n\t\t\t\t};\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(`[json-canvas-vite-plugin] Failed to parse: ${id}`);\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t},\n\t};\n}\n","import type { MarkdownParser } from '$/declarations';\nimport type { Compiler } from 'webpack';\n\nexport default class JsonCanvasWebpackPlugin {\n\tparser: MarkdownParser;\n\n\tconstructor(parser: MarkdownParser) {\n\t\tthis.parser = parser;\n\t}\n\n\tapply(compiler: Compiler) {\n\t\tconst loaderPath = require.resolve('./webpackLoader');\n\n\t\tcompiler.options.module.rules.unshift({\n\t\t\ttest: /\\.canvas$/,\n\t\t\tuse: [\n\t\t\t\t{\n\t\t\t\t\tloader: loaderPath,\n\t\t\t\t\toptions: { parser: this.parser },\n\t\t\t\t},\n\t\t\t],\n\t\t\t// Prevent Webpack's default JSON handling\n\t\t\ttype: 'javascript/auto',\n\t\t});\n\t}\n}\n"],"names":["vitePlugin","parser","name","transform","code","id","endsWith","json","JSON","parse","nodes","Promise","all","map","async","node","type","text","stringify","e","console","error","JsonCanvasWebpackPlugin","constructor","this","apply","compiler","loaderPath","require","options","module","rules","unshift","test","use","loader"],"mappings":"iDAEA,SAAAA,EAAyBC,GACxB,MAAO,CACNC,KAAM,0BACN,eAAMC,CAAUC,EAAcC,GAC7B,IAAKA,EAAGC,SAAS,WAAY,OAAO,KACpC,IACC,MAAMC,EAAOC,KAAKC,MAAML,GAOxB,OANIH,GAAUM,EAAKG,aACZC,QAAQC,IACbL,EAAKG,MAAMG,IAAIC,MAAOC,IACH,SAAdA,EAAKC,OAAiBD,EAAKE,WAAahB,EAAOc,EAAKE,UAGpD,CACNb,KAAM,kBAAkBI,KAAKU,UAAUX,KACvCM,IAAK,KAEP,OAASM,GAER,MADAC,QAAQC,MAAM,8CAA8ChB,KACtDc,CACP,CACD,EAEF,CCtBA,MAAqBG,EACpBrB,OAEA,WAAAsB,CAAYtB,GACXuB,KAAKvB,OAASA,CACf,CAEA,KAAAwB,CAAMC,GACL,MAAMC,EAAaC,gBAAgB,mBAEnCF,EAASG,QAAQC,OAAOC,MAAMC,QAAQ,CACrCC,KAAM,YACNC,IAAK,CACJ,CACCC,OAAQR,EACRE,QAAS,CAAE5B,OAAQuB,KAAKvB,UAI1Be,KAAM,mBAER"}