@owomark/core 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 +30 -10
- package/dist/.build-manifest.json +130 -0
- package/dist/browser.d.ts +66 -0
- package/dist/browser.js +396 -0
- package/dist/chunk-3KTK7CSS.js +82 -0
- package/dist/chunk-5JNL3LHV.js +215 -0
- package/dist/chunk-ASRCHEFF.js +0 -0
- package/dist/chunk-BKJCBEI7.js +397 -0
- package/dist/chunk-CJSBFWKS.js +549 -0
- package/dist/chunk-GA5EFGSZ.js +5820 -0
- package/dist/chunk-OOH46GIF.js +95 -0
- package/dist/chunk-ROJILHRQ.js +192 -0
- package/dist/chunk-WFPUIPWU.js +34 -0
- package/dist/chunk-WXVKSKP3.js +191 -0
- package/dist/chunk-YZYJIXGO.js +0 -0
- package/dist/editor-core-DbPhn6aI.d.ts +249 -0
- package/dist/index.d.ts +77 -86
- package/dist/index.js +161 -245
- package/dist/internal/dom-adapter.d.ts +37 -1
- package/dist/internal/dom-adapter.js +9 -2
- package/dist/public-zMo7BR9l.d.ts +469 -0
- package/dist/registry-C849sxCo.d.ts +74 -0
- package/dist/semantic/components/index.d.ts +9 -0
- package/dist/semantic/components/index.js +11 -0
- package/dist/semantic/editor/index.d.ts +9 -0
- package/dist/semantic/editor/index.js +13 -0
- package/dist/semantic/index.d.ts +7 -0
- package/dist/semantic/index.js +106 -0
- package/dist/semantic/runtime/index.d.ts +9 -0
- package/dist/semantic/runtime/index.js +13 -0
- package/dist/semantic/shared/index.d.ts +10 -0
- package/dist/semantic/shared/index.js +17 -0
- package/dist/semantic/syntax/index.d.ts +151 -0
- package/dist/semantic/syntax/index.js +63 -0
- package/dist/types-DMqYF6Zn.d.ts +83 -0
- package/package.json +29 -1
- package/dist/chunk-TRLKIMRD.js +0 -3227
- package/dist/dom-adapter-CTSJe5Uo.d.ts +0 -469
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createDescriptorRegistry,
|
|
3
|
+
requireDescriptor,
|
|
4
|
+
validateEditorEntryDescriptors
|
|
5
|
+
} from "./chunk-OOH46GIF.js";
|
|
6
|
+
|
|
7
|
+
// src/semantic/editor/index.ts
|
|
8
|
+
var BUILTIN_EDITOR_I18N = {
|
|
9
|
+
"command.bold.label": "Bold",
|
|
10
|
+
"command.italic.label": "Italic",
|
|
11
|
+
"command.link.label": "Link",
|
|
12
|
+
"command.codeFence.label": "Code Block",
|
|
13
|
+
"command.math.label": "Math Block",
|
|
14
|
+
"command.sideAnnotation.label": "Side Annotation",
|
|
15
|
+
"command.heading1.label": "Heading 1",
|
|
16
|
+
"command.heading2.label": "Heading 2",
|
|
17
|
+
"command.heading3.label": "Heading 3",
|
|
18
|
+
"command.blockquote.label": "Blockquote",
|
|
19
|
+
"command.unorderedList.label": "Bullet List",
|
|
20
|
+
"command.orderedList.label": "Numbered List",
|
|
21
|
+
"command.thematicBreak.label": "Divider",
|
|
22
|
+
"command.table.label": "Table",
|
|
23
|
+
"command.image.label": "Image",
|
|
24
|
+
"command.component.note.label": "Note",
|
|
25
|
+
"command.component.callout.label": "Callout",
|
|
26
|
+
"command.component.codeDemo.label": "Code Demo",
|
|
27
|
+
"command.component.details.label": "Details",
|
|
28
|
+
"command.component.steps.label": "Steps",
|
|
29
|
+
"command.component.tabs.label": "Tabs",
|
|
30
|
+
"command.component.linkCard.label": "Link Card",
|
|
31
|
+
"command.component.fileTree.label": "File Tree",
|
|
32
|
+
"command.category.basic": "basic",
|
|
33
|
+
"command.category.insert": "insert",
|
|
34
|
+
"command.category.format": "format",
|
|
35
|
+
"command.category.components": "components"
|
|
36
|
+
};
|
|
37
|
+
var builtinEditorEntryDescriptors = [
|
|
38
|
+
{ key: "builtin.editor.bold", family: "editor", commandId: "bold", entryKind: "format", labelKey: "command.bold.label", categoryKey: "command.category.format", keywords: ["bold"], slashMenu: false, toolbarEligible: false, shortcut: "Ctrl+B", specIds: ["docs/specs/editor.md"] },
|
|
39
|
+
{ key: "builtin.editor.italic", family: "editor", commandId: "italic", entryKind: "format", labelKey: "command.italic.label", categoryKey: "command.category.format", keywords: ["italic"], slashMenu: false, toolbarEligible: false, shortcut: "Ctrl+I", specIds: ["docs/specs/editor.md"] },
|
|
40
|
+
{ key: "builtin.editor.link", family: "editor", commandId: "link", entryKind: "insert", labelKey: "command.link.label", categoryKey: "command.category.insert", keywords: ["link"], slashMenu: true, toolbarEligible: false, priority: 50, shortcut: "Ctrl+K", specIds: ["docs/specs/editor.md"] },
|
|
41
|
+
{ key: "builtin.editor.code-fence", family: "editor", commandId: "code-fence", entryKind: "insert", labelKey: "command.codeFence.label", categoryKey: "command.category.insert", keywords: ["code", "fence", "block"], slashMenu: true, toolbarEligible: false, priority: 60, specIds: ["docs/specs/editor.md"] },
|
|
42
|
+
{ key: "builtin.editor.math", family: "editor", commandId: "math", entryKind: "insert", labelKey: "command.math.label", categoryKey: "command.category.insert", keywords: ["math", "equation", "formula", "latex", "katex"], slashMenu: true, toolbarEligible: false, priority: 65, specIds: ["docs/specs/editor.md"], featureFlag: "enableMath" },
|
|
43
|
+
{ key: "builtin.editor.side-annotation", family: "editor", commandId: "side-annotation", entryKind: "insert", labelKey: "command.sideAnnotation.label", categoryKey: "command.category.insert", keywords: ["side", "annotation", "brace", "margin", "note"], slashMenu: true, toolbarEligible: false, priority: 70, shortcut: "Ctrl+Shift+]", specIds: ["docs/specs/editor.md"], featureFlag: "enableSideAnnotation" },
|
|
44
|
+
{ key: "builtin.editor.heading-1", family: "editor", commandId: "heading-1", entryKind: "block", labelKey: "command.heading1.label", categoryKey: "command.category.basic", keywords: ["h1", "title"], slashMenu: true, toolbarEligible: false, priority: 10, specIds: ["docs/specs/editor.md"] },
|
|
45
|
+
{ key: "builtin.editor.heading-2", family: "editor", commandId: "heading-2", entryKind: "block", labelKey: "command.heading2.label", categoryKey: "command.category.basic", keywords: ["h2"], slashMenu: true, toolbarEligible: false, priority: 11, specIds: ["docs/specs/editor.md"] },
|
|
46
|
+
{ key: "builtin.editor.heading-3", family: "editor", commandId: "heading-3", entryKind: "block", labelKey: "command.heading3.label", categoryKey: "command.category.basic", keywords: ["h3"], slashMenu: true, toolbarEligible: false, priority: 12, specIds: ["docs/specs/editor.md"] },
|
|
47
|
+
{ key: "builtin.editor.blockquote", family: "editor", commandId: "blockquote", entryKind: "block", labelKey: "command.blockquote.label", categoryKey: "command.category.basic", keywords: ["quote"], slashMenu: true, toolbarEligible: false, priority: 20, specIds: ["docs/specs/editor.md"] },
|
|
48
|
+
{ key: "builtin.editor.unordered-list", family: "editor", commandId: "unordered-list", entryKind: "block", labelKey: "command.unorderedList.label", categoryKey: "command.category.basic", keywords: ["bullet", "list", "ul"], slashMenu: true, toolbarEligible: false, priority: 30, specIds: ["docs/specs/editor.md"] },
|
|
49
|
+
{ key: "builtin.editor.ordered-list", family: "editor", commandId: "ordered-list", entryKind: "block", labelKey: "command.orderedList.label", categoryKey: "command.category.basic", keywords: ["number", "list", "ol"], slashMenu: true, toolbarEligible: false, priority: 31, specIds: ["docs/specs/editor.md"] },
|
|
50
|
+
{ key: "builtin.editor.thematic-break", family: "editor", commandId: "thematic-break", entryKind: "block", labelKey: "command.thematicBreak.label", categoryKey: "command.category.basic", keywords: ["divider", "hr", "line", "separator"], slashMenu: true, toolbarEligible: false, priority: 40, specIds: ["docs/specs/editor.md"] },
|
|
51
|
+
{ key: "builtin.editor.insert-table", family: "editor", commandId: "insert-table", entryKind: "insert", labelKey: "command.table.label", categoryKey: "command.category.insert", keywords: ["table", "grid"], slashMenu: true, toolbarEligible: false, priority: 75, specIds: ["docs/specs/editor.md"] },
|
|
52
|
+
{ key: "builtin.editor.insert-image", family: "editor", commandId: "insert-image", entryKind: "insert", labelKey: "command.image.label", categoryKey: "command.category.insert", keywords: ["image", "picture", "photo", "img"], slashMenu: true, toolbarEligible: false, priority: 80, specIds: ["docs/specs/editor.md"] },
|
|
53
|
+
{ key: "builtin.editor.component-note", family: "editor", commandId: "component-note", entryKind: "component", labelKey: "command.component.note.label", categoryKey: "command.category.components", keywords: ["note", "tip", "info", "\u8BF4\u660E"], slashMenu: true, toolbarEligible: true, templateKey: "component-note", specIds: ["docs/specs/editor.md", "docs/specs/owomark-components-extension.md"], featureFlag: "enableComponents" },
|
|
54
|
+
{ key: "builtin.editor.component-callout", family: "editor", commandId: "component-callout", entryKind: "component", labelKey: "command.component.callout.label", categoryKey: "command.category.components", keywords: ["callout", "warning", "warn", "info"], slashMenu: true, toolbarEligible: true, templateKey: "component-callout", specIds: ["docs/specs/editor.md", "docs/specs/owomark-components-extension.md"], featureFlag: "enableComponents" },
|
|
55
|
+
{ key: "builtin.editor.component-code-demo", family: "editor", commandId: "component-code-demo", entryKind: "component", labelKey: "command.component.codeDemo.label", categoryKey: "command.category.components", keywords: ["code", "demo", "example", "snippet"], slashMenu: true, toolbarEligible: true, templateKey: "component-code-demo", specIds: ["docs/specs/editor.md", "docs/specs/owomark-components-extension.md"], featureFlag: "enableComponents" },
|
|
56
|
+
{ key: "builtin.editor.component-details", family: "editor", commandId: "component-details", entryKind: "component", labelKey: "command.component.details.label", categoryKey: "command.category.components", keywords: ["details", "accordion", "collapse"], slashMenu: true, toolbarEligible: true, templateKey: "component-details", specIds: ["docs/specs/editor.md", "docs/specs/owomark-components-extension.md"], featureFlag: "enableComponents" },
|
|
57
|
+
{ key: "builtin.editor.component-steps", family: "editor", commandId: "component-steps", entryKind: "component", labelKey: "command.component.steps.label", categoryKey: "command.category.components", keywords: ["steps", "process", "guide"], slashMenu: true, toolbarEligible: true, templateKey: "component-steps", specIds: ["docs/specs/editor.md", "docs/specs/owomark-components-extension.md"], featureFlag: "enableComponents" },
|
|
58
|
+
{ key: "builtin.editor.component-tabs", family: "editor", commandId: "component-tabs", entryKind: "component", labelKey: "command.component.tabs.label", categoryKey: "command.category.components", keywords: ["tabs", "tab", "switch"], slashMenu: true, toolbarEligible: true, templateKey: "component-tabs", specIds: ["docs/specs/editor.md", "docs/specs/owomark-components-extension.md"], featureFlag: "enableComponents" },
|
|
59
|
+
{ key: "builtin.editor.component-link-card", family: "editor", commandId: "component-link-card", entryKind: "component", labelKey: "command.component.linkCard.label", categoryKey: "command.category.components", keywords: ["link", "card", "reference"], slashMenu: true, toolbarEligible: true, templateKey: "component-link-card", specIds: ["docs/specs/editor.md", "docs/specs/owomark-components-extension.md"], featureFlag: "enableComponents" },
|
|
60
|
+
{ key: "builtin.editor.component-file-tree", family: "editor", commandId: "component-file-tree", entryKind: "component", labelKey: "command.component.fileTree.label", categoryKey: "command.category.components", keywords: ["file", "tree", "directory"], slashMenu: true, toolbarEligible: true, templateKey: "component-file-tree", specIds: ["docs/specs/editor.md", "docs/specs/owomark-components-extension.md"], featureFlag: "enableComponents" }
|
|
61
|
+
];
|
|
62
|
+
validateEditorEntryDescriptors(builtinEditorEntryDescriptors);
|
|
63
|
+
var editorEntryRegistry = createDescriptorRegistry(builtinEditorEntryDescriptors, "editor");
|
|
64
|
+
function getEditorEntryDescriptor(key) {
|
|
65
|
+
return requireDescriptor(editorEntryRegistry, key, "editor");
|
|
66
|
+
}
|
|
67
|
+
function getEditorEntryDescriptorByCommandId(commandId) {
|
|
68
|
+
return editorEntryRegistry.list().find((descriptor) => descriptor.commandId === commandId);
|
|
69
|
+
}
|
|
70
|
+
function resolveEditorEntryPresentation(descriptor) {
|
|
71
|
+
return {
|
|
72
|
+
label: BUILTIN_EDITOR_I18N[descriptor.labelKey] ?? descriptor.labelKey,
|
|
73
|
+
category: BUILTIN_EDITOR_I18N[descriptor.categoryKey] ?? descriptor.categoryKey
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
editorEntryRegistry,
|
|
79
|
+
getEditorEntryDescriptor,
|
|
80
|
+
getEditorEntryDescriptorByCommandId,
|
|
81
|
+
resolveEditorEntryPresentation
|
|
82
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import {
|
|
2
|
+
deriveSourceKey
|
|
3
|
+
} from "./chunk-WFPUIPWU.js";
|
|
4
|
+
|
|
5
|
+
// src/scroll/projection.ts
|
|
6
|
+
var projectionRevisionCounter = 0;
|
|
7
|
+
function projectToScrollSegments(previewBlocks) {
|
|
8
|
+
const segments = [];
|
|
9
|
+
for (const block of previewBlocks) {
|
|
10
|
+
const sourceKey = deriveSourceKey(block.startLine, block.endLine);
|
|
11
|
+
segments.push({
|
|
12
|
+
contentId: block.blockId,
|
|
13
|
+
sourceKey,
|
|
14
|
+
startLine: block.startLine,
|
|
15
|
+
endLine: block.endLine,
|
|
16
|
+
kind: block.kind
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return segments;
|
|
20
|
+
}
|
|
21
|
+
function buildScrollProjectionSnapshot(previewBlocks, documentRevision) {
|
|
22
|
+
projectionRevisionCounter += 1;
|
|
23
|
+
return {
|
|
24
|
+
documentRevision,
|
|
25
|
+
projectionRevision: projectionRevisionCounter,
|
|
26
|
+
segments: projectToScrollSegments(previewBlocks)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/scroll/progress-engine.ts
|
|
31
|
+
var DEFAULT_VIEWPORT_ANCHOR_RATIO = 0.35;
|
|
32
|
+
var EPSILON = 1e-9;
|
|
33
|
+
var BOTTOM_SNAP_THRESHOLD_PX = 1;
|
|
34
|
+
function buildProgressSegments(projection, geometry) {
|
|
35
|
+
if (projection.segments.length === 0) return [];
|
|
36
|
+
const geoIndex = /* @__PURE__ */ new Map();
|
|
37
|
+
for (const g of geometry.segments) {
|
|
38
|
+
geoIndex.set(g.sourceKey, g);
|
|
39
|
+
}
|
|
40
|
+
let totalWeight = 0;
|
|
41
|
+
const weights = [];
|
|
42
|
+
for (const seg of projection.segments) {
|
|
43
|
+
const w = Math.max(1, seg.endLine - seg.startLine + 1);
|
|
44
|
+
weights.push(w);
|
|
45
|
+
totalWeight += w;
|
|
46
|
+
}
|
|
47
|
+
const result = [];
|
|
48
|
+
let cum = 0;
|
|
49
|
+
for (let i = 0; i < projection.segments.length; i++) {
|
|
50
|
+
const seg = projection.segments[i];
|
|
51
|
+
const span = weights[i] / totalWeight;
|
|
52
|
+
const geo = geoIndex.get(seg.sourceKey);
|
|
53
|
+
const measured = geo?.measured ?? false;
|
|
54
|
+
result.push({
|
|
55
|
+
sourceKey: seg.sourceKey,
|
|
56
|
+
startLine: seg.startLine,
|
|
57
|
+
endLine: seg.endLine,
|
|
58
|
+
progressStart: cum,
|
|
59
|
+
progressEnd: cum + span,
|
|
60
|
+
top: geo?.top ?? 0,
|
|
61
|
+
bottom: geo?.bottom ?? 0,
|
|
62
|
+
height: geo?.height ?? 0,
|
|
63
|
+
measured
|
|
64
|
+
});
|
|
65
|
+
cum += span;
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
function resolveScrollPosition(projection, geometry, viewport, viewportAnchorRatio = DEFAULT_VIEWPORT_ANCHOR_RATIO) {
|
|
70
|
+
const segments = buildProgressSegments(projection, geometry);
|
|
71
|
+
if (segments.length === 0) return null;
|
|
72
|
+
const maxScroll = viewport.scrollHeight - viewport.clientHeight;
|
|
73
|
+
if (maxScroll <= 0) return null;
|
|
74
|
+
if (viewport.scrollTop <= 0) {
|
|
75
|
+
return {
|
|
76
|
+
documentRevision: projection.documentRevision,
|
|
77
|
+
projectionRevision: projection.projectionRevision,
|
|
78
|
+
sourceKey: segments[0].sourceKey,
|
|
79
|
+
blockProgress: 0
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (viewport.scrollTop >= maxScroll - BOTTOM_SNAP_THRESHOLD_PX) {
|
|
83
|
+
const last = segments[segments.length - 1];
|
|
84
|
+
return {
|
|
85
|
+
documentRevision: projection.documentRevision,
|
|
86
|
+
projectionRevision: projection.projectionRevision,
|
|
87
|
+
sourceKey: last.sourceKey,
|
|
88
|
+
blockProgress: 1
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const anchorY = viewport.scrollTop + viewport.clientHeight * viewportAnchorRatio;
|
|
92
|
+
const live = segments.filter((s) => s.measured);
|
|
93
|
+
if (live.length === 0) return null;
|
|
94
|
+
for (const seg of live) {
|
|
95
|
+
if (anchorY >= seg.top && anchorY < seg.bottom) {
|
|
96
|
+
const local = seg.height > 0 ? clamp01((anchorY - seg.top) / seg.height) : 0;
|
|
97
|
+
const globalProgress2 = seg.progressStart + local * (seg.progressEnd - seg.progressStart);
|
|
98
|
+
return positionFromProgress(projection, segments, globalProgress2);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
let before = null;
|
|
102
|
+
let after = null;
|
|
103
|
+
for (const seg of live) {
|
|
104
|
+
if (seg.bottom <= anchorY) before = seg;
|
|
105
|
+
else if (seg.top > anchorY && !after) {
|
|
106
|
+
after = seg;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
let globalProgress;
|
|
111
|
+
if (!before && !after) return null;
|
|
112
|
+
if (!before) {
|
|
113
|
+
globalProgress = after.top <= 0 ? after.progressStart : clamp01(anchorY / after.top) * after.progressStart;
|
|
114
|
+
} else if (!after) {
|
|
115
|
+
const remaining = viewport.scrollHeight - before.bottom;
|
|
116
|
+
const frac = remaining <= 0 ? 1 : clamp01((anchorY - before.bottom) / remaining);
|
|
117
|
+
globalProgress = before.progressEnd + frac * (1 - before.progressEnd);
|
|
118
|
+
} else {
|
|
119
|
+
const pixelGap = after.top - before.bottom;
|
|
120
|
+
const frac = pixelGap <= 0 ? 0 : clamp01((anchorY - before.bottom) / pixelGap);
|
|
121
|
+
globalProgress = before.progressEnd + frac * (after.progressStart - before.progressEnd);
|
|
122
|
+
}
|
|
123
|
+
return positionFromProgress(projection, segments, globalProgress);
|
|
124
|
+
}
|
|
125
|
+
function positionFromProgress(projection, segments, globalProgress) {
|
|
126
|
+
const p = clamp01(globalProgress);
|
|
127
|
+
for (const seg of segments) {
|
|
128
|
+
if (p >= seg.progressStart - EPSILON && p <= seg.progressEnd + EPSILON) {
|
|
129
|
+
const span2 = seg.progressEnd - seg.progressStart;
|
|
130
|
+
const blockProgress2 = span2 > EPSILON ? clamp01((p - seg.progressStart) / span2) : 0;
|
|
131
|
+
return {
|
|
132
|
+
documentRevision: projection.documentRevision,
|
|
133
|
+
projectionRevision: projection.projectionRevision,
|
|
134
|
+
sourceKey: seg.sourceKey,
|
|
135
|
+
blockProgress: blockProgress2
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
let closest = segments[0];
|
|
140
|
+
let minDist = Infinity;
|
|
141
|
+
for (const seg of segments) {
|
|
142
|
+
const mid = (seg.progressStart + seg.progressEnd) / 2;
|
|
143
|
+
const dist = Math.abs(p - mid);
|
|
144
|
+
if (dist < minDist) {
|
|
145
|
+
minDist = dist;
|
|
146
|
+
closest = seg;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const span = closest.progressEnd - closest.progressStart;
|
|
150
|
+
const blockProgress = span > EPSILON ? clamp01((p - closest.progressStart) / span) : 0;
|
|
151
|
+
return {
|
|
152
|
+
documentRevision: projection.documentRevision,
|
|
153
|
+
projectionRevision: projection.projectionRevision,
|
|
154
|
+
sourceKey: closest.sourceKey,
|
|
155
|
+
blockProgress
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function resolveScrollTopFromPosition(position, projection, geometry, viewportHeight, scrollHeight, viewportAnchorRatio = DEFAULT_VIEWPORT_ANCHOR_RATIO) {
|
|
159
|
+
const maxScroll = scrollHeight - viewportHeight;
|
|
160
|
+
if (maxScroll <= 0) return null;
|
|
161
|
+
const segments = buildProgressSegments(projection, geometry);
|
|
162
|
+
if (segments.length === 0) return null;
|
|
163
|
+
const targetSeg = segments.find((s) => s.sourceKey === position.sourceKey);
|
|
164
|
+
if (!targetSeg) return null;
|
|
165
|
+
const globalProgress = targetSeg.progressStart + clamp01(position.blockProgress) * (targetSeg.progressEnd - targetSeg.progressStart);
|
|
166
|
+
const p = clamp01(globalProgress);
|
|
167
|
+
if (p <= 0) return 0;
|
|
168
|
+
if (p >= 1 - EPSILON) return maxScroll;
|
|
169
|
+
const live = segments.filter((s) => s.measured);
|
|
170
|
+
if (live.length === 0) return null;
|
|
171
|
+
for (const seg of live) {
|
|
172
|
+
if (p >= seg.progressStart - EPSILON && p <= seg.progressEnd + EPSILON) {
|
|
173
|
+
const segSpan = seg.progressEnd - seg.progressStart;
|
|
174
|
+
const local = segSpan > EPSILON ? clamp01((p - seg.progressStart) / segSpan) : 0;
|
|
175
|
+
const targetY = seg.top + local * seg.height;
|
|
176
|
+
return clampRange(targetY - viewportHeight * viewportAnchorRatio, 0, maxScroll);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
let before = null;
|
|
180
|
+
let after = null;
|
|
181
|
+
for (const seg of live) {
|
|
182
|
+
if (seg.progressEnd <= p + EPSILON) before = seg;
|
|
183
|
+
else if (!after) after = seg;
|
|
184
|
+
}
|
|
185
|
+
if (before && after) {
|
|
186
|
+
const progressGap = after.progressStart - before.progressEnd;
|
|
187
|
+
const frac = progressGap > EPSILON ? clamp01((p - before.progressEnd) / progressGap) : 0;
|
|
188
|
+
const targetY = before.bottom + frac * (after.top - before.bottom);
|
|
189
|
+
return clampRange(targetY - viewportHeight * viewportAnchorRatio, 0, maxScroll);
|
|
190
|
+
}
|
|
191
|
+
if (before) {
|
|
192
|
+
return clampRange(before.bottom - viewportHeight * viewportAnchorRatio, 0, maxScroll);
|
|
193
|
+
}
|
|
194
|
+
if (after) {
|
|
195
|
+
const frac = after.progressStart > EPSILON ? clamp01(p / after.progressStart) : 0;
|
|
196
|
+
const targetY = frac * after.top;
|
|
197
|
+
return clampRange(targetY - viewportHeight * viewportAnchorRatio, 0, maxScroll);
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
function clamp01(v) {
|
|
202
|
+
return v < 0 ? 0 : v > 1 ? 1 : v;
|
|
203
|
+
}
|
|
204
|
+
function clampRange(v, min, max) {
|
|
205
|
+
return v < min ? min : v > max ? max : v;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export {
|
|
209
|
+
projectToScrollSegments,
|
|
210
|
+
buildScrollProjectionSnapshot,
|
|
211
|
+
DEFAULT_VIEWPORT_ANCHOR_RATIO,
|
|
212
|
+
buildProgressSegments,
|
|
213
|
+
resolveScrollPosition,
|
|
214
|
+
resolveScrollTopFromPosition
|
|
215
|
+
};
|
|
File without changes
|