json-canvas-viewer 4.1.1 → 4.2.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/dist/chimp.js +6 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kernel/BaseModule.d.ts +1 -2
- package/dist/kernel/BaseModule.js.map +1 -1
- package/dist/kernel/Controller.d.ts +10 -10
- package/dist/kernel/Controller.js +1 -1
- package/dist/kernel/Controller.js.map +1 -1
- package/dist/kernel/DataManager.d.ts +15 -15
- package/dist/kernel/DataManager.js +1 -1
- package/dist/kernel/DataManager.js.map +1 -1
- package/dist/kernel/InteractionHandler.d.ts +16 -16
- package/dist/kernel/InteractionHandler.js +1 -1
- package/dist/kernel/InteractionHandler.js.map +1 -1
- package/dist/kernel/OverlayManager.d.ts +27 -20
- package/dist/kernel/OverlayManager.js +1 -1
- package/dist/kernel/OverlayManager.js.map +1 -1
- package/dist/kernel/Renderer.d.ts +22 -21
- package/dist/kernel/Renderer.js +2 -1
- package/dist/kernel/Renderer.js.map +1 -1
- package/dist/kernel/StyleManager.d.ts +34 -34
- package/dist/kernel/StyleManager.js +1 -1
- package/dist/kernel/StyleManager.js.map +1 -1
- package/dist/kernel/index.d.ts +6 -6
- package/dist/kernel/index.js +1 -1
- package/dist/kernel/index.js.map +1 -1
- package/dist/kernel/types.d.ts +1 -1
- package/dist/kernel/utilities.d.ts +1 -27
- package/dist/kernel/utilities.js +1 -1
- package/dist/kernel/utilities.js.map +1 -1
- package/dist/modules/Controls/index.d.ts +14 -14
- package/dist/modules/Controls/index.js +1 -1
- package/dist/modules/Controls/index.js.map +1 -1
- package/dist/modules/DebugPanel/index.d.ts +3 -3
- package/dist/modules/DebugPanel/index.js +1 -1
- package/dist/modules/DebugPanel/index.js.map +1 -1
- package/dist/modules/Minimap/index.d.ts +13 -13
- package/dist/modules/Minimap/index.js +1 -1
- package/dist/modules/Minimap/index.js.map +1 -1
- package/dist/modules/MistouchPreventer/index.d.ts +10 -10
- package/dist/modules/MistouchPreventer/index.js +1 -1
- package/dist/modules/MistouchPreventer/index.js.map +1 -1
- package/dist/shared/index.d.ts +14 -14
- package/dist/utilities/{fetchCanvas.d.ts → fetch-canvas.d.ts} +2 -2
- package/dist/utilities/{fetchCanvas.js → fetch-canvas.js} +1 -1
- package/dist/utilities/fetch-canvas.js.map +1 -0
- package/dist/utilities/{renderToString.d.ts → render-to-string.d.ts} +2 -2
- package/dist/utilities/render-to-string.js +2 -0
- package/dist/utilities/render-to-string.js.map +1 -0
- package/package.json +1 -1
- package/dist/utilities/fetchCanvas.js.map +0 -1
- package/dist/utilities/renderToString.js +0 -2
- package/dist/utilities/renderToString.js.map +0 -1
|
@@ -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
|
-
|
|
5
|
+
type Options = {
|
|
6
6
|
preventMistouchAtStart?: boolean;
|
|
7
7
|
mistouchPreventerBannerText?: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
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
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,
|
|
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 {
|
|
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 | undefined;\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,KAAK,qBAGb,YAAY,GAAG,EAAgB,CAC9B,MAAM,GAAG,EAAK,CAEd,IAAM,EAAmB,SAAS,cAAc,MAAM,CACtD,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EA,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"}
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
//#region ../shared/index.d.ts
|
|
2
2
|
type Parser = (markdown: string) => string | Promise<string>;
|
|
3
|
-
|
|
3
|
+
type JSONCanvasGroupNode = {
|
|
4
4
|
type: 'group';
|
|
5
5
|
label?: string;
|
|
6
6
|
background?: string;
|
|
7
7
|
backgroundStyle?: 'cover' | 'ratio' | 'repeat';
|
|
8
|
-
}
|
|
9
|
-
|
|
8
|
+
} & JSONCanvasGenericNode;
|
|
9
|
+
type JSONCanvasFileNode = {
|
|
10
10
|
type: 'file';
|
|
11
11
|
file: string;
|
|
12
12
|
subpath?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
13
|
+
} & JSONCanvasGenericNode;
|
|
14
|
+
type JSONCanvasTextNode = {
|
|
15
15
|
type: 'text';
|
|
16
16
|
text: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
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
|
-
|
|
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
|
-
|
|
33
|
+
};
|
|
34
|
+
type JSONCanvas = {
|
|
35
35
|
nodes?: Array<JSONCanvasNode>;
|
|
36
36
|
edges?: Array<JSONCanvasEdge>;
|
|
37
|
-
}
|
|
38
|
-
|
|
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/
|
|
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=
|
|
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=
|
|
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/
|
|
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=
|
|
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 +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,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