@fusion.dev/helix-core 0.245.0 → 0.247.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.
Files changed (40) hide show
  1. package/custom-elements.json +1 -1
  2. package/dist/controllers/chart-pointer-controller/chart-pointer-controller.d.ts +20 -0
  3. package/dist/controllers/chart-pointer-controller/chart-pointer-controller.js +23 -3
  4. package/dist/controllers/drag-dismiss-controller/drag-dismiss-controller.d.ts +170 -0
  5. package/dist/controllers/drag-dismiss-controller/drag-dismiss-controller.js +215 -0
  6. package/dist/controllers/focus-mark-controller/focus-mark-controller.d.ts +58 -0
  7. package/dist/controllers/focus-mark-controller/focus-mark-controller.js +76 -0
  8. package/dist/controllers/hover-mark-controller/hover-mark-controller.d.ts +21 -3
  9. package/dist/controllers/hover-mark-controller/hover-mark-controller.js +31 -15
  10. package/dist/controllers/indicator-controller/indicator-controller.js +1 -1
  11. package/dist/controllers/layout-motion-controller/layout-motion-controller.d.ts +6 -0
  12. package/dist/controllers/layout-motion-controller/layout-motion-controller.js +1 -1
  13. package/dist/controllers/readings-motion-controller/readings-motion-controller.d.ts +167 -0
  14. package/dist/controllers/readings-motion-controller/readings-motion-controller.js +306 -0
  15. package/dist/controllers/source-controller/source-controller.d.ts +7 -0
  16. package/dist/controllers/source-controller/source-controller.js +2 -0
  17. package/dist/controllers/swipe-controller/swipe-controller.d.ts +19 -3
  18. package/dist/controllers/swipe-controller/swipe-controller.js +32 -10
  19. package/dist/events/details.d.ts +6 -2
  20. package/dist/helix-element/mark-rules.d.ts +14 -0
  21. package/dist/helix-element/mark-rules.js +1 -0
  22. package/dist/index.d.ts +9 -1
  23. package/dist/index.js +9 -1
  24. package/dist/utils/burst-confetti/burst-confetti.d.ts +39 -0
  25. package/dist/utils/burst-confetti/burst-confetti.js +251 -0
  26. package/dist/utils/draw-value-axis/draw-value-axis.d.ts +8 -1
  27. package/dist/utils/draw-value-axis/draw-value-axis.js +11 -5
  28. package/dist/utils/flash-change/flash-change.d.ts +55 -0
  29. package/dist/utils/flash-change/flash-change.js +85 -0
  30. package/dist/utils/readings-motion/readings-motion.d.ts +45 -0
  31. package/dist/utils/readings-motion/readings-motion.js +40 -0
  32. package/dist/utils/resize-from/resize-from.d.ts +36 -0
  33. package/dist/utils/resize-from/resize-from.js +37 -0
  34. package/dist/utils/scale/levels.d.ts +57 -0
  35. package/dist/utils/scale/levels.js +19 -0
  36. package/dist/utils/swipe/swipe.d.ts +52 -0
  37. package/dist/utils/swipe/swipe.js +78 -0
  38. package/dist/version.d.ts +1 -1
  39. package/dist/version.js +1 -1
  40. package/package.json +4 -4
@@ -1,4 +1,5 @@
1
1
  const SLOP = 8;
2
+ const RECENT = 100;
2
3
  export class SwipeController {
3
4
  constructor(host, options) {
4
5
  this.samples = [];
@@ -42,12 +43,20 @@ export class SwipeController {
42
43
  return;
43
44
  }
44
45
  this.swiping = true;
45
- this.options.surface()?.setAttribute('data-swiping', '');
46
+ const surface = this.options.surface();
47
+ surface?.setAttribute('data-swiping', '');
48
+ if (this.options.capture && surface) {
49
+ try {
50
+ surface.setPointerCapture(event.pointerId);
51
+ this.captured = surface;
52
+ }
53
+ catch {
54
+ this.captured = undefined;
55
+ }
56
+ }
46
57
  }
47
- this.samples = [
48
- ...this.samples.slice(-1),
49
- { t: event.timeStamp, x: event.clientX, y: event.clientY },
50
- ];
58
+ const at = { t: event.timeStamp, x: event.clientX, y: event.clientY };
59
+ this.samples = [...this.samples.filter((one) => at.t - one.t <= RECENT), at];
51
60
  this.options.move(dx, dy);
52
61
  };
53
62
  this.handleUp = (event) => {
@@ -56,10 +65,11 @@ export class SwipeController {
56
65
  return;
57
66
  }
58
67
  const swiped = this.swiping;
59
- const [before, last] = [this.samples[0], this.samples[this.samples.length - 1]];
60
- const elapsed = before && last ? last.t - before.t : 0;
61
- const vx = before && last && elapsed > 0 ? (last.x - before.x) / elapsed : 0;
62
- const vy = before && last && elapsed > 0 ? (last.y - before.y) / elapsed : 0;
68
+ const at = { t: event.timeStamp, x: event.clientX, y: event.clientY };
69
+ const first = [...this.samples, at].find((one) => at.t - one.t <= RECENT);
70
+ const elapsed = first ? at.t - first.t : 0;
71
+ const vx = first && elapsed > 0 ? (at.x - first.x) / elapsed : 0;
72
+ const vy = first && elapsed > 0 ? (at.y - first.y) / elapsed : 0;
63
73
  this.stop();
64
74
  if (!swiped) {
65
75
  return;
@@ -74,7 +84,13 @@ export class SwipeController {
74
84
  }
75
85
  const swiped = this.swiping;
76
86
  this.stop();
77
- if (swiped) {
87
+ if (!swiped) {
88
+ return;
89
+ }
90
+ if (this.options.cancel) {
91
+ this.options.cancel();
92
+ }
93
+ else {
78
94
  this.options.end(0, 0, 0, 0);
79
95
  }
80
96
  };
@@ -93,6 +109,12 @@ export class SwipeController {
93
109
  window.removeEventListener('pointermove', this.handleMove);
94
110
  window.removeEventListener('pointerup', this.handleUp);
95
111
  window.removeEventListener('pointercancel', this.handleCancel);
112
+ const captured = this.captured;
113
+ const pointer = this.pointer;
114
+ this.captured = undefined;
115
+ if (captured && pointer !== undefined && captured.hasPointerCapture?.(pointer)) {
116
+ captured.releasePointerCapture(pointer);
117
+ }
96
118
  this.options.surface()?.removeAttribute('data-swiping');
97
119
  this.origin = undefined;
98
120
  this.pointer = undefined;
@@ -143,8 +143,12 @@ export interface ActivateDetail extends ChangeDetail {
143
143
  }
144
144
  /** Detail carried by `helix-plot-change`. */
145
145
  export interface PlotChangeDetail {
146
- /** `data` for the points or the axes, which are drawn again; `focus` for the point the keys rest on. */
147
- kind: 'data' | 'focus';
146
+ /**
147
+ * `data` for the points or the axes, which are drawn again; `move` for a
148
+ * frame of the points moving to new readings, drawn again in the colors
149
+ * last read; `focus` for the point the keys rest on.
150
+ */
151
+ kind: 'data' | 'focus' | 'move';
148
152
  }
149
153
  /** Detail carried by `helix-plot-turn`. */
150
154
  export interface PlotTurnDetail {
@@ -175,3 +175,17 @@ export declare const SHUT_RULE = "[data-shut]{rotate:-90deg}:host(:dir(rtl)) [da
175
175
  * leaves the page its scroll.
176
176
  */
177
177
  export declare const TOUCHES_RULE = "[data-touches]{touch-action:none}";
178
+ /**
179
+ * Keeps the page's pan off the axis a surface is dragged along, and leaves it
180
+ * the other one.
181
+ *
182
+ * **A drag the browser reads as a pan is the browser's**, as for
183
+ * `TOUCHES_RULE`: it scrolls and sends `pointercancel`, so a drawer or a
184
+ * message dragged toward its edge would stop under the finger. A surface
185
+ * dragged across keeps the vertical pan for the page, and one dragged up or
186
+ * down the horizontal. `DragDismissController` marks the surface
187
+ * `data-drags="x"` or `data-drags="y"` while it can be dragged, and takes the
188
+ * mark off while it cannot, such as a closed drawer or one with
189
+ * `swipe="false"`.
190
+ */
191
+ export declare const DRAGS_RULE = "[data-drags=x]{touch-action:pan-y}[data-drags=y]{touch-action:pan-x}";
@@ -11,3 +11,4 @@ export const SPOKEN_RULE = '[data-spoken]{position:absolute;inline-size:1px;bloc
11
11
  export const MIRROR_RULE = ':host(:dir(rtl)) [data-mirror]{scale:-1 1}';
12
12
  export const SHUT_RULE = '[data-shut]{rotate:-90deg}:host(:dir(rtl)) [data-shut]{rotate:90deg}';
13
13
  export const TOUCHES_RULE = '[data-touches]{touch-action:none}';
14
+ export const DRAGS_RULE = '[data-drags=x]{touch-action:pan-y}[data-drags=y]{touch-action:pan-x}';
package/dist/index.d.ts CHANGED
@@ -16,8 +16,10 @@ export { activeCue, adoptTrack, type Caption, CueController, captionsAmong, capt
16
16
  export { DelayController, type DelayOptions, } from './controllers/delay-controller/delay-controller.js';
17
17
  export { DisabledCascadeController, type DisabledCascadeOptions, } from './controllers/disabled-cascade-controller/disabled-cascade-controller.js';
18
18
  export { DismissController, type DismissOptions, } from './controllers/dismiss-controller/dismiss-controller.js';
19
+ export { type DragBounds, DragDismissController, type DragDismissOptions, type DragRelease, } from './controllers/drag-dismiss-controller/drag-dismiss-controller.js';
19
20
  export { DrilldownController, type DrilldownOptions, } from './controllers/drilldown-controller/drilldown-controller.js';
20
21
  export { FloatingController, type FloatingOptions, type Placement, type Side, } from './controllers/floating-controller/floating-controller.js';
22
+ export { FocusMarkController, type FocusMarkOptions, } from './controllers/focus-mark-controller/focus-mark-controller.js';
21
23
  export { controlsIn, FocusScopeController, type FocusScopeOptions, } from './controllers/focus-scope-controller/focus-scope-controller.js';
22
24
  export { FullscreenController } from './controllers/fullscreen-controller/fullscreen-controller.js';
23
25
  export { HostClickController } from './controllers/host-click-controller/host-click-controller.js';
@@ -35,6 +37,7 @@ export { MAX_FRAME_STEP, PaintGateController, type PaintGateOptions, } from './c
35
37
  export { PlacementController } from './controllers/placement-controller/placement-controller.js';
36
38
  export { PointerFollowController, type PointerFollowOptions, } from './controllers/pointer-follow-controller/pointer-follow-controller.js';
37
39
  export { hintInside, hintMayShow, onPanelOpen, PopoverController, type PopoverOptions, } from './controllers/popover-controller/popover-controller.js';
40
+ export { type MotionItem, type MotionShares, ReadingsMotionController, type ReadingsMotionOptions, } from './controllers/readings-motion-controller/readings-motion-controller.js';
38
41
  export { RelativeClockController, type RelativeClockOptions, } from './controllers/relative-clock-controller/relative-clock-controller.js';
39
42
  export { RemotePlaybackController, type RemoteReport, } from './controllers/remote-playback-controller/remote-playback-controller.js';
40
43
  export { ReorderController, type ReorderMove, type ReorderOptions, type ReorderWords, requestReorder, } from './controllers/reorder-controller/reorder-controller.js';
@@ -50,7 +53,7 @@ export { eventsForTag, registerElementEvents } from './events/element-events.js'
50
53
  export { type ActivateDetail, type ChangeDetail, type CheckDetail, type CompleteDetail, type CopyDetail, type DismissDetail, type FilterDetail, type FoundDetail, HelixActivateEvent, HelixBeforeActivateEvent, HelixBeforeChangeEvent, HelixBeforeCheckEvent, HelixBeforeCloseEvent, HelixBeforeFilterEvent, HelixBeforeListenEvent, HelixBeforeNavigateEvent, HelixBeforeOpenEvent, HelixBeforePinEvent, HelixBeforeReorderEvent, HelixBeforeResizeEvent, HelixBeforeSelectEvent, HelixBeforeSortEvent, HelixCheckEvent, HelixClearEvent, HelixCompleteEvent, HelixCopyErrorEvent, HelixCopyEvent, HelixDismissEvent, HelixExpandEvent, HelixFilterEvent, HelixFoundEvent, HelixListenEvent, HelixLoadEvent, HelixLoadMoreEvent, HelixNavigateEvent, HelixPinEvent, HelixPlotChangeEvent, HelixPlotTurnEvent, HelixReadingChangeEvent, HelixReadingPressEvent, HelixReorderEvent, HelixResizedEvent, HelixResizeEvent, HelixSelectEvent, HelixSortEvent, type ListenDetail, type NavigateDetail, type OpenDetail, type PlotChangeDetail, type PlotTurnDetail, type PressPointerType, type ReadingDetail, type ReorderDetail, type ResizeDetail, type SelectDetail, type SortDetail, type ViewportPanDetail, type ViewportZoomDetail, } from './events/events.js';
51
54
  export { helixEventNames, registerEventNames } from './events/names.js';
52
55
  export { HelixElement, internalsOf, whenHydrated } from './helix-element/helix-element.js';
53
- export { LAYERS_RULE, MIRROR_RULE, SCROLLER_RULE, SHUT_RULE, SPOKEN_RULE, TOUCHES_RULE, VIRTUAL_RULE, } from './helix-element/mark-rules.js';
56
+ export { DRAGS_RULE, LAYERS_RULE, MIRROR_RULE, SCROLLER_RULE, SHUT_RULE, SPOKEN_RULE, TOUCHES_RULE, VIRTUAL_RULE, } from './helix-element/mark-rules.js';
54
57
  export { untilReactHydrated } from './helix-element/react-bridge.js';
55
58
  export { HelixFormElement } from './helix-form-element/helix-form-element.js';
56
59
  export { HelixFormElementBase } from './helix-form-element/helix-form-element-base.js';
@@ -77,6 +80,7 @@ export { arrowReach, sideOf } from './utils/arrow/arrow.js';
77
80
  export { assignSlot, assignSlots } from './utils/assign-slots/assign-slots.js';
78
81
  export { type DrawAutofillOptions, drawAutofill, } from './utils/autofill-select/autofill-select.js';
79
82
  export { type BoxAxisText, type BoxLabel, type BoxLabelSizes, type BoxPlace, boxLabels, type SeenPlace, } from './utils/box-labels/box-labels.js';
83
+ export { type BurstConfettiOptions, burstConfetti } from './utils/burst-confetti/burst-confetti.js';
80
84
  export { addDays, addMonths, type Barring, barredBy, type CalendarParts, type CalendarView, calendarLocale, type DateCalendar, localToday, MONTH_CALENDARS, type MonthCalendar, type MonthSystem, monthOf, monthOut, monthSystem, type PeriodCell, type PeriodPage, periodCells, periodKey, periodMove, sameMonth, todayIn, weekendOf, weekStartOf, YEARS_SHOWN, yearOut, yearPageOf, } from './utils/calendar/calendar.js';
81
85
  export { capturePointer } from './utils/capture-pointer/capture-pointer.js';
82
86
  export { type AxisLengths, type Category, type PlacedLabel, placeLabels, UNMEASURED_LABELS, } from './utils/category-labels/category-labels.js';
@@ -112,6 +116,7 @@ export { exportParts } from './utils/export-parts/export-parts.js';
112
116
  export { fillTemplate, labelWith } from './utils/fill-template/fill-template.js';
113
117
  export { FILTER_MARK, filterKeeps, markMatches, rangeOf, } from './utils/filter-marks/filter-marks.js';
114
118
  export { FIND_CURRENT, FIND_MATCH, type FindDirection, type Finder, type FindQuery, type FindResult, findPattern, findRanges, findTextRanges, type TextFinderOptions, textFinder, } from './utils/find-text/find-text.js';
119
+ export { type FlashChangeOptions, flashChange } from './utils/flash-change/flash-change.js';
115
120
  export { focusTarget } from './utils/focus-target/focus-target.js';
116
121
  export { autofocusTarget, deepActiveElement, deepContains, focusAs, focusableElements, openingFocus, PRESSABLE, pressedOwnControl, refocusWithin, } from './utils/focusable-elements/focusable-elements.js';
117
122
  export { afterLinkFollowed, followLink, type LinkModifiers, type LinkTarget, } from './utils/follow-link/follow-link.js';
@@ -152,6 +157,7 @@ export { rangeAdd } from './utils/range-add/range-add.js';
152
157
  export { type ColorBytes, type ColorBytesAlpha, readColor, readColorAlpha, rgbOf, } from './utils/read-color/read-color.js';
153
158
  export { type ChartData, type ChartDatum, rowsFromData, seriesFromData, } from './utils/read-data/read-data.js';
154
159
  export { byRow, type Extremes, extremesOf, type Row, type RowCell, readRows, readSeries, type Series, type SeriesPoint, seriesKey, unbroken, } from './utils/read-series/read-series.js';
160
+ export { grownAt, growTime, keysOf, type MovingAxis, mix, mixAxis, } from './utils/readings-motion/readings-motion.js';
155
161
  export { type ElementsProperty, linkDescription, reflectElements, unlinkDescription, } from './utils/reflect-elements/reflect-elements.js';
156
162
  export { type Relative, type RelativeOptions, relativeTime, } from './utils/relative-time/relative-time.js';
157
163
  export { centersOf, dropMark, edgeSpeed, passedCount, placeKey, type ReorderAxis, type ReorderHold, type ReorderInput, type ReorderState, reorderKey, reorderStep, } from './utils/reorder/reorder.js';
@@ -160,11 +166,13 @@ export { RUNTIME_LOG, RUNTIME_SLOT, type RuntimeEvent, type RuntimeKind, reportR
160
166
  export { noteVersion, reportUsage, USAGE_SLOT, VERSIONS_SLOT, } from './utils/report-usage/report-usage.js';
161
167
  export { type ReportValuesOptions, reportValues } from './utils/report-values/report-values.js';
162
168
  export { type ChangeRequestOptions, requestChange, requestValue, } from './utils/request-change/request-change.js';
169
+ export { type ResizeFromOptions, resizeFrom } from './utils/resize-from/resize-from.js';
163
170
  export { type ActivatableItem, resolveActiveItem, } from './utils/resolve-active-item/resolve-active-item.js';
164
171
  export { holdCaret, restoreValue } from './utils/restore-value/restore-value.js';
165
172
  export { type RovingOptions, rovingStop } from './utils/roving-stop/roving-stop.js';
166
173
  export { valueAt } from './utils/row-data/row-data.js';
167
174
  export { type Arranged, type Axis, arranged, cycle, type DataRow, filter, format, type Ordered, ordered, parse, type Sort, sort, window_, } from './utils/row-order/row-order.js';
175
+ export { heldInside, type Level, levelsOf, ScaleMemory, } from './utils/scale/levels.js';
168
176
  export { extent, linear, type Scale } from './utils/scale/scale.js';
169
177
  export { headroom, ticks } from './utils/scale/ticks.js';
170
178
  export { type ScrollerOptions, type ScrollItemOptions, type ScrollRoomOptions, scrollItemIntoView, scrollingAncestor, scrollRoom, scrollWithin, } from './utils/scroll-item-into-view/scroll-item-into-view.js';
package/dist/index.js CHANGED
@@ -16,8 +16,10 @@ export { activeCue, adoptTrack, CueController, captionsAmong, captionTracks, sho
16
16
  export { DelayController, } from './controllers/delay-controller/delay-controller.js';
17
17
  export { DisabledCascadeController, } from './controllers/disabled-cascade-controller/disabled-cascade-controller.js';
18
18
  export { DismissController, } from './controllers/dismiss-controller/dismiss-controller.js';
19
+ export { DragDismissController, } from './controllers/drag-dismiss-controller/drag-dismiss-controller.js';
19
20
  export { DrilldownController, } from './controllers/drilldown-controller/drilldown-controller.js';
20
21
  export { FloatingController, } from './controllers/floating-controller/floating-controller.js';
22
+ export { FocusMarkController, } from './controllers/focus-mark-controller/focus-mark-controller.js';
21
23
  export { controlsIn, FocusScopeController, } from './controllers/focus-scope-controller/focus-scope-controller.js';
22
24
  export { FullscreenController } from './controllers/fullscreen-controller/fullscreen-controller.js';
23
25
  export { HostClickController } from './controllers/host-click-controller/host-click-controller.js';
@@ -35,6 +37,7 @@ export { MAX_FRAME_STEP, PaintGateController, } from './controllers/paint-gate-c
35
37
  export { PlacementController } from './controllers/placement-controller/placement-controller.js';
36
38
  export { PointerFollowController, } from './controllers/pointer-follow-controller/pointer-follow-controller.js';
37
39
  export { hintInside, hintMayShow, onPanelOpen, PopoverController, } from './controllers/popover-controller/popover-controller.js';
40
+ export { ReadingsMotionController, } from './controllers/readings-motion-controller/readings-motion-controller.js';
38
41
  export { RelativeClockController, } from './controllers/relative-clock-controller/relative-clock-controller.js';
39
42
  export { RemotePlaybackController, } from './controllers/remote-playback-controller/remote-playback-controller.js';
40
43
  export { ReorderController, requestReorder, } from './controllers/reorder-controller/reorder-controller.js';
@@ -50,7 +53,7 @@ export { eventsForTag, registerElementEvents } from './events/element-events.js'
50
53
  export { HelixActivateEvent, HelixBeforeActivateEvent, HelixBeforeChangeEvent, HelixBeforeCheckEvent, HelixBeforeCloseEvent, HelixBeforeFilterEvent, HelixBeforeListenEvent, HelixBeforeNavigateEvent, HelixBeforeOpenEvent, HelixBeforePinEvent, HelixBeforeReorderEvent, HelixBeforeResizeEvent, HelixBeforeSelectEvent, HelixBeforeSortEvent, HelixCheckEvent, HelixClearEvent, HelixCompleteEvent, HelixCopyErrorEvent, HelixCopyEvent, HelixDismissEvent, HelixExpandEvent, HelixFilterEvent, HelixFoundEvent, HelixListenEvent, HelixLoadEvent, HelixLoadMoreEvent, HelixNavigateEvent, HelixPinEvent, HelixPlotChangeEvent, HelixPlotTurnEvent, HelixReadingChangeEvent, HelixReadingPressEvent, HelixReorderEvent, HelixResizedEvent, HelixResizeEvent, HelixSelectEvent, HelixSortEvent, } from './events/events.js';
51
54
  export { helixEventNames, registerEventNames } from './events/names.js';
52
55
  export { HelixElement, internalsOf, whenHydrated } from './helix-element/helix-element.js';
53
- export { LAYERS_RULE, MIRROR_RULE, SCROLLER_RULE, SHUT_RULE, SPOKEN_RULE, TOUCHES_RULE, VIRTUAL_RULE, } from './helix-element/mark-rules.js';
56
+ export { DRAGS_RULE, LAYERS_RULE, MIRROR_RULE, SCROLLER_RULE, SHUT_RULE, SPOKEN_RULE, TOUCHES_RULE, VIRTUAL_RULE, } from './helix-element/mark-rules.js';
54
57
  export { untilReactHydrated } from './helix-element/react-bridge.js';
55
58
  export { HelixFormElement } from './helix-form-element/helix-form-element.js';
56
59
  export { HelixFormElementBase } from './helix-form-element/helix-form-element-base.js';
@@ -77,6 +80,7 @@ export { arrowReach, sideOf } from './utils/arrow/arrow.js';
77
80
  export { assignSlot, assignSlots } from './utils/assign-slots/assign-slots.js';
78
81
  export { drawAutofill, } from './utils/autofill-select/autofill-select.js';
79
82
  export { boxLabels, } from './utils/box-labels/box-labels.js';
83
+ export { burstConfetti } from './utils/burst-confetti/burst-confetti.js';
80
84
  export { addDays, addMonths, barredBy, calendarLocale, localToday, MONTH_CALENDARS, monthOf, monthOut, monthSystem, periodCells, periodKey, periodMove, sameMonth, todayIn, weekendOf, weekStartOf, YEARS_SHOWN, yearOut, yearPageOf, } from './utils/calendar/calendar.js';
81
85
  export { capturePointer } from './utils/capture-pointer/capture-pointer.js';
82
86
  export { placeLabels, UNMEASURED_LABELS, } from './utils/category-labels/category-labels.js';
@@ -112,6 +116,7 @@ export { exportParts } from './utils/export-parts/export-parts.js';
112
116
  export { fillTemplate, labelWith } from './utils/fill-template/fill-template.js';
113
117
  export { FILTER_MARK, filterKeeps, markMatches, rangeOf, } from './utils/filter-marks/filter-marks.js';
114
118
  export { FIND_CURRENT, FIND_MATCH, findPattern, findRanges, findTextRanges, textFinder, } from './utils/find-text/find-text.js';
119
+ export { flashChange } from './utils/flash-change/flash-change.js';
115
120
  export { focusTarget } from './utils/focus-target/focus-target.js';
116
121
  export { autofocusTarget, deepActiveElement, deepContains, focusAs, focusableElements, openingFocus, PRESSABLE, pressedOwnControl, refocusWithin, } from './utils/focusable-elements/focusable-elements.js';
117
122
  export { afterLinkFollowed, followLink, } from './utils/follow-link/follow-link.js';
@@ -152,6 +157,7 @@ export { rangeAdd } from './utils/range-add/range-add.js';
152
157
  export { readColor, readColorAlpha, rgbOf, } from './utils/read-color/read-color.js';
153
158
  export { rowsFromData, seriesFromData, } from './utils/read-data/read-data.js';
154
159
  export { byRow, extremesOf, readRows, readSeries, seriesKey, unbroken, } from './utils/read-series/read-series.js';
160
+ export { grownAt, growTime, keysOf, mix, mixAxis, } from './utils/readings-motion/readings-motion.js';
155
161
  export { linkDescription, reflectElements, unlinkDescription, } from './utils/reflect-elements/reflect-elements.js';
156
162
  export { relativeTime, } from './utils/relative-time/relative-time.js';
157
163
  export { centersOf, dropMark, edgeSpeed, passedCount, placeKey, reorderKey, reorderStep, } from './utils/reorder/reorder.js';
@@ -160,11 +166,13 @@ export { RUNTIME_LOG, RUNTIME_SLOT, reportRuntime, } from './utils/report-runtim
160
166
  export { noteVersion, reportUsage, USAGE_SLOT, VERSIONS_SLOT, } from './utils/report-usage/report-usage.js';
161
167
  export { reportValues } from './utils/report-values/report-values.js';
162
168
  export { requestChange, requestValue, } from './utils/request-change/request-change.js';
169
+ export { resizeFrom } from './utils/resize-from/resize-from.js';
163
170
  export { resolveActiveItem, } from './utils/resolve-active-item/resolve-active-item.js';
164
171
  export { holdCaret, restoreValue } from './utils/restore-value/restore-value.js';
165
172
  export { rovingStop } from './utils/roving-stop/roving-stop.js';
166
173
  export { valueAt } from './utils/row-data/row-data.js';
167
174
  export { arranged, cycle, filter, format, ordered, parse, sort, window_, } from './utils/row-order/row-order.js';
175
+ export { heldInside, levelsOf, ScaleMemory, } from './utils/scale/levels.js';
168
176
  export { extent, linear } from './utils/scale/scale.js';
169
177
  export { headroom, ticks } from './utils/scale/ticks.js';
170
178
  export { scrollItemIntoView, scrollingAncestor, scrollRoom, scrollWithin, } from './utils/scroll-item-into-view/scroll-item-into-view.js';
@@ -0,0 +1,39 @@
1
+ /** How `burstConfetti` bursts. */
2
+ export interface BurstConfettiOptions {
3
+ /**
4
+ * The colors of the pieces, as any CSS colors, such as `#e5677d`,
5
+ * `var(--brand)`, or `light-dark(navy, skyblue)`, each read where the origin
6
+ * is. Defaults to the theme's first six series colors,
7
+ * `--helix-color-series-1` to `--helix-color-series-6`.
8
+ */
9
+ colors?: readonly string[] | undefined;
10
+ /** How many pieces burst. Defaults to 80, and at most 400 are drawn. */
11
+ count?: number | undefined;
12
+ }
13
+ /**
14
+ * Bursts confetti up and out of an element, once, for an action that has
15
+ * finished, such as a reader completing onboarding or publishing a page.
16
+ * Resolves once the last piece is gone, about a second and a half later.
17
+ *
18
+ * ```js
19
+ * import { burstConfetti } from '@fusion.dev/helix-core'
20
+ *
21
+ * await publish()
22
+ * burstConfetti(document.querySelector('#publish'))
23
+ * ```
24
+ *
25
+ * **Call it once the action is done.** The press that starts an action can
26
+ * still fail. The pieces fly up from the element, fall, turn, and fade. A
27
+ * second burst while one runs is drawn with it.
28
+ *
29
+ * **Drawn on one canvas over the whole viewport**, which takes no pointer, is
30
+ * hidden from screen readers, and is removed when the last piece is gone. It
31
+ * sits in the top layer where the browser has one, so a burst from inside an
32
+ * open modal `Dialog` is drawn over the dialog.
33
+ *
34
+ * **A burst is decoration**, so say that the action is done in words as well.
35
+ * Nothing is drawn, and the promise resolves at once, for a reader who asked
36
+ * for less motion, while the page's motion is paused, on a server, and while
37
+ * the page is hidden. Pausing the page's motion mid-burst ends it.
38
+ */
39
+ export declare const burstConfetti: (origin: Element, options?: BurstConfettiOptions) => Promise<void>;
@@ -0,0 +1,251 @@
1
+ import { motionPaused, reducedMotion } from '../page-motion/page-motion.js';
2
+ import { readColorAlpha } from '../read-color/read-color.js';
3
+ const COUNT = 80;
4
+ const MOST = 400;
5
+ const GRAVITY = 900;
6
+ const FALLBACK = [
7
+ [91, 124, 250],
8
+ [229, 103, 125],
9
+ [242, 169, 59],
10
+ [63, 182, 139],
11
+ [155, 123, 240],
12
+ [76, 184, 212],
13
+ ];
14
+ const BACK = 0.86;
15
+ let stage;
16
+ const between = (low, high) => low + Math.random() * (high - low);
17
+ const faces = ([red, green, blue], alpha = 1) => [
18
+ `rgb(${red} ${green} ${blue} / ${alpha})`,
19
+ `rgb(${Math.round(red * BACK)} ${Math.round(green * BACK)} ${Math.round(blue * BACK)} / ${alpha})`,
20
+ ];
21
+ const readFaces = (origin, colors) => {
22
+ const style = getComputedStyle(origin);
23
+ const values = colors ??
24
+ [1, 2, 3, 4, 5, 6]
25
+ .map((step) => style.getPropertyValue(`--helix-color-series-${step}`).trim())
26
+ .filter(Boolean);
27
+ const read = [];
28
+ if (values.length > 0) {
29
+ const probe = document.createElement('span');
30
+ probe.setAttribute('aria-hidden', 'true');
31
+ probe.style.cssText = 'position:fixed;visibility:hidden;pointer-events:none';
32
+ probe.style.colorScheme = style.colorScheme;
33
+ document.body.append(probe);
34
+ for (const value of values) {
35
+ probe.style.color = '';
36
+ probe.style.color = value.replace(/currentcolor/gi, style.color);
37
+ if (!probe.style.color) {
38
+ continue;
39
+ }
40
+ const bytes = readColorAlpha(getComputedStyle(probe).color);
41
+ if (bytes && bytes[3] > 0) {
42
+ read.push(faces([bytes[0], bytes[1], bytes[2]], bytes[3]));
43
+ }
44
+ }
45
+ probe.remove();
46
+ }
47
+ return read.length > 0 ? read : FALLBACK.map((bytes) => faces(bytes));
48
+ };
49
+ const fit = (open) => {
50
+ const width = open.canvas.clientWidth || innerWidth;
51
+ const height = open.canvas.clientHeight || innerHeight;
52
+ const ratio = Math.min(devicePixelRatio || 1, 3);
53
+ if (width === open.width && height === open.height && ratio === open.ratio) {
54
+ return;
55
+ }
56
+ Object.assign(open, { height, ratio, width });
57
+ open.canvas.width = Math.round(width * ratio);
58
+ open.canvas.height = Math.round(height * ratio);
59
+ };
60
+ const openStage = () => {
61
+ if (stage) {
62
+ if (stage.canvas.matches(':popover-open')) {
63
+ try {
64
+ stage.canvas.hidePopover();
65
+ stage.canvas.showPopover();
66
+ }
67
+ catch {
68
+ }
69
+ }
70
+ return stage;
71
+ }
72
+ const canvas = document.createElement('canvas');
73
+ const context = canvas.getContext('2d');
74
+ if (!context) {
75
+ return undefined;
76
+ }
77
+ canvas.setAttribute('aria-hidden', 'true');
78
+ canvas.style.cssText =
79
+ 'position:fixed;inset:0;display:block;width:100%;height:100%;max-width:none;max-height:none;margin:0;padding:0;border:0;overflow:visible;background:transparent;pointer-events:none;z-index:2147483647';
80
+ const popover = typeof canvas.showPopover === 'function';
81
+ if (popover) {
82
+ canvas.setAttribute('popover', 'manual');
83
+ }
84
+ document.body.append(canvas);
85
+ if (popover) {
86
+ try {
87
+ canvas.showPopover();
88
+ }
89
+ catch {
90
+ }
91
+ }
92
+ stage = { canvas, context, height: 0, last: undefined, pieces: [], ratio: 0, width: 0 };
93
+ fit(stage);
94
+ return stage;
95
+ };
96
+ const closeStage = () => {
97
+ const open = stage;
98
+ if (!open) {
99
+ return;
100
+ }
101
+ stage = undefined;
102
+ open.canvas.remove();
103
+ for (const piece of open.pieces) {
104
+ piece.burst.done();
105
+ }
106
+ open.pieces = [];
107
+ };
108
+ const advance = (piece, dt) => {
109
+ piece.age += dt;
110
+ if (piece.age < piece.delay) {
111
+ return;
112
+ }
113
+ const slowed = Math.exp(-piece.drag * dt);
114
+ piece.vx *= slowed;
115
+ piece.vy = piece.vy * slowed + (GRAVITY / piece.drag) * (1 - slowed);
116
+ piece.x += piece.vx * dt;
117
+ piece.y += piece.vy * dt;
118
+ piece.angle += piece.spin * dt;
119
+ piece.flip += piece.flipRate * dt;
120
+ piece.wobble += piece.wobbleRate * dt;
121
+ };
122
+ const draw = (open, piece) => {
123
+ const flown = piece.age - piece.delay;
124
+ if (flown < 0) {
125
+ return;
126
+ }
127
+ const { context, ratio } = open;
128
+ const left = 1 - flown / piece.life;
129
+ context.globalAlpha = left > 0.35 ? 1 : (left / 0.35) ** 1.5;
130
+ const turned = Math.cos(piece.flip);
131
+ const across = Math.sign(turned || 1) * Math.max(Math.abs(turned), 0.08);
132
+ context.fillStyle = turned >= 0 ? piece.front : piece.back;
133
+ const x = piece.x + Math.sin(piece.wobble) * piece.sway * Math.min(1, flown / 0.4);
134
+ const cos = Math.cos(piece.angle);
135
+ const sin = Math.sin(piece.angle);
136
+ context.setTransform(ratio * cos, ratio * sin, -ratio * sin * across, ratio * cos * across, ratio * x, ratio * piece.y);
137
+ if (piece.round) {
138
+ context.beginPath();
139
+ context.arc(0, 0, piece.width / 2, 0, Math.PI * 2);
140
+ context.fill();
141
+ }
142
+ else {
143
+ context.fillRect(-piece.width / 2, -piece.height / 2, piece.width, piece.height);
144
+ }
145
+ };
146
+ const tick = (now) => {
147
+ const open = stage;
148
+ if (!open) {
149
+ return;
150
+ }
151
+ if (motionPaused()) {
152
+ closeStage();
153
+ return;
154
+ }
155
+ const dt = open.last === undefined ? 1 / 60 : Math.min(Math.max(now - open.last, 0) / 1000, 1 / 30);
156
+ open.last = now;
157
+ fit(open);
158
+ const { canvas, context } = open;
159
+ context.setTransform(1, 0, 0, 1, 0, 0);
160
+ context.clearRect(0, 0, canvas.width, canvas.height);
161
+ let kept = 0;
162
+ for (const piece of open.pieces) {
163
+ advance(piece, dt);
164
+ if (piece.age >= piece.delay + piece.life) {
165
+ piece.burst.left -= 1;
166
+ if (piece.burst.left === 0) {
167
+ piece.burst.done();
168
+ }
169
+ continue;
170
+ }
171
+ draw(open, piece);
172
+ open.pieces[kept] = piece;
173
+ kept += 1;
174
+ }
175
+ open.pieces.length = kept;
176
+ context.globalAlpha = 1;
177
+ if (kept === 0) {
178
+ closeStage();
179
+ return;
180
+ }
181
+ requestAnimationFrame(tick);
182
+ };
183
+ const makePieces = (box, count, colors, burst) => {
184
+ const centerX = box.left + box.width / 2;
185
+ const centerY = box.top + box.height * 0.3;
186
+ const spreadX = Math.min(box.width, 160) * 0.3;
187
+ const spreadY = Math.min(box.height, 48) * 0.15;
188
+ const cone = 0.88;
189
+ const offset = Math.floor(Math.random() * colors.length);
190
+ const pieces = [];
191
+ for (let index = 0; index < count; index++) {
192
+ const lean = between(-1, 1);
193
+ const heading = -Math.PI / 2 + lean * cone;
194
+ const speed = between(680, 1150) * (1 - 0.22 * Math.abs(lean));
195
+ const round = Math.random() < 0.2;
196
+ const width = round ? between(4.5, 6.5) : between(6, 10);
197
+ const [front, back] = colors[(index + offset) % colors.length] ?? ['gray', 'gray'];
198
+ pieces.push({
199
+ age: 0,
200
+ angle: between(0, Math.PI * 2),
201
+ back,
202
+ burst,
203
+ delay: between(0, 0.08),
204
+ drag: between(2.7, 3.7),
205
+ flip: between(0, Math.PI * 2),
206
+ flipRate: between(7, 15) * (Math.random() < 0.5 ? -1 : 1),
207
+ front,
208
+ height: round ? width : between(3.5, 5.5),
209
+ life: between(1.1, 1.45),
210
+ round,
211
+ spin: between(1, 5) * (Math.random() < 0.5 ? -1 : 1),
212
+ sway: between(3, 9),
213
+ vx: Math.cos(heading) * speed,
214
+ vy: Math.sin(heading) * speed,
215
+ width,
216
+ wobble: between(0, Math.PI * 2),
217
+ wobbleRate: between(5, 10),
218
+ x: centerX + between(-1, 1) * spreadX,
219
+ y: centerY + between(-1, 1) * spreadY,
220
+ });
221
+ }
222
+ return pieces;
223
+ };
224
+ export const burstConfetti = (origin, options = {}) => new Promise((resolve) => {
225
+ if (typeof document === 'undefined' ||
226
+ document.hidden ||
227
+ !origin.isConnected ||
228
+ reducedMotion() ||
229
+ motionPaused()) {
230
+ resolve();
231
+ return;
232
+ }
233
+ const asked = Math.round(options.count ?? COUNT);
234
+ const count = Number.isFinite(asked) ? Math.min(Math.max(asked, 0), MOST) : COUNT;
235
+ if (count === 0) {
236
+ resolve();
237
+ return;
238
+ }
239
+ const colors = readFaces(origin, options.colors);
240
+ const open = openStage();
241
+ if (!open) {
242
+ resolve();
243
+ return;
244
+ }
245
+ const burst = { done: resolve, left: count };
246
+ open.pieces.push(...makePieces(origin.getBoundingClientRect(), count, colors, burst));
247
+ if (open.pieces.length === count) {
248
+ open.last = undefined;
249
+ requestAnimationFrame(tick);
250
+ }
251
+ });
@@ -14,9 +14,16 @@ import { type TemplateResult } from 'lit';
14
14
  * their own, so each family writes its own custom property there, such as
15
15
  * `--line-chart-axis` in `ch`, and a stylesheet sizes the column from it.
16
16
  *
17
+ * **A number that stays on a new scale is the same tick**, keyed by its value,
18
+ * so a stylesheet moves it to its new level. Given `before`, the numbers that
19
+ * scale had and this one does not stay too, as `tick-leaving` beside `tick`,
20
+ * `hidden`, and at their place on the new scale held inside the plot, so a
21
+ * stylesheet can fade them out as they move.
22
+ *
17
23
  * @param domain The scale's lowest and highest values.
18
24
  * @param place Where a value sits down the plot, from 0 at the top to 100 at the bottom.
19
25
  * @param format How a value is written, such as a number in the chart's locale.
20
26
  * @param width The style the axis carries, from the number of characters in its widest number.
27
+ * @param before The scale drawn before this one, which `ScaleMemory` holds.
21
28
  */
22
- export declare const drawValueAxis: (domain: readonly [number, number], place: (value: number) => number, format: (value: number) => string, width: (widest: number) => string) => TemplateResult;
29
+ export declare const drawValueAxis: (domain: readonly [number, number], place: (value: number) => number, format: (value: number) => string, width: (widest: number) => string, before?: readonly [number, number]) => TemplateResult;
@@ -1,9 +1,15 @@
1
1
  import { html } from 'lit';
2
- import { ticks } from '../scale/ticks.js';
3
- export const drawValueAxis = (domain, place, format, width) => {
4
- const levels = ticks(domain);
5
- const widest = Math.max(1, ...levels.map((level) => format(level).length));
2
+ import { repeat } from 'lit/directives/repeat.js';
3
+ import { heldInside, levelsOf } from '../scale/levels.js';
4
+ export const drawValueAxis = (domain, place, format, width, before) => {
5
+ const levels = levelsOf(domain, before);
6
+ const widest = Math.max(1, ...levels.filter((one) => !one.leaving).map((one) => format(one.level).length));
6
7
  return html `<div aria-hidden="true" part="axis" style=${width(widest)}>
7
- ${levels.map((level) => html `<span part="tick" style=${`inset-block-start: ${place(level)}%`}>${format(level)}</span>`)}
8
+ ${repeat(levels, (one) => one.level, ({ leaving, level }) => html `<span
9
+ ?hidden=${leaving}
10
+ part="tick${leaving ? ' tick-leaving' : ''}"
11
+ style=${`inset-block-start: ${leaving ? heldInside(place(level)) : place(level)}%`}
12
+ >${format(level)}</span
13
+ >`)}
8
14
  </div>`;
9
15
  };
@@ -0,0 +1,55 @@
1
+ /** How `flashChange` lights an element. */
2
+ export interface FlashChangeOptions {
3
+ /**
4
+ * The wash at its strongest: a color, or a custom property that holds one.
5
+ * Defaults to `--helix-color-info` at 14 percent in light mode and 22 in
6
+ * dark. A translucent color lets the element's own background show through
7
+ * it; an opaque one covers it until it fades.
8
+ */
9
+ color?: string | undefined;
10
+ /**
11
+ * How long the wash takes to fade, evenly, once it has held: milliseconds,
12
+ * a time such as `640ms`, or a custom property. Defaults to twice
13
+ * `--helix-duration-slow`. `0` takes the wash off at once.
14
+ */
15
+ duration?: number | string | undefined;
16
+ /**
17
+ * How long the wash holds at its strongest before it fades: milliseconds, a
18
+ * time, or a custom property. Defaults to `--helix-duration-slow`.
19
+ */
20
+ hold?: number | string | undefined;
21
+ }
22
+ /**
23
+ * Lights an element up with a quiet wash and fades it out, so you see what
24
+ * changed when live data or an agent changes it, and resolves once the wash is
25
+ * gone.
26
+ *
27
+ * ```js
28
+ * import { flashChange } from '@fusion.dev/helix-core'
29
+ *
30
+ * cell.textContent = '1,284'
31
+ * flashChange(cell)
32
+ * ```
33
+ *
34
+ * **The wash is drawn over the element's background and under its content**,
35
+ * as an inset shadow added to the element's own shadows, so nothing moves and
36
+ * the element's own background, shadows, and focus ring are as they were once
37
+ * it ends. It works on a line of text that wraps, on a table cell, and on a
38
+ * row: a row that draws no box of its own, such as a `<tr>` or a
39
+ * `display: contents` row, is washed through its cells.
40
+ *
41
+ * **A second flash on the same element starts from the strength drawn**, rises
42
+ * back to full over `--helix-duration-fast`, and holds and fades again, so a
43
+ * value that keeps changing stays lit and never doubles up. The first call
44
+ * resolves then.
45
+ *
46
+ * **Under reduced motion the wash still shows**, since it shows what changed:
47
+ * it holds at full strength, with no rise, and goes over
48
+ * `--helix-duration-fade`, the crossfade Helix keeps for that setting. The
49
+ * hold keeps its usual length there, though the stylesheet shortens
50
+ * `--helix-duration-slow` to almost nothing.
51
+ *
52
+ * Announce the change some other way as well, such as in a live region, for a
53
+ * reader who does not see the wash.
54
+ */
55
+ export declare const flashChange: (element: Element, options?: FlashChangeOptions) => Promise<void>;