@coldsmirk/inkstone-core 0.8.2-canary.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/README.md +41 -0
- package/dist/index.cjs +80 -0
- package/dist/index.d.cts +55 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +46 -0
- package/package.json +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# @coldsmirk/inkstone-core
|
|
2
|
+
|
|
3
|
+
The shared [Shiki](https://shiki.style/) highlighter service behind inkstone: one fine-grained, lazily-created singleton (catppuccin latte / macchiato, JS regex engine) that serves the editors, static code rendering, and markdown surfaces alike — one instance, consistent colors everywhere.
|
|
4
|
+
|
|
5
|
+
Part of [inkstone](https://github.com/coldsmirk/inkstone). The editor layers ([`@coldsmirk/inkstone-monaco`](https://www.npmjs.com/package/@coldsmirk/inkstone-monaco), [`@coldsmirk/inkstone-codemirror`](https://www.npmjs.com/package/@coldsmirk/inkstone-codemirror)) and the React components ([`@coldsmirk/inkstone-react`](https://www.npmjs.com/package/@coldsmirk/inkstone-react)) consume this package; use it directly when a non-editor surface needs the same highlighting.
|
|
6
|
+
|
|
7
|
+
## What you get
|
|
8
|
+
|
|
9
|
+
- **`getHighlighter()`** — the process-wide `HighlighterCore` promise. JavaScript / TypeScript / JSON / SQL grammars and the catppuccin theme pair load by default.
|
|
10
|
+
- **`configureHighlighter(config)`** — extend or replace the default grammar / theme set, once, before any editor mounts. `DEFAULT_HIGHLIGHTER_LANGS` is exported so extension is additive.
|
|
11
|
+
- **`shikiThemeId(dark)`** plus the `INKSTONE_LIGHT_THEME` / `INKSTONE_DARK_THEME` constants — the theme names to pass wherever a Shiki theme id is expected.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @coldsmirk/inkstone-core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`shiki` is a regular dependency and installs automatically. Node.js >= 22 for build / SSR hosts.
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { configureHighlighter, DEFAULT_HIGHLIGHTER_LANGS, getHighlighter, shikiThemeId } from "@coldsmirk/inkstone-core";
|
|
25
|
+
import yaml from "@shikijs/langs/yaml";
|
|
26
|
+
|
|
27
|
+
// Optional: add grammars/themes beyond the defaults — once, before any editor mounts.
|
|
28
|
+
configureHighlighter({ langs: [...DEFAULT_HIGHLIGHTER_LANGS, yaml] });
|
|
29
|
+
|
|
30
|
+
const highlighter = await getHighlighter();
|
|
31
|
+
const html = highlighter.codeToHtml("const x = 1;", {
|
|
32
|
+
lang: "javascript",
|
|
33
|
+
theme: shikiThemeId(true) // dark → catppuccin macchiato
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The same instance is the right one for non-editor surfaces (markdown code blocks, JSON inspectors, Mantine's `@mantine/code-highlight` adapter) — sharing it keeps their colors identical to the editors'.
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
|
|
41
|
+
UNLICENSED — proprietary. All rights reserved; no use, copying, or redistribution without the author's permission.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let _shikijs_langs_javascript = require("@shikijs/langs/javascript");
|
|
25
|
+
_shikijs_langs_javascript = __toESM(_shikijs_langs_javascript, 1);
|
|
26
|
+
let _shikijs_langs_json = require("@shikijs/langs/json");
|
|
27
|
+
_shikijs_langs_json = __toESM(_shikijs_langs_json, 1);
|
|
28
|
+
let _shikijs_langs_sql = require("@shikijs/langs/sql");
|
|
29
|
+
_shikijs_langs_sql = __toESM(_shikijs_langs_sql, 1);
|
|
30
|
+
let _shikijs_langs_typescript = require("@shikijs/langs/typescript");
|
|
31
|
+
_shikijs_langs_typescript = __toESM(_shikijs_langs_typescript, 1);
|
|
32
|
+
let _shikijs_themes_catppuccin_latte = require("@shikijs/themes/catppuccin-latte");
|
|
33
|
+
_shikijs_themes_catppuccin_latte = __toESM(_shikijs_themes_catppuccin_latte, 1);
|
|
34
|
+
let _shikijs_themes_catppuccin_macchiato = require("@shikijs/themes/catppuccin-macchiato");
|
|
35
|
+
_shikijs_themes_catppuccin_macchiato = __toESM(_shikijs_themes_catppuccin_macchiato, 1);
|
|
36
|
+
let shiki_core = require("shiki/core");
|
|
37
|
+
let shiki_engine_javascript = require("shiki/engine/javascript");
|
|
38
|
+
//#region src/shiki.ts
|
|
39
|
+
const INKSTONE_LIGHT_THEME = "catppuccin-latte";
|
|
40
|
+
const INKSTONE_DARK_THEME = "catppuccin-macchiato";
|
|
41
|
+
const DEFAULT_HIGHLIGHTER_LANGS = [
|
|
42
|
+
_shikijs_langs_javascript.default,
|
|
43
|
+
_shikijs_langs_typescript.default,
|
|
44
|
+
_shikijs_langs_json.default,
|
|
45
|
+
_shikijs_langs_sql.default
|
|
46
|
+
];
|
|
47
|
+
let config = {};
|
|
48
|
+
let promise = null;
|
|
49
|
+
function configureHighlighter(options) {
|
|
50
|
+
if (promise) throw new Error("configureHighlighter must be called before the first getHighlighter()");
|
|
51
|
+
config = {
|
|
52
|
+
...config,
|
|
53
|
+
...options
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function getHighlighter() {
|
|
57
|
+
promise ??= (0, shiki_core.createHighlighterCore)({
|
|
58
|
+
themes: [
|
|
59
|
+
_shikijs_themes_catppuccin_latte.default,
|
|
60
|
+
_shikijs_themes_catppuccin_macchiato.default,
|
|
61
|
+
...config.themes ?? []
|
|
62
|
+
],
|
|
63
|
+
langs: config.langs ?? [...DEFAULT_HIGHLIGHTER_LANGS],
|
|
64
|
+
engine: (0, shiki_engine_javascript.createJavaScriptRegexEngine)()
|
|
65
|
+
}).catch((error) => {
|
|
66
|
+
promise = null;
|
|
67
|
+
throw error;
|
|
68
|
+
});
|
|
69
|
+
return promise;
|
|
70
|
+
}
|
|
71
|
+
function shikiThemeId(dark) {
|
|
72
|
+
return dark ? INKSTONE_DARK_THEME : INKSTONE_LIGHT_THEME;
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
exports.DEFAULT_HIGHLIGHTER_LANGS = DEFAULT_HIGHLIGHTER_LANGS;
|
|
76
|
+
exports.INKSTONE_DARK_THEME = INKSTONE_DARK_THEME;
|
|
77
|
+
exports.INKSTONE_LIGHT_THEME = INKSTONE_LIGHT_THEME;
|
|
78
|
+
exports.configureHighlighter = configureHighlighter;
|
|
79
|
+
exports.getHighlighter = getHighlighter;
|
|
80
|
+
exports.shikiThemeId = shikiThemeId;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { HighlighterCore, HighlighterCore as HighlighterCore$1, LanguageInput, ThemeInput } from "shiki/core";
|
|
2
|
+
|
|
3
|
+
//#region src/shiki.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Shiki theme id inkstone editors use in light mode.
|
|
6
|
+
*/
|
|
7
|
+
declare const INKSTONE_LIGHT_THEME = "catppuccin-latte";
|
|
8
|
+
/**
|
|
9
|
+
* Shiki theme id inkstone editors use in dark mode.
|
|
10
|
+
*/
|
|
11
|
+
declare const INKSTONE_DARK_THEME = "catppuccin-macchiato";
|
|
12
|
+
/**
|
|
13
|
+
* The grammars the shared highlighter loads when {@link configureHighlighter} is not called:
|
|
14
|
+
* JavaScript / TypeScript / JSON / SQL — the set the coldsmirk apps actually edit and render.
|
|
15
|
+
* Spread these when adding a grammar: `configureHighlighter({ langs: [...DEFAULT_HIGHLIGHTER_LANGS, yaml] })`.
|
|
16
|
+
*/
|
|
17
|
+
declare const DEFAULT_HIGHLIGHTER_LANGS: readonly LanguageInput[];
|
|
18
|
+
interface HighlighterConfig {
|
|
19
|
+
/**
|
|
20
|
+
* Grammars to load, replacing {@link DEFAULT_HIGHLIGHTER_LANGS}.
|
|
21
|
+
*/
|
|
22
|
+
langs?: LanguageInput[];
|
|
23
|
+
/**
|
|
24
|
+
* Extra themes loaded alongside the built-in catppuccin pair (which is always loaded —
|
|
25
|
+
* the editor components select it by id).
|
|
26
|
+
*/
|
|
27
|
+
themes?: ThemeInput[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Configure the shared highlighter before its first use. The highlighter is a process-wide
|
|
31
|
+
* singleton (editors, static rendering, and markdown surfaces all share it for consistent
|
|
32
|
+
* colors), so configuration is process-global too and must happen before the first
|
|
33
|
+
* {@link getHighlighter} call — afterwards the instance is already built and this throws.
|
|
34
|
+
*/
|
|
35
|
+
declare function configureHighlighter(options: HighlighterConfig): void;
|
|
36
|
+
/**
|
|
37
|
+
* The shared Shiki highlighter, built lazily on first call.
|
|
38
|
+
*
|
|
39
|
+
* Fine-grained build: only the configured grammars and the two catppuccin themes are bundled,
|
|
40
|
+
* whereas the convenient `createHighlighter` generates a lazy chunk for *every* Shiki theme and
|
|
41
|
+
* language. The JS regex engine avoids the Oniguruma WASM — smaller, no extra network request,
|
|
42
|
+
* ideal for offline deployments (Tauri webviews, rust-embed consoles).
|
|
43
|
+
*
|
|
44
|
+
* A failed build is not cached: the slot resets so a later call retries (and
|
|
45
|
+
* {@link configureHighlighter} becomes callable again), instead of replaying one transient
|
|
46
|
+
* failure — a chunk 404 after a redeploy, a flaky network — for the rest of the session.
|
|
47
|
+
*/
|
|
48
|
+
declare function getHighlighter(): Promise<HighlighterCore$1>;
|
|
49
|
+
/**
|
|
50
|
+
* The Shiki theme id for a color scheme — {@link INKSTONE_DARK_THEME} when `dark`, else
|
|
51
|
+
* {@link INKSTONE_LIGHT_THEME}.
|
|
52
|
+
*/
|
|
53
|
+
declare function shikiThemeId(dark: boolean): string;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { DEFAULT_HIGHLIGHTER_LANGS, type HighlighterConfig, type HighlighterCore, INKSTONE_DARK_THEME, INKSTONE_LIGHT_THEME, configureHighlighter, getHighlighter, shikiThemeId };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { HighlighterCore, HighlighterCore as HighlighterCore$1, LanguageInput, ThemeInput } from "shiki/core";
|
|
2
|
+
|
|
3
|
+
//#region src/shiki.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Shiki theme id inkstone editors use in light mode.
|
|
6
|
+
*/
|
|
7
|
+
declare const INKSTONE_LIGHT_THEME = "catppuccin-latte";
|
|
8
|
+
/**
|
|
9
|
+
* Shiki theme id inkstone editors use in dark mode.
|
|
10
|
+
*/
|
|
11
|
+
declare const INKSTONE_DARK_THEME = "catppuccin-macchiato";
|
|
12
|
+
/**
|
|
13
|
+
* The grammars the shared highlighter loads when {@link configureHighlighter} is not called:
|
|
14
|
+
* JavaScript / TypeScript / JSON / SQL — the set the coldsmirk apps actually edit and render.
|
|
15
|
+
* Spread these when adding a grammar: `configureHighlighter({ langs: [...DEFAULT_HIGHLIGHTER_LANGS, yaml] })`.
|
|
16
|
+
*/
|
|
17
|
+
declare const DEFAULT_HIGHLIGHTER_LANGS: readonly LanguageInput[];
|
|
18
|
+
interface HighlighterConfig {
|
|
19
|
+
/**
|
|
20
|
+
* Grammars to load, replacing {@link DEFAULT_HIGHLIGHTER_LANGS}.
|
|
21
|
+
*/
|
|
22
|
+
langs?: LanguageInput[];
|
|
23
|
+
/**
|
|
24
|
+
* Extra themes loaded alongside the built-in catppuccin pair (which is always loaded —
|
|
25
|
+
* the editor components select it by id).
|
|
26
|
+
*/
|
|
27
|
+
themes?: ThemeInput[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Configure the shared highlighter before its first use. The highlighter is a process-wide
|
|
31
|
+
* singleton (editors, static rendering, and markdown surfaces all share it for consistent
|
|
32
|
+
* colors), so configuration is process-global too and must happen before the first
|
|
33
|
+
* {@link getHighlighter} call — afterwards the instance is already built and this throws.
|
|
34
|
+
*/
|
|
35
|
+
declare function configureHighlighter(options: HighlighterConfig): void;
|
|
36
|
+
/**
|
|
37
|
+
* The shared Shiki highlighter, built lazily on first call.
|
|
38
|
+
*
|
|
39
|
+
* Fine-grained build: only the configured grammars and the two catppuccin themes are bundled,
|
|
40
|
+
* whereas the convenient `createHighlighter` generates a lazy chunk for *every* Shiki theme and
|
|
41
|
+
* language. The JS regex engine avoids the Oniguruma WASM — smaller, no extra network request,
|
|
42
|
+
* ideal for offline deployments (Tauri webviews, rust-embed consoles).
|
|
43
|
+
*
|
|
44
|
+
* A failed build is not cached: the slot resets so a later call retries (and
|
|
45
|
+
* {@link configureHighlighter} becomes callable again), instead of replaying one transient
|
|
46
|
+
* failure — a chunk 404 after a redeploy, a flaky network — for the rest of the session.
|
|
47
|
+
*/
|
|
48
|
+
declare function getHighlighter(): Promise<HighlighterCore$1>;
|
|
49
|
+
/**
|
|
50
|
+
* The Shiki theme id for a color scheme — {@link INKSTONE_DARK_THEME} when `dark`, else
|
|
51
|
+
* {@link INKSTONE_LIGHT_THEME}.
|
|
52
|
+
*/
|
|
53
|
+
declare function shikiThemeId(dark: boolean): string;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { DEFAULT_HIGHLIGHTER_LANGS, type HighlighterConfig, type HighlighterCore, INKSTONE_DARK_THEME, INKSTONE_LIGHT_THEME, configureHighlighter, getHighlighter, shikiThemeId };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import langJavascript from "@shikijs/langs/javascript";
|
|
2
|
+
import langJson from "@shikijs/langs/json";
|
|
3
|
+
import langSql from "@shikijs/langs/sql";
|
|
4
|
+
import langTypescript from "@shikijs/langs/typescript";
|
|
5
|
+
import catppuccinLatte from "@shikijs/themes/catppuccin-latte";
|
|
6
|
+
import catppuccinMacchiato from "@shikijs/themes/catppuccin-macchiato";
|
|
7
|
+
import { createHighlighterCore } from "shiki/core";
|
|
8
|
+
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
|
|
9
|
+
//#region src/shiki.ts
|
|
10
|
+
const INKSTONE_LIGHT_THEME = "catppuccin-latte";
|
|
11
|
+
const INKSTONE_DARK_THEME = "catppuccin-macchiato";
|
|
12
|
+
const DEFAULT_HIGHLIGHTER_LANGS = [
|
|
13
|
+
langJavascript,
|
|
14
|
+
langTypescript,
|
|
15
|
+
langJson,
|
|
16
|
+
langSql
|
|
17
|
+
];
|
|
18
|
+
let config = {};
|
|
19
|
+
let promise = null;
|
|
20
|
+
function configureHighlighter(options) {
|
|
21
|
+
if (promise) throw new Error("configureHighlighter must be called before the first getHighlighter()");
|
|
22
|
+
config = {
|
|
23
|
+
...config,
|
|
24
|
+
...options
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function getHighlighter() {
|
|
28
|
+
promise ??= createHighlighterCore({
|
|
29
|
+
themes: [
|
|
30
|
+
catppuccinLatte,
|
|
31
|
+
catppuccinMacchiato,
|
|
32
|
+
...config.themes ?? []
|
|
33
|
+
],
|
|
34
|
+
langs: config.langs ?? [...DEFAULT_HIGHLIGHTER_LANGS],
|
|
35
|
+
engine: createJavaScriptRegexEngine()
|
|
36
|
+
}).catch((error) => {
|
|
37
|
+
promise = null;
|
|
38
|
+
throw error;
|
|
39
|
+
});
|
|
40
|
+
return promise;
|
|
41
|
+
}
|
|
42
|
+
function shikiThemeId(dark) {
|
|
43
|
+
return dark ? INKSTONE_DARK_THEME : INKSTONE_LIGHT_THEME;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { DEFAULT_HIGHLIGHTER_LANGS, INKSTONE_DARK_THEME, INKSTONE_LIGHT_THEME, configureHighlighter, getHighlighter, shikiThemeId };
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@coldsmirk/inkstone-core",
|
|
3
|
+
"version": "0.8.2-canary.0",
|
|
4
|
+
"description": "Shared Shiki highlighter service for the inkstone editor toolkit: one fine-grained singleton (catppuccin themes, JS regex engine) reused by Monaco, static rendering, and markdown surfaces.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"shiki",
|
|
7
|
+
"syntax-highlighting",
|
|
8
|
+
"editor",
|
|
9
|
+
"catppuccin",
|
|
10
|
+
"highlighter"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/coldsmirk/inkstone/tree/main/packages/core#readme",
|
|
13
|
+
"bugs": "https://github.com/coldsmirk/inkstone/issues",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/coldsmirk/inkstone.git",
|
|
17
|
+
"directory": "packages/core"
|
|
18
|
+
},
|
|
19
|
+
"license": "UNLICENSED",
|
|
20
|
+
"author": {
|
|
21
|
+
"name": "Venus"
|
|
22
|
+
},
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"source": "./src/index.ts",
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./dist/index.d.cts",
|
|
34
|
+
"default": "./dist/index.cjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"main": "./dist/index.cjs",
|
|
40
|
+
"module": "./dist/index.js",
|
|
41
|
+
"types": "./dist/index.d.ts",
|
|
42
|
+
"files": [
|
|
43
|
+
"dist"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsdown",
|
|
47
|
+
"clean": "rimraf dist",
|
|
48
|
+
"typecheck": "tsc --noEmit"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@shikijs/langs": "^4.3.1",
|
|
52
|
+
"@shikijs/themes": "^4.3.1",
|
|
53
|
+
"shiki": "^4.3.1"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=22"
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public",
|
|
60
|
+
"exports": {
|
|
61
|
+
".": {
|
|
62
|
+
"import": {
|
|
63
|
+
"types": "./dist/index.d.ts",
|
|
64
|
+
"default": "./dist/index.js"
|
|
65
|
+
},
|
|
66
|
+
"require": {
|
|
67
|
+
"types": "./dist/index.d.cts",
|
|
68
|
+
"default": "./dist/index.cjs"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"./package.json": "./package.json"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|