@floffah/astro-typst 0.0.0 → 0.1.0-rc.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,22 +1 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
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-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}});
package/dist/index.js CHANGED
@@ -1,6 +1 @@
1
- import { t as typstLoader } from "./loader-CxNOQzU1.js";
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-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};
@@ -0,0 +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 +1 @@
1
- {"version":3,"file":"loader-DetFooDG.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":";;;;;;AAEA,SAAgB,YAAY,MAAsB;AAC9C,QAAO,KAAK,MAAMA,cAAI,CAAC,KAAK,IAAI;;AAGpC,SAAgB,iBAAiB,MAAuB;CACpD,MAAM,WAAW,KAAK,MAAM,IAAI,CAAC,GAAG,GAAG;AAEvC,QACI,KAAK,SAAS,OAAO,IACrB,SAAS,QACT,CAAC,KAAK,WAAW,MAAM,IACvB,CAAC,UAAU,WAAW,IAAI;;AAIlC,SAAgB,aAAa,MAAsB;CAC/C,MAAM,KAAK,KAAK,MAAM,GAAG,GAAe;AACxC,QAAO,GAAG,SAAS,SAAS,GAAG,GAAG,MAAM,GAAG,GAAiB,GAAG;;;;;ACGnE,SAAgB,YAAY,EACxB,OAAO,kBACa,EAAE,EAAU;AAChC,QAAO;EACH,MAAM;EACN,MAAM,KAAK,EACP,QACA,gBACA,QACA,WACA,OACA,WACD;GACC,MAAM,uCAAyB,OAAO,KAAK;GAC3C,MAAM,uCACF,IAAI,IAAI,KAAK,SAAS,IAAI,GAAG,OAAO,GAAG,KAAK,IAAI,OAAO,KAAK,CAC/D;GAED,eAAe,aAA4B;IACvC,MAAM,YAAsB,EAAE;AAC9B,eAAW,MAAM,oCAAc,YAAY,EAAE,KAAK,UAAU,CAAC,CAEzD,KAAI,iBADc,YAAY,MACA,CAAC,CAC3B,WAAU,4BAAa,UAAU,MAAM,CAAC;AAGhD,QAAI,UAAU,WAAW,EACrB,QAAO,KAAK,2BAA2B,WAAW;IAEtD,MAAM,UAAU,MAAM,QAAQ,IAC1B,UAAU,IAAI,OAAO,aAAqC;KAItD,MAAM,KAAK,aAHO,oCACL,UAAU,SAAS,CAEC,CAAC;K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AAC,cAAc;AACf,sBAAgB;OAClB;AACF,WAAM;AACN,YAAO,KAAK,gCAAgC,YAAY;aACnD,OAAO;KACZ,MAAM,UACF,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AAC1D,YAAO,MACH,wCAAwC,UAAU,IAAI,UACzD;;;AAIT,WAAQ,GAAG,OAAO,OAAO;AACzB,WAAQ,GAAG,UAAU,OAAO;AAC5B,WAAQ,GAAG,UAAU,OAAO;;EAEnC"}
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,EAAA,SAAa,EAAU,EAAM,CAAC,CAG5C,EAAU,SAAW,GACrB,EAAO,KAAK,2BAA2B,IAAW,CAEtD,IAAM,EAAU,MAAM,QAAQ,IAC1B,EAAU,IAAI,KA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B,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
+ 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 +1 @@
1
- {"version":3,"file":"loader-CxNOQzU1.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":";;;;;;AAEA,SAAgB,YAAY,MAAsB;AAC9C,QAAO,KAAK,MAAM,IAAI,CAAC,KAAK,IAAI;;AAGpC,SAAgB,iBAAiB,MAAuB;CACpD,MAAM,WAAW,KAAK,MAAM,IAAI,CAAC,GAAG,GAAG;AAEvC,QACI,KAAK,SAAS,OAAO,IACrB,SAAS,QACT,CAAC,KAAK,WAAW,MAAM,IACvB,CAAC,UAAU,WAAW,IAAI;;AAIlC,SAAgB,aAAa,MAAsB;CAC/C,MAAM,KAAK,KAAK,MAAM,GAAG,GAAe;AACxC,QAAO,GAAG,SAAS,SAAS,GAAG,GAAG,MAAM,GAAG,GAAiB,GAAG;;;;;ACGnE,SAAgB,YAAY,EACxB,OAAO,kBACa,EAAE,EAAU;AAChC,QAAO;EACH,MAAM;EACN,MAAM,KAAK,EACP,QACA,gBACA,QACA,WACA,OACA,WACD;GACC,MAAM,WAAW,cAAc,OAAO,KAAK;GAC3C,MAAM,WAAW,cACb,IAAI,IAAI,KAAK,SAAS,IAAI,GAAG,OAAO,GAAG,KAAK,IAAI,OAAO,KAAK,CAC/D;GAED,eAAe,aAA4B;IACvC,MAAM,YAAsB,EAAE;AAC9B,eAAW,MAAM,SAAS,KAAK,YAAY,EAAE,KAAK,UAAU,CAAC,CAEzD,KAAI,iBADc,YAAY,MACA,CAAC,CAC3B,WAAU,KAAK,QAAQ,UAAU,MAAM,CAAC;AAGhD,QAAI,UAAU,WAAW,EACrB,QAAO,KAAK,2BAA2B,WAAW;IAEtD,MAAM,UAAU,MAAM,QA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AAE;AAElC,QAAI;AACA,oBAAe;AACf,wBAAmB,YAAY;AAC3B,aAAO,cAAc;AACjB,sBAAe;AACf,aAAM,YAAY;;SAEtB,CAAC,cAAc;AACf,sBAAgB;OAClB;AACF,WAAM;AACN,YAAO,KAAK,gCAAgC,YAAY;aACnD,OAAO;KACZ,MAAM,UACF,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AAC1D,YAAO,MACH,wCAAwC,UAAU,IAAI,UACzD;;;AAIT,WAAQ,GAAG,OAAO,OAAO;AACzB,WAAQ,GAAG,UAAU,OAAO;AAC5B,WAAQ,GAAG,UAAU,OAAO;;EAEnC"}
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,2BAA2B,IAAW,CAEtD,IAAM,EA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,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, Symbol.toStringTag, { value: 'Module' });
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-CL78jcWw.cjs`);exports.typstLoader=e.t;
package/dist/loader.js CHANGED
@@ -1,3 +1 @@
1
- import { t as typstLoader } from "./loader-CxNOQzU1.js";
2
-
3
- export { typstLoader };
1
+ import{t as e}from"./loader-DVvjDXn4.js";export{e as typstLoader};
@@ -0,0 +1,2 @@
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 +1 @@
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,SAAS,SAAS,OAAkD;AAChE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;AAG/E,SAAS,YAAY,MAGnB;CACE,MAAM,sBAAS,MAAM,MAAM,MAAM;CACjC,MAAM,WAA8B,EAAE;CACtC,MAAM,UAAU,IAAI,IAChB,EAAE,OAAO,CACJ,KAAK,GAAG,YAAY,EAAE,QAAQ,CAAC,KAAK,KAAK,CAAC,CAC1C,KAAK,CACL,QAAQ,OAAqB,QAAQ,GAAG,CAAC,CACjD;AAED,GAAE,yBAAyB,CAAC,MAAM,GAAG,YAAY;EAC7C,MAAM,UAAU,EAAE,QAAQ;EAC1B,MAAM,OAAO,QAAQ,MAAM,CAAC,MAAM;EAClC,IAAI,KAAK,QAAQ,KAAK,KAAK;AAE3B,MAAI,CAAC,IAAI;GACL,MAAM,OAAO,QAAQ,KAAK,IAAI;AAC9B,QAAK;GACL,IAAI,SAAS;AACb,UAAO,QAAQ,IAAI,GAAG,EAAE;AACpB,SAAK,GAAG,KAAK,GAAG;AAChB,cAAU;;AAEd,WAAQ,KAAK,MAAM,GAAG;AACtB,WAAQ,IAAI,GAAG;;AAGnB,WAAS,KAAK;GACV,OAAO,OAAO,QAAQ,QAAQ,MAAM,EAAE,CAAC;GACvC,MAAM;GACN;GACH,CAAC;GACJ;AAEF,QAAO;EAAE,MAAM,EAAE,MAAM;EAAE;EAAU;;AAGvC,SAAS,QAAQ,OAAuB;AACpC,QAAO,MACF,UAAU,OAAO,CACjB,QAAQ,eAAe,GAAG,CAC1B,kBAAkB,KAAK,CACvB,QAAQ,UAAU,GAAG,CACrB,QAAQ,8BAA8B,IAAI,CAC1C,QAAQ,aAAa,GAAG"}
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,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"}
@@ -0,0 +1,2 @@
1
+ import{typstToHtml as e,typstToHtmlWithMetadata 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
@@ -1 +1 @@
1
- {"version":3,"file":"render-hwAGjpa0.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":";;;;AAUA,SAAgB,YAAY,OAAuB;AAC/C,QAAO,YAAY,YAAY,MAAM,CAAC,CAAC;;AAG3C,SAAgB,aAAa,OAA8B;CACvD,MAAM,WAAoB,KAAK,MAAM,wBAAwB,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,SAAS,SAAS,OAAkD;AAChE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;AAG/E,SAAS,YAAY,MAGnB;CACE,MAAM,IAAI,KAAK,MAAM,MAAM,MAAM;CACjC,MAAM,WAA8B,EAAE;CACtC,MAAM,UAAU,IAAI,IAChB,EAAE,OAAO,CACJ,KAAK,GAAG,YAAY,EAAE,QAAQ,CAAC,KAAK,KAAK,CAAC,CAC1C,KAAK,CACL,QAAQ,OAAqB,QAAQ,GAAG,CAAC,CACjD;AAED,GAAE,yBAAyB,CAAC,MAAM,GAAG,YAAY;EAC7C,MAAM,UAAU,EAAE,QAAQ;EAC1B,MAAM,OAAO,QAAQ,MAAM,CAAC,MAAM;EAClC,IAAI,KAAK,QAAQ,KAAK,KAAK;AAE3B,MAAI,CAAC,IAAI;GACL,MAAM,OAAO,QAAQ,KAAK,IAAI;AAC9B,QAAK;GACL,IAAI,SAAS;AACb,UAAO,QAAQ,IAAI,GAAG,EAAE;AACpB,SAAK,GAAG,KAAK,GAAG;AAChB,cAAU;;AAEd,WAAQ,KAAK,MAAM,GAAG;AACtB,WAAQ,IAAI,GAAG;;AAGnB,WAAS,KAAK;GACV,OAAO,OAAO,QAAQ,QAAQ,MAAM,EAAE,CAAC;GACvC,MAAM;GACN;GACH,CAAC;GACJ;AAEF,QAAO;EAAE,MAAM,EAAE,MAAM;EAAE;EAAU;;AAGvC,SAAS,QAAQ,OAAuB;AACpC,QAAO,MACF,UAAU,OAAO,CACjB,QAAQ,eAAe,GAAG,CAC1B,kBAAkB,KAAK,CACvB,QAAQ,UAAU,GAAG,CACrB,QAAQ,8BAA8B,IAAI,CAC1C,QAAQ,aAAa,GAAG"}
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,EAA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,CACvB,QAAQ,SAAU,GAAG,CACrB,QAAQ,6BAA8B,IAAI,CAC1C,QAAQ,YAAa,GAAG"}
package/dist/vite.cjs CHANGED
@@ -1,25 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
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-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;
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":";;;;;AAQA,SAAgB,MAAM,EAClB,UAAU,aACU,EAAE,EAAgB;AACtC,QAAO;EACH,MAAM;EACN,SAAS;EACT,WAAW;GACP,QAAQ,EAAE,IAAI,SAAS;GACvB,QAAQ,QAAQ;IACZ,MAAM,OAAOA,2BAAY,OAAO;AAChC,WAAO;KACH,MAAM,kBAAkB,KAAK,UAAU,KAAK,CAAC;KAC7C,KAAK;KACR;;GAER;EACJ"}
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 { n as renderTypst } from "./render-hwAGjpa0.js";
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-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};
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":";;;;AAQA,SAAgB,MAAM,EAClB,UAAU,aACU,EAAE,EAAgB;AACtC,QAAO;EACH,MAAM;EACN,SAAS;EACT,WAAW;GACP,QAAQ,EAAE,IAAI,SAAS;GACvB,QAAQ,QAAQ;IACZ,MAAM,OAAO,YAAY,OAAO;AAChC,WAAO;KACH,MAAM,kBAAkB,KAAK,UAAU,KAAK,CAAC;KAC7C,KAAK;KACR;;GAER;EACJ"}
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"}
package/dist/wasm.cjs CHANGED
@@ -1,15 +1 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
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`});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}});
package/dist/wasm.js CHANGED
@@ -1,3 +1 @@
1
- import { typstToHtml, typstToHtmlWithMetadata } from "../wasm/typst_wasm.js";
2
-
3
- export { typstToHtml, typstToHtmlWithMetadata };
1
+ import{typstToHtml as e,typstToHtmlWithMetadata as t}from"../wasm/typst_wasm.js";export{e as typstToHtml,t as typstToHtmlWithMetadata};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floffah/astro-typst",
3
- "version": "0.0.0",
3
+ "version": "0.1.0-rc.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,
@@ -123,7 +123,8 @@
123
123
  },
124
124
  "author": "Floffah <therealfloffah@gmail.com>",
125
125
  "publishConfig": {
126
- "access": "public"
126
+ "access": "public",
127
+ "provenance": true
127
128
  },
128
129
  "packageManager": "bun@1.3.14",
129
130
  "license": "MIT"
Binary file
@@ -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
@@ -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
@@ -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,58 +0,0 @@
1
- import { typstToHtml, typstToHtmlWithMetadata } from "./wasm.js";
2
- import { load } from "cheerio";
3
-
4
- //#region src/render.ts
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