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