histropediajs 1.6.0 → 1.6.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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- HistropediaJS v1.6.0 | Histropedia Ltd. (c) 2026 | https://js.histropedia.com
2
+ HistropediaJS v1.6.1 | Histropedia Ltd. (c) 2026 | https://js.histropedia.com
3
3
  Use of this software is subject to our End User Licence Agreement: https://js.histropedia.com/licence.html
4
4
  */
5
5
  var __defProp = Object.defineProperty;
@@ -65,1785 +65,42 @@ function tween({
65
65
  };
66
66
  }
67
67
  __name(tween, "tween");
68
- const _LoggerImpl = class _LoggerImpl {
69
- constructor() {
70
- this._enabled = false;
71
- this._prefix = "[Histropedia]";
72
- const c = typeof console !== "undefined" ? console : null;
73
- this._console = c;
74
- this._fns = {
75
- log: c && c.log ? c.log.bind(c) : () => {
76
- },
77
- warn: c && c.warn ? c.warn.bind(c) : () => {
78
- },
79
- error: c && c.error ? c.error.bind(c) : () => {
80
- },
81
- info: c && c.info ? c.info.bind(c) : () => {
82
- },
83
- debug: c && c.debug ? c.debug.bind(c) : c && c.log ? c.log.bind(c) : () => {
84
- },
85
- group: c && c.group ? c.group.bind(c) : c && c.log ? c.log.bind(c) : () => {
86
- },
87
- groupCollapsed: c && c.groupCollapsed ? c.groupCollapsed.bind(c) : c && c.group ? c.group.bind(c) : c && c.log ? c.log.bind(c) : () => {
88
- },
89
- groupEnd: c && c.groupEnd ? c.groupEnd.bind(c) : () => {
90
- }
91
- };
92
- }
93
- setEnabled(enabled) {
94
- this._enabled = !!enabled;
95
- }
96
- isEnabled() {
97
- return !!this._enabled;
98
- }
99
- setPrefix(prefix) {
100
- this._prefix = String(prefix || "");
101
- }
102
- getPrefix() {
103
- return this._prefix;
104
- }
105
- _withPrefixedArgs(argsArray) {
106
- if (!this._prefix) {
107
- return argsArray;
108
- }
109
- if (argsArray && argsArray.length > 0 && typeof argsArray[0] === "string") {
110
- const cloned = argsArray.slice();
111
- cloned[0] = `${this._prefix} ${cloned[0]}`;
112
- return cloned;
113
- }
114
- return [this._prefix, ...argsArray];
115
- }
116
- _log(method, args) {
117
- if (!this._enabled) {
118
- return;
119
- }
120
- const fn = this._fns[method] || this._fns.log;
121
- fn(...this._withPrefixedArgs(args));
122
- }
123
- log(...args) {
124
- this._log("log", args);
125
- }
126
- warn(...args) {
127
- this._log("warn", args);
128
- }
129
- error(...args) {
130
- this._log("error", args);
131
- }
132
- info(...args) {
133
- this._log("info", args);
134
- }
135
- debug(...args) {
136
- this._log("debug", args);
137
- }
138
- group(...args) {
139
- if (!this._enabled) {
140
- return;
141
- }
142
- this._fns.group(...this._withPrefixedArgs(args));
143
- }
144
- groupCollapsed(...args) {
145
- if (!this._enabled) {
146
- return;
147
- }
148
- this._fns.groupCollapsed(...this._withPrefixedArgs(args));
149
- }
150
- groupEnd() {
151
- if (!this._enabled) {
152
- return;
153
- }
154
- this._fns.groupEnd();
155
- }
156
- };
157
- __name(_LoggerImpl, "LoggerImpl");
158
- let LoggerImpl = _LoggerImpl;
159
- const Logger = new LoggerImpl();
160
- const DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
161
- const MONTH_NAMES = [
162
- "Jan",
163
- "Feb",
164
- "Mar",
165
- "Apr",
166
- "May",
167
- "Jun",
168
- "Jul",
169
- "Aug",
170
- "Sep",
171
- "Oct",
172
- "Nov",
173
- "Dec"
174
- ];
175
- const LEGACY_PRECISIONS = {
176
- 1: "billion-years",
177
- 3: "million-years",
178
- 6: "millennium",
179
- 7: "century",
180
- 8: "decade",
181
- 9: "year",
182
- 10: "month",
183
- 11: "day",
184
- 12: "hour",
185
- 13: "minute",
186
- 14: "second",
187
- 15: "millisecond"
188
- };
189
- const DMY_STRING_PATTERN = /^(-?\d+)(?:-(\d{1,2}))?(?:-(\d{1,2}))?(?:[T ](\d{1,2})(?::(\d{1,2}))?(?::(\d{1,2})(?:\.(\d{1,3}))?)?)?$/;
190
- const MILLISECONDS_PER_SECOND = 1e3;
191
- const MILLISECONDS_PER_MINUTE = 60 * MILLISECONDS_PER_SECOND;
192
- const MILLISECONDS_PER_HOUR = 60 * MILLISECONDS_PER_MINUTE;
193
- const MILLISECONDS_PER_DAY = 24 * MILLISECONDS_PER_HOUR;
194
- function normalizePrecision(precision) {
195
- return Object.prototype.hasOwnProperty.call(LEGACY_PRECISIONS, precision) ? LEGACY_PRECISIONS[precision] : precision || "day";
196
- }
197
- __name(normalizePrecision, "normalizePrecision");
198
- function getHistoricalPeriodBounds(year, size) {
199
- const endYear = Math.ceil(year / size) * size;
200
- return {
201
- startYear: endYear - size + 1,
202
- endYear
203
- };
204
- }
205
- __name(getHistoricalPeriodBounds, "getHistoricalPeriodBounds");
206
- function clampInteger(value, fallback, minimum, maximum) {
207
- const parsed = Number(value);
208
- if (!Number.isFinite(parsed)) {
209
- return fallback;
210
- }
211
- return Math.min(maximum, Math.max(minimum, Math.trunc(parsed)));
212
- }
213
- __name(clampInteger, "clampInteger");
214
- function setTimeParts(target, hour, minute, second, millisecond) {
215
- const values = {
216
- hour: clampInteger(hour, 0, 0, 23),
217
- minute: clampInteger(minute, 0, 0, 59),
218
- second: clampInteger(second, 0, 0, 59),
219
- millisecond: clampInteger(millisecond, 0, 0, 999)
220
- };
221
- for (const [key, value] of Object.entries(values)) {
222
- Object.defineProperty(target, key, {
223
- value,
224
- enumerable: value !== 0,
225
- configurable: true,
226
- writable: true
227
- });
228
- }
229
- }
230
- __name(setTimeParts, "setTimeParts");
231
- function setPrecision(target, precision) {
232
- if (precision === void 0) {
233
- return;
234
- }
235
- Object.defineProperty(target, "precision", {
236
- value: precision,
237
- enumerable: false,
238
- configurable: true,
239
- writable: true
240
- });
241
- }
242
- __name(setPrecision, "setPrecision");
243
- function createAdjustedDmy(source, values) {
244
- return new Dmy({ ...values, precision: source.precision });
245
- }
246
- __name(createAdjustedDmy, "createAdjustedDmy");
247
- function Dmy(year, month, day, hour, minute, second, millisecond) {
248
- if (typeof year === "object") {
249
- const options = year;
250
- this.year = options.year;
251
- this.month = options.month;
252
- this.day = getCorrectDay(options.year, options.month, options.day);
253
- setTimeParts(this, options.hour, options.minute, options.second, options.millisecond);
254
- setPrecision(this, options.precision);
255
- } else {
256
- this.year = year;
257
- this.month = month;
258
- this.day = getCorrectDay(year, month, day);
259
- setTimeParts(this, hour, minute, second, millisecond);
260
- }
261
- }
262
- __name(Dmy, "Dmy");
263
- function getCorrectDay(year, month, day) {
264
- return day > 28 ? Math.min(day, daysInMonth(year, month)) : day;
265
- }
266
- __name(getCorrectDay, "getCorrectDay");
267
- function daysInMonth(year, month) {
268
- if (month === 2) {
269
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
270
- return 29;
271
- }
272
- }
273
- return DAYS_IN_MONTH[month - 1];
274
- }
275
- __name(daysInMonth, "daysInMonth");
276
- function digitGroupedNumber(number, separator) {
277
- number = number.toString();
278
- separator = typeof separator === "string" ? separator : ",";
279
- if (number.length <= 4) {
280
- return number;
281
- }
282
- return number.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
283
- }
284
- __name(digitGroupedNumber, "digitGroupedNumber");
285
- Dmy.prototype.getDaysTo = function(other) {
286
- const dayDifference = other.getDaysSinceYearZero() - this.getDaysSinceYearZero();
287
- const timeDifference = other.getMillisecondsOfDay() - this.getMillisecondsOfDay();
288
- return dayDifference + timeDifference / MILLISECONDS_PER_DAY;
289
- };
290
- Dmy.prototype.getMillisecondsOfDay = function() {
291
- return this.hour * MILLISECONDS_PER_HOUR + this.minute * MILLISECONDS_PER_MINUTE + this.second * MILLISECONDS_PER_SECOND + this.millisecond;
292
- };
293
- Dmy.prototype.getMonthsTo = function(other) {
294
- return this.getYearsTo(other) * 12;
295
- };
296
- Dmy.prototype.getYearsTo = function(other) {
297
- let yearDiff = other.year - this.year;
298
- yearDiff += (other.month - this.month) / 12 + (other.day - this.day) / 365.2422 + (other.getMillisecondsOfDay() - this.getMillisecondsOfDay()) / (MILLISECONDS_PER_DAY * 365.2422);
299
- return yearDiff;
300
- };
301
- Dmy.prototype.getLeapYearsSinceYearZero = function() {
302
- let year = this.year;
303
- if (this.month < 3) {
304
- year--;
305
- }
306
- return Math.floor(year / 4) - Math.floor(year / 100) + Math.floor(year / 400);
307
- };
308
- Dmy.prototype.getDaysSinceYearZero = function() {
309
- const year = this.year;
310
- let days = year * 365 + this.day;
311
- for (let i = 0; i < this.month - 1; i++) {
312
- days += DAYS_IN_MONTH[i];
313
- }
314
- days += this.getLeapYearsSinceYearZero();
315
- return days;
316
- };
317
- Dmy.prototype.getDayOfYear = function() {
318
- let dayOfYear = this.day;
319
- for (let m = 1; m < this.month; m++) {
320
- dayOfYear += daysInMonth(this.year, m);
321
- }
322
- return dayOfYear;
323
- };
324
- Dmy.getByDayOfYear = function(year, dayOfYear) {
325
- const dmy = new Dmy(year, 1, 1);
326
- let dim = DAYS_IN_MONTH[0];
327
- for (let i = 0; i < dayOfYear - 1; i++) {
328
- dmy.day++;
329
- if (dmy.day > dim) {
330
- dmy.day = 1;
331
- dmy.month++;
332
- if (dmy.month > 12) {
333
- dmy.month = 1;
334
- dmy.year++;
335
- }
336
- dim = dmy.month === 2 ? daysInMonth(dmy.year, dmy.month) : DAYS_IN_MONTH[dmy.month - 1];
337
- }
338
- }
339
- return dmy;
340
- };
341
- Dmy.prototype.getNextDay = function() {
342
- return this.addDays(1);
343
- };
344
- Dmy.prototype.addDays = function(amount) {
345
- let day = this.day;
346
- let month = this.month;
347
- let year = this.year;
348
- const direction = amount < 0 ? -1 : 1;
349
- let remaining = Math.abs(Math.trunc(amount));
350
- while (remaining > 0) {
351
- if (direction > 0) {
352
- day++;
353
- if (day > daysInMonth(year, month)) {
354
- day = 1;
355
- month++;
356
- if (month > 12) {
357
- month = 1;
358
- year++;
359
- }
360
- }
361
- } else {
362
- day--;
363
- if (day < 1) {
364
- month--;
365
- if (month < 1) {
366
- month = 12;
367
- year--;
368
- }
369
- day = daysInMonth(year, month);
370
- }
371
- }
372
- remaining--;
373
- }
374
- return createAdjustedDmy(this, {
375
- year,
376
- month,
377
- day,
378
- hour: this.hour,
379
- minute: this.minute,
380
- second: this.second,
381
- millisecond: this.millisecond
382
- });
383
- };
384
- Dmy.prototype.addMilliseconds = function(amount) {
385
- let date = this;
386
- let milliseconds = this.getMillisecondsOfDay() + Math.trunc(amount);
387
- while (milliseconds < 0) {
388
- date = date.addDays(-1);
389
- milliseconds += MILLISECONDS_PER_DAY;
390
- }
391
- while (milliseconds >= MILLISECONDS_PER_DAY) {
392
- date = date.addDays(1);
393
- milliseconds -= MILLISECONDS_PER_DAY;
394
- }
395
- const hour = Math.floor(milliseconds / MILLISECONDS_PER_HOUR);
396
- milliseconds -= hour * MILLISECONDS_PER_HOUR;
397
- const minute = Math.floor(milliseconds / MILLISECONDS_PER_MINUTE);
398
- milliseconds -= minute * MILLISECONDS_PER_MINUTE;
399
- const second = Math.floor(milliseconds / MILLISECONDS_PER_SECOND);
400
- const millisecond = milliseconds - second * MILLISECONDS_PER_SECOND;
401
- return createAdjustedDmy(this, {
402
- year: date.year,
403
- month: date.month,
404
- day: date.day,
405
- hour,
406
- minute,
407
- second,
408
- millisecond
409
- });
410
- };
411
- Dmy.prototype.addSeconds = function(amount) {
412
- return this.addMilliseconds(amount * MILLISECONDS_PER_SECOND);
413
- };
414
- Dmy.prototype.addMinutes = function(amount) {
415
- return this.addMilliseconds(amount * MILLISECONDS_PER_MINUTE);
416
- };
417
- Dmy.prototype.addHours = function(amount) {
418
- return this.addMilliseconds(amount * MILLISECONDS_PER_HOUR);
419
- };
420
- Dmy.prototype.addMonths = function(amount) {
421
- let month = this.month;
422
- let year = this.year;
423
- for (let i = 0; i < amount; i++) {
424
- month++;
425
- if (month > 12) {
426
- month = 1;
427
- year++;
428
- }
429
- }
430
- return createAdjustedDmy(this, { year, month, day: 1 });
431
- };
432
- Dmy.prototype.getPreviousDay = function() {
433
- return this.addDays(-1);
434
- };
435
- Dmy.prototype.getNextMonth = function() {
436
- let month = this.month;
437
- let year = this.year;
438
- month++;
439
- if (month > 12) {
440
- month = 1;
441
- year++;
442
- }
443
- return createAdjustedDmy(this, { year, month, day: 1 });
444
- };
445
- Dmy.prototype.getPreviousMonth = function() {
446
- let month = this.month;
447
- let year = this.year;
448
- month--;
449
- if (month < 1) {
450
- month = 12;
451
- year--;
452
- }
453
- return createAdjustedDmy(this, { year, month, day: 1 });
454
- };
455
- Dmy.prototype.addYears = function(amount) {
456
- return createAdjustedDmy(this, { year: this.year + amount, month: 1, day: 1 });
457
- };
458
- function pad(value, length) {
459
- return String(value).padStart(length, "0");
460
- }
461
- __name(pad, "pad");
462
- Dmy.prototype.format = function(format, options) {
463
- options = options || {};
464
- format = format || "D MMM YYYY";
465
- const prefixSettings = options.yearPrefix;
466
- const bceText = typeof options.bceText === "string" ? options.bceText : " ʙᴄᴇ";
467
- const isBc = this.year <= 0;
468
- const is1Bc = this.year === 0;
469
- const thousandsSeparator = options.thousandsSeparator;
470
- if (prefixSettings && !is1Bc) {
471
- const prefixValue = prefixSettings.value || 1;
472
- const prefixLabel = prefixSettings.label || "";
473
- let formattedYear;
474
- if (isBc) {
475
- formattedYear = digitGroupedNumber((-this.year + 1) / prefixValue, thousandsSeparator) + prefixLabel + bceText;
476
- } else {
477
- formattedYear = digitGroupedNumber(this.year / prefixValue, thousandsSeparator) + prefixLabel;
478
- }
479
- return formattedYear;
480
- }
481
- return format.replace(
482
- "YYYY",
483
- isBc ? digitGroupedNumber(-this.year + 1, thousandsSeparator) + bceText : digitGroupedNumber(this.year, thousandsSeparator)
484
- ).replace("D", this.day).replace("MMM", MONTH_NAMES[this.month - 1]).replace("HH", pad(this.hour, 2)).replace("mm", pad(this.minute, 2)).replace("ss", pad(this.second, 2)).replace("SSS", pad(this.millisecond, 3));
485
- };
486
- Dmy.prototype.isSame = function(other) {
487
- return other.year === this.year && other.month === this.month && other.day === this.day && (other.hour || 0) === this.hour && (other.minute || 0) === this.minute && (other.second || 0) === this.second && (other.millisecond || 0) === this.millisecond;
488
- };
489
- Dmy.prototype.toKeyString = function() {
490
- const dateKey = `${this.year}|${this.month}|${this.day}`;
491
- if (this.getMillisecondsOfDay() === 0) {
492
- return dateKey;
493
- }
494
- return `${dateKey}|${this.hour}|${this.minute}|${this.second}|${this.millisecond}`;
495
- };
496
- Dmy.prototype.isAfter = function(other) {
497
- const fields = ["year", "month", "day", "hour", "minute", "second", "millisecond"];
498
- for (let i = 0; i < fields.length; i++) {
499
- const field = fields[i];
500
- const thisValue = this[field] || 0;
501
- const otherValue = other[field] || 0;
502
- if (thisValue !== otherValue) {
503
- return thisValue > otherValue;
504
- }
505
- }
506
- return false;
507
- };
508
- Dmy.prototype.isBetween = function(from, to) {
509
- return this.isAfter(from) && to.isAfter(this);
510
- };
511
- Dmy.prototype.compare = function(other) {
512
- if (this.isSame(other)) {
513
- return 0;
514
- }
515
- if (this.isAfter(other)) {
516
- return 1;
517
- }
518
- return -1;
519
- };
520
- Dmy.prototype.asFloat = function() {
521
- const m = this.month - 1;
522
- const d = this.day - 1;
523
- const dayFraction = this.getMillisecondsOfDay() / MILLISECONDS_PER_DAY;
524
- if (m === 0 && d === 0 && dayFraction === 0) {
525
- return this.year;
526
- }
527
- return Math.round((this.year + (m * 31 + d + dayFraction) / 371) * 100) / 100;
528
- };
529
- Dmy.prototype.isInFuture = function() {
530
- const date = /* @__PURE__ */ new Date();
531
- const now = new Dmy(
532
- date.getFullYear(),
533
- date.getMonth() + 1,
534
- date.getDate(),
535
- date.getHours(),
536
- date.getMinutes(),
537
- date.getSeconds(),
538
- date.getMilliseconds()
539
- );
540
- return this.isAfter(now);
541
- };
542
- Dmy.prototype.convertToIso = function() {
543
- if (this.year < 0) {
544
- this.year += 1;
545
- }
546
- return this;
547
- };
548
- Dmy.CreateAsStartOfPeriod = function(isoDmy, precision) {
549
- const isoYear = isoDmy.year;
550
- const month = isoDmy.month || 1;
551
- const day = isoDmy.day || 1;
552
- precision = normalizePrecision(precision);
553
- if (precision === "millisecond") {
554
- return new Dmy(isoDmy);
555
- }
556
- if (precision === "second") {
557
- return new Dmy(isoYear, month, day, isoDmy.hour, isoDmy.minute, isoDmy.second, 0);
558
- }
559
- if (precision === "minute") {
560
- return new Dmy(isoYear, month, day, isoDmy.hour, isoDmy.minute, 0, 0);
561
- }
562
- if (precision === "hour") {
563
- return new Dmy(isoYear, month, day, isoDmy.hour, 0, 0, 0);
564
- }
565
- if (precision === "day") {
566
- return new Dmy(isoYear, month, day);
567
- }
568
- if (precision === "month") {
569
- return new Dmy(isoYear, month, 1);
570
- }
571
- if (precision === "year" || precision === "million-years" || precision === "billion-years") {
572
- return new Dmy(isoYear, 1, 1);
573
- }
574
- if (precision === "decade") {
575
- return new Dmy(Math.floor(isoYear / 10) * 10, 1, 1);
576
- }
577
- if (precision === "century") {
578
- return new Dmy(getHistoricalPeriodBounds(isoYear, 100).startYear, 1, 1);
579
- }
580
- if (precision === "millennium") {
581
- return new Dmy(getHistoricalPeriodBounds(isoYear, 1e3).startYear, 1, 1);
582
- }
583
- return new Dmy(isoYear, month, day);
584
- };
585
- Dmy.CreateAsEndOfPeriod = function(isoDmy, precision) {
586
- const isoYear = isoDmy.year;
587
- const month = isoDmy.month || 1;
588
- const day = isoDmy.day || 1;
589
- precision = normalizePrecision(precision);
590
- if (precision === "millisecond") {
591
- return new Dmy(isoDmy);
592
- }
593
- if (precision === "second") {
594
- return new Dmy(isoYear, month, day, isoDmy.hour, isoDmy.minute, isoDmy.second, 999);
595
- }
596
- if (precision === "minute") {
597
- return new Dmy(isoYear, month, day, isoDmy.hour, isoDmy.minute, 59, 999);
598
- }
599
- if (precision === "hour") {
600
- return new Dmy(isoYear, month, day, isoDmy.hour, 59, 59, 999);
601
- }
602
- if (precision === "day") {
603
- return new Dmy(isoYear, month, day);
604
- }
605
- if (precision === "month") {
606
- return new Dmy(isoYear, month, daysInMonth(isoYear, month));
607
- }
608
- if (precision === "year") {
609
- return new Dmy(isoYear, 12, 31);
610
- }
611
- if (precision === "decade") {
612
- return new Dmy(Math.floor(isoYear / 10) * 10 + 9, 12, 31);
613
- }
614
- if (precision === "century") {
615
- return new Dmy(getHistoricalPeriodBounds(isoYear, 100).endYear, 12, 31);
616
- }
617
- if (precision === "millennium") {
618
- return new Dmy(getHistoricalPeriodBounds(isoYear, 1e3).endYear, 12, 31);
619
- }
620
- if (precision === "million-years") {
621
- return new Dmy(isoYear + 999999, 12, 31);
622
- }
623
- if (precision === "billion-years") {
624
- return new Dmy(isoYear + 999999999, 12, 31);
625
- }
626
- Logger.error("precision is not implemented");
627
- return new Dmy(isoYear, month, day);
628
- };
629
- Dmy.CreateAsExclusiveEndOfPeriod = function(isoDmy, precision) {
630
- precision = normalizePrecision(precision);
631
- const start = Dmy.CreateAsStartOfPeriod(isoDmy, precision);
632
- if (precision === "millisecond") {
633
- return start.addMilliseconds(1);
634
- }
635
- if (precision === "second") {
636
- return start.addSeconds(1);
637
- }
638
- if (precision === "minute") {
639
- return start.addMinutes(1);
640
- }
641
- if (precision === "hour") {
642
- return start.addHours(1);
643
- }
644
- if (precision === "day") {
645
- return start.addDays(1);
646
- }
647
- return Dmy.CreateAsEndOfPeriod(isoDmy, precision).addDays(1);
648
- };
649
- Dmy.now = function() {
650
- const now = /* @__PURE__ */ new Date();
651
- return new Dmy({
652
- year: now.getYear() + 1900,
653
- month: now.getMonth() + 1,
654
- day: now.getDate()
655
- });
656
- };
657
- function parseDmyString(dateString) {
658
- const match = String(dateString).match(DMY_STRING_PATTERN);
659
- if (!match) {
660
- return null;
661
- }
662
- const year = parseInt(match[1], 10);
663
- const month = match[2] == null ? 1 : parseInt(match[2], 10);
664
- const day = match[3] == null ? 1 : parseInt(match[3], 10);
665
- const hour = match[4] == null ? 0 : parseInt(match[4], 10);
666
- const minute = match[5] == null ? 0 : parseInt(match[5], 10);
667
- const second = match[6] == null ? 0 : parseInt(match[6], 10);
668
- const millisecond = match[7] ? parseInt(match[7].padEnd(3, "0"), 10) : 0;
669
- return {
670
- date: new Dmy({
671
- year,
672
- month,
673
- day,
674
- hour,
675
- minute,
676
- second,
677
- millisecond
678
- }),
679
- hasMonth: match[2] != null,
680
- hasDay: match[3] != null,
681
- hasTime: match[4] != null
682
- };
683
- }
684
- __name(parseDmyString, "parseDmyString");
685
- Dmy.fromString = function(dateString) {
686
- const parsed = parseDmyString(dateString);
687
- return parsed ? parsed.date : new Dmy(NaN, 1, 1);
688
- };
689
- function merge(target, ...sources) {
690
- return Object.assign(target, ...sources);
691
- }
692
- __name(merge, "merge");
693
- function deepMerge(target, ...sources) {
694
- const ensureSafeProto = /* @__PURE__ */ __name((obj) => {
695
- if (obj && typeof obj === "object" && !Object.prototype.hasOwnProperty.call(obj, "__proto__")) {
696
- try {
697
- Object.defineProperty(obj, "__proto__", {
698
- value: void 0,
699
- writable: true,
700
- enumerable: false,
701
- configurable: true
702
- });
703
- } catch {
704
- }
705
- }
706
- }, "ensureSafeProto");
707
- ensureSafeProto(target);
708
- const isUnsafeKey = /* @__PURE__ */ __name((key) => key === "__proto__" || key === "constructor" || key === "prototype", "isUnsafeKey");
709
- const isPlainObject = /* @__PURE__ */ __name((obj) => {
710
- if (obj === null || typeof obj !== "object") {
711
- return false;
712
- }
713
- const proto = Object.getPrototypeOf(obj);
714
- return proto === Object.prototype || proto === null;
715
- }, "isPlainObject");
716
- for (const src of sources) {
717
- if (!src || typeof src !== "object") {
718
- continue;
719
- }
720
- for (const k of Object.keys(src)) {
721
- if (isUnsafeKey(k)) {
722
- continue;
723
- }
724
- const v = src[k];
725
- if (Array.isArray(v)) {
726
- target[k] = v.slice();
727
- continue;
728
- }
729
- if (isPlainObject(v)) {
730
- const base = isPlainObject(target[k]) ? target[k] : {};
731
- ensureSafeProto(base);
732
- target[k] = deepMerge(base, v);
733
- continue;
734
- }
735
- target[k] = v;
736
- }
737
- }
738
- ensureSafeProto(target);
739
- return target;
740
- }
741
- __name(deepMerge, "deepMerge");
742
- function buildObjectFromPath(path, value) {
743
- const pathParts = path.split(".");
744
- const pathEnd = pathParts[pathParts.length - 1];
745
- let obj = {};
746
- obj[pathEnd] = value;
747
- for (let i = pathParts.length - 2; i >= 0; i--) {
748
- const previousPathPart = pathParts[i];
749
- const objClone = deepMerge({}, obj);
750
- obj = {};
751
- obj[previousPathPart] = objClone;
752
- }
753
- return obj;
754
- }
755
- __name(buildObjectFromPath, "buildObjectFromPath");
756
- function defineValueOrFunctionProperty(obj, propName) {
757
- const privatePropertyName = `_${propName}`;
758
- obj[privatePropertyName] = void 0;
759
- Object.defineProperty(obj, propName, {
760
- get() {
761
- const value = this[privatePropertyName];
762
- if (typeof value === "function") {
763
- return value(this);
764
- }
765
- return value;
766
- },
767
- set(value) {
768
- this[privatePropertyName] = value;
769
- },
770
- enumerable: true,
771
- configurable: false
772
- });
773
- }
774
- __name(defineValueOrFunctionProperty, "defineValueOrFunctionProperty");
775
- function isUndefined(value) {
776
- return typeof value === "undefined";
777
- }
778
- __name(isUndefined, "isUndefined");
779
- const propertyAbbreviations = {
780
- id: "i",
781
- title: "t",
782
- rank: "r",
783
- subtitle: "s",
784
- "from.year": "fy",
785
- "from.month": "fm",
786
- "from.day": "fd",
787
- "from.hour": "fhr",
788
- "from.minute": "fmi",
789
- "from.second": "fs",
790
- "from.millisecond": "fms",
791
- "from.precision": "fp",
792
- "to.year": "ty",
793
- "to.month": "tm",
794
- "to.day": "td",
795
- "to.hour": "thr",
796
- "to.minute": "tmi",
797
- "to.second": "ts",
798
- "to.millisecond": "tms",
799
- "to.precision": "tp",
800
- isToPresent: "p",
801
- isStarred: "v",
802
- "offset.left": "ol",
803
- "offset.top": "ot",
804
- imageUrl: "m",
805
- lane: "ln",
806
- style: "st",
807
- activeStyle: "ast",
808
- hiddenByFilter: "h",
809
- hidePeriodLine: "hp"
810
- };
811
- function extractProperty(data, property) {
812
- return Object.prototype.hasOwnProperty.call(data, property) ? data[property] : data[propertyAbbreviations[property]];
813
- }
814
- __name(extractProperty, "extractProperty");
815
- function extractPropertyFromPath(data, path) {
816
- const pathParts = path.split(".");
817
- const value = pathParts.reduce((curr, next) => curr ? curr[next] : void 0, data);
818
- return isUndefined(value) ? data[propertyAbbreviations[path]] : value;
819
- }
820
- __name(extractPropertyFromPath, "extractPropertyFromPath");
821
- function isPath(property) {
822
- return property.indexOf(".") > -1;
823
- }
824
- __name(isPath, "isPath");
825
- function getPropertyFromData(data, property) {
826
- if (isPath(property)) {
827
- return extractPropertyFromPath(data, property);
828
- }
829
- return extractProperty(data, property);
830
- }
831
- __name(getPropertyFromData, "getPropertyFromData");
832
- function existsInData(data, property) {
833
- if (isPath(property)) {
834
- return !isUndefined(extractPropertyFromPath(data, property));
835
- }
836
- return !isUndefined(extractProperty(data, property));
837
- }
838
- __name(existsInData, "existsInData");
839
- defineValueOrFunctionProperty(Article.prototype, "hidePeriodLine");
840
- defineValueOrFunctionProperty(Article.prototype, "hiddenByFilter");
841
- function Article(owner, id) {
842
- this.id = id;
843
- this.owner = owner;
844
- this.isDataLoaded = false;
845
- this.imageLoaded = false;
846
- this.stacking = 0;
847
- this.groupIndex = 0;
848
- this.isActive = false;
849
- this.isVisible = false;
850
- this.isVisibleInLane = true;
851
- this.isInRange = false;
852
- this.isInView = false;
853
- this.isVisibleInGroup = false;
854
- this.isVisibleInRows = true;
855
- this.isStarred = false;
856
- this.isMouseOverStar = false;
857
- this.isMouseover = false;
858
- this.isDragging = false;
859
- this.registeredPosition = { left: 0, top: 0 };
860
- this.position = { left: 0, top: 0 };
861
- this.dragStartOffset = { left: 0, top: 0 };
862
- this.indicator = { fromX: 0, toX: 0 };
863
- this.offset = { left: 0, top: 0 };
864
- this.finalOffset = { left: 0, top: 0 };
865
- this.isVisibleAfterFade = false;
866
- this.opacity = 0;
867
- this.fadeAnimation = {
868
- finalOpacity: 0,
869
- dummyElement: null
870
- };
871
- this.moveAnimation = {
872
- finalOffset: { left: 0, top: 0 },
873
- dummyElement: void 0
874
- };
875
- this.row = 0;
876
- this.laneId = null;
877
- this.laneOrder = 0;
878
- this.isFading = false;
879
- this.isMoving = false;
880
- this._cachedHeight = 0;
881
- this._cachedWidth = 0;
882
- this._sizeValid = false;
883
- this._sizeCacheKey = null;
884
- this._layoutCaches = null;
885
- this._resolvedDefaultCardLayout = null;
886
- this._resolvedCardLayoutName = null;
887
- }
888
- __name(Article, "Article");
889
- Article.prototype.setupByReceivedData = function(receivedData) {
890
- this.owner._assignArticleToLane(this, this.owner._resolveLaneIdFromArticleData(receivedData));
891
- const articleDefaultData = this.owner._getResolvedArticleOptions(this).defaultData;
892
- const data = deepMerge({}, articleDefaultData, receivedData);
893
- if (!existsInData(receivedData, "to")) {
894
- delete data.to;
895
- }
896
- this.data = deepMerge({}, receivedData);
897
- this.title = getPropertyFromData(data, "title") || "";
898
- this.rank = getPropertyFromData(data, "rank") || 0;
899
- this.subtitle = getPropertyFromData(data, "subtitle") || "";
900
- this._setupArticlePeriod(data);
901
- this.offset.left = this.finalOffset.left = this.moveAnimation.finalOffset.left = data.offsetLeft || 0;
902
- this.offset.top = this.finalOffset.top = this.moveAnimation.finalOffset.top = data.offsetTop || 0;
903
- this.isStarred = !!data.starred;
904
- this.cardLayout = getPropertyFromData(data, "cardLayout") || null;
905
- this.initialiseStyles(data);
906
- this.hiddenByFilter = getPropertyFromData(data, "hiddenByFilter");
907
- this.hidePeriodLine = existsInData(data, "hidePeriodLine") ? getPropertyFromData(data, "hidePeriodLine") : this.owner.options.article.periodLine.defaultHide;
908
- this.isDataLoaded = true;
909
- this.isImageInfoLoaded = false;
910
- };
911
- Article.prototype._setupArticlePeriod = function(data) {
912
- let fromDmy = new Dmy(
913
- parseInt(getPropertyFromData(data, "from.year")),
914
- parseInt(getPropertyFromData(data, "from.month")),
915
- parseInt(getPropertyFromData(data, "from.day")),
916
- parseInt(getPropertyFromData(data, "from.hour")),
917
- parseInt(getPropertyFromData(data, "from.minute")),
918
- parseInt(getPropertyFromData(data, "from.second")),
919
- parseInt(getPropertyFromData(data, "from.millisecond"))
920
- );
921
- fromDmy = this.owner.getDmyFromInput(fromDmy);
922
- const fromPrecision = getPropertyFromData(data, "from.precision");
923
- const isToPresentProp = getPropertyFromData(data, "isToPresent");
924
- const isToPresent = isToPresentProp === true || isToPresentProp === 1;
925
- let toDmy, toPrecision;
926
- if (isToPresent) {
927
- toDmy = Dmy.now();
928
- } else if (existsInData(data, "to")) {
929
- toDmy = new Dmy(
930
- parseInt(getPropertyFromData(data, "to.year")),
931
- parseInt(getPropertyFromData(data, "to.month")),
932
- parseInt(getPropertyFromData(data, "to.day")),
933
- parseInt(getPropertyFromData(data, "to.hour")),
934
- parseInt(getPropertyFromData(data, "to.minute")),
935
- parseInt(getPropertyFromData(data, "to.second")),
936
- parseInt(getPropertyFromData(data, "to.millisecond"))
937
- );
938
- toDmy = this.owner.getDmyFromInput(toDmy);
939
- toPrecision = getPropertyFromData(data, "to.precision");
940
- } else {
941
- toDmy = fromDmy;
942
- toPrecision = fromPrecision;
943
- }
944
- const from = Dmy.CreateAsStartOfPeriod(fromDmy, fromPrecision);
945
- const to = Dmy.CreateAsExclusiveEndOfPeriod(toDmy, toPrecision);
946
- this.period = { from, to, isToPresent };
947
- this.period.years = this.period.to.asFloat() - this.period.from.asFloat();
948
- };
949
- Article.prototype.setImage = function() {
950
- this.isImageInfoLoaded = true;
951
- if (getPropertyFromData(this.data, "imageUrl")) {
952
- this.owner.enqueueImageLoad(this);
953
- } else {
954
- this._releaseImageResource();
955
- this.image = null;
956
- this.imageLoaded = false;
957
- }
958
- };
959
- Article.prototype._releaseImageResource = function(options = {}) {
960
- const releaser = typeof this._closeImage === "function" ? this._closeImage : null;
961
- if (releaser) {
962
- this._closeImage = null;
963
- try {
964
- releaser(options);
965
- } catch {
966
- }
967
- return;
968
- }
969
- if (!options.keepState) {
970
- this.image = null;
971
- this.imageLoaded = false;
972
- this._loadedImageKey = null;
973
- }
974
- };
975
- Article.prototype.registerPosition = function(pos) {
976
- this.registeredPosition = this.position = pos;
977
- };
978
- Article.prototype.overlaps = function(other) {
979
- return other.period.from.isSame(this.period.from) && other.period.to.isSame(this.period.to) || other.period.from.isBetween(this.period.from, this.period.to) || other.period.to.isBetween(this.period.from, this.period.to) || this.period.from.isBetween(other.period.from, other.period.to) || this.period.to.isBetween(other.period.from, other.period.to);
980
- };
981
- Article.prototype.overlapsInclusiveWithDates = function(from, to) {
982
- return !(this.period.from.isAfter(to) || from.isAfter(this.period.to));
983
- };
984
- Article.prototype.overlapsInclusive = function(other) {
985
- return this.overlapsInclusiveWithDates(other.period.from, other.period.to);
986
- };
987
- Article.prototype.isInside = function(pos) {
988
- if (!this.isVisible) {
989
- return false;
990
- }
991
- this._ensureSizeCache();
992
- const left = this.position.left;
993
- const top = this.position.top;
994
- const width = this._cachedWidth;
995
- const height = this._cachedHeight;
996
- return pos.left >= left && pos.left <= left + width && pos.top >= top && pos.top <= top + height;
997
- };
998
- Article.prototype.pointerEnter = function(event) {
999
- this.isMouseover = true;
1000
- this.owner.trigger("article-pointerenter", this, event);
1001
- };
1002
- Article.prototype.pointerLeave = function(event) {
1003
- this.isMouseover = false;
1004
- this.owner.trigger("article-pointerleave", this, event);
1005
- };
1006
- Article.prototype.updateIsMouseOverStar = function(pos) {
1007
- const star = this.getIconBox();
1008
- if (!star) {
1009
- return false;
1010
- }
1011
- const oldState = this.isMouseOverStar;
1012
- this.isMouseOverStar = pos.left >= star.left && pos.left <= star.left + star.width && pos.top >= star.top && pos.top <= star.top + star.height;
1013
- if (this.isMouseOverStar !== oldState && !this.owner.isAnimating) {
1014
- this.owner.redraw();
1015
- }
1016
- return this.isMouseOverStar;
1017
- };
1018
- Article.prototype.getCursor = function(pos) {
1019
- const cursor = this.owner.options.style.cursor;
1020
- if (this.isDragging) {
1021
- return cursor.article.dragging;
1022
- }
1023
- this.updateIsMouseOverStar(pos);
1024
- if (!this.owner.options.article.draggable) {
1025
- return cursor.clickable;
1026
- }
1027
- if (this.isActive) {
1028
- return this.isMouseOverStar ? cursor.clickable : cursor.article.hoverDraggable;
1029
- }
1030
- return cursor.clickable;
1031
- };
1032
- Article.prototype.clicked = function(pos) {
1033
- this.updateIsMouseOverStar(pos);
1034
- if (this.isMouseOverStar) {
1035
- this.isStarred = !this.isStarred;
1036
- return true;
1037
- }
1038
- return false;
1039
- };
1040
- Article.prototype.getStatusForSave = function() {
1041
- const state = { i: this.id };
1042
- if (this.offset.left !== 0) {
1043
- state.l = this.offset.left;
1044
- }
1045
- if (this.offset.top !== 0) {
1046
- state.t = this.offset.top;
1047
- }
1048
- if (this.isStarred) {
1049
- state.v = true;
1050
- }
1051
- return state;
1052
- };
1053
- Article.prototype.headerOverlapsWith = function(other) {
1054
- const thisLeft = this.registeredPosition.left;
1055
- const otherLeft = other.registeredPosition.left;
1056
- const thisRight = thisLeft + this.getWidth();
1057
- const otherRight = otherLeft + other.getWidth();
1058
- return otherRight >= thisLeft && thisRight >= otherLeft;
1059
- };
1060
- Article.prototype._getWidth = function() {
1061
- return this.getCurrentStyle().width;
1062
- };
1063
- Article.prototype.getWidth = function() {
1064
- this._ensureSizeCache();
1065
- return this._cachedWidth;
1066
- };
1067
- Article.prototype.getHeight = function() {
1068
- this._ensureSizeCache();
1069
- return this._cachedHeight;
1070
- };
1071
- Article.prototype.setOption = function(option, value) {
1072
- let needsDefaultRedraw = false;
1073
- if (typeof option === "string") {
1074
- if (typeof value === "undefined") {
1075
- const selectedOption = getPropertyFromData(this.data, option);
1076
- return selectedOption;
1077
- }
1078
- option = buildObjectFromPath(option, value);
1079
- }
1080
- deepMerge(this.data, option);
1081
- if (existsInData(option, "id")) {
1082
- this.id = option.id;
1083
- }
1084
- if (existsInData(option, "title")) {
1085
- this.title = option.title;
1086
- this.titleLines = void 0;
1087
- }
1088
- if (existsInData(option, "subtitle")) {
1089
- this.subtitle = option.subtitle;
1090
- this.summarisedSubtitle = void 0;
1091
- }
1092
- if (existsInData(option, "from") || existsInData(option, "to") || existsInData(option, "isToPresent")) {
1093
- this._setupArticlePeriod(this.data);
1094
- needsDefaultRedraw = true;
1095
- }
1096
- if (existsInData(option, "imageUrl")) {
1097
- this.setImage();
1098
- }
1099
- if (existsInData(option, "rank")) {
1100
- this.rank = option.rank;
1101
- needsDefaultRedraw = true;
1102
- }
1103
- if (existsInData(option, "starred")) {
1104
- this.isStarred = option.starred;
1105
- }
1106
- if (existsInData(option, "hiddenByFilter")) {
1107
- this.hiddenByFilter = option.hiddenByFilter;
1108
- }
1109
- if (existsInData(option, "hidePeriodLine")) {
1110
- this.hidePeriodLine = option.hidePeriodLine;
1111
- }
1112
- const laneChanged = existsInData(option, "lane");
1113
- if (laneChanged) {
1114
- this.owner._assignArticleToLane(this, option.lane);
1115
- this.initialiseStyles(this.data);
1116
- this.invalidateCaches();
1117
- needsDefaultRedraw = true;
1118
- }
1119
- const styleChanged = existsInData(option, "style");
1120
- const activeStyleChanged = existsInData(option, "activeStyle");
1121
- const hoverStyleChanged = existsInData(option, "hoverStyle");
1122
- if (styleChanged || hoverStyleChanged || activeStyleChanged) {
1123
- this.initialiseStyles(this.data);
1124
- }
1125
- this.invalidateCaches();
1126
- const cardLayoutChanged = existsInData(option, "cardLayout");
1127
- if (cardLayoutChanged) {
1128
- this.setCardLayout(option.cardLayout);
1129
- }
1130
- if (laneChanged) {
1131
- this.owner.updateArticlesGroupIndex();
1132
- }
1133
- if (needsDefaultRedraw) {
1134
- this.owner.requestRedraw();
1135
- } else {
1136
- this.owner.requestRedraw(this.redraw);
1137
- }
1138
- };
1139
- Article.prototype.initialiseStyles = function(data = this.data) {
1140
- const resolvedDefaultCardLayout = this.owner._resolveDefaultCardLayoutName(this);
1141
- const explicitCardLayout = this.owner._getExplicitArticleCardLayout(this);
1142
- const cardLayout = explicitCardLayout || resolvedDefaultCardLayout;
1143
- this._resolvedDefaultCardLayout = resolvedDefaultCardLayout;
1144
- this._resolvedCardLayoutName = cardLayout;
1145
- const styleOverrides = this.owner._getResolvedArticleStyleOverrides(this, cardLayout);
1146
- const style = deepMerge({}, styleOverrides.style, getPropertyFromData(data, "style") || {});
1147
- const activeStyle = deepMerge(
1148
- {},
1149
- styleOverrides.activeStyle,
1150
- getPropertyFromData(data, "activeStyle") || {}
1151
- );
1152
- const hoverStyle = deepMerge(
1153
- {},
1154
- styleOverrides.hoverStyle,
1155
- getPropertyFromData(data, "hoverStyle") || {}
1156
- );
1157
- this.style = style;
1158
- this.activeStyle = deepMerge({}, style, activeStyle);
1159
- this.hoverStyle = deepMerge({}, style, hoverStyle);
1160
- this.activeHoverStyle = deepMerge({}, style, hoverStyle, activeStyle);
1161
- };
1162
- Article.prototype.setStyle = function(option, value) {
1163
- if (typeof option === "string") {
1164
- if (typeof value === "undefined") {
1165
- return getPropertyFromData(this.style, option);
1166
- }
1167
- option = buildObjectFromPath(option, value);
1168
- }
1169
- this.data.style = deepMerge(this.data.style || {}, option);
1170
- this.initialiseStyles(this.data);
1171
- this.invalidateCaches();
1172
- this.owner.requestRedraw();
1173
- };
1174
- Article.prototype.setHoverStyle = function(option, value) {
1175
- if (typeof option === "string") {
1176
- if (typeof value === "undefined") {
1177
- return getPropertyFromData(this.activeStyle, option);
1178
- }
1179
- option = buildObjectFromPath(option, value);
1180
- }
1181
- this.data.hoverStyle = deepMerge(this.data.hoverStyle || {}, option);
1182
- this.initialiseStyles(this.data);
1183
- this.owner.requestRedraw();
1184
- };
1185
- Article.prototype.setActiveStyle = function(option, value) {
1186
- if (typeof option === "string") {
1187
- if (typeof value === "undefined") {
1188
- return getPropertyFromData(this.activeStyle, option);
1189
- }
1190
- option = buildObjectFromPath(option, value);
1191
- }
1192
- this.data.activeStyle = deepMerge(this.data.activeStyle || {}, option);
1193
- this.initialiseStyles(this.data);
1194
- this.owner.requestRedraw();
1195
- };
1196
- Article.prototype.activated = function() {
1197
- Logger.warn(
1198
- 'DEPRECATION WARNING: article.activated() was deprecated in v1.3.0. Use timeline.select(article.id) and handle selection with options.on["article-select"] instead.'
1199
- );
1200
- this.owner.trigger("article-click", this);
1201
- };
1202
- Article.prototype.updateVisibility = function() {
1203
- const oldVisibility = this.isVisibleAfterFade;
1204
- const newVisibility = this.isInRange && this.isVisibleInLane && this.isVisibleInGroup && this.isVisibleInRows && !this.isHiddenByFilter;
1205
- if (!this.isVisibleInLane) {
1206
- this.setVisibility(false);
1207
- return;
1208
- }
1209
- if (oldVisibility === newVisibility) {
1210
- return;
1211
- }
1212
- if (newVisibility && !this.isImageInfoLoaded) {
1213
- this.setImage();
1214
- }
1215
- if (!this.owner.options.article.animation.fade.active) {
1216
- this.setVisibility(newVisibility);
1217
- return;
1218
- }
1219
- this.setVisibilityWithFade(newVisibility);
1220
- };
1221
- Article.prototype.setVisibility = function(visibility) {
1222
- if (this.isFading && this.fadeAnimation?.dummyElement?.stop) {
1223
- this.fadeAnimation.dummyElement.stop();
1224
- this.isFading = false;
1225
- if (this.owner?.lastAnimatingArticle?.id === this.id && this.owner.lastAnimatingArticle.animationType === "fade") {
1226
- this.owner.isAnimatingArticles = false;
1227
- }
1228
- }
1229
- this.isVisible = visibility;
1230
- this.isVisibleAfterFade = visibility;
1231
- this.opacity = visibility ? 1 : 0;
1232
- if (!visibility) {
1233
- this._releaseImageResource({ skipRedraw: true });
1234
- }
1235
- };
1236
- Article.prototype.setVisibilityWithFade = function(visibility) {
1237
- const me = this;
1238
- if (visibility === me.isVisibleAfterFade) {
1239
- return;
1240
- }
1241
- if (me.isFading && me.fadeAnimation?.dummyElement?.stop) {
1242
- me.fadeAnimation.dummyElement.stop();
1243
- }
1244
- me.isFading = true;
1245
- me.isVisibleAfterFade = visibility;
1246
- me.fadeAnimation = me.fadeAnimation || {};
1247
- me.fadeAnimation.finalOpacity = visibility;
1248
- if (visibility) {
1249
- me.isVisible = true;
1250
- }
1251
- me.owner.notifyArticleAnimating("fade", me.id);
1252
- const settings = me.owner.options.article.animation.fade;
1253
- const duration = settings.duration ?? 400;
1254
- const easingName = settings.easing ?? "swing";
1255
- const easingFn = EASINGS[easingName] || EASINGS.swing;
1256
- const startOpacity = me.opacity;
1257
- const endOpacity = visibility ? 1 : 0;
1258
- const fadeTween = tween({
1259
- from: startOpacity,
1260
- to: endOpacity,
1261
- duration,
1262
- easing: easingFn,
1263
- /** Fired every animation frame */
1264
- onUpdate(value) {
1265
- me.opacity = value;
1266
- me.owner.requestRedraw();
1267
- },
1268
- /** Finalise */
1269
- onComplete() {
1270
- me.isFading = false;
1271
- if (!visibility) {
1272
- me.isVisible = false;
1273
- me._releaseImageResource({ skipRedraw: true });
1274
- }
1275
- const last = me.owner.lastAnimatingArticle;
1276
- if (me.id === last.id && last.animationType === "fade") {
1277
- me.owner.isAnimatingArticles = false;
1278
- }
1279
- if (typeof settings.complete === "function") {
1280
- settings.complete.call(me);
1281
- }
1282
- }
1283
- });
1284
- me.fadeAnimation.dummyElement = fadeTween;
1285
- };
1286
- Article.prototype.moveToOffset = function(destination) {
1287
- this.finalOffset.top = this.offset.top = destination.top || this.offset.top;
1288
- this.finalOffset.left = this.offset.left = destination.left || this.offset.left;
1289
- this.position.top = this.registeredPosition.top + this.offset.top;
1290
- this.position.left = this.registeredPosition.left + this.offset.left;
1291
- };
1292
- Article.prototype.moveTo = function(destination) {
1293
- const finalOffset = {
1294
- left: destination.left - this.registeredPosition.left,
1295
- top: destination.top - this.registeredPosition.top
1296
- };
1297
- this.moveToOffset(finalOffset);
1298
- };
1299
- Article.prototype.moveToWithAnim = function(destination) {
1300
- const finalOffset = {
1301
- left: destination.left - this.registeredPosition.left,
1302
- top: destination.top - this.registeredPosition.top
1303
- };
1304
- this.moveToOffsetWithAnim(finalOffset);
1305
- };
1306
- Article.prototype.moveToOffsetWithAnim = function(destination) {
1307
- const me = this;
1308
- const moveAnimation = me.moveAnimation;
1309
- if (destination.top === moveAnimation.finalOffset.top && destination.left === moveAnimation.finalOffset.left) {
1310
- return;
1311
- }
1312
- if (me.isMoving && moveAnimation?.dummyElement?.stop) {
1313
- moveAnimation.dummyElement.stop();
1314
- }
1315
- moveAnimation.finalOffset = this.finalOffset = {
1316
- left: destination.left,
1317
- top: destination.top
1318
- };
1319
- me.isMoving = true;
1320
- me.owner.notifyArticleAnimating("move", me.id);
1321
- const settings = me.owner.options.article.animation.move;
1322
- const duration = settings.duration ?? 400;
1323
- const easingName = settings.easing ?? "swing";
1324
- const easingFn = EASINGS[easingName] || EASINGS.swing;
1325
- const startTop = me.offset.top;
1326
- const startLeft = me.offset.left;
1327
- const deltaTop = destination.top - startTop;
1328
- const deltaLeft = destination.left - startLeft;
1329
- const moveTween = tween({
1330
- from: 0,
1331
- to: 1,
1332
- duration,
1333
- easing: easingFn,
1334
- onUpdate(progress) {
1335
- me.offset.top = startTop + deltaTop * progress;
1336
- me.offset.left = startLeft + deltaLeft * progress;
1337
- me.position.top = me.registeredPosition.top + me.offset.top;
1338
- me.position.left = me.registeredPosition.left + me.offset.left;
1339
- me.owner.requestRedraw();
1340
- },
1341
- onComplete() {
1342
- me.offset.top = destination.top;
1343
- me.offset.left = destination.left;
1344
- me.position.top = me.registeredPosition.top + destination.top;
1345
- me.position.left = me.registeredPosition.left + destination.left;
1346
- me.isMoving = false;
1347
- const last = me.owner.lastAnimatingArticle;
1348
- if (me.id === last.id && last.animationType === "move") {
1349
- me.owner.isAnimatingArticles = false;
1350
- }
1351
- }
1352
- });
1353
- moveAnimation.dummyElement = moveTween;
1354
- };
1355
- function roundPixel(value) {
1356
- return Math.round(value);
1357
- }
1358
- __name(roundPixel, "roundPixel");
1359
- function snapPixel(value, dpr = 1) {
1360
- const ratio = typeof dpr === "number" && isFinite(dpr) && dpr > 0 ? dpr : 1;
1361
- return Math.round(value * ratio) / ratio;
1362
- }
1363
- __name(snapPixel, "snapPixel");
1364
- function retainPixel(value) {
1365
- return value;
1366
- }
1367
- __name(retainPixel, "retainPixel");
1368
- function createPixelSnap(dpr = 1, mode = "device") {
1369
- if (mode === false || mode === "none") {
1370
- return retainPixel;
1371
- }
1372
- if (mode === "css") {
1373
- return roundPixel;
1374
- }
1375
- return /* @__PURE__ */ __name(function snapToDevicePixel(value) {
1376
- return snapPixel(value, dpr);
1377
- }, "snapToDevicePixel");
1378
- }
1379
- __name(createPixelSnap, "createPixelSnap");
1380
- function createStrokePixelSnap(dpr = 1, mode = "device", lineWidth = 1) {
1381
- if (mode === false || mode === "none") {
1382
- return retainPixel;
1383
- }
1384
- const deviceRatio = typeof dpr === "number" && isFinite(dpr) && dpr > 0 ? dpr : 1;
1385
- const ratio = mode === "css" ? 1 : deviceRatio;
1386
- const width = typeof lineWidth === "number" && isFinite(lineWidth) && lineWidth > 0 ? lineWidth : 1;
1387
- const halfPhysicalWidth = width * ratio / 2;
1388
- return /* @__PURE__ */ __name(function snapStrokeCentre(value) {
1389
- return (Math.round(value * ratio - halfPhysicalWidth) + halfPhysicalWidth) / ratio;
1390
- }, "snapStrokeCentre");
1391
- }
1392
- __name(createStrokePixelSnap, "createStrokePixelSnap");
1393
- function createInnerSpace(outerSpace, borderWidth, snap) {
1394
- if (!snap) {
1395
- snap = roundPixel;
1396
- }
1397
- const halfBorder = borderWidth / 2;
1398
- return {
1399
- left: snap(outerSpace.left + halfBorder),
1400
- top: snap(outerSpace.top + halfBorder),
1401
- width: snap(outerSpace.width - borderWidth),
1402
- height: snap(outerSpace.height - borderWidth)
1403
- };
1404
- }
1405
- __name(createInnerSpace, "createInnerSpace");
1406
- Article.prototype.draw = function(ctx) {
1407
- if (!this.isDataLoaded || isNaN(this.position.left)) {
1408
- return;
1409
- }
1410
- this._ensureSizeCache();
1411
- ctx.globalAlpha = this.opacity;
1412
- const cardLayout = this._getCurrentCardLayout();
1413
- cardLayout.draw.call(this, ctx);
1414
- };
1415
- Article.prototype.getCurrentStyle = function() {
1416
- if (this.isActive) {
1417
- return this.isMouseover ? this.activeHoverStyle : this.activeStyle;
1418
- }
1419
- return this.isMouseover ? this.hoverStyle : this.style;
1420
- };
1421
- Article.prototype._getCurrentStyle = function() {
1422
- return this.getCurrentStyle();
1423
- };
1424
- Article.prototype._getPeriodLineRenderGeometry = function(axisY) {
1425
- const resolvedArticleOptions = this.owner._getResolvedArticleOptions(this);
1426
- const periodLineOptions = resolvedArticleOptions.periodLine || {};
1427
- const globalPeriodLineOptions = this.owner.options.article.periodLine || {};
1428
- const position = globalPeriodLineOptions.position || "axis";
1429
- const baselineGap = Number.isFinite(periodLineOptions.baselineGap) ? periodLineOptions.baselineGap : 0;
1430
- const spacing = this.hidePeriodLine ? 0 : periodLineOptions.spacing || 0;
1431
- const thickness = this.hidePeriodLine ? 0 : periodLineOptions.thickness || 0;
1432
- const offset = (spacing + thickness) * this.stacking;
1433
- let anchorY = axisY;
1434
- let anchorOffset = this.owner.options.style.mainLine.size / 2;
1435
- if (position === "lane" && this.owner._isLaneLayoutActive()) {
1436
- const lane = this.owner.getLaneById(this.laneId);
1437
- if (lane && lane.geometry) {
1438
- anchorY = Math.floor(lane.geometry.bottom);
1439
- anchorOffset = 0;
1440
- }
1441
- }
1442
- const y = anchorY - baselineGap - offset - anchorOffset - thickness / 2;
1443
- return {
1444
- position,
1445
- baselineGap,
1446
- spacing,
1447
- thickness,
1448
- anchorY,
1449
- anchorOffset,
1450
- y
1451
- };
1452
- };
1453
- Article.prototype.drawPeriodLinesAndConnectors = function(ctx, axisY) {
1454
- ctx.globalAlpha = this.opacity;
1455
- const style = this.getCurrentStyle();
1456
- const geometry = this._getPeriodLineRenderGeometry(axisY);
1457
- const y = geometry.y;
1458
- if (!this.hidePeriodLine) {
1459
- const fromX = this.indicator.fromX, toX = this.indicator.toX;
1460
- ctx.beginPath();
1461
- ctx.lineWidth = geometry.thickness;
1462
- ctx.moveTo(fromX, y);
1463
- ctx.lineTo(toX, y);
1464
- if (this.period.isToPresent) {
1465
- const periodLength = toX - fromX, maxFadeLength = 15, fadeStartColorStop = Math.max(1 - maxFadeLength / periodLength, 0.7), grad = ctx.createLinearGradient(fromX, y, toX, y);
1466
- grad.addColorStop(0, style.color);
1467
- grad.addColorStop(fadeStartColorStop, style.color);
1468
- grad.addColorStop(1, "rgba(255,255,255,0)");
1469
- ctx.strokeStyle = grad;
1470
- } else {
1471
- ctx.strokeStyle = style.color;
1472
- }
1473
- ctx.stroke();
1474
- }
1475
- if (!style.connectorLine.visible) {
1476
- return;
1477
- }
1478
- const cardLayout = this._getCurrentCardLayout();
1479
- const connectorEnd = typeof cardLayout.getConnectorEnd === "function" ? cardLayout.getConnectorEnd.call(this) : {
1480
- left: this.position.left + style.connectorLine.offsetX,
1481
- top: this.position.top + this.getHeight() + style.connectorLine.offsetY
1482
- };
1483
- const x1 = Math.max(0, this.indicator.fromX);
1484
- const y1 = y;
1485
- const x2 = connectorEnd.left;
1486
- const y2 = connectorEnd.top;
1487
- const isVertical = Math.abs(x1 - x2) < Number.EPSILON;
1488
- const pixelSnapMode = this.owner?.options?.article?.rendering?.pixelSnap;
1489
- const snapStroke = createStrokePixelSnap(
1490
- this.owner?.getCanvasDpr?.() || 1,
1491
- pixelSnapMode,
1492
- style.connectorLine.thickness
1493
- );
1494
- const connectorX = isVertical ? snapStroke(x2) : null;
1495
- const drawX1 = connectorX ?? x1;
1496
- const drawX2 = connectorX ?? x2;
1497
- ctx.strokeStyle = ctx.fillStyle = style.color;
1498
- ctx.lineWidth = style.connectorLine.thickness;
1499
- ctx.beginPath();
1500
- ctx.moveTo(drawX1, y1);
1501
- ctx.lineTo(drawX2, y2);
1502
- ctx.stroke();
1503
- const radians = Math.atan((y2 - y1) / (drawX2 - drawX1)) + (drawX2 >= drawX1 ? -90 : 90) * Math.PI / 180;
1504
- ctx.save();
1505
- ctx.beginPath();
1506
- ctx.translate(drawX2, y2);
1507
- ctx.rotate(radians);
1508
- ctx.moveTo(-style.connectorLine.arrow.width, 0);
1509
- ctx.lineTo(style.connectorLine.arrow.width, 0);
1510
- ctx.lineTo(0, -style.connectorLine.arrow.height);
1511
- ctx.closePath();
1512
- ctx.restore();
1513
- ctx.fill();
1514
- };
1515
- Article.prototype.getIconBox = function() {
1516
- const cardLayout = this._getCurrentCardLayout();
1517
- return cardLayout.getIconBox.call(this);
1518
- };
1519
- Article.prototype.startDragging = function(pos, evt) {
1520
- if (this.isMoving) {
1521
- this.moveAnimation.dummyElement.stop();
1522
- }
1523
- this.isDragging = true;
1524
- this.dragInitialPosition = { left: this.position.left, top: this.position.top };
1525
- this.lastDragPosition = { left: this.position.left, top: this.position.top };
1526
- this.dragStartOffset = {
1527
- left: pos.left - this.position.left,
1528
- top: pos.top - this.position.top
1529
- };
1530
- this.owner.startAnimation();
1531
- if (this.owner && typeof this.owner.trigger === "function") {
1532
- this.owner.trigger("article-drag-start", this, evt);
1533
- }
1534
- };
1535
- Article.prototype.stopDragging = function(evt) {
1536
- this.offset = this.finalOffset = this.moveAnimation.finalOffset = {
1537
- left: this.position.left - this.registeredPosition.left,
1538
- top: this.position.top - this.registeredPosition.top
1539
- };
1540
- this.isDragging = false;
1541
- this.owner?._markTimelineStateChanged?.();
1542
- if (this.owner && typeof this.owner.trigger === "function") {
1543
- this.owner.trigger("article-drag-end", this, evt);
1544
- }
1545
- };
1546
- Article.prototype.dragging = function(pos, evt) {
1547
- const newPosition = {
1548
- left: pos.left - this.dragStartOffset.left,
1549
- top: pos.top - this.dragStartOffset.top
1550
- };
1551
- const previousPosition = this.lastDragPosition || {
1552
- left: this.position.left,
1553
- top: this.position.top
1554
- };
1555
- const initialPosition = this.dragInitialPosition || previousPosition;
1556
- const dx = newPosition.left - previousPosition.left;
1557
- const dy = newPosition.top - previousPosition.top;
1558
- const totalDx = newPosition.left - initialPosition.left;
1559
- const totalDy = newPosition.top - initialPosition.top;
1560
- this.position = newPosition;
1561
- this.lastDragPosition = newPosition;
1562
- if (this.owner && typeof this.owner.trigger === "function") {
1563
- this.owner.trigger("article-drag", this, { dx, dy, totalDx, totalDy }, evt);
1564
- }
1565
- };
1566
- Article.prototype._cacheBucket = function() {
1567
- const name = this._getCurrentCardLayoutName();
1568
- if (!this._layoutCaches) {
1569
- this._layoutCaches = /* @__PURE__ */ Object.create(null);
1570
- }
1571
- return this._layoutCaches[name] || (this._layoutCaches[name] = /* @__PURE__ */ Object.create(null));
1572
- };
1573
- Article.prototype.memo = function(key, factory) {
1574
- const bucket = this._cacheBucket();
1575
- return key in bucket ? bucket[key] : bucket[key] = factory.call(this);
1576
- };
1577
- Article.prototype._getSizeCacheKey = function() {
1578
- const style = typeof this.getCurrentStyle === "function" ? this.getCurrentStyle() : null;
1579
- const imageStyle = style && style.image || {};
1580
- const header = style && style.header || {};
1581
- const subheader = style && style.subheader || {};
1582
- const border = style && style.border || {};
1583
- const layout = typeof this._getCurrentCardLayoutName === "function" ? this._getCurrentCardLayoutName() : "";
1584
- const hasImage = this.imageLoaded && this.image;
1585
- const keyParts = [
1586
- layout,
1587
- style && style.width,
1588
- style && style.height,
1589
- header.height,
1590
- subheader.height,
1591
- border.width,
1592
- imageStyle.margin ?? 0,
1593
- imageStyle.shape || "",
1594
- imageStyle.maxHeight ?? "",
1595
- style && style.maxImageHeight !== void 0 ? style.maxImageHeight : "",
1596
- hasImage ? this.image.width : "noimg",
1597
- hasImage ? this.image.height : ""
1598
- ];
1599
- return keyParts.join("|");
1600
- };
1601
- Article.prototype.updateCachedSize = function() {
1602
- const cardLayout = this._getCurrentCardLayout();
1603
- this._cachedWidth = cardLayout.getWidth.call(this);
1604
- this._cachedHeight = cardLayout.getHeight.call(this);
1605
- this.height = this._cachedHeight;
1606
- this._sizeValid = true;
1607
- this._sizeCacheKey = this._getSizeCacheKey();
1608
- };
1609
- Article.prototype._ensureSizeCache = function() {
1610
- const cacheKey = this._getSizeCacheKey();
1611
- if (!this._sizeValid || cacheKey !== this._sizeCacheKey) {
1612
- this.updateCachedSize();
1613
- }
1614
- };
1615
- Article.prototype.invalidateCaches = function() {
1616
- this._sizeValid = false;
1617
- this._sizeCacheKey = null;
1618
- if (this._layoutCaches) {
1619
- const buckets = this._layoutCaches;
1620
- for (const layoutName in buckets) {
1621
- const bucket = buckets[layoutName];
1622
- if (!bucket) {
1623
- continue;
1624
- }
1625
- for (const k in bucket) {
1626
- const v = bucket[k];
1627
- if (v && typeof v.close === "function") {
1628
- try {
1629
- v.close();
1630
- } catch {
1631
- }
1632
- }
1633
- }
1634
- }
1635
- }
1636
- this._layoutCaches = null;
1637
- };
1638
- Article.prototype._getCurrentCardLayoutName = function() {
1639
- return this._resolvedCardLayoutName || this.cardLayout || this._resolvedDefaultCardLayout || this.owner._resolveArticleCardLayoutName(this);
1640
- };
1641
- Article.prototype._getCurrentCardLayout = function() {
1642
- return this.owner.getCardLayout(this._getCurrentCardLayoutName());
1643
- };
1644
- Article.prototype.setCardLayout = function(cardLayout) {
1645
- const layout = this.owner.getCardLayout(cardLayout);
1646
- if (!layout) {
1647
- throw new Error(`Card layout "${cardLayout}" not found`);
1648
- }
1649
- this.cardLayout = cardLayout;
1650
- this._resolvedCardLayoutName = cardLayout;
1651
- this.initialiseStyles();
1652
- this.invalidateCaches();
1653
- this.owner.requestRedraw(this.redraw);
1654
- };
1655
- function compareArticleIds(idA, idB) {
1656
- const numA = Number(idA);
1657
- const numB = Number(idB);
1658
- const idsAreNumeric = Number.isFinite(numA) && Number.isFinite(numB);
1659
- if (idsAreNumeric) {
1660
- return numA - numB;
1661
- }
1662
- const strA = String(idA);
1663
- const strB = String(idB);
1664
- if (strA === strB) {
1665
- return 0;
1666
- }
1667
- return strA < strB ? -1 : 1;
1668
- }
1669
- __name(compareArticleIds, "compareArticleIds");
1670
- function ARTICLE_DURATION_SORTER(articleA, articleB) {
1671
- const a = articleA.period.from.getDaysTo(articleA.period.to);
1672
- const b = articleB.period.from.getDaysTo(articleB.period.to);
1673
- if (a < b) {
1674
- return 1;
1675
- }
1676
- if (a > b) {
1677
- return -1;
1678
- }
1679
- return compareArticleIds(articleA.id, articleB.id);
1680
- }
1681
- __name(ARTICLE_DURATION_SORTER, "ARTICLE_DURATION_SORTER");
1682
- function ARTICLE_DURATION_YEARS_SORTER(articleA, articleB) {
1683
- const a = articleA.period.years;
1684
- const b = articleB.period.years;
1685
- if (a < b) {
1686
- return 1;
1687
- }
1688
- if (a > b) {
1689
- return -1;
1690
- }
1691
- return compareArticleIds(articleA.id, articleB.id);
1692
- }
1693
- __name(ARTICLE_DURATION_YEARS_SORTER, "ARTICLE_DURATION_YEARS_SORTER");
1694
- function ARTICLE_IMAGE_QUEUE_SORTER(articleA, articleB) {
1695
- const a = articleA.isInView && articleA.isVisible;
1696
- const b = articleB.isInView && articleB.isVisible;
1697
- if (!a && b) {
1698
- return -1;
1699
- }
1700
- if (a && !b) {
1701
- return 1;
1702
- }
1703
- return articleA.position.top - articleB.position.top;
1704
- }
1705
- __name(ARTICLE_IMAGE_QUEUE_SORTER, "ARTICLE_IMAGE_QUEUE_SORTER");
1706
- function ARTICLE_FROM_SORTER(articleA, articleB) {
1707
- const a = articleA.period.from;
1708
- const b = articleB.period.from;
1709
- let result = a.compare(b);
1710
- if (result === 0) {
1711
- result = compareArticleIds(articleB.id, articleA.id);
1712
- }
1713
- return result;
1714
- }
1715
- __name(ARTICLE_FROM_SORTER, "ARTICLE_FROM_SORTER");
1716
- function ARTICLE_TO_SORTER(articleA, articleB) {
1717
- const a = articleA.period.to;
1718
- const b = articleB.period.to;
1719
- let result = b.compare(a);
1720
- if (result === 0) {
1721
- result = compareArticleIds(articleB.id, articleA.id);
1722
- }
1723
- return result;
1724
- }
1725
- __name(ARTICLE_TO_SORTER, "ARTICLE_TO_SORTER");
1726
- function ARTICLE_TOP_SORTER(articleA, articleB) {
1727
- const a = articleA.position.top;
1728
- const b = articleB.position.top;
1729
- if (a < b) {
1730
- return -1;
1731
- }
1732
- if (a > b) {
1733
- return 1;
1734
- }
1735
- return compareArticleIds(articleB.id, articleA.id);
1736
- }
1737
- __name(ARTICLE_TOP_SORTER, "ARTICLE_TOP_SORTER");
1738
- function ARTICLE_ROW_SORTER(articleA, articleB) {
1739
- const laneOrderA = articleA.laneOrder || 0;
1740
- const laneOrderB = articleB.laneOrder || 0;
1741
- if (laneOrderA > laneOrderB) {
1742
- return -1;
1743
- }
1744
- if (laneOrderA < laneOrderB) {
1745
- return 1;
1746
- }
1747
- const a = articleA.row;
1748
- const b = articleB.row;
1749
- if (a < b) {
1750
- return 1;
1751
- }
1752
- if (a > b) {
1753
- return -1;
1754
- }
1755
- return compareArticleIds(articleB.id, articleA.id);
1756
- }
1757
- __name(ARTICLE_ROW_SORTER, "ARTICLE_ROW_SORTER");
1758
- function ARTICLE_RANK_SORTER(articleA, articleB) {
1759
- const a = articleA.rank;
1760
- const b = articleB.rank;
1761
- if (a < b) {
1762
- return 1;
1763
- }
1764
- if (a > b) {
1765
- return -1;
1766
- }
1767
- return compareArticleIds(articleB.id, articleA.id);
1768
- }
1769
- __name(ARTICLE_RANK_SORTER, "ARTICLE_RANK_SORTER");
1770
- function ARTICLE_EFFECTIVE_RANK_SORTER(articleA, articleB) {
1771
- const a = articleA.effectiveRank;
1772
- const b = articleB.effectiveRank;
1773
- if (a < b) {
1774
- return 1;
1775
- }
1776
- if (a > b) {
1777
- return -1;
1778
- }
1779
- return compareArticleIds(articleB.id, articleA.id);
1780
- }
1781
- __name(ARTICLE_EFFECTIVE_RANK_SORTER, "ARTICLE_EFFECTIVE_RANK_SORTER");
1782
- function ARTICLE_POSITION_SORTER(articleA, articleB) {
1783
- const a = articleA.position.left;
1784
- const b = articleB.position.left;
1785
- let result = a < b ? 1 : a > b ? -1 : 0;
1786
- if (result === 0) {
1787
- result = articleA.position.top - articleB.position.top;
1788
- if (result === 0) {
1789
- result = articleA.period.from.compare(articleB.period.from);
1790
- if (result === 0) {
1791
- result = compareArticleIds(articleA.id, articleB.id);
1792
- }
1793
- }
1794
- }
1795
- return result;
1796
- }
1797
- __name(ARTICLE_POSITION_SORTER, "ARTICLE_POSITION_SORTER");
1798
- const sorters = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1799
- __proto__: null,
1800
- ARTICLE_DURATION_SORTER,
1801
- ARTICLE_DURATION_YEARS_SORTER,
1802
- ARTICLE_EFFECTIVE_RANK_SORTER,
1803
- ARTICLE_FROM_SORTER,
1804
- ARTICLE_IMAGE_QUEUE_SORTER,
1805
- ARTICLE_POSITION_SORTER,
1806
- ARTICLE_RANK_SORTER,
1807
- ARTICLE_ROW_SORTER,
1808
- ARTICLE_TOP_SORTER,
1809
- ARTICLE_TO_SORTER
1810
- }, Symbol.toStringTag, { value: "Module" }));
1811
- const MINOR_MARKER = 0;
1812
- const MAJOR_MARKER = 1;
1813
- const ERA_MARKER = 2;
1814
- const ZOOM_MILLISECOND = -4;
1815
- const ZOOM_SECOND = -3;
1816
- const ZOOM_MINUTE = -2;
1817
- const ZOOM_HOUR = -1;
1818
- const ZOOM_DAY = 0;
1819
- const ZOOM_MONTH = 1;
1820
- const ZOOM_YEAR = 2;
1821
- const ZOOM_DECADE = 3;
1822
- const ZOOM_CENTURY = 4;
1823
- const ZOOM_MILLENNIUM = 5;
1824
- const ZOOM_10_THOUSAND_YEARS = 6;
1825
- const ZOOM_100_THOUSAND_YEARS = 7;
1826
- const ZOOM_MILLION_YEARS = 8;
1827
- const ZOOM_10_MILLION_YEARS = 9;
1828
- const ZOOM_100_MILLION_YEARS = 10;
1829
- const ZOOM_BILLION_YEARS = 11;
1830
- const PRECISION_MILLISECOND = "millisecond";
1831
- const PRECISION_SECOND = "second";
1832
- const PRECISION_MINUTE = "minute";
1833
- const PRECISION_HOUR = "hour";
1834
- const PRECISION_DAY = "day";
1835
- const PRECISION_MONTH = "month";
1836
- const PRECISION_YEAR = "year";
1837
- const PRECISION_DECADE = "decade";
1838
- const PRECISION_CENTURY = "century";
1839
- const PRECISION_MILLENNIUM = "millennium";
1840
- const PRECISION_MILLION_YEARS = "million-years";
1841
- const PRECISION_BILLION_YEARS = "billion-years";
1842
- const YEAR_PREFIXES = {
1843
- //uses power of ten of prefix as key to access it's settings
1844
- 3: { label: " ka", value: 1e3 },
1845
- 6: { label: " Ma", value: 1e6 },
1846
- 9: { label: " Ga", value: 1e9 }
68
+ const MINOR_MARKER = 0;
69
+ const MAJOR_MARKER = 1;
70
+ const ERA_MARKER = 2;
71
+ const ZOOM_MILLISECOND = -4;
72
+ const ZOOM_SECOND = -3;
73
+ const ZOOM_MINUTE = -2;
74
+ const ZOOM_HOUR = -1;
75
+ const ZOOM_DAY = 0;
76
+ const ZOOM_MONTH = 1;
77
+ const ZOOM_YEAR = 2;
78
+ const ZOOM_DECADE = 3;
79
+ const ZOOM_CENTURY = 4;
80
+ const ZOOM_MILLENNIUM = 5;
81
+ const ZOOM_10_THOUSAND_YEARS = 6;
82
+ const ZOOM_100_THOUSAND_YEARS = 7;
83
+ const ZOOM_MILLION_YEARS = 8;
84
+ const ZOOM_10_MILLION_YEARS = 9;
85
+ const ZOOM_100_MILLION_YEARS = 10;
86
+ const ZOOM_BILLION_YEARS = 11;
87
+ const PRECISION_MILLISECOND = "millisecond";
88
+ const PRECISION_SECOND = "second";
89
+ const PRECISION_MINUTE = "minute";
90
+ const PRECISION_HOUR = "hour";
91
+ const PRECISION_DAY = "day";
92
+ const PRECISION_MONTH = "month";
93
+ const PRECISION_YEAR = "year";
94
+ const PRECISION_DECADE = "decade";
95
+ const PRECISION_CENTURY = "century";
96
+ const PRECISION_MILLENNIUM = "millennium";
97
+ const PRECISION_MILLION_YEARS = "million-years";
98
+ const PRECISION_BILLION_YEARS = "billion-years";
99
+ const YEAR_PREFIXES = {
100
+ //uses power of ten of prefix as key to access it's settings
101
+ 3: { label: " ka", value: 1e3 },
102
+ 6: { label: " Ma", value: 1e6 },
103
+ 9: { label: " Ga", value: 1e9 }
1847
104
  };
1848
105
  const DENSITY_LOW = "low";
1849
106
  const DENSITY_MEDIUM = "medium";
@@ -2455,48 +712,1805 @@ const DENSITY_SETTINGS = [
2455
712
  all: 25,
2456
713
  step: { months: 0, days: 549755813888 }
2457
714
  }
2458
- ];
2459
- const constants = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
715
+ ];
716
+ const constants = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
717
+ __proto__: null,
718
+ DENSITY_ALL,
719
+ DENSITY_HIGH,
720
+ DENSITY_LOW,
721
+ DENSITY_MEDIUM,
722
+ DENSITY_SETTINGS,
723
+ ERA_MARKER,
724
+ MAJOR_MARKER,
725
+ MINOR_MARKER,
726
+ PRECISION_BILLION_YEARS,
727
+ PRECISION_CENTURY,
728
+ PRECISION_DAY,
729
+ PRECISION_DECADE,
730
+ PRECISION_HOUR,
731
+ PRECISION_MILLENNIUM,
732
+ PRECISION_MILLION_YEARS,
733
+ PRECISION_MILLISECOND,
734
+ PRECISION_MINUTE,
735
+ PRECISION_MONTH,
736
+ PRECISION_SECOND,
737
+ PRECISION_YEAR,
738
+ RANGE_ALL,
739
+ RANGE_SCREEN,
740
+ YEAR_PREFIXES,
741
+ ZOOM_100_MILLION_YEARS,
742
+ ZOOM_100_THOUSAND_YEARS,
743
+ ZOOM_10_MILLION_YEARS,
744
+ ZOOM_10_THOUSAND_YEARS,
745
+ ZOOM_BILLION_YEARS,
746
+ ZOOM_CENTURY,
747
+ ZOOM_DAY,
748
+ ZOOM_DECADE,
749
+ ZOOM_HOUR,
750
+ ZOOM_MILLENNIUM,
751
+ ZOOM_MILLION_YEARS,
752
+ ZOOM_MILLISECOND,
753
+ ZOOM_MINUTE,
754
+ ZOOM_MONTH,
755
+ ZOOM_SECOND,
756
+ ZOOM_YEAR
757
+ }, Symbol.toStringTag, { value: "Module" }));
758
+ const _LoggerImpl = class _LoggerImpl {
759
+ constructor() {
760
+ this._enabled = false;
761
+ this._prefix = "[Histropedia]";
762
+ const c = typeof console !== "undefined" ? console : null;
763
+ this._console = c;
764
+ this._fns = {
765
+ log: c && c.log ? c.log.bind(c) : () => {
766
+ },
767
+ warn: c && c.warn ? c.warn.bind(c) : () => {
768
+ },
769
+ error: c && c.error ? c.error.bind(c) : () => {
770
+ },
771
+ info: c && c.info ? c.info.bind(c) : () => {
772
+ },
773
+ debug: c && c.debug ? c.debug.bind(c) : c && c.log ? c.log.bind(c) : () => {
774
+ },
775
+ group: c && c.group ? c.group.bind(c) : c && c.log ? c.log.bind(c) : () => {
776
+ },
777
+ groupCollapsed: c && c.groupCollapsed ? c.groupCollapsed.bind(c) : c && c.group ? c.group.bind(c) : c && c.log ? c.log.bind(c) : () => {
778
+ },
779
+ groupEnd: c && c.groupEnd ? c.groupEnd.bind(c) : () => {
780
+ }
781
+ };
782
+ }
783
+ setEnabled(enabled) {
784
+ this._enabled = !!enabled;
785
+ }
786
+ isEnabled() {
787
+ return !!this._enabled;
788
+ }
789
+ setPrefix(prefix) {
790
+ this._prefix = String(prefix || "");
791
+ }
792
+ getPrefix() {
793
+ return this._prefix;
794
+ }
795
+ _withPrefixedArgs(argsArray) {
796
+ if (!this._prefix) {
797
+ return argsArray;
798
+ }
799
+ if (argsArray && argsArray.length > 0 && typeof argsArray[0] === "string") {
800
+ const cloned = argsArray.slice();
801
+ cloned[0] = `${this._prefix} ${cloned[0]}`;
802
+ return cloned;
803
+ }
804
+ return [this._prefix, ...argsArray];
805
+ }
806
+ _log(method, args) {
807
+ if (!this._enabled) {
808
+ return;
809
+ }
810
+ const fn = this._fns[method] || this._fns.log;
811
+ fn(...this._withPrefixedArgs(args));
812
+ }
813
+ log(...args) {
814
+ this._log("log", args);
815
+ }
816
+ warn(...args) {
817
+ this._log("warn", args);
818
+ }
819
+ error(...args) {
820
+ this._log("error", args);
821
+ }
822
+ info(...args) {
823
+ this._log("info", args);
824
+ }
825
+ debug(...args) {
826
+ this._log("debug", args);
827
+ }
828
+ group(...args) {
829
+ if (!this._enabled) {
830
+ return;
831
+ }
832
+ this._fns.group(...this._withPrefixedArgs(args));
833
+ }
834
+ groupCollapsed(...args) {
835
+ if (!this._enabled) {
836
+ return;
837
+ }
838
+ this._fns.groupCollapsed(...this._withPrefixedArgs(args));
839
+ }
840
+ groupEnd() {
841
+ if (!this._enabled) {
842
+ return;
843
+ }
844
+ this._fns.groupEnd();
845
+ }
846
+ };
847
+ __name(_LoggerImpl, "LoggerImpl");
848
+ let LoggerImpl = _LoggerImpl;
849
+ const Logger = new LoggerImpl();
850
+ const DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
851
+ const MONTH_NAMES = [
852
+ "Jan",
853
+ "Feb",
854
+ "Mar",
855
+ "Apr",
856
+ "May",
857
+ "Jun",
858
+ "Jul",
859
+ "Aug",
860
+ "Sep",
861
+ "Oct",
862
+ "Nov",
863
+ "Dec"
864
+ ];
865
+ const LEGACY_PRECISIONS = {
866
+ 1: "billion-years",
867
+ 3: "million-years",
868
+ 6: "millennium",
869
+ 7: "century",
870
+ 8: "decade",
871
+ 9: "year",
872
+ 10: "month",
873
+ 11: "day",
874
+ 12: "hour",
875
+ 13: "minute",
876
+ 14: "second",
877
+ 15: "millisecond"
878
+ };
879
+ const DMY_STRING_PATTERN = /^(-?\d+)(?:-(\d{1,2}))?(?:-(\d{1,2}))?(?:[T ](\d{1,2})(?::(\d{1,2}))?(?::(\d{1,2})(?:\.(\d{1,3}))?)?)?$/;
880
+ const MILLISECONDS_PER_SECOND = 1e3;
881
+ const MILLISECONDS_PER_MINUTE = 60 * MILLISECONDS_PER_SECOND;
882
+ const MILLISECONDS_PER_HOUR = 60 * MILLISECONDS_PER_MINUTE;
883
+ const MILLISECONDS_PER_DAY = 24 * MILLISECONDS_PER_HOUR;
884
+ function normalizePrecision(precision) {
885
+ return Object.prototype.hasOwnProperty.call(LEGACY_PRECISIONS, precision) ? LEGACY_PRECISIONS[precision] : precision || "day";
886
+ }
887
+ __name(normalizePrecision, "normalizePrecision");
888
+ function getDatePrecision(parts) {
889
+ if (parts.precision !== void 0) {
890
+ return parts.precision;
891
+ }
892
+ if (!(parts instanceof Dmy)) {
893
+ for (const component of [
894
+ PRECISION_MILLISECOND,
895
+ PRECISION_SECOND,
896
+ PRECISION_MINUTE,
897
+ PRECISION_HOUR
898
+ ]) {
899
+ if (parts[component] !== void 0) {
900
+ return component;
901
+ }
902
+ }
903
+ }
904
+ return PRECISION_DAY;
905
+ }
906
+ __name(getDatePrecision, "getDatePrecision");
907
+ function getHistoricalPeriodBounds(year, size) {
908
+ const endYear = Math.ceil(year / size) * size;
909
+ return {
910
+ startYear: endYear - size + 1,
911
+ endYear
912
+ };
913
+ }
914
+ __name(getHistoricalPeriodBounds, "getHistoricalPeriodBounds");
915
+ function clampInteger(value, fallback, minimum, maximum) {
916
+ const parsed = Number(value);
917
+ if (!Number.isFinite(parsed)) {
918
+ return fallback;
919
+ }
920
+ return Math.min(maximum, Math.max(minimum, Math.trunc(parsed)));
921
+ }
922
+ __name(clampInteger, "clampInteger");
923
+ function setTimeParts(target, hour, minute, second, millisecond) {
924
+ const values = {
925
+ hour: clampInteger(hour, 0, 0, 23),
926
+ minute: clampInteger(minute, 0, 0, 59),
927
+ second: clampInteger(second, 0, 0, 59),
928
+ millisecond: clampInteger(millisecond, 0, 0, 999)
929
+ };
930
+ for (const [key, value] of Object.entries(values)) {
931
+ Object.defineProperty(target, key, {
932
+ value,
933
+ enumerable: value !== 0,
934
+ configurable: true,
935
+ writable: true
936
+ });
937
+ }
938
+ }
939
+ __name(setTimeParts, "setTimeParts");
940
+ function setPrecision(target, precision) {
941
+ if (precision === void 0) {
942
+ return;
943
+ }
944
+ Object.defineProperty(target, "precision", {
945
+ value: precision,
946
+ enumerable: false,
947
+ configurable: true,
948
+ writable: true
949
+ });
950
+ }
951
+ __name(setPrecision, "setPrecision");
952
+ function createAdjustedDmy(source, values) {
953
+ return new Dmy({ ...values, precision: getDatePrecision(source) });
954
+ }
955
+ __name(createAdjustedDmy, "createAdjustedDmy");
956
+ function Dmy(year, month, day, hour, minute, second, millisecond) {
957
+ if (typeof year === "object") {
958
+ const options = year;
959
+ this.year = options.year;
960
+ this.month = options.month;
961
+ this.day = getCorrectDay(options.year, options.month, options.day);
962
+ setTimeParts(this, options.hour, options.minute, options.second, options.millisecond);
963
+ setPrecision(this, getDatePrecision(options));
964
+ } else {
965
+ this.year = year;
966
+ this.month = month;
967
+ this.day = getCorrectDay(year, month, day);
968
+ setTimeParts(this, hour, minute, second, millisecond);
969
+ }
970
+ }
971
+ __name(Dmy, "Dmy");
972
+ function getCorrectDay(year, month, day) {
973
+ return day > 28 ? Math.min(day, daysInMonth(year, month)) : day;
974
+ }
975
+ __name(getCorrectDay, "getCorrectDay");
976
+ function daysInMonth(year, month) {
977
+ if (month === 2) {
978
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
979
+ return 29;
980
+ }
981
+ }
982
+ return DAYS_IN_MONTH[month - 1];
983
+ }
984
+ __name(daysInMonth, "daysInMonth");
985
+ function digitGroupedNumber(number, separator) {
986
+ number = number.toString();
987
+ separator = typeof separator === "string" ? separator : ",";
988
+ if (number.length <= 4) {
989
+ return number;
990
+ }
991
+ return number.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
992
+ }
993
+ __name(digitGroupedNumber, "digitGroupedNumber");
994
+ Dmy.prototype.getDaysTo = function(other) {
995
+ const dayDifference = other.getDaysSinceYearZero() - this.getDaysSinceYearZero();
996
+ const timeDifference = other.getMillisecondsOfDay() - this.getMillisecondsOfDay();
997
+ return dayDifference + timeDifference / MILLISECONDS_PER_DAY;
998
+ };
999
+ Dmy.prototype.getMillisecondsOfDay = function() {
1000
+ return this.hour * MILLISECONDS_PER_HOUR + this.minute * MILLISECONDS_PER_MINUTE + this.second * MILLISECONDS_PER_SECOND + this.millisecond;
1001
+ };
1002
+ Dmy.prototype.getMonthsTo = function(other) {
1003
+ return this.getYearsTo(other) * 12;
1004
+ };
1005
+ Dmy.prototype.getYearsTo = function(other) {
1006
+ let yearDiff = other.year - this.year;
1007
+ yearDiff += (other.month - this.month) / 12 + (other.day - this.day) / 365.2422 + (other.getMillisecondsOfDay() - this.getMillisecondsOfDay()) / (MILLISECONDS_PER_DAY * 365.2422);
1008
+ return yearDiff;
1009
+ };
1010
+ Dmy.prototype.getLeapYearsSinceYearZero = function() {
1011
+ let year = this.year;
1012
+ if (this.month < 3) {
1013
+ year--;
1014
+ }
1015
+ return Math.floor(year / 4) - Math.floor(year / 100) + Math.floor(year / 400);
1016
+ };
1017
+ Dmy.prototype.getDaysSinceYearZero = function() {
1018
+ const year = this.year;
1019
+ let days = year * 365 + this.day;
1020
+ for (let i = 0; i < this.month - 1; i++) {
1021
+ days += DAYS_IN_MONTH[i];
1022
+ }
1023
+ days += this.getLeapYearsSinceYearZero();
1024
+ return days;
1025
+ };
1026
+ Dmy.prototype.getDayOfYear = function() {
1027
+ let dayOfYear = this.day;
1028
+ for (let m = 1; m < this.month; m++) {
1029
+ dayOfYear += daysInMonth(this.year, m);
1030
+ }
1031
+ return dayOfYear;
1032
+ };
1033
+ Dmy.getByDayOfYear = function(year, dayOfYear) {
1034
+ const dmy = new Dmy(year, 1, 1);
1035
+ let dim = DAYS_IN_MONTH[0];
1036
+ for (let i = 0; i < dayOfYear - 1; i++) {
1037
+ dmy.day++;
1038
+ if (dmy.day > dim) {
1039
+ dmy.day = 1;
1040
+ dmy.month++;
1041
+ if (dmy.month > 12) {
1042
+ dmy.month = 1;
1043
+ dmy.year++;
1044
+ }
1045
+ dim = dmy.month === 2 ? daysInMonth(dmy.year, dmy.month) : DAYS_IN_MONTH[dmy.month - 1];
1046
+ }
1047
+ }
1048
+ return dmy;
1049
+ };
1050
+ Dmy.prototype.getNextDay = function() {
1051
+ return this.addDays(1);
1052
+ };
1053
+ Dmy.prototype.addDays = function(amount) {
1054
+ let day = this.day;
1055
+ let month = this.month;
1056
+ let year = this.year;
1057
+ const direction = amount < 0 ? -1 : 1;
1058
+ let remaining = Math.abs(Math.trunc(amount));
1059
+ while (remaining > 0) {
1060
+ if (direction > 0) {
1061
+ day++;
1062
+ if (day > daysInMonth(year, month)) {
1063
+ day = 1;
1064
+ month++;
1065
+ if (month > 12) {
1066
+ month = 1;
1067
+ year++;
1068
+ }
1069
+ }
1070
+ } else {
1071
+ day--;
1072
+ if (day < 1) {
1073
+ month--;
1074
+ if (month < 1) {
1075
+ month = 12;
1076
+ year--;
1077
+ }
1078
+ day = daysInMonth(year, month);
1079
+ }
1080
+ }
1081
+ remaining--;
1082
+ }
1083
+ return createAdjustedDmy(this, {
1084
+ year,
1085
+ month,
1086
+ day,
1087
+ hour: this.hour,
1088
+ minute: this.minute,
1089
+ second: this.second,
1090
+ millisecond: this.millisecond
1091
+ });
1092
+ };
1093
+ Dmy.prototype.addMilliseconds = function(amount) {
1094
+ let date = this;
1095
+ let milliseconds = this.getMillisecondsOfDay() + Math.trunc(amount);
1096
+ while (milliseconds < 0) {
1097
+ date = date.addDays(-1);
1098
+ milliseconds += MILLISECONDS_PER_DAY;
1099
+ }
1100
+ while (milliseconds >= MILLISECONDS_PER_DAY) {
1101
+ date = date.addDays(1);
1102
+ milliseconds -= MILLISECONDS_PER_DAY;
1103
+ }
1104
+ const hour = Math.floor(milliseconds / MILLISECONDS_PER_HOUR);
1105
+ milliseconds -= hour * MILLISECONDS_PER_HOUR;
1106
+ const minute = Math.floor(milliseconds / MILLISECONDS_PER_MINUTE);
1107
+ milliseconds -= minute * MILLISECONDS_PER_MINUTE;
1108
+ const second = Math.floor(milliseconds / MILLISECONDS_PER_SECOND);
1109
+ const millisecond = milliseconds - second * MILLISECONDS_PER_SECOND;
1110
+ return createAdjustedDmy(this, {
1111
+ year: date.year,
1112
+ month: date.month,
1113
+ day: date.day,
1114
+ hour,
1115
+ minute,
1116
+ second,
1117
+ millisecond
1118
+ });
1119
+ };
1120
+ Dmy.prototype.addSeconds = function(amount) {
1121
+ return this.addMilliseconds(amount * MILLISECONDS_PER_SECOND);
1122
+ };
1123
+ Dmy.prototype.addMinutes = function(amount) {
1124
+ return this.addMilliseconds(amount * MILLISECONDS_PER_MINUTE);
1125
+ };
1126
+ Dmy.prototype.addHours = function(amount) {
1127
+ return this.addMilliseconds(amount * MILLISECONDS_PER_HOUR);
1128
+ };
1129
+ Dmy.prototype.addMonths = function(amount) {
1130
+ let month = this.month;
1131
+ let year = this.year;
1132
+ for (let i = 0; i < amount; i++) {
1133
+ month++;
1134
+ if (month > 12) {
1135
+ month = 1;
1136
+ year++;
1137
+ }
1138
+ }
1139
+ return createAdjustedDmy(this, { year, month, day: 1 });
1140
+ };
1141
+ Dmy.prototype.getPreviousDay = function() {
1142
+ return this.addDays(-1);
1143
+ };
1144
+ Dmy.prototype.getNextMonth = function() {
1145
+ let month = this.month;
1146
+ let year = this.year;
1147
+ month++;
1148
+ if (month > 12) {
1149
+ month = 1;
1150
+ year++;
1151
+ }
1152
+ return createAdjustedDmy(this, { year, month, day: 1 });
1153
+ };
1154
+ Dmy.prototype.getPreviousMonth = function() {
1155
+ let month = this.month;
1156
+ let year = this.year;
1157
+ month--;
1158
+ if (month < 1) {
1159
+ month = 12;
1160
+ year--;
1161
+ }
1162
+ return createAdjustedDmy(this, { year, month, day: 1 });
1163
+ };
1164
+ Dmy.prototype.addYears = function(amount) {
1165
+ return createAdjustedDmy(this, { year: this.year + amount, month: 1, day: 1 });
1166
+ };
1167
+ function pad(value, length) {
1168
+ return String(value).padStart(length, "0");
1169
+ }
1170
+ __name(pad, "pad");
1171
+ Dmy.prototype.format = function(format, options) {
1172
+ options = options || {};
1173
+ format = format || "D MMM YYYY";
1174
+ const prefixSettings = options.yearPrefix;
1175
+ const bceText = typeof options.bceText === "string" ? options.bceText : " ʙᴄᴇ";
1176
+ const isBc = this.year <= 0;
1177
+ const is1Bc = this.year === 0;
1178
+ const thousandsSeparator = options.thousandsSeparator;
1179
+ if (prefixSettings && !is1Bc) {
1180
+ const prefixValue = prefixSettings.value || 1;
1181
+ const prefixLabel = prefixSettings.label || "";
1182
+ let formattedYear;
1183
+ if (isBc) {
1184
+ formattedYear = digitGroupedNumber((-this.year + 1) / prefixValue, thousandsSeparator) + prefixLabel + bceText;
1185
+ } else {
1186
+ formattedYear = digitGroupedNumber(this.year / prefixValue, thousandsSeparator) + prefixLabel;
1187
+ }
1188
+ return formattedYear;
1189
+ }
1190
+ return format.replace(
1191
+ "YYYY",
1192
+ isBc ? digitGroupedNumber(-this.year + 1, thousandsSeparator) + bceText : digitGroupedNumber(this.year, thousandsSeparator)
1193
+ ).replace("D", this.day).replace("MMM", MONTH_NAMES[this.month - 1]).replace("HH", pad(this.hour, 2)).replace("mm", pad(this.minute, 2)).replace("ss", pad(this.second, 2)).replace("SSS", pad(this.millisecond, 3));
1194
+ };
1195
+ Dmy.prototype.isSame = function(other) {
1196
+ return other.year === this.year && other.month === this.month && other.day === this.day && (other.hour || 0) === this.hour && (other.minute || 0) === this.minute && (other.second || 0) === this.second && (other.millisecond || 0) === this.millisecond;
1197
+ };
1198
+ Dmy.prototype.toKeyString = function() {
1199
+ const dateKey = `${this.year}|${this.month}|${this.day}`;
1200
+ if (this.getMillisecondsOfDay() === 0) {
1201
+ return dateKey;
1202
+ }
1203
+ return `${dateKey}|${this.hour}|${this.minute}|${this.second}|${this.millisecond}`;
1204
+ };
1205
+ Dmy.prototype.isAfter = function(other) {
1206
+ const fields = ["year", "month", "day", "hour", "minute", "second", "millisecond"];
1207
+ for (let i = 0; i < fields.length; i++) {
1208
+ const field = fields[i];
1209
+ const thisValue = this[field] || 0;
1210
+ const otherValue = other[field] || 0;
1211
+ if (thisValue !== otherValue) {
1212
+ return thisValue > otherValue;
1213
+ }
1214
+ }
1215
+ return false;
1216
+ };
1217
+ Dmy.prototype.isBetween = function(from, to) {
1218
+ return this.isAfter(from) && to.isAfter(this);
1219
+ };
1220
+ Dmy.prototype.compare = function(other) {
1221
+ if (this.isSame(other)) {
1222
+ return 0;
1223
+ }
1224
+ if (this.isAfter(other)) {
1225
+ return 1;
1226
+ }
1227
+ return -1;
1228
+ };
1229
+ Dmy.prototype.asFloat = function() {
1230
+ const m = this.month - 1;
1231
+ const d = this.day - 1;
1232
+ const dayFraction = this.getMillisecondsOfDay() / MILLISECONDS_PER_DAY;
1233
+ if (m === 0 && d === 0 && dayFraction === 0) {
1234
+ return this.year;
1235
+ }
1236
+ return Math.round((this.year + (m * 31 + d + dayFraction) / 371) * 100) / 100;
1237
+ };
1238
+ Dmy.prototype.isInFuture = function() {
1239
+ const date = /* @__PURE__ */ new Date();
1240
+ const now = new Dmy(
1241
+ date.getFullYear(),
1242
+ date.getMonth() + 1,
1243
+ date.getDate(),
1244
+ date.getHours(),
1245
+ date.getMinutes(),
1246
+ date.getSeconds(),
1247
+ date.getMilliseconds()
1248
+ );
1249
+ return this.isAfter(now);
1250
+ };
1251
+ Dmy.prototype.convertToIso = function() {
1252
+ if (this.year < 0) {
1253
+ this.year += 1;
1254
+ }
1255
+ return this;
1256
+ };
1257
+ Dmy.CreateAsStartOfPeriod = function(isoDmy, precision) {
1258
+ const isoYear = isoDmy.year;
1259
+ const month = isoDmy.month || 1;
1260
+ const day = isoDmy.day || 1;
1261
+ precision = normalizePrecision(precision);
1262
+ if (precision === "millisecond") {
1263
+ return new Dmy(isoDmy);
1264
+ }
1265
+ if (precision === "second") {
1266
+ return new Dmy(isoYear, month, day, isoDmy.hour, isoDmy.minute, isoDmy.second, 0);
1267
+ }
1268
+ if (precision === "minute") {
1269
+ return new Dmy(isoYear, month, day, isoDmy.hour, isoDmy.minute, 0, 0);
1270
+ }
1271
+ if (precision === "hour") {
1272
+ return new Dmy(isoYear, month, day, isoDmy.hour, 0, 0, 0);
1273
+ }
1274
+ if (precision === "day") {
1275
+ return new Dmy(isoYear, month, day);
1276
+ }
1277
+ if (precision === "month") {
1278
+ return new Dmy(isoYear, month, 1);
1279
+ }
1280
+ if (precision === "year" || precision === "million-years" || precision === "billion-years") {
1281
+ return new Dmy(isoYear, 1, 1);
1282
+ }
1283
+ if (precision === "decade") {
1284
+ return new Dmy(Math.floor(isoYear / 10) * 10, 1, 1);
1285
+ }
1286
+ if (precision === "century") {
1287
+ return new Dmy(getHistoricalPeriodBounds(isoYear, 100).startYear, 1, 1);
1288
+ }
1289
+ if (precision === "millennium") {
1290
+ return new Dmy(getHistoricalPeriodBounds(isoYear, 1e3).startYear, 1, 1);
1291
+ }
1292
+ return new Dmy(isoYear, month, day);
1293
+ };
1294
+ Dmy.CreateAsEndOfPeriod = function(isoDmy, precision) {
1295
+ const isoYear = isoDmy.year;
1296
+ const month = isoDmy.month || 1;
1297
+ const day = isoDmy.day || 1;
1298
+ precision = normalizePrecision(precision);
1299
+ if (precision === "millisecond") {
1300
+ return new Dmy(isoDmy);
1301
+ }
1302
+ if (precision === "second") {
1303
+ return new Dmy(isoYear, month, day, isoDmy.hour, isoDmy.minute, isoDmy.second, 999);
1304
+ }
1305
+ if (precision === "minute") {
1306
+ return new Dmy(isoYear, month, day, isoDmy.hour, isoDmy.minute, 59, 999);
1307
+ }
1308
+ if (precision === "hour") {
1309
+ return new Dmy(isoYear, month, day, isoDmy.hour, 59, 59, 999);
1310
+ }
1311
+ if (precision === "day") {
1312
+ return new Dmy(isoYear, month, day);
1313
+ }
1314
+ if (precision === "month") {
1315
+ return new Dmy(isoYear, month, daysInMonth(isoYear, month));
1316
+ }
1317
+ if (precision === "year") {
1318
+ return new Dmy(isoYear, 12, 31);
1319
+ }
1320
+ if (precision === "decade") {
1321
+ return new Dmy(Math.floor(isoYear / 10) * 10 + 9, 12, 31);
1322
+ }
1323
+ if (precision === "century") {
1324
+ return new Dmy(getHistoricalPeriodBounds(isoYear, 100).endYear, 12, 31);
1325
+ }
1326
+ if (precision === "millennium") {
1327
+ return new Dmy(getHistoricalPeriodBounds(isoYear, 1e3).endYear, 12, 31);
1328
+ }
1329
+ if (precision === "million-years") {
1330
+ return new Dmy(isoYear + 999999, 12, 31);
1331
+ }
1332
+ if (precision === "billion-years") {
1333
+ return new Dmy(isoYear + 999999999, 12, 31);
1334
+ }
1335
+ Logger.error("precision is not implemented");
1336
+ return new Dmy(isoYear, month, day);
1337
+ };
1338
+ Dmy.CreateAsExclusiveEndOfPeriod = function(isoDmy, precision) {
1339
+ precision = normalizePrecision(precision);
1340
+ const start = Dmy.CreateAsStartOfPeriod(isoDmy, precision);
1341
+ if (precision === "millisecond") {
1342
+ return start.addMilliseconds(1);
1343
+ }
1344
+ if (precision === "second") {
1345
+ return start.addSeconds(1);
1346
+ }
1347
+ if (precision === "minute") {
1348
+ return start.addMinutes(1);
1349
+ }
1350
+ if (precision === "hour") {
1351
+ return start.addHours(1);
1352
+ }
1353
+ if (precision === "day") {
1354
+ return start.addDays(1);
1355
+ }
1356
+ return Dmy.CreateAsEndOfPeriod(isoDmy, precision).addDays(1);
1357
+ };
1358
+ Dmy.now = function() {
1359
+ const now = /* @__PURE__ */ new Date();
1360
+ return new Dmy({
1361
+ year: now.getYear() + 1900,
1362
+ month: now.getMonth() + 1,
1363
+ day: now.getDate()
1364
+ });
1365
+ };
1366
+ function parseDmyString(dateString) {
1367
+ const match = String(dateString).match(DMY_STRING_PATTERN);
1368
+ if (!match) {
1369
+ return null;
1370
+ }
1371
+ const year = parseInt(match[1], 10);
1372
+ const month = match[2] == null ? 1 : parseInt(match[2], 10);
1373
+ const day = match[3] == null ? 1 : parseInt(match[3], 10);
1374
+ const hour = match[4] == null ? 0 : parseInt(match[4], 10);
1375
+ const minute = match[5] == null ? 0 : parseInt(match[5], 10);
1376
+ const second = match[6] == null ? 0 : parseInt(match[6], 10);
1377
+ const millisecond = match[7] ? parseInt(match[7].padEnd(3, "0"), 10) : 0;
1378
+ return {
1379
+ // These fields are already defaulted; keep string parsing outside object inference.
1380
+ date: new Dmy(year, month, day, hour, minute, second, millisecond),
1381
+ hasMonth: match[2] != null,
1382
+ hasDay: match[3] != null,
1383
+ hasTime: match[4] != null
1384
+ };
1385
+ }
1386
+ __name(parseDmyString, "parseDmyString");
1387
+ Dmy.fromString = function(dateString) {
1388
+ const parsed = parseDmyString(dateString);
1389
+ return parsed ? parsed.date : new Dmy(NaN, 1, 1);
1390
+ };
1391
+ function merge(target, ...sources) {
1392
+ return Object.assign(target, ...sources);
1393
+ }
1394
+ __name(merge, "merge");
1395
+ function deepMerge(target, ...sources) {
1396
+ const ensureSafeProto = /* @__PURE__ */ __name((obj) => {
1397
+ if (obj && typeof obj === "object" && !Object.prototype.hasOwnProperty.call(obj, "__proto__")) {
1398
+ try {
1399
+ Object.defineProperty(obj, "__proto__", {
1400
+ value: void 0,
1401
+ writable: true,
1402
+ enumerable: false,
1403
+ configurable: true
1404
+ });
1405
+ } catch {
1406
+ }
1407
+ }
1408
+ }, "ensureSafeProto");
1409
+ ensureSafeProto(target);
1410
+ const isUnsafeKey = /* @__PURE__ */ __name((key) => key === "__proto__" || key === "constructor" || key === "prototype", "isUnsafeKey");
1411
+ const isPlainObject = /* @__PURE__ */ __name((obj) => {
1412
+ if (obj === null || typeof obj !== "object") {
1413
+ return false;
1414
+ }
1415
+ const proto = Object.getPrototypeOf(obj);
1416
+ return proto === Object.prototype || proto === null;
1417
+ }, "isPlainObject");
1418
+ for (const src of sources) {
1419
+ if (!src || typeof src !== "object") {
1420
+ continue;
1421
+ }
1422
+ for (const k of Object.keys(src)) {
1423
+ if (isUnsafeKey(k)) {
1424
+ continue;
1425
+ }
1426
+ const v = src[k];
1427
+ if (Array.isArray(v)) {
1428
+ target[k] = v.slice();
1429
+ continue;
1430
+ }
1431
+ if (isPlainObject(v)) {
1432
+ const base = isPlainObject(target[k]) ? target[k] : {};
1433
+ ensureSafeProto(base);
1434
+ target[k] = deepMerge(base, v);
1435
+ continue;
1436
+ }
1437
+ target[k] = v;
1438
+ }
1439
+ }
1440
+ ensureSafeProto(target);
1441
+ return target;
1442
+ }
1443
+ __name(deepMerge, "deepMerge");
1444
+ function buildObjectFromPath(path, value) {
1445
+ const pathParts = path.split(".");
1446
+ const pathEnd = pathParts[pathParts.length - 1];
1447
+ let obj = {};
1448
+ obj[pathEnd] = value;
1449
+ for (let i = pathParts.length - 2; i >= 0; i--) {
1450
+ const previousPathPart = pathParts[i];
1451
+ const objClone = deepMerge({}, obj);
1452
+ obj = {};
1453
+ obj[previousPathPart] = objClone;
1454
+ }
1455
+ return obj;
1456
+ }
1457
+ __name(buildObjectFromPath, "buildObjectFromPath");
1458
+ function defineValueOrFunctionProperty(obj, propName) {
1459
+ const privatePropertyName = `_${propName}`;
1460
+ obj[privatePropertyName] = void 0;
1461
+ Object.defineProperty(obj, propName, {
1462
+ get() {
1463
+ const value = this[privatePropertyName];
1464
+ if (typeof value === "function") {
1465
+ return value(this);
1466
+ }
1467
+ return value;
1468
+ },
1469
+ set(value) {
1470
+ this[privatePropertyName] = value;
1471
+ },
1472
+ enumerable: true,
1473
+ configurable: false
1474
+ });
1475
+ }
1476
+ __name(defineValueOrFunctionProperty, "defineValueOrFunctionProperty");
1477
+ function isUndefined(value) {
1478
+ return typeof value === "undefined";
1479
+ }
1480
+ __name(isUndefined, "isUndefined");
1481
+ const propertyAbbreviations = {
1482
+ id: "i",
1483
+ title: "t",
1484
+ rank: "r",
1485
+ subtitle: "s",
1486
+ "from.year": "fy",
1487
+ "from.month": "fm",
1488
+ "from.day": "fd",
1489
+ "from.hour": "fhr",
1490
+ "from.minute": "fmi",
1491
+ "from.second": "fs",
1492
+ "from.millisecond": "fms",
1493
+ "from.precision": "fp",
1494
+ "to.year": "ty",
1495
+ "to.month": "tm",
1496
+ "to.day": "td",
1497
+ "to.hour": "thr",
1498
+ "to.minute": "tmi",
1499
+ "to.second": "ts",
1500
+ "to.millisecond": "tms",
1501
+ "to.precision": "tp",
1502
+ isToPresent: "p",
1503
+ isStarred: "v",
1504
+ "offset.left": "ol",
1505
+ "offset.top": "ot",
1506
+ imageUrl: "m",
1507
+ lane: "ln",
1508
+ style: "st",
1509
+ activeStyle: "ast",
1510
+ hiddenByFilter: "h",
1511
+ hidePeriodLine: "hp"
1512
+ };
1513
+ function extractProperty(data, property) {
1514
+ return Object.prototype.hasOwnProperty.call(data, property) ? data[property] : data[propertyAbbreviations[property]];
1515
+ }
1516
+ __name(extractProperty, "extractProperty");
1517
+ function extractPropertyFromPath(data, path) {
1518
+ const pathParts = path.split(".");
1519
+ const value = pathParts.reduce((curr, next) => curr ? curr[next] : void 0, data);
1520
+ return isUndefined(value) ? data[propertyAbbreviations[path]] : value;
1521
+ }
1522
+ __name(extractPropertyFromPath, "extractPropertyFromPath");
1523
+ function isPath(property) {
1524
+ return property.indexOf(".") > -1;
1525
+ }
1526
+ __name(isPath, "isPath");
1527
+ function getPropertyFromData(data, property) {
1528
+ if (isPath(property)) {
1529
+ return extractPropertyFromPath(data, property);
1530
+ }
1531
+ return extractProperty(data, property);
1532
+ }
1533
+ __name(getPropertyFromData, "getPropertyFromData");
1534
+ function getDmyFromData(data, prefix) {
1535
+ const precision = getDatePrecision(
1536
+ Object.fromEntries(
1537
+ ["precision", "hour", "minute", "second", "millisecond"].map((key) => [
1538
+ key,
1539
+ getPropertyFromData(data, `${prefix}.${key}`)
1540
+ ])
1541
+ )
1542
+ );
1543
+ const parts = Object.fromEntries(
1544
+ ["year", "month", "day", "hour", "minute", "second", "millisecond"].map((key) => [
1545
+ key,
1546
+ parseInt(getPropertyFromData(data, `${prefix}.${key}`))
1547
+ ])
1548
+ );
1549
+ return new Dmy({ ...parts, precision });
1550
+ }
1551
+ __name(getDmyFromData, "getDmyFromData");
1552
+ function existsInData(data, property) {
1553
+ if (isPath(property)) {
1554
+ return !isUndefined(extractPropertyFromPath(data, property));
1555
+ }
1556
+ return !isUndefined(extractProperty(data, property));
1557
+ }
1558
+ __name(existsInData, "existsInData");
1559
+ defineValueOrFunctionProperty(Article.prototype, "hidePeriodLine");
1560
+ defineValueOrFunctionProperty(Article.prototype, "hiddenByFilter");
1561
+ function Article(owner, id) {
1562
+ this.id = id;
1563
+ this.owner = owner;
1564
+ this.isDataLoaded = false;
1565
+ this.imageLoaded = false;
1566
+ this.stacking = 0;
1567
+ this.groupIndex = 0;
1568
+ this.isActive = false;
1569
+ this.isVisible = false;
1570
+ this.isVisibleInLane = true;
1571
+ this.isInRange = false;
1572
+ this.isInView = false;
1573
+ this.isVisibleInGroup = false;
1574
+ this.isVisibleInRows = true;
1575
+ this.isStarred = false;
1576
+ this.isMouseOverStar = false;
1577
+ this.isMouseover = false;
1578
+ this.isDragging = false;
1579
+ this.registeredPosition = { left: 0, top: 0 };
1580
+ this.position = { left: 0, top: 0 };
1581
+ this.dragStartOffset = { left: 0, top: 0 };
1582
+ this.indicator = { fromX: 0, toX: 0 };
1583
+ this.offset = { left: 0, top: 0 };
1584
+ this.finalOffset = { left: 0, top: 0 };
1585
+ this.isVisibleAfterFade = false;
1586
+ this.opacity = 0;
1587
+ this.fadeAnimation = {
1588
+ finalOpacity: 0,
1589
+ dummyElement: null
1590
+ };
1591
+ this.moveAnimation = {
1592
+ finalOffset: { left: 0, top: 0 },
1593
+ dummyElement: void 0
1594
+ };
1595
+ this.row = 0;
1596
+ this.laneId = null;
1597
+ this.laneOrder = 0;
1598
+ this.isFading = false;
1599
+ this.isMoving = false;
1600
+ this._cachedHeight = 0;
1601
+ this._cachedWidth = 0;
1602
+ this._sizeValid = false;
1603
+ this._sizeCacheKey = null;
1604
+ this._layoutCaches = null;
1605
+ this._resolvedDefaultCardLayout = null;
1606
+ this._resolvedCardLayoutName = null;
1607
+ }
1608
+ __name(Article, "Article");
1609
+ Article.prototype.setupByReceivedData = function(receivedData) {
1610
+ this.owner._assignArticleToLane(this, this.owner._resolveLaneIdFromArticleData(receivedData));
1611
+ const articleDefaultData = this.owner._getResolvedArticleOptions(this).defaultData;
1612
+ const data = deepMerge({}, articleDefaultData, receivedData);
1613
+ if (!existsInData(receivedData, "to")) {
1614
+ delete data.to;
1615
+ }
1616
+ this.data = deepMerge({}, receivedData);
1617
+ this.title = getPropertyFromData(data, "title") || "";
1618
+ this.rank = getPropertyFromData(data, "rank") || 0;
1619
+ this.subtitle = getPropertyFromData(data, "subtitle") || "";
1620
+ this._setupArticlePeriod(data);
1621
+ this.offset.left = this.finalOffset.left = this.moveAnimation.finalOffset.left = data.offsetLeft || 0;
1622
+ this.offset.top = this.finalOffset.top = this.moveAnimation.finalOffset.top = data.offsetTop || 0;
1623
+ this.isStarred = !!data.starred;
1624
+ this.cardLayout = getPropertyFromData(data, "cardLayout") || null;
1625
+ this.initialiseStyles(data);
1626
+ this.hiddenByFilter = getPropertyFromData(data, "hiddenByFilter");
1627
+ this.hidePeriodLine = existsInData(data, "hidePeriodLine") ? getPropertyFromData(data, "hidePeriodLine") : this.owner.options.article.periodLine.defaultHide;
1628
+ this.isDataLoaded = true;
1629
+ this.isImageInfoLoaded = false;
1630
+ };
1631
+ Article.prototype._setupArticlePeriod = function(data) {
1632
+ let fromDmy = getDmyFromData(data, "from");
1633
+ fromDmy = this.owner.getDmyFromInput(fromDmy);
1634
+ const fromPrecision = fromDmy.precision;
1635
+ const isToPresentProp = getPropertyFromData(data, "isToPresent");
1636
+ const isToPresent = isToPresentProp === true || isToPresentProp === 1;
1637
+ let toDmy, toPrecision;
1638
+ if (isToPresent) {
1639
+ toDmy = Dmy.now();
1640
+ } else if (existsInData(data, "to")) {
1641
+ toDmy = getDmyFromData(data, "to");
1642
+ toDmy = this.owner.getDmyFromInput(toDmy);
1643
+ toPrecision = toDmy.precision;
1644
+ } else {
1645
+ toDmy = fromDmy;
1646
+ toPrecision = fromPrecision;
1647
+ }
1648
+ const from = Dmy.CreateAsStartOfPeriod(fromDmy, fromPrecision);
1649
+ const to = Dmy.CreateAsExclusiveEndOfPeriod(toDmy, toPrecision);
1650
+ this.period = { from, to, isToPresent };
1651
+ this.period.years = this.period.to.asFloat() - this.period.from.asFloat();
1652
+ };
1653
+ Article.prototype.setImage = function() {
1654
+ this.isImageInfoLoaded = true;
1655
+ if (getPropertyFromData(this.data, "imageUrl")) {
1656
+ this.owner.enqueueImageLoad(this);
1657
+ } else {
1658
+ this._releaseImageResource();
1659
+ this.image = null;
1660
+ this.imageLoaded = false;
1661
+ }
1662
+ };
1663
+ Article.prototype._releaseImageResource = function(options = {}) {
1664
+ const releaser = typeof this._closeImage === "function" ? this._closeImage : null;
1665
+ if (releaser) {
1666
+ this._closeImage = null;
1667
+ try {
1668
+ releaser(options);
1669
+ } catch {
1670
+ }
1671
+ return;
1672
+ }
1673
+ if (!options.keepState) {
1674
+ this.image = null;
1675
+ this.imageLoaded = false;
1676
+ this._loadedImageKey = null;
1677
+ }
1678
+ };
1679
+ Article.prototype.registerPosition = function(pos) {
1680
+ this.registeredPosition = this.position = pos;
1681
+ };
1682
+ Article.prototype.overlaps = function(other) {
1683
+ return other.period.from.isSame(this.period.from) && other.period.to.isSame(this.period.to) || other.period.from.isBetween(this.period.from, this.period.to) || other.period.to.isBetween(this.period.from, this.period.to) || this.period.from.isBetween(other.period.from, other.period.to) || this.period.to.isBetween(other.period.from, other.period.to);
1684
+ };
1685
+ Article.prototype.overlapsInclusiveWithDates = function(from, to) {
1686
+ return !(this.period.from.isAfter(to) || from.isAfter(this.period.to));
1687
+ };
1688
+ Article.prototype.overlapsInclusive = function(other) {
1689
+ return this.overlapsInclusiveWithDates(other.period.from, other.period.to);
1690
+ };
1691
+ Article.prototype.isInside = function(pos) {
1692
+ if (!this.isVisible) {
1693
+ return false;
1694
+ }
1695
+ this._ensureSizeCache();
1696
+ const left = this.position.left;
1697
+ const top = this.position.top;
1698
+ const width = this._cachedWidth;
1699
+ const height = this._cachedHeight;
1700
+ return pos.left >= left && pos.left <= left + width && pos.top >= top && pos.top <= top + height;
1701
+ };
1702
+ Article.prototype.pointerEnter = function(event) {
1703
+ this.isMouseover = true;
1704
+ this.owner.trigger("article-pointerenter", this, event);
1705
+ };
1706
+ Article.prototype.pointerLeave = function(event) {
1707
+ this.isMouseover = false;
1708
+ this.owner.trigger("article-pointerleave", this, event);
1709
+ };
1710
+ Article.prototype.updateIsMouseOverStar = function(pos) {
1711
+ const star = this.getIconBox();
1712
+ if (!star) {
1713
+ return false;
1714
+ }
1715
+ const oldState = this.isMouseOverStar;
1716
+ this.isMouseOverStar = pos.left >= star.left && pos.left <= star.left + star.width && pos.top >= star.top && pos.top <= star.top + star.height;
1717
+ if (this.isMouseOverStar !== oldState && !this.owner.isAnimating) {
1718
+ this.owner.redraw();
1719
+ }
1720
+ return this.isMouseOverStar;
1721
+ };
1722
+ Article.prototype.getCursor = function(pos) {
1723
+ const cursor = this.owner.options.style.cursor;
1724
+ if (this.isDragging) {
1725
+ return cursor.article.dragging;
1726
+ }
1727
+ this.updateIsMouseOverStar(pos);
1728
+ if (!this.owner.options.article.draggable) {
1729
+ return cursor.clickable;
1730
+ }
1731
+ if (this.isActive) {
1732
+ return this.isMouseOverStar ? cursor.clickable : cursor.article.hoverDraggable;
1733
+ }
1734
+ return cursor.clickable;
1735
+ };
1736
+ Article.prototype.clicked = function(pos) {
1737
+ this.updateIsMouseOverStar(pos);
1738
+ if (this.isMouseOverStar) {
1739
+ this.isStarred = !this.isStarred;
1740
+ return true;
1741
+ }
1742
+ return false;
1743
+ };
1744
+ Article.prototype.getStatusForSave = function() {
1745
+ const state = { i: this.id };
1746
+ if (this.offset.left !== 0) {
1747
+ state.l = this.offset.left;
1748
+ }
1749
+ if (this.offset.top !== 0) {
1750
+ state.t = this.offset.top;
1751
+ }
1752
+ if (this.isStarred) {
1753
+ state.v = true;
1754
+ }
1755
+ return state;
1756
+ };
1757
+ Article.prototype.headerOverlapsWith = function(other) {
1758
+ const thisLeft = this.registeredPosition.left;
1759
+ const otherLeft = other.registeredPosition.left;
1760
+ const thisRight = thisLeft + this.getWidth();
1761
+ const otherRight = otherLeft + other.getWidth();
1762
+ return otherRight >= thisLeft && thisRight >= otherLeft;
1763
+ };
1764
+ Article.prototype._getWidth = function() {
1765
+ return this.getCurrentStyle().width;
1766
+ };
1767
+ Article.prototype.getWidth = function() {
1768
+ this._ensureSizeCache();
1769
+ return this._cachedWidth;
1770
+ };
1771
+ Article.prototype.getHeight = function() {
1772
+ this._ensureSizeCache();
1773
+ return this._cachedHeight;
1774
+ };
1775
+ Article.prototype.setOption = function(option, value) {
1776
+ let needsDefaultRedraw = false;
1777
+ if (typeof option === "string") {
1778
+ if (typeof value === "undefined") {
1779
+ const selectedOption = getPropertyFromData(this.data, option);
1780
+ return selectedOption;
1781
+ }
1782
+ option = buildObjectFromPath(option, value);
1783
+ }
1784
+ deepMerge(this.data, option);
1785
+ if (existsInData(option, "id")) {
1786
+ this.id = option.id;
1787
+ }
1788
+ if (existsInData(option, "title")) {
1789
+ this.title = option.title;
1790
+ this.titleLines = void 0;
1791
+ }
1792
+ if (existsInData(option, "subtitle")) {
1793
+ this.subtitle = option.subtitle;
1794
+ this.summarisedSubtitle = void 0;
1795
+ }
1796
+ if (existsInData(option, "from") || existsInData(option, "to") || existsInData(option, "isToPresent")) {
1797
+ this._setupArticlePeriod(this.data);
1798
+ needsDefaultRedraw = true;
1799
+ }
1800
+ if (existsInData(option, "imageUrl")) {
1801
+ this.setImage();
1802
+ }
1803
+ if (existsInData(option, "rank")) {
1804
+ this.rank = option.rank;
1805
+ needsDefaultRedraw = true;
1806
+ }
1807
+ if (existsInData(option, "starred")) {
1808
+ this.isStarred = option.starred;
1809
+ }
1810
+ if (existsInData(option, "hiddenByFilter")) {
1811
+ this.hiddenByFilter = option.hiddenByFilter;
1812
+ }
1813
+ if (existsInData(option, "hidePeriodLine")) {
1814
+ this.hidePeriodLine = option.hidePeriodLine;
1815
+ }
1816
+ const laneChanged = existsInData(option, "lane");
1817
+ if (laneChanged) {
1818
+ this.owner._assignArticleToLane(this, option.lane);
1819
+ this.initialiseStyles(this.data);
1820
+ this.invalidateCaches();
1821
+ needsDefaultRedraw = true;
1822
+ }
1823
+ const styleChanged = existsInData(option, "style");
1824
+ const activeStyleChanged = existsInData(option, "activeStyle");
1825
+ const hoverStyleChanged = existsInData(option, "hoverStyle");
1826
+ if (styleChanged || hoverStyleChanged || activeStyleChanged) {
1827
+ this.initialiseStyles(this.data);
1828
+ }
1829
+ this.invalidateCaches();
1830
+ const cardLayoutChanged = existsInData(option, "cardLayout");
1831
+ if (cardLayoutChanged) {
1832
+ this.setCardLayout(option.cardLayout);
1833
+ }
1834
+ if (laneChanged) {
1835
+ this.owner.updateArticlesGroupIndex();
1836
+ }
1837
+ if (needsDefaultRedraw) {
1838
+ this.owner.requestRedraw();
1839
+ } else {
1840
+ this.owner.requestRedraw(this.redraw);
1841
+ }
1842
+ };
1843
+ Article.prototype.initialiseStyles = function(data = this.data) {
1844
+ const resolvedDefaultCardLayout = this.owner._resolveDefaultCardLayoutName(this);
1845
+ const explicitCardLayout = this.owner._getExplicitArticleCardLayout(this);
1846
+ const cardLayout = explicitCardLayout || resolvedDefaultCardLayout;
1847
+ this._resolvedDefaultCardLayout = resolvedDefaultCardLayout;
1848
+ this._resolvedCardLayoutName = cardLayout;
1849
+ const styleOverrides = this.owner._getResolvedArticleStyleOverrides(this, cardLayout);
1850
+ const style = deepMerge({}, styleOverrides.style, getPropertyFromData(data, "style") || {});
1851
+ const activeStyle = deepMerge(
1852
+ {},
1853
+ styleOverrides.activeStyle,
1854
+ getPropertyFromData(data, "activeStyle") || {}
1855
+ );
1856
+ const hoverStyle = deepMerge(
1857
+ {},
1858
+ styleOverrides.hoverStyle,
1859
+ getPropertyFromData(data, "hoverStyle") || {}
1860
+ );
1861
+ this.style = style;
1862
+ this.activeStyle = deepMerge({}, style, activeStyle);
1863
+ this.hoverStyle = deepMerge({}, style, hoverStyle);
1864
+ this.activeHoverStyle = deepMerge({}, style, hoverStyle, activeStyle);
1865
+ };
1866
+ Article.prototype.setStyle = function(option, value) {
1867
+ if (typeof option === "string") {
1868
+ if (typeof value === "undefined") {
1869
+ return getPropertyFromData(this.style, option);
1870
+ }
1871
+ option = buildObjectFromPath(option, value);
1872
+ }
1873
+ this.data.style = deepMerge(this.data.style || {}, option);
1874
+ this.initialiseStyles(this.data);
1875
+ this.invalidateCaches();
1876
+ this.owner.requestRedraw();
1877
+ };
1878
+ Article.prototype.setHoverStyle = function(option, value) {
1879
+ if (typeof option === "string") {
1880
+ if (typeof value === "undefined") {
1881
+ return getPropertyFromData(this.activeStyle, option);
1882
+ }
1883
+ option = buildObjectFromPath(option, value);
1884
+ }
1885
+ this.data.hoverStyle = deepMerge(this.data.hoverStyle || {}, option);
1886
+ this.initialiseStyles(this.data);
1887
+ this.owner.requestRedraw();
1888
+ };
1889
+ Article.prototype.setActiveStyle = function(option, value) {
1890
+ if (typeof option === "string") {
1891
+ if (typeof value === "undefined") {
1892
+ return getPropertyFromData(this.activeStyle, option);
1893
+ }
1894
+ option = buildObjectFromPath(option, value);
1895
+ }
1896
+ this.data.activeStyle = deepMerge(this.data.activeStyle || {}, option);
1897
+ this.initialiseStyles(this.data);
1898
+ this.owner.requestRedraw();
1899
+ };
1900
+ Article.prototype.activated = function() {
1901
+ Logger.warn(
1902
+ 'DEPRECATION WARNING: article.activated() was deprecated in v1.3.0. Use timeline.select(article.id) and handle selection with options.on["article-select"] instead.'
1903
+ );
1904
+ this.owner.trigger("article-click", this);
1905
+ };
1906
+ Article.prototype.updateVisibility = function() {
1907
+ const oldVisibility = this.isVisibleAfterFade;
1908
+ const newVisibility = this.isInRange && this.isVisibleInLane && this.isVisibleInGroup && this.isVisibleInRows && !this.isHiddenByFilter;
1909
+ if (!this.isVisibleInLane) {
1910
+ this.setVisibility(false);
1911
+ return;
1912
+ }
1913
+ if (oldVisibility === newVisibility) {
1914
+ return;
1915
+ }
1916
+ if (newVisibility && !this.isImageInfoLoaded) {
1917
+ this.setImage();
1918
+ }
1919
+ if (!this.owner.options.article.animation.fade.active) {
1920
+ this.setVisibility(newVisibility);
1921
+ return;
1922
+ }
1923
+ this.setVisibilityWithFade(newVisibility);
1924
+ };
1925
+ Article.prototype.setVisibility = function(visibility) {
1926
+ if (this.isFading && this.fadeAnimation?.dummyElement?.stop) {
1927
+ this.fadeAnimation.dummyElement.stop();
1928
+ this.isFading = false;
1929
+ if (this.owner?.lastAnimatingArticle?.id === this.id && this.owner.lastAnimatingArticle.animationType === "fade") {
1930
+ this.owner.isAnimatingArticles = false;
1931
+ }
1932
+ }
1933
+ this.isVisible = visibility;
1934
+ this.isVisibleAfterFade = visibility;
1935
+ this.opacity = visibility ? 1 : 0;
1936
+ if (!visibility) {
1937
+ this._releaseImageResource({ skipRedraw: true });
1938
+ }
1939
+ };
1940
+ Article.prototype.setVisibilityWithFade = function(visibility) {
1941
+ const me = this;
1942
+ if (visibility === me.isVisibleAfterFade) {
1943
+ return;
1944
+ }
1945
+ if (me.isFading && me.fadeAnimation?.dummyElement?.stop) {
1946
+ me.fadeAnimation.dummyElement.stop();
1947
+ }
1948
+ me.isFading = true;
1949
+ me.isVisibleAfterFade = visibility;
1950
+ me.fadeAnimation = me.fadeAnimation || {};
1951
+ me.fadeAnimation.finalOpacity = visibility;
1952
+ if (visibility) {
1953
+ me.isVisible = true;
1954
+ }
1955
+ me.owner.notifyArticleAnimating("fade", me.id);
1956
+ const settings = me.owner.options.article.animation.fade;
1957
+ const duration = settings.duration ?? 400;
1958
+ const easingName = settings.easing ?? "swing";
1959
+ const easingFn = EASINGS[easingName] || EASINGS.swing;
1960
+ const startOpacity = me.opacity;
1961
+ const endOpacity = visibility ? 1 : 0;
1962
+ const fadeTween = tween({
1963
+ from: startOpacity,
1964
+ to: endOpacity,
1965
+ duration,
1966
+ easing: easingFn,
1967
+ /** Fired every animation frame */
1968
+ onUpdate(value) {
1969
+ me.opacity = value;
1970
+ me.owner.requestRedraw();
1971
+ },
1972
+ /** Finalise */
1973
+ onComplete() {
1974
+ me.isFading = false;
1975
+ if (!visibility) {
1976
+ me.isVisible = false;
1977
+ me._releaseImageResource({ skipRedraw: true });
1978
+ }
1979
+ const last = me.owner.lastAnimatingArticle;
1980
+ if (me.id === last.id && last.animationType === "fade") {
1981
+ me.owner.isAnimatingArticles = false;
1982
+ }
1983
+ if (typeof settings.complete === "function") {
1984
+ settings.complete.call(me);
1985
+ }
1986
+ }
1987
+ });
1988
+ me.fadeAnimation.dummyElement = fadeTween;
1989
+ };
1990
+ Article.prototype.moveToOffset = function(destination) {
1991
+ this.finalOffset.top = this.offset.top = destination.top || this.offset.top;
1992
+ this.finalOffset.left = this.offset.left = destination.left || this.offset.left;
1993
+ this.position.top = this.registeredPosition.top + this.offset.top;
1994
+ this.position.left = this.registeredPosition.left + this.offset.left;
1995
+ };
1996
+ Article.prototype.moveTo = function(destination) {
1997
+ const finalOffset = {
1998
+ left: destination.left - this.registeredPosition.left,
1999
+ top: destination.top - this.registeredPosition.top
2000
+ };
2001
+ this.moveToOffset(finalOffset);
2002
+ };
2003
+ Article.prototype.moveToWithAnim = function(destination) {
2004
+ const finalOffset = {
2005
+ left: destination.left - this.registeredPosition.left,
2006
+ top: destination.top - this.registeredPosition.top
2007
+ };
2008
+ this.moveToOffsetWithAnim(finalOffset);
2009
+ };
2010
+ Article.prototype.moveToOffsetWithAnim = function(destination) {
2011
+ const me = this;
2012
+ const moveAnimation = me.moveAnimation;
2013
+ if (destination.top === moveAnimation.finalOffset.top && destination.left === moveAnimation.finalOffset.left) {
2014
+ return;
2015
+ }
2016
+ if (me.isMoving && moveAnimation?.dummyElement?.stop) {
2017
+ moveAnimation.dummyElement.stop();
2018
+ }
2019
+ moveAnimation.finalOffset = this.finalOffset = {
2020
+ left: destination.left,
2021
+ top: destination.top
2022
+ };
2023
+ me.isMoving = true;
2024
+ me.owner.notifyArticleAnimating("move", me.id);
2025
+ const settings = me.owner.options.article.animation.move;
2026
+ const duration = settings.duration ?? 400;
2027
+ const easingName = settings.easing ?? "swing";
2028
+ const easingFn = EASINGS[easingName] || EASINGS.swing;
2029
+ const startTop = me.offset.top;
2030
+ const startLeft = me.offset.left;
2031
+ const deltaTop = destination.top - startTop;
2032
+ const deltaLeft = destination.left - startLeft;
2033
+ const moveTween = tween({
2034
+ from: 0,
2035
+ to: 1,
2036
+ duration,
2037
+ easing: easingFn,
2038
+ onUpdate(progress) {
2039
+ me.offset.top = startTop + deltaTop * progress;
2040
+ me.offset.left = startLeft + deltaLeft * progress;
2041
+ me.position.top = me.registeredPosition.top + me.offset.top;
2042
+ me.position.left = me.registeredPosition.left + me.offset.left;
2043
+ me.owner.requestRedraw();
2044
+ },
2045
+ onComplete() {
2046
+ me.offset.top = destination.top;
2047
+ me.offset.left = destination.left;
2048
+ me.position.top = me.registeredPosition.top + destination.top;
2049
+ me.position.left = me.registeredPosition.left + destination.left;
2050
+ me.isMoving = false;
2051
+ const last = me.owner.lastAnimatingArticle;
2052
+ if (me.id === last.id && last.animationType === "move") {
2053
+ me.owner.isAnimatingArticles = false;
2054
+ }
2055
+ }
2056
+ });
2057
+ moveAnimation.dummyElement = moveTween;
2058
+ };
2059
+ function roundPixel(value) {
2060
+ return Math.round(value);
2061
+ }
2062
+ __name(roundPixel, "roundPixel");
2063
+ function snapPixel(value, dpr = 1) {
2064
+ const ratio = typeof dpr === "number" && isFinite(dpr) && dpr > 0 ? dpr : 1;
2065
+ return Math.round(value * ratio) / ratio;
2066
+ }
2067
+ __name(snapPixel, "snapPixel");
2068
+ function retainPixel(value) {
2069
+ return value;
2070
+ }
2071
+ __name(retainPixel, "retainPixel");
2072
+ function createPixelSnap(dpr = 1, mode = "device") {
2073
+ if (mode === false || mode === "none") {
2074
+ return retainPixel;
2075
+ }
2076
+ if (mode === "css") {
2077
+ return roundPixel;
2078
+ }
2079
+ return /* @__PURE__ */ __name(function snapToDevicePixel(value) {
2080
+ return snapPixel(value, dpr);
2081
+ }, "snapToDevicePixel");
2082
+ }
2083
+ __name(createPixelSnap, "createPixelSnap");
2084
+ function createStrokePixelSnap(dpr = 1, mode = "device", lineWidth = 1) {
2085
+ if (mode === false || mode === "none") {
2086
+ return retainPixel;
2087
+ }
2088
+ const deviceRatio = typeof dpr === "number" && isFinite(dpr) && dpr > 0 ? dpr : 1;
2089
+ const ratio = mode === "css" ? 1 : deviceRatio;
2090
+ const width = typeof lineWidth === "number" && isFinite(lineWidth) && lineWidth > 0 ? lineWidth : 1;
2091
+ const halfPhysicalWidth = width * ratio / 2;
2092
+ return /* @__PURE__ */ __name(function snapStrokeCentre(value) {
2093
+ return (Math.round(value * ratio - halfPhysicalWidth) + halfPhysicalWidth) / ratio;
2094
+ }, "snapStrokeCentre");
2095
+ }
2096
+ __name(createStrokePixelSnap, "createStrokePixelSnap");
2097
+ function createInnerSpace(outerSpace, borderWidth, snap) {
2098
+ if (!snap) {
2099
+ snap = roundPixel;
2100
+ }
2101
+ const halfBorder = borderWidth / 2;
2102
+ return {
2103
+ left: snap(outerSpace.left + halfBorder),
2104
+ top: snap(outerSpace.top + halfBorder),
2105
+ width: snap(outerSpace.width - borderWidth),
2106
+ height: snap(outerSpace.height - borderWidth)
2107
+ };
2108
+ }
2109
+ __name(createInnerSpace, "createInnerSpace");
2110
+ Article.prototype.draw = function(ctx) {
2111
+ if (!this.isDataLoaded || isNaN(this.position.left)) {
2112
+ return;
2113
+ }
2114
+ this._ensureSizeCache();
2115
+ ctx.globalAlpha = this.opacity;
2116
+ const cardLayout = this._getCurrentCardLayout();
2117
+ cardLayout.draw.call(this, ctx);
2118
+ };
2119
+ Article.prototype.getCurrentStyle = function() {
2120
+ if (this.isActive) {
2121
+ return this.isMouseover ? this.activeHoverStyle : this.activeStyle;
2122
+ }
2123
+ return this.isMouseover ? this.hoverStyle : this.style;
2124
+ };
2125
+ Article.prototype._getCurrentStyle = function() {
2126
+ return this.getCurrentStyle();
2127
+ };
2128
+ Article.prototype._getPeriodLineRenderGeometry = function(axisY) {
2129
+ const resolvedArticleOptions = this.owner._getResolvedArticleOptions(this);
2130
+ const periodLineOptions = resolvedArticleOptions.periodLine || {};
2131
+ const globalPeriodLineOptions = this.owner.options.article.periodLine || {};
2132
+ const position = globalPeriodLineOptions.position || "axis";
2133
+ const baselineGap = Number.isFinite(periodLineOptions.baselineGap) ? periodLineOptions.baselineGap : 0;
2134
+ const spacing = this.hidePeriodLine ? 0 : periodLineOptions.spacing || 0;
2135
+ const thickness = this.hidePeriodLine ? 0 : periodLineOptions.thickness || 0;
2136
+ const offset = (spacing + thickness) * this.stacking;
2137
+ let anchorY = axisY;
2138
+ let anchorOffset = this.owner.options.style.mainLine.size / 2;
2139
+ if (position === "lane" && this.owner._isLaneLayoutActive()) {
2140
+ const lane = this.owner.getLaneById(this.laneId);
2141
+ if (lane && lane.geometry) {
2142
+ anchorY = Math.floor(lane.geometry.bottom);
2143
+ anchorOffset = 0;
2144
+ }
2145
+ }
2146
+ const y = anchorY - baselineGap - offset - anchorOffset - thickness / 2;
2147
+ return {
2148
+ position,
2149
+ baselineGap,
2150
+ spacing,
2151
+ thickness,
2152
+ anchorY,
2153
+ anchorOffset,
2154
+ y
2155
+ };
2156
+ };
2157
+ Article.prototype.drawPeriodLinesAndConnectors = function(ctx, axisY) {
2158
+ ctx.globalAlpha = this.opacity;
2159
+ const style = this.getCurrentStyle();
2160
+ const geometry = this._getPeriodLineRenderGeometry(axisY);
2161
+ const y = geometry.y;
2162
+ if (!this.hidePeriodLine) {
2163
+ const fromX = this.indicator.fromX, toX = this.indicator.toX;
2164
+ ctx.beginPath();
2165
+ ctx.lineWidth = geometry.thickness;
2166
+ ctx.moveTo(fromX, y);
2167
+ ctx.lineTo(toX, y);
2168
+ if (this.period.isToPresent) {
2169
+ const periodLength = toX - fromX, maxFadeLength = 15, fadeStartColorStop = Math.max(1 - maxFadeLength / periodLength, 0.7), grad = ctx.createLinearGradient(fromX, y, toX, y);
2170
+ grad.addColorStop(0, style.color);
2171
+ grad.addColorStop(fadeStartColorStop, style.color);
2172
+ grad.addColorStop(1, "rgba(255,255,255,0)");
2173
+ ctx.strokeStyle = grad;
2174
+ } else {
2175
+ ctx.strokeStyle = style.color;
2176
+ }
2177
+ ctx.stroke();
2178
+ }
2179
+ if (!style.connectorLine.visible) {
2180
+ return;
2181
+ }
2182
+ const cardLayout = this._getCurrentCardLayout();
2183
+ const connectorEnd = typeof cardLayout.getConnectorEnd === "function" ? cardLayout.getConnectorEnd.call(this) : {
2184
+ left: this.position.left + style.connectorLine.offsetX,
2185
+ top: this.position.top + this.getHeight() + style.connectorLine.offsetY
2186
+ };
2187
+ const x1 = Math.max(0, this.indicator.fromX);
2188
+ const y1 = y;
2189
+ const x2 = connectorEnd.left;
2190
+ const y2 = connectorEnd.top;
2191
+ const isVertical = Math.abs(x1 - x2) < Number.EPSILON;
2192
+ const pixelSnapMode = this.owner?.options?.article?.rendering?.pixelSnap;
2193
+ const snapStroke = createStrokePixelSnap(
2194
+ this.owner?.getCanvasDpr?.() || 1,
2195
+ pixelSnapMode,
2196
+ style.connectorLine.thickness
2197
+ );
2198
+ const connectorX = isVertical ? snapStroke(x2) : null;
2199
+ const drawX1 = connectorX ?? x1;
2200
+ const drawX2 = connectorX ?? x2;
2201
+ ctx.strokeStyle = ctx.fillStyle = style.color;
2202
+ ctx.lineWidth = style.connectorLine.thickness;
2203
+ ctx.beginPath();
2204
+ ctx.moveTo(drawX1, y1);
2205
+ ctx.lineTo(drawX2, y2);
2206
+ ctx.stroke();
2207
+ const radians = Math.atan((y2 - y1) / (drawX2 - drawX1)) + (drawX2 >= drawX1 ? -90 : 90) * Math.PI / 180;
2208
+ ctx.save();
2209
+ ctx.beginPath();
2210
+ ctx.translate(drawX2, y2);
2211
+ ctx.rotate(radians);
2212
+ ctx.moveTo(-style.connectorLine.arrow.width, 0);
2213
+ ctx.lineTo(style.connectorLine.arrow.width, 0);
2214
+ ctx.lineTo(0, -style.connectorLine.arrow.height);
2215
+ ctx.closePath();
2216
+ ctx.restore();
2217
+ ctx.fill();
2218
+ };
2219
+ Article.prototype.getIconBox = function() {
2220
+ const cardLayout = this._getCurrentCardLayout();
2221
+ return cardLayout.getIconBox.call(this);
2222
+ };
2223
+ Article.prototype.startDragging = function(pos, evt) {
2224
+ if (this.isMoving) {
2225
+ this.moveAnimation.dummyElement.stop();
2226
+ }
2227
+ this.isDragging = true;
2228
+ this.dragInitialPosition = { left: this.position.left, top: this.position.top };
2229
+ this.lastDragPosition = { left: this.position.left, top: this.position.top };
2230
+ this.dragStartOffset = {
2231
+ left: pos.left - this.position.left,
2232
+ top: pos.top - this.position.top
2233
+ };
2234
+ this.owner.startAnimation();
2235
+ if (this.owner && typeof this.owner.trigger === "function") {
2236
+ this.owner.trigger("article-drag-start", this, evt);
2237
+ }
2238
+ };
2239
+ Article.prototype.stopDragging = function(evt) {
2240
+ this.offset = this.finalOffset = this.moveAnimation.finalOffset = {
2241
+ left: this.position.left - this.registeredPosition.left,
2242
+ top: this.position.top - this.registeredPosition.top
2243
+ };
2244
+ this.isDragging = false;
2245
+ this.owner?._markTimelineStateChanged?.();
2246
+ if (this.owner && typeof this.owner.trigger === "function") {
2247
+ this.owner.trigger("article-drag-end", this, evt);
2248
+ }
2249
+ };
2250
+ Article.prototype.dragging = function(pos, evt) {
2251
+ const newPosition = {
2252
+ left: pos.left - this.dragStartOffset.left,
2253
+ top: pos.top - this.dragStartOffset.top
2254
+ };
2255
+ const previousPosition = this.lastDragPosition || {
2256
+ left: this.position.left,
2257
+ top: this.position.top
2258
+ };
2259
+ const initialPosition = this.dragInitialPosition || previousPosition;
2260
+ const dx = newPosition.left - previousPosition.left;
2261
+ const dy = newPosition.top - previousPosition.top;
2262
+ const totalDx = newPosition.left - initialPosition.left;
2263
+ const totalDy = newPosition.top - initialPosition.top;
2264
+ this.position = newPosition;
2265
+ this.lastDragPosition = newPosition;
2266
+ if (this.owner && typeof this.owner.trigger === "function") {
2267
+ this.owner.trigger("article-drag", this, { dx, dy, totalDx, totalDy }, evt);
2268
+ }
2269
+ };
2270
+ Article.prototype._cacheBucket = function() {
2271
+ const name = this._getCurrentCardLayoutName();
2272
+ if (!this._layoutCaches) {
2273
+ this._layoutCaches = /* @__PURE__ */ Object.create(null);
2274
+ }
2275
+ return this._layoutCaches[name] || (this._layoutCaches[name] = /* @__PURE__ */ Object.create(null));
2276
+ };
2277
+ Article.prototype.memo = function(key, factory) {
2278
+ const bucket = this._cacheBucket();
2279
+ return key in bucket ? bucket[key] : bucket[key] = factory.call(this);
2280
+ };
2281
+ Article.prototype._getSizeCacheKey = function() {
2282
+ const style = typeof this.getCurrentStyle === "function" ? this.getCurrentStyle() : null;
2283
+ const imageStyle = style && style.image || {};
2284
+ const header = style && style.header || {};
2285
+ const subheader = style && style.subheader || {};
2286
+ const border = style && style.border || {};
2287
+ const layout = typeof this._getCurrentCardLayoutName === "function" ? this._getCurrentCardLayoutName() : "";
2288
+ const hasImage = this.imageLoaded && this.image;
2289
+ const keyParts = [
2290
+ layout,
2291
+ style && style.width,
2292
+ style && style.height,
2293
+ header.height,
2294
+ subheader.height,
2295
+ border.width,
2296
+ imageStyle.margin ?? 0,
2297
+ imageStyle.shape || "",
2298
+ imageStyle.maxHeight ?? "",
2299
+ style && style.maxImageHeight !== void 0 ? style.maxImageHeight : "",
2300
+ hasImage ? this.image.width : "noimg",
2301
+ hasImage ? this.image.height : ""
2302
+ ];
2303
+ return keyParts.join("|");
2304
+ };
2305
+ Article.prototype.updateCachedSize = function() {
2306
+ const cardLayout = this._getCurrentCardLayout();
2307
+ this._cachedWidth = cardLayout.getWidth.call(this);
2308
+ this._cachedHeight = cardLayout.getHeight.call(this);
2309
+ this.height = this._cachedHeight;
2310
+ this._sizeValid = true;
2311
+ this._sizeCacheKey = this._getSizeCacheKey();
2312
+ };
2313
+ Article.prototype._ensureSizeCache = function() {
2314
+ const cacheKey = this._getSizeCacheKey();
2315
+ if (!this._sizeValid || cacheKey !== this._sizeCacheKey) {
2316
+ this.updateCachedSize();
2317
+ }
2318
+ };
2319
+ Article.prototype.invalidateCaches = function() {
2320
+ this._sizeValid = false;
2321
+ this._sizeCacheKey = null;
2322
+ if (this._layoutCaches) {
2323
+ const buckets = this._layoutCaches;
2324
+ for (const layoutName in buckets) {
2325
+ const bucket = buckets[layoutName];
2326
+ if (!bucket) {
2327
+ continue;
2328
+ }
2329
+ for (const k in bucket) {
2330
+ const v = bucket[k];
2331
+ if (v && typeof v.close === "function") {
2332
+ try {
2333
+ v.close();
2334
+ } catch {
2335
+ }
2336
+ }
2337
+ }
2338
+ }
2339
+ }
2340
+ this._layoutCaches = null;
2341
+ };
2342
+ Article.prototype._getCurrentCardLayoutName = function() {
2343
+ return this._resolvedCardLayoutName || this.cardLayout || this._resolvedDefaultCardLayout || this.owner._resolveArticleCardLayoutName(this);
2344
+ };
2345
+ Article.prototype._getCurrentCardLayout = function() {
2346
+ return this.owner.getCardLayout(this._getCurrentCardLayoutName());
2347
+ };
2348
+ Article.prototype.setCardLayout = function(cardLayout) {
2349
+ const layout = this.owner.getCardLayout(cardLayout);
2350
+ if (!layout) {
2351
+ throw new Error(`Card layout "${cardLayout}" not found`);
2352
+ }
2353
+ this.cardLayout = cardLayout;
2354
+ this._resolvedCardLayoutName = cardLayout;
2355
+ this.initialiseStyles();
2356
+ this.invalidateCaches();
2357
+ this.owner.requestRedraw(this.redraw);
2358
+ };
2359
+ function compareArticleIds(idA, idB) {
2360
+ const numA = Number(idA);
2361
+ const numB = Number(idB);
2362
+ const idsAreNumeric = Number.isFinite(numA) && Number.isFinite(numB);
2363
+ if (idsAreNumeric) {
2364
+ return numA - numB;
2365
+ }
2366
+ const strA = String(idA);
2367
+ const strB = String(idB);
2368
+ if (strA === strB) {
2369
+ return 0;
2370
+ }
2371
+ return strA < strB ? -1 : 1;
2372
+ }
2373
+ __name(compareArticleIds, "compareArticleIds");
2374
+ function ARTICLE_DURATION_SORTER(articleA, articleB) {
2375
+ const a = articleA.period.from.getDaysTo(articleA.period.to);
2376
+ const b = articleB.period.from.getDaysTo(articleB.period.to);
2377
+ if (a < b) {
2378
+ return 1;
2379
+ }
2380
+ if (a > b) {
2381
+ return -1;
2382
+ }
2383
+ return compareArticleIds(articleA.id, articleB.id);
2384
+ }
2385
+ __name(ARTICLE_DURATION_SORTER, "ARTICLE_DURATION_SORTER");
2386
+ function ARTICLE_DURATION_YEARS_SORTER(articleA, articleB) {
2387
+ const a = articleA.period.years;
2388
+ const b = articleB.period.years;
2389
+ if (a < b) {
2390
+ return 1;
2391
+ }
2392
+ if (a > b) {
2393
+ return -1;
2394
+ }
2395
+ return compareArticleIds(articleA.id, articleB.id);
2396
+ }
2397
+ __name(ARTICLE_DURATION_YEARS_SORTER, "ARTICLE_DURATION_YEARS_SORTER");
2398
+ function ARTICLE_IMAGE_QUEUE_SORTER(articleA, articleB) {
2399
+ const a = articleA.isInView && articleA.isVisible;
2400
+ const b = articleB.isInView && articleB.isVisible;
2401
+ if (!a && b) {
2402
+ return -1;
2403
+ }
2404
+ if (a && !b) {
2405
+ return 1;
2406
+ }
2407
+ return articleA.position.top - articleB.position.top;
2408
+ }
2409
+ __name(ARTICLE_IMAGE_QUEUE_SORTER, "ARTICLE_IMAGE_QUEUE_SORTER");
2410
+ function ARTICLE_FROM_SORTER(articleA, articleB) {
2411
+ const a = articleA.period.from;
2412
+ const b = articleB.period.from;
2413
+ let result = a.compare(b);
2414
+ if (result === 0) {
2415
+ result = compareArticleIds(articleB.id, articleA.id);
2416
+ }
2417
+ return result;
2418
+ }
2419
+ __name(ARTICLE_FROM_SORTER, "ARTICLE_FROM_SORTER");
2420
+ function ARTICLE_TO_SORTER(articleA, articleB) {
2421
+ const a = articleA.period.to;
2422
+ const b = articleB.period.to;
2423
+ let result = b.compare(a);
2424
+ if (result === 0) {
2425
+ result = compareArticleIds(articleB.id, articleA.id);
2426
+ }
2427
+ return result;
2428
+ }
2429
+ __name(ARTICLE_TO_SORTER, "ARTICLE_TO_SORTER");
2430
+ function ARTICLE_TOP_SORTER(articleA, articleB) {
2431
+ const a = articleA.position.top;
2432
+ const b = articleB.position.top;
2433
+ if (a < b) {
2434
+ return -1;
2435
+ }
2436
+ if (a > b) {
2437
+ return 1;
2438
+ }
2439
+ return compareArticleIds(articleB.id, articleA.id);
2440
+ }
2441
+ __name(ARTICLE_TOP_SORTER, "ARTICLE_TOP_SORTER");
2442
+ function ARTICLE_ROW_SORTER(articleA, articleB) {
2443
+ const laneOrderA = articleA.laneOrder || 0;
2444
+ const laneOrderB = articleB.laneOrder || 0;
2445
+ if (laneOrderA > laneOrderB) {
2446
+ return -1;
2447
+ }
2448
+ if (laneOrderA < laneOrderB) {
2449
+ return 1;
2450
+ }
2451
+ const a = articleA.row;
2452
+ const b = articleB.row;
2453
+ if (a < b) {
2454
+ return 1;
2455
+ }
2456
+ if (a > b) {
2457
+ return -1;
2458
+ }
2459
+ return compareArticleIds(articleB.id, articleA.id);
2460
+ }
2461
+ __name(ARTICLE_ROW_SORTER, "ARTICLE_ROW_SORTER");
2462
+ function ARTICLE_RANK_SORTER(articleA, articleB) {
2463
+ const a = articleA.rank;
2464
+ const b = articleB.rank;
2465
+ if (a < b) {
2466
+ return 1;
2467
+ }
2468
+ if (a > b) {
2469
+ return -1;
2470
+ }
2471
+ return compareArticleIds(articleB.id, articleA.id);
2472
+ }
2473
+ __name(ARTICLE_RANK_SORTER, "ARTICLE_RANK_SORTER");
2474
+ function ARTICLE_EFFECTIVE_RANK_SORTER(articleA, articleB) {
2475
+ const a = articleA.effectiveRank;
2476
+ const b = articleB.effectiveRank;
2477
+ if (a < b) {
2478
+ return 1;
2479
+ }
2480
+ if (a > b) {
2481
+ return -1;
2482
+ }
2483
+ return compareArticleIds(articleB.id, articleA.id);
2484
+ }
2485
+ __name(ARTICLE_EFFECTIVE_RANK_SORTER, "ARTICLE_EFFECTIVE_RANK_SORTER");
2486
+ function ARTICLE_POSITION_SORTER(articleA, articleB) {
2487
+ const a = articleA.position.left;
2488
+ const b = articleB.position.left;
2489
+ let result = a < b ? 1 : a > b ? -1 : 0;
2490
+ if (result === 0) {
2491
+ result = articleA.position.top - articleB.position.top;
2492
+ if (result === 0) {
2493
+ result = articleA.period.from.compare(articleB.period.from);
2494
+ if (result === 0) {
2495
+ result = compareArticleIds(articleA.id, articleB.id);
2496
+ }
2497
+ }
2498
+ }
2499
+ return result;
2500
+ }
2501
+ __name(ARTICLE_POSITION_SORTER, "ARTICLE_POSITION_SORTER");
2502
+ const sorters = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2460
2503
  __proto__: null,
2461
- DENSITY_ALL,
2462
- DENSITY_HIGH,
2463
- DENSITY_LOW,
2464
- DENSITY_MEDIUM,
2465
- DENSITY_SETTINGS,
2466
- ERA_MARKER,
2467
- MAJOR_MARKER,
2468
- MINOR_MARKER,
2469
- PRECISION_BILLION_YEARS,
2470
- PRECISION_CENTURY,
2471
- PRECISION_DAY,
2472
- PRECISION_DECADE,
2473
- PRECISION_HOUR,
2474
- PRECISION_MILLENNIUM,
2475
- PRECISION_MILLION_YEARS,
2476
- PRECISION_MILLISECOND,
2477
- PRECISION_MINUTE,
2478
- PRECISION_MONTH,
2479
- PRECISION_SECOND,
2480
- PRECISION_YEAR,
2481
- RANGE_ALL,
2482
- RANGE_SCREEN,
2483
- YEAR_PREFIXES,
2484
- ZOOM_100_MILLION_YEARS,
2485
- ZOOM_100_THOUSAND_YEARS,
2486
- ZOOM_10_MILLION_YEARS,
2487
- ZOOM_10_THOUSAND_YEARS,
2488
- ZOOM_BILLION_YEARS,
2489
- ZOOM_CENTURY,
2490
- ZOOM_DAY,
2491
- ZOOM_DECADE,
2492
- ZOOM_HOUR,
2493
- ZOOM_MILLENNIUM,
2494
- ZOOM_MILLION_YEARS,
2495
- ZOOM_MILLISECOND,
2496
- ZOOM_MINUTE,
2497
- ZOOM_MONTH,
2498
- ZOOM_SECOND,
2499
- ZOOM_YEAR
2504
+ ARTICLE_DURATION_SORTER,
2505
+ ARTICLE_DURATION_YEARS_SORTER,
2506
+ ARTICLE_EFFECTIVE_RANK_SORTER,
2507
+ ARTICLE_FROM_SORTER,
2508
+ ARTICLE_IMAGE_QUEUE_SORTER,
2509
+ ARTICLE_POSITION_SORTER,
2510
+ ARTICLE_RANK_SORTER,
2511
+ ARTICLE_ROW_SORTER,
2512
+ ARTICLE_TOP_SORTER,
2513
+ ARTICLE_TO_SORTER
2500
2514
  }, Symbol.toStringTag, { value: "Module" }));
2501
2515
  const CHART_RENDERERS = /* @__PURE__ */ new Map();
2502
2516
  function registerChartRenderer(type, renderer) {
@@ -3714,16 +3728,17 @@ function normalizeDate(owner, input) {
3714
3728
  }
3715
3729
  const month = parseFiniteInteger(input.month, 1);
3716
3730
  const day = parseFiniteInteger(input.day, 1);
3717
- const precision = input.precision;
3718
- let dmy = new Dmy(
3731
+ const precision = getDatePrecision(input);
3732
+ let dmy = new Dmy({
3719
3733
  year,
3720
3734
  month,
3721
3735
  day,
3722
- parseFiniteInteger(input.hour, 0),
3723
- parseFiniteInteger(input.minute, 0),
3724
- parseFiniteInteger(input.second, 0),
3725
- parseFiniteInteger(input.millisecond, 0)
3726
- );
3736
+ precision,
3737
+ hour: parseFiniteInteger(input.hour, 0),
3738
+ minute: parseFiniteInteger(input.minute, 0),
3739
+ second: parseFiniteInteger(input.second, 0),
3740
+ millisecond: parseFiniteInteger(input.millisecond, 0)
3741
+ });
3727
3742
  dmy = owner.getDmyFromInput(dmy);
3728
3743
  return Dmy.CreateAsStartOfPeriod(dmy, precision);
3729
3744
  }
@@ -4139,12 +4154,8 @@ function resolveDistanceToBaselineValue(distanceToBaseline, availableHeight, lan
4139
4154
  }
4140
4155
  __name(resolveDistanceToBaselineValue, "resolveDistanceToBaselineValue");
4141
4156
  const ARTICLE_DATA_DEFAULTS = {
4142
- from: {
4143
- precision: "day"
4144
- },
4145
- to: {
4146
- precision: "day"
4147
- },
4157
+ from: {},
4158
+ to: {},
4148
4159
  rank: 0,
4149
4160
  starred: false,
4150
4161
  hidePeriodLine: false,
@@ -4942,17 +4953,9 @@ TimeBand.prototype.setupByReceivedData = function(receivedData) {
4942
4953
  this.isDataLoaded = true;
4943
4954
  };
4944
4955
  TimeBand.prototype._setupPeriod = function(data) {
4945
- let fromDmy = new Dmy(
4946
- parseInt(getPropertyFromData(data, "from.year")),
4947
- parseInt(getPropertyFromData(data, "from.month")),
4948
- parseInt(getPropertyFromData(data, "from.day")),
4949
- parseInt(getPropertyFromData(data, "from.hour")),
4950
- parseInt(getPropertyFromData(data, "from.minute")),
4951
- parseInt(getPropertyFromData(data, "from.second")),
4952
- parseInt(getPropertyFromData(data, "from.millisecond"))
4953
- );
4956
+ let fromDmy = getDmyFromData(data, "from");
4954
4957
  fromDmy = this.owner.getDmyFromInput(fromDmy);
4955
- const fromPrecision = getPropertyFromData(data, "from.precision");
4958
+ const fromPrecision = fromDmy.precision;
4956
4959
  const isToPresentProp = getPropertyFromData(data, "isToPresent");
4957
4960
  const isToPresent = isToPresentProp === true || isToPresentProp === 1;
4958
4961
  let toDmy;
@@ -4960,17 +4963,9 @@ TimeBand.prototype._setupPeriod = function(data) {
4960
4963
  if (isToPresent) {
4961
4964
  toDmy = Dmy.now();
4962
4965
  } else if (existsInData(data, "to")) {
4963
- toDmy = new Dmy(
4964
- parseInt(getPropertyFromData(data, "to.year")),
4965
- parseInt(getPropertyFromData(data, "to.month")),
4966
- parseInt(getPropertyFromData(data, "to.day")),
4967
- parseInt(getPropertyFromData(data, "to.hour")),
4968
- parseInt(getPropertyFromData(data, "to.minute")),
4969
- parseInt(getPropertyFromData(data, "to.second")),
4970
- parseInt(getPropertyFromData(data, "to.millisecond"))
4971
- );
4966
+ toDmy = getDmyFromData(data, "to");
4972
4967
  toDmy = this.owner.getDmyFromInput(toDmy);
4973
- toPrecision = getPropertyFromData(data, "to.precision");
4968
+ toPrecision = toDmy.precision;
4974
4969
  } else {
4975
4970
  toDmy = fromDmy;
4976
4971
  toPrecision = fromPrecision;
@@ -7452,6 +7447,7 @@ Timeline.prototype.setOption = function(option, value) {
7452
7447
  }
7453
7448
  option = buildObjectFromPath(normalizedOptionPath, value);
7454
7449
  }
7450
+ const previousTop = this.top;
7455
7451
  option = handleDeprecatedOptions(option);
7456
7452
  if (existsInData(option, "article")) {
7457
7453
  deepMerge(this._explicitArticleOptions, option.article || {});
@@ -7529,6 +7525,9 @@ Timeline.prototype.setOption = function(option, value) {
7529
7525
  const articleStyleScope = articleImpact.styleChanged ? "all" : laneRefreshState.styleLaneIds.size > 0 ? laneRefreshState.styleLaneIds : null;
7530
7526
  this._refreshResolvedLanesFromOptions({ articleStyleScope });
7531
7527
  }
7528
+ if (this.top !== previousTop && this.options.article.autoStacking.fitToHeight && !this._isLaneLayoutActive()) {
7529
+ this.fitToHeight();
7530
+ }
7532
7531
  this.requestRedraw();
7533
7532
  };
7534
7533
  Timeline.prototype.setSize = function(width, height) {
@@ -7903,6 +7902,7 @@ function normaliseDateInput(date) {
7903
7902
  throw new Error("Date input requires a numeric year or canonical Histropedia date string");
7904
7903
  }
7905
7904
  return new Dmy({
7905
+ precision: getDatePrecision(parsed),
7906
7906
  year: parsed.year,
7907
7907
  month: parsed.month ?? 1,
7908
7908
  day: parsed.day ?? 1,
@@ -9284,13 +9284,14 @@ Timeline.prototype.getDmyFromInput = function(dmy) {
9284
9284
  normalised = new Dmy(dmy);
9285
9285
  } else {
9286
9286
  normalised = new Dmy({
9287
+ precision: dmy.precision,
9287
9288
  year: dmy.year,
9288
9289
  month: dmy.month ?? 1,
9289
9290
  day: dmy.day ?? 1,
9290
- hour: dmy.hour ?? 0,
9291
- minute: dmy.minute ?? 0,
9292
- second: dmy.second ?? 0,
9293
- millisecond: dmy.millisecond ?? 0
9291
+ hour: dmy.hour,
9292
+ minute: dmy.minute,
9293
+ second: dmy.second,
9294
+ millisecond: dmy.millisecond
9294
9295
  });
9295
9296
  }
9296
9297
  if (!this.options?.shiftBceDates) {