@just-web/toolkits 2.1.0 → 3.1.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 (130) hide show
  1. package/dist/attributes/observe-attribute.cjs +10 -7
  2. package/dist/attributes/observe-attribute.cjs.map +1 -1
  3. package/dist/attributes/observe-attribute.d.cts +6 -6
  4. package/dist/attributes/observe-attribute.d.cts.map +1 -1
  5. package/dist/attributes/observe-attribute.d.mts +6 -6
  6. package/dist/attributes/observe-attribute.d.mts.map +1 -1
  7. package/dist/attributes/observe-attribute.mjs +10 -7
  8. package/dist/attributes/observe-attribute.mjs.map +1 -1
  9. package/dist/attributes/observe-data-attribute.cjs +7 -10
  10. package/dist/attributes/observe-data-attribute.cjs.map +1 -1
  11. package/dist/attributes/observe-data-attribute.d.cts +8 -11
  12. package/dist/attributes/observe-data-attribute.d.cts.map +1 -1
  13. package/dist/attributes/observe-data-attribute.d.mts +8 -11
  14. package/dist/attributes/observe-data-attribute.d.mts.map +1 -1
  15. package/dist/attributes/observe-data-attribute.mjs +7 -10
  16. package/dist/attributes/observe-data-attribute.mjs.map +1 -1
  17. package/dist/index.cjs +13 -2
  18. package/dist/index.d.cts +8 -2
  19. package/dist/index.d.mts +8 -2
  20. package/dist/index.mjs +7 -2
  21. package/dist/react/hooks/use-attribute.cjs +1 -2
  22. package/dist/react/hooks/use-attribute.cjs.map +1 -1
  23. package/dist/react/hooks/use-attribute.mjs +1 -2
  24. package/dist/react/hooks/use-attribute.mjs.map +1 -1
  25. package/dist/style/css-properties.d.cts +2 -1
  26. package/dist/style/css-properties.d.cts.map +1 -1
  27. package/dist/style/css-properties.d.mts +2 -1
  28. package/dist/style/css-properties.d.mts.map +1 -1
  29. package/dist/theme/class-name/subscribe-class-name.cjs +1 -2
  30. package/dist/theme/class-name/subscribe-class-name.cjs.map +1 -1
  31. package/dist/theme/class-name/subscribe-class-name.mjs +1 -2
  32. package/dist/theme/class-name/subscribe-class-name.mjs.map +1 -1
  33. package/dist/theme/data-attribute/subscribe-data-attribute.cjs +1 -2
  34. package/dist/theme/data-attribute/subscribe-data-attribute.cjs.map +1 -1
  35. package/dist/theme/data-attribute/subscribe-data-attribute.mjs +1 -2
  36. package/dist/theme/data-attribute/subscribe-data-attribute.mjs.map +1 -1
  37. package/dist/units/convert-css-unit.cjs +173 -0
  38. package/dist/units/convert-css-unit.cjs.map +1 -0
  39. package/dist/units/convert-css-unit.d.cts +25 -0
  40. package/dist/units/convert-css-unit.d.cts.map +1 -0
  41. package/dist/units/convert-css-unit.d.mts +25 -0
  42. package/dist/units/convert-css-unit.d.mts.map +1 -0
  43. package/dist/units/convert-css-unit.mjs +173 -0
  44. package/dist/units/convert-css-unit.mjs.map +1 -0
  45. package/dist/units/create-css-unit-converter.cjs +33 -0
  46. package/dist/units/create-css-unit-converter.cjs.map +1 -0
  47. package/dist/units/create-css-unit-converter.d.cts +28 -0
  48. package/dist/units/create-css-unit-converter.d.cts.map +1 -0
  49. package/dist/units/create-css-unit-converter.d.mts +28 -0
  50. package/dist/units/create-css-unit-converter.d.mts.map +1 -0
  51. package/dist/units/create-css-unit-converter.mjs +33 -0
  52. package/dist/units/create-css-unit-converter.mjs.map +1 -0
  53. package/dist/units/css-unit-converter.types.d.cts +35 -0
  54. package/dist/units/css-unit-converter.types.d.cts.map +1 -0
  55. package/dist/units/css-unit-converter.types.d.mts +35 -0
  56. package/dist/units/css-unit-converter.types.d.mts.map +1 -0
  57. package/dist/units/get-css-unit.cjs +29 -0
  58. package/dist/units/get-css-unit.cjs.map +1 -0
  59. package/dist/units/get-css-unit.d.cts +23 -0
  60. package/dist/units/get-css-unit.d.cts.map +1 -0
  61. package/dist/units/get-css-unit.d.mts +23 -0
  62. package/dist/units/get-css-unit.d.mts.map +1 -0
  63. package/dist/units/get-css-unit.mjs +29 -0
  64. package/dist/units/get-css-unit.mjs.map +1 -0
  65. package/dist/units/is-effectively-zero.cjs +35 -0
  66. package/dist/units/is-effectively-zero.cjs.map +1 -0
  67. package/dist/units/is-effectively-zero.d.cts +28 -0
  68. package/dist/units/is-effectively-zero.d.cts.map +1 -0
  69. package/dist/units/is-effectively-zero.d.mts +28 -0
  70. package/dist/units/is-effectively-zero.d.mts.map +1 -0
  71. package/dist/units/is-effectively-zero.mjs +35 -0
  72. package/dist/units/is-effectively-zero.mjs.map +1 -0
  73. package/dist/units/parse-css-number.cjs +29 -0
  74. package/dist/units/parse-css-number.cjs.map +1 -0
  75. package/dist/units/parse-css-number.d.cts +24 -0
  76. package/dist/units/parse-css-number.d.cts.map +1 -0
  77. package/dist/units/parse-css-number.d.mts +24 -0
  78. package/dist/units/parse-css-number.d.mts.map +1 -0
  79. package/dist/units/parse-css-number.mjs +29 -0
  80. package/dist/units/parse-css-number.mjs.map +1 -0
  81. package/dist/units/parse-css-value.cjs +32 -0
  82. package/dist/units/parse-css-value.cjs.map +1 -0
  83. package/dist/units/parse-css-value.d.cts +22 -0
  84. package/dist/units/parse-css-value.d.cts.map +1 -0
  85. package/dist/units/parse-css-value.d.mts +22 -0
  86. package/dist/units/parse-css-value.d.mts.map +1 -0
  87. package/dist/units/parse-css-value.mjs +31 -0
  88. package/dist/units/parse-css-value.mjs.map +1 -0
  89. package/dist/units/px-2-rem.cjs +8 -5
  90. package/dist/units/px-2-rem.cjs.map +1 -1
  91. package/dist/units/px-2-rem.d.cts +9 -7
  92. package/dist/units/px-2-rem.d.cts.map +1 -1
  93. package/dist/units/px-2-rem.d.mts +9 -7
  94. package/dist/units/px-2-rem.d.mts.map +1 -1
  95. package/dist/units/px-2-rem.mjs +8 -5
  96. package/dist/units/px-2-rem.mjs.map +1 -1
  97. package/dist/units/rem-2-px.cjs +8 -5
  98. package/dist/units/rem-2-px.cjs.map +1 -1
  99. package/dist/units/rem-2-px.d.cts +9 -7
  100. package/dist/units/rem-2-px.d.cts.map +1 -1
  101. package/dist/units/rem-2-px.d.mts +9 -7
  102. package/dist/units/rem-2-px.d.mts.map +1 -1
  103. package/dist/units/rem-2-px.mjs +8 -5
  104. package/dist/units/rem-2-px.mjs.map +1 -1
  105. package/package.json +1 -1
  106. package/src/attributes/observe-attribute.ts +13 -8
  107. package/src/attributes/observe-data-attribute.ts +7 -10
  108. package/src/index.ts +7 -0
  109. package/src/react/hooks/use-attribute.ts +1 -2
  110. package/src/style/css-properties.ts +3 -1
  111. package/src/theme/class-name/subscribe-class-name.ts +1 -2
  112. package/src/theme/data-attribute/subscribe-data-attribute.ts +1 -2
  113. package/src/units/convert-css-unit.ts +292 -0
  114. package/src/units/create-css-unit-converter.ts +30 -0
  115. package/src/units/css-unit-converter.types.ts +49 -0
  116. package/src/units/get-css-unit.ts +24 -0
  117. package/src/units/is-effectively-zero.ts +35 -0
  118. package/src/units/parse-css-number.ts +26 -0
  119. package/src/units/parse-css-value.ts +35 -0
  120. package/src/units/px-2-num.ts +5 -4
  121. package/src/units/px-2-rem.ts +12 -8
  122. package/src/units/rem-2-px.ts +11 -9
  123. package/dist/units/px-2-num.cjs +0 -23
  124. package/dist/units/px-2-num.cjs.map +0 -1
  125. package/dist/units/px-2-num.d.cts +0 -19
  126. package/dist/units/px-2-num.d.cts.map +0 -1
  127. package/dist/units/px-2-num.d.mts +0 -19
  128. package/dist/units/px-2-num.d.mts.map +0 -1
  129. package/dist/units/px-2-num.mjs +0 -22
  130. package/dist/units/px-2-num.mjs.map +0 -1
@@ -5,21 +5,24 @@
5
5
  *
6
6
  * @param handlers - An object mapping attribute names to handler functions.
7
7
  * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`.
8
- * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.
8
+ * @returns An unsubscribe function to stop observing. Returns a no-op function in SSR environments.
9
9
  *
10
10
  * @example
11
11
  * ```ts
12
- * const observer = observeAttributes({
13
- * 'data-theme': (attr, value) => console.log(`Theme changed to: ${value}`),
14
- * 'class': (attr, value) => console.log(`class changed to: ${value}`)
12
+ * const unsubscribe = observeAttributes({
13
+ * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
14
+ * 'class': (value) => console.log(`class changed to: ${value}`)
15
15
  * });
16
16
  *
17
17
  * // Later, to stop observing:
18
- * observer.disconnect();
18
+ * unsubscribe();
19
19
  * ```
20
20
  */
21
21
  function observeAttributes(handlers, element) {
22
- element = element ?? globalThis.document.documentElement;
22
+ /* c8 ignore start */
23
+ if (typeof document === "undefined") return () => {};
24
+ /* c8 ignore end */
25
+ element = element ?? document.documentElement;
23
26
  const observer = new MutationObserver((mutations) => {
24
27
  for (const mutation of mutations) {
25
28
  const attribute = mutation.attributeName;
@@ -32,7 +35,7 @@ function observeAttributes(handlers, element) {
32
35
  attributes: true,
33
36
  attributeFilter: Object.keys(handlers)
34
37
  });
35
- return observer;
38
+ return () => observer.disconnect();
36
39
  }
37
40
 
38
41
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"observe-attribute.cjs","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":["/**\n * Observes attributes changes on an element and calls corresponding handlers.\n *\n * @param handlers - An object mapping attribute names to handler functions.\n * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`.\n * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.\n *\n * @example\n * ```ts\n * const observer = observeAttributes({\n * 'data-theme': (attr, value) => console.log(`Theme changed to: ${value}`),\n * 'class': (attr, value) => console.log(`class changed to: ${value}`)\n * });\n *\n * // Later, to stop observing:\n * observer.disconnect();\n * ```\n */\nexport function observeAttributes<T extends string>(\n\thandlers: Record<string, (value: T | null) => void>,\n\telement?: Element | null | undefined\n) {\n\telement = element ?? globalThis.document.documentElement\n\tconst observer = new MutationObserver((mutations) => {\n\t\tfor (const mutation of mutations) {\n\t\t\tconst attribute = mutation.attributeName\n\t\t\tif (!attribute) continue\n\t\t\tconst value = element.getAttribute(attribute) as T | null\n\t\t\thandlers[attribute]?.(value)\n\t\t}\n\t})\n\tobserver.observe(element, {\n\t\tattributes: true,\n\t\tattributeFilter: Object.keys(handlers)\n\t})\n\treturn observer\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,kBACf,UACA,SACC;AACD,WAAU,WAAW,WAAW,SAAS;CACzC,MAAM,WAAW,IAAI,kBAAkB,cAAc;AACpD,OAAK,MAAM,YAAY,WAAW;GACjC,MAAM,YAAY,SAAS;AAC3B,OAAI,CAAC,UAAW;GAChB,MAAM,QAAQ,QAAQ,aAAa,UAAU;AAC7C,YAAS,aAAa,MAAM;;GAE5B;AACF,UAAS,QAAQ,SAAS;EACzB,YAAY;EACZ,iBAAiB,OAAO,KAAK,SAAS;EACtC,CAAC;AACF,QAAO"}
1
+ {"version":3,"file":"observe-attribute.cjs","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":["/**\n * Observes attributes changes on an element and calls corresponding handlers.\n *\n * @param handlers - An object mapping attribute names to handler functions.\n * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`.\n * @returns An unsubscribe function to stop observing. Returns a no-op function in SSR environments.\n *\n * @example\n * ```ts\n * const unsubscribe = observeAttributes({\n * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),\n * 'class': (value) => console.log(`class changed to: ${value}`)\n * });\n *\n * // Later, to stop observing:\n * unsubscribe();\n * ```\n */\nexport function observeAttributes<T extends string>(\n\thandlers: Record<string, (value: T | null) => void>,\n\telement?: Element | null | undefined\n): () => void {\n\t/* c8 ignore start */\n\tif (typeof document === 'undefined') {\n\t\treturn () => {}\n\t}\n\t/* c8 ignore end */\n\telement = element ?? document.documentElement\n\tconst observer = new MutationObserver((mutations) => {\n\t\tfor (const mutation of mutations) {\n\t\t\tconst attribute = mutation.attributeName\n\t\t\tif (!attribute) continue\n\t\t\tconst value = element.getAttribute(attribute) as T | null\n\t\t\thandlers[attribute]?.(value)\n\t\t}\n\t})\n\tobserver.observe(element, {\n\t\tattributes: true,\n\t\tattributeFilter: Object.keys(handlers)\n\t})\n\treturn () => observer.disconnect()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,kBACf,UACA,SACa;;AAEb,KAAI,OAAO,aAAa,YACvB,cAAa;;AAGd,WAAU,WAAW,SAAS;CAC9B,MAAM,WAAW,IAAI,kBAAkB,cAAc;AACpD,OAAK,MAAM,YAAY,WAAW;GACjC,MAAM,YAAY,SAAS;AAC3B,OAAI,CAAC,UAAW;GAChB,MAAM,QAAQ,QAAQ,aAAa,UAAU;AAC7C,YAAS,aAAa,MAAM;;GAE5B;AACF,UAAS,QAAQ,SAAS;EACzB,YAAY;EACZ,iBAAiB,OAAO,KAAK,SAAS;EACtC,CAAC;AACF,cAAa,SAAS,YAAY"}
@@ -4,20 +4,20 @@
4
4
  *
5
5
  * @param handlers - An object mapping attribute names to handler functions.
6
6
  * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`.
7
- * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.
7
+ * @returns An unsubscribe function to stop observing. Returns a no-op function in SSR environments.
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
- * const observer = observeAttributes({
12
- * 'data-theme': (attr, value) => console.log(`Theme changed to: ${value}`),
13
- * 'class': (attr, value) => console.log(`class changed to: ${value}`)
11
+ * const unsubscribe = observeAttributes({
12
+ * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
13
+ * 'class': (value) => console.log(`class changed to: ${value}`)
14
14
  * });
15
15
  *
16
16
  * // Later, to stop observing:
17
- * observer.disconnect();
17
+ * unsubscribe();
18
18
  * ```
19
19
  */
20
- declare function observeAttributes<T extends string>(handlers: Record<string, (value: T | null) => void>, element?: Element | null | undefined): MutationObserver;
20
+ declare function observeAttributes<T extends string>(handlers: Record<string, (value: T | null) => void>, element?: Element | null | undefined): () => void;
21
21
  //#endregion
22
22
  export { observeAttributes };
23
23
  //# sourceMappingURL=observe-attribute.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"observe-attribute.d.cts","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":[],"mappings":";;AAkBA;;;;;;;;;;;;;;;;;iBAAgB,8CACL,uBAAuB,8BACvB,6BAA0B"}
1
+ {"version":3,"file":"observe-attribute.d.cts","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":[],"mappings":";;AAkBA;;;;;;;;;;;;;;;;;iBAAgB,8CACL,uBAAuB,8BACvB"}
@@ -4,20 +4,20 @@
4
4
  *
5
5
  * @param handlers - An object mapping attribute names to handler functions.
6
6
  * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`.
7
- * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.
7
+ * @returns An unsubscribe function to stop observing. Returns a no-op function in SSR environments.
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
- * const observer = observeAttributes({
12
- * 'data-theme': (attr, value) => console.log(`Theme changed to: ${value}`),
13
- * 'class': (attr, value) => console.log(`class changed to: ${value}`)
11
+ * const unsubscribe = observeAttributes({
12
+ * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
13
+ * 'class': (value) => console.log(`class changed to: ${value}`)
14
14
  * });
15
15
  *
16
16
  * // Later, to stop observing:
17
- * observer.disconnect();
17
+ * unsubscribe();
18
18
  * ```
19
19
  */
20
- declare function observeAttributes<T extends string>(handlers: Record<string, (value: T | null) => void>, element?: Element | null | undefined): MutationObserver;
20
+ declare function observeAttributes<T extends string>(handlers: Record<string, (value: T | null) => void>, element?: Element | null | undefined): () => void;
21
21
  //#endregion
22
22
  export { observeAttributes };
23
23
  //# sourceMappingURL=observe-attribute.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"observe-attribute.d.mts","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":[],"mappings":";;AAkBA;;;;;;;;;;;;;;;;;iBAAgB,8CACL,uBAAuB,8BACvB,6BAA0B"}
1
+ {"version":3,"file":"observe-attribute.d.mts","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":[],"mappings":";;AAkBA;;;;;;;;;;;;;;;;;iBAAgB,8CACL,uBAAuB,8BACvB"}
@@ -4,21 +4,24 @@
4
4
  *
5
5
  * @param handlers - An object mapping attribute names to handler functions.
6
6
  * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`.
7
- * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.
7
+ * @returns An unsubscribe function to stop observing. Returns a no-op function in SSR environments.
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
- * const observer = observeAttributes({
12
- * 'data-theme': (attr, value) => console.log(`Theme changed to: ${value}`),
13
- * 'class': (attr, value) => console.log(`class changed to: ${value}`)
11
+ * const unsubscribe = observeAttributes({
12
+ * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
13
+ * 'class': (value) => console.log(`class changed to: ${value}`)
14
14
  * });
15
15
  *
16
16
  * // Later, to stop observing:
17
- * observer.disconnect();
17
+ * unsubscribe();
18
18
  * ```
19
19
  */
20
20
  function observeAttributes(handlers, element) {
21
- element = element ?? globalThis.document.documentElement;
21
+ /* c8 ignore start */
22
+ if (typeof document === "undefined") return () => {};
23
+ /* c8 ignore end */
24
+ element = element ?? document.documentElement;
22
25
  const observer = new MutationObserver((mutations) => {
23
26
  for (const mutation of mutations) {
24
27
  const attribute = mutation.attributeName;
@@ -31,7 +34,7 @@ function observeAttributes(handlers, element) {
31
34
  attributes: true,
32
35
  attributeFilter: Object.keys(handlers)
33
36
  });
34
- return observer;
37
+ return () => observer.disconnect();
35
38
  }
36
39
 
37
40
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"observe-attribute.mjs","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":["/**\n * Observes attributes changes on an element and calls corresponding handlers.\n *\n * @param handlers - An object mapping attribute names to handler functions.\n * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`.\n * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer.\n *\n * @example\n * ```ts\n * const observer = observeAttributes({\n * 'data-theme': (attr, value) => console.log(`Theme changed to: ${value}`),\n * 'class': (attr, value) => console.log(`class changed to: ${value}`)\n * });\n *\n * // Later, to stop observing:\n * observer.disconnect();\n * ```\n */\nexport function observeAttributes<T extends string>(\n\thandlers: Record<string, (value: T | null) => void>,\n\telement?: Element | null | undefined\n) {\n\telement = element ?? globalThis.document.documentElement\n\tconst observer = new MutationObserver((mutations) => {\n\t\tfor (const mutation of mutations) {\n\t\t\tconst attribute = mutation.attributeName\n\t\t\tif (!attribute) continue\n\t\t\tconst value = element.getAttribute(attribute) as T | null\n\t\t\thandlers[attribute]?.(value)\n\t\t}\n\t})\n\tobserver.observe(element, {\n\t\tattributes: true,\n\t\tattributeFilter: Object.keys(handlers)\n\t})\n\treturn observer\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,kBACf,UACA,SACC;AACD,WAAU,WAAW,WAAW,SAAS;CACzC,MAAM,WAAW,IAAI,kBAAkB,cAAc;AACpD,OAAK,MAAM,YAAY,WAAW;GACjC,MAAM,YAAY,SAAS;AAC3B,OAAI,CAAC,UAAW;GAChB,MAAM,QAAQ,QAAQ,aAAa,UAAU;AAC7C,YAAS,aAAa,MAAM;;GAE5B;AACF,UAAS,QAAQ,SAAS;EACzB,YAAY;EACZ,iBAAiB,OAAO,KAAK,SAAS;EACtC,CAAC;AACF,QAAO"}
1
+ {"version":3,"file":"observe-attribute.mjs","names":[],"sources":["../../src/attributes/observe-attribute.ts"],"sourcesContent":["/**\n * Observes attributes changes on an element and calls corresponding handlers.\n *\n * @param handlers - An object mapping attribute names to handler functions.\n * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`.\n * @returns An unsubscribe function to stop observing. Returns a no-op function in SSR environments.\n *\n * @example\n * ```ts\n * const unsubscribe = observeAttributes({\n * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),\n * 'class': (value) => console.log(`class changed to: ${value}`)\n * });\n *\n * // Later, to stop observing:\n * unsubscribe();\n * ```\n */\nexport function observeAttributes<T extends string>(\n\thandlers: Record<string, (value: T | null) => void>,\n\telement?: Element | null | undefined\n): () => void {\n\t/* c8 ignore start */\n\tif (typeof document === 'undefined') {\n\t\treturn () => {}\n\t}\n\t/* c8 ignore end */\n\telement = element ?? document.documentElement\n\tconst observer = new MutationObserver((mutations) => {\n\t\tfor (const mutation of mutations) {\n\t\t\tconst attribute = mutation.attributeName\n\t\t\tif (!attribute) continue\n\t\t\tconst value = element.getAttribute(attribute) as T | null\n\t\t\thandlers[attribute]?.(value)\n\t\t}\n\t})\n\tobserver.observe(element, {\n\t\tattributes: true,\n\t\tattributeFilter: Object.keys(handlers)\n\t})\n\treturn () => observer.disconnect()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,kBACf,UACA,SACa;;AAEb,KAAI,OAAO,aAAa,YACvB,cAAa;;AAGd,WAAU,WAAW,SAAS;CAC9B,MAAM,WAAW,IAAI,kBAAkB,cAAc;AACpD,OAAK,MAAM,YAAY,WAAW;GACjC,MAAM,YAAY,SAAS;AAC3B,OAAI,CAAC,UAAW;GAChB,MAAM,QAAQ,QAAQ,aAAa,UAAU;AAC7C,YAAS,aAAa,MAAM;;GAE5B;AACF,UAAS,QAAQ,SAAS;EACzB,YAAY;EACZ,iBAAiB,OAAO,KAAK,SAAS;EACtC,CAAC;AACF,cAAa,SAAS,YAAY"}
@@ -4,22 +4,19 @@ const require_observe_attribute = require('./observe-attribute.cjs');
4
4
  /**
5
5
  * Observes changes to `data-*` attributes on an element and calls corresponding handlers.
6
6
  *
7
- * @param options - Configuration options
8
- * @param options.handlers - An object mapping `data-*` attribute names to handler functions.
9
- * @param options.element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`
10
- * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer
7
+ * @param handlers - An object mapping `data-*` attribute names to handler functions.
8
+ * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`
9
+ * @returns An unsubscribe function to stop observing. Returns a no-op function in SSR environments.
11
10
  *
12
11
  * @example
13
12
  * ```ts
14
- * const observer = observeDataAttributes({
15
- * handlers: {
16
- * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
17
- * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)
18
- * }
13
+ * const unsubscribe = observeDataAttributes({
14
+ * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
15
+ * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)
19
16
  * });
20
17
  *
21
18
  * // Later, to stop observing:
22
- * observer.disconnect();
19
+ * unsubscribe();
23
20
  * ```
24
21
  */
25
22
  function observeDataAttributes(handlers, element) {
@@ -1 +1 @@
1
- {"version":3,"file":"observe-data-attribute.cjs","names":["observeAttributes"],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":["import { observeAttributes } from './observe-attribute.ts'\n\n/**\n * Observes changes to `data-*` attributes on an element and calls corresponding handlers.\n *\n * @param options - Configuration options\n * @param options.handlers - An object mapping `data-*` attribute names to handler functions.\n * @param options.element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`\n * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer\n *\n * @example\n * ```ts\n * const observer = observeDataAttributes({\n * handlers: {\n * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),\n * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)\n * }\n * });\n *\n * // Later, to stop observing:\n * observer.disconnect();\n * ```\n */\nexport function observeDataAttributes<T extends string, K extends `data-${string}`>(\n\thandlers: Record<K, (value: T | null) => void>,\n\telement?: Element | null | undefined\n) {\n\treturn observeAttributes(handlers, element)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,sBACf,UACA,SACC;AACD,QAAOA,4CAAkB,UAAU,QAAQ"}
1
+ {"version":3,"file":"observe-data-attribute.cjs","names":["observeAttributes"],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":["import { observeAttributes } from './observe-attribute.ts'\n\n/**\n * Observes changes to `data-*` attributes on an element and calls corresponding handlers.\n *\n * @param handlers - An object mapping `data-*` attribute names to handler functions.\n * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`\n * @returns An unsubscribe function to stop observing. Returns a no-op function in SSR environments.\n *\n * @example\n * ```ts\n * const unsubscribe = observeDataAttributes({\n * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),\n * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)\n * });\n *\n * // Later, to stop observing:\n * unsubscribe();\n * ```\n */\nexport function observeDataAttributes<T extends string, K extends `data-${string}`>(\n\thandlers: Record<K, (value: T | null) => void>,\n\telement?: Element | null | undefined\n) {\n\treturn observeAttributes(handlers, element)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,sBACf,UACA,SACC;AACD,QAAOA,4CAAkB,UAAU,QAAQ"}
@@ -2,25 +2,22 @@
2
2
  /**
3
3
  * Observes changes to `data-*` attributes on an element and calls corresponding handlers.
4
4
  *
5
- * @param options - Configuration options
6
- * @param options.handlers - An object mapping `data-*` attribute names to handler functions.
7
- * @param options.element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`
8
- * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer
5
+ * @param handlers - An object mapping `data-*` attribute names to handler functions.
6
+ * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`
7
+ * @returns An unsubscribe function to stop observing. Returns a no-op function in SSR environments.
9
8
  *
10
9
  * @example
11
10
  * ```ts
12
- * const observer = observeDataAttributes({
13
- * handlers: {
14
- * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
15
- * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)
16
- * }
11
+ * const unsubscribe = observeDataAttributes({
12
+ * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
13
+ * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)
17
14
  * });
18
15
  *
19
16
  * // Later, to stop observing:
20
- * observer.disconnect();
17
+ * unsubscribe();
21
18
  * ```
22
19
  */
23
- declare function observeDataAttributes<T extends string, K extends `data-${string}`>(handlers: Record<K, (value: T | null) => void>, element?: Element | null | undefined): MutationObserver;
20
+ declare function observeDataAttributes<T extends string, K extends `data-${string}`>(handlers: Record<K, (value: T | null) => void>, element?: Element | null | undefined): () => void;
24
21
  //#endregion
25
22
  export { observeDataAttributes };
26
23
  //# sourceMappingURL=observe-data-attribute.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"observe-data-attribute.d.cts","names":[],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":[],"mappings":";;AAuBA;;;;;;;;;;;;;;;;;;;;iBAAgB,8EACL,OAAO,WAAW,8BAClB,6BAA0B"}
1
+ {"version":3,"file":"observe-data-attribute.d.cts","names":[],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":[],"mappings":";;AAoBA;;;;;;;;;;;;;;;;;iBAAgB,8EACL,OAAO,WAAW,8BAClB"}
@@ -2,25 +2,22 @@
2
2
  /**
3
3
  * Observes changes to `data-*` attributes on an element and calls corresponding handlers.
4
4
  *
5
- * @param options - Configuration options
6
- * @param options.handlers - An object mapping `data-*` attribute names to handler functions.
7
- * @param options.element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`
8
- * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer
5
+ * @param handlers - An object mapping `data-*` attribute names to handler functions.
6
+ * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`
7
+ * @returns An unsubscribe function to stop observing. Returns a no-op function in SSR environments.
9
8
  *
10
9
  * @example
11
10
  * ```ts
12
- * const observer = observeDataAttributes({
13
- * handlers: {
14
- * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
15
- * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)
16
- * }
11
+ * const unsubscribe = observeDataAttributes({
12
+ * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
13
+ * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)
17
14
  * });
18
15
  *
19
16
  * // Later, to stop observing:
20
- * observer.disconnect();
17
+ * unsubscribe();
21
18
  * ```
22
19
  */
23
- declare function observeDataAttributes<T extends string, K extends `data-${string}`>(handlers: Record<K, (value: T | null) => void>, element?: Element | null | undefined): MutationObserver;
20
+ declare function observeDataAttributes<T extends string, K extends `data-${string}`>(handlers: Record<K, (value: T | null) => void>, element?: Element | null | undefined): () => void;
24
21
  //#endregion
25
22
  export { observeDataAttributes };
26
23
  //# sourceMappingURL=observe-data-attribute.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"observe-data-attribute.d.mts","names":[],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":[],"mappings":";;AAuBA;;;;;;;;;;;;;;;;;;;;iBAAgB,8EACL,OAAO,WAAW,8BAClB,6BAA0B"}
1
+ {"version":3,"file":"observe-data-attribute.d.mts","names":[],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":[],"mappings":";;AAoBA;;;;;;;;;;;;;;;;;iBAAgB,8EACL,OAAO,WAAW,8BAClB"}
@@ -4,22 +4,19 @@ import { observeAttributes } from "./observe-attribute.mjs";
4
4
  /**
5
5
  * Observes changes to `data-*` attributes on an element and calls corresponding handlers.
6
6
  *
7
- * @param options - Configuration options
8
- * @param options.handlers - An object mapping `data-*` attribute names to handler functions.
9
- * @param options.element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`
10
- * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer
7
+ * @param handlers - An object mapping `data-*` attribute names to handler functions.
8
+ * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`
9
+ * @returns An unsubscribe function to stop observing. Returns a no-op function in SSR environments.
11
10
  *
12
11
  * @example
13
12
  * ```ts
14
- * const observer = observeDataAttributes({
15
- * handlers: {
16
- * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
17
- * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)
18
- * }
13
+ * const unsubscribe = observeDataAttributes({
14
+ * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),
15
+ * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)
19
16
  * });
20
17
  *
21
18
  * // Later, to stop observing:
22
- * observer.disconnect();
19
+ * unsubscribe();
23
20
  * ```
24
21
  */
25
22
  function observeDataAttributes(handlers, element) {
@@ -1 +1 @@
1
- {"version":3,"file":"observe-data-attribute.mjs","names":[],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":["import { observeAttributes } from './observe-attribute.ts'\n\n/**\n * Observes changes to `data-*` attributes on an element and calls corresponding handlers.\n *\n * @param options - Configuration options\n * @param options.handlers - An object mapping `data-*` attribute names to handler functions.\n * @param options.element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`\n * @returns {MutationObserver} The observer instance, which can be used to disconnect the observer\n *\n * @example\n * ```ts\n * const observer = observeDataAttributes({\n * handlers: {\n * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),\n * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)\n * }\n * });\n *\n * // Later, to stop observing:\n * observer.disconnect();\n * ```\n */\nexport function observeDataAttributes<T extends string, K extends `data-${string}`>(\n\thandlers: Record<K, (value: T | null) => void>,\n\telement?: Element | null | undefined\n) {\n\treturn observeAttributes(handlers, element)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,sBACf,UACA,SACC;AACD,QAAO,kBAAkB,UAAU,QAAQ"}
1
+ {"version":3,"file":"observe-data-attribute.mjs","names":[],"sources":["../../src/attributes/observe-data-attribute.ts"],"sourcesContent":["import { observeAttributes } from './observe-attribute.ts'\n\n/**\n * Observes changes to `data-*` attributes on an element and calls corresponding handlers.\n *\n * @param handlers - An object mapping `data-*` attribute names to handler functions.\n * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement`\n * @returns An unsubscribe function to stop observing. Returns a no-op function in SSR environments.\n *\n * @example\n * ```ts\n * const unsubscribe = observeDataAttributes({\n * 'data-theme': (value) => console.log(`Theme changed to: ${value}`),\n * 'data-mode': (value) => console.log(`Mode changed to: ${value}`)\n * });\n *\n * // Later, to stop observing:\n * unsubscribe();\n * ```\n */\nexport function observeDataAttributes<T extends string, K extends `data-${string}`>(\n\thandlers: Record<K, (value: T | null) => void>,\n\telement?: Element | null | undefined\n) {\n\treturn observeAttributes(handlers, element)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,sBACf,UACA,SACC;AACD,QAAO,kBAAkB,UAAU,QAAQ"}
package/dist/index.cjs CHANGED
@@ -13,7 +13,12 @@ const require_get_css_variable_value = require('./style/get-css-variable-value.c
13
13
  const require_resolve_style = require('./style/resolve-style.cjs');
14
14
  const require_to_dom_style = require('./style/to-dom-style.cjs');
15
15
  const require_get_rem_to_px_scale = require('./units/get-rem-to-px-scale.cjs');
16
- const require_px_2_num = require('./units/px-2-num.cjs');
16
+ const require_parse_css_value = require('./units/parse-css-value.cjs');
17
+ const require_convert_css_unit = require('./units/convert-css-unit.cjs');
18
+ const require_create_css_unit_converter = require('./units/create-css-unit-converter.cjs');
19
+ const require_get_css_unit = require('./units/get-css-unit.cjs');
20
+ const require_parse_css_number = require('./units/parse-css-number.cjs');
21
+ const require_is_effectively_zero = require('./units/is-effectively-zero.cjs');
17
22
  const require_px_2_rem = require('./units/px-2-rem.cjs');
18
23
  const require_rem_2_px = require('./units/rem-2-px.cjs');
19
24
  const require_append_id = require('./utils/append-id.cjs');
@@ -21,16 +26,22 @@ let clsx = require("clsx");
21
26
 
22
27
  exports.appendId = require_append_id.appendId;
23
28
  exports.clsx = clsx.default;
29
+ exports.convertCssUnit = require_convert_css_unit.convertCssUnit;
30
+ exports.createCssUnitConverter = require_create_css_unit_converter.createCssUnitConverter;
24
31
  exports.defineCSSProperties = require_define_css_properties.defineCSSProperties;
25
32
  exports.getAttribute = require_get_attribute.getAttribute;
26
33
  exports.getCSSVariableValue = require_get_css_variable_value.getCSSVariableValue;
34
+ exports.getCssUnit = require_get_css_unit.getCssUnit;
27
35
  exports.getDataAttribute = require_get_data_attribute.getDataAttribute;
28
36
  exports.getPrefersColorScheme = require_get_prefers_color_scheme.getPrefersColorScheme;
29
37
  exports.getRemToPxScale = require_get_rem_to_px_scale.getRemToPxScale;
38
+ exports.isEffectivelyZero = require_is_effectively_zero.isEffectivelyZero;
30
39
  exports.observeAttributes = require_observe_attribute.observeAttributes;
31
40
  exports.observeDataAttributes = require_observe_data_attribute.observeDataAttributes;
32
41
  exports.observePrefersColorScheme = require_observe_prefers_color_scheme.observePrefersColorScheme;
33
- exports.px2num = require_px_2_num.px2num;
42
+ exports.parseCssNumber = require_parse_css_number.parseCssNumber;
43
+ exports.parseCssValue = require_parse_css_value.parseCssValue;
44
+ exports.px2num = require_parse_css_number.parseCssNumber;
34
45
  exports.px2rem = require_px_2_rem.px2rem;
35
46
  exports.rem2px = require_rem_2_px.rem2px;
36
47
  exports.resolveChildren = require_resolve_children.resolveChildren;
package/dist/index.d.cts CHANGED
@@ -19,9 +19,15 @@ import { JustStyle, JustStyleFnProps, JustStyleProps } from "./style/just-style.
19
19
  import { resolveStyle } from "./style/resolve-style.cjs";
20
20
  import { StyleProps } from "./style/style-props.cjs";
21
21
  import { toDomStyle } from "./style/to-dom-style.cjs";
22
+ import { ConvertCssUnitOptions, CssLengthUnit, CssUnitConverterContext } from "./units/css-unit-converter.types.cjs";
23
+ import { convertCssUnit } from "./units/convert-css-unit.cjs";
24
+ import { createCssUnitConverter } from "./units/create-css-unit-converter.cjs";
25
+ import { getCssUnit } from "./units/get-css-unit.cjs";
22
26
  import { getRemToPxScale } from "./units/get-rem-to-px-scale.cjs";
23
- import { px2num } from "./units/px-2-num.cjs";
27
+ import { isEffectivelyZero } from "./units/is-effectively-zero.cjs";
28
+ import { parseCssNumber } from "./units/parse-css-number.cjs";
29
+ import { parseCssValue } from "./units/parse-css-value.cjs";
24
30
  import { px2rem } from "./units/px-2-rem.cjs";
25
31
  import { rem2px } from "./units/rem-2-px.cjs";
26
32
  import { appendId } from "./utils/append-id.cjs";
27
- export { CSSProperties, ClassNameProps, ColorScheme, DataAttribute, JustChildren, JustChildrenFnProps, JustChildrenProps, JustClassName, JustClassNameFnProps, JustClassNameProps, JustStyle, JustStyleFnProps, JustStyleProps, StyleProps, appendId, clsx, defineCSSProperties, getAttribute, getCSSVariableValue, getDataAttribute, getPrefersColorScheme, getRemToPxScale, observeAttributes, observeDataAttributes, observePrefersColorScheme, px2num, px2rem, rem2px, resolveChildren, resolveClassName, resolveStyle, toDomStyle };
33
+ export { CSSProperties, ClassNameProps, ColorScheme, ConvertCssUnitOptions, CssLengthUnit, CssUnitConverterContext, DataAttribute, JustChildren, JustChildrenFnProps, JustChildrenProps, JustClassName, JustClassNameFnProps, JustClassNameProps, JustStyle, JustStyleFnProps, JustStyleProps, StyleProps, appendId, clsx, convertCssUnit, createCssUnitConverter, defineCSSProperties, getAttribute, getCSSVariableValue, getCssUnit, getDataAttribute, getPrefersColorScheme, getRemToPxScale, isEffectivelyZero, observeAttributes, observeDataAttributes, observePrefersColorScheme, parseCssNumber, parseCssValue, parseCssNumber as px2num, px2rem, rem2px, resolveChildren, resolveClassName, resolveStyle, toDomStyle };
package/dist/index.d.mts CHANGED
@@ -19,9 +19,15 @@ import { JustStyle, JustStyleFnProps, JustStyleProps } from "./style/just-style.
19
19
  import { resolveStyle } from "./style/resolve-style.mjs";
20
20
  import { StyleProps } from "./style/style-props.mjs";
21
21
  import { toDomStyle } from "./style/to-dom-style.mjs";
22
+ import { ConvertCssUnitOptions, CssLengthUnit, CssUnitConverterContext } from "./units/css-unit-converter.types.mjs";
23
+ import { convertCssUnit } from "./units/convert-css-unit.mjs";
24
+ import { createCssUnitConverter } from "./units/create-css-unit-converter.mjs";
25
+ import { getCssUnit } from "./units/get-css-unit.mjs";
22
26
  import { getRemToPxScale } from "./units/get-rem-to-px-scale.mjs";
23
- import { px2num } from "./units/px-2-num.mjs";
27
+ import { isEffectivelyZero } from "./units/is-effectively-zero.mjs";
28
+ import { parseCssNumber } from "./units/parse-css-number.mjs";
29
+ import { parseCssValue } from "./units/parse-css-value.mjs";
24
30
  import { px2rem } from "./units/px-2-rem.mjs";
25
31
  import { rem2px } from "./units/rem-2-px.mjs";
26
32
  import { appendId } from "./utils/append-id.mjs";
27
- export { CSSProperties, ClassNameProps, ColorScheme, DataAttribute, JustChildren, JustChildrenFnProps, JustChildrenProps, JustClassName, JustClassNameFnProps, JustClassNameProps, JustStyle, JustStyleFnProps, JustStyleProps, StyleProps, appendId, clsx, defineCSSProperties, getAttribute, getCSSVariableValue, getDataAttribute, getPrefersColorScheme, getRemToPxScale, observeAttributes, observeDataAttributes, observePrefersColorScheme, px2num, px2rem, rem2px, resolveChildren, resolveClassName, resolveStyle, toDomStyle };
33
+ export { CSSProperties, ClassNameProps, ColorScheme, ConvertCssUnitOptions, CssLengthUnit, CssUnitConverterContext, DataAttribute, JustChildren, JustChildrenFnProps, JustChildrenProps, JustClassName, JustClassNameFnProps, JustClassNameProps, JustStyle, JustStyleFnProps, JustStyleProps, StyleProps, appendId, clsx, convertCssUnit, createCssUnitConverter, defineCSSProperties, getAttribute, getCSSVariableValue, getCssUnit, getDataAttribute, getPrefersColorScheme, getRemToPxScale, isEffectivelyZero, observeAttributes, observeDataAttributes, observePrefersColorScheme, parseCssNumber, parseCssValue, parseCssNumber as px2num, px2rem, rem2px, resolveChildren, resolveClassName, resolveStyle, toDomStyle };
package/dist/index.mjs CHANGED
@@ -12,9 +12,14 @@ import { getCSSVariableValue } from "./style/get-css-variable-value.mjs";
12
12
  import { resolveStyle } from "./style/resolve-style.mjs";
13
13
  import { toDomStyle } from "./style/to-dom-style.mjs";
14
14
  import { getRemToPxScale } from "./units/get-rem-to-px-scale.mjs";
15
- import { px2num } from "./units/px-2-num.mjs";
15
+ import { parseCssValue } from "./units/parse-css-value.mjs";
16
+ import { convertCssUnit } from "./units/convert-css-unit.mjs";
17
+ import { createCssUnitConverter } from "./units/create-css-unit-converter.mjs";
18
+ import { getCssUnit } from "./units/get-css-unit.mjs";
19
+ import { parseCssNumber } from "./units/parse-css-number.mjs";
20
+ import { isEffectivelyZero } from "./units/is-effectively-zero.mjs";
16
21
  import { px2rem } from "./units/px-2-rem.mjs";
17
22
  import { rem2px } from "./units/rem-2-px.mjs";
18
23
  import { appendId } from "./utils/append-id.mjs";
19
24
 
20
- export { appendId, clsx, defineCSSProperties, getAttribute, getCSSVariableValue, getDataAttribute, getPrefersColorScheme, getRemToPxScale, observeAttributes, observeDataAttributes, observePrefersColorScheme, px2num, px2rem, rem2px, resolveChildren, resolveClassName, resolveStyle, toDomStyle };
25
+ export { appendId, clsx, convertCssUnit, createCssUnitConverter, defineCSSProperties, getAttribute, getCSSVariableValue, getCssUnit, getDataAttribute, getPrefersColorScheme, getRemToPxScale, isEffectivelyZero, observeAttributes, observeDataAttributes, observePrefersColorScheme, parseCssNumber, parseCssValue, parseCssNumber as px2num, px2rem, rem2px, resolveChildren, resolveClassName, resolveStyle, toDomStyle };
@@ -24,10 +24,9 @@ function useAttribute(attributeName, element = typeof document !== "undefined" ?
24
24
  (0, react.useEffect)(() => {
25
25
  if (!element) return;
26
26
  setValueState(element.getAttribute(attributeName) ?? void 0);
27
- const observer = require_observe_attribute.observeAttributes({ [attributeName]: (next) => {
27
+ return require_observe_attribute.observeAttributes({ [attributeName]: (next) => {
28
28
  setValueState(next ?? void 0);
29
29
  } }, element);
30
- return () => observer.disconnect();
31
30
  }, [element, attributeName]);
32
31
  return [value, (0, react.useCallback)((next) => {
33
32
  if (!element) return;
@@ -1 +1 @@
1
- {"version":3,"file":"use-attribute.cjs","names":["observeAttributes"],"sources":["../../../src/react/hooks/use-attribute.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { observeAttributes } from '../../attributes/observe-attribute.ts'\n\n/**\n * React hook that returns the current value of an attribute on a target element\n * and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).\n *\n * @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).\n * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement` when omitted.\n * @returns Tuple of [value, setValue]. Pass null or undefined to setValue to remove the attribute.\n *\n * @example\n * ```tsx\n * const [className, setClassName] = useAttribute('class')\n * const [theme, setTheme] = useAttribute('data-theme', myElement)\n * setTheme('dark')\n * setClassName(undefined) // removes class attribute\n * ```\n */\nexport function useAttribute(\n\tattributeName: string,\n\telement: Element | null | undefined = typeof document !== 'undefined'\n\t\t? document.documentElement\n\t\t: undefined\n): [string | undefined, (value: string | null | undefined) => void] {\n\tconst [value, setValueState] = useState<string | undefined>(\n\t\t() => element?.getAttribute(attributeName) ?? undefined\n\t)\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\n\t\tsetValueState(element.getAttribute(attributeName) ?? undefined)\n\n\t\tconst observer = observeAttributes(\n\t\t\t{\n\t\t\t\t[attributeName]: (next) => {\n\t\t\t\t\tsetValueState(next ?? undefined)\n\t\t\t\t}\n\t\t\t},\n\t\t\telement\n\t\t)\n\t\treturn () => observer.disconnect()\n\t}, [element, attributeName])\n\n\tconst setValue = useCallback(\n\t\t(next: string | null | undefined) => {\n\t\t\tif (!element) return\n\t\t\tif (next == null) {\n\t\t\t\telement.removeAttribute(attributeName)\n\t\t\t} else {\n\t\t\t\telement.setAttribute(attributeName, next)\n\t\t\t}\n\t\t},\n\t\t[element, attributeName]\n\t)\n\n\treturn [value, setValue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aACf,eACA,UAAsC,OAAO,aAAa,cACvD,SAAS,kBACT,QACgE;CACnE,MAAM,CAAC,OAAO,2CACP,SAAS,aAAa,cAAc,IAAI,OAC9C;AAED,4BAAgB;AACf,MAAI,CAAC,QAAS;AAEd,gBAAc,QAAQ,aAAa,cAAc,IAAI,OAAU;EAE/D,MAAM,WAAWA,4CAChB,GACE,iBAAiB,SAAS;AAC1B,iBAAc,QAAQ,OAAU;KAEjC,EACD,QACA;AACD,eAAa,SAAS,YAAY;IAChC,CAAC,SAAS,cAAc,CAAC;AAc5B,QAAO,CAAC,+BAXN,SAAoC;AACpC,MAAI,CAAC,QAAS;AACd,MAAI,QAAQ,KACX,SAAQ,gBAAgB,cAAc;MAEtC,SAAQ,aAAa,eAAe,KAAK;IAG3C,CAAC,SAAS,cAAc,CACxB,CAEuB"}
1
+ {"version":3,"file":"use-attribute.cjs","names":["observeAttributes"],"sources":["../../../src/react/hooks/use-attribute.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { observeAttributes } from '../../attributes/observe-attribute.ts'\n\n/**\n * React hook that returns the current value of an attribute on a target element\n * and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).\n *\n * @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).\n * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement` when omitted.\n * @returns Tuple of [value, setValue]. Pass null or undefined to setValue to remove the attribute.\n *\n * @example\n * ```tsx\n * const [className, setClassName] = useAttribute('class')\n * const [theme, setTheme] = useAttribute('data-theme', myElement)\n * setTheme('dark')\n * setClassName(undefined) // removes class attribute\n * ```\n */\nexport function useAttribute(\n\tattributeName: string,\n\telement: Element | null | undefined = typeof document !== 'undefined'\n\t\t? document.documentElement\n\t\t: undefined\n): [string | undefined, (value: string | null | undefined) => void] {\n\tconst [value, setValueState] = useState<string | undefined>(\n\t\t() => element?.getAttribute(attributeName) ?? undefined\n\t)\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\n\t\tsetValueState(element.getAttribute(attributeName) ?? undefined)\n\n\t\treturn observeAttributes(\n\t\t\t{\n\t\t\t\t[attributeName]: (next) => {\n\t\t\t\t\tsetValueState(next ?? undefined)\n\t\t\t\t}\n\t\t\t},\n\t\t\telement\n\t\t)\n\t}, [element, attributeName])\n\n\tconst setValue = useCallback(\n\t\t(next: string | null | undefined) => {\n\t\t\tif (!element) return\n\t\t\tif (next == null) {\n\t\t\t\telement.removeAttribute(attributeName)\n\t\t\t} else {\n\t\t\t\telement.setAttribute(attributeName, next)\n\t\t\t}\n\t\t},\n\t\t[element, attributeName]\n\t)\n\n\treturn [value, setValue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aACf,eACA,UAAsC,OAAO,aAAa,cACvD,SAAS,kBACT,QACgE;CACnE,MAAM,CAAC,OAAO,2CACP,SAAS,aAAa,cAAc,IAAI,OAC9C;AAED,4BAAgB;AACf,MAAI,CAAC,QAAS;AAEd,gBAAc,QAAQ,aAAa,cAAc,IAAI,OAAU;AAE/D,SAAOA,4CACN,GACE,iBAAiB,SAAS;AAC1B,iBAAc,QAAQ,OAAU;KAEjC,EACD,QACA;IACC,CAAC,SAAS,cAAc,CAAC;AAc5B,QAAO,CAAC,+BAXN,SAAoC;AACpC,MAAI,CAAC,QAAS;AACd,MAAI,QAAQ,KACX,SAAQ,gBAAgB,cAAc;MAEtC,SAAQ,aAAa,eAAe,KAAK;IAG3C,CAAC,SAAS,cAAc,CACxB,CAEuB"}
@@ -23,10 +23,9 @@ function useAttribute(attributeName, element = typeof document !== "undefined" ?
23
23
  useEffect(() => {
24
24
  if (!element) return;
25
25
  setValueState(element.getAttribute(attributeName) ?? void 0);
26
- const observer = observeAttributes({ [attributeName]: (next) => {
26
+ return observeAttributes({ [attributeName]: (next) => {
27
27
  setValueState(next ?? void 0);
28
28
  } }, element);
29
- return () => observer.disconnect();
30
29
  }, [element, attributeName]);
31
30
  return [value, useCallback((next) => {
32
31
  if (!element) return;
@@ -1 +1 @@
1
- {"version":3,"file":"use-attribute.mjs","names":[],"sources":["../../../src/react/hooks/use-attribute.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { observeAttributes } from '../../attributes/observe-attribute.ts'\n\n/**\n * React hook that returns the current value of an attribute on a target element\n * and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).\n *\n * @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).\n * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement` when omitted.\n * @returns Tuple of [value, setValue]. Pass null or undefined to setValue to remove the attribute.\n *\n * @example\n * ```tsx\n * const [className, setClassName] = useAttribute('class')\n * const [theme, setTheme] = useAttribute('data-theme', myElement)\n * setTheme('dark')\n * setClassName(undefined) // removes class attribute\n * ```\n */\nexport function useAttribute(\n\tattributeName: string,\n\telement: Element | null | undefined = typeof document !== 'undefined'\n\t\t? document.documentElement\n\t\t: undefined\n): [string | undefined, (value: string | null | undefined) => void] {\n\tconst [value, setValueState] = useState<string | undefined>(\n\t\t() => element?.getAttribute(attributeName) ?? undefined\n\t)\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\n\t\tsetValueState(element.getAttribute(attributeName) ?? undefined)\n\n\t\tconst observer = observeAttributes(\n\t\t\t{\n\t\t\t\t[attributeName]: (next) => {\n\t\t\t\t\tsetValueState(next ?? undefined)\n\t\t\t\t}\n\t\t\t},\n\t\t\telement\n\t\t)\n\t\treturn () => observer.disconnect()\n\t}, [element, attributeName])\n\n\tconst setValue = useCallback(\n\t\t(next: string | null | undefined) => {\n\t\t\tif (!element) return\n\t\t\tif (next == null) {\n\t\t\t\telement.removeAttribute(attributeName)\n\t\t\t} else {\n\t\t\t\telement.setAttribute(attributeName, next)\n\t\t\t}\n\t\t},\n\t\t[element, attributeName]\n\t)\n\n\treturn [value, setValue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aACf,eACA,UAAsC,OAAO,aAAa,cACvD,SAAS,kBACT,QACgE;CACnE,MAAM,CAAC,OAAO,iBAAiB,eACxB,SAAS,aAAa,cAAc,IAAI,OAC9C;AAED,iBAAgB;AACf,MAAI,CAAC,QAAS;AAEd,gBAAc,QAAQ,aAAa,cAAc,IAAI,OAAU;EAE/D,MAAM,WAAW,kBAChB,GACE,iBAAiB,SAAS;AAC1B,iBAAc,QAAQ,OAAU;KAEjC,EACD,QACA;AACD,eAAa,SAAS,YAAY;IAChC,CAAC,SAAS,cAAc,CAAC;AAc5B,QAAO,CAAC,OAZS,aACf,SAAoC;AACpC,MAAI,CAAC,QAAS;AACd,MAAI,QAAQ,KACX,SAAQ,gBAAgB,cAAc;MAEtC,SAAQ,aAAa,eAAe,KAAK;IAG3C,CAAC,SAAS,cAAc,CACxB,CAEuB"}
1
+ {"version":3,"file":"use-attribute.mjs","names":[],"sources":["../../../src/react/hooks/use-attribute.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { observeAttributes } from '../../attributes/observe-attribute.ts'\n\n/**\n * React hook that returns the current value of an attribute on a target element\n * and a setter to update it. Stays in sync when the attribute changes (e.g. from elsewhere).\n *\n * @param attributeName - The attribute to observe (e.g. `'class'`, `'data-theme'`).\n * @param element - The element to observe (accepts null e.g. from refs). Defaults to `document.documentElement` when omitted.\n * @returns Tuple of [value, setValue]. Pass null or undefined to setValue to remove the attribute.\n *\n * @example\n * ```tsx\n * const [className, setClassName] = useAttribute('class')\n * const [theme, setTheme] = useAttribute('data-theme', myElement)\n * setTheme('dark')\n * setClassName(undefined) // removes class attribute\n * ```\n */\nexport function useAttribute(\n\tattributeName: string,\n\telement: Element | null | undefined = typeof document !== 'undefined'\n\t\t? document.documentElement\n\t\t: undefined\n): [string | undefined, (value: string | null | undefined) => void] {\n\tconst [value, setValueState] = useState<string | undefined>(\n\t\t() => element?.getAttribute(attributeName) ?? undefined\n\t)\n\n\tuseEffect(() => {\n\t\tif (!element) return\n\n\t\tsetValueState(element.getAttribute(attributeName) ?? undefined)\n\n\t\treturn observeAttributes(\n\t\t\t{\n\t\t\t\t[attributeName]: (next) => {\n\t\t\t\t\tsetValueState(next ?? undefined)\n\t\t\t\t}\n\t\t\t},\n\t\t\telement\n\t\t)\n\t}, [element, attributeName])\n\n\tconst setValue = useCallback(\n\t\t(next: string | null | undefined) => {\n\t\t\tif (!element) return\n\t\t\tif (next == null) {\n\t\t\t\telement.removeAttribute(attributeName)\n\t\t\t} else {\n\t\t\t\telement.setAttribute(attributeName, next)\n\t\t\t}\n\t\t},\n\t\t[element, attributeName]\n\t)\n\n\treturn [value, setValue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aACf,eACA,UAAsC,OAAO,aAAa,cACvD,SAAS,kBACT,QACgE;CACnE,MAAM,CAAC,OAAO,iBAAiB,eACxB,SAAS,aAAa,cAAc,IAAI,OAC9C;AAED,iBAAgB;AACf,MAAI,CAAC,QAAS;AAEd,gBAAc,QAAQ,aAAa,cAAc,IAAI,OAAU;AAE/D,SAAO,kBACN,GACE,iBAAiB,SAAS;AAC1B,iBAAc,QAAQ,OAAU;KAEjC,EACD,QACA;IACC,CAAC,SAAS,cAAc,CAAC;AAc5B,QAAO,CAAC,OAZS,aACf,SAAoC;AACpC,MAAI,CAAC,QAAS;AACd,MAAI,QAAQ,KACX,SAAQ,gBAAgB,cAAc;MAEtC,SAAQ,aAAa,eAAe,KAAK;IAG3C,CAAC,SAAS,cAAc,CACxB,CAEuB"}
@@ -12,7 +12,8 @@ interface CustomProperties {
12
12
  * Widens CSS properties to support custom properties.
13
13
  * Allows for string or number values for standard properties,
14
14
  * and string values for custom properties with '--' prefix.
15
- * Defined as a union so plain Properties (e.g. from React) are assignable.
15
+ *
16
+ * Note that `React.CSSProperties` (using `csstype`) is augmented so you can use it directly without this type.
16
17
  */
17
18
  interface CSSProperties<TLength = string | number, TTime = string & {}> extends Properties<TLength, TTime>, CustomProperties {}
18
19
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"css-properties.d.cts","names":[],"sources":["../../src/style/css-properties.ts"],"sourcesContent":[],"mappings":";;;;iFAGgF,kBAHvC;;;UAO/B,gBAAA,CAJsF;EAAA,CAAA,CAAA,EAAA,KAAA,MAAA,EAAA,CAAA,EAAA,MAAA;AAAA;AAchG;;;;;;UAAiB,sEACR,WAAW,SAAS,QAC3B"}
1
+ {"version":3,"file":"css-properties.d.cts","names":[],"sources":["../../src/style/css-properties.ts"],"sourcesContent":[],"mappings":";;;;iFAIgF,kBAJvC;;;UAQ/B,gBAAA,CAJsF;EAAA,CAAA,CAAA,EAAA,KAAA,MAAA,EAAA,CAAA,EAAA,MAAA;AAAA;AAehG;;;;;;;UAAiB,sEACR,WAAW,SAAS,QAC3B"}
@@ -12,7 +12,8 @@ interface CustomProperties {
12
12
  * Widens CSS properties to support custom properties.
13
13
  * Allows for string or number values for standard properties,
14
14
  * and string values for custom properties with '--' prefix.
15
- * Defined as a union so plain Properties (e.g. from React) are assignable.
15
+ *
16
+ * Note that `React.CSSProperties` (using `csstype`) is augmented so you can use it directly without this type.
16
17
  */
17
18
  interface CSSProperties<TLength = string | number, TTime = string & {}> extends Properties<TLength, TTime>, CustomProperties {}
18
19
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"css-properties.d.mts","names":[],"sources":["../../src/style/css-properties.ts"],"sourcesContent":[],"mappings":";;;;iFAGgF,kBAHvC;;;UAO/B,gBAAA,CAJsF;EAAA,CAAA,CAAA,EAAA,KAAA,MAAA,EAAA,CAAA,EAAA,MAAA;AAAA;AAchG;;;;;;UAAiB,sEACR,WAAW,SAAS,QAC3B"}
1
+ {"version":3,"file":"css-properties.d.mts","names":[],"sources":["../../src/style/css-properties.ts"],"sourcesContent":[],"mappings":";;;;iFAIgF,kBAJvC;;;UAQ/B,gBAAA,CAJsF;EAAA,CAAA,CAAA,EAAA,KAAA,MAAA,EAAA,CAAA,EAAA,MAAA;AAAA;AAehG;;;;;;;UAAiB,sEACR,WAAW,SAAS,QAC3B"}
@@ -16,14 +16,13 @@ function subscribeClassName(themes, handler, options) {
16
16
  if (!element) return () => {};
17
17
  const parse = options?.parse ?? require_parse_class_name.parseClassName;
18
18
  let lastEmitted = null;
19
- const observer = require_observe_attribute.observeAttributes({ class: (value) => {
19
+ return require_observe_attribute.observeAttributes({ class: (value) => {
20
20
  const entry = parse(themes, value ?? void 0);
21
21
  const key = entry?.theme ?? void 0;
22
22
  if (lastEmitted === key) return;
23
23
  lastEmitted = key;
24
24
  handler(entry);
25
25
  } }, element);
26
- return () => observer.disconnect();
27
26
  }
28
27
 
29
28
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"subscribe-class-name.cjs","names":["parseClassName","lastEmitted: keyof Themes | undefined | null","observeAttributes"],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":["import { observeAttributes } from '../../attributes/observe-attribute.ts'\nimport type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Subscribes to changes on the class attribute and invokes the handler with parsed theme entries.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param handler - Callback invoked when the class attribute changes\n * @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).\n */\nexport function subscribeClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\thandler: (entry: ThemeEntry<Themes> | undefined) => void,\n\toptions?:\n\t\t| { element?: Element | null | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): () => void {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return () => {}\n\tconst parse = options?.parse ?? parseClassName\n\tlet lastEmitted: keyof Themes | undefined | null = null\n\tconst observer = observeAttributes(\n\t\t{\n\t\t\tclass: (value) => {\n\t\t\t\tconst entry = parse(themes, value ?? undefined)\n\t\t\t\tconst key = entry?.theme ?? undefined\n\t\t\t\tif (lastEmitted === key) return\n\t\t\t\tlastEmitted = key\n\t\t\t\thandler(entry)\n\t\t\t}\n\t\t},\n\t\telement\n\t)\n\treturn () => observer.disconnect()\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,mBACf,QACA,SACA,SAGa;CACb,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,cAAa;CAC3B,MAAM,QAAQ,SAAS,SAASA;CAChC,IAAIC,cAA+C;CACnD,MAAM,WAAWC,4CAChB,EACC,QAAQ,UAAU;EACjB,MAAM,QAAQ,MAAM,QAAQ,SAAS,OAAU;EAC/C,MAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,gBAAgB,IAAK;AACzB,gBAAc;AACd,UAAQ,MAAM;IAEf,EACD,QACA;AACD,cAAa,SAAS,YAAY"}
1
+ {"version":3,"file":"subscribe-class-name.cjs","names":["parseClassName","lastEmitted: keyof Themes | undefined | null","observeAttributes"],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":["import { observeAttributes } from '../../attributes/observe-attribute.ts'\nimport type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Subscribes to changes on the class attribute and invokes the handler with parsed theme entries.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param handler - Callback invoked when the class attribute changes\n * @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).\n */\nexport function subscribeClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\thandler: (entry: ThemeEntry<Themes> | undefined) => void,\n\toptions?:\n\t\t| { element?: Element | null | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): () => void {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return () => {}\n\tconst parse = options?.parse ?? parseClassName\n\tlet lastEmitted: keyof Themes | undefined | null = null\n\treturn observeAttributes(\n\t\t{\n\t\t\tclass: (value) => {\n\t\t\t\tconst entry = parse(themes, value ?? undefined)\n\t\t\t\tconst key = entry?.theme ?? undefined\n\t\t\t\tif (lastEmitted === key) return\n\t\t\t\tlastEmitted = key\n\t\t\t\thandler(entry)\n\t\t\t}\n\t\t},\n\t\telement\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,mBACf,QACA,SACA,SAGa;CACb,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,cAAa;CAC3B,MAAM,QAAQ,SAAS,SAASA;CAChC,IAAIC,cAA+C;AACnD,QAAOC,4CACN,EACC,QAAQ,UAAU;EACjB,MAAM,QAAQ,MAAM,QAAQ,SAAS,OAAU;EAC/C,MAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,gBAAgB,IAAK;AACzB,gBAAc;AACd,UAAQ,MAAM;IAEf,EACD,QACA"}
@@ -16,14 +16,13 @@ function subscribeClassName(themes, handler, options) {
16
16
  if (!element) return () => {};
17
17
  const parse = options?.parse ?? parseClassName;
18
18
  let lastEmitted = null;
19
- const observer = observeAttributes({ class: (value) => {
19
+ return observeAttributes({ class: (value) => {
20
20
  const entry = parse(themes, value ?? void 0);
21
21
  const key = entry?.theme ?? void 0;
22
22
  if (lastEmitted === key) return;
23
23
  lastEmitted = key;
24
24
  handler(entry);
25
25
  } }, element);
26
- return () => observer.disconnect();
27
26
  }
28
27
 
29
28
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"subscribe-class-name.mjs","names":["lastEmitted: keyof Themes | undefined | null"],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":["import { observeAttributes } from '../../attributes/observe-attribute.ts'\nimport type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Subscribes to changes on the class attribute and invokes the handler with parsed theme entries.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param handler - Callback invoked when the class attribute changes\n * @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).\n */\nexport function subscribeClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\thandler: (entry: ThemeEntry<Themes> | undefined) => void,\n\toptions?:\n\t\t| { element?: Element | null | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): () => void {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return () => {}\n\tconst parse = options?.parse ?? parseClassName\n\tlet lastEmitted: keyof Themes | undefined | null = null\n\tconst observer = observeAttributes(\n\t\t{\n\t\t\tclass: (value) => {\n\t\t\t\tconst entry = parse(themes, value ?? undefined)\n\t\t\t\tconst key = entry?.theme ?? undefined\n\t\t\t\tif (lastEmitted === key) return\n\t\t\t\tlastEmitted = key\n\t\t\t\thandler(entry)\n\t\t\t}\n\t\t},\n\t\telement\n\t)\n\treturn () => observer.disconnect()\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,mBACf,QACA,SACA,SAGa;CACb,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,cAAa;CAC3B,MAAM,QAAQ,SAAS,SAAS;CAChC,IAAIA,cAA+C;CACnD,MAAM,WAAW,kBAChB,EACC,QAAQ,UAAU;EACjB,MAAM,QAAQ,MAAM,QAAQ,SAAS,OAAU;EAC/C,MAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,gBAAgB,IAAK;AACzB,gBAAc;AACd,UAAQ,MAAM;IAEf,EACD,QACA;AACD,cAAa,SAAS,YAAY"}
1
+ {"version":3,"file":"subscribe-class-name.mjs","names":["lastEmitted: keyof Themes | undefined | null"],"sources":["../../../src/theme/class-name/subscribe-class-name.ts"],"sourcesContent":["import { observeAttributes } from '../../attributes/observe-attribute.ts'\nimport type { ParseStoredTheme, ThemeEntry } from '../theme-entry.types.ts'\nimport type { ThemeMap } from '../theme-map.types.ts'\nimport { parseClassName } from './parse-class-name.ts'\n\n/**\n * Subscribes to changes on the class attribute and invokes the handler with parsed theme entries.\n *\n * @param themes - Record mapping theme keys to class name(s)\n * @param handler - Callback invoked when the class attribute changes\n * @param options.element - Element to observe (accepts null e.g. from refs). Defaults to document.documentElement.\n * @param options.parse - Custom parser (default: parseClassName)\n * @returns Unsubscribe function. Returns a no-op function when element is not available (e.g. SSR).\n */\nexport function subscribeClassName<Themes extends ThemeMap>(\n\tthemes: Themes,\n\thandler: (entry: ThemeEntry<Themes> | undefined) => void,\n\toptions?:\n\t\t| { element?: Element | null | undefined; parse?: ParseStoredTheme<Themes> | undefined }\n\t\t| undefined\n): () => void {\n\tconst element = options?.element ?? document?.documentElement\n\tif (!element) return () => {}\n\tconst parse = options?.parse ?? parseClassName\n\tlet lastEmitted: keyof Themes | undefined | null = null\n\treturn observeAttributes(\n\t\t{\n\t\t\tclass: (value) => {\n\t\t\t\tconst entry = parse(themes, value ?? undefined)\n\t\t\t\tconst key = entry?.theme ?? undefined\n\t\t\t\tif (lastEmitted === key) return\n\t\t\t\tlastEmitted = key\n\t\t\t\thandler(entry)\n\t\t\t}\n\t\t},\n\t\telement\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,mBACf,QACA,SACA,SAGa;CACb,MAAM,UAAU,SAAS,WAAW,UAAU;AAC9C,KAAI,CAAC,QAAS,cAAa;CAC3B,MAAM,QAAQ,SAAS,SAAS;CAChC,IAAIA,cAA+C;AACnD,QAAO,kBACN,EACC,QAAQ,UAAU;EACjB,MAAM,QAAQ,MAAM,QAAQ,SAAS,OAAU;EAC/C,MAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,gBAAgB,IAAK;AACzB,gBAAc;AACd,UAAQ,MAAM;IAEf,EACD,QACA"}