@heroiclands/package-build 22.8.0 → 22.9.1
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/CHANGELOG.md +26 -0
- package/content-config.mjs +0 -78
- package/docs/api.md +45 -9
- package/docs/configuration.md +1 -55
- package/docs/content-format.md +150 -14
- package/engine/base-compiler.mjs +9 -0
- package/engine/being-age.mjs +270 -0
- package/engine/calendar-notes.mjs +805 -0
- package/engine/calendars.mjs +115 -14
- package/engine/content-index.mjs +15 -1
- package/engine/index.mjs +6 -0
- package/engine/infobox.mjs +6 -0
- package/engine/note-dates.mjs +27 -21
- package/engine/note-vocabulary.mjs +57 -6
- package/engine/site-build.mjs +16 -0
- package/package.json +1 -1
- package/types/content-config.d.mts +0 -10
- package/types/engine/base-compiler.d.mts +1 -0
- package/types/engine/being-age.d.mts +92 -0
- package/types/engine/calendar-notes.d.mts +173 -0
- package/types/engine/calendars.d.mts +108 -17
- package/types/engine/index.d.mts +2 -0
- package/types/engine/note-dates.d.mts +6 -6
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The world facts a package declares, read from its own notes.
|
|
3
|
+
*
|
|
4
|
+
* Nothing here is configured and nothing is assumed: a package with no world
|
|
5
|
+
* note has no year, and every question that depends on one goes unasked.
|
|
6
|
+
*
|
|
7
|
+
* @param {object} [index] - The link index, holding every note in the package.
|
|
8
|
+
* @returns {{year: object|null, present: unknown, moon: object|null,
|
|
9
|
+
* body: object|null, moonName: string|null, yearNote: object|null,
|
|
10
|
+
* moonNote: object|null}} What the package's notes state.
|
|
11
|
+
*/
|
|
12
|
+
export function worldInvariants(index?: object): {
|
|
13
|
+
year: object | null;
|
|
14
|
+
present: unknown;
|
|
15
|
+
moon: object | null;
|
|
16
|
+
body: object | null;
|
|
17
|
+
moonName: string | null;
|
|
18
|
+
yearNote: object | null;
|
|
19
|
+
moonNote: object | null;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Check a `place` note's world facts.
|
|
23
|
+
*
|
|
24
|
+
* Declared on `place` beside its tenure check, so the lint runs both with the
|
|
25
|
+
* same index. Four rules, and each is a fact about the setting rather than
|
|
26
|
+
* about the file:
|
|
27
|
+
*
|
|
28
|
+
* - a world fact is written on a body — a `world` or a `celestial` — and
|
|
29
|
+
* nowhere else;
|
|
30
|
+
* - a package states **one** year, because two years is two settings and
|
|
31
|
+
* nothing can choose between them;
|
|
32
|
+
* - a package states **one** moon, for the same reason;
|
|
33
|
+
* - a moon with no year is refused, because a cycle measured in days has
|
|
34
|
+
* nothing to be measured against.
|
|
35
|
+
*
|
|
36
|
+
* `data.present` is read through the parser a note's dates go through, with the
|
|
37
|
+
* corpus in hand, so a present written in an era resolves where it is written.
|
|
38
|
+
*
|
|
39
|
+
* @param {object} note - The note, as the link index hands it over.
|
|
40
|
+
* @param {object} [opts]
|
|
41
|
+
* @param {object} [opts.index] - The link index, holding every note.
|
|
42
|
+
* @returns {object[]} Findings.
|
|
43
|
+
*/
|
|
44
|
+
export function checkWorldFacts(note: object, { index }?: {
|
|
45
|
+
index?: object | undefined;
|
|
46
|
+
}): object[];
|
|
47
|
+
/**
|
|
48
|
+
* Check a `lore` note's calendar declaration.
|
|
49
|
+
*
|
|
50
|
+
* Both halves of one sentence, and the second is the half that keeps the family
|
|
51
|
+
* from leaking: a calendar note must carry its months and its epoch, and a lore
|
|
52
|
+
* note that is not a calendar must carry none of the family at all.
|
|
53
|
+
*
|
|
54
|
+
* The sum is the only arithmetic. It runs where the package states a year and
|
|
55
|
+
* the note states months, and nowhere else — neither fires on a package that
|
|
56
|
+
* declared nothing.
|
|
57
|
+
*
|
|
58
|
+
* A calendar note **cannot** restate a world fact, and it needs no rule of its
|
|
59
|
+
* own to stop it: `data.year`, `data.moon`, `data.world` and `data.body` are
|
|
60
|
+
* declared on `place` and not on `lore`, so the closed `data:` container
|
|
61
|
+
* already refuses them by the rule it refuses every undeclared key by.
|
|
62
|
+
*
|
|
63
|
+
* @param {object} note - The note, as the link index hands it over.
|
|
64
|
+
* @param {object} [opts]
|
|
65
|
+
* @param {object} [opts.index] - The link index, for the world's year.
|
|
66
|
+
* @returns {object[]} Findings.
|
|
67
|
+
*/
|
|
68
|
+
export function checkCalendarNote(note: object, { index }?: {
|
|
69
|
+
index?: object | undefined;
|
|
70
|
+
}): object[];
|
|
71
|
+
/**
|
|
72
|
+
* The four days the year turns on, by day of year.
|
|
73
|
+
*
|
|
74
|
+
* The year opens on the first of the first month, and the year's length sets
|
|
75
|
+
* the spacing; nothing else is consulted. A body's tilt is what makes seasons
|
|
76
|
+
* exist at all, and it is read by nobody — a quarter day is where the calendar
|
|
77
|
+
* opens plus a quarter of the year, to the nearest whole day, because a day is
|
|
78
|
+
* the smallest thing a calendar can name.
|
|
79
|
+
*
|
|
80
|
+
* @param {number} daysPerYear - The world's year.
|
|
81
|
+
* @returns {number[]} Four day-of-year numbers, in order from the year's start.
|
|
82
|
+
*/
|
|
83
|
+
export function quarterDays(daysPerYear: number): number[];
|
|
84
|
+
/**
|
|
85
|
+
* Compile one calendar note and the package's world facts into one definition.
|
|
86
|
+
*
|
|
87
|
+
* The object both consumers read: array-shaped for core's `ArrayField`
|
|
88
|
+
* collections, carrying the keys core prunes and Calendaria keeps.
|
|
89
|
+
*
|
|
90
|
+
* @param {object} opts
|
|
91
|
+
* @param {object} opts.note - The calendar note.
|
|
92
|
+
* @param {object} opts.invariants - What {@link worldInvariants} read.
|
|
93
|
+
* @param {string} [opts.contentPackage] - The package shipping the note, which
|
|
94
|
+
* is a fact about the tree rather than about the note: a note never declares
|
|
95
|
+
* its own package.
|
|
96
|
+
* @returns {object} The definition.
|
|
97
|
+
*/
|
|
98
|
+
export function compileCalendar({ note, invariants, contentPackage }: {
|
|
99
|
+
note: object;
|
|
100
|
+
invariants: object;
|
|
101
|
+
contentPackage?: string | undefined;
|
|
102
|
+
}): object;
|
|
103
|
+
/**
|
|
104
|
+
* Wrap a definition in the envelope a Calendaria settings import reads.
|
|
105
|
+
*
|
|
106
|
+
* `calendarData` is the definition unchanged — the importer derives an id from
|
|
107
|
+
* its `name` and creates a custom calendar from it — so the envelope adds a
|
|
108
|
+
* header and nothing else. That is what makes the two artefacts assertable
|
|
109
|
+
* against each other rather than merely similar.
|
|
110
|
+
*
|
|
111
|
+
* @param {object} definition - What {@link compileCalendar} produced.
|
|
112
|
+
* @param {object} opts
|
|
113
|
+
* @param {string} opts.version - The Calendaria version this was generated
|
|
114
|
+
* against, which the importer records.
|
|
115
|
+
* @param {string} opts.exportedAt - When, as an ISO 8601 instant.
|
|
116
|
+
* @returns {object} The envelope.
|
|
117
|
+
*/
|
|
118
|
+
export function calendariaEnvelope(definition: object, { version, exportedAt }: {
|
|
119
|
+
version: string;
|
|
120
|
+
exportedAt: string;
|
|
121
|
+
}): object;
|
|
122
|
+
/**
|
|
123
|
+
* Every calendar a package declares, compiled.
|
|
124
|
+
*
|
|
125
|
+
* A package whose notes state no year declares no calendars and is asked
|
|
126
|
+
* nothing about one, which is the right answer for a package that builds a
|
|
127
|
+
* setting somebody else wrote down.
|
|
128
|
+
*
|
|
129
|
+
* @param {object} [index] - The link index, holding every note.
|
|
130
|
+
* @param {object} [opts]
|
|
131
|
+
* @param {string} [opts.contentPackage] - The package shipping the tree.
|
|
132
|
+
* @returns {{calendars: object[], invariants: object}} One compiled definition
|
|
133
|
+
* per calendar note, and the facts they were compiled against.
|
|
134
|
+
*/
|
|
135
|
+
export function compileCalendars(index?: object, { contentPackage }?: {
|
|
136
|
+
contentPackage?: string | undefined;
|
|
137
|
+
}): {
|
|
138
|
+
calendars: object[];
|
|
139
|
+
invariants: object;
|
|
140
|
+
};
|
|
141
|
+
/** The `lore` subType whose notes are calendars. */
|
|
142
|
+
export const CALENDAR_SUBTYPE: "calendar";
|
|
143
|
+
/**
|
|
144
|
+
* The `place` subTypes a world fact may be written on.
|
|
145
|
+
*
|
|
146
|
+
* `world` is a body people stand on; `celestial` is one they only look at. A
|
|
147
|
+
* region, a settlement, a site, a structure or a feature is somewhere *in* a
|
|
148
|
+
* world and states nothing about the world's year.
|
|
149
|
+
*
|
|
150
|
+
* @type {readonly string[]}
|
|
151
|
+
*/
|
|
152
|
+
export const INVARIANT_SUBTYPES: readonly string[];
|
|
153
|
+
/**
|
|
154
|
+
* The `data:` keys a calendar note may write — the closed list, in authored
|
|
155
|
+
* order.
|
|
156
|
+
*
|
|
157
|
+
* Every key in either target schema that is not here is either a world fact,
|
|
158
|
+
* read from a `place` note and written by the emitters, or omitted because no
|
|
159
|
+
* calendar has declared one.
|
|
160
|
+
*
|
|
161
|
+
* @type {readonly object[]}
|
|
162
|
+
*/
|
|
163
|
+
export const CALENDAR_FIELDS: readonly object[];
|
|
164
|
+
/**
|
|
165
|
+
* The `data:` keys a world or a celestial body may write.
|
|
166
|
+
*
|
|
167
|
+
* Four groups, and which note carries which is a fact about the body rather
|
|
168
|
+
* than a convention: a planet states its own size, tilt, year and present; a
|
|
169
|
+
* moon states its own size, orbit and cycle.
|
|
170
|
+
*
|
|
171
|
+
* @type {readonly object[]}
|
|
172
|
+
*/
|
|
173
|
+
export const INVARIANT_FIELDS: readonly object[];
|
|
@@ -36,22 +36,87 @@ export function canonicalYear(year: number, epoch?: number): number;
|
|
|
36
36
|
*/
|
|
37
37
|
export function dateSortKey(year: number, month: number | null, day: number | null): number;
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* One month of a calendar, as the note declares it.
|
|
40
40
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* @typedef {object} CalendarMonth
|
|
42
|
+
* @property {string} name - What the month is called.
|
|
43
|
+
* @property {string} [abbreviation] - A short form, where the note gives one.
|
|
44
|
+
* @property {number} days - How many days it holds.
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* The months a calendar keeps, or `null` where it declares none.
|
|
43
48
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
49
|
+
* Separate from the check that reads it so a caller can ask what a calendar
|
|
50
|
+
* divides its year into without phrasing a finding about it. An empty list
|
|
51
|
+
* reads as no list: a calendar that declares nothing and one that declares
|
|
52
|
+
* nothing in a pair of brackets divide the year identically.
|
|
53
|
+
*
|
|
54
|
+
* @param {{months?: readonly CalendarMonth[]|null}} [calendar] - The calendar
|
|
55
|
+
* the date is written in, as its note declares it.
|
|
56
|
+
* @returns {{months: readonly CalendarMonth[]|null}} What it divides the year
|
|
57
|
+
* into.
|
|
47
58
|
*/
|
|
48
59
|
export function calendarStructure(calendar?: {
|
|
49
|
-
months?:
|
|
50
|
-
monthDays?: number | null;
|
|
60
|
+
months?: readonly CalendarMonth[] | null;
|
|
51
61
|
}): {
|
|
52
|
-
months:
|
|
53
|
-
monthDays: number | null;
|
|
62
|
+
months: readonly CalendarMonth[] | null;
|
|
54
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* How long one month of a calendar is, or `null` where the calendar is silent.
|
|
66
|
+
*
|
|
67
|
+
* @param {{months?: readonly CalendarMonth[]|null}} [calendar] - The calendar.
|
|
68
|
+
* @param {number} month - The month, numbered from 1.
|
|
69
|
+
* @returns {number|null} Its length in days, or `null`.
|
|
70
|
+
*/
|
|
71
|
+
export function daysInMonth(calendar?: {
|
|
72
|
+
months?: readonly CalendarMonth[] | null;
|
|
73
|
+
}, month: number): number | null;
|
|
74
|
+
/**
|
|
75
|
+
* How many days the months add up to.
|
|
76
|
+
*
|
|
77
|
+
* The number a calendar's list claims the year is. Whether that is the year the
|
|
78
|
+
* world keeps is a question about the world, and is asked elsewhere.
|
|
79
|
+
*
|
|
80
|
+
* @param {readonly CalendarMonth[]} months - The ordered month list.
|
|
81
|
+
* @returns {number} The sum of their day counts.
|
|
82
|
+
*/
|
|
83
|
+
export function daysInYear(months: readonly CalendarMonth[]): number;
|
|
84
|
+
/**
|
|
85
|
+
* The day of the year each month opens on, in order, numbered from 1.
|
|
86
|
+
*
|
|
87
|
+
* The sum read as a sequence rather than as a total. Two lists holding the same
|
|
88
|
+
* numbers in a different order sum alike and open their months on different
|
|
89
|
+
* days, which is the error a total cannot see.
|
|
90
|
+
*
|
|
91
|
+
* @param {readonly CalendarMonth[]} months - The ordered month list.
|
|
92
|
+
* @returns {number[]} One entry per month: the day of the year it begins on.
|
|
93
|
+
*/
|
|
94
|
+
export function monthStarts(months: readonly CalendarMonth[]): number[];
|
|
95
|
+
/**
|
|
96
|
+
* Which day of the year a written month and day land on, numbered from 1.
|
|
97
|
+
*
|
|
98
|
+
* @param {readonly CalendarMonth[]} months - The ordered month list.
|
|
99
|
+
* @param {number} month - The month, numbered from 1.
|
|
100
|
+
* @param {number} day - The day within it, numbered from 1.
|
|
101
|
+
* @returns {number} The day of the year.
|
|
102
|
+
*/
|
|
103
|
+
export function dayOfYear(months: readonly CalendarMonth[], month: number, day: number): number;
|
|
104
|
+
/**
|
|
105
|
+
* How far into its cycle a moon is on a given day.
|
|
106
|
+
*
|
|
107
|
+
* **Floored, not truncated.** JavaScript's `%` takes the dividend's sign, so a
|
|
108
|
+
* day seven before the epoch yields `-7` where the phase is 23 — a value that
|
|
109
|
+
* is right on one side of the epoch and wrong on the other, which is invisible
|
|
110
|
+
* in any list that does not span it.
|
|
111
|
+
*
|
|
112
|
+
* @param {number} dayNumber - The day, on whatever continuous day count the
|
|
113
|
+
* caller keeps.
|
|
114
|
+
* @param {number} epochDay - The day of that same count on which the moon was
|
|
115
|
+
* new.
|
|
116
|
+
* @param {number} cycle - The cycle's length in days.
|
|
117
|
+
* @returns {number} Days into the cycle, `0` to `cycle - 1`.
|
|
118
|
+
*/
|
|
119
|
+
export function lunarPhase(dayNumber: number, epochDay: number, cycle: number): number;
|
|
55
120
|
/**
|
|
56
121
|
* **The axis every date normalises onto, and the one function that puts a
|
|
57
122
|
* reckoning on it.**
|
|
@@ -93,14 +158,23 @@ export function calendarStructure(calendar?: {
|
|
|
93
158
|
* and off by one on the other, which is invisible in any list that does not
|
|
94
159
|
* span it.
|
|
95
160
|
*
|
|
96
|
-
* ## The month structure is the
|
|
161
|
+
* ## The month structure is the calendar's, and an absent list bounds nothing
|
|
97
162
|
*
|
|
98
|
-
* An era moves where year 1 sits; it does not divide the year differently.
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
163
|
+
* An era moves where year 1 sits; it does not divide the year differently. The
|
|
164
|
+
* division belongs to the calendar, which is a note declaring an **ordered
|
|
165
|
+
* list** of months, each with a name and a day count. Position in the list is
|
|
166
|
+
* position in the year, so a five-day month sits wherever its people put it and
|
|
167
|
+
* needs no rule of its own.
|
|
168
|
+
*
|
|
169
|
+
* A date is bounded by the calendar it is written in, and a calendar whose list
|
|
170
|
+
* nobody has written down bounds nothing — a toolchain that invented twelve
|
|
171
|
+
* Gregorian months would refuse `667/2/30`, an ordinary date in a year of
|
|
172
|
+
* twelve thirty-day months.
|
|
173
|
+
*
|
|
174
|
+
* ## The lunar phase takes a floored modulo, not JavaScript's
|
|
175
|
+
*
|
|
176
|
+
* `%` takes the dividend's sign, so a day before the epoch yields `-7` where
|
|
177
|
+
* the phase is 23. {@link lunarPhase} is the one place that is written.
|
|
104
178
|
*
|
|
105
179
|
* @module
|
|
106
180
|
*/
|
|
@@ -113,3 +187,20 @@ export function calendarStructure(calendar?: {
|
|
|
113
187
|
* @type {number}
|
|
114
188
|
*/
|
|
115
189
|
export const CANONICAL_EPOCH: number;
|
|
190
|
+
/**
|
|
191
|
+
* One month of a calendar, as the note declares it.
|
|
192
|
+
*/
|
|
193
|
+
export type CalendarMonth = {
|
|
194
|
+
/**
|
|
195
|
+
* - What the month is called.
|
|
196
|
+
*/
|
|
197
|
+
name: string;
|
|
198
|
+
/**
|
|
199
|
+
* - A short form, where the note gives one.
|
|
200
|
+
*/
|
|
201
|
+
abbreviation?: string | undefined;
|
|
202
|
+
/**
|
|
203
|
+
* - How many days it holds.
|
|
204
|
+
*/
|
|
205
|
+
days: number;
|
|
206
|
+
};
|
package/types/engine/index.d.mts
CHANGED
|
@@ -31,6 +31,8 @@ export * as siteMaps from "./site-maps.mjs";
|
|
|
31
31
|
export * as systems from "./systems.mjs";
|
|
32
32
|
export * as calendars from "./calendars.mjs";
|
|
33
33
|
export * as noteDates from "./note-dates.mjs";
|
|
34
|
+
export * as calendarNotes from "./calendar-notes.mjs";
|
|
35
|
+
export * as beingAge from "./being-age.mjs";
|
|
34
36
|
export * as contentSlug from "./content-slug.mjs";
|
|
35
37
|
export * as contentAddress from "./content-address.mjs";
|
|
36
38
|
export * as subtypeRegistry from "./subtype-registry.mjs";
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
* @param {unknown} value - The authored value. A number is what YAML hands
|
|
15
15
|
* back for a bare year, so it is accepted and stringified.
|
|
16
16
|
* @param {object} [options]
|
|
17
|
-
* @param {{months?:
|
|
18
|
-
*
|
|
19
|
-
* written month and day
|
|
17
|
+
* @param {{months?: readonly object[]|null}} [options.calendar] - The calendar
|
|
18
|
+
* the value is written in, as its note declares it. Its ordered month list
|
|
19
|
+
* bounds a written month and a written day, the day against the length of
|
|
20
|
+
* the month it names. A calendar that declares no list bounds nothing.
|
|
20
21
|
* @param {string} [options.field] - The key that carried it, named in every
|
|
21
22
|
* message. Omitted, a message names the value alone.
|
|
22
23
|
* @param {boolean} [options.allowUnknown=true] - Whether `"unknown"` is a
|
|
@@ -31,8 +32,7 @@
|
|
|
31
32
|
*/
|
|
32
33
|
export function parseNoteDate(value: unknown, options?: {
|
|
33
34
|
calendar?: {
|
|
34
|
-
months?:
|
|
35
|
-
monthDays?: number | null;
|
|
35
|
+
months?: readonly object[] | null;
|
|
36
36
|
} | undefined;
|
|
37
37
|
field?: string | undefined;
|
|
38
38
|
allowUnknown?: boolean | undefined;
|
|
@@ -52,7 +52,7 @@ export const UNKNOWN_DATE: string;
|
|
|
52
52
|
/**
|
|
53
53
|
* What a date's trailing token may look like.
|
|
54
54
|
*
|
|
55
|
-
*
|
|
55
|
+
* A calendar note's address followed by `.<era shortcode>`. The `{0,3}`
|
|
56
56
|
* repetition is the four address forms exactly — bare `shortcode`,
|
|
57
57
|
* `type-shortcode`, `system-type-shortcode` and
|
|
58
58
|
* `package-system-type-shortcode` — so the hyphen separates an address's
|