// @bun
var __create = Object.create;
var __getProtoOf = Object.getPrototypeOf;
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __hasOwnProp = Object.prototype.hasOwnProperty;
function __accessProp(key) {
  return this[key];
}
var __toESMCache_node;
var __toESMCache_esm;
var __toESM = (mod, isNodeMode, target) => {
  var canCache = mod != null && typeof mod === "object";
  if (canCache) {
    var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
    var cached = cache.get(mod);
    if (cached)
      return cached;
  }
  target = mod != null ? __create(__getProtoOf(mod)) : {};
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
  for (let key of __getOwnPropNames(mod))
    if (!__hasOwnProp.call(to, key))
      __defProp(to, key, {
        get: __accessProp.bind(mod, key),
        enumerable: true
      });
  if (canCache)
    cache.set(mod, to);
  return to;
};
var __toCommonJS = (from) => {
  var entry = (__moduleCache ??= new WeakMap).get(from), desc;
  if (entry)
    return entry;
  entry = __defProp({}, "__esModule", { value: true });
  if (from && typeof from === "object" || typeof from === "function") {
    for (var key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(entry, key))
        __defProp(entry, key, {
          get: __accessProp.bind(from, key),
          enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
        });
  }
  __moduleCache.set(from, entry);
  return entry;
};
var __moduleCache;
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
var __returnValue = (v) => v;
function __exportSetter(name, newValue) {
  this[name] = __returnValue.bind(null, newValue);
}
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, {
      get: all[name],
      enumerable: true,
      configurable: true,
      set: __exportSetter.bind(all, name)
    });
};
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
    r = Reflect.decorate(decorators, target, key, desc);
  else
    for (var i = decorators.length - 1;i >= 0; i--)
      if (d = decorators[i])
        r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __legacyMetadataTS = (k, v) => {
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
    return Reflect.metadata(k, v);
};
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
var __require = import.meta.require;
// src/react/hooks/useIslandStore.ts
import { useSyncExternalStore } from "react";

// node_modules/zustand/esm/vanilla.mjs
var createStoreImpl = (createState) => {
  let state;
  const listeners = /* @__PURE__ */ new Set;
  const setState = (partial, replace) => {
    const nextState = typeof partial === "function" ? partial(state) : partial;
    if (!Object.is(nextState, state)) {
      const previousState = state;
      state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
      listeners.forEach((listener) => listener(state, previousState));
    }
  };
  const getState = () => state;
  const getInitialState = () => initialState;
  const subscribe = (listener) => {
    listeners.add(listener);
    return () => listeners.delete(listener);
  };
  const api = { setState, getState, getInitialState, subscribe };
  const initialState = state = createState(setState, getState, api);
  return api;
};
var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;

// node_modules/zustand/esm/middleware.mjs
function combine(initialState, create) {
  return (...args) => Object.assign({}, initialState, create(...args));
}

// src/client/islandStore.ts
var getIslandStoreSnapshot = () => {
  globalThis.__ABS_ISLAND_STATE__ ??= {};
  return globalThis.__ABS_ISLAND_STATE__;
};
var getIslandStores = () => {
  globalThis.__ABS_ISLAND_STORES__ ??= new Map;
  return globalThis.__ABS_ISLAND_STORES__;
};
var isSerializableValue = (value) => typeof value !== "function" && value !== undefined;
var toSerializableState = (state) => Object.fromEntries(Object.entries(state).filter(([, value]) => isSerializableValue(value)));
var applySnapshot = (store, snapshot) => {
  if (!snapshot) {
    return;
  }
  store.setState({
    ...store.getState(),
    ...snapshot
  });
};
var getPeerStores = (storeInstances, ownerStore) => [...storeInstances].filter((peer) => peer.store !== ownerStore);
var syncIslandSnapshot = (storeId, state, storeInstances, ownerStore) => {
  const nextSnapshot = toSerializableState(state);
  getIslandStoreSnapshot()[storeId] = nextSnapshot;
  for (const peerStore of getPeerStores(storeInstances, ownerStore)) {
    peerStore.applyExternalSnapshot(nextSnapshot);
  }
};
var createIslandStore = (storeId, initialState, createState) => {
  const store = createStore(combine(initialState, createState));
  const stores = getIslandStores();
  const storeInstances = stores.get(storeId) ?? new Set;
  const initialSnapshot = getIslandStoreSnapshot()[storeId];
  applySnapshot(store, initialSnapshot);
  let isApplyingExternalSnapshot = false;
  const applyExternalSnapshot = (snapshot) => {
    isApplyingExternalSnapshot = true;
    applySnapshot(store, snapshot);
  };
  storeInstances.add({
    applyExternalSnapshot,
    store
  });
  stores.set(storeId, storeInstances);
  syncIslandSnapshot(storeId, store.getState(), storeInstances, store);
  store.subscribe((state) => {
    if (isApplyingExternalSnapshot) {
      isApplyingExternalSnapshot = false;
      return;
    }
    syncIslandSnapshot(storeId, state, storeInstances, store);
  });
  return store;
};
var getIslandStoreServerSnapshot = (store, selector) => selector(store.getInitialState());
var applySnapshotToStoreInstances = (storeId, instances, snapshot) => {
  for (const instance of instances) {
    instance.applyExternalSnapshot(snapshot[storeId] ?? {});
  }
};
var initializeIslandStores = (state) => {
  const currentSnapshot = getIslandStoreSnapshot();
  const nextSnapshot = {
    ...state,
    ...currentSnapshot
  };
  globalThis.__ABS_ISLAND_STATE__ = nextSnapshot;
  for (const [storeId, store] of getIslandStores()) {
    applySnapshotToStoreInstances(storeId, store, nextSnapshot);
  }
};
var readIslandStore = (store, selector) => selector(store.getState());
var subscribeIslandStore = (store, selector, listener) => {
  let currentSelection = selector(store.getState());
  return store.subscribe((state) => {
    const nextSelection = selector(state);
    if (Object.is(nextSelection, currentSelection)) {
      return;
    }
    currentSelection = nextSelection;
    listener(nextSelection);
  });
};

// src/react/hooks/useIslandStore.ts
var useIslandStore = (store, selector) => useSyncExternalStore((listener) => subscribeIslandStore(store, selector, () => {
  listener();
}), () => readIslandStore(store, selector), () => getIslandStoreServerSnapshot(store, selector));
// src/react/hooks/useMediaQuery.ts
import { createContext, useContext, useSyncExternalStore as useSyncExternalStore2 } from "react";
var UserAgentContext = createContext(null);
var UserAgentProvider = UserAgentContext.Provider;
var useUserAgentType = () => {
  const context = useContext(UserAgentContext);
  if (context === null) {
    throw new Error("useMediaQuery must be used within a UserAgentProvider");
  }
  return context;
};
var defaultBreakpoints = {
  "2xl": 1536,
  lg: 1024,
  md: 768,
  sm: 640,
  xl: 1280,
  xs: 0
};
var userAgentInitialWidth = {
  bot: 1024,
  car: 768,
  console: 1024,
  desktop: 1024,
  iot: 640,
  other: 768,
  phone: 375,
  tablet: 768,
  tv: 1280
};
var subscribers = new Set;
var width = typeof window !== "undefined" ? window.innerWidth : 0;
var isListening = false;
var ensureListener = () => {
  if (isListening || typeof window === "undefined")
    return;
  isListening = true;
  let isTicking = false;
  const onResize = () => {
    if (isTicking)
      return;
    isTicking = true;
    requestAnimationFrame(() => {
      isTicking = false;
      width = window.innerWidth;
      subscribers.forEach((notify) => notify());
    });
  };
  window.addEventListener("resize", onResize, { passive: true });
};
var subscribe = (callback) => {
  ensureListener();
  subscribers.add(callback);
  return () => subscribers.delete(callback);
};
var getViewportWidth = () => width;
var computeBreakpoint = (widthValue, breakpoints) => {
  if (widthValue < breakpoints.sm)
    return "xs";
  if (widthValue < breakpoints.md)
    return "sm";
  if (widthValue < breakpoints.lg)
    return "md";
  if (widthValue < breakpoints.xl)
    return "lg";
  if (widthValue < breakpoints["2xl"])
    return "xl";
  return "2xl";
};
var useMediaQuery = (customBreakpoints = defaultBreakpoints) => {
  const userAgentType = useUserAgentType();
  const getServerWidth = () => userAgentInitialWidth[userAgentType];
  const currentWidth = useSyncExternalStore2(subscribe, getViewportWidth, getServerWidth);
  const breakpoint = computeBreakpoint(currentWidth, customBreakpoints);
  const isSizeOrGreater = (target) => customBreakpoints[breakpoint] >= customBreakpoints[target];
  const isSizeOrLess = (target) => customBreakpoints[breakpoint] <= customBreakpoints[target];
  return { breakpoint, isSizeOrGreater, isSizeOrLess };
};
export {
  useMediaQuery,
  useIslandStore,
  UserAgentProvider
};

//# debugId=EE8269F258A5BD9764756E2164756E21
//# sourceMappingURL=index.js.map
