@owomark/view 0.1.5 → 0.1.7
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 +1 -1
- package/dist/.build-manifest.json +76 -0
- package/dist/{chunk-F3LG7AML.js → chunk-656BO747.js} +35 -13
- package/dist/{chunk-Y72HQJQI.js → chunk-BPOZMVU7.js} +2 -3
- package/dist/index.d.ts +29 -80
- package/dist/index.js +681 -54
- 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/preview-render.worker.js +369 -0
- package/dist/types-D4TVpyP7.d.ts +103 -0
- package/package.json +2 -2
- package/src/style.css +2 -0
- package/src/theme/cards.css +50 -0
- package/src/theme/dark.css +8 -0
- package/src/theme/light.css +8 -0
- package/src/theme/owomark.css +28 -2
- package/src/theme/preview.css +15 -0
- package/src/theme/toolbar.css +104 -0
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ npm install @owomark/view
|
|
|
10
10
|
|
|
11
11
|
## Scope
|
|
12
12
|
|
|
13
|
-
- `createOwoMarkView()`
|
|
13
|
+
- `createOwoMarkView()` for interactive editing
|
|
14
14
|
- `createOwoMarkPreviewEngine()` and renderer registry APIs for preview DOM rendering
|
|
15
15
|
- `PreviewDomPatcher` and `SideAnnotationPositioner` for browser layout work
|
|
16
16
|
- `getThemeClassName()`, `light.css`, `dark.css`, `owomark.css`, `preview.css`, `slash-menu.css`, `side-annotation.css`
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"packageName": "@owomark/view",
|
|
4
|
+
"packagePath": "owomark/packages/owomark-view",
|
|
5
|
+
"packageFingerprint": "f70b7037c41905c87554e2d2a912d682e65e87ef960675bb32ee9a3776c4efd6",
|
|
6
|
+
"workspaceFingerprint": "29c91b05781cfd51984ade38b2b582f8dab1013dfaaf87ed5b2b6e9723653157",
|
|
7
|
+
"builtAt": "2026-04-22T18:27:59.683Z",
|
|
8
|
+
"builderVersion": "2026-04-22-industrialization-v1",
|
|
9
|
+
"inputFiles": [
|
|
10
|
+
"owomark/package.json",
|
|
11
|
+
"owomark/packages/owomark-view/package.json",
|
|
12
|
+
"owomark/packages/owomark-view/src/dom/patcher.ts",
|
|
13
|
+
"owomark/packages/owomark-view/src/dom/side-annotation-positioner.ts",
|
|
14
|
+
"owomark/packages/owomark-view/src/dom/skeleton.ts",
|
|
15
|
+
"owomark/packages/owomark-view/src/dom/slash-menu.ts",
|
|
16
|
+
"owomark/packages/owomark-view/src/editor.ts",
|
|
17
|
+
"owomark/packages/owomark-view/src/engine.ts",
|
|
18
|
+
"owomark/packages/owomark-view/src/index.ts",
|
|
19
|
+
"owomark/packages/owomark-view/src/internal/testing/vanilla-editor.ts",
|
|
20
|
+
"owomark/packages/owomark-view/src/internal/virtual/block-layout-map.ts",
|
|
21
|
+
"owomark/packages/owomark-view/src/internal/virtual/height-cache.ts",
|
|
22
|
+
"owomark/packages/owomark-view/src/internal/virtual/height-estimator.ts",
|
|
23
|
+
"owomark/packages/owomark-view/src/internal/virtual/viewport-manager.ts",
|
|
24
|
+
"owomark/packages/owomark-view/src/renderer/default-renderer.ts",
|
|
25
|
+
"owomark/packages/owomark-view/src/renderer/highlight-cache.ts",
|
|
26
|
+
"owomark/packages/owomark-view/src/renderer/registry.ts",
|
|
27
|
+
"owomark/packages/owomark-view/src/renderer/side-annotation-renderer.ts",
|
|
28
|
+
"owomark/packages/owomark-view/src/strategies/incremental.ts",
|
|
29
|
+
"owomark/packages/owomark-view/src/strategies/shared.ts",
|
|
30
|
+
"owomark/packages/owomark-view/src/strategies/virtual.ts",
|
|
31
|
+
"owomark/packages/owomark-view/src/style.css",
|
|
32
|
+
"owomark/packages/owomark-view/src/theme.ts",
|
|
33
|
+
"owomark/packages/owomark-view/src/theme/dark.css",
|
|
34
|
+
"owomark/packages/owomark-view/src/theme/light.css",
|
|
35
|
+
"owomark/packages/owomark-view/src/theme/owomark.css",
|
|
36
|
+
"owomark/packages/owomark-view/src/theme/preview.css",
|
|
37
|
+
"owomark/packages/owomark-view/src/theme/side-annotation.css",
|
|
38
|
+
"owomark/packages/owomark-view/src/theme/slash-menu.css",
|
|
39
|
+
"owomark/packages/owomark-view/src/theme/toolbar.css",
|
|
40
|
+
"owomark/packages/owomark-view/src/types.ts",
|
|
41
|
+
"owomark/packages/owomark-view/src/view-engine.ts",
|
|
42
|
+
"owomark/packages/owomark-view/src/virtual/block-layout-map.ts",
|
|
43
|
+
"owomark/packages/owomark-view/src/virtual/height-cache.ts",
|
|
44
|
+
"owomark/packages/owomark-view/src/virtual/height-estimator.ts",
|
|
45
|
+
"owomark/packages/owomark-view/src/virtual/offscreen-measurer.ts",
|
|
46
|
+
"owomark/packages/owomark-view/src/virtual/viewport-manager.ts",
|
|
47
|
+
"owomark/packages/owomark-view/src/worker/preview-render.worker.ts",
|
|
48
|
+
"owomark/packages/owomark-view/src/worker/preview-task-scheduler.ts",
|
|
49
|
+
"owomark/packages/owomark-view/src/worker/renderer-registry.ts",
|
|
50
|
+
"owomark/packages/owomark-view/src/worker/types.ts",
|
|
51
|
+
"owomark/packages/owomark-view/tsconfig.json",
|
|
52
|
+
"owomark/packages/owomark-view/tsup.config.ts",
|
|
53
|
+
"package-lock.json"
|
|
54
|
+
],
|
|
55
|
+
"artifactFiles": [
|
|
56
|
+
"dist/chunk-3CKPBCIP.js",
|
|
57
|
+
"dist/chunk-656BO747.js",
|
|
58
|
+
"dist/chunk-6LWPFJCB.js",
|
|
59
|
+
"dist/chunk-BPOZMVU7.js",
|
|
60
|
+
"dist/index.d.ts",
|
|
61
|
+
"dist/index.js",
|
|
62
|
+
"dist/internal/virtual/block-layout-map.d.ts",
|
|
63
|
+
"dist/internal/virtual/block-layout-map.js",
|
|
64
|
+
"dist/internal/virtual/height-cache.d.ts",
|
|
65
|
+
"dist/internal/virtual/height-cache.js",
|
|
66
|
+
"dist/internal/virtual/height-estimator.d.ts",
|
|
67
|
+
"dist/internal/virtual/height-estimator.js",
|
|
68
|
+
"dist/internal/virtual/viewport-manager.d.ts",
|
|
69
|
+
"dist/internal/virtual/viewport-manager.js",
|
|
70
|
+
"dist/preview-render.worker.js",
|
|
71
|
+
"dist/types-D4TVpyP7.d.ts"
|
|
72
|
+
],
|
|
73
|
+
"localDependencyFingerprints": {
|
|
74
|
+
"@owomark/core": "32024bd874bc287d8de92d6142487720dd3e31af4477e6f91a54b8e8db3aec4e"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -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;
|
|
@@ -89,11 +108,12 @@ var VirtualViewportManager = class {
|
|
|
89
108
|
wrapper.setAttribute(BLOCK_ID_ATTR, block.blockId);
|
|
90
109
|
wrapper.setAttribute(SOURCE_START_ATTR, String(block.startLine));
|
|
91
110
|
wrapper.setAttribute(SOURCE_END_ATTR, String(block.endLine));
|
|
111
|
+
wrapper.style.display = "flow-root";
|
|
92
112
|
wrapper.style.position = "absolute";
|
|
93
113
|
wrapper.style.left = "0";
|
|
94
114
|
wrapper.style.width = "100%";
|
|
95
115
|
wrapper.style.transition = HEIGHT_TRANSITION;
|
|
96
|
-
wrapper.innerHTML = createSkeletonHtml(layout.height);
|
|
116
|
+
wrapper.innerHTML = createSkeletonHtml({ height: layout.height });
|
|
97
117
|
this.contentLayer.appendChild(wrapper);
|
|
98
118
|
this.mounted.set(block.blockId, wrapper);
|
|
99
119
|
newlyMounted.add(block.blockId);
|
|
@@ -188,5 +208,7 @@ var VirtualViewportManager = class {
|
|
|
188
208
|
};
|
|
189
209
|
|
|
190
210
|
export {
|
|
211
|
+
createSkeletonHtml,
|
|
212
|
+
ensureSkeletonStyles,
|
|
191
213
|
VirtualViewportManager
|
|
192
214
|
};
|
|
@@ -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)) {
|
|
18
17
|
return estimateHeavyBlockHeight(lineCount);
|
|
19
18
|
}
|
|
20
19
|
if (block.kind === "code-fence") {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { OwoMarkCore,
|
|
1
|
+
import { OwoMarkCore, PreviewBlock, CardsFamilyAttributes, CARDS_FAMILY_CUSTOM_BLOCK_KEY } from '@owomark/core';
|
|
2
2
|
export { DocumentChangeCallback } from '@owomark/core';
|
|
3
|
+
import { O as OwoMarkPreviewEngineOptions, a as OwoMarkPreviewEngine, P as PreviewRendererRegistry, b as PreviewTaskScheduler } from './types-D4TVpyP7.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 PreviewRendererRegistryLookup, l as PreviewRendererTarget, m as PreviewStrategy, n as PreviewTaskPriority } from './types-D4TVpyP7.js';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Three-layer view engine for OwoMark.
|
|
@@ -25,9 +27,8 @@ declare function createViewEngine(options: ViewEngineOptions): OwoMarkViewEngine
|
|
|
25
27
|
/**
|
|
26
28
|
* View engine for OwoMark.
|
|
27
29
|
*
|
|
28
|
-
*
|
|
30
|
+
* Public API:
|
|
29
31
|
* - createOwoMarkView(core, element): Three-layer sovereign view engine
|
|
30
|
-
* - createOwoMarkVanillaEditor(): Legacy standalone editor (backward compat)
|
|
31
32
|
*/
|
|
32
33
|
|
|
33
34
|
type OwoMarkView = OwoMarkViewEngine;
|
|
@@ -39,82 +40,6 @@ type OwoMarkView = OwoMarkViewEngine;
|
|
|
39
40
|
* const view = createOwoMarkView(core, element);
|
|
40
41
|
*/
|
|
41
42
|
declare function createOwoMarkView(core: OwoMarkCore, element: HTMLElement): OwoMarkView;
|
|
42
|
-
/**
|
|
43
|
-
* Create a standalone editor (creates its own Core internally).
|
|
44
|
-
* Preserved for backward compatibility with vanilla adapter consumers.
|
|
45
|
-
*/
|
|
46
|
-
declare function createOwoMarkVanillaEditor(): OwoMarkEditorInstance;
|
|
47
|
-
|
|
48
|
-
type PreviewRenderPhase = 'idle' | 'rendering' | 'highlighting' | 'ready' | 'error';
|
|
49
|
-
type PreviewCacheEntry = {
|
|
50
|
-
blockId: string;
|
|
51
|
-
renderKey: string;
|
|
52
|
-
html: string;
|
|
53
|
-
highlighted: boolean;
|
|
54
|
-
themeKey: string;
|
|
55
|
-
updatedAt: number;
|
|
56
|
-
};
|
|
57
|
-
type PreviewRenderContext = {
|
|
58
|
-
version: number;
|
|
59
|
-
themeKey: string;
|
|
60
|
-
abortSignal?: AbortSignal;
|
|
61
|
-
/**
|
|
62
|
-
* Line offset to add to source-line attributes in the rendered HTML.
|
|
63
|
-
* When a block starts at line N in the document, the renderer processes
|
|
64
|
-
* its raw content starting from line 1; this offset (N - 1) must be
|
|
65
|
-
* added to `data-source-line-start/end` so scroll sync anchors map
|
|
66
|
-
* to the correct document lines.
|
|
67
|
-
*/
|
|
68
|
-
sourceLineOffset: number;
|
|
69
|
-
};
|
|
70
|
-
type PreviewRenderResult = {
|
|
71
|
-
kind: 'html';
|
|
72
|
-
html: string;
|
|
73
|
-
} | {
|
|
74
|
-
kind: 'dom';
|
|
75
|
-
mount: (container: HTMLElement) => void;
|
|
76
|
-
unmount?: () => void;
|
|
77
|
-
};
|
|
78
|
-
type PreviewRendererMode = 'html-worker-safe' | 'dom-main-thread';
|
|
79
|
-
type PreviewTaskPriority = 'realtime' | 'deferred';
|
|
80
|
-
type PreviewRendererDefinition = {
|
|
81
|
-
mode: PreviewRendererMode;
|
|
82
|
-
priority: PreviewTaskPriority;
|
|
83
|
-
render: PreviewBlockRenderer;
|
|
84
|
-
version: string;
|
|
85
|
-
};
|
|
86
|
-
type PreviewBlockRenderer = (block: PreviewBlock, context: PreviewRenderContext) => Promise<PreviewRenderResult> | PreviewRenderResult;
|
|
87
|
-
type PreviewRendererRegistry = {
|
|
88
|
-
get(kind: PreviewBlockKind): PreviewRendererDefinition | null;
|
|
89
|
-
register(kind: PreviewBlockKind, renderer: PreviewRendererDefinition): void;
|
|
90
|
-
unregister(kind: PreviewBlockKind): void;
|
|
91
|
-
};
|
|
92
|
-
type PreviewStrategy = 'incremental' | 'virtual';
|
|
93
|
-
type OwoMarkPreviewEngineOptions = {
|
|
94
|
-
strategy?: PreviewStrategy;
|
|
95
|
-
themeKey?: string;
|
|
96
|
-
registry?: PreviewRendererRegistry;
|
|
97
|
-
viewportFirst?: boolean;
|
|
98
|
-
/**
|
|
99
|
-
* External block renderer function. When provided, the engine uses this
|
|
100
|
-
* instead of the built-in default renderer. This allows the host to supply
|
|
101
|
-
* its own Markdown pipeline (unified, remark, rehype, Shiki, etc.) without
|
|
102
|
-
* the preview package bundling those heavy dependencies.
|
|
103
|
-
*/
|
|
104
|
-
renderBlock?: (block: PreviewBlock, context: PreviewRenderContext) => Promise<string>;
|
|
105
|
-
/**
|
|
106
|
-
* Called after every DOM mutation — including idle-backfilled and deferred
|
|
107
|
-
* block renders — not just after the synchronous update() return.
|
|
108
|
-
* Use for scroll sync or other post-DOM-update side effects.
|
|
109
|
-
*/
|
|
110
|
-
onContentUpdate?: () => void;
|
|
111
|
-
};
|
|
112
|
-
type OwoMarkPreviewEngine = {
|
|
113
|
-
mount(root: HTMLElement): void;
|
|
114
|
-
destroy(): void;
|
|
115
|
-
update(state: OwoMarkSharedState): void;
|
|
116
|
-
getRenderedVersion(): number;
|
|
117
|
-
};
|
|
118
43
|
|
|
119
44
|
/**
|
|
120
45
|
* OwoMark Preview Engine factory.
|
|
@@ -145,6 +70,30 @@ declare function createRendererRegistry(): PreviewRendererRegistry;
|
|
|
145
70
|
*/
|
|
146
71
|
declare function renderBlockDefault(block: PreviewBlock): string;
|
|
147
72
|
|
|
73
|
+
type CardsFamilyPreviewBlock = PreviewBlock & {
|
|
74
|
+
kind: 'custom';
|
|
75
|
+
attributes: CardsFamilyAttributes & {
|
|
76
|
+
customBlockKey: typeof CARDS_FAMILY_CUSTOM_BLOCK_KEY;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
declare function isCardsFamilyPreviewBlock(block: PreviewBlock): block is CardsFamilyPreviewBlock;
|
|
80
|
+
declare function renderCardsFamilyPreviewBlock(block: PreviewBlock): string;
|
|
81
|
+
|
|
82
|
+
declare function isSideAnnotationPreviewBlock(block: PreviewBlock): boolean;
|
|
83
|
+
declare function renderSideAnnotationPreviewBlock(block: PreviewBlock): string;
|
|
84
|
+
|
|
85
|
+
declare function createPreviewTaskScheduler(options?: {
|
|
86
|
+
poolSize?: number;
|
|
87
|
+
onCrash?: () => void;
|
|
88
|
+
}): PreviewTaskScheduler;
|
|
89
|
+
|
|
90
|
+
type SkeletonOptions = {
|
|
91
|
+
height?: number;
|
|
92
|
+
lines?: number;
|
|
93
|
+
};
|
|
94
|
+
declare function createSkeletonHtml(options?: SkeletonOptions): string;
|
|
95
|
+
declare function ensureSkeletonStyles(doc: Document): void;
|
|
96
|
+
|
|
148
97
|
/**
|
|
149
98
|
* DOM patcher: blockId-driven incremental DOM updates.
|
|
150
99
|
*
|
|
@@ -226,4 +175,4 @@ declare const THEME_DARK_CLASS = "owo-theme-dark";
|
|
|
226
175
|
type OwoMarkThemeName = 'light' | 'dark' | string;
|
|
227
176
|
declare function getThemeClassName(theme: OwoMarkThemeName): string;
|
|
228
177
|
|
|
229
|
-
export {
|
|
178
|
+
export { OwoMarkPreviewEngine, OwoMarkPreviewEngineOptions, type OwoMarkThemeName, type OwoMarkView, type OwoMarkViewEngine, PreviewDomPatcher, PreviewRendererRegistry, PreviewTaskScheduler, SideAnnotationPositioner, type SkeletonOptions, THEME_DARK_CLASS, THEME_LIGHT_CLASS, type ViewEngineOptions, createOwoMarkPreviewEngine, createOwoMarkView, createPreviewTaskScheduler, createRendererRegistry, createSkeletonHtml, createViewEngine, ensureSkeletonStyles, getThemeClassName, isCardsFamilyPreviewBlock, isSideAnnotationPreviewBlock, renderBlockDefault, renderCardsFamilyPreviewBlock, renderSideAnnotationPreviewBlock };
|