@authhero/widget 0.2.2 → 0.4.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/authhero-widget/authhero-widget.esm.js +1 -0
- package/dist/authhero-widget/index.esm.js +1 -0
- package/dist/authhero-widget/p-2e93c814.entry.js +1 -0
- package/dist/authhero-widget/p-539fc666.entry.js +1 -0
- package/dist/authhero-widget/p-DQuL1Twl.js +1 -0
- package/dist/authhero-widget/p-Doiemx6o.js +2 -0
- package/dist/cjs/app-globals-V2Kpy_OQ.js +5 -0
- package/dist/cjs/authhero-node.cjs.entry.js +255 -0
- package/dist/cjs/authhero-widget.cjs.entry.js +577 -0
- package/dist/cjs/authhero-widget.cjs.js +25 -0
- package/dist/cjs/index-D0xitTOL.js +3788 -0
- package/dist/cjs/index.cjs.js +8123 -0
- package/dist/cjs/loader.cjs.js +13 -0
- package/dist/collection/collection-manifest.json +13 -0
- package/dist/collection/components/authhero-node/authhero-node.css +298 -0
- package/dist/collection/components/authhero-node/authhero-node.js +360 -0
- package/dist/collection/components/authhero-widget/authhero-widget.css +186 -0
- package/dist/collection/components/authhero-widget/authhero-widget.js +628 -0
- package/dist/collection/index.js +2 -0
- package/dist/collection/server/index.js +453 -0
- package/dist/collection/themes/index.js +71 -0
- package/dist/collection/types/components.js +8 -0
- package/dist/collection/utils/branding.js +248 -0
- package/dist/components/authhero-node.d.ts +11 -0
- package/dist/components/authhero-node.js +1 -0
- package/dist/components/authhero-widget.d.ts +11 -0
- package/dist/components/authhero-widget.js +1 -0
- package/dist/components/index.d.ts +35 -0
- package/dist/components/index.js +1 -0
- package/dist/components/p-086EZrPM.js +1 -0
- package/dist/components/p-DS6y_iDJ.js +1 -0
- package/dist/esm/app-globals-DQuL1Twl.js +3 -0
- package/dist/esm/authhero-node.entry.js +253 -0
- package/dist/esm/authhero-widget.entry.js +575 -0
- package/dist/esm/authhero-widget.js +21 -0
- package/dist/esm/index-Doiemx6o.js +3780 -0
- package/dist/esm/index.js +8122 -0
- package/dist/esm/loader.js +11 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/types/components/authhero-node/authhero-node.d.ts +72 -0
- package/dist/types/components/authhero-widget/authhero-widget.d.ts +172 -0
- package/dist/types/components.d.ts +215 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/server/index.d.ts +85 -0
- package/dist/types/stencil-public-runtime.d.ts +1839 -0
- package/dist/types/themes/index.d.ts +40 -0
- package/dist/types/types/components.d.ts +8 -0
- package/dist/types/utils/branding.d.ts +119 -0
- package/hydrate/index.d.ts +287 -0
- package/hydrate/index.js +23729 -0
- package/hydrate/index.mjs +23719 -0
- package/hydrate/package.json +12 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AuthHero Widget - Branding Utilities
|
|
3
|
+
*
|
|
4
|
+
* Converts AuthHero branding and theme configurations to CSS custom properties.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Convert a style enum to border radius value
|
|
8
|
+
*/
|
|
9
|
+
function styleToRadius(style, baseRadius) {
|
|
10
|
+
if (baseRadius !== undefined)
|
|
11
|
+
return `${baseRadius}px`;
|
|
12
|
+
switch (style) {
|
|
13
|
+
case 'pill':
|
|
14
|
+
return '9999px';
|
|
15
|
+
case 'rounded':
|
|
16
|
+
return '8px';
|
|
17
|
+
case 'sharp':
|
|
18
|
+
return '0';
|
|
19
|
+
default:
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Convert branding configuration to CSS custom properties
|
|
25
|
+
*/
|
|
26
|
+
export function brandingToCssVars(branding) {
|
|
27
|
+
if (!branding)
|
|
28
|
+
return {};
|
|
29
|
+
const vars = {};
|
|
30
|
+
// Primary color
|
|
31
|
+
if (branding.colors?.primary) {
|
|
32
|
+
vars['--ah-color-primary'] = branding.colors.primary;
|
|
33
|
+
// Generate hover variant (slightly darker)
|
|
34
|
+
vars['--ah-color-primary-hover'] = branding.colors.primary;
|
|
35
|
+
}
|
|
36
|
+
// Page background
|
|
37
|
+
if (branding.colors?.page_background) {
|
|
38
|
+
const bg = branding.colors.page_background;
|
|
39
|
+
if (bg.type === 'solid' && bg.start) {
|
|
40
|
+
vars['--ah-page-bg'] = bg.start;
|
|
41
|
+
}
|
|
42
|
+
else if (bg.type === 'gradient' && bg.start && bg.end) {
|
|
43
|
+
const angle = bg.angle_deg ?? 180;
|
|
44
|
+
vars['--ah-page-bg'] = `linear-gradient(${angle}deg, ${bg.start}, ${bg.end})`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Logo URL (stored for reference, used via prop)
|
|
48
|
+
if (branding.logo_url) {
|
|
49
|
+
vars['--ah-logo-url'] = `url(${branding.logo_url})`;
|
|
50
|
+
}
|
|
51
|
+
// Font URL
|
|
52
|
+
if (branding.font?.url) {
|
|
53
|
+
vars['--ah-font-url'] = branding.font.url;
|
|
54
|
+
}
|
|
55
|
+
return vars;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Convert theme configuration to CSS custom properties
|
|
59
|
+
*/
|
|
60
|
+
export function themeToCssVars(theme) {
|
|
61
|
+
if (!theme)
|
|
62
|
+
return {};
|
|
63
|
+
const vars = {};
|
|
64
|
+
// Border radii
|
|
65
|
+
if (theme.borders) {
|
|
66
|
+
const b = theme.borders;
|
|
67
|
+
// Widget
|
|
68
|
+
if (b.widget_corner_radius !== undefined) {
|
|
69
|
+
vars['--ah-widget-radius'] = `${b.widget_corner_radius}px`;
|
|
70
|
+
}
|
|
71
|
+
if (b.widget_border_weight !== undefined) {
|
|
72
|
+
vars['--ah-widget-border-width'] = `${b.widget_border_weight}px`;
|
|
73
|
+
}
|
|
74
|
+
if (b.show_widget_shadow === false) {
|
|
75
|
+
vars['--ah-widget-shadow'] = 'none';
|
|
76
|
+
}
|
|
77
|
+
// Buttons
|
|
78
|
+
const btnRadius = styleToRadius(b.buttons_style, b.button_border_radius);
|
|
79
|
+
if (btnRadius) {
|
|
80
|
+
vars['--ah-btn-radius'] = btnRadius;
|
|
81
|
+
}
|
|
82
|
+
if (b.button_border_weight !== undefined) {
|
|
83
|
+
vars['--ah-btn-border-width'] = `${b.button_border_weight}px`;
|
|
84
|
+
}
|
|
85
|
+
// Inputs
|
|
86
|
+
const inputRadius = styleToRadius(b.inputs_style, b.input_border_radius);
|
|
87
|
+
if (inputRadius) {
|
|
88
|
+
vars['--ah-input-radius'] = inputRadius;
|
|
89
|
+
}
|
|
90
|
+
if (b.input_border_weight !== undefined) {
|
|
91
|
+
vars['--ah-input-border-width'] = `${b.input_border_weight}px`;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Colors
|
|
95
|
+
if (theme.colors) {
|
|
96
|
+
const c = theme.colors;
|
|
97
|
+
// Primary button
|
|
98
|
+
if (c.primary_button) {
|
|
99
|
+
vars['--ah-color-primary'] = c.primary_button;
|
|
100
|
+
vars['--ah-color-primary-hover'] = c.primary_button;
|
|
101
|
+
}
|
|
102
|
+
if (c.primary_button_label) {
|
|
103
|
+
vars['--ah-btn-primary-text'] = c.primary_button_label;
|
|
104
|
+
}
|
|
105
|
+
// Secondary button
|
|
106
|
+
if (c.secondary_button_border) {
|
|
107
|
+
vars['--ah-btn-secondary-border'] = c.secondary_button_border;
|
|
108
|
+
}
|
|
109
|
+
if (c.secondary_button_label) {
|
|
110
|
+
vars['--ah-btn-secondary-text'] = c.secondary_button_label;
|
|
111
|
+
}
|
|
112
|
+
// Text colors
|
|
113
|
+
if (c.body_text) {
|
|
114
|
+
vars['--ah-color-text'] = c.body_text;
|
|
115
|
+
}
|
|
116
|
+
if (c.header) {
|
|
117
|
+
vars['--ah-color-text-header'] = c.header;
|
|
118
|
+
}
|
|
119
|
+
if (c.input_labels_placeholders) {
|
|
120
|
+
vars['--ah-color-text-label'] = c.input_labels_placeholders;
|
|
121
|
+
vars['--ah-color-text-muted'] = c.input_labels_placeholders;
|
|
122
|
+
}
|
|
123
|
+
if (c.input_filled_text) {
|
|
124
|
+
vars['--ah-color-input-text'] = c.input_filled_text;
|
|
125
|
+
}
|
|
126
|
+
// Backgrounds
|
|
127
|
+
if (c.widget_background) {
|
|
128
|
+
vars['--ah-color-bg'] = c.widget_background;
|
|
129
|
+
}
|
|
130
|
+
if (c.input_background) {
|
|
131
|
+
vars['--ah-color-input-bg'] = c.input_background;
|
|
132
|
+
}
|
|
133
|
+
// Borders
|
|
134
|
+
if (c.widget_border) {
|
|
135
|
+
vars['--ah-widget-border-color'] = c.widget_border;
|
|
136
|
+
}
|
|
137
|
+
if (c.input_border) {
|
|
138
|
+
vars['--ah-color-border'] = c.input_border;
|
|
139
|
+
}
|
|
140
|
+
// Links
|
|
141
|
+
if (c.links_focused_components) {
|
|
142
|
+
vars['--ah-color-link'] = c.links_focused_components;
|
|
143
|
+
}
|
|
144
|
+
// Focus/hover
|
|
145
|
+
if (c.base_focus_color) {
|
|
146
|
+
vars['--ah-color-focus-ring'] = c.base_focus_color;
|
|
147
|
+
}
|
|
148
|
+
if (c.base_hover_color) {
|
|
149
|
+
vars['--ah-color-primary-hover'] = c.base_hover_color;
|
|
150
|
+
}
|
|
151
|
+
// Semantic colors
|
|
152
|
+
if (c.error) {
|
|
153
|
+
vars['--ah-color-error'] = c.error;
|
|
154
|
+
}
|
|
155
|
+
if (c.success) {
|
|
156
|
+
vars['--ah-color-success'] = c.success;
|
|
157
|
+
}
|
|
158
|
+
// Icons
|
|
159
|
+
if (c.icons) {
|
|
160
|
+
vars['--ah-color-icon'] = c.icons;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Fonts
|
|
164
|
+
if (theme.fonts) {
|
|
165
|
+
const f = theme.fonts;
|
|
166
|
+
if (f.font_url) {
|
|
167
|
+
vars['--ah-font-url'] = f.font_url;
|
|
168
|
+
}
|
|
169
|
+
if (f.reference_text_size) {
|
|
170
|
+
vars['--ah-font-size-base'] = `${f.reference_text_size}px`;
|
|
171
|
+
}
|
|
172
|
+
if (f.title?.size) {
|
|
173
|
+
vars['--ah-font-size-title'] = `${f.title.size}px`;
|
|
174
|
+
}
|
|
175
|
+
if (f.subtitle?.size) {
|
|
176
|
+
vars['--ah-font-size-subtitle'] = `${f.subtitle.size}px`;
|
|
177
|
+
}
|
|
178
|
+
if (f.body_text?.size) {
|
|
179
|
+
vars['--ah-font-size-body'] = `${f.body_text.size}px`;
|
|
180
|
+
}
|
|
181
|
+
if (f.input_labels?.size) {
|
|
182
|
+
vars['--ah-font-size-label'] = `${f.input_labels.size}px`;
|
|
183
|
+
}
|
|
184
|
+
if (f.buttons_text?.size) {
|
|
185
|
+
vars['--ah-font-size-btn'] = `${f.buttons_text.size}px`;
|
|
186
|
+
}
|
|
187
|
+
if (f.links?.size) {
|
|
188
|
+
vars['--ah-font-size-link'] = `${f.links.size}px`;
|
|
189
|
+
}
|
|
190
|
+
if (f.links_style === 'underlined') {
|
|
191
|
+
vars['--ah-link-decoration'] = 'underline';
|
|
192
|
+
}
|
|
193
|
+
// Font weights
|
|
194
|
+
if (f.title?.bold) {
|
|
195
|
+
vars['--ah-font-weight-title'] = '700';
|
|
196
|
+
}
|
|
197
|
+
if (f.buttons_text?.bold) {
|
|
198
|
+
vars['--ah-font-weight-btn'] = '600';
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Widget settings
|
|
202
|
+
if (theme.widget) {
|
|
203
|
+
const w = theme.widget;
|
|
204
|
+
if (w.header_text_alignment) {
|
|
205
|
+
vars['--ah-title-align'] = w.header_text_alignment;
|
|
206
|
+
}
|
|
207
|
+
if (w.logo_height) {
|
|
208
|
+
vars['--ah-logo-height'] = `${w.logo_height}px`;
|
|
209
|
+
}
|
|
210
|
+
if (w.logo_position) {
|
|
211
|
+
const positionMap = {
|
|
212
|
+
center: 'center',
|
|
213
|
+
left: 'flex-start',
|
|
214
|
+
right: 'flex-end',
|
|
215
|
+
none: 'none',
|
|
216
|
+
};
|
|
217
|
+
vars['--ah-logo-align'] = positionMap[w.logo_position] ?? 'center';
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Page background
|
|
221
|
+
if (theme.page_background) {
|
|
222
|
+
const pb = theme.page_background;
|
|
223
|
+
if (pb.background_color) {
|
|
224
|
+
vars['--ah-page-bg'] = pb.background_color;
|
|
225
|
+
}
|
|
226
|
+
if (pb.background_image_url) {
|
|
227
|
+
vars['--ah-page-bg-image'] = `url(${pb.background_image_url})`;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return vars;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Merge branding and theme into a single CSS variables object
|
|
234
|
+
*/
|
|
235
|
+
export function mergeThemeVars(branding, theme) {
|
|
236
|
+
return {
|
|
237
|
+
...brandingToCssVars(branding),
|
|
238
|
+
...themeToCssVars(theme),
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Apply CSS variables to an element's style
|
|
243
|
+
*/
|
|
244
|
+
export function applyCssVars(element, vars) {
|
|
245
|
+
Object.entries(vars).forEach(([key, value]) => {
|
|
246
|
+
element.style.setProperty(key, value);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Components, JSX } from "../types/components";
|
|
2
|
+
|
|
3
|
+
interface AuthheroNode extends Components.AuthheroNode, HTMLElement {}
|
|
4
|
+
export const AuthheroNode: {
|
|
5
|
+
prototype: AuthheroNode;
|
|
6
|
+
new (): AuthheroNode;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Used to define this component and all nested components recursively.
|
|
10
|
+
*/
|
|
11
|
+
export const defineCustomElement: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as o,d as s}from"./p-DS6y_iDJ.js";const p=o,r=s;export{p as AuthheroNode,r as defineCustomElement}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Components, JSX } from "../types/components";
|
|
2
|
+
|
|
3
|
+
interface AuthheroWidget extends Components.AuthheroWidget, HTMLElement {}
|
|
4
|
+
export const AuthheroWidget: {
|
|
5
|
+
prototype: AuthheroWidget;
|
|
6
|
+
new (): AuthheroWidget;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Used to define this component and all nested components recursively.
|
|
10
|
+
*/
|
|
11
|
+
export const defineCustomElement: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e,p as t,H as r,c as i,h as s}from"./p-086EZrPM.js";import{d as a}from"./p-DS6y_iDJ.js";function o(e,t){if(void 0!==t)return t+"px";switch(e){case"pill":return"9999px";case"rounded":return"8px";case"sharp":return"0";default:return}}function n(e){if(!e)return{};const t={};if(e.colors?.primary&&(t["--ah-color-primary"]=e.colors.primary,t["--ah-color-primary-hover"]=e.colors.primary),e.colors?.page_background){const r=e.colors.page_background;"solid"===r.type&&r.start?t["--ah-page-bg"]=r.start:"gradient"===r.type&&r.start&&r.end&&(t["--ah-page-bg"]=`linear-gradient(${r.angle_deg??180}deg, ${r.start}, ${r.end})`)}return e.logo_url&&(t["--ah-logo-url"]=`url(${e.logo_url})`),e.font?.url&&(t["--ah-font-url"]=e.font.url),t}function c(e){if(!e)return{};const t={};if(e.borders){const r=e.borders;void 0!==r.widget_corner_radius&&(t["--ah-widget-radius"]=r.widget_corner_radius+"px"),void 0!==r.widget_border_weight&&(t["--ah-widget-border-width"]=r.widget_border_weight+"px"),!1===r.show_widget_shadow&&(t["--ah-widget-shadow"]="none");const i=o(r.buttons_style,r.button_border_radius);i&&(t["--ah-btn-radius"]=i),void 0!==r.button_border_weight&&(t["--ah-btn-border-width"]=r.button_border_weight+"px");const s=o(r.inputs_style,r.input_border_radius);s&&(t["--ah-input-radius"]=s),void 0!==r.input_border_weight&&(t["--ah-input-border-width"]=r.input_border_weight+"px")}if(e.colors){const r=e.colors;r.primary_button&&(t["--ah-color-primary"]=r.primary_button,t["--ah-color-primary-hover"]=r.primary_button),r.primary_button_label&&(t["--ah-btn-primary-text"]=r.primary_button_label),r.secondary_button_border&&(t["--ah-btn-secondary-border"]=r.secondary_button_border),r.secondary_button_label&&(t["--ah-btn-secondary-text"]=r.secondary_button_label),r.body_text&&(t["--ah-color-text"]=r.body_text),r.header&&(t["--ah-color-text-header"]=r.header),r.input_labels_placeholders&&(t["--ah-color-text-label"]=r.input_labels_placeholders,t["--ah-color-text-muted"]=r.input_labels_placeholders),r.input_filled_text&&(t["--ah-color-input-text"]=r.input_filled_text),r.widget_background&&(t["--ah-color-bg"]=r.widget_background),r.input_background&&(t["--ah-color-input-bg"]=r.input_background),r.widget_border&&(t["--ah-widget-border-color"]=r.widget_border),r.input_border&&(t["--ah-color-border"]=r.input_border),r.links_focused_components&&(t["--ah-color-link"]=r.links_focused_components),r.base_focus_color&&(t["--ah-color-focus-ring"]=r.base_focus_color),r.base_hover_color&&(t["--ah-color-primary-hover"]=r.base_hover_color),r.error&&(t["--ah-color-error"]=r.error),r.success&&(t["--ah-color-success"]=r.success),r.icons&&(t["--ah-color-icon"]=r.icons)}if(e.fonts){const r=e.fonts;r.font_url&&(t["--ah-font-url"]=r.font_url),r.reference_text_size&&(t["--ah-font-size-base"]=r.reference_text_size+"px"),r.title?.size&&(t["--ah-font-size-title"]=r.title.size+"px"),r.subtitle?.size&&(t["--ah-font-size-subtitle"]=r.subtitle.size+"px"),r.body_text?.size&&(t["--ah-font-size-body"]=r.body_text.size+"px"),r.input_labels?.size&&(t["--ah-font-size-label"]=r.input_labels.size+"px"),r.buttons_text?.size&&(t["--ah-font-size-btn"]=r.buttons_text.size+"px"),r.links?.size&&(t["--ah-font-size-link"]=r.links.size+"px"),"underlined"===r.links_style&&(t["--ah-link-decoration"]="underline"),r.title?.bold&&(t["--ah-font-weight-title"]="700"),r.buttons_text?.bold&&(t["--ah-font-weight-btn"]="600")}if(e.widget){const r=e.widget;r.header_text_alignment&&(t["--ah-title-align"]=r.header_text_alignment),r.logo_height&&(t["--ah-logo-height"]=r.logo_height+"px"),r.logo_position&&(t["--ah-logo-align"]={center:"center",left:"flex-start",right:"flex-end",none:"none"}[r.logo_position]??"center")}if(e.page_background){const r=e.page_background;r.background_color&&(t["--ah-page-bg"]=r.background_color),r.background_image_url&&(t["--ah-page-bg-image"]=`url(${r.background_image_url})`)}return t}const h=t(class extends r{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow(),this.formSubmit=i(this,"formSubmit"),this.buttonClick=i(this,"buttonClick"),this.linkClick=i(this,"linkClick"),this.navigate=i(this,"navigate"),this.flowComplete=i(this,"flowComplete"),this.flowError=i(this,"flowError"),this.screenChange=i(this,"screenChange")}get el(){return this}screen;apiUrl;branding;theme;loading=!1;autoSubmit=!1;_screen;_branding;_theme;formData={};formSubmit;buttonClick;linkClick;navigate;flowComplete;flowError;screenChange;watchScreen(e){if("string"==typeof e)try{this._screen=JSON.parse(e)}catch{console.error("Failed to parse screen JSON")}else this._screen=e;this._screen&&this.screenChange.emit(this._screen)}watchBranding(e){if("string"==typeof e)try{this._branding=JSON.parse(e)}catch{console.error("Failed to parse branding JSON")}else this._branding=e;this.applyThemeStyles()}watchTheme(e){if("string"==typeof e)try{this._theme=JSON.parse(e)}catch{console.error("Failed to parse theme JSON")}else this._theme=e;this.applyThemeStyles()}applyThemeStyles(){const e=function(e,t){return{...n(e),...c(t)}}(this._branding,this._theme);!function(e,t){Object.entries(t).forEach((([t,r])=>{e.style.setProperty(t,r)}))}(this.el,e)}async componentWillLoad(){this.watchScreen(this.screen),this.watchBranding(this.branding),this.watchTheme(this.theme),this.apiUrl&&!this._screen&&await this.fetchScreen()}async fetchScreen(){if(this.apiUrl){this.loading=!0;try{const e=await fetch(this.apiUrl,{credentials:"include",headers:{Accept:"application/json"}});e.ok&&(this._screen=await e.json(),this._screen&&this.screenChange.emit(this._screen))}catch(e){console.error("Failed to fetch screen:",e)}finally{this.loading=!1}}}handleInputChange=(e,t)=>{this.formData={...this.formData,[e]:t}};handleSubmit=async e=>{if(e.preventDefault(),this._screen&&(this.formSubmit.emit({screen:this._screen,data:this.formData}),this.autoSubmit)){this.loading=!0;try{const e=await fetch(this._screen.action,{method:this._screen.method,credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({data:this.formData})}),t=e.headers.get("content-type");if(t?.includes("application/json")){const t=await e.json();t.redirect?(this.flowComplete.emit({redirectUrl:t.redirect}),this.navigate.emit({url:t.redirect})):t.screen?(this._screen=t.screen,this.formData={},this.screenChange.emit(t.screen),t.branding&&(this._branding=t.branding,this.applyThemeStyles())):t.complete&&this.flowComplete.emit({}),!e.ok&&t.screen&&(this._screen=t.screen,this.screenChange.emit(t.screen))}}catch(e){console.error("Form submission failed:",e),this.flowError.emit({message:e instanceof Error?e.message:"Form submission failed"})}finally{this.loading=!1}}};handleButtonClick=e=>{this.buttonClick.emit(e)};handleLinkClick=(e,t)=>{this.linkClick.emit({id:t.id,href:t.href,text:t.text}),this.autoSubmit||e.preventDefault()};getScreenErrors(){return this._screen?.messages?.filter((e=>"error"===e.type))||[]}getScreenSuccesses(){return this._screen?.messages?.filter((e=>"success"===e.type))||[]}getOrderedComponents(){return this._screen?[...this._screen.components].filter((e=>!1!==e.visible)).sort(((e,t)=>(e.order??0)-(t.order??0))):[]}render(){if(this.loading&&!this._screen)return s("div",{class:"widget-container"},s("div",{class:"loading-spinner"}));if(!this._screen)return s("div",{class:"widget-container"},s("div",{class:"error-message"},"No screen configuration provided"));const e=this.getScreenErrors(),t=this.getScreenSuccesses(),r=this.getOrderedComponents(),i=this._branding?.logo_url;return s("div",{class:"widget-container",part:"container"},i&&s("img",{class:"logo",part:"logo",src:i,alt:"Logo"}),this._screen.title&&s("h1",{class:"title",part:"title"},this._screen.title),this._screen.description&&s("p",{class:"description",part:"description"},this._screen.description),e.map((e=>s("div",{class:"message message-error",part:"message message-error",key:e.id??e.text},e.text))),t.map((e=>s("div",{class:"message message-success",part:"message message-success",key:e.id??e.text},e.text))),s("form",{onSubmit:this.handleSubmit,part:"form"},r.map((e=>s("authhero-node",{key:e.id,component:e,value:this.formData[e.id],onFieldChange:e=>this.handleInputChange(e.detail.id,e.detail.value),onButtonClick:e=>this.handleButtonClick(e.detail),disabled:this.loading})))),this._screen.links&&this._screen.links.length>0&&s("div",{class:"links",part:"links"},this._screen.links.map((e=>s("span",{class:"link-wrapper",part:"link-wrapper",key:e.id??e.href},e.linkText?s("span",null,e.text," ",s("a",{href:e.href,class:"link",part:"link",onClick:t=>this.handleLinkClick(t,{id:e.id,href:e.href,text:e.linkText||e.text})},e.linkText)):s("a",{href:e.href,class:"link",part:"link",onClick:t=>this.handleLinkClick(t,{id:e.id,href:e.href,text:e.text})},e.text))))))}static get watchers(){return{screen:[{watchScreen:0}],branding:[{watchBranding:0}],theme:[{watchTheme:0}]}}static get style(){return":host{display:block;font-family:var(--ah-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif)}.widget-container{max-width:var(--ah-widget-max-width, 400px);margin:0 auto;padding:var(--ah-widget-padding, 2rem);background-color:var(--ah-color-bg, #ffffff);border-radius:var(--ah-widget-radius, 8px);box-shadow:var(--ah-widget-shadow, 0 2px 10px rgba(0, 0, 0, 0.1))}.logo{display:block;width:var(--ah-logo-size, 48px);height:var(--ah-logo-size, 48px);margin:0 auto var(--ah-space-6, 1.5rem);object-fit:contain;border-radius:var(--ah-logo-radius, 8px)}.title{font-size:var(--ah-font-size-2xl, 1.5rem);font-weight:var(--ah-font-weight-semibold, 600);text-align:center;margin:0 0 var(--ah-space-8, 2rem);color:var(--ah-color-text, #111827);line-height:var(--ah-line-height-tight, 1.25)}.message{padding:var(--ah-space-3, 0.75rem) var(--ah-space-4, 1rem);border-radius:var(--ah-radius-md, 4px);margin-bottom:var(--ah-space-4, 1rem);font-size:var(--ah-font-size-sm, 0.875rem);line-height:var(--ah-line-height-normal, 1.5)}.message-error{background-color:var(--ah-color-error-bg, #fee2e2);color:var(--ah-color-error, #dc2626);border:1px solid var(--ah-color-error-border, #fecaca)}.message-success{background-color:var(--ah-color-success-bg, #dcfce7);color:var(--ah-color-success, #16a34a);border:1px solid var(--ah-color-success-border, #bbf7d0)}form{display:flex;flex-direction:column;gap:var(--ah-space-4, 1rem)}.links{display:flex;flex-direction:column;align-items:center;gap:var(--ah-space-2, 0.5rem);margin-top:var(--ah-space-6, 1.5rem);padding-top:var(--ah-space-4, 1rem)}.link-wrapper{font-size:var(--ah-font-size-sm, 0.875rem);color:var(--ah-color-text-muted, #6b7280)}.link{color:var(--ah-color-primary, #0066cc);text-decoration:none;font-size:var(--ah-font-size-sm, 0.875rem);transition:color var(--ah-transition-fast, 150ms ease)}.link:hover{text-decoration:underline}.link:focus-visible{outline:2px solid var(--ah-color-primary, #0066cc);outline-offset:2px}.divider{display:flex;align-items:center;text-align:center;margin:var(--ah-space-2, 0.5rem) 0}.divider::before,.divider::after{content:'';flex:1;border-bottom:1px solid var(--ah-color-border-muted, #e5e7eb)}.divider-text{padding:0 var(--ah-space-4, 1rem);font-size:var(--ah-font-size-sm, 0.875rem);color:var(--ah-color-text-muted, #9ca3af);text-transform:uppercase;letter-spacing:0.05em}.loading-spinner{width:40px;height:40px;margin:var(--ah-space-8, 2rem) auto;border:3px solid var(--ah-color-border-muted, #f3f3f3);border-top:3px solid var(--ah-color-primary, #0066cc);border-radius:50%;animation:spin 1s linear infinite}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}.error-message{text-align:center;color:var(--ah-color-error, #dc2626);padding:var(--ah-space-4, 1rem)}"}},[513,"authhero-widget",{screen:[1],apiUrl:[1,"api-url"],branding:[1],theme:[1],loading:[1028],autoSubmit:[4,"auto-submit"],_screen:[32],_branding:[32],_theme:[32],formData:[32]},void 0,{screen:[{watchScreen:0}],branding:[{watchBranding:0}],theme:[{watchTheme:0}]}]);function l(){"undefined"!=typeof customElements&&["authhero-widget","authhero-node"].forEach((t=>{switch(t){case"authhero-widget":customElements.get(e(t))||customElements.define(e(t),h);break;case"authhero-node":customElements.get(e(t))||a()}}))}l();const d=h,p=l;export{d as AuthheroWidget,p as defineCustomElement}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the base path to where the assets can be found. Use "setAssetPath(path)"
|
|
3
|
+
* if the path needs to be customized.
|
|
4
|
+
*/
|
|
5
|
+
export declare const getAssetPath: (path: string) => string;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Used to manually set the base path where assets can be found.
|
|
9
|
+
* If the script is used as "module", it's recommended to use "import.meta.url",
|
|
10
|
+
* such as "setAssetPath(import.meta.url)". Other options include
|
|
11
|
+
* "setAssetPath(document.currentScript.src)", or using a bundler's replace plugin to
|
|
12
|
+
* dynamically set the path at build time, such as "setAssetPath(process.env.ASSET_PATH)".
|
|
13
|
+
* But do note that this configuration depends on how your script is bundled, or lack of
|
|
14
|
+
* bundling, and where your assets can be loaded from. Additionally custom bundling
|
|
15
|
+
* will have to ensure the static assets are copied to its build directory.
|
|
16
|
+
*/
|
|
17
|
+
export declare const setAssetPath: (path: string) => void;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Used to specify a nonce value that corresponds with an application's CSP.
|
|
21
|
+
* When set, the nonce will be added to all dynamically created script and style tags at runtime.
|
|
22
|
+
* Alternatively, the nonce value can be set on a meta tag in the DOM head
|
|
23
|
+
* (<meta name="csp-nonce" content="{ nonce value here }" />) which
|
|
24
|
+
* will result in the same behavior.
|
|
25
|
+
*/
|
|
26
|
+
export declare const setNonce: (nonce: string) => void
|
|
27
|
+
|
|
28
|
+
export interface SetPlatformOptions {
|
|
29
|
+
raf?: (c: FrameRequestCallback) => number;
|
|
30
|
+
ael?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
|
|
31
|
+
rel?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
|
|
32
|
+
}
|
|
33
|
+
export declare const setPlatformOptions: (opts: SetPlatformOptions) => void;
|
|
34
|
+
|
|
35
|
+
export * from '../types';
|