@opengeoweb/time-slider 20.0.1 → 20.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -986,20 +986,19 @@ var withModeSelections = function withModeSelections(setting, now) {
986
986
  }
987
987
  return setting;
988
988
  };
989
+ /* A longer timestep floors to the hour, so a window keeps the frames its offsets ask for. */
990
+ var MAX_ANCHOR_ROUNDING_IN_MINUTES = 60;
991
+ var startOfTimeStep = function startOfTimeStep(instant, timeStep) {
992
+ return dateUtils.fromUnix(roundWithTimeStep(dateUtils.unix(instant), Math.min(timeStep, MAX_ANCHOR_ROUNDING_IN_MINUTES), 'floor'));
993
+ };
989
994
  /**
990
995
  * A recurring period anchors on its time of day within the current UTC date, so the
991
996
  * window it resolves rolls onto the next day once the clock passes midnight.
992
997
  */
993
- var resolveAnchorInstant = function resolveAnchorInstant(setting, now) {
994
- if (now === void 0) {
995
- now = dateUtils.utc();
996
- }
997
- if (setting.mode !== AnimationLengthMode.RecurringPeriod) {
998
- return now;
999
- }
1000
- var _setting$recurringPer = setting.recurringPeriod.anchorTime.split(':').map(Number),
1001
- hours = _setting$recurringPer[0],
1002
- minutes = _setting$recurringPer[1];
998
+ var recurringPeriodAnchor = function recurringPeriodAnchor(anchorTime, now) {
999
+ var _anchorTime$split$map = anchorTime.split(':').map(Number),
1000
+ hours = _anchorTime$split$map[0],
1001
+ minutes = _anchorTime$split$map[1];
1003
1002
  return dateUtils.set(now, {
1004
1003
  hours: hours,
1005
1004
  minutes: minutes,
@@ -1007,29 +1006,34 @@ var resolveAnchorInstant = function resolveAnchorInstant(setting, now) {
1007
1006
  milliseconds: 0
1008
1007
  });
1009
1008
  };
1010
- /**
1011
- * The instant a mode counts its offsets from. Only ReferenceTime takes one from
1012
- * outside, so handing a layer's reference time to any other mode cannot move it.
1013
- */
1014
- var anchorInstantFor = function anchorInstantFor(setting, referenceTime, now) {
1015
- if (now === void 0) {
1016
- now = dateUtils.utc();
1009
+ /** The instant a mode counts its offsets from. */
1010
+ var anchorInstantFor = function anchorInstantFor(setting, _temp) {
1011
+ var _ref4 = _temp === void 0 ? {} : _temp,
1012
+ _ref4$now = _ref4.now,
1013
+ now = _ref4$now === void 0 ? dateUtils.utc() : _ref4$now,
1014
+ referenceTime = _ref4.referenceTime,
1015
+ timeStep = _ref4.timeStep;
1016
+ if (setting.mode === AnimationLengthMode.ReferenceTime && referenceTime) {
1017
+ return dateUtils.utc(referenceTime);
1018
+ }
1019
+ if (setting.mode === AnimationLengthMode.RecurringPeriod) {
1020
+ return recurringPeriodAnchor(setting.recurringPeriod.anchorTime, now);
1017
1021
  }
1018
- return setting.mode === AnimationLengthMode.ReferenceTime && referenceTime ? dateUtils.utc(referenceTime) : resolveAnchorInstant(setting, now);
1022
+ return timeStep ? startOfTimeStep(now, timeStep) : now;
1019
1023
  };
1020
1024
  /**
1021
1025
  * Offsets are signed: negative lands before the anchor, positive after. They are
1022
1026
  * applied as calendar durations, so "+ 1 month" lands on the same day of the next
1023
1027
  * month rather than a fixed number of days later.
1024
1028
  */
1025
- var resolveAnimationRange = function resolveAnimationRange(setting, now) {
1026
- if (now === void 0) {
1027
- now = dateUtils.utc();
1029
+ var resolveAnimationRange = function resolveAnimationRange(setting, anchorInputs) {
1030
+ if (anchorInputs === void 0) {
1031
+ anchorInputs = {};
1028
1032
  }
1029
1033
  var _activeOffsets = activeOffsets(setting),
1030
1034
  startOffset = _activeOffsets.startOffset,
1031
1035
  endOffset = _activeOffsets.endOffset;
1032
- var anchor = resolveAnchorInstant(setting, now);
1036
+ var anchor = anchorInstantFor(setting, anchorInputs);
1033
1037
  return {
1034
1038
  animationStartTime: toAnimationTime(dateUtils.add(anchor, offsetToDuration(startOffset))),
1035
1039
  animationEndTime: toAnimationTime(dateUtils.add(anchor, offsetToDuration(endOffset)))
@@ -1065,9 +1069,9 @@ var offsetForInstant = function offsetForInstant(anchor, instant, unit) {
1065
1069
  var snapInstantToOffsetGrid = function snapInstantToOffsetGrid(anchor, instant, unit) {
1066
1070
  return dateUtils.add(anchor, offsetToDuration(clampOffset(offsetForInstant(anchor, instant, unit))));
1067
1071
  };
1068
- var isWithinOffsetLimit = function isWithinOffsetLimit(_ref4) {
1069
- var value = _ref4.value,
1070
- unit = _ref4.unit;
1072
+ var isWithinOffsetLimit = function isWithinOffsetLimit(_ref5) {
1073
+ var value = _ref5.value,
1074
+ unit = _ref5.unit;
1071
1075
  return Math.abs(value) <= maxOffsetByUnit[unit];
1072
1076
  };
1073
1077
  /**
@@ -1075,10 +1079,10 @@ var isWithinOffsetLimit = function isWithinOffsetLimit(_ref4) {
1075
1079
  * out keeps the offset it holds: reading its instant back would subtract whatever time
1076
1080
  * passed since that instant was resolved.
1077
1081
  */
1078
- var offsetsForRange = function offsetsForRange(setting, _ref5, now) {
1079
- var animationStartTime = _ref5.animationStartTime,
1080
- animationEndTime = _ref5.animationEndTime;
1081
- var anchor = resolveAnchorInstant(setting, now);
1082
+ var offsetsForRange = function offsetsForRange(setting, _ref6, anchorInputs) {
1083
+ var animationStartTime = _ref6.animationStartTime,
1084
+ animationEndTime = _ref6.animationEndTime;
1085
+ var anchor = anchorInstantFor(setting, anchorInputs);
1082
1086
  var unit = activeEditUnit(setting);
1083
1087
  var heldOffsets = activeOffsets(setting);
1084
1088
  var offsetOf = function offsetOf(time) {
@@ -1097,9 +1101,9 @@ var offsetsForRange = function offsetsForRange(setting, _ref5, now) {
1097
1101
  * own selections change, and only on the edges the range names; the modes that read their
1098
1102
  * range from elsewhere keep it, and so does an edge the mode's offsets cannot reach.
1099
1103
  */
1100
- var withDraggedRange = function withDraggedRange(setting, range, now) {
1101
- if (now === void 0) {
1102
- now = dateUtils.utc();
1104
+ var withDraggedRange = function withDraggedRange(setting, range, anchorInputs) {
1105
+ if (anchorInputs === void 0) {
1106
+ anchorInputs = {};
1103
1107
  }
1104
1108
  if (setting.mode === AnimationLengthMode.Exact) {
1105
1109
  var _range$animationStart, _range$animationEndTi;
@@ -1110,7 +1114,7 @@ var withDraggedRange = function withDraggedRange(setting, range, now) {
1110
1114
  }
1111
1115
  });
1112
1116
  }
1113
- var offsets = isAnchoredMode(setting.mode) ? offsetsForRange(setting, range, now) : undefined;
1117
+ var offsets = isAnchoredMode(setting.mode) ? offsetsForRange(setting, range, anchorInputs) : undefined;
1114
1118
  if (!offsets) {
1115
1119
  return setting;
1116
1120
  }
@@ -1130,18 +1134,18 @@ var withDraggedRange = function withDraggedRange(setting, range, now) {
1130
1134
  };
1131
1135
  /** Offsets can use different units, so validity is decided on the resolved instants. */
1132
1136
  /** Exact names its range outright; every other mode resolves one from its offsets. */
1133
- var settingRange = function settingRange(setting, now) {
1134
- if (now === void 0) {
1135
- now = dateUtils.utc();
1137
+ var settingRange = function settingRange(setting, anchorInputs) {
1138
+ if (anchorInputs === void 0) {
1139
+ anchorInputs = {};
1136
1140
  }
1137
- return setting.mode === AnimationLengthMode.Exact ? setting.exact : resolveAnimationRange(setting, now);
1141
+ return setting.mode === AnimationLengthMode.Exact ? setting.exact : resolveAnimationRange(setting, anchorInputs);
1138
1142
  };
1139
1143
  /* Exact times are picked to the minute, so seconds must not decide validity. */
1140
- var isValidAnimationLength = function isValidAnimationLength(setting, now) {
1141
- if (now === void 0) {
1142
- now = dateUtils.utc();
1144
+ var isValidAnimationLength = function isValidAnimationLength(setting, anchorInputs) {
1145
+ if (anchorInputs === void 0) {
1146
+ anchorInputs = {};
1143
1147
  }
1144
- var _settingRange = settingRange(setting, now),
1148
+ var _settingRange = settingRange(setting, anchorInputs),
1145
1149
  animationStartTime = _settingRange.animationStartTime,
1146
1150
  animationEndTime = _settingRange.animationEndTime;
1147
1151
  return dateUtils.isBefore(dateUtils.utc(animationStartTime).setSeconds(0, 0), dateUtils.utc(animationEndTime).setSeconds(0, 0));
@@ -1152,14 +1156,14 @@ var MAX_ANIMATION_STEPS = 10000;
1152
1156
  * The cost of an animation is its span divided by the time step, so a wide range
1153
1157
  * is affordable with a coarse step and unaffordable with a fine one.
1154
1158
  */
1155
- var isWithinAnimationStepLimit = function isWithinAnimationStepLimit(setting, timeStepInMinutes, now) {
1156
- if (now === void 0) {
1157
- now = dateUtils.utc();
1159
+ var isWithinAnimationStepLimit = function isWithinAnimationStepLimit(setting, timeStepInMinutes, anchorInputs) {
1160
+ if (anchorInputs === void 0) {
1161
+ anchorInputs = {};
1158
1162
  }
1159
1163
  if (!timeStepInMinutes) {
1160
1164
  return true;
1161
1165
  }
1162
- var _settingRange2 = settingRange(setting, now),
1166
+ var _settingRange2 = settingRange(setting, anchorInputs),
1163
1167
  animationStartTime = _settingRange2.animationStartTime,
1164
1168
  animationEndTime = _settingRange2.animationEndTime;
1165
1169
  var spanInMinutes = dateUtils.differenceInMinutes(dateUtils.utc(animationEndTime), dateUtils.utc(animationStartTime));
@@ -1186,9 +1190,9 @@ var defaultExactSelections = function defaultExactSelections(now) {
1186
1190
  };
1187
1191
  };
1188
1192
  /** Starts Exact from whatever range is already on screen, falling back to the defaults. */
1189
- var exactAnimationLengthFrom = function exactAnimationLengthFrom(_ref6, now) {
1190
- var animationStartTime = _ref6.animationStartTime,
1191
- animationEndTime = _ref6.animationEndTime;
1193
+ var exactAnimationLengthFrom = function exactAnimationLengthFrom(_ref7, now) {
1194
+ var animationStartTime = _ref7.animationStartTime,
1195
+ animationEndTime = _ref7.animationEndTime;
1192
1196
  if (now === void 0) {
1193
1197
  now = dateUtils.utc();
1194
1198
  }
@@ -1208,9 +1212,9 @@ var getOffsetFromTime = function getOffsetFromTime(time, anchorTime) {
1208
1212
  value: value
1209
1213
  };
1210
1214
  };
1211
- var getAnimationLengthFromRange = function getAnimationLengthFromRange(mode, _ref7, now) {
1212
- var animationStartTime = _ref7.animationStartTime,
1213
- animationEndTime = _ref7.animationEndTime;
1215
+ var getAnimationLengthFromRange = function getAnimationLengthFromRange(mode, _ref8, now) {
1216
+ var animationStartTime = _ref8.animationStartTime,
1217
+ animationEndTime = _ref8.animationEndTime;
1214
1218
  if (now === void 0) {
1215
1219
  now = dateUtils.utc();
1216
1220
  }
@@ -2789,7 +2793,9 @@ var AnimationLengthMenu = function AnimationLengthMenu(_ref) {
2789
2793
  }, isStep);
2790
2794
  };
2791
2795
  var resolvesOwnRange = isAnchoredMode(setting.mode);
2792
- var hasInvertedRange = !isValidAnimationLength(setting, dateUtils.utc(referenceTimeFromLayer));
2796
+ var hasInvertedRange = !isValidAnimationLength(setting, {
2797
+ referenceTime: referenceTimeFromLayer
2798
+ });
2793
2799
  var hasTooManySteps = resolvesOwnRange && !hasInvertedRange && !isWithinAnimationStepLimit(setting, timeStep);
2794
2800
  var hasRangeError = hasInvertedRange || hasTooManySteps;
2795
2801
  var rangeError = function () {
@@ -4679,4 +4685,4 @@ var DemoWrapper = function DemoWrapper(_ref2) {
4679
4685
  });
4680
4686
  };
4681
4687
 
4682
- export { ANCHOR_MINUTE_STEP, AUTO_MOVE_AREA_PADDING, AnchorTimeField, AnimationLengthMenu, AnimationLengthMode, AnimationLengthPanel, AutoUpdateButton, _BackwardForwardStepButton as BackwardForwardStepButton, ControlButtons, DRAG_AREA_WIDTH, DemoWrapper, HideSliderButton, MAX_ANIMATION_STEPS, NowButton, OptionsMenu, OptionsMenuButton, PlayButton, Scale, SpeedButton, TIME_SLIDER_LEGEND_HEIGHT, TIME_SLIDER_NAMESPACE, TimeInMinutes, TimeSlider, TimeSliderButtons, TimeSliderCurrentTimeBox, TimeSliderLegend, TimeSliderMenu, TimeSpanButton, _TimeStepButton as TimeStepButton, activeEditUnit, activeOffsets, anchorInstantFor, anchorTimeToPickerDate, asDisplayTime, clampOffset, convertStringTimeToUnix, defaultAnimationDelayAtStart, defaultDelay, defaultEndOffset, defaultExactSelections, defaultOffsetSelections, defaultRecurringPeriodSelections, defaultSecondsPerPx, defaultStartOffset, defaultTimeSpan, defaultTimeStep, exactAnimationLengthFrom, exceedsAnimationStepLimit, getAnimationLengthFromRange, getAutoMoveAreaWidth, getFilteredTime, getFundamentalScale, getLargestTimeUnit, getNewCenterOfFixedPointZoom, getPixelsBetweenViewportAndTimesliderOnLeft, getPositions, getScaleFromSpan, getSpeedDelay, getTimeBoxWidth, getTimeSliderLegendElement, getTimeSliderLegendId, handleSetNowEvent, isAnchoredMode, isDraggingEndWithinBounds, isDraggingStartWithinBounds, isInsideAnimationArea, isLeftAnimationIconArea, isRecurringPeriodMode, isRightAnimationIconArea, isSelectedTimeIconArea, isValidAnchorTime, isValidAnimationLength, isWithinAnimationStepLimit, marks$1 as marks, maxOffsetByUnit, minutesToDescribedDuration, modeTranslationKey, moveSelectedTimePx, offsetForInstant, onsetNewDateDebounced, pickerDateToAnchorTime, pixelToTimestamp, resolveAnchorInstant, resolveAnimationRange, roundWithTimeStep, scaleToSecondsPerPx, scalingCoefficient, secondsPerPxFromCanvasWidth, secondsPerPxToScale, setNextTimeStep, setPreviousTimeStep, settingRange, shortUnitTranslationKey, snapInstantToOffsetGrid, spanToScale, speedFactors, timeBoxGeom, timeSliderUtils, timeUnits, timeValues, timesliderTranslations, timestampToPixel, timestampToPixelEdges, toAnchorTime, toExactAnimationTime, unitTranslationKey, useCanvasTarget, withDraggedRange, withModeSelections };
4688
+ export { ANCHOR_MINUTE_STEP, AUTO_MOVE_AREA_PADDING, AnchorTimeField, AnimationLengthMenu, AnimationLengthMode, AnimationLengthPanel, AutoUpdateButton, _BackwardForwardStepButton as BackwardForwardStepButton, ControlButtons, DRAG_AREA_WIDTH, DemoWrapper, HideSliderButton, MAX_ANIMATION_STEPS, NowButton, OptionsMenu, OptionsMenuButton, PlayButton, Scale, SpeedButton, TIME_SLIDER_LEGEND_HEIGHT, TIME_SLIDER_NAMESPACE, TimeInMinutes, TimeSlider, TimeSliderButtons, TimeSliderCurrentTimeBox, TimeSliderLegend, TimeSliderMenu, TimeSpanButton, _TimeStepButton as TimeStepButton, activeEditUnit, activeOffsets, anchorInstantFor, anchorTimeToPickerDate, asDisplayTime, clampOffset, convertStringTimeToUnix, defaultAnimationDelayAtStart, defaultDelay, defaultEndOffset, defaultExactSelections, defaultOffsetSelections, defaultRecurringPeriodSelections, defaultSecondsPerPx, defaultStartOffset, defaultTimeSpan, defaultTimeStep, exactAnimationLengthFrom, exceedsAnimationStepLimit, getAnimationLengthFromRange, getAutoMoveAreaWidth, getFilteredTime, getFundamentalScale, getLargestTimeUnit, getNewCenterOfFixedPointZoom, getPixelsBetweenViewportAndTimesliderOnLeft, getPositions, getScaleFromSpan, getSpeedDelay, getTimeBoxWidth, getTimeSliderLegendElement, getTimeSliderLegendId, handleSetNowEvent, isAnchoredMode, isDraggingEndWithinBounds, isDraggingStartWithinBounds, isInsideAnimationArea, isLeftAnimationIconArea, isRecurringPeriodMode, isRightAnimationIconArea, isSelectedTimeIconArea, isValidAnchorTime, isValidAnimationLength, isWithinAnimationStepLimit, marks$1 as marks, maxOffsetByUnit, minutesToDescribedDuration, modeTranslationKey, moveSelectedTimePx, offsetForInstant, onsetNewDateDebounced, pickerDateToAnchorTime, pixelToTimestamp, resolveAnimationRange, roundWithTimeStep, scaleToSecondsPerPx, scalingCoefficient, secondsPerPxFromCanvasWidth, secondsPerPxToScale, setNextTimeStep, setPreviousTimeStep, settingRange, shortUnitTranslationKey, snapInstantToOffsetGrid, spanToScale, speedFactors, timeBoxGeom, timeSliderUtils, timeUnits, timeValues, timesliderTranslations, timestampToPixel, timestampToPixelEdges, toAnchorTime, toExactAnimationTime, unitTranslationKey, useCanvasTarget, withDraggedRange, withModeSelections };
@@ -89,22 +89,22 @@ export declare const activeEditUnit: (setting: AnimationLengthSetting) => TimeUn
89
89
  export declare const defaultRecurringPeriodSelections: (now?: Date) => RecurringPeriodSelections;
90
90
  /** Presets carry settings the compiler cannot vouch for, so the selected mode is given the slice it needs. */
91
91
  export declare const withModeSelections: (setting: AnimationLengthSetting, now?: Date) => AnimationLengthSetting;
92
- /**
93
- * A recurring period anchors on its time of day within the current UTC date, so the
94
- * window it resolves rolls onto the next day once the clock passes midnight.
95
- */
96
- export declare const resolveAnchorInstant: (setting: AnimationLengthSetting, now?: Date) => Date;
97
- /**
98
- * The instant a mode counts its offsets from. Only ReferenceTime takes one from
99
- * outside, so handing a layer's reference time to any other mode cannot move it.
100
- */
101
- export declare const anchorInstantFor: (setting: AnimationLengthSetting, referenceTime?: string, now?: Date) => Date;
92
+ /** What the anchored modes count their offsets from; each mode reads only its own input. */
93
+ export interface AnimationAnchorInputs {
94
+ now?: Date;
95
+ /** The leading layer's reference time, which only ReferenceTime counts from. */
96
+ referenceTime?: string;
97
+ /** In minutes; the clock is floored onto it, as the animation frames are. */
98
+ timeStep?: number;
99
+ }
100
+ /** The instant a mode counts its offsets from. */
101
+ export declare const anchorInstantFor: (setting: AnimationLengthSetting, { now, referenceTime, timeStep, }?: AnimationAnchorInputs) => Date;
102
102
  /**
103
103
  * Offsets are signed: negative lands before the anchor, positive after. They are
104
104
  * applied as calendar durations, so "+ 1 month" lands on the same day of the next
105
105
  * month rather than a fixed number of days later.
106
106
  */
107
- export declare const resolveAnimationRange: (setting: AnimationLengthSetting, now?: Date) => AnimationRange;
107
+ export declare const resolveAnimationRange: (setting: AnimationLengthSetting, anchorInputs?: AnimationAnchorInputs) => AnimationRange;
108
108
  /** The whole-unit offset landing nearest the instant, so a handle reaches only what the menu can express. */
109
109
  export declare const offsetForInstant: (anchor: Date, instant: Date, unit: TimeUnit) => RelativeTimeOffset;
110
110
  /** Snaps a dragged handle onto the grid the mode's offsets can describe. */
@@ -114,18 +114,18 @@ export declare const snapInstantToOffsetGrid: (anchor: Date, instant: Date, unit
114
114
  * own selections change, and only on the edges the range names; the modes that read their
115
115
  * range from elsewhere keep it, and so does an edge the mode's offsets cannot reach.
116
116
  */
117
- export declare const withDraggedRange: (setting: AnimationLengthSetting, range: Partial<AnimationRange>, now?: Date) => AnimationLengthSetting;
117
+ export declare const withDraggedRange: (setting: AnimationLengthSetting, range: Partial<AnimationRange>, anchorInputs?: AnimationAnchorInputs) => AnimationLengthSetting;
118
118
  /** Offsets can use different units, so validity is decided on the resolved instants. */
119
119
  /** Exact names its range outright; every other mode resolves one from its offsets. */
120
- export declare const settingRange: (setting: AnimationLengthSetting, now?: Date) => AnimationRange;
121
- export declare const isValidAnimationLength: (setting: AnimationLengthSetting, now?: Date) => boolean;
120
+ export declare const settingRange: (setting: AnimationLengthSetting, anchorInputs?: AnimationAnchorInputs) => AnimationRange;
121
+ export declare const isValidAnimationLength: (setting: AnimationLengthSetting, anchorInputs?: AnimationAnchorInputs) => boolean;
122
122
  /** Frames the animation may hold; the range is expanded one entry per time step. */
123
123
  export declare const MAX_ANIMATION_STEPS = 10000;
124
124
  /**
125
125
  * The cost of an animation is its span divided by the time step, so a wide range
126
126
  * is affordable with a coarse step and unaffordable with a fine one.
127
127
  */
128
- export declare const isWithinAnimationStepLimit: (setting: AnimationLengthSetting, timeStepInMinutes: number | undefined, now?: Date) => boolean;
128
+ export declare const isWithinAnimationStepLimit: (setting: AnimationLengthSetting, timeStepInMinutes: number | undefined, anchorInputs?: AnimationAnchorInputs) => boolean;
129
129
  export declare const toExactAnimationTime: (date: Date) => string;
130
130
  /** A day either side of now, so an exact window opens on something usable. */
131
131
  export declare const defaultExactSelections: (now?: Date) => ExactSelections;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/time-slider",
3
- "version": "20.0.1",
3
+ "version": "20.1.0",
4
4
  "description": "GeoWeb time-slider library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -20,9 +20,9 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "@opengeoweb/shared": "20.0.1",
23
+ "@opengeoweb/shared": "20.1.0",
24
24
  "lodash": "^4.18.1",
25
- "@opengeoweb/theme": "20.0.1",
25
+ "@opengeoweb/theme": "20.1.0",
26
26
  "@mui/x-date-pickers": "^9.3.0",
27
27
  "@mui/system": "^9.0.1",
28
28
  "i18next": "^25.0.1",