@refrakt-md/next 0.14.3 → 0.14.4
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.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/metadata.d.ts +26 -4
- package/dist/metadata.d.ts.map +1 -1
- package/dist/metadata.js +57 -6
- package/dist/metadata.js.map +1 -1
- package/dist/tokens.d.ts +96 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +125 -0
- package/dist/tokens.js.map +1 -0
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,9 @@ export type { RefraktMetadataInput } from './metadata.js';
|
|
|
6
6
|
export { buildUrlFromParams } from './loader.js';
|
|
7
7
|
export type { PageParams } from './loader.js';
|
|
8
8
|
export { hasInteractiveRunes } from './behaviors.js';
|
|
9
|
+
export { getSiteTokensCss } from './tokens.js';
|
|
10
|
+
export { getUsedCssImports } from './tokens.js';
|
|
11
|
+
export { printPipelineSummary } from './tokens.js';
|
|
12
|
+
export { createNextLoader } from './tokens.js';
|
|
9
13
|
export type { NextTheme } from './types.js';
|
|
10
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC3D,YAAY,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAG1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC3D,YAAY,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAG1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAIrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAK/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAInD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,4 +7,17 @@ export { buildMetadata, buildJsonLd } from './metadata.js';
|
|
|
7
7
|
export { buildUrlFromParams } from './loader.js';
|
|
8
8
|
// Behaviors (server-side detection only)
|
|
9
9
|
export { hasInteractiveRunes } from './behaviors.js';
|
|
10
|
+
// Site-level token-overrides CSS (SPEC-048 + SPEC-056). Async helper consumers
|
|
11
|
+
// call at module-scope in `app/layout.tsx` and inline via `<style />`.
|
|
12
|
+
export { getSiteTokensCss } from './tokens.js';
|
|
13
|
+
// Tree-shaken per-rune CSS imports. Async helper returns the ordered list of
|
|
14
|
+
// module specifiers the consumer should import in `app/layout.tsx` (via
|
|
15
|
+
// generated code or a pre-build script).
|
|
16
|
+
export { getUsedCssImports } from './tokens.js';
|
|
17
|
+
// Pipeline-stats summary writer — matches the SvelteKit reference's build
|
|
18
|
+
// output across the refrakt stack.
|
|
19
|
+
export { printPipelineSummary } from './tokens.js';
|
|
20
|
+
// Pre-configured loader factory — typed shorthand around createRefraktLoader
|
|
21
|
+
// for the common Next.js case (configPath + site + variables + security).
|
|
22
|
+
export { createNextLoader } from './tokens.js';
|
|
10
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM;AACN,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG3D,0BAA0B;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGjD,yCAAyC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM;AACN,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG3D,0BAA0B;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGjD,yCAAyC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,+EAA+E;AAC/E,uEAAuE;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,6EAA6E;AAC7E,wEAAwE;AACxE,yCAAyC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,0EAA0E;AAC1E,mCAAmC;AACnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,6EAA6E;AAC7E,0EAA0E;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/metadata.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import type { SeoInput } from '@refrakt-md/transform';
|
|
2
|
-
|
|
1
|
+
import type { SeoInput, SeoToHtmlOptions } from '@refrakt-md/transform';
|
|
2
|
+
/**
|
|
3
|
+
* Combined input shape: per-page SEO (title, frontmatter, seo block) plus
|
|
4
|
+
* site-level options (siteName, baseUrl, defaultImage, logo). Matches the
|
|
5
|
+
* surface every other adapter's SEO helper accepts.
|
|
6
|
+
*/
|
|
7
|
+
export type RefraktMetadataInput = SeoInput & SeoToHtmlOptions;
|
|
3
8
|
/**
|
|
4
9
|
* Transform refrakt page SEO data into a Next.js Metadata object.
|
|
5
10
|
*
|
|
@@ -7,12 +12,29 @@ export type RefraktMetadataInput = SeoInput;
|
|
|
7
12
|
*
|
|
8
13
|
* export async function generateMetadata({ params }) {
|
|
9
14
|
* const page = await loadPage(params.slug);
|
|
10
|
-
* return buildMetadata({
|
|
15
|
+
* return buildMetadata({
|
|
16
|
+
* title: page.title,
|
|
17
|
+
* seo: page.seo,
|
|
18
|
+
* siteName: site.siteName,
|
|
19
|
+
* baseUrl: site.baseUrl,
|
|
20
|
+
* defaultImage: site.defaultImage,
|
|
21
|
+
* });
|
|
11
22
|
* }
|
|
23
|
+
*
|
|
24
|
+
* When site-level options are supplied:
|
|
25
|
+
* - `metadata.metadataBase` is set to `new URL(baseUrl)` so Next.js
|
|
26
|
+
* absolutizes relative URLs natively in og:url, canonical, etc.
|
|
27
|
+
* - `metadata.openGraph.siteName` carries the site name
|
|
28
|
+
* - `metadata.openGraph.images` falls back to `[defaultImage]` for pages
|
|
29
|
+
* without their own image
|
|
12
30
|
*/
|
|
13
31
|
export declare function buildMetadata(input: RefraktMetadataInput): Record<string, unknown>;
|
|
14
32
|
/**
|
|
15
33
|
* Build JSON-LD structured data objects for inclusion in the page head.
|
|
34
|
+
*
|
|
35
|
+
* Page-level JSON-LD entries (from `seo.jsonLd`) come first. When `baseUrl`
|
|
36
|
+
* + `siteName` are supplied, synthetic WebSite and Organization entries are
|
|
37
|
+
* appended — matching the SvelteKit reference's `seoToHtml` output.
|
|
16
38
|
*/
|
|
17
|
-
export declare function buildJsonLd(input?:
|
|
39
|
+
export declare function buildJsonLd(input?: RefraktMetadataInput): object[];
|
|
18
40
|
//# sourceMappingURL=metadata.d.ts.map
|
package/dist/metadata.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAExE;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,gBAAgB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAwClF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,CAAC,EAAE,oBAAoB,GAAG,MAAM,EAAE,CA2BlE"}
|
package/dist/metadata.js
CHANGED
|
@@ -6,12 +6,34 @@ import { extractSeoData } from '@refrakt-md/transform';
|
|
|
6
6
|
*
|
|
7
7
|
* export async function generateMetadata({ params }) {
|
|
8
8
|
* const page = await loadPage(params.slug);
|
|
9
|
-
* return buildMetadata({
|
|
9
|
+
* return buildMetadata({
|
|
10
|
+
* title: page.title,
|
|
11
|
+
* seo: page.seo,
|
|
12
|
+
* siteName: site.siteName,
|
|
13
|
+
* baseUrl: site.baseUrl,
|
|
14
|
+
* defaultImage: site.defaultImage,
|
|
15
|
+
* });
|
|
10
16
|
* }
|
|
17
|
+
*
|
|
18
|
+
* When site-level options are supplied:
|
|
19
|
+
* - `metadata.metadataBase` is set to `new URL(baseUrl)` so Next.js
|
|
20
|
+
* absolutizes relative URLs natively in og:url, canonical, etc.
|
|
21
|
+
* - `metadata.openGraph.siteName` carries the site name
|
|
22
|
+
* - `metadata.openGraph.images` falls back to `[defaultImage]` for pages
|
|
23
|
+
* without their own image
|
|
11
24
|
*/
|
|
12
25
|
export function buildMetadata(input) {
|
|
26
|
+
const { siteName, baseUrl, defaultImage } = input;
|
|
13
27
|
const data = extractSeoData(input);
|
|
14
28
|
const metadata = {};
|
|
29
|
+
if (baseUrl) {
|
|
30
|
+
try {
|
|
31
|
+
metadata.metadataBase = new URL(baseUrl);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// Invalid baseUrl — skip metadataBase rather than throwing.
|
|
35
|
+
}
|
|
36
|
+
}
|
|
15
37
|
if (data.title)
|
|
16
38
|
metadata.title = data.title;
|
|
17
39
|
if (data.description)
|
|
@@ -21,12 +43,15 @@ export function buildMetadata(input) {
|
|
|
21
43
|
openGraph.title = data.title;
|
|
22
44
|
if (data.description)
|
|
23
45
|
openGraph.description = data.description;
|
|
24
|
-
if (
|
|
25
|
-
openGraph.
|
|
46
|
+
if (siteName)
|
|
47
|
+
openGraph.siteName = siteName;
|
|
26
48
|
if (data.ogUrl)
|
|
27
49
|
openGraph.url = data.ogUrl;
|
|
28
50
|
if (data.ogType)
|
|
29
51
|
openGraph.type = data.ogType;
|
|
52
|
+
const ogImage = data.ogImage ?? defaultImage;
|
|
53
|
+
if (ogImage)
|
|
54
|
+
openGraph.images = [ogImage];
|
|
30
55
|
if (Object.keys(openGraph).length > 0)
|
|
31
56
|
metadata.openGraph = openGraph;
|
|
32
57
|
const twitter = {};
|
|
@@ -34,9 +59,9 @@ export function buildMetadata(input) {
|
|
|
34
59
|
twitter.title = data.title;
|
|
35
60
|
if (data.description)
|
|
36
61
|
twitter.description = data.description;
|
|
37
|
-
if (
|
|
62
|
+
if (ogImage) {
|
|
38
63
|
twitter.card = 'summary_large_image';
|
|
39
|
-
twitter.images = [
|
|
64
|
+
twitter.images = [ogImage];
|
|
40
65
|
}
|
|
41
66
|
else {
|
|
42
67
|
twitter.card = 'summary';
|
|
@@ -47,10 +72,36 @@ export function buildMetadata(input) {
|
|
|
47
72
|
}
|
|
48
73
|
/**
|
|
49
74
|
* Build JSON-LD structured data objects for inclusion in the page head.
|
|
75
|
+
*
|
|
76
|
+
* Page-level JSON-LD entries (from `seo.jsonLd`) come first. When `baseUrl`
|
|
77
|
+
* + `siteName` are supplied, synthetic WebSite and Organization entries are
|
|
78
|
+
* appended — matching the SvelteKit reference's `seoToHtml` output.
|
|
50
79
|
*/
|
|
51
80
|
export function buildJsonLd(input) {
|
|
52
81
|
if (!input)
|
|
53
82
|
return [];
|
|
54
|
-
|
|
83
|
+
const { siteName, baseUrl, logo } = input;
|
|
84
|
+
const data = extractSeoData(input);
|
|
85
|
+
const entries = [...data.jsonLd];
|
|
86
|
+
if (baseUrl) {
|
|
87
|
+
const name = siteName ?? '';
|
|
88
|
+
entries.push({
|
|
89
|
+
'@context': 'https://schema.org',
|
|
90
|
+
'@type': 'WebSite',
|
|
91
|
+
name,
|
|
92
|
+
url: baseUrl,
|
|
93
|
+
});
|
|
94
|
+
const org = {
|
|
95
|
+
'@context': 'https://schema.org',
|
|
96
|
+
'@type': 'Organization',
|
|
97
|
+
name,
|
|
98
|
+
url: baseUrl,
|
|
99
|
+
};
|
|
100
|
+
if (logo) {
|
|
101
|
+
org.logo = baseUrl + logo;
|
|
102
|
+
}
|
|
103
|
+
entries.push(org);
|
|
104
|
+
}
|
|
105
|
+
return entries;
|
|
55
106
|
}
|
|
56
107
|
//# sourceMappingURL=metadata.js.map
|
package/dist/metadata.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAUvD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,aAAa,CAAC,KAA2B;IACxD,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAClD,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,QAAQ,GAA4B,EAAE,CAAC;IAE7C,IAAI,OAAO,EAAE,CAAC;QACb,IAAI,CAAC;YACJ,QAAQ,CAAC,YAAY,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC;QAAC,MAAM,CAAC;YACR,4DAA4D;QAC7D,CAAC;IACF,CAAC;IAED,IAAI,IAAI,CAAC,KAAK;QAAE,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IAC5C,IAAI,IAAI,CAAC,WAAW;QAAE,QAAQ,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;IAE9D,MAAM,SAAS,GAA4B,EAAE,CAAC;IAC9C,IAAI,IAAI,CAAC,KAAK;QAAE,SAAS,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IAC7C,IAAI,IAAI,CAAC,WAAW;QAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;IAC/D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,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,OAAO,GAAa,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAE3C,IAAI,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,GAAG,QAAQ,IAAI,EAAE,CAAC;QAC5B,OAAO,CAAC,IAAI,CAAC;YACZ,UAAU,EAAE,oBAAoB;YAChC,OAAO,EAAE,SAAS;YAClB,IAAI;YACJ,GAAG,EAAE,OAAO;SACZ,CAAC,CAAC;QACH,MAAM,GAAG,GAA2B;YACnC,UAAU,EAAE,oBAAoB;YAChC,OAAO,EAAE,cAAc;YACvB,IAAI;YACJ,GAAG,EAAE,OAAO;SACZ,CAAC;QACF,IAAI,IAAI,EAAE,CAAC;YACV,GAAG,CAAC,IAAI,GAAG,OAAO,GAAG,IAAI,CAAC;QAC3B,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC"}
|
package/dist/tokens.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type SecurityPolicy } from '@refrakt-md/types';
|
|
2
|
+
import type { Site } from '@refrakt-md/content';
|
|
3
|
+
/**
|
|
4
|
+
* Resolve the per-site config from `refrakt.config.json` and compose the
|
|
5
|
+
* site-level token overrides CSS (SPEC-048 presets + tokens + modes, SPEC-056
|
|
6
|
+
* scoped tint projections).
|
|
7
|
+
*
|
|
8
|
+
* Designed to be called at module-scope in a Next.js `app/layout.tsx` Server
|
|
9
|
+
* Component, with the result inlined as a `<style dangerouslySetInnerHTML />`
|
|
10
|
+
* block in `<head>`:
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const siteTokensCss = await getSiteTokensCss();
|
|
14
|
+
* // ...
|
|
15
|
+
* <head>
|
|
16
|
+
* <style dangerouslySetInnerHTML={{ __html: siteTokensCss }} />
|
|
17
|
+
* </head>
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Returns an empty string when the site uses the legacy string-theme form or
|
|
21
|
+
* declares no overrides — safe to inline either way.
|
|
22
|
+
*
|
|
23
|
+
* For consumers who prefer a linked stylesheet over an inline `<style>`,
|
|
24
|
+
* write the result to `public/site-tokens.css` via a build-time script and
|
|
25
|
+
* reference it with `<link rel="stylesheet" href="/site-tokens.css">`.
|
|
26
|
+
*
|
|
27
|
+
* @param configPath Path to `refrakt.config.json`. Default: `./refrakt.config.json`.
|
|
28
|
+
* @param siteName Which site to use from a multi-site config. Required when
|
|
29
|
+
* the config declares multiple `sites.*`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getSiteTokensCss(configPath?: string, siteName?: string): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Compute the tree-shaken list of CSS module specifiers the site should
|
|
34
|
+
* import — `base.css` first, then one entry per used rune block. Designed
|
|
35
|
+
* for use in a Next.js pre-build script that generates `import` statements
|
|
36
|
+
* for `app/layout.tsx`, or in `next.config.mjs`'s webpack hook.
|
|
37
|
+
*
|
|
38
|
+
* Falls back to the theme package's barrel specifier (`@refrakt-md/lumina`)
|
|
39
|
+
* when rune-usage analysis fails — same graceful-degradation behaviour as
|
|
40
|
+
* the SvelteKit + Astro plugins.
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* // scripts/generate-css-imports.mjs
|
|
44
|
+
* import { getUsedCssImports } from '@refrakt-md/next';
|
|
45
|
+
* import { writeFileSync } from 'node:fs';
|
|
46
|
+
*
|
|
47
|
+
* const imports = await getUsedCssImports();
|
|
48
|
+
* const code = imports.map(spec => `import '${spec}';`).join('\n');
|
|
49
|
+
* writeFileSync('./app/generated-css-imports.ts', code);
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @param configPath Path to `refrakt.config.json`.
|
|
53
|
+
* @param siteName Which site to use from a multi-site config.
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* Print the cross-page pipeline's Phase 1/2/3/4 + warnings summary to stderr.
|
|
57
|
+
*
|
|
58
|
+
* Call once from `app/[...slug]/page.tsx` or a setup module so Next.js builds
|
|
59
|
+
* get the same visibility into the content pipeline that the SvelteKit
|
|
60
|
+
* reference adapter prints.
|
|
61
|
+
*
|
|
62
|
+
* Memoise the call site (e.g. via a module-scope flag) — Next will re-evaluate
|
|
63
|
+
* the page module per static-param entry, and you only want one summary.
|
|
64
|
+
*/
|
|
65
|
+
export declare function printPipelineSummary(site: Site): void;
|
|
66
|
+
export declare function getUsedCssImports(configPath?: string, siteName?: string): Promise<string[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Convenience factory: build a `createRefraktLoader` instance pre-configured
|
|
69
|
+
* with the four optional Next.js-side fields (configPath, site, variables,
|
|
70
|
+
* security). Re-exports the loader for direct use in Server Components.
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* // app/layout.tsx or a setup module
|
|
74
|
+
* import { createNextLoader } from '@refrakt-md/next';
|
|
75
|
+
*
|
|
76
|
+
* const loader = createNextLoader({
|
|
77
|
+
* variables: { version: '1.0.0' },
|
|
78
|
+
* security: 'strict',
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* export async function generateStaticParams() {
|
|
82
|
+
* const site = await loader.getSite();
|
|
83
|
+
* // ...
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* For consumers who already wire `createRefraktLoader` directly: use that
|
|
88
|
+
* import — this helper is purely a typed shorthand for the common case.
|
|
89
|
+
*/
|
|
90
|
+
export declare function createNextLoader(options?: {
|
|
91
|
+
configPath?: string;
|
|
92
|
+
site?: string;
|
|
93
|
+
variables?: Record<string, unknown>;
|
|
94
|
+
security?: SecurityPolicy;
|
|
95
|
+
}): Promise<import("@refrakt-md/content").RefraktLoader>;
|
|
96
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAQA,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,gBAAgB,CACrC,UAAU,SAA0B,EACpC,QAAQ,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAKjB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAKrD;AAED,wBAAsB,iBAAiB,CACtC,UAAU,SAA0B,EACpC,QAAQ,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,EAAE,CAAC,CAyBnB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,GAAE;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,QAAQ,CAAC,EAAE,cAAc,CAAC;CACrB,wDAGL"}
|
package/dist/tokens.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { dirname, resolve } from 'node:path';
|
|
2
|
+
import { composeSiteTokensCss, loadRefraktConfig, resolveSite, computeUsedCssBlocks, buildUsedCssImports, } from '@refrakt-md/transform/node';
|
|
3
|
+
import { getThemePackage } from '@refrakt-md/types';
|
|
4
|
+
/**
|
|
5
|
+
* Resolve the per-site config from `refrakt.config.json` and compose the
|
|
6
|
+
* site-level token overrides CSS (SPEC-048 presets + tokens + modes, SPEC-056
|
|
7
|
+
* scoped tint projections).
|
|
8
|
+
*
|
|
9
|
+
* Designed to be called at module-scope in a Next.js `app/layout.tsx` Server
|
|
10
|
+
* Component, with the result inlined as a `<style dangerouslySetInnerHTML />`
|
|
11
|
+
* block in `<head>`:
|
|
12
|
+
*
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const siteTokensCss = await getSiteTokensCss();
|
|
15
|
+
* // ...
|
|
16
|
+
* <head>
|
|
17
|
+
* <style dangerouslySetInnerHTML={{ __html: siteTokensCss }} />
|
|
18
|
+
* </head>
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Returns an empty string when the site uses the legacy string-theme form or
|
|
22
|
+
* declares no overrides — safe to inline either way.
|
|
23
|
+
*
|
|
24
|
+
* For consumers who prefer a linked stylesheet over an inline `<style>`,
|
|
25
|
+
* write the result to `public/site-tokens.css` via a build-time script and
|
|
26
|
+
* reference it with `<link rel="stylesheet" href="/site-tokens.css">`.
|
|
27
|
+
*
|
|
28
|
+
* @param configPath Path to `refrakt.config.json`. Default: `./refrakt.config.json`.
|
|
29
|
+
* @param siteName Which site to use from a multi-site config. Required when
|
|
30
|
+
* the config declares multiple `sites.*`.
|
|
31
|
+
*/
|
|
32
|
+
export async function getSiteTokensCss(configPath = './refrakt.config.json', siteName) {
|
|
33
|
+
const absConfigPath = resolve(configPath);
|
|
34
|
+
const config = loadRefraktConfig(absConfigPath);
|
|
35
|
+
const { site } = resolveSite(config, siteName);
|
|
36
|
+
return composeSiteTokensCss(site, dirname(absConfigPath));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Compute the tree-shaken list of CSS module specifiers the site should
|
|
40
|
+
* import — `base.css` first, then one entry per used rune block. Designed
|
|
41
|
+
* for use in a Next.js pre-build script that generates `import` statements
|
|
42
|
+
* for `app/layout.tsx`, or in `next.config.mjs`'s webpack hook.
|
|
43
|
+
*
|
|
44
|
+
* Falls back to the theme package's barrel specifier (`@refrakt-md/lumina`)
|
|
45
|
+
* when rune-usage analysis fails — same graceful-degradation behaviour as
|
|
46
|
+
* the SvelteKit + Astro plugins.
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* // scripts/generate-css-imports.mjs
|
|
50
|
+
* import { getUsedCssImports } from '@refrakt-md/next';
|
|
51
|
+
* import { writeFileSync } from 'node:fs';
|
|
52
|
+
*
|
|
53
|
+
* const imports = await getUsedCssImports();
|
|
54
|
+
* const code = imports.map(spec => `import '${spec}';`).join('\n');
|
|
55
|
+
* writeFileSync('./app/generated-css-imports.ts', code);
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @param configPath Path to `refrakt.config.json`.
|
|
59
|
+
* @param siteName Which site to use from a multi-site config.
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* Print the cross-page pipeline's Phase 1/2/3/4 + warnings summary to stderr.
|
|
63
|
+
*
|
|
64
|
+
* Call once from `app/[...slug]/page.tsx` or a setup module so Next.js builds
|
|
65
|
+
* get the same visibility into the content pipeline that the SvelteKit
|
|
66
|
+
* reference adapter prints.
|
|
67
|
+
*
|
|
68
|
+
* Memoise the call site (e.g. via a module-scope flag) — Next will re-evaluate
|
|
69
|
+
* the page module per static-param entry, and you only want one summary.
|
|
70
|
+
*/
|
|
71
|
+
export function printPipelineSummary(site) {
|
|
72
|
+
// Resolved lazily so the import surface stays Server-Component-safe.
|
|
73
|
+
void import('@refrakt-md/content').then(({ formatPipelineSummary }) => {
|
|
74
|
+
process.stderr.write(formatPipelineSummary(site.pipelineStats, site.pipelineWarnings));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export async function getUsedCssImports(configPath = './refrakt.config.json', siteName) {
|
|
78
|
+
const absConfigPath = resolve(configPath);
|
|
79
|
+
const config = loadRefraktConfig(absConfigPath);
|
|
80
|
+
const { site } = resolveSite(config, siteName);
|
|
81
|
+
const themePackage = getThemePackage(site.theme);
|
|
82
|
+
try {
|
|
83
|
+
const { createRefraktLoader, analyzeRuneUsage } = await import('@refrakt-md/content');
|
|
84
|
+
const themeModule = await import(themePackage + '/transform');
|
|
85
|
+
const themeConfig = themeModule.themeConfig ?? themeModule.luminaConfig ?? themeModule.default;
|
|
86
|
+
const loader = createRefraktLoader({ configPath: absConfigPath, site: siteName });
|
|
87
|
+
const loadedSite = await loader.getSite();
|
|
88
|
+
const report = analyzeRuneUsage(loadedSite.pages);
|
|
89
|
+
const { usedBlocks } = await computeUsedCssBlocks(report.allTypes, themeConfig, themePackage);
|
|
90
|
+
return buildUsedCssImports(themePackage, usedBlocks);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// Fall back to the theme package barrel — pulls in every rune's CSS,
|
|
94
|
+
// matching the pre-tree-shake behaviour.
|
|
95
|
+
return [themePackage];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Convenience factory: build a `createRefraktLoader` instance pre-configured
|
|
100
|
+
* with the four optional Next.js-side fields (configPath, site, variables,
|
|
101
|
+
* security). Re-exports the loader for direct use in Server Components.
|
|
102
|
+
*
|
|
103
|
+
* ```ts
|
|
104
|
+
* // app/layout.tsx or a setup module
|
|
105
|
+
* import { createNextLoader } from '@refrakt-md/next';
|
|
106
|
+
*
|
|
107
|
+
* const loader = createNextLoader({
|
|
108
|
+
* variables: { version: '1.0.0' },
|
|
109
|
+
* security: 'strict',
|
|
110
|
+
* });
|
|
111
|
+
*
|
|
112
|
+
* export async function generateStaticParams() {
|
|
113
|
+
* const site = await loader.getSite();
|
|
114
|
+
* // ...
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* For consumers who already wire `createRefraktLoader` directly: use that
|
|
119
|
+
* import — this helper is purely a typed shorthand for the common case.
|
|
120
|
+
*/
|
|
121
|
+
export async function createNextLoader(options = {}) {
|
|
122
|
+
const { createRefraktLoader } = await import('@refrakt-md/content');
|
|
123
|
+
return createRefraktLoader(options);
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"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
|
|
3
3
|
"description": "Next.js adapter for refrakt.md — render Markdoc runes with React Server Components",
|
|
4
|
-
"version": "0.14.
|
|
4
|
+
"version": "0.14.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"build": "tsc"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@refrakt-md/behaviors": "0.14.
|
|
37
|
-
"@refrakt-md/content": "0.14.
|
|
38
|
-
"@refrakt-md/transform": "0.14.
|
|
39
|
-
"@refrakt-md/types": "0.14.
|
|
36
|
+
"@refrakt-md/behaviors": "0.14.4",
|
|
37
|
+
"@refrakt-md/content": "0.14.4",
|
|
38
|
+
"@refrakt-md/transform": "0.14.4",
|
|
39
|
+
"@refrakt-md/types": "0.14.4"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"next": "^15.0.0",
|