@bagisto-native/core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,211 @@
1
+ 'use strict';
2
+
3
+ // src/components/hotwire-toast.ts
4
+ exports.HotwireToast = void 0;
5
+ if (typeof window !== "undefined") {
6
+ class ToastClass extends HTMLElement {
7
+ constructor() {
8
+ super();
9
+ this.handleClick = this.handleClick.bind(this);
10
+ }
11
+ connectedCallback() {
12
+ this.setAttribute("role", "button");
13
+ this.setAttribute("data-controller", "bridge--toast");
14
+ this.setAttribute("data-action", "click->bridge--toast#show");
15
+ this.addEventListener("click", this.handleClick);
16
+ }
17
+ handleClick(e) {
18
+ }
19
+ disconnectedCallback() {
20
+ this.removeEventListener("click", this.handleClick);
21
+ }
22
+ }
23
+ if (!customElements.get("hotwire-toast")) {
24
+ customElements.define("hotwire-toast", ToastClass);
25
+ }
26
+ exports.HotwireToast = ToastClass;
27
+ }
28
+
29
+ // src/components/dynamic-button.ts
30
+ exports.DynamicButton = void 0;
31
+ if (typeof window !== "undefined") {
32
+ class DynamicButtonClass extends HTMLElement {
33
+ static get observedAttributes() {
34
+ return ["data-page-type"];
35
+ }
36
+ constructor() {
37
+ super();
38
+ }
39
+ connectedCallback() {
40
+ this.type = "button";
41
+ this.setAttribute("data-controller", "bridge--dynamicbutton");
42
+ }
43
+ attributeChangedCallback(name, oldVal, newVal) {
44
+ }
45
+ disconnectedCallback() {
46
+ }
47
+ }
48
+ if (typeof window !== "undefined" && !customElements.get("dynamic-button")) {
49
+ customElements.define("dynamic-button", DynamicButtonClass);
50
+ }
51
+ exports.DynamicButton = DynamicButtonClass;
52
+ }
53
+
54
+ // src/components/hotwire-location.ts
55
+ exports.HotwireLocation = void 0;
56
+ if (typeof window !== "undefined") {
57
+ class LocationClass extends HTMLElement {
58
+ constructor() {
59
+ super();
60
+ this.handleClick = this.handleClick.bind(this);
61
+ }
62
+ connectedCallback() {
63
+ this.setAttribute("role", "button");
64
+ this.setAttribute("data-controller", "bridge--location");
65
+ this.addEventListener("click", this.handleClick);
66
+ }
67
+ handleClick(e) {
68
+ }
69
+ disconnectedCallback() {
70
+ this.removeEventListener("click", this.handleClick);
71
+ }
72
+ }
73
+ if (!customElements.get("hotwire-location")) {
74
+ customElements.define("hotwire-location", LocationClass);
75
+ }
76
+ exports.HotwireLocation = LocationClass;
77
+ }
78
+
79
+ // src/components/hotwire-search.ts
80
+ exports.HotwireSearch = void 0;
81
+ if (typeof window !== "undefined") {
82
+ class HotwireSearchClass extends HTMLElement {
83
+ constructor() {
84
+ super();
85
+ }
86
+ connectedCallback() {
87
+ this.innerHTML = "";
88
+ const p = document.createElement("p");
89
+ p.setAttribute("data-controller", "bridge--search");
90
+ p.setAttribute("data-action", "input->bridge--search#handleInput");
91
+ p.style.display = "none";
92
+ p.appendChild(document.createTextNode("Search Form"));
93
+ const resultsDiv = document.createElement("div");
94
+ resultsDiv.setAttribute("data-bridge--search-target", "results");
95
+ p.appendChild(resultsDiv);
96
+ this.appendChild(p);
97
+ }
98
+ disconnectedCallback() {
99
+ }
100
+ }
101
+ if (!customElements.get("hotwire-search")) {
102
+ customElements.define("hotwire-search", HotwireSearchClass);
103
+ }
104
+ exports.HotwireSearch = HotwireSearchClass;
105
+ }
106
+
107
+ // src/components/hotwire-history-sync.ts
108
+ exports.HotwireHistorySync = void 0;
109
+ if (typeof window !== "undefined") {
110
+ class HistorySyncClass extends HTMLElement {
111
+ constructor() {
112
+ super();
113
+ this.handleClick = this.handleClick.bind(this);
114
+ }
115
+ connectedCallback() {
116
+ this.setAttribute("role", "button");
117
+ this.setAttribute("data-controller", "bridge--historysync");
118
+ }
119
+ handleClick(e) {
120
+ }
121
+ disconnectedCallback() {
122
+ }
123
+ }
124
+ if (!customElements.get("hotwire-history-sync")) {
125
+ customElements.define("hotwire-history-sync", HistorySyncClass);
126
+ }
127
+ exports.HotwireHistorySync = HistorySyncClass;
128
+ }
129
+
130
+ // src/components/hotwire-theme-mode.ts
131
+ exports.HotwireThemeMode = void 0;
132
+ if (typeof window !== "undefined") {
133
+ class ThemeModeClass extends HTMLElement {
134
+ constructor() {
135
+ super();
136
+ this.handleClick = this.handleClick.bind(this);
137
+ }
138
+ connectedCallback() {
139
+ this.setAttribute("role", "button");
140
+ this.setAttribute("data-controller", "bridge--thememode");
141
+ this.setAttribute("data-action", "click->bridge--thememode#handleClick");
142
+ this.addEventListener("click", this.handleClick);
143
+ }
144
+ handleClick(e) {
145
+ }
146
+ disconnectedCallback() {
147
+ this.removeEventListener("click", this.handleClick);
148
+ }
149
+ }
150
+ if (!customElements.get("hotwire-theme-mode")) {
151
+ customElements.define("hotwire-theme-mode", ThemeModeClass);
152
+ }
153
+ exports.HotwireThemeMode = ThemeModeClass;
154
+ }
155
+
156
+ // src/utils/utils.ts
157
+ function isTurboNativeUserAgent(userAgent) {
158
+ if (!userAgent && typeof navigator !== "undefined") {
159
+ userAgent = navigator.userAgent;
160
+ }
161
+ userAgent = userAgent || "";
162
+ return userAgent.includes("Turbo Native");
163
+ }
164
+ function triggerHotwireNativeToast(message) {
165
+ if (typeof document === "undefined") return;
166
+ const nativeToasts = document.querySelectorAll(
167
+ "[data-controller='bridge--toast']"
168
+ );
169
+ if (nativeToasts.length > 0) {
170
+ nativeToasts[0].setAttribute("data-bridge-message", message);
171
+ nativeToasts[0].click();
172
+ }
173
+ }
174
+ function triggerHistorySyncEvent(url) {
175
+ if (typeof document === "undefined") return;
176
+ const hotwireElements = document.querySelectorAll(
177
+ "[data-controller='bridge--historysync']"
178
+ );
179
+ if (hotwireElements.length > 0) {
180
+ hotwireElements[0].dispatchEvent(new CustomEvent("turbo:next-history-sync", {
181
+ detail: url,
182
+ bubbles: true
183
+ }));
184
+ }
185
+ }
186
+ function triggerThemeModeEvent(theme) {
187
+ if (typeof document === "undefined") return;
188
+ const themeModeBtns = document.querySelectorAll(
189
+ '[data-controller="bridge--thememode"]'
190
+ );
191
+ if (themeModeBtns.length > 0) {
192
+ themeModeBtns[0].dataset.bridgeMode = theme;
193
+ themeModeBtns[0].click();
194
+ }
195
+ }
196
+ function triggerCartCountValue(cartcount) {
197
+ if (typeof document === "undefined") return;
198
+ const nativeButton = document.querySelectorAll(
199
+ "[data-controller='bridge--dynamicbutton'][data-action='click->bridge--dynamicbutton#sendCartCount']"
200
+ );
201
+ if (nativeButton.length > 0) {
202
+ nativeButton[0].setAttribute("data-bridge-cartcount", cartcount.toString());
203
+ nativeButton[0].click();
204
+ }
205
+ }
206
+
207
+ exports.isTurboNativeUserAgent = isTurboNativeUserAgent;
208
+ exports.triggerCartCountValue = triggerCartCountValue;
209
+ exports.triggerHistorySyncEvent = triggerHistorySyncEvent;
210
+ exports.triggerHotwireNativeToast = triggerHotwireNativeToast;
211
+ exports.triggerThemeModeEvent = triggerThemeModeEvent;
@@ -0,0 +1,127 @@
1
+ declare let HotwireToast: typeof HTMLElement | undefined;
2
+
3
+ declare let DynamicButton: typeof HTMLElement | undefined;
4
+
5
+ declare let HotwireLocation: typeof HTMLElement | undefined;
6
+
7
+ declare let HotwireSearch: typeof HTMLElement | undefined;
8
+
9
+ declare let HotwireHistorySync: typeof HTMLElement | undefined;
10
+
11
+ declare let HotwireThemeMode: typeof HTMLElement | undefined;
12
+
13
+ interface FrameworkDelegate {
14
+ attachViewToDom(
15
+ container: any,
16
+ component: any,
17
+ propsOrDataObj?: any,
18
+ cssClasses?: string[]
19
+ ): Promise<HTMLElement>;
20
+ removeViewFromDom(container: any, component: any): Promise<void>;
21
+ }
22
+
23
+ declare global {
24
+ namespace JSX {
25
+ interface IntrinsicElements {
26
+ 'dynamic-button': Partial<HTMLElementTagNameMap['button']> & {
27
+ 'data-action'?: string;
28
+ 'data-page-type'?: string;
29
+ };
30
+ 'hotwire-toast': Partial<HTMLElementTagNameMap['button']> & {
31
+ 'data-bridge-message'?: string;
32
+ };
33
+ 'hotwire-location': Partial<HTMLElementTagNameMap['button']>;
34
+ 'hotwire-search': Partial<HTMLElementTagNameMap['p']> & {
35
+ 'data-controller'?: string;
36
+ 'data-action'?: string;
37
+ 'data-bridge--search-target'?: string;
38
+ };
39
+ 'hotwire-history-sync': Partial<HTMLElementTagNameMap['button']>;
40
+ 'hotwire-theme-mode': Partial<HTMLElementTagNameMap['button']> & {
41
+ 'data-bridge-mode'?: string;
42
+ };
43
+ }
44
+ }
45
+
46
+ interface HTMLElementTagNameMap {
47
+ 'dynamic-button': HTMLElement;
48
+ 'hotwire-toast': HTMLElement;
49
+ 'hotwire-location': HTMLElement;
50
+ 'hotwire-search': HTMLElement;
51
+ 'hotwire-history-sync': HTMLElement;
52
+ 'hotwire-theme-mode': HTMLElement;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Check the turbo native user agent is present or not. (Hotwire)
58
+ * Function call from server components : isTurboNativeUserAgent(req.headers['user-agent']) or isTurboNativeUserAgent(useragent) where you have to find and send the useragent manually (ex. Next js Server Component);
59
+ * Function call from client components : isTurboNativeUserAgent();
60
+ * @param userAgent
61
+ * @returns
62
+ */
63
+ declare function isTurboNativeUserAgent(userAgent?: string): boolean;
64
+ /**
65
+ * Triggers a native Hotwire toast message in the DOM.
66
+ *
67
+ * This function searches for the first element in the document
68
+ * that uses the Stimulus controller `bridge--toast`. If found,
69
+ * it updates its `data-bridge-message` attribute with the provided
70
+ * message and simulates a click event to display the toast.
71
+ *
72
+ * This utility is useful for programmatically invoking toasts from
73
+ * anywhere in your application (e.g., after form submissions or API actions).
74
+ *
75
+ * @function triggerHotwireNativeToast
76
+ * @param {string} message - The message text to display in the toast.
77
+ * @example
78
+ * // Trigger a simple toast notification
79
+ * TriggerHotwireNativeToast("Profile updated successfully!");
80
+ *
81
+ * @remarks
82
+ * The function safely checks for the presence of the `document` object,
83
+ * so it can be called in both browser and server environments.
84
+ */
85
+ declare function triggerHotwireNativeToast(message: string): void;
86
+ /**
87
+ * Dispatches a custom Turbo history sync event to the first
88
+ * `bridge--historysync` controller found in the DOM.
89
+ *
90
+ * This is used to notify the native / Hotwire bridge that the
91
+ * browser history should be synchronized with the given URL.
92
+ *
93
+ * The event name dispatched is `turbo:next-history-sync` and it
94
+ * bubbles up the DOM tree.
95
+ *
96
+ * @param url - A `URL` object representing the next location
97
+ * to be synced with Turbo / native navigation.
98
+ */
99
+ declare function triggerHistorySyncEvent(url: URL): void;
100
+ /**
101
+ * Triggers the Theme Mode bridge event by programmatically clicking
102
+ * the hidden theme mode button in the DOM.
103
+ *
104
+ * This function updates the `data-bridge-mode` attribute on the button
105
+ * and dispatches a click event so the native bridge can react.
106
+ *
107
+ * @param theme - The theme mode to apply.
108
+ * Must be either `"dark"` or `"light"`.
109
+ */
110
+ declare function triggerThemeModeEvent(theme: string): void;
111
+ /**
112
+ * Triggers a native cart count update via the Hotwire bridge.
113
+ *
114
+ * This function:
115
+ * - Finds the first DOM element wired with the Hotwire Dynamic Button controller
116
+ * responsible for sending cart count data to the native app.
117
+ * - Sets the `data-bridge-cartcount` attribute with the provided cart count.
118
+ * - Programmatically triggers a click event to notify the native layer.
119
+ *
120
+ * The function safely exits when executed in a non-browser environment
121
+ * (e.g., during server-side rendering).
122
+ *
123
+ * @param {number} cartcount - The total number of items in the cart
124
+ */
125
+ declare function triggerCartCountValue(cartcount: number): void;
126
+
127
+ export { DynamicButton, type FrameworkDelegate, HotwireHistorySync, HotwireLocation, HotwireSearch, HotwireThemeMode, HotwireToast, isTurboNativeUserAgent, triggerCartCountValue, triggerHistorySyncEvent, triggerHotwireNativeToast, triggerThemeModeEvent };
@@ -0,0 +1,127 @@
1
+ declare let HotwireToast: typeof HTMLElement | undefined;
2
+
3
+ declare let DynamicButton: typeof HTMLElement | undefined;
4
+
5
+ declare let HotwireLocation: typeof HTMLElement | undefined;
6
+
7
+ declare let HotwireSearch: typeof HTMLElement | undefined;
8
+
9
+ declare let HotwireHistorySync: typeof HTMLElement | undefined;
10
+
11
+ declare let HotwireThemeMode: typeof HTMLElement | undefined;
12
+
13
+ interface FrameworkDelegate {
14
+ attachViewToDom(
15
+ container: any,
16
+ component: any,
17
+ propsOrDataObj?: any,
18
+ cssClasses?: string[]
19
+ ): Promise<HTMLElement>;
20
+ removeViewFromDom(container: any, component: any): Promise<void>;
21
+ }
22
+
23
+ declare global {
24
+ namespace JSX {
25
+ interface IntrinsicElements {
26
+ 'dynamic-button': Partial<HTMLElementTagNameMap['button']> & {
27
+ 'data-action'?: string;
28
+ 'data-page-type'?: string;
29
+ };
30
+ 'hotwire-toast': Partial<HTMLElementTagNameMap['button']> & {
31
+ 'data-bridge-message'?: string;
32
+ };
33
+ 'hotwire-location': Partial<HTMLElementTagNameMap['button']>;
34
+ 'hotwire-search': Partial<HTMLElementTagNameMap['p']> & {
35
+ 'data-controller'?: string;
36
+ 'data-action'?: string;
37
+ 'data-bridge--search-target'?: string;
38
+ };
39
+ 'hotwire-history-sync': Partial<HTMLElementTagNameMap['button']>;
40
+ 'hotwire-theme-mode': Partial<HTMLElementTagNameMap['button']> & {
41
+ 'data-bridge-mode'?: string;
42
+ };
43
+ }
44
+ }
45
+
46
+ interface HTMLElementTagNameMap {
47
+ 'dynamic-button': HTMLElement;
48
+ 'hotwire-toast': HTMLElement;
49
+ 'hotwire-location': HTMLElement;
50
+ 'hotwire-search': HTMLElement;
51
+ 'hotwire-history-sync': HTMLElement;
52
+ 'hotwire-theme-mode': HTMLElement;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Check the turbo native user agent is present or not. (Hotwire)
58
+ * Function call from server components : isTurboNativeUserAgent(req.headers['user-agent']) or isTurboNativeUserAgent(useragent) where you have to find and send the useragent manually (ex. Next js Server Component);
59
+ * Function call from client components : isTurboNativeUserAgent();
60
+ * @param userAgent
61
+ * @returns
62
+ */
63
+ declare function isTurboNativeUserAgent(userAgent?: string): boolean;
64
+ /**
65
+ * Triggers a native Hotwire toast message in the DOM.
66
+ *
67
+ * This function searches for the first element in the document
68
+ * that uses the Stimulus controller `bridge--toast`. If found,
69
+ * it updates its `data-bridge-message` attribute with the provided
70
+ * message and simulates a click event to display the toast.
71
+ *
72
+ * This utility is useful for programmatically invoking toasts from
73
+ * anywhere in your application (e.g., after form submissions or API actions).
74
+ *
75
+ * @function triggerHotwireNativeToast
76
+ * @param {string} message - The message text to display in the toast.
77
+ * @example
78
+ * // Trigger a simple toast notification
79
+ * TriggerHotwireNativeToast("Profile updated successfully!");
80
+ *
81
+ * @remarks
82
+ * The function safely checks for the presence of the `document` object,
83
+ * so it can be called in both browser and server environments.
84
+ */
85
+ declare function triggerHotwireNativeToast(message: string): void;
86
+ /**
87
+ * Dispatches a custom Turbo history sync event to the first
88
+ * `bridge--historysync` controller found in the DOM.
89
+ *
90
+ * This is used to notify the native / Hotwire bridge that the
91
+ * browser history should be synchronized with the given URL.
92
+ *
93
+ * The event name dispatched is `turbo:next-history-sync` and it
94
+ * bubbles up the DOM tree.
95
+ *
96
+ * @param url - A `URL` object representing the next location
97
+ * to be synced with Turbo / native navigation.
98
+ */
99
+ declare function triggerHistorySyncEvent(url: URL): void;
100
+ /**
101
+ * Triggers the Theme Mode bridge event by programmatically clicking
102
+ * the hidden theme mode button in the DOM.
103
+ *
104
+ * This function updates the `data-bridge-mode` attribute on the button
105
+ * and dispatches a click event so the native bridge can react.
106
+ *
107
+ * @param theme - The theme mode to apply.
108
+ * Must be either `"dark"` or `"light"`.
109
+ */
110
+ declare function triggerThemeModeEvent(theme: string): void;
111
+ /**
112
+ * Triggers a native cart count update via the Hotwire bridge.
113
+ *
114
+ * This function:
115
+ * - Finds the first DOM element wired with the Hotwire Dynamic Button controller
116
+ * responsible for sending cart count data to the native app.
117
+ * - Sets the `data-bridge-cartcount` attribute with the provided cart count.
118
+ * - Programmatically triggers a click event to notify the native layer.
119
+ *
120
+ * The function safely exits when executed in a non-browser environment
121
+ * (e.g., during server-side rendering).
122
+ *
123
+ * @param {number} cartcount - The total number of items in the cart
124
+ */
125
+ declare function triggerCartCountValue(cartcount: number): void;
126
+
127
+ export { DynamicButton, type FrameworkDelegate, HotwireHistorySync, HotwireLocation, HotwireSearch, HotwireThemeMode, HotwireToast, isTurboNativeUserAgent, triggerCartCountValue, triggerHistorySyncEvent, triggerHotwireNativeToast, triggerThemeModeEvent };
package/dist/index.js ADDED
@@ -0,0 +1,205 @@
1
+ // src/components/hotwire-toast.ts
2
+ var HotwireToast;
3
+ if (typeof window !== "undefined") {
4
+ class ToastClass extends HTMLElement {
5
+ constructor() {
6
+ super();
7
+ this.handleClick = this.handleClick.bind(this);
8
+ }
9
+ connectedCallback() {
10
+ this.setAttribute("role", "button");
11
+ this.setAttribute("data-controller", "bridge--toast");
12
+ this.setAttribute("data-action", "click->bridge--toast#show");
13
+ this.addEventListener("click", this.handleClick);
14
+ }
15
+ handleClick(e) {
16
+ }
17
+ disconnectedCallback() {
18
+ this.removeEventListener("click", this.handleClick);
19
+ }
20
+ }
21
+ if (!customElements.get("hotwire-toast")) {
22
+ customElements.define("hotwire-toast", ToastClass);
23
+ }
24
+ HotwireToast = ToastClass;
25
+ }
26
+
27
+ // src/components/dynamic-button.ts
28
+ var DynamicButton;
29
+ if (typeof window !== "undefined") {
30
+ class DynamicButtonClass extends HTMLElement {
31
+ static get observedAttributes() {
32
+ return ["data-page-type"];
33
+ }
34
+ constructor() {
35
+ super();
36
+ }
37
+ connectedCallback() {
38
+ this.type = "button";
39
+ this.setAttribute("data-controller", "bridge--dynamicbutton");
40
+ }
41
+ attributeChangedCallback(name, oldVal, newVal) {
42
+ }
43
+ disconnectedCallback() {
44
+ }
45
+ }
46
+ if (typeof window !== "undefined" && !customElements.get("dynamic-button")) {
47
+ customElements.define("dynamic-button", DynamicButtonClass);
48
+ }
49
+ DynamicButton = DynamicButtonClass;
50
+ }
51
+
52
+ // src/components/hotwire-location.ts
53
+ var HotwireLocation;
54
+ if (typeof window !== "undefined") {
55
+ class LocationClass extends HTMLElement {
56
+ constructor() {
57
+ super();
58
+ this.handleClick = this.handleClick.bind(this);
59
+ }
60
+ connectedCallback() {
61
+ this.setAttribute("role", "button");
62
+ this.setAttribute("data-controller", "bridge--location");
63
+ this.addEventListener("click", this.handleClick);
64
+ }
65
+ handleClick(e) {
66
+ }
67
+ disconnectedCallback() {
68
+ this.removeEventListener("click", this.handleClick);
69
+ }
70
+ }
71
+ if (!customElements.get("hotwire-location")) {
72
+ customElements.define("hotwire-location", LocationClass);
73
+ }
74
+ HotwireLocation = LocationClass;
75
+ }
76
+
77
+ // src/components/hotwire-search.ts
78
+ var HotwireSearch;
79
+ if (typeof window !== "undefined") {
80
+ class HotwireSearchClass extends HTMLElement {
81
+ constructor() {
82
+ super();
83
+ }
84
+ connectedCallback() {
85
+ this.innerHTML = "";
86
+ const p = document.createElement("p");
87
+ p.setAttribute("data-controller", "bridge--search");
88
+ p.setAttribute("data-action", "input->bridge--search#handleInput");
89
+ p.style.display = "none";
90
+ p.appendChild(document.createTextNode("Search Form"));
91
+ const resultsDiv = document.createElement("div");
92
+ resultsDiv.setAttribute("data-bridge--search-target", "results");
93
+ p.appendChild(resultsDiv);
94
+ this.appendChild(p);
95
+ }
96
+ disconnectedCallback() {
97
+ }
98
+ }
99
+ if (!customElements.get("hotwire-search")) {
100
+ customElements.define("hotwire-search", HotwireSearchClass);
101
+ }
102
+ HotwireSearch = HotwireSearchClass;
103
+ }
104
+
105
+ // src/components/hotwire-history-sync.ts
106
+ var HotwireHistorySync;
107
+ if (typeof window !== "undefined") {
108
+ class HistorySyncClass extends HTMLElement {
109
+ constructor() {
110
+ super();
111
+ this.handleClick = this.handleClick.bind(this);
112
+ }
113
+ connectedCallback() {
114
+ this.setAttribute("role", "button");
115
+ this.setAttribute("data-controller", "bridge--historysync");
116
+ }
117
+ handleClick(e) {
118
+ }
119
+ disconnectedCallback() {
120
+ }
121
+ }
122
+ if (!customElements.get("hotwire-history-sync")) {
123
+ customElements.define("hotwire-history-sync", HistorySyncClass);
124
+ }
125
+ HotwireHistorySync = HistorySyncClass;
126
+ }
127
+
128
+ // src/components/hotwire-theme-mode.ts
129
+ var HotwireThemeMode;
130
+ if (typeof window !== "undefined") {
131
+ class ThemeModeClass extends HTMLElement {
132
+ constructor() {
133
+ super();
134
+ this.handleClick = this.handleClick.bind(this);
135
+ }
136
+ connectedCallback() {
137
+ this.setAttribute("role", "button");
138
+ this.setAttribute("data-controller", "bridge--thememode");
139
+ this.setAttribute("data-action", "click->bridge--thememode#handleClick");
140
+ this.addEventListener("click", this.handleClick);
141
+ }
142
+ handleClick(e) {
143
+ }
144
+ disconnectedCallback() {
145
+ this.removeEventListener("click", this.handleClick);
146
+ }
147
+ }
148
+ if (!customElements.get("hotwire-theme-mode")) {
149
+ customElements.define("hotwire-theme-mode", ThemeModeClass);
150
+ }
151
+ HotwireThemeMode = ThemeModeClass;
152
+ }
153
+
154
+ // src/utils/utils.ts
155
+ function isTurboNativeUserAgent(userAgent) {
156
+ if (!userAgent && typeof navigator !== "undefined") {
157
+ userAgent = navigator.userAgent;
158
+ }
159
+ userAgent = userAgent || "";
160
+ return userAgent.includes("Turbo Native");
161
+ }
162
+ function triggerHotwireNativeToast(message) {
163
+ if (typeof document === "undefined") return;
164
+ const nativeToasts = document.querySelectorAll(
165
+ "[data-controller='bridge--toast']"
166
+ );
167
+ if (nativeToasts.length > 0) {
168
+ nativeToasts[0].setAttribute("data-bridge-message", message);
169
+ nativeToasts[0].click();
170
+ }
171
+ }
172
+ function triggerHistorySyncEvent(url) {
173
+ if (typeof document === "undefined") return;
174
+ const hotwireElements = document.querySelectorAll(
175
+ "[data-controller='bridge--historysync']"
176
+ );
177
+ if (hotwireElements.length > 0) {
178
+ hotwireElements[0].dispatchEvent(new CustomEvent("turbo:next-history-sync", {
179
+ detail: url,
180
+ bubbles: true
181
+ }));
182
+ }
183
+ }
184
+ function triggerThemeModeEvent(theme) {
185
+ if (typeof document === "undefined") return;
186
+ const themeModeBtns = document.querySelectorAll(
187
+ '[data-controller="bridge--thememode"]'
188
+ );
189
+ if (themeModeBtns.length > 0) {
190
+ themeModeBtns[0].dataset.bridgeMode = theme;
191
+ themeModeBtns[0].click();
192
+ }
193
+ }
194
+ function triggerCartCountValue(cartcount) {
195
+ if (typeof document === "undefined") return;
196
+ const nativeButton = document.querySelectorAll(
197
+ "[data-controller='bridge--dynamicbutton'][data-action='click->bridge--dynamicbutton#sendCartCount']"
198
+ );
199
+ if (nativeButton.length > 0) {
200
+ nativeButton[0].setAttribute("data-bridge-cartcount", cartcount.toString());
201
+ nativeButton[0].click();
202
+ }
203
+ }
204
+
205
+ export { DynamicButton, HotwireHistorySync, HotwireLocation, HotwireSearch, HotwireThemeMode, HotwireToast, isTurboNativeUserAgent, triggerCartCountValue, triggerHistorySyncEvent, triggerHotwireNativeToast, triggerThemeModeEvent };