fuma-content 0.0.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/bin.d.ts +1 -0
  2. package/dist/bin.js +18 -0
  3. package/dist/build-mdx-I4NROXCF.js +8 -0
  4. package/dist/bun/index.d.ts +16 -0
  5. package/dist/bun/index.js +37 -0
  6. package/dist/bun-DMNX4PBC.js +40 -0
  7. package/dist/chunk-3VQS3KSP.js +39 -0
  8. package/dist/chunk-BTRE6MOX.js +16 -0
  9. package/dist/chunk-E4HRKSP4.js +24 -0
  10. package/dist/chunk-ERBMAQYP.js +33 -0
  11. package/dist/chunk-GGL4EF6H.js +38 -0
  12. package/dist/chunk-JBZTQ55D.js +30 -0
  13. package/dist/chunk-KH5GT2Y5.js +104 -0
  14. package/dist/chunk-LUM7SIZN.js +40 -0
  15. package/dist/chunk-MT7RY65Y.js +167 -0
  16. package/dist/chunk-NRZ4GE5O.js +207 -0
  17. package/dist/chunk-OQQNA7L7.js +412 -0
  18. package/dist/chunk-OUJENWQ4.js +45 -0
  19. package/dist/chunk-RMSV4HP6.js +85 -0
  20. package/dist/chunk-RXR7OL76.js +37 -0
  21. package/dist/chunk-VWJKRQZR.js +19 -0
  22. package/dist/chunk-W6HENTK7.js +44 -0
  23. package/dist/chunk-XR5N6ZXJ.js +50 -0
  24. package/dist/collections/handlers/fs.d.ts +10 -0
  25. package/dist/collections/handlers/fs.js +6 -0
  26. package/dist/collections/index.d.ts +10 -0
  27. package/dist/collections/index.js +6 -0
  28. package/dist/collections/mdx/loader-webpack.d.ts +17 -0
  29. package/dist/collections/mdx/loader-webpack.js +39 -0
  30. package/dist/collections/mdx/runtime-browser.d.ts +55 -0
  31. package/dist/collections/mdx/runtime-browser.js +82 -0
  32. package/dist/collections/mdx/runtime-dynamic.d.ts +43 -0
  33. package/dist/collections/mdx/runtime-dynamic.js +96 -0
  34. package/dist/collections/mdx/runtime.d.ts +70 -0
  35. package/dist/collections/mdx/runtime.js +45 -0
  36. package/dist/collections/mdx.d.ts +10 -0
  37. package/dist/collections/mdx.js +291 -0
  38. package/dist/collections/meta/loader-webpack.d.ts +17 -0
  39. package/dist/collections/meta/loader-webpack.js +42 -0
  40. package/dist/collections/meta/runtime.d.ts +19 -0
  41. package/dist/collections/meta/runtime.js +18 -0
  42. package/dist/collections/meta.d.ts +10 -0
  43. package/dist/collections/meta.js +170 -0
  44. package/dist/collections/runtime/file-store.d.ts +19 -0
  45. package/dist/collections/runtime/file-store.js +7 -0
  46. package/dist/collections/runtime/store.d.ts +28 -0
  47. package/dist/collections/runtime/store.js +6 -0
  48. package/dist/config/index.d.ts +10 -0
  49. package/dist/config/index.js +7 -0
  50. package/dist/core-Bo8KaWQz.d.ts +411 -0
  51. package/dist/index.d.ts +15 -31
  52. package/dist/index.js +6 -49
  53. package/dist/load-from-file-HL2VEY3M.js +7 -0
  54. package/dist/loader-NFSL6P5I.js +7 -0
  55. package/dist/loader-T756NSCS.js +7 -0
  56. package/dist/next/index.cjs +594 -0
  57. package/dist/next/index.d.ts +27 -0
  58. package/dist/next/index.js +100 -0
  59. package/dist/node/loader.d.ts +5 -0
  60. package/dist/node/loader.js +47 -0
  61. package/dist/node-DCMYL4DL.js +34 -0
  62. package/dist/plugins/git.d.ts +10 -0
  63. package/dist/plugins/git.js +70 -0
  64. package/dist/plugins/json-schema.d.ts +10 -0
  65. package/dist/plugins/json-schema.js +59 -0
  66. package/dist/plugins/with-loader/index.d.ts +61 -0
  67. package/dist/plugins/with-loader/index.js +6 -0
  68. package/dist/plugins/with-loader/webpack.d.ts +27 -0
  69. package/dist/plugins/with-loader/webpack.js +12 -0
  70. package/dist/vite/index.d.ts +33 -0
  71. package/dist/vite/index.js +61 -0
  72. package/dist/vite-QCUPZHHB.js +32 -0
  73. package/package.json +104 -36
  74. package/dist/internal.d.ts +0 -114
  75. package/dist/internal.js +0 -420
@@ -0,0 +1,85 @@
1
+ import {
2
+ validate
3
+ } from "./chunk-OUJENWQ4.js";
4
+
5
+ // src/collections/meta/loader.ts
6
+ import { dump, load } from "js-yaml";
7
+ import { z } from "zod";
8
+ var querySchema = z.object({
9
+ collection: z.string().optional(),
10
+ workspace: z.string().optional()
11
+ }).loose();
12
+ function createMetaLoader({ getCore }, resolve = {}) {
13
+ const { json: resolveJson = "js", yaml: resolveYaml = "js" } = resolve;
14
+ function parse(filePath, source) {
15
+ try {
16
+ if (filePath.endsWith(".json")) return JSON.parse(source);
17
+ if (filePath.endsWith(".yaml")) return load(source);
18
+ } catch (e) {
19
+ throw new Error(`invalid data in ${filePath}`, { cause: e });
20
+ }
21
+ throw new Error(`Unknown file type ${filePath}`);
22
+ }
23
+ function onMeta(source, { filePath, query }) {
24
+ const parsed = querySchema.safeParse(query);
25
+ if (!parsed.success || !parsed.data.collection) return null;
26
+ const { collection: collectionName, workspace } = parsed.data;
27
+ return async () => {
28
+ let core = await getCore();
29
+ if (workspace) {
30
+ core = core.getWorkspaces().get(workspace) ?? core;
31
+ }
32
+ const collection = core.getCollection(collectionName);
33
+ const handler = collection?.handlers.meta;
34
+ let data = parse(filePath, source);
35
+ if (!handler) return data;
36
+ const context = {
37
+ path: filePath,
38
+ source
39
+ };
40
+ if (handler.schema) {
41
+ data = await validate(
42
+ handler.schema,
43
+ data,
44
+ context,
45
+ `invalid data in ${filePath}`
46
+ );
47
+ }
48
+ return handler.transform?.call(context, data);
49
+ };
50
+ }
51
+ return {
52
+ async load(input) {
53
+ const result = onMeta(await input.getSource(), input);
54
+ if (result === null) return null;
55
+ const data = await result();
56
+ if (input.filePath.endsWith(".json")) {
57
+ return {
58
+ code: resolveJson === "json" ? JSON.stringify(data) : `export default ${JSON.stringify(data)}`
59
+ };
60
+ } else {
61
+ return {
62
+ code: resolveYaml === "yaml" ? dump(data) : `export default ${JSON.stringify(data)}`
63
+ };
64
+ }
65
+ },
66
+ bun: {
67
+ load(source, input) {
68
+ const result = onMeta(source, input);
69
+ if (result === null)
70
+ return {
71
+ loader: "object",
72
+ exports: parse(input.filePath, source)
73
+ };
74
+ return result().then((data) => ({
75
+ loader: "object",
76
+ exports: { default: data }
77
+ }));
78
+ }
79
+ }
80
+ };
81
+ }
82
+
83
+ export {
84
+ createMetaLoader
85
+ };
@@ -0,0 +1,37 @@
1
+ import {
2
+ SimpleCollectionStore
3
+ } from "./chunk-3VQS3KSP.js";
4
+
5
+ // src/collections/runtime/file-store.ts
6
+ import path from "path";
7
+ function fileInfo(base, globKey) {
8
+ if (globKey.startsWith("./")) {
9
+ globKey = globKey.slice(2);
10
+ }
11
+ return {
12
+ path: globKey,
13
+ fullPath: path.join(base, globKey)
14
+ };
15
+ }
16
+ var FileCollectionStore = class extends SimpleCollectionStore {
17
+ constructor(base, glob) {
18
+ const data = /* @__PURE__ */ new Map();
19
+ for (const [key, value] of Object.entries(glob)) {
20
+ data.set(key, {
21
+ ...value,
22
+ ...fileInfo(base, key)
23
+ });
24
+ }
25
+ super(data);
26
+ }
27
+ transform(fn) {
28
+ return super.transform(fn);
29
+ }
30
+ $data(_cast) {
31
+ return super.$data(_cast);
32
+ }
33
+ };
34
+
35
+ export {
36
+ FileCollectionStore
37
+ };
@@ -0,0 +1,19 @@
1
+ // src/utils/fuma-matter.ts
2
+ import { load } from "js-yaml";
3
+ var regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
4
+ function fumaMatter(input) {
5
+ const output = { matter: "", data: {}, content: input };
6
+ const match = regex.exec(input);
7
+ if (!match) {
8
+ return output;
9
+ }
10
+ output.matter = match[0];
11
+ output.content = input.slice(match[0].length);
12
+ const loaded = load(match[1]);
13
+ output.data = loaded ?? {};
14
+ return output;
15
+ }
16
+
17
+ export {
18
+ fumaMatter
19
+ };
@@ -0,0 +1,44 @@
1
+ // src/config/build.ts
2
+ function buildConfig(config, workspace) {
3
+ const collections = /* @__PURE__ */ new Map();
4
+ const loaded = {};
5
+ let globalConfig;
6
+ if ("default" in config) {
7
+ globalConfig = config.default;
8
+ for (const [k, v] of Object.entries(config)) {
9
+ if (k === "default") continue;
10
+ globalConfig.collections ??= {};
11
+ globalConfig.collections[k] = v;
12
+ }
13
+ } else {
14
+ globalConfig = config;
15
+ }
16
+ if (globalConfig.collections) {
17
+ for (const [name, collection] of Object.entries(globalConfig.collections)) {
18
+ collection.init?.({ name, workspace });
19
+ collections.set(name, collection);
20
+ }
21
+ }
22
+ return {
23
+ ...globalConfig,
24
+ collections,
25
+ workspaces: Object.fromEntries(
26
+ Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {
27
+ return [
28
+ key,
29
+ {
30
+ dir: value.dir,
31
+ config: buildConfig(value.config, {
32
+ ...value,
33
+ name: key
34
+ })
35
+ }
36
+ ];
37
+ })
38
+ )
39
+ };
40
+ }
41
+
42
+ export {
43
+ buildConfig
44
+ };
@@ -0,0 +1,50 @@
1
+ import {
2
+ ValidationError
3
+ } from "./chunk-OUJENWQ4.js";
4
+ import {
5
+ Core
6
+ } from "./chunk-NRZ4GE5O.js";
7
+
8
+ // src/plugins/with-loader/webpack.ts
9
+ import { parse } from "querystring";
10
+ import path from "path";
11
+ var core;
12
+ function getCore(options) {
13
+ return core ??= new Core({
14
+ outDir: options.outDir,
15
+ configPath: options.configPath
16
+ });
17
+ }
18
+ function toWebpack(loader) {
19
+ return async function(source, callback) {
20
+ try {
21
+ const result = await loader.load({
22
+ filePath: this.resourcePath,
23
+ query: parse(this.resourceQuery.slice(1)),
24
+ getSource() {
25
+ return source;
26
+ },
27
+ development: this.mode === "development",
28
+ compiler: this
29
+ });
30
+ if (result === null) {
31
+ callback(void 0, source);
32
+ } else {
33
+ callback(void 0, result.code, result.map);
34
+ }
35
+ } catch (error) {
36
+ if (error instanceof ValidationError) {
37
+ return callback(new Error(await error.toStringFormatted()));
38
+ }
39
+ if (!(error instanceof Error)) throw error;
40
+ const fpath = path.relative(this.context, this.resourcePath);
41
+ error.message = `${fpath}:${error.name}: ${error.message}`;
42
+ callback(error);
43
+ }
44
+ };
45
+ }
46
+
47
+ export {
48
+ getCore,
49
+ toWebpack
50
+ };
@@ -0,0 +1,10 @@
1
+ export { m as FIleCollectionHandler, F as FileHandlerConfig, n as buildFileHandler } from '../../core-Bo8KaWQz.js';
2
+ import 'chokidar';
3
+ import '@mdx-js/mdx';
4
+ import 'vfile';
5
+ import '@standard-schema/spec';
6
+ import 'unified';
7
+ import 'mdast';
8
+ import 'vite';
9
+ import 'next';
10
+ import 'node:module';
@@ -0,0 +1,6 @@
1
+ import {
2
+ buildFileHandler
3
+ } from "../../chunk-E4HRKSP4.js";
4
+ export {
5
+ buildFileHandler
6
+ };
@@ -0,0 +1,10 @@
1
+ export { d as Collection, A as CollectionHandlers, z as CollectionTypeInfo, I as InitOptions, B as createCollection } from '../core-Bo8KaWQz.js';
2
+ import 'chokidar';
3
+ import '@mdx-js/mdx';
4
+ import 'vfile';
5
+ import '@standard-schema/spec';
6
+ import 'unified';
7
+ import 'mdast';
8
+ import 'vite';
9
+ import 'next';
10
+ import 'node:module';
@@ -0,0 +1,6 @@
1
+ import {
2
+ createCollection
3
+ } from "../chunk-BTRE6MOX.js";
4
+ export {
5
+ createCollection
6
+ };
@@ -0,0 +1,17 @@
1
+ import { LoaderContext } from 'webpack';
2
+ import { WebpackLoaderOptions } from '../../plugins/with-loader/webpack.js';
3
+ import '../../plugins/with-loader/index.js';
4
+ import '../../core-Bo8KaWQz.js';
5
+ import 'chokidar';
6
+ import '@mdx-js/mdx';
7
+ import 'vfile';
8
+ import '@standard-schema/spec';
9
+ import 'unified';
10
+ import 'mdast';
11
+ import 'vite';
12
+ import 'next';
13
+ import 'node:module';
14
+
15
+ declare function loader(this: LoaderContext<WebpackLoaderOptions>, source: string): Promise<void>;
16
+
17
+ export { loader as default };
@@ -0,0 +1,39 @@
1
+ import {
2
+ createMdxLoader
3
+ } from "../../chunk-KH5GT2Y5.js";
4
+ import {
5
+ getCore,
6
+ toWebpack
7
+ } from "../../chunk-XR5N6ZXJ.js";
8
+ import "../../chunk-OUJENWQ4.js";
9
+ import {
10
+ createDynamicCore
11
+ } from "../../chunk-GGL4EF6H.js";
12
+ import "../../chunk-VWJKRQZR.js";
13
+ import "../../chunk-NRZ4GE5O.js";
14
+ import "../../chunk-MT7RY65Y.js";
15
+ import "../../chunk-JBZTQ55D.js";
16
+
17
+ // src/collections/mdx/loader-webpack.ts
18
+ var instance;
19
+ async function loader(source) {
20
+ const callback = this.async();
21
+ const options = this.getOptions();
22
+ this.cacheable(true);
23
+ this.addDependency(options.absoluteCompiledConfigPath);
24
+ if (!instance) {
25
+ instance = toWebpack(
26
+ createMdxLoader(
27
+ createDynamicCore({
28
+ core: getCore(options),
29
+ buildConfig: false,
30
+ mode: options.isDev ? "dev" : "production"
31
+ })
32
+ )
33
+ );
34
+ }
35
+ await instance.call(this, source, callback);
36
+ }
37
+ export {
38
+ loader as default
39
+ };
@@ -0,0 +1,55 @@
1
+ import { ReactNode } from 'react';
2
+ import { CompiledMDXProperties } from './runtime.js';
3
+ import { GetCollectionConfig } from '../../index.js';
4
+ import { M as MDXCollection, E as ExtractedReference, V as VersionControlFileData } from '../../core-Bo8KaWQz.js';
5
+ import { SimpleCollectionStore } from '../runtime/store.js';
6
+ import '../runtime/file-store.js';
7
+ import 'mdx/types';
8
+ import 'chokidar';
9
+ import '@mdx-js/mdx';
10
+ import 'vfile';
11
+ import '@standard-schema/spec';
12
+ import 'unified';
13
+ import 'mdast';
14
+ import 'vite';
15
+ import 'next';
16
+ import 'node:module';
17
+
18
+ interface AsyncCache<V> {
19
+ cached: (key: string, fn: () => V | Promise<V>) => V | Promise<V>;
20
+ $value: <T>() => AsyncCache<T>;
21
+ invalidate: (key: string) => void;
22
+ }
23
+
24
+ interface MDXStoreBrowserData<Frontmatter, CustomData> {
25
+ id: string;
26
+ preload: () => (CompiledMDXProperties<Frontmatter> & CustomData) | Promise<CompiledMDXProperties<Frontmatter> & CustomData>;
27
+ _renderer: StoreRendererData;
28
+ }
29
+ interface StoreRendererData {
30
+ storeId: string;
31
+ renderers: Map<string, {
32
+ fn: () => ReactNode;
33
+ forceOnDemand: boolean;
34
+ }>;
35
+ }
36
+ interface StoreData {
37
+ preloaded: AsyncCache<CompiledMDXProperties>;
38
+ }
39
+ type GetFrontmatter<Config, Name extends string> = GetCollectionConfig<Config, Name> extends MDXCollection<infer _Frontmatter> ? _Frontmatter : never;
40
+ declare const _internal_data: Map<string, StoreData>;
41
+ declare function mdxStoreBrowser<Config, Name extends string>(name: Name, _input: Record<string, () => Promise<unknown>>): SimpleCollectionStore<MDXStoreBrowserData<GetFrontmatter<Config, Name>, unknown>>;
42
+ /**
43
+ * Renders content with `React.lazy`.
44
+ */
45
+ declare function useRenderer<Frontmatter, CustomData>(entry: MDXStoreBrowserData<Frontmatter, CustomData> | undefined, renderFn: (data: CompiledMDXProperties<Frontmatter> & CustomData) => ReactNode): ReactNode;
46
+ declare function $attachCompiled<Add>(): <T>(data: T) => T extends MDXStoreBrowserData<infer Frontmatter, infer CustomData> ? MDXStoreBrowserData<Frontmatter, CustomData & Add> : T;
47
+ declare function $extractedReferences(): <T>(data: T) => T extends MDXStoreBrowserData<infer Frontmatter, infer CustomData> ? MDXStoreBrowserData<Frontmatter, CustomData & {
48
+ /**
49
+ * extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
50
+ */
51
+ extractedReferences: ExtractedReference[];
52
+ }> : T;
53
+ declare function $versionControl(): <T>(data: T) => T extends MDXStoreBrowserData<infer Frontmatter, infer CustomData> ? MDXStoreBrowserData<Frontmatter, CustomData & VersionControlFileData> : T;
54
+
55
+ export { $attachCompiled, $extractedReferences, $versionControl, type MDXStoreBrowserData, _internal_data, mdxStoreBrowser, useRenderer };
@@ -0,0 +1,82 @@
1
+ "use client";
2
+ import {
3
+ SimpleCollectionStore
4
+ } from "../../chunk-3VQS3KSP.js";
5
+ import {
6
+ createCache
7
+ } from "../../chunk-JBZTQ55D.js";
8
+
9
+ // src/collections/mdx/runtime-browser.ts
10
+ import { lazy, createElement } from "react";
11
+ var _internal_data = /* @__PURE__ */ new Map();
12
+ function mdxStoreBrowser(name, _input) {
13
+ const input = _input;
14
+ const merged = /* @__PURE__ */ new Map();
15
+ function getStoreData() {
16
+ let store = _internal_data.get(name);
17
+ if (store) return store;
18
+ store = {
19
+ preloaded: createCache()
20
+ };
21
+ _internal_data.set(name, store);
22
+ return store;
23
+ }
24
+ const _renderer = {
25
+ storeId: name,
26
+ renderers: /* @__PURE__ */ new Map()
27
+ };
28
+ for (const [key, value] of Object.entries(input)) {
29
+ merged.set(key, {
30
+ id: key,
31
+ preload() {
32
+ return getStoreData().preloaded.$value().cached(key, value);
33
+ },
34
+ _renderer
35
+ });
36
+ }
37
+ return new SimpleCollectionStore(merged);
38
+ }
39
+ function useRenderer(entry, renderFn) {
40
+ if (!entry) return null;
41
+ const {
42
+ id,
43
+ _renderer: { renderers }
44
+ } = entry;
45
+ let renderer = renderers.get(id);
46
+ if (!renderer) {
47
+ const OnDemand = lazy(async () => {
48
+ const loaded = await entry.preload();
49
+ return { default: () => renderFn(loaded) };
50
+ });
51
+ renderer = {
52
+ forceOnDemand: false,
53
+ fn() {
54
+ const v = entry.preload();
55
+ if (!(v instanceof Promise) && !this.forceOnDemand) {
56
+ return renderFn(v);
57
+ }
58
+ this.forceOnDemand = true;
59
+ return createElement(OnDemand);
60
+ }
61
+ };
62
+ renderers.set(id, renderer);
63
+ }
64
+ return renderer.fn();
65
+ }
66
+ function $attachCompiled() {
67
+ return (data) => data;
68
+ }
69
+ function $extractedReferences() {
70
+ return $attachCompiled();
71
+ }
72
+ function $versionControl() {
73
+ return $attachCompiled();
74
+ }
75
+ export {
76
+ $attachCompiled,
77
+ $extractedReferences,
78
+ $versionControl,
79
+ _internal_data,
80
+ mdxStoreBrowser,
81
+ useRenderer
82
+ };
@@ -0,0 +1,43 @@
1
+ import { C as CoreOptions, M as MDXCollection, E as ExtractedReference, V as VersionControlFileData } from '../../core-Bo8KaWQz.js';
2
+ import { MDXComponents } from 'mdx/types';
3
+ import { FC } from 'react';
4
+ import { FileCollectionStore } from '../runtime/file-store.js';
5
+ import { CompiledMDXProperties } from './runtime.js';
6
+ import { GetCollectionConfig } from '../../index.js';
7
+ import 'chokidar';
8
+ import '@mdx-js/mdx';
9
+ import 'vfile';
10
+ import '@standard-schema/spec';
11
+ import 'unified';
12
+ import 'mdast';
13
+ import 'vite';
14
+ import 'next';
15
+ import 'node:module';
16
+ import '../runtime/store.js';
17
+
18
+ interface MDXStoreDynamicData<Frontmatter> {
19
+ id: string;
20
+ frontmatter: Frontmatter;
21
+ compile: () => Promise<CompiledMDXProperties<Frontmatter>>;
22
+ }
23
+ type GetFrontmatter<Config, Name extends string> = GetCollectionConfig<Config, Name> extends MDXCollection<infer _Frontmatter> ? _Frontmatter : never;
24
+ declare function mdxStoreDynamic<Config, Name extends string>(config: Config, coreOptions: CoreOptions, name: Name, base: string, _frontmatter: Record<string, unknown>): Promise<FileCollectionStore<MDXStoreDynamicData<GetFrontmatter<Config, Name>>>>;
25
+ type MdxContent = FC<{
26
+ components?: MDXComponents;
27
+ }>;
28
+ declare function $attachCompiled<Add>(): <T>(data: T) => T extends MDXStoreDynamicData<unknown> ? T & {
29
+ compile: () => Promise<Awaited<ReturnType<T["compile"]>> & Add>;
30
+ } : T;
31
+ declare function $extractedReferences(): <T>(data: T) => T extends MDXStoreDynamicData<unknown> ? T & {
32
+ compile: () => Promise<Awaited<ReturnType<T["compile"]>> & {
33
+ /**
34
+ * extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
35
+ */
36
+ extractedReferences: ExtractedReference[];
37
+ }>;
38
+ } : T;
39
+ declare function $versionControl(): <T>(data: T) => T extends MDXStoreDynamicData<unknown> ? T & {
40
+ compile: () => Promise<Awaited<ReturnType<T["compile"]>> & VersionControlFileData>;
41
+ } : T;
42
+
43
+ export { $attachCompiled, $extractedReferences, $versionControl, type MDXStoreDynamicData, type MdxContent, mdxStoreDynamic };
@@ -0,0 +1,96 @@
1
+ import {
2
+ buildMDX
3
+ } from "../../chunk-OQQNA7L7.js";
4
+ import {
5
+ FileCollectionStore
6
+ } from "../../chunk-RXR7OL76.js";
7
+ import {
8
+ fumaMatter
9
+ } from "../../chunk-VWJKRQZR.js";
10
+ import "../../chunk-3VQS3KSP.js";
11
+ import {
12
+ buildConfig
13
+ } from "../../chunk-W6HENTK7.js";
14
+ import {
15
+ Core
16
+ } from "../../chunk-NRZ4GE5O.js";
17
+ import "../../chunk-MT7RY65Y.js";
18
+ import {
19
+ createCache
20
+ } from "../../chunk-JBZTQ55D.js";
21
+
22
+ // src/collections/mdx/runtime-dynamic.ts
23
+ import { pathToFileURL } from "url";
24
+ import fs from "fs/promises";
25
+ import jsxRuntimeDefault from "react/jsx-runtime";
26
+ import path from "path";
27
+ var corePromise;
28
+ async function mdxStoreDynamic(config, coreOptions, name, base, _frontmatter) {
29
+ corePromise ??= (async () => {
30
+ const core2 = new Core(coreOptions);
31
+ await core2.init({
32
+ config: buildConfig(config)
33
+ });
34
+ return core2;
35
+ })();
36
+ const core = await corePromise;
37
+ const frontmatter = _frontmatter;
38
+ const collection = core.getCollection(name);
39
+ if (!collection || !collection.handlers.mdx)
40
+ throw new Error("invalid collection name");
41
+ const merged = {};
42
+ const cache = createCache();
43
+ for (const [k, v] of Object.entries(frontmatter)) {
44
+ merged[k] = {
45
+ id: k,
46
+ frontmatter: v,
47
+ async compile() {
48
+ return cache.cached(k, async () => {
49
+ const filePath = path.join(base, k);
50
+ let content = (await fs.readFile(filePath)).toString();
51
+ content = fumaMatter(content).content;
52
+ const compiled = await buildMDX(core, collection, {
53
+ filePath,
54
+ source: content,
55
+ frontmatter: v,
56
+ isDevelopment: false,
57
+ environment: "runtime"
58
+ });
59
+ return await executeMdx(String(compiled.value), {
60
+ baseUrl: pathToFileURL(filePath)
61
+ });
62
+ });
63
+ }
64
+ };
65
+ }
66
+ return new FileCollectionStore(base, merged);
67
+ }
68
+ var AsyncFunction = Object.getPrototypeOf(executeMdx).constructor;
69
+ async function executeMdx(compiled, options = {}) {
70
+ const { opts: scopeOpts, ...scope } = options.scope ?? {};
71
+ const fullScope = {
72
+ opts: {
73
+ ...scopeOpts,
74
+ ...options.jsxRuntime ?? jsxRuntimeDefault,
75
+ baseUrl: options.baseUrl
76
+ },
77
+ ...scope
78
+ };
79
+ const hydrateFn = new AsyncFunction(...Object.keys(fullScope), compiled);
80
+ return await hydrateFn.apply(hydrateFn, Object.values(fullScope));
81
+ }
82
+ function $attachCompiled() {
83
+ return (data) => data;
84
+ }
85
+ function $extractedReferences() {
86
+ return $attachCompiled();
87
+ }
88
+ function $versionControl() {
89
+ return $attachCompiled();
90
+ }
91
+ export {
92
+ $attachCompiled,
93
+ $extractedReferences,
94
+ $versionControl,
95
+ mdxStoreDynamic
96
+ };
@@ -0,0 +1,70 @@
1
+ import { GetCollectionConfig } from '../../index.js';
2
+ import { M as MDXCollection, E as ExtractedReference, V as VersionControlFileData } from '../../core-Bo8KaWQz.js';
3
+ import { FileCollectionStore } from '../runtime/file-store.js';
4
+ import { FC } from 'react';
5
+ import { MDXProps } from 'mdx/types';
6
+ import 'chokidar';
7
+ import '@mdx-js/mdx';
8
+ import 'vfile';
9
+ import '@standard-schema/spec';
10
+ import 'unified';
11
+ import 'mdast';
12
+ import 'vite';
13
+ import 'next';
14
+ import 'node:module';
15
+ import '../runtime/store.js';
16
+
17
+ type CompiledMDXProperties<Frontmatter = Record<string, unknown>> = {
18
+ frontmatter: Frontmatter;
19
+ default: FC<MDXProps>;
20
+ /**
21
+ * Enable from `postprocess` option.
22
+ */
23
+ _markdown?: string;
24
+ /**
25
+ * Enable from `postprocess` option.
26
+ */
27
+ _mdast?: string;
28
+ } & Record<string, unknown>;
29
+ interface MDXStoreData<Frontmatter> {
30
+ id: string;
31
+ compiled: CompiledMDXProperties<Frontmatter>;
32
+ }
33
+ type GetFrontmatter<Config, Name extends string> = GetCollectionConfig<Config, Name> extends MDXCollection<infer _Frontmatter> ? _Frontmatter : never;
34
+ declare function mdxStore<Config, Name extends string>(_name: Name, base: string, _input: Record<string, unknown>): FileCollectionStore<MDXStoreData<GetFrontmatter<Config, Name>>>;
35
+ interface MDXStoreLazyData<Frontmatter> {
36
+ id: string;
37
+ frontmatter: Frontmatter;
38
+ load: () => Promise<CompiledMDXProperties<Frontmatter>>;
39
+ }
40
+ declare function mdxStoreLazy<Config, Name extends string>(_name: Name, base: string, _input: {
41
+ head: Record<string, unknown>;
42
+ body: Record<string, () => Promise<unknown>>;
43
+ }): FileCollectionStore<MDXStoreLazyData<GetFrontmatter<Config, Name>>>;
44
+ declare function $attachCompiled<Add>(): <T>(data: T) => T extends MDXStoreData<unknown> ? T & {
45
+ compiled: Add;
46
+ } : T extends MDXStoreLazyData<unknown> ? T & {
47
+ load: () => Promise<Awaited<ReturnType<T["load"]>> & Add>;
48
+ } : T;
49
+ declare function $extractedReferences(): <T>(data: T) => T extends MDXStoreData<unknown> ? T & {
50
+ compiled: {
51
+ /**
52
+ * extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
53
+ */
54
+ extractedReferences: ExtractedReference[];
55
+ };
56
+ } : T extends MDXStoreLazyData<unknown> ? T & {
57
+ load: () => Promise<Awaited<ReturnType<T["load"]>> & {
58
+ /**
59
+ * extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
60
+ */
61
+ extractedReferences: ExtractedReference[];
62
+ }>;
63
+ } : T;
64
+ declare function $versionControl(): <T>(data: T) => T extends MDXStoreData<unknown> ? T & {
65
+ compiled: VersionControlFileData;
66
+ } : T extends MDXStoreLazyData<unknown> ? T & {
67
+ load: () => Promise<Awaited<ReturnType<T["load"]>> & VersionControlFileData>;
68
+ } : T;
69
+
70
+ export { $attachCompiled, $extractedReferences, $versionControl, type CompiledMDXProperties, type MDXStoreData, type MDXStoreLazyData, mdxStore, mdxStoreLazy };