@coldsmirk/inkstone-core 0.9.0 → 0.10.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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +28 -12
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -16,7 +16,7 @@ Part of [inkstone](https://github.com/coldsmirk/inkstone). The editor layers ([`
16
16
  pnpm add @coldsmirk/inkstone-core
17
17
  ```
18
18
 
19
- `shiki` is a regular dependency and installs automatically. Node.js >= 22 for build / SSR hosts.
19
+ `shiki` is a regular dependency and installs automatically. Node.js >= 24 for build / SSR hosts.
20
20
 
21
21
  ## Quick start
22
22
 
package/dist/index.js CHANGED
@@ -15,29 +15,45 @@ const DEFAULT_HIGHLIGHTER_LANGS = [
15
15
  langJson,
16
16
  langSql
17
17
  ];
18
- let config = {};
19
- let promise = null;
18
+ const HIGHLIGHTER_REGISTRY_KEY = Symbol.for("coldsmirk.inkstone.shiki.registry");
19
+ function getHighlighterRegistry() {
20
+ const host = globalThis;
21
+ let registry = host[HIGHLIGHTER_REGISTRY_KEY];
22
+ if (!registry) {
23
+ registry = {
24
+ config: {},
25
+ promise: null
26
+ };
27
+ host[HIGHLIGHTER_REGISTRY_KEY] = registry;
28
+ }
29
+ return registry;
30
+ }
20
31
  function configureHighlighter(options) {
21
- if (promise) throw new Error("configureHighlighter must be called before the first getHighlighter()");
22
- config = {
23
- ...config,
32
+ const registry = getHighlighterRegistry();
33
+ if (registry.promise) throw new Error("configureHighlighter must be called before the first getHighlighter()");
34
+ registry.config = {
35
+ ...registry.config,
24
36
  ...options
25
37
  };
26
38
  }
27
39
  function getHighlighter() {
28
- promise ??= createHighlighterCore({
40
+ const registry = getHighlighterRegistry();
41
+ const existing = registry.promise;
42
+ if (existing) return existing;
43
+ const attempt = createHighlighterCore({
29
44
  themes: [
30
45
  catppuccinLatte,
31
46
  catppuccinMacchiato,
32
- ...config.themes ?? []
47
+ ...registry.config.themes ?? []
33
48
  ],
34
- langs: config.langs ?? [...DEFAULT_HIGHLIGHTER_LANGS],
49
+ langs: registry.config.langs ?? [...DEFAULT_HIGHLIGHTER_LANGS],
35
50
  engine: createJavaScriptRegexEngine()
36
- }).catch((error) => {
37
- promise = null;
38
- throw error;
39
51
  });
40
- return promise;
52
+ registry.promise = attempt;
53
+ attempt.catch(() => {
54
+ if (registry.promise === attempt) registry.promise = null;
55
+ });
56
+ return attempt;
41
57
  }
42
58
  function shikiThemeId(dark) {
43
59
  return dark ? INKSTONE_DARK_THEME : INKSTONE_LIGHT_THEME;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coldsmirk/inkstone-core",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
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
5
  "keywords": [
6
6
  "shiki",