@vortexlabs/kirari-react 1.1.1 → 1.2.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/CHANGELOG.md +12 -0
- package/README.md +5 -87
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +17 -17
- package/stream.d.ts +1 -0
- package/stream.js +1 -0
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -16
- package/dist/render.d.ts +0 -5
- package/dist/render.js +0 -104
- package/dist/stream.d.ts +0 -11
- package/dist/stream.js +0 -24
- package/dist/types.d.ts +0 -37
- package/dist/types.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @vortexlabs/kirari-react
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ef4462a: Publish under unscoped names: `kirari`, `kirari-react`, and `kirari-rehype`. The `@vortexlabs/kirari`, `@vortexlabs/kirari-react`, and `@vortexlabs/kirari-rehype` packages now re-export them, so existing imports keep working.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [ef4462a]
|
|
12
|
+
- kirari@1.2.0
|
|
13
|
+
- kirari-react@1.2.0
|
|
14
|
+
|
|
3
15
|
## 1.1.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,95 +1,13 @@
|
|
|
1
1
|
# @vortexlabs/kirari-react
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[`@vortexlabs/kirari`](https://github.com/vortexkit/kirari/blob/main/packages/kirari/README.md).
|
|
5
|
-
`<Code>` renders code as React elements and works in Server Components. Use the
|
|
6
|
-
optional streaming hook for code that arrives in chunks.
|
|
3
|
+
This package has been renamed to [`kirari-react`](https://www.npmjs.com/package/kirari-react).
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## Install
|
|
5
|
+
`@vortexlabs/kirari-react` re-exports `kirari-react` on every entry point, so existing imports keep working and keep receiving updates. New projects should install `kirari-react` directly:
|
|
11
6
|
|
|
12
7
|
```sh
|
|
13
|
-
npm install
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
Requires React 19. Kirari is a peer dependency.
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
```tsx
|
|
21
|
-
import { Code } from '@vortexlabs/kirari-react'
|
|
22
|
-
import { typescript } from '@vortexlabs/kirari/languages'
|
|
23
|
-
import '@vortexlabs/kirari/theme.css'
|
|
24
|
-
|
|
25
|
-
export const CodeExample = () => (
|
|
26
|
-
<Code language={typescript}>
|
|
27
|
-
{'const greeting: string = "Hello"'}
|
|
28
|
-
</Code>
|
|
29
|
-
)
|
|
8
|
+
npm install kirari-react
|
|
30
9
|
```
|
|
31
10
|
|
|
32
|
-
|
|
33
|
-
`kirari-*` classes, so every Kirari theme works. Code text is escaped by React;
|
|
34
|
-
the component does not use `dangerouslySetInnerHTML`. Text children are joined
|
|
35
|
-
as React joins text, so `{value}` interpolation works; elements throw. `language`
|
|
36
|
-
defaults to JavaScript. Other props go to the `<pre>`.
|
|
37
|
-
|
|
38
|
-
## Lines and customization
|
|
39
|
-
|
|
40
|
-
Use `highlightLines={[1, [3, 4]]}` to mark line 1 and lines 3–4. Style
|
|
41
|
-
`.kirari-line-highlighted` to choose the highlight's appearance.
|
|
42
|
-
|
|
43
|
-
| Prop | Effect |
|
|
44
|
-
| --- | --- |
|
|
45
|
-
| `lines` | Wrap each line in `<span class="kirari-line" data-line="n">`. |
|
|
46
|
-
| `highlightLines` | Lines or `[first, last]` ranges get `kirari-line-highlighted`. Implies `lines`. |
|
|
47
|
-
| `lineClassName` | `(line) => class` for a line wrapper. `line` is `{ number, start, end }`. |
|
|
48
|
-
| `decorations` | `{ start, end, className }` source ranges, as in [decorations](https://github.com/vortexkit/kirari/blob/main/docs/decorations.md). |
|
|
49
|
-
| `classes` | Extra classes per token type, e.g. `{ keyword: 'kw' }`. |
|
|
50
|
-
| `tokenClassName` | `(token) => class` per token. |
|
|
51
|
-
| `tokens` | Pre-scanned tokens instead of `children`. |
|
|
52
|
-
|
|
53
|
-
Line numbers are CSS:
|
|
54
|
-
|
|
55
|
-
```css
|
|
56
|
-
.kirari-line::before { content: attr(data-line); display: inline-block; width: 3ch; margin-right: 2ch; opacity: 0.5; }
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Streaming
|
|
60
|
-
|
|
61
|
-
```tsx
|
|
62
|
-
'use client'
|
|
63
|
-
|
|
64
|
-
import { Code } from '@vortexlabs/kirari-react'
|
|
65
|
-
import { useTokenStream } from '@vortexlabs/kirari-react/stream'
|
|
66
|
-
import { javascript } from '@vortexlabs/kirari/languages'
|
|
67
|
-
import '@vortexlabs/kirari/theme.css'
|
|
68
|
-
|
|
69
|
-
export const StreamExample = () => {
|
|
70
|
-
const { tokens, write, reset } = useTokenStream(javascript)
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
<>
|
|
74
|
-
<button type="button" onClick={() => write('const count = 42\n')}>
|
|
75
|
-
Append a line
|
|
76
|
-
</button>
|
|
77
|
-
<button type="button" onClick={reset}>Reset</button>
|
|
78
|
-
<Code tokens={tokens} />
|
|
79
|
-
</>
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
This example adds one chunk per click. In your app, call `write(chunk)` as text
|
|
85
|
-
arrives. The hook also returns `end()`, which closes the stream when it is complete.
|
|
86
|
-
|
|
87
|
-
- Built-in JavaScript, TypeScript, JSX, TSX, JSON, JSONC, and Python reuse completed scanning work. Other languages rescan the full source. Long unfinished tokens can still be expensive; see [token streaming](https://github.com/vortexkit/kirari/blob/main/docs/streaming.md).
|
|
88
|
-
- Changing `language` starts a new, empty stream.
|
|
89
|
-
- After `end()`, call `reset()` before writing again.
|
|
90
|
-
- `/stream` is a client module; `<Code>` is not.
|
|
91
|
-
- Managing tokens yourself? Use `createTokenStream` from `@vortexlabs/kirari/stream` with `applyPatch(tokens, patch)`.
|
|
92
|
-
|
|
93
|
-
## License
|
|
11
|
+
To switch an existing project, replace `@vortexlabs/kirari-react` with `kirari-react` in `package.json` and in import paths. Nothing else changes.
|
|
94
12
|
|
|
95
|
-
[
|
|
13
|
+
Documentation: [kirari.sh](https://kirari.sh)
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'kirari-react'
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'kirari-react'
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vortexlabs/kirari-react",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Renamed to kirari-react. This package re-exports kirari-react so existing imports keep working.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
7
7
|
"react-component",
|
|
@@ -14,36 +14,40 @@
|
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
16
|
"url": "git+https://github.com/vortexkit/kirari.git",
|
|
17
|
-
"directory": "packages/react"
|
|
17
|
+
"directory": "packages/compat-react"
|
|
18
18
|
},
|
|
19
19
|
"type": "module",
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"files": [
|
|
22
|
-
"
|
|
22
|
+
"index.js",
|
|
23
|
+
"index.d.ts",
|
|
24
|
+
"stream.js",
|
|
25
|
+
"stream.d.ts",
|
|
23
26
|
"README.md",
|
|
24
27
|
"LICENSE",
|
|
25
28
|
"CHANGELOG.md"
|
|
26
29
|
],
|
|
27
30
|
"exports": {
|
|
28
31
|
".": {
|
|
29
|
-
"types": "./
|
|
30
|
-
"import": "./
|
|
32
|
+
"types": "./index.d.ts",
|
|
33
|
+
"import": "./index.js"
|
|
31
34
|
},
|
|
32
35
|
"./stream": {
|
|
33
|
-
"types": "./
|
|
34
|
-
"import": "./
|
|
36
|
+
"types": "./stream.d.ts",
|
|
37
|
+
"import": "./stream.js"
|
|
35
38
|
}
|
|
36
39
|
},
|
|
37
40
|
"scripts": {
|
|
38
|
-
"build": "tsc -p tsconfig.build.json",
|
|
39
41
|
"test": "bun test ./test",
|
|
40
42
|
"typecheck": "tsc --noEmit",
|
|
41
|
-
"check": "bun run typecheck && bun
|
|
42
|
-
|
|
43
|
+
"check": "bun run typecheck && bun test ./test"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"kirari": "^1.2.0",
|
|
47
|
+
"kirari-react": "^1.2.0"
|
|
43
48
|
},
|
|
44
49
|
"peerDependencies": {
|
|
45
50
|
"@types/react": "^19",
|
|
46
|
-
"@vortexlabs/kirari": "^1.0.0",
|
|
47
51
|
"react": "^19"
|
|
48
52
|
},
|
|
49
53
|
"peerDependenciesMeta": {
|
|
@@ -52,12 +56,8 @@
|
|
|
52
56
|
}
|
|
53
57
|
},
|
|
54
58
|
"devDependencies": {
|
|
55
|
-
"@happy-dom/global-registrator": "^20.14.6",
|
|
56
59
|
"@types/react": "^19.3.0",
|
|
57
|
-
"
|
|
58
|
-
"@vortexlabs/kirari": "1.1.3",
|
|
59
|
-
"react": "^19.3.1",
|
|
60
|
-
"react-dom": "^19.3.1"
|
|
60
|
+
"react": "^19.3.1"
|
|
61
61
|
},
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|
package/stream.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'kirari-react/stream'
|
package/stream.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'kirari-react/stream'
|
package/dist/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
import type { CodeProps } from './types.js';
|
|
3
|
-
export type { CodeProps, CodeText, Line, LineRange } from './types.js';
|
|
4
|
-
/** Highlighted code as React elements. Uses no hooks, so it also renders as a Server Component. */
|
|
5
|
-
export declare const Code: ({ children, tokens, language, ...props }: CodeProps) => ReactNode;
|
|
6
|
-
export type { Decoration } from '@vortexlabs/kirari/decorations';
|
|
7
|
-
export type { Language, Token } from '@vortexlabs/kirari/core';
|
package/dist/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { tokenize } from '@vortexlabs/kirari/core';
|
|
2
|
-
import { javascript } from '@vortexlabs/kirari/languages/javascript';
|
|
3
|
-
import { renderCode } from './render.js';
|
|
4
|
-
const sourceText = (children) => {
|
|
5
|
-
if (children == null || typeof children === 'boolean')
|
|
6
|
-
return '';
|
|
7
|
-
if (typeof children === 'string' || typeof children === 'number' || typeof children === 'bigint')
|
|
8
|
-
return String(children);
|
|
9
|
-
if (Array.isArray(children))
|
|
10
|
-
return children.map(sourceText).join('');
|
|
11
|
-
throw new TypeError('Kirari: <Code> children must be text');
|
|
12
|
-
};
|
|
13
|
-
/** Highlighted code as React elements. Uses no hooks, so it also renders as a Server Component. */
|
|
14
|
-
export const Code = ({ children, tokens, language = javascript, ...props }) => {
|
|
15
|
-
return renderCode(tokens ?? tokenize(sourceText(children), language), props);
|
|
16
|
-
};
|
package/dist/render.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
import type { Token } from '@vortexlabs/kirari/core';
|
|
3
|
-
import type { CodeProps } from './types.js';
|
|
4
|
-
/** Renders highlighted tokens and forwards the remaining props to the pre element. */
|
|
5
|
-
export declare const renderCode: (tokens: readonly Token[], options: Omit<CodeProps, 'children' | 'tokens' | 'language'>) => ReactNode;
|
package/dist/render.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
const join = (...names) => {
|
|
3
|
-
return names.filter(Boolean).join(' ');
|
|
4
|
-
};
|
|
5
|
-
const splitsSurrogate = (source, offset) => {
|
|
6
|
-
const before = source.charCodeAt(offset - 1);
|
|
7
|
-
const after = source.charCodeAt(offset);
|
|
8
|
-
return before >= 0xd800 && before <= 0xdbff && after >= 0xdc00 && after <= 0xdfff;
|
|
9
|
-
};
|
|
10
|
-
const highlighted = (ranges) => {
|
|
11
|
-
const pairs = ranges.map(range => typeof range === 'number' ? [range, range] : range);
|
|
12
|
-
return line => pairs.some(([first, last]) => first <= line && line <= last);
|
|
13
|
-
};
|
|
14
|
-
const assertContiguous = (tokens) => {
|
|
15
|
-
let offset = 0;
|
|
16
|
-
for (const token of tokens) {
|
|
17
|
-
if (token.start !== offset || token.end !== offset + token.value.length) {
|
|
18
|
-
throw new RangeError('Kirari: tokens must cover contiguous source offsets starting at zero');
|
|
19
|
-
}
|
|
20
|
-
offset = token.end;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
/** Validated enter/leave points for each decoration, in source order. */
|
|
24
|
-
const decorationEvents = (decorations, source) => {
|
|
25
|
-
const events = [];
|
|
26
|
-
for (const [index, decoration] of decorations.entries()) {
|
|
27
|
-
if (!Number.isInteger(decoration.start) || !Number.isInteger(decoration.end)
|
|
28
|
-
|| decoration.start < 0 || decoration.start >= decoration.end || decoration.end > source.length) {
|
|
29
|
-
throw new RangeError('Kirari: decoration offsets must be integers with 0 <= start < end <= source length');
|
|
30
|
-
}
|
|
31
|
-
if (splitsSurrogate(source, decoration.start) || splitsSurrogate(source, decoration.end)) {
|
|
32
|
-
throw new RangeError('Kirari: decoration offsets must not split a UTF-16 surrogate pair');
|
|
33
|
-
}
|
|
34
|
-
events.push({ offset: decoration.start, index, entering: true }, { offset: decoration.end, index, entering: false });
|
|
35
|
-
}
|
|
36
|
-
return events.sort((a, b) => a.offset - b.offset);
|
|
37
|
-
};
|
|
38
|
-
const codeNodes = (tokens, options = {}) => {
|
|
39
|
-
assertContiguous(tokens);
|
|
40
|
-
const source = tokens.map(token => token.value).join('');
|
|
41
|
-
const decorations = options.decorations ?? [];
|
|
42
|
-
const events = decorationEvents(decorations, source);
|
|
43
|
-
// Resolve callbacks once so tokens split by lines or decorations see them a single time.
|
|
44
|
-
const tokenClasses = tokens.map(token => join(options.classes && Object.hasOwn(options.classes, token.type) ? options.classes[token.type] : undefined, options.tokenClassName?.(token)));
|
|
45
|
-
const active = new Set();
|
|
46
|
-
let activeClasses = '';
|
|
47
|
-
let eventIndex = 0;
|
|
48
|
-
let tokenIndex = 0;
|
|
49
|
-
const rangeNodes = (start, end) => {
|
|
50
|
-
const nodes = [];
|
|
51
|
-
while (start < end) {
|
|
52
|
-
while (tokens[tokenIndex].end <= start)
|
|
53
|
-
tokenIndex++;
|
|
54
|
-
let changed = false;
|
|
55
|
-
while (eventIndex < events.length && events[eventIndex].offset <= start) {
|
|
56
|
-
const event = events[eventIndex++];
|
|
57
|
-
if (event.entering)
|
|
58
|
-
active.add(event.index);
|
|
59
|
-
else
|
|
60
|
-
active.delete(event.index);
|
|
61
|
-
changed = true;
|
|
62
|
-
}
|
|
63
|
-
if (changed)
|
|
64
|
-
activeClasses = [...active].sort((a, b) => a - b).map(index => decorations[index].className).join(' ');
|
|
65
|
-
const token = tokens[tokenIndex];
|
|
66
|
-
const stop = Math.min(end, token.end, events[eventIndex]?.offset ?? end);
|
|
67
|
-
const value = source.slice(start, stop);
|
|
68
|
-
const extra = join(tokenClasses[tokenIndex], activeClasses);
|
|
69
|
-
nodes.push(token.type === 'text' && !extra
|
|
70
|
-
? value
|
|
71
|
-
: _jsx("span", { className: join(`kirari-${token.type}`, extra), children: value }, start));
|
|
72
|
-
start = stop;
|
|
73
|
-
}
|
|
74
|
-
return nodes;
|
|
75
|
-
};
|
|
76
|
-
const ranges = options.highlightLines ?? [];
|
|
77
|
-
if (!options.lines && ranges.length === 0)
|
|
78
|
-
return rangeNodes(0, source.length);
|
|
79
|
-
const isHighlighted = highlighted(ranges);
|
|
80
|
-
const nodes = [];
|
|
81
|
-
const newline = /\r\n|\r|\n/g;
|
|
82
|
-
let start = 0;
|
|
83
|
-
let number = 1;
|
|
84
|
-
do {
|
|
85
|
-
const match = newline.exec(source);
|
|
86
|
-
const end = match?.index ?? source.length;
|
|
87
|
-
const className = join('kirari-line', options.lineClassName?.({ number, start, end }), isHighlighted(number) ? 'kirari-line-highlighted' : undefined);
|
|
88
|
-
nodes.push(_jsx("span", { className: className, "data-line": number, children: rangeNodes(start, end) }, `line-${number}`));
|
|
89
|
-
if (!match)
|
|
90
|
-
break;
|
|
91
|
-
nodes.push(match[0]);
|
|
92
|
-
start = end + match[0].length;
|
|
93
|
-
if (start === source.length)
|
|
94
|
-
break;
|
|
95
|
-
number++;
|
|
96
|
-
} while (true);
|
|
97
|
-
return nodes;
|
|
98
|
-
};
|
|
99
|
-
/** Renders highlighted tokens and forwards the remaining props to the pre element. */
|
|
100
|
-
export const renderCode = (tokens, options) => {
|
|
101
|
-
const { classes, tokenClassName, decorations, lines, lineClassName, highlightLines, className, ...props } = options;
|
|
102
|
-
const nodes = codeNodes(tokens, options);
|
|
103
|
-
return _jsx("pre", { ...props, className: join('kirari', className), children: _jsx("code", { children: nodes }) });
|
|
104
|
-
};
|
package/dist/stream.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Language, Token } from '@vortexlabs/kirari/core';
|
|
2
|
-
import type { TokenPatch } from '@vortexlabs/kirari/stream';
|
|
3
|
-
export type StreamedTokens = {
|
|
4
|
-
readonly tokens: readonly Token[];
|
|
5
|
-
write(chunk: string): void;
|
|
6
|
-
end(chunk?: string): void;
|
|
7
|
-
reset(): void;
|
|
8
|
-
};
|
|
9
|
-
export declare const applyPatch: (tokens: readonly Token[], patch: TokenPatch) => readonly Token[];
|
|
10
|
-
/** Tokens for source that arrives in chunks. Pass the result's `tokens` to `<Code tokens>`. */
|
|
11
|
-
export declare const useTokenStream: (language: Language) => StreamedTokens;
|
package/dist/stream.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useCallback, useMemo, useState } from 'react';
|
|
3
|
-
import { createTokenStream } from '@vortexlabs/kirari/stream';
|
|
4
|
-
export const applyPatch = (tokens, patch) => {
|
|
5
|
-
return [...tokens.filter(token => token.end <= patch.from), ...patch.tokens];
|
|
6
|
-
};
|
|
7
|
-
/** Tokens for source that arrives in chunks. Pass the result's `tokens` to `<Code tokens>`. */
|
|
8
|
-
export const useTokenStream = (language) => {
|
|
9
|
-
const stream = useMemo(() => createTokenStream(language), [language]);
|
|
10
|
-
const [snapshot, setSnapshot] = useState({ stream, tokens: [] });
|
|
11
|
-
// A new language starts a new stream; tokens from the previous one no longer apply.
|
|
12
|
-
if (snapshot.stream !== stream)
|
|
13
|
-
setSnapshot({ stream, tokens: [] });
|
|
14
|
-
const apply = useCallback((patch) => {
|
|
15
|
-
setSnapshot(previous => previous.stream === stream ? { stream, tokens: applyPatch(previous.tokens, patch) } : previous);
|
|
16
|
-
}, [stream]);
|
|
17
|
-
const write = useCallback((chunk) => apply(stream.write(chunk)), [stream, apply]);
|
|
18
|
-
const end = useCallback((chunk) => apply(stream.end(chunk)), [stream, apply]);
|
|
19
|
-
const reset = useCallback(() => {
|
|
20
|
-
stream.reset();
|
|
21
|
-
setSnapshot({ stream, tokens: [] });
|
|
22
|
-
}, [stream]);
|
|
23
|
-
return { tokens: snapshot.stream === stream ? snapshot.tokens : [], write, end, reset };
|
|
24
|
-
};
|
package/dist/types.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { ComponentPropsWithoutRef } from 'react';
|
|
2
|
-
import type { Language, Token } from '@vortexlabs/kirari/core';
|
|
3
|
-
import type { Decoration } from '@vortexlabs/kirari/decorations';
|
|
4
|
-
/** A one-based line number or an inclusive pair of line numbers. */
|
|
5
|
-
export type LineRange = number | readonly [first: number, last: number];
|
|
6
|
-
/** A rendered source line; CRLF, CR, and LF separators sit outside its wrapper. */
|
|
7
|
-
export type Line = {
|
|
8
|
-
/** One-based line number. */
|
|
9
|
-
readonly number: number;
|
|
10
|
-
/** Inclusive UTF-16 offset into the complete source. */
|
|
11
|
-
readonly start: number;
|
|
12
|
-
/** Exclusive UTF-16 offset; excludes any line separator. */
|
|
13
|
-
readonly end: number;
|
|
14
|
-
};
|
|
15
|
-
/** Text children, joined like React text: `null`, `undefined`, and booleans render nothing. */
|
|
16
|
-
export type CodeText = string | number | bigint | boolean | null | undefined | readonly CodeText[];
|
|
17
|
-
/** Highlighted code options; remaining native props are forwarded to the `<pre>` element. */
|
|
18
|
-
export interface CodeProps extends Omit<ComponentPropsWithoutRef<'pre'>, 'children'> {
|
|
19
|
-
/** Source to highlight. Ignored when `tokens` is set. */
|
|
20
|
-
readonly children?: CodeText;
|
|
21
|
-
/** Pre-scanned tokens covering contiguous source offsets from zero; overrides `children` and `language`. */
|
|
22
|
-
readonly tokens?: readonly Token[];
|
|
23
|
-
/** Language used to tokenize `children`. Defaults to JavaScript. */
|
|
24
|
-
readonly language?: Language;
|
|
25
|
-
/** Additional classes by token category, combined with the standard `kirari-*` classes. */
|
|
26
|
-
readonly classes?: Readonly<Record<string, string>>;
|
|
27
|
-
/** Additional classes, resolved once per original token before line or decoration splits. */
|
|
28
|
-
readonly tokenClassName?: (token: Token) => string | undefined;
|
|
29
|
-
/** Source ranges receiving extra classes; offsets must be valid UTF-16 boundaries. */
|
|
30
|
-
readonly decorations?: readonly Decoration[];
|
|
31
|
-
/** Wrap each line in `<span class="kirari-line" data-line="n">`. Defaults to `false`. */
|
|
32
|
-
readonly lines?: boolean;
|
|
33
|
-
/** Additional classes per rendered line; used when `lines` or nonempty `highlightLines` enables wrappers. */
|
|
34
|
-
readonly lineClassName?: (line: Line) => string | undefined;
|
|
35
|
-
/** One-based lines or inclusive ranges that receive `kirari-line-highlighted`. Implies `lines`. */
|
|
36
|
-
readonly highlightLines?: readonly LineRange[];
|
|
37
|
-
}
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|