@coldsmirk/inkstone-mantine 0.11.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 ADDED
@@ -0,0 +1,63 @@
1
+ # @coldsmirk/inkstone-mantine
2
+
3
+ The [Mantine](https://mantine.dev/) bridge for the inkstone highlighter: a
4
+ [`CodeHighlight` adapter](https://mantine.dev/x/code-highlight/) that renders every static code
5
+ block through the shared Shiki singleton from
6
+ [`@coldsmirk/inkstone-core`](https://www.npmjs.com/package/@coldsmirk/inkstone-core), themed with
7
+ the same catppuccin pair (latte light / macchiato dark) the inkstone editors select — one
8
+ engine, one palette, across live editors and read-only blocks alike.
9
+
10
+ Part of [inkstone](https://github.com/coldsmirk/inkstone).
11
+
12
+ ## Why not Mantine's `createShikiAdapter`?
13
+
14
+ Mantine's built-in Shiki adapter accepts your highlighter but not your themes: for the `light` and
15
+ `dark` color schemes it substitutes its own bundled GitHub-flavoured theme objects. A highlighter
16
+ that loaded catppuccin renders GitHub colors anyway, and the app's static code blocks silently
17
+ drift from its editors. This adapter selects the inkstone theme pair by the computed color scheme
18
+ instead, so the drift cannot happen.
19
+
20
+ ## What you get
21
+
22
+ - **`codeHighlightAdapter`** — pass it to `CodeHighlightAdapterProvider` once; every
23
+ `CodeHighlight` / `InlineCodeHighlight` below it highlights through the shared singleton.
24
+
25
+ Degradation is total, never throwing into React: if the highlighter fails to load, blocks render
26
+ as plain text (logged, and retried by a later provider mount); a language without a loaded grammar
27
+ renders that block as plain text (warned once per language).
28
+
29
+ ## Install
30
+
31
+ ```bash
32
+ pnpm add @coldsmirk/inkstone-mantine @mantine/code-highlight
33
+ ```
34
+
35
+ `@mantine/code-highlight` (>= 8) is a peer dependency — the app owns its Mantine version.
36
+ `@coldsmirk/inkstone-core` installs automatically. Node.js >= 24 for build / SSR hosts.
37
+
38
+ ## Usage
39
+
40
+ ```tsx
41
+ import { codeHighlightAdapter } from "@coldsmirk/inkstone-mantine";
42
+ import { CodeHighlightAdapterProvider } from "@mantine/code-highlight";
43
+ import { MantineProvider } from "@mantine/core";
44
+
45
+ createRoot(document.querySelector("#root")!).render(
46
+ <MantineProvider defaultColorScheme="auto">
47
+ <CodeHighlightAdapterProvider adapter={codeHighlightAdapter}>
48
+ <App />
49
+ </CodeHighlightAdapterProvider>
50
+ </MantineProvider>
51
+ );
52
+ ```
53
+
54
+ The core defaults load JavaScript / TypeScript / JSON / SQL. Need more? Extend the shared
55
+ highlighter before anything renders — the editors and the code blocks pick up the grammar
56
+ together:
57
+
58
+ ```ts
59
+ import { configureHighlighter, DEFAULT_HIGHLIGHTER_LANGS } from "@coldsmirk/inkstone-core";
60
+ import langYaml from "@shikijs/langs/yaml";
61
+
62
+ configureHighlighter({ langs: [...DEFAULT_HIGHLIGHTER_LANGS, langYaml] });
63
+ ```
@@ -0,0 +1,25 @@
1
+ import { CodeHighlightAdapter } from "@mantine/code-highlight";
2
+
3
+ //#region src/code-highlight.d.ts
4
+ /**
5
+ * Mantine `CodeHighlight` adapter over the shared inkstone highlighter: install it once via
6
+ * `CodeHighlightAdapterProvider`, and every `CodeHighlight` / `InlineCodeHighlight` renders
7
+ * through the same Shiki singleton the inkstone editors tokenize with, themed with the same
8
+ * catppuccin pair (latte light / macchiato dark) the editors select — one engine, one palette,
9
+ * flipped by Mantine's computed color scheme.
10
+ *
11
+ * This exists because Mantine's own `createShikiAdapter` cannot express that: for the `light` /
12
+ * `dark` schemes it substitutes its bundled GitHub-flavoured theme objects, silently sidelining
13
+ * whatever themes the supplied highlighter loaded — static code blocks and live editors drift
14
+ * into two palettes.
15
+ *
16
+ * Degradation is total, never throwing into React: if the highlighter fails to load the adapter
17
+ * stays in plain-text mode (the failure is logged, and `getHighlighter` does not cache it — a
18
+ * later provider mount retries); a language the highlighter has no grammar for falls back to
19
+ * that block rendering as plain text (warned once per language). Grammars beyond the
20
+ * `@coldsmirk/inkstone-core` defaults are loaded app-side with `configureHighlighter`, before
21
+ * anything highlights.
22
+ */
23
+ declare const codeHighlightAdapter: CodeHighlightAdapter;
24
+ //#endregion
25
+ export { codeHighlightAdapter };
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ import { getHighlighter, shikiThemeId } from "@coldsmirk/inkstone-core";
2
+ import { stripShikiCodeBlocks } from "@mantine/code-highlight";
3
+ //#region src/code-highlight.ts
4
+ const warnedLanguages = /* @__PURE__ */ new Set();
5
+ function plainText(code) {
6
+ return {
7
+ highlightedCode: code,
8
+ isHighlighted: false
9
+ };
10
+ }
11
+ const codeHighlightAdapter = {
12
+ loadContext: () => getHighlighter().catch((error) => {
13
+ console.error("inkstone: shiki highlighter failed to load", error);
14
+ }),
15
+ getHighlighter: (ctx) => {
16
+ if (!ctx) return ({ code }) => plainText(code);
17
+ return ({ code, language, colorScheme }) => {
18
+ const lang = language ?? "text";
19
+ try {
20
+ return {
21
+ isHighlighted: true,
22
+ highlightedCode: stripShikiCodeBlocks(ctx.codeToHtml(code, {
23
+ lang,
24
+ theme: shikiThemeId(colorScheme === "dark")
25
+ }))
26
+ };
27
+ } catch (error) {
28
+ if (!warnedLanguages.has(lang)) {
29
+ warnedLanguages.add(lang);
30
+ console.warn(`inkstone: no grammar loaded for language "${lang}", rendering plain text`, error);
31
+ }
32
+ return plainText(code);
33
+ }
34
+ };
35
+ }
36
+ };
37
+ //#endregion
38
+ export { codeHighlightAdapter };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@coldsmirk/inkstone-mantine",
3
+ "version": "0.11.0",
4
+ "description": "Mantine adapter for the inkstone Shiki highlighter: a CodeHighlight adapter that renders through the shared singleton with its catppuccin pair — the same palette the inkstone editors use.",
5
+ "keywords": [
6
+ "mantine",
7
+ "shiki",
8
+ "code-highlight",
9
+ "syntax-highlighting",
10
+ "catppuccin"
11
+ ],
12
+ "homepage": "https://github.com/coldsmirk/inkstone/tree/main/packages/mantine#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/mantine"
18
+ },
19
+ "license": "UNLICENSED",
20
+ "author": {
21
+ "name": "Venus"
22
+ },
23
+ "sideEffects": false,
24
+ "type": "module",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "types": "./dist/index.d.ts",
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "dependencies": {
37
+ "@coldsmirk/inkstone-core": "^0.11.0"
38
+ },
39
+ "devDependencies": {
40
+ "@mantine/code-highlight": "^9.4.1",
41
+ "@mantine/core": "^9.4.1",
42
+ "@mantine/hooks": "^9.4.1",
43
+ "react": "^19.2.7",
44
+ "react-dom": "^19.2.7"
45
+ },
46
+ "peerDependencies": {
47
+ "@mantine/code-highlight": "^8.0.0 || ^9.0.0"
48
+ },
49
+ "engines": {
50
+ "node": ">=24"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "scripts": {
56
+ "build": "tsdown",
57
+ "clean": "rimraf dist",
58
+ "typecheck": "tsc --noEmit"
59
+ }
60
+ }