foldkit-primitives 0.3.0 → 0.5.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/README.md +144 -723
- package/dist/device/index.d.mts.map +1 -1
- package/dist/device/index.mjs +95 -87
- package/dist/device/index.mjs.map +1 -1
- package/dist/dom/index.d.mts +71 -3
- package/dist/dom/index.d.mts.map +1 -1
- package/dist/dom/index.mjs +303 -6
- package/dist/dom/index.mjs.map +1 -1
- package/dist/editable-text-CKkS_mWt.d.mts +235 -0
- package/dist/editable-text-CKkS_mWt.d.mts.map +1 -0
- package/dist/events/index.d.mts +8 -1
- package/dist/events/index.d.mts.map +1 -1
- package/dist/events/index.mjs +32 -17
- package/dist/events/index.mjs.map +1 -1
- package/dist/follow-tab-stop-BSZsUrrk.mjs +805 -0
- package/dist/follow-tab-stop-BSZsUrrk.mjs.map +1 -0
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +7 -7
- package/dist/interaction/index.d.mts +247 -92
- package/dist/interaction/index.d.mts.map +1 -1
- package/dist/interaction/index.mjs +507 -224
- package/dist/interaction/index.mjs.map +1 -1
- package/dist/internal-DP-xLKbT.mjs +37 -0
- package/dist/internal-DP-xLKbT.mjs.map +1 -0
- package/dist/media/index.d.mts.map +1 -1
- package/dist/media/index.mjs +3 -3
- package/dist/media/index.mjs.map +1 -1
- package/dist/motion/index.mjs +1 -1
- package/dist/{motion-LfJYAMnP.mjs → motion-DGGBZ0wt.mjs} +14 -13
- package/dist/motion-DGGBZ0wt.mjs.map +1 -0
- package/dist/net/index.d.mts +69 -5
- package/dist/net/index.d.mts.map +1 -1
- package/dist/net/index.mjs +139 -56
- package/dist/net/index.mjs.map +1 -1
- package/dist/observers/index.d.mts +1 -1
- package/dist/observers/index.mjs +3 -0
- package/dist/observers/index.mjs.map +1 -1
- package/dist/state/index.d.mts +54 -12
- package/dist/state/index.d.mts.map +1 -1
- package/dist/state/index.mjs +198 -90
- package/dist/state/index.mjs.map +1 -1
- package/dist/time/index.d.mts +21 -1
- package/dist/time/index.d.mts.map +1 -1
- package/dist/time/index.mjs +48 -19
- package/dist/time/index.mjs.map +1 -1
- package/package.json +20 -9
- package/dist/motion-LfJYAMnP.mjs.map +0 -1
- package/dist/move-CZwHyTGk.mjs +0 -215
- package/dist/move-CZwHyTGk.mjs.map +0 -1
- package/dist/move-DNiMPcuf.d.mts +0 -58
- package/dist/move-DNiMPcuf.d.mts.map +0 -1
package/dist/move-CZwHyTGk.mjs
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { Effect, Queue, Schema, Stream } from "effect";
|
|
2
|
-
import * as Mount from "foldkit/mount";
|
|
3
|
-
import * as Dom from "foldkit/dom";
|
|
4
|
-
//#region src/dom/focus-scope.ts
|
|
5
|
-
/**
|
|
6
|
-
* A focus scope as a Mount: on insert it remembers what was focused, focuses
|
|
7
|
-
* an initial element inside, and with `contain` keeps Tab and Shift+Tab
|
|
8
|
-
* cycling inside; on unmount it gives focus back. Nothing crosses to the
|
|
9
|
-
* Model: which element had focus is a DOM fact, so this is element lifecycle,
|
|
10
|
-
* not state. It emits no Messages.
|
|
11
|
-
*/
|
|
12
|
-
const FOCUSABLE = [
|
|
13
|
-
"a[href]",
|
|
14
|
-
"button:not([disabled])",
|
|
15
|
-
"input:not([disabled]):not([type=\"hidden\"])",
|
|
16
|
-
"select:not([disabled])",
|
|
17
|
-
"textarea:not([disabled])",
|
|
18
|
-
"[tabindex]",
|
|
19
|
-
"[contenteditable=\"true\"]"
|
|
20
|
-
].join(", ");
|
|
21
|
-
const isVisible = (element) => {
|
|
22
|
-
const probe = element;
|
|
23
|
-
return element.closest("[hidden], [inert]") === null && (probe.checkVisibility?.() ?? true);
|
|
24
|
-
};
|
|
25
|
-
/** Tabbable descendants in DOM order: focusable, visible, and not `tabindex="-1"`. */
|
|
26
|
-
const tabbableWithin = (root) => Array.from(root.querySelectorAll(FOCUSABLE)).filter((element) => element.tabIndex >= 0 && isVisible(element));
|
|
27
|
-
const focusFirst = (elements) => {
|
|
28
|
-
const first = elements[0];
|
|
29
|
-
if (first === void 0) return false;
|
|
30
|
-
first.focus();
|
|
31
|
-
return true;
|
|
32
|
-
};
|
|
33
|
-
const FocusScope = Mount.defineStream("FocusScope", {
|
|
34
|
-
messages: [Schema.Never],
|
|
35
|
-
args: {
|
|
36
|
-
/** Keep Tab, Shift+Tab, and a stray focus inside. */
|
|
37
|
-
contain: Schema.Boolean,
|
|
38
|
-
/** Give focus back to what had it, on unmount. */
|
|
39
|
-
restore: Schema.Boolean,
|
|
40
|
-
/** A selector inside the element to focus first; else the first tabbable
|
|
41
|
-
* descendant, else the element itself when it is focusable. */
|
|
42
|
-
initialFocus: Schema.NullOr(Schema.String)
|
|
43
|
-
},
|
|
44
|
-
execute: ({ element, contain, restore, initialFocus }) => Stream.callback(() => Effect.acquireRelease(Effect.sync(() => {
|
|
45
|
-
const ownerDocument = element.ownerDocument;
|
|
46
|
-
const previous = ownerDocument.activeElement;
|
|
47
|
-
const initial = initialFocus === null ? null : element.querySelector(initialFocus);
|
|
48
|
-
if (initial !== null) initial.focus();
|
|
49
|
-
else if (!focusFirst(tabbableWithin(element)) && element instanceof HTMLElement) element.focus();
|
|
50
|
-
const onKeyDown = (event) => {
|
|
51
|
-
const key = event;
|
|
52
|
-
if (key.key !== "Tab") return;
|
|
53
|
-
const tabbable = tabbableWithin(element);
|
|
54
|
-
const first = tabbable[0];
|
|
55
|
-
const last = tabbable[tabbable.length - 1];
|
|
56
|
-
if (first === void 0 || last === void 0) {
|
|
57
|
-
key.preventDefault();
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const active = ownerDocument.activeElement;
|
|
61
|
-
if (key.shiftKey && (active === first || !element.contains(active))) {
|
|
62
|
-
key.preventDefault();
|
|
63
|
-
last.focus();
|
|
64
|
-
} else if (!key.shiftKey && (active === last || !element.contains(active))) {
|
|
65
|
-
key.preventDefault();
|
|
66
|
-
first.focus();
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
const onFocusIn = (event) => {
|
|
70
|
-
const target = event.target;
|
|
71
|
-
if (target instanceof Node && element.contains(target)) return;
|
|
72
|
-
focusFirst(tabbableWithin(element));
|
|
73
|
-
};
|
|
74
|
-
if (contain) {
|
|
75
|
-
element.addEventListener("keydown", onKeyDown);
|
|
76
|
-
ownerDocument.addEventListener("focusin", onFocusIn);
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
previous,
|
|
80
|
-
onKeyDown,
|
|
81
|
-
onFocusIn,
|
|
82
|
-
ownerDocument
|
|
83
|
-
};
|
|
84
|
-
}), ({ previous, onKeyDown, onFocusIn, ownerDocument }) => Effect.sync(() => {
|
|
85
|
-
if (contain) {
|
|
86
|
-
element.removeEventListener("keydown", onKeyDown);
|
|
87
|
-
ownerDocument.removeEventListener("focusin", onFocusIn);
|
|
88
|
-
}
|
|
89
|
-
if (restore && previous instanceof HTMLElement && ownerDocument.contains(previous)) previous.focus();
|
|
90
|
-
})))
|
|
91
|
-
});
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region src/dom/layers.ts
|
|
94
|
-
/**
|
|
95
|
-
* Two Mounts over Foldkit's own DOM helpers, for an overlay that is not a
|
|
96
|
-
* native `<dialog>` or `popover`:
|
|
97
|
-
*
|
|
98
|
-
* - `ScrollLock` locks the document's scroll while mounted. Foldkit's lock is
|
|
99
|
-
* refcounted, so nested overlays release it only when the last one goes.
|
|
100
|
-
* - `HideOutside` marks everything outside the element inert while mounted,
|
|
101
|
-
* through `Dom.inertOthers`, keyed by an id this Mount mints.
|
|
102
|
-
*
|
|
103
|
-
* Both emit no Messages; they are element lifecycle.
|
|
104
|
-
*/
|
|
105
|
-
const ScrollLock = Mount.defineStream("ScrollLock", {
|
|
106
|
-
messages: [Schema.Never],
|
|
107
|
-
execute: () => Stream.callback(() => Effect.acquireRelease(Dom.lockScroll, () => Dom.unlockScroll))
|
|
108
|
-
});
|
|
109
|
-
const HIDE_OUTSIDE_ATTRIBUTE = "data-foldkit-plus-hide-outside";
|
|
110
|
-
let minted = 0;
|
|
111
|
-
const HideOutside = Mount.defineStream("HideOutside", {
|
|
112
|
-
messages: [Schema.Never],
|
|
113
|
-
execute: ({ element }) => Stream.callback(() => Effect.acquireRelease(Effect.gen(function* () {
|
|
114
|
-
const id = `hide-outside-${minted += 1}`;
|
|
115
|
-
element.setAttribute(HIDE_OUTSIDE_ATTRIBUTE, id);
|
|
116
|
-
yield* Dom.inertOthers(id, [`[${HIDE_OUTSIDE_ATTRIBUTE}="${id}"]`]);
|
|
117
|
-
return id;
|
|
118
|
-
}), (id) => Effect.andThen(Dom.restoreInert(id), () => Effect.sync(() => element.removeAttribute(HIDE_OUTSIDE_ATTRIBUTE)))))
|
|
119
|
-
});
|
|
120
|
-
//#endregion
|
|
121
|
-
//#region src/dom/move.ts
|
|
122
|
-
/**
|
|
123
|
-
* Pointer movement on an element as a Mount: a primary-button pointer down
|
|
124
|
-
* captures the pointer, each move reports the delta from where it started,
|
|
125
|
-
* and up, cancel, or lost capture ends it. Nothing is decided here: a drag
|
|
126
|
-
* threshold, a snap, or a constraint is the parent's `update`. Capture is
|
|
127
|
-
* released with the Mount.
|
|
128
|
-
*/
|
|
129
|
-
const MoveStarted = Schema.TaggedStruct("MoveStarted", {
|
|
130
|
-
pointerId: Schema.Number,
|
|
131
|
-
pointerType: Schema.String
|
|
132
|
-
});
|
|
133
|
-
const Moved = Schema.TaggedStruct("Moved", {
|
|
134
|
-
pointerId: Schema.Number,
|
|
135
|
-
/** From where the pointer went down, in CSS pixels. */
|
|
136
|
-
deltaX: Schema.Number,
|
|
137
|
-
deltaY: Schema.Number,
|
|
138
|
-
pointerType: Schema.String
|
|
139
|
-
});
|
|
140
|
-
const MoveEnded = Schema.TaggedStruct("MoveEnded", {
|
|
141
|
-
pointerId: Schema.Number,
|
|
142
|
-
/** `false` when the pointer was cancelled or capture was lost. */
|
|
143
|
-
completed: Schema.Boolean
|
|
144
|
-
});
|
|
145
|
-
const Move = Mount.defineStream("Move", {
|
|
146
|
-
messages: [
|
|
147
|
-
MoveStarted,
|
|
148
|
-
Moved,
|
|
149
|
-
MoveEnded
|
|
150
|
-
],
|
|
151
|
-
execute: ({ element }) => Stream.callback((queue) => Effect.acquireRelease(Effect.sync(() => {
|
|
152
|
-
const target = element;
|
|
153
|
-
let active = null;
|
|
154
|
-
const offer = (fact) => Queue.offerUnsafe(queue, fact);
|
|
155
|
-
const end = (pointerId, completed) => {
|
|
156
|
-
if (active === null || active.pointerId !== pointerId) return;
|
|
157
|
-
active = null;
|
|
158
|
-
try {
|
|
159
|
-
target.releasePointerCapture?.(pointerId);
|
|
160
|
-
} catch {}
|
|
161
|
-
offer(MoveEnded.make({
|
|
162
|
-
pointerId,
|
|
163
|
-
completed
|
|
164
|
-
}));
|
|
165
|
-
};
|
|
166
|
-
const listeners = [
|
|
167
|
-
["pointerdown", (event) => {
|
|
168
|
-
const pointer = event;
|
|
169
|
-
if ((pointer.button ?? 0) !== 0 || active !== null) return;
|
|
170
|
-
const pointerId = pointer.pointerId ?? 0;
|
|
171
|
-
active = {
|
|
172
|
-
pointerId,
|
|
173
|
-
x: pointer.clientX ?? 0,
|
|
174
|
-
y: pointer.clientY ?? 0
|
|
175
|
-
};
|
|
176
|
-
try {
|
|
177
|
-
target.setPointerCapture?.(pointerId);
|
|
178
|
-
} catch {}
|
|
179
|
-
offer(MoveStarted.make({
|
|
180
|
-
pointerId,
|
|
181
|
-
pointerType: pointer.pointerType ?? "mouse"
|
|
182
|
-
}));
|
|
183
|
-
}],
|
|
184
|
-
["pointermove", (event) => {
|
|
185
|
-
const pointer = event;
|
|
186
|
-
const pointerId = pointer.pointerId ?? 0;
|
|
187
|
-
if (active === null || active.pointerId !== pointerId) return;
|
|
188
|
-
offer(Moved.make({
|
|
189
|
-
pointerId,
|
|
190
|
-
deltaX: (pointer.clientX ?? 0) - active.x,
|
|
191
|
-
deltaY: (pointer.clientY ?? 0) - active.y,
|
|
192
|
-
pointerType: pointer.pointerType ?? "mouse"
|
|
193
|
-
}));
|
|
194
|
-
}],
|
|
195
|
-
["pointerup", (event) => end(event.pointerId ?? 0, true)],
|
|
196
|
-
["pointercancel", (event) => end(event.pointerId ?? 0, false)],
|
|
197
|
-
["lostpointercapture", (event) => end(event.pointerId ?? 0, false)]
|
|
198
|
-
];
|
|
199
|
-
for (const [type, listener] of listeners) element.addEventListener(type, listener);
|
|
200
|
-
return {
|
|
201
|
-
listeners,
|
|
202
|
-
current: () => active
|
|
203
|
-
};
|
|
204
|
-
}), ({ listeners, current }) => Effect.sync(() => {
|
|
205
|
-
for (const [type, listener] of listeners) element.removeEventListener(type, listener);
|
|
206
|
-
const pointer = current();
|
|
207
|
-
if (pointer !== null) try {
|
|
208
|
-
element.releasePointerCapture?.(pointer.pointerId);
|
|
209
|
-
} catch {}
|
|
210
|
-
})))
|
|
211
|
-
});
|
|
212
|
-
//#endregion
|
|
213
|
-
export { HideOutside as a, tabbableWithin as c, Moved as i, MoveEnded as n, ScrollLock as o, MoveStarted as r, FocusScope as s, Move as t };
|
|
214
|
-
|
|
215
|
-
//# sourceMappingURL=move-CZwHyTGk.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"move-CZwHyTGk.mjs","names":[],"sources":["../src/dom/focus-scope.ts","../src/dom/layers.ts","../src/dom/move.ts"],"sourcesContent":["/**\n * A focus scope as a Mount: on insert it remembers what was focused, focuses\n * an initial element inside, and with `contain` keeps Tab and Shift+Tab\n * cycling inside; on unmount it gives focus back. Nothing crosses to the\n * Model: which element had focus is a DOM fact, so this is element lifecycle,\n * not state. It emits no Messages.\n */\nimport { Effect, Schema, Stream } from 'effect'\nimport * as Mount from 'foldkit/mount'\n\nconst FOCUSABLE = [\n 'a[href]',\n 'button:not([disabled])',\n 'input:not([disabled]):not([type=\"hidden\"])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n '[tabindex]',\n '[contenteditable=\"true\"]',\n].join(', ')\n\nconst isVisible = (element: Element): boolean => {\n const probe = element as { checkVisibility?: () => boolean }\n return element.closest('[hidden], [inert]') === null && (probe.checkVisibility?.() ?? true)\n}\n\n/** Tabbable descendants in DOM order: focusable, visible, and not `tabindex=\"-1\"`. */\nexport const tabbableWithin = (root: Element): ReadonlyArray<HTMLElement> =>\n Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(\n element => element.tabIndex >= 0 && isVisible(element),\n )\n\nconst focusFirst = (elements: ReadonlyArray<HTMLElement>): boolean => {\n const first = elements[0]\n if (first === undefined) return false\n first.focus()\n return true\n}\n\nexport const FocusScope = Mount.defineStream('FocusScope', {\n messages: [Schema.Never],\n args: {\n /** Keep Tab, Shift+Tab, and a stray focus inside. */\n contain: Schema.Boolean,\n /** Give focus back to what had it, on unmount. */\n restore: Schema.Boolean,\n /** A selector inside the element to focus first; else the first tabbable\n * descendant, else the element itself when it is focusable. */\n initialFocus: Schema.NullOr(Schema.String),\n },\n execute: ({ element, contain, restore, initialFocus }) =>\n Stream.callback<never>(() =>\n Effect.acquireRelease(\n Effect.sync(() => {\n const ownerDocument = element.ownerDocument\n const previous = ownerDocument.activeElement\n const initial =\n initialFocus === null ? null : element.querySelector<HTMLElement>(initialFocus)\n if (initial !== null) initial.focus()\n else if (!focusFirst(tabbableWithin(element)) && element instanceof HTMLElement) {\n element.focus()\n }\n const onKeyDown = (event: Event) => {\n const key = event as KeyboardEvent\n if (key.key !== 'Tab') return\n const tabbable = tabbableWithin(element)\n const first = tabbable[0]\n const last = tabbable[tabbable.length - 1]\n if (first === undefined || last === undefined) {\n key.preventDefault()\n return\n }\n const active = ownerDocument.activeElement\n if (key.shiftKey && (active === first || !element.contains(active))) {\n key.preventDefault()\n last.focus()\n } else if (!key.shiftKey && (active === last || !element.contains(active))) {\n key.preventDefault()\n first.focus()\n }\n }\n const onFocusIn = (event: Event) => {\n const target = event.target\n if (target instanceof Node && element.contains(target)) return\n focusFirst(tabbableWithin(element))\n }\n if (contain) {\n element.addEventListener('keydown', onKeyDown)\n ownerDocument.addEventListener('focusin', onFocusIn)\n }\n return { previous, onKeyDown, onFocusIn, ownerDocument }\n }),\n ({ previous, onKeyDown, onFocusIn, ownerDocument }) =>\n Effect.sync(() => {\n if (contain) {\n element.removeEventListener('keydown', onKeyDown)\n ownerDocument.removeEventListener('focusin', onFocusIn)\n }\n if (restore && previous instanceof HTMLElement && ownerDocument.contains(previous)) {\n previous.focus()\n }\n }),\n ),\n ),\n})\n","/**\n * Two Mounts over Foldkit's own DOM helpers, for an overlay that is not a\n * native `<dialog>` or `popover`:\n *\n * - `ScrollLock` locks the document's scroll while mounted. Foldkit's lock is\n * refcounted, so nested overlays release it only when the last one goes.\n * - `HideOutside` marks everything outside the element inert while mounted,\n * through `Dom.inertOthers`, keyed by an id this Mount mints.\n *\n * Both emit no Messages; they are element lifecycle.\n */\nimport { Effect, Schema, Stream } from 'effect'\nimport * as Dom from 'foldkit/dom'\nimport * as Mount from 'foldkit/mount'\n\nexport const ScrollLock = Mount.defineStream('ScrollLock', {\n messages: [Schema.Never],\n execute: () =>\n Stream.callback<never>(() => Effect.acquireRelease(Dom.lockScroll, () => Dom.unlockScroll)),\n})\n\nconst HIDE_OUTSIDE_ATTRIBUTE = 'data-foldkit-plus-hide-outside'\n\nlet minted = 0\n\nexport const HideOutside = Mount.defineStream('HideOutside', {\n messages: [Schema.Never],\n execute: ({ element }) =>\n Stream.callback<never>(() =>\n Effect.acquireRelease(\n Effect.gen(function* () {\n // A per-mount id: Foldkit keys the inert set by it, so two overlays\n // restore independently. The attribute is how the element is found.\n const id = `hide-outside-${(minted += 1)}`\n element.setAttribute(HIDE_OUTSIDE_ATTRIBUTE, id)\n yield* Dom.inertOthers(id, [`[${HIDE_OUTSIDE_ATTRIBUTE}=\"${id}\"]`])\n return id\n }),\n id =>\n Effect.andThen(Dom.restoreInert(id), () =>\n Effect.sync(() => element.removeAttribute(HIDE_OUTSIDE_ATTRIBUTE)),\n ),\n ),\n ),\n})\n","/**\n * Pointer movement on an element as a Mount: a primary-button pointer down\n * captures the pointer, each move reports the delta from where it started,\n * and up, cancel, or lost capture ends it. Nothing is decided here: a drag\n * threshold, a snap, or a constraint is the parent's `update`. Capture is\n * released with the Mount.\n */\nimport { Effect, Queue, Schema, Stream } from 'effect'\nimport * as Mount from 'foldkit/mount'\n\nexport const MoveStarted = Schema.TaggedStruct('MoveStarted', {\n pointerId: Schema.Number,\n pointerType: Schema.String,\n})\nexport type MoveStarted = typeof MoveStarted.Type\n\nexport const Moved = Schema.TaggedStruct('Moved', {\n pointerId: Schema.Number,\n /** From where the pointer went down, in CSS pixels. */\n deltaX: Schema.Number,\n deltaY: Schema.Number,\n pointerType: Schema.String,\n})\nexport type Moved = typeof Moved.Type\n\nexport const MoveEnded = Schema.TaggedStruct('MoveEnded', {\n pointerId: Schema.Number,\n /** `false` when the pointer was cancelled or capture was lost. */\n completed: Schema.Boolean,\n})\nexport type MoveEnded = typeof MoveEnded.Type\n\nexport type Fact = MoveStarted | Moved | MoveEnded\n\ntype PointerLike = Event & {\n readonly pointerId?: number\n readonly button?: number\n readonly pointerType?: string\n readonly clientX?: number\n readonly clientY?: number\n}\n\ntype Capturing = Element & {\n setPointerCapture?: (pointerId: number) => void\n releasePointerCapture?: (pointerId: number) => void\n}\n\nexport const Move = Mount.defineStream('Move', {\n messages: [MoveStarted, Moved, MoveEnded],\n execute: ({ element }) =>\n Stream.callback<Fact>(queue =>\n Effect.acquireRelease(\n Effect.sync(() => {\n const target = element as Capturing\n let active: {\n readonly pointerId: number\n readonly x: number\n readonly y: number\n } | null = null\n const offer = (fact: Fact) => Queue.offerUnsafe(queue, fact)\n const end = (pointerId: number, completed: boolean) => {\n if (active === null || active.pointerId !== pointerId) return\n active = null\n try {\n target.releasePointerCapture?.(pointerId)\n } catch {\n // Capture may already be gone; the end is still reported.\n }\n offer(MoveEnded.make({ pointerId, completed }))\n }\n const listeners: ReadonlyArray<readonly [string, (event: Event) => void]> = [\n [\n 'pointerdown',\n event => {\n const pointer = event as PointerLike\n if ((pointer.button ?? 0) !== 0 || active !== null) return\n const pointerId = pointer.pointerId ?? 0\n active = { pointerId, x: pointer.clientX ?? 0, y: pointer.clientY ?? 0 }\n try {\n target.setPointerCapture?.(pointerId)\n } catch {\n // Without capture the move still reports while over the element.\n }\n offer(MoveStarted.make({ pointerId, pointerType: pointer.pointerType ?? 'mouse' }))\n },\n ],\n [\n 'pointermove',\n event => {\n const pointer = event as PointerLike\n const pointerId = pointer.pointerId ?? 0\n if (active === null || active.pointerId !== pointerId) return\n offer(\n Moved.make({\n pointerId,\n deltaX: (pointer.clientX ?? 0) - active.x,\n deltaY: (pointer.clientY ?? 0) - active.y,\n pointerType: pointer.pointerType ?? 'mouse',\n }),\n )\n },\n ],\n ['pointerup', event => end((event as PointerLike).pointerId ?? 0, true)],\n ['pointercancel', event => end((event as PointerLike).pointerId ?? 0, false)],\n ['lostpointercapture', event => end((event as PointerLike).pointerId ?? 0, false)],\n ]\n for (const [type, listener] of listeners) element.addEventListener(type, listener)\n return { listeners, current: () => active }\n }),\n ({ listeners, current }) =>\n Effect.sync(() => {\n for (const [type, listener] of listeners) element.removeEventListener(type, listener)\n const pointer = current()\n if (pointer !== null) {\n try {\n ;(element as Capturing).releasePointerCapture?.(pointer.pointerId)\n } catch {\n // Already released.\n }\n }\n }),\n ),\n ),\n})\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAEX,MAAM,aAAa,YAA8B;CAC/C,MAAM,QAAQ;CACd,OAAO,QAAQ,QAAQ,mBAAmB,MAAM,SAAS,MAAM,kBAAkB,KAAK;AACxF;;AAGA,MAAa,kBAAkB,SAC7B,MAAM,KAAK,KAAK,iBAA8B,SAAS,CAAC,CAAC,CAAC,QACxD,YAAW,QAAQ,YAAY,KAAK,UAAU,OAAO,CACvD;AAEF,MAAM,cAAc,aAAkD;CACpE,MAAM,QAAQ,SAAS;CAC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AAG,KAAK,CAAC;EACnF;EACA,KAAK,MAAM,CAAC,MAAM,aAAa,WAAW,QAAQ,iBAAiB,MAAM,QAAQ;EACjF,OAAO;GAAE;GAAW,eAAe;EAAO;CAC5C,CAAC,IACA,EAAE,WAAW,cACZ,OAAO,WAAW;EAChB,KAAK,MAAM,CAAC,MAAM,aAAa,WAAW,QAAQ,oBAAoB,MAAM,QAAQ;EACpF,MAAM,UAAU,QAAQ;EACxB,IAAI,YAAY,MACd,IAAI;GACD,QAAuB,wBAAwB,QAAQ,SAAS;EACnE,QAAQ,CAER;CAEJ,CAAC,CACL,CACF;AACJ,CAAC"}
|
package/dist/move-DNiMPcuf.d.mts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
2
|
-
import * as Mount from "foldkit/mount";
|
|
3
|
-
//#region src/dom/focus-scope.d.ts
|
|
4
|
-
/** Tabbable descendants in DOM order: focusable, visible, and not `tabindex="-1"`. */
|
|
5
|
-
declare const tabbableWithin: (root: Element) => ReadonlyArray<HTMLElement>;
|
|
6
|
-
declare const FocusScope: Mount.MountDefinitionWithArgs<"FocusScope", {
|
|
7
|
-
/** Keep Tab, Shift+Tab, and a stray focus inside. */
|
|
8
|
-
contain: Schema.Boolean;
|
|
9
|
-
/** Give focus back to what had it, on unmount. */
|
|
10
|
-
restore: Schema.Boolean;
|
|
11
|
-
/** A selector inside the element to focus first; else the first tabbable
|
|
12
|
-
* descendant, else the element itself when it is focusable. */
|
|
13
|
-
initialFocus: Schema.NullOr<Schema.String>;
|
|
14
|
-
}, never>;
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/dom/layers.d.ts
|
|
17
|
-
declare const ScrollLock: Mount.MountDefinitionNoArgs<"ScrollLock", never>;
|
|
18
|
-
declare const HideOutside: Mount.MountDefinitionNoArgs<"HideOutside", never>;
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/dom/move.d.ts
|
|
21
|
-
declare const MoveStarted: Schema.TaggedStruct<"MoveStarted", {
|
|
22
|
-
readonly pointerId: Schema.Number;
|
|
23
|
-
readonly pointerType: Schema.String;
|
|
24
|
-
}>;
|
|
25
|
-
type MoveStarted = typeof MoveStarted.Type;
|
|
26
|
-
declare const Moved: Schema.TaggedStruct<"Moved", {
|
|
27
|
-
readonly pointerId: Schema.Number;
|
|
28
|
-
/** From where the pointer went down, in CSS pixels. */
|
|
29
|
-
readonly deltaX: Schema.Number;
|
|
30
|
-
readonly deltaY: Schema.Number;
|
|
31
|
-
readonly pointerType: Schema.String;
|
|
32
|
-
}>;
|
|
33
|
-
type Moved = typeof Moved.Type;
|
|
34
|
-
declare const MoveEnded: Schema.TaggedStruct<"MoveEnded", {
|
|
35
|
-
readonly pointerId: Schema.Number;
|
|
36
|
-
/** `false` when the pointer was cancelled or capture was lost. */
|
|
37
|
-
readonly completed: Schema.Boolean;
|
|
38
|
-
}>;
|
|
39
|
-
type MoveEnded = typeof MoveEnded.Type;
|
|
40
|
-
type Fact = MoveStarted | Moved | MoveEnded;
|
|
41
|
-
declare const Move: Mount.MountDefinitionNoArgs<"Move", {
|
|
42
|
-
readonly _tag: "MoveStarted";
|
|
43
|
-
readonly pointerId: number;
|
|
44
|
-
readonly pointerType: string;
|
|
45
|
-
} | {
|
|
46
|
-
readonly _tag: "Moved";
|
|
47
|
-
readonly pointerId: number;
|
|
48
|
-
readonly deltaX: number;
|
|
49
|
-
readonly deltaY: number;
|
|
50
|
-
readonly pointerType: string;
|
|
51
|
-
} | {
|
|
52
|
-
readonly _tag: "MoveEnded";
|
|
53
|
-
readonly pointerId: number;
|
|
54
|
-
readonly completed: boolean;
|
|
55
|
-
}>;
|
|
56
|
-
//#endregion
|
|
57
|
-
export { Moved as a, FocusScope as c, MoveStarted as i, tabbableWithin as l, Move as n, HideOutside as o, MoveEnded as r, ScrollLock as s, Fact as t };
|
|
58
|
-
//# sourceMappingURL=move-DNiMPcuf.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"move-DNiMPcuf.d.mts","names":[],"sources":["../src/dom/focus-scope.ts","../src/dom/layers.ts","../src/dom/move.ts"],"mappings":";;;;cA0Ba,iBAAkB,MAAM,YAAU,cAAc;cAYhD,YAAU,MAAA;;;;;;;;;;;cCvBV,YAAU,MAAA;cAUV,aAAW,MAAA;;;cCfX,aAAW,OAAA;;;;KAIZ,qBAAqB,YAAY;cAEhC,OAAK,OAAA;;;;;;;KAON,eAAe,MAAM;cAEpB,WAAS,OAAA;;;;;KAKV,mBAAmB,UAAU;KAE7B,OAAO,cAAc,QAAQ;cAe5B,MAAI,MAAA"}
|