@zealakit/chrono-react 1.0.0-beta.1 → 1.0.0-beta.2

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 (163) hide show
  1. package/README.md +1 -0
  2. package/dist/calendar/components.d.ts +2 -2
  3. package/dist/calendar/components.js +10 -12
  4. package/dist/calendar/mini-calendar.js +6 -5
  5. package/dist/calendar/use-calendar.js +1 -3
  6. package/dist/calendar/use-mini-calendar.js +1 -1
  7. package/dist/date/bind-panel.js +1 -1
  8. package/dist/date/components.js +20 -29
  9. package/dist/date/utilities.d.ts +1 -1
  10. package/dist/date/utilities.js +1 -1
  11. package/dist/datetime/components.js +16 -21
  12. package/dist/datetime/use-datetime-panel.js +1 -1
  13. package/dist/shared/defined-options.d.ts +18 -0
  14. package/dist/shared/defined-options.js +9 -0
  15. package/dist/shared/merge-props.js +1 -3
  16. package/dist/shared/part.d.ts +1 -1
  17. package/dist/shared/slot.js +1 -4
  18. package/dist/shared/style-properties.js +1 -1
  19. package/dist/time/bind-panel.js +2 -2
  20. package/dist/time/components.d.ts +2 -2
  21. package/dist/time/components.js +16 -21
  22. package/dist/time/utilities.d.ts +1 -1
  23. package/dist/time/utilities.js +1 -1
  24. package/dist/vendor/core/calendar/availability.d.ts +2 -2
  25. package/dist/vendor/core/calendar/availability.js +4 -5
  26. package/dist/vendor/core/calendar/controllers/calendar-controller.js +93 -145
  27. package/dist/vendor/core/calendar/controllers/drag-engine.js +15 -34
  28. package/dist/vendor/core/calendar/controllers/mini-calendar-controller.js +3 -2
  29. package/dist/vendor/core/calendar/controllers/shared.d.ts +9 -5
  30. package/dist/vendor/core/calendar/controllers/shared.js +8 -8
  31. package/dist/vendor/core/calendar/events/agenda-layout.js +4 -3
  32. package/dist/vendor/core/calendar/events/all-day-row.d.ts +1 -1
  33. package/dist/vendor/core/calendar/events/all-day-row.js +5 -5
  34. package/dist/vendor/core/calendar/events/background-layout.d.ts +1 -1
  35. package/dist/vendor/core/calendar/events/background-layout.js +6 -7
  36. package/dist/vendor/core/calendar/events/month-layout.js +6 -5
  37. package/dist/vendor/core/calendar/events/normalize.d.ts +2 -2
  38. package/dist/vendor/core/calendar/events/normalize.js +6 -9
  39. package/dist/vendor/core/calendar/events/now-indicator.d.ts +2 -2
  40. package/dist/vendor/core/calendar/events/time-grid-layout.d.ts +4 -4
  41. package/dist/vendor/core/calendar/events/time-grid-layout.js +8 -15
  42. package/dist/vendor/core/calendar/events/types.d.ts +2 -2
  43. package/dist/vendor/core/calendar/index.d.ts +11 -11
  44. package/dist/vendor/core/calendar/index.js +5 -5
  45. package/dist/vendor/core/calendar/interaction/auto-scroll.d.ts +1 -9
  46. package/dist/vendor/core/calendar/interaction/auto-scroll.js +12 -39
  47. package/dist/vendor/core/calendar/interaction/drag-geometry.js +2 -5
  48. package/dist/vendor/core/calendar/interaction/drag-keyboard.js +1 -4
  49. package/dist/vendor/core/calendar/interaction/drag-pointer.d.ts +5 -4
  50. package/dist/vendor/core/calendar/interaction/drag-pointer.js +33 -193
  51. package/dist/vendor/core/calendar/interaction/gesture-handle.d.ts +17 -0
  52. package/dist/vendor/core/calendar/interaction/gesture-handle.js +26 -0
  53. package/dist/vendor/core/calendar/interaction/pointer.d.ts +1 -1
  54. package/dist/vendor/core/calendar/interaction/pointer.js +65 -15
  55. package/dist/vendor/core/calendar/interaction/selection.d.ts +1 -1
  56. package/dist/vendor/core/calendar/navigation/navigate.d.ts +3 -3
  57. package/dist/vendor/core/calendar/navigation/navigate.js +1 -3
  58. package/dist/vendor/core/calendar/navigation/range.js +1 -1
  59. package/dist/vendor/core/calendar/navigation/view-definition.d.ts +1 -1
  60. package/dist/vendor/core/calendar/navigation/view-definition.js +2 -1
  61. package/dist/vendor/core/calendar/recurrence/apply.js +7 -8
  62. package/dist/vendor/core/calendar/recurrence/expand.d.ts +1 -1
  63. package/dist/vendor/core/calendar/recurrence/expand.js +14 -18
  64. package/dist/vendor/core/calendar/recurrence/pack.js +4 -7
  65. package/dist/vendor/core/calendar/recurrence/rrule.js +6 -16
  66. package/dist/vendor/core/calendar/recurrence/series.js +1 -3
  67. package/dist/vendor/core/calendar/recurrence/types.d.ts +1 -1
  68. package/dist/vendor/core/calendar/resources/resource-time-grid.js +1 -2
  69. package/dist/vendor/core/calendar/resources/timeline-layout.js +4 -6
  70. package/dist/vendor/core/calendar/resources/types.d.ts +7 -7
  71. package/dist/vendor/core/calendar/views/day.d.ts +5 -5
  72. package/dist/vendor/core/calendar/views/day.js +2 -5
  73. package/dist/vendor/core/calendar/views/mini-calendar.d.ts +8 -8
  74. package/dist/vendor/core/calendar/views/mini-calendar.js +1 -1
  75. package/dist/vendor/core/calendar/views/month-layout.d.ts +1 -1
  76. package/dist/vendor/core/calendar/views/month-layout.js +1 -1
  77. package/dist/vendor/core/calendar/views/time-grid-layout.js +1 -4
  78. package/dist/vendor/core/date/input/date-input-controller.d.ts +15 -15
  79. package/dist/vendor/core/date/input/date-input-controller.js +9 -21
  80. package/dist/vendor/core/date/input/date-range-input-controller.js +2 -5
  81. package/dist/vendor/core/date/input/parse.d.ts +2 -2
  82. package/dist/vendor/core/date/input/parse.js +3 -9
  83. package/dist/vendor/core/date/input/validity.js +1 -1
  84. package/dist/vendor/core/date/panel/panel-controller.d.ts +11 -11
  85. package/dist/vendor/core/date/panel/panel-controller.js +18 -40
  86. package/dist/vendor/core/date/presets.js +1 -2
  87. package/dist/vendor/core/date/selection/multiple.js +2 -5
  88. package/dist/vendor/core/date/selection/range.d.ts +2 -2
  89. package/dist/vendor/core/date/selection/range.js +2 -6
  90. package/dist/vendor/core/datetime/compose.d.ts +3 -3
  91. package/dist/vendor/core/datetime/constraints.d.ts +9 -9
  92. package/dist/vendor/core/datetime/input/datetime-input-controller.d.ts +2 -2
  93. package/dist/vendor/core/datetime/input/datetime-input-controller.js +12 -27
  94. package/dist/vendor/core/datetime/input/datetime-range-input-controller.js +5 -16
  95. package/dist/vendor/core/datetime/input/parse.d.ts +2 -2
  96. package/dist/vendor/core/datetime/input/parse.js +2 -5
  97. package/dist/vendor/core/datetime/panel/controller.js +4 -10
  98. package/dist/vendor/core/datetime/panel/range-controller.js +4 -16
  99. package/dist/vendor/core/datetime/zone/day-instants.js +1 -3
  100. package/dist/vendor/core/datetime/zone/resolve.js +2 -4
  101. package/dist/vendor/core/dom/auto-scroll.d.ts +37 -0
  102. package/dist/vendor/core/dom/auto-scroll.js +57 -0
  103. package/dist/vendor/core/dom/drag-session.d.ts +25 -0
  104. package/dist/vendor/core/dom/drag-session.js +257 -0
  105. package/dist/vendor/core/foundation/a11y/announcer.d.ts +9 -4
  106. package/dist/vendor/core/foundation/a11y/announcer.js +15 -27
  107. package/dist/vendor/core/foundation/a11y/grid-navigation.d.ts +2 -2
  108. package/dist/vendor/core/foundation/a11y/grid-navigation.js +2 -12
  109. package/dist/vendor/core/foundation/a11y/roving-focus.js +23 -2
  110. package/dist/vendor/core/foundation/constraints/availability-rules.js +2 -4
  111. package/dist/vendor/core/foundation/constraints/availability.d.ts +6 -6
  112. package/dist/vendor/core/foundation/constraints/availability.js +6 -16
  113. package/dist/vendor/core/foundation/constraints/date.d.ts +3 -3
  114. package/dist/vendor/core/foundation/constraints/index.d.ts +1 -1
  115. package/dist/vendor/core/foundation/constraints/range.d.ts +4 -4
  116. package/dist/vendor/core/foundation/constraints/range.js +1 -1
  117. package/dist/vendor/core/foundation/constraints/time.d.ts +5 -5
  118. package/dist/vendor/core/foundation/constraints/time.js +1 -1
  119. package/dist/vendor/core/foundation/grid/index.d.ts +2 -2
  120. package/dist/vendor/core/foundation/grid/month-grid.d.ts +2 -2
  121. package/dist/vendor/core/foundation/grid/time-axis.d.ts +3 -3
  122. package/dist/vendor/core/foundation/grid/time-axis.js +1 -1
  123. package/dist/vendor/core/foundation/input/index.d.ts +1 -1
  124. package/dist/vendor/core/foundation/input/index.js +1 -1
  125. package/dist/vendor/core/foundation/input/segment-engine.js +2 -6
  126. package/dist/vendor/core/foundation/locale/direction.js +1 -13
  127. package/dist/vendor/core/foundation/locale/format.js +1 -3
  128. package/dist/vendor/core/foundation/locale/hour-cycle.js +2 -6
  129. package/dist/vendor/core/foundation/locale/index.d.ts +1 -1
  130. package/dist/vendor/core/foundation/locale/index.js +1 -1
  131. package/dist/vendor/core/foundation/locale/resolve.js +12 -2
  132. package/dist/vendor/core/foundation/locale/week-info.js +1 -2
  133. package/dist/vendor/core/foundation/ranges/index.d.ts +1 -1
  134. package/dist/vendor/core/foundation/ranges/index.js +1 -1
  135. package/dist/vendor/core/foundation/ranges/interval.js +1 -3
  136. package/dist/vendor/core/foundation/store/controllable.d.ts +1 -1
  137. package/dist/vendor/core/foundation/store/ids.d.ts +8 -1
  138. package/dist/vendor/core/foundation/store/ids.js +10 -5
  139. package/dist/vendor/core/foundation/store/index.d.ts +2 -2
  140. package/dist/vendor/core/foundation/store/index.js +2 -2
  141. package/dist/vendor/core/foundation/store/with-optional.d.ts +15 -0
  142. package/dist/vendor/core/foundation/store/with-optional.js +3 -0
  143. package/dist/vendor/core/foundation/values/convert.js +3 -7
  144. package/dist/vendor/core/foundation/values/epoch-day.js +1 -5
  145. package/dist/vendor/core/foundation/values/index.d.ts +1 -1
  146. package/dist/vendor/core/foundation/values/index.js +1 -1
  147. package/dist/vendor/core/foundation/values/iso.js +2 -4
  148. package/dist/vendor/core/foundation/values/plain-time.js +1 -3
  149. package/dist/vendor/core/foundation/values/zoned.js +2 -5
  150. package/dist/vendor/core/time/input/parse.d.ts +1 -1
  151. package/dist/vendor/core/time/input/parse.js +1 -3
  152. package/dist/vendor/core/time/input/time-input-controller.d.ts +18 -18
  153. package/dist/vendor/core/time/input/time-input-controller.js +12 -27
  154. package/dist/vendor/core/time/input/time-range-input-controller.js +3 -10
  155. package/dist/vendor/core/time/input/validity.js +1 -1
  156. package/dist/vendor/core/time/panel/time-panel-controller.d.ts +12 -12
  157. package/dist/vendor/core/time/panel/time-panel-controller.js +19 -49
  158. package/dist/vendor/core/time/selection/range.d.ts +3 -3
  159. package/dist/vendor/core/time/selection/slots.d.ts +9 -9
  160. package/dist/vendor/core/time/selection/slots.js +1 -3
  161. package/package.json +21 -28
  162. package/dist/vendor/core/foundation/store/global-state.d.ts +0 -1
  163. package/dist/vendor/core/foundation/store/global-state.js +0 -21
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Candidate A.4 `auto-scroll` — private `src/dom/` module (D35, plan 08-2 Step 4).
3
+ *
4
+ * Edge auto-scroll maths for any pointer drag: speed by distance, the nearest
5
+ * scrollable ancestor, and the per-frame scroll deltas. **Stateless**: it owns
6
+ * no loop, no listener and no timer — the drag session that owns the single
7
+ * frame loop applies `autoScrollStep` in it (NP9). The calendar layer passes
8
+ * the container it already resolved; datagrid will be the 2nd consumer
9
+ * (plan 10).
10
+ *
11
+ * No Chrono types and no DOM access at import time.
12
+ */
13
+ const hasFrames = typeof requestAnimationFrame === "function";
14
+ /** Schedule one frame (rAF, or a 16 ms timer where rAF is unavailable). */
15
+ export const scheduleFrame = (callback) => hasFrames ? requestAnimationFrame(callback) : setTimeout(callback, 16);
16
+ /** Cancel a frame scheduled by {@link scheduleFrame}. */
17
+ export const cancelFrame = (handle) => hasFrames
18
+ ? cancelAnimationFrame(handle)
19
+ : clearTimeout(handle);
20
+ /** `speed(d) = d >= 40 ? 0 : round(20 · (1 − d / 40))` pixels per frame. */
21
+ export function autoScrollSpeed(distance) {
22
+ const d = Math.max(0, distance);
23
+ return d >= 40 ? 0 : Math.round(20 * (1 - d / 40));
24
+ }
25
+ /** The nearest scrollable ancestor of `element`, or `null`. */
26
+ export function scrollParent(element) {
27
+ let node = element?.parentElement ?? null;
28
+ while (node) {
29
+ const style = getComputedStyle(node);
30
+ if (/(auto|scroll)/.test(`${style.overflowY} ${style.overflowX}`)) {
31
+ return node;
32
+ }
33
+ node = node.parentElement;
34
+ }
35
+ return null;
36
+ }
37
+ /**
38
+ * The scroll deltas for this pointer position, read from the container's rect.
39
+ * The caller writes them (`scrollLeft`/`scrollTop`) in its own frame loop.
40
+ */
41
+ export function autoScrollStep(container, point) {
42
+ if (!container) {
43
+ return { x: 0, y: 0 };
44
+ }
45
+ const rect = container.getBoundingClientRect();
46
+ const y = autoScrollSpeed(point.y - rect.top) * -1 + autoScrollSpeed(rect.bottom - point.y);
47
+ const x = autoScrollSpeed(point.x - rect.left) * -1 + autoScrollSpeed(rect.right - point.x);
48
+ return { x, y };
49
+ }
50
+ /** Scroll `container` one step toward `point`; the caller owns the frame loop. */
51
+ export function applyAutoScroll(container, point) {
52
+ const delta = autoScrollStep(container, point);
53
+ if (delta.x !== 0 || delta.y !== 0) {
54
+ container.scrollLeft += delta.x;
55
+ container.scrollTop += delta.y;
56
+ }
57
+ }
@@ -0,0 +1,25 @@
1
+ /** A pointer position in client coordinates. */
2
+ export type DragPoint = {
3
+ x: number;
4
+ y: number;
5
+ };
6
+ export type DragSessionOptions<TPress, THit = TPress> = {
7
+ root: HTMLElement;
8
+ /** Free-form gesture kind, e.g. `"chrono-calendar-drag"`. */
9
+ gestureKind: string;
10
+ /** Candidate for a press; return `null` to ignore it (not draggable). */
11
+ press: (event: PointerEvent) => TPress | null;
12
+ /** Whether a pointer position hits a drag target (used by begin and move). */
13
+ hitTest: (point: DragPoint) => THit | null;
14
+ /** Start the drag; return `false` to refuse it (the claim is released). */
15
+ begin: (pressed: TPress, hit: THit | null, point: DragPoint) => boolean;
16
+ update: (hit: THit) => void;
17
+ drop: () => void;
18
+ cancel: () => void;
19
+ /** Scroll container for auto-scroll; `false` turns it off. */
20
+ scroll?: (() => HTMLElement | null | false) | undefined;
21
+ };
22
+ export type DragSession = {
23
+ destroy(): void;
24
+ };
25
+ export declare function createDragSession<TPress, THit = TPress>(options: DragSessionOptions<TPress, THit>): DragSession;
@@ -0,0 +1,257 @@
1
+ /**
2
+ * Candidate A.4 `drag-session` — private `src/dom/` module (D35, plan 08-2 Step 4).
3
+ *
4
+ * The generic pointer-drag mechanics: primary button only, a pixel threshold for
5
+ * mouse, a long press for touch, pointer capture **after** the engine gesture
6
+ * claim (E23), the engine gesture claim itself (§13.2), a temporary engine layer
7
+ * so Escape cancels the drag before any popover below it (§4, Step 3), one frame
8
+ * loop shared by move and edge auto-scroll (NP9), click suppression after a
9
+ * drag, the engine cursor/user-select interaction lock (§13.7), and idempotent
10
+ * cleanup.
11
+ *
12
+ * Calendar rules (what a drag means, snapping, proposals) stay in
13
+ * `calendar/interaction/drag-pointer.ts`; datagrid is the 2nd consumer
14
+ * (plan 10). No Chrono types are imported here: the calendar passes callbacks.
15
+ *
16
+ * The app or component must set `touch-action: none` on the drag handle before
17
+ * `pointerdown`: pointer events only report a touch drag while the browser does
18
+ * not scroll, so the component owns that CSS expectation. As a fallback,
19
+ * `touchmove` is prevented while a touch drag runs. No styles are injected.
20
+ */
21
+ import { createLayer } from "@zealakit/ui-engine";
22
+ import { acquireInteractionLock, claimGesture, } from "@zealakit/ui-engine/internal";
23
+ import { applyAutoScroll, cancelFrame, scheduleFrame, scrollParent } from "./auto-scroll.js";
24
+ /** Mouse movement that starts a drag. */
25
+ const THRESHOLD = 4;
26
+ /** Touch movement that turns a pending long press into a scroll. */
27
+ const TOUCH_SLOP = 8;
28
+ /** Touch long-press delay. */
29
+ const LONG_PRESS_MS = 400;
30
+ export function createDragSession(options) {
31
+ const { root, gestureKind, press, hitTest, begin: beginDrag, update, drop, cancel, scroll, } = options;
32
+ let pressed = null;
33
+ let dragging = false;
34
+ let longPress;
35
+ let pendingFrame = 0;
36
+ let lastPoint;
37
+ let pendingMove;
38
+ let claim = null;
39
+ let layer = null;
40
+ let lock = null;
41
+ let swallowClick = false;
42
+ const finish = () => {
43
+ clearTimeout(longPress);
44
+ longPress = undefined;
45
+ cancelFrame(pendingFrame);
46
+ pendingFrame = 0;
47
+ listen(false);
48
+ if (pressed) {
49
+ try {
50
+ pressed.element.releasePointerCapture?.(pressed.id);
51
+ }
52
+ catch {
53
+ // The pointer may already be gone.
54
+ }
55
+ }
56
+ lock?.release();
57
+ lock = null;
58
+ layer?.release();
59
+ layer = null;
60
+ claim?.release();
61
+ claim = null;
62
+ pressed = null;
63
+ dragging = false;
64
+ lastPoint = undefined;
65
+ };
66
+ const frameTick = () => {
67
+ pendingFrame = 0;
68
+ if (!dragging) {
69
+ return;
70
+ }
71
+ if (pendingMove) {
72
+ const hit = hitTest(pendingMove);
73
+ pendingMove = undefined;
74
+ if (hit) {
75
+ update(hit);
76
+ }
77
+ }
78
+ // No auto-scroll until the pointer has moved: a long press near an edge waits.
79
+ if (lastPoint) {
80
+ const configured = scroll?.();
81
+ const node = configured === false ? null : (configured ?? scrollParent(root));
82
+ if (node) {
83
+ applyAutoScroll(node, lastPoint);
84
+ }
85
+ }
86
+ pendingFrame = scheduleFrame(frameTick);
87
+ };
88
+ const abort = () => {
89
+ cancel();
90
+ finish();
91
+ };
92
+ const begin = () => {
93
+ if (!pressed || dragging) {
94
+ return false;
95
+ }
96
+ // §13.2: the first claimant wins; a null claim means another part of the
97
+ // page owns the gesture, so we neither capture nor start.
98
+ claim = claimGesture({
99
+ element: root,
100
+ kind: gestureKind,
101
+ pointerId: pressed.id,
102
+ cancel: abort,
103
+ });
104
+ if (!claim) {
105
+ return false;
106
+ }
107
+ // E23: capture only after the claim is ours.
108
+ try {
109
+ pressed.element.setPointerCapture?.(pressed.id);
110
+ }
111
+ catch {
112
+ // setPointerCapture throws for inactive pointers.
113
+ }
114
+ const point = { x: pressed.x, y: pressed.y };
115
+ const hit = hitTest(point);
116
+ if (!beginDrag(pressed.target, hit, point)) {
117
+ return false; // every caller then calls `finish()`, which releases the claim
118
+ }
119
+ dragging = true;
120
+ // §4 recipe: a drag is a temporary layer. Escape cancels the drag before
121
+ // any popover under it closes; outside presses never end a drag (E6).
122
+ layer = createLayer({
123
+ element: root,
124
+ dismiss: { escapeKey: true, outsidePress: false },
125
+ onDismiss: abort,
126
+ });
127
+ listen(true);
128
+ // §13.7: owned by the claim, so cancelling or pruning it unlocks the page.
129
+ lock = acquireInteractionLock({ gestureId: claim.id });
130
+ // NP9: the single loop drives both the drag updates and auto-scroll.
131
+ pendingFrame = scheduleFrame(frameTick);
132
+ return true;
133
+ };
134
+ // A root removed without `destroy()` never gets its own `pointerup`.
135
+ function onLostPointer(event) {
136
+ if (!root.isConnected) {
137
+ onCancel(event);
138
+ }
139
+ }
140
+ function onTouchMove(event) {
141
+ event.preventDefault();
142
+ }
143
+ /** E26: a native drag cannot run inside a pointer session. */
144
+ function onDragStart(event) {
145
+ event.preventDefault();
146
+ abort();
147
+ }
148
+ /** The listeners that exist only while a drag runs. */
149
+ function listen(on) {
150
+ const method = on ? "addEventListener" : "removeEventListener";
151
+ root[method]("dragstart", onDragStart);
152
+ window[method]("blur", abort);
153
+ window[method]("pointerup", onLostPointer);
154
+ window[method]("pointercancel", onLostPointer);
155
+ if (pressed?.touch) {
156
+ document[method]("touchmove", onTouchMove, { passive: false });
157
+ }
158
+ }
159
+ const onDown = (event) => {
160
+ if (event.button !== 0 || pressed) {
161
+ return;
162
+ }
163
+ const target = press(event);
164
+ if (target === null) {
165
+ return;
166
+ }
167
+ pressed = {
168
+ target,
169
+ x: event.clientX,
170
+ y: event.clientY,
171
+ id: event.pointerId,
172
+ touch: event.pointerType === "touch",
173
+ element: event.target,
174
+ };
175
+ if (pressed.touch) {
176
+ longPress = setTimeout(() => {
177
+ longPress = undefined;
178
+ if (!begin()) {
179
+ finish();
180
+ }
181
+ }, LONG_PRESS_MS);
182
+ }
183
+ };
184
+ const onMove = (event) => {
185
+ if (!pressed || event.pointerId !== pressed.id) {
186
+ return;
187
+ }
188
+ if (!dragging) {
189
+ const slop = pressed.touch ? TOUCH_SLOP : THRESHOLD;
190
+ const far = Math.abs(event.clientX - pressed.x) > slop || Math.abs(event.clientY - pressed.y) > slop;
191
+ if (pressed.touch) {
192
+ if (far && longPress !== undefined) {
193
+ finish(); // the finger scrolled: no drag
194
+ }
195
+ return;
196
+ }
197
+ if (!far) {
198
+ return;
199
+ }
200
+ if (!begin()) {
201
+ finish();
202
+ return;
203
+ }
204
+ }
205
+ // NP9: pointermove only stores the latest event; the frame loop applies it.
206
+ lastPoint = { x: event.clientX, y: event.clientY };
207
+ pendingMove = lastPoint;
208
+ if (pendingFrame === 0) {
209
+ pendingFrame = scheduleFrame(frameTick);
210
+ }
211
+ };
212
+ const onUp = (event) => {
213
+ if (!pressed || event.pointerId !== pressed.id) {
214
+ return;
215
+ }
216
+ if (dragging) {
217
+ swallowClick = true;
218
+ drop();
219
+ }
220
+ finish();
221
+ };
222
+ const onCancel = (event) => {
223
+ if (!pressed || event.pointerId !== pressed.id) {
224
+ return;
225
+ }
226
+ if (dragging) {
227
+ cancel();
228
+ }
229
+ finish();
230
+ };
231
+ /** The click after a real drag must not select or activate the target. */
232
+ const onClick = (event) => {
233
+ if (swallowClick) {
234
+ swallowClick = false;
235
+ event.stopPropagation();
236
+ event.preventDefault();
237
+ }
238
+ };
239
+ root.addEventListener("pointerdown", onDown);
240
+ root.addEventListener("pointermove", onMove);
241
+ root.addEventListener("pointerup", onUp);
242
+ root.addEventListener("pointercancel", onCancel);
243
+ root.addEventListener("click", onClick, true);
244
+ return {
245
+ destroy() {
246
+ if (dragging) {
247
+ cancel();
248
+ }
249
+ finish();
250
+ root.removeEventListener("pointerdown", onDown);
251
+ root.removeEventListener("pointermove", onMove);
252
+ root.removeEventListener("pointerup", onUp);
253
+ root.removeEventListener("pointercancel", onCancel);
254
+ root.removeEventListener("click", onClick, true);
255
+ },
256
+ };
257
+ }
@@ -1,7 +1,12 @@
1
1
  /**
2
- * Announce `message` through a polite live region. The region is created
3
- * lazily and shared by every copy of core on the page; the app can pass its
4
- * own element, or `false` to disable announcements. A no-op outside the
5
- * browser.
2
+ * Announce `message` through a polite live region.
3
+ *
4
+ * Without an element, the engine owns the page-wide live region (created
5
+ * lazily, shared by every engine copy, cleared after 7 s). Passing an app
6
+ * element keeps Chrono's old escape hatch and writes to that element directly;
7
+ * `false` disables announcements. A no-op outside the browser.
8
+ *
9
+ * @param message Text to announce.
10
+ * @param element Optional app-owned live region, or `false` to disable.
6
11
  */
7
12
  export declare function announce(message: string, element?: HTMLElement | false): void;
@@ -1,36 +1,24 @@
1
- import { getGlobalState } from "../store/global-state.js";
1
+ import { announce as engineAnnounce } from "@zealakit/ui-engine";
2
2
  import { isBrowser } from "../store/env.js";
3
3
  /**
4
- * The one shared visually-hidden live region per document (plan 05 E20). This
5
- * inline style is the single accessibility exception to the "no styles" rule
6
- * (02 §2.8): it hides the region from sight while screen readers read it.
7
- */
8
- const VISUALLY_HIDDEN = "position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0";
9
- function createRegion() {
10
- const region = document.createElement("div");
11
- region.setAttribute("aria-live", "polite");
12
- region.setAttribute("role", "status");
13
- region.setAttribute("aria-atomic", "true");
14
- region.setAttribute("style", VISUALLY_HIDDEN);
15
- document.body.appendChild(region);
16
- return region;
17
- }
18
- /**
19
- * Announce `message` through a polite live region. The region is created
20
- * lazily and shared by every copy of core on the page; the app can pass its
21
- * own element, or `false` to disable announcements. A no-op outside the
22
- * browser.
4
+ * Announce `message` through a polite live region.
5
+ *
6
+ * Without an element, the engine owns the page-wide live region (created
7
+ * lazily, shared by every engine copy, cleared after 7 s). Passing an app
8
+ * element keeps Chrono's old escape hatch and writes to that element directly;
9
+ * `false` disables announcements. A no-op outside the browser.
10
+ *
11
+ * @param message Text to announce.
12
+ * @param element Optional app-owned live region, or `false` to disable.
23
13
  */
24
14
  export function announce(message, element) {
25
15
  if (element === false || !isBrowser()) {
26
16
  return;
27
17
  }
28
- const shared = element === undefined;
29
- const region = element ?? getGlobalState("announcer", createRegion);
30
- if (shared && !region.isConnected) {
31
- document.body.appendChild(region);
18
+ if (element !== undefined) {
19
+ element.textContent = "";
20
+ element.textContent = message;
21
+ return;
32
22
  }
33
- // Clearing first lets the same message be read twice in a row.
34
- region.textContent = "";
35
- region.textContent = message;
23
+ engineAnnounce(message);
36
24
  }
@@ -3,8 +3,8 @@ export type GridNavKey = "ArrowLeft" | "ArrowRight" | "ArrowUp" | "ArrowDown" |
3
3
  export type GridNavContext = {
4
4
  weekStartsOn: DayOfWeek;
5
5
  direction: "ltr" | "rtl";
6
- min?: PlainDate;
7
- max?: PlainDate;
6
+ min?: PlainDate | undefined;
7
+ max?: PlainDate | undefined;
8
8
  level: "day" | "month" | "year";
9
9
  /** Cells per row of the month and year grids (default 4). */
10
10
  columns?: number;
@@ -26,15 +26,7 @@ function safely(move, towardsEnd) {
26
26
  export function nextFocusedDate(current, key, modifiers, ctx) {
27
27
  const rtl = ctx.direction === "rtl";
28
28
  const columns = ctx.columns ?? 4;
29
- const horizontal = key === "ArrowLeft"
30
- ? rtl
31
- ? 1
32
- : -1
33
- : key === "ArrowRight"
34
- ? rtl
35
- ? -1
36
- : 1
37
- : 0;
29
+ const horizontal = key === "ArrowLeft" ? (rtl ? 1 : -1) : key === "ArrowRight" ? (rtl ? -1 : 1) : 0;
38
30
  const vertical = key === "ArrowUp" ? -1 : key === "ArrowDown" ? 1 : 0;
39
31
  const page = key === "PageUp" ? -1 : key === "PageDown" ? 1 : 0;
40
32
  const forward = horizontal > 0 || vertical > 0 || page > 0 || key === "End";
@@ -48,9 +40,7 @@ export function nextFocusedDate(current, key, modifiers, ctx) {
48
40
  return startOfWeek(current, ctx.weekStartsOn);
49
41
  if (key === "End")
50
42
  return endOfWeek(current, ctx.weekStartsOn);
51
- return modifiers.shift
52
- ? addYears(current, page)
53
- : addMonths(current, page);
43
+ return modifiers.shift ? addYears(current, page) : addMonths(current, page);
54
44
  }
55
45
  if (ctx.level === "month") {
56
46
  if (horizontal)
@@ -1,9 +1,30 @@
1
+ /**
2
+ * Calendar focus helpers — **calendar rule, not an engine candidate** (X16, spec §7).
3
+ *
4
+ * The engine's `createRovingFocus` manages a one-dimensional list: it owns one
5
+ * `keydown` + one `focusin` listener on a container, keeps its own active index,
6
+ * and applies `tabindex` to items it is handed. Chrono's grid cannot use it:
7
+ *
8
+ * - the cells are keyed by data (`data-chrono-key`, ISO dates; outside-month cells
9
+ * are skipped), not by a list order;
10
+ * - movement is two-dimensional and calendar-specific (week, month, PageUp/PageDown,
11
+ * year) and comes from the pure `grid-navigation.ts` rules, driven by the
12
+ * controller state — not from arrow-key listeners per container;
13
+ * - the tabindex for every cell is rendered from controller state
14
+ * (`tabindex: focused ? 0 : -1`), and the adapters only synchronise focus and the
15
+ * DOM attribute after a render. Registering an engine listener as well would
16
+ * duplicate the keydown ownership and break NP1.
17
+ *
18
+ * The helpers below are the DOM half of that model: data-keyed focus and tabindex
19
+ * sync, plus direct part focus for input segments. They stay in Core.
20
+ */
1
21
  import { toIsoString } from "../values/iso.js";
2
- const keyOf = (value) => typeof value === "string" ? value : toIsoString(value);
22
+ const keyOf = (value) => (typeof value === "string" ? value : toIsoString(value));
3
23
  const escapeAttribute = (key) => key.replace(/["\\]/g, "\\$&");
4
24
  function findCell(container, key) {
5
25
  const selector = `[data-chrono-key="${escapeAttribute(key)}"]`;
6
- return (container.querySelector(`${selector}:not([data-outside-month])`) ?? container.querySelector(selector));
26
+ return (container.querySelector(`${selector}:not([data-outside-month])`) ??
27
+ container.querySelector(selector));
7
28
  }
8
29
  /**
9
30
  * Move DOM focus to the cell carrying `data-chrono-key`. Call it from
@@ -27,7 +27,7 @@ export function normalizeRule(rule) {
27
27
  if (rule.type === "dates") {
28
28
  return {
29
29
  ...rule,
30
- dates: rule.dates.map((date) => typeof date === "string" ? parseIsoDate(date) : date),
30
+ dates: rule.dates.map((date) => (typeof date === "string" ? parseIsoDate(date) : date)),
31
31
  };
32
32
  }
33
33
  return rule;
@@ -41,9 +41,7 @@ export function ruleMatchesResource(rule, resourceId) {
41
41
  if (resourceId === undefined) {
42
42
  return false;
43
43
  }
44
- return typeof target === "string"
45
- ? target === resourceId
46
- : target.includes(resourceId);
44
+ return typeof target === "string" ? target === resourceId : target.includes(resourceId);
47
45
  }
48
46
  /** The wall-time window of a day-scoped rule on `day`, as instants in `zone`. */
49
47
  export function expandRuleDay(rule, day, zone) {
@@ -16,17 +16,17 @@ export type AvailabilityBookingWindow = {
16
16
  /** The one availability model (plan 11 V1–V5, V13). */
17
17
  export type AvailabilitySpec = {
18
18
  /** Only times inside an `open` rule are available. Without `open`, everything is open. */
19
- open?: readonly AvailabilityRule[];
19
+ open?: readonly AvailabilityRule[] | undefined;
20
20
  /** Always unavailable; `blocked` wins over `open`. */
21
- blocked?: readonly AvailabilityRule[];
21
+ blocked?: readonly AvailabilityRule[] | undefined;
22
22
  /** The zone the rule wall times are written in. */
23
23
  timeZone?: string;
24
24
  /** Nothing before `now` + lead time is available. Needs `now` at compile time. */
25
- leadTime?: AvailabilityLeadTime;
25
+ leadTime?: AvailabilityLeadTime | undefined;
26
26
  /** Wall time after which "today" no longer counts for `businessDays` lead time. */
27
27
  cutoffTime?: string;
28
28
  /** Nothing after `now` + the window is available. */
29
- bookingWindow?: AvailabilityBookingWindow;
29
+ bookingWindow?: AvailabilityBookingWindow | undefined;
30
30
  };
31
31
  /** The pre-plan-11 shape, accepted for one minor version (plan 11 R1). */
32
32
  export type LegacyAvailabilitySpec = {
@@ -63,9 +63,9 @@ export type Availability = {
63
63
  export type AvailabilityInput = PlainDate | PlainDateTime | ZonedDateTime | string;
64
64
  export type AvailabilityOptions = {
65
65
  /** The display zone; defaults to `spec.timeZone`. */
66
- timeZone?: string;
66
+ timeZone?: string | undefined;
67
67
  /** The instant "now" for lead time and booking windows (epoch ms). */
68
- now?: number;
68
+ now?: number | undefined;
69
69
  };
70
70
  /** `true` for the pre-plan-11 shape (plan 11 R1). */
71
71
  export declare function isLegacyAvailabilitySpec(input: AvailabilitySpec | LegacyAvailabilitySpec): input is LegacyAvailabilitySpec;
@@ -1,4 +1,4 @@
1
- import { addDays, addMonths, fromEpochDay, plainDate, toEpochDay, } from "../values/plain-date.js";
1
+ import { addDays, addMonths, fromEpochDay, plainDate, toEpochDay } from "../values/plain-date.js";
2
2
  import { plainDateTime } from "../values/plain-date-time.js";
3
3
  import { plainTime } from "../values/plain-time.js";
4
4
  import { parseIsoDate, parseIsoDateTime } from "../values/iso.js";
@@ -234,8 +234,7 @@ export function createAvailability(input, options = {}) {
234
234
  return spans;
235
235
  };
236
236
  // The lead-time-free base, so business days never depend on lead time (plan 11 §12.2).
237
- const baseBusiness = spec.leadTime?.businessDays !== undefined ||
238
- spec.bookingWindow !== undefined
237
+ const baseBusiness = spec.leadTime?.businessDays !== undefined || spec.bookingWindow !== undefined
239
238
  ? createAvailability({ ...spec, leadTime: undefined, bookingWindow: undefined }, options)
240
239
  : undefined;
241
240
  const businessDay = (date) => (baseBusiness ?? self).getDayStatus(date) !== "unavailable";
@@ -280,9 +279,7 @@ export function createAvailability(input, options = {}) {
280
279
  notBefore = Math.max(notBefore, startOfDayInstant(addDays(today, lead.days), ruleZone));
281
280
  }
282
281
  if (lead.businessDays !== undefined) {
283
- const cutoff = spec.cutoffTime === undefined
284
- ? Infinity
285
- : timeTokenToSeconds(spec.cutoffTime);
282
+ const cutoff = spec.cutoffTime === undefined ? Infinity : timeTokenToSeconds(spec.cutoffTime);
286
283
  const nowSeconds = nowZoned.hour * 3600 + nowZoned.minute * 60 + nowZoned.second;
287
284
  let orderDay = today;
288
285
  if (!businessDay(today) || nowSeconds >= cutoff) {
@@ -313,9 +310,7 @@ export function createAvailability(input, options = {}) {
313
310
  }
314
311
  return spans;
315
312
  };
316
- const openSpansFor = (start, end, resourceId) => hasOpen
317
- ? mergeSpans(spansBetween(openRules, start, end, resourceId))
318
- : [{ start, end }];
313
+ const openSpansFor = (start, end, resourceId) => hasOpen ? mergeSpans(spansBetween(openRules, start, end, resourceId)) : [{ start, end }];
319
314
  const piecesBetween = (start, end, resourceId) => {
320
315
  if (end <= start) {
321
316
  return [];
@@ -348,18 +343,13 @@ export function createAvailability(input, options = {}) {
348
343
  }
349
344
  const open = openSpansFor(start, end, resourceId);
350
345
  const blocked = blockedSpansFor(start, end, resourceId);
351
- const potential = open.reduce((total, span) => total +
352
- Math.max(0, Math.min(span.end, end) - Math.max(span.start, start)), 0);
346
+ const potential = open.reduce((total, span) => total + Math.max(0, Math.min(span.end, end) - Math.max(span.start, start)), 0);
353
347
  if (potential <= 0) {
354
348
  return "unavailable";
355
349
  }
356
350
  const available = sweep(open, blocked, start, end);
357
351
  const availableMs = sumMs(available, "available");
358
- const status = availableMs <= 0
359
- ? "unavailable"
360
- : availableMs < potential
361
- ? "partial"
362
- : "available";
352
+ const status = availableMs <= 0 ? "unavailable" : availableMs < potential ? "partial" : "available";
363
353
  if (statusCache.size >= CACHE_DAYS) {
364
354
  const oldest = statusCache.keys().next().value;
365
355
  if (oldest !== undefined)
@@ -1,8 +1,8 @@
1
1
  import type { PlainDate } from "../values/types.js";
2
2
  export type DateConstraints = {
3
- min?: PlainDate;
4
- max?: PlainDate;
5
- isDateDisabled?: (date: PlainDate) => boolean;
3
+ min?: PlainDate | undefined;
4
+ max?: PlainDate | undefined;
5
+ isDateDisabled?: ((date: PlainDate) => boolean) | undefined;
6
6
  isDateUnavailable?: (date: PlainDate) => boolean;
7
7
  };
8
8
  export type DateStatusReason = "before-min" | "after-max" | "disabled" | "unavailable";
@@ -1,7 +1,7 @@
1
1
  export { getDateStatus, isDateSelectable } from "./date.js";
2
2
  export type { DateConstraints, DateStatus, DateStatusReason } from "./date.js";
3
3
  export { getTimeStatus, snapTime } from "./time.js";
4
- export type { TimeConstraints, TimeStatus, TimeStatusReason, TimeStep, } from "./time.js";
4
+ export type { TimeConstraints, TimeStatus, TimeStatusReason, TimeStep } from "./time.js";
5
5
  export { checkDateRange, checkTimeRange } from "./range.js";
6
6
  export type { DateRangeCheck, DateRangeConstraints, DateRangeReason, TimeRangeCheck, TimeRangeConstraints, TimeRangeReason, } from "./range.js";
7
7
  export { addBusinessDays, countBusinessDays, compileAvailability, createAvailability, filterDailyRules, getAvailabilityLabel, isBusinessDay, isLegacyAvailabilitySpec, legacyToAvailabilitySpec, } from "./availability.js";
@@ -4,10 +4,10 @@ import type { Availability } from "./availability.js";
4
4
  import { type DateConstraints } from "./date.js";
5
5
  import { type TimeConstraints } from "./time.js";
6
6
  export type DateRangeConstraints = DateConstraints & {
7
- minDays?: number;
8
- maxDays?: number;
9
- allowUnavailableInside?: boolean;
10
- allowDisabledInside?: boolean;
7
+ minDays?: number | undefined;
8
+ maxDays?: number | undefined;
9
+ allowUnavailableInside?: boolean | undefined;
10
+ allowDisabledInside?: boolean | undefined;
11
11
  /** Extra unavailable days from {@link createAvailability}. */
12
12
  availability?: Availability;
13
13
  };
@@ -10,7 +10,7 @@ import { getTimeStatus } from "./time.js";
10
10
  * `allow*Inside` option is set. Only days between the endpoints are scanned.
11
11
  */
12
12
  export function checkDateRange(range, constraints = {}) {
13
- const { minDays, maxDays, allowUnavailableInside, allowDisabledInside, availability, } = constraints;
13
+ const { minDays, maxDays, allowUnavailableInside, allowDisabledInside, availability } = constraints;
14
14
  const isUnavailable = (date) => (constraints.isDateUnavailable?.(date) ?? false) ||
15
15
  (availability ? !availability.isAvailable(date) : false);
16
16
  const withAvailability = {