@floffah/astro-typst 0.0.0 → 0.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -22
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -6
- package/dist/loader-C5JXSvPj.js +2 -0
- package/dist/{loader-CxNOQzU1.js.map → loader-C5JXSvPj.js.map} +1 -1
- package/dist/loader-H5uKHfiV.cjs +2 -0
- package/dist/{loader-DetFooDG.cjs.map → loader-H5uKHfiV.cjs.map} +1 -1
- package/dist/loader.cjs +1 -4
- package/dist/loader.js +1 -3
- package/dist/render-DA5hfbvx.js +2 -0
- package/dist/{render-hwAGjpa0.js.map → render-DA5hfbvx.js.map} +1 -1
- package/dist/render-Oy9Sy3-q.cjs +2 -0
- package/dist/render-Oy9Sy3-q.cjs.map +1 -0
- package/dist/vite.cjs +1 -24
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.js +1 -23
- package/dist/vite.js.map +1 -1
- package/dist/wasm-BSRnB8hH.cjs +2 -0
- package/dist/wasm-BSRnB8hH.cjs.map +1 -0
- package/dist/wasm-Bp_4rcoG.d.ts +11 -0
- package/dist/wasm-DcPE0DPA.d.cts +11 -0
- package/dist/wasm-j2mRjvaE.js +2 -0
- package/dist/wasm-j2mRjvaE.js.map +1 -0
- package/dist/wasm.cjs +1 -15
- package/dist/wasm.d.cts +1 -1
- package/dist/wasm.d.ts +1 -1
- package/dist/wasm.js +1 -3
- package/package.json +5 -3
- package/wasm/package.json +1 -1
- package/wasm/typst_wasm.d.ts +34 -0
- package/wasm/typst_wasm.js +102 -9
- package/wasm/typst_wasm_bg.wasm +0 -0
- package/dist/loader-CxNOQzU1.js +0 -109
- package/dist/loader-DetFooDG.cjs +0 -114
- package/dist/render-UEphEA_d.cjs +0 -69
- package/dist/render-UEphEA_d.cjs.map +0 -1
- package/dist/render-hwAGjpa0.js +0 -58
package/dist/index.cjs
CHANGED
|
@@ -1,22 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_loader = require('./loader-DetFooDG.cjs');
|
|
3
|
-
const require_render = require('./render-UEphEA_d.cjs');
|
|
4
|
-
const require_vite = require('./vite.cjs');
|
|
5
|
-
let wasm_typst_wasm_js = require("../wasm/typst_wasm.js");
|
|
6
|
-
|
|
7
|
-
exports.compileTypst = require_render.compileTypst;
|
|
8
|
-
exports.renderTypst = require_render.renderTypst;
|
|
9
|
-
exports.typst = require_vite.typst;
|
|
10
|
-
exports.typstLoader = require_loader.typstLoader;
|
|
11
|
-
Object.defineProperty(exports, 'typstToHtml', {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () {
|
|
14
|
-
return wasm_typst_wasm_js.typstToHtml;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(exports, 'typstToHtmlWithMetadata', {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () {
|
|
20
|
-
return wasm_typst_wasm_js.typstToHtmlWithMetadata;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./loader-H5uKHfiV.cjs`),t=require(`./wasm-BSRnB8hH.cjs`),n=require(`./render-Oy9Sy3-q.cjs`),r=require(`./vite.cjs`);exports.compileTypst=n.t,exports.renderTypst=n.n,exports.typst=r.typst,exports.typstLoader=e.t,exports.typstToHtml=t.t,exports.typstToHtmlWithMetadata=t.n;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TypstLoaderOptions, typstLoader } from "./loader.cjs";
|
|
2
2
|
import { TypstPluginOptions, typst } from "./vite.cjs";
|
|
3
|
-
import {
|
|
3
|
+
import { n as typstToHtmlWithMetadata, t as typstToHtml } from "./wasm-DcPE0DPA.cjs";
|
|
4
4
|
import { MarkdownHeading } from "astro";
|
|
5
5
|
|
|
6
6
|
//#region src/render.d.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TypstLoaderOptions, typstLoader } from "./loader.js";
|
|
2
2
|
import { TypstPluginOptions, typst } from "./vite.js";
|
|
3
|
-
import {
|
|
3
|
+
import { n as typstToHtmlWithMetadata, t as typstToHtml } from "./wasm-Bp_4rcoG.js";
|
|
4
4
|
import { MarkdownHeading } from "astro";
|
|
5
5
|
|
|
6
6
|
//#region src/render.d.ts
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { typstToHtml, typstToHtmlWithMetadata } from "./wasm.js";
|
|
3
|
-
import { n as renderTypst, t as compileTypst } from "./render-hwAGjpa0.js";
|
|
4
|
-
import { typst } from "./vite.js";
|
|
5
|
-
|
|
6
|
-
export { compileTypst, renderTypst, typst, typstLoader, typstToHtml, typstToHtmlWithMetadata };
|
|
1
|
+
import{t as e}from"./loader-C5JXSvPj.js";import{n as t,t as n}from"./wasm-j2mRjvaE.js";import{n as r,t as i}from"./render-DA5hfbvx.js";import{typst as a}from"./vite.js";export{i as compileTypst,r as renderTypst,a as typst,e as typstLoader,n as typstToHtml,t as typstToHtmlWithMetadata};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./render-DA5hfbvx.js";import{relative as t,resolve as n,sep as r}from"node:path";import{glob as i,readFile as a}from"node:fs/promises";import{fileURLToPath as o}from"node:url";function s(e){return e.split(r).join(`/`)}function c(e){let t=e.split(`/`).at(-1);return e.endsWith(`.typ`)&&e!==`..`&&!e.startsWith(`../`)&&!t?.startsWith(`_`)}function l(e){let t=e.slice(0,-4);return t.endsWith(`/index`)?t.slice(0,-6):t}function u({base:r=`src/content`}={}){return{name:`astro-typst-loader`,async load({config:u,generateDigest:d,logger:f,parseData:p,store:m,watcher:h}){let g=o(u.root),_=o(new URL(r.endsWith(`/`)?r:`${r}/`,u.root));async function v(){let r=[];for await(let e of i(`**/*.typ`,{cwd:_}))c(s(e))&&r.push(n(_,e));r.length===0&&f.warn(`No Typst files found in ${_}`);let o=await Promise.all(r.map(async n=>{let r=l(s(t(_,n))),i=await a(n,`utf8`),o=e(i);return{id:r,source:i,data:await p({id:r,data:o.metadata,filePath:n}),html:o.html,headings:o.headings,filePath:s(t(g,n)),digest:d(JSON.stringify({source:i,html:o.html}))}}));o.sort((e,t)=>e.id.localeCompare(t.id));let u=new Set;for(let e of o){if(u.has(e.id))throw Error(`More than one Typst content file resolves to id "${e.id}"`);u.add(e.id)}let h=new Set(m.keys());for(let e of o)h.delete(e.id),m.set({id:e.id,data:e.data,body:e.source,digest:e.digest,filePath:e.filePath,rendered:{html:e.html,metadata:{headings:e.headings}}});h.forEach(e=>m.delete(e))}if(await v(),!h)return;h.add(_);let y,b=!1,x=async e=>{let n=s(t(_,e));if(c(n))try{b=!0,y??=(async()=>{for(;b;)b=!1,await v()})().finally(()=>{y=void 0}),await y,f.info(`Reloaded Typst content after ${n}`)}catch(e){let t=e instanceof Error?e.message:String(e);f.error(`Failed to reload Typst content after ${n}: ${t}`)}};h.on(`add`,x),h.on(`change`,x),h.on(`unlink`,x)}}}export{u as t};
|
|
2
|
+
//# sourceMappingURL=loader-C5JXSvPj.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-
|
|
1
|
+
{"version":3,"file":"loader-C5JXSvPj.js","names":[],"sources":["../src/paths.ts","../src/loader.ts"],"sourcesContent":["import { sep } from \"node:path\";\n\nexport function toPosixPath(path: string): string {\n return path.split(sep).join(\"/\");\n}\n\nexport function isTypstEntryPath(path: string): boolean {\n const fileName = path.split(\"/\").at(-1);\n\n return (\n path.endsWith(\".typ\") &&\n path !== \"..\" &&\n !path.startsWith(\"../\") &&\n !fileName?.startsWith(\"_\")\n );\n}\n\nexport function typstEntryId(path: string): string {\n const id = path.slice(0, -\".typ\".length);\n return id.endsWith(\"/index\") ? id.slice(0, -\"/index\".length) : id;\n}\n","import { isTypstEntryPath, toPosixPath, typstEntryId } from \"./paths.js\";\nimport { type CompiledTypst, compileTypst } from \"./render.js\";\nimport type { Loader } from \"astro/loaders\";\nimport { glob, readFile } from \"node:fs/promises\";\nimport { relative, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport interface TypstLoaderOptions {\n /** Directory containing Typst entries, resolved relative to Astro's root. */\n base?: string;\n}\n\ninterface CompiledEntry {\n id: string;\n source: string;\n data: Record<string, unknown>;\n html: string;\n headings: CompiledTypst[\"headings\"];\n filePath: string;\n digest: string;\n}\n\nexport function typstLoader({\n base = \"src/content\",\n}: TypstLoaderOptions = {}): Loader {\n return {\n name: \"astro-typst-loader\",\n async load({\n config,\n generateDigest,\n logger,\n parseData,\n store,\n watcher,\n }) {\n const rootPath = fileURLToPath(config.root);\n const basePath = fileURLToPath(\n new URL(base.endsWith(\"/\") ? base : `${base}/`, config.root),\n );\n\n async function rebuildAll(): Promise<void> {\n const filePaths: string[] = [];\n for await (const entry of glob(\"**/*.typ\", { cwd: basePath })) {\n const entryPath = toPosixPath(entry);\n if (isTypstEntryPath(entryPath))\n filePaths.push(resolve(basePath, entry));\n }\n\n if (filePaths.length === 0)\n logger.warn(`No Typst files found in ${basePath}`);\n\n const entries = await Promise.all(\n filePaths.map(async (filePath): Promise<CompiledEntry> => {\n const entryPath = toPosixPath(\n relative(basePath, filePath),\n );\n const id = typstEntryId(entryPath);\n const source = await readFile(filePath, \"utf8\");\n const compiled = compileTypst(source);\n const data = (await parseData({\n id,\n data: compiled.metadata,\n filePath,\n })) as Record<string, unknown>;\n\n return {\n id,\n source,\n data,\n html: compiled.html,\n headings: compiled.headings,\n filePath: toPosixPath(relative(rootPath, filePath)),\n digest: generateDigest(\n JSON.stringify({ source, html: compiled.html }),\n ),\n };\n }),\n );\n\n entries.sort((left, right) => left.id.localeCompare(right.id));\n const entryIds = new Set<string>();\n for (const entry of entries) {\n if (entryIds.has(entry.id)) {\n throw new Error(\n `More than one Typst content file resolves to id \"${entry.id}\"`,\n );\n }\n entryIds.add(entry.id);\n }\n\n const untouchedEntries = new Set(store.keys());\n for (const entry of entries) {\n untouchedEntries.delete(entry.id);\n store.set({\n id: entry.id,\n data: entry.data,\n body: entry.source,\n digest: entry.digest,\n filePath: entry.filePath,\n rendered: {\n html: entry.html,\n metadata: { headings: entry.headings },\n },\n });\n }\n untouchedEntries.forEach((id) => store.delete(id));\n }\n\n await rebuildAll();\n if (!watcher) return;\n\n watcher.add(basePath);\n let activeRebuild: Promise<void> | undefined;\n let rebuildAgain = false;\n\n const reload = async (filePath: string): Promise<void> => {\n const entryPath = toPosixPath(relative(basePath, filePath));\n if (!isTypstEntryPath(entryPath)) return;\n\n try {\n rebuildAgain = true;\n activeRebuild ??= (async () => {\n while (rebuildAgain) {\n rebuildAgain = false;\n await rebuildAll();\n }\n })().finally(() => {\n activeRebuild = undefined;\n });\n await activeRebuild;\n logger.info(`Reloaded Typst content after ${entryPath}`);\n } catch (error) {\n const message =\n error instanceof Error ? error.message : String(error);\n logger.error(\n `Failed to reload Typst content after ${entryPath}: ${message}`,\n );\n }\n };\n\n watcher.on(\"add\", reload);\n watcher.on(\"change\", reload);\n watcher.on(\"unlink\", reload);\n },\n };\n}\n"],"mappings":"mMAEA,SAAgB,EAAY,EAAsB,CAC9C,OAAO,EAAK,MAAM,EAAI,CAAC,KAAK,IAAI,CAGpC,SAAgB,EAAiB,EAAuB,CACpD,IAAM,EAAW,EAAK,MAAM,IAAI,CAAC,GAAG,GAAG,CAEvC,OACI,EAAK,SAAS,OAAO,EACrB,IAAS,MACT,CAAC,EAAK,WAAW,MAAM,EACvB,CAAC,GAAU,WAAW,IAAI,CAIlC,SAAgB,EAAa,EAAsB,CAC/C,IAAM,EAAK,EAAK,MAAM,EAAG,GAAe,CACxC,OAAO,EAAG,SAAS,SAAS,CAAG,EAAG,MAAM,EAAG,GAAiB,CAAG,ECGnE,SAAgB,EAAY,CACxB,OAAO,eACa,EAAE,CAAU,CAChC,MAAO,CACH,KAAM,q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EAAM,KACZ,KAAM,EAAM,OACZ,OAAQ,EAAM,OACd,SAAU,EAAM,SAChB,SAAU,CACN,KAAM,EAAM,KACZ,SAAU,CAAE,SAAU,EAAM,SAAU,CACzC,CACJ,CAAC,CAEN,EAAiB,QAAS,GAAO,EAAM,OAAO,EAAG,CAAC,CAItD,GADA,MAAM,GAAY,CACd,CAAC,EAAS,OAEd,EAAQ,IAAI,EAAS,CACrB,IAAI,EACA,EAAe,GAEb,EAAS,KAAO,IAAoC,CACtD,IAAM,EAAY,EAAY,EAAS,EAAU,EAAS,CAAC,CACtD,KAAiB,EAAU,CAEhC,GAAI,CACA,EAAe,GACf,KAAmB,SAAY,CAC3B,KAAO,GACH,EAAe,GACf,MAAM,GAAY,IAEtB,CAAC,YAAc,CACf,EAAgB,IAAA,IAClB,CACF,MAAM,EACN,EAAO,KAAK,gCAAgC,IAAY,OACnD,EAAO,CACZ,IAAM,EACF,aAAiB,MAAQ,EAAM,QAAU,OAAO,EAAM,CAC1D,EAAO,MACH,wCAAwC,EAAU,IAAI,IACzD,GAIT,EAAQ,GAAG,MAAO,EAAO,CACzB,EAAQ,GAAG,SAAU,EAAO,CAC5B,EAAQ,GAAG,SAAU,EAAO,EAEnC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`./render-Oy9Sy3-q.cjs`);let t=require(`node:path`),n=require(`node:fs/promises`),r=require(`node:url`);function i(e){return e.split(t.sep).join(`/`)}function a(e){let t=e.split(`/`).at(-1);return e.endsWith(`.typ`)&&e!==`..`&&!e.startsWith(`../`)&&!t?.startsWith(`_`)}function o(e){let t=e.slice(0,-4);return t.endsWith(`/index`)?t.slice(0,-6):t}function s({base:s=`src/content`}={}){return{name:`astro-typst-loader`,async load({config:c,generateDigest:l,logger:u,parseData:d,store:f,watcher:p}){let m=(0,r.fileURLToPath)(c.root),h=(0,r.fileURLToPath)(new URL(s.endsWith(`/`)?s:`${s}/`,c.root));async function g(){let r=[];for await(let e of(0,n.glob)(`**/*.typ`,{cwd:h}))a(i(e))&&r.push((0,t.resolve)(h,e));r.length===0&&u.warn(`No Typst files found in ${h}`);let s=await Promise.all(r.map(async r=>{let a=o(i((0,t.relative)(h,r))),s=await(0,n.readFile)(r,`utf8`),c=e.t(s);return{id:a,source:s,data:await d({id:a,data:c.metadata,filePath:r}),html:c.html,headings:c.headings,filePath:i((0,t.relative)(m,r)),digest:l(JSON.stringify({source:s,html:c.html}))}}));s.sort((e,t)=>e.id.localeCompare(t.id));let c=new Set;for(let e of s){if(c.has(e.id))throw Error(`More than one Typst content file resolves to id "${e.id}"`);c.add(e.id)}let p=new Set(f.keys());for(let e of s)p.delete(e.id),f.set({id:e.id,data:e.data,body:e.source,digest:e.digest,filePath:e.filePath,rendered:{html:e.html,metadata:{headings:e.headings}}});p.forEach(e=>f.delete(e))}if(await g(),!p)return;p.add(h);let _,v=!1,y=async e=>{let n=i((0,t.relative)(h,e));if(a(n))try{v=!0,_??=(async()=>{for(;v;)v=!1,await g()})().finally(()=>{_=void 0}),await _,u.info(`Reloaded Typst content after ${n}`)}catch(e){let t=e instanceof Error?e.message:String(e);u.error(`Failed to reload Typst content after ${n}: ${t}`)}};p.on(`add`,y),p.on(`change`,y),p.on(`unlink`,y)}}}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return s}});
|
|
2
|
+
//# sourceMappingURL=loader-H5uKHfiV.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-
|
|
1
|
+
{"version":3,"file":"loader-H5uKHfiV.cjs","names":["sep","compileTypst"],"sources":["../src/paths.ts","../src/loader.ts"],"sourcesContent":["import { sep } from \"node:path\";\n\nexport function toPosixPath(path: string): string {\n return path.split(sep).join(\"/\");\n}\n\nexport function isTypstEntryPath(path: string): boolean {\n const fileName = path.split(\"/\").at(-1);\n\n return (\n path.endsWith(\".typ\") &&\n path !== \"..\" &&\n !path.startsWith(\"../\") &&\n !fileName?.startsWith(\"_\")\n );\n}\n\nexport function typstEntryId(path: string): string {\n const id = path.slice(0, -\".typ\".length);\n return id.endsWith(\"/index\") ? id.slice(0, -\"/index\".length) : id;\n}\n","import { isTypstEntryPath, toPosixPath, typstEntryId } from \"./paths.js\";\nimport { type CompiledTypst, compileTypst } from \"./render.js\";\nimport type { Loader } from \"astro/loaders\";\nimport { glob, readFile } from \"node:fs/promises\";\nimport { relative, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport interface TypstLoaderOptions {\n /** Directory containing Typst entries, resolved relative to Astro's root. */\n base?: string;\n}\n\ninterface CompiledEntry {\n id: string;\n source: string;\n data: Record<string, unknown>;\n html: string;\n headings: CompiledTypst[\"headings\"];\n filePath: string;\n digest: string;\n}\n\nexport function typstLoader({\n base = \"src/content\",\n}: TypstLoaderOptions = {}): Loader {\n return {\n name: \"astro-typst-loader\",\n async load({\n config,\n generateDigest,\n logger,\n parseData,\n store,\n watcher,\n }) {\n const rootPath = fileURLToPath(config.root);\n const basePath = fileURLToPath(\n new URL(base.endsWith(\"/\") ? base : `${base}/`, config.root),\n );\n\n async function rebuildAll(): Promise<void> {\n const filePaths: string[] = [];\n for await (const entry of glob(\"**/*.typ\", { cwd: basePath })) {\n const entryPath = toPosixPath(entry);\n if (isTypstEntryPath(entryPath))\n filePaths.push(resolve(basePath, entry));\n }\n\n if (filePaths.length === 0)\n logger.warn(`No Typst files found in ${basePath}`);\n\n const entries = await Promise.all(\n filePaths.map(async (filePath): Promise<CompiledEntry> => {\n const entryPath = toPosixPath(\n relative(basePath, filePath),\n );\n const id = typstEntryId(entryPath);\n const source = await readFile(filePath, \"utf8\");\n const compiled = compileTypst(source);\n const data = (await parseData({\n id,\n data: compiled.metadata,\n filePath,\n })) as Record<string, unknown>;\n\n return {\n id,\n source,\n data,\n html: compiled.html,\n headings: compiled.headings,\n filePath: toPosixPath(relative(rootPath, filePath)),\n digest: generateDigest(\n JSON.stringify({ source, html: compiled.html }),\n ),\n };\n }),\n );\n\n entries.sort((left, right) => left.id.localeCompare(right.id));\n const entryIds = new Set<string>();\n for (const entry of entries) {\n if (entryIds.has(entry.id)) {\n throw new Error(\n `More than one Typst content file resolves to id \"${entry.id}\"`,\n );\n }\n entryIds.add(entry.id);\n }\n\n const untouchedEntries = new Set(store.keys());\n for (const entry of entries) {\n untouchedEntries.delete(entry.id);\n store.set({\n id: entry.id,\n data: entry.data,\n body: entry.source,\n digest: entry.digest,\n filePath: entry.filePath,\n rendered: {\n html: entry.html,\n metadata: { headings: entry.headings },\n },\n });\n }\n untouchedEntries.forEach((id) => store.delete(id));\n }\n\n await rebuildAll();\n if (!watcher) return;\n\n watcher.add(basePath);\n let activeRebuild: Promise<void> | undefined;\n let rebuildAgain = false;\n\n const reload = async (filePath: string): Promise<void> => {\n const entryPath = toPosixPath(relative(basePath, filePath));\n if (!isTypstEntryPath(entryPath)) return;\n\n try {\n rebuildAgain = true;\n activeRebuild ??= (async () => {\n while (rebuildAgain) {\n rebuildAgain = false;\n await rebuildAll();\n }\n })().finally(() => {\n activeRebuild = undefined;\n });\n await activeRebuild;\n logger.info(`Reloaded Typst content after ${entryPath}`);\n } catch (error) {\n const message =\n error instanceof Error ? error.message : String(error);\n logger.error(\n `Failed to reload Typst content after ${entryPath}: ${message}`,\n );\n }\n };\n\n watcher.on(\"add\", reload);\n watcher.on(\"change\", reload);\n watcher.on(\"unlink\", reload);\n },\n };\n}\n"],"mappings":"wHAEA,SAAgB,EAAY,EAAsB,CAC9C,OAAO,EAAK,MAAMA,EAAAA,IAAI,CAAC,KAAK,IAAI,CAGpC,SAAgB,EAAiB,EAAuB,CACpD,IAAM,EAAW,EAAK,MAAM,IAAI,CAAC,GAAG,GAAG,CAEvC,OACI,EAAK,SAAS,OAAO,EACrB,IAAS,MACT,CAAC,EAAK,WAAW,MAAM,EACvB,CAAC,GAAU,WAAW,IAAI,CAIlC,SAAgB,EAAa,EAAsB,CAC/C,IAAM,EAAK,EAAK,MAAM,EAAG,GAAe,CACxC,OAAO,EAAG,SAAS,SAAS,CAA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EAAM,GAAG,GAChE,CAEL,EAAS,IAAI,EAAM,GAAG,CAG1B,IAAM,EAAmB,IAAI,IAAI,EAAM,MAAM,CAAC,CAC9C,IAAK,IAAM,KAAS,EAChB,EAAiB,OAAO,EAAM,GAAG,CACjC,EAAM,IAAI,CACN,GAAI,EAAM,GACV,KAAM,EAAM,KACZ,KAAM,EAAM,OACZ,OAAQ,EAAM,OACd,SAAU,EAAM,SAChB,SAAU,CACN,KAAM,EAAM,KACZ,SAAU,CAAE,SAAU,EAAM,SAAU,CACzC,CACJ,CAAC,CAEN,EAAiB,QAAS,GAAO,EAAM,OAAO,EAAG,CAAC,CAItD,GADA,MAAM,GAAY,CACd,CAAC,EAAS,OAEd,EAAQ,IAAI,EAAS,CACrB,IAAI,EACA,EAAe,GAEb,EAAS,KAAO,IAAoC,CACtD,IAAM,EAAY,GAAA,EAAA,EAAA,UAAqB,EAAU,EAAS,CAAC,CACtD,KAAiB,EAAU,CAEhC,GAAI,CACA,EAAe,GACf,KAAmB,SAAY,CAC3B,KAAO,GACH,EAAe,GACf,MAAM,GAAY,IAEtB,CAAC,YAAc,CACf,EAAgB,IAAA,IAClB,CACF,MAAM,EACN,EAAO,KAAK,gCAAgC,IAAY,OACnD,EAAO,CACZ,IAAM,EACF,aAAiB,MAAQ,EAAM,QAAU,OAAO,EAAM,CAC1D,EAAO,MACH,wCAAwC,EAAU,IAAI,IACzD,GAIT,EAAQ,GAAG,MAAO,EAAO,CACzB,EAAQ,GAAG,SAAU,EAAO,CAC5B,EAAQ,GAAG,SAAU,EAAO,EAEnC"}
|
package/dist/loader.cjs
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_loader = require('./loader-DetFooDG.cjs');
|
|
3
|
-
|
|
4
|
-
exports.typstLoader = require_loader.typstLoader;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./loader-H5uKHfiV.cjs`);exports.typstLoader=e.t;
|
package/dist/loader.js
CHANGED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{n as e,t}from"./wasm-j2mRjvaE.js";import{load as n}from"cheerio";function r(e){return o(t(e)).html}function i(t){let n=JSON.parse(e(t));if(!a(n)||typeof n.html!=`string`)throw TypeError(`Typst WASM returned an invalid compilation result`);if(!a(n.metadata))throw TypeError("the Typst `astro` variable must be a dictionary");let r=o(n.html);return{html:r.html,headings:r.headings,metadata:n.metadata}}function a(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function o(e){let t=n(e,null,!1),r=[],i=new Set(t(`[id]`).map((e,n)=>t(n).attr(`id`)).get().filter(e=>!!e));return t(`h1, h2, h3, h4, h5, h6`).each((e,n)=>{let a=t(n),o=a.text().trim(),c=a.attr(`id`);if(!c){let e=s(o)||`heading`;c=e;let t=2;for(;i.has(c);)c=`${e}-${t}`,t+=1;a.attr(`id`,c),i.add(c)}r.push({depth:Number(n.tagName.slice(1)),slug:c,text:o})}),{html:t.html(),headings:r}}function s(e){return e.normalize(`NFKD`).replace(/\p{Mark}+/gu,``).toLocaleLowerCase(`en`).replace(/[’']/gu,``).replace(/[^\p{Letter}\p{Number}]+/gu,`-`).replace(/^-+|-+$/gu,``)}export{r as n,i as t};
|
|
2
|
+
//# sourceMappingURL=render-DA5hfbvx.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-
|
|
1
|
+
{"version":3,"file":"render-DA5hfbvx.js","names":[],"sources":["../src/render.ts"],"sourcesContent":["import { typstToHtml, typstToHtmlWithMetadata } from \"./wasm.js\";\nimport type { MarkdownHeading } from \"astro\";\nimport { load } from \"cheerio\";\n\nexport interface CompiledTypst {\n html: string;\n headings: MarkdownHeading[];\n metadata: Record<string, unknown>;\n}\n\nexport function renderTypst(typst: string): string {\n return prepareHtml(typstToHtml(typst)).html;\n}\n\nexport function compileTypst(typst: string): CompiledTypst {\n const compiled: unknown = JSON.parse(typstToHtmlWithMetadata(typst));\n\n if (!isRecord(compiled) || typeof compiled.html !== \"string\") {\n throw new TypeError(\n \"Typst WASM returned an invalid compilation result\",\n );\n }\n\n if (!isRecord(compiled.metadata)) {\n throw new TypeError(\"the Typst `astro` variable must be a dictionary\");\n }\n\n const rendered = prepareHtml(compiled.html);\n return {\n html: rendered.html,\n headings: rendered.headings,\n metadata: compiled.metadata,\n };\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction prepareHtml(html: string): {\n html: string;\n headings: MarkdownHeading[];\n} {\n const $ = load(html, null, false);\n const headings: MarkdownHeading[] = [];\n const usedIds = new Set(\n $(\"[id]\")\n .map((_, element) => $(element).attr(\"id\"))\n .get()\n .filter((id): id is string => Boolean(id)),\n );\n\n $(\"h1, h2, h3, h4, h5, h6\").each((_, heading) => {\n const element = $(heading);\n const text = element.text().trim();\n let id = element.attr(\"id\");\n\n if (!id) {\n const base = slugify(text) || \"heading\";\n id = base;\n let suffix = 2;\n while (usedIds.has(id)) {\n id = `${base}-${suffix}`;\n suffix += 1;\n }\n element.attr(\"id\", id);\n usedIds.add(id);\n }\n\n headings.push({\n depth: Number(heading.tagName.slice(1)),\n slug: id,\n text,\n });\n });\n\n return { html: $.html(), headings };\n}\n\nfunction slugify(value: string): string {\n return value\n .normalize(\"NFKD\")\n .replace(/\\p{Mark}+/gu, \"\")\n .toLocaleLowerCase(\"en\")\n .replace(/[’']/gu, \"\")\n .replace(/[^\\p{Letter}\\p{Number}]+/gu, \"-\")\n .replace(/^-+|-+$/gu, \"\");\n}\n"],"mappings":"wEAUA,SAAgB,EAAY,EAAuB,CAC/C,OAAO,EAAY,EAAY,EAAM,CAAC,CAAC,KAG3C,SAAgB,EAAa,EAA8B,CACvD,IAAM,EAAoB,KAAK,MAAM,EAAwB,EAAM,CAAC,CAEpE,GAAI,CAAC,EAAS,EAAS,EAAI,OAAO,EAAS,MAAS,SAChD,MAAU,UACN,oDACH,CAGL,GAAI,CAAC,EAAS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SRnB8hH.cjs`);let t=require(`cheerio`);function n(t){return a(e.t(t)).html}function r(t){let n=JSON.parse(e.n(t));if(!i(n)||typeof n.html!=`string`)throw TypeError(`Typst WASM returned an invalid compilation result`);if(!i(n.metadata))throw TypeError("the Typst `astro` variable must be a dictionary");let r=a(n.html);return{html:r.html,headings:r.headings,metadata:n.metadata}}function i(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function a(e){let n=(0,t.load)(e,null,!1),r=[],i=new Set(n(`[id]`).map((e,t)=>n(t).attr(`id`)).get().filter(e=>!!e));return n(`h1, h2, h3, h4, h5, h6`).each((e,t)=>{let a=n(t),s=a.text().trim(),c=a.attr(`id`);if(!c){let e=o(s)||`heading`;c=e;let t=2;for(;i.has(c);)c=`${e}-${t}`,t+=1;a.attr(`id`,c),i.add(c)}r.push({depth:Number(t.tagName.slice(1)),slug:c,text:s})}),{html:n.html(),headings:r}}function o(e){return e.normalize(`NFKD`).replace(/\p{Mark}+/gu,``).toLocaleLowerCase(`en`).replace(/[’']/gu,``).replace(/[^\p{Letter}\p{Number}]+/gu,`-`).replace(/^-+|-+$/gu,``)}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return r}});
|
|
2
|
+
//# sourceMappingURL=render-Oy9Sy3-q.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-Oy9Sy3-q.cjs","names":["typstToHtml","typstToHtmlWithMetadata"],"sources":["../src/render.ts"],"sourcesContent":["import { typstToHtml, typstToHtmlWithMetadata } from \"./wasm.js\";\nimport type { MarkdownHeading } from \"astro\";\nimport { load } from \"cheerio\";\n\nexport interface CompiledTypst {\n html: string;\n headings: MarkdownHeading[];\n metadata: Record<string, unknown>;\n}\n\nexport function renderTypst(typst: string): string {\n return prepareHtml(typstToHtml(typst)).html;\n}\n\nexport function compileTypst(typst: string): CompiledTypst {\n const compiled: unknown = JSON.parse(typstToHtmlWithMetadata(typst));\n\n if (!isRecord(compiled) || typeof compiled.html !== \"string\") {\n throw new TypeError(\n \"Typst WASM returned an invalid compilation result\",\n );\n }\n\n if (!isRecord(compiled.metadata)) {\n throw new TypeError(\"the Typst `astro` variable must be a dictionary\");\n }\n\n const rendered = prepareHtml(compiled.html);\n return {\n html: rendered.html,\n headings: rendered.headings,\n metadata: compiled.metadata,\n };\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction prepareHtml(html: string): {\n html: string;\n headings: MarkdownHeading[];\n} {\n const $ = load(html, null, false);\n const headings: MarkdownHeading[] = [];\n const usedIds = new Set(\n $(\"[id]\")\n .map((_, element) => $(element).attr(\"id\"))\n .get()\n .filter((id): id is string => Boolean(id)),\n );\n\n $(\"h1, h2, h3, h4, h5, h6\").each((_, heading) => {\n const element = $(heading);\n const text = element.text().trim();\n let id = element.attr(\"id\");\n\n if (!id) {\n const base = slugify(text) || \"heading\";\n id = base;\n let suffix = 2;\n while (usedIds.has(id)) {\n id = `${base}-${suffix}`;\n suffix += 1;\n }\n element.attr(\"id\", id);\n usedIds.add(id);\n }\n\n headings.push({\n depth: Number(heading.tagName.slice(1)),\n slug: id,\n text,\n });\n });\n\n return { html: $.html(), headings };\n}\n\nfunction slugify(value: string): string {\n return value\n .normalize(\"NFKD\")\n .replace(/\\p{Mark}+/gu, \"\")\n .toLocaleLowerCase(\"en\")\n .replace(/[’']/gu, \"\")\n .replace(/[^\\p{Letter}\\p{Number}]+/gu, \"-\")\n .replace(/^-+|-+$/gu, \"\");\n}\n"],"mappings":"gEAUA,SAAgB,EAAY,EAAuB,CAC/C,OAAO,EAAYA,EAAAA,EAAY,EAAM,CAAC,CAAC,KAG3C,SAAgB,EAAa,EAA8B,CACvD,IAAM,EAAoB,KAAK,MAAMC,EAAAA,EAAwB,EAAM,CAAC,CAEpE,GAAI,CAAC,EAAS,EAAS,EAAI,OAAO,EAAS,MAAS,SAChD,MAA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dist/vite.cjs
CHANGED
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_render = require('./render-UEphEA_d.cjs');
|
|
3
|
-
|
|
4
|
-
//#region src/vite.ts
|
|
5
|
-
/** Transform imported `.typ` files into modules whose default export is HTML. */
|
|
6
|
-
function typst({ include = /\.typ$/ } = {}) {
|
|
7
|
-
return {
|
|
8
|
-
name: "astro-typst",
|
|
9
|
-
enforce: "pre",
|
|
10
|
-
transform: {
|
|
11
|
-
filter: { id: include },
|
|
12
|
-
handler(source) {
|
|
13
|
-
const html = require_render.renderTypst(source);
|
|
14
|
-
return {
|
|
15
|
-
code: `export default ${JSON.stringify(html)};`,
|
|
16
|
-
map: null
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
exports.typst = typst;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./render-Oy9Sy3-q.cjs`);function t({include:t=/\.typ$/}={}){return{name:`astro-typst`,enforce:`pre`,transform:{filter:{id:t},handler(t){let n=e.n(t);return{code:`export default ${JSON.stringify(n)};`,map:null}}}}}exports.typst=t;
|
|
25
2
|
//# sourceMappingURL=vite.cjs.map
|
package/dist/vite.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.cjs","names":["renderTypst"],"sources":["../src/vite.ts"],"sourcesContent":["import { renderTypst } from \"./render.js\";\nimport type { PluginOption } from \"vite\";\n\nexport interface TypstPluginOptions {\n include?: RegExp;\n}\n\n/** Transform imported `.typ` files into modules whose default export is HTML. */\nexport function typst({\n include = /\\.typ$/,\n}: TypstPluginOptions = {}): PluginOption {\n return {\n name: \"astro-typst\",\n enforce: \"pre\",\n transform: {\n filter: { id: include },\n handler(source) {\n const html = renderTypst(source);\n return {\n code: `export default ${JSON.stringify(html)};`,\n map: null,\n };\n },\n },\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"vite.cjs","names":["renderTypst"],"sources":["../src/vite.ts"],"sourcesContent":["import { renderTypst } from \"./render.js\";\nimport type { PluginOption } from \"vite\";\n\nexport interface TypstPluginOptions {\n include?: RegExp;\n}\n\n/** Transform imported `.typ` files into modules whose default export is HTML. */\nexport function typst({\n include = /\\.typ$/,\n}: TypstPluginOptions = {}): PluginOption {\n return {\n name: \"astro-typst\",\n enforce: \"pre\",\n transform: {\n filter: { id: include },\n handler(source) {\n const html = renderTypst(source);\n return {\n code: `export default ${JSON.stringify(html)};`,\n map: null,\n };\n },\n },\n };\n}\n"],"mappings":"4GAQA,SAAgB,EAAM,CAClB,UAAU,UACU,EAAE,CAAgB,CACtC,MAAO,CACH,KAAM,cACN,QAAS,MACT,UAAW,CACP,OAAQ,CAAE,GAAI,EAAS,CACvB,QAAQ,EAAQ,CACZ,IAAM,EAAOA,EAAAA,EAAY,EAAO,CAChC,MAAO,CACH,KAAM,kBAAkB,KAAK,UAAU,EAAK,CAAC,GAC7C,IAAK,KACR,EAER,CACJ"}
|
package/dist/vite.js
CHANGED
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/vite.ts
|
|
4
|
-
/** Transform imported `.typ` files into modules whose default export is HTML. */
|
|
5
|
-
function typst({ include = /\.typ$/ } = {}) {
|
|
6
|
-
return {
|
|
7
|
-
name: "astro-typst",
|
|
8
|
-
enforce: "pre",
|
|
9
|
-
transform: {
|
|
10
|
-
filter: { id: include },
|
|
11
|
-
handler(source) {
|
|
12
|
-
const html = renderTypst(source);
|
|
13
|
-
return {
|
|
14
|
-
code: `export default ${JSON.stringify(html)};`,
|
|
15
|
-
map: null
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
export { typst };
|
|
1
|
+
import{n as e}from"./render-DA5hfbvx.js";function t({include:t=/\.typ$/}={}){return{name:`astro-typst`,enforce:`pre`,transform:{filter:{id:t},handler(t){let n=e(t);return{code:`export default ${JSON.stringify(n)};`,map:null}}}}}export{t as typst};
|
|
24
2
|
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import { renderTypst } from \"./render.js\";\nimport type { PluginOption } from \"vite\";\n\nexport interface TypstPluginOptions {\n include?: RegExp;\n}\n\n/** Transform imported `.typ` files into modules whose default export is HTML. */\nexport function typst({\n include = /\\.typ$/,\n}: TypstPluginOptions = {}): PluginOption {\n return {\n name: \"astro-typst\",\n enforce: \"pre\",\n transform: {\n filter: { id: include },\n handler(source) {\n const html = renderTypst(source);\n return {\n code: `export default ${JSON.stringify(html)};`,\n map: null,\n };\n },\n },\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import { renderTypst } from \"./render.js\";\nimport type { PluginOption } from \"vite\";\n\nexport interface TypstPluginOptions {\n include?: RegExp;\n}\n\n/** Transform imported `.typ` files into modules whose default export is HTML. */\nexport function typst({\n include = /\\.typ$/,\n}: TypstPluginOptions = {}): PluginOption {\n return {\n name: \"astro-typst\",\n enforce: \"pre\",\n transform: {\n filter: { id: include },\n handler(source) {\n const html = renderTypst(source);\n return {\n code: `export default ${JSON.stringify(html)};`,\n map: null,\n };\n },\n },\n };\n}\n"],"mappings":"yCAQA,SAAgB,EAAM,CAClB,UAAU,UACU,EAAE,CAAgB,CACtC,MAAO,CACH,KAAM,cACN,QAAS,MACT,UAAW,CACP,OAAQ,CAAE,GAAI,EAAS,CACvB,QAAQ,EAAQ,CACZ,IAAM,EAAO,EAAY,EAAO,CAChC,MAAO,CACH,KAAM,kBAAkB,KAAK,UAAU,EAAK,CAAC,GAC7C,IAAK,KACR,EAER,CACJ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
let e=require(`node:fs`);function t(e){let t,n;try{let d=x.__wbindgen_add_to_stack_pointer(-16),f=m(e,x.__wbindgen_export,x.__wbindgen_export2),p=b;x.typstToHtml(d,f,p);var r=s().getInt32(d+0,!0),i=s().getInt32(d+4,!0),a=s().getInt32(d+8,!0),o=s().getInt32(d+12,!0),l=r,u=i;if(o)throw l=0,u=0,h(a);return t=l,n=u,c(l,u)}finally{x.__wbindgen_add_to_stack_pointer(16),x.__wbindgen_export3(t,n,1)}}function n(e){let t,n;try{let d=x.__wbindgen_add_to_stack_pointer(-16),f=m(e,x.__wbindgen_export,x.__wbindgen_export2),p=b;x.typstToHtmlWithMetadata(d,f,p);var r=s().getInt32(d+0,!0),i=s().getInt32(d+4,!0),a=s().getInt32(d+8,!0),o=s().getInt32(d+12,!0),l=r,u=i;if(o)throw l=0,u=0,h(a);return t=l,n=u,c(l,u)}finally{x.__wbindgen_add_to_stack_pointer(16),x.__wbindgen_export3(t,n,1)}}function r(){return{__proto__:null,"./typst_wasm_bg.js":{__proto__:null,__wbg_Error_fdd633d4bb5dd76a:function(e,t){return i(Error(c(e,t)))}}}}function i(e){p===f.length&&f.push(f.length+1);let t=p;return p=f[t],f[t]=e,t}function a(e){e<1028||(f[e]=p,p=e)}let o=null;function s(){return(o===null||o.buffer.detached===!0||o.buffer.detached===void 0&&o.buffer!==x.memory.buffer)&&(o=new DataView(x.memory.buffer)),o}function c(e,t){return v(e>>>0,t)}let l=null;function u(){return(l===null||l.byteLength===0)&&(l=new Uint8Array(x.memory.buffer)),l}function d(e){return f[e]}let f=Array(1024).fill(void 0);f.push(void 0,null,!0,!1);let p=f.length;function m(e,t,n){if(n===void 0){let n=y.encode(e),r=t(n.length,1)>>>0;return u().subarray(r,r+n.length).set(n),b=n.length,r}let r=e.length,i=t(r,1)>>>0,a=u(),o=0;for(;o<r;o++){let t=e.charCodeAt(o);if(t>127)break;a[i+o]=t}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;let t=u().subarray(i+o,i+r),a=y.encodeInto(e,t);o+=a.written,i=n(i,r,o,1)>>>0}return b=o,i}function h(e){let t=d(e);return a(e),t}let g=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0});g.decode();let _=0;function v(e,t){return _+=t,_>=2146435072&&(g=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0}),g.decode(),_=t),g.decode(u().subarray(e,e+t))}const y=new TextEncoder;`encodeInto`in y||(y.encodeInto=function(e,t){let n=y.encode(e);return t.set(n),{read:e.length,written:n.length}});let b=0,x;function S(e,t){return x=e.exports,o=null,l=null,x}function C(e){if(x!==void 0)return x;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module:e}=e:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let t=r();return e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e)),S(new WebAssembly.Instance(e,t),e)}C({module:(0,e.readFileSync)(new URL(`../wasm/typst_wasm_bg.wasm`,require(`url`).pathToFileURL(__filename).href))}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|
|
2
|
+
//# sourceMappingURL=wasm-BSRnB8hH.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-BSRnB8hH.cjs","names":[],"sources":["../wasm/typst_wasm.js","../src/wasm.ts"],"sourcesContent":["/* @ts-self-types=\"./typst_wasm.d.ts\" */\n\n/**\n * @param {string} input\n * @returns {string}\n */\nexport function typstToHtml(input) {\n let deferred3_0;\n let deferred3_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);\n const len0 = WASM_VECTOR_LEN;\n wasm.typstToHtml(retptr, ptr0, len0);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);\n var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);\n var ptr2 = r0;\n var len2 = r1;\n if (r3) {\n ptr2 = 0; len2 = 0;\n throw takeObject(r2);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);\n }\n}\n\n/**\n * Compile a Typst content entry and return `{ html, metadata }` as JSON.\n * @param {string} input\n * @returns {string}\n */\nexport function typstToHtmlWithMetadata(input) {\n let deferred3_0;\n let deferred3_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);\n const len0 = WASM_VECTOR_LEN;\n wasm.typstToHtmlWithMetadata(retptr, ptr0, len0);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);\n var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);\n var ptr2 = r0;\n var len2 = r1;\n if (r3) {\n ptr2 = 0; len2 = 0;\n throw takeObject(r2);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);\n }\n}\nfunction __wbg_get_imports() {\n const import0 = {\n __proto__: null,\n __wbg_Error_fdd633d4bb5dd76a: function(arg0, arg1) {\n const ret = Error(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n },\n };\n return {\n __proto__: null,\n \"./typst_wasm_bg.js\": import0,\n };\n}\n\nfunction addHeapObject(obj) {\n if (heap_next === heap.length) heap.push(heap.length + 1);\n const idx = heap_next;\n heap_next = heap[idx];\n\n heap[idx] = obj;\n return idx;\n}\n\nfunction dropObject(idx) {\n if (idx < 1028) return;\n heap[idx] = heap_next;\n heap_next = idx;\n}\n\nlet cachedDataViewMemory0 = null;\nfunction getDataViewMemory0() {\n if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {\n cachedDataViewMemory0 = new DataView(wasm.memory.buffer);\n }\n return cachedDataViewMemory0;\n}\n\nfunction getStringFromWasm0(ptr, len) {\n return decodeText(ptr >>> 0, len);\n}\n\nlet cachedUint8ArrayMemory0 = null;\nfunction getUint8ArrayMemory0() {\n if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {\n cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachedUint8ArrayMemory0;\n}\n\nfunction getObject(idx) { return heap[idx]; }\n\nlet heap = new Array(1024).fill(undefined);\nheap.push(undefined, null, true, false);\n\nlet heap_next = heap.length;\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length, 1) >>> 0;\n getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len, 1) >>> 0;\n\n const mem = getUint8ArrayMemory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7F) break;\n mem[ptr + offset] = code;\n }\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;\n const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);\n const ret = cachedTextEncoder.encodeInto(arg, view);\n\n offset += ret.written;\n ptr = realloc(ptr, len, offset, 1) >>> 0;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nfunction takeObject(idx) {\n const ret = getObject(idx);\n dropObject(idx);\n return ret;\n}\n\nlet cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\ncachedTextDecoder.decode();\nconst MAX_SAFARI_DECODE_BYTES = 2146435072;\nlet numBytesDecoded = 0;\nfunction decodeText(ptr, len) {\n numBytesDecoded += len;\n if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {\n cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\n cachedTextDecoder.decode();\n numBytesDecoded = len;\n }\n return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));\n}\n\nconst cachedTextEncoder = new TextEncoder();\n\nif (!('encodeInto' in cachedTextEncoder)) {\n cachedTextEncoder.encodeInto = function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length\n };\n };\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nlet wasmModule, wasmInstance, wasm;\nfunction __wbg_finalize_init(instance, module) {\n wasmInstance = instance;\n wasm = instance.exports;\n wasmModule = module;\n cachedDataViewMemory0 = null;\n cachedUint8ArrayMemory0 = null;\n return wasm;\n}\n\nasync function __wbg_load(module, imports) {\n if (typeof Response === 'function' && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === 'function') {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n } catch (e) {\n const validResponse = module.ok && expectedResponseType(module.type);\n\n if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {\n console.warn(\"`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\", e);\n\n } else { throw e; }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n } else {\n return instance;\n }\n }\n\n function expectedResponseType(type) {\n switch (type) {\n case 'basic': case 'cors': case 'default': return true;\n }\n return false;\n }\n}\n\nfunction initSync(module) {\n if (wasm !== undefined) return wasm;\n\n\n if (module !== undefined) {\n if (Object.getPrototypeOf(module) === Object.prototype) {\n ({module} = module)\n } else {\n console.warn('using deprecated parameters for `initSync()`; pass a single object instead')\n }\n }\n\n const imports = __wbg_get_imports();\n if (!(module instanceof WebAssembly.Module)) {\n module = new WebAssembly.Module(module);\n }\n const instance = new WebAssembly.Instance(module, imports);\n return __wbg_finalize_init(instance, module);\n}\n\nasync function __wbg_init(module_or_path) {\n if (wasm !== undefined) return wasm;\n\n\n if (module_or_path !== undefined) {\n if (Object.getPrototypeOf(module_or_path) === Object.prototype) {\n ({module_or_path} = module_or_path)\n } else {\n console.warn('using deprecated parameters for the initialization function; pass a single object instead')\n }\n }\n\n if (module_or_path === undefined) {\n module_or_path = new URL('typst_wasm_bg.wasm', import.meta.url);\n }\n const imports = __wbg_get_imports();\n\n if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {\n module_or_path = fetch(module_or_path);\n }\n\n const { instance, module } = await __wbg_load(await module_or_path, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nexport { initSync, __wbg_init as default };\n","import {\n initSync,\n typstToHtml,\n typstToHtmlWithMetadata,\n} from \"../wasm/typst_wasm.js\";\nimport { readFileSync } from \"node:fs\";\n\ninitSync({\n module: readFileSync(\n new URL(\"../wasm/typst_wasm_bg.wasm\", import.meta.url),\n ),\n});\n\nexport { typstToHtml, typstToHtmlWithMetadata };\n"],"mappings":"yBAMA,SAAgB,EAAY,EAAO,CAC/B,IAAI,EACA,EACJ,GAAI,CACA,IAAM,EAAS,EAAK,gCAAgC,IAAI,CAClD,EAAO,EAAkB,EAAO,EAAK,k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EZ,QAAQ,KAAK,6EAA6E,EAIlG,IAAM,EAAU,GAAmB,CAKnC,OAJM,aAAkB,YAAY,SAChC,EAAS,IAAI,YAAY,OAAO,EAAO,EAGpC,EAAoB,IADN,YAAY,SAAS,EAAQ,EACf,CAAE,EAAO,CCvPhD,EAAS,CACL,QAAA,EAAA,EAAA,cACI,IAAI,IAAI,6BAAA,QAAA,MAAA,CAAA,cAAA,WAAA,CAAA,KAA8C,CACzD,CACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region wasm/typst_wasm.d.ts
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
declare function typstToHtml(input: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Compile a Typst content entry and return `{ html, metadata }` as JSON.
|
|
7
|
+
*/
|
|
8
|
+
declare function typstToHtmlWithMetadata(input: string): string;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { typstToHtmlWithMetadata as n, typstToHtml as t };
|
|
11
|
+
//# sourceMappingURL=wasm-Bp_4rcoG.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region wasm/typst_wasm.d.ts
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
declare function typstToHtml(input: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Compile a Typst content entry and return `{ html, metadata }` as JSON.
|
|
7
|
+
*/
|
|
8
|
+
declare function typstToHtmlWithMetadata(input: string): string;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { typstToHtmlWithMetadata as n, typstToHtml as t };
|
|
11
|
+
//# sourceMappingURL=wasm-DcPE0DPA.d.cts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{readFileSync as e}from"node:fs";function t(e){let t,n;try{let d=x.__wbindgen_add_to_stack_pointer(-16),f=m(e,x.__wbindgen_export,x.__wbindgen_export2),p=b;x.typstToHtml(d,f,p);var r=s().getInt32(d+0,!0),i=s().getInt32(d+4,!0),a=s().getInt32(d+8,!0),o=s().getInt32(d+12,!0),l=r,u=i;if(o)throw l=0,u=0,h(a);return t=l,n=u,c(l,u)}finally{x.__wbindgen_add_to_stack_pointer(16),x.__wbindgen_export3(t,n,1)}}function n(e){let t,n;try{let d=x.__wbindgen_add_to_stack_pointer(-16),f=m(e,x.__wbindgen_export,x.__wbindgen_export2),p=b;x.typstToHtmlWithMetadata(d,f,p);var r=s().getInt32(d+0,!0),i=s().getInt32(d+4,!0),a=s().getInt32(d+8,!0),o=s().getInt32(d+12,!0),l=r,u=i;if(o)throw l=0,u=0,h(a);return t=l,n=u,c(l,u)}finally{x.__wbindgen_add_to_stack_pointer(16),x.__wbindgen_export3(t,n,1)}}function r(){return{__proto__:null,"./typst_wasm_bg.js":{__proto__:null,__wbg_Error_fdd633d4bb5dd76a:function(e,t){return i(Error(c(e,t)))}}}}function i(e){p===f.length&&f.push(f.length+1);let t=p;return p=f[t],f[t]=e,t}function a(e){e<1028||(f[e]=p,p=e)}let o=null;function s(){return(o===null||o.buffer.detached===!0||o.buffer.detached===void 0&&o.buffer!==x.memory.buffer)&&(o=new DataView(x.memory.buffer)),o}function c(e,t){return v(e>>>0,t)}let l=null;function u(){return(l===null||l.byteLength===0)&&(l=new Uint8Array(x.memory.buffer)),l}function d(e){return f[e]}let f=Array(1024).fill(void 0);f.push(void 0,null,!0,!1);let p=f.length;function m(e,t,n){if(n===void 0){let n=y.encode(e),r=t(n.length,1)>>>0;return u().subarray(r,r+n.length).set(n),b=n.length,r}let r=e.length,i=t(r,1)>>>0,a=u(),o=0;for(;o<r;o++){let t=e.charCodeAt(o);if(t>127)break;a[i+o]=t}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;let t=u().subarray(i+o,i+r),a=y.encodeInto(e,t);o+=a.written,i=n(i,r,o,1)>>>0}return b=o,i}function h(e){let t=d(e);return a(e),t}let g=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0});g.decode();let _=0;function v(e,t){return _+=t,_>=2146435072&&(g=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0}),g.decode(),_=t),g.decode(u().subarray(e,e+t))}const y=new TextEncoder;`encodeInto`in y||(y.encodeInto=function(e,t){let n=y.encode(e);return t.set(n),{read:e.length,written:n.length}});let b=0,x;function S(e,t){return x=e.exports,o=null,l=null,x}function C(e){if(x!==void 0)return x;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module:e}=e:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let t=r();return e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e)),S(new WebAssembly.Instance(e,t),e)}C({module:e(new URL(`../wasm/typst_wasm_bg.wasm`,import.meta.url))});export{n,t};
|
|
2
|
+
//# sourceMappingURL=wasm-j2mRjvaE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-j2mRjvaE.js","names":[],"sources":["../wasm/typst_wasm.js","../src/wasm.ts"],"sourcesContent":["/* @ts-self-types=\"./typst_wasm.d.ts\" */\n\n/**\n * @param {string} input\n * @returns {string}\n */\nexport function typstToHtml(input) {\n let deferred3_0;\n let deferred3_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);\n const len0 = WASM_VECTOR_LEN;\n wasm.typstToHtml(retptr, ptr0, len0);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);\n var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);\n var ptr2 = r0;\n var len2 = r1;\n if (r3) {\n ptr2 = 0; len2 = 0;\n throw takeObject(r2);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);\n }\n}\n\n/**\n * Compile a Typst content entry and return `{ html, metadata }` as JSON.\n * @param {string} input\n * @returns {string}\n */\nexport function typstToHtmlWithMetadata(input) {\n let deferred3_0;\n let deferred3_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);\n const len0 = WASM_VECTOR_LEN;\n wasm.typstToHtmlWithMetadata(retptr, ptr0, len0);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);\n var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);\n var ptr2 = r0;\n var len2 = r1;\n if (r3) {\n ptr2 = 0; len2 = 0;\n throw takeObject(r2);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);\n }\n}\nfunction __wbg_get_imports() {\n const import0 = {\n __proto__: null,\n __wbg_Error_fdd633d4bb5dd76a: function(arg0, arg1) {\n const ret = Error(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n },\n };\n return {\n __proto__: null,\n \"./typst_wasm_bg.js\": import0,\n };\n}\n\nfunction addHeapObject(obj) {\n if (heap_next === heap.length) heap.push(heap.length + 1);\n const idx = heap_next;\n heap_next = heap[idx];\n\n heap[idx] = obj;\n return idx;\n}\n\nfunction dropObject(idx) {\n if (idx < 1028) return;\n heap[idx] = heap_next;\n heap_next = idx;\n}\n\nlet cachedDataViewMemory0 = null;\nfunction getDataViewMemory0() {\n if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {\n cachedDataViewMemory0 = new DataView(wasm.memory.buffer);\n }\n return cachedDataViewMemory0;\n}\n\nfunction getStringFromWasm0(ptr, len) {\n return decodeText(ptr >>> 0, len);\n}\n\nlet cachedUint8ArrayMemory0 = null;\nfunction getUint8ArrayMemory0() {\n if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {\n cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachedUint8ArrayMemory0;\n}\n\nfunction getObject(idx) { return heap[idx]; }\n\nlet heap = new Array(1024).fill(undefined);\nheap.push(undefined, null, true, false);\n\nlet heap_next = heap.length;\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length, 1) >>> 0;\n getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len, 1) >>> 0;\n\n const mem = getUint8ArrayMemory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7F) break;\n mem[ptr + offset] = code;\n }\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;\n const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);\n const ret = cachedTextEncoder.encodeInto(arg, view);\n\n offset += ret.written;\n ptr = realloc(ptr, len, offset, 1) >>> 0;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nfunction takeObject(idx) {\n const ret = getObject(idx);\n dropObject(idx);\n return ret;\n}\n\nlet cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\ncachedTextDecoder.decode();\nconst MAX_SAFARI_DECODE_BYTES = 2146435072;\nlet numBytesDecoded = 0;\nfunction decodeText(ptr, len) {\n numBytesDecoded += len;\n if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {\n cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\n cachedTextDecoder.decode();\n numBytesDecoded = len;\n }\n return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));\n}\n\nconst cachedTextEncoder = new TextEncoder();\n\nif (!('encodeInto' in cachedTextEncoder)) {\n cachedTextEncoder.encodeInto = function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length\n };\n };\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nlet wasmModule, wasmInstance, wasm;\nfunction __wbg_finalize_init(instance, module) {\n wasmInstance = instance;\n wasm = instance.exports;\n wasmModule = module;\n cachedDataViewMemory0 = null;\n cachedUint8ArrayMemory0 = null;\n return wasm;\n}\n\nasync function __wbg_load(module, imports) {\n if (typeof Response === 'function' && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === 'function') {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n } catch (e) {\n const validResponse = module.ok && expectedResponseType(module.type);\n\n if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {\n console.warn(\"`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\", e);\n\n } else { throw e; }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n } else {\n return instance;\n }\n }\n\n function expectedResponseType(type) {\n switch (type) {\n case 'basic': case 'cors': case 'default': return true;\n }\n return false;\n }\n}\n\nfunction initSync(module) {\n if (wasm !== undefined) return wasm;\n\n\n if (module !== undefined) {\n if (Object.getPrototypeOf(module) === Object.prototype) {\n ({module} = module)\n } else {\n console.warn('using deprecated parameters for `initSync()`; pass a single object instead')\n }\n }\n\n const imports = __wbg_get_imports();\n if (!(module instanceof WebAssembly.Module)) {\n module = new WebAssembly.Module(module);\n }\n const instance = new WebAssembly.Instance(module, imports);\n return __wbg_finalize_init(instance, module);\n}\n\nasync function __wbg_init(module_or_path) {\n if (wasm !== undefined) return wasm;\n\n\n if (module_or_path !== undefined) {\n if (Object.getPrototypeOf(module_or_path) === Object.prototype) {\n ({module_or_path} = module_or_path)\n } else {\n console.warn('using deprecated parameters for the initialization function; pass a single object instead')\n }\n }\n\n if (module_or_path === undefined) {\n module_or_path = new URL('typst_wasm_bg.wasm', import.meta.url);\n }\n const imports = __wbg_get_imports();\n\n if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {\n module_or_path = fetch(module_or_path);\n }\n\n const { instance, module } = await __wbg_load(await module_or_path, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nexport { initSync, __wbg_init as default };\n","import {\n initSync,\n typstToHtml,\n typstToHtmlWithMetadata,\n} from \"../wasm/typst_wasm.js\";\nimport { readFileSync } from \"node:fs\";\n\ninitSync({\n module: readFileSync(\n new URL(\"../wasm/typst_wasm_bg.wasm\", import.meta.url),\n ),\n});\n\nexport { typstToHtml, typstToHtmlWithMetadata };\n"],"mappings":"uCAMA,SAAgB,EAAY,EAAO,CAC/B,IAAI,EACA,EACJ,GAAI,CACA,IAAM,EAAS,EAAK,gCAAgC,IAAI,CAClD,EAAO,EAAkB,EAAO,EAAK,kBAAmB,EAAK,mBAAmB,CAChF,EAAO,EACb,EAAK,YAAY,EAAQ,EAAM,EAAK,CACpC,IAAI,EAAK,GAAoB,CAAC,SAAS,EAAS,EAAO,GAAK,CACxD,EAAK,GAAoB,CAAC,SAAS,EAAS,EAAO,GAAK,CACxD,EAAK,GAAoB,CAAC,SAAS,EAAS,EAAO,GAAK,CACxD,EAAK,GAAoB,CAAC,SAAS,EAAS,GAAO,GAAK,CACxD,EAAO,EACP,EAAO,EACX,G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 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
let wasm_typst_wasm_js = require("../wasm/typst_wasm.js");
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, 'typstToHtml', {
|
|
5
|
-
enumerable: true,
|
|
6
|
-
get: function () {
|
|
7
|
-
return wasm_typst_wasm_js.typstToHtml;
|
|
8
|
-
}
|
|
9
|
-
});
|
|
10
|
-
Object.defineProperty(exports, 'typstToHtmlWithMetadata', {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return wasm_typst_wasm_js.typstToHtmlWithMetadata;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./wasm-BSRnB8hH.cjs`);exports.typstToHtml=e.t,exports.typstToHtmlWithMetadata=e.n;
|
package/dist/wasm.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as typstToHtmlWithMetadata, t as typstToHtml } from "./wasm-DcPE0DPA.cjs";
|
|
2
2
|
export { typstToHtml, typstToHtmlWithMetadata };
|
package/dist/wasm.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as typstToHtmlWithMetadata, t as typstToHtml } from "./wasm-Bp_4rcoG.js";
|
|
2
2
|
export { typstToHtml, typstToHtmlWithMetadata };
|
package/dist/wasm.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floffah/astro-typst",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.1.0-rc.1",
|
|
4
4
|
"description": "Typst rendering primitives, an Astro content loader, and a Vite plugin powered by WebAssembly.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -70,9 +70,10 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
|
-
"build:wasm": "wasm-pack build crates/typst-wasm --release --target
|
|
73
|
+
"build:wasm": "wasm-pack build crates/typst-wasm --release --target web --out-dir ../../wasm --no-pack && bun run scripts/write-wasm-package.ts",
|
|
74
74
|
"build:ts": "tsdown",
|
|
75
75
|
"build": "bun run build:wasm && bun run build:ts",
|
|
76
|
+
"smoke": "bun run build && bun run scripts/smoke.ts",
|
|
76
77
|
"lint": "tsc -p tsconfig.json --noEmit && eslint . --ext .ts",
|
|
77
78
|
"format": "prettier --write .",
|
|
78
79
|
"format:check": "prettier --check .",
|
|
@@ -123,7 +124,8 @@
|
|
|
123
124
|
},
|
|
124
125
|
"author": "Floffah <therealfloffah@gmail.com>",
|
|
125
126
|
"publishConfig": {
|
|
126
|
-
"access": "public"
|
|
127
|
+
"access": "public",
|
|
128
|
+
"provenance": true
|
|
127
129
|
},
|
|
128
130
|
"packageManager": "bun@1.3.14",
|
|
129
131
|
"license": "MIT"
|
package/wasm/package.json
CHANGED
package/wasm/typst_wasm.d.ts
CHANGED
|
@@ -7,3 +7,37 @@ export function typstToHtml(input: string): string;
|
|
|
7
7
|
* Compile a Typst content entry and return `{ html, metadata }` as JSON.
|
|
8
8
|
*/
|
|
9
9
|
export function typstToHtmlWithMetadata(input: string): string;
|
|
10
|
+
|
|
11
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
12
|
+
|
|
13
|
+
export interface InitOutput {
|
|
14
|
+
readonly memory: WebAssembly.Memory;
|
|
15
|
+
readonly typstToHtml: (a: number, b: number, c: number) => void;
|
|
16
|
+
readonly typstToHtmlWithMetadata: (a: number, b: number, c: number) => void;
|
|
17
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
18
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
19
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
20
|
+
readonly __wbindgen_export3: (a: number, b: number, c: number) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
27
|
+
* a precompiled `WebAssembly.Module`.
|
|
28
|
+
*
|
|
29
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
30
|
+
*
|
|
31
|
+
* @returns {InitOutput}
|
|
32
|
+
*/
|
|
33
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
37
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
38
|
+
*
|
|
39
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
40
|
+
*
|
|
41
|
+
* @returns {Promise<InitOutput>}
|
|
42
|
+
*/
|
|
43
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/wasm/typst_wasm.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param {string} input
|
|
5
5
|
* @returns {string}
|
|
6
6
|
*/
|
|
7
|
-
function typstToHtml(input) {
|
|
7
|
+
export function typstToHtml(input) {
|
|
8
8
|
let deferred3_0;
|
|
9
9
|
let deferred3_1;
|
|
10
10
|
try {
|
|
@@ -30,14 +30,13 @@ function typstToHtml(input) {
|
|
|
30
30
|
wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
exports.typstToHtml = typstToHtml;
|
|
34
33
|
|
|
35
34
|
/**
|
|
36
35
|
* Compile a Typst content entry and return `{ html, metadata }` as JSON.
|
|
37
36
|
* @param {string} input
|
|
38
37
|
* @returns {string}
|
|
39
38
|
*/
|
|
40
|
-
function typstToHtmlWithMetadata(input) {
|
|
39
|
+
export function typstToHtmlWithMetadata(input) {
|
|
41
40
|
let deferred3_0;
|
|
42
41
|
let deferred3_1;
|
|
43
42
|
try {
|
|
@@ -63,7 +62,6 @@ function typstToHtmlWithMetadata(input) {
|
|
|
63
62
|
wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
|
-
exports.typstToHtmlWithMetadata = typstToHtmlWithMetadata;
|
|
67
65
|
function __wbg_get_imports() {
|
|
68
66
|
const import0 = {
|
|
69
67
|
__proto__: null,
|
|
@@ -165,7 +163,15 @@ function takeObject(idx) {
|
|
|
165
163
|
|
|
166
164
|
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
167
165
|
cachedTextDecoder.decode();
|
|
166
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
167
|
+
let numBytesDecoded = 0;
|
|
168
168
|
function decodeText(ptr, len) {
|
|
169
|
+
numBytesDecoded += len;
|
|
170
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
171
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
172
|
+
cachedTextDecoder.decode();
|
|
173
|
+
numBytesDecoded = len;
|
|
174
|
+
}
|
|
169
175
|
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
170
176
|
}
|
|
171
177
|
|
|
@@ -184,8 +190,95 @@ if (!('encodeInto' in cachedTextEncoder)) {
|
|
|
184
190
|
|
|
185
191
|
let WASM_VECTOR_LEN = 0;
|
|
186
192
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
let wasmModule, wasmInstance, wasm;
|
|
194
|
+
function __wbg_finalize_init(instance, module) {
|
|
195
|
+
wasmInstance = instance;
|
|
196
|
+
wasm = instance.exports;
|
|
197
|
+
wasmModule = module;
|
|
198
|
+
cachedDataViewMemory0 = null;
|
|
199
|
+
cachedUint8ArrayMemory0 = null;
|
|
200
|
+
return wasm;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async function __wbg_load(module, imports) {
|
|
204
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
205
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
206
|
+
try {
|
|
207
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
208
|
+
} catch (e) {
|
|
209
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
210
|
+
|
|
211
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
212
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
213
|
+
|
|
214
|
+
} else { throw e; }
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const bytes = await module.arrayBuffer();
|
|
219
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
220
|
+
} else {
|
|
221
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
222
|
+
|
|
223
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
224
|
+
return { instance, module };
|
|
225
|
+
} else {
|
|
226
|
+
return instance;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function expectedResponseType(type) {
|
|
231
|
+
switch (type) {
|
|
232
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
233
|
+
}
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function initSync(module) {
|
|
239
|
+
if (wasm !== undefined) return wasm;
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
if (module !== undefined) {
|
|
243
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
244
|
+
({module} = module)
|
|
245
|
+
} else {
|
|
246
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const imports = __wbg_get_imports();
|
|
251
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
252
|
+
module = new WebAssembly.Module(module);
|
|
253
|
+
}
|
|
254
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
255
|
+
return __wbg_finalize_init(instance, module);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async function __wbg_init(module_or_path) {
|
|
259
|
+
if (wasm !== undefined) return wasm;
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
if (module_or_path !== undefined) {
|
|
263
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
264
|
+
({module_or_path} = module_or_path)
|
|
265
|
+
} else {
|
|
266
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (module_or_path === undefined) {
|
|
271
|
+
module_or_path = new URL('typst_wasm_bg.wasm', import.meta.url);
|
|
272
|
+
}
|
|
273
|
+
const imports = __wbg_get_imports();
|
|
274
|
+
|
|
275
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
276
|
+
module_or_path = fetch(module_or_path);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
280
|
+
|
|
281
|
+
return __wbg_finalize_init(instance, module);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export { initSync, __wbg_init as default };
|
package/wasm/typst_wasm_bg.wasm
CHANGED
|
Binary file
|
package/dist/loader-CxNOQzU1.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { t as compileTypst } from "./render-hwAGjpa0.js";
|
|
2
|
-
import { relative, resolve, sep } from "node:path";
|
|
3
|
-
import { glob, readFile } from "node:fs/promises";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
|
|
6
|
-
//#region src/paths.ts
|
|
7
|
-
function toPosixPath(path) {
|
|
8
|
-
return path.split(sep).join("/");
|
|
9
|
-
}
|
|
10
|
-
function isTypstEntryPath(path) {
|
|
11
|
-
const fileName = path.split("/").at(-1);
|
|
12
|
-
return path.endsWith(".typ") && path !== ".." && !path.startsWith("../") && !fileName?.startsWith("_");
|
|
13
|
-
}
|
|
14
|
-
function typstEntryId(path) {
|
|
15
|
-
const id = path.slice(0, -4);
|
|
16
|
-
return id.endsWith("/index") ? id.slice(0, -6) : id;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/loader.ts
|
|
21
|
-
function typstLoader({ base = "src/content" } = {}) {
|
|
22
|
-
return {
|
|
23
|
-
name: "astro-typst-loader",
|
|
24
|
-
async load({ config, generateDigest, logger, parseData, store, watcher }) {
|
|
25
|
-
const rootPath = fileURLToPath(config.root);
|
|
26
|
-
const basePath = fileURLToPath(new URL(base.endsWith("/") ? base : `${base}/`, config.root));
|
|
27
|
-
async function rebuildAll() {
|
|
28
|
-
const filePaths = [];
|
|
29
|
-
for await (const entry of glob("**/*.typ", { cwd: basePath })) if (isTypstEntryPath(toPosixPath(entry))) filePaths.push(resolve(basePath, entry));
|
|
30
|
-
if (filePaths.length === 0) logger.warn(`No Typst files found in ${basePath}`);
|
|
31
|
-
const entries = await Promise.all(filePaths.map(async (filePath) => {
|
|
32
|
-
const id = typstEntryId(toPosixPath(relative(basePath, filePath)));
|
|
33
|
-
const source = await readFile(filePath, "utf8");
|
|
34
|
-
const compiled = compileTypst(source);
|
|
35
|
-
return {
|
|
36
|
-
id,
|
|
37
|
-
source,
|
|
38
|
-
data: await parseData({
|
|
39
|
-
id,
|
|
40
|
-
data: compiled.metadata,
|
|
41
|
-
filePath
|
|
42
|
-
}),
|
|
43
|
-
html: compiled.html,
|
|
44
|
-
headings: compiled.headings,
|
|
45
|
-
filePath: toPosixPath(relative(rootPath, filePath)),
|
|
46
|
-
digest: generateDigest(JSON.stringify({
|
|
47
|
-
source,
|
|
48
|
-
html: compiled.html
|
|
49
|
-
}))
|
|
50
|
-
};
|
|
51
|
-
}));
|
|
52
|
-
entries.sort((left, right) => left.id.localeCompare(right.id));
|
|
53
|
-
const entryIds = /* @__PURE__ */ new Set();
|
|
54
|
-
for (const entry of entries) {
|
|
55
|
-
if (entryIds.has(entry.id)) throw new Error(`More than one Typst content file resolves to id "${entry.id}"`);
|
|
56
|
-
entryIds.add(entry.id);
|
|
57
|
-
}
|
|
58
|
-
const untouchedEntries = new Set(store.keys());
|
|
59
|
-
for (const entry of entries) {
|
|
60
|
-
untouchedEntries.delete(entry.id);
|
|
61
|
-
store.set({
|
|
62
|
-
id: entry.id,
|
|
63
|
-
data: entry.data,
|
|
64
|
-
body: entry.source,
|
|
65
|
-
digest: entry.digest,
|
|
66
|
-
filePath: entry.filePath,
|
|
67
|
-
rendered: {
|
|
68
|
-
html: entry.html,
|
|
69
|
-
metadata: { headings: entry.headings }
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
untouchedEntries.forEach((id) => store.delete(id));
|
|
74
|
-
}
|
|
75
|
-
await rebuildAll();
|
|
76
|
-
if (!watcher) return;
|
|
77
|
-
watcher.add(basePath);
|
|
78
|
-
let activeRebuild;
|
|
79
|
-
let rebuildAgain = false;
|
|
80
|
-
const reload = async (filePath) => {
|
|
81
|
-
const entryPath = toPosixPath(relative(basePath, filePath));
|
|
82
|
-
if (!isTypstEntryPath(entryPath)) return;
|
|
83
|
-
try {
|
|
84
|
-
rebuildAgain = true;
|
|
85
|
-
activeRebuild ??= (async () => {
|
|
86
|
-
while (rebuildAgain) {
|
|
87
|
-
rebuildAgain = false;
|
|
88
|
-
await rebuildAll();
|
|
89
|
-
}
|
|
90
|
-
})().finally(() => {
|
|
91
|
-
activeRebuild = void 0;
|
|
92
|
-
});
|
|
93
|
-
await activeRebuild;
|
|
94
|
-
logger.info(`Reloaded Typst content after ${entryPath}`);
|
|
95
|
-
} catch (error) {
|
|
96
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
97
|
-
logger.error(`Failed to reload Typst content after ${entryPath}: ${message}`);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
watcher.on("add", reload);
|
|
101
|
-
watcher.on("change", reload);
|
|
102
|
-
watcher.on("unlink", reload);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
//#endregion
|
|
108
|
-
export { typstLoader as t };
|
|
109
|
-
//# sourceMappingURL=loader-CxNOQzU1.js.map
|
package/dist/loader-DetFooDG.cjs
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
const require_render = require('./render-UEphEA_d.cjs');
|
|
2
|
-
let node_path = require("node:path");
|
|
3
|
-
let node_fs_promises = require("node:fs/promises");
|
|
4
|
-
let node_url = require("node:url");
|
|
5
|
-
|
|
6
|
-
//#region src/paths.ts
|
|
7
|
-
function toPosixPath(path) {
|
|
8
|
-
return path.split(node_path.sep).join("/");
|
|
9
|
-
}
|
|
10
|
-
function isTypstEntryPath(path) {
|
|
11
|
-
const fileName = path.split("/").at(-1);
|
|
12
|
-
return path.endsWith(".typ") && path !== ".." && !path.startsWith("../") && !fileName?.startsWith("_");
|
|
13
|
-
}
|
|
14
|
-
function typstEntryId(path) {
|
|
15
|
-
const id = path.slice(0, -4);
|
|
16
|
-
return id.endsWith("/index") ? id.slice(0, -6) : id;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/loader.ts
|
|
21
|
-
function typstLoader({ base = "src/content" } = {}) {
|
|
22
|
-
return {
|
|
23
|
-
name: "astro-typst-loader",
|
|
24
|
-
async load({ config, generateDigest, logger, parseData, store, watcher }) {
|
|
25
|
-
const rootPath = (0, node_url.fileURLToPath)(config.root);
|
|
26
|
-
const basePath = (0, node_url.fileURLToPath)(new URL(base.endsWith("/") ? base : `${base}/`, config.root));
|
|
27
|
-
async function rebuildAll() {
|
|
28
|
-
const filePaths = [];
|
|
29
|
-
for await (const entry of (0, node_fs_promises.glob)("**/*.typ", { cwd: basePath })) if (isTypstEntryPath(toPosixPath(entry))) filePaths.push((0, node_path.resolve)(basePath, entry));
|
|
30
|
-
if (filePaths.length === 0) logger.warn(`No Typst files found in ${basePath}`);
|
|
31
|
-
const entries = await Promise.all(filePaths.map(async (filePath) => {
|
|
32
|
-
const id = typstEntryId(toPosixPath((0, node_path.relative)(basePath, filePath)));
|
|
33
|
-
const source = await (0, node_fs_promises.readFile)(filePath, "utf8");
|
|
34
|
-
const compiled = require_render.compileTypst(source);
|
|
35
|
-
return {
|
|
36
|
-
id,
|
|
37
|
-
source,
|
|
38
|
-
data: await parseData({
|
|
39
|
-
id,
|
|
40
|
-
data: compiled.metadata,
|
|
41
|
-
filePath
|
|
42
|
-
}),
|
|
43
|
-
html: compiled.html,
|
|
44
|
-
headings: compiled.headings,
|
|
45
|
-
filePath: toPosixPath((0, node_path.relative)(rootPath, filePath)),
|
|
46
|
-
digest: generateDigest(JSON.stringify({
|
|
47
|
-
source,
|
|
48
|
-
html: compiled.html
|
|
49
|
-
}))
|
|
50
|
-
};
|
|
51
|
-
}));
|
|
52
|
-
entries.sort((left, right) => left.id.localeCompare(right.id));
|
|
53
|
-
const entryIds = /* @__PURE__ */ new Set();
|
|
54
|
-
for (const entry of entries) {
|
|
55
|
-
if (entryIds.has(entry.id)) throw new Error(`More than one Typst content file resolves to id "${entry.id}"`);
|
|
56
|
-
entryIds.add(entry.id);
|
|
57
|
-
}
|
|
58
|
-
const untouchedEntries = new Set(store.keys());
|
|
59
|
-
for (const entry of entries) {
|
|
60
|
-
untouchedEntries.delete(entry.id);
|
|
61
|
-
store.set({
|
|
62
|
-
id: entry.id,
|
|
63
|
-
data: entry.data,
|
|
64
|
-
body: entry.source,
|
|
65
|
-
digest: entry.digest,
|
|
66
|
-
filePath: entry.filePath,
|
|
67
|
-
rendered: {
|
|
68
|
-
html: entry.html,
|
|
69
|
-
metadata: { headings: entry.headings }
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
untouchedEntries.forEach((id) => store.delete(id));
|
|
74
|
-
}
|
|
75
|
-
await rebuildAll();
|
|
76
|
-
if (!watcher) return;
|
|
77
|
-
watcher.add(basePath);
|
|
78
|
-
let activeRebuild;
|
|
79
|
-
let rebuildAgain = false;
|
|
80
|
-
const reload = async (filePath) => {
|
|
81
|
-
const entryPath = toPosixPath((0, node_path.relative)(basePath, filePath));
|
|
82
|
-
if (!isTypstEntryPath(entryPath)) return;
|
|
83
|
-
try {
|
|
84
|
-
rebuildAgain = true;
|
|
85
|
-
activeRebuild ??= (async () => {
|
|
86
|
-
while (rebuildAgain) {
|
|
87
|
-
rebuildAgain = false;
|
|
88
|
-
await rebuildAll();
|
|
89
|
-
}
|
|
90
|
-
})().finally(() => {
|
|
91
|
-
activeRebuild = void 0;
|
|
92
|
-
});
|
|
93
|
-
await activeRebuild;
|
|
94
|
-
logger.info(`Reloaded Typst content after ${entryPath}`);
|
|
95
|
-
} catch (error) {
|
|
96
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
97
|
-
logger.error(`Failed to reload Typst content after ${entryPath}: ${message}`);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
watcher.on("add", reload);
|
|
101
|
-
watcher.on("change", reload);
|
|
102
|
-
watcher.on("unlink", reload);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
//#endregion
|
|
108
|
-
Object.defineProperty(exports, 'typstLoader', {
|
|
109
|
-
enumerable: true,
|
|
110
|
-
get: function () {
|
|
111
|
-
return typstLoader;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
//# sourceMappingURL=loader-DetFooDG.cjs.map
|
package/dist/render-UEphEA_d.cjs
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
let cheerio = require("cheerio");
|
|
2
|
-
let wasm_typst_wasm_js = require("../wasm/typst_wasm.js");
|
|
3
|
-
|
|
4
|
-
//#region src/render.ts
|
|
5
|
-
function renderTypst(typst) {
|
|
6
|
-
return prepareHtml((0, wasm_typst_wasm_js.typstToHtml)(typst)).html;
|
|
7
|
-
}
|
|
8
|
-
function compileTypst(typst) {
|
|
9
|
-
const compiled = JSON.parse((0, wasm_typst_wasm_js.typstToHtmlWithMetadata)(typst));
|
|
10
|
-
if (!isRecord(compiled) || typeof compiled.html !== "string") throw new TypeError("Typst WASM returned an invalid compilation result");
|
|
11
|
-
if (!isRecord(compiled.metadata)) throw new TypeError("the Typst `astro` variable must be a dictionary");
|
|
12
|
-
const rendered = prepareHtml(compiled.html);
|
|
13
|
-
return {
|
|
14
|
-
html: rendered.html,
|
|
15
|
-
headings: rendered.headings,
|
|
16
|
-
metadata: compiled.metadata
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function isRecord(value) {
|
|
20
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21
|
-
}
|
|
22
|
-
function prepareHtml(html) {
|
|
23
|
-
const $ = (0, cheerio.load)(html, null, false);
|
|
24
|
-
const headings = [];
|
|
25
|
-
const usedIds = new Set($("[id]").map((_, element) => $(element).attr("id")).get().filter((id) => Boolean(id)));
|
|
26
|
-
$("h1, h2, h3, h4, h5, h6").each((_, heading) => {
|
|
27
|
-
const element = $(heading);
|
|
28
|
-
const text = element.text().trim();
|
|
29
|
-
let id = element.attr("id");
|
|
30
|
-
if (!id) {
|
|
31
|
-
const base = slugify(text) || "heading";
|
|
32
|
-
id = base;
|
|
33
|
-
let suffix = 2;
|
|
34
|
-
while (usedIds.has(id)) {
|
|
35
|
-
id = `${base}-${suffix}`;
|
|
36
|
-
suffix += 1;
|
|
37
|
-
}
|
|
38
|
-
element.attr("id", id);
|
|
39
|
-
usedIds.add(id);
|
|
40
|
-
}
|
|
41
|
-
headings.push({
|
|
42
|
-
depth: Number(heading.tagName.slice(1)),
|
|
43
|
-
slug: id,
|
|
44
|
-
text
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
return {
|
|
48
|
-
html: $.html(),
|
|
49
|
-
headings
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function slugify(value) {
|
|
53
|
-
return value.normalize("NFKD").replace(/\p{Mark}+/gu, "").toLocaleLowerCase("en").replace(/[’']/gu, "").replace(/[^\p{Letter}\p{Number}]+/gu, "-").replace(/^-+|-+$/gu, "");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
//#endregion
|
|
57
|
-
Object.defineProperty(exports, 'compileTypst', {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
get: function () {
|
|
60
|
-
return compileTypst;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
Object.defineProperty(exports, 'renderTypst', {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
get: function () {
|
|
66
|
-
return renderTypst;
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
//# sourceMappingURL=render-UEphEA_d.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"render-UEphEA_d.cjs","names":[],"sources":["../src/render.ts"],"sourcesContent":["import { typstToHtml, typstToHtmlWithMetadata } from \"./wasm.js\";\nimport type { MarkdownHeading } from \"astro\";\nimport { load } from \"cheerio\";\n\nexport interface CompiledTypst {\n html: string;\n headings: MarkdownHeading[];\n metadata: Record<string, unknown>;\n}\n\nexport function renderTypst(typst: string): string {\n return prepareHtml(typstToHtml(typst)).html;\n}\n\nexport function compileTypst(typst: string): CompiledTypst {\n const compiled: unknown = JSON.parse(typstToHtmlWithMetadata(typst));\n\n if (!isRecord(compiled) || typeof compiled.html !== \"string\") {\n throw new TypeError(\n \"Typst WASM returned an invalid compilation result\",\n );\n }\n\n if (!isRecord(compiled.metadata)) {\n throw new TypeError(\"the Typst `astro` variable must be a dictionary\");\n }\n\n const rendered = prepareHtml(compiled.html);\n return {\n html: rendered.html,\n headings: rendered.headings,\n metadata: compiled.metadata,\n };\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction prepareHtml(html: string): {\n html: string;\n headings: MarkdownHeading[];\n} {\n const $ = load(html, null, false);\n const headings: MarkdownHeading[] = [];\n const usedIds = new Set(\n $(\"[id]\")\n .map((_, element) => $(element).attr(\"id\"))\n .get()\n .filter((id): id is string => Boolean(id)),\n );\n\n $(\"h1, h2, h3, h4, h5, h6\").each((_, heading) => {\n const element = $(heading);\n const text = element.text().trim();\n let id = element.attr(\"id\");\n\n if (!id) {\n const base = slugify(text) || \"heading\";\n id = base;\n let suffix = 2;\n while (usedIds.has(id)) {\n id = `${base}-${suffix}`;\n suffix += 1;\n }\n element.attr(\"id\", id);\n usedIds.add(id);\n }\n\n headings.push({\n depth: Number(heading.tagName.slice(1)),\n slug: id,\n text,\n });\n });\n\n return { html: $.html(), headings };\n}\n\nfunction slugify(value: string): string {\n return value\n .normalize(\"NFKD\")\n .replace(/\\p{Mark}+/gu, \"\")\n .toLocaleLowerCase(\"en\")\n .replace(/[’']/gu, \"\")\n .replace(/[^\\p{Letter}\\p{Number}]+/gu, \"-\")\n .replace(/^-+|-+$/gu, \"\");\n}\n"],"mappings":";;;;AAUA,SAAgB,YAAY,OAAuB;AAC/C,QAAO,gDAAwB,MAAM,CAAC,CAAC;;AAG3C,SAAgB,aAAa,OAA8B;CACvD,MAAM,WAAoB,KAAK,sDAA8B,MAAM,CAAC;AAEpE,KAAI,CAAC,SAAS,SAAS,IAAI,OAAO,SAAS,SAAS,SAChD,OAAM,IAAI,UACN,oDACH;AAGL,KAAI,CAAC,SAAS,SAAS,SAAS,CAC5B,OAAM,IAAI,UAAU,kDAAkD;CAG1E,MAAM,WAAW,YAAY,SAAS,KAAK;AAC3C,QAAO;EACH,MAAM,SAAS;EACf,UAAU,SAAS;EACnB,UAAU,SAAS;EACtB;;AAGL,SA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5
|
-
function renderTypst(typst) {
|
|
6
|
-
return prepareHtml(typstToHtml(typst)).html;
|
|
7
|
-
}
|
|
8
|
-
function compileTypst(typst) {
|
|
9
|
-
const compiled = JSON.parse(typstToHtmlWithMetadata(typst));
|
|
10
|
-
if (!isRecord(compiled) || typeof compiled.html !== "string") throw new TypeError("Typst WASM returned an invalid compilation result");
|
|
11
|
-
if (!isRecord(compiled.metadata)) throw new TypeError("the Typst `astro` variable must be a dictionary");
|
|
12
|
-
const rendered = prepareHtml(compiled.html);
|
|
13
|
-
return {
|
|
14
|
-
html: rendered.html,
|
|
15
|
-
headings: rendered.headings,
|
|
16
|
-
metadata: compiled.metadata
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function isRecord(value) {
|
|
20
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21
|
-
}
|
|
22
|
-
function prepareHtml(html) {
|
|
23
|
-
const $ = load(html, null, false);
|
|
24
|
-
const headings = [];
|
|
25
|
-
const usedIds = new Set($("[id]").map((_, element) => $(element).attr("id")).get().filter((id) => Boolean(id)));
|
|
26
|
-
$("h1, h2, h3, h4, h5, h6").each((_, heading) => {
|
|
27
|
-
const element = $(heading);
|
|
28
|
-
const text = element.text().trim();
|
|
29
|
-
let id = element.attr("id");
|
|
30
|
-
if (!id) {
|
|
31
|
-
const base = slugify(text) || "heading";
|
|
32
|
-
id = base;
|
|
33
|
-
let suffix = 2;
|
|
34
|
-
while (usedIds.has(id)) {
|
|
35
|
-
id = `${base}-${suffix}`;
|
|
36
|
-
suffix += 1;
|
|
37
|
-
}
|
|
38
|
-
element.attr("id", id);
|
|
39
|
-
usedIds.add(id);
|
|
40
|
-
}
|
|
41
|
-
headings.push({
|
|
42
|
-
depth: Number(heading.tagName.slice(1)),
|
|
43
|
-
slug: id,
|
|
44
|
-
text
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
return {
|
|
48
|
-
html: $.html(),
|
|
49
|
-
headings
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function slugify(value) {
|
|
53
|
-
return value.normalize("NFKD").replace(/\p{Mark}+/gu, "").toLocaleLowerCase("en").replace(/[’']/gu, "").replace(/[^\p{Letter}\p{Number}]+/gu, "-").replace(/^-+|-+$/gu, "");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
//#endregion
|
|
57
|
-
export { renderTypst as n, compileTypst as t };
|
|
58
|
-
//# sourceMappingURL=render-hwAGjpa0.js.map
|