@floffah/astro-typst 0.1.0-rc.0 → 0.1.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/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./loader-CL78jcWw.cjs`),t=require(`./render-DdLPWB-M.cjs`),n=require(`./vite.cjs`);let r=require(`../wasm/typst_wasm.js`);exports.compileTypst=t.t,exports.renderTypst=t.n,exports.typst=n.typst,exports.typstLoader=e.t,Object.defineProperty(exports,`typstToHtml`,{enumerable:!0,get:function(){return r.typstToHtml}}),Object.defineProperty(exports,`typstToHtmlWithMetadata`,{enumerable:!0,get:function(){return r.typstToHtmlWithMetadata}});
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 { typstToHtml, typstToHtmlWithMetadata } from "./wasm.cjs";
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 { typstToHtml, typstToHtmlWithMetadata } from "./wasm.js";
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 +1 @@
1
- import{t as e}from"./loader-DVvjDXn4.js";import{typstToHtml as t,typstToHtmlWithMetadata as n}from"./wasm.js";import{n as r,t as i}from"./render-KtXoCVbt.js";import{typst as a}from"./vite.js";export{i as compileTypst,r as renderTypst,a as typst,e as typstLoader,t as typstToHtml,n as 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};
@@ -1,2 +1,2 @@
1
- import{t as e}from"./render-KtXoCVbt.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-DVvjDXn4.js.map
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-DVvjDXn4.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,qBACN,MAAM,KAAK,CACP,SACA,iBACA,SACA,YACA,QACA,WACD,CACC,IAAM,EAAW,EAAc,EAAO,KAAK,CACrC,EAAW,EACb,IAAI,IAAI,EAAK,SAAS,IAAI,CAAG,EAAO,GAAG,EAAK,GAAI,EAAO,KAAK,CAC/D,CAED,eAAe,GAA4B,CACvC,IAAM,EAAsB,EAAE,CAC9B,UAAW,IAAM,KAAS,EAAK,WAAY,CAAE,IAAK,EAAU,CAAC,CAErD,EADc,EAAY,EACA,CAAC,EAC3B,EAAU,KAAK,EAAQ,EAAU,EAAM,CAAC,CAG5C,EAAU,SAAW,GACrB,EAAO,KAAK,2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ACf,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"}
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,qBACN,MAAM,KAAK,CACP,SACA,iBACA,SACA,YACA,QACA,WACD,CACC,IAAM,EAAW,EAAc,EAAO,KAAK,CACrC,EAAW,EACb,IAAI,IAAI,EAAK,SAAS,IAAI,CAAG,EAAO,GAAG,EAAK,GAAI,EAAO,KAAK,CAC/D,CAED,eAAe,GAA4B,CACvC,IAAM,EAAsB,EAAE,CAC9B,UAAW,IAAM,KAAS,EAAK,WAAY,CAAE,IAAK,EAAU,CAAC,CAErD,EADc,EAAY,EACA,CAAC,EAC3B,EAAU,KAAK,EAAQ,EAAU,EAAM,CAAC,CAG5C,EAAU,SAAW,GACrB,EAAO,KAAK,2BAA2B,IAAW,CAEtD,IAAM,EAAU,MAAM,QAAQ,IAC1B,EAAU,IAAI,KAAO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,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"}
@@ -1,2 +1,2 @@
1
- const e=require(`./render-DdLPWB-M.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-CL78jcWw.cjs.map
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-CL78jcWw.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,CAAG,EAAG,MAAM,EAAG,GAAiB,CAAG,ECGnE,SAAgB,EAAY,CACxB,OAAO,eACa,EAAE,CAAU,CAChC,MAAO,CACH,KAAM,qBACN,MAAM,KAAK,CACP,SACA,iBACA,SACA,YACA,QACA,WACD,CACC,IAAM,GAAA,EAAA,EAAA,eAAyB,EAAO,KAAK,CACrC,GAAA,EAAA,EAAA,eACF,IAAI,IAAI,EAAK,SAAS,IAAI,CAAG,EAAO,GAAG,EAAK,GAAI,EAAO,KAAK,CAC/D,CAED,eAAe,GAA4B,CACvC,IAAM,EAAsB,EAAE,CAC9B,UAAW,IAAM,KAAA,EAAA,EAAA,MAAc,WAAY,CAAE,IAAK,EAAU,CAAC,CAErD,EADc,EAAY,EACA,CAAC,EAC3B,EAAU,MAAA,EAAA,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b,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"}
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,CAAG,EAAG,MAAM,EAAG,GAAiB,CAAG,ECGnE,SAAgB,EAAY,CACxB,OAAO,eACa,EAAE,CAAU,CAChC,MAAO,CACH,KAAM,qBACN,MAAM,KAAK,CACP,SACA,iBACA,SACA,YACA,QACA,WACD,CACC,IAAM,GAAA,EAAA,EAAA,eAAyB,EAAO,KAAK,CACrC,GAAA,EAAA,EAAA,eACF,IAAI,IAAI,EAAK,SAAS,IAAI,CAAG,EAAO,GAAG,EAAK,GAAI,EAAO,KAAK,CAC/D,CAED,eAAe,GAA4B,CACvC,IAAM,EAAsB,EAAE,CAC9B,UAAW,IAAM,KAAA,EAAA,EAAA,MAAc,WAAY,CAAE,IAAK,EAAU,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,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 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./loader-CL78jcWw.cjs`);exports.typstLoader=e.t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./loader-H5uKHfiV.cjs`);exports.typstLoader=e.t;
package/dist/loader.js CHANGED
@@ -1 +1 @@
1
- import{t as e}from"./loader-DVvjDXn4.js";export{e as typstLoader};
1
+ import{t as e}from"./loader-C5JXSvPj.js";export{e as typstLoader};
@@ -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-KtXoCVbt.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":"oGAUA,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,EAAS,SAAS,CAC5B,MAAU,UAAU,kDAAkD,CAG1E,IAAM,EAAW,EAAY,EAAS,KAAK,CAC3C,MAAO,CACH,KAAM,EAAS,KACf,SAAU,EAAS,SACnB,SAAU,EAAS,SACtB,CAGL,SAAS,EAAS,EAAkD,CAChE,OAAO,OAAO,GAAU,YAAY,GAAkB,CAAC,MAAM,QAAQ,EAAM,CAG/E,SAAS,EAAY,EAGnB,CACE,IAAM,EAAI,EAAK,EAAM,KAAM,GAAM,CAC3B,EAA8B,EAAE,CAChC,EAAU,IAAI,IAChB,EAAE,OAAO,CACJ,KAAK,EAAG,IAAY,EAAE,EAAQ,CAAC,KAAK,KAAK,CAAC,CAC1C,KAAK,CACL,OAAQ,GAAqB,EAAQ,EAAI,CACjD,CA0BD,OAxBA,EAAE,yBAAyB,CAAC,MAAM,EAAG,IAAY,CAC7C,IAAM,EAAU,EAAE,EAAQ,CACpB,EAAO,EAAQ,MAAM,CAAC,MAAM,CAC9B,EAAK,EAAQ,KAAK,KAAK,CAE3B,GAAI,CAAC,EAAI,CACL,IAAM,EAAO,EAAQ,EAAK,EAAI,UAC9B,EAAK,EACL,IAAI,EAAS,EACb,KAAO,EAAQ,IAAI,EAAG,EAClB,EAAK,GAAG,EAAK,GAAG,IAChB,GAAU,EAEd,EAAQ,KAAK,KAAM,EAAG,CACtB,EAAQ,IAAI,EAAG,CAGnB,EAAS,KAAK,CACV,MAAO,OAAO,EAAQ,QAAQ,MAAM,EAAE,CAAC,CACvC,KAAM,EACN,OACH,CAAC,EACJ,CAEK,CAAE,KAAM,EAAE,MAAM,CAAE,WAAU,CAGvC,SAAS,EAAQ,EAAuB,CACpC,OAAO,EACF,UAAU,OAAO,CACjB,QAAQ,cAAe,GAAG,CAC1B,kBAAkB,KAAK,CACvB,QAAQ,SAAU,GAAG,CACrB,QAAQ,6BAA8B,IAAI,CAC1C,QAAQ,YAAa,GAAG"}
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,EAAS,SAAS,CAC5B,MAAU,UAAU,kDAAkD,CAG1E,IAAM,EAAW,EAAY,EAAS,KAAK,CAC3C,MAAO,CACH,KAAM,EAAS,KACf,SAAU,EAAS,SACnB,SAAU,EAAS,SACtB,CAGL,SAAS,EAAS,EAAkD,CAChE,OAAO,OAAO,GAAU,YAAY,GAAkB,CAAC,MAAM,QAAQ,EAAM,CAG/E,SAAS,EAAY,EAGnB,CACE,IAAM,EAAI,EAAK,EAAM,KAAM,GAAM,CAC3B,EAA8B,EAAE,CAChC,EAAU,IAAI,IAChB,EAAE,OAAO,CACJ,KAAK,EAAG,IAAY,EAAE,EAAQ,CAAC,KAAK,KAAK,CAAC,CAC1C,KAAK,CACL,OAAQ,GAAqB,EAAQ,EAAI,CACjD,CA0BD,OAxBA,EAAE,yBAAyB,CAAC,MAAM,EAAG,IAAY,CAC7C,IAAM,EAAU,EAAE,EAAQ,CACpB,EAAO,EAAQ,MAAM,CAAC,MAAM,CAC9B,EAAK,EAAQ,KAAK,KAAK,CAE3B,GAAI,CAAC,EAAI,CACL,IAAM,EAAO,EAAQ,EAAK,EAAI,UAC9B,EAAK,EACL,IAAI,EAAS,EACb,KAAO,EAAQ,IAAI,EAAG,EAClB,EAAK,GAAG,EAAK,GAAG,IAChB,GAAU,EAEd,EAAQ,KAAK,KAAM,EAAG,CACtB,EAAQ,IAAI,EAAG,CAGnB,EAAS,KAAK,CACV,MAAO,OAAO,EAAQ,QAAQ,MAAM,EAAE,CAAC,CACvC,KAAM,EACN,OACH,CAAC,EACJ,CAEK,CAAE,KAAM,EAAE,MAAM,CAAE,WAAU,CAGvC,SAAS,EAAQ,EAAuB,CACpC,OAAO,EACF,UAAU,OAAO,CACjB,QAAQ,cAAe,GAAG,CAC1B,kBAAkB,KAAK,CACvB,QAAQ,SAAU,GAAG,CACrB,QAAQ,6BAA8B,IAAI,CAC1C,QAAQ,YAAa,GAAG"}
@@ -0,0 +1,2 @@
1
+ const e=require(`./wasm-BSRnB8hH.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,MAAU,UACN,oDACH,CAGL,GAAI,CAAC,EAAS,EAAS,SAAS,CAC5B,MAAU,UAAU,kDAAkD,CAG1E,IAAM,EAAW,EAAY,EAAS,KAAK,CAC3C,MAAO,CACH,KAAM,EAAS,KACf,SAAU,EAAS,SACnB,SAAU,EAAS,SACtB,CAGL,SAAS,EAAS,EAAkD,CAChE,OAAO,OAAO,GAAU,YAAY,GAAkB,CAAC,MAAM,QAAQ,EAAM,CAG/E,SAAS,EAAY,EAGnB,CACE,IAAM,GAAA,EAAA,EAAA,MAAS,EAAM,KAAM,GAAM,CAC3B,EAA8B,EAAE,CAChC,EAAU,IAAI,IAChB,EAAE,OAAO,CACJ,KAAK,EAAG,IAAY,EAAE,EAAQ,CAAC,KAAK,KAAK,CAAC,CAC1C,KAAK,CACL,OAAQ,GAAqB,EAAQ,EAAI,CACjD,CA0BD,OAxBA,EAAE,yBAAyB,CAAC,MAAM,EAAG,IAAY,CAC7C,IAAM,EAAU,EAAE,EAAQ,CACpB,EAAO,EAAQ,MAAM,CAAC,MAAM,CAC9B,EAAK,EAAQ,KAAK,KAAK,CAE3B,GAAI,CAAC,EAAI,CACL,IAAM,EAAO,EAAQ,EAAK,EAAI,UAC9B,EAAK,EACL,IAAI,EAAS,EACb,KAAO,EAAQ,IAAI,EAAG,EAClB,EAAK,GAAG,EAAK,GAAG,IAChB,GAAU,EAEd,EAAQ,KAAK,KAAM,EAAG,CACtB,EAAQ,IAAI,EAAG,CAGnB,EAAS,KAAK,CACV,MAAO,OAAO,EAAQ,QAAQ,MAAM,EAAE,CAAC,CACvC,KAAM,EACN,OACH,CAAC,EACJ,CAEK,CAAE,KAAM,EAAE,MAAM,CAAE,WAAU,CAGvC,SAAS,EAAQ,EAAuB,CACpC,OAAO,EACF,UAAU,OAAO,CACjB,QAAQ,cAAe,GAAG,CAC1B,kBAAkB,KAAK,CACvB,QAAQ,SAAU,GAAG,CACrB,QAAQ,6BAA8B,IAAI,CAC1C,QAAQ,YAAa,GAAG"}
package/dist/vite.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./render-DdLPWB-M.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;
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;
2
2
  //# sourceMappingURL=vite.cjs.map
package/dist/vite.js CHANGED
@@ -1,2 +1,2 @@
1
- import{n as e}from"./render-KtXoCVbt.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};
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};
2
2
  //# sourceMappingURL=vite.js.map
@@ -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,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,GAAI,EAEA,KADA,GAAO,EAAG,EAAO,EACX,EAAW,EAAG,CAIxB,MAFA,GAAc,EACd,EAAc,EACP,EAAmB,EAAM,EAAK,QAC/B,CACN,EAAK,gCAAgC,GAAG,CACxC,EAAK,mBAAmB,EAAa,EAAa,EAAE,EAS5D,SAAgB,EAAwB,EAAO,CAC3C,IAAI,EACA,EACJ,GAAI,CACA,IAAM,EAAS,EAAK,gCAAgC,IAAI,CAClD,EAAO,EAAkB,EAAO,EAAK,kBAAmB,EAAK,mB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AAmB,aACnB,EAAoB,IAAI,YAAY,QAAS,CAAE,UAAW,GAAM,MAAO,GAAM,CAAC,CAC9E,EAAkB,QAAQ,CAC1B,EAAkB,GAEf,EAAkB,OAAO,GAAsB,CAAC,SAAS,EAAK,EAAM,EAAI,CAAC,CAGpF,MAAM,EAAoB,IAAI,YAExB,eAAgB,IAClB,EAAkB,WAAa,SAAU,EAAK,EAAM,CAChD,IAAM,EAAM,EAAkB,OAAO,EAAI,CAEzC,OADA,EAAK,IAAI,EAAI,CACN,CACH,KAAM,EAAI,OACV,QAAS,EAAI,OAChB,GAIT,IAAI,EAAkB,EAEQ,EAC9B,SAAS,EAAoB,EAAU,EAAQ,CAM3C,MAJA,GAAO,EAAS,QAEhB,EAAwB,KACxB,EAA0B,KACnB,EAsCX,SAAS,EAAS,EAAQ,CACtB,GAAI,IAAS,IAAA,GAAW,OAAO,EAG3B,IAAW,IAAA,KACP,OAAO,eAAe,EAAO,GAAK,OAAO,UACxC,WAAW,EAEZ,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,CA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AAI,IAAS,IAAA,GAAW,OAAO,EAG3B,IAAW,IAAA,KACP,OAAO,eAAe,EAAO,GAAK,OAAO,UACxC,WAAW,EAEZ,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,OAAQ,EACJ,IAAI,IAAI,6BAA8B,OAAO,KAAK,IAAI,CACzD,CACJ,CAAC"}
package/dist/wasm.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`../wasm/typst_wasm.js`);Object.defineProperty(exports,`typstToHtml`,{enumerable:!0,get:function(){return e.typstToHtml}}),Object.defineProperty(exports,`typstToHtmlWithMetadata`,{enumerable:!0,get:function(){return e.typstToHtmlWithMetadata}});
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 { typstToHtml, typstToHtmlWithMetadata } from "../wasm/typst_wasm.js";
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 { typstToHtml, typstToHtmlWithMetadata } from "../wasm/typst_wasm.js";
1
+ import { n as typstToHtmlWithMetadata, t as typstToHtml } from "./wasm-Bp_4rcoG.js";
2
2
  export { typstToHtml, typstToHtmlWithMetadata };
package/dist/wasm.js CHANGED
@@ -1 +1 @@
1
- import{typstToHtml as e,typstToHtmlWithMetadata as t}from"../wasm/typst_wasm.js";export{e as typstToHtml,t as typstToHtmlWithMetadata};
1
+ import{n as e,t}from"./wasm-j2mRjvaE.js";export{t as typstToHtml,e as typstToHtmlWithMetadata};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floffah/astro-typst",
3
- "version": "0.1.0-rc.0",
3
+ "version": "0.1.0",
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 nodejs --out-dir ../../wasm --no-pack && bun run scripts/write-wasm-package.ts",
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 .",
package/wasm/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "type": "commonjs",
2
+ "type": "module",
3
3
  "private": true
4
4
  }
@@ -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>;
@@ -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
- const wasmPath = `${__dirname}/typst_wasm_bg.wasm`;
188
- const wasmBytes = require('fs').readFileSync(wasmPath);
189
- const wasmModule = new WebAssembly.Module(wasmBytes);
190
- let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
191
- let wasm = wasmInstance.exports;
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 };
Binary file
@@ -1,2 +0,0 @@
1
- let e=require(`cheerio`),t=require(`../wasm/typst_wasm.js`);function n(e){return a((0,t.typstToHtml)(e)).html}function r(e){let n=JSON.parse((0,t.typstToHtmlWithMetadata)(e));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(t){let n=(0,e.load)(t,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-DdLPWB-M.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"render-DdLPWB-M.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":"4DAUA,SAAgB,EAAY,EAAuB,CAC/C,OAAO,GAAA,EAAA,EAAA,aAAwB,EAAM,CAAC,CAAC,KAG3C,SAAgB,EAAa,EAA8B,CACvD,IAAM,EAAoB,KAAK,OAAA,EAAA,EAAA,yBAA8B,EAAM,CAAC,CAEpE,GAAI,CAAC,EAAS,EAAS,EAAI,OAAO,EAAS,MAAS,SAChD,MAAU,UACN,oDACH,CAGL,GAAI,CAAC,EAAS,EAAS,S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adata as t}from"./wasm.js";import{load as n}from"cheerio";function r(t){return o(e(t)).html}function i(e){let n=JSON.parse(t(e));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-KtXoCVbt.js.map