markloom 0.6.0 → 0.7.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.
Files changed (59) hide show
  1. package/collab.md +25 -13
  2. package/dist/ai/index.cjs +5 -4
  3. package/dist/ai/index.d.cts +5 -5
  4. package/dist/ai/index.d.ts +5 -5
  5. package/dist/ai/index.js +4 -3
  6. package/dist/{chunk-KYZJIOOL.js → chunk-4Q7PAR2T.js} +3671 -904
  7. package/dist/chunk-75EJ4ARB.cjs +642 -0
  8. package/dist/{chunk-U3JZDFL4.cjs → chunk-BMPCVT3B.cjs} +2 -34
  9. package/dist/{chunk-VSBIMMI7.js → chunk-EFYT2223.js} +3 -35
  10. package/dist/chunk-HXABDVLZ.cjs +297 -0
  11. package/dist/{chunk-I5VK4U7J.cjs → chunk-I2LDEVLA.cjs} +434 -80
  12. package/dist/{chunk-YBAT343I.js → chunk-MQLRZQZL.js} +263 -119
  13. package/dist/chunk-OVHASRID.cjs +4279 -0
  14. package/dist/chunk-PCSVBPOR.cjs +40 -0
  15. package/dist/{chunk-TB2OY3D4.js → chunk-PSAXWBNM.js} +413 -59
  16. package/dist/{chunk-QEVME6ZU.cjs → chunk-PZRWTLLB.cjs} +260 -161
  17. package/dist/chunk-QO7JEZDB.js +4279 -0
  18. package/dist/{chunk-EJSFZHGT.js → chunk-WSJUXPAG.js} +18 -2
  19. package/dist/{chunk-ACFYBYZJ.cjs → chunk-Y4IXQFWL.cjs} +4212 -1445
  20. package/dist/{chunk-CGYCJORO.js → chunk-YLVSMDIO.js} +220 -121
  21. package/dist/chunk-ZL6WT6OY.js +297 -0
  22. package/dist/{client-CLYq17SW.d.ts → client-BvvyHjhh.d.ts} +57 -7
  23. package/dist/{client-DAth8pPq.d.cts → client-Ciy7Fa_k.d.cts} +57 -7
  24. package/dist/collab/index.cjs +5 -4
  25. package/dist/collab/index.d.cts +13 -15
  26. package/dist/collab/index.d.ts +13 -15
  27. package/dist/collab/index.js +4 -3
  28. package/dist/{controller-BIOO_XKJ.d.cts → controller-CHznEhAR.d.cts} +186 -27
  29. package/dist/{controller-6AJ36G52.d.ts → controller-DLqI8_jm.d.ts} +186 -27
  30. package/dist/index.cjs +69 -7
  31. package/dist/index.d.cts +127 -8
  32. package/dist/index.d.ts +127 -8
  33. package/dist/index.js +80 -18
  34. package/dist/io/index.cjs +58 -59
  35. package/dist/io/index.d.cts +1 -1
  36. package/dist/io/index.d.ts +1 -1
  37. package/dist/io/index.js +15 -16
  38. package/dist/react/index.cjs +9 -8
  39. package/dist/react/index.d.cts +5 -5
  40. package/dist/react/index.d.ts +5 -5
  41. package/dist/react/index.js +8 -7
  42. package/dist/{rebase-batch-DlerAcFN.d.ts → rebase-batch-CSnv8FKp.d.ts} +1 -1
  43. package/dist/{rebase-batch-PjENQ742.d.cts → rebase-batch-DO1ygkx9.d.cts} +1 -1
  44. package/dist/{types-COUweEav.d.cts → types-BkHlmUFL.d.cts} +5 -1
  45. package/dist/{types-COUweEav.d.ts → types-BkHlmUFL.d.ts} +5 -1
  46. package/dist/{versions-9mG1epfB.d.cts → versions-DNFf8zVz.d.cts} +1 -1
  47. package/dist/{versions-Bubyo4pt.d.ts → versions-DOkOyh2J.d.ts} +1 -1
  48. package/dist/view/index.cjs +215 -17
  49. package/dist/view/index.d.cts +82 -9
  50. package/dist/view/index.d.ts +82 -9
  51. package/dist/view/index.js +212 -14
  52. package/dist/view/theme.css +349 -75
  53. package/dist/{suggest-Bk4zLzuv.d.ts → word-count-BPw9G2Bg.d.ts} +15 -5
  54. package/dist/{suggest-BkGGiPKA.d.cts → word-count-DNLn1h_t.d.cts} +15 -5
  55. package/package.json +11 -6
  56. package/dist/chunk-EADZKEU4.cjs +0 -498
  57. package/dist/chunk-SNFF6X45.js +0 -2347
  58. package/dist/chunk-TWD5T4YC.cjs +0 -2347
  59. package/dist/chunk-ZKQSQSSM.cjs +0 -24
@@ -1,16 +1,31 @@
1
- import { N as NodeView, l as Extension } from '../controller-6AJ36G52.js';
2
- export { e as AiWriteMode, f as AiWriteSession, m as AtomSelectCtx, B as BlockInputRule, n as BlockKind, o as BlockRenderCtx, p as BlockRenderer, C as CALLOUT_VARIANTS, q as CalloutVariant, D as DecorationFactory, r as DecorationHost, k as Editor, E as EditorOptions, I as InputResult, t as InputRuleCtx, u as Intent, K as KeymapCommand, v as KeymapCtx, w as KeymapResult, x as MentionCandidate, y as MentionHost, z as MentionMenu, F as MentionPopovers, G as MentionPopoversHost, H as MentionProfile, J as NodeViewCtx, P as PasteRule, R as RenderOpts, L as Resolved, S as SlashCommand, T as TextStylePatch, O as atomIsSelected, h as blockPlainText, Q as blockTransform, U as calloutVariantFromQuery, V as caret, W as chord, X as cycleCalloutVariant, Y as defaultBlockRenderers, Z as defaultBlockTag, _ as defaultMarkTag, $ as diffSpan, j as focusBlockId, a0 as indentItem, a1 as isAtom, a2 as isOpaque, a3 as leafText, a4 as lineBoundaryBack, a5 as lineBoundaryFwd, a6 as mapInput, a7 as mapPaste, a8 as mapPasteBlocks, a9 as marksAtCaret, aa as mergeTextStyleAttrs, ab as outdentItem, ac as projectDoc, ad as renderCode, ae as renderDoc, af as renderEmbed, ag as renderHr, ah as renderImage, ai as renderTable, aj as renderToHtml, ak as resolve, al as safeCssValue, am as serializeBlock, an as serializeSelection, ao as setAlign, ap as setCalloutVariant, aq as setTextStyle, s as startAiWrite, ar as textStyleCss, as as toggleMark, at as toggleMarkList, au as twitchChannel, av as wordBoundaryBack, aw as wordBoundaryFwd, ax as wrapList, ay as youtubeId } from '../controller-6AJ36G52.js';
3
- import { E as ElementNode, S as Selection, a as Position, N as Node } from '../types-COUweEav.js';
4
- import { S as Step, a as DocVersion } from '../versions-Bubyo4pt.js';
5
- import { C as CommentAuthor, c as CommentThread, b as CommentRenderState, T as TextMatch, e as SuggestAuthor, g as SuggestKind } from '../suggest-Bk4zLzuv.js';
1
+ import { N as NodeView, E as EditorOptions, k as Editor, l as Extension } from '../controller-DLqI8_jm.js';
2
+ export { e as AiWriteMode, f as AiWriteSession, m as AtomSelectCtx, n as Autofocus, B as BlockInputRule, o as BlockKind, p as BlockRenderCtx, q as BlockRenderer, r as BlockVnodeCache, C as CALLOUT_VARIANTS, t as CalloutVariant, D as DecorationFactory, u as DecorationHost, v as DiagramResolver, w as DiagramState, I as INLINE_PAIRS, x as InlineDeco, y as InlinePairHit, z as InputResult, F as InputRuleCtx, G as Intent, K as KeymapCommand, H as KeymapCtx, J as KeymapResult, L as MentionCandidate, O as MentionHost, P as MentionMenu, Q as MentionPopovers, R as MentionPopoversHost, S as MentionProfile, T as NodeViewCtx, U as PasteRule, V as RenderOpts, W as Resolved, X as SlashCommand, Y as TextStylePatch, Z as TypedLink, _ as TypedUrl, $ as atomIsSelected, a0 as autofocusSelection, h as blockPlainText, a1 as blockTransform, a2 as blockTransformRange, a3 as calloutVariantFromQuery, a4 as caret, a5 as chord, a6 as clearMarks, a7 as cycleCalloutVariant, a8 as defaultBlockRenderers, a9 as defaultBlockTag, aa as defaultMarkTag, ab as diffSpan, ac as expandToLink, j as focusBlockId, ad as indentItem, ae as inlinePairRule, af as isAtom, ag as isCellBlockKind, ah as isOpaque, ai as joinPrevList, aj as keepsApart, ak as leafBlockPath, al as leafText, am as lineBoundaryBack, an as lineBoundaryFwd, ao as mapInput, ap as mapPaste, aq as mapPasteBlocks, ar as markdownLinkRule, as as marksAtCaret, at as matchInlinePair, au as mergeTextStyleAttrs, av as nearestListPath, aw as outdentItem, ax as parseTypedLink, ay as parseTypedUrl, az as projectDoc, aA as renderCode, aB as renderDoc, aC as renderEmbed, aD as renderHr, aE as renderImage, aF as renderTable, aG as renderToHtml, aH as resolve, aI as safeCssValue, aJ as serializeBlock, aK as serializeSelection, aL as setAlign, aM as setCalloutVariant, aN as setHeadingDepth, aO as setListType, aP as setTextStyle, s as startAiWrite, aQ as tableAbove, aR as textStyleCss, aS as toggleMark, aT as toggleMarkList, aU as twitchChannel, aV as urlAutolink, aW as urlAutolinkRule, aX as wordBoundaryBack, aY as wordBoundaryFwd, aZ as wrapList, a_ as youtubeId } from '../controller-DLqI8_jm.js';
3
+ import { E as ElementNode, S as Selection, a as Position, N as Node, P as Path } from '../types-BkHlmUFL.js';
4
+ import { S as Step, a as DocVersion } from '../versions-DOkOyh2J.js';
5
+ import { C as CommentAuthor, c as CommentThread, b as CommentRenderState, T as TextMatch, e as SuggestAuthor, g as SuggestKind } from '../word-count-BPw9G2Bg.js';
6
6
  import 'preact';
7
- import '../client-CLYq17SW.js';
7
+ import '../client-BvvyHjhh.js';
8
+
9
+ declare function isSafeLinkUrl(url: string): boolean;
10
+ declare function linkTip(mark: {
11
+ attrs?: Record<string, unknown>;
12
+ }, url: string): string;
8
13
 
9
14
  declare function shikiCodeView(highlight: (code: string, lang?: string) => string, langs?: () => string[]): NodeView;
10
15
 
11
16
  declare function rootEl(root: HTMLElement): HTMLElement;
17
+ declare function nodeExtent(doc: ElementNode, nodePath?: Path): Selection | null;
12
18
  declare function docExtent(doc: ElementNode): Selection | null;
19
+ declare const SELECT_UNIT_TYPES: readonly ["code", "quote"];
20
+ type SelectUnitType = (typeof SELECT_UNIT_TYPES)[number];
21
+ declare function isSelectUnitType(type: string): boolean;
22
+ declare function isSelectUnit(n: Node): boolean;
23
+ /** 渐进全选可停层:内容 unit + 表结构(cell/table)。 */
24
+ declare function isProgressiveSelectUnit(n: Node): boolean;
25
+ declare function progressiveUnitPaths(doc: ElementNode, caretPath: Path): Path[];
26
+ declare function selectUnitPath(doc: ElementNode, caretPath: Path): Path | null;
13
27
  declare function selectionCovers(sel: Selection, extent: Selection): boolean;
28
+ declare function expandSelectAll(doc: ElementNode, sel: Selection | null): Selection | null;
14
29
  declare function pointToDom(root: HTMLElement, doc: ElementNode, pos: Position): {
15
30
  node: Node;
16
31
  offset: number;
@@ -20,8 +35,19 @@ declare function readSelection(root: HTMLElement, doc: ElementNode): Selection |
20
35
  declare function writeSelection(root: HTMLElement, doc: ElementNode, selection: Selection, opts?: {
21
36
  scroll?: boolean;
22
37
  }): void;
38
+ declare function invalidateStructure(keep?: HTMLElement | null): void;
23
39
  declare function elementChildren(el: HTMLElement): HTMLElement[];
24
40
 
41
+ /**
42
+ * opaque 块四周补可落光标真空 paragraph(纯函数,无 DOM)。
43
+ * Editor 初始化 / 派批后调用;md 序列化剥合成段(见 md trimSynthGapPara)。
44
+ */
45
+
46
+ declare function emptyGapPara(id: string): ElementNode;
47
+ declare function ensureGaps(doc: ElementNode, newId: () => string): ElementNode;
48
+ /** 与 ensureGaps 同判据,产 spliceChildren 批(自高位到低位)。 */
49
+ declare function gapSteps(after: ElementNode, newId: () => string): Step[];
50
+
25
51
  type PasteContext = {
26
52
  inCode: boolean;
27
53
  selCollapsed: boolean;
@@ -77,6 +103,11 @@ declare const tryImageUrl: PasteFormat;
77
103
  * 带文字的富图文返 null,走 blocks。
78
104
  */
79
105
  declare function soloImgSrcFromHtml(html: string | undefined): string | null;
106
+ /** 同上,连 alt 一起返(落成 `![alt](url)`,alt 不丢)。 */
107
+ declare function soloImgFromHtml(html: string | undefined): {
108
+ src: string;
109
+ alt: string;
110
+ } | null;
80
111
 
81
112
  declare const tryLinkMark: PasteFormat;
82
113
  /** trim 后无空白,http(s):// 起头。词法扫。 */
@@ -90,6 +121,24 @@ declare const tryMarkdown: PasteFormat;
90
121
 
91
122
  declare function resolvePaste(ctx: PasteContext, clip: PasteClipboard): PastePlan;
92
123
 
124
+ declare const ASYNC_MIN_BYTES: number;
125
+ interface OpenAsyncOptions extends EditorOptions {
126
+ /** 每片解析/渲染最多占主线程多久(毫秒),默认 8。 */
127
+ budgetMs?: number;
128
+ /** 铺 DOM 每片的目标耗时(默认 25):片内是一次同步 layout,比解析片贵,放宽它换更短的总时间。 */
129
+ layoutMs?: number;
130
+ /** 先给出的开头预览有多少个块,默认 200(一屏多)。 */
131
+ headBlocks?: number;
132
+ signal?: AbortSignal;
133
+ }
134
+ interface OpenedEditor {
135
+ /** 立刻可用(只读预览),载完后变可编辑。 */
136
+ editor: Editor;
137
+ /** 整篇载入并可编辑后 resolve,值是整篇文档。被 signal 取消则 reject AbortError。 */
138
+ loaded: Promise<ElementNode>;
139
+ }
140
+ declare function openEditorAsync(root: HTMLElement, md: string, opts?: OpenAsyncOptions): Promise<OpenedEditor>;
141
+
93
142
  declare function markloomKit(): Extension[];
94
143
 
95
144
  declare const boldMark: Extension;
@@ -102,6 +151,7 @@ declare const superscriptMark: Extension;
102
151
  declare const subscriptMark: Extension;
103
152
  declare const linkMark: Extension;
104
153
  declare const textStyleMark: Extension;
154
+ declare const clearFormatting: Extension;
105
155
  declare const markExtensions: Extension[];
106
156
 
107
157
  declare const tableBlock: Extension;
@@ -125,6 +175,8 @@ declare const suggest: Extension;
125
175
 
126
176
  declare const textAlign: Extension;
127
177
 
178
+ declare const typoraKeys: Extension;
179
+
128
180
  interface CommentPanelHost {
129
181
  root: HTMLElement;
130
182
  doc: () => ElementNode;
@@ -203,7 +255,9 @@ interface AskPopoverOpts {
203
255
  /** @deprecated 用 AskPopoverOpts;保留别名 */
204
256
  type AskLinkPopoverOpts = Pick<AskPopoverOpts, 'anchor' | 'placeholder' | 'defaultValue' | 'confirmLabel'>;
205
257
  declare function askInput(opts: AskInputOpts): Promise<string | null>;
206
- /** 无协议时补 https://;空串原样返回 */
258
+ /** 无协议时补 https://;空串原样返回。
259
+ * 危险 scheme(javascript:/data:/vbscript:)原样返回、不补 https——避免「钉成 https://javascript:…」被当链接。
260
+ */
207
261
  declare function normalizeLinkUrl(raw: string): string;
208
262
  declare function askPopover(opts: AskPopoverOpts): Promise<string | null>;
209
263
  /** 链接专用:补协议 + 单行 */
@@ -213,10 +267,23 @@ declare function closeAskInput(): void;
213
267
 
214
268
  declare const history: Extension;
215
269
 
270
+ /** 浮条上哪些控件显示,缺省全开(逐字节同旧行为)。关掉的不渲染;一个都不剩的块不出浮条。 */
271
+ interface DragHandleOptions {
272
+ /** 普通块的「+」(下方插入内容) */
273
+ add?: boolean;
274
+ /** 六点拖柄 */
275
+ grip?: boolean;
276
+ /** 标题块的「H1…H6」标记(拖拽 + 悬停格式) */
277
+ kind?: boolean;
278
+ /** 标题块的折叠箭头 */
279
+ fold?: boolean;
280
+ }
281
+
216
282
  declare const codeControls: Extension;
217
283
  declare const bubbleMenu: Extension;
218
284
  declare const slashMenu: Extension;
219
285
  declare const mentionMenu: Extension;
286
+ declare const createDragHandle: (opts?: DragHandleOptions) => Extension;
220
287
  declare const dragHandle: Extension;
221
288
  declare const decorationExtensions: Extension[];
222
289
 
@@ -243,7 +310,7 @@ declare class TocPanel {
243
310
  private onRedraw;
244
311
  private onScroll;
245
312
  private onResize;
246
- private refresh;
313
+ refresh(): void;
247
314
  /** 留白挂在滚动容器上(在全部子节点之后),避免夹在正文与页脚/prev-next 之间 */
248
315
  private padTarget;
249
316
  /**
@@ -269,6 +336,8 @@ type SearchBarHost = {
269
336
  dispatch: (steps: Step[], selectionAfter?: Selection) => void;
270
337
  readonly: () => boolean;
271
338
  focusMatch: (m: TextMatch) => void;
339
+ /** 文档里标出每一处命中(current = 当前那一个的下标,没有 = -1;空数组 = 清掉) */
340
+ setHits: (hits: TextMatch[], current: number) => void;
272
341
  };
273
342
  declare class SearchBar {
274
343
  private host;
@@ -346,4 +415,8 @@ declare class SuggestBar {
346
415
  private paint;
347
416
  }
348
417
 
349
- export { type AskInputOpts, type AskLinkPopoverOpts, type AskPopoverOpts, CommentPanel, type CommentPanelHost, Extension, NodeView, type PasteClipboard, type PasteContext, type PasteFormat, type PastePlan, SearchBar, type SearchBarHost, SuggestBar, type SuggestBarHost, TocPanel, type TocPanelHost, VersionsPanel, type VersionsPanelHost, askInput, askLinkPopover, askPopover, blockExtensions, boldMark, bubbleMenu, clipboardFromDataTransfer, closeAskInput, codeBlock, codeControls, codeMark, comments, decorationExtensions, docExtent, domToPoint, dragHandle, elementChildren, embedBlock, emoji, highlightMark, history, hrBlock, htmlToPlainText, imageBlock, imageFileFrom, inputRules, invisibleCharacters, isBareUrl, italicMark, linkMark, markExtensions, markloomKit, mentionMenu, normalizeLinkUrl, pointToDom, readSelection, resolvePaste, rootEl, selectionCovers, shikiCodeView, slashMenu, soloImgSrcFromHtml, strikeMark, subscriptMark, suggest, superscriptMark, tableBlock, textAlign, textStyleMark, tryEmbed, tryHtmlBlocks, tryImageFile, tryImageUrl, tryLinkMark, tryLiteral, tryMarkdown, typography, underlineMark, writeSelection };
418
+ type Locale = 'zh' | 'en';
419
+ declare function setLocale(l: Locale): void;
420
+ declare function getLocale(): Locale;
421
+
422
+ export { ASYNC_MIN_BYTES, type AskInputOpts, type AskLinkPopoverOpts, type AskPopoverOpts, CommentPanel, type CommentPanelHost, type DragHandleOptions, Editor, EditorOptions, Extension, type Locale, NodeView, type OpenAsyncOptions, type OpenedEditor, type PasteClipboard, type PasteContext, type PasteFormat, type PastePlan, SELECT_UNIT_TYPES, SearchBar, type SearchBarHost, type SelectUnitType, SuggestBar, type SuggestBarHost, TocPanel, type TocPanelHost, VersionsPanel, type VersionsPanelHost, askInput, askLinkPopover, askPopover, blockExtensions, boldMark, bubbleMenu, clearFormatting, clipboardFromDataTransfer, closeAskInput, codeBlock, codeControls, codeMark, comments, createDragHandle, decorationExtensions, docExtent, domToPoint, dragHandle, elementChildren, embedBlock, emoji, emptyGapPara, ensureGaps, expandSelectAll, gapSteps, getLocale, highlightMark, history, hrBlock, htmlToPlainText, imageBlock, imageFileFrom, inputRules, invalidateStructure, invisibleCharacters, isBareUrl, isProgressiveSelectUnit, isSafeLinkUrl, isSelectUnit, isSelectUnitType, italicMark, linkMark, linkTip, markExtensions, markloomKit, mentionMenu, nodeExtent, normalizeLinkUrl, openEditorAsync, pointToDom, progressiveUnitPaths, readSelection, resolvePaste, rootEl, selectUnitPath, selectionCovers, setLocale, shikiCodeView, slashMenu, soloImgFromHtml, soloImgSrcFromHtml, strikeMark, subscriptMark, suggest, superscriptMark, tableBlock, textAlign, textStyleMark, tryEmbed, tryHtmlBlocks, tryImageFile, tryImageUrl, tryLinkMark, tryLiteral, tryMarkdown, typography, typoraKeys, underlineMark, writeSelection };
@@ -2,6 +2,7 @@ import {
2
2
  CALLOUT_VARIANTS,
3
3
  CommentPanel,
4
4
  Editor,
5
+ INLINE_PAIRS,
5
6
  MentionMenu,
6
7
  MentionPopovers,
7
8
  SearchBar,
@@ -12,18 +13,23 @@ import {
12
13
  askLinkPopover,
13
14
  askPopover,
14
15
  atomIsSelected,
16
+ autofocusSelection,
15
17
  blockExtensions,
16
18
  blockTransform,
19
+ blockTransformRange,
17
20
  boldMark,
18
21
  bubbleMenu,
19
22
  calloutVariantFromQuery,
20
23
  caret,
21
24
  chord,
25
+ clearFormatting,
26
+ clearMarks,
22
27
  clipboardFromDataTransfer,
23
28
  closeAskInput,
24
29
  codeBlock,
25
30
  codeControls,
26
31
  codeMark,
32
+ createDragHandle,
27
33
  cycleCalloutVariant,
28
34
  decorationExtensions,
29
35
  defaultBlockRenderers,
@@ -32,6 +38,10 @@ import {
32
38
  diffSpan,
33
39
  dragHandle,
34
40
  embedBlock,
41
+ emptyGapPara,
42
+ ensureGaps,
43
+ expandToLink,
44
+ gapSteps,
35
45
  highlightMark,
36
46
  history,
37
47
  hrBlock,
@@ -39,25 +49,37 @@ import {
39
49
  imageBlock,
40
50
  imageFileFrom,
41
51
  indentItem,
52
+ inlinePairRule,
42
53
  inputRules,
43
54
  isAtom,
44
55
  isBareUrl,
56
+ isCellBlockKind,
45
57
  isOpaque,
58
+ isSafeLinkUrl,
46
59
  italicMark,
60
+ joinPrevList,
61
+ keepsApart,
62
+ leafBlockPath,
47
63
  leafText,
48
64
  lineBoundaryBack,
49
65
  lineBoundaryFwd,
50
66
  linkMark,
67
+ linkTip,
51
68
  mapInput,
52
69
  mapPaste,
53
70
  mapPasteBlocks,
54
71
  markExtensions,
72
+ markdownLinkRule,
55
73
  markloomKit,
56
74
  marksAtCaret,
75
+ matchInlinePair,
57
76
  mentionMenu,
58
77
  mergeTextStyleAttrs,
78
+ nearestListPath,
59
79
  normalizeLinkUrl,
60
80
  outdentItem,
81
+ parseTypedLink,
82
+ parseTypedUrl,
61
83
  projectDoc,
62
84
  renderCode,
63
85
  renderDoc,
@@ -68,18 +90,21 @@ import {
68
90
  renderToHtml,
69
91
  resolve,
70
92
  resolvePaste,
71
- safeCssValue,
72
93
  serializeBlock,
73
94
  serializeSelection,
74
95
  setAlign,
75
96
  setCalloutVariant,
97
+ setHeadingDepth,
98
+ setListType,
76
99
  setTextStyle,
77
100
  slashMenu,
101
+ soloImgFromHtml,
78
102
  soloImgSrcFromHtml,
79
103
  strikeMark,
80
104
  subscriptMark,
81
105
  suggest,
82
106
  superscriptMark,
107
+ tableAbove,
83
108
  tableBlock,
84
109
  textAlign,
85
110
  textStyleCss,
@@ -95,29 +120,53 @@ import {
95
120
  tryMarkdown,
96
121
  twitchChannel,
97
122
  underlineMark,
123
+ urlAutolink,
124
+ urlAutolinkRule,
98
125
  wordBoundaryBack,
99
126
  wordBoundaryFwd,
100
127
  wrapList,
101
128
  youtubeId
102
- } from "../chunk-KYZJIOOL.js";
103
- import "../chunk-CGYCJORO.js";
129
+ } from "../chunk-4Q7PAR2T.js";
130
+ import "../chunk-YLVSMDIO.js";
104
131
  import {
132
+ SELECT_UNIT_TYPES,
105
133
  blockPlainText,
106
134
  docExtent,
107
135
  domToPoint,
108
136
  elementChildren,
137
+ expandSelectAll,
109
138
  focusBlockId,
139
+ getLocale,
140
+ invalidateStructure,
141
+ isProgressiveSelectUnit,
142
+ isSelectUnit,
143
+ isSelectUnitType,
144
+ nodeExtent,
110
145
  pointToDom,
146
+ progressiveUnitPaths,
111
147
  readSelection,
112
148
  rootEl,
149
+ selectUnitPath,
113
150
  selectionCovers,
151
+ setLocale,
114
152
  startAiWrite,
153
+ t,
115
154
  writeSelection
116
- } from "../chunk-TB2OY3D4.js";
117
- import "../chunk-SNFF6X45.js";
118
- import "../chunk-YBAT343I.js";
119
- import "../chunk-VSBIMMI7.js";
120
- import "../chunk-EJSFZHGT.js";
155
+ } from "../chunk-PSAXWBNM.js";
156
+ import {
157
+ mdToDoc,
158
+ mdToDocAsync,
159
+ safeCssValue,
160
+ yieldToMain
161
+ } from "../chunk-QO7JEZDB.js";
162
+ import "../chunk-MQLRZQZL.js";
163
+ import "../chunk-EFYT2223.js";
164
+ import {
165
+ nodeAt
166
+ } from "../chunk-ZL6WT6OY.js";
167
+ import {
168
+ isText
169
+ } from "../chunk-WSJUXPAG.js";
121
170
 
122
171
  // src/view/shiki-code-view.ts
123
172
  import { h } from "preact";
@@ -133,9 +182,9 @@ function shikiCodeView(highlight, langs) {
133
182
  // 标记:此叶是多 text 节点拼接,selection 按全文 offset 走
134
183
  "dangerouslySetInnerHTML": { __html: anchorEmptyLines(highlight(ctx.text, lang)) }
135
184
  });
136
- const copy = h("button", { "key": "copy", "data-copy": "", "type": "button", "contentEditable": "false", "tabIndex": -1, "aria-label": "\u590D\u5236\u4EE3\u7801" });
137
- const langBtn = ctx.editable === false ? null : h("button", { "key": "lang", "data-code-lang": "", "type": "button", "contentEditable": "false", "tabIndex": -1 }, lang || "\u7EAF\u6587\u672C");
138
- return h("div", { "key": ctx.key, "data-block-id": ctx.node.id ?? "", "data-code-block": "" }, [langBtn, copy, leaf]);
185
+ const copy = h("button", { "key": "copy", "data-copy": "", "type": "button", "contentEditable": "false", "tabIndex": -1, "aria-label": t("copyCode") });
186
+ const langBtn = ctx.editable === false ? null : h("button", { "key": "lang", "data-code-lang": "", "type": "button", "contentEditable": "false", "tabIndex": -1 }, lang || t("plainText"));
187
+ return h("div", { "key": ctx.key, "data-block-id": ctx.node.id ?? "", "data-code-block": "", "spellcheck": "false" }, [langBtn, copy, leaf]);
139
188
  }
140
189
  };
141
190
  }
@@ -155,6 +204,63 @@ function anchorEmptyLines(html) {
155
204
  return pre.outerHTML;
156
205
  }
157
206
 
207
+ // src/view/open-async.ts
208
+ var ASYNC_MIN_BYTES = 48 * 1024;
209
+ async function openEditorAsync(root, md, opts = {}) {
210
+ const { budgetMs = 8, layoutMs = 25, headBlocks = 200, signal, ...eopts } = opts;
211
+ const source = eopts.source ?? md;
212
+ if (md.length < ASYNC_MIN_BYTES) {
213
+ const editor2 = new Editor(root, mdToDoc(md), { ...eopts, source });
214
+ return { editor: editor2, loaded: Promise.resolve(editor2.doc) };
215
+ }
216
+ let onHead;
217
+ const headP = new Promise((r) => {
218
+ onHead = r;
219
+ });
220
+ const fullP = mdToDocAsync(md, { budgetMs, headBlocks, onHead, signal });
221
+ const first = await Promise.race([headP, fullP]);
222
+ const wantEditable = eopts.editable !== false;
223
+ const editor = new Editor(root, first, { ...eopts, source, editable: false });
224
+ const loaded = (async () => {
225
+ try {
226
+ const doc = await fullP;
227
+ const total = doc.children.length;
228
+ let n = first.children.length;
229
+ let step = 128;
230
+ let perBlock = 0.05;
231
+ while (n < total) {
232
+ if (signal?.aborted)
233
+ throw Object.assign(new Error("openEditorAsync aborted"), { name: "AbortError" });
234
+ await yieldToMain();
235
+ const t0 = performance.now();
236
+ const take = Math.min(total - n, step);
237
+ n += take;
238
+ editor.replaceDoc({ ...doc, children: doc.children.slice(0, n) }, { notify: false, quiet: true });
239
+ const dt = performance.now() - t0;
240
+ perBlock = perBlock * 0.7 + dt / take * 0.3;
241
+ step = Math.max(128, Math.min(4096, Math.round(layoutMs / perBlock)));
242
+ }
243
+ editor.replaceDoc(doc, { notify: false });
244
+ if (wantEditable)
245
+ editor.setEditable(true);
246
+ if (eopts.autofocus != null && eopts.autofocus !== false && wantEditable) {
247
+ const sel = autofocusSelection(editor.doc, eopts.autofocus);
248
+ if (sel) {
249
+ root.focus({ preventScroll: true });
250
+ writeSelection(editor.root, editor.doc, sel);
251
+ }
252
+ }
253
+ return editor.doc;
254
+ } catch (e) {
255
+ editor.destroy();
256
+ throw e;
257
+ }
258
+ })();
259
+ loaded.catch(() => {
260
+ });
261
+ return { editor, loaded };
262
+ }
263
+
158
264
  // src/view/extensions/typography.ts
159
265
  var SUBS = [
160
266
  { trigger: "-", from: "--", to: "\u2014" },
@@ -171,10 +277,31 @@ var SUBS = [
171
277
  { trigger: "4", from: "1/4", to: "\xBC" },
172
278
  { trigger: "4", from: "3/4", to: "\xBE" }
173
279
  ];
280
+ function inLiteral(ctx) {
281
+ const leaf = nodeAt(ctx.doc, ctx.leafPath);
282
+ if (isText(leaf) && leaf.marks?.some((m) => m.name === "code" || m.name === "link"))
283
+ return true;
284
+ let ticks = 0;
285
+ for (const ch of ctx.marker) {
286
+ if (ch === "`")
287
+ ticks++;
288
+ }
289
+ if (ticks % 2 === 1)
290
+ return true;
291
+ let start = ctx.marker.length;
292
+ while (start > 0 && !/\s/.test(ctx.marker[start - 1]))
293
+ start--;
294
+ const word = ctx.marker.slice(start);
295
+ return word.includes("://") || word.startsWith("www.");
296
+ }
297
+ function isCjk(ch) {
298
+ const c = ch.codePointAt(0) ?? 0;
299
+ return c >= 11904 && c <= 40959 || c >= 44032 && c <= 55215 || c >= 63744 && c <= 64255 || c >= 65280 && c <= 65519 || c >= 131072 && c <= 195103;
300
+ }
174
301
  function subRule() {
175
302
  return {
176
303
  match: (ctx) => {
177
- if (ctx.block.type === "code")
304
+ if (ctx.block.type === "code" || inLiteral(ctx))
178
305
  return null;
179
306
  const combined = ctx.marker + ctx.trigger;
180
307
  for (const s of SUBS) {
@@ -184,6 +311,8 @@ function subRule() {
184
311
  const at = ctx.offset - eaten;
185
312
  if (at < 0)
186
313
  return null;
314
+ if (s.from === "--" && ctx.leafIdx === 0 && ctx.block.type === "paragraph" && [...combined].every((ch) => ch === "-"))
315
+ return null;
187
316
  const steps = [
188
317
  { kind: "deleteText", path: ctx.leafPath, offset: at, length: eaten },
189
318
  { kind: "insertText", path: ctx.leafPath, offset: at, text: s.to }
@@ -197,10 +326,22 @@ function subRule() {
197
326
  function quoteRule(quote, open, close) {
198
327
  return {
199
328
  match: (ctx) => {
200
- if (ctx.block.type === "code" || ctx.trigger !== quote)
329
+ if (ctx.block.type === "code" || ctx.trigger !== quote || inLiteral(ctx))
201
330
  return null;
202
331
  const prev = ctx.marker.slice(-1);
203
- const to = prev === "" || prev === " " || prev === "\n" || prev === " " || prev === "(" || prev === "[" || prev === "{" ? open : close;
332
+ let to;
333
+ if (prev === "" || prev === " " || prev === "\n" || prev === " " || prev === "(" || prev === "[" || prev === "{") {
334
+ to = open;
335
+ } else {
336
+ let depth = 0;
337
+ for (const ch of ctx.marker) {
338
+ if (ch === open)
339
+ depth++;
340
+ else if (ch === close && depth > 0)
341
+ depth--;
342
+ }
343
+ to = depth > 0 ? close : isCjk(prev) ? open : close;
344
+ }
204
345
  const steps = [{ kind: "insertText", path: ctx.leafPath, offset: ctx.offset, text: to }];
205
346
  return { steps, selection: caret(ctx.leafPath.concat(ctx.offset + to.length)) };
206
347
  }
@@ -295,12 +436,30 @@ var comments = {
295
436
  name: "comments",
296
437
  marks: [{ name: "comment", tag: "span" }]
297
438
  };
439
+
440
+ // src/view/extensions/typora-keys.ts
441
+ var level = (depth) => (ctx) => ctx.sel ? setHeadingDepth(ctx.doc, ctx.sel, depth) : null;
442
+ var typoraKeys = {
443
+ name: "typoraKeys",
444
+ keymap: {
445
+ "Mod-0": level(0),
446
+ "Mod-1": level(1),
447
+ "Mod-2": level(2),
448
+ "Mod-3": level(3),
449
+ "Mod-4": level(4),
450
+ "Mod-5": level(5),
451
+ "Mod-6": level(6)
452
+ }
453
+ };
298
454
  export {
455
+ ASYNC_MIN_BYTES,
299
456
  CALLOUT_VARIANTS,
300
457
  CommentPanel,
301
458
  Editor,
459
+ INLINE_PAIRS,
302
460
  MentionMenu,
303
461
  MentionPopovers,
462
+ SELECT_UNIT_TYPES,
304
463
  SearchBar,
305
464
  SuggestBar,
306
465
  TocPanel,
@@ -309,20 +468,25 @@ export {
309
468
  askLinkPopover,
310
469
  askPopover,
311
470
  atomIsSelected,
471
+ autofocusSelection,
312
472
  blockExtensions,
313
473
  blockPlainText,
314
474
  blockTransform,
475
+ blockTransformRange,
315
476
  boldMark,
316
477
  bubbleMenu,
317
478
  calloutVariantFromQuery,
318
479
  caret,
319
480
  chord,
481
+ clearFormatting,
482
+ clearMarks,
320
483
  clipboardFromDataTransfer,
321
484
  closeAskInput,
322
485
  codeBlock,
323
486
  codeControls,
324
487
  codeMark,
325
488
  comments,
489
+ createDragHandle,
326
490
  cycleCalloutVariant,
327
491
  decorationExtensions,
328
492
  defaultBlockRenderers,
@@ -335,7 +499,13 @@ export {
335
499
  elementChildren,
336
500
  embedBlock,
337
501
  emoji,
502
+ emptyGapPara,
503
+ ensureGaps,
504
+ expandSelectAll,
505
+ expandToLink,
338
506
  focusBlockId,
507
+ gapSteps,
508
+ getLocale,
339
509
  highlightMark,
340
510
  history,
341
511
  hrBlock,
@@ -343,27 +513,46 @@ export {
343
513
  imageBlock,
344
514
  imageFileFrom,
345
515
  indentItem,
516
+ inlinePairRule,
346
517
  inputRules,
518
+ invalidateStructure,
347
519
  invisibleCharacters,
348
520
  isAtom,
349
521
  isBareUrl,
522
+ isCellBlockKind,
350
523
  isOpaque,
524
+ isProgressiveSelectUnit,
525
+ isSafeLinkUrl,
526
+ isSelectUnit,
527
+ isSelectUnitType,
351
528
  italicMark,
529
+ joinPrevList,
530
+ keepsApart,
531
+ leafBlockPath,
352
532
  leafText,
353
533
  lineBoundaryBack,
354
534
  lineBoundaryFwd,
355
535
  linkMark,
536
+ linkTip,
356
537
  mapInput,
357
538
  mapPaste,
358
539
  mapPasteBlocks,
359
540
  markExtensions,
541
+ markdownLinkRule,
360
542
  markloomKit,
361
543
  marksAtCaret,
544
+ matchInlinePair,
362
545
  mentionMenu,
363
546
  mergeTextStyleAttrs,
547
+ nearestListPath,
548
+ nodeExtent,
364
549
  normalizeLinkUrl,
550
+ openEditorAsync,
365
551
  outdentItem,
552
+ parseTypedLink,
553
+ parseTypedUrl,
366
554
  pointToDom,
555
+ progressiveUnitPaths,
367
556
  projectDoc,
368
557
  readSelection,
369
558
  renderCode,
@@ -377,20 +566,26 @@ export {
377
566
  resolvePaste,
378
567
  rootEl,
379
568
  safeCssValue,
569
+ selectUnitPath,
380
570
  selectionCovers,
381
571
  serializeBlock,
382
572
  serializeSelection,
383
573
  setAlign,
384
574
  setCalloutVariant,
575
+ setHeadingDepth,
576
+ setListType,
577
+ setLocale,
385
578
  setTextStyle,
386
579
  shikiCodeView,
387
580
  slashMenu,
581
+ soloImgFromHtml,
388
582
  soloImgSrcFromHtml,
389
583
  startAiWrite,
390
584
  strikeMark,
391
585
  subscriptMark,
392
586
  suggest,
393
587
  superscriptMark,
588
+ tableAbove,
394
589
  tableBlock,
395
590
  textAlign,
396
591
  textStyleCss,
@@ -406,7 +601,10 @@ export {
406
601
  tryMarkdown,
407
602
  twitchChannel,
408
603
  typography,
604
+ typoraKeys,
409
605
  underlineMark,
606
+ urlAutolink,
607
+ urlAutolinkRule,
410
608
  wordBoundaryBack,
411
609
  wordBoundaryFwd,
412
610
  wrapList,