@razorwind/shiki 0.0.3 → 0.0.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.cjs +48 -1
- package/dist/index.d.cts +21 -12
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +21 -12
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +48 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1 +1,48 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require("@razorwind/core/plugin"),t=require("@razorwind/core/utils"),n=require("node:path");
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require("@razorwind/core/plugin"),t=require("@razorwind/core/utils"),n=require("node:path");function r(e){let t=e.themes[0],n=e.themes.length===1?t.displayName:`Shiki Themes`,r=e.themes.map(e=>`- \`${e.fileName}\` — ${e.displayName} (theme id: \`${e.name}\`)`).join(`
|
|
2
|
+
`),i=e.themes.map(e=>`- \`${e.name}\` — ${e.displayName}`).join(`
|
|
3
|
+
`);return`# Installing ${n}
|
|
4
|
+
|
|
5
|
+
Generated by \`@razorwind/shiki\`.
|
|
6
|
+
|
|
7
|
+
## Files
|
|
8
|
+
|
|
9
|
+
${r}
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
1. Copy or import the generated JSON into your app (paths depend on your bundler).
|
|
14
|
+
|
|
15
|
+
2. Register themes when creating a Shiki highlighter:
|
|
16
|
+
|
|
17
|
+
\`\`\`ts
|
|
18
|
+
import { createHighlighter } from "shiki";
|
|
19
|
+
import theme from "./${t.fileName}";
|
|
20
|
+
|
|
21
|
+
const highlighter = await createHighlighter({
|
|
22
|
+
themes: [theme],
|
|
23
|
+
langs: ["javascript"]
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const html = highlighter.codeToHtml("const x = 1", {
|
|
27
|
+
lang: "javascript",
|
|
28
|
+
theme: "${t.name}"
|
|
29
|
+
});
|
|
30
|
+
\`\`\`
|
|
31
|
+
|
|
32
|
+
Or load at runtime:
|
|
33
|
+
|
|
34
|
+
\`\`\`ts
|
|
35
|
+
import { readFile } from "node:fs/promises";
|
|
36
|
+
|
|
37
|
+
const theme = JSON.parse(
|
|
38
|
+
await readFile("./${t.fileName}", "utf8")
|
|
39
|
+
);
|
|
40
|
+
await highlighter.loadTheme(theme);
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
## Select / load theme
|
|
44
|
+
|
|
45
|
+
Pass the theme id to \`codeToHtml\`, \`codeToTokens\`, or \`getTokenStyle\`:
|
|
46
|
+
|
|
47
|
+
${i}
|
|
48
|
+
`}function i(e){return(0,t.themeDisplayName)(e)}const a={name:`razorwind-shiki`};function o(e,n,r){return(0,t.createDocument)(e,n,a,r)}function s(e){return(0,t.isObject)(e)&&typeof e.name==`string`&&e.name.length>0}function c(e){if(Array.isArray(e))return e.map((e,t)=>{if(!s(e))throw TypeError(`@razorwind/shiki mapTheme()[${t}] must be a ShikiTheme with name`);return e});if(s(e))return[e];if(!(0,t.isObject)(e))throw TypeError(`@razorwind/shiki mapTheme() must return a theme, theme array, or theme record`);return Object.entries(e).map(([e,t])=>{if(!s(t))throw TypeError(`@razorwind/shiki mapTheme()["${e}"] must be a ShikiTheme with name`);return{...t,name:t.name||e}})}function l(e){if(!e.mapTheme)throw Error(`@razorwind/shiki requires options.mapTheme`)}function u(e){let t=e.settings??e.tokenColors??[],n={name:e.name,settings:t};return e.displayName&&(n.displayName=e.displayName),e.type&&(n.type=e.type),e.fg!==void 0&&(n.fg=e.fg),e.bg!==void 0&&(n.bg=e.bg),e.colors&&(n.colors=e.colors),e.tokenColors&&e.settings&&(n.tokenColors=e.tokenColors),e.colorReplacements&&(n.colorReplacements=e.colorReplacements),e.semanticHighlighting!==void 0&&(n.semanticHighlighting=e.semanticHighlighting),e.semanticTokenColors&&(n.semanticTokenColors=e.semanticTokenColors),`${JSON.stringify(n,null,2)}\n`}function d(e,a){l(a);let s=a.outputPath??`shiki-themes`,d=c(a.mapTheme(e.tokens));if(d.length===0)throw Error(`@razorwind/shiki mapTheme() returned no themes`);let f={},p=new Set,m=[];for(let e of d){let r=`${(0,t.slugifyThemeName)(e.name)}.json`;if(p.has(r)){let n=2;for(;p.has(`${(0,t.slugifyThemeName)(e.name)}-${n}.json`);)n+=1;r=`${(0,t.slugifyThemeName)(e.name)}-${n}.json`}p.add(r);let a=(0,n.join)(s,r);f[a]=o(a,u(e),`json`),m.push({name:e.name,displayName:i(e),fileName:r})}let h=a.installGuide??r({themes:m}),g=(0,n.join)(s,`INSTALL.md`);return f[g]=o(g,h,`markdown`),f}var f=(0,e.definePlugin)(e=>({name:`shiki`,generate:async t=>{if(!e)throw Error(`@razorwind/shiki requires options: { mapTheme }`);return d(t,e)}}));exports.default=f,Object.defineProperty(exports,"flattenTokens",{enumerable:!0,get:function(){return t.flattenTokens}}),Object.defineProperty(exports,"formatTokenValue",{enumerable:!0,get:function(){return t.formatTokenValue}}),exports.generateShikiTheme=d,exports.normalizeThemes=c,exports.renderInstallMd=r,exports.renderThemeJson=u,Object.defineProperty(exports,"resolveTokenSets",{enumerable:!0,get:function(){return t.resolveTokenSets}}),exports.themeDisplayName=i,Object.defineProperty(exports,"toCssVar",{enumerable:!0,get:function(){return t.toCssVar}});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { flattenTokens, formatTokenValue, resolveTokenSets, toCssVar } from "@razorwind/core/utils";
|
|
2
|
+
import { GeneratorFunctionResult } from "@power-plant/core";
|
|
1
3
|
import { Schema, Tokens } from "@razorwind/core/schema";
|
|
2
4
|
import { TokenType } from "@power-plant/dtcg-schema";
|
|
3
|
-
import { formatTokenValue, toCssVar } from "@razorwind/core/utils";
|
|
4
|
-
import { GeneratorFunctionResult } from "@power-plant/core";
|
|
5
5
|
//#region src/types.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* A flattened design token ready for Shiki theme mapping.
|
|
@@ -100,21 +100,30 @@ interface ShikiPluginOptions {
|
|
|
100
100
|
* Does not filter what {@link mapTheme} receives.
|
|
101
101
|
*/
|
|
102
102
|
includeTypes?: TokenType[];
|
|
103
|
+
/**
|
|
104
|
+
* Override body for generated `INSTALL.md`. When omitted, Shiki load-theme
|
|
105
|
+
* steps are generated from contributed themes.
|
|
106
|
+
*/
|
|
107
|
+
installGuide?: string;
|
|
103
108
|
}
|
|
104
109
|
//#endregion
|
|
105
|
-
//#region src/
|
|
106
|
-
interface TokenSet {
|
|
107
|
-
id: string;
|
|
108
|
-
tokens: Tokens;
|
|
109
|
-
}
|
|
110
|
+
//#region src/install.d.ts
|
|
110
111
|
/**
|
|
111
|
-
*
|
|
112
|
+
* Build Shiki INSTALL.md for generated theme JSON files.
|
|
113
|
+
*
|
|
114
|
+
* @see https://shiki.style/guide/load-theme
|
|
112
115
|
*/
|
|
113
|
-
declare function
|
|
116
|
+
declare function renderInstallMd(options: {
|
|
117
|
+
themes: Array<{
|
|
118
|
+
name: string;
|
|
119
|
+
displayName: string;
|
|
120
|
+
fileName: string;
|
|
121
|
+
}>;
|
|
122
|
+
}): string;
|
|
114
123
|
/**
|
|
115
|
-
*
|
|
124
|
+
* Title-case a theme name for display when \`displayName\` is omitted.
|
|
116
125
|
*/
|
|
117
|
-
declare function
|
|
126
|
+
declare function themeDisplayName(theme: ShikiTheme): string;
|
|
118
127
|
//#endregion
|
|
119
128
|
//#region src/generate.d.ts
|
|
120
129
|
/**
|
|
@@ -186,5 +195,5 @@ declare function generateShikiTheme(spec: Schema, options: ShikiPluginOptions):
|
|
|
186
195
|
*/
|
|
187
196
|
declare const _default: (options?: ShikiPluginOptions | undefined) => import("@razorwind/core/plugin").Plugin;
|
|
188
197
|
//#endregion
|
|
189
|
-
export { type FlatToken, type GenerateShikiTheme, type ShikiPluginOptions, type ShikiTheme, type ShikiThemeSetting, _default as default, flattenTokens, formatTokenValue, generateShikiTheme, normalizeThemes, renderThemeJson, resolveTokenSets, toCssVar };
|
|
198
|
+
export { type FlatToken, type GenerateShikiTheme, type ShikiPluginOptions, type ShikiTheme, type ShikiThemeSetting, _default as default, flattenTokens, formatTokenValue, generateShikiTheme, normalizeThemes, renderInstallMd, renderThemeJson, resolveTokenSets, themeDisplayName, toCssVar };
|
|
190
199
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/install.ts","../src/generate.ts","../src/index.ts"],"mappings":";;;;;;;;UAwBiB;;EAEf;;EAEA,OAAO;;EAEP;;EAEA;;EAEA;;EAEA;;;;;;;UAQe;EACf;EACA;EACA;IACE;IACA;IACA;;;;;;;;;;;;UAaa;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;;;;EAKA,SAAS;;EAET,WAAW;;;;;EAKX,cAAc;;EAEd,oBAAoB;EACpB;EACA,sBAAsB;;;;;;;KAQZ,sBACV,QAAQ,SAAS,eAAe,YAC7B,aAAa,eAAe,eAAe;;;;;;UAO/B;;;;;;EAMf;;;;;;EAOA,UAAU;;;;;EAMV,eAAe;;;;;EAMf;;;;;;;;;iBCzGc,gBAAgB;EAC9B,QAAQ;IAAQ;IAAc;IAAqB;;;;;;iBAsErC,iBAAiB,OAAO;;;;;;iBChDxB,gBACd,QAAQ,aAAa,eAAe,eAAe,cAClD;;;;;;iBAkDa,gBAAgB,OAAO;;;;;;;;;iBAkDvB,mBACd,MAAM,QACN,SAAS,qBACR,wBAAwB,QAAQ"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { formatTokenValue, toCssVar } from "@razorwind/core/utils";
|
|
1
|
+
import { flattenTokens, formatTokenValue, resolveTokenSets, toCssVar } from "@razorwind/core/utils";
|
|
2
|
+
import { GeneratorFunctionResult } from "@power-plant/core";
|
|
2
3
|
import { Schema, Tokens } from "@razorwind/core/schema";
|
|
3
4
|
import { TokenType } from "@power-plant/dtcg-schema";
|
|
4
|
-
import { GeneratorFunctionResult } from "@power-plant/core";
|
|
5
5
|
//#region src/types.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* A flattened design token ready for Shiki theme mapping.
|
|
@@ -100,21 +100,30 @@ interface ShikiPluginOptions {
|
|
|
100
100
|
* Does not filter what {@link mapTheme} receives.
|
|
101
101
|
*/
|
|
102
102
|
includeTypes?: TokenType[];
|
|
103
|
+
/**
|
|
104
|
+
* Override body for generated `INSTALL.md`. When omitted, Shiki load-theme
|
|
105
|
+
* steps are generated from contributed themes.
|
|
106
|
+
*/
|
|
107
|
+
installGuide?: string;
|
|
103
108
|
}
|
|
104
109
|
//#endregion
|
|
105
|
-
//#region src/
|
|
106
|
-
interface TokenSet {
|
|
107
|
-
id: string;
|
|
108
|
-
tokens: Tokens;
|
|
109
|
-
}
|
|
110
|
+
//#region src/install.d.ts
|
|
110
111
|
/**
|
|
111
|
-
*
|
|
112
|
+
* Build Shiki INSTALL.md for generated theme JSON files.
|
|
113
|
+
*
|
|
114
|
+
* @see https://shiki.style/guide/load-theme
|
|
112
115
|
*/
|
|
113
|
-
declare function
|
|
116
|
+
declare function renderInstallMd(options: {
|
|
117
|
+
themes: Array<{
|
|
118
|
+
name: string;
|
|
119
|
+
displayName: string;
|
|
120
|
+
fileName: string;
|
|
121
|
+
}>;
|
|
122
|
+
}): string;
|
|
114
123
|
/**
|
|
115
|
-
*
|
|
124
|
+
* Title-case a theme name for display when \`displayName\` is omitted.
|
|
116
125
|
*/
|
|
117
|
-
declare function
|
|
126
|
+
declare function themeDisplayName(theme: ShikiTheme): string;
|
|
118
127
|
//#endregion
|
|
119
128
|
//#region src/generate.d.ts
|
|
120
129
|
/**
|
|
@@ -186,5 +195,5 @@ declare function generateShikiTheme(spec: Schema, options: ShikiPluginOptions):
|
|
|
186
195
|
*/
|
|
187
196
|
declare const _default: (options?: ShikiPluginOptions | undefined) => import("@razorwind/core/plugin").Plugin;
|
|
188
197
|
//#endregion
|
|
189
|
-
export { type FlatToken, type GenerateShikiTheme, type ShikiPluginOptions, type ShikiTheme, type ShikiThemeSetting, _default as default, flattenTokens, formatTokenValue, generateShikiTheme, normalizeThemes, renderThemeJson, resolveTokenSets, toCssVar };
|
|
198
|
+
export { type FlatToken, type GenerateShikiTheme, type ShikiPluginOptions, type ShikiTheme, type ShikiThemeSetting, _default as default, flattenTokens, formatTokenValue, generateShikiTheme, normalizeThemes, renderInstallMd, renderThemeJson, resolveTokenSets, themeDisplayName, toCssVar };
|
|
190
199
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/install.ts","../src/generate.ts","../src/index.ts"],"mappings":""}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,49 @@
|
|
|
1
|
-
import{definePlugin as e}from"@razorwind/core/plugin";import{createDocument as t,
|
|
1
|
+
import{definePlugin as e}from"@razorwind/core/plugin";import{createDocument as t,flattenTokens as n,formatTokenValue as r,isObject as i,resolveTokenSets as a,slugifyThemeName as o,themeDisplayName as s,toCssVar as c}from"@razorwind/core/utils";import{join as l}from"node:path";function u(e){let t=e.themes[0],n=e.themes.length===1?t.displayName:`Shiki Themes`,r=e.themes.map(e=>`- \`${e.fileName}\` — ${e.displayName} (theme id: \`${e.name}\`)`).join(`
|
|
2
|
+
`),i=e.themes.map(e=>`- \`${e.name}\` — ${e.displayName}`).join(`
|
|
3
|
+
`);return`# Installing ${n}
|
|
4
|
+
|
|
5
|
+
Generated by \`@razorwind/shiki\`.
|
|
6
|
+
|
|
7
|
+
## Files
|
|
8
|
+
|
|
9
|
+
${r}
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
1. Copy or import the generated JSON into your app (paths depend on your bundler).
|
|
14
|
+
|
|
15
|
+
2. Register themes when creating a Shiki highlighter:
|
|
16
|
+
|
|
17
|
+
\`\`\`ts
|
|
18
|
+
import { createHighlighter } from "shiki";
|
|
19
|
+
import theme from "./${t.fileName}";
|
|
20
|
+
|
|
21
|
+
const highlighter = await createHighlighter({
|
|
22
|
+
themes: [theme],
|
|
23
|
+
langs: ["javascript"]
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const html = highlighter.codeToHtml("const x = 1", {
|
|
27
|
+
lang: "javascript",
|
|
28
|
+
theme: "${t.name}"
|
|
29
|
+
});
|
|
30
|
+
\`\`\`
|
|
31
|
+
|
|
32
|
+
Or load at runtime:
|
|
33
|
+
|
|
34
|
+
\`\`\`ts
|
|
35
|
+
import { readFile } from "node:fs/promises";
|
|
36
|
+
|
|
37
|
+
const theme = JSON.parse(
|
|
38
|
+
await readFile("./${t.fileName}", "utf8")
|
|
39
|
+
);
|
|
40
|
+
await highlighter.loadTheme(theme);
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
## Select / load theme
|
|
44
|
+
|
|
45
|
+
Pass the theme id to \`codeToHtml\`, \`codeToTokens\`, or \`getTokenStyle\`:
|
|
46
|
+
|
|
47
|
+
${i}
|
|
48
|
+
`}function d(e){return s(e)}const f={name:`razorwind-shiki`};function p(e,n,r){return t(e,n,f,r)}function m(e){return i(e)&&typeof e.name==`string`&&e.name.length>0}function h(e){if(Array.isArray(e))return e.map((e,t)=>{if(!m(e))throw TypeError(`@razorwind/shiki mapTheme()[${t}] must be a ShikiTheme with name`);return e});if(m(e))return[e];if(!i(e))throw TypeError(`@razorwind/shiki mapTheme() must return a theme, theme array, or theme record`);return Object.entries(e).map(([e,t])=>{if(!m(t))throw TypeError(`@razorwind/shiki mapTheme()["${e}"] must be a ShikiTheme with name`);return{...t,name:t.name||e}})}function g(e){if(!e.mapTheme)throw Error(`@razorwind/shiki requires options.mapTheme`)}function _(e){let t=e.settings??e.tokenColors??[],n={name:e.name,settings:t};return e.displayName&&(n.displayName=e.displayName),e.type&&(n.type=e.type),e.fg!==void 0&&(n.fg=e.fg),e.bg!==void 0&&(n.bg=e.bg),e.colors&&(n.colors=e.colors),e.tokenColors&&e.settings&&(n.tokenColors=e.tokenColors),e.colorReplacements&&(n.colorReplacements=e.colorReplacements),e.semanticHighlighting!==void 0&&(n.semanticHighlighting=e.semanticHighlighting),e.semanticTokenColors&&(n.semanticTokenColors=e.semanticTokenColors),`${JSON.stringify(n,null,2)}\n`}function v(e,t){g(t);let n=t.outputPath??`shiki-themes`,r=h(t.mapTheme(e.tokens));if(r.length===0)throw Error(`@razorwind/shiki mapTheme() returned no themes`);let i={},a=new Set,s=[];for(let e of r){let t=`${o(e.name)}.json`;if(a.has(t)){let n=2;for(;a.has(`${o(e.name)}-${n}.json`);)n+=1;t=`${o(e.name)}-${n}.json`}a.add(t);let r=l(n,t);i[r]=p(r,_(e),`json`),s.push({name:e.name,displayName:d(e),fileName:t})}let c=t.installGuide??u({themes:s}),f=l(n,`INSTALL.md`);return i[f]=p(f,c,`markdown`),i}var y=e(e=>({name:`shiki`,generate:async t=>{if(!e)throw Error(`@razorwind/shiki requires options: { mapTheme }`);return v(t,e)}}));export{y as default,n as flattenTokens,r as formatTokenValue,v as generateShikiTheme,h as normalizeThemes,u as renderInstallMd,_ as renderThemeJson,a as resolveTokenSets,d as themeDisplayName,c as toCssVar};
|
|
2
49
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@razorwind/shiki",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Razorwind plugin that generates Shiki / TextMate themes from design tokens.",
|
|
6
6
|
"repository": {
|
|
@@ -67,15 +67,15 @@
|
|
|
67
67
|
"types": "./dist/index.d.cts",
|
|
68
68
|
"typings": "dist/index.d.mts",
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@power-plant/core": "^0.0.
|
|
70
|
+
"@power-plant/core": "^0.0.81",
|
|
71
71
|
"@power-plant/dtcg-schema": "^0.0.1",
|
|
72
|
-
"@razorwind/core": "0.0.
|
|
72
|
+
"@razorwind/core": "^0.0.30"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@powerlines/plugin-tsdown": "^0.1.
|
|
75
|
+
"@powerlines/plugin-tsdown": "^0.1.590",
|
|
76
76
|
"@types/node": "^25.9.5",
|
|
77
77
|
"typescript": "^6.0.3"
|
|
78
78
|
},
|
|
79
79
|
"publishConfig": { "access": "public" },
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "11a6e827627acf51ef0044e366fd9493f2173ec2"
|
|
81
81
|
}
|