asterui 0.12.16 → 0.12.17

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 (140) hide show
  1. package/dist/components/Checkbox.d.ts +3 -1
  2. package/dist/components/Form.d.ts +7 -1
  3. package/dist/components/Input.d.ts +10 -2
  4. package/dist/index.d.ts +0 -2
  5. package/dist/index.js +134 -136
  6. package/dist/index.js.map +1 -1
  7. package/dist/index10.js +70 -65
  8. package/dist/index10.js.map +1 -1
  9. package/dist/index100.js +43 -11
  10. package/dist/index100.js.map +1 -1
  11. package/dist/index101.js +11 -44
  12. package/dist/index101.js.map +1 -1
  13. package/dist/index102.js +12 -10
  14. package/dist/index102.js.map +1 -1
  15. package/dist/index103.js +7 -14
  16. package/dist/index103.js.map +1 -1
  17. package/dist/index104.js +12 -7
  18. package/dist/index104.js.map +1 -1
  19. package/dist/index105.js +29 -11
  20. package/dist/index105.js.map +1 -1
  21. package/dist/index106.js +16 -29
  22. package/dist/index106.js.map +1 -1
  23. package/dist/index34.js +198 -158
  24. package/dist/index34.js.map +1 -1
  25. package/dist/index42.js +185 -148
  26. package/dist/index42.js.map +1 -1
  27. package/dist/index43.js +19 -19
  28. package/dist/index43.js.map +1 -1
  29. package/dist/index46.js +134 -18
  30. package/dist/index46.js.map +1 -1
  31. package/dist/index47.js +10 -134
  32. package/dist/index47.js.map +1 -1
  33. package/dist/index48.js +35 -13
  34. package/dist/index48.js.map +1 -1
  35. package/dist/index49.js +34 -35
  36. package/dist/index49.js.map +1 -1
  37. package/dist/index50.js +81 -34
  38. package/dist/index50.js.map +1 -1
  39. package/dist/index51.js +166 -71
  40. package/dist/index51.js.map +1 -1
  41. package/dist/index52.js +144 -167
  42. package/dist/index52.js.map +1 -1
  43. package/dist/index53.js +11 -152
  44. package/dist/index53.js.map +1 -1
  45. package/dist/index54.js +20 -10
  46. package/dist/index54.js.map +1 -1
  47. package/dist/index55.js +14 -22
  48. package/dist/index55.js.map +1 -1
  49. package/dist/index56.js +7 -14
  50. package/dist/index56.js.map +1 -1
  51. package/dist/index57.js +333 -6
  52. package/dist/index57.js.map +1 -1
  53. package/dist/index58.js +47 -334
  54. package/dist/index58.js.map +1 -1
  55. package/dist/index59.js +122 -47
  56. package/dist/index59.js.map +1 -1
  57. package/dist/index60.js +108 -120
  58. package/dist/index60.js.map +1 -1
  59. package/dist/index61.js +167 -107
  60. package/dist/index61.js.map +1 -1
  61. package/dist/index62.js +29 -167
  62. package/dist/index62.js.map +1 -1
  63. package/dist/index63.js +120 -30
  64. package/dist/index63.js.map +1 -1
  65. package/dist/index64.js +80 -116
  66. package/dist/index64.js.map +1 -1
  67. package/dist/index65.js +19 -85
  68. package/dist/index65.js.map +1 -1
  69. package/dist/index66.js +73 -19
  70. package/dist/index66.js.map +1 -1
  71. package/dist/index67.js +54 -71
  72. package/dist/index67.js.map +1 -1
  73. package/dist/index68.js +44 -56
  74. package/dist/index68.js.map +1 -1
  75. package/dist/index69.js +49 -42
  76. package/dist/index69.js.map +1 -1
  77. package/dist/index70.js +121 -50
  78. package/dist/index70.js.map +1 -1
  79. package/dist/index71.js +102 -118
  80. package/dist/index71.js.map +1 -1
  81. package/dist/index72.js +41 -107
  82. package/dist/index72.js.map +1 -1
  83. package/dist/index73.js +68 -41
  84. package/dist/index73.js.map +1 -1
  85. package/dist/index74.js +19 -66
  86. package/dist/index74.js.map +1 -1
  87. package/dist/index75.js +55 -18
  88. package/dist/index75.js.map +1 -1
  89. package/dist/index76.js +251 -55
  90. package/dist/index76.js.map +1 -1
  91. package/dist/index77.js +22 -254
  92. package/dist/index77.js.map +1 -1
  93. package/dist/index78.js +31 -22
  94. package/dist/index78.js.map +1 -1
  95. package/dist/index79.js +93 -30
  96. package/dist/index79.js.map +1 -1
  97. package/dist/index80.js +324 -89
  98. package/dist/index80.js.map +1 -1
  99. package/dist/index81.js +73 -322
  100. package/dist/index81.js.map +1 -1
  101. package/dist/index82.js +39 -79
  102. package/dist/index82.js.map +1 -1
  103. package/dist/index83.js +23 -40
  104. package/dist/index83.js.map +1 -1
  105. package/dist/index84.js +93 -21
  106. package/dist/index84.js.map +1 -1
  107. package/dist/index85.js +148 -87
  108. package/dist/index85.js.map +1 -1
  109. package/dist/index86.js +152 -147
  110. package/dist/index86.js.map +1 -1
  111. package/dist/index87.js +63 -159
  112. package/dist/index87.js.map +1 -1
  113. package/dist/index88.js +35 -65
  114. package/dist/index88.js.map +1 -1
  115. package/dist/index89.js +234 -35
  116. package/dist/index89.js.map +1 -1
  117. package/dist/index90.js +31 -231
  118. package/dist/index90.js.map +1 -1
  119. package/dist/index91.js +210 -34
  120. package/dist/index91.js.map +1 -1
  121. package/dist/index92.js +198 -195
  122. package/dist/index92.js.map +1 -1
  123. package/dist/index93.js +241 -159
  124. package/dist/index93.js.map +1 -1
  125. package/dist/index94.js +166 -283
  126. package/dist/index94.js.map +1 -1
  127. package/dist/index95.js +253 -173
  128. package/dist/index95.js.map +1 -1
  129. package/dist/index96.js +14 -258
  130. package/dist/index96.js.map +1 -1
  131. package/dist/index97.js +31 -12
  132. package/dist/index97.js.map +1 -1
  133. package/dist/index98.js +5 -32
  134. package/dist/index98.js.map +1 -1
  135. package/dist/index99.js +13 -5
  136. package/dist/index99.js.map +1 -1
  137. package/package.json +1 -1
  138. package/dist/components/Label.d.ts +0 -15
  139. package/dist/index107.js +0 -21
  140. package/dist/index107.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index10.js","sources":["../src/components/Checkbox.tsx"],"sourcesContent":["import React, { forwardRef, createContext, useContext } from 'react'\n\nexport interface CheckboxSwapConfig {\n /** Content shown when checked */\n on: React.ReactNode\n /** Content shown when unchecked */\n off: React.ReactNode\n /** Animation effect for the swap transition */\n effect?: 'rotate' | 'flip'\n}\n\nexport interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'type'> {\n children?: React.ReactNode\n size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'\n color?: 'primary' | 'secondary' | 'accent' | 'neutral' | 'success' | 'warning' | 'info' | 'error'\n indeterminate?: boolean\n /** Swap mode: toggle between two visual states instead of showing a checkbox */\n swap?: CheckboxSwapConfig\n className?: string\n}\n\nexport interface CheckboxOptionType {\n label: React.ReactNode\n value: string | number\n disabled?: boolean\n}\n\nexport interface CheckboxGroupProps {\n children?: React.ReactNode\n value?: (string | number)[]\n defaultValue?: (string | number)[]\n onChange?: (values: (string | number)[]) => void\n disabled?: boolean\n options?: (string | number | CheckboxOptionType)[]\n className?: string\n}\n\ninterface CheckboxGroupContextValue {\n value?: (string | number)[]\n onChange?: (checkedValue: string | number, checked: boolean) => void\n disabled?: boolean\n}\n\nconst CheckboxGroupContext = createContext<CheckboxGroupContextValue | null>(null)\n\nfunction CheckboxGroup({\n children,\n value,\n defaultValue,\n onChange,\n disabled = false,\n options,\n className = ''\n}: CheckboxGroupProps) {\n const [internalValue, setInternalValue] = React.useState<(string | number)[]>(defaultValue || [])\n const currentValue = value !== undefined ? value : internalValue\n\n const handleChange = (checkedValue: string | number, checked: boolean) => {\n const newValue = checked\n ? [...currentValue, checkedValue]\n : currentValue.filter((v) => v !== checkedValue)\n\n if (value === undefined) {\n setInternalValue(newValue)\n }\n onChange?.(newValue)\n }\n\n const contextValue: CheckboxGroupContextValue = {\n value: currentValue,\n onChange: handleChange,\n disabled,\n }\n\n // If options are provided, render checkboxes automatically\n if (options) {\n return (\n <CheckboxGroupContext.Provider value={contextValue}>\n <div className={className}>\n {options.map((option) => {\n if (typeof option === 'string' || typeof option === 'number') {\n return (\n <label key={option} className=\"label cursor-pointer justify-start gap-2\">\n <CheckboxRoot value={option} />\n <span className=\"label-text\">{option}</span>\n </label>\n )\n } else {\n return (\n <label key={option.value} className=\"label cursor-pointer justify-start gap-2\">\n <CheckboxRoot value={option.value} disabled={option.disabled} />\n <span className=\"label-text\">{option.label}</span>\n </label>\n )\n }\n })}\n </div>\n </CheckboxGroupContext.Provider>\n )\n }\n\n return (\n <CheckboxGroupContext.Provider value={contextValue}>\n <div className={className}>{children}</div>\n </CheckboxGroupContext.Provider>\n )\n}\n\nconst CheckboxRoot = forwardRef<HTMLInputElement, CheckboxProps>(\n (\n {\n children,\n size,\n color,\n indeterminate = false,\n swap,\n className = '',\n value,\n checked,\n onChange,\n disabled: disabledProp,\n ...props\n },\n ref\n ) => {\n const groupContext = useContext(CheckboxGroupContext)\n\n const sizeClasses = {\n xs: 'checkbox-xs',\n sm: 'checkbox-sm',\n md: 'checkbox-md',\n lg: 'checkbox-lg',\n xl: 'checkbox-xl',\n }\n\n const colorClasses = {\n primary: 'checkbox-primary',\n secondary: 'checkbox-secondary',\n accent: 'checkbox-accent',\n neutral: 'checkbox-neutral',\n success: 'checkbox-success',\n warning: 'checkbox-warning',\n info: 'checkbox-info',\n error: 'checkbox-error',\n }\n\n const checkboxClasses = [\n 'checkbox',\n size && sizeClasses[size],\n color && colorClasses[color],\n ]\n .filter(Boolean)\n .join(' ')\n\n // If in a group, use group's value to determine checked state\n const isChecked = groupContext && value !== undefined && (typeof value === 'string' || typeof value === 'number')\n ? groupContext.value?.includes(value) ?? false\n : checked\n\n const isDisabled = groupContext?.disabled || disabledProp\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (groupContext && value !== undefined && (typeof value === 'string' || typeof value === 'number')) {\n groupContext.onChange?.(value, e.target.checked)\n }\n onChange?.(e)\n }\n\n // Handle indeterminate state\n const checkboxRef = React.useCallback(\n (node: HTMLInputElement | null) => {\n if (node) {\n node.indeterminate = indeterminate\n }\n if (typeof ref === 'function') {\n ref(node)\n } else if (ref) {\n ref.current = node\n }\n },\n [indeterminate, ref]\n )\n\n const dataState = indeterminate ? 'indeterminate' : isChecked ? 'checked' : 'unchecked'\n\n // Swap mode: render as a swap toggle instead of checkbox\n if (swap) {\n const swapClasses = [\n 'swap',\n swap.effect === 'rotate' && 'swap-rotate',\n swap.effect === 'flip' && 'swap-flip',\n className,\n ]\n .filter(Boolean)\n .join(' ')\n\n return (\n <label className={swapClasses}>\n <input\n ref={ref}\n type=\"checkbox\"\n checked={isChecked}\n onChange={handleChange}\n disabled={isDisabled}\n data-state={dataState}\n {...props}\n />\n <div className=\"swap-on\">{swap.on}</div>\n <div className=\"swap-off\">{swap.off}</div>\n </label>\n )\n }\n\n const checkboxInput = (\n <input\n ref={checkboxRef}\n type=\"checkbox\"\n className={checkboxClasses}\n value={value}\n checked={isChecked}\n onChange={handleChange}\n disabled={isDisabled}\n data-state={dataState}\n {...props}\n />\n )\n\n // If children provided, wrap in label\n if (children) {\n return (\n <label className={`label cursor-pointer justify-start gap-2 ${className}`}>\n {checkboxInput}\n <span className=\"label-text\">{children}</span>\n </label>\n )\n }\n\n return checkboxInput\n }\n)\n\nCheckboxRoot.displayName = 'Checkbox'\n\nexport const Checkbox = Object.assign(CheckboxRoot, {\n Group: CheckboxGroup,\n})\n"],"names":["CheckboxGroupContext","createContext","CheckboxGroup","children","value","defaultValue","onChange","disabled","options","className","internalValue","setInternalValue","React","currentValue","contextValue","checkedValue","checked","newValue","v","jsx","option","jsxs","CheckboxRoot","forwardRef","size","color","indeterminate","swap","disabledProp","props","ref","groupContext","useContext","sizeClasses","colorClasses","checkboxClasses","isChecked","isDisabled","handleChange","e","checkboxRef","node","dataState","swapClasses","checkboxInput","Checkbox"],"mappings":";;AA2CA,MAAMA,IAAuBC,EAAgD,IAAI;AAEjF,SAASC,EAAc;AAAA,EACrB,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,cAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,SAAAC;AAAA,EACA,WAAAC,IAAY;AACd,GAAuB;AACrB,QAAM,CAACC,GAAeC,CAAgB,IAAIC,EAAM,SAA8BP,KAAgB,EAAE,GAC1FQ,IAAeT,MAAU,SAAYA,IAAQM,GAa7CI,IAA0C;AAAA,IAC9C,OAAOD;AAAA,IACP,UAbmB,CAACE,GAA+BC,MAAqB;AACxE,YAAMC,IAAWD,IACb,CAAC,GAA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,EAAC,SAAA,EAAM,WAAWsB,GAChB,UAAA;AAAA,QAAA,gBAAAxB;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,KAAAW;AAAA,YACA,MAAK;AAAA,YACL,SAASM;AAAA,YACT,UAAUE;AAAA,YACV,UAAUD;AAAA,YACV,cAAYK;AAAA,YACX,GAAGb;AAAA,UAAA;AAAA,QAAA;AAAA,QAEN,gBAAAV,EAAC,OAAA,EAAI,WAAU,WAAW,YAAK,IAAG;AAAA,QAClC,gBAAAA,EAAC,OAAA,EAAI,WAAU,YAAY,YAAK,IAAA,CAAI;AAAA,MAAA,GACtC;AAAA,IAEJ;AAEA,UAAMyB,IACJ,gBAAAzB;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,KAAKqB;AAAA,QACL,MAAK;AAAA,QACL,WAAWL;AAAA,QACX,OAAA/B;AAAA,QACA,SAASgC;AAAA,QACT,UAAUE;AAAA,QACV,UAAUD;AAAA,QACV,cAAYK;AAAA,QACX,GAAGb;AAAA,MAAA;AAAA,IAAA;AAKR,WAAI1B,IAEA,gBAAAkB,EAAC,SAAA,EAAM,WAAW,4CAA4CZ,CAAS,IACpE,UAAA;AAAA,MAAAmC;AAAA,MACD,gBAAAzB,EAAC,QAAA,EAAK,WAAU,cAAc,UAAAhB,EAAA,CAAS;AAAA,IAAA,GACzC,IAIGyC;AAAA,EACT;AACF;AAEAtB,EAAa,cAAc;AAEpB,MAAMuB,IAAW,OAAO,OAAOvB,GAAc;AAAA,EAClD,OAAOpB;AACT,CAAC;"}
1
+ {"version":3,"file":"index10.js","sources":["../src/components/Checkbox.tsx"],"sourcesContent":["import React, { forwardRef, createContext, useContext } from 'react'\n\nexport interface CheckboxSwapConfig {\n /** Content shown when checked */\n on: React.ReactNode\n /** Content shown when unchecked */\n off: React.ReactNode\n /** Animation effect for the swap transition */\n effect?: 'rotate' | 'flip'\n}\n\nexport interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'type'> {\n children?: React.ReactNode\n size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'\n color?: 'primary' | 'secondary' | 'accent' | 'neutral' | 'success' | 'warning' | 'info' | 'error'\n indeterminate?: boolean\n /** Swap mode: toggle between two visual states instead of showing a checkbox */\n swap?: CheckboxSwapConfig\n className?: string\n}\n\nexport interface CheckboxOptionType {\n label: React.ReactNode\n value: string | number\n disabled?: boolean\n}\n\nexport interface CheckboxGroupProps {\n children?: React.ReactNode\n value?: (string | number)[]\n defaultValue?: (string | number)[]\n onChange?: (values: (string | number)[]) => void\n disabled?: boolean\n options?: (string | number | CheckboxOptionType)[]\n /** Layout direction for options */\n direction?: 'horizontal' | 'vertical'\n className?: string\n}\n\ninterface CheckboxGroupContextValue {\n value?: (string | number)[]\n onChange?: (checkedValue: string | number, checked: boolean) => void\n disabled?: boolean\n}\n\nconst CheckboxGroupContext = createContext<CheckboxGroupContextValue | null>(null)\n\nfunction CheckboxGroup({\n children,\n value,\n defaultValue,\n onChange,\n disabled = false,\n options,\n direction = 'vertical',\n className = ''\n}: CheckboxGroupProps) {\n const [internalValue, setInternalValue] = React.useState<(string | number)[]>(defaultValue || [])\n const currentValue = value !== undefined ? value : internalValue\n\n const handleChange = (checkedValue: string | number, checked: boolean) => {\n const newValue = checked\n ? [...currentValue, checkedValue]\n : currentValue.filter((v) => v !== checkedValue)\n\n if (value === undefined) {\n setInternalValue(newValue)\n }\n onChange?.(newValue)\n }\n\n const contextValue: CheckboxGroupContextValue = {\n value: currentValue,\n onChange: handleChange,\n disabled,\n }\n\n // If options are provided, render checkboxes automatically\n if (options) {\n const directionClasses = direction === 'horizontal' ? 'flex flex-row flex-wrap gap-4' : 'flex flex-col'\n return (\n <CheckboxGroupContext.Provider value={contextValue}>\n <div className={`${directionClasses} ${className}`.trim()}>\n {options.map((option) => {\n if (typeof option === 'string' || typeof option === 'number') {\n return (\n <label key={option} className=\"label cursor-pointer justify-start gap-2\">\n <CheckboxRoot value={option} />\n <span className=\"label-text\">{option}</span>\n </label>\n )\n } else {\n return (\n <label key={option.value} className=\"label cursor-pointer justify-start gap-2\">\n <CheckboxRoot value={option.value} disabled={option.disabled} />\n <span className=\"label-text\">{option.label}</span>\n </label>\n )\n }\n })}\n </div>\n </CheckboxGroupContext.Provider>\n )\n }\n\n return (\n <CheckboxGroupContext.Provider value={contextValue}>\n <div className={className}>{children}</div>\n </CheckboxGroupContext.Provider>\n )\n}\n\nconst CheckboxRoot = forwardRef<HTMLInputElement, CheckboxProps>(\n (\n {\n children,\n size,\n color,\n indeterminate = false,\n swap,\n className = '',\n value,\n checked,\n onChange,\n disabled: disabledProp,\n ...props\n },\n ref\n ) => {\n const groupContext = useContext(CheckboxGroupContext)\n\n const sizeClasses = {\n xs: 'checkbox-xs',\n sm: 'checkbox-sm',\n md: 'checkbox-md',\n lg: 'checkbox-lg',\n xl: 'checkbox-xl',\n }\n\n const colorClasses = {\n primary: 'checkbox-primary',\n secondary: 'checkbox-secondary',\n accent: 'checkbox-accent',\n neutral: 'checkbox-neutral',\n success: 'checkbox-success',\n warning: 'checkbox-warning',\n info: 'checkbox-info',\n error: 'checkbox-error',\n }\n\n const checkboxClasses = [\n 'checkbox',\n size && sizeClasses[size],\n color && colorClasses[color],\n ]\n .filter(Boolean)\n .join(' ')\n\n // If in a group, use group's value to determine checked state\n const isChecked = groupContext && value !== undefined && (typeof value === 'string' || typeof value === 'number')\n ? groupContext.value?.includes(value) ?? false\n : checked\n\n const isDisabled = groupContext?.disabled || disabledProp\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (groupContext && value !== undefined && (typeof value === 'string' || typeof value === 'number')) {\n groupContext.onChange?.(value, e.target.checked)\n }\n onChange?.(e)\n }\n\n // Handle indeterminate state\n const checkboxRef = React.useCallback(\n (node: HTMLInputElement | null) => {\n if (node) {\n node.indeterminate = indeterminate\n }\n if (typeof ref === 'function') {\n ref(node)\n } else if (ref) {\n ref.current = node\n }\n },\n [indeterminate, ref]\n )\n\n const dataState = indeterminate ? 'indeterminate' : isChecked ? 'checked' : 'unchecked'\n\n // Swap mode: render as a swap toggle instead of checkbox\n if (swap) {\n const swapClasses = [\n 'swap',\n swap.effect === 'rotate' && 'swap-rotate',\n swap.effect === 'flip' && 'swap-flip',\n className,\n ]\n .filter(Boolean)\n .join(' ')\n\n return (\n <label className={swapClasses}>\n <input\n ref={ref}\n type=\"checkbox\"\n checked={isChecked}\n onChange={handleChange}\n disabled={isDisabled}\n data-state={dataState}\n {...props}\n />\n <div className=\"swap-on\">{swap.on}</div>\n <div className=\"swap-off\">{swap.off}</div>\n </label>\n )\n }\n\n const checkboxInput = (\n <input\n ref={checkboxRef}\n type=\"checkbox\"\n className={checkboxClasses}\n value={value}\n checked={isChecked}\n onChange={handleChange}\n disabled={isDisabled}\n data-state={dataState}\n {...props}\n />\n )\n\n // If children provided, wrap in label\n if (children) {\n return (\n <label className={`label cursor-pointer justify-start gap-2 ${className}`}>\n {checkboxInput}\n <span className=\"label-text\">{children}</span>\n </label>\n )\n }\n\n return checkboxInput\n }\n)\n\nCheckboxRoot.displayName = 'Checkbox'\n\nexport const Checkbox = Object.assign(CheckboxRoot, {\n Group: CheckboxGroup,\n})\n"],"names":["CheckboxGroupContext","createContext","CheckboxGroup","children","value","defaultValue","onChange","disabled","options","direction","className","internalValue","setInternalValue","React","currentValue","contextValue","checkedValue","checked","newValue","v","directionClasses","option","jsxs","jsx","CheckboxRoot","forwardRef","size","color","indeterminate","swap","disabledProp","props","ref","groupContext","useContext","sizeClasses","colorClasses","checkboxClasses","isChecked","isDisabled","handleChange","e","checkboxRef","node","dataState","swapClasses","checkboxInput","Checkbox"],"mappings":";;AA6CA,MAAMA,IAAuBC,EAAgD,IAAI;AAEjF,SAASC,EAAc;AAAA,EACrB,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,cAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,SAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,WAAAC,IAA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,OAAOtB;AACT,CAAC;"}
package/dist/index100.js CHANGED
@@ -1,17 +1,49 @@
1
- import { useState as a, useCallback as s } from "react";
2
- function p(t = 2e3) {
3
- const [n, r] = a(!1), [l, e] = a(null), c = s(async (i) => {
1
+ import { useState as u, useCallback as c, useEffect as f } from "react";
2
+ function S(o, t) {
3
+ const [s, n] = u(() => {
4
+ if (typeof window > "u")
5
+ return t;
4
6
  try {
5
- return await navigator.clipboard.writeText(i), r(!0), e(null), setTimeout(() => r(!1), t), !0;
6
- } catch (o) {
7
- return e(o instanceof Error ? o : new Error("Failed to copy")), r(!1), !1;
7
+ const e = window.localStorage.getItem(o);
8
+ return e ? JSON.parse(e) : t;
9
+ } catch {
10
+ return t;
8
11
  }
9
- }, [t]), u = s(() => {
10
- r(!1), e(null);
11
- }, []);
12
- return { copy: c, copied: n, error: l, reset: u };
12
+ }), d = c(
13
+ (e) => {
14
+ n((r) => {
15
+ const a = e instanceof Function ? e(r) : e;
16
+ if (typeof window < "u")
17
+ try {
18
+ window.localStorage.setItem(o, JSON.stringify(a));
19
+ } catch (l) {
20
+ console.warn(`Failed to save to localStorage key "${o}":`, l);
21
+ }
22
+ return a;
23
+ });
24
+ },
25
+ [o]
26
+ ), w = c(() => {
27
+ if (typeof window < "u")
28
+ try {
29
+ window.localStorage.removeItem(o);
30
+ } catch (e) {
31
+ console.warn(`Failed to remove localStorage key "${o}":`, e);
32
+ }
33
+ n(t);
34
+ }, [o, t]);
35
+ return f(() => {
36
+ const e = (r) => {
37
+ if (r.key === o && r.newValue !== null)
38
+ try {
39
+ n(JSON.parse(r.newValue));
40
+ } catch {
41
+ }
42
+ };
43
+ return window.addEventListener("storage", e), () => window.removeEventListener("storage", e);
44
+ }, [o]), [s, d, w];
13
45
  }
14
46
  export {
15
- p as useClipboard
47
+ S as useLocalStorage
16
48
  };
17
49
  //# sourceMappingURL=index100.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index100.js","sources":["../src/hooks/useClipboard.ts"],"sourcesContent":["import { useState, useCallback } from 'react'\n\nexport interface UseClipboardReturn {\n copy: (text: string) => Promise<boolean>\n copied: boolean\n error: Error | null\n reset: () => void\n}\n\n/**\n * Hook for copying text to clipboard with success/error state.\n *\n * @param timeout - Duration in ms to show copied state (default: 2000)\n * @returns Object with copy function and state\n *\n * @example\n * const { copy, copied } = useClipboard()\n *\n * <Button onClick={() => copy('Hello!')}>\n * {copied ? 'Copied!' : 'Copy'}\n * </Button>\n */\nexport function useClipboard(timeout = 2000): UseClipboardReturn {\n const [copied, setCopied] = useState(false)\n const [error, setError] = useState<Error | null>(null)\n\n const copy = useCallback(async (text: string): Promise<boolean> => {\n try {\n await navigator.clipboard.writeText(text)\n setCopied(true)\n setError(null)\n\n setTimeout(() => setCopied(false), timeout)\n return true\n } catch (err) {\n setError(err instanceof Error ? err : new Error('Failed to copy'))\n setCopied(false)\n return false\n }\n }, [timeout])\n\n const reset = useCallback(() => {\n setCopied(false)\n setError(null)\n }, [])\n\n return { copy, copied, error, reset }\n}\n"],"names":["useClipboard","timeout","copied","setCopied","useState","error","setError","copy","useCallback","text","err","reset"],"mappings":";AAsBO,SAASA,EAAaC,IAAU,KAA0B;AAC/D,QAAM,CAACC,GAAQC,CAAS,IAAIC,EAAS,EAAK,GACpC,CAACC,GAAOC,CAAQ,IAAIF,EAAuB,IAAI,GAE/CG,IAAOC,EAAY,OAAOC,MAAmC;AACjE,QAAI;AACF,mBAAM,UAAU,UAAU,UAAUA,CAAI,GACxCN,EAAU,EAAI,GACdG,EAAS,IAAI,GAEb,WAAW,MAAMH,EAAU,EAAK,GAAGF,CAAO,GACnC;AAAA,IACT,SAASS,GAAK;AACZ,aAAAJ,EAASI,aAAe,QAAQA,IAAM,IAAI,MAAM,gBAAgB,CAAC,GACjEP,EAAU,EAAK,GACR;AAAA,IACT;AAAA,EACF,GAAG,CAACF,CAAO,CAAC,GAENU,IAAQH,EAAY,MAAM;AAC9B,IAAAL,EAAU,EAAK,GACfG,EAAS,IAAI;AAAA,EACf,GAAG,CAAA,CAAE;AAEL,SAAO,EAAE,MAAAC,GAAM,QAAAL,GAAQ,OAAAG,GAAO,OAAAM,EAAA;AAChC;"}
1
+ {"version":3,"file":"index100.js","sources":["../src/hooks/useLocalStorage.ts"],"sourcesContent":["import { useState, useCallback, useEffect } from 'react'\n\n/**\n * Hook for persisting state to localStorage.\n *\n * @param key - localStorage key\n * @param initialValue - Initial value if key doesn't exist\n * @returns [value, setValue, removeValue] tuple\n *\n * @example\n * const [theme, setTheme] = useLocalStorage('theme', 'light')\n * const [user, setUser, removeUser] = useLocalStorage('user', null)\n */\nexport function useLocalStorage<T>(\n key: string,\n initialValue: T\n): [T, (value: T | ((prev: T) => T)) => void, () => void] {\n // Get initial value from localStorage or use default\n const [storedValue, setStoredValue] = useState<T>(() => {\n if (typeof window === 'undefined') {\n return initialValue\n }\n\n try {\n const item = window.localStorage.getItem(key)\n return item ? (JSON.parse(item) as T) : initialValue\n } catch {\n return initialValue\n }\n })\n\n // Update localStorage when value changes\n const setValue = useCallback(\n (value: T | ((prev: T) => T)) => {\n setStoredValue(prev => {\n const valueToStore = value instanceof Function ? value(prev) : value\n\n if (typeof window !== 'undefined') {\n try {\n window.localStorage.setItem(key, JSON.stringify(valueToStore))\n } catch (error) {\n console.warn(`Failed to save to localStorage key \"${key}\":`, error)\n }\n }\n\n return valueToStore\n })\n },\n [key]\n )\n\n // Remove from localStorage\n const removeValue = useCallback(() => {\n if (typeof window !== 'undefined') {\n try {\n window.localStorage.removeItem(key)\n } catch (error) {\n console.warn(`Failed to remove localStorage key \"${key}\":`, error)\n }\n }\n setStoredValue(initialValue)\n }, [key, initialValue])\n\n // Sync with other tabs/windows\n useEffect(() => {\n const handleStorageChange = (e: StorageEvent) => {\n if (e.key === key && e.newValue !== null) {\n try {\n setStoredValue(JSON.parse(e.newValue) as T)\n } catch {\n // Ignore parse errors\n }\n }\n }\n\n window.addEventListener('storage', handleStorageChange)\n return () => window.removeEventListener('storage', handleStorageChange)\n }, [key])\n\n return [storedValue, setValue, removeValue]\n}\n"],"names":["useLocalStorage","key","initialValue","storedValue","setStoredValue","useState","item","setValue","useCallback","value","prev","valueToStore","error","removeValue","useEffect","handleStorageChange","e"],"mappings":";AAaO,SAASA,EACdC,GACAC,GACwD;AAExD,QAAM,CAACC,GAAaC,CAAc,IAAIC,EAAY,MAAM;AACtD,QAAI,OAAO,SAAW;AACpB,aAAOH;AAGT,QAAI;AACF,YAAMI,IAAO,OAAO,aAAa,QAAQL,CAAG;AAC5C,aAAOK,IAAQ,KAAK,MAAMA,CAAI,IAAUJ;AAAA,IAC1C,QAAQ;AACN,aAAOA;AAAA,IACT;AAAA,EACF,CAAC,GAGKK,IAAWC;AAAA,IACf,CAACC,MAAgC;AAC/B,MAAAL,EAAe,CAAAM,MAAQ;AACrB,cAAMC,IAAeF,aAAiB,WAAWA,EAAMC,CAAI,IAAID;AAE/D,YAAI,OAAO,SAAW;AACpB,cAAI;AACF,mBAAO,aAAa,QAAQR,GAAK,KAAK,UAAUU,CAAY,CAAC;AAAA,UAC/D,SAASC,GAAO;AACd,oBAAQ,KAAK,uCAAuCX,CAAG,MAAMW,CAAK;AAAA,UACpE;AAGF,eAAOD;AAAA,MACT,CAAC;AAAA,IACH;AAAA,IACA,CAACV,CAAG;AAAA,EAAA,GAIAY,IAAcL,EAAY,MAAM;AACpC,QAAI,OAAO,SAAW;AACpB,UAAI;AACF,eAAO,aAAa,WAAWP,CAAG;AAAA,MACpC,SAASW,GAAO;AACd,gBAAQ,KAAK,sCAAsCX,CAAG,MAAMW,CAAK;AAAA,MACnE;AAEF,IAAAR,EAAeF,CAAY;AAAA,EAC7B,GAAG,CAACD,GAAKC,CAAY,CAAC;AAGtB,SAAAY,EAAU,MAAM;AACd,UAAMC,IAAsB,CAACC,MAAoB;AAC/C,UAAIA,EAAE,QAAQf,KAAOe,EAAE,aAAa;AAClC,YAAI;AACF,UAAAZ,EAAe,KAAK,MAAMY,EAAE,QAAQ,CAAM;AAAA,QAC5C,QAAQ;AAAA,QAER;AAAA,IAEJ;AAEA,kBAAO,iBAAiB,WAAWD,CAAmB,GAC/C,MAAM,OAAO,oBAAoB,WAAWA,CAAmB;AAAA,EACxE,GAAG,CAACd,CAAG,CAAC,GAED,CAACE,GAAaI,GAAUM,CAAW;AAC5C;"}
package/dist/index101.js CHANGED
@@ -1,49 +1,16 @@
1
- import { useState as u, useCallback as c, useEffect as f } from "react";
2
- function S(o, t) {
3
- const [s, n] = u(() => {
4
- if (typeof window > "u")
5
- return t;
6
- try {
7
- const e = window.localStorage.getItem(o);
8
- return e ? JSON.parse(e) : t;
9
- } catch {
10
- return t;
11
- }
12
- }), d = c(
13
- (e) => {
14
- n((r) => {
15
- const a = e instanceof Function ? e(r) : e;
16
- if (typeof window < "u")
17
- try {
18
- window.localStorage.setItem(o, JSON.stringify(a));
19
- } catch (l) {
20
- console.warn(`Failed to save to localStorage key "${o}":`, l);
21
- }
22
- return a;
23
- });
24
- },
25
- [o]
26
- ), w = c(() => {
27
- if (typeof window < "u")
28
- try {
29
- window.localStorage.removeItem(o);
30
- } catch (e) {
31
- console.warn(`Failed to remove localStorage key "${o}":`, e);
32
- }
33
- n(t);
34
- }, [o, t]);
35
- return f(() => {
36
- const e = (r) => {
37
- if (r.key === o && r.newValue !== null)
38
- try {
39
- n(JSON.parse(r.newValue));
40
- } catch {
41
- }
1
+ import { useState as r, useEffect as c } from "react";
2
+ function i(e, t = 300) {
3
+ const [o, u] = r(e);
4
+ return c(() => {
5
+ const n = setTimeout(() => {
6
+ u(e);
7
+ }, t);
8
+ return () => {
9
+ clearTimeout(n);
42
10
  };
43
- return window.addEventListener("storage", e), () => window.removeEventListener("storage", e);
44
- }, [o]), [s, d, w];
11
+ }, [e, t]), o;
45
12
  }
46
13
  export {
47
- S as useLocalStorage
14
+ i as useDebounce
48
15
  };
49
16
  //# sourceMappingURL=index101.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index101.js","sources":["../src/hooks/useLocalStorage.ts"],"sourcesContent":["import { useState, useCallback, useEffect } from 'react'\n\n/**\n * Hook for persisting state to localStorage.\n *\n * @param key - localStorage key\n * @param initialValue - Initial value if key doesn't exist\n * @returns [value, setValue, removeValue] tuple\n *\n * @example\n * const [theme, setTheme] = useLocalStorage('theme', 'light')\n * const [user, setUser, removeUser] = useLocalStorage('user', null)\n */\nexport function useLocalStorage<T>(\n key: string,\n initialValue: T\n): [T, (value: T | ((prev: T) => T)) => void, () => void] {\n // Get initial value from localStorage or use default\n const [storedValue, setStoredValue] = useState<T>(() => {\n if (typeof window === 'undefined') {\n return initialValue\n }\n\n try {\n const item = window.localStorage.getItem(key)\n return item ? (JSON.parse(item) as T) : initialValue\n } catch {\n return initialValue\n }\n })\n\n // Update localStorage when value changes\n const setValue = useCallback(\n (value: T | ((prev: T) => T)) => {\n setStoredValue(prev => {\n const valueToStore = value instanceof Function ? value(prev) : value\n\n if (typeof window !== 'undefined') {\n try {\n window.localStorage.setItem(key, JSON.stringify(valueToStore))\n } catch (error) {\n console.warn(`Failed to save to localStorage key \"${key}\":`, error)\n }\n }\n\n return valueToStore\n })\n },\n [key]\n )\n\n // Remove from localStorage\n const removeValue = useCallback(() => {\n if (typeof window !== 'undefined') {\n try {\n window.localStorage.removeItem(key)\n } catch (error) {\n console.warn(`Failed to remove localStorage key \"${key}\":`, error)\n }\n }\n setStoredValue(initialValue)\n }, [key, initialValue])\n\n // Sync with other tabs/windows\n useEffect(() => {\n const handleStorageChange = (e: StorageEvent) => {\n if (e.key === key && e.newValue !== null) {\n try {\n setStoredValue(JSON.parse(e.newValue) as T)\n } catch {\n // Ignore parse errors\n }\n }\n }\n\n window.addEventListener('storage', handleStorageChange)\n return () => window.removeEventListener('storage', handleStorageChange)\n }, [key])\n\n return [storedValue, setValue, removeValue]\n}\n"],"names":["useLocalStorage","key","initialValue","storedValue","setStoredValue","useState","item","setValue","useCallback","value","prev","valueToStore","error","removeValue","useEffect","handleStorageChange","e"],"mappings":";AAaO,SAASA,EACdC,GACAC,GAC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,GAAUM,CAAW;AAC5C;"}
1
+ {"version":3,"file":"index101.js","sources":["../src/hooks/useDebounce.ts"],"sourcesContent":["import { useState, useEffect } from 'react'\n\n/**\n * Hook that delays updating a value until after a specified delay.\n * Useful for search inputs to avoid excessive API calls.\n *\n * @param value - Value to debounce\n * @param delay - Delay in milliseconds (default: 300)\n * @returns Debounced value\n *\n * @example\n * const [search, setSearch] = useState('')\n * const debouncedSearch = useDebounce(search, 500)\n *\n * useEffect(() => {\n * // This runs 500ms after user stops typing\n * fetchResults(debouncedSearch)\n * }, [debouncedSearch])\n */\nexport function useDebounce<T>(value: T, delay = 300): T {\n const [debouncedValue, setDebouncedValue] = useState<T>(value)\n\n useEffect(() => {\n const timer = setTimeout(() => {\n setDebouncedValue(value)\n }, delay)\n\n return () => {\n clearTimeout(timer)\n }\n }, [value, delay])\n\n return debouncedValue\n}\n"],"names":["useDebounce","value","delay","debouncedValue","setDebouncedValue","useState","useEffect","timer"],"mappings":";AAmBO,SAASA,EAAeC,GAAUC,IAAQ,KAAQ;AACvD,QAAM,CAACC,GAAgBC,CAAiB,IAAIC,EAAYJ,CAAK;AAE7D,SAAAK,EAAU,MAAM;AACd,UAAMC,IAAQ,WAAW,MAAM;AAC7B,MAAAH,EAAkBH,CAAK;AAAA,IACzB,GAAGC,CAAK;AAER,WAAO,MAAM;AACX,mBAAaK,CAAK;AAAA,IACpB;AAAA,EACF,GAAG,CAACN,GAAOC,CAAK,CAAC,GAEVC;AACT;"}
package/dist/index102.js CHANGED
@@ -1,16 +1,18 @@
1
- import { useState as r, useEffect as c } from "react";
2
- function i(e, t = 300) {
3
- const [o, u] = r(e);
1
+ import { useRef as s, useEffect as c } from "react";
2
+ function m(t, n = !0) {
3
+ const r = s(null);
4
4
  return c(() => {
5
- const n = setTimeout(() => {
6
- u(e);
7
- }, t);
8
- return () => {
9
- clearTimeout(n);
5
+ if (!n) return;
6
+ const e = (o) => {
7
+ const u = r.current;
8
+ !u || u.contains(o.target) || t(o);
10
9
  };
11
- }, [e, t]), o;
10
+ return document.addEventListener("mousedown", e), document.addEventListener("touchstart", e), () => {
11
+ document.removeEventListener("mousedown", e), document.removeEventListener("touchstart", e);
12
+ };
13
+ }, [t, n]), r;
12
14
  }
13
15
  export {
14
- i as useDebounce
16
+ m as useClickOutside
15
17
  };
16
18
  //# sourceMappingURL=index102.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index102.js","sources":["../src/hooks/useDebounce.ts"],"sourcesContent":["import { useState, useEffect } from 'react'\n\n/**\n * Hook that delays updating a value until after a specified delay.\n * Useful for search inputs to avoid excessive API calls.\n *\n * @param value - Value to debounce\n * @param delay - Delay in milliseconds (default: 300)\n * @returns Debounced value\n *\n * @example\n * const [search, setSearch] = useState('')\n * const debouncedSearch = useDebounce(search, 500)\n *\n * useEffect(() => {\n * // This runs 500ms after user stops typing\n * fetchResults(debouncedSearch)\n * }, [debouncedSearch])\n */\nexport function useDebounce<T>(value: T, delay = 300): T {\n const [debouncedValue, setDebouncedValue] = useState<T>(value)\n\n useEffect(() => {\n const timer = setTimeout(() => {\n setDebouncedValue(value)\n }, delay)\n\n return () => {\n clearTimeout(timer)\n }\n }, [value, delay])\n\n return debouncedValue\n}\n"],"names":["useDebounce","value","delay","debouncedValue","setDebouncedValue","useState","useEffect","timer"],"mappings":";AAmBO,SAASA,EAAeC,GAAUC,IAAQ,KAAQ;AACvD,QAAM,CAACC,GAAgBC,CAAiB,IAAIC,EAAYJ,CAAK;AAE7D,SAAAK,EAAU,MAAM;AACd,UAAMC,IAAQ,WAAW,MAAM;AAC7B,MAAAH,EAAkBH,CAAK;AAAA,IACzB,GAAGC,CAAK;AAER,WAAO,MAAM;AACX,mBAAaK,CAAK;AAAA,IACpB;AAAA,EACF,GAAG,CAACN,GAAOC,CAAK,CAAC,GAEVC;AACT;"}
1
+ {"version":3,"file":"index102.js","sources":["../src/hooks/useClickOutside.ts"],"sourcesContent":["import { useEffect, useRef, type RefObject } from 'react'\n\n/**\n * Hook that detects clicks outside of a referenced element.\n * Useful for closing dropdowns, modals, or menus.\n *\n * @param handler - Callback when click outside is detected\n * @param enabled - Whether the listener is active (default: true)\n * @returns Ref to attach to the element\n *\n * @example\n * const ref = useClickOutside(() => setIsOpen(false))\n *\n * <div ref={ref}>\n * <Dropdown>...</Dropdown>\n * </div>\n */\nexport function useClickOutside<T extends HTMLElement = HTMLElement>(\n handler: (event: MouseEvent | TouchEvent) => void,\n enabled = true\n): RefObject<T | null> {\n const ref = useRef<T>(null)\n\n useEffect(() => {\n if (!enabled) return\n\n const listener = (event: MouseEvent | TouchEvent) => {\n const el = ref.current\n if (!el || el.contains(event.target as Node)) {\n return\n }\n handler(event)\n }\n\n document.addEventListener('mousedown', listener)\n document.addEventListener('touchstart', listener)\n\n return () => {\n document.removeEventListener('mousedown', listener)\n document.removeEventListener('touchstart', listener)\n }\n }, [handler, enabled])\n\n return ref\n}\n"],"names":["useClickOutside","handler","enabled","ref","useRef","useEffect","listener","event","el"],"mappings":";AAiBO,SAASA,EACdC,GACAC,IAAU,IACW;AACrB,QAAMC,IAAMC,EAAU,IAAI;AAE1B,SAAAC,EAAU,MAAM;AACd,QAAI,CAACH,EAAS;AAEd,UAAMI,IAAW,CAACC,MAAmC;AACnD,YAAMC,IAAKL,EAAI;AACf,MAAI,CAACK,KAAMA,EAAG,SAASD,EAAM,MAAc,KAG3CN,EAAQM,CAAK;AAAA,IACf;AAEA,oBAAS,iBAAiB,aAAaD,CAAQ,GAC/C,SAAS,iBAAiB,cAAcA,CAAQ,GAEzC,MAAM;AACX,eAAS,oBAAoB,aAAaA,CAAQ,GAClD,SAAS,oBAAoB,cAAcA,CAAQ;AAAA,IACrD;AAAA,EACF,GAAG,CAACL,GAASC,CAAO,CAAC,GAEdC;AACT;"}
package/dist/index103.js CHANGED
@@ -1,18 +1,11 @@
1
- import { useRef as s, useEffect as c } from "react";
2
- function m(t, n = !0) {
3
- const r = s(null);
4
- return c(() => {
5
- if (!n) return;
6
- const e = (o) => {
7
- const u = r.current;
8
- !u || u.contains(o.target) || t(o);
9
- };
10
- return document.addEventListener("mousedown", e), document.addEventListener("touchstart", e), () => {
11
- document.removeEventListener("mousedown", e), document.removeEventListener("touchstart", e);
12
- };
13
- }, [t, n]), r;
1
+ import { useRef as t, useEffect as o } from "react";
2
+ function f(r) {
3
+ const e = t(void 0);
4
+ return o(() => {
5
+ e.current = r;
6
+ }, [r]), e.current;
14
7
  }
15
8
  export {
16
- m as useClickOutside
9
+ f as usePrevious
17
10
  };
18
11
  //# sourceMappingURL=index103.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index103.js","sources":["../src/hooks/useClickOutside.ts"],"sourcesContent":["import { useEffect, useRef, type RefObject } from 'react'\n\n/**\n * Hook that detects clicks outside of a referenced element.\n * Useful for closing dropdowns, modals, or menus.\n *\n * @param handler - Callback when click outside is detected\n * @param enabled - Whether the listener is active (default: true)\n * @returns Ref to attach to the element\n *\n * @example\n * const ref = useClickOutside(() => setIsOpen(false))\n *\n * <div ref={ref}>\n * <Dropdown>...</Dropdown>\n * </div>\n */\nexport function useClickOutside<T extends HTMLElement = HTMLElement>(\n handler: (event: MouseEvent | TouchEvent) => void,\n enabled = true\n): RefObject<T | null> {\n const ref = useRef<T>(null)\n\n useEffect(() => {\n if (!enabled) return\n\n const listener = (event: MouseEvent | TouchEvent) => {\n const el = ref.current\n if (!el || el.contains(event.target as Node)) {\n return\n }\n handler(event)\n }\n\n document.addEventListener('mousedown', listener)\n document.addEventListener('touchstart', listener)\n\n return () => {\n document.removeEventListener('mousedown', listener)\n document.removeEventListener('touchstart', listener)\n }\n }, [handler, enabled])\n\n return ref\n}\n"],"names":["useClickOutside","handler","enabled","ref","useRef","useEffect","listener","event","el"],"mappings":";AAiBO,SAASA,EACdC,GACAC,IAAU,IACW;AACrB,QAAMC,IAAMC,EAAU,IAAI;AAE1B,SAAAC,EAAU,MAAM;AACd,QAAI,CAACH,EAAS;AAEd,UAAMI,IAAW,CAACC,MAAmC;AACnD,YAAMC,IAAKL,EAAI;AACf,MAAI,CAACK,KAAMA,EAAG,SAASD,EAAM,MAAc,KAG3CN,EAAQM,CAAK;AAAA,IACf;AAEA,oBAAS,iBAAiB,aAAaD,CAAQ,GAC/C,SAAS,iBAAiB,cAAcA,CAAQ,GAEzC,MAAM;AACX,eAAS,oBAAoB,aAAaA,CAAQ,GAClD,SAAS,oBAAoB,cAAcA,CAAQ;AAAA,IACrD;AAAA,EACF,GAAG,CAACL,GAASC,CAAO,CAAC,GAEdC;AACT;"}
1
+ {"version":3,"file":"index103.js","sources":["../src/hooks/usePrevious.ts"],"sourcesContent":["import { useRef, useEffect } from 'react'\n\n/**\n * Hook that returns the previous value of a variable.\n * Useful for comparing current and previous values in effects.\n *\n * @param value - Current value\n * @returns Previous value (undefined on first render)\n *\n * @example\n * const [count, setCount] = useState(0)\n * const prevCount = usePrevious(count)\n *\n * // prevCount is the value from previous render\n * console.log(`Changed from ${prevCount} to ${count}`)\n */\nexport function usePrevious<T>(value: T): T | undefined {\n const ref = useRef<T | undefined>(undefined)\n\n useEffect(() => {\n ref.current = value\n }, [value])\n\n return ref.current\n}\n"],"names":["usePrevious","value","ref","useRef","useEffect"],"mappings":";AAgBO,SAASA,EAAeC,GAAyB;AACtD,QAAMC,IAAMC,EAAsB,MAAS;AAE3C,SAAAC,EAAU,MAAM;AACd,IAAAF,EAAI,UAAUD;AAAA,EAChB,GAAG,CAACA,CAAK,CAAC,GAEHC,EAAI;AACb;"}
package/dist/index104.js CHANGED
@@ -1,11 +1,16 @@
1
- import { useRef as t, useEffect as o } from "react";
2
- function f(r) {
3
- const e = t(void 0);
4
- return o(() => {
5
- e.current = r;
6
- }, [r]), e.current;
1
+ import { useState as u, useRef as v, useEffect as a } from "react";
2
+ function f() {
3
+ const [o, t] = u(!1), n = v(null);
4
+ return a(() => {
5
+ const e = n.current;
6
+ if (!e) return;
7
+ const r = () => t(!0), s = () => t(!1);
8
+ return e.addEventListener("mouseenter", r), e.addEventListener("mouseleave", s), () => {
9
+ e.removeEventListener("mouseenter", r), e.removeEventListener("mouseleave", s);
10
+ };
11
+ }, []), { ref: n, isHovered: o };
7
12
  }
8
13
  export {
9
- f as usePrevious
14
+ f as useHover
10
15
  };
11
16
  //# sourceMappingURL=index104.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index104.js","sources":["../src/hooks/usePrevious.ts"],"sourcesContent":["import { useRef, useEffect } from 'react'\n\n/**\n * Hook that returns the previous value of a variable.\n * Useful for comparing current and previous values in effects.\n *\n * @param value - Current value\n * @returns Previous value (undefined on first render)\n *\n * @example\n * const [count, setCount] = useState(0)\n * const prevCount = usePrevious(count)\n *\n * // prevCount is the value from previous render\n * console.log(`Changed from ${prevCount} to ${count}`)\n */\nexport function usePrevious<T>(value: T): T | undefined {\n const ref = useRef<T | undefined>(undefined)\n\n useEffect(() => {\n ref.current = value\n }, [value])\n\n return ref.current\n}\n"],"names":["usePrevious","value","ref","useRef","useEffect"],"mappings":";AAgBO,SAASA,EAAeC,GAAyB;AACtD,QAAMC,IAAMC,EAAsB,MAAS;AAE3C,SAAAC,EAAU,MAAM;AACd,IAAAF,EAAI,UAAUD;AAAA,EAChB,GAAG,CAACA,CAAK,CAAC,GAEHC,EAAI;AACb;"}
1
+ {"version":3,"file":"index104.js","sources":["../src/hooks/useHover.ts"],"sourcesContent":["import { useState, useRef, useEffect, type RefObject } from 'react'\n\nexport interface UseHoverReturn<T extends HTMLElement> {\n ref: RefObject<T | null>\n isHovered: boolean\n}\n\n/**\n * Hook that tracks hover state of an element.\n *\n * @returns Object with ref and isHovered state\n *\n * @example\n * const { ref, isHovered } = useHover<HTMLDivElement>()\n *\n * <div ref={ref} className={isHovered ? 'bg-blue-500' : 'bg-gray-500'}>\n * Hover me!\n * </div>\n */\nexport function useHover<T extends HTMLElement = HTMLElement>(): UseHoverReturn<T> {\n const [isHovered, setIsHovered] = useState(false)\n const ref = useRef<T>(null)\n\n useEffect(() => {\n const node = ref.current\n if (!node) return\n\n const handleMouseEnter = () => setIsHovered(true)\n const handleMouseLeave = () => setIsHovered(false)\n\n node.addEventListener('mouseenter', handleMouseEnter)\n node.addEventListener('mouseleave', handleMouseLeave)\n\n return () => {\n node.removeEventListener('mouseenter', handleMouseEnter)\n node.removeEventListener('mouseleave', handleMouseLeave)\n }\n }, [])\n\n return { ref, isHovered }\n}\n"],"names":["useHover","isHovered","setIsHovered","useState","ref","useRef","useEffect","node","handleMouseEnter","handleMouseLeave"],"mappings":";AAmBO,SAASA,IAAmE;AACjF,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1CC,IAAMC,EAAU,IAAI;AAE1B,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAOH,EAAI;AACjB,QAAI,CAACG,EAAM;AAEX,UAAMC,IAAmB,MAAMN,EAAa,EAAI,GAC1CO,IAAmB,MAAMP,EAAa,EAAK;AAEjD,WAAAK,EAAK,iBAAiB,cAAcC,CAAgB,GACpDD,EAAK,iBAAiB,cAAcE,CAAgB,GAE7C,MAAM;AACX,MAAAF,EAAK,oBAAoB,cAAcC,CAAgB,GACvDD,EAAK,oBAAoB,cAAcE,CAAgB;AAAA,IACzD;AAAA,EACF,GAAG,CAAA,CAAE,GAEE,EAAE,KAAAL,GAAK,WAAAH,EAAA;AAChB;"}
package/dist/index105.js CHANGED
@@ -1,16 +1,34 @@
1
- import { useState as u, useRef as v, useEffect as a } from "react";
2
- function f() {
3
- const [o, t] = u(!1), n = v(null);
4
- return a(() => {
5
- const e = n.current;
6
- if (!e) return;
7
- const r = () => t(!0), s = () => t(!1);
8
- return e.addEventListener("mouseenter", r), e.addEventListener("mouseleave", s), () => {
9
- e.removeEventListener("mouseenter", r), e.removeEventListener("mouseleave", s);
1
+ import { useState as v, useCallback as i, useEffect as l } from "react";
2
+ function c(n, f = {}) {
3
+ const { target: u, event: o = "keydown", preventDefault: r = !1 } = f, [a, d] = v(!1), t = i(
4
+ (e) => {
5
+ e.key === n && (r && e.preventDefault(), d(!0));
6
+ },
7
+ [n, r]
8
+ ), s = i(
9
+ (e) => {
10
+ e.key === n && d(!1);
11
+ },
12
+ [n]
13
+ );
14
+ return l(() => {
15
+ const e = u ?? window;
16
+ return o === "keydown" ? (e.addEventListener("keydown", t), e.addEventListener("keyup", s)) : e.addEventListener("keyup", t), () => {
17
+ e.removeEventListener("keydown", t), e.removeEventListener("keyup", s);
10
18
  };
11
- }, []), { ref: n, isHovered: o };
19
+ }, [u, o, t, s]), a;
20
+ }
21
+ function y(n, f, u = {}) {
22
+ const { target: o, event: r = "keydown", preventDefault: a = !1 } = u;
23
+ l(() => {
24
+ const d = o ?? window, t = (s) => {
25
+ s.key === n && (a && s.preventDefault(), f(s));
26
+ };
27
+ return d.addEventListener(r, t), () => d.removeEventListener(r, t);
28
+ }, [o, n, f, r, a]);
12
29
  }
13
30
  export {
14
- f as useHover
31
+ c as useKeyPress,
32
+ y as useKeyPressCallback
15
33
  };
16
34
  //# sourceMappingURL=index105.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index105.js","sources":["../src/hooks/useHover.ts"],"sourcesContent":["import { useState, useRef, useEffect, type RefObject } from 'react'\n\nexport interface UseHoverReturn<T extends HTMLElement> {\n ref: RefObject<T | null>\n isHovered: boolean\n}\n\n/**\n * Hook that tracks hover state of an element.\n *\n * @returns Object with ref and isHovered state\n *\n * @example\n * const { ref, isHovered } = useHover<HTMLDivElement>()\n *\n * <div ref={ref} className={isHovered ? 'bg-blue-500' : 'bg-gray-500'}>\n * Hover me!\n * </div>\n */\nexport function useHover<T extends HTMLElement = HTMLElement>(): UseHoverReturn<T> {\n const [isHovered, setIsHovered] = useState(false)\n const ref = useRef<T>(null)\n\n useEffect(() => {\n const node = ref.current\n if (!node) return\n\n const handleMouseEnter = () => setIsHovered(true)\n const handleMouseLeave = () => setIsHovered(false)\n\n node.addEventListener('mouseenter', handleMouseEnter)\n node.addEventListener('mouseleave', handleMouseLeave)\n\n return () => {\n node.removeEventListener('mouseenter', handleMouseEnter)\n node.removeEventListener('mouseleave', handleMouseLeave)\n }\n }, [])\n\n return { ref, isHovered }\n}\n"],"names":["useHover","isHovered","setIsHovered","useState","ref","useRef","useEffect","node","handleMouseEnter","handleMouseLeave"],"mappings":";AAmBO,SAASA,IAAmE;AACjF,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1CC,IAAMC,EAAU,IAAI;AAE1B,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAOH,EAAI;AACjB,QAAI,CAACG,EAAM;AAEX,UAAMC,IAAmB,MAAMN,EAAa,EAAI,GAC1CO,IAAmB,MAAMP,EAAa,EAAK;AAEjD,WAAAK,EAAK,iBAAiB,cAAcC,CAAgB,GACpDD,EAAK,iBAAiB,cAAcE,CAAgB,GAE7C,MAAM;AACX,MAAAF,EAAK,oBAAoB,cAAcC,CAAgB,GACvDD,EAAK,oBAAoB,cAAcE,CAAgB;AAAA,IACzD;AAAA,EACF,GAAG,CAAA,CAAE,GAEE,EAAE,KAAAL,GAAK,WAAAH,EAAA;AAChB;"}
1
+ {"version":3,"file":"index105.js","sources":["../src/hooks/useKeyPress.ts"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react'\n\nexport interface UseKeyPressOptions {\n /** Target element (default: window) */\n target?: HTMLElement | Window | null\n /** Event type: 'keydown' | 'keyup' (default: 'keydown') */\n event?: 'keydown' | 'keyup'\n /** Prevent default browser behavior */\n preventDefault?: boolean\n}\n\n/**\n * Hook that detects when a specific key is pressed.\n *\n * @param targetKey - Key to detect (e.g., 'Enter', 'Escape', 'a')\n * @param options - Configuration options\n * @returns Whether the key is currently pressed\n *\n * @example\n * const enterPressed = useKeyPress('Enter')\n * const escapePressed = useKeyPress('Escape')\n *\n * useEffect(() => {\n * if (escapePressed) closeModal()\n * }, [escapePressed])\n *\n * @example\n * // With callback for immediate action\n * useKeyPress('Escape', { preventDefault: true })\n */\nexport function useKeyPress(\n targetKey: string,\n options: UseKeyPressOptions = {}\n): boolean {\n const { target, event = 'keydown', preventDefault = false } = options\n const [keyPressed, setKeyPressed] = useState(false)\n\n const downHandler = useCallback(\n (e: KeyboardEvent) => {\n if (e.key === targetKey) {\n if (preventDefault) e.preventDefault()\n setKeyPressed(true)\n }\n },\n [targetKey, preventDefault]\n )\n\n const upHandler = useCallback(\n (e: KeyboardEvent) => {\n if (e.key === targetKey) {\n setKeyPressed(false)\n }\n },\n [targetKey]\n )\n\n useEffect(() => {\n const targetElement = target ?? window\n\n if (event === 'keydown') {\n targetElement.addEventListener('keydown', downHandler as EventListener)\n targetElement.addEventListener('keyup', upHandler as EventListener)\n } else {\n targetElement.addEventListener('keyup', downHandler as EventListener)\n }\n\n return () => {\n targetElement.removeEventListener('keydown', downHandler as EventListener)\n targetElement.removeEventListener('keyup', upHandler as EventListener)\n }\n }, [target, event, downHandler, upHandler])\n\n return keyPressed\n}\n\n/**\n * Hook that calls a callback when a specific key is pressed.\n *\n * @param targetKey - Key to detect\n * @param callback - Function to call when key is pressed\n * @param options - Configuration options\n *\n * @example\n * useKeyPressCallback('Escape', () => closeModal())\n * useKeyPressCallback('Enter', () => submitForm(), { preventDefault: true })\n */\nexport function useKeyPressCallback(\n targetKey: string,\n callback: (event: KeyboardEvent) => void,\n options: UseKeyPressOptions = {}\n): void {\n const { target, event = 'keydown', preventDefault = false } = options\n\n useEffect(() => {\n const targetElement = target ?? window\n\n const handler = (e: KeyboardEvent) => {\n if (e.key === targetKey) {\n if (preventDefault) e.preventDefault()\n callback(e)\n }\n }\n\n targetElement.addEventListener(event, handler as EventListener)\n return () => targetElement.removeEventListener(event, handler as EventListener)\n }, [target, targetKey, callback, event, preventDefault])\n}\n"],"names":["useKeyPress","targetKey","options","target","event","preventDefault","keyPressed","setKeyPressed","useState","downHandler","useCallback","upHandler","useEffect","targetElement","useKeyPressCallback","callback","handler","e"],"mappings":";AA8BO,SAASA,EACdC,GACAC,IAA8B,IACrB;AACT,QAAM,EAAE,QAAAC,GAAQ,OAAAC,IAAQ,WAAW,gBAAAC,IAAiB,OAAUH,GACxD,CAACI,GAAYC,CAAa,IAAIC,EAAS,EAAK,GAE5CC,IAAcC;AAAA,IAClB,CAAC,MAAqB;AACpB,MAAI,EAAE,QAAQT,MACRI,OAAkB,eAAA,GACtBE,EAAc,EAAI;AAAA,IAEtB;AAAA,IACA,CAACN,GAAWI,CAAc;AAAA,EAAA,GAGtBM,IAAYD;AAAA,IAChB,CAAC,MAAqB;AACpB,MAAI,EAAE,QAAQT,KACZM,EAAc,EAAK;AAAA,IAEvB;AAAA,IACA,CAACN,CAAS;AAAA,EAAA;AAGZ,SAAAW,EAAU,MAAM;AACd,UAAMC,IAAgBV,KAAU;AAEhC,WAAIC,MAAU,aACZS,EAAc,iBAAiB,WAAWJ,CAA4B,GACtEI,EAAc,iBAAiB,SAASF,CAA0B,KAElEE,EAAc,iBAAiB,SAASJ,CAA4B,GAG/D,MAAM;AACX,MAAAI,EAAc,oBAAoB,WAAWJ,CAA4B,GACzEI,EAAc,oBAAoB,SAASF,CAA0B;AAAA,IACvE;AAAA,EACF,GAAG,CAACR,GAAQC,GAAOK,GAAaE,CAAS,CAAC,GAEnCL;AACT;AAaO,SAASQ,EACdb,GACAc,GACAb,IAA8B,CAAA,GACxB;AACN,QAAM,EAAE,QAAAC,GAAQ,OAAAC,IAAQ,WAAW,gBAAAC,IAAiB,OAAUH;AAE9D,EAAAU,EAAU,MAAM;AACd,UAAMC,IAAgBV,KAAU,QAE1Ba,IAAU,CAACC,MAAqB;AACpC,MAAIA,EAAE,QAAQhB,MACRI,OAAkB,eAAA,GACtBU,EAASE,CAAC;AAAA,IAEd;AAEA,WAAAJ,EAAc,iBAAiBT,GAAOY,CAAwB,GACvD,MAAMH,EAAc,oBAAoBT,GAAOY,CAAwB;AAAA,EAChF,GAAG,CAACb,GAAQF,GAAWc,GAAUX,GAAOC,CAAc,CAAC;AACzD;"}
package/dist/index106.js CHANGED
@@ -1,34 +1,21 @@
1
- import { useState as v, useCallback as i, useEffect as l } from "react";
2
- function c(n, f = {}) {
3
- const { target: u, event: o = "keydown", preventDefault: r = !1 } = f, [a, d] = v(!1), t = i(
4
- (e) => {
5
- e.key === n && (r && e.preventDefault(), d(!0));
6
- },
7
- [n, r]
8
- ), s = i(
9
- (e) => {
10
- e.key === n && d(!1);
11
- },
12
- [n]
13
- );
14
- return l(() => {
15
- const e = u ?? window;
16
- return o === "keydown" ? (e.addEventListener("keydown", t), e.addEventListener("keyup", s)) : e.addEventListener("keyup", t), () => {
17
- e.removeEventListener("keydown", t), e.removeEventListener("keyup", s);
1
+ import { useState as t, useEffect as d } from "react";
2
+ function r() {
3
+ const [i, n] = t(() => typeof window > "u" ? { width: 0, height: 0 } : {
4
+ width: window.innerWidth,
5
+ height: window.innerHeight
6
+ });
7
+ return d(() => {
8
+ if (typeof window > "u") return;
9
+ const e = () => {
10
+ n({
11
+ width: window.innerWidth,
12
+ height: window.innerHeight
13
+ });
18
14
  };
19
- }, [u, o, t, s]), a;
20
- }
21
- function y(n, f, u = {}) {
22
- const { target: o, event: r = "keydown", preventDefault: a = !1 } = u;
23
- l(() => {
24
- const d = o ?? window, t = (s) => {
25
- s.key === n && (a && s.preventDefault(), f(s));
26
- };
27
- return d.addEventListener(r, t), () => d.removeEventListener(r, t);
28
- }, [o, n, f, r, a]);
15
+ return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
16
+ }, []), i;
29
17
  }
30
18
  export {
31
- c as useKeyPress,
32
- y as useKeyPressCallback
19
+ r as useWindowSize
33
20
  };
34
21
  //# sourceMappingURL=index106.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index106.js","sources":["../src/hooks/useKeyPress.ts"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react'\n\nexport interface UseKeyPressOptions {\n /** Target element (default: window) */\n target?: HTMLElement | Window | null\n /** Event type: 'keydown' | 'keyup' (default: 'keydown') */\n event?: 'keydown' | 'keyup'\n /** Prevent default browser behavior */\n preventDefault?: boolean\n}\n\n/**\n * Hook that detects when a specific key is pressed.\n *\n * @param targetKey - Key to detect (e.g., 'Enter', 'Escape', 'a')\n * @param options - Configuration options\n * @returns Whether the key is currently pressed\n *\n * @example\n * const enterPressed = useKeyPress('Enter')\n * const escapePressed = useKeyPress('Escape')\n *\n * useEffect(() => {\n * if (escapePressed) closeModal()\n * }, [escapePressed])\n *\n * @example\n * // With callback for immediate action\n * useKeyPress('Escape', { preventDefault: true })\n */\nexport function useKeyPress(\n targetKey: string,\n options: UseKeyPressOptions = {}\n): boolean {\n const { target, event = 'keydown', preventDefault = false } = options\n const [keyPressed, setKeyPressed] = useState(false)\n\n const downHandler = useCallback(\n (e: KeyboardEvent) => {\n if (e.key === targetKey) {\n if (preventDefault) e.preventDefault()\n setKeyPressed(true)\n }\n },\n [targetKey, preventDefault]\n )\n\n const upHandler = useCallback(\n (e: KeyboardEvent) => {\n if (e.key === targetKey) {\n setKeyPressed(false)\n }\n },\n [targetKey]\n )\n\n useEffect(() => {\n const targetElement = target ?? window\n\n if (event === 'keydown') {\n targetElement.addEventListener('keydown', downHandler as EventListener)\n targetElement.addEventListener('keyup', upHandler as EventListener)\n } else {\n targetElement.addEventListener('keyup', downHandler as EventListener)\n }\n\n return () => {\n targetElement.removeEventListener('keydown', downHandler as EventListener)\n targetElement.removeEventListener('keyup', upHandler as EventListener)\n }\n }, [target, event, downHandler, upHandler])\n\n return keyPressed\n}\n\n/**\n * Hook that calls a callback when a specific key is pressed.\n *\n * @param targetKey - Key to detect\n * @param callback - Function to call when key is pressed\n * @param options - Configuration options\n *\n * @example\n * useKeyPressCallback('Escape', () => closeModal())\n * useKeyPressCallback('Enter', () => submitForm(), { preventDefault: true })\n */\nexport function useKeyPressCallback(\n targetKey: string,\n callback: (event: KeyboardEvent) => void,\n options: UseKeyPressOptions = {}\n): void {\n const { target, event = 'keydown', preventDefault = false } = options\n\n useEffect(() => {\n const targetElement = target ?? window\n\n const handler = (e: KeyboardEvent) => {\n if (e.key === targetKey) {\n if (preventDefault) e.preventDefault()\n callback(e)\n }\n }\n\n targetElement.addEventListener(event, handler as EventListener)\n return () => targetElement.removeEventListener(event, handler as EventListener)\n }, [target, targetKey, callback, event, preventDefault])\n}\n"],"names":["useKeyPress","targetKey","options","target","event","preventDefault","keyPressed","setKeyPressed","useState","downHandler","useCallback","upHandler","useEffect","targetElement","useKeyPressCallback","callback","handler","e"],"mappings":";AA8BO,SAASA,EACdC,GACAC,IAA8B,IACrB;AACT,QAAM,EAAE,QAAAC,GAAQ,OAAAC,IAAQ,WAAW,gBAAAC,IAAiB,OAAUH,GACxD,CAACI,GAAYC,CAAa,IAAIC,EAAS,EAAK,GAE5CC,IAAcC;AAAA,IAClB,CAAC,MAAqB;AACpB,MAAI,EAAE,QAAQT,MACRI,OAAkB,eAAA,GACtBE,EAAc,EAAI;AAAA,IAEtB;AAAA,IACA,CAACN,GAAWI,CAAc;AAAA,EAAA,GAGtBM,IAAYD;AAAA,IAChB,CAAC,MAAqB;AACpB,MAAI,EAAE,QAAQT,KACZM,EAAc,EAAK;AAAA,IAEvB;AAAA,IACA,CAACN,CAAS;AAAA,EAAA;AAGZ,SAAAW,EAAU,MAAM;AACd,UAAMC,IAAgBV,KAAU;AAEhC,WAAIC,MAAU,aACZS,EAAc,iBAAiB,WAAWJ,CAA4B,GACtEI,EAAc,iBAAiB,SAASF,CAA0B,KAElEE,EAAc,iBAAiB,SAASJ,CAA4B,GAG/D,MAAM;AACX,MAAAI,EAAc,oBAAoB,WAAWJ,CAA4B,GACzEI,EAAc,oBAAoB,SAASF,CAA0B;AAAA,IACvE;AAAA,EACF,GAAG,CAACR,GAAQC,GAAOK,GAAaE,CAAS,CAAC,GAEnCL;AACT;AAaO,SAASQ,EACdb,GACAc,GACAb,IAA8B,CAAA,GACxB;AACN,QAAM,EAAE,QAAAC,GAAQ,OAAAC,IAAQ,WAAW,gBAAAC,IAAiB,OAAUH;AAE9D,EAAAU,EAAU,MAAM;AACd,UAAMC,IAAgBV,KAAU,QAE1Ba,IAAU,CAACC,MAAqB;AACpC,MAAIA,EAAE,QAAQhB,MACRI,OAAkB,eAAA,GACtBU,EAASE,CAAC;AAAA,IAEd;AAEA,WAAAJ,EAAc,iBAAiBT,GAAOY,CAAwB,GACvD,MAAMH,EAAc,oBAAoBT,GAAOY,CAAwB;AAAA,EAChF,GAAG,CAACb,GAAQF,GAAWc,GAAUX,GAAOC,CAAc,CAAC;AACzD;"}
1
+ {"version":3,"file":"index106.js","sources":["../src/hooks/useWindowSize.ts"],"sourcesContent":["import { useState, useEffect } from 'react'\n\nexport interface WindowSize {\n width: number\n height: number\n}\n\n/**\n * Hook that tracks window dimensions.\n * Updates on window resize.\n *\n * @returns Object with current width and height\n *\n * @example\n * const { width, height } = useWindowSize()\n *\n * return (\n * <div>\n * Window: {width} x {height}\n * {width < 768 && <MobileNav />}\n * </div>\n * )\n */\nexport function useWindowSize(): WindowSize {\n const [windowSize, setWindowSize] = useState<WindowSize>(() => {\n if (typeof window === 'undefined') {\n return { width: 0, height: 0 }\n }\n return {\n width: window.innerWidth,\n height: window.innerHeight,\n }\n })\n\n useEffect(() => {\n if (typeof window === 'undefined') return\n\n const handleResize = () => {\n setWindowSize({\n width: window.innerWidth,\n height: window.innerHeight,\n })\n }\n\n window.addEventListener('resize', handleResize)\n return () => window.removeEventListener('resize', handleResize)\n }, [])\n\n return windowSize\n}\n"],"names":["useWindowSize","windowSize","setWindowSize","useState","useEffect","handleResize"],"mappings":";AAuBO,SAASA,IAA4B;AAC1C,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAAqB,MACnD,OAAO,SAAW,MACb,EAAE,OAAO,GAAG,QAAQ,EAAA,IAEtB;AAAA,IACL,OAAO,OAAO;AAAA,IACd,QAAQ,OAAO;AAAA,EAAA,CAElB;AAED,SAAAC,EAAU,MAAM;AACd,QAAI,OAAO,SAAW,IAAa;AAEnC,UAAMC,IAAe,MAAM;AACzB,MAAAH,EAAc;AAAA,QACZ,OAAO,OAAO;AAAA,QACd,QAAQ,OAAO;AAAA,MAAA,CAChB;AAAA,IACH;AAEA,kBAAO,iBAAiB,UAAUG,CAAY,GACvC,MAAM,OAAO,oBAAoB,UAAUA,CAAY;AAAA,EAChE,GAAG,CAAA,CAAE,GAEEJ;AACT;"}