react-better-html 1.1.158 → 1.1.159

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.
package/dist/index.d.mts CHANGED
@@ -3,7 +3,7 @@ import * as react from 'react';
3
3
  import { ComponentType, ComponentProps, ReactNode } from 'react';
4
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
5
 
6
- type PluginName = "react-router-dom" | "alerts";
6
+ type PluginName = "alerts" | "react-router-dom" | "localStorage";
7
7
  type BetterHtmlPluginConstructor<T extends object = object> = (config?: T) => BetterHtmlPlugin<T>;
8
8
  type BetterHtmlPlugin<T = object> = {
9
9
  name: PluginName;
@@ -981,12 +981,17 @@ declare const colorThemeControls: {
981
981
  toggleTheme: (theme?: ColorTheme) => void;
982
982
  };
983
983
 
984
+ declare function generateLocalStorage<LocalStorage extends object>(): {
985
+ setItem: <StorageName extends keyof LocalStorage>(name: StorageName, value: LocalStorage[StorageName]) => void;
986
+ getItem: <StorageName extends keyof LocalStorage>(name: StorageName) => LocalStorage[StorageName] | undefined;
987
+ removeItem: (name: keyof LocalStorage) => void;
988
+ removeAllItems: () => void;
989
+ };
990
+
984
991
  declare const countries: Country[];
985
992
 
986
993
  declare const isMobileDevice: boolean;
987
994
 
988
- declare const reactRouterDomPlugin: BetterHtmlPluginConstructor;
989
-
990
995
  type AlertsPluginOptions = {
991
996
  /** @default "bottom" */
992
997
  position?: "top" | "bottom";
@@ -1004,4 +1009,22 @@ type AlertsPluginOptions = {
1004
1009
  declare const defaultAlertsPluginOptions: Required<AlertsPluginOptions>;
1005
1010
  declare const alertsPlugin: BetterHtmlPluginConstructor<AlertsPluginOptions>;
1006
1011
 
1007
- export { type Alert, type AlertType, type AlertsPluginOptions, type AppConfig, type AssetName, type AssetsConfig, type BetterHtmlConfig, type BetterHtmlPlugin, _default as BetterHtmlProvider, type BetterHtmlProviderValue, type BrowserName, Button, type ButtonProps, Chip, type ChipProps, type Color, type ColorName, type ColorTheme, ColorThemeSwitch, type ColorThemeSwitchProps, type Colors, type ComponentHoverStyle, type ComponentMarginProps, type ComponentPaddingProps, type DeepPartialRecord, Div, type DivProps, _default$3 as Divider, Dropdown, type DropdownOption, type DropdownProps, type ExcludeOptions, Foldable, type FoldableProps, type FoldableRef, Form, type FormProps, FormRow, type FormRowProps, type HorizontalDividerProps, _default$5 as Icon, type IconName, type IconProps, type IconsConfig, _default$4 as Image, type ImageProps, InputField, type InputFieldProps, _default$1 as Label, type LabelProps, Loader, type LoaderConfig, type LoaderName, type LoaderProps, Modal, type ModalProps, type ModalRef, type OmitProps, PageHeader, type PageHeaderProps, PageHolder, type PageHolderProps, type PartialRecord, type PickAllRequired, type PickValue, type PluginName, type Styles, type TabGroup, Table, type TableColumn, type TableProps, type TableRef, Tabs, type TabsProps, type TabsRef, Text, type TextAs, type TextProps, type TextareaFieldProps, type Theme, type ThemeConfig, _default$2 as ToggleInput, type ToggleInputProps, type ToggleInputRef, Tooltip, type TooltipProps, type TooltipRef, type VerticalDividerProps, alertControls, alertsPlugin, colorThemeControls, countries, darkenColor, defaultAlertsPluginOptions, desaturateColor, eventPreventDefault, eventPreventStop, eventStopPropagation, formatPhoneNumber, generateRandomString, getBrowser, getFormErrorObject, isMobileDevice, lightenColor, loaderControls, reactRouterDomPlugin, saturateColor, useAlertControls, useBetterHtmlContext, useBooleanState, useDebounceState, useForm, useLoader, useLoaderControls, useMediaQuery, usePageResize, usePageScroll, useTheme, useUrlQuery };
1012
+ type ReactRouterDomPluginOptions = {};
1013
+ declare const defaultReactRouterDomPluginOptions: Required<ReactRouterDomPluginOptions>;
1014
+ declare const reactRouterDomPlugin: BetterHtmlPluginConstructor<ReactRouterDomPluginOptions>;
1015
+
1016
+ type LocalStoragePluginOptions = {
1017
+ encryption?: {
1018
+ /** @default false */
1019
+ enabled?: false;
1020
+ } | {
1021
+ /** @default false */
1022
+ enabled?: true;
1023
+ secretKey: string;
1024
+ iv: string;
1025
+ };
1026
+ };
1027
+ declare const defaultLocalStoragePluginOptions: Required<LocalStoragePluginOptions>;
1028
+ declare const localStoragePlugin: BetterHtmlPluginConstructor<LocalStoragePluginOptions>;
1029
+
1030
+ export { type Alert, type AlertType, type AlertsPluginOptions, type AppConfig, type AssetName, type AssetsConfig, type BetterHtmlConfig, type BetterHtmlPlugin, _default as BetterHtmlProvider, type BetterHtmlProviderValue, type BrowserName, Button, type ButtonProps, Chip, type ChipProps, type Color, type ColorName, type ColorTheme, ColorThemeSwitch, type ColorThemeSwitchProps, type Colors, type ComponentHoverStyle, type ComponentMarginProps, type ComponentPaddingProps, type DeepPartialRecord, Div, type DivProps, _default$3 as Divider, Dropdown, type DropdownOption, type DropdownProps, type ExcludeOptions, Foldable, type FoldableProps, type FoldableRef, Form, type FormProps, FormRow, type FormRowProps, type HorizontalDividerProps, _default$5 as Icon, type IconName, type IconProps, type IconsConfig, _default$4 as Image, type ImageProps, InputField, type InputFieldProps, _default$1 as Label, type LabelProps, Loader, type LoaderConfig, type LoaderName, type LoaderProps, type LocalStoragePluginOptions, Modal, type ModalProps, type ModalRef, type OmitProps, PageHeader, type PageHeaderProps, PageHolder, type PageHolderProps, type PartialRecord, type PickAllRequired, type PickValue, type PluginName, type ReactRouterDomPluginOptions, type Styles, type TabGroup, Table, type TableColumn, type TableProps, type TableRef, Tabs, type TabsProps, type TabsRef, Text, type TextAs, type TextProps, type TextareaFieldProps, type Theme, type ThemeConfig, _default$2 as ToggleInput, type ToggleInputProps, type ToggleInputRef, Tooltip, type TooltipProps, type TooltipRef, type VerticalDividerProps, alertControls, alertsPlugin, colorThemeControls, countries, darkenColor, defaultAlertsPluginOptions, defaultLocalStoragePluginOptions, defaultReactRouterDomPluginOptions, desaturateColor, eventPreventDefault, eventPreventStop, eventStopPropagation, formatPhoneNumber, generateLocalStorage, generateRandomString, getBrowser, getFormErrorObject, isMobileDevice, lightenColor, loaderControls, localStoragePlugin, reactRouterDomPlugin, saturateColor, useAlertControls, useBetterHtmlContext, useBooleanState, useDebounceState, useForm, useLoader, useLoaderControls, useMediaQuery, usePageResize, usePageScroll, useTheme, useUrlQuery };
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import * as react from 'react';
3
3
  import { ComponentType, ComponentProps, ReactNode } from 'react';
4
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
5
 
6
- type PluginName = "react-router-dom" | "alerts";
6
+ type PluginName = "alerts" | "react-router-dom" | "localStorage";
7
7
  type BetterHtmlPluginConstructor<T extends object = object> = (config?: T) => BetterHtmlPlugin<T>;
8
8
  type BetterHtmlPlugin<T = object> = {
9
9
  name: PluginName;
@@ -981,12 +981,17 @@ declare const colorThemeControls: {
981
981
  toggleTheme: (theme?: ColorTheme) => void;
982
982
  };
983
983
 
984
+ declare function generateLocalStorage<LocalStorage extends object>(): {
985
+ setItem: <StorageName extends keyof LocalStorage>(name: StorageName, value: LocalStorage[StorageName]) => void;
986
+ getItem: <StorageName extends keyof LocalStorage>(name: StorageName) => LocalStorage[StorageName] | undefined;
987
+ removeItem: (name: keyof LocalStorage) => void;
988
+ removeAllItems: () => void;
989
+ };
990
+
984
991
  declare const countries: Country[];
985
992
 
986
993
  declare const isMobileDevice: boolean;
987
994
 
988
- declare const reactRouterDomPlugin: BetterHtmlPluginConstructor;
989
-
990
995
  type AlertsPluginOptions = {
991
996
  /** @default "bottom" */
992
997
  position?: "top" | "bottom";
@@ -1004,4 +1009,22 @@ type AlertsPluginOptions = {
1004
1009
  declare const defaultAlertsPluginOptions: Required<AlertsPluginOptions>;
1005
1010
  declare const alertsPlugin: BetterHtmlPluginConstructor<AlertsPluginOptions>;
1006
1011
 
1007
- export { type Alert, type AlertType, type AlertsPluginOptions, type AppConfig, type AssetName, type AssetsConfig, type BetterHtmlConfig, type BetterHtmlPlugin, _default as BetterHtmlProvider, type BetterHtmlProviderValue, type BrowserName, Button, type ButtonProps, Chip, type ChipProps, type Color, type ColorName, type ColorTheme, ColorThemeSwitch, type ColorThemeSwitchProps, type Colors, type ComponentHoverStyle, type ComponentMarginProps, type ComponentPaddingProps, type DeepPartialRecord, Div, type DivProps, _default$3 as Divider, Dropdown, type DropdownOption, type DropdownProps, type ExcludeOptions, Foldable, type FoldableProps, type FoldableRef, Form, type FormProps, FormRow, type FormRowProps, type HorizontalDividerProps, _default$5 as Icon, type IconName, type IconProps, type IconsConfig, _default$4 as Image, type ImageProps, InputField, type InputFieldProps, _default$1 as Label, type LabelProps, Loader, type LoaderConfig, type LoaderName, type LoaderProps, Modal, type ModalProps, type ModalRef, type OmitProps, PageHeader, type PageHeaderProps, PageHolder, type PageHolderProps, type PartialRecord, type PickAllRequired, type PickValue, type PluginName, type Styles, type TabGroup, Table, type TableColumn, type TableProps, type TableRef, Tabs, type TabsProps, type TabsRef, Text, type TextAs, type TextProps, type TextareaFieldProps, type Theme, type ThemeConfig, _default$2 as ToggleInput, type ToggleInputProps, type ToggleInputRef, Tooltip, type TooltipProps, type TooltipRef, type VerticalDividerProps, alertControls, alertsPlugin, colorThemeControls, countries, darkenColor, defaultAlertsPluginOptions, desaturateColor, eventPreventDefault, eventPreventStop, eventStopPropagation, formatPhoneNumber, generateRandomString, getBrowser, getFormErrorObject, isMobileDevice, lightenColor, loaderControls, reactRouterDomPlugin, saturateColor, useAlertControls, useBetterHtmlContext, useBooleanState, useDebounceState, useForm, useLoader, useLoaderControls, useMediaQuery, usePageResize, usePageScroll, useTheme, useUrlQuery };
1012
+ type ReactRouterDomPluginOptions = {};
1013
+ declare const defaultReactRouterDomPluginOptions: Required<ReactRouterDomPluginOptions>;
1014
+ declare const reactRouterDomPlugin: BetterHtmlPluginConstructor<ReactRouterDomPluginOptions>;
1015
+
1016
+ type LocalStoragePluginOptions = {
1017
+ encryption?: {
1018
+ /** @default false */
1019
+ enabled?: false;
1020
+ } | {
1021
+ /** @default false */
1022
+ enabled?: true;
1023
+ secretKey: string;
1024
+ iv: string;
1025
+ };
1026
+ };
1027
+ declare const defaultLocalStoragePluginOptions: Required<LocalStoragePluginOptions>;
1028
+ declare const localStoragePlugin: BetterHtmlPluginConstructor<LocalStoragePluginOptions>;
1029
+
1030
+ export { type Alert, type AlertType, type AlertsPluginOptions, type AppConfig, type AssetName, type AssetsConfig, type BetterHtmlConfig, type BetterHtmlPlugin, _default as BetterHtmlProvider, type BetterHtmlProviderValue, type BrowserName, Button, type ButtonProps, Chip, type ChipProps, type Color, type ColorName, type ColorTheme, ColorThemeSwitch, type ColorThemeSwitchProps, type Colors, type ComponentHoverStyle, type ComponentMarginProps, type ComponentPaddingProps, type DeepPartialRecord, Div, type DivProps, _default$3 as Divider, Dropdown, type DropdownOption, type DropdownProps, type ExcludeOptions, Foldable, type FoldableProps, type FoldableRef, Form, type FormProps, FormRow, type FormRowProps, type HorizontalDividerProps, _default$5 as Icon, type IconName, type IconProps, type IconsConfig, _default$4 as Image, type ImageProps, InputField, type InputFieldProps, _default$1 as Label, type LabelProps, Loader, type LoaderConfig, type LoaderName, type LoaderProps, type LocalStoragePluginOptions, Modal, type ModalProps, type ModalRef, type OmitProps, PageHeader, type PageHeaderProps, PageHolder, type PageHolderProps, type PartialRecord, type PickAllRequired, type PickValue, type PluginName, type ReactRouterDomPluginOptions, type Styles, type TabGroup, Table, type TableColumn, type TableProps, type TableRef, Tabs, type TabsProps, type TabsRef, Text, type TextAs, type TextProps, type TextareaFieldProps, type Theme, type ThemeConfig, _default$2 as ToggleInput, type ToggleInputProps, type ToggleInputRef, Tooltip, type TooltipProps, type TooltipRef, type VerticalDividerProps, alertControls, alertsPlugin, colorThemeControls, countries, darkenColor, defaultAlertsPluginOptions, defaultLocalStoragePluginOptions, defaultReactRouterDomPluginOptions, desaturateColor, eventPreventDefault, eventPreventStop, eventStopPropagation, formatPhoneNumber, generateLocalStorage, generateRandomString, getBrowser, getFormErrorObject, isMobileDevice, lightenColor, loaderControls, localStoragePlugin, reactRouterDomPlugin, saturateColor, useAlertControls, useBetterHtmlContext, useBooleanState, useDebounceState, useForm, useLoader, useLoaderControls, useMediaQuery, usePageResize, usePageScroll, useTheme, useUrlQuery };
package/dist/index.js CHANGED
@@ -59,17 +59,21 @@ __export(index_exports, {
59
59
  countries: () => countries,
60
60
  darkenColor: () => darkenColor,
61
61
  defaultAlertsPluginOptions: () => defaultAlertsPluginOptions,
62
+ defaultLocalStoragePluginOptions: () => defaultLocalStoragePluginOptions,
63
+ defaultReactRouterDomPluginOptions: () => defaultReactRouterDomPluginOptions,
62
64
  desaturateColor: () => desaturateColor,
63
65
  eventPreventDefault: () => eventPreventDefault,
64
66
  eventPreventStop: () => eventPreventStop,
65
67
  eventStopPropagation: () => eventStopPropagation,
66
68
  formatPhoneNumber: () => formatPhoneNumber,
69
+ generateLocalStorage: () => generateLocalStorage,
67
70
  generateRandomString: () => generateRandomString,
68
71
  getBrowser: () => getBrowser,
69
72
  getFormErrorObject: () => getFormErrorObject,
70
73
  isMobileDevice: () => isMobileDevice,
71
74
  lightenColor: () => lightenColor,
72
75
  loaderControls: () => loaderControls,
76
+ localStoragePlugin: () => localStoragePlugin,
73
77
  reactRouterDomPlugin: () => reactRouterDomPlugin,
74
78
  saturateColor: () => saturateColor,
75
79
  useAlertControls: () => useAlertControls,
@@ -1615,19 +1619,6 @@ var import_react8 = require("react");
1615
1619
  var import_react7 = require("react");
1616
1620
  var import_styled_components6 = __toESM(require("styled-components"));
1617
1621
 
1618
- // src/plugins/react-router-dom.ts
1619
- var import_react_router_dom = require("react-router-dom");
1620
- var reactRouterDomPlugin = () => ({
1621
- name: "react-router-dom",
1622
- components: {
1623
- Link: import_react_router_dom.Link,
1624
- NavLink: import_react_router_dom.NavLink
1625
- },
1626
- initialize: () => {
1627
- console.log("react-router-dom plugin initialized");
1628
- }
1629
- });
1630
-
1631
1622
  // src/plugins/alerts.ts
1632
1623
  var defaultAlertsPluginOptions = {
1633
1624
  position: "bottom",
@@ -1648,6 +1639,39 @@ var alertsPlugin = (options) => ({
1648
1639
  })
1649
1640
  });
1650
1641
 
1642
+ // src/plugins/reactRouterDom.ts
1643
+ var import_react_router_dom = require("react-router-dom");
1644
+ var defaultReactRouterDomPluginOptions = {};
1645
+ var reactRouterDomPlugin = (options) => ({
1646
+ name: "react-router-dom",
1647
+ components: {
1648
+ Link: import_react_router_dom.Link,
1649
+ NavLink: import_react_router_dom.NavLink
1650
+ },
1651
+ initialize: () => {
1652
+ console.log("react-router-dom plugin initialized");
1653
+ },
1654
+ getConfig: () => ({
1655
+ ...defaultReactRouterDomPluginOptions,
1656
+ ...options
1657
+ })
1658
+ });
1659
+
1660
+ // src/plugins/localStorage.ts
1661
+ var defaultLocalStoragePluginOptions = {
1662
+ encryption: {}
1663
+ };
1664
+ var localStoragePlugin = (options) => ({
1665
+ name: "localStorage",
1666
+ initialize: () => {
1667
+ console.log("localStorage plugin initialized");
1668
+ },
1669
+ getConfig: () => ({
1670
+ ...defaultLocalStoragePluginOptions,
1671
+ ...options
1672
+ })
1673
+ });
1674
+
1651
1675
  // src/components/Icon.tsx
1652
1676
  var import_react = require("react");
1653
1677
  var import_styled_components = __toESM(require("styled-components"));
@@ -5428,6 +5452,62 @@ var countries = [
5428
5452
  }
5429
5453
  ];
5430
5454
 
5455
+ // src/utils/functions.ts
5456
+ var import_crypto_js = __toESM(require("crypto-js"));
5457
+
5458
+ // src/utils/variableFunctions.ts
5459
+ var checkBetterHtmlContextValue = (value, functionsName) => {
5460
+ if (value === void 0) {
5461
+ throw new Error(
5462
+ `\`${functionsName}()\` must be used within a \`<BetterHtmlProvider>\`. Make sure to add one at the root of your component tree.`
5463
+ );
5464
+ }
5465
+ return value !== void 0;
5466
+ };
5467
+ var loaderControls = {
5468
+ startLoading: (loaderName) => {
5469
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "loaderControls.startLoading")) return;
5470
+ externalBetterHtmlContextValue.setLoaders((oldValue) => ({
5471
+ ...oldValue,
5472
+ [loaderName.toString()]: true
5473
+ }));
5474
+ },
5475
+ stopLoading: (loaderName) => {
5476
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "loaderControls.stopLoading")) return;
5477
+ externalBetterHtmlContextValue.setLoaders((oldValue) => ({
5478
+ ...oldValue,
5479
+ [loaderName.toString()]: false
5480
+ }));
5481
+ }
5482
+ };
5483
+ var alertControls = {
5484
+ createAlert: (alert) => {
5485
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "alertControls.createAlert"))
5486
+ return void 0;
5487
+ const readyAlert = {
5488
+ id: crypto.randomUUID(),
5489
+ ...alert
5490
+ };
5491
+ externalBetterHtmlContextValue.setAlerts((oldValue) => [...oldValue, readyAlert]);
5492
+ return readyAlert;
5493
+ },
5494
+ removeAlert: (alertId) => {
5495
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "alertControls.removeAlert")) return;
5496
+ externalBetterHtmlContextValue.setAlerts((oldValue) => oldValue.filter((alert) => alert.id !== alertId));
5497
+ }
5498
+ };
5499
+ var colorThemeControls = {
5500
+ toggleTheme: (theme2) => {
5501
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "colorThemeControls.toggleTheme")) return;
5502
+ const currentColorTheme = externalBetterHtmlContextValue.colorTheme;
5503
+ const newColorTheme = theme2 ?? (currentColorTheme === "dark" ? "light" : "dark");
5504
+ setTimeout(() => {
5505
+ window.document.body.parentElement?.setAttribute("data-theme", newColorTheme);
5506
+ localStorage.setItem("theme", newColorTheme);
5507
+ }, 0.01 * 1e3);
5508
+ }
5509
+ };
5510
+
5431
5511
  // src/utils/functions.ts
5432
5512
  var generateRandomString = (stringLength, options) => {
5433
5513
  const capitals = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -5499,6 +5579,40 @@ var eventPreventStop = (event) => {
5499
5579
  event.preventDefault();
5500
5580
  event.stopPropagation();
5501
5581
  };
5582
+ var encryptString = (text) => {
5583
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "encryptString")) return void 0;
5584
+ const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find((plugin) => plugin.name === "localStorage");
5585
+ if (!localStoragePlugin2) {
5586
+ throw new Error(
5587
+ "`encryptString` hook requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
5588
+ );
5589
+ }
5590
+ const pluginConfig = localStoragePlugin2.getConfig?.() ?? {};
5591
+ if (!pluginConfig?.encryption?.enabled) return text;
5592
+ const encrypted = import_crypto_js.default.AES.encrypt(text, import_crypto_js.default.enc.Hex.parse(pluginConfig.encryption.secretKey), {
5593
+ iv: import_crypto_js.default.enc.Hex.parse(pluginConfig.encryption.iv),
5594
+ mode: import_crypto_js.default.mode.CBC,
5595
+ padding: import_crypto_js.default.pad.Pkcs7
5596
+ }).toString();
5597
+ return encrypted;
5598
+ };
5599
+ var decryptString = (text) => {
5600
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "decryptString")) return void 0;
5601
+ const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find((plugin) => plugin.name === "localStorage");
5602
+ if (!localStoragePlugin2) {
5603
+ throw new Error(
5604
+ "`decryptString` hook requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
5605
+ );
5606
+ }
5607
+ const pluginConfig = localStoragePlugin2.getConfig?.() ?? {};
5608
+ if (!pluginConfig?.encryption?.enabled) return text;
5609
+ const decrypted = import_crypto_js.default.AES.decrypt(text, import_crypto_js.default.enc.Hex.parse(pluginConfig.encryption.secretKey), {
5610
+ iv: import_crypto_js.default.enc.Hex.parse(pluginConfig.encryption.iv),
5611
+ mode: import_crypto_js.default.mode.CBC,
5612
+ padding: import_crypto_js.default.pad.Pkcs7
5613
+ });
5614
+ return decrypted.toString(import_crypto_js.default.enc.Utf8);
5615
+ };
5502
5616
 
5503
5617
  // src/components/Label.tsx
5504
5618
  var import_react17 = require("react");
@@ -7463,61 +7577,6 @@ var FormRow_default = FormRow2;
7463
7577
 
7464
7578
  // src/components/ColorThemeSwitch.tsx
7465
7579
  var import_react24 = require("react");
7466
-
7467
- // src/utils/variableFunctions.ts
7468
- var checkBetterHtmlContextValue = (value, functionsName) => {
7469
- if (value === void 0) {
7470
- throw new Error(
7471
- `\`${functionsName}()\` must be used within a \`<BetterHtmlProvider>\`. Make sure to add one at the root of your component tree.`
7472
- );
7473
- }
7474
- return value !== void 0;
7475
- };
7476
- var loaderControls = {
7477
- startLoading: (loaderName) => {
7478
- if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "loaderControls.startLoading")) return;
7479
- externalBetterHtmlContextValue.setLoaders((oldValue) => ({
7480
- ...oldValue,
7481
- [loaderName.toString()]: true
7482
- }));
7483
- },
7484
- stopLoading: (loaderName) => {
7485
- if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "loaderControls.stopLoading")) return;
7486
- externalBetterHtmlContextValue.setLoaders((oldValue) => ({
7487
- ...oldValue,
7488
- [loaderName.toString()]: false
7489
- }));
7490
- }
7491
- };
7492
- var alertControls = {
7493
- createAlert: (alert) => {
7494
- if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "alertControls.createAlert"))
7495
- return void 0;
7496
- const readyAlert = {
7497
- id: crypto.randomUUID(),
7498
- ...alert
7499
- };
7500
- externalBetterHtmlContextValue.setAlerts((oldValue) => [...oldValue, readyAlert]);
7501
- return readyAlert;
7502
- },
7503
- removeAlert: (alertId) => {
7504
- if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "alertControls.removeAlert")) return;
7505
- externalBetterHtmlContextValue.setAlerts((oldValue) => oldValue.filter((alert) => alert.id !== alertId));
7506
- }
7507
- };
7508
- var colorThemeControls = {
7509
- toggleTheme: (theme2) => {
7510
- if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "colorThemeControls.toggleTheme")) return;
7511
- const currentColorTheme = externalBetterHtmlContextValue.colorTheme;
7512
- const newColorTheme = theme2 ?? (currentColorTheme === "dark" ? "light" : "dark");
7513
- setTimeout(() => {
7514
- window.document.body.parentElement?.setAttribute("data-theme", newColorTheme);
7515
- localStorage.setItem("theme", newColorTheme);
7516
- }, 0.01 * 1e3);
7517
- }
7518
- };
7519
-
7520
- // src/components/ColorThemeSwitch.tsx
7521
7580
  var import_jsx_runtime22 = require("react/jsx-runtime");
7522
7581
  var ColorThemeSwitchComponent = function ColorThemeSwitch({
7523
7582
  withMoon,
@@ -9121,6 +9180,71 @@ FoldableComponent.box = (0, import_react28.forwardRef)(function Box3({ ...props
9121
9180
  var Foldable2 = (0, import_react28.memo)(FoldableComponent);
9122
9181
  Foldable2.box = FoldableComponent.box;
9123
9182
  var Foldable_default = Foldable2;
9183
+
9184
+ // src/utils/localStorage.ts
9185
+ function generateLocalStorage() {
9186
+ return {
9187
+ setItem: (name, value) => {
9188
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "generateLocalStorage"))
9189
+ return void 0;
9190
+ const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find(
9191
+ (plugin) => plugin.name === "localStorage"
9192
+ );
9193
+ if (!localStoragePlugin2) {
9194
+ throw new Error(
9195
+ "`generateLocalStorage` hook requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
9196
+ );
9197
+ }
9198
+ const pluginConfig = localStoragePlugin2.getConfig?.() ?? {};
9199
+ const encryptionEnabled = pluginConfig.encryption?.enabled ?? false;
9200
+ const readyName = encryptionEnabled ? encryptString(name.toString()) : name;
9201
+ const readyValue = encryptionEnabled ? encryptString(JSON.stringify(value)) : JSON.stringify(value);
9202
+ if (value) localStorage.setItem(readyName.toString(), readyValue);
9203
+ else localStorage.removeItem(readyName.toString());
9204
+ },
9205
+ getItem: (name) => {
9206
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "generateLocalStorage"))
9207
+ return void 0;
9208
+ const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find(
9209
+ (plugin) => plugin.name === "localStorage"
9210
+ );
9211
+ if (!localStoragePlugin2) {
9212
+ throw new Error(
9213
+ "`generateLocalStorage` hook requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
9214
+ );
9215
+ }
9216
+ const pluginConfig = localStoragePlugin2.getConfig?.() ?? {};
9217
+ const encryptionEnabled = pluginConfig.encryption?.enabled ?? false;
9218
+ const readyName = encryptionEnabled ? encryptString(name.toString()) : name;
9219
+ const item = localStorage.getItem(readyName.toString());
9220
+ if (item === null) return void 0;
9221
+ try {
9222
+ return encryptionEnabled ? JSON.parse(decryptString(item)) : JSON.parse(item);
9223
+ } catch (error) {
9224
+ return void 0;
9225
+ }
9226
+ },
9227
+ removeItem: (name) => {
9228
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "generateLocalStorage"))
9229
+ return void 0;
9230
+ const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find(
9231
+ (plugin) => plugin.name === "localStorage"
9232
+ );
9233
+ if (!localStoragePlugin2) {
9234
+ throw new Error(
9235
+ "`generateLocalStorage` hook requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
9236
+ );
9237
+ }
9238
+ const pluginConfig = localStoragePlugin2.getConfig?.() ?? {};
9239
+ const encryptionEnabled = pluginConfig.encryption?.enabled ?? false;
9240
+ const readyName = encryptionEnabled ? encryptString(name.toString()) : name;
9241
+ localStorage.removeItem(readyName.toString());
9242
+ },
9243
+ removeAllItems: () => {
9244
+ localStorage.clear();
9245
+ }
9246
+ };
9247
+ }
9124
9248
  // Annotate the CommonJS export names for ESM import in node:
9125
9249
  0 && (module.exports = {
9126
9250
  BetterHtmlProvider,
@@ -9152,17 +9276,21 @@ var Foldable_default = Foldable2;
9152
9276
  countries,
9153
9277
  darkenColor,
9154
9278
  defaultAlertsPluginOptions,
9279
+ defaultLocalStoragePluginOptions,
9280
+ defaultReactRouterDomPluginOptions,
9155
9281
  desaturateColor,
9156
9282
  eventPreventDefault,
9157
9283
  eventPreventStop,
9158
9284
  eventStopPropagation,
9159
9285
  formatPhoneNumber,
9286
+ generateLocalStorage,
9160
9287
  generateRandomString,
9161
9288
  getBrowser,
9162
9289
  getFormErrorObject,
9163
9290
  isMobileDevice,
9164
9291
  lightenColor,
9165
9292
  loaderControls,
9293
+ localStoragePlugin,
9166
9294
  reactRouterDomPlugin,
9167
9295
  saturateColor,
9168
9296
  useAlertControls,