@ai-matrx/kit 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.
Files changed (118) hide show
  1. package/CHANGELOG.md +132 -0
  2. package/LICENSE +21 -0
  3. package/README.md +72 -0
  4. package/dist/autosave.cjs +92 -0
  5. package/dist/autosave.cjs.map +1 -0
  6. package/dist/autosave.d.cts +17 -0
  7. package/dist/autosave.d.ts +17 -0
  8. package/dist/autosave.js +72 -0
  9. package/dist/autosave.js.map +1 -0
  10. package/dist/clipboard.cjs +152 -0
  11. package/dist/clipboard.cjs.map +1 -0
  12. package/dist/clipboard.d.cts +17 -0
  13. package/dist/clipboard.d.ts +17 -0
  14. package/dist/clipboard.js +132 -0
  15. package/dist/clipboard.js.map +1 -0
  16. package/dist/color-util.cjs +790 -0
  17. package/dist/color-util.cjs.map +1 -0
  18. package/dist/color-util.d.cts +235 -0
  19. package/dist/color-util.d.ts +235 -0
  20. package/dist/color-util.js +767 -0
  21. package/dist/color-util.js.map +1 -0
  22. package/dist/concurrency.cjs +59 -0
  23. package/dist/concurrency.cjs.map +1 -0
  24. package/dist/concurrency.d.cts +19 -0
  25. package/dist/concurrency.d.ts +19 -0
  26. package/dist/concurrency.js +38 -0
  27. package/dist/concurrency.js.map +1 -0
  28. package/dist/confirm.cjs +344 -0
  29. package/dist/confirm.cjs.map +1 -0
  30. package/dist/confirm.d.cts +132 -0
  31. package/dist/confirm.d.ts +132 -0
  32. package/dist/confirm.js +312 -0
  33. package/dist/confirm.js.map +1 -0
  34. package/dist/delimiter-guard.cjs +172 -0
  35. package/dist/delimiter-guard.cjs.map +1 -0
  36. package/dist/delimiter-guard.d.cts +119 -0
  37. package/dist/delimiter-guard.d.ts +119 -0
  38. package/dist/delimiter-guard.js +151 -0
  39. package/dist/delimiter-guard.js.map +1 -0
  40. package/dist/drafts.cjs +223 -0
  41. package/dist/drafts.cjs.map +1 -0
  42. package/dist/drafts.d.cts +62 -0
  43. package/dist/drafts.d.ts +62 -0
  44. package/dist/drafts.js +201 -0
  45. package/dist/drafts.js.map +1 -0
  46. package/dist/idb-store.cjs +178 -0
  47. package/dist/idb-store.cjs.map +1 -0
  48. package/dist/idb-store.d.cts +111 -0
  49. package/dist/idb-store.d.ts +111 -0
  50. package/dist/idb-store.js +155 -0
  51. package/dist/idb-store.js.map +1 -0
  52. package/dist/idle-scheduler.cjs +268 -0
  53. package/dist/idle-scheduler.cjs.map +1 -0
  54. package/dist/idle-scheduler.d.cts +185 -0
  55. package/dist/idle-scheduler.d.ts +185 -0
  56. package/dist/idle-scheduler.js +246 -0
  57. package/dist/idle-scheduler.js.map +1 -0
  58. package/dist/index.cjs +3113 -0
  59. package/dist/index.cjs.map +1 -0
  60. package/dist/index.d.cts +897 -0
  61. package/dist/index.d.ts +897 -0
  62. package/dist/index.js +3088 -0
  63. package/dist/index.js.map +1 -0
  64. package/dist/invalidation.cjs +64 -0
  65. package/dist/invalidation.cjs.map +1 -0
  66. package/dist/invalidation.d.cts +52 -0
  67. package/dist/invalidation.d.ts +52 -0
  68. package/dist/invalidation.js +43 -0
  69. package/dist/invalidation.js.map +1 -0
  70. package/dist/json-format.cjs +319 -0
  71. package/dist/json-format.cjs.map +1 -0
  72. package/dist/json-format.d.cts +148 -0
  73. package/dist/json-format.d.ts +148 -0
  74. package/dist/json-format.js +286 -0
  75. package/dist/json-format.js.map +1 -0
  76. package/dist/latest-request.cjs +36 -0
  77. package/dist/latest-request.cjs.map +1 -0
  78. package/dist/latest-request.d.cts +29 -0
  79. package/dist/latest-request.d.ts +29 -0
  80. package/dist/latest-request.js +16 -0
  81. package/dist/latest-request.js.map +1 -0
  82. package/dist/qr.cjs +109 -0
  83. package/dist/qr.cjs.map +1 -0
  84. package/dist/qr.d.cts +47 -0
  85. package/dist/qr.d.ts +47 -0
  86. package/dist/qr.js +78 -0
  87. package/dist/qr.js.map +1 -0
  88. package/dist/react-tree.cjs +69 -0
  89. package/dist/react-tree.cjs.map +1 -0
  90. package/dist/react-tree.d.cts +38 -0
  91. package/dist/react-tree.d.ts +38 -0
  92. package/dist/react-tree.js +38 -0
  93. package/dist/react-tree.js.map +1 -0
  94. package/dist/search-scoring.cjs +116 -0
  95. package/dist/search-scoring.cjs.map +1 -0
  96. package/dist/search-scoring.d.cts +77 -0
  97. package/dist/search-scoring.d.ts +77 -0
  98. package/dist/search-scoring.js +95 -0
  99. package/dist/search-scoring.js.map +1 -0
  100. package/dist/text-case.cjs +313 -0
  101. package/dist/text-case.cjs.map +1 -0
  102. package/dist/text-case.d.cts +53 -0
  103. package/dist/text-case.d.ts +53 -0
  104. package/dist/text-case.js +292 -0
  105. package/dist/text-case.js.map +1 -0
  106. package/dist/toast.cjs +74 -0
  107. package/dist/toast.cjs.map +1 -0
  108. package/dist/toast.d.cts +92 -0
  109. package/dist/toast.d.ts +92 -0
  110. package/dist/toast.js +54 -0
  111. package/dist/toast.js.map +1 -0
  112. package/dist/url-state.cjs +212 -0
  113. package/dist/url-state.cjs.map +1 -0
  114. package/dist/url-state.d.cts +90 -0
  115. package/dist/url-state.d.ts +90 -0
  116. package/dist/url-state.js +199 -0
  117. package/dist/url-state.js.map +1 -0
  118. package/package.json +286 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/url-state.ts"],"sourcesContent":["\"use client\";\n\n/**\n * @ai-matrx/kit/url-state — THE canonical URL-state core. Every surface that\n * puts view state in the address bar goes through here.\n *\n * The URL is the source of truth: refresh, copied links, and browser\n * back/forward all reproduce the same value. Discrete controls push a history\n * entry by default; high-frequency text inputs opt into `replace` so a single\n * search does not create one entry per keystroke.\n *\n * WHY A RAW `history.pushState` IS A BUG, not just a style choice. It fires no\n * event and no popstate, so every OTHER url-backed control on the page keeps\n * rendering stale values until something unrelated re-renders it.\n * `commitUrlParams` dispatches `matrx:url-state`, which is what\n * `useUrlSearchParams` subscribes to. (Measured in the Matrx frontend,\n * 2026-08-25: 33 hand-rolled writes across 21 files, every one of them\n * silent.)\n *\n * PICK THE RIGHT ONE:\n * one control owns one parameter → `useUrlState` + a codec\n * a cluster of values moving together → `useMirroredUrlState`\n *\n * Codecs below cover string / enum / boolean / positive-integer / JSON, and all\n * of them OMIT the default rather than writing it, so a pristine surface has a\n * clean URL and a link carries only what the user actually chose.\n *\n * Ported verbatim from matrx-frontend `lib/url-state/useUrlState.ts`. The\n * original deliberately imports NOTHING from `next/navigation` — it writes\n * through the History API and notifies subscribers itself, which is exactly\n * how it runs in the Next.js App Router host. This port adds ONE optional\n * seam on top of that verbatim behavior: `setUrlStateRouter` lets a host whose\n * router must observe/perform the writes (react-router, a memory router in\n * tests, a native shell) inject `{ push, replace, getLocation? }`. With no\n * router injected — the default, and the Next.js wiring — behavior is\n * byte-identical to the original. The injected router lives on `globalThis`\n * under `Symbol.for(\"ai-matrx.kit.url-state-router\")` because the package\n * builds `splitting: false` dual ESM/CJS: module-level state would silently\n * split the registration across bundle graphs (the confirm-opener hazard).\n */\n\nimport {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\n\nconst URL_STATE_EVENT = \"matrx:url-state\";\n\n/**\n * The optional injected router. `push`/`replace` receive the full relative\n * URL (`pathname?query#hash`) exactly as the History API default would write\n * it. `getLocation` overrides where the current URL is read from (a memory\n * router); absent, `window.location` is read.\n */\nexport interface UrlStateRouter {\n push: (url: string) => void;\n replace: (url: string) => void;\n getLocation?: (() => { pathname: string; search: string; hash: string }) | undefined;\n}\n\nconst ROUTER_SLOT = Symbol.for(\"ai-matrx.kit.url-state-router\");\n\nfunction getRouter(): UrlStateRouter | null {\n return (\n (globalThis as Record<symbol, UrlStateRouter | null | undefined>)[\n ROUTER_SLOT\n ] ?? null\n );\n}\n\n/**\n * Inject (or with `null` remove) the host router. Optional — with none set,\n * writes go through `window.history` push/replaceState, which is the verbatim\n * Matrx-frontend behavior and correct for Next.js App Router hosts.\n */\nexport function setUrlStateRouter(router: UrlStateRouter | null): void {\n (globalThis as Record<symbol, UrlStateRouter | null | undefined>)[\n ROUTER_SLOT\n ] = router;\n}\n\nfunction currentLocation(): { pathname: string; search: string; hash: string } {\n const custom = getRouter()?.getLocation;\n if (custom) return custom();\n return {\n pathname: window.location.pathname,\n search: window.location.search,\n hash: window.location.hash,\n };\n}\n\nfunction subscribeToUrl(listener: () => void) {\n window.addEventListener(\"popstate\", listener);\n window.addEventListener(URL_STATE_EVENT, listener);\n return () => {\n window.removeEventListener(\"popstate\", listener);\n window.removeEventListener(URL_STATE_EVENT, listener);\n };\n}\n\nfunction getUrlSnapshot() {\n return currentLocation().search;\n}\n\nfunction getServerUrlSnapshot() {\n return \"\";\n}\n\n/** Reactive query-string snapshot for URL-backed primitives. */\nexport function useUrlSearchParams(): URLSearchParams {\n const search = useSyncExternalStore(\n subscribeToUrl,\n getUrlSnapshot,\n getServerUrlSnapshot,\n );\n return useMemo(() => new URLSearchParams(search), [search]);\n}\n\nexport type UrlHistoryMode = \"push\" | \"replace\";\n\nexport interface UrlStateCodec<T> {\n defaultValue: T;\n parse: (raw: string | null) => T;\n serialize: (value: T) => string | null;\n}\n\nexport interface SetUrlStateOptions {\n history?: UrlHistoryMode | undefined;\n}\n\nexport function commitUrlParams(\n patch: Readonly<Record<string, string | null>>,\n history: UrlHistoryMode,\n) {\n const location = currentLocation();\n const params = new URLSearchParams(location.search);\n for (const [key, value] of Object.entries(patch)) {\n if (value === null || value === \"\") params.delete(key);\n else params.set(key, value);\n }\n\n const query = params.toString();\n const next = `${location.pathname}${query ? `?${query}` : \"\"}${location.hash}`;\n const current = `${location.pathname}${location.search}${location.hash}`;\n if (next === current) return;\n\n const router = getRouter();\n if (router) {\n if (history === \"replace\") router.replace(next);\n else router.push(next);\n } else if (history === \"replace\") {\n window.history.replaceState(window.history.state, \"\", next);\n } else {\n window.history.pushState(window.history.state, \"\", next);\n }\n window.dispatchEvent(new Event(URL_STATE_EVENT));\n}\n\n/**\n * Classify a URL transition for surfaces that MIRROR state (a store, local\n * state) into the URL from an effect, where there is no single call site to\n * label.\n *\n * THE RULE: a discrete user decision (tab, filter, sort, page, selection)\n * PUSHES, so Back undoes exactly that one step; only high-frequency text\n * (`textKeys` — search boxes, a slider being dragged) REPLACES, so one search\n * is one entry instead of one per keystroke.\n */\nexport function historyModeForParamChange(\n current: URLSearchParams,\n next: URLSearchParams,\n textKeys: readonly string[],\n): UrlHistoryMode {\n const keys = new Set([...current.keys(), ...next.keys()]);\n const changed = [...keys].filter(\n (key) => current.get(key) !== next.get(key),\n );\n if (changed.length === 0) return \"replace\";\n return changed.every((key) => textKeys.includes(key)) ? \"replace\" : \"push\";\n}\n\nexport function useUrlState<T>(\n key: string,\n codec: UrlStateCodec<T>,\n): readonly [T, (value: T, options?: SetUrlStateOptions) => void] {\n const searchParams = useUrlSearchParams();\n const value = codec.parse(searchParams.get(key));\n\n const setValue = (next: T, options?: SetUrlStateOptions) => {\n commitUrlParams(\n { [key]: codec.serialize(next) },\n options?.history ?? \"push\",\n );\n };\n\n return [value, setValue] as const;\n}\n\nexport function stringUrlCodec(defaultValue = \"\"): UrlStateCodec<string> {\n return {\n defaultValue,\n parse: (raw) => raw ?? defaultValue,\n serialize: (value) => (value === defaultValue ? null : value),\n };\n}\n\nexport function enumUrlCodec<const T extends string>(\n values: readonly T[],\n defaultValue: T,\n): UrlStateCodec<T> {\n const allowed = new Set<string>(values);\n return {\n defaultValue,\n parse: (raw) => (raw && allowed.has(raw) ? (raw as T) : defaultValue),\n serialize: (value) => (value === defaultValue ? null : value),\n };\n}\n\nexport function booleanUrlCodec(defaultValue = false): UrlStateCodec<boolean> {\n return {\n defaultValue,\n parse: (raw) => (raw === null ? defaultValue : raw === \"1\"),\n serialize: (value) => (value === defaultValue ? null : value ? \"1\" : \"0\"),\n };\n}\n\nexport function positiveIntegerUrlCodec(\n defaultValue: number,\n): UrlStateCodec<number> {\n return {\n defaultValue,\n parse: (raw) => {\n const parsed = raw ? Number.parseInt(raw, 10) : Number.NaN;\n return Number.isFinite(parsed) && parsed > 0 ? parsed : defaultValue;\n },\n serialize: (value) =>\n value === defaultValue || !Number.isFinite(value) || value <= 0\n ? null\n : String(Math.trunc(value)),\n };\n}\n\nexport function jsonUrlCodec<T>(\n defaultValue: T,\n isValid: (value: unknown) => value is T,\n): UrlStateCodec<T> {\n return {\n defaultValue,\n parse: (raw) => {\n if (!raw) return defaultValue;\n try {\n const parsed: unknown = JSON.parse(raw);\n return isValid(parsed) ? parsed : defaultValue;\n } catch {\n return defaultValue;\n }\n },\n serialize: (value) =>\n JSON.stringify(value) === JSON.stringify(defaultValue)\n ? null\n : JSON.stringify(value),\n };\n}\n\n/**\n * Mirror a whole view-state OBJECT into the URL, in both directions.\n *\n * THE PATTERN 18 FILES WERE HAND-ROLLING. `useUrlState` is right when one\n * control owns one parameter. It is the wrong shape when a surface holds a\n * cluster of related values (search + sort + filters + page) that must move\n * together, be seeded from the URL on first render, and follow Back/Forward.\n * Every surface that needed that wrote its own `history.pushState` — and NONE\n * of them dispatched the sync event, so any other URL-backed control on the\n * same page silently kept showing stale values after they wrote.\n *\n * 🚨 THE LOOP IS BROKEN BY VALUE, NEVER BY BOOKKEEPING. The obvious guard —\n * remember the last URL you wrote and ignore anything matching it — looks\n * equivalent and is not: pressing Forward to a view already visited produces a\n * URL you did indeed write before, so the guard swallows it and the address bar\n * moves while the surface does not. Compare the DECODED value to the current\n * one instead; your own write compares equal and stops.\n *\n * Seeding happens in the `useState` initialiser, not an effect, so the first\n * render already shows the requested view rather than flashing the default and\n * fetching the wrong page before correcting itself.\n */\nexport interface MirroredUrlStateOptions<T> {\n /** Decode the whole value from the query string. Must never throw. */\n parse: (params: URLSearchParams) => T;\n /** Encode it; `null` for a key means \"omit\", which keeps defaults out of the URL. */\n toParams: (value: T) => Record<string, string | null>;\n /** Value equality — what stops the two directions fighting. */\n isSame: (a: T, b: T) => boolean;\n /** Keys that REPLACE instead of pushing (search boxes, dragged sliders). */\n textKeys?: readonly string[] | undefined;\n /**\n * Changing this clears the mirrored state and its parameters — for when the\n * surface switches to a different subject and the old view would be a lie.\n */\n resetKey?: string | undefined;\n}\n\nexport function useMirroredUrlState<T>(\n options: MirroredUrlStateOptions<T>,\n): readonly [T, (updater: T | ((prev: T) => T)) => void] {\n const { parse, toParams, isSame, textKeys = [], resetKey } = options;\n const params = useUrlSearchParams();\n\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n const [value, setValue] = useState<T>(() =>\n parse(\n typeof window === \"undefined\"\n ? new URLSearchParams()\n : new URLSearchParams(currentLocation().search),\n ),\n );\n\n // value → URL\n useEffect(() => {\n if (typeof window === \"undefined\") return;\n const current = new URLSearchParams(currentLocation().search);\n const patch = optionsRef.current.toParams(value);\n\n const next = new URLSearchParams(current);\n for (const [key, v] of Object.entries(patch)) {\n if (v === null || v === \"\") next.delete(key);\n else next.set(key, v);\n }\n if (next.toString() === current.toString()) return;\n\n commitUrlParams(patch, historyModeForParamChange(current, next, textKeys));\n // `textKeys` is a literal in every caller; `value` is the real trigger.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [value]);\n\n // URL → value (Back/Forward, a pasted link, another control writing)\n useEffect(() => {\n // Read the URL at EFFECT time, not the render snapshot. The value→URL\n // effect runs first. When it commits a local filter/sort decision it\n // synchronously notifies the external store, but `params` in this render\n // still describes the URL from before that write. Re-applying that stale\n // snapshot here ping-pongs state and URL until React raises #185.\n const fromUrl = optionsRef.current.parse(\n new URLSearchParams(currentLocation().search),\n );\n setValue((prev) => (optionsRef.current.isSame(prev, fromUrl) ? prev : fromUrl));\n }, [params]);\n\n // Clearing on a subject change is deliberate; clearing on a subject ARRIVING\n // is destructive. A surface whose id is undefined for its first render (async\n // params, a late store hydration, a suspended boundary) would otherwise wipe\n // the very view the user just loaded — and the symptom is indistinguishable\n // from \"the URL never saved my filters\", because the write lands and is\n // erased a tick later.\n //\n // So: only a transition between two REAL, DIFFERENT keys resets.\n const previousResetKey = useRef(resetKey);\n useEffect(() => {\n const previous = previousResetKey.current;\n previousResetKey.current = resetKey;\n if (previous === resetKey) return;\n if (previous === undefined || previous === \"\") return; // arriving, not changing\n if (resetKey === undefined || resetKey === \"\") return; // leaving, not changing\n\n const cleared = optionsRef.current.parse(new URLSearchParams());\n setValue(cleared);\n commitUrlParams(optionsRef.current.toParams(cleared), \"replace\");\n }, [resetKey]);\n\n const update = useCallback((updater: T | ((prev: T) => T)) => {\n setValue((prev) =>\n typeof updater === \"function\"\n ? (updater as (p: T) => T)(prev)\n : updater,\n );\n }, []);\n\n return [value, update] as const;\n}\n"],"mappings":";;;;AAyCA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,IAAM,kBAAkB;AAcxB,IAAM,cAAc,uBAAO,IAAI,+BAA+B;AAE9D,SAAS,YAAmC;AAC1C,SACG,WACC,WACF,KAAK;AAET;AAOO,SAAS,kBAAkB,QAAqC;AACrE,EAAC,WACC,WACF,IAAI;AACN;AAEA,SAAS,kBAAsE;AAC7E,QAAM,SAAS,UAAU,GAAG;AAC5B,MAAI,OAAQ,QAAO,OAAO;AAC1B,SAAO;AAAA,IACL,UAAU,OAAO,SAAS;AAAA,IAC1B,QAAQ,OAAO,SAAS;AAAA,IACxB,MAAM,OAAO,SAAS;AAAA,EACxB;AACF;AAEA,SAAS,eAAe,UAAsB;AAC5C,SAAO,iBAAiB,YAAY,QAAQ;AAC5C,SAAO,iBAAiB,iBAAiB,QAAQ;AACjD,SAAO,MAAM;AACX,WAAO,oBAAoB,YAAY,QAAQ;AAC/C,WAAO,oBAAoB,iBAAiB,QAAQ;AAAA,EACtD;AACF;AAEA,SAAS,iBAAiB;AACxB,SAAO,gBAAgB,EAAE;AAC3B;AAEA,SAAS,uBAAuB;AAC9B,SAAO;AACT;AAGO,SAAS,qBAAsC;AACpD,QAAM,SAAS;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO,QAAQ,MAAM,IAAI,gBAAgB,MAAM,GAAG,CAAC,MAAM,CAAC;A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AACA,aAAS,CAAC,SAAU,WAAW,QAAQ,OAAO,MAAM,OAAO,IAAI,OAAO,OAAQ;AAAA,EAChF,GAAG,CAAC,MAAM,CAAC;AAUX,QAAM,mBAAmB,OAAO,QAAQ;AACxC,YAAU,MAAM;AACd,UAAM,WAAW,iBAAiB;AAClC,qBAAiB,UAAU;AAC3B,QAAI,aAAa,SAAU;AAC3B,QAAI,aAAa,UAAa,aAAa,GAAI;AAC/C,QAAI,aAAa,UAAa,aAAa,GAAI;AAE/C,UAAM,UAAU,WAAW,QAAQ,MAAM,IAAI,gBAAgB,CAAC;AAC9D,aAAS,OAAO;AAChB,oBAAgB,WAAW,QAAQ,SAAS,OAAO,GAAG,SAAS;AAAA,EACjE,GAAG,CAAC,QAAQ,CAAC;AAEb,QAAM,SAAS,YAAY,CAAC,YAAkC;AAC5D;AAAA,MAAS,CAAC,SACR,OAAO,YAAY,aACd,QAAwB,IAAI,IAC7B;AAAA,IACN;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO,CAAC,OAAO,MAAM;AACvB;","names":[]}
package/package.json ADDED
@@ -0,0 +1,286 @@
1
+ {
2
+ "name": "@ai-matrx/kit",
3
+ "version": "0.5.0",
4
+ "description": "The always-include AI Matrx kit: the little primitives every Matrx app speaks — autosave that never loses a keystroke, stale-response guards, clipboard with graceful fallbacks — one per subpath, tree-shaken to what you use.",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "license": "MIT",
10
+ "keywords": [
11
+ "react",
12
+ "hooks",
13
+ "autosave",
14
+ "clipboard",
15
+ "confirm-dialog",
16
+ "toast",
17
+ "ai-matrx",
18
+ "url-state",
19
+ "json",
20
+ "idle-callback",
21
+ "markdown-streaming",
22
+ "indexeddb",
23
+ "tailwind-colors",
24
+ "qr-code"
25
+ ],
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/AI-Matrix-Engine/aidream.git",
29
+ "directory": "apps/shared/kit"
30
+ },
31
+ "homepage": "https://github.com/AI-Matrix-Engine/aidream/tree/main/apps/shared/kit#readme",
32
+ "bugs": {
33
+ "url": "https://github.com/AI-Matrix-Engine/aidream/issues"
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "README.md",
38
+ "LICENSE",
39
+ "CHANGELOG.md"
40
+ ],
41
+ "exports": {
42
+ ".": {
43
+ "import": {
44
+ "types": "./dist/index.d.ts",
45
+ "default": "./dist/index.js"
46
+ },
47
+ "require": {
48
+ "types": "./dist/index.d.cts",
49
+ "default": "./dist/index.cjs"
50
+ }
51
+ },
52
+ "./autosave": {
53
+ "import": {
54
+ "types": "./dist/autosave.d.ts",
55
+ "default": "./dist/autosave.js"
56
+ },
57
+ "require": {
58
+ "types": "./dist/autosave.d.cts",
59
+ "default": "./dist/autosave.cjs"
60
+ }
61
+ },
62
+ "./latest-request": {
63
+ "import": {
64
+ "types": "./dist/latest-request.d.ts",
65
+ "default": "./dist/latest-request.js"
66
+ },
67
+ "require": {
68
+ "types": "./dist/latest-request.d.cts",
69
+ "default": "./dist/latest-request.cjs"
70
+ }
71
+ },
72
+ "./clipboard": {
73
+ "import": {
74
+ "types": "./dist/clipboard.d.ts",
75
+ "default": "./dist/clipboard.js"
76
+ },
77
+ "require": {
78
+ "types": "./dist/clipboard.d.cts",
79
+ "default": "./dist/clipboard.cjs"
80
+ }
81
+ },
82
+ "./package.json": "./package.json",
83
+ "./search-scoring": {
84
+ "import": {
85
+ "types": "./dist/search-scoring.d.ts",
86
+ "default": "./dist/search-scoring.js"
87
+ },
88
+ "require": {
89
+ "types": "./dist/search-scoring.d.cts",
90
+ "default": "./dist/search-scoring.cjs"
91
+ }
92
+ },
93
+ "./concurrency": {
94
+ "import": {
95
+ "types": "./dist/concurrency.d.ts",
96
+ "default": "./dist/concurrency.js"
97
+ },
98
+ "require": {
99
+ "types": "./dist/concurrency.d.cts",
100
+ "default": "./dist/concurrency.cjs"
101
+ }
102
+ },
103
+ "./text-case": {
104
+ "import": {
105
+ "types": "./dist/text-case.d.ts",
106
+ "default": "./dist/text-case.js"
107
+ },
108
+ "require": {
109
+ "types": "./dist/text-case.d.cts",
110
+ "default": "./dist/text-case.cjs"
111
+ }
112
+ },
113
+ "./drafts": {
114
+ "import": {
115
+ "types": "./dist/drafts.d.ts",
116
+ "default": "./dist/drafts.js"
117
+ },
118
+ "require": {
119
+ "types": "./dist/drafts.d.cts",
120
+ "default": "./dist/drafts.cjs"
121
+ }
122
+ },
123
+ "./confirm": {
124
+ "import": {
125
+ "types": "./dist/confirm.d.ts",
126
+ "default": "./dist/confirm.js"
127
+ },
128
+ "require": {
129
+ "types": "./dist/confirm.d.cts",
130
+ "default": "./dist/confirm.cjs"
131
+ }
132
+ },
133
+ "./toast": {
134
+ "import": {
135
+ "types": "./dist/toast.d.ts",
136
+ "default": "./dist/toast.js"
137
+ },
138
+ "require": {
139
+ "types": "./dist/toast.d.cts",
140
+ "default": "./dist/toast.cjs"
141
+ }
142
+ },
143
+ "./invalidation": {
144
+ "import": {
145
+ "types": "./dist/invalidation.d.ts",
146
+ "default": "./dist/invalidation.js"
147
+ },
148
+ "require": {
149
+ "types": "./dist/invalidation.d.cts",
150
+ "default": "./dist/invalidation.cjs"
151
+ }
152
+ },
153
+ "./delimiter-guard": {
154
+ "import": {
155
+ "types": "./dist/delimiter-guard.d.ts",
156
+ "default": "./dist/delimiter-guard.js"
157
+ },
158
+ "require": {
159
+ "types": "./dist/delimiter-guard.d.cts",
160
+ "default": "./dist/delimiter-guard.cjs"
161
+ }
162
+ },
163
+ "./json-format": {
164
+ "import": {
165
+ "types": "./dist/json-format.d.ts",
166
+ "default": "./dist/json-format.js"
167
+ },
168
+ "require": {
169
+ "types": "./dist/json-format.d.cts",
170
+ "default": "./dist/json-format.cjs"
171
+ }
172
+ },
173
+ "./idle-scheduler": {
174
+ "import": {
175
+ "types": "./dist/idle-scheduler.d.ts",
176
+ "default": "./dist/idle-scheduler.js"
177
+ },
178
+ "require": {
179
+ "types": "./dist/idle-scheduler.d.cts",
180
+ "default": "./dist/idle-scheduler.cjs"
181
+ }
182
+ },
183
+ "./url-state": {
184
+ "import": {
185
+ "types": "./dist/url-state.d.ts",
186
+ "default": "./dist/url-state.js"
187
+ },
188
+ "require": {
189
+ "types": "./dist/url-state.d.cts",
190
+ "default": "./dist/url-state.cjs"
191
+ }
192
+ },
193
+ "./idb-store": {
194
+ "import": {
195
+ "types": "./dist/idb-store.d.ts",
196
+ "default": "./dist/idb-store.js"
197
+ },
198
+ "require": {
199
+ "types": "./dist/idb-store.d.cts",
200
+ "default": "./dist/idb-store.cjs"
201
+ }
202
+ },
203
+ "./color-util": {
204
+ "import": {
205
+ "types": "./dist/color-util.d.ts",
206
+ "default": "./dist/color-util.js"
207
+ },
208
+ "require": {
209
+ "types": "./dist/color-util.d.cts",
210
+ "default": "./dist/color-util.cjs"
211
+ }
212
+ },
213
+ "./react-tree": {
214
+ "import": {
215
+ "types": "./dist/react-tree.d.ts",
216
+ "default": "./dist/react-tree.js"
217
+ },
218
+ "require": {
219
+ "types": "./dist/react-tree.d.cts",
220
+ "default": "./dist/react-tree.cjs"
221
+ }
222
+ },
223
+ "./qr": {
224
+ "import": {
225
+ "types": "./dist/qr.d.ts",
226
+ "default": "./dist/qr.js"
227
+ },
228
+ "require": {
229
+ "types": "./dist/qr.d.cts",
230
+ "default": "./dist/qr.cjs"
231
+ }
232
+ }
233
+ },
234
+ "dependencies": {
235
+ "@radix-ui/react-alert-dialog": "^1.1.23",
236
+ "idb": "^8.0.3",
237
+ "json5": "^2.2.3",
238
+ "jsqr": "^1.4.0",
239
+ "tailwind-merge": "^3.6.0"
240
+ },
241
+ "peerDependencies": {
242
+ "react": ">=18.0.0",
243
+ "sonner": ">=1.0.0"
244
+ },
245
+ "peerDependenciesMeta": {
246
+ "sonner": {
247
+ "optional": true
248
+ }
249
+ },
250
+ "devDependencies": {
251
+ "@arethetypeswrong/cli": "^0.18.5",
252
+ "@testing-library/react": "^16.3.0",
253
+ "@types/node": "^22.20.0",
254
+ "@types/qrcode": "^1.5.6",
255
+ "@types/react": "^19.1.0",
256
+ "@types/react-dom": "^19.2.3",
257
+ "colord": "^2.10.0",
258
+ "fake-indexeddb": "^6.2.5",
259
+ "jsdom": "^25.0.1",
260
+ "publint": "^0.3.24",
261
+ "qrcode": "^1.5.4",
262
+ "react": "^19.1.0",
263
+ "react-dom": "^19.1.0",
264
+ "sonner": "^2.0.8",
265
+ "tsup": "^8.5.1",
266
+ "typescript": "^5.9.3",
267
+ "vitest": "^4.1.6"
268
+ },
269
+ "publishConfig": {
270
+ "access": "public",
271
+ "registry": "https://registry.npmjs.org/"
272
+ },
273
+ "engines": {
274
+ "node": ">=20"
275
+ },
276
+ "sideEffects": false,
277
+ "scripts": {
278
+ "build": "pnpm clean && tsup",
279
+ "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
280
+ "check:package": "pnpm build && publint && pnpm verify:tarball",
281
+ "typecheck": "tsc -p tsconfig.json --noEmit",
282
+ "test": "vitest run",
283
+ "test:watch": "vitest",
284
+ "verify:tarball": "node ./scripts/verify-tarball.mjs"
285
+ }
286
+ }