ng-prime-tools 1.1.13 → 1.1.15
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.
|
@@ -9794,6 +9794,7 @@ var PTNewsTickerTrend;
|
|
|
9794
9794
|
|
|
9795
9795
|
class PTNewsTickerComponent {
|
|
9796
9796
|
static { this.SCROLL_ANIMATION_NAME = 'pt-news-ticker-scroll'; }
|
|
9797
|
+
static { this.MINIMUM_CYCLE_TIMEOUT_MS = 50; }
|
|
9797
9798
|
constructor(changeDetectorRef, zone) {
|
|
9798
9799
|
this.changeDetectorRef = changeDetectorRef;
|
|
9799
9800
|
this.zone = zone;
|
|
@@ -9843,6 +9844,7 @@ class PTNewsTickerComponent {
|
|
|
9843
9844
|
this.hovered = false;
|
|
9844
9845
|
this.pendingNews = null;
|
|
9845
9846
|
this.animationFrameId = null;
|
|
9847
|
+
this.pendingNewsCycleTimeoutId = null;
|
|
9846
9848
|
this.viewInitialized = false;
|
|
9847
9849
|
this.applyingPendingNews = false;
|
|
9848
9850
|
this.newBadgeTimeouts = new Map();
|
|
@@ -9851,11 +9853,15 @@ class PTNewsTickerComponent {
|
|
|
9851
9853
|
ngOnChanges(changes) {
|
|
9852
9854
|
if (changes['news']) {
|
|
9853
9855
|
const normalizedNews = this.normalizeNews(changes['news'].currentValue ?? []);
|
|
9854
|
-
this.
|
|
9856
|
+
this.applyInputNewsPreservingAnimation(normalizedNews);
|
|
9855
9857
|
}
|
|
9856
9858
|
if (changes['speed'] || changes['minSpeed'] || changes['maxSpeed']) {
|
|
9857
9859
|
this.speed = this.normalizeSpeed(this.speed);
|
|
9860
|
+
this.clearPendingNewsCycleTimeout();
|
|
9858
9861
|
this.scheduleAnimationRefresh(true);
|
|
9862
|
+
if (this.pendingNews) {
|
|
9863
|
+
this.schedulePendingNewsAtCurrentCycleEnd();
|
|
9864
|
+
}
|
|
9859
9865
|
}
|
|
9860
9866
|
if (changes['defaultSpeed']) {
|
|
9861
9867
|
this.defaultSpeed = this.normalizeSpeed(this.defaultSpeed);
|
|
@@ -9869,12 +9875,19 @@ class PTNewsTickerComponent {
|
|
|
9869
9875
|
if (!this.playing) {
|
|
9870
9876
|
this.applyPendingNewsImmediately();
|
|
9871
9877
|
}
|
|
9878
|
+
else if (this.pendingNews) {
|
|
9879
|
+
this.schedulePendingNewsAtCurrentCycleEnd();
|
|
9880
|
+
}
|
|
9872
9881
|
}
|
|
9873
9882
|
if (changes['gap'] ||
|
|
9874
9883
|
changes['height'] ||
|
|
9875
9884
|
changes['direction'] ||
|
|
9876
9885
|
changes['loop']) {
|
|
9886
|
+
this.clearPendingNewsCycleTimeout();
|
|
9877
9887
|
this.scheduleAnimationRefresh(true);
|
|
9888
|
+
if (this.pendingNews) {
|
|
9889
|
+
this.schedulePendingNewsAtCurrentCycleEnd();
|
|
9890
|
+
}
|
|
9878
9891
|
}
|
|
9879
9892
|
}
|
|
9880
9893
|
ngAfterViewInit() {
|
|
@@ -9883,6 +9896,9 @@ class PTNewsTickerComponent {
|
|
|
9883
9896
|
this.initializeResizeObserver();
|
|
9884
9897
|
this.scheduleAnimationRefresh(true);
|
|
9885
9898
|
this.changeDetectorRef.detectChanges();
|
|
9899
|
+
if (this.pendingNews) {
|
|
9900
|
+
this.schedulePendingNewsAtCurrentCycleEnd();
|
|
9901
|
+
}
|
|
9886
9902
|
}
|
|
9887
9903
|
ngOnDestroy() {
|
|
9888
9904
|
this.resizeObserver?.disconnect();
|
|
@@ -9891,6 +9907,7 @@ class PTNewsTickerComponent {
|
|
|
9891
9907
|
cancelAnimationFrame(this.animationFrameId);
|
|
9892
9908
|
this.animationFrameId = null;
|
|
9893
9909
|
}
|
|
9910
|
+
this.clearPendingNewsCycleTimeout();
|
|
9894
9911
|
this.clearNewBadgeTimeouts();
|
|
9895
9912
|
this.pendingNews = null;
|
|
9896
9913
|
}
|
|
@@ -9927,6 +9944,7 @@ class PTNewsTickerComponent {
|
|
|
9927
9944
|
});
|
|
9928
9945
|
}
|
|
9929
9946
|
clearNews() {
|
|
9947
|
+
this.clearPendingNewsCycleTimeout();
|
|
9930
9948
|
this.pendingNews = null;
|
|
9931
9949
|
this.internalNews = [];
|
|
9932
9950
|
this.clearNewBadgeTimeouts();
|
|
@@ -9949,6 +9967,9 @@ class PTNewsTickerComponent {
|
|
|
9949
9967
|
}
|
|
9950
9968
|
this.playing = true;
|
|
9951
9969
|
this.emitPlayStateChange();
|
|
9970
|
+
if (this.pendingNews) {
|
|
9971
|
+
this.schedulePendingNewsAtCurrentCycleEnd();
|
|
9972
|
+
}
|
|
9952
9973
|
}
|
|
9953
9974
|
pause() {
|
|
9954
9975
|
if (!this.playing) {
|
|
@@ -9963,6 +9984,10 @@ class PTNewsTickerComponent {
|
|
|
9963
9984
|
this.emitPlayStateChange();
|
|
9964
9985
|
if (!this.playing) {
|
|
9965
9986
|
this.applyPendingNewsImmediately();
|
|
9987
|
+
return;
|
|
9988
|
+
}
|
|
9989
|
+
if (this.pendingNews) {
|
|
9990
|
+
this.schedulePendingNewsAtCurrentCycleEnd();
|
|
9966
9991
|
}
|
|
9967
9992
|
}
|
|
9968
9993
|
increaseSpeed() {
|
|
@@ -9986,16 +10011,24 @@ class PTNewsTickerComponent {
|
|
|
9986
10011
|
speed: nextSpeed,
|
|
9987
10012
|
});
|
|
9988
10013
|
this.emitPlayStateChange();
|
|
10014
|
+
this.clearPendingNewsCycleTimeout();
|
|
9989
10015
|
this.scheduleAnimationRefresh(true);
|
|
10016
|
+
if (this.pendingNews) {
|
|
10017
|
+
this.schedulePendingNewsAtCurrentCycleEnd();
|
|
10018
|
+
}
|
|
9990
10019
|
}
|
|
9991
10020
|
onMouseEnter() {
|
|
9992
10021
|
if (!this.pauseOnHover) {
|
|
9993
10022
|
return;
|
|
9994
10023
|
}
|
|
9995
10024
|
this.hovered = true;
|
|
10025
|
+
this.clearPendingNewsCycleTimeout();
|
|
9996
10026
|
}
|
|
9997
10027
|
onMouseLeave() {
|
|
9998
10028
|
this.hovered = false;
|
|
10029
|
+
if (this.pendingNews && this.playing) {
|
|
10030
|
+
this.schedulePendingNewsAtCurrentCycleEnd();
|
|
10031
|
+
}
|
|
9999
10032
|
}
|
|
10000
10033
|
onTrackAnimationIteration(event) {
|
|
10001
10034
|
if (!this.isTickerScrollEvent(event)) {
|
|
@@ -10179,34 +10212,138 @@ class PTNewsTickerComponent {
|
|
|
10179
10212
|
? 0
|
|
10180
10213
|
: -1;
|
|
10181
10214
|
}
|
|
10182
|
-
|
|
10215
|
+
applyInputNewsPreservingAnimation(news) {
|
|
10183
10216
|
const clonedNews = this.cloneNews(news);
|
|
10184
10217
|
this.scheduleNewBadges(clonedNews);
|
|
10185
|
-
|
|
10186
|
-
|
|
10187
|
-
!this.playing ||
|
|
10188
|
-
this.internalNews.length === 0 ||
|
|
10189
|
-
this.prefersReducedMotion()) {
|
|
10218
|
+
this.clearPendingNewsCycleTimeout();
|
|
10219
|
+
if (!this.viewInitialized) {
|
|
10190
10220
|
this.pendingNews = null;
|
|
10191
10221
|
this.internalNews = clonedNews;
|
|
10192
|
-
|
|
10193
|
-
|
|
10194
|
-
|
|
10222
|
+
return;
|
|
10223
|
+
}
|
|
10224
|
+
if (this.areNewsListsEquivalent(this.internalNews, clonedNews)) {
|
|
10225
|
+
return;
|
|
10226
|
+
}
|
|
10227
|
+
const animationState = this.captureTrackAnimationState();
|
|
10228
|
+
this.pendingNews = null;
|
|
10229
|
+
this.internalNews = clonedNews;
|
|
10230
|
+
this.changeDetectorRef.detectChanges();
|
|
10231
|
+
this.zone.runOutsideAngular(() => {
|
|
10232
|
+
requestAnimationFrame(() => {
|
|
10233
|
+
requestAnimationFrame(() => {
|
|
10234
|
+
this.zone.run(() => {
|
|
10235
|
+
this.calculateAnimationDuration();
|
|
10236
|
+
this.restoreTrackAnimationState(animationState);
|
|
10237
|
+
});
|
|
10238
|
+
});
|
|
10239
|
+
});
|
|
10240
|
+
});
|
|
10241
|
+
}
|
|
10242
|
+
captureTrackAnimationState() {
|
|
10243
|
+
const animation = this.findTrackAnimation();
|
|
10244
|
+
if (!animation) {
|
|
10245
|
+
return {
|
|
10246
|
+
progress: null,
|
|
10247
|
+
playbackRate: 1,
|
|
10248
|
+
wasPaused: !this.playing || (this.pauseOnHover && this.hovered),
|
|
10249
|
+
};
|
|
10250
|
+
}
|
|
10251
|
+
const timing = animation.effect?.getComputedTiming();
|
|
10252
|
+
const duration = typeof timing?.duration === 'number' ? timing.duration : null;
|
|
10253
|
+
const currentTime = typeof animation.currentTime === 'number' ? animation.currentTime : null;
|
|
10254
|
+
const progress = duration !== null && duration > 0 && currentTime !== null
|
|
10255
|
+
? (currentTime % duration) / duration
|
|
10256
|
+
: null;
|
|
10257
|
+
return {
|
|
10258
|
+
progress,
|
|
10259
|
+
playbackRate: Number.isFinite(animation.playbackRate)
|
|
10260
|
+
? animation.playbackRate
|
|
10261
|
+
: 1,
|
|
10262
|
+
wasPaused: animation.playState === 'paused' ||
|
|
10263
|
+
!this.playing ||
|
|
10264
|
+
(this.pauseOnHover && this.hovered),
|
|
10265
|
+
};
|
|
10266
|
+
}
|
|
10267
|
+
restoreTrackAnimationState(state) {
|
|
10268
|
+
const animation = this.findTrackAnimation();
|
|
10269
|
+
if (!animation) {
|
|
10270
|
+
return;
|
|
10271
|
+
}
|
|
10272
|
+
if (Number.isFinite(state.playbackRate)) {
|
|
10273
|
+
animation.playbackRate = state.playbackRate;
|
|
10274
|
+
}
|
|
10275
|
+
if (state.progress !== null) {
|
|
10276
|
+
const timing = animation.effect?.getComputedTiming();
|
|
10277
|
+
const duration = typeof timing?.duration === 'number' ? timing.duration : null;
|
|
10278
|
+
if (duration !== null && duration > 0) {
|
|
10279
|
+
animation.currentTime = state.progress * duration;
|
|
10195
10280
|
}
|
|
10281
|
+
}
|
|
10282
|
+
if (state.wasPaused) {
|
|
10283
|
+
animation.pause();
|
|
10196
10284
|
return;
|
|
10197
10285
|
}
|
|
10198
|
-
|
|
10286
|
+
animation.play();
|
|
10287
|
+
}
|
|
10288
|
+
findTrackAnimation() {
|
|
10289
|
+
const trackElement = this.tickerTrack?.nativeElement;
|
|
10290
|
+
if (!trackElement || typeof trackElement.getAnimations !== 'function') {
|
|
10291
|
+
return null;
|
|
10292
|
+
}
|
|
10293
|
+
const animations = trackElement.getAnimations();
|
|
10294
|
+
const tickerAnimation = animations.find((animation) => {
|
|
10295
|
+
const animationName = animation.animationName;
|
|
10296
|
+
return animationName === PTNewsTickerComponent.SCROLL_ANIMATION_NAME;
|
|
10297
|
+
});
|
|
10298
|
+
return (tickerAnimation ??
|
|
10299
|
+
animations.find((animation) => animation.playState !== 'idle') ??
|
|
10300
|
+
null);
|
|
10301
|
+
}
|
|
10302
|
+
areNewsListsEquivalent(currentNews, nextNews) {
|
|
10303
|
+
if (currentNews.length !== nextNews.length) {
|
|
10304
|
+
return false;
|
|
10305
|
+
}
|
|
10306
|
+
return currentNews.every((currentItem, index) => {
|
|
10307
|
+
const nextItem = nextNews[index];
|
|
10308
|
+
if (!nextItem) {
|
|
10309
|
+
return false;
|
|
10310
|
+
}
|
|
10311
|
+
return (String(currentItem.id) === String(nextItem.id) &&
|
|
10312
|
+
currentItem.text === nextItem.text &&
|
|
10313
|
+
currentItem.type === nextItem.type &&
|
|
10314
|
+
currentItem.link === nextItem.link &&
|
|
10315
|
+
this.areSegmentsEquivalent(currentItem.segments, nextItem.segments));
|
|
10316
|
+
});
|
|
10317
|
+
}
|
|
10318
|
+
areSegmentsEquivalent(currentSegments, nextSegments) {
|
|
10319
|
+
const safeCurrentSegments = currentSegments ?? [];
|
|
10320
|
+
const safeNextSegments = nextSegments ?? [];
|
|
10321
|
+
if (safeCurrentSegments.length !== safeNextSegments.length) {
|
|
10322
|
+
return false;
|
|
10323
|
+
}
|
|
10324
|
+
return safeCurrentSegments.every((currentSegment, index) => {
|
|
10325
|
+
const nextSegment = safeNextSegments[index];
|
|
10326
|
+
if (!nextSegment) {
|
|
10327
|
+
return false;
|
|
10328
|
+
}
|
|
10329
|
+
return (currentSegment.label === nextSegment.label &&
|
|
10330
|
+
currentSegment.value === nextSegment.value &&
|
|
10331
|
+
currentSegment.trend === nextSegment.trend &&
|
|
10332
|
+
currentSegment.icon === nextSegment.icon);
|
|
10333
|
+
});
|
|
10199
10334
|
}
|
|
10200
10335
|
queueOrApplyNews(news) {
|
|
10201
10336
|
const clonedNews = this.cloneNews(news);
|
|
10202
10337
|
this.scheduleNewBadges(clonedNews);
|
|
10203
10338
|
if (this.shouldApplyNewsImmediately()) {
|
|
10339
|
+
this.clearPendingNewsCycleTimeout();
|
|
10204
10340
|
this.pendingNews = null;
|
|
10205
10341
|
this.internalNews = clonedNews;
|
|
10206
10342
|
this.scheduleAnimationRefresh(true);
|
|
10207
10343
|
return;
|
|
10208
10344
|
}
|
|
10209
10345
|
this.pendingNews = clonedNews;
|
|
10346
|
+
this.schedulePendingNewsAtCurrentCycleEnd();
|
|
10210
10347
|
}
|
|
10211
10348
|
shouldApplyNewsImmediately() {
|
|
10212
10349
|
return (!this.viewInitialized ||
|
|
@@ -10215,10 +10352,63 @@ class PTNewsTickerComponent {
|
|
|
10215
10352
|
this.internalNews.length === 0 ||
|
|
10216
10353
|
this.prefersReducedMotion());
|
|
10217
10354
|
}
|
|
10355
|
+
schedulePendingNewsAtCurrentCycleEnd() {
|
|
10356
|
+
if (!this.pendingNews ||
|
|
10357
|
+
this.pendingNewsCycleTimeoutId !== null ||
|
|
10358
|
+
!this.viewInitialized ||
|
|
10359
|
+
!this.playing ||
|
|
10360
|
+
this.hovered) {
|
|
10361
|
+
return;
|
|
10362
|
+
}
|
|
10363
|
+
const remainingDuration = this.resolveCurrentCycleRemainingDuration();
|
|
10364
|
+
this.zone.runOutsideAngular(() => {
|
|
10365
|
+
this.pendingNewsCycleTimeoutId = setTimeout(() => {
|
|
10366
|
+
this.zone.run(() => {
|
|
10367
|
+
this.pendingNewsCycleTimeoutId = null;
|
|
10368
|
+
if (!this.playing || this.hovered) {
|
|
10369
|
+
return;
|
|
10370
|
+
}
|
|
10371
|
+
this.applyPendingNewsAtCycleBoundary();
|
|
10372
|
+
});
|
|
10373
|
+
}, remainingDuration);
|
|
10374
|
+
});
|
|
10375
|
+
}
|
|
10376
|
+
resolveCurrentCycleRemainingDuration() {
|
|
10377
|
+
const trackElement = this.tickerTrack?.nativeElement;
|
|
10378
|
+
const fallbackDuration = Math.max(PTNewsTickerComponent.MINIMUM_CYCLE_TIMEOUT_MS, this.animationDurationSeconds * 1000);
|
|
10379
|
+
if (!trackElement || typeof trackElement.getAnimations !== 'function') {
|
|
10380
|
+
return fallbackDuration;
|
|
10381
|
+
}
|
|
10382
|
+
const animation = trackElement
|
|
10383
|
+
.getAnimations()
|
|
10384
|
+
.find((candidate) => candidate.playState !== 'idle');
|
|
10385
|
+
if (!animation) {
|
|
10386
|
+
return fallbackDuration;
|
|
10387
|
+
}
|
|
10388
|
+
const computedTiming = animation.effect?.getComputedTiming();
|
|
10389
|
+
const animationDuration = typeof computedTiming?.duration === 'number'
|
|
10390
|
+
? computedTiming.duration
|
|
10391
|
+
: fallbackDuration;
|
|
10392
|
+
const currentTime = typeof animation.currentTime === 'number' ? animation.currentTime : 0;
|
|
10393
|
+
if (!Number.isFinite(animationDuration) || animationDuration <= 0) {
|
|
10394
|
+
return fallbackDuration;
|
|
10395
|
+
}
|
|
10396
|
+
const elapsedInCurrentCycle = currentTime % animationDuration;
|
|
10397
|
+
const remainingDuration = animationDuration - elapsedInCurrentCycle;
|
|
10398
|
+
return Math.max(PTNewsTickerComponent.MINIMUM_CYCLE_TIMEOUT_MS, Math.ceil(remainingDuration));
|
|
10399
|
+
}
|
|
10400
|
+
clearPendingNewsCycleTimeout() {
|
|
10401
|
+
if (this.pendingNewsCycleTimeoutId === null) {
|
|
10402
|
+
return;
|
|
10403
|
+
}
|
|
10404
|
+
clearTimeout(this.pendingNewsCycleTimeoutId);
|
|
10405
|
+
this.pendingNewsCycleTimeoutId = null;
|
|
10406
|
+
}
|
|
10218
10407
|
applyPendingNewsAtCycleBoundary() {
|
|
10219
10408
|
if (!this.pendingNews || this.applyingPendingNews) {
|
|
10220
10409
|
return;
|
|
10221
10410
|
}
|
|
10411
|
+
this.clearPendingNewsCycleTimeout();
|
|
10222
10412
|
this.applyingPendingNews = true;
|
|
10223
10413
|
const nextNews = this.cloneNews(this.pendingNews);
|
|
10224
10414
|
this.pendingNews = null;
|
|
@@ -10230,6 +10420,9 @@ class PTNewsTickerComponent {
|
|
|
10230
10420
|
this.zone.run(() => {
|
|
10231
10421
|
this.calculateAnimationDuration();
|
|
10232
10422
|
this.applyingPendingNews = false;
|
|
10423
|
+
if (this.pendingNews) {
|
|
10424
|
+
this.schedulePendingNewsAtCurrentCycleEnd();
|
|
10425
|
+
}
|
|
10233
10426
|
});
|
|
10234
10427
|
});
|
|
10235
10428
|
});
|
|
@@ -10239,6 +10432,7 @@ class PTNewsTickerComponent {
|
|
|
10239
10432
|
if (!this.pendingNews) {
|
|
10240
10433
|
return;
|
|
10241
10434
|
}
|
|
10435
|
+
this.clearPendingNewsCycleTimeout();
|
|
10242
10436
|
const nextNews = this.cloneNews(this.pendingNews);
|
|
10243
10437
|
this.pendingNews = null;
|
|
10244
10438
|
this.internalNews = nextNews;
|
|
@@ -10361,7 +10555,11 @@ class PTNewsTickerComponent {
|
|
|
10361
10555
|
this.zone.runOutsideAngular(() => {
|
|
10362
10556
|
this.resizeObserver = new ResizeObserver(() => {
|
|
10363
10557
|
this.zone.run(() => {
|
|
10558
|
+
this.clearPendingNewsCycleTimeout();
|
|
10364
10559
|
this.scheduleAnimationRefresh(true);
|
|
10560
|
+
if (this.pendingNews) {
|
|
10561
|
+
this.schedulePendingNewsAtCurrentCycleEnd();
|
|
10562
|
+
}
|
|
10365
10563
|
});
|
|
10366
10564
|
});
|
|
10367
10565
|
this.resizeObserver.observe(viewportElement);
|