@agentshouse/mdmodel 0.1.0-c03f6cf931ca0 → 0.1.0-c047361b218db
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/API.md +33 -94
- package/README.md +1 -1
- package/dist/definition.d.ts +4 -0
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +13 -4
- package/dist/document.d.ts +1 -0
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +56 -21
- package/dist/house-model.d.ts +103 -5
- package/dist/house-model.d.ts.map +1 -1
- package/dist/house-model.js +54 -4
- package/dist/index.d.ts +12 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -7
- package/dist/indexed.d.ts +9 -0
- package/dist/indexed.d.ts.map +1 -0
- package/dist/indexed.js +55 -0
- package/dist/kinds.d.ts +3 -0
- package/dist/kinds.d.ts.map +1 -1
- package/dist/kinds.js +60 -0
- package/dist/markdown.d.ts +0 -4
- package/dist/markdown.d.ts.map +1 -1
- package/dist/markdown.js +1 -34
- package/dist/moment.d.ts +7 -0
- package/dist/moment.d.ts.map +1 -0
- package/dist/moment.js +18 -0
- package/dist/paths.d.ts +6 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +33 -3
- package/dist/query/language.d.ts +2 -1
- package/dist/query/language.d.ts.map +1 -1
- package/dist/query/language.js +1 -1
- package/dist/query/rows.d.ts.map +1 -1
- package/dist/query/rows.js +1 -4
- package/dist/query/sql.d.ts +5 -1
- package/dist/query/sql.d.ts.map +1 -1
- package/dist/query/sql.js +3 -3
- package/dist/query/walk.d.ts +63 -0
- package/dist/query/walk.d.ts.map +1 -0
- package/dist/query/walk.js +263 -0
- package/dist/reserved.d.ts +1 -0
- package/dist/reserved.d.ts.map +1 -1
- package/dist/reserved.js +15 -4
- package/dist/room-types.d.ts +1 -1
- package/dist/room-types.d.ts.map +1 -1
- package/dist/room-types.js +1 -0
- package/dist/types.d.ts +0 -21
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +2 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +9 -5
- package/dist/yaml.d.ts +3 -1
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +153 -32
- package/fixtures/README.md +41 -53
- package/fixtures/cases/block-scalar-frontmatter/context.json +1 -0
- package/fixtures/cases/block-scalar-frontmatter/expected.json +1 -0
- package/fixtures/cases/block-scalar-frontmatter/library/notes/literal.md +17 -0
- package/fixtures/cases/block-scalar-frontmatter/library/skills/notes/SKILL.md +10 -0
- package/fixtures/cases/frontmatter-construct/context.json +1 -0
- package/fixtures/cases/frontmatter-construct/expected.json +7 -0
- package/fixtures/cases/frontmatter-construct/library/note.md +6 -0
- package/fixtures/cases/reference-to-any-file-name/context.json +1 -0
- package/fixtures/cases/reference-to-any-file-name/expected.json +1 -0
- package/fixtures/cases/reference-to-any-file-name/library/people/100%.md +4 -0
- package/fixtures/cases/reference-to-any-file-name/library/people/C#.md +4 -0
- package/fixtures/cases/reference-to-any-file-name/library/people/My notes.md +4 -0
- package/fixtures/cases/reference-to-any-file-name/library/people/[draft].md +4 -0
- package/fixtures/cases/reference-to-any-file-name/library/people/c (d).md +4 -0
- package/fixtures/cases/reference-to-any-file-name/library/people/caf/303/251.md +4 -0
- package/fixtures/cases/reference-to-any-file-name/library/people//320/236/321/202/321/207/321/221/321/202.md +4 -0
- package/fixtures/cases/reference-to-any-file-name/library/tasks/bracket.md +9 -0
- package/fixtures/cases/reference-to-any-file-name/library/tasks/cyrillic.md +9 -0
- package/fixtures/cases/reference-to-any-file-name/library/tasks/decomposed.md +9 -0
- package/fixtures/cases/reference-to-any-file-name/library/tasks/hash.md +9 -0
- package/fixtures/cases/reference-to-any-file-name/library/tasks/parenthesis.md +9 -0
- package/fixtures/cases/reference-to-any-file-name/library/tasks/percent.md +9 -0
- package/fixtures/cases/reference-to-any-file-name/library/tasks/spaced.md +9 -0
- package/fixtures/cases/reference-to-any-file-name/schema.yaml +10 -0
- package/fixtures/cases/referenced-missing-non-latin-file/context.json +1 -0
- package/fixtures/cases/referenced-missing-non-latin-file/expected.json +6 -0
- package/fixtures/cases/referenced-missing-non-latin-file/library/tasks/a.md +9 -0
- package/fixtures/cases/referenced-missing-non-latin-file/library/tasks/b.md +9 -0
- package/fixtures/cases/referenced-missing-non-latin-file/schema.yaml +10 -0
- package/fixtures/forms.json +24 -0
- package/fixtures/preamble.json +4 -4
- package/fixtures/queries.json +397 -2
- package/package.json +1 -1
- package/dist/divide.d.ts +0 -3
- package/dist/divide.d.ts.map +0 -1
- package/dist/divide.js +0 -321
- package/dist/project.d.ts +0 -22
- package/dist/project.d.ts.map +0 -1
- package/dist/project.js +0 -101
- package/fixtures/division.json +0 -454
- package/fixtures/projection.json +0 -358
package/dist/divide.js
DELETED
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import { readingOf } from './document.js';
|
|
2
|
-
import { blockRanges, headingsIn } from './markdown.js';
|
|
3
|
-
import { firstEditFrom, projectionInput, rangeText, } from './project.js';
|
|
4
|
-
import { refusal } from './refuse.js';
|
|
5
|
-
const SMALLEST_BOUND = 2;
|
|
6
|
-
function node(draft) {
|
|
7
|
-
return {
|
|
8
|
-
start: draft.start,
|
|
9
|
-
end: draft.end,
|
|
10
|
-
bodyStart: draft.bodyStart,
|
|
11
|
-
heading: draft.heading,
|
|
12
|
-
children: draft.children.map(node),
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function forest(state, range) {
|
|
16
|
-
const headings = headingsIn(state.reading, range.start, range.end);
|
|
17
|
-
const roots = [];
|
|
18
|
-
const open = [];
|
|
19
|
-
const first = headings[0]?.start ?? range.end;
|
|
20
|
-
if (first > range.start) {
|
|
21
|
-
roots.push({
|
|
22
|
-
level: 0,
|
|
23
|
-
start: range.start,
|
|
24
|
-
end: first,
|
|
25
|
-
bodyStart: range.start,
|
|
26
|
-
heading: '',
|
|
27
|
-
children: [],
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
for (const heading of headings) {
|
|
31
|
-
while ((open[open.length - 1]?.level ?? 0) >= heading.level) {
|
|
32
|
-
open.pop().end = heading.start;
|
|
33
|
-
}
|
|
34
|
-
const draft = {
|
|
35
|
-
level: heading.level,
|
|
36
|
-
start: heading.start,
|
|
37
|
-
end: range.end,
|
|
38
|
-
bodyStart: heading.next,
|
|
39
|
-
heading: `${textOf(state, { start: heading.start, end: heading.textEnd })}\n\n`,
|
|
40
|
-
children: [],
|
|
41
|
-
};
|
|
42
|
-
(open[open.length - 1]?.children ?? roots).push(draft);
|
|
43
|
-
open.push(draft);
|
|
44
|
-
}
|
|
45
|
-
return roots.map(node);
|
|
46
|
-
}
|
|
47
|
-
function isSpace(character) {
|
|
48
|
-
return character === ' ' || character === '\t' || character === '\n' || character === '\r';
|
|
49
|
-
}
|
|
50
|
-
const TERMINATORS = new Set(['.', '!', '?', '…', '。', '!', '?']);
|
|
51
|
-
function isTerminator(character) {
|
|
52
|
-
return TERMINATORS.has(character);
|
|
53
|
-
}
|
|
54
|
-
const CLOSERS = new Set(['"', "'", ')', ']', '»', '”']);
|
|
55
|
-
function isCloser(character) {
|
|
56
|
-
return CLOSERS.has(character);
|
|
57
|
-
}
|
|
58
|
-
function sentenceBounds(text) {
|
|
59
|
-
const bounds = [0];
|
|
60
|
-
let i = 0;
|
|
61
|
-
while (i < text.length) {
|
|
62
|
-
if (!isTerminator(text[i])) {
|
|
63
|
-
i += 1;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
let after = i + 1;
|
|
67
|
-
while (after < text.length && isCloser(text[after]))
|
|
68
|
-
after += 1;
|
|
69
|
-
if (after >= text.length || !isSpace(text[after])) {
|
|
70
|
-
i = after + 1;
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
while (after < text.length && isSpace(text[after]))
|
|
74
|
-
after += 1;
|
|
75
|
-
if (after < text.length)
|
|
76
|
-
bounds.push(after);
|
|
77
|
-
i = after;
|
|
78
|
-
}
|
|
79
|
-
bounds.push(text.length);
|
|
80
|
-
return bounds;
|
|
81
|
-
}
|
|
82
|
-
function isTrailingSurrogate(text, index) {
|
|
83
|
-
const code = text.charCodeAt(index);
|
|
84
|
-
return code >= 0xdc00 && code <= 0xdfff;
|
|
85
|
-
}
|
|
86
|
-
function characterLength(text, index) {
|
|
87
|
-
return isTrailingSurrogate(text, index + 1) ? 2 : 1;
|
|
88
|
-
}
|
|
89
|
-
function boundOf(cutting, from, to, bound) {
|
|
90
|
-
const limit = from + bound;
|
|
91
|
-
if (limit >= to)
|
|
92
|
-
return to;
|
|
93
|
-
for (let index = limit; index > from + 1; index -= 1) {
|
|
94
|
-
if (isSpace(cutting.text[index]))
|
|
95
|
-
return index;
|
|
96
|
-
}
|
|
97
|
-
const inside = cutting.masks.find((mask) => limit > mask.start && limit < mask.end);
|
|
98
|
-
if (inside !== undefined)
|
|
99
|
-
return inside.start > from ? inside.start : Math.min(inside.end, to);
|
|
100
|
-
return isTrailingSurrogate(cutting.text, limit) ? limit - 1 : limit;
|
|
101
|
-
}
|
|
102
|
-
function utf8Size(code) {
|
|
103
|
-
if (code < 0x80)
|
|
104
|
-
return 1;
|
|
105
|
-
if (code < 0x800)
|
|
106
|
-
return 2;
|
|
107
|
-
if (code < 0x10000)
|
|
108
|
-
return 3;
|
|
109
|
-
return 4;
|
|
110
|
-
}
|
|
111
|
-
function byteBounds(content, spans) {
|
|
112
|
-
const marks = [...new Set(spans.flatMap((span) => [span.start, span.end]))].sort((left, right) => left - right);
|
|
113
|
-
const bytes = new Map();
|
|
114
|
-
let index = 0;
|
|
115
|
-
let count = 0;
|
|
116
|
-
for (const mark of marks) {
|
|
117
|
-
while (index < mark) {
|
|
118
|
-
const code = content.codePointAt(index);
|
|
119
|
-
count += utf8Size(code);
|
|
120
|
-
index += code > 0xffff ? 2 : 1;
|
|
121
|
-
}
|
|
122
|
-
bytes.set(mark, count);
|
|
123
|
-
}
|
|
124
|
-
return spans.map((span) => ({
|
|
125
|
-
...span,
|
|
126
|
-
start: bytes.get(span.start),
|
|
127
|
-
end: bytes.get(span.end),
|
|
128
|
-
}));
|
|
129
|
-
}
|
|
130
|
-
function textOf(state, extent) {
|
|
131
|
-
return rangeText(state.content, extent, state.edits);
|
|
132
|
-
}
|
|
133
|
-
function sourceCutting(state, extent) {
|
|
134
|
-
const source = state.content.slice(extent.start, extent.end);
|
|
135
|
-
const masks = [];
|
|
136
|
-
for (let index = firstEditFrom(state.edits, extent.start); index < state.edits.length; index += 1) {
|
|
137
|
-
const edit = state.edits[index];
|
|
138
|
-
if (edit.start > extent.end)
|
|
139
|
-
break;
|
|
140
|
-
if (edit.end > extent.end)
|
|
141
|
-
continue;
|
|
142
|
-
masks.push({ start: edit.start - extent.start, end: edit.end - extent.start });
|
|
143
|
-
}
|
|
144
|
-
let text = '';
|
|
145
|
-
let cursor = 0;
|
|
146
|
-
for (const mask of masks) {
|
|
147
|
-
if (mask.end <= cursor)
|
|
148
|
-
continue;
|
|
149
|
-
const from = Math.max(mask.start, cursor);
|
|
150
|
-
text += `${source.slice(cursor, from)}${'x'.repeat(mask.end - from)}`;
|
|
151
|
-
cursor = mask.end;
|
|
152
|
-
}
|
|
153
|
-
text += source.slice(cursor);
|
|
154
|
-
return {
|
|
155
|
-
text,
|
|
156
|
-
masks,
|
|
157
|
-
piece: (from, to) => {
|
|
158
|
-
const cut = { start: extent.start + from, end: extent.start + to };
|
|
159
|
-
return { ...cut, text: textOf(state, cut) };
|
|
160
|
-
},
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
function valueCutting(value) {
|
|
164
|
-
return {
|
|
165
|
-
text: value.text,
|
|
166
|
-
masks: [],
|
|
167
|
-
piece: (from, to) => ({ start: value.start, end: value.end, text: value.text.slice(from, to) }),
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
function prefixOf(state, body) {
|
|
171
|
-
if (body.emitted === 0 || body.heading.length >= state.bound)
|
|
172
|
-
return '';
|
|
173
|
-
return body.heading;
|
|
174
|
-
}
|
|
175
|
-
function available(state, body) {
|
|
176
|
-
return state.bound - prefixOf(state, body).length;
|
|
177
|
-
}
|
|
178
|
-
function emit(state, body, piece, bare = false) {
|
|
179
|
-
if (piece.text.trim() === '')
|
|
180
|
-
return;
|
|
181
|
-
const text = (bare ? '' : prefixOf(state, body)) + piece.text;
|
|
182
|
-
state.spans.push({ start: piece.start, end: piece.end, text });
|
|
183
|
-
body.emitted += 1;
|
|
184
|
-
}
|
|
185
|
-
function merge(run) {
|
|
186
|
-
return {
|
|
187
|
-
start: Math.min(...run.map((unit) => unit.start)),
|
|
188
|
-
end: Math.max(...run.map((unit) => unit.end)),
|
|
189
|
-
text: run.map((unit) => unit.text).join(''),
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
function divideUnits(state, body, units) {
|
|
193
|
-
let run = [];
|
|
194
|
-
let length = 0;
|
|
195
|
-
const flush = () => {
|
|
196
|
-
if (run.length === 0)
|
|
197
|
-
return;
|
|
198
|
-
emit(state, body, merge(run));
|
|
199
|
-
run = [];
|
|
200
|
-
length = 0;
|
|
201
|
-
};
|
|
202
|
-
for (const unit of units) {
|
|
203
|
-
if (run.length > 0 && length + unit.text.length > available(state, body))
|
|
204
|
-
flush();
|
|
205
|
-
if (unit.text.length > available(state, body)) {
|
|
206
|
-
flush();
|
|
207
|
-
unit.descend();
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
run.push(unit);
|
|
211
|
-
length += unit.text.length;
|
|
212
|
-
}
|
|
213
|
-
flush();
|
|
214
|
-
}
|
|
215
|
-
function divideBound(state, body, cutting, range) {
|
|
216
|
-
let start = range.start;
|
|
217
|
-
while (start < range.end) {
|
|
218
|
-
const bare = available(state, body) < characterLength(cutting.text, start);
|
|
219
|
-
const room = bare ? state.bound : available(state, body);
|
|
220
|
-
const stop = boundOf(cutting, start, range.end, room);
|
|
221
|
-
const piece = cutting.piece(start, stop);
|
|
222
|
-
if (cutting.masks.length === 0 || piece.text.length <= room) {
|
|
223
|
-
emit(state, body, piece, bare);
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
divideBound(state, body, valueCutting(piece), { start: 0, end: piece.text.length });
|
|
227
|
-
}
|
|
228
|
-
start = stop;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
function divideSentences(state, body, cutting) {
|
|
232
|
-
const cut = cutting.piece;
|
|
233
|
-
const bounds = sentenceBounds(cutting.text);
|
|
234
|
-
let index = 0;
|
|
235
|
-
while (index + 1 < bounds.length) {
|
|
236
|
-
const alone = { start: bounds[index], end: bounds[index + 1] };
|
|
237
|
-
if (cut(alone.start, alone.end).text.length > available(state, body)) {
|
|
238
|
-
divideBound(state, body, cutting, alone);
|
|
239
|
-
index += 1;
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
const carried = bounds[Math.max(index - 1, 0)];
|
|
243
|
-
const from = cut(carried, alone.end).text.length <= available(state, body) ? carried : alone.start;
|
|
244
|
-
let last = index;
|
|
245
|
-
while (last + 2 < bounds.length &&
|
|
246
|
-
cut(from, bounds[last + 2]).text.length <= available(state, body)) {
|
|
247
|
-
last += 1;
|
|
248
|
-
}
|
|
249
|
-
emit(state, body, cut(from, bounds[last + 1]));
|
|
250
|
-
index = last + 1;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
function blockUnit(state, body, block) {
|
|
254
|
-
return {
|
|
255
|
-
start: block.start,
|
|
256
|
-
end: block.end,
|
|
257
|
-
text: textOf(state, block),
|
|
258
|
-
descend: () => divideSentences(state, body, sourceCutting(state, block)),
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
function valueUnit(state, body, value) {
|
|
262
|
-
return {
|
|
263
|
-
start: value.start,
|
|
264
|
-
end: value.end,
|
|
265
|
-
text: value.text,
|
|
266
|
-
descend: () => divideSentences(state, body, valueCutting(value)),
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
function nodeUnit(state, subject) {
|
|
270
|
-
return {
|
|
271
|
-
start: subject.start,
|
|
272
|
-
end: subject.end,
|
|
273
|
-
text: textOf(state, subject),
|
|
274
|
-
descend: () => divideNode(state, subject),
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
function ownBlocks(subject, end, blocks) {
|
|
278
|
-
const first = blocks[0];
|
|
279
|
-
return first === undefined
|
|
280
|
-
? [{ start: subject.start, end }]
|
|
281
|
-
: [{ start: subject.start, end: first.end }, ...blocks.slice(1)];
|
|
282
|
-
}
|
|
283
|
-
function divideNode(state, subject) {
|
|
284
|
-
const end = subject.children[0]?.start ?? subject.end;
|
|
285
|
-
const blocks = blockRanges(state.reading, subject.bodyStart, end);
|
|
286
|
-
const children = { heading: '', emitted: 0 };
|
|
287
|
-
if (blocks.length === 0 && subject.children.length > 0) {
|
|
288
|
-
const [first, ...rest] = subject.children;
|
|
289
|
-
const led = [{ ...first, start: subject.start }, ...rest];
|
|
290
|
-
divideUnits(state, children, led.map((child) => nodeUnit(state, child)));
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
const body = { heading: subject.heading, emitted: 0 };
|
|
294
|
-
const own = ownBlocks(subject, end, blocks);
|
|
295
|
-
divideUnits(state, body, own.map((block) => blockUnit(state, body, block)));
|
|
296
|
-
divideUnits(state, children, subject.children.map((child) => nodeUnit(state, child)));
|
|
297
|
-
}
|
|
298
|
-
function divideInput(state, input) {
|
|
299
|
-
const body = { heading: '', emitted: 0 };
|
|
300
|
-
divideUnits(state, body, [
|
|
301
|
-
...input.values.map((value) => valueUnit(state, body, value)),
|
|
302
|
-
...input.ranges.flatMap((range) => forest(state, range).map((subject) => nodeUnit(state, subject))),
|
|
303
|
-
]);
|
|
304
|
-
}
|
|
305
|
-
export function divide(document, file, context) {
|
|
306
|
-
if (!Number.isInteger(context.bound) || context.bound < SMALLEST_BOUND) {
|
|
307
|
-
return { ok: false, refusal: refusal(file, 'division-bound') };
|
|
308
|
-
}
|
|
309
|
-
const result = projectionInput(document, file, context);
|
|
310
|
-
if (!result.ok)
|
|
311
|
-
return { ok: false, refusal: result.refusal };
|
|
312
|
-
const state = {
|
|
313
|
-
content: document.content,
|
|
314
|
-
reading: readingOf(document),
|
|
315
|
-
edits: result.input.edits,
|
|
316
|
-
bound: context.bound,
|
|
317
|
-
spans: [],
|
|
318
|
-
};
|
|
319
|
-
divideInput(state, result.input);
|
|
320
|
-
return { ok: true, spans: byteBounds(document.content, state.spans) };
|
|
321
|
-
}
|
package/dist/project.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Document, Extent, Projection, ProjectionContext, Refusal } from './types.js';
|
|
2
|
-
export type Piece = Extent & {
|
|
3
|
-
readonly text: string;
|
|
4
|
-
};
|
|
5
|
-
export type Edit = Piece;
|
|
6
|
-
export type Input = {
|
|
7
|
-
readonly values: readonly Piece[];
|
|
8
|
-
readonly ranges: readonly Extent[];
|
|
9
|
-
readonly edits: readonly Edit[];
|
|
10
|
-
};
|
|
11
|
-
export type InputResult = {
|
|
12
|
-
readonly ok: true;
|
|
13
|
-
readonly input: Input;
|
|
14
|
-
} | {
|
|
15
|
-
readonly ok: false;
|
|
16
|
-
readonly refusal: Refusal;
|
|
17
|
-
};
|
|
18
|
-
export declare function firstEditFrom(edits: readonly Edit[], start: number): number;
|
|
19
|
-
export declare function rangeText(content: string, range: Extent, edits: readonly Edit[]): string;
|
|
20
|
-
export declare function projectionInput(document: Document, file: string, context: ProjectionContext): InputResult;
|
|
21
|
-
export declare function project(document: Document, file: string, context?: ProjectionContext): Projection;
|
|
22
|
-
//# sourceMappingURL=project.d.ts.map
|
package/dist/project.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG3F,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC;AAEzB,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC5C;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAqCtD,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAS3E;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,MAAM,CAWxF;AAOD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,GACzB,WAAW,CA4Bb;AAED,wBAAgB,OAAO,CACrB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,iBAA2C,GACnD,UAAU,CAMZ"}
|
package/dist/project.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { bodyWith, readingOf } from './document.js';
|
|
2
|
-
import { classifyHref } from './paths.js';
|
|
3
|
-
import { refusal } from './refuse.js';
|
|
4
|
-
import { bodyStartOf } from './yaml.js';
|
|
5
|
-
function internalEdits(content, reading, file, documentTargets) {
|
|
6
|
-
const internal = new Set();
|
|
7
|
-
const uses = reading.uses
|
|
8
|
-
.filter((use) => {
|
|
9
|
-
const resolved = classifyHref(file, use.destination.href);
|
|
10
|
-
return (resolved.kind === 'room' || (resolved.kind === 'path' && documentTargets.has(resolved.path)));
|
|
11
|
-
})
|
|
12
|
-
.sort((left, right) => left.start - right.start);
|
|
13
|
-
const edits = [];
|
|
14
|
-
for (let index = uses.length - 1; index >= 0; index -= 1) {
|
|
15
|
-
const use = uses[index];
|
|
16
|
-
internal.add(use.destination.start);
|
|
17
|
-
const label = { start: use.labelStart, end: use.labelEnd };
|
|
18
|
-
const inner = [];
|
|
19
|
-
for (let nested = index + 1; nested < uses.length; nested += 1) {
|
|
20
|
-
const edit = edits[uses.length - 1 - nested];
|
|
21
|
-
if (edit.start >= label.end)
|
|
22
|
-
break;
|
|
23
|
-
if (edit.end <= label.end)
|
|
24
|
-
inner.push(edit);
|
|
25
|
-
}
|
|
26
|
-
edits.push({ start: use.start, end: use.end, text: rangeText(content, label, inner) });
|
|
27
|
-
}
|
|
28
|
-
for (const block of reading.definitions) {
|
|
29
|
-
if (!internal.has(block.destination.start))
|
|
30
|
-
continue;
|
|
31
|
-
edits.push({ start: block.start, end: block.end, text: '' });
|
|
32
|
-
}
|
|
33
|
-
return edits.sort((left, right) => left.start - right.start);
|
|
34
|
-
}
|
|
35
|
-
export function firstEditFrom(edits, start) {
|
|
36
|
-
let low = 0;
|
|
37
|
-
let high = edits.length;
|
|
38
|
-
while (low < high) {
|
|
39
|
-
const middle = (low + high) >>> 1;
|
|
40
|
-
if (edits[middle].start < start)
|
|
41
|
-
low = middle + 1;
|
|
42
|
-
else
|
|
43
|
-
high = middle;
|
|
44
|
-
}
|
|
45
|
-
return low;
|
|
46
|
-
}
|
|
47
|
-
export function rangeText(content, range, edits) {
|
|
48
|
-
let text = '';
|
|
49
|
-
let cursor = range.start;
|
|
50
|
-
for (let index = firstEditFrom(edits, range.start); index < edits.length; index += 1) {
|
|
51
|
-
const edit = edits[index];
|
|
52
|
-
if (edit.start > range.end)
|
|
53
|
-
break;
|
|
54
|
-
if (edit.start < cursor || edit.end > range.end)
|
|
55
|
-
continue;
|
|
56
|
-
text += content.slice(cursor, edit.start) + edit.text;
|
|
57
|
-
cursor = edit.end;
|
|
58
|
-
}
|
|
59
|
-
return text + content.slice(cursor, range.end);
|
|
60
|
-
}
|
|
61
|
-
function linked(edits, range) {
|
|
62
|
-
const at = firstEditFrom(edits, range.start);
|
|
63
|
-
return at < edits.length && edits[at].start < range.end;
|
|
64
|
-
}
|
|
65
|
-
export function projectionInput(document, file, context) {
|
|
66
|
-
const content = document.content;
|
|
67
|
-
const bodyStart = bodyStartOf(content);
|
|
68
|
-
const reading = readingOf(document);
|
|
69
|
-
const edits = internalEdits(content, reading, file, new Set(context.documentTargets));
|
|
70
|
-
const declared = document.type;
|
|
71
|
-
const definition = context.definition;
|
|
72
|
-
if (definition === undefined && declared !== undefined && declared !== 'any')
|
|
73
|
-
return { ok: false, refusal: refusal(file, 'unknown-type') };
|
|
74
|
-
const body = definition === undefined ? null : bodyWith(document, definition);
|
|
75
|
-
if (body === null || !('top' in body)) {
|
|
76
|
-
return {
|
|
77
|
-
ok: true,
|
|
78
|
-
input: { values: [], ranges: [{ start: bodyStart, end: content.length }], edits },
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
const values = body.prose
|
|
82
|
-
.filter((one) => !one.markdown)
|
|
83
|
-
.map((one) => ({
|
|
84
|
-
start: one.start,
|
|
85
|
-
end: one.end,
|
|
86
|
-
text: `${linked(edits, one) ? rangeText(content, one, edits) : one.text}\n\n`,
|
|
87
|
-
}));
|
|
88
|
-
const ranges = [
|
|
89
|
-
...body.prose.filter((one) => one.markdown).map(({ start, end }) => ({ start, end })),
|
|
90
|
-
...body.free,
|
|
91
|
-
].sort((left, right) => left.start - right.start);
|
|
92
|
-
return { ok: true, input: { values, ranges, edits } };
|
|
93
|
-
}
|
|
94
|
-
export function project(document, file, context = { documentTargets: [] }) {
|
|
95
|
-
const result = projectionInput(document, file, context);
|
|
96
|
-
if (!result.ok)
|
|
97
|
-
return { ok: false, refusal: result.refusal };
|
|
98
|
-
const { values, ranges, edits } = result.input;
|
|
99
|
-
const prose = ranges.map((range) => rangeText(document.content, range, edits)).join('');
|
|
100
|
-
return { ok: true, text: values.map((value) => value.text).join('') + prose };
|
|
101
|
-
}
|