@tempo-kit/plugin-roman 0.0.0-stage → 2.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,906 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+
19
+ // auto-inject-version:tempo-kit/plugin/sdk
20
+ var sdk_exports = {};
21
+ __export(sdk_exports, {
22
+ definePlugin: () => definePlugin,
23
+ defineTerm: () => defineTerm
24
+ });
25
+ __reExport(sdk_exports, sdk_star);
26
+ import * as sdk_star from "tempo-kit/plugin/sdk";
27
+ import { definePlugin as originalPlugin, defineTerm as originalTerm } from "tempo-kit/plugin/sdk";
28
+ var definePlugin = (config) => originalPlugin({ ...config, version: "2.0.0-rc.0" });
29
+ var defineTerm = (config) => originalTerm({ ...config, version: "2.0.0-rc.0" });
30
+
31
+ // src/index.ts
32
+ import { isLeapYear as isLeapYear2 } from "tempo-kit/library";
33
+
34
+ // src/math.ts
35
+ import { getDaysInMonth, isLeapYear } from "tempo-kit/library";
36
+
37
+ // src/constants.ts
38
+ var AUC_OFFSET = 753;
39
+ var MOMJ_MONTHS = /* @__PURE__ */ new Set([3, 5, 7, 10]);
40
+ var ANCHOR_NOMINATIVE = Object.freeze({
41
+ Kalends: "Kalendae",
42
+ Nones: "Nonae",
43
+ Ides: "Idus"
44
+ });
45
+ var ANCHOR_ABLATIVE = Object.freeze({
46
+ Kalends: "Kalendis",
47
+ Nones: "Nonis",
48
+ Ides: "Idibus"
49
+ });
50
+ var ANCHOR_ACCUSATIVE = Object.freeze({
51
+ Kalends: "Kalendas",
52
+ Nones: "Nonas",
53
+ Ides: "Idus"
54
+ });
55
+ var ANCHOR_SHORT = Object.freeze({
56
+ Kalends: "Kal.",
57
+ Nones: "Non.",
58
+ Ides: "Id."
59
+ });
60
+ var MONTH_NOMINATIVE = Object.freeze([
61
+ "",
62
+ "Januariae",
63
+ "Februariae",
64
+ "Martiae",
65
+ "Apriles",
66
+ "Maiae",
67
+ "Juniae",
68
+ "Juliae",
69
+ "Augustae",
70
+ "Septembres",
71
+ "Octobres",
72
+ "Novembres",
73
+ "Decembres"
74
+ ]);
75
+ var MONTH_ACCUSATIVE = Object.freeze([
76
+ "",
77
+ "Januarias",
78
+ "Februarias",
79
+ "Martias",
80
+ "Apriles",
81
+ "Maias",
82
+ "Junias",
83
+ "Julias",
84
+ "Augustas",
85
+ "Septembres",
86
+ "Octobres",
87
+ "Novembres",
88
+ "Decembres"
89
+ ]);
90
+ var MONTH_ABLATIVE = Object.freeze([
91
+ "",
92
+ "Januariis",
93
+ "Februariis",
94
+ "Martiis",
95
+ "Aprilibus",
96
+ "Maiis",
97
+ "Juniis",
98
+ "Juliis",
99
+ "Augustis",
100
+ "Septembribus",
101
+ "Octobribus",
102
+ "Novembribus",
103
+ "Decembribus"
104
+ ]);
105
+ var MONTH_SHORT = Object.freeze([
106
+ "",
107
+ "Jan.",
108
+ "Feb.",
109
+ "Mart.",
110
+ "Apr.",
111
+ "Mai.",
112
+ "Jun.",
113
+ "Jul.",
114
+ "Aug.",
115
+ "Sept.",
116
+ "Oct.",
117
+ "Nov.",
118
+ "Dec."
119
+ ]);
120
+ var COUNT_WORDS_ACCUSATIVE = Object.freeze([
121
+ "",
122
+ "",
123
+ "pridie",
124
+ "tertium",
125
+ "quartum",
126
+ "quintum",
127
+ "sextum",
128
+ "septimum",
129
+ "octavum",
130
+ "nonum",
131
+ "decimum",
132
+ "undecimum",
133
+ "duodecimum",
134
+ "tertium decimum",
135
+ "quartum decimum",
136
+ "quintum decimum",
137
+ "sextum decimum",
138
+ "septimum decimum",
139
+ "duodevicesimum",
140
+ "undevicesimum"
141
+ ]);
142
+ var COUNT_WORDS_ABLATIVE = Object.freeze([
143
+ "",
144
+ "",
145
+ "pridie",
146
+ "tertio",
147
+ "quarto",
148
+ "quinto",
149
+ "sexto",
150
+ "septimo",
151
+ "octavo",
152
+ "nono",
153
+ "decimo",
154
+ "undecimo",
155
+ "duodecimo",
156
+ "tertio decimo",
157
+ "quarto decimo",
158
+ "quinto decimo",
159
+ "sexto decimo",
160
+ "septimo decimo",
161
+ "duodevicesimo",
162
+ "undevicesimo"
163
+ ]);
164
+
165
+ // src/consul-engine.ts
166
+ var LANDMARK_CONSULS = Object.freeze({
167
+ // 509 BCE: Founding of the Republic
168
+ "-508": ["L. Junius Brutus", "L. Tarquinius Collatinus"],
169
+ // 321 BCE: Second Samnite War / Caudine Forks
170
+ "-320": ["T. Veturius Calvinus II", "Sp. Postumius Albinus Caudinus II"],
171
+ // 280 BCE: Pyrrhic War
172
+ "-279": ["P. Valerius Laevinus", "Ti. Coruncanius"],
173
+ // 216 BCE: Second Punic War / Cannae
174
+ "-215": ["C. Terentius Varro", "L. Aemilius Paullus II"],
175
+ // 202 BCE: Second Punic War / Zama
176
+ "-201": ["M. Servilius Pulex Geminus", "Ti. Claudius Nero"],
177
+ // 133 BCE: Tribunate of Tiberius Gracchus
178
+ "-132": ["P. Mucius Scaevola", "L. Calpurnius Piso Frugi"],
179
+ // 107 BCE: First consulship of Gaius Marius
180
+ "-106": ["C. Marius I", "L. Cassius Longinus"],
181
+ // 63 BCE: Consulship of Cicero, Catilinarian conspiracy
182
+ "-62": ["M. Tullius Cicero", "C. Antonius Hybrida"],
183
+ // 59 BCE: First consulship of Julius Caesar ("Julius and Caesar")
184
+ "-58": ["C. Julius Caesar", "M. Calpurnius Bibulus"],
185
+ // 55 BCE: Second consulship of Pompey and Crassus
186
+ "-54": ["Cn. Pompeius Magnus II", "M. Licinius Crassus II"],
187
+ // 48 BCE: Battle of Pharsalus
188
+ "-47": ["C. Julius Caesar II", "P. Servilius Isauricus"],
189
+ // 44 BCE: Assassination of Julius Caesar (Ides of March)
190
+ "-43": ["C. Julius Caesar V", "M. Antonius"],
191
+ // 43 BCE: Formation of the Second Triumvirate
192
+ "-42": ["C. Vibius Pansa Caetronianus", "A. Hirtius"],
193
+ // 31 BCE: Battle of Actium
194
+ "-30": ["M. Antonius III", "Imp. Caesar III"],
195
+ // 28 BCE: Octavian and Agrippa
196
+ "-27": ["Imp. Caesar VI", "M. Agrippa II"],
197
+ // 27 BCE: Establishment of the Principate (Augustus)
198
+ "-26": ["Imp. Caesar Augustus VII", "M. Agrippa III"],
199
+ // 14 CE: Death of Augustus, accession of Tiberius
200
+ "14": ["Sex. Pompeius", "Sex. Appuleius"],
201
+ // 69 CE: Year of the Four Emperors
202
+ "69": ["Ser. Galba Caesar Augustus II", "T. Vinius"],
203
+ // 541 CE: Last ordinary consul in the West
204
+ "541": ["Anicius Faustus Albinus Basilius"]
205
+ });
206
+ var CONSULAR_REGISTRY_SYMBOL = /* @__PURE__ */ Symbol.for("@tempo-kit/plugin-roman/consuls");
207
+ function getRegistry() {
208
+ const g = globalThis;
209
+ if (!g[CONSULAR_REGISTRY_SYMBOL]) {
210
+ g[CONSULAR_REGISTRY_SYMBOL] = { ...LANDMARK_CONSULS };
211
+ }
212
+ return g[CONSULAR_REGISTRY_SYMBOL];
213
+ }
214
+ function registerConsuls(catalog) {
215
+ const registry = getRegistry();
216
+ Object.assign(registry, catalog);
217
+ }
218
+ function getConsulCatalog() {
219
+ return getRegistry();
220
+ }
221
+ function resetConsulCatalog() {
222
+ const g = globalThis;
223
+ g[CONSULAR_REGISTRY_SYMBOL] = { ...LANDMARK_CONSULS };
224
+ }
225
+ function getConsulsByYear(year) {
226
+ return getRegistry()[year];
227
+ }
228
+ function formatConsuls(year, style = "ablative") {
229
+ const consuls = getRegistry()[year];
230
+ if (!consuls || consuls.length === 0) return void 0;
231
+ if (style === "nominative") {
232
+ return consuls.join(", ");
233
+ }
234
+ const ablativeNames = consuls.map(toAblativeConsulName);
235
+ const suffix = consuls.length > 1 ? "coss." : "cos.";
236
+ return `${ablativeNames.join(", ")} ${suffix}`;
237
+ }
238
+ var ABLATIVE_OVERRIDES = Object.freeze({
239
+ Pulex: "Pulice",
240
+ pulex: "pulice",
241
+ Pulcher: "Pulchro",
242
+ pulcher: "pulchro",
243
+ Niger: "Nigro",
244
+ niger: "nigro",
245
+ Aper: "Apro",
246
+ aper: "apro"
247
+ });
248
+ function toAblativeConsulName(name) {
249
+ return name.split(" ").map((token) => {
250
+ if (/^[A-Z]['a-z]?\.$/.test(token) || /^[IVXLCDM]+$/.test(token))
251
+ return token;
252
+ if (ABLATIVE_OVERRIDES[token])
253
+ return ABLATIVE_OVERRIDES[token];
254
+ if (token.endsWith("ius")) return token.slice(0, -3) + "io";
255
+ if (token.endsWith("us")) return token.slice(0, -2) + "o";
256
+ if (token.endsWith("o")) return token + "ne";
257
+ if (token.endsWith("or")) return token + "e";
258
+ if (token.endsWith("ar")) return token + "e";
259
+ if (token.endsWith("as")) return token.slice(0, -2) + "a";
260
+ if (token.endsWith("es")) return token.slice(0, -2) + "e";
261
+ if (token.endsWith("is")) return token.slice(0, -2) + "e";
262
+ if (token.endsWith("x")) return token.slice(0, -1) + "ce";
263
+ if (/[bcdfghjklmnpqrstvz]$/i.test(token)) {
264
+ return token + "e";
265
+ }
266
+ return token;
267
+ }).join(" ");
268
+ }
269
+ function findConsulYears(nameQuery) {
270
+ let query = nameQuery.trim().toLowerCase();
271
+ if (!query) return [];
272
+ const words = query.replace(/[.,;:!?]/g, " ").split(/\s+/).filter((w) => w && !["et", "ac", "atque", "coss", "cos", "consulibus", "consule"].includes(w));
273
+ if (words.length === 0) return [];
274
+ const results = [];
275
+ const catalog = getRegistry();
276
+ for (const [yearStr, names] of Object.entries(catalog)) {
277
+ const year = Number(yearStr);
278
+ const fullNamesStr = names.join(" ").toLowerCase();
279
+ const match = words.every((w) => {
280
+ if (fullNamesStr.includes(w)) return true;
281
+ if (w.endsWith("one") && fullNamesStr.includes(w.slice(0, -3) + "o")) return true;
282
+ if (w.endsWith("e") && fullNamesStr.includes(w.slice(0, -1))) return true;
283
+ if (w.endsWith("o") && fullNamesStr.includes(w.slice(0, -1))) return true;
284
+ return false;
285
+ });
286
+ if (match) {
287
+ results.push({
288
+ year,
289
+ consuls: names,
290
+ formatted: formatConsuls(year)
291
+ });
292
+ }
293
+ }
294
+ return results.sort((a, b) => a.year - b.year);
295
+ }
296
+
297
+ // src/format.ts
298
+ function formatClassicalRomanDate(roman, options) {
299
+ const grammarCase = options?.case ?? "customary";
300
+ const style = options?.style ?? "classical";
301
+ const useWords = options?.words ?? false;
302
+ const isShort = style === "short";
303
+ let result = "";
304
+ if (roman.isBissextile) {
305
+ if (isShort) {
306
+ result = "a.d. bis VI Kal. Mart.";
307
+ } else {
308
+ result = "ante diem bis sextum Kalendas Martias";
309
+ }
310
+ } else if (roman.relation === "on") {
311
+ if (isShort) {
312
+ result = `${ANCHOR_SHORT[roman.anchor]} ${MONTH_SHORT[roman.anchorMonth]}`;
313
+ } else {
314
+ switch (grammarCase) {
315
+ case "nominative":
316
+ result = `${ANCHOR_NOMINATIVE[roman.anchor]} ${MONTH_NOMINATIVE[roman.anchorMonth]}`;
317
+ break;
318
+ case "accusative":
319
+ result = `${ANCHOR_ACCUSATIVE[roman.anchor]} ${MONTH_ACCUSATIVE[roman.anchorMonth]}`;
320
+ break;
321
+ case "ablative":
322
+ case "customary":
323
+ default:
324
+ result = `${ANCHOR_ABLATIVE[roman.anchor]} ${MONTH_ABLATIVE[roman.anchorMonth]}`;
325
+ break;
326
+ }
327
+ }
328
+ } else if (roman.relation === "pridie") {
329
+ if (isShort) {
330
+ result = `Prid. ${ANCHOR_SHORT[roman.anchor]} ${MONTH_SHORT[roman.anchorMonth]}`;
331
+ } else {
332
+ switch (grammarCase) {
333
+ case "nominative":
334
+ result = `Pridie ${ANCHOR_NOMINATIVE[roman.anchor]} ${MONTH_NOMINATIVE[roman.anchorMonth]}`;
335
+ break;
336
+ case "ablative":
337
+ result = `Pridie ${ANCHOR_ABLATIVE[roman.anchor]} ${MONTH_ABLATIVE[roman.anchorMonth]}`;
338
+ break;
339
+ case "accusative":
340
+ case "customary":
341
+ default:
342
+ result = `Pridie ${ANCHOR_ACCUSATIVE[roman.anchor]} ${MONTH_ACCUSATIVE[roman.anchorMonth]}`;
343
+ break;
344
+ }
345
+ }
346
+ } else {
347
+ const numeral = useWords && COUNT_WORDS_ACCUSATIVE[roman.count] ? COUNT_WORDS_ACCUSATIVE[roman.count] : roman.romanNumeral || (0, sdk_exports.toRoman)(roman.count);
348
+ if (isShort) {
349
+ result = `a.d. ${roman.romanNumeral || (0, sdk_exports.toRoman)(roman.count)} ${ANCHOR_SHORT[roman.anchor]} ${MONTH_SHORT[roman.anchorMonth]}`;
350
+ } else {
351
+ switch (grammarCase) {
352
+ case "nominative":
353
+ result = `ante diem ${numeral} ${ANCHOR_NOMINATIVE[roman.anchor]} ${MONTH_NOMINATIVE[roman.anchorMonth]}`;
354
+ break;
355
+ case "ablative":
356
+ result = `ante diem ${numeral} ${ANCHOR_ABLATIVE[roman.anchor]} ${MONTH_ABLATIVE[roman.anchorMonth]}`;
357
+ break;
358
+ case "accusative":
359
+ case "customary":
360
+ default:
361
+ result = `ante diem ${numeral} ${ANCHOR_ACCUSATIVE[roman.anchor]} ${MONTH_ACCUSATIVE[roman.anchorMonth]}`;
362
+ break;
363
+ }
364
+ }
365
+ }
366
+ if (options?.auc) {
367
+ const aucFormatted = options.aucFormat === "numeric" ? `AUC ${roman.auc}` : `AUC ${(0, sdk_exports.toRoman)(roman.auc)}`;
368
+ result = `${result} ${aucFormatted}`;
369
+ }
370
+ if (options?.casing) {
371
+ switch (options.casing) {
372
+ case "upper":
373
+ result = result.toUpperCase();
374
+ break;
375
+ case "lower":
376
+ result = result.toLowerCase();
377
+ break;
378
+ case "capitalize":
379
+ result = result.charAt(0).toUpperCase() + result.slice(1);
380
+ break;
381
+ default:
382
+ break;
383
+ }
384
+ }
385
+ return result;
386
+ }
387
+ function createRomanTokenEvaluator(calculator) {
388
+ return (zdt, context) => {
389
+ const rawMods = context?.modifiers ?? [];
390
+ const mods = rawMods.map((m) => m.toLowerCase());
391
+ if (mods.includes("auc") && !mods.includes("classical") && !mods.includes("short") && !mods.includes("nominative") && !mods.includes("accusative") && !mods.includes("ablative") && !mods.includes("consul")) {
392
+ const auc = zdt.year + 753;
393
+ let aucStr = mods.includes("num") || mods.includes("numeric") ? String(auc) : mods.includes("raw") ? (0, sdk_exports.toRoman)(auc) || String(auc) : `AUC ${(0, sdk_exports.toRoman)(auc) || auc}`;
394
+ if (mods.includes("upper")) aucStr = aucStr.toUpperCase();
395
+ if (mods.includes("lower")) aucStr = aucStr.toLowerCase();
396
+ return aucStr;
397
+ }
398
+ if (mods.includes("consul") || mods.includes("consuls")) {
399
+ const style = mods.includes("nominative") || mods.includes("nom") ? "nominative" : "ablative";
400
+ let consulStr = formatConsuls(zdt.year, style) ?? "";
401
+ if (mods.includes("upper")) consulStr = consulStr.toUpperCase();
402
+ if (mods.includes("lower")) consulStr = consulStr.toLowerCase();
403
+ return consulStr;
404
+ }
405
+ const roman = calculator(zdt.year, zdt.month, zdt.day);
406
+ const options = {};
407
+ if (mods.includes("short")) options.style = "short";
408
+ else options.style = "classical";
409
+ if (mods.includes("nominative")) options.case = "nominative";
410
+ else if (mods.includes("accusative")) options.case = "accusative";
411
+ else if (mods.includes("ablative")) options.case = "ablative";
412
+ else options.case = "customary";
413
+ if (mods.includes("words")) options.words = true;
414
+ if (mods.includes("auc")) options.auc = true;
415
+ if (mods.includes("num") || mods.includes("numeric")) options.aucFormat = "numeric";
416
+ if (mods.includes("upper")) options.casing = "upper";
417
+ else if (mods.includes("lower")) options.casing = "lower";
418
+ else if (mods.includes("capitalize")) options.casing = "capitalize";
419
+ return formatClassicalRomanDate(roman, options);
420
+ };
421
+ }
422
+
423
+ // src/math.ts
424
+ function getNonesDay(month) {
425
+ return MOMJ_MONTHS.has(month) ? 7 : 5;
426
+ }
427
+ function getIdesDay(month) {
428
+ return MOMJ_MONTHS.has(month) ? 15 : 13;
429
+ }
430
+ function yearToAuc(year, era) {
431
+ if (era === "BCE") return 754 - Math.abs(year);
432
+ if (era === "CE") return Math.abs(year) + AUC_OFFSET;
433
+ return year + AUC_OFFSET;
434
+ }
435
+ function aucToYear(auc, format = "astronomical") {
436
+ if (format === "historical") {
437
+ if (auc >= 754) return Object.freeze({ year: auc - AUC_OFFSET, era: "CE" });
438
+ if (auc >= 1) return Object.freeze({ year: 754 - auc, era: "BCE" });
439
+ return Object.freeze({ year: Math.abs(auc - 754) + 1, era: "BCE" });
440
+ }
441
+ return auc - AUC_OFFSET;
442
+ }
443
+ function calculateClassicalRomanDate(year, month, day, options) {
444
+ const isJulian = options?.isJulian ?? false;
445
+ const bissextile = options?.bissextile ?? true;
446
+ const leap = isLeapYear(year, isJulian);
447
+ const nones = getNonesDay(month);
448
+ const ides = getIdesDay(month);
449
+ let anchor;
450
+ let anchorMonth = month;
451
+ let anchorYear = year;
452
+ let relation;
453
+ let count = 1;
454
+ let isBissextileDay = false;
455
+ if (day === 1) {
456
+ anchor = "Kalends";
457
+ relation = "on";
458
+ count = 1;
459
+ } else if (day < nones) {
460
+ anchor = "Nones";
461
+ count = nones - day + 1;
462
+ relation = count === 2 ? "pridie" : "ante_diem";
463
+ } else if (day === nones) {
464
+ anchor = "Nones";
465
+ relation = "on";
466
+ count = 1;
467
+ } else if (day < ides) {
468
+ anchor = "Ides";
469
+ count = ides - day + 1;
470
+ relation = count === 2 ? "pridie" : "ante_diem";
471
+ } else if (day === ides) {
472
+ anchor = "Ides";
473
+ relation = "on";
474
+ count = 1;
475
+ } else {
476
+ anchor = "Kalends";
477
+ anchorMonth = month === 12 ? 1 : month + 1;
478
+ anchorYear = month === 12 ? year + 1 : year;
479
+ if (month === 2 && leap && bissextile) {
480
+ if (day === 24) {
481
+ count = 6;
482
+ relation = "ante_diem";
483
+ isBissextileDay = true;
484
+ } else if (day === 25) {
485
+ count = 6;
486
+ relation = "ante_diem";
487
+ isBissextileDay = false;
488
+ } else if (day > 25) {
489
+ count = 29 - day + 2;
490
+ relation = count === 2 ? "pridie" : "ante_diem";
491
+ } else {
492
+ count = 30 - day;
493
+ relation = "ante_diem";
494
+ }
495
+ } else {
496
+ const daysInCurrentMonth = getDaysInMonth(year, month, isJulian);
497
+ count = daysInCurrentMonth - day + 2;
498
+ relation = count === 2 ? "pridie" : "ante_diem";
499
+ }
500
+ }
501
+ const romanNumeral = relation === "ante_diem" && !isBissextileDay ? (0, sdk_exports.toRoman)(count) : "";
502
+ let latin = "";
503
+ let shortLatin = "";
504
+ if (isBissextileDay) {
505
+ latin = "ante diem bis sextum Kalendas Martias";
506
+ shortLatin = "a.d. bis VI Kal. Mart.";
507
+ } else if (relation === "on") {
508
+ latin = `${ANCHOR_ABLATIVE[anchor]} ${MONTH_ABLATIVE[anchorMonth]}`;
509
+ shortLatin = `${ANCHOR_SHORT[anchor]} ${MONTH_SHORT[anchorMonth]}`;
510
+ } else if (relation === "pridie") {
511
+ latin = `Pridie ${ANCHOR_ACCUSATIVE[anchor]} ${MONTH_ACCUSATIVE[anchorMonth]}`;
512
+ shortLatin = `Prid. ${ANCHOR_SHORT[anchor]} ${MONTH_SHORT[anchorMonth]}`;
513
+ } else {
514
+ latin = `ante diem ${romanNumeral} ${ANCHOR_ACCUSATIVE[anchor]} ${MONTH_ACCUSATIVE[anchorMonth]}`;
515
+ shortLatin = `a.d. ${romanNumeral} ${ANCHOR_SHORT[anchor]} ${MONTH_SHORT[anchorMonth]}`;
516
+ }
517
+ const auc = yearToAuc(year);
518
+ const base = {
519
+ anchor,
520
+ anchorMonth,
521
+ anchorYear,
522
+ relation,
523
+ count,
524
+ romanNumeral: isBissextileDay ? "bis VI" : romanNumeral,
525
+ isBissextile: isBissextileDay,
526
+ day,
527
+ month,
528
+ year,
529
+ auc,
530
+ latin,
531
+ shortLatin
532
+ };
533
+ const nominative = formatClassicalRomanDate(base, { case: "nominative", style: "classical" });
534
+ const accusative = formatClassicalRomanDate(base, { case: "accusative", style: "classical" });
535
+ const ablative = formatClassicalRomanDate(base, { case: "ablative", style: "classical" });
536
+ return Object.freeze({
537
+ ...base,
538
+ nominative,
539
+ accusative,
540
+ ablative,
541
+ format(opts) {
542
+ return formatClassicalRomanDate(this, opts);
543
+ }
544
+ });
545
+ }
546
+ function calculateGregorianFromRoman(anchor, anchorMonth, anchorYear, relation, count = 1, isBissextile = false, isJulian = false, bissextile = true) {
547
+ if (anchor === "Kalends") {
548
+ if (relation === "on") return Object.freeze({ year: anchorYear, month: anchorMonth, day: 1 });
549
+ const targetMonth = anchorMonth === 1 ? 12 : anchorMonth - 1;
550
+ const targetYear = anchorMonth === 1 ? anchorYear - 1 : anchorYear;
551
+ const leap = isLeapYear(targetYear, isJulian);
552
+ const effectiveCount2 = relation === "pridie" ? 2 : count;
553
+ if (targetMonth === 2 && leap && bissextile) {
554
+ if (isBissextile) return Object.freeze({ year: targetYear, month: 2, day: 24 });
555
+ if (effectiveCount2 === 6 && !isBissextile) return Object.freeze({ year: targetYear, month: 2, day: 25 });
556
+ if (effectiveCount2 < 6) return Object.freeze({ year: targetYear, month: 2, day: 29 - effectiveCount2 + 2 });
557
+ return Object.freeze({ year: targetYear, month: 2, day: 30 - effectiveCount2 });
558
+ }
559
+ const daysInMonth = getDaysInMonth(targetYear, targetMonth, isJulian);
560
+ return Object.freeze({ year: targetYear, month: targetMonth, day: daysInMonth - effectiveCount2 + 2 });
561
+ }
562
+ if (anchor === "Nones") {
563
+ const nonesDay = getNonesDay(anchorMonth);
564
+ if (relation === "on") return Object.freeze({ year: anchorYear, month: anchorMonth, day: nonesDay });
565
+ const effectiveCount2 = relation === "pridie" ? 2 : count;
566
+ return Object.freeze({ year: anchorYear, month: anchorMonth, day: nonesDay - effectiveCount2 + 1 });
567
+ }
568
+ const idesDay = getIdesDay(anchorMonth);
569
+ if (relation === "on") return Object.freeze({ year: anchorYear, month: anchorMonth, day: idesDay });
570
+ const effectiveCount = relation === "pridie" ? 2 : count;
571
+ return Object.freeze({ year: anchorYear, month: anchorMonth, day: idesDay - effectiveCount + 1 });
572
+ }
573
+
574
+ // src/parser.ts
575
+ import { getDaysInMonth as getDaysInMonth2 } from "tempo-kit/library";
576
+ var fold = (s) => s.toLowerCase().replace(/j/g, "i");
577
+ var MONTH_STEMS = Object.freeze({
578
+ ian: 1,
579
+ feb: 2,
580
+ mar: 3,
581
+ apr: 4,
582
+ mai: 5,
583
+ iun: 6,
584
+ iul: 7,
585
+ aug: 8,
586
+ sep: 9,
587
+ oct: 10,
588
+ nov: 11,
589
+ dec: 12
590
+ });
591
+ var COUNT_WORDS = (() => {
592
+ const map = /* @__PURE__ */ new Map();
593
+ for (const list of [COUNT_WORDS_ACCUSATIVE, COUNT_WORDS_ABLATIVE])
594
+ list.forEach((word, count) => {
595
+ if (word && count > 2) map.set(fold(word), count);
596
+ });
597
+ return map;
598
+ })();
599
+ var ERA_BCE = /* @__PURE__ */ new Set(["bce", "bc", "ac", "aec"]);
600
+ var ERA_CE = /* @__PURE__ */ new Set(["ce", "ad", "ce."]);
601
+ function toAnchor(token) {
602
+ if (!token) return void 0;
603
+ if (token === "kal" || token.startsWith("kalend") || token === "cal" || token.startsWith("calend")) return "Kalends";
604
+ if (token === "non" || token === "nonis" || token === "nonas" || token === "nonae" || token === "nones") return "Nones";
605
+ if (token === "id" || token === "idus" || token === "idibus") return "Ides";
606
+ return void 0;
607
+ }
608
+ function toMonth(token) {
609
+ if (!token || token.length < 3) return void 0;
610
+ return MONTH_STEMS[token.slice(0, 3)];
611
+ }
612
+ function toNumber(token) {
613
+ if (/^\d+$/.test(token)) return Number(token);
614
+ return (0, sdk_exports.fromRoman)(token);
615
+ }
616
+ function parseClassicalRomanDate(input, options) {
617
+ if (typeof input !== "string" || !input.trim())
618
+ throw new TypeError("Tempo.roman.parse requires a non-empty Latin date string");
619
+ const fail = (why) => {
620
+ throw new RangeError(`Unrecognised classical Roman date "${input}": ${why}`);
621
+ };
622
+ const tokens = fold(input).replace(/ab urbe condita/g, "auc").replace(/[.,;()]/g, " ").split(/\s+/).filter(Boolean);
623
+ let i = 0;
624
+ const peek = (n = 0) => tokens[i + n];
625
+ let marker = false;
626
+ if (peek() === "ante" && peek(1) === "diem") {
627
+ i += 2;
628
+ marker = true;
629
+ } else if (peek() === "a" && peek(1) === "d") {
630
+ i += 2;
631
+ marker = true;
632
+ } else if (peek() === "ad" || peek() === "die") {
633
+ i += 1;
634
+ marker = true;
635
+ }
636
+ let relation;
637
+ let count = 1;
638
+ let isBissextile = false;
639
+ if (peek() === "pridie" || peek() === "prid") {
640
+ i += 1;
641
+ relation = "pridie";
642
+ count = 2;
643
+ } else if (toAnchor(peek()) && !marker) {
644
+ relation = "on";
645
+ } else {
646
+ if (peek() === "bis") {
647
+ i += 1;
648
+ isBissextile = true;
649
+ }
650
+ const two = peek(1) ? `${peek()} ${peek(1)}` : void 0;
651
+ const asNumber = peek() ? toNumber(peek()) : NaN;
652
+ if (two && COUNT_WORDS.has(two)) {
653
+ count = COUNT_WORDS.get(two);
654
+ i += 2;
655
+ } else if (peek() && COUNT_WORDS.has(peek())) {
656
+ count = COUNT_WORDS.get(peek());
657
+ i += 1;
658
+ } else if (Number.isFinite(asNumber) && asNumber >= 2) {
659
+ count = asNumber;
660
+ i += 1;
661
+ } else {
662
+ return fail('expected a day count, "pridie", or an anchor (Kalends, Nones, Ides)');
663
+ }
664
+ if (count > 19) fail("the day count is out of range");
665
+ relation = count === 2 ? "pridie" : "ante_diem";
666
+ }
667
+ if (peek() === "ante") i += 1;
668
+ const anchor = toAnchor(peek());
669
+ if (!anchor) return fail("expected Kalends, Nones or Ides");
670
+ i += 1;
671
+ const anchorMonth = toMonth(peek());
672
+ if (!anchorMonth) return fail("expected a Latin month name");
673
+ i += 1;
674
+ if (isBissextile && !(count === 6 && anchor === "Kalends" && anchorMonth === 3))
675
+ fail('"bis" is only valid for "ante diem bis sextum Kalendas Martias"');
676
+ const rest = tokens.slice(i);
677
+ let year;
678
+ if (rest.length) {
679
+ const aucAt = rest.indexOf("auc");
680
+ if (aucAt >= 0) {
681
+ const value = toNumber(rest[aucAt === 0 ? 1 : aucAt - 1] ?? "");
682
+ if (!Number.isFinite(value) || value < 1 || rest.length !== 2)
683
+ return fail("invalid AUC year");
684
+ year = value - 753;
685
+ } else if (rest.length === 2 && ERA_BCE.has(rest[1]) && /^\d+$/.test(rest[0])) {
686
+ year = 1 - Number(rest[0]);
687
+ } else if (rest.length === 2 && ERA_CE.has(rest[1]) && /^\d+$/.test(rest[0])) {
688
+ year = Number(rest[0]);
689
+ } else if (rest.length === 1 && /^-?\d+$/.test(rest[0])) {
690
+ year = Number(rest[0]);
691
+ } else {
692
+ const restStr = rest.join(" ").replace(/\b(coss?|consulibus|consule)\b/g, "").trim();
693
+ const matches = restStr ? findConsulYears(restStr) : [];
694
+ if (matches.length === 1) {
695
+ year = matches[0].year;
696
+ } else if (matches.length > 1) {
697
+ return fail(`ambiguous consular dating "${restStr}": multiple years match (${matches.map((m) => m.year).join(", ")})`);
698
+ } else {
699
+ return fail(`unexpected trailing text "${rest.join(" ")}"`);
700
+ }
701
+ }
702
+ }
703
+ year ??= options?.year;
704
+ if (year === void 0) return fail('no year given; add "AUC", "BCE"/"CE", or pass options.year');
705
+ const anchorYear = anchor === "Kalends" && anchorMonth === 1 && relation !== "on" ? year + 1 : year;
706
+ const { month, day, year: resolvedYear } = calculateGregorianFromRoman(
707
+ anchor,
708
+ anchorMonth,
709
+ anchorYear,
710
+ relation,
711
+ count,
712
+ isBissextile,
713
+ options?.isJulian ?? false,
714
+ options?.bissextile ?? true
715
+ );
716
+ const valid = month >= 1 && month <= 12 && day >= 1 && day <= getDaysInMonth2(resolvedYear, month, options?.isJulian ?? false);
717
+ const classical = valid ? calculateClassicalRomanDate(resolvedYear, month, day, options) : void 0;
718
+ if (!classical || classical.anchor !== anchor || classical.anchorMonth !== anchorMonth || classical.relation !== relation || classical.count !== count || classical.isBissextile !== isBissextile)
719
+ return fail("that expression does not describe a real calendar date");
720
+ return Object.freeze({
721
+ year: resolvedYear,
722
+ month,
723
+ day,
724
+ auc: classical.auc,
725
+ classical
726
+ });
727
+ }
728
+
729
+ // src/index.ts
730
+ function extractDateComponents(date) {
731
+ if (!date)
732
+ throw new TypeError("Invalid date input provided to Tempo.roman");
733
+ if ((0, sdk_exports.isNumber)(date.yy) && (0, sdk_exports.isNumber)(date.mm) && (0, sdk_exports.isNumber)(date.dd))
734
+ return { year: date.yy, month: date.mm, day: date.dd };
735
+ if ((0, sdk_exports.isNumber)(date.year) && (0, sdk_exports.isNumber)(date.month) && (0, sdk_exports.isNumber)(date.day))
736
+ return { year: date.year, month: date.month, day: date.day };
737
+ if (date instanceof Date)
738
+ return { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() };
739
+ if ((0, sdk_exports.isFunction)(date.toDateTime)) {
740
+ const dt = date.toDateTime();
741
+ return { year: dt.year, month: dt.month, day: dt.day };
742
+ }
743
+ throw new TypeError("Invalid date input provided to Tempo.roman");
744
+ }
745
+ function createRomanNamespace(TempoClass) {
746
+ return {
747
+ parse(input, options) {
748
+ const { year, month, day } = parseClassicalRomanDate(input, options);
749
+ return new TempoClass({ year, month, day });
750
+ },
751
+ parseDate(input, options) {
752
+ return parseClassicalRomanDate(input, options);
753
+ },
754
+ toClassical(date, options) {
755
+ const { year, month, day } = extractDateComponents(date);
756
+ return calculateClassicalRomanDate(year, month, day, options);
757
+ },
758
+ yearToAuc(year, era) {
759
+ return yearToAuc(year, era);
760
+ },
761
+ aucToYear(auc, format = "astronomical") {
762
+ return aucToYear(auc, format);
763
+ },
764
+ getNonesDay(month) {
765
+ return getNonesDay(month);
766
+ },
767
+ getIdesDay(month) {
768
+ return getIdesDay(month);
769
+ },
770
+ isLeapYear(year, isJulian) {
771
+ return isLeapYear2(year, isJulian);
772
+ },
773
+ fromClassical(anchor, anchorMonth, anchorYear, relation, count = 1, isBissextile = false, isJulian = false, bissextile = true) {
774
+ return calculateGregorianFromRoman(
775
+ anchor,
776
+ anchorMonth,
777
+ anchorYear,
778
+ relation,
779
+ count,
780
+ isBissextile,
781
+ isJulian,
782
+ bissextile
783
+ );
784
+ },
785
+ format(date, options) {
786
+ const { year, month, day } = extractDateComponents(date);
787
+ const roman = calculateClassicalRomanDate(year, month, day, options);
788
+ return formatClassicalRomanDate(roman, options);
789
+ },
790
+ getConsuls(year) {
791
+ return getConsulsByYear(year);
792
+ },
793
+ formatConsuls(year, style) {
794
+ return formatConsuls(year, style);
795
+ },
796
+ findConsuls(query) {
797
+ return findConsulYears(query);
798
+ },
799
+ registerConsuls(catalog) {
800
+ registerConsuls(catalog);
801
+ }
802
+ };
803
+ }
804
+ var RomanPlugin = definePlugin({
805
+ name: "roman",
806
+ install(TempoClass) {
807
+ const romanNamespace = createRomanNamespace(TempoClass);
808
+ Object.defineProperty(TempoClass, "roman", {
809
+ value: (0, sdk_exports.deepFreeze)(romanNamespace),
810
+ writable: false,
811
+ configurable: true,
812
+ enumerable: false
813
+ });
814
+ if (!TempoClass.prototype.toRomanClassical) {
815
+ TempoClass.prototype.toRomanClassical = function(options) {
816
+ const { year, month, day } = extractDateComponents(this);
817
+ return calculateClassicalRomanDate(year, month, day, options);
818
+ };
819
+ }
820
+ if (!TempoClass.prototype.formatRoman) {
821
+ TempoClass.prototype.formatRoman = function(options) {
822
+ const { year, month, day } = extractDateComponents(this);
823
+ const roman = calculateClassicalRomanDate(year, month, day, options);
824
+ return formatClassicalRomanDate(roman, options);
825
+ };
826
+ }
827
+ if (!TempoClass.prototype.toAUC) {
828
+ TempoClass.prototype.toAUC = function() {
829
+ const { year } = extractDateComponents(this);
830
+ return yearToAuc(year);
831
+ };
832
+ }
833
+ if (!Object.getOwnPropertyDescriptor(TempoClass.prototype, "auc")) {
834
+ Object.defineProperty(TempoClass.prototype, "auc", {
835
+ get() {
836
+ const { year } = extractDateComponents(this);
837
+ return yearToAuc(year);
838
+ },
839
+ configurable: true,
840
+ enumerable: false
841
+ });
842
+ }
843
+ if (!Object.getOwnPropertyDescriptor(TempoClass.prototype, "roman")) {
844
+ Object.defineProperty(TempoClass.prototype, "roman", {
845
+ get() {
846
+ const { year, month, day } = extractDateComponents(this);
847
+ return calculateClassicalRomanDate(year, month, day);
848
+ },
849
+ configurable: true,
850
+ enumerable: false
851
+ });
852
+ }
853
+ if (!Object.getOwnPropertyDescriptor(TempoClass.prototype, "consuls")) {
854
+ Object.defineProperty(TempoClass.prototype, "consuls", {
855
+ get() {
856
+ const { year } = extractDateComponents(this);
857
+ return formatConsuls(year);
858
+ },
859
+ configurable: true,
860
+ enumerable: false
861
+ });
862
+ }
863
+ const tokenEvaluator = createRomanTokenEvaluator((y, m, d) => calculateClassicalRomanDate(y, m, d));
864
+ TempoClass.use({
865
+ registry: {
866
+ tokens: {
867
+ roman: tokenEvaluator
868
+ }
869
+ }
870
+ });
871
+ }
872
+ });
873
+ var index_default = RomanPlugin;
874
+ export {
875
+ ANCHOR_ABLATIVE,
876
+ ANCHOR_ACCUSATIVE,
877
+ ANCHOR_NOMINATIVE,
878
+ ANCHOR_SHORT,
879
+ AUC_OFFSET,
880
+ COUNT_WORDS_ABLATIVE,
881
+ COUNT_WORDS_ACCUSATIVE,
882
+ LANDMARK_CONSULS,
883
+ MOMJ_MONTHS,
884
+ MONTH_ABLATIVE,
885
+ MONTH_ACCUSATIVE,
886
+ MONTH_NOMINATIVE,
887
+ MONTH_SHORT,
888
+ RomanPlugin,
889
+ aucToYear,
890
+ calculateClassicalRomanDate,
891
+ calculateGregorianFromRoman,
892
+ createRomanTokenEvaluator,
893
+ index_default as default,
894
+ findConsulYears,
895
+ formatClassicalRomanDate,
896
+ formatConsuls,
897
+ getConsulCatalog,
898
+ getConsulsByYear,
899
+ getIdesDay,
900
+ getNonesDay,
901
+ parseClassicalRomanDate,
902
+ registerConsuls,
903
+ resetConsulCatalog,
904
+ toAblativeConsulName,
905
+ yearToAuc
906
+ };