json-canvas-viewer 3.3.1 → 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.
- package/README.md +145 -156
- package/dist/bridges.cjs +1 -1
- package/dist/bridges.cjs.map +1 -1
- package/dist/bridges.js +1 -1
- package/dist/bridges.js.map +1 -1
- package/dist/chimp.cjs +1 -1
- package/dist/chimp.js +1 -1
- package/dist/controller-BRBUPg_j.js +2 -0
- package/dist/controller-BRBUPg_j.js.map +1 -0
- package/dist/controller-Bc-S4ZVK.cjs +2 -0
- package/dist/controller-Bc-S4ZVK.cjs.map +1 -0
- package/dist/dev.cjs +1 -1
- package/dist/dev.js +1 -1
- package/dist/index-DJQyGIFX.js +2 -0
- package/dist/index-DJQyGIFX.js.map +1 -0
- package/dist/index-DwvIUSbr.cjs +2 -0
- package/dist/index-DwvIUSbr.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/modules.cjs +1 -1
- package/dist/modules.cjs.map +1 -1
- package/dist/modules.js +1 -1
- package/dist/modules.js.map +1 -1
- package/dist/react.cjs +2 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.js +2 -0
- package/dist/react.js.map +1 -0
- package/dist/renderToString-ChykAKof.js +2 -0
- package/dist/renderToString-ChykAKof.js.map +1 -0
- package/dist/renderToString-Cxh5DtRo.cjs +2 -0
- package/dist/renderToString-Cxh5DtRo.cjs.map +1 -0
- package/dist/renderer-0RqgAOLH.js +2 -0
- package/dist/renderer-0RqgAOLH.js.map +1 -0
- package/dist/renderer-BEKV7hr3.cjs +2 -0
- package/dist/renderer-BEKV7hr3.cjs.map +1 -0
- package/dist/types/bridges/reactComponent.d.ts +6 -3
- package/dist/types/bridges/vueComponent.vue.d.ts +7 -2
- package/dist/types/bridges/webpackPlugin.d.ts +7 -0
- package/dist/types/bridges.d.ts +1 -2
- package/dist/types/core/baseModule.d.ts +13 -9
- package/dist/types/core/controller.d.ts +6 -1
- package/dist/types/core/dataManager.d.ts +23 -16
- package/dist/types/core/declarations.d.ts +20 -4
- package/dist/types/core/index.d.ts +16 -5
- package/dist/types/core/interactionHandler.d.ts +3 -1
- package/dist/types/core/overlayManager.d.ts +7 -1
- package/dist/types/core/renderer.d.ts +9 -2
- package/dist/types/core/styleManager.d.ts +48 -0
- package/dist/types/core/utilities.d.ts +3 -6
- package/dist/types/dev.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/modules/controls/index.d.ts +4 -1
- package/dist/types/modules/minimap/index.d.ts +5 -1
- package/dist/types/modules/mistouchPreventer/index.d.ts +7 -5
- package/dist/vue.cjs +2 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.js +2 -0
- package/dist/vue.js.map +1 -0
- package/dist/webpackLoader.js +33 -0
- package/package.json +56 -41
- package/dist/controller-CnUlrkdp.cjs +0 -2
- package/dist/controller-CnUlrkdp.cjs.map +0 -1
- package/dist/controller-UN-hOZ_r.js +0 -2
- package/dist/controller-UN-hOZ_r.js.map +0 -1
- package/dist/index-RXeXyAu0.cjs +0 -2
- package/dist/index-RXeXyAu0.cjs.map +0 -1
- package/dist/index-ujiv9m9Y.js +0 -2
- package/dist/index-ujiv9m9Y.js.map +0 -1
- package/dist/renderer-Bzv3aLXp.cjs +0 -2
- package/dist/renderer-Bzv3aLXp.cjs.map +0 -1
- package/dist/renderer-NPxavnke.js +0 -2
- package/dist/renderer-NPxavnke.js.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/
|
|
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
|
-
<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
</
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
55
|
-
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
- ✅
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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("
|
|
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
|
package/dist/bridges.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridges.cjs","sources":["../src/bridges/
|
|
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{
|
|
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
|
package/dist/bridges.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridges.js","sources":["../src/bridges/
|
|
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"}
|