@baleada/logic 0.24.10 → 0.24.12

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/lib/index.cjs CHANGED
@@ -2212,26 +2212,61 @@ const defaultOptions$d = {
2212
2212
  };
2213
2213
  function createFocusable(order, options = {}) {
2214
2214
  const { predicatesElement, tabbableSelector } = { ...defaultOptions$d, ...options }, predicateFocusable = (element) => element.matches(tabbableSelector);
2215
- return (element) => {
2216
- if (predicatesElement && predicateFocusable(element))
2217
- return element;
2218
- switch (order) {
2219
- case "first":
2215
+ switch (order) {
2216
+ case "first":
2217
+ return (element) => {
2218
+ if (predicatesElement && predicateFocusable(element))
2219
+ return element;
2220
2220
  for (let i = 0; i < element.children.length; i++) {
2221
2221
  const focusable = createFocusable(order, { predicatesElement: true })(element.children[i]);
2222
2222
  if (focusable)
2223
2223
  return focusable;
2224
2224
  }
2225
- break;
2226
- case "last":
2225
+ };
2226
+ case "last":
2227
+ return (element) => {
2228
+ if (predicatesElement && predicateFocusable(element))
2229
+ return element;
2227
2230
  for (let i = element.children.length - 1; i > -1; i--) {
2228
2231
  const focusable = createFocusable(order, { predicatesElement: true })(element.children[i]);
2229
2232
  if (focusable)
2230
2233
  return focusable;
2231
2234
  }
2232
- break;
2233
- }
2234
- };
2235
+ };
2236
+ case "next":
2237
+ return (element) => {
2238
+ if (predicatesElement && predicateFocusable(element))
2239
+ return element;
2240
+ const focusable = createFocusable("first")(element);
2241
+ if (focusable)
2242
+ return focusable;
2243
+ let current = element;
2244
+ while (current && current !== document.documentElement) {
2245
+ const nextSibling = current.nextElementSibling;
2246
+ if (nextSibling) {
2247
+ const focusable2 = createFocusable("first", { predicatesElement: true })(nextSibling);
2248
+ if (focusable2)
2249
+ return focusable2;
2250
+ }
2251
+ current = current.nextElementSibling || current.parentElement;
2252
+ }
2253
+ };
2254
+ case "previous":
2255
+ return (element) => {
2256
+ if (predicatesElement && predicateFocusable(element))
2257
+ return element;
2258
+ let current = element;
2259
+ while (current && current !== document.documentElement) {
2260
+ const previousSibling = current.previousElementSibling;
2261
+ if (previousSibling) {
2262
+ const focusable = createFocusable("last", { predicatesElement: true })(previousSibling);
2263
+ if (focusable)
2264
+ return focusable;
2265
+ }
2266
+ current = current.previousElementSibling || current.parentElement;
2267
+ }
2268
+ };
2269
+ }
2235
2270
  }
2236
2271
  function createComputedStyle(pseudoElement) {
2237
2272
  return (element) => getComputedStyle(element, pseudoElement);
@@ -2796,6 +2831,11 @@ function storeKeyboardTimeMetadata({
2796
2831
  effect(event);
2797
2832
  }
2798
2833
  }, storeDuration = () => {
2834
+ const sequence = api.getSequence();
2835
+ if (!document.body.contains(
2836
+ lazyCollections.at(-1)(sequence).target
2837
+ ))
2838
+ return;
2799
2839
  const request = requestAnimationFrame((timestamp) => {
2800
2840
  if (!getShouldStore())
2801
2841
  return;
@@ -2915,6 +2955,11 @@ function storePointerTimeMetadata(event, api, getShouldStore, setRequest, recogn
2915
2955
  if (getStatus() === "recognized")
2916
2956
  effect(event2);
2917
2957
  }, storeDuration = () => {
2958
+ const sequence = api.getSequence();
2959
+ if (!document.body.contains(
2960
+ lazyCollections.at(-1)(sequence).target
2961
+ ))
2962
+ return;
2918
2963
  const request = requestAnimationFrame((timestamp) => {
2919
2964
  if (!getShouldStore())
2920
2965
  return;
package/lib/index.d.ts CHANGED
@@ -638,7 +638,7 @@ type CreateFocusableOptions = {
638
638
  /**
639
639
  * [Docs](https://baleada.dev/docs/logic/pipes/focusable)
640
640
  */
641
- declare function createFocusable(order: 'first' | 'last', options?: CreateFocusableOptions): ElementTransform<HTMLElement, HTMLElement | undefined>;
641
+ declare function createFocusable(order: 'first' | 'last' | 'next' | 'previous', options?: CreateFocusableOptions): ElementTransform<HTMLElement, HTMLElement | undefined>;
642
642
  /**
643
643
  * [Docs](https://baleada.dev/docs/logic/pipes/computed-style)
644
644
  */
package/lib/index.js CHANGED
@@ -2210,26 +2210,61 @@ const defaultOptions$d = {
2210
2210
  };
2211
2211
  function createFocusable(order, options = {}) {
2212
2212
  const { predicatesElement, tabbableSelector } = { ...defaultOptions$d, ...options }, predicateFocusable = (element) => element.matches(tabbableSelector);
2213
- return (element) => {
2214
- if (predicatesElement && predicateFocusable(element))
2215
- return element;
2216
- switch (order) {
2217
- case "first":
2213
+ switch (order) {
2214
+ case "first":
2215
+ return (element) => {
2216
+ if (predicatesElement && predicateFocusable(element))
2217
+ return element;
2218
2218
  for (let i = 0; i < element.children.length; i++) {
2219
2219
  const focusable = createFocusable(order, { predicatesElement: true })(element.children[i]);
2220
2220
  if (focusable)
2221
2221
  return focusable;
2222
2222
  }
2223
- break;
2224
- case "last":
2223
+ };
2224
+ case "last":
2225
+ return (element) => {
2226
+ if (predicatesElement && predicateFocusable(element))
2227
+ return element;
2225
2228
  for (let i = element.children.length - 1; i > -1; i--) {
2226
2229
  const focusable = createFocusable(order, { predicatesElement: true })(element.children[i]);
2227
2230
  if (focusable)
2228
2231
  return focusable;
2229
2232
  }
2230
- break;
2231
- }
2232
- };
2233
+ };
2234
+ case "next":
2235
+ return (element) => {
2236
+ if (predicatesElement && predicateFocusable(element))
2237
+ return element;
2238
+ const focusable = createFocusable("first")(element);
2239
+ if (focusable)
2240
+ return focusable;
2241
+ let current = element;
2242
+ while (current && current !== document.documentElement) {
2243
+ const nextSibling = current.nextElementSibling;
2244
+ if (nextSibling) {
2245
+ const focusable2 = createFocusable("first", { predicatesElement: true })(nextSibling);
2246
+ if (focusable2)
2247
+ return focusable2;
2248
+ }
2249
+ current = current.nextElementSibling || current.parentElement;
2250
+ }
2251
+ };
2252
+ case "previous":
2253
+ return (element) => {
2254
+ if (predicatesElement && predicateFocusable(element))
2255
+ return element;
2256
+ let current = element;
2257
+ while (current && current !== document.documentElement) {
2258
+ const previousSibling = current.previousElementSibling;
2259
+ if (previousSibling) {
2260
+ const focusable = createFocusable("last", { predicatesElement: true })(previousSibling);
2261
+ if (focusable)
2262
+ return focusable;
2263
+ }
2264
+ current = current.previousElementSibling || current.parentElement;
2265
+ }
2266
+ };
2267
+ }
2233
2268
  }
2234
2269
  function createComputedStyle(pseudoElement) {
2235
2270
  return (element) => getComputedStyle(element, pseudoElement);
@@ -2794,6 +2829,11 @@ function storeKeyboardTimeMetadata({
2794
2829
  effect(event);
2795
2830
  }
2796
2831
  }, storeDuration = () => {
2832
+ const sequence = api.getSequence();
2833
+ if (!document.body.contains(
2834
+ at(-1)(sequence).target
2835
+ ))
2836
+ return;
2797
2837
  const request = requestAnimationFrame((timestamp) => {
2798
2838
  if (!getShouldStore())
2799
2839
  return;
@@ -2913,6 +2953,11 @@ function storePointerTimeMetadata(event, api, getShouldStore, setRequest, recogn
2913
2953
  if (getStatus() === "recognized")
2914
2954
  effect(event2);
2915
2955
  }, storeDuration = () => {
2956
+ const sequence = api.getSequence();
2957
+ if (!document.body.contains(
2958
+ at(-1)(sequence).target
2959
+ ))
2960
+ return;
2916
2961
  const request = requestAnimationFrame((timestamp) => {
2917
2962
  if (!getShouldStore())
2918
2963
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baleada/logic",
3
- "version": "0.24.10",
3
+ "version": "0.24.12",
4
4
  "description": "UI logic for the Baleada toolkit",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.js",