@agentshouse/mdmodel 0.1.0-c04c0d681d2d4 → 0.1.0-c08b2adadd2fe
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 +150 -110
- package/README.md +8 -6
- package/dist/definition.d.ts +3 -1
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +138 -26
- package/dist/divide.d.ts.map +1 -1
- package/dist/divide.js +5 -4
- package/dist/document.d.ts +9 -5
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +169 -67
- package/dist/event.d.ts +78 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +201 -0
- package/dist/facts.d.ts +15 -0
- package/dist/facts.d.ts.map +1 -0
- package/dist/facts.js +41 -0
- package/dist/index.d.ts +23 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -7
- package/dist/kinds.d.ts +18 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/kinds.js +150 -0
- package/dist/markdown.d.ts +51 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +271 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +9 -2
- package/dist/pattern.d.ts +10 -0
- package/dist/pattern.d.ts.map +1 -0
- package/dist/pattern.js +356 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +16 -21
- package/dist/query/language.d.ts +254 -0
- package/dist/query/language.d.ts.map +1 -0
- package/dist/query/language.js +620 -0
- package/dist/query/match.d.ts +14 -0
- package/dist/query/match.d.ts.map +1 -0
- package/dist/query/match.js +150 -0
- package/dist/query/rows.d.ts +32 -0
- package/dist/query/rows.d.ts.map +1 -0
- package/dist/query/rows.js +161 -0
- package/dist/query/sql.d.ts +39 -0
- package/dist/query/sql.d.ts.map +1 -0
- package/dist/query/sql.js +285 -0
- package/dist/reserved.d.ts +6 -0
- package/dist/reserved.d.ts.map +1 -0
- package/dist/reserved.js +21 -0
- package/dist/schema.d.ts +1 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +55 -4
- package/dist/types.d.ts +19 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +29 -5
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +327 -161
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +40 -14
- package/fixtures/README.md +25 -3
- package/fixtures/cases/conditional-section/context.json +1 -0
- package/fixtures/cases/conditional-section/expected.json +6 -0
- package/fixtures/cases/conditional-section/library/questions/hosting.md +9 -0
- package/fixtures/cases/conditional-section/library/questions/payments.md +12 -0
- package/fixtures/cases/conditional-section/schema.yaml +14 -0
- package/fixtures/cases/lazy-list-item/context.json +1 -0
- package/fixtures/cases/lazy-list-item/expected.json +3 -0
- package/fixtures/cases/lazy-list-item/library/item.md +8 -0
- package/fixtures/cases/lazy-list-item/schema.yaml +3 -0
- package/fixtures/cases/link-into-a-reserved-name/context.json +1 -0
- package/fixtures/cases/link-into-a-reserved-name/expected.json +5 -0
- package/fixtures/cases/link-into-a-reserved-name/library/notes/a.md +6 -0
- package/fixtures/cases/link-into-a-reserved-name/schema.yaml +3 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/context.json +1 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/expected.json +5 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/library/notes/b.md +5 -0
- package/fixtures/cases/member-on-an-untyped-document/context.json +1 -0
- package/fixtures/cases/member-on-an-untyped-document/expected.json +6 -0
- package/fixtures/cases/member-on-an-untyped-document/library/note.md +4 -0
- package/fixtures/cases/member-on-another-type/context.json +1 -0
- package/fixtures/cases/member-on-another-type/expected.json +6 -0
- package/fixtures/cases/member-on-another-type/library/note.md +4 -0
- package/fixtures/cases/member-on-another-type/schema.yaml +7 -0
- package/fixtures/cases/reference-into-a-reserved-name/context.json +1 -0
- package/fixtures/cases/reference-into-a-reserved-name/expected.json +6 -0
- package/fixtures/cases/reference-into-a-reserved-name/library/notes/a.md +4 -0
- package/fixtures/cases/reference-into-a-reserved-name/library/settings/brief.md +1 -0
- package/fixtures/cases/reference-into-a-reserved-name/schema.yaml +3 -0
- package/fixtures/cases/room-md-declares-a-type/context.json +1 -0
- package/fixtures/cases/room-md-declares-a-type/expected.json +6 -0
- package/fixtures/cases/room-md-declares-a-type/library/ROOM.md +5 -0
- package/fixtures/cases/thematic-break-in-a-list-section/context.json +1 -0
- package/fixtures/cases/thematic-break-in-a-list-section/expected.json +6 -0
- package/fixtures/cases/thematic-break-in-a-list-section/library/item.md +7 -0
- package/fixtures/cases/thematic-break-in-a-list-section/schema.yaml +3 -0
- package/fixtures/cases/typed-path-names-another-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-another-type/expected.json +6 -0
- package/fixtures/cases/typed-path-names-another-type/library/settings/prefs/one.md +3 -0
- package/fixtures/cases/typed-path-names-another-type/schema.yaml +6 -0
- package/fixtures/cases/typed-path-names-its-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-its-type/expected.json +3 -0
- package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/deeper/two.md +1 -0
- package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/one.md +4 -0
- package/fixtures/cases/typed-path-names-its-type/schema.yaml +6 -0
- package/fixtures/cases/typed-path-names-no-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-no-type/expected.json +6 -0
- package/fixtures/cases/typed-path-names-no-type/library/settings/prefs/one.md +1 -0
- package/fixtures/cases/typed-path-names-no-type/schema.yaml +6 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/expected.json +6 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/library/rooms/team/tasks/plan.md +4 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/expected.json +6 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/library/rooms/team/tasks/plan.md +6 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/expected.json +3 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/plan.md +1 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/tasks/plan.md +5 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/expected.json +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/library/rooms/team/tasks/plan.md +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/schema.yaml +5 -0
- package/fixtures/division.json +47 -2
- package/fixtures/preamble.json +24 -3
- package/fixtures/projection.json +105 -2
- package/fixtures/queries.json +964 -0
- package/package.json +16 -2
- package/dist/blocks.d.ts +0 -11
- package/dist/blocks.d.ts.map +0 -1
- package/dist/blocks.js +0 -69
- package/dist/condition.d.ts +0 -162
- package/dist/condition.d.ts.map +0 -1
- package/dist/condition.js +0 -616
- package/dist/links.d.ts +0 -29
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -788
- package/dist/profile.d.ts +0 -6
- package/dist/profile.d.ts.map +0 -1
- package/dist/profile.js +0 -5
- package/dist/sections.d.ts +0 -11
- package/dist/sections.d.ts.map +0 -1
- package/dist/sections.js +0 -57
package/dist/facts.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Document, ParseResult, VerifiedModel } from './types.js';
|
|
2
|
+
export type SavedFacts = {
|
|
3
|
+
readonly type: string;
|
|
4
|
+
readonly fields: Readonly<Record<string, unknown>>;
|
|
5
|
+
readonly links: readonly string[];
|
|
6
|
+
};
|
|
7
|
+
export type ReferenceTarget = {
|
|
8
|
+
readonly location: string;
|
|
9
|
+
readonly to: readonly string[];
|
|
10
|
+
readonly target: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function referenceTarget(file: string, value: string): string | null;
|
|
13
|
+
export declare function referenceTargets(document: Document, file: string, model: VerifiedModel): readonly ReferenceTarget[];
|
|
14
|
+
export declare function documentFacts(file: string, parsed: ParseResult, model: VerifiedModel): SavedFacts | null;
|
|
15
|
+
//# sourceMappingURL=facts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facts.d.ts","sourceRoot":"","sources":["../src/facts.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEvE,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAIF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM1E;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,aAAa,GACnB,SAAS,eAAe,EAAE,CAO5B;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,aAAa,GACnB,UAAU,GAAG,IAAI,CAenB"}
|
package/dist/facts.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BUILT_IN_TYPE } from './definition.js';
|
|
2
|
+
import { links, parse } from './document.js';
|
|
3
|
+
import { target } from './paths.js';
|
|
4
|
+
import { references } from './references.js';
|
|
5
|
+
const SETTINGS_AREA = 'settings/';
|
|
6
|
+
export function referenceTarget(file, value) {
|
|
7
|
+
if (value.trim() === '' || /[<>\n\r]/.test(value))
|
|
8
|
+
return null;
|
|
9
|
+
if (!value.includes('\\'))
|
|
10
|
+
return target(file, value);
|
|
11
|
+
const parsed = parse(`[](<${value}>)\n`, file);
|
|
12
|
+
if (!parsed.ok)
|
|
13
|
+
return null;
|
|
14
|
+
return links(parsed.document, file)[0]?.target ?? null;
|
|
15
|
+
}
|
|
16
|
+
export function referenceTargets(document, file, model) {
|
|
17
|
+
const type = document.type;
|
|
18
|
+
if (type === undefined || !Object.hasOwn(model.types, type))
|
|
19
|
+
return [];
|
|
20
|
+
return references(document, model.types[type]).flatMap(({ pointer, value, to }) => {
|
|
21
|
+
const target = referenceTarget(file, value);
|
|
22
|
+
return target === null ? [] : [{ location: pointer, to, target }];
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export function documentFacts(file, parsed, model) {
|
|
26
|
+
if (!parsed.ok)
|
|
27
|
+
return null;
|
|
28
|
+
const { document } = parsed;
|
|
29
|
+
return {
|
|
30
|
+
type: document.type ?? BUILT_IN_TYPE,
|
|
31
|
+
fields: document.fields,
|
|
32
|
+
links: file.startsWith(SETTINGS_AREA)
|
|
33
|
+
? []
|
|
34
|
+
: [
|
|
35
|
+
...new Set([
|
|
36
|
+
...links(document, file).map((link) => link.target),
|
|
37
|
+
...referenceTargets(document, file, model).map(({ target }) => target),
|
|
38
|
+
]),
|
|
39
|
+
].sort(),
|
|
40
|
+
};
|
|
41
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type { Actor,
|
|
3
|
-
export {
|
|
4
|
-
export type {
|
|
1
|
+
export { candidateOf, datePointers, facts, memberPointers, members, pointed, prosePaths, TEXT_FIELD, valuedChange, WRITE_DOORS, } from './event.js';
|
|
2
|
+
export type { Actor, DocumentEvent, DocumentFacts, Fact, ItemFacts, MessageFacts, Resolved, WriteDoor, } from './event.js';
|
|
3
|
+
export { byCodePoint, compared, dated, fitsKind, instant, instantKey, kindOf, kindWords, } from './kinds.js';
|
|
4
|
+
export type { Kind, Ordering } from './kinds.js';
|
|
5
|
+
export { bodied, cursorOf, decodedCursor, identityOf, invalid, known, placeText, planOf, QueryError, queryKey, } from './query/language.js';
|
|
6
|
+
export type { Clause, Continuation, Direction, DocumentQuery, DocumentShape, Filter, GroupKey, GroupOrder, GroupQuery, GroupSelect, GroupShape, HeldRooms, Key, KeyPlan, LocalQuery, OrderOptions, Place, Predicate, QueryErrorCode, QueryPlan, Related, RoomFacts, Scope, Select, Test, Value, Where, } from './query/language.js';
|
|
7
|
+
export { heldAt, matches } from './query/match.js';
|
|
8
|
+
export type { Candidate } from './query/match.js';
|
|
9
|
+
export { heldKind, indexed } from './query/rows.js';
|
|
10
|
+
export type { HeldKind, HeldLink, HeldValue, Indexed, Reach } from './query/rows.js';
|
|
11
|
+
export * as sql from './query/sql.js';
|
|
12
|
+
export { headingLines } from './markdown.js';
|
|
13
|
+
export type { HeadingLine } from './markdown.js';
|
|
5
14
|
export { divide } from './divide.js';
|
|
6
|
-
export { apply, bodyLinks, links, parse, parseFrontmatter, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
|
|
15
|
+
export { apply, bodyLinks, create, links, parse, parseFrontmatter, relativize, relativizeBody, relinkBody, serialize, textSpans, unlinkBody, } from './document.js';
|
|
16
|
+
export { documentFacts, referenceTarget, referenceTargets } from './facts.js';
|
|
17
|
+
export type { ReferenceTarget, SavedFacts } from './facts.js';
|
|
7
18
|
export { HOUSE_FIELDS, MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
|
|
8
19
|
export { relative, retarget, roomPath, roomTarget, target } from './paths.js';
|
|
20
|
+
export { openPatternBudget } from './pattern.js';
|
|
9
21
|
export type { RoomTarget } from './paths.js';
|
|
10
|
-
export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
|
|
11
22
|
export { project } from './project.js';
|
|
12
23
|
export { references } from './references.js';
|
|
13
|
-
export {
|
|
24
|
+
export { CAPTURE_HOME, isDocumentPath, isReservedName, RESERVED_NAMES, ROOM_DESCRIPTION, } from './reserved.js';
|
|
25
|
+
export { ARRAY_INDEX, ATTACHMENT, crossedFacts, escapePointer, itemFacts, JSON_POINTER, memberFacts, pointerFacts, pointerSegments, untitled, } from './definition.js';
|
|
14
26
|
export type { Definition, FieldRules, JsonType, PatternFacts, PointerFacts, RuleValue, SectionSpec, Shape, Transition, ValueFacts, } from './definition.js';
|
|
15
|
-
export type { ApplyResult, BodyResult, Change, Division, DivisionContext, Document, DocumentCheck, Frontmatter, FrontmatterResult, Library, ModelVerification, Link, ParseResult, Projection, ProjectionContext, Reached, Reference, Refusal, RoomReference, Span, Validation, ValidationContext, ValidationStep, VerifiedModel, } from './types.js';
|
|
16
|
-
export { bodyRoomLinks, checkDocument, resolves, roomReferences,
|
|
27
|
+
export type { ApplyResult, BodyResult, Change, DefinitionOf, Division, DivisionContext, Document, DocumentCheck, Frontmatter, FrontmatterResult, Library, ModelVerification, Link, ParseResult, Projection, ProjectionContext, Reached, Reference, Refusal, RoomReference, Span, TypedPath, UnlinkedBody, Validation, ValidationContext, ValidationStep, VerifiedModel, } from './types.js';
|
|
28
|
+
export { assess, assessReferences, bodyRoomLinks, checkDocument, definitionAt, readTypes, resolves, roomReferences, validate, validating, verdicts, verify, } from './validate.js';
|
|
29
|
+
export type { Assessment, Verdicts } from './validate.js';
|
|
17
30
|
export { VERSION } from './version.js';
|
|
18
|
-
export { bodyAfterFrontmatter, equalValue, frontmatterValue } from './yaml.js';
|
|
31
|
+
export { bodyAfterFrontmatter, equalValue, frontmatterValue, plain } from './yaml.js';
|
|
19
32
|
export type { FrontmatterValue } from './yaml.js';
|
|
20
33
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,cAAc,EACd,YAAY,EACZ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,KAAK,EACL,cAAc,EACd,OAAO,EACP,OAAO,EACP,UAAU,EACV,UAAU,EACV,YAAY,EACZ,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,KAAK,EACL,aAAa,EACb,aAAa,EACb,IAAI,EACJ,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,SAAS,GACV,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,WAAW,EACX,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,OAAO,EACP,UAAU,EACV,MAAM,EACN,SAAS,GACV,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EACL,MAAM,EACN,QAAQ,EACR,aAAa,EACb,UAAU,EACV,OAAO,EACP,KAAK,EACL,SAAS,EACT,MAAM,EACN,UAAU,EACV,QAAQ,GACT,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,MAAM,EACN,YAAY,EACZ,SAAS,EACT,aAAa,EACb,aAAa,EACb,MAAM,EACN,QAAQ,EACR,UAAU,EACV,UAAU,EACV,WAAW,EACX,UAAU,EACV,SAAS,EACT,GAAG,EACH,OAAO,EACP,UAAU,EACV,YAAY,EACZ,KAAK,EACL,SAAS,EACT,cAAc,EACd,SAAS,EACT,OAAO,EACP,SAAS,E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|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { candidateOf, datePointers, facts, memberPointers, members, pointed, prosePaths, TEXT_FIELD, valuedChange, WRITE_DOORS, } from './event.js';
|
|
2
|
+
export { byCodePoint, compared, dated, fitsKind, instant, instantKey, kindOf, kindWords, } from './kinds.js';
|
|
3
|
+
export { bodied, cursorOf, decodedCursor, identityOf, invalid, known, placeText, planOf, QueryError, queryKey, } from './query/language.js';
|
|
4
|
+
export { heldAt, matches } from './query/match.js';
|
|
5
|
+
export { heldKind, indexed } from './query/rows.js';
|
|
6
|
+
export * as sql from './query/sql.js';
|
|
7
|
+
export { headingLines } from './markdown.js';
|
|
3
8
|
export { divide } from './divide.js';
|
|
4
|
-
export { apply, bodyLinks, links, parse, parseFrontmatter, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
|
|
9
|
+
export { apply, bodyLinks, create, links, parse, parseFrontmatter, relativize, relativizeBody, relinkBody, serialize, textSpans, unlinkBody, } from './document.js';
|
|
10
|
+
export { documentFacts, referenceTarget, referenceTargets } from './facts.js';
|
|
5
11
|
export { HOUSE_FIELDS, MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
|
|
6
12
|
export { relative, retarget, roomPath, roomTarget, target } from './paths.js';
|
|
7
|
-
export {
|
|
13
|
+
export { openPatternBudget } from './pattern.js';
|
|
8
14
|
export { project } from './project.js';
|
|
9
15
|
export { references } from './references.js';
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
16
|
+
export { CAPTURE_HOME, isDocumentPath, isReservedName, RESERVED_NAMES, ROOM_DESCRIPTION, } from './reserved.js';
|
|
17
|
+
export { ARRAY_INDEX, ATTACHMENT, crossedFacts, escapePointer, itemFacts, JSON_POINTER, memberFacts, pointerFacts, pointerSegments, untitled, } from './definition.js';
|
|
18
|
+
export { assess, assessReferences, bodyRoomLinks, checkDocument, definitionAt, readTypes, resolves, roomReferences, validate, validating, verdicts, verify, } from './validate.js';
|
|
12
19
|
export { VERSION } from './version.js';
|
|
13
|
-
export { bodyAfterFrontmatter, equalValue, frontmatterValue } from './yaml.js';
|
|
20
|
+
export { bodyAfterFrontmatter, equalValue, frontmatterValue, plain } from './yaml.js';
|
package/dist/kinds.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ValueFacts } from './definition.js';
|
|
2
|
+
export type Kind = 'string' | 'number' | 'integer' | 'boolean' | 'date' | 'date-time' | 'time' | 'enum' | 'reference';
|
|
3
|
+
export type Ordering = {
|
|
4
|
+
readonly direction: 'asc' | 'desc';
|
|
5
|
+
readonly nulls: 'first' | 'last';
|
|
6
|
+
readonly stringSort: 'lexical' | 'locale';
|
|
7
|
+
readonly locale: string | undefined;
|
|
8
|
+
readonly localeOptions: Intl.CollatorOptions | undefined;
|
|
9
|
+
};
|
|
10
|
+
export declare function kindOf(facts: ValueFacts): Kind | null;
|
|
11
|
+
export declare function fitsKind(kind: Kind, facts: ValueFacts, value: unknown): boolean;
|
|
12
|
+
export declare function kindWords(facts: ValueFacts | undefined): readonly string[];
|
|
13
|
+
export declare function dated(value: unknown): value is string;
|
|
14
|
+
export declare function instant(value: unknown): bigint | undefined;
|
|
15
|
+
export declare function instantKey(value: unknown): string | null;
|
|
16
|
+
export declare function byCodePoint(left: string, right: string): number;
|
|
17
|
+
export declare function compared(left: unknown, right: unknown, ordering: Ordering): number;
|
|
18
|
+
//# sourceMappingURL=kinds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../src/kinds.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,MAAM,MAAM,IAAI,GACZ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,SAAS,GACT,MAAM,GACN,WAAW,GACX,MAAM,GACN,MAAM,GACN,WAAW,CAAC;AAEhB,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ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2}))?)$/u;
|
|
4
|
+
const BEFORE_YEAR_ZERO = 62200000000000000000n;
|
|
5
|
+
const INSTANT_DIGITS = 21;
|
|
6
|
+
export function kindOf(facts) {
|
|
7
|
+
if (facts.reference !== undefined)
|
|
8
|
+
return 'reference';
|
|
9
|
+
if (facts.values !== undefined)
|
|
10
|
+
return 'enum';
|
|
11
|
+
if (facts.type === 'number')
|
|
12
|
+
return 'number';
|
|
13
|
+
if (facts.type === 'integer')
|
|
14
|
+
return 'integer';
|
|
15
|
+
if (facts.type === 'boolean')
|
|
16
|
+
return 'boolean';
|
|
17
|
+
if (facts.type !== 'string')
|
|
18
|
+
return null;
|
|
19
|
+
if (facts.format === 'date')
|
|
20
|
+
return 'date';
|
|
21
|
+
if (facts.format === 'date-time')
|
|
22
|
+
return 'date-time';
|
|
23
|
+
if (facts.format === 'time')
|
|
24
|
+
return 'time';
|
|
25
|
+
return 'string';
|
|
26
|
+
}
|
|
27
|
+
export function fitsKind(kind, facts, value) {
|
|
28
|
+
if (kind === 'enum')
|
|
29
|
+
return (facts.values ?? []).includes(value);
|
|
30
|
+
if (kind === 'number')
|
|
31
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
32
|
+
if (kind === 'integer')
|
|
33
|
+
return Number.isSafeInteger(value);
|
|
34
|
+
if (kind === 'boolean')
|
|
35
|
+
return typeof value === 'boolean';
|
|
36
|
+
if (typeof value !== 'string')
|
|
37
|
+
return false;
|
|
38
|
+
if (kind === 'reference')
|
|
39
|
+
return value !== '' && normalize(value) === value;
|
|
40
|
+
if (kind === 'date')
|
|
41
|
+
return dated(value);
|
|
42
|
+
if (kind === 'date-time')
|
|
43
|
+
return instant(value) !== undefined;
|
|
44
|
+
if (kind === 'time')
|
|
45
|
+
return format.time(value);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
export function kindWords(facts) {
|
|
49
|
+
const kind = facts === undefined ? null : kindOf(facts);
|
|
50
|
+
if (kind === 'enum')
|
|
51
|
+
return (facts.values ?? []).map((value) => typeof value === 'string' ? value : JSON.stringify(value));
|
|
52
|
+
if (kind === 'number')
|
|
53
|
+
return ['a number'];
|
|
54
|
+
if (kind === 'integer')
|
|
55
|
+
return ['an integer'];
|
|
56
|
+
if (kind === 'boolean')
|
|
57
|
+
return ['true', 'false'];
|
|
58
|
+
if (kind === 'date')
|
|
59
|
+
return ['a date as YYYY-MM-DD'];
|
|
60
|
+
if (kind === 'date-time')
|
|
61
|
+
return ['a date-time with its offset, such as 2026-10-10T09:30:00Z'];
|
|
62
|
+
if (kind === 'time')
|
|
63
|
+
return ['a time as HH:MM:SS'];
|
|
64
|
+
if (kind === 'reference')
|
|
65
|
+
return [`the Room Path of a ${facts.reference.join(' or ')} document, such as notes/a.md`];
|
|
66
|
+
return kind === 'string' ? ['a string'] : [];
|
|
67
|
+
}
|
|
68
|
+
export function dated(value) {
|
|
69
|
+
return typeof value === 'string' && format.date(value);
|
|
70
|
+
}
|
|
71
|
+
export function instant(value) {
|
|
72
|
+
if (typeof value !== 'string' || !format['date-time'](value))
|
|
73
|
+
return undefined;
|
|
74
|
+
const parts = DATE_TIME.exec(value);
|
|
75
|
+
const [year, month, day, hour, minute, second, offsetHours, offsetMinutes] = [
|
|
76
|
+
1, 2, 3, 4, 5, 6, 9, 10,
|
|
77
|
+
].map((at) => Number(parts[at] ?? 0));
|
|
78
|
+
const at = new Date(0);
|
|
79
|
+
at.setUTCFullYear(year, month - 1, day);
|
|
80
|
+
at.setUTCHours(hour, minute, second);
|
|
81
|
+
const offset = (parts[8] === '-' ? -1 : 1) * (offsetHours * 60 + offsetMinutes);
|
|
82
|
+
const fraction = (parts[7] ?? '').padEnd(9, '0').slice(0, 9);
|
|
83
|
+
return (BigInt(at.getTime()) - BigInt(offset) * 60000n) * 1000000n + BigInt(fraction);
|
|
84
|
+
}
|
|
85
|
+
export function instantKey(value) {
|
|
86
|
+
const at = instant(value);
|
|
87
|
+
return at === undefined ? null : (at + BEFORE_YEAR_ZERO).toString().padStart(INSTANT_DIGITS, '0');
|
|
88
|
+
}
|
|
89
|
+
function rank(value) {
|
|
90
|
+
if (typeof value === 'boolean' || typeof value === 'number')
|
|
91
|
+
return 1;
|
|
92
|
+
if (typeof value === 'string')
|
|
93
|
+
return 2;
|
|
94
|
+
return Array.isArray(value) ? 3 : 4;
|
|
95
|
+
}
|
|
96
|
+
function unit(code) {
|
|
97
|
+
if (code >= 0xd800 && code < 0xe000)
|
|
98
|
+
return code + 0x2000;
|
|
99
|
+
return code >= 0xe000 ? code - 0x800 : code;
|
|
100
|
+
}
|
|
101
|
+
export function byCodePoint(left, right) {
|
|
102
|
+
for (let at = 0; at < Math.min(left.length, right.length); at += 1) {
|
|
103
|
+
const ours = left.charCodeAt(at);
|
|
104
|
+
const theirs = right.charCodeAt(at);
|
|
105
|
+
if (ours !== theirs)
|
|
106
|
+
return unit(ours) - unit(theirs);
|
|
107
|
+
}
|
|
108
|
+
return left.length - right.length;
|
|
109
|
+
}
|
|
110
|
+
function ascending(left, right, ordering) {
|
|
111
|
+
if (left == null && right == null)
|
|
112
|
+
return 0;
|
|
113
|
+
if (left == null)
|
|
114
|
+
return ordering.nulls === 'first' ? -1 : 1;
|
|
115
|
+
if (right == null)
|
|
116
|
+
return ordering.nulls === 'first' ? 1 : -1;
|
|
117
|
+
const ranked = rank(left) - rank(right);
|
|
118
|
+
if (ranked !== 0)
|
|
119
|
+
return ranked;
|
|
120
|
+
if (typeof left === 'string' && typeof right === 'string') {
|
|
121
|
+
return ordering.stringSort === 'locale'
|
|
122
|
+
? left.localeCompare(right, ordering.locale, ordering.localeOptions)
|
|
123
|
+
: byCodePoint(left, right);
|
|
124
|
+
}
|
|
125
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
126
|
+
for (let at = 0; at < Math.min(left.length, right.length); at += 1) {
|
|
127
|
+
const result = ascending(left[at], right[at], ordering);
|
|
128
|
+
if (result !== 0)
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
return left.length - right.length;
|
|
132
|
+
}
|
|
133
|
+
if (typeof left === 'object')
|
|
134
|
+
return 0;
|
|
135
|
+
const held = left;
|
|
136
|
+
const other = right;
|
|
137
|
+
if (held < other)
|
|
138
|
+
return -1;
|
|
139
|
+
if (held > other)
|
|
140
|
+
return 1;
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
export function compared(left, right, ordering) {
|
|
144
|
+
if (ordering.direction === 'asc')
|
|
145
|
+
return ascending(left, right, ordering);
|
|
146
|
+
return ascending(right, left, {
|
|
147
|
+
...ordering,
|
|
148
|
+
nulls: ordering.nulls === 'first' ? 'last' : 'first',
|
|
149
|
+
});
|
|
150
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Extent } from './types.js';
|
|
2
|
+
export type HeadingLine = {
|
|
3
|
+
readonly level: number;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly start: number;
|
|
6
|
+
readonly textEnd: number;
|
|
7
|
+
readonly next: number;
|
|
8
|
+
};
|
|
9
|
+
export type HrefOccurrence = {
|
|
10
|
+
readonly href: string;
|
|
11
|
+
readonly start: number;
|
|
12
|
+
readonly end: number;
|
|
13
|
+
readonly bracketed: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type LinkUse = {
|
|
16
|
+
readonly start: number;
|
|
17
|
+
readonly end: number;
|
|
18
|
+
readonly labelStart: number;
|
|
19
|
+
readonly labelEnd: number;
|
|
20
|
+
readonly destination: HrefOccurrence;
|
|
21
|
+
};
|
|
22
|
+
export type DefinitionBlock = {
|
|
23
|
+
readonly start: number;
|
|
24
|
+
readonly end: number;
|
|
25
|
+
readonly destination: HrefOccurrence;
|
|
26
|
+
};
|
|
27
|
+
export type Block = Extent & {
|
|
28
|
+
readonly items: readonly Extent[] | null;
|
|
29
|
+
};
|
|
30
|
+
export type Reading = {
|
|
31
|
+
readonly headings: readonly HeadingLine[];
|
|
32
|
+
readonly blocks: readonly Block[];
|
|
33
|
+
readonly uses: readonly LinkUse[];
|
|
34
|
+
readonly definitions: readonly DefinitionBlock[];
|
|
35
|
+
};
|
|
36
|
+
export declare function read(text: string, at?: number): Reading;
|
|
37
|
+
export declare function destinations(reading: Reading): readonly HrefOccurrence[];
|
|
38
|
+
export declare function hrefOccurrences(body: string): readonly HrefOccurrence[];
|
|
39
|
+
export declare function headingLines(content: string, from: number, to: number): HeadingLine[];
|
|
40
|
+
export type SectionSpan = {
|
|
41
|
+
readonly name: string;
|
|
42
|
+
readonly headingStart: number;
|
|
43
|
+
readonly bodyStart: number;
|
|
44
|
+
readonly bodyEnd: number;
|
|
45
|
+
};
|
|
46
|
+
export declare function sectionSpans(reading: Reading, end: number): SectionSpan[];
|
|
47
|
+
export declare function sectionsRecord(spans: readonly SectionSpan[], content: string): Record<string, string>;
|
|
48
|
+
export declare function headingsIn(reading: Reading, from: number, to: number): readonly HeadingLine[];
|
|
49
|
+
export declare function listItems(reading: Reading, from: number, to: number): Extent[] | null;
|
|
50
|
+
export declare function blockRanges(reading: Reading, from: number, to: number): Extent[];
|
|
51
|
+
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE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AAE,CAErF;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,WAAW,EAAE,CAczE;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,OAAO,EAAE,MAAM,GACd,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB;AAqBD,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,WAAW,EAAE,CAM7F;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAOrF;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAMhF"}
|
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { fromMarkdown, } from 'mdast-util-from-markdown';
|
|
2
|
+
import { gfmFootnoteFromMarkdown } from 'mdast-util-gfm-footnote';
|
|
3
|
+
import { gfmStrikethroughFromMarkdown } from 'mdast-util-gfm-strikethrough';
|
|
4
|
+
import { gfmTableFromMarkdown } from 'mdast-util-gfm-table';
|
|
5
|
+
import { gfmTaskListItemFromMarkdown } from 'mdast-util-gfm-task-list-item';
|
|
6
|
+
import { gfmFootnote } from 'micromark-extension-gfm-footnote';
|
|
7
|
+
import { gfmStrikethrough } from 'micromark-extension-gfm-strikethrough';
|
|
8
|
+
import { gfmTable } from 'micromark-extension-gfm-table';
|
|
9
|
+
import { gfmTaskListItem } from 'micromark-extension-gfm-task-list-item';
|
|
10
|
+
const BYTE_ORDER_MARK = 0xfeff;
|
|
11
|
+
const LINKED = new Set(['link', 'image', 'linkReference', 'imageReference']);
|
|
12
|
+
const REFERENCED = new Set(['linkReference', 'imageReference']);
|
|
13
|
+
const SYNTAX = [gfmFootnote(), gfmStrikethrough(), gfmTable(), gfmTaskListItem()];
|
|
14
|
+
function startOf(node) {
|
|
15
|
+
return node.position.start.offset;
|
|
16
|
+
}
|
|
17
|
+
function endOf(node) {
|
|
18
|
+
return node.position.end.offset;
|
|
19
|
+
}
|
|
20
|
+
function marked(marks, node) {
|
|
21
|
+
let mark = marks.get(node);
|
|
22
|
+
if (mark === undefined) {
|
|
23
|
+
mark = {};
|
|
24
|
+
marks.set(node, mark);
|
|
25
|
+
}
|
|
26
|
+
return mark;
|
|
27
|
+
}
|
|
28
|
+
function marking(text, shift, marks, labelled) {
|
|
29
|
+
const at = (point) => point.offset + shift;
|
|
30
|
+
return {
|
|
31
|
+
afterExit(token) {
|
|
32
|
+
const top = this.stack[this.stack.length - 1];
|
|
33
|
+
const start = at(token.start);
|
|
34
|
+
const end = at(token.end);
|
|
35
|
+
switch (token.type) {
|
|
36
|
+
case 'labelText': {
|
|
37
|
+
const node = this.stack[this.stack.length - 2];
|
|
38
|
+
marked(marks, node).label = { start, end };
|
|
39
|
+
labelled.push(node);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
case 'resourceDestinationLiteral':
|
|
43
|
+
case 'definitionDestinationLiteral':
|
|
44
|
+
marked(marks, top).destination = {
|
|
45
|
+
href: text.slice(start + 1, end - 1),
|
|
46
|
+
start,
|
|
47
|
+
end,
|
|
48
|
+
bracketed: true,
|
|
49
|
+
};
|
|
50
|
+
return;
|
|
51
|
+
case 'resourceDestinationRaw':
|
|
52
|
+
case 'definitionDestinationRaw':
|
|
53
|
+
marked(marks, top).destination = {
|
|
54
|
+
href: text.slice(start, end),
|
|
55
|
+
start,
|
|
56
|
+
end,
|
|
57
|
+
bracketed: false,
|
|
58
|
+
};
|
|
59
|
+
return;
|
|
60
|
+
case 'resource':
|
|
61
|
+
marked(marks, top).resourceEnd = end;
|
|
62
|
+
return;
|
|
63
|
+
case 'atxHeadingText':
|
|
64
|
+
case 'setextHeadingText':
|
|
65
|
+
marked(marks, top).text = { start, end };
|
|
66
|
+
return;
|
|
67
|
+
case 'listItemPrefix':
|
|
68
|
+
marked(marks, top).content = end;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function lineStart(text, index) {
|
|
75
|
+
let at = index;
|
|
76
|
+
while (at > 0 && text[at - 1] !== '\n' && text[at - 1] !== '\r')
|
|
77
|
+
at -= 1;
|
|
78
|
+
return at;
|
|
79
|
+
}
|
|
80
|
+
function lineEnd(text, index) {
|
|
81
|
+
let at = index;
|
|
82
|
+
while (at < text.length && text[at] !== '\n' && text[at] !== '\r')
|
|
83
|
+
at += 1;
|
|
84
|
+
if (at === text.length)
|
|
85
|
+
return { end: at, next: at };
|
|
86
|
+
return { end: at, next: text[at] === '\r' && text[at + 1] === '\n' ? at + 2 : at + 1 };
|
|
87
|
+
}
|
|
88
|
+
function trimmed(text, start, end) {
|
|
89
|
+
let from = start;
|
|
90
|
+
let to = end;
|
|
91
|
+
while (from < to && /\s/.test(text[from]))
|
|
92
|
+
from += 1;
|
|
93
|
+
while (to > from && /\s/.test(text[to - 1]))
|
|
94
|
+
to -= 1;
|
|
95
|
+
return { start: from, end: to };
|
|
96
|
+
}
|
|
97
|
+
function shifted(value, by) {
|
|
98
|
+
return { ...value, start: value.start + by, end: value.end + by };
|
|
99
|
+
}
|
|
100
|
+
function walked(root, visit) {
|
|
101
|
+
const pending = [root];
|
|
102
|
+
while (pending.length > 0) {
|
|
103
|
+
const node = pending.pop();
|
|
104
|
+
visit(node);
|
|
105
|
+
const children = node.children ?? [];
|
|
106
|
+
for (let index = children.length - 1; index >= 0; index -= 1)
|
|
107
|
+
pending.push(children[index]);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export function read(text, at = 0) {
|
|
111
|
+
const marks = new WeakMap();
|
|
112
|
+
const labelled = [];
|
|
113
|
+
const shift = text.charCodeAt(0) === BYTE_ORDER_MARK ? 1 : 0;
|
|
114
|
+
const root = fromMarkdown(text, {
|
|
115
|
+
extensions: SYNTAX,
|
|
116
|
+
mdastExtensions: [
|
|
117
|
+
gfmFootnoteFromMarkdown(),
|
|
118
|
+
gfmStrikethroughFromMarkdown(),
|
|
119
|
+
gfmTableFromMarkdown(),
|
|
120
|
+
gfmTaskListItemFromMarkdown(),
|
|
121
|
+
marking(text, shift, marks, labelled),
|
|
122
|
+
],
|
|
123
|
+
});
|
|
124
|
+
const local = (offset) => offset + shift;
|
|
125
|
+
const headings = [];
|
|
126
|
+
const blocks = [];
|
|
127
|
+
for (const node of root.children ?? []) {
|
|
128
|
+
let start = local(startOf(node));
|
|
129
|
+
while (start > 0 && (text[start - 1] === ' ' || text[start - 1] === '\t'))
|
|
130
|
+
start -= 1;
|
|
131
|
+
const end = local(endOf(node));
|
|
132
|
+
if (node.type === 'heading') {
|
|
133
|
+
const name = marks.get(node)?.text;
|
|
134
|
+
const line = lineEnd(text, end);
|
|
135
|
+
headings.push({
|
|
136
|
+
level: node.depth,
|
|
137
|
+
name: name === undefined ? '' : text.slice(name.start, name.end),
|
|
138
|
+
start: at + start,
|
|
139
|
+
textEnd: at + line.end,
|
|
140
|
+
next: at + line.next,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
blocks.push({
|
|
144
|
+
start: at + start,
|
|
145
|
+
end: at + end,
|
|
146
|
+
items: node.type === 'list'
|
|
147
|
+
? (node.children ?? []).map((item) => shifted(trimmed(text, marks.get(item)?.content ?? local(startOf(item)), local(endOf(item))), at))
|
|
148
|
+
: null,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
const destinations = new Map();
|
|
152
|
+
const definitions = [];
|
|
153
|
+
walked(root, (node) => {
|
|
154
|
+
const mark = marks.get(node);
|
|
155
|
+
if (node.type !== 'definition' || mark?.destination === undefined)
|
|
156
|
+
return;
|
|
157
|
+
const destination = shifted(mark.destination, at);
|
|
158
|
+
if (!destinations.has(node.identifier))
|
|
159
|
+
destinations.set(node.identifier, destination);
|
|
160
|
+
definitions.push({
|
|
161
|
+
start: at + lineStart(text, local(startOf(node))),
|
|
162
|
+
end: at + lineEnd(text, local(endOf(node))).next,
|
|
163
|
+
destination,
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
const uses = [];
|
|
167
|
+
for (const node of labelled) {
|
|
168
|
+
if (!LINKED.has(node.type))
|
|
169
|
+
continue;
|
|
170
|
+
const mark = marks.get(node);
|
|
171
|
+
const destination = REFERENCED.has(node.type)
|
|
172
|
+
? destinations.get(node.identifier)
|
|
173
|
+
: mark.destination !== undefined
|
|
174
|
+
? shifted(mark.destination, at)
|
|
175
|
+
: mark.resourceEnd === undefined
|
|
176
|
+
? undefined
|
|
177
|
+
: {
|
|
178
|
+
href: '',
|
|
179
|
+
start: at + mark.resourceEnd - 1,
|
|
180
|
+
end: at + mark.resourceEnd - 1,
|
|
181
|
+
bracketed: false,
|
|
182
|
+
};
|
|
183
|
+
if (destination === undefined)
|
|
184
|
+
continue;
|
|
185
|
+
uses.push({
|
|
186
|
+
start: at + local(startOf(node)),
|
|
187
|
+
end: at + local(endOf(node)),
|
|
188
|
+
labelStart: at + mark.label.start,
|
|
189
|
+
labelEnd: at + mark.label.end,
|
|
190
|
+
destination,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
uses.sort((left, right) => left.start - right.start);
|
|
194
|
+
return { headings, blocks, uses, definitions };
|
|
195
|
+
}
|
|
196
|
+
export function destinations(reading) {
|
|
197
|
+
const byStart = new Map();
|
|
198
|
+
for (const use of reading.uses)
|
|
199
|
+
byStart.set(use.destination.start, use.destination);
|
|
200
|
+
return [...byStart.values()].sort((left, right) => left.start - right.start);
|
|
201
|
+
}
|
|
202
|
+
export function hrefOccurrences(body) {
|
|
203
|
+
return destinations(read(body));
|
|
204
|
+
}
|
|
205
|
+
export function headingLines(content, from, to) {
|
|
206
|
+
return [...read(content.slice(from, to), from).headings];
|
|
207
|
+
}
|
|
208
|
+
export function sectionSpans(reading, end) {
|
|
209
|
+
const found = [];
|
|
210
|
+
for (const heading of reading.headings) {
|
|
211
|
+
if (heading.level !== 2)
|
|
212
|
+
continue;
|
|
213
|
+
if (found.length > 0)
|
|
214
|
+
found[found.length - 1] = { ...found[found.length - 1], bodyEnd: heading.start };
|
|
215
|
+
found.push({
|
|
216
|
+
name: heading.name,
|
|
217
|
+
headingStart: heading.start,
|
|
218
|
+
bodyStart: heading.next,
|
|
219
|
+
bodyEnd: end,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
return found;
|
|
223
|
+
}
|
|
224
|
+
export function sectionsRecord(spans, content) {
|
|
225
|
+
const record = Object.create(null);
|
|
226
|
+
for (const span of spans) {
|
|
227
|
+
if (record[span.name] === undefined)
|
|
228
|
+
record[span.name] = content.slice(span.bodyStart, span.bodyEnd);
|
|
229
|
+
}
|
|
230
|
+
return record;
|
|
231
|
+
}
|
|
232
|
+
function firstPast(items, at, key) {
|
|
233
|
+
let low = 0;
|
|
234
|
+
let high = items.length;
|
|
235
|
+
while (low < high) {
|
|
236
|
+
const middle = (low + high) >>> 1;
|
|
237
|
+
if (key(items[middle]) <= at)
|
|
238
|
+
low = middle + 1;
|
|
239
|
+
else
|
|
240
|
+
high = middle;
|
|
241
|
+
}
|
|
242
|
+
return low;
|
|
243
|
+
}
|
|
244
|
+
function blocksIn(reading, from, to) {
|
|
245
|
+
const blocks = reading.blocks;
|
|
246
|
+
const first = firstPast(blocks, from, (block) => block.end);
|
|
247
|
+
let end = first;
|
|
248
|
+
while (end < blocks.length && blocks[end].start < to)
|
|
249
|
+
end += 1;
|
|
250
|
+
return blocks.slice(first, end);
|
|
251
|
+
}
|
|
252
|
+
export function headingsIn(reading, from, to) {
|
|
253
|
+
const start = (heading) => heading.start;
|
|
254
|
+
return reading.headings.slice(firstPast(reading.headings, from - 1, start), firstPast(reading.headings, to - 1, start));
|
|
255
|
+
}
|
|
256
|
+
export function listItems(reading, from, to) {
|
|
257
|
+
const items = [];
|
|
258
|
+
for (const block of blocksIn(reading, from, to)) {
|
|
259
|
+
if (block.items === null)
|
|
260
|
+
return null;
|
|
261
|
+
items.push(...block.items);
|
|
262
|
+
}
|
|
263
|
+
return items;
|
|
264
|
+
}
|
|
265
|
+
export function blockRanges(reading, from, to) {
|
|
266
|
+
const starts = blocksIn(reading, from, to).map((block) => block.start);
|
|
267
|
+
return starts.map((start, index) => ({
|
|
268
|
+
start: index === 0 ? from : start,
|
|
269
|
+
end: starts[index + 1] ?? to,
|
|
270
|
+
}));
|
|
271
|
+
}
|