@owomark/view 0.1.4 → 0.1.6
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 +16 -281
- package/dist/{chunk-Y72HQJQI.js → chunk-KHKPOH74.js} +2 -3
- package/dist/{chunk-F3LG7AML.js → chunk-WA6XHBZS.js} +34 -13
- package/dist/index.d.ts +21 -77
- package/dist/index.js +268 -46
- package/dist/internal/virtual/height-estimator.d.ts +2 -9
- package/dist/internal/virtual/height-estimator.js +1 -1
- package/dist/internal/virtual/viewport-manager.js +1 -1
- package/dist/types-DsL_4tUb.d.ts +93 -0
- package/package.json +2 -38
- package/src/style.css +0 -3
- package/src/theme/dark.css +6 -0
- package/src/theme/light.css +6 -0
- package/src/theme/owomark.css +22 -2
- package/dist/chunk-DHRAXGIK.js +0 -1710
- package/dist/static.d.ts +0 -220
- package/dist/static.js +0 -40
- package/src/mdx-components/mdx-components.css +0 -336
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@owomark/view`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Install the official package: `@owomark/view`.
|
|
3
|
+
Browser-only view infrastructure for OwoMark. This package owns the editor view, preview engine, DOM patching, layout logic, and official theme token values.
|
|
6
4
|
|
|
7
5
|
## Install
|
|
8
6
|
|
|
@@ -10,287 +8,24 @@ Install the official package: `@owomark/view`.
|
|
|
10
8
|
npm install @owomark/view
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install @mdx-js/mdx react react-dom
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Quick Start
|
|
20
|
-
|
|
21
|
-
### Official CSS Entry
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
import '@owomark/view/style.css';
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
`style.css` is the official base theme bundle. It includes the structural CSS, built-in MDX component styles, side-annotation/slash-menu styles, and the light/dark preset token values. New users should start here.
|
|
11
|
+
## Scope
|
|
28
12
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const processor = createOwoMarkProcessor();
|
|
35
|
-
const result = await processor.process('# Hello\n\nA paragraph with **bold**.');
|
|
36
|
-
console.log(String(result));
|
|
37
|
-
// <h1 id="hello">Hello</h1>\n<p>A paragraph with <strong>bold</strong>.</p>
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### MDX → HTML
|
|
41
|
-
|
|
42
|
-
Enable MDX to render JSX components and expressions at build time:
|
|
43
|
-
|
|
44
|
-
```ts
|
|
45
|
-
import { createOwoMarkProcessor } from '@owomark/view/static';
|
|
46
|
-
|
|
47
|
-
const processor = createOwoMarkProcessor({ enableMdx: true });
|
|
48
|
-
const result = await processor.process(`
|
|
49
|
-
<Callout type="info">
|
|
50
|
-
Today is {new Date().getFullYear()}. MDX expressions just work.
|
|
51
|
-
</Callout>
|
|
52
|
-
`);
|
|
53
|
-
console.log(String(result));
|
|
54
|
-
// Built-in Callout component renders to styled HTML
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### With Custom Components
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
import { createElement } from 'react';
|
|
61
|
-
import { createOwoMarkProcessor } from '@owomark/view/static';
|
|
62
|
-
|
|
63
|
-
const Chart = ({ data }) => createElement('div', { className: 'chart' }, `Chart: ${data}`);
|
|
64
|
-
|
|
65
|
-
const processor = createOwoMarkProcessor({
|
|
66
|
-
enableMdx: true,
|
|
67
|
-
mdxComponents: {
|
|
68
|
-
Chart, // Add your own component
|
|
69
|
-
// Callout, // Built-ins are still available unless you override them
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const result = await processor.process('<Chart data="revenue" />');
|
|
74
|
-
```
|
|
13
|
+
- `createOwoMarkView()` and `createOwoMarkVanillaEditor()` for interactive editing
|
|
14
|
+
- `createOwoMarkPreviewEngine()` and renderer registry APIs for preview DOM rendering
|
|
15
|
+
- `PreviewDomPatcher` and `SideAnnotationPositioner` for browser layout work
|
|
16
|
+
- `getThemeClassName()`, `light.css`, `dark.css`, `owomark.css`, `preview.css`, `slash-menu.css`, `side-annotation.css`
|
|
75
17
|
|
|
76
|
-
##
|
|
77
|
-
|
|
78
|
-
The Gold Processor Factory is the single source of truth for OwoMark's rendering pipeline. Both preview and production consume the same factory.
|
|
79
|
-
|
|
80
|
-
### `createOwoMarkProcessor(options?)`
|
|
81
|
-
|
|
82
|
-
Returns an `OwoMarkProcessor` with a single `process(source) → Promise<{ value, toString }>` method.
|
|
83
|
-
|
|
84
|
-
| Option | Type | Default | Description |
|
|
85
|
-
|--------|------|---------|-------------|
|
|
86
|
-
| `mode` | `'preview' \| 'production'` | `'preview'` | Rendering mode |
|
|
87
|
-
| `enableMdx` | `boolean` | `false` | Enable MDX rendering (JSX components + expressions) |
|
|
88
|
-
| `mdxComponents` | `Record<string, ComponentType>` | `{}` | Additional/override components (merged with built-ins) |
|
|
89
|
-
| `enableMath` | `boolean` | `true` | Enable KaTeX math rendering (`$...$`, `$$...$$`) |
|
|
90
|
-
| `enableSideAnnotation` | `boolean` | `true` | Enable side annotation syntax |
|
|
91
|
-
| `preserveSoftLineBreaks` | `boolean` | `false` | When false, plain newlines become `<br>` |
|
|
92
|
-
| `codeTheme` | `string` | `'vitesse-light'` | Shiki theme for code highlighting |
|
|
93
|
-
| `extraRemarkPlugins` | `PluginEntry[]` | `[]` | Additional remark plugins |
|
|
94
|
-
| `extraRehypePlugins` | `PluginEntry[]` | `[]` | Additional rehype plugins |
|
|
95
|
-
|
|
96
|
-
### `getOwoMarkPlugins(options?)`
|
|
97
|
-
|
|
98
|
-
Returns `{ remarkPlugins, rehypePlugins }` arrays for use with `@mdx-js/mdx` compile paths directly. Excludes `remark-parse` and `remark-mdx` (MDX manages its own parser).
|
|
99
|
-
|
|
100
|
-
## Theme Packages
|
|
101
|
-
|
|
102
|
-
`@owomark/view` owns the official base theme. Third-party themes should layer on top of it instead of replacing it.
|
|
103
|
-
|
|
104
|
-
### Using a Third-Party Theme
|
|
105
|
-
|
|
106
|
-
```ts
|
|
107
|
-
import '@owomark/view/style.css';
|
|
108
|
-
import 'owomark-theme-acme/style.css';
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
Load `@owomark/view/style.css` first, then the theme package. The theme package should override `--owo-*` tokens and only add narrowly scoped visual overrides when tokens are not enough.
|
|
112
|
-
|
|
113
|
-
### Authoring `owomark-theme-xxx`
|
|
114
|
-
|
|
115
|
-
A theme package should:
|
|
116
|
-
|
|
117
|
-
- depend on `@owomark/view` and require consumers to import `@owomark/view/style.css` first
|
|
118
|
-
- publish token overrides and theme classes, not a copy of OwoMark's structural CSS
|
|
119
|
-
- target the public `--owo-*` token contract instead of private internal selectors
|
|
120
|
-
- treat `@owomark/view/style.css`, `@owomark/view/owomark.css`, `@owomark/view/mdx-components.css`, and exported theme helpers as the supported extension surface
|
|
121
|
-
|
|
122
|
-
Minimal example:
|
|
123
|
-
|
|
124
|
-
```css
|
|
125
|
-
.owo-theme-acme {
|
|
126
|
-
--owo-brand: #0f766e;
|
|
127
|
-
--owo-text: #123047;
|
|
128
|
-
--owo-surface: #f6fffb;
|
|
129
|
-
--owo-surface-raised: #ecfdf5;
|
|
130
|
-
--owo-border: #99f6e4;
|
|
131
|
-
--owo-border-strong: #5eead4;
|
|
132
|
-
}
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
Then pass the class to OwoMark:
|
|
136
|
-
|
|
137
|
-
```tsx
|
|
138
|
-
import { OwoMarkEditor } from '@owomark/react';
|
|
139
|
-
import '@owomark/view/style.css';
|
|
140
|
-
import 'owomark-theme-acme/style.css';
|
|
141
|
-
|
|
142
|
-
<OwoMarkEditor value={md} onChange={setMd} theme="owo-theme-acme" />;
|
|
143
|
-
```
|
|
18
|
+
## Not in this package
|
|
144
19
|
|
|
145
|
-
|
|
20
|
+
Static Markdown and MDX processing no longer lives in `@owomark/view`.
|
|
146
21
|
|
|
147
|
-
|
|
148
|
-
- Do not assume private DOM structure is stable beyond documented classes and token hooks.
|
|
149
|
-
- Prefer base tokens such as `--owo-brand`, `--owo-text`, and `--owo-border`; only override component-level tokens when the editor needs to diverge from the shared base theme.
|
|
22
|
+
Use `@owomark/processor` for:
|
|
150
23
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
-
|
|
154
|
-
-
|
|
155
|
-
- `--owo-syntax-*`: syntax-highlight tokens
|
|
156
|
-
- `--owo-toolbar-*`: toolbar tokens
|
|
157
|
-
- `--owo-panel-*`: panel/popover tokens
|
|
158
|
-
|
|
159
|
-
## MDX Support
|
|
160
|
-
|
|
161
|
-
When `enableMdx: true`, the processor delegates to `@mdx-js/mdx` `evaluate()` + `renderToStaticMarkup()`. The output is still an HTML string — callers see no difference.
|
|
162
|
-
|
|
163
|
-
### Built-in Components
|
|
164
|
-
|
|
165
|
-
Import the base styles for built-in components:
|
|
166
|
-
|
|
167
|
-
```ts
|
|
168
|
-
import '@owomark/view/mdx-components.css';
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
#### Theming
|
|
172
|
-
|
|
173
|
-
MDX component styles consume `--owo-*` base tokens with hardcoded fallbacks. This means:
|
|
174
|
-
|
|
175
|
-
- **Zero-config**: Components render correctly without any theme import (fallback colors are embedded).
|
|
176
|
-
- **With theme**: Import `@owomark/view/style.css` and components automatically adapt to light/dark mode.
|
|
177
|
-
- **Custom brand**: Set `--owo-brand` on a wrapper element to change the accent color across Callout (info), Steps, and Tabs simultaneously.
|
|
178
|
-
|
|
179
|
-
| Component | Props | Description |
|
|
180
|
-
|-----------|-------|-------------|
|
|
181
|
-
| `<Callout>` | `type?: 'info' \| 'warn' \| 'error' \| 'success'` | Styled callout box with icon |
|
|
182
|
-
| `<CodeDemo>` | `title?: string, language?: string, code: string` | Code demonstration block |
|
|
183
|
-
| `<Steps>` | (children: `<Step>`) | Numbered step-by-step guide with vertical line |
|
|
184
|
-
| `<Step>` | `title?: string` | Single step within `<Steps>` |
|
|
185
|
-
| `<Tabs>` | (children: `<Tab>`) | CSS-only tab switcher (no JS runtime) |
|
|
186
|
-
| `<Tab>` | `label?: string` | Single tab panel within `<Tabs>` |
|
|
187
|
-
| `<FileTree>` | (children: indented text) | Directory tree visualization |
|
|
188
|
-
| `<Kbd>` | (children: key name) | Keyboard key indicator |
|
|
189
|
-
|
|
190
|
-
```mdx
|
|
191
|
-
<Callout type="warn">
|
|
192
|
-
Watch out — this is a warning.
|
|
193
|
-
</Callout>
|
|
194
|
-
|
|
195
|
-
<Steps>
|
|
196
|
-
<Step title="Install">Run `npm install @owomark/view`</Step>
|
|
197
|
-
<Step title="Configure">Enable MDX in your processor options</Step>
|
|
198
|
-
</Steps>
|
|
199
|
-
|
|
200
|
-
<Tabs>
|
|
201
|
-
<Tab label="npm">`npm install @owomark/view`</Tab>
|
|
202
|
-
<Tab label="pnpm">`pnpm add @owomark/view`</Tab>
|
|
203
|
-
</Tabs>
|
|
204
|
-
|
|
205
|
-
<FileTree>
|
|
206
|
-
{`src/
|
|
207
|
-
components/
|
|
208
|
-
lib/
|
|
209
|
-
styles/
|
|
210
|
-
package.json`}
|
|
211
|
-
</FileTree>
|
|
212
|
-
|
|
213
|
-
Press <Kbd>Ctrl</Kbd> + <Kbd>S</Kbd> to save.
|
|
214
|
-
|
|
215
|
-
<CodeDemo title="Hello World" language="python" code="print('hello')" />
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
### Component Override
|
|
219
|
-
|
|
220
|
-
User-provided components override built-ins with the same name:
|
|
221
|
-
|
|
222
|
-
```ts
|
|
223
|
-
import { createElement } from 'react';
|
|
224
|
-
|
|
225
|
-
const MyCallout = ({ type, children }) =>
|
|
226
|
-
createElement('aside', { className: `my-callout-${type}` }, children);
|
|
227
|
-
|
|
228
|
-
const processor = createOwoMarkProcessor({
|
|
229
|
-
enableMdx: true,
|
|
230
|
-
mdxComponents: { Callout: MyCallout }, // Replaces built-in Callout
|
|
231
|
-
});
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
### Unregistered Components
|
|
235
|
-
|
|
236
|
-
Components used in MDX but not registered (built-in or user-provided) will:
|
|
237
|
-
|
|
238
|
-
1. Print a `[owomark-mdx] Unregistered MDX component: <Name>` warning
|
|
239
|
-
2. Render as `<div data-mdx-missing="Name">children</div>`
|
|
240
|
-
3. Not interrupt the build
|
|
241
|
-
|
|
242
|
-
### MDX + Side Annotations
|
|
243
|
-
|
|
244
|
-
The `{` and `=>` side annotation types conflict with MDX expression syntax. Use keyword forms instead:
|
|
245
|
-
|
|
246
|
-
| Symbol | Keyword | Example |
|
|
247
|
-
|--------|---------|---------|
|
|
248
|
-
| `{` | `left-brace` | `(>left-brace annotation text)` |
|
|
249
|
-
| `=>` | `fat-arrow` | `(>fat-arrow annotation text)` |
|
|
250
|
-
|
|
251
|
-
All other side annotation types (`}`, `]`, `->`, etc.) work unchanged in MDX mode.
|
|
252
|
-
|
|
253
|
-
### Peer Dependencies
|
|
254
|
-
|
|
255
|
-
MDX support requires these optional peer dependencies:
|
|
256
|
-
|
|
257
|
-
- `@mdx-js/mdx` ^3.0.0
|
|
258
|
-
- `react` ^18.0.0 or ^19.0.0
|
|
259
|
-
- `react-dom` ^18.0.0 or ^19.0.0
|
|
260
|
-
|
|
261
|
-
When `enableMdx` is false (default), these are not needed.
|
|
262
|
-
|
|
263
|
-
## Plugin Chain
|
|
264
|
-
|
|
265
|
-
The Gold Processor applies plugins in this order:
|
|
266
|
-
|
|
267
|
-
**Remark** (Markdown → mdast):
|
|
268
|
-
`remark-parse` → `remark-gfm` → `remark-math`* → `remark-directive` → `remark-mdx`† → `soft-breaks`‡ → `remark-side-annotation`* → extras
|
|
269
|
-
|
|
270
|
-
**Rehype** (hast → HTML):
|
|
271
|
-
`rehype-katex`* → `rehype-math-display-fix`* → `rehype-slug` → `rehype-pretty-code` → `rehype-side-annotation`* → extras → `rehype-stringify`
|
|
272
|
-
|
|
273
|
-
<small>* = gated by feature flag · † = production mode only · ‡ = when `preserveSoftLineBreaks` is false</small>
|
|
274
|
-
|
|
275
|
-
## Exports
|
|
276
|
-
|
|
277
|
-
### `@owomark/view/static` (SSR-safe)
|
|
278
|
-
|
|
279
|
-
```ts
|
|
280
|
-
import {
|
|
281
|
-
createOwoMarkProcessor,
|
|
282
|
-
getOwoMarkPlugins,
|
|
283
|
-
// Built-in MDX components
|
|
284
|
-
DEFAULT_MDX_COMPONENTS,
|
|
285
|
-
Callout, CodeDemo, Steps, Step, Tabs, Tab, FileTree, Kbd,
|
|
286
|
-
// Internal plugins (for advanced use)
|
|
287
|
-
remarkSideAnnotation,
|
|
288
|
-
rehypeSideAnnotation,
|
|
289
|
-
remarkConvertSoftBreaksToHardBreaks,
|
|
290
|
-
rehypeMathDisplayFix,
|
|
291
|
-
} from '@owomark/view/static';
|
|
292
|
-
```
|
|
24
|
+
- `createOwoMarkProcessor()`
|
|
25
|
+
- `getOwoMarkPlugins()`
|
|
26
|
+
- `DEFAULT_MDX_COMPONENTS`
|
|
27
|
+
- `@owomark/processor/mdx-components.css`
|
|
293
28
|
|
|
294
|
-
|
|
29
|
+
## CSS
|
|
295
30
|
|
|
296
|
-
|
|
31
|
+
`@owomark/view/style.css` now aggregates only browser-side view CSS and theme presets. MDX component CSS is intentionally excluded and must be imported from `@owomark/processor`.
|
|
@@ -11,10 +11,9 @@ var HEAVY_LARGE_THRESHOLD = 50;
|
|
|
11
11
|
var HEAVY_SMALL_HEIGHT = 60;
|
|
12
12
|
var HEAVY_MEDIUM_HEIGHT = 200;
|
|
13
13
|
var HEAVY_LARGE_HEIGHT = 500;
|
|
14
|
-
|
|
15
|
-
function estimateBlockHeight(block) {
|
|
14
|
+
function estimateBlockHeight(block, registry) {
|
|
16
15
|
const lineCount = block.endLine - block.startLine + 1;
|
|
17
|
-
if (
|
|
16
|
+
if (registry?.isHeavy(block.kind)) {
|
|
18
17
|
return estimateHeavyBlockHeight(lineCount);
|
|
19
18
|
}
|
|
20
19
|
if (block.kind === "code-fence") {
|
|
@@ -1,25 +1,44 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
var BLOCK_ID_ATTR = "data-block-id";
|
|
3
|
-
var SOURCE_START_ATTR = "data-source-line-start";
|
|
4
|
-
var SOURCE_END_ATTR = "data-source-line-end";
|
|
5
|
-
var HEIGHT_TRANSITION = "top 0.15s ease-out";
|
|
6
|
-
var TOTAL_HEIGHT_TRANSITION = "height 0.15s ease-out";
|
|
1
|
+
// src/dom/skeleton.ts
|
|
7
2
|
var SKELETON_GAP = 8;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
var SKELETON_LINE_HEIGHT = 14;
|
|
4
|
+
var SKELETON_PADDING = 24;
|
|
5
|
+
function createSkeletonHtml(options = {}) {
|
|
6
|
+
const { height, lines } = options;
|
|
7
|
+
const lineCount = lines ?? (height != null ? Math.max(1, Math.min(5, Math.round(Math.max(height - SKELETON_PADDING, 8) / (SKELETON_LINE_HEIGHT + SKELETON_GAP)))) : 3);
|
|
8
|
+
const heightStyle = height != null ? ` style="height:${height}px;min-height:${height}px"` : "";
|
|
9
|
+
const lineEls = [];
|
|
10
|
+
for (let i = 0; i < lineCount; i++) {
|
|
11
|
+
const isLast = i === lineCount - 1;
|
|
12
|
+
lineEls.push(`<div class="owo-mdx-skeleton owo-mdx-skeleton-line"${isLast ? ' style="width:60%"' : ""}></div>`);
|
|
13
|
+
}
|
|
14
|
+
return `<div class="owo-mdx-skeleton-block"${heightStyle} aria-hidden="true">${lineEls.join("")}</div>`;
|
|
11
15
|
}
|
|
16
|
+
var SKELETON_CSS = `
|
|
17
|
+
.owo-mdx-skeleton{background:linear-gradient(90deg,var(--owo-skeleton-base,#e5e7eb) 25%,var(--owo-skeleton-shine,#f3f4f6) 50%,var(--owo-skeleton-base,#e5e7eb) 75%);background-size:200% 100%;animation:owo-mdx-skeleton-shimmer 1.5s ease-in-out infinite;border-radius:4px}
|
|
18
|
+
@keyframes owo-mdx-skeleton-shimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}
|
|
19
|
+
.owo-mdx-skeleton-block{display:flex;flex-direction:column;gap:8px;padding:12px 0}
|
|
20
|
+
.owo-mdx-skeleton-line{height:14px}
|
|
21
|
+
.owo-mdx-skeleton-line:last-child{width:60%}
|
|
22
|
+
`.trim();
|
|
23
|
+
var STYLE_ID = "owo-mdx-skeleton-styles";
|
|
12
24
|
function ensureSkeletonStyles(doc) {
|
|
13
25
|
try {
|
|
14
|
-
if (doc.getElementById?.(
|
|
26
|
+
if (doc.getElementById?.(STYLE_ID)) return;
|
|
15
27
|
const style = doc.createElement("style");
|
|
16
|
-
style.id =
|
|
17
|
-
style.textContent =
|
|
28
|
+
style.id = STYLE_ID;
|
|
29
|
+
style.textContent = SKELETON_CSS;
|
|
18
30
|
const target = doc.head ?? doc.body;
|
|
19
31
|
target?.appendChild(style);
|
|
20
32
|
} catch {
|
|
21
33
|
}
|
|
22
34
|
}
|
|
35
|
+
|
|
36
|
+
// src/virtual/viewport-manager.ts
|
|
37
|
+
var BLOCK_ID_ATTR = "data-block-id";
|
|
38
|
+
var SOURCE_START_ATTR = "data-source-line-start";
|
|
39
|
+
var SOURCE_END_ATTR = "data-source-line-end";
|
|
40
|
+
var HEIGHT_TRANSITION = "top 0.15s ease-out";
|
|
41
|
+
var TOTAL_HEIGHT_TRANSITION = "height 0.15s ease-out";
|
|
23
42
|
var VirtualViewportManager = class {
|
|
24
43
|
root = null;
|
|
25
44
|
scrollContainer = null;
|
|
@@ -93,7 +112,7 @@ var VirtualViewportManager = class {
|
|
|
93
112
|
wrapper.style.left = "0";
|
|
94
113
|
wrapper.style.width = "100%";
|
|
95
114
|
wrapper.style.transition = HEIGHT_TRANSITION;
|
|
96
|
-
wrapper.innerHTML = createSkeletonHtml(layout.height);
|
|
115
|
+
wrapper.innerHTML = createSkeletonHtml({ height: layout.height });
|
|
97
116
|
this.contentLayer.appendChild(wrapper);
|
|
98
117
|
this.mounted.set(block.blockId, wrapper);
|
|
99
118
|
newlyMounted.add(block.blockId);
|
|
@@ -188,5 +207,7 @@ var VirtualViewportManager = class {
|
|
|
188
207
|
};
|
|
189
208
|
|
|
190
209
|
export {
|
|
210
|
+
createSkeletonHtml,
|
|
211
|
+
ensureSkeletonStyles,
|
|
191
212
|
VirtualViewportManager
|
|
192
213
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { OwoMarkCore, OwoMarkEditorInstance,
|
|
1
|
+
import { OwoMarkCore, OwoMarkEditorInstance, PreviewBlock } from '@owomark/core';
|
|
2
2
|
export { DocumentChangeCallback } from '@owomark/core';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import 'mdast';
|
|
6
|
-
import 'hast';
|
|
3
|
+
import { O as OwoMarkPreviewEngineOptions, a as OwoMarkPreviewEngine, P as PreviewRendererRegistry, b as PreviewTaskScheduler } from './types-DsL_4tUb.js';
|
|
4
|
+
export { c as PreviewBlockMetadata, d as PreviewBlockRenderer, e as PreviewCacheEntry, f as PreviewRenderContext, g as PreviewRenderPhase, h as PreviewRenderResult, i as PreviewRendererDefinition, j as PreviewRendererMode, k as PreviewStrategy, l as PreviewTaskPriority } from './types-DsL_4tUb.js';
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* Three-layer view engine for OwoMark.
|
|
@@ -49,77 +47,6 @@ declare function createOwoMarkView(core: OwoMarkCore, element: HTMLElement): Owo
|
|
|
49
47
|
*/
|
|
50
48
|
declare function createOwoMarkVanillaEditor(): OwoMarkEditorInstance;
|
|
51
49
|
|
|
52
|
-
type PreviewRenderPhase = 'idle' | 'rendering' | 'highlighting' | 'ready' | 'error';
|
|
53
|
-
type PreviewCacheEntry = {
|
|
54
|
-
blockId: string;
|
|
55
|
-
renderKey: string;
|
|
56
|
-
html: string;
|
|
57
|
-
highlighted: boolean;
|
|
58
|
-
themeKey: string;
|
|
59
|
-
updatedAt: number;
|
|
60
|
-
};
|
|
61
|
-
type PreviewRenderContext = {
|
|
62
|
-
version: number;
|
|
63
|
-
themeKey: string;
|
|
64
|
-
abortSignal?: AbortSignal;
|
|
65
|
-
/**
|
|
66
|
-
* Line offset to add to source-line attributes in the rendered HTML.
|
|
67
|
-
* When a block starts at line N in the document, the renderer processes
|
|
68
|
-
* its raw content starting from line 1; this offset (N - 1) must be
|
|
69
|
-
* added to `data-source-line-start/end` so scroll sync anchors map
|
|
70
|
-
* to the correct document lines.
|
|
71
|
-
*/
|
|
72
|
-
sourceLineOffset: number;
|
|
73
|
-
};
|
|
74
|
-
type PreviewRenderResult = {
|
|
75
|
-
kind: 'html';
|
|
76
|
-
html: string;
|
|
77
|
-
} | {
|
|
78
|
-
kind: 'dom';
|
|
79
|
-
mount: (container: HTMLElement) => void;
|
|
80
|
-
unmount?: () => void;
|
|
81
|
-
};
|
|
82
|
-
type PreviewRendererMode = 'html-worker-safe' | 'dom-main-thread';
|
|
83
|
-
type PreviewTaskPriority = 'realtime' | 'deferred';
|
|
84
|
-
type PreviewRendererDefinition = {
|
|
85
|
-
mode: PreviewRendererMode;
|
|
86
|
-
priority: PreviewTaskPriority;
|
|
87
|
-
render: PreviewBlockRenderer;
|
|
88
|
-
version: string;
|
|
89
|
-
};
|
|
90
|
-
type PreviewBlockRenderer = (block: PreviewBlock, context: PreviewRenderContext) => Promise<PreviewRenderResult> | PreviewRenderResult;
|
|
91
|
-
type PreviewRendererRegistry = {
|
|
92
|
-
get(kind: PreviewBlockKind): PreviewRendererDefinition | null;
|
|
93
|
-
register(kind: PreviewBlockKind, renderer: PreviewRendererDefinition): void;
|
|
94
|
-
unregister(kind: PreviewBlockKind): void;
|
|
95
|
-
};
|
|
96
|
-
type PreviewStrategy = 'incremental' | 'virtual';
|
|
97
|
-
type OwoMarkPreviewEngineOptions = {
|
|
98
|
-
strategy?: PreviewStrategy;
|
|
99
|
-
themeKey?: string;
|
|
100
|
-
registry?: PreviewRendererRegistry;
|
|
101
|
-
viewportFirst?: boolean;
|
|
102
|
-
/**
|
|
103
|
-
* External block renderer function. When provided, the engine uses this
|
|
104
|
-
* instead of the built-in default renderer. This allows the host to supply
|
|
105
|
-
* its own Markdown pipeline (unified, remark, rehype, Shiki, etc.) without
|
|
106
|
-
* the preview package bundling those heavy dependencies.
|
|
107
|
-
*/
|
|
108
|
-
renderBlock?: (block: PreviewBlock, context: PreviewRenderContext) => Promise<string>;
|
|
109
|
-
/**
|
|
110
|
-
* Called after every DOM mutation — including idle-backfilled and deferred
|
|
111
|
-
* block renders — not just after the synchronous update() return.
|
|
112
|
-
* Use for scroll sync or other post-DOM-update side effects.
|
|
113
|
-
*/
|
|
114
|
-
onContentUpdate?: () => void;
|
|
115
|
-
};
|
|
116
|
-
type OwoMarkPreviewEngine = {
|
|
117
|
-
mount(root: HTMLElement): void;
|
|
118
|
-
destroy(): void;
|
|
119
|
-
update(state: OwoMarkSharedState): void;
|
|
120
|
-
getRenderedVersion(): number;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
50
|
/**
|
|
124
51
|
* OwoMark Preview Engine factory.
|
|
125
52
|
*
|
|
@@ -149,6 +76,18 @@ declare function createRendererRegistry(): PreviewRendererRegistry;
|
|
|
149
76
|
*/
|
|
150
77
|
declare function renderBlockDefault(block: PreviewBlock): string;
|
|
151
78
|
|
|
79
|
+
declare function createPreviewTaskScheduler(options?: {
|
|
80
|
+
poolSize?: number;
|
|
81
|
+
onCrash?: () => void;
|
|
82
|
+
}): PreviewTaskScheduler;
|
|
83
|
+
|
|
84
|
+
type SkeletonOptions = {
|
|
85
|
+
height?: number;
|
|
86
|
+
lines?: number;
|
|
87
|
+
};
|
|
88
|
+
declare function createSkeletonHtml(options?: SkeletonOptions): string;
|
|
89
|
+
declare function ensureSkeletonStyles(doc: Document): void;
|
|
90
|
+
|
|
152
91
|
/**
|
|
153
92
|
* DOM patcher: blockId-driven incremental DOM updates.
|
|
154
93
|
*
|
|
@@ -225,4 +164,9 @@ declare class SideAnnotationPositioner {
|
|
|
225
164
|
destroy(): void;
|
|
226
165
|
}
|
|
227
166
|
|
|
228
|
-
|
|
167
|
+
declare const THEME_LIGHT_CLASS = "owo-theme-light";
|
|
168
|
+
declare const THEME_DARK_CLASS = "owo-theme-dark";
|
|
169
|
+
type OwoMarkThemeName = 'light' | 'dark' | string;
|
|
170
|
+
declare function getThemeClassName(theme: OwoMarkThemeName): string;
|
|
171
|
+
|
|
172
|
+
export { OwoMarkPreviewEngine, OwoMarkPreviewEngineOptions, type OwoMarkThemeName, type OwoMarkView, type OwoMarkViewEngine, PreviewDomPatcher, PreviewRendererRegistry, PreviewTaskScheduler, SideAnnotationPositioner, type SkeletonOptions, THEME_DARK_CLASS, THEME_LIGHT_CLASS, type ViewEngineOptions, createOwoMarkPreviewEngine, createOwoMarkVanillaEditor, createOwoMarkView, createPreviewTaskScheduler, createRendererRegistry, createSkeletonHtml, createViewEngine, ensureSkeletonStyles, getThemeClassName, renderBlockDefault };
|