@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.
Files changed (38) hide show
  1. package/README.md +30 -10
  2. package/dist/.build-manifest.json +130 -0
  3. package/dist/browser.d.ts +66 -0
  4. package/dist/browser.js +396 -0
  5. package/dist/chunk-3KTK7CSS.js +82 -0
  6. package/dist/chunk-5JNL3LHV.js +215 -0
  7. package/dist/chunk-ASRCHEFF.js +0 -0
  8. package/dist/chunk-BKJCBEI7.js +397 -0
  9. package/dist/chunk-CJSBFWKS.js +549 -0
  10. package/dist/chunk-GA5EFGSZ.js +5820 -0
  11. package/dist/chunk-OOH46GIF.js +95 -0
  12. package/dist/chunk-ROJILHRQ.js +192 -0
  13. package/dist/chunk-WFPUIPWU.js +34 -0
  14. package/dist/chunk-WXVKSKP3.js +191 -0
  15. package/dist/chunk-YZYJIXGO.js +0 -0
  16. package/dist/editor-core-DbPhn6aI.d.ts +249 -0
  17. package/dist/index.d.ts +77 -86
  18. package/dist/index.js +161 -245
  19. package/dist/internal/dom-adapter.d.ts +37 -1
  20. package/dist/internal/dom-adapter.js +9 -2
  21. package/dist/public-zMo7BR9l.d.ts +469 -0
  22. package/dist/registry-C849sxCo.d.ts +74 -0
  23. package/dist/semantic/components/index.d.ts +9 -0
  24. package/dist/semantic/components/index.js +11 -0
  25. package/dist/semantic/editor/index.d.ts +9 -0
  26. package/dist/semantic/editor/index.js +13 -0
  27. package/dist/semantic/index.d.ts +7 -0
  28. package/dist/semantic/index.js +106 -0
  29. package/dist/semantic/runtime/index.d.ts +9 -0
  30. package/dist/semantic/runtime/index.js +13 -0
  31. package/dist/semantic/shared/index.d.ts +10 -0
  32. package/dist/semantic/shared/index.js +17 -0
  33. package/dist/semantic/syntax/index.d.ts +151 -0
  34. package/dist/semantic/syntax/index.js +63 -0
  35. package/dist/types-DMqYF6Zn.d.ts +83 -0
  36. package/package.json +29 -1
  37. package/dist/chunk-TRLKIMRD.js +0 -3227
  38. package/dist/dom-adapter-CTSJe5Uo.d.ts +0 -469
@@ -0,0 +1,397 @@
1
+ import {
2
+ createDescriptorRegistry,
3
+ requireDescriptor,
4
+ validateSyntaxDescriptors
5
+ } from "./chunk-OOH46GIF.js";
6
+
7
+ // src/semantic/syntax/builtin/math.ts
8
+ var MATH_FENCE_RE = /^ {0,3}\$\$\s*$/;
9
+ var SINGLE_LINE_MATH_BLOCK_RE = /^ {0,3}\$\$(?!\s*$)([^\n]*?)(?<!\\)\$\$\s*$/;
10
+ var MULTI_LINE_MATH_BLOCK_OPEN_RE = /^ {0,3}\$\$(?!\s*$)(?!.*(?<!\\)\$\$\s*$).+$/;
11
+ var MULTI_LINE_MATH_BLOCK_CLOSE_RE = /(?<!\\)\$\$\s*$/;
12
+ var mathSyntaxDescriptor = {
13
+ key: "builtin.math",
14
+ family: "syntax",
15
+ syntaxKind: "block",
16
+ consumes: ["parser", "processor", "preview", "runtime"],
17
+ specIds: ["docs/specs/owomark-math.md"],
18
+ featureFlag: "enableMath",
19
+ aliases: ["math-block"]
20
+ };
21
+ function isFenceOnlyMathLine(line) {
22
+ return MATH_FENCE_RE.test(line);
23
+ }
24
+ function isSingleLineMathBlock(line) {
25
+ return SINGLE_LINE_MATH_BLOCK_RE.test(line);
26
+ }
27
+ function isMultiLineMathBlockOpen(line) {
28
+ return MULTI_LINE_MATH_BLOCK_OPEN_RE.test(line);
29
+ }
30
+ function isMultiLineMathBlockClose(line) {
31
+ return MULTI_LINE_MATH_BLOCK_CLOSE_RE.test(line);
32
+ }
33
+ function getLeadingWhitespace(line) {
34
+ return line.match(/^ {0,3}/)?.[0] ?? "";
35
+ }
36
+ function splitOpeningMathLine(line) {
37
+ const prefix = getLeadingWhitespace(line);
38
+ return [`${prefix}$$`, `${prefix}${line.slice(prefix.length + 2)}`];
39
+ }
40
+ function splitClosingMathLine(line) {
41
+ const match = line.match(MULTI_LINE_MATH_BLOCK_CLOSE_RE);
42
+ if (!match || match.index == null) return [line];
43
+ const prefix = getLeadingWhitespace(line);
44
+ const content = line.slice(0, match.index);
45
+ const output = [];
46
+ if (content.length > 0) {
47
+ output.push(content);
48
+ }
49
+ output.push(`${prefix}$$`);
50
+ return output;
51
+ }
52
+ function collectMathFenceNormalizationRewrites(source) {
53
+ const lines = source.split("\n");
54
+ if (source.endsWith("\n")) {
55
+ lines.pop();
56
+ }
57
+ const rewrites = [];
58
+ for (let index = 0; index < lines.length; index += 1) {
59
+ const line = lines[index];
60
+ if (!isFenceOnlyMathLine(line) && !isMultiLineMathBlockOpen(line)) {
61
+ continue;
62
+ }
63
+ if (isSingleLineMathBlock(line)) {
64
+ continue;
65
+ }
66
+ let closeIndex = -1;
67
+ for (let cursor = index + 1; cursor < lines.length; cursor += 1) {
68
+ if (isMultiLineMathBlockClose(lines[cursor])) {
69
+ closeIndex = cursor;
70
+ break;
71
+ }
72
+ }
73
+ if (closeIndex === -1) {
74
+ continue;
75
+ }
76
+ const firstLine = lines[index];
77
+ const lastLine = lines[closeIndex];
78
+ const needsOpeningSplit = !isFenceOnlyMathLine(firstLine);
79
+ const needsClosingSplit = !isFenceOnlyMathLine(lastLine);
80
+ if (!needsOpeningSplit && !needsClosingSplit) {
81
+ index = closeIndex;
82
+ continue;
83
+ }
84
+ const replacementLines = [];
85
+ const lineMappings = [];
86
+ if (needsOpeningSplit) {
87
+ const openingLines = splitOpeningMathLine(firstLine);
88
+ replacementLines.push(openingLines[0]);
89
+ lineMappings.push({ sourceLine: index + 1, sourceColumn: 1 });
90
+ replacementLines.push(openingLines[1]);
91
+ lineMappings.push({ sourceLine: index + 1, sourceColumn: 3 });
92
+ } else {
93
+ replacementLines.push(firstLine);
94
+ lineMappings.push({ sourceLine: index + 1, sourceColumn: 1 });
95
+ }
96
+ for (let cursor = index + 1; cursor < closeIndex; cursor += 1) {
97
+ replacementLines.push(lines[cursor]);
98
+ lineMappings.push({ sourceLine: cursor + 1, sourceColumn: 1 });
99
+ }
100
+ if (needsClosingSplit) {
101
+ const closingLines = splitClosingMathLine(lastLine);
102
+ const prefixLength = getLeadingWhitespace(lastLine).length;
103
+ const fenceStart = lastLine.match(MULTI_LINE_MATH_BLOCK_CLOSE_RE)?.index ?? prefixLength;
104
+ if (closingLines.length === 2) {
105
+ replacementLines.push(closingLines[0]);
106
+ lineMappings.push({ sourceLine: closeIndex + 1, sourceColumn: 1 });
107
+ replacementLines.push(closingLines[1]);
108
+ lineMappings.push({
109
+ sourceLine: closeIndex + 1,
110
+ sourceColumn: fenceStart - prefixLength + 1
111
+ });
112
+ } else {
113
+ replacementLines.push(closingLines[0]);
114
+ lineMappings.push({ sourceLine: closeIndex + 1, sourceColumn: 1 });
115
+ }
116
+ } else {
117
+ replacementLines.push(lastLine);
118
+ lineMappings.push({ sourceLine: closeIndex + 1, sourceColumn: 1 });
119
+ }
120
+ rewrites.push({
121
+ kind: "math-fence",
122
+ startLine: index + 1,
123
+ endLine: closeIndex + 1,
124
+ replacementLines,
125
+ lineMappings
126
+ });
127
+ index = closeIndex;
128
+ }
129
+ return rewrites;
130
+ }
131
+
132
+ // src/semantic/syntax/builtin/side-annotation.ts
133
+ var sideAnnotationTypeDescriptors = [
134
+ { symbol: ":", keyword: "plain", rendererKey: "plain" },
135
+ { symbol: "}", keyword: "brace", rendererKey: "brace" },
136
+ { symbol: "{", keyword: "left-brace", rendererKey: "left-brace" },
137
+ { symbol: "]", keyword: "bracket", rendererKey: "bracket" },
138
+ { symbol: "[", keyword: "left-bracket", rendererKey: "left-bracket" },
139
+ { symbol: "|", keyword: "line", rendererKey: "line" },
140
+ { symbol: "-", keyword: "dash", rendererKey: "dash" },
141
+ { symbol: "->", keyword: "arrow", rendererKey: "arrow" },
142
+ { symbol: "=>", keyword: "fat-arrow", rendererKey: "fat-arrow" },
143
+ { symbol: "~>", keyword: "wave-arrow", rendererKey: "wave-arrow" },
144
+ { symbol: "!", keyword: "warning", rendererKey: "line" },
145
+ { symbol: "?", keyword: "question", rendererKey: "line" },
146
+ { symbol: "}->", keyword: "brace-arrow", rendererKey: "brace-arrow" },
147
+ { symbol: "}=>", keyword: "brace-fat-arrow", rendererKey: "brace-fat-arrow" },
148
+ { symbol: "]->", keyword: "bracket-arrow", rendererKey: "bracket-arrow" },
149
+ { symbol: "]=>", keyword: "bracket-fat-arrow", rendererKey: "bracket-fat-arrow" },
150
+ { symbol: "|->", keyword: "line-arrow", rendererKey: "line-arrow" },
151
+ { symbol: "|=>", keyword: "line-fat-arrow", rendererKey: "line-fat-arrow" },
152
+ { symbol: "}!", keyword: "brace-warning", rendererKey: "brace" },
153
+ { symbol: "}?", keyword: "brace-question", rendererKey: "brace" }
154
+ ];
155
+ var SIDE_ANNOTATION_TYPE_TABLE = Object.freeze(
156
+ Object.fromEntries(
157
+ sideAnnotationTypeDescriptors.map((descriptor) => [descriptor.symbol, descriptor.keyword])
158
+ )
159
+ );
160
+ var SIDE_ANNOTATION_TYPE_SYMBOLS = sideAnnotationTypeDescriptors.map(
161
+ (descriptor) => descriptor.symbol
162
+ );
163
+ var SIDE_ANNOTATION_TYPE_SYMBOLS_SORTED = [...SIDE_ANNOTATION_TYPE_SYMBOLS].sort((a, b) => b.length - a.length);
164
+ var SIDE_ANNOTATION_SYMBOL_BY_KEYWORD = Object.freeze(
165
+ Object.fromEntries(
166
+ sideAnnotationTypeDescriptors.map((descriptor) => [descriptor.keyword, descriptor.symbol])
167
+ )
168
+ );
169
+ var SIDE_ANNOTATION_RENDERER_KEY_BY_TYPE = Object.freeze(
170
+ Object.fromEntries(
171
+ sideAnnotationTypeDescriptors.map((descriptor) => [descriptor.keyword, descriptor.rendererKey])
172
+ )
173
+ );
174
+ var TYPE_PATTERN = [
175
+ ...SIDE_ANNOTATION_TYPE_SYMBOLS_SORTED,
176
+ ...Object.keys(SIDE_ANNOTATION_SYMBOL_BY_KEYWORD).sort((a, b) => b.length - a.length)
177
+ ].map((symbol) => symbol.replace(/[|\\{}()[\]^$+*?.-]/g, "\\$&")).join("|");
178
+ var sideAnnotationSyntaxDescriptors = [
179
+ {
180
+ key: "builtin.side-inline-head",
181
+ family: "syntax",
182
+ syntaxKind: "block",
183
+ consumes: ["parser", "processor", "preview", "rehype", "runtime"],
184
+ specIds: ["docs/specs/owomark-side-annotation.md"],
185
+ featureFlag: "enableSideAnnotation",
186
+ aliases: ["side-inline-head"]
187
+ },
188
+ {
189
+ key: "builtin.side-continuation",
190
+ family: "syntax",
191
+ syntaxKind: "block",
192
+ consumes: ["parser", "processor", "preview", "rehype", "runtime"],
193
+ specIds: ["docs/specs/owomark-side-annotation.md"],
194
+ featureFlag: "enableSideAnnotation",
195
+ aliases: ["side-continuation"]
196
+ },
197
+ {
198
+ key: "builtin.side-container",
199
+ family: "syntax",
200
+ syntaxKind: "container-block",
201
+ consumes: ["parser", "processor", "preview", "rehype", "runtime"],
202
+ specIds: ["docs/specs/owomark-side-annotation.md"],
203
+ featureFlag: "enableSideAnnotation",
204
+ aliases: ["side-container"]
205
+ },
206
+ {
207
+ key: "builtin.side-reference-definition",
208
+ family: "syntax",
209
+ syntaxKind: "block",
210
+ consumes: ["parser", "processor", "preview", "rehype", "runtime"],
211
+ specIds: ["docs/specs/owomark-side-annotation.md"],
212
+ featureFlag: "enableSideAnnotation",
213
+ aliases: ["side-reference-definition"]
214
+ }
215
+ ];
216
+ var SIDE_ANNOTATION_TAIL_RE = new RegExp(`\\(>(?:${TYPE_PATTERN})[^\\n)]*\\)\\s*$`);
217
+ var SIDE_CONTINUATION_TAIL_RE = /\(>\+\)\s*$/;
218
+ var SIDE_NOTE_REF_RE = /^\[>([\w-]+)\]$/;
219
+ var SIDE_NOTE_DEFINITION_RE = /^\[>([\w-]+)\]:\s*(?:\{type=([^}"]+|"[^"]*")\}\s*)?(.*)$/;
220
+ function findUnescapedClose(text) {
221
+ for (let index = 0; index < text.length; index += 1) {
222
+ if (text[index] === ")") {
223
+ let backslashCount = 0;
224
+ for (let cursor = index - 1; cursor >= 0 && text[cursor] === "\\"; cursor -= 1) {
225
+ backslashCount += 1;
226
+ }
227
+ if (backslashCount > 0) {
228
+ continue;
229
+ }
230
+ return index;
231
+ }
232
+ }
233
+ return -1;
234
+ }
235
+ function resolveTypeSymbol(raw) {
236
+ if (raw in SIDE_ANNOTATION_TYPE_TABLE) {
237
+ const symbol = raw;
238
+ return {
239
+ sideType: SIDE_ANNOTATION_TYPE_TABLE[symbol],
240
+ sideTypeSymbol: symbol
241
+ };
242
+ }
243
+ const symbolFromKeyword = SIDE_ANNOTATION_SYMBOL_BY_KEYWORD[raw];
244
+ if (!symbolFromKeyword) {
245
+ return null;
246
+ }
247
+ return {
248
+ sideType: SIDE_ANNOTATION_TYPE_TABLE[symbolFromKeyword],
249
+ sideTypeSymbol: symbolFromKeyword
250
+ };
251
+ }
252
+ function parseInlineSideAnnotationText(inner) {
253
+ const spaceIndex = inner.indexOf(" ");
254
+ if (spaceIndex < 0) {
255
+ return null;
256
+ }
257
+ const typeCandidate = inner.slice(0, spaceIndex);
258
+ if (!typeCandidate || typeCandidate === "+") {
259
+ return null;
260
+ }
261
+ const resolved = resolveTypeSymbol(typeCandidate);
262
+ if (!resolved) {
263
+ return null;
264
+ }
265
+ const content = inner.slice(spaceIndex + 1).replace(/\\+\)/g, ")").trim();
266
+ if (!content) {
267
+ return null;
268
+ }
269
+ return {
270
+ sideType: resolved.sideType,
271
+ sideTypeSymbol: resolved.sideTypeSymbol,
272
+ content
273
+ };
274
+ }
275
+ function parseInlineSideAnnotationFromText(text) {
276
+ if (!text || /\(\\>/.test(text)) {
277
+ return null;
278
+ }
279
+ const openIndex = text.lastIndexOf("(>");
280
+ if (openIndex < 0) {
281
+ return null;
282
+ }
283
+ const afterOpen = text.slice(openIndex + 2);
284
+ const closeIndex = findUnescapedClose(afterOpen);
285
+ if (closeIndex < 0) {
286
+ return null;
287
+ }
288
+ if (afterOpen.slice(closeIndex + 1).trim()) {
289
+ return null;
290
+ }
291
+ return parseInlineSideAnnotationText(afterOpen.slice(0, closeIndex));
292
+ }
293
+ function stripInlineSideAnnotationTail(text) {
294
+ if (!parseInlineSideAnnotationFromText(text)) {
295
+ return text;
296
+ }
297
+ const openIndex = text.lastIndexOf("(>");
298
+ if (openIndex < 0) {
299
+ return text;
300
+ }
301
+ return text.slice(0, openIndex).trimEnd();
302
+ }
303
+ function stripSideContinuationTail(text) {
304
+ return text.replace(SIDE_CONTINUATION_TAIL_RE, "").trimEnd();
305
+ }
306
+ function parseSideDirectiveLabel(label) {
307
+ const trimmed = label.trim();
308
+ const noteRefMatch = SIDE_NOTE_REF_RE.exec(trimmed);
309
+ if (noteRefMatch) {
310
+ return { noteRef: noteRefMatch[1] };
311
+ }
312
+ const inner = trimmed.replace(/^\(>(.*)\)$/, "$1");
313
+ return parseInlineSideAnnotationText(inner);
314
+ }
315
+ function parseSideNoteDefinitionRaw(raw) {
316
+ const lines = raw.split("\n");
317
+ const firstLine = lines[0]?.trim() ?? "";
318
+ const prefixMatch = /^\[>([\w-]+)\]:\s*(.*)$/.exec(firstLine);
319
+ if (!prefixMatch) {
320
+ return null;
321
+ }
322
+ const identifier = prefixMatch[1];
323
+ let remainder = prefixMatch[2] ?? "";
324
+ let typeToken = ":";
325
+ if (remainder.startsWith("{type=")) {
326
+ const attributeMatch = /^\{type=("[^"]*"|.+?)\}(?:\s+|$)(.*)$/.exec(remainder);
327
+ if (attributeMatch) {
328
+ typeToken = attributeMatch[1].replace(/^"|"$/g, "");
329
+ remainder = attributeMatch[2] ?? "";
330
+ }
331
+ }
332
+ const resolved = resolveTypeSymbol(typeToken);
333
+ if (!resolved) {
334
+ return null;
335
+ }
336
+ const contentParts = [];
337
+ const firstLineTail = remainder.trim();
338
+ if (firstLineTail) {
339
+ contentParts.push(firstLineTail);
340
+ }
341
+ for (let index = 1; index < lines.length; index += 1) {
342
+ const continuation = lines[index].match(/^(?: {1,4}|\t)(.*)$/);
343
+ if (!continuation) {
344
+ break;
345
+ }
346
+ contentParts.push(continuation[1]);
347
+ }
348
+ return {
349
+ identifier,
350
+ sideType: resolved.sideType,
351
+ sideTypeSymbol: resolved.sideTypeSymbol,
352
+ content: contentParts.join("\n").trim()
353
+ };
354
+ }
355
+
356
+ // src/semantic/syntax/index.ts
357
+ var descriptors = [
358
+ mathSyntaxDescriptor,
359
+ ...sideAnnotationSyntaxDescriptors
360
+ ];
361
+ validateSyntaxDescriptors(descriptors);
362
+ var syntaxRegistry = createDescriptorRegistry(descriptors, "syntax");
363
+ function getSyntaxDescriptor(key) {
364
+ return requireDescriptor(syntaxRegistry, key, "syntax");
365
+ }
366
+
367
+ export {
368
+ MATH_FENCE_RE,
369
+ SINGLE_LINE_MATH_BLOCK_RE,
370
+ MULTI_LINE_MATH_BLOCK_OPEN_RE,
371
+ MULTI_LINE_MATH_BLOCK_CLOSE_RE,
372
+ mathSyntaxDescriptor,
373
+ isFenceOnlyMathLine,
374
+ isSingleLineMathBlock,
375
+ isMultiLineMathBlockOpen,
376
+ isMultiLineMathBlockClose,
377
+ collectMathFenceNormalizationRewrites,
378
+ sideAnnotationTypeDescriptors,
379
+ SIDE_ANNOTATION_TYPE_TABLE,
380
+ SIDE_ANNOTATION_TYPE_SYMBOLS,
381
+ SIDE_ANNOTATION_TYPE_SYMBOLS_SORTED,
382
+ SIDE_ANNOTATION_SYMBOL_BY_KEYWORD,
383
+ SIDE_ANNOTATION_RENDERER_KEY_BY_TYPE,
384
+ sideAnnotationSyntaxDescriptors,
385
+ SIDE_ANNOTATION_TAIL_RE,
386
+ SIDE_CONTINUATION_TAIL_RE,
387
+ SIDE_NOTE_REF_RE,
388
+ SIDE_NOTE_DEFINITION_RE,
389
+ parseInlineSideAnnotationText,
390
+ parseInlineSideAnnotationFromText,
391
+ stripInlineSideAnnotationTail,
392
+ stripSideContinuationTail,
393
+ parseSideDirectiveLabel,
394
+ parseSideNoteDefinitionRaw,
395
+ syntaxRegistry,
396
+ getSyntaxDescriptor
397
+ };