@futaba-soft/mbox 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +80 -2
  3. package/dist/create-editor-BKTpQ8TK.js +2866 -0
  4. package/dist/editor/create-editor.d.ts +100 -0
  5. package/dist/editor/document-cache.d.ts +20 -0
  6. package/dist/editor/focused-line.d.ts +14 -0
  7. package/dist/editor/plugin.d.ts +191 -0
  8. package/dist/editor/test-context.d.ts +28 -0
  9. package/dist/gfm.d.ts +34 -0
  10. package/dist/gfm.js +1719 -0
  11. package/dist/hatena.d.ts +32 -0
  12. package/dist/hatena.js +856 -0
  13. package/dist/index.d.ts +34 -0
  14. package/dist/index.js +77 -0
  15. package/dist/plugin-DI0ubB-M.js +297 -0
  16. package/dist/plugins/bracket-pair-kit.d.ts +9 -0
  17. package/dist/plugins/code-block-kit.d.ts +77 -0
  18. package/dist/plugins/code-block-language-loader.d.ts +33 -0
  19. package/dist/plugins/gfm/active-lines.d.ts +11 -0
  20. package/dist/plugins/gfm/code-block.d.ts +28 -0
  21. package/dist/plugins/gfm/footnote.d.ts +17 -0
  22. package/dist/plugins/gfm/heading.d.ts +12 -0
  23. package/dist/plugins/gfm/image.d.ts +30 -0
  24. package/dist/plugins/gfm/index.d.ts +19 -0
  25. package/dist/plugins/gfm/inline-code.d.ts +4 -0
  26. package/dist/plugins/gfm/inline.d.ts +4 -0
  27. package/dist/plugins/gfm/link.d.ts +34 -0
  28. package/dist/plugins/gfm/list.d.ts +32 -0
  29. package/dist/plugins/gfm/math.d.ts +39 -0
  30. package/dist/plugins/gfm/parser-cache.d.ts +3 -0
  31. package/dist/plugins/gfm/parser.d.ts +355 -0
  32. package/dist/plugins/gfm/quote.d.ts +3 -0
  33. package/dist/plugins/gfm/table.d.ts +34 -0
  34. package/dist/plugins/gfm/thematic-break.d.ts +9 -0
  35. package/dist/plugins/hatena/blockquote.d.ts +12 -0
  36. package/dist/plugins/hatena/definition.d.ts +5 -0
  37. package/dist/plugins/hatena/footnote.d.ts +15 -0
  38. package/dist/plugins/hatena/heading.d.ts +8 -0
  39. package/dist/plugins/hatena/index.d.ts +12 -0
  40. package/dist/plugins/hatena/link.d.ts +16 -0
  41. package/dist/plugins/hatena/list.d.ts +24 -0
  42. package/dist/plugins/hatena/parser-cache.d.ts +5 -0
  43. package/dist/plugins/hatena/parser.d.ts +129 -0
  44. package/dist/plugins/hatena/pre.d.ts +3 -0
  45. package/dist/plugins/hatena/shared.d.ts +31 -0
  46. package/dist/plugins/hatena/super-pre.d.ts +23 -0
  47. package/dist/plugins/hatena/table.d.ts +12 -0
  48. package/dist/plugins/image-kit.d.ts +84 -0
  49. package/dist/plugins/inline-notation-kit.d.ts +39 -0
  50. package/dist/plugins/inline-style-kit.d.ts +38 -0
  51. package/dist/plugins/link-url.d.ts +1 -0
  52. package/dist/plugins/logical-lines.d.ts +18 -0
  53. package/dist/plugins/mbox/bracket.d.ts +4 -0
  54. package/dist/plugins/mbox/code-block.d.ts +32 -0
  55. package/dist/plugins/mbox/complete.d.ts +33 -0
  56. package/dist/plugins/mbox/default.d.ts +13 -0
  57. package/dist/plugins/mbox/emoji.d.ts +3 -0
  58. package/dist/plugins/mbox/footnote.d.ts +14 -0
  59. package/dist/plugins/mbox/heading.d.ts +10 -0
  60. package/dist/plugins/mbox/inline-code.d.ts +6 -0
  61. package/dist/plugins/mbox/inline-style.d.ts +7 -0
  62. package/dist/plugins/mbox/inline-visitor.d.ts +8 -0
  63. package/dist/plugins/mbox/list.d.ts +13 -0
  64. package/dist/plugins/mbox/markdown-image.d.ts +13 -0
  65. package/dist/plugins/mbox/page-link.d.ts +19 -0
  66. package/dist/plugins/mbox/paragraph.d.ts +6 -0
  67. package/dist/plugins/mbox/parser-cache.d.ts +3 -0
  68. package/dist/plugins/mbox/parser.d.ts +2 -0
  69. package/dist/plugins/mbox/quote.d.ts +5 -0
  70. package/dist/plugins/mbox/table.d.ts +13 -0
  71. package/dist/plugins/mbox/task-list.d.ts +19 -0
  72. package/dist/plugins/mbox/types.d.ts +172 -0
  73. package/dist/plugins/mbox/url-link.d.ts +3 -0
  74. package/dist/plugins/mbox/vertical-motion.d.ts +3 -0
  75. package/dist/plugins/pipe-table-row.d.ts +18 -0
  76. package/dist/plugins/scrapbox/bracket.d.ts +20 -0
  77. package/dist/plugins/scrapbox/code-block.d.ts +37 -0
  78. package/dist/plugins/scrapbox/command-line.d.ts +9 -0
  79. package/dist/plugins/scrapbox/complete.d.ts +58 -0
  80. package/dist/plugins/scrapbox/decoration.d.ts +16 -0
  81. package/dist/plugins/scrapbox/formula.d.ts +43 -0
  82. package/dist/plugins/scrapbox/image.d.ts +62 -0
  83. package/dist/plugins/scrapbox/indent.d.ts +40 -0
  84. package/dist/plugins/scrapbox/index.d.ts +41 -0
  85. package/dist/plugins/scrapbox/inline-code-highlight.d.ts +16 -0
  86. package/dist/plugins/scrapbox/inline-code.d.ts +7 -0
  87. package/dist/plugins/scrapbox/inline-scanner-kit.d.ts +66 -0
  88. package/dist/plugins/scrapbox/inline-walker.d.ts +2 -0
  89. package/dist/plugins/scrapbox/inline.d.ts +86 -0
  90. package/dist/plugins/scrapbox/link.d.ts +110 -0
  91. package/dist/plugins/scrapbox/list.d.ts +21 -0
  92. package/dist/plugins/scrapbox/parser-cache.d.ts +5 -0
  93. package/dist/plugins/scrapbox/parser.d.ts +65 -0
  94. package/dist/plugins/scrapbox/quote.d.ts +7 -0
  95. package/dist/plugins/scrapbox/table.d.ts +22 -0
  96. package/dist/plugins/scrapbox/title.d.ts +3 -0
  97. package/dist/plugins/scrapbox/visible-lines.d.ts +34 -0
  98. package/dist/plugins/table-kit.d.ts +142 -0
  99. package/dist/plugins/task-checkbox-kit.d.ts +18 -0
  100. package/dist/scrapbox.d.ts +42 -0
  101. package/dist/scrapbox.js +1903 -0
  102. package/dist/testing.d.ts +2 -0
  103. package/dist/testing.js +13 -0
  104. package/dist/themes/code-token-presentation.d.ts +6 -0
  105. package/dist/themes/default-presentation.d.ts +4 -0
  106. package/dist/themes/gfm-presentation.d.ts +15 -0
  107. package/dist/themes/hatena-presentation.d.ts +10 -0
  108. package/dist/themes/heading-presentation.d.ts +18 -0
  109. package/dist/themes/scrapbox-presentation.d.ts +10 -0
  110. package/docs/guide.md +297 -0
  111. package/package.json +121 -4
@@ -0,0 +1,172 @@
1
+ export interface MboxRange {
2
+ from: number;
3
+ to: number;
4
+ }
5
+ export interface MboxDocument {
6
+ blocks: MboxBlock[];
7
+ }
8
+ export type MboxBlock = MboxParagraphBlock | MboxHeadingBlock | MboxListItemBlock | MboxTaskListItemBlock | MboxQuoteBlock | MboxCodeBlock | MboxTableBlock | MboxFootnoteDefinitionBlock;
9
+ export type MboxInlineNode = MboxInlineTextNode | MboxInlineCodeNode | MboxInlineStyleNode | MboxWikiLinkNode | MboxIconNode | MboxFootnoteRefNode | MboxMarkdownLinkNode | MboxMarkdownImageNode | MboxAutoLinkNode | MboxEmojiNode;
10
+ export interface MboxBaseBlock {
11
+ type: string;
12
+ from: number;
13
+ to: number;
14
+ line: number;
15
+ }
16
+ export interface MboxParagraphBlock extends MboxBaseBlock {
17
+ type: "paragraph";
18
+ content: MboxRange;
19
+ inline: MboxInlineNode[];
20
+ }
21
+ export interface MboxHeadingBlock extends MboxBaseBlock {
22
+ type: "heading";
23
+ level: number;
24
+ marker: MboxRange;
25
+ syntax: MboxRange;
26
+ content: MboxRange;
27
+ inline: MboxInlineNode[];
28
+ }
29
+ export interface MboxListItemBlock extends MboxBaseBlock {
30
+ type: "listItem";
31
+ depth: number;
32
+ marker: MboxRange;
33
+ syntax: MboxRange;
34
+ content: MboxRange;
35
+ inline: MboxInlineNode[];
36
+ }
37
+ export interface MboxTaskListItemBlock extends MboxBaseBlock {
38
+ type: "taskListItem";
39
+ depth: number;
40
+ checked: boolean;
41
+ marker: MboxRange;
42
+ checkbox: MboxRange;
43
+ syntax: MboxRange;
44
+ content: MboxRange;
45
+ inline: MboxInlineNode[];
46
+ }
47
+ export interface MboxQuoteBlock extends MboxBaseBlock {
48
+ type: "quote";
49
+ marker: MboxRange;
50
+ syntax: MboxRange;
51
+ content: MboxRange;
52
+ inline: MboxInlineNode[];
53
+ }
54
+ export interface MboxCodeBlock extends MboxBaseBlock {
55
+ type: "codeBlock";
56
+ openingFence: MboxRange;
57
+ info: MboxRange;
58
+ infoValue: string;
59
+ content: MboxRange;
60
+ closingFence: MboxRange | null;
61
+ value: string;
62
+ }
63
+ export interface MboxTableCell extends MboxRange {
64
+ content: MboxRange;
65
+ value: string;
66
+ }
67
+ export interface MboxTableRow extends MboxRange {
68
+ cells: MboxTableCell[];
69
+ }
70
+ export interface MboxTableBlock extends MboxBaseBlock {
71
+ type: "table";
72
+ header: MboxTableRow;
73
+ delimiter: MboxTableRow;
74
+ rows: MboxTableRow[];
75
+ }
76
+ export interface MboxFootnoteDefinitionBlock extends MboxBaseBlock {
77
+ type: "footnoteDefinition";
78
+ label: string;
79
+ identifier: string;
80
+ marker: MboxRange;
81
+ syntax: MboxRange;
82
+ content: MboxRange;
83
+ value: string;
84
+ }
85
+ export interface MboxInlineTextNode extends MboxRange {
86
+ type: "text";
87
+ value: string;
88
+ }
89
+ export interface MboxInlineCodeNode extends MboxRange {
90
+ type: "inlineCode";
91
+ openingMarker: MboxRange;
92
+ closingMarker: MboxRange;
93
+ content: MboxRange;
94
+ value: string;
95
+ }
96
+ export interface MboxInlineStyleNode extends MboxRange {
97
+ type: "emphasis" | "strong" | "strikethrough";
98
+ openingMarker: MboxRange;
99
+ closingMarker: MboxRange;
100
+ content: MboxRange;
101
+ value: string;
102
+ }
103
+ export interface MboxWikiLinkNode extends MboxRange {
104
+ type: "wikiLink";
105
+ marker: MboxRange;
106
+ target: MboxRange;
107
+ value: string;
108
+ }
109
+ export interface MboxIconNode extends MboxRange {
110
+ type: "icon";
111
+ marker: MboxRange;
112
+ name: MboxRange;
113
+ value: string;
114
+ }
115
+ export interface MboxFootnoteRefNode extends MboxRange {
116
+ type: "footnoteRef";
117
+ marker: MboxRange;
118
+ label: MboxRange;
119
+ identifier: string;
120
+ value: string;
121
+ }
122
+ export interface MboxMarkdownLinkNode extends MboxRange {
123
+ type: "markdownLink";
124
+ label: MboxRange;
125
+ url: MboxRange;
126
+ markers: {
127
+ labelOpen: MboxRange;
128
+ labelClose: MboxRange;
129
+ urlOpen: MboxRange;
130
+ urlClose: MboxRange;
131
+ };
132
+ labelValue: string;
133
+ urlValue: string;
134
+ }
135
+ export interface MboxMarkdownImageNode extends MboxRange {
136
+ type: "markdownImage";
137
+ alt: MboxRange;
138
+ url: MboxRange;
139
+ markers: {
140
+ image: MboxRange;
141
+ labelOpen: MboxRange;
142
+ labelClose: MboxRange;
143
+ urlOpen: MboxRange;
144
+ urlClose: MboxRange;
145
+ };
146
+ altValue: string;
147
+ urlValue: string;
148
+ }
149
+ export interface MboxAutoLinkNode extends MboxRange {
150
+ type: "autoLink";
151
+ url: MboxRange;
152
+ urlValue: string;
153
+ }
154
+ export interface MboxEmojiNode extends MboxRange {
155
+ type: "emoji";
156
+ marker: MboxRange;
157
+ name: MboxRange;
158
+ value: string;
159
+ }
160
+ /** @internal */
161
+ export interface MboxBlockParserContext {
162
+ input: string;
163
+ lines: LogicalLine[];
164
+ lineIndex: number;
165
+ }
166
+ /** @internal */
167
+ export interface MboxBlockParseResult {
168
+ block: MboxBlock;
169
+ nextLineIndex: number;
170
+ }
171
+ export type MboxBlockParser = (context: MboxBlockParserContext) => MboxBlockParseResult | null;
172
+ import type { LogicalLine } from "../logical-lines.js";
@@ -0,0 +1,3 @@
1
+ import type { MboxPlugin } from "../../editor/plugin.js";
2
+ export declare const urlLinkClassName = "mbox-url-link";
3
+ export declare function urlLinkPlugin(): MboxPlugin;
@@ -0,0 +1,3 @@
1
+ import type { EditorView } from "@codemirror/view";
2
+ import type { MboxBlock } from "./types.js";
3
+ export declare function moveCursorToPreviousBlockStart(view: EditorView, blockTypes: MboxBlock["type"][]): boolean;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Finds pipe-table separators at the offsets understood by JavaScript string
3
+ * slicing and CodeMirror decorations: UTF-16 code units. This small scanner
4
+ * exists because `[...text]` produces code points, so its `index` values drift
5
+ * after every non-BMP character when used as UTF-16 offsets. That does not
6
+ * merely choose a wrong cell boundary: it can leave a separator pipe in the
7
+ * cell value or split a surrogate pair while slicing/decorating the row.
8
+ *
9
+ * Only pipe positions are shared. Each notation still decides its own cell
10
+ * boundaries and leading/trailing-pipe policy; Hatena also owns its leading
11
+ * `*` header marker. Keeping those rules in their namespaces prevents GFM
12
+ * grammar from leaking into mbox or Hatena. The GFM, mbox, and Hatena parsers
13
+ * use this helper. Scrapbox tables are tab-separated, so they intentionally do
14
+ * not.
15
+ *
16
+ * This is internal parser infrastructure, not part of the public API.
17
+ */
18
+ export declare function findPipeOffsets(text: string): number[];
@@ -0,0 +1,20 @@
1
+ import type { EditorState, TransactionSpec } from "@codemirror/state";
2
+ import type { MboxPlugin } from "../../editor/plugin.js";
3
+ /**
4
+ * A transaction that surrounds each selection range with `[` … `]` and leaves
5
+ * the caret/selection inside. For an empty selection it inserts `[]` with the
6
+ * caret between the brackets (the Scrapbox link/icon entry point); for a
7
+ * non-empty selection it wraps the selected text and keeps it selected.
8
+ *
9
+ * The document text stays the single source of truth — this is a plain edit, so
10
+ * undo/redo and every decoration plugin see the closing bracket as real text.
11
+ */
12
+ export declare function insertScrapboxBracketPair(state: EditorState): TransactionSpec;
13
+ /**
14
+ * Auto-close the Scrapbox `[` bracket: typing `[` inserts the matching `]` and
15
+ * drops the caret between them, so the user starts an empty `[]` ready for a
16
+ * page link, icon or (later) an autocomplete popup. A non-empty selection is
17
+ * wrapped instead. Everything else — IME composition, paste, other keys — falls
18
+ * through untouched.
19
+ */
20
+ export declare function scrapboxBracketPlugin(): MboxPlugin;
@@ -0,0 +1,37 @@
1
+ import type { MboxPlugin } from "../../editor/plugin.js";
2
+ import { CodeBlockKitCopyButtonWidget as ScrapboxCodeBlockCopyButtonWidget } from "../code-block-kit.js";
3
+ import type { ScrapboxDocument } from "./parser.js";
4
+ export { ScrapboxCodeBlockCopyButtonWidget };
5
+ export declare const scrapboxCodeBlockClassName = "mbox-scrapbox-code-block";
6
+ export declare const scrapboxCodeBlockOpenerClassName = "mbox-scrapbox-code-block-opener";
7
+ export declare const scrapboxCodeBlockBodyClassName = "mbox-scrapbox-code-block-body";
8
+ export declare const scrapboxCodeBlockKeywordClassName = "mbox-scrapbox-code-block-keyword";
9
+ export declare const scrapboxCodeBlockFileNameClassName = "mbox-scrapbox-code-block-filename";
10
+ export declare const scrapboxCodeBlockLanguageLabelClassName = "mbox-scrapbox-code-block-language-label";
11
+ export declare const scrapboxCodeBlockCopyButtonClassName = "mbox-scrapbox-code-block-copy-button";
12
+ export declare const scrapboxCodeBlockTokenClassName = "mbox-scrapbox-code-block-token";
13
+ export declare const scrapboxCodeBlockClassNames: {
14
+ codeBlock: string;
15
+ opener: string;
16
+ body: string;
17
+ keyword: string;
18
+ fileName: string;
19
+ languageLabel: string;
20
+ copyButton: string;
21
+ token: string;
22
+ };
23
+ /** File names eligible for code highlighting. Formula blocks deliberately do
24
+ * not reach this boundary: the dynamic loader must not try to resolve TeX. */
25
+ export declare function scrapboxCodeBlockHighlightFileNames(document: ScrapboxDocument): string[];
26
+ export declare function scrapboxCodeBlockPlugin(): MboxPlugin;
27
+ export interface ScrapboxCodeBlockHighlightPluginOptions {
28
+ /** Restrict dynamic loading to these language names/aliases/extensions, or
29
+ * pass `"all"` to allow any language in the full @codemirror/language-data
30
+ * registry (still only loaded, one dynamic import at a time, for a
31
+ * language actually used in the document). Omit entirely to skip the
32
+ * dynamic loader altogether and stay on the zero-dependency JS/TS sync
33
+ * default. */
34
+ languages?: readonly string[] | "all";
35
+ onLoadError?: (languageId: string, error: unknown) => void;
36
+ }
37
+ export declare function scrapboxCodeBlockHighlightPlugin(options?: ScrapboxCodeBlockHighlightPluginOptions): MboxPlugin;
@@ -0,0 +1,9 @@
1
+ import { type MboxPlugin } from "../../editor/plugin.js";
2
+ export declare const scrapboxCommandLineClassName = "mbox-scrapbox-command-line";
3
+ export declare const scrapboxCommandPromptClassName = "mbox-scrapbox-command-prompt";
4
+ export declare const scrapboxCommandClassName = "mbox-scrapbox-command";
5
+ export declare const scrapboxCommandLineClassNames: {
6
+ line: string;
7
+ command: string;
8
+ };
9
+ export declare function scrapboxCommandLinePlugin(): MboxPlugin;
@@ -0,0 +1,58 @@
1
+ import { type CompletionContext, type CompletionResult } from "@codemirror/autocomplete";
2
+ import type { MboxPlugin } from "../../editor/plugin.js";
3
+ export declare const scrapboxCompletionOptionClassName = "scrapbox-completion-option";
4
+ export declare const scrapboxCompletionOptionWithPreviewClassName = "scrapbox-completion-option-with-preview";
5
+ export declare const scrapboxCompletionPreviewClassName = "scrapbox-completion-preview";
6
+ export declare const scrapboxCompletionPreviewImageClassName = "scrapbox-completion-preview-image";
7
+ export declare const scrapboxCompletionClassNames: {
8
+ readonly option: "scrapbox-completion-option";
9
+ readonly optionWithPreview: "scrapbox-completion-option-with-preview";
10
+ readonly preview: "scrapbox-completion-preview";
11
+ readonly previewImage: "scrapbox-completion-preview-image";
12
+ };
13
+ /** The notation whose token the caret is currently inside. */
14
+ export type ScrapboxCompletionNotation = "bracket" | "hash";
15
+ /** A suggestion candidate. `iconUrl` (when set) is shown in the popup (iteration 2). */
16
+ export interface ScrapboxCompletionCandidate {
17
+ title: string;
18
+ iconUrl?: string;
19
+ }
20
+ /**
21
+ * Consumer-supplied recommender: given the text typed so far and the notation,
22
+ * return already-ranked/filtered candidates. Called synchronously on each
23
+ * keystroke, so the consumer owns an in-memory index (fetched however it likes).
24
+ */
25
+ export type ScrapboxRecommend = (query: string, notation: ScrapboxCompletionNotation) => ScrapboxCompletionCandidate[];
26
+ export interface ScrapboxCompletePluginOptions {
27
+ recommend?: ScrapboxRecommend;
28
+ }
29
+ export interface ScrapboxActiveToken {
30
+ kind: ScrapboxCompletionNotation;
31
+ /** The text between the opener and the caret — the recommend query. */
32
+ query: string;
33
+ /** Token bounds relative to the line: the whole `[ … ]` / `#tag` to replace. */
34
+ from: number;
35
+ to: number;
36
+ }
37
+ /**
38
+ * Detect the suggestion token the caret sits in, or null. The token spans the
39
+ * whole notation so accepting a candidate replaces it entirely (including the
40
+ * auto-closed `]`): `[ru|]` → `{ kind: "bracket", query: "ru", from: 0, to: 4 }`,
41
+ * `#ru|` → `{ kind: "hash", query: "ru", from: 0, to: 3 }`. A bracket wins over a
42
+ * hash when the caret is inside `[ … ]`.
43
+ */
44
+ export declare function findScrapboxActiveToken(lineText: string, cursorCh: number): ScrapboxActiveToken | null;
45
+ /**
46
+ * Build a CodeMirror completion source from a consumer recommender. It reads the
47
+ * active token, asks `recommend` for candidates and returns them verbatim with
48
+ * `filter: false` — the consumer already ranked/filtered, so CodeMirror must not
49
+ * filter again. Accepting a candidate replaces the whole token with `[title]` /
50
+ * `#title`, leaving the caret past it.
51
+ */
52
+ export declare function createScrapboxCompletionSource(recommend: ScrapboxRecommend): (context: CompletionContext) => CompletionResult | null;
53
+ /**
54
+ * Native completion popup for Scrapbox `[ … ]` page links and `#tag`s, driven by
55
+ * a consumer-supplied {@link ScrapboxRecommend}. Without a recommender the plugin
56
+ * is inert.
57
+ */
58
+ export declare function scrapboxCompletePlugin(options?: ScrapboxCompletePluginOptions): MboxPlugin;
@@ -0,0 +1,16 @@
1
+ import { type MboxPlugin } from "../../editor/plugin.js";
2
+ export declare const scrapboxCodeClassName = "mbox-scrapbox-code";
3
+ export declare const scrapboxStrongClassName = "mbox-scrapbox-strong";
4
+ export declare const scrapboxEmphasisClassName = "mbox-scrapbox-em";
5
+ export declare const scrapboxStrikethroughClassName = "mbox-scrapbox-strikethrough";
6
+ export declare const scrapboxUnderlineClassName = "mbox-scrapbox-underline";
7
+ export declare const scrapboxDecorationClassName = "mbox-scrapbox-decoration";
8
+ export declare const scrapboxStrongLevelClassNamePrefix = "mbox-scrapbox-strong-level";
9
+ export declare const scrapboxDecorationClassNames: {
10
+ strong: string;
11
+ em: string;
12
+ strikethrough: string;
13
+ underline: string;
14
+ code: string;
15
+ };
16
+ export declare function scrapboxDecorationPlugin(): MboxPlugin;
@@ -0,0 +1,43 @@
1
+ import { WidgetType } from "@codemirror/view";
2
+ import type { MboxPlugin } from "../../editor/plugin.js";
3
+ export declare const scrapboxFormulaClassName = "mbox-scrapbox-formula";
4
+ export declare const scrapboxFormulaClassNames: {
5
+ formula: string;
6
+ block: string;
7
+ };
8
+ /**
9
+ * Render a KaTeX/MathJax-style expression into a DOM node (pluggable).
10
+ *
11
+ * Returned DOM is trusted input: it must be created from trusted content or
12
+ * sanitized by the renderer. mbox deliberately does not apply a generic HTML
13
+ * sanitizer, because that could break legitimate MathML/HTML from renderers
14
+ * such as KaTeX.
15
+ *
16
+ * Every call must return a newly created, parentless `HTMLElement`. A renderer
17
+ * must never return the same `Node` more than once: mbox appends the result to
18
+ * the widget that owns it, and DOM insertion moves an already-parented node.
19
+ *
20
+ * By default, mbox adds a visually hidden TeX source fallback so assistive
21
+ * technology always has an equivalent representation. Set
22
+ * `providesAccessibleMath` when every DOM node this renderer returns already
23
+ * exposes an accessible mathematical equivalent (for example, KaTeX's MathML).
24
+ * That declaration suppresses the fallback and avoids duplicate announcements.
25
+ *
26
+ * If rendering throws, mbox displays the TeX source as visible text instead.
27
+ */
28
+ export interface ScrapboxFormulaRenderer {
29
+ (expression: string): HTMLElement;
30
+ providesAccessibleMath?: boolean;
31
+ }
32
+ export interface ScrapboxFormulaPluginOptions {
33
+ render?: ScrapboxFormulaRenderer;
34
+ }
35
+ export declare class ScrapboxFormulaWidget extends WidgetType {
36
+ private readonly expression;
37
+ private readonly render;
38
+ private readonly block;
39
+ constructor(expression: string, render: ScrapboxFormulaRenderer | undefined, block?: boolean);
40
+ eq(other: WidgetType): boolean;
41
+ toDOM(): HTMLElement;
42
+ }
43
+ export declare function scrapboxFormulaPlugin(options?: ScrapboxFormulaPluginOptions): MboxPlugin;
@@ -0,0 +1,62 @@
1
+ import type { MboxPlugin } from "../../editor/plugin.js";
2
+ import { ImageKitSelfCancelingMeasureWidget, ImageKitPreviewWidget, ImageKitTokenWidget, type ImageKitImage } from "../image-kit.js";
3
+ export declare const scrapboxImageClassName = "mbox-scrapbox-image";
4
+ export declare const scrapboxImageTokenClassName = "mbox-scrapbox-image-token";
5
+ export declare const scrapboxImagePreviewClassName = "mbox-scrapbox-image-preview";
6
+ export declare const scrapboxImageElementClassName = "mbox-scrapbox-image-element";
7
+ export declare const scrapboxImageStrongClassName = "mbox-scrapbox-image-strong";
8
+ export declare const scrapboxImageMeasureClassName = "mbox-scrapbox-image-measure";
9
+ export declare const scrapboxImageClassNames: {
10
+ image: string;
11
+ token: string;
12
+ preview: string;
13
+ element: string;
14
+ strong: string;
15
+ };
16
+ export type ScrapboxImageRenderMode = "token" | "preview";
17
+ /**
18
+ * Transform an image notation's matched URL into the one actually fetched as
19
+ * the `<img>` src. Called with the raw `src` an `image`/`strongImage` node
20
+ * matched, unparsed; returning it unchanged is always safe. `text`/`link`
21
+ * (the widget's display label and click-through href) are left as the
22
+ * matched URL regardless of what this returns, so the resolver only affects
23
+ * what gets fetched. Use this when a host serves a different address for its
24
+ * image bytes than the address that appears in notation -- see
25
+ * {@link defaultScrapboxImageSrcResolver} for the one case mbox handles out of
26
+ * the box. When set, this option replaces the default resolver entirely --
27
+ * call {@link defaultScrapboxImageSrcResolver} yourself if you want to extend
28
+ * rather than replace it.
29
+ */
30
+ export type ScrapboxImageSrcResolver = (src: string) => string;
31
+ export interface ScrapboxImagePluginOptions {
32
+ renderMode?: ScrapboxImageRenderMode;
33
+ resolveSrc?: ScrapboxImageSrcResolver;
34
+ }
35
+ /**
36
+ * Default {@link ScrapboxImageSrcResolver}: append `/raw` to a bare
37
+ * `gyazo.com/<id>` URL (or a subdomain like `i.gyazo.com/<id>`) that has no
38
+ * `/raw` suffix, because the bare form did not load as an `<img>` src when
39
+ * this was written. Any other src is returned unchanged.
40
+ *
41
+ * SOURCE NOT RECORDED. That observation has no recorded input, method or date.
42
+ * Treat the rule as mbox's own default, not as a durable fact about the host:
43
+ * a consumer that finds otherwise passes its own `resolveSrc`.
44
+ */
45
+ export declare function defaultScrapboxImageSrcResolver(src: string): string;
46
+ export declare class ScrapboxImageWidget extends ImageKitTokenWidget {
47
+ constructor(image: ImageKitImage);
48
+ }
49
+ export declare class ScrapboxImagePreviewWidget extends ImageKitPreviewWidget {
50
+ constructor(image: ImageKitImage);
51
+ }
52
+ /**
53
+ * Reserves the preview's HEIGHT only. Reserving its width as well would shove
54
+ * any same-line text after the image far to the right while the line is being
55
+ * edited -- pure noise. The cancelling mechanism lives in the kit; see
56
+ * {@link ImageKitSelfCancelingMeasureWidget} for why it is a negative margin
57
+ * and a ResizeObserver rather than a wrapper.
58
+ */
59
+ export declare class ScrapboxImageMeasureWidget extends ImageKitSelfCancelingMeasureWidget {
60
+ constructor(image: ImageKitImage);
61
+ }
62
+ export declare function scrapboxImagePlugin(options?: ScrapboxImagePluginOptions): MboxPlugin;
@@ -0,0 +1,40 @@
1
+ import type { EditorView } from "@codemirror/view";
2
+ import type { MboxPlugin } from "../../editor/plugin.js";
3
+ /**
4
+ * Indent every line touched by the selection by one Scrapbox indent level
5
+ * (a single leading space). The selection is mapped through the insertions so
6
+ * the cursor stays with its text.
7
+ */
8
+ export declare function indentScrapboxLines(view: EditorView): boolean;
9
+ /**
10
+ * Outdent every selected line that starts with whitespace by removing one
11
+ * leading whitespace character. Returns false when nothing is indented so the
12
+ * key can fall through to other handlers.
13
+ */
14
+ export declare function outdentScrapboxLines(view: EditorView): boolean;
15
+ /**
16
+ * Delete a single leading whitespace character when the caret sits inside a
17
+ * line's indent. Scrapbox indent levels are one space each, so a backspace in
18
+ * the indent must remove exactly one level. Without this, CodeMirror's
19
+ * indent-unit-aware Backspace deletes a whole 2-space indent unit, collapsing
20
+ * two Scrapbox levels at once. Returns false (falls through to the default
21
+ * deletion) whenever the caret is not a plain cursor within the indent.
22
+ */
23
+ export declare function backspaceScrapboxIndent(view: EditorView): boolean;
24
+ /**
25
+ * Move every cursor to the start of its line's content, i.e. just to the right
26
+ * of the indent whitespace (`" xyz"` puts the caret left of `x`). Falls
27
+ * through when the selection is already there, so a repeat press can reach the
28
+ * true line start via the default line-boundary motion.
29
+ */
30
+ export declare function scrapboxLineStart(view: EditorView): boolean;
31
+ /**
32
+ * On an empty list line — one that holds only indent whitespace, with the caret
33
+ * at its end — pressing Enter clears the whole line and drops the caret onto the
34
+ * next line, instead of carrying the indentation down. Mirrors the markdown list
35
+ * plugin's empty-list Enter behaviour. Falls through (returns false) for lines
36
+ * with content, non-indented empty lines, mid-line carets, multi-cursor
37
+ * selections and code/table block bodies.
38
+ */
39
+ export declare function enterScrapboxEmptyList(view: EditorView): boolean;
40
+ export declare function scrapboxIndentPlugin(): MboxPlugin;
@@ -0,0 +1,41 @@
1
+ import type { MboxPlugin } from "../../editor/plugin.js";
2
+ import { type ScrapboxCodeBlockHighlightPluginOptions } from "./code-block.js";
3
+ import { type ScrapboxCompletePluginOptions } from "./complete.js";
4
+ import { type ScrapboxFormulaPluginOptions } from "./formula.js";
5
+ import { type ScrapboxImagePluginOptions } from "./image.js";
6
+ import { type ScrapboxInlineCodeHighlightPluginOptions } from "./inline-code-highlight.js";
7
+ import { type ScrapboxLinkPluginOptions } from "./link.js";
8
+ export interface ScrapboxPluginsOptions {
9
+ /** Internal page/icon link rendering options. */
10
+ link?: ScrapboxLinkPluginOptions;
11
+ /** `true` adds scrapboxCodeBlockHighlightPlugin() with its zero-dependency
12
+ * JS/TS default; pass a ScrapboxCodeBlockHighlightPluginOptions object
13
+ * instead to also set `languages`/`onLoadError`. Omitted or falsy adds no
14
+ * highlighter at all (kept off by default so the base card carries no
15
+ * Lezer weight), matching gfm's own codeHighlight option. */
16
+ codeHighlight?: boolean | ScrapboxCodeBlockHighlightPluginOptions;
17
+ complete?: ScrapboxCompletePluginOptions;
18
+ formula?: ScrapboxFormulaPluginOptions;
19
+ image?: ScrapboxImagePluginOptions;
20
+ /** `true` adds scrapboxInlineCodeHighlightPlugin(), highlighting inline
21
+ * code (`` `...` ``) as Ruby -- a fixed approximation, not per-span language
22
+ * detection (see the plugin's own doc comment for why mbox fixes the
23
+ * language instead of detecting one).
24
+ * Off by default: it dynamically loads Ruby's legacy-mode parser the first
25
+ * time any inline code appears, which a consumer should opt into rather
26
+ * than pay for unconditionally. */
27
+ inlineCodeHighlight?: boolean | ScrapboxInlineCodeHighlightPluginOptions;
28
+ /** `true` adds scrapboxTitlePlugin(), marking the document's first line as
29
+ * the page title (an app-level convention, not part of the notation
30
+ * itself). Off by default -- it changes the first line's visual
31
+ * appearance once a presentation theme styles the class, so a consumer
32
+ * opts in explicitly rather than getting a surprise restyle. */
33
+ titleLine?: boolean;
34
+ }
35
+ /**
36
+ * Bundle of Scrapbox notation plugins: Tab indentation, list/indent structure,
37
+ * block quotes, command lines, code blocks, tables, inline decoration/strong/
38
+ * code styling, formulas, image previews and
39
+ * internal/external/hashtag/icon link anchors.
40
+ */
41
+ export declare function scrapboxPlugins(options?: ScrapboxPluginsOptions): MboxPlugin[];
@@ -0,0 +1,16 @@
1
+ import type { Extension } from "@codemirror/state";
2
+ import type { MboxMarkDecorationSpec, MboxPlugin } from "../../editor/plugin.js";
3
+ import type { ScrapboxDocument } from "./parser.js";
4
+ export declare const scrapboxInlineCodeTokenClassName = "mbox-scrapbox-code-token";
5
+ export interface ScrapboxInlineCodeHighlightPluginOptions {
6
+ onLoadError?: (languageId: string, error: unknown) => void;
7
+ }
8
+ /** Whether any line outside a code/table block has an inline `code` node.
9
+ * The language loader only starts Ruby's dynamic import once this is true,
10
+ * so enabling this plugin costs nothing until inline code actually shows up
11
+ * in the document. */
12
+ export declare function scrapboxDocumentHasInlineCode(document: ScrapboxDocument): boolean;
13
+ /** Clears `cache` on every doc change, so the text-keyed highlight cache
14
+ * below never retains specs for text no longer in the document. */
15
+ export declare function createInlineCodeCacheClearer(cache: Map<string, MboxMarkDecorationSpec[]>): Extension;
16
+ export declare function scrapboxInlineCodeHighlightPlugin(options?: ScrapboxInlineCodeHighlightPluginOptions): MboxPlugin;
@@ -0,0 +1,7 @@
1
+ import type { MboxPlugin } from "../../editor/plugin.js";
2
+ /**
3
+ * Surrounds the selected range with Scrapbox inline code backticks and keeps
4
+ * the content selected. Empty selections fall through so a single backtick is
5
+ * handled by normal text input.
6
+ */
7
+ export declare function scrapboxInlineCodePlugin(): MboxPlugin;
@@ -0,0 +1,66 @@
1
+ /** A match whose text is already in hand -- the shape `RegExp.exec` returns. */
2
+ interface InlinePatternMatch {
3
+ 0: string;
4
+ index: number;
5
+ }
6
+ /**
7
+ * A match that knows only where it starts. `resolve` produces the matched text
8
+ * and is called at most once, after this candidate has won.
9
+ */
10
+ interface DeferredInlinePatternMatch {
11
+ index: number;
12
+ resolve: () => string;
13
+ }
14
+ /**
15
+ * What a scanner may return. Deliberately a union with no common text member:
16
+ * `candidate[0]` does not compile, which is the point.
17
+ *
18
+ * The two members are not exported. A scanner writes `{ 0: text, index }` or
19
+ * `{ index, resolve }` and structural typing does the rest; naming them
20
+ * publicly before anything needs the names would be one more export to keep.
21
+ */
22
+ export type InlineScanMatch = InlinePatternMatch | DeferredInlinePatternMatch;
23
+ /** Finds the next match at or after `from`, or null when there is none. */
24
+ export interface InlinePatternScanner {
25
+ exec: (text: string, from: number) => InlineScanMatch | null;
26
+ }
27
+ /**
28
+ * The default way to build a scanner for a parse. A stateful scanner may use a
29
+ * factory, explicit reset when its input changes, or both. Prefer a factory
30
+ * for a scanner whose cursor or cache belongs to one parse; retain a reset
31
+ * when silently reusing that state for another input would yield plausible,
32
+ * wrong positions. A stateless scanner does not need a factory.
33
+ */
34
+ export interface InlineScannerFactory {
35
+ createScanner: () => InlinePatternScanner;
36
+ }
37
+ export type InlinePattern = RegExp | InlinePatternScanner | InlineScannerFactory;
38
+ /**
39
+ * The per-parse instance of one pattern.
40
+ *
41
+ * A RegExp becomes a clone with the global flag, because the driver drives
42
+ * `lastIndex` and two parses sharing one RegExp would share that position. A
43
+ * factory is invoked. A plain scanner is returned unchanged -- it holds nothing
44
+ * to keep apart.
45
+ */
46
+ export declare function instantiateInlinePattern(pattern: InlinePattern): RegExp | InlinePatternScanner;
47
+ /** The matched text, producing it now if the match deferred it. */
48
+ export declare function inlineMatchText(match: InlineScanMatch | RegExpExecArray): string;
49
+ /**
50
+ * Wraps a monotone search so that a forward-only caller does not rescan.
51
+ *
52
+ * `find(from)` must return the first position at or after `from` that matches,
53
+ * or -1. Monotone means: if `find(a)` is -1 then `find(b)` is -1 for every
54
+ * `b >= a`, and results never move backwards as `from` grows. Every "next
55
+ * newline", "next `]`", "next whitespace" search over a fixed string satisfies
56
+ * this.
57
+ *
58
+ * Given that, a cached result at or after the requested position is still the
59
+ * answer, and once the search comes up empty it stays empty.
60
+ *
61
+ * BUILD ONE PER PARSE. A shared cursor keeps positions from whichever document
62
+ * it saw last, and the failure is silent: the cached index is a perfectly
63
+ * plausible number for the new text.
64
+ */
65
+ export declare function createMonotonicCursor(find: (from: number) => number): (from: number) => number;
66
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { ScrapboxInlineNode } from "./inline.js";
2
+ export declare function collectScrapboxInlineNodeResults<T>(nodes: ScrapboxInlineNode[], visitor: (node: ScrapboxInlineNode) => T[]): T[];