@just-web/toolkits 1.0.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 (449) hide show
  1. package/dist/_internal/utils/try-parse-json.cjs +14 -0
  2. package/dist/_internal/utils/try-parse-json.cjs.map +1 -0
  3. package/dist/_internal/utils/try-parse-json.mjs +13 -0
  4. package/dist/_internal/utils/try-parse-json.mjs.map +1 -0
  5. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  6. package/dist/attributes/data-attribute.d.cts +17 -0
  7. package/dist/attributes/data-attribute.d.cts.map +1 -0
  8. package/dist/attributes/data-attribute.d.mts +17 -0
  9. package/dist/attributes/data-attribute.d.mts.map +1 -0
  10. package/dist/attributes/get-attribute.cjs +26 -0
  11. package/dist/attributes/get-attribute.cjs.map +1 -0
  12. package/dist/attributes/get-attribute.d.cts +21 -0
  13. package/dist/attributes/get-attribute.d.cts.map +1 -0
  14. package/dist/attributes/get-attribute.d.mts +21 -0
  15. package/dist/attributes/get-attribute.d.mts.map +1 -0
  16. package/dist/attributes/get-attribute.mjs +25 -0
  17. package/dist/attributes/get-attribute.mjs.map +1 -0
  18. package/dist/attributes/get-data-attribute.cjs +19 -0
  19. package/dist/attributes/get-data-attribute.cjs.map +1 -0
  20. package/dist/attributes/get-data-attribute.d.cts +17 -0
  21. package/dist/attributes/get-data-attribute.d.cts.map +1 -0
  22. package/dist/attributes/get-data-attribute.d.mts +17 -0
  23. package/dist/attributes/get-data-attribute.d.mts.map +1 -0
  24. package/dist/attributes/get-data-attribute.mjs +19 -0
  25. package/dist/attributes/get-data-attribute.mjs.map +1 -0
  26. package/dist/attributes/observe-attribute.cjs +40 -0
  27. package/dist/attributes/observe-attribute.cjs.map +1 -0
  28. package/dist/attributes/observe-attribute.d.cts +23 -0
  29. package/dist/attributes/observe-attribute.d.cts.map +1 -0
  30. package/dist/attributes/observe-attribute.d.mts +23 -0
  31. package/dist/attributes/observe-attribute.d.mts.map +1 -0
  32. package/dist/attributes/observe-attribute.mjs +39 -0
  33. package/dist/attributes/observe-attribute.mjs.map +1 -0
  34. package/dist/attributes/observe-data-attribute.cjs +31 -0
  35. package/dist/attributes/observe-data-attribute.cjs.map +1 -0
  36. package/dist/attributes/observe-data-attribute.d.cts +26 -0
  37. package/dist/attributes/observe-data-attribute.d.cts.map +1 -0
  38. package/dist/attributes/observe-data-attribute.d.mts +26 -0
  39. package/dist/attributes/observe-data-attribute.d.mts.map +1 -0
  40. package/dist/attributes/observe-data-attribute.mjs +31 -0
  41. package/dist/attributes/observe-data-attribute.mjs.map +1 -0
  42. package/dist/children/just-children.d.cts +37 -0
  43. package/dist/children/just-children.d.cts.map +1 -0
  44. package/dist/children/just-children.d.mts +37 -0
  45. package/dist/children/just-children.d.mts.map +1 -0
  46. package/dist/children/resolve-children.cjs +11 -0
  47. package/dist/children/resolve-children.cjs.map +1 -0
  48. package/dist/children/resolve-children.d.cts +9 -0
  49. package/dist/children/resolve-children.d.cts.map +1 -0
  50. package/dist/children/resolve-children.d.mts +9 -0
  51. package/dist/children/resolve-children.d.mts.map +1 -0
  52. package/dist/children/resolve-children.mjs +10 -0
  53. package/dist/children/resolve-children.mjs.map +1 -0
  54. package/dist/class-name/class-name-props.d.cts +11 -0
  55. package/dist/class-name/class-name-props.d.cts.map +1 -0
  56. package/dist/class-name/class-name-props.d.mts +11 -0
  57. package/dist/class-name/class-name-props.d.mts.map +1 -0
  58. package/dist/class-name/clsx.cjs +3 -0
  59. package/dist/class-name/clsx.d.cts +2 -0
  60. package/dist/class-name/clsx.d.mts +2 -0
  61. package/dist/class-name/clsx.mjs +3 -0
  62. package/dist/class-name/just-class-name.d.cts +36 -0
  63. package/dist/class-name/just-class-name.d.cts.map +1 -0
  64. package/dist/class-name/just-class-name.d.mts +36 -0
  65. package/dist/class-name/just-class-name.d.mts.map +1 -0
  66. package/dist/class-name/resolve-class-name.cjs +12 -0
  67. package/dist/class-name/resolve-class-name.cjs.map +1 -0
  68. package/dist/class-name/resolve-class-name.d.cts +8 -0
  69. package/dist/class-name/resolve-class-name.d.cts.map +1 -0
  70. package/dist/class-name/resolve-class-name.d.mts +8 -0
  71. package/dist/class-name/resolve-class-name.d.mts.map +1 -0
  72. package/dist/class-name/resolve-class-name.mjs +10 -0
  73. package/dist/class-name/resolve-class-name.mjs.map +1 -0
  74. package/dist/color-scheme/get-prefers-color-scheme.cjs +21 -0
  75. package/dist/color-scheme/get-prefers-color-scheme.cjs.map +1 -0
  76. package/dist/color-scheme/get-prefers-color-scheme.d.cts +16 -0
  77. package/dist/color-scheme/get-prefers-color-scheme.d.cts.map +1 -0
  78. package/dist/color-scheme/get-prefers-color-scheme.d.mts +16 -0
  79. package/dist/color-scheme/get-prefers-color-scheme.d.mts.map +1 -0
  80. package/dist/color-scheme/get-prefers-color-scheme.mjs +20 -0
  81. package/dist/color-scheme/get-prefers-color-scheme.mjs.map +1 -0
  82. package/dist/color-scheme/observe-prefers-color-scheme.cjs +29 -0
  83. package/dist/color-scheme/observe-prefers-color-scheme.cjs.map +1 -0
  84. package/dist/color-scheme/observe-prefers-color-scheme.d.cts +20 -0
  85. package/dist/color-scheme/observe-prefers-color-scheme.d.cts.map +1 -0
  86. package/dist/color-scheme/observe-prefers-color-scheme.d.mts +20 -0
  87. package/dist/color-scheme/observe-prefers-color-scheme.d.mts.map +1 -0
  88. package/dist/color-scheme/observe-prefers-color-scheme.mjs +28 -0
  89. package/dist/color-scheme/observe-prefers-color-scheme.mjs.map +1 -0
  90. package/dist/index.cjs +39 -0
  91. package/dist/index.d.cts +26 -0
  92. package/dist/index.d.mts +26 -0
  93. package/dist/index.mjs +20 -0
  94. package/dist/react/hooks/use-attribute.cjs +41 -0
  95. package/dist/react/hooks/use-attribute.cjs.map +1 -0
  96. package/dist/react/hooks/use-attribute.d.cts +21 -0
  97. package/dist/react/hooks/use-attribute.d.cts.map +1 -0
  98. package/dist/react/hooks/use-attribute.d.mts +21 -0
  99. package/dist/react/hooks/use-attribute.d.mts.map +1 -0
  100. package/dist/react/hooks/use-attribute.mjs +40 -0
  101. package/dist/react/hooks/use-attribute.mjs.map +1 -0
  102. package/dist/react/hooks/use-prefers-color-scheme.cjs +42 -0
  103. package/dist/react/hooks/use-prefers-color-scheme.cjs.map +1 -0
  104. package/dist/react/hooks/use-prefers-color-scheme.d.cts +29 -0
  105. package/dist/react/hooks/use-prefers-color-scheme.d.cts.map +1 -0
  106. package/dist/react/hooks/use-prefers-color-scheme.d.mts +29 -0
  107. package/dist/react/hooks/use-prefers-color-scheme.d.mts.map +1 -0
  108. package/dist/react/hooks/use-prefers-color-scheme.mjs +41 -0
  109. package/dist/react/hooks/use-prefers-color-scheme.mjs.map +1 -0
  110. package/dist/react/hooks/use-theme-by-class-name.cjs +60 -0
  111. package/dist/react/hooks/use-theme-by-class-name.cjs.map +1 -0
  112. package/dist/react/hooks/use-theme-by-class-name.d.cts +34 -0
  113. package/dist/react/hooks/use-theme-by-class-name.d.cts.map +1 -0
  114. package/dist/react/hooks/use-theme-by-class-name.d.mts +34 -0
  115. package/dist/react/hooks/use-theme-by-class-name.d.mts.map +1 -0
  116. package/dist/react/hooks/use-theme-by-class-name.mjs +59 -0
  117. package/dist/react/hooks/use-theme-by-class-name.mjs.map +1 -0
  118. package/dist/react/hooks/use-theme-by-data-attribute.cjs +73 -0
  119. package/dist/react/hooks/use-theme-by-data-attribute.cjs.map +1 -0
  120. package/dist/react/hooks/use-theme-by-data-attribute.d.cts +39 -0
  121. package/dist/react/hooks/use-theme-by-data-attribute.d.cts.map +1 -0
  122. package/dist/react/hooks/use-theme-by-data-attribute.d.mts +39 -0
  123. package/dist/react/hooks/use-theme-by-data-attribute.d.mts.map +1 -0
  124. package/dist/react/hooks/use-theme-by-data-attribute.mjs +72 -0
  125. package/dist/react/hooks/use-theme-by-data-attribute.mjs.map +1 -0
  126. package/dist/react/hooks/use-theme-by-local-storage.cjs +53 -0
  127. package/dist/react/hooks/use-theme-by-local-storage.cjs.map +1 -0
  128. package/dist/react/hooks/use-theme-by-local-storage.d.cts +37 -0
  129. package/dist/react/hooks/use-theme-by-local-storage.d.cts.map +1 -0
  130. package/dist/react/hooks/use-theme-by-local-storage.d.mts +37 -0
  131. package/dist/react/hooks/use-theme-by-local-storage.d.mts.map +1 -0
  132. package/dist/react/hooks/use-theme-by-local-storage.mjs +52 -0
  133. package/dist/react/hooks/use-theme-by-local-storage.mjs.map +1 -0
  134. package/dist/react/hooks/use-theme-stores.cjs +40 -0
  135. package/dist/react/hooks/use-theme-stores.cjs.map +1 -0
  136. package/dist/react/hooks/use-theme-stores.d.cts +38 -0
  137. package/dist/react/hooks/use-theme-stores.d.cts.map +1 -0
  138. package/dist/react/hooks/use-theme-stores.d.mts +38 -0
  139. package/dist/react/hooks/use-theme-stores.d.mts.map +1 -0
  140. package/dist/react/hooks/use-theme-stores.mjs +39 -0
  141. package/dist/react/hooks/use-theme-stores.mjs.map +1 -0
  142. package/dist/react/theme/create-theme-hook.cjs +105 -0
  143. package/dist/react/theme/create-theme-hook.cjs.map +1 -0
  144. package/dist/react/theme/create-theme-hook.d.cts +29 -0
  145. package/dist/react/theme/create-theme-hook.d.cts.map +1 -0
  146. package/dist/react/theme/create-theme-hook.d.mts +29 -0
  147. package/dist/react/theme/create-theme-hook.d.mts.map +1 -0
  148. package/dist/react/theme/create-theme-hook.mjs +104 -0
  149. package/dist/react/theme/create-theme-hook.mjs.map +1 -0
  150. package/dist/react.cjs +15 -0
  151. package/dist/react.d.cts +8 -0
  152. package/dist/react.d.mts +8 -0
  153. package/dist/react.mjs +9 -0
  154. package/dist/style/css-properties.d.cts +20 -0
  155. package/dist/style/css-properties.d.cts.map +1 -0
  156. package/dist/style/css-properties.d.mts +20 -0
  157. package/dist/style/css-properties.d.mts.map +1 -0
  158. package/dist/style/define-css-properties.cjs +25 -0
  159. package/dist/style/define-css-properties.cjs.map +1 -0
  160. package/dist/style/define-css-properties.d.cts +24 -0
  161. package/dist/style/define-css-properties.d.cts.map +1 -0
  162. package/dist/style/define-css-properties.d.mts +24 -0
  163. package/dist/style/define-css-properties.d.mts.map +1 -0
  164. package/dist/style/define-css-properties.mjs +24 -0
  165. package/dist/style/define-css-properties.mjs.map +1 -0
  166. package/dist/style/get-css-variable-value.cjs +11 -0
  167. package/dist/style/get-css-variable-value.cjs.map +1 -0
  168. package/dist/style/get-css-variable-value.d.cts +22 -0
  169. package/dist/style/get-css-variable-value.d.cts.map +1 -0
  170. package/dist/style/get-css-variable-value.d.mts +22 -0
  171. package/dist/style/get-css-variable-value.d.mts.map +1 -0
  172. package/dist/style/get-css-variable-value.mjs +10 -0
  173. package/dist/style/get-css-variable-value.mjs.map +1 -0
  174. package/dist/style/just-style.d.cts +44 -0
  175. package/dist/style/just-style.d.cts.map +1 -0
  176. package/dist/style/just-style.d.mts +44 -0
  177. package/dist/style/just-style.d.mts.map +1 -0
  178. package/dist/style/resolve-style.cjs +14 -0
  179. package/dist/style/resolve-style.cjs.map +1 -0
  180. package/dist/style/resolve-style.d.cts +11 -0
  181. package/dist/style/resolve-style.d.cts.map +1 -0
  182. package/dist/style/resolve-style.d.mts +11 -0
  183. package/dist/style/resolve-style.d.mts.map +1 -0
  184. package/dist/style/resolve-style.mjs +13 -0
  185. package/dist/style/resolve-style.mjs.map +1 -0
  186. package/dist/style/style-props.d.cts +13 -0
  187. package/dist/style/style-props.d.cts.map +1 -0
  188. package/dist/style/style-props.d.mts +13 -0
  189. package/dist/style/style-props.d.mts.map +1 -0
  190. package/dist/style/to-dom-style.cjs +33 -0
  191. package/dist/style/to-dom-style.cjs.map +1 -0
  192. package/dist/style/to-dom-style.d.cts +29 -0
  193. package/dist/style/to-dom-style.d.cts.map +1 -0
  194. package/dist/style/to-dom-style.d.mts +29 -0
  195. package/dist/style/to-dom-style.d.mts.map +1 -0
  196. package/dist/style/to-dom-style.mjs +32 -0
  197. package/dist/style/to-dom-style.mjs.map +1 -0
  198. package/dist/testing/theme/dummy-theme-store.cjs +11 -0
  199. package/dist/testing/theme/dummy-theme-store.cjs.map +1 -0
  200. package/dist/testing/theme/dummy-theme-store.mjs +10 -0
  201. package/dist/testing/theme/dummy-theme-store.mjs.map +1 -0
  202. package/dist/theme/_utils/get-theme-from-stores.cjs +24 -0
  203. package/dist/theme/_utils/get-theme-from-stores.cjs.map +1 -0
  204. package/dist/theme/_utils/get-theme-from-stores.mjs +23 -0
  205. package/dist/theme/_utils/get-theme-from-stores.mjs.map +1 -0
  206. package/dist/theme/_utils/observe-theme-from-stores.cjs +39 -0
  207. package/dist/theme/_utils/observe-theme-from-stores.cjs.map +1 -0
  208. package/dist/theme/_utils/observe-theme-from-stores.mjs +39 -0
  209. package/dist/theme/_utils/observe-theme-from-stores.mjs.map +1 -0
  210. package/dist/theme/_utils/parse-stored-theme.cjs +22 -0
  211. package/dist/theme/_utils/parse-stored-theme.cjs.map +1 -0
  212. package/dist/theme/_utils/parse-stored-theme.mjs +22 -0
  213. package/dist/theme/_utils/parse-stored-theme.mjs.map +1 -0
  214. package/dist/theme/_utils/set-theme-to-stores.cjs +16 -0
  215. package/dist/theme/_utils/set-theme-to-stores.cjs.map +1 -0
  216. package/dist/theme/_utils/set-theme-to-stores.mjs +15 -0
  217. package/dist/theme/_utils/set-theme-to-stores.mjs.map +1 -0
  218. package/dist/theme/class-name/apply-theme-to-class-name.cjs +23 -0
  219. package/dist/theme/class-name/apply-theme-to-class-name.cjs.map +1 -0
  220. package/dist/theme/class-name/apply-theme-to-class-name.mjs +22 -0
  221. package/dist/theme/class-name/apply-theme-to-class-name.mjs.map +1 -0
  222. package/dist/theme/class-name/resolve-theme-from-class-name.cjs +23 -0
  223. package/dist/theme/class-name/resolve-theme-from-class-name.cjs.map +1 -0
  224. package/dist/theme/class-name/resolve-theme-from-class-name.mjs +22 -0
  225. package/dist/theme/class-name/resolve-theme-from-class-name.mjs.map +1 -0
  226. package/dist/theme/compose-theme-stores.cjs +74 -0
  227. package/dist/theme/compose-theme-stores.cjs.map +1 -0
  228. package/dist/theme/compose-theme-stores.d.cts +33 -0
  229. package/dist/theme/compose-theme-stores.d.cts.map +1 -0
  230. package/dist/theme/compose-theme-stores.d.mts +33 -0
  231. package/dist/theme/compose-theme-stores.d.mts.map +1 -0
  232. package/dist/theme/compose-theme-stores.mjs +74 -0
  233. package/dist/theme/compose-theme-stores.mjs.map +1 -0
  234. package/dist/theme/data-attribute/apply-theme-to-data-attribute.cjs +23 -0
  235. package/dist/theme/data-attribute/apply-theme-to-data-attribute.cjs.map +1 -0
  236. package/dist/theme/data-attribute/apply-theme-to-data-attribute.mjs +22 -0
  237. package/dist/theme/data-attribute/apply-theme-to-data-attribute.mjs.map +1 -0
  238. package/dist/theme/data-attribute/resolve-theme-from-data-attribute.cjs +23 -0
  239. package/dist/theme/data-attribute/resolve-theme-from-data-attribute.cjs.map +1 -0
  240. package/dist/theme/data-attribute/resolve-theme-from-data-attribute.mjs +22 -0
  241. package/dist/theme/data-attribute/resolve-theme-from-data-attribute.mjs.map +1 -0
  242. package/dist/theme/theme-entry.cjs +13 -0
  243. package/dist/theme/theme-entry.cjs.map +1 -0
  244. package/dist/theme/theme-entry.d.cts +9 -0
  245. package/dist/theme/theme-entry.d.cts.map +1 -0
  246. package/dist/theme/theme-entry.d.mts +9 -0
  247. package/dist/theme/theme-entry.d.mts.map +1 -0
  248. package/dist/theme/theme-entry.mjs +12 -0
  249. package/dist/theme/theme-entry.mjs.map +1 -0
  250. package/dist/theme/theme-entry.types.d.cts +16 -0
  251. package/dist/theme/theme-entry.types.d.cts.map +1 -0
  252. package/dist/theme/theme-entry.types.d.mts +16 -0
  253. package/dist/theme/theme-entry.types.d.mts.map +1 -0
  254. package/dist/theme/theme-map.types.d.cts +10 -0
  255. package/dist/theme/theme-map.types.d.cts.map +1 -0
  256. package/dist/theme/theme-map.types.d.mts +10 -0
  257. package/dist/theme/theme-map.types.d.mts.map +1 -0
  258. package/dist/theme/theme-store/async-theme-store.types.d.cts +25 -0
  259. package/dist/theme/theme-store/async-theme-store.types.d.cts.map +1 -0
  260. package/dist/theme/theme-store/async-theme-store.types.d.mts +25 -0
  261. package/dist/theme/theme-store/async-theme-store.types.d.mts.map +1 -0
  262. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.cjs +53 -0
  263. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.cjs.map +1 -0
  264. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.cts +28 -0
  265. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.cts.map +1 -0
  266. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.mts +28 -0
  267. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.d.mts.map +1 -0
  268. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.mjs +53 -0
  269. package/dist/theme/theme-store/class-name-theme-store/class-name-theme-store.mjs.map +1 -0
  270. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.cjs +121 -0
  271. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.cjs.map +1 -0
  272. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.cts +65 -0
  273. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.cts.map +1 -0
  274. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.mts +65 -0
  275. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.d.mts.map +1 -0
  276. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.mjs +120 -0
  277. package/dist/theme/theme-store/cookie-theme-store/cookie-theme-store.mjs.map +1 -0
  278. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.cjs +51 -0
  279. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.cjs.map +1 -0
  280. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.cts +30 -0
  281. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.cts.map +1 -0
  282. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.mts +30 -0
  283. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.d.mts.map +1 -0
  284. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.mjs +51 -0
  285. package/dist/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.mjs.map +1 -0
  286. package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.cjs +54 -0
  287. package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.cjs.map +1 -0
  288. package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.d.cts +31 -0
  289. package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.d.cts.map +1 -0
  290. package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.d.mts +31 -0
  291. package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.d.mts.map +1 -0
  292. package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.mjs +54 -0
  293. package/dist/theme/theme-store/in-memory-theme-store/in-memory-theme-store.mjs.map +1 -0
  294. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.cjs +67 -0
  295. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.cjs.map +1 -0
  296. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.cts +34 -0
  297. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.cts.map +1 -0
  298. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.mts +34 -0
  299. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.d.mts.map +1 -0
  300. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.mjs +67 -0
  301. package/dist/theme/theme-store/local-storage-theme-store/local-storage-theme-store.mjs.map +1 -0
  302. package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.cjs +39 -0
  303. package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.cjs.map +1 -0
  304. package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.d.cts +32 -0
  305. package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.d.cts.map +1 -0
  306. package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.d.mts +32 -0
  307. package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.d.mts.map +1 -0
  308. package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.mjs +39 -0
  309. package/dist/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.mjs.map +1 -0
  310. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.cjs +67 -0
  311. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.cjs.map +1 -0
  312. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.cts +34 -0
  313. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.cts.map +1 -0
  314. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.mts +34 -0
  315. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.d.mts.map +1 -0
  316. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.mjs +67 -0
  317. package/dist/theme/theme-store/session-storage-theme-store/session-storage-theme-store.mjs.map +1 -0
  318. package/dist/theme/theme-store/theme-store-factory.types.d.cts +10 -0
  319. package/dist/theme/theme-store/theme-store-factory.types.d.cts.map +1 -0
  320. package/dist/theme/theme-store/theme-store-factory.types.d.mts +10 -0
  321. package/dist/theme/theme-store/theme-store-factory.types.d.mts.map +1 -0
  322. package/dist/theme/theme-store/theme-store.types.d.cts +33 -0
  323. package/dist/theme/theme-store/theme-store.types.d.cts.map +1 -0
  324. package/dist/theme/theme-store/theme-store.types.d.mts +33 -0
  325. package/dist/theme/theme-store/theme-store.types.d.mts.map +1 -0
  326. package/dist/theme.cjs +20 -0
  327. package/dist/theme.d.cts +15 -0
  328. package/dist/theme.d.mts +15 -0
  329. package/dist/theme.mjs +11 -0
  330. package/dist/units/get-rem-to-px-scale.cjs +30 -0
  331. package/dist/units/get-rem-to-px-scale.cjs.map +1 -0
  332. package/dist/units/get-rem-to-px-scale.d.cts +21 -0
  333. package/dist/units/get-rem-to-px-scale.d.cts.map +1 -0
  334. package/dist/units/get-rem-to-px-scale.d.mts +21 -0
  335. package/dist/units/get-rem-to-px-scale.d.mts.map +1 -0
  336. package/dist/units/get-rem-to-px-scale.mjs +29 -0
  337. package/dist/units/get-rem-to-px-scale.mjs.map +1 -0
  338. package/dist/units/px-2-num.cjs +23 -0
  339. package/dist/units/px-2-num.cjs.map +1 -0
  340. package/dist/units/px-2-num.d.cts +19 -0
  341. package/dist/units/px-2-num.d.cts.map +1 -0
  342. package/dist/units/px-2-num.d.mts +19 -0
  343. package/dist/units/px-2-num.d.mts.map +1 -0
  344. package/dist/units/px-2-num.mjs +22 -0
  345. package/dist/units/px-2-num.mjs.map +1 -0
  346. package/dist/units/px-2-rem.cjs +31 -0
  347. package/dist/units/px-2-rem.cjs.map +1 -0
  348. package/dist/units/px-2-rem.d.cts +25 -0
  349. package/dist/units/px-2-rem.d.cts.map +1 -0
  350. package/dist/units/px-2-rem.d.mts +25 -0
  351. package/dist/units/px-2-rem.d.mts.map +1 -0
  352. package/dist/units/px-2-rem.mjs +30 -0
  353. package/dist/units/px-2-rem.mjs.map +1 -0
  354. package/dist/units/rem-2-px.cjs +31 -0
  355. package/dist/units/rem-2-px.cjs.map +1 -0
  356. package/dist/units/rem-2-px.d.cts +25 -0
  357. package/dist/units/rem-2-px.d.cts.map +1 -0
  358. package/dist/units/rem-2-px.d.mts +25 -0
  359. package/dist/units/rem-2-px.d.mts.map +1 -0
  360. package/dist/units/rem-2-px.mjs +30 -0
  361. package/dist/units/rem-2-px.mjs.map +1 -0
  362. package/dist/utils/append-id.cjs +16 -0
  363. package/dist/utils/append-id.cjs.map +1 -0
  364. package/dist/utils/append-id.d.cts +12 -0
  365. package/dist/utils/append-id.d.cts.map +1 -0
  366. package/dist/utils/append-id.d.mts +12 -0
  367. package/dist/utils/append-id.d.mts.map +1 -0
  368. package/dist/utils/append-id.mjs +15 -0
  369. package/dist/utils/append-id.mjs.map +1 -0
  370. package/package.json +120 -0
  371. package/readme.md +15 -0
  372. package/src/_internal/utils/try-parse-json.ts +8 -0
  373. package/src/attributes/data-attribute.ts +49 -0
  374. package/src/attributes/get-attribute.ts +20 -0
  375. package/src/attributes/get-data-attribute.ts +15 -0
  376. package/src/attributes/observe-attribute.ts +37 -0
  377. package/src/attributes/observe-data-attribute.ts +29 -0
  378. package/src/children/just-children-fn-props.editor.default.tsx +29 -0
  379. package/src/children/just-children-props.editor.default.tsx +17 -0
  380. package/src/children/just-children.editor.default.tsx +11 -0
  381. package/src/children/just-children.ts +37 -0
  382. package/src/children/resolve-children.ts +16 -0
  383. package/src/class-name/class-name-props.editor.tsx +13 -0
  384. package/src/class-name/class-name-props.ts +7 -0
  385. package/src/class-name/clsx.ts +3 -0
  386. package/src/class-name/just-class-name-props.editor.default.tsx +23 -0
  387. package/src/class-name/just-class-name-resolver-state.editor.default.tsx +18 -0
  388. package/src/class-name/just-class-name.editor.default-class-name.tsx +28 -0
  389. package/src/class-name/just-class-name.editor.default.tsx +14 -0
  390. package/src/class-name/just-class-name.editor.type-param.tsx +25 -0
  391. package/src/class-name/just-class-name.ts +36 -0
  392. package/src/class-name/resolve-class-name.ts +12 -0
  393. package/src/color-scheme/get-prefers-color-scheme.ts +17 -0
  394. package/src/color-scheme/observe-prefers-color-scheme.ts +24 -0
  395. package/src/index.ts +25 -0
  396. package/src/react/hooks/use-attribute.ts +59 -0
  397. package/src/react/hooks/use-prefers-color-scheme.ts +42 -0
  398. package/src/react/hooks/use-theme-by-class-name.ts +69 -0
  399. package/src/react/hooks/use-theme-by-data-attribute.ts +84 -0
  400. package/src/react/hooks/use-theme-by-local-storage.ts +68 -0
  401. package/src/react/hooks/use-theme-stores.ts +83 -0
  402. package/src/react/theme/create-theme-hook.ts +197 -0
  403. package/src/react.ts +7 -0
  404. package/src/style/css-properties.ts +20 -0
  405. package/src/style/define-css-properties.ts +23 -0
  406. package/src/style/get-css-variable-value.ts +32 -0
  407. package/src/style/just-style-props.editor.default.tsx +17 -0
  408. package/src/style/just-style-resolver-state.editor.default.tsx +22 -0
  409. package/src/style/just-style.editor.default.tsx +17 -0
  410. package/src/style/just-style.editor.type-param.tsx +31 -0
  411. package/src/style/just-style.ts +60 -0
  412. package/src/style/resolve-style.ts +23 -0
  413. package/src/style/style-props.editor.tsx +13 -0
  414. package/src/style/style-props.ts +8 -0
  415. package/src/style/to-dom-style.ts +36 -0
  416. package/src/testing/button.theme.ts +21 -0
  417. package/src/testing/button.tsx +11 -0
  418. package/src/testing/log-panel.tsx +14 -0
  419. package/src/testing/theme/dummy-theme-store.ts +7 -0
  420. package/src/testing/theme/theme-result-card.tsx +43 -0
  421. package/src/testing/theme/theme-store-demo.tsx +87 -0
  422. package/src/theme/_utils/get-theme-from-stores.ts +34 -0
  423. package/src/theme/_utils/observe-theme-from-stores.ts +57 -0
  424. package/src/theme/_utils/parse-stored-theme.ts +21 -0
  425. package/src/theme/_utils/set-theme-to-stores.ts +23 -0
  426. package/src/theme/class-name/apply-theme-to-class-name.ts +26 -0
  427. package/src/theme/class-name/resolve-theme-from-class-name.ts +22 -0
  428. package/src/theme/compose-theme-stores.ts +139 -0
  429. package/src/theme/data-attribute/apply-theme-to-data-attribute.ts +27 -0
  430. package/src/theme/data-attribute/resolve-theme-from-data-attribute.ts +23 -0
  431. package/src/theme/theme-entry.ts +10 -0
  432. package/src/theme/theme-entry.types.ts +11 -0
  433. package/src/theme/theme-map.types.ts +6 -0
  434. package/src/theme/theme-store/async-theme-store.types.ts +24 -0
  435. package/src/theme/theme-store/class-name-theme-store/class-name-theme-store.ts +62 -0
  436. package/src/theme/theme-store/cookie-theme-store/cookie-theme-store.ts +174 -0
  437. package/src/theme/theme-store/data-attribute-theme-store/data-attribute-theme-store.ts +60 -0
  438. package/src/theme/theme-store/in-memory-theme-store/in-memory-theme-store.ts +54 -0
  439. package/src/theme/theme-store/local-storage-theme-store/local-storage-theme-store.ts +83 -0
  440. package/src/theme/theme-store/prefers-color-scheme-theme-store/prefers-color-scheme-theme-store.ts +43 -0
  441. package/src/theme/theme-store/session-storage-theme-store/session-storage-theme-store.ts +83 -0
  442. package/src/theme/theme-store/theme-store-factory.types.ts +9 -0
  443. package/src/theme/theme-store/theme-store.types.ts +30 -0
  444. package/src/theme.ts +14 -0
  445. package/src/units/get-rem-to-px-scale.ts +27 -0
  446. package/src/units/px-2-num.ts +17 -0
  447. package/src/units/px-2-rem.ts +30 -0
  448. package/src/units/rem-2-px.ts +30 -0
  449. package/src/utils/append-id.ts +10 -0
@@ -0,0 +1,25 @@
1
+ //#region src/units/rem-2-px.d.ts
2
+ /**
3
+ * Converts rem values to pixel units.
4
+ *
5
+ * @param rem - The rem value to convert. Can be a number or string (e.g. '1rem' or '1')
6
+ * @param options - Optional configuration
7
+ * @param options.base - Base pixel value to calculate pixels from. Defaults to 16
8
+ * @param options.precision - Number of decimal places in the output. Defaults to 4
9
+ * @returns The converted value as a string with 'px' units
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * rem2px(1) // '16.0000'
14
+ * rem2px('2rem') // '32.0000'
15
+ * rem2px(1, { base: 20 }) // '20.0000'
16
+ * rem2px(0.8125, { precision: 2 }) // '13.00'
17
+ * ```
18
+ */
19
+ declare function rem2px(rem: number | string, options?: {
20
+ base?: number | undefined;
21
+ precision?: number | undefined;
22
+ }): number;
23
+ //#endregion
24
+ export { rem2px };
25
+ //# sourceMappingURL=rem-2-px.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rem-2-px.d.mts","names":[],"sources":["../../src/units/rem-2-px.ts"],"sourcesContent":[],"mappings":";;AAiBA;;;;;;;;;;;;;;;;iBAAgB,MAAA"}
@@ -0,0 +1,30 @@
1
+ //#region src/units/rem-2-px.ts
2
+ /**
3
+ * Converts rem values to pixel units.
4
+ *
5
+ * @param rem - The rem value to convert. Can be a number or string (e.g. '1rem' or '1')
6
+ * @param options - Optional configuration
7
+ * @param options.base - Base pixel value to calculate pixels from. Defaults to 16
8
+ * @param options.precision - Number of decimal places in the output. Defaults to 4
9
+ * @returns The converted value as a string with 'px' units
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * rem2px(1) // '16.0000'
14
+ * rem2px('2rem') // '32.0000'
15
+ * rem2px(1, { base: 20 }) // '20.0000'
16
+ * rem2px(0.8125, { precision: 2 }) // '13.00'
17
+ * ```
18
+ */
19
+ function rem2px(rem, options) {
20
+ const { base = 16, precision = 4 } = options ?? {};
21
+ if (typeof rem === "string") {
22
+ rem = rem.replace(/rem$/, "");
23
+ rem = Number.parseFloat(rem);
24
+ }
25
+ return Number((rem * base).toFixed(precision));
26
+ }
27
+
28
+ //#endregion
29
+ export { rem2px };
30
+ //# sourceMappingURL=rem-2-px.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rem-2-px.mjs","names":[],"sources":["../../src/units/rem-2-px.ts"],"sourcesContent":["/**\n * Converts rem values to pixel units.\n *\n * @param rem - The rem value to convert. Can be a number or string (e.g. '1rem' or '1')\n * @param options - Optional configuration\n * @param options.base - Base pixel value to calculate pixels from. Defaults to 16\n * @param options.precision - Number of decimal places in the output. Defaults to 4\n * @returns The converted value as a string with 'px' units\n *\n * @example\n * ```ts\n * rem2px(1) // '16.0000'\n * rem2px('2rem') // '32.0000'\n * rem2px(1, { base: 20 }) // '20.0000'\n * rem2px(0.8125, { precision: 2 }) // '13.00'\n * ```\n */\nexport function rem2px(\n\trem: number | string,\n\toptions?: { base?: number | undefined; precision?: number | undefined }\n): number {\n\tconst { base = 16, precision = 4 } = options ?? {}\n\n\tif (typeof rem === 'string') {\n\t\trem = rem.replace(/rem$/, '')\n\t\trem = Number.parseFloat(rem)\n\t}\n\n\treturn Number((rem * base).toFixed(precision))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,SAAgB,OACf,KACA,SACS;CACT,MAAM,EAAE,OAAO,IAAI,YAAY,MAAM,WAAW,EAAE;AAElD,KAAI,OAAO,QAAQ,UAAU;AAC5B,QAAM,IAAI,QAAQ,QAAQ,GAAG;AAC7B,QAAM,OAAO,WAAW,IAAI;;AAG7B,QAAO,QAAQ,MAAM,MAAM,QAAQ,UAAU,CAAC"}
@@ -0,0 +1,16 @@
1
+
2
+ //#region src/utils/append-id.ts
3
+ /**
4
+ * Appends a suffix to an ID if the ID is defined.
5
+ *
6
+ * @param id - The ID to append the suffix to.
7
+ * @param suffix - The suffix to append to the ID.
8
+ * @returns The ID with the suffix appended, or undefined if the ID is undefined.
9
+ */
10
+ function appendId(id, suffix) {
11
+ return id ? `${id}-${suffix}` : void 0;
12
+ }
13
+
14
+ //#endregion
15
+ exports.appendId = appendId;
16
+ //# sourceMappingURL=append-id.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"append-id.cjs","names":[],"sources":["../../src/utils/append-id.ts"],"sourcesContent":["/**\n * Appends a suffix to an ID if the ID is defined.\n *\n * @param id - The ID to append the suffix to.\n * @param suffix - The suffix to append to the ID.\n * @returns The ID with the suffix appended, or undefined if the ID is undefined.\n */\nexport function appendId(id: string | undefined, suffix: string): string | undefined {\n\treturn id ? `${id}-${suffix}` : undefined\n}\n"],"mappings":";;;;;;;;;AAOA,SAAgB,SAAS,IAAwB,QAAoC;AACpF,QAAO,KAAK,GAAG,GAAG,GAAG,WAAW"}
@@ -0,0 +1,12 @@
1
+ //#region src/utils/append-id.d.ts
2
+ /**
3
+ * Appends a suffix to an ID if the ID is defined.
4
+ *
5
+ * @param id - The ID to append the suffix to.
6
+ * @param suffix - The suffix to append to the ID.
7
+ * @returns The ID with the suffix appended, or undefined if the ID is undefined.
8
+ */
9
+ declare function appendId(id: string | undefined, suffix: string): string | undefined;
10
+ //#endregion
11
+ export { appendId };
12
+ //# sourceMappingURL=append-id.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"append-id.d.cts","names":[],"sources":["../../src/utils/append-id.ts"],"sourcesContent":[],"mappings":";;AAOA;;;;;;iBAAgB,QAAA"}
@@ -0,0 +1,12 @@
1
+ //#region src/utils/append-id.d.ts
2
+ /**
3
+ * Appends a suffix to an ID if the ID is defined.
4
+ *
5
+ * @param id - The ID to append the suffix to.
6
+ * @param suffix - The suffix to append to the ID.
7
+ * @returns The ID with the suffix appended, or undefined if the ID is undefined.
8
+ */
9
+ declare function appendId(id: string | undefined, suffix: string): string | undefined;
10
+ //#endregion
11
+ export { appendId };
12
+ //# sourceMappingURL=append-id.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"append-id.d.mts","names":[],"sources":["../../src/utils/append-id.ts"],"sourcesContent":[],"mappings":";;AAOA;;;;;;iBAAgB,QAAA"}
@@ -0,0 +1,15 @@
1
+ //#region src/utils/append-id.ts
2
+ /**
3
+ * Appends a suffix to an ID if the ID is defined.
4
+ *
5
+ * @param id - The ID to append the suffix to.
6
+ * @param suffix - The suffix to append to the ID.
7
+ * @returns The ID with the suffix appended, or undefined if the ID is undefined.
8
+ */
9
+ function appendId(id, suffix) {
10
+ return id ? `${id}-${suffix}` : void 0;
11
+ }
12
+
13
+ //#endregion
14
+ export { appendId };
15
+ //# sourceMappingURL=append-id.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"append-id.mjs","names":[],"sources":["../../src/utils/append-id.ts"],"sourcesContent":["/**\n * Appends a suffix to an ID if the ID is defined.\n *\n * @param id - The ID to append the suffix to.\n * @param suffix - The suffix to append to the ID.\n * @returns The ID with the suffix appended, or undefined if the ID is undefined.\n */\nexport function appendId(id: string | undefined, suffix: string): string | undefined {\n\treturn id ? `${id}-${suffix}` : undefined\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,SAAS,IAAwB,QAAoC;AACpF,QAAO,KAAK,GAAG,GAAG,GAAG,WAAW"}
package/package.json ADDED
@@ -0,0 +1,120 @@
1
+ {
2
+ "name": "@just-web/toolkits",
3
+ "version": "1.0.0",
4
+ "description": "Toolkits for web applications",
5
+ "homepage": "https://github.com/justland/just-web-foundation/tree/main/libs/toolkits",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/justland/just-web-foundation.git",
9
+ "directory": "libs/toolkits"
10
+ },
11
+ "license": "MIT",
12
+ "author": "Unional <homawong@gmail.com>",
13
+ "type": "module",
14
+ "imports": {
15
+ "#just-web/toolkits": {
16
+ "@just-web/toolkits-dev": "./src/index.ts",
17
+ "types": "./dist/index.d.mts",
18
+ "default": "./dist/index.mjs"
19
+ },
20
+ "#just-web/toolkits/react": {
21
+ "@just-web/toolkits-dev": "./src/react.ts",
22
+ "types": "./dist/react.d.mts",
23
+ "default": "./dist/react.mjs"
24
+ },
25
+ "#just-web/toolkits/theme": {
26
+ "@just-web/toolkits-dev": "./src/theme.ts",
27
+ "types": "./dist/theme.d.mts",
28
+ "default": "./dist/theme.mjs"
29
+ }
30
+ },
31
+ "exports": {
32
+ ".": {
33
+ "types": [
34
+ "./dist/index.d.mts",
35
+ "./src/index.ts"
36
+ ],
37
+ "source": "./src/index.ts",
38
+ "default": "./dist/index.mjs"
39
+ },
40
+ "./react": {
41
+ "types": [
42
+ "./dist/react.d.mts",
43
+ "./src/react.ts"
44
+ ],
45
+ "source": "./src/react.ts",
46
+ "default": "./dist/react.mjs"
47
+ },
48
+ "./theme": {
49
+ "types": [
50
+ "./dist/theme.d.mts",
51
+ "./src/theme.ts"
52
+ ],
53
+ "source": "./src/theme.ts",
54
+ "default": "./dist/theme.mjs"
55
+ },
56
+ "./package.json": "./package.json"
57
+ },
58
+ "main": "./dist/index.cjs",
59
+ "source": "./src/index.ts",
60
+ "types": "./dist/index.d.cts",
61
+ "files": [
62
+ "dist",
63
+ "src",
64
+ "!**/*.{spec,test,unit,accept,integrate,system,stories}.*",
65
+ "!**/*.mdx"
66
+ ],
67
+ "dependencies": {
68
+ "clsx": "^2.1.1",
69
+ "csstype": "^3.2.3",
70
+ "react-aria-components": "^1.15.1",
71
+ "type-plus": "8.0.0-beta.8"
72
+ },
73
+ "devDependencies": {
74
+ "@repobuddy/storybook": "^2.25.0",
75
+ "@repobuddy/vitest": "^2.1.1",
76
+ "@storybook-community/storybook-dark-mode": "^7.1.0",
77
+ "@storybook/addon-docs": "^10.2.7",
78
+ "@storybook/addon-vitest": "^10.2.7",
79
+ "@storybook/react-vite": "^10.2.7",
80
+ "@tailwindcss/cli": "^4.1.18",
81
+ "@tailwindcss/vite": "^4.1.18",
82
+ "@testing-library/react": "^16.3.2",
83
+ "@types/react": "^19.2.13",
84
+ "@vitest/browser": "^4.0.18",
85
+ "@vitest/browser-playwright": "^4.0.18",
86
+ "@vitest/coverage-v8": "^4.0.18",
87
+ "dedent": "^1.7.1",
88
+ "jotai": "^2.18.0",
89
+ "npm-run-all2": "^8.0.4",
90
+ "react": "^18.3.1",
91
+ "react-dom": "^18.3.1",
92
+ "rimraf": "^6.1.2",
93
+ "storybook": "^10.2.7",
94
+ "storybook-addon-code-editor": "^6.1.3",
95
+ "storybook-addon-tag-badges": "^3.0.6",
96
+ "storybook-addon-vis": "^3.1.2",
97
+ "tailwind-merge": "^3.5.0",
98
+ "tailwindcss": "^4.1.18",
99
+ "tsdown": "^0.18.4",
100
+ "typescript": "^5.9.3",
101
+ "vite": "^7.3.1",
102
+ "vitest": "^4.0.18",
103
+ "zustand": "^5.0.11",
104
+ "@tools/typescript": "^0.0.1"
105
+ },
106
+ "scripts": {
107
+ "build": "run-p build:* test:types",
108
+ "build-doc": "storybook build -o ../../docs/foundation",
109
+ "build:code": "tsdown",
110
+ "check:css": "tailwindcss -i .storybook/tailwind.css -o ./styles.storybook.css",
111
+ "clean": "rimraf .turbo dist *.tsbuildinfo",
112
+ "cov": "vitest run --coverage",
113
+ "cov:w": "vitest --coverage",
114
+ "nuke": "rimraf node_modules",
115
+ "sb": "storybook dev -p 6206",
116
+ "test": "vitest run",
117
+ "test:types": "tsc --noEmit",
118
+ "w": "vitest"
119
+ }
120
+ }
package/readme.md ADDED
@@ -0,0 +1,15 @@
1
+ # @just-web/toolkits
2
+
3
+ [@just-web/toolkits][@just-web/toolkits] is a toolkit for working with web technologies.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @just-web/toolkits
9
+
10
+ yarn add @just-web/toolkits
11
+
12
+ pnpm add @just-web/toolkits
13
+ ```
14
+
15
+ [@just-web/toolkits]: https://github.com/justland/just-web-foundation/tree/main/libs/toolkits
@@ -0,0 +1,8 @@
1
+ export function tryParseJSON<T>(json: string | null | undefined): T | undefined {
2
+ if (!json) return undefined
3
+ try {
4
+ return JSON.parse(json)
5
+ } catch {
6
+ return undefined
7
+ }
8
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Well-known data attribute names used in web development.
3
+ * Includes testing, analytics, Radix/shadcn-style component state,
4
+ * positioning, and common UI/design-system attributes.
5
+ * The `data-${string}` tail allows any custom data attribute.
6
+ *
7
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/data-* MDN: data-* (HTML)}
8
+ * @see {@link https://testing-library.com/docs/queries/bytestid/ Testing Library: ByTestId}
9
+ * @see {@link https://css-tricks.com/a-complete-guide-to-data-attributes/ CSS-Tricks: A Complete Guide to Data Attributes}
10
+ * @see {@link https://www.components.build/data-attributes Components.build: Data Attributes}
11
+ * @see {@link https://www.radix-ui.com/primitives/docs/guides/styling Radix UI: Styling (data attributes)}
12
+ */
13
+ export type DataAttribute =
14
+ // Testing & analytics
15
+ | 'data-testid'
16
+ | 'data-metrics'
17
+ // Component state (Radix/shadcn pattern)
18
+ | 'data-state'
19
+ | 'data-orientation'
20
+ | 'data-side'
21
+ | 'data-align'
22
+ | 'data-placement'
23
+ // Common UI state
24
+ | 'data-loading'
25
+ | 'data-disabled'
26
+ | 'data-selected'
27
+ | 'data-checked'
28
+ | 'data-expanded'
29
+ | 'data-highlighted'
30
+ | 'data-active'
31
+ | 'data-open'
32
+ | 'data-pressed'
33
+ // Content / value
34
+ | 'data-value'
35
+ | 'data-id'
36
+ | 'data-name'
37
+ | 'data-type'
38
+ | 'data-label'
39
+ | 'data-key'
40
+ | 'data-index'
41
+ | 'data-position'
42
+ // Design system / theming
43
+ | 'data-variant'
44
+ | 'data-size'
45
+ | 'data-theme'
46
+ | 'data-color'
47
+ | 'data-intent'
48
+ // Custom
49
+ | (`data-${string}` & {})
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Gets the value of an attribute from an element.
3
+ *
4
+ * @param qualifiedName - The name of the attribute to get
5
+ * @param element - The element to get the attribute from. Defaults to `document.documentElement`
6
+ * @returns The attribute value cast to type T, or null if the attribute doesn't exist
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * // Get theme from document root
11
+ * const theme = getAttribute('data-theme')
12
+ *
13
+ * // Get data-testid from a specific element
14
+ * const testId = getAttribute('data-testid', element)
15
+ * ```
16
+ */
17
+ export function getAttribute<T extends string>(qualifiedName: T, element?: Element | undefined) {
18
+ element = element ?? globalThis.document.documentElement
19
+ return element.getAttribute(qualifiedName)
20
+ }
@@ -0,0 +1,15 @@
1
+ import type { DataAttribute } from './data-attribute.ts'
2
+ import { getAttribute } from './get-attribute.ts'
3
+
4
+ /**
5
+ * Gets the value of a data attribute from an element.
6
+ *
7
+ * @param qualifiedName - The name of the data attribute to get
8
+ * @param element - The element to get the data attribute from. Defaults to `document.documentElement`
9
+ * @returns The data attribute value, or null if the attribute doesn't exist
10
+ *
11
+ * @example
12
+ */
13
+ export function getDataAttribute(qualifiedName: DataAttribute, element?: Element | undefined) {
14
+ return getAttribute(qualifiedName, element)
15
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Observes attributes changes on an element and calls corresponding handlers.
3
+ *
4
+ * @param handlers - An object mapping attribute names to handler functions.
5
+ * @param element - The element to observe. Defaults to `document.documentElement`.
6
+ * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const observer = observeAttributes({
11
+ * 'data-theme': (attr, value) => console.log(`Theme changed to: ${value}`),
12
+ * 'class': (attr, value) => console.log(`class changed to: ${value}`)
13
+ * });
14
+ *
15
+ * // Later, to stop observing:
16
+ * observer.disconnect();
17
+ * ```
18
+ */
19
+ export function observeAttributes<T extends string>(
20
+ handlers: Record<string, (value: T | null) => void>,
21
+ element?: Element | undefined
22
+ ) {
23
+ element = element ?? globalThis.document.documentElement
24
+ const observer = new MutationObserver((mutations) => {
25
+ for (const mutation of mutations) {
26
+ const attribute = mutation.attributeName
27
+ if (!attribute) continue
28
+ const value = element.getAttribute(attribute) as T | null
29
+ handlers[attribute]?.(value)
30
+ }
31
+ })
32
+ observer.observe(element, {
33
+ attributes: true,
34
+ attributeFilter: Object.keys(handlers)
35
+ })
36
+ return observer
37
+ }
@@ -0,0 +1,29 @@
1
+ import { observeAttributes } from './observe-attribute.ts'
2
+
3
+ /**
4
+ * Observes changes to `data-*` attributes on an element and calls corresponding handlers.
5
+ *
6
+ * @param options - Configuration options
7
+ * @param options.handlers - An object mapping `data-*` attribute names to handler functions.
8
+ * @param options.element - The element to observe. Defaults to `document.documentElement`
9
+ * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const observer = observeDataAttributes({
14
+ * handlers: {
15
+ * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
16
+ * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)
17
+ * }
18
+ * });
19
+ *
20
+ * // Later, to stop observing:
21
+ * observer.disconnect();
22
+ * ```
23
+ */
24
+ export function observeDataAttributes<T extends string, K extends `data-${string}`>(
25
+ handlers: Record<K, (value: T | null) => void>,
26
+ element?: Element | undefined
27
+ ) {
28
+ return observeAttributes(handlers, element)
29
+ }
@@ -0,0 +1,29 @@
1
+ import type { JustChildrenFnProps, JustChildrenProps } from '@just-web/toolkits'
2
+ import { resolveChildren } from '@just-web/toolkits'
3
+ import { StoryCard } from '@repobuddy/storybook'
4
+
5
+ type CardRenderProps = { label: string }
6
+
7
+ function Card({ children, ...rest }: JustChildrenProps<CardRenderProps>) {
8
+ const renderProps: JustChildrenFnProps<CardRenderProps> = {
9
+ label: 'Item',
10
+ children: 'Default content'
11
+ }
12
+ return (
13
+ <div {...rest}>
14
+ <span className="font-medium">{renderProps.label}: </span>
15
+ {resolveChildren(renderProps, children)}
16
+ </div>
17
+ )
18
+ }
19
+
20
+ export default () => (
21
+ <StoryCard appearance="output">
22
+ <Card />
23
+ <Card>
24
+ {(props: JustChildrenFnProps<CardRenderProps>) =>
25
+ `${props.label} → ${String(props.children)}`
26
+ }
27
+ </Card>
28
+ </StoryCard>
29
+ )
@@ -0,0 +1,17 @@
1
+ import type { JustChildrenProps } from '@just-web/toolkits'
2
+ import { resolveChildren } from '@just-web/toolkits'
3
+ import { StoryCard } from '@repobuddy/storybook'
4
+
5
+ function Card({ children, ...rest }: JustChildrenProps) {
6
+ const renderProps = { children: 'Default content' as const }
7
+ return <div {...rest}>{resolveChildren(renderProps, children)}</div>
8
+ }
9
+
10
+ export default () => (
11
+ <StoryCard appearance="output">
12
+ <Card />
13
+ <Card>Override content</Card>
14
+ <Card>{(renderProps) => `Computed: ${String(renderProps.children)}`}</Card>
15
+ <Card>{() => undefined}</Card>
16
+ </StoryCard>
17
+ )
@@ -0,0 +1,11 @@
1
+ import type { JustChildren } from '@just-web/toolkits'
2
+ import { StoryCard } from '@repobuddy/storybook'
3
+
4
+ const functionChildren: JustChildren<{ count?: number }> = (renderProps) =>
5
+ renderProps.count !== undefined ? `Count: ${renderProps.count}` : renderProps.children
6
+
7
+ export default () => (
8
+ <StoryCard appearance="output">
9
+ <div>{functionChildren({ children: 'Default', count: 42 })}</div>
10
+ </StoryCard>
11
+ )
@@ -0,0 +1,37 @@
1
+ import type { ReactNode } from 'react'
2
+ import type { AnyRecord } from 'type-plus'
3
+
4
+ /**
5
+ * Props interface for components that accept a render-props-aware `children`.
6
+ *
7
+ * Use this when defining component props that support the same `children` contract as {@link JustChildren}:
8
+ * a static value, a resolver function that receives render props (including existing `children`), or `undefined`.
9
+ *
10
+ * @typeParam RenderProps - Record type for render props. When `children` is a function, it receives `RenderProps` merged with `{ children?: ReactNode }`.
11
+ */
12
+ export interface JustChildrenProps<RenderProps extends AnyRecord = AnyRecord> {
13
+ children?: JustChildren<RenderProps> | undefined
14
+ }
15
+
16
+ /**
17
+ * A `children` type that can be static or computed from render props.
18
+ *
19
+ * - `ReactNode`: The value is used as the children (replaces existing `children` in render props when provided).
20
+ * - `undefined`: Uses the existing `children` from render props as-is.
21
+ * - `function`: Process the render props and return the desired `children`.
22
+ *
23
+ * @typeParam RenderProps - Record type for render props. Resolvers receive `RenderProps` merged with `{ children?: ReactNode }`.
24
+ */
25
+ export type JustChildren<RenderProps extends AnyRecord = AnyRecord> =
26
+ | ((renderProps: JustChildrenFnProps<RenderProps>) => ReactNode | undefined)
27
+ | ReactNode
28
+ | undefined
29
+
30
+ /**
31
+ * The props type for `JustChildren` resolver functions.
32
+ *
33
+ * @typeParam RenderProps - Record type for render props.
34
+ */
35
+ export type JustChildrenFnProps<RenderProps extends AnyRecord = AnyRecord> = RenderProps & {
36
+ children?: ReactNode | undefined
37
+ }
@@ -0,0 +1,16 @@
1
+ import type { ReactNode } from 'react'
2
+ import type { AnyRecord } from 'type-plus'
3
+ import type { JustChildren, JustChildrenFnProps } from './just-children.ts'
4
+
5
+ export function resolveChildren<RenderProps extends AnyRecord = AnyRecord>(
6
+ renderProps: JustChildrenFnProps<RenderProps>,
7
+ children?: JustChildren<RenderProps>
8
+ ): ReactNode | undefined {
9
+ if (typeof children === 'function') {
10
+ return children(renderProps)
11
+ }
12
+ if (children !== undefined) {
13
+ return children
14
+ }
15
+ return renderProps.children
16
+ }
@@ -0,0 +1,13 @@
1
+ import type { ClassNameProps } from '@just-web/toolkits'
2
+ import { StoryCard } from '@repobuddy/storybook'
3
+ import type { PropsWithChildren } from 'react'
4
+
5
+ export default () => (
6
+ <StoryCard appearance="output">
7
+ <MyComponent className="font-extrabold">Hello in extra bold</MyComponent>
8
+ </StoryCard>
9
+ )
10
+
11
+ function MyComponent({ className, children }: PropsWithChildren<ClassNameProps>) {
12
+ return <div className={className}>{children}</div>
13
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Interface for component props that include a className property.
3
+ * The className property accepts a string value for CSS class names.
4
+ */
5
+ export interface ClassNameProps {
6
+ className?: string | undefined
7
+ }
@@ -0,0 +1,3 @@
1
+ import clsx from 'clsx'
2
+
3
+ export { clsx }
@@ -0,0 +1,23 @@
1
+ import type { JustClassNameProps } from '@just-web/toolkits'
2
+ import { StoryCard } from '@repobuddy/storybook'
3
+ import type { PropsWithChildren } from 'react'
4
+
5
+ function Badge({ className, ...rest }: PropsWithChildren<JustClassNameProps>) {
6
+ const props = { className: 'bg-blue-400' }
7
+ return (
8
+ <div
9
+ {...rest}
10
+ className={
11
+ typeof className === 'function' ? className(props) : (className ?? props.className)
12
+ }
13
+ />
14
+ )
15
+ }
16
+
17
+ export default () => (
18
+ <StoryCard appearance="output">
19
+ <Badge className="font-extrabold">Override</Badge>
20
+ <Badge className={(renderProps) => `${renderProps.className} font-extrabold`}>Amend</Badge>
21
+ <Badge className={() => undefined}>Unstyled</Badge>
22
+ </StoryCard>
23
+ )
@@ -0,0 +1,18 @@
1
+ import type { JustClassNameFnProps } from '@just-web/toolkits'
2
+ import { clsx } from '@just-web/toolkits'
3
+
4
+ function textTheme(renderProps?: JustClassNameFnProps) {
5
+ return {
6
+ ...renderProps,
7
+ className: clsx(renderProps?.className, 'text-emerald-800 dark:text-emerald-200')
8
+ }
9
+ }
10
+
11
+ export default () => {
12
+ const props = textTheme()
13
+ return (
14
+ <button type="button" {...props}>
15
+ Hello World
16
+ </button>
17
+ )
18
+ }