@kbach/react 0.3.8 → 0.3.10

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.
@@ -8,7 +8,7 @@ import {
8
8
  resolve,
9
9
  useConditionalWidth,
10
10
  useGlobalDarkMode
11
- } from "./chunk-WYY3PRRC.mjs";
11
+ } from "./chunk-LZYPVC5K.mjs";
12
12
 
13
13
  // src/jsx-runtime.tsx
14
14
  import { jsx as _jsx, jsxs as _jsxs, Fragment } from "react/jsx-runtime";
@@ -2040,12 +2040,10 @@ function resolve(classString, theme, darkMode = "attribute") {
2040
2040
  }
2041
2041
  }
2042
2042
  styleCache.set(cacheKey, result);
2043
- if (isWeb && injectQueue.length > 0) {
2044
- Promise.resolve().then(() => {
2045
- for (const { cls, bucketKey, styles } of injectQueue) {
2046
- injectClassRule(cls, bucketKey, styles, darkMode);
2047
- }
2048
- });
2043
+ if (isWeb) {
2044
+ for (const { cls, bucketKey, styles } of injectQueue) {
2045
+ injectClassRule(cls, bucketKey, styles, darkMode);
2046
+ }
2049
2047
  }
2050
2048
  return result;
2051
2049
  }
@@ -2319,13 +2317,45 @@ var NOOP_SUB = (_) => () => {
2319
2317
  };
2320
2318
  var ZERO_SNAP = () => 0;
2321
2319
  var EMPTY_BREAKPOINTS = /* @__PURE__ */ new Set();
2320
+ var _webListeners = null;
2321
+ var _webRaf = 0;
2322
+ function _webResizeHandler() {
2323
+ cancelAnimationFrame(_webRaf);
2324
+ _webRaf = requestAnimationFrame(() => {
2325
+ if (_webListeners) for (const cb of _webListeners) cb();
2326
+ });
2327
+ }
2328
+ function subscribeWebWidth(cb) {
2329
+ if (typeof window === "undefined") return () => {
2330
+ };
2331
+ if (!_webListeners) {
2332
+ _webListeners = /* @__PURE__ */ new Set();
2333
+ window.addEventListener("resize", _webResizeHandler);
2334
+ }
2335
+ _webListeners.add(cb);
2336
+ return () => {
2337
+ _webListeners.delete(cb);
2338
+ if (_webListeners.size === 0) {
2339
+ window.removeEventListener("resize", _webResizeHandler);
2340
+ cancelAnimationFrame(_webRaf);
2341
+ _webListeners = null;
2342
+ }
2343
+ };
2344
+ }
2345
+ function getWebWidth() {
2346
+ return typeof window !== "undefined" ? window.innerWidth : 0;
2347
+ }
2322
2348
  function useGlobalWidth() {
2323
- return useSyncExternalStore2(subscribeGlobalWidth, getGlobalWidth, ZERO_SNAP);
2349
+ return useSyncExternalStore2(
2350
+ isWeb ? subscribeWebWidth : subscribeGlobalWidth,
2351
+ isWeb ? getWebWidth : getGlobalWidth,
2352
+ ZERO_SNAP
2353
+ );
2324
2354
  }
2325
2355
  function useConditionalWidth(active) {
2326
2356
  return useSyncExternalStore2(
2327
- active ? subscribeGlobalWidth : NOOP_SUB,
2328
- active ? getGlobalWidth : ZERO_SNAP,
2357
+ active ? isWeb ? subscribeWebWidth : subscribeGlobalWidth : NOOP_SUB,
2358
+ active ? isWeb ? getWebWidth : getGlobalWidth : ZERO_SNAP,
2329
2359
  ZERO_SNAP
2330
2360
  );
2331
2361
  }
package/dist/index.js CHANGED
@@ -2170,12 +2170,10 @@ function resolve(classString, theme, darkMode = "attribute") {
2170
2170
  }
2171
2171
  }
2172
2172
  styleCache.set(cacheKey, result);
2173
- if (isWeb && injectQueue.length > 0) {
2174
- Promise.resolve().then(() => {
2175
- for (const { cls, bucketKey, styles } of injectQueue) {
2176
- injectClassRule(cls, bucketKey, styles, darkMode);
2177
- }
2178
- });
2173
+ if (isWeb) {
2174
+ for (const { cls, bucketKey, styles } of injectQueue) {
2175
+ injectClassRule(cls, bucketKey, styles, darkMode);
2176
+ }
2179
2177
  }
2180
2178
  return result;
2181
2179
  }
@@ -2764,13 +2762,45 @@ var NOOP_SUB = (_) => () => {
2764
2762
  };
2765
2763
  var ZERO_SNAP = () => 0;
2766
2764
  var EMPTY_BREAKPOINTS = /* @__PURE__ */ new Set();
2765
+ var _webListeners = null;
2766
+ var _webRaf = 0;
2767
+ function _webResizeHandler() {
2768
+ cancelAnimationFrame(_webRaf);
2769
+ _webRaf = requestAnimationFrame(() => {
2770
+ if (_webListeners) for (const cb of _webListeners) cb();
2771
+ });
2772
+ }
2773
+ function subscribeWebWidth(cb) {
2774
+ if (typeof window === "undefined") return () => {
2775
+ };
2776
+ if (!_webListeners) {
2777
+ _webListeners = /* @__PURE__ */ new Set();
2778
+ window.addEventListener("resize", _webResizeHandler);
2779
+ }
2780
+ _webListeners.add(cb);
2781
+ return () => {
2782
+ _webListeners.delete(cb);
2783
+ if (_webListeners.size === 0) {
2784
+ window.removeEventListener("resize", _webResizeHandler);
2785
+ cancelAnimationFrame(_webRaf);
2786
+ _webListeners = null;
2787
+ }
2788
+ };
2789
+ }
2790
+ function getWebWidth() {
2791
+ return typeof window !== "undefined" ? window.innerWidth : 0;
2792
+ }
2767
2793
  function useGlobalWidth() {
2768
- return useSyncExternalStore(subscribeGlobalWidth, getGlobalWidth, ZERO_SNAP);
2794
+ return useSyncExternalStore(
2795
+ isWeb ? subscribeWebWidth : subscribeGlobalWidth,
2796
+ isWeb ? getWebWidth : getGlobalWidth,
2797
+ ZERO_SNAP
2798
+ );
2769
2799
  }
2770
2800
  function useConditionalWidth(active) {
2771
2801
  return useSyncExternalStore(
2772
- active ? subscribeGlobalWidth : NOOP_SUB,
2773
- active ? getGlobalWidth : ZERO_SNAP,
2802
+ active ? isWeb ? subscribeWebWidth : subscribeGlobalWidth : NOOP_SUB,
2803
+ active ? isWeb ? getWebWidth : getGlobalWidth : ZERO_SNAP,
2774
2804
  ZERO_SNAP
2775
2805
  );
2776
2806
  }
package/dist/index.mjs CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  updateConfig,
22
22
  useGlobalDarkMode,
23
23
  useGlobalWidth
24
- } from "./chunk-WYY3PRRC.mjs";
24
+ } from "./chunk-LZYPVC5K.mjs";
25
25
 
26
26
  // src/context.tsx
27
27
  import { createContext, useContext } from "react";
@@ -2061,12 +2061,10 @@ function resolve(classString, theme, darkMode = "attribute") {
2061
2061
  }
2062
2062
  }
2063
2063
  styleCache.set(cacheKey, result);
2064
- if (isWeb && injectQueue.length > 0) {
2065
- Promise.resolve().then(() => {
2066
- for (const { cls, bucketKey, styles } of injectQueue) {
2067
- injectClassRule(cls, bucketKey, styles, darkMode);
2068
- }
2069
- });
2064
+ if (isWeb) {
2065
+ for (const { cls, bucketKey, styles } of injectQueue) {
2066
+ injectClassRule(cls, bucketKey, styles, darkMode);
2067
+ }
2070
2068
  }
2071
2069
  return result;
2072
2070
  }
@@ -2309,10 +2307,38 @@ var NOOP_SUB = (_) => () => {
2309
2307
  };
2310
2308
  var ZERO_SNAP = () => 0;
2311
2309
  var EMPTY_BREAKPOINTS = /* @__PURE__ */ new Set();
2310
+ var _webListeners = null;
2311
+ var _webRaf = 0;
2312
+ function _webResizeHandler() {
2313
+ cancelAnimationFrame(_webRaf);
2314
+ _webRaf = requestAnimationFrame(() => {
2315
+ if (_webListeners) for (const cb of _webListeners) cb();
2316
+ });
2317
+ }
2318
+ function subscribeWebWidth(cb) {
2319
+ if (typeof window === "undefined") return () => {
2320
+ };
2321
+ if (!_webListeners) {
2322
+ _webListeners = /* @__PURE__ */ new Set();
2323
+ window.addEventListener("resize", _webResizeHandler);
2324
+ }
2325
+ _webListeners.add(cb);
2326
+ return () => {
2327
+ _webListeners.delete(cb);
2328
+ if (_webListeners.size === 0) {
2329
+ window.removeEventListener("resize", _webResizeHandler);
2330
+ cancelAnimationFrame(_webRaf);
2331
+ _webListeners = null;
2332
+ }
2333
+ };
2334
+ }
2335
+ function getWebWidth() {
2336
+ return typeof window !== "undefined" ? window.innerWidth : 0;
2337
+ }
2312
2338
  function useConditionalWidth(active) {
2313
2339
  return useSyncExternalStore2(
2314
- active ? subscribeGlobalWidth : NOOP_SUB,
2315
- active ? getGlobalWidth : ZERO_SNAP,
2340
+ active ? isWeb ? subscribeWebWidth : subscribeGlobalWidth : NOOP_SUB,
2341
+ active ? isWeb ? getWebWidth : getGlobalWidth : ZERO_SNAP,
2316
2342
  ZERO_SNAP
2317
2343
  );
2318
2344
  }
@@ -2,8 +2,8 @@ import {
2
2
  Fragment,
3
3
  jsx,
4
4
  jsxs
5
- } from "./chunk-H5232HHF.mjs";
6
- import "./chunk-WYY3PRRC.mjs";
5
+ } from "./chunk-3AMSZMOL.mjs";
6
+ import "./chunk-LZYPVC5K.mjs";
7
7
 
8
8
  // src/jsx-dev-runtime.tsx
9
9
  function jsxDEV(type, props, key, isStaticChildren, _source, _self) {
@@ -2060,12 +2060,10 @@ function resolve(classString, theme, darkMode = "attribute") {
2060
2060
  }
2061
2061
  }
2062
2062
  styleCache.set(cacheKey, result);
2063
- if (isWeb && injectQueue.length > 0) {
2064
- Promise.resolve().then(() => {
2065
- for (const { cls, bucketKey, styles } of injectQueue) {
2066
- injectClassRule(cls, bucketKey, styles, darkMode);
2067
- }
2068
- });
2063
+ if (isWeb) {
2064
+ for (const { cls, bucketKey, styles } of injectQueue) {
2065
+ injectClassRule(cls, bucketKey, styles, darkMode);
2066
+ }
2069
2067
  }
2070
2068
  return result;
2071
2069
  }
@@ -2308,10 +2306,38 @@ var NOOP_SUB = (_) => () => {
2308
2306
  };
2309
2307
  var ZERO_SNAP = () => 0;
2310
2308
  var EMPTY_BREAKPOINTS = /* @__PURE__ */ new Set();
2309
+ var _webListeners = null;
2310
+ var _webRaf = 0;
2311
+ function _webResizeHandler() {
2312
+ cancelAnimationFrame(_webRaf);
2313
+ _webRaf = requestAnimationFrame(() => {
2314
+ if (_webListeners) for (const cb of _webListeners) cb();
2315
+ });
2316
+ }
2317
+ function subscribeWebWidth(cb) {
2318
+ if (typeof window === "undefined") return () => {
2319
+ };
2320
+ if (!_webListeners) {
2321
+ _webListeners = /* @__PURE__ */ new Set();
2322
+ window.addEventListener("resize", _webResizeHandler);
2323
+ }
2324
+ _webListeners.add(cb);
2325
+ return () => {
2326
+ _webListeners.delete(cb);
2327
+ if (_webListeners.size === 0) {
2328
+ window.removeEventListener("resize", _webResizeHandler);
2329
+ cancelAnimationFrame(_webRaf);
2330
+ _webListeners = null;
2331
+ }
2332
+ };
2333
+ }
2334
+ function getWebWidth() {
2335
+ return typeof window !== "undefined" ? window.innerWidth : 0;
2336
+ }
2311
2337
  function useConditionalWidth(active) {
2312
2338
  return useSyncExternalStore2(
2313
- active ? subscribeGlobalWidth : NOOP_SUB,
2314
- active ? getGlobalWidth : ZERO_SNAP,
2339
+ active ? isWeb ? subscribeWebWidth : subscribeGlobalWidth : NOOP_SUB,
2340
+ active ? isWeb ? getWebWidth : getGlobalWidth : ZERO_SNAP,
2315
2341
  ZERO_SNAP
2316
2342
  );
2317
2343
  }
@@ -2,8 +2,8 @@ import {
2
2
  Fragment,
3
3
  jsx,
4
4
  jsxs
5
- } from "./chunk-H5232HHF.mjs";
6
- import "./chunk-WYY3PRRC.mjs";
5
+ } from "./chunk-3AMSZMOL.mjs";
6
+ import "./chunk-LZYPVC5K.mjs";
7
7
  export {
8
8
  Fragment,
9
9
  jsx,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbach/react",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "React / React Native components and hooks for the Kbach framework",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",