@authhero/widget 0.37.1 → 0.38.1

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 (32) hide show
  1. package/dist/authhero-widget/authhero-widget.esm.js +1 -1
  2. package/dist/authhero-widget/index.esm.js +1 -1
  3. package/dist/authhero-widget/p-c2744f87.entry.js +1 -0
  4. package/dist/authhero-widget/p-f94037cd.entry.js +1 -0
  5. package/dist/cjs/authhero-node.cjs.entry.js +526 -13
  6. package/dist/cjs/authhero-widget.cjs.entry.js +79 -10
  7. package/dist/cjs/authhero-widget.cjs.js +1 -1
  8. package/dist/cjs/index.cjs.js +1 -1
  9. package/dist/cjs/loader.cjs.js +1 -1
  10. package/dist/collection/components/authhero-node/authhero-node.css +94 -0
  11. package/dist/collection/components/authhero-node/authhero-node.js +302 -13
  12. package/dist/collection/components/authhero-widget/authhero-widget.js +98 -10
  13. package/dist/collection/utils/date-format.js +244 -0
  14. package/dist/components/authhero-node.js +1 -1
  15. package/dist/components/authhero-widget.js +1 -1
  16. package/dist/components/index.js +1 -1
  17. package/dist/components/p-B_R7ma-J.js +1 -0
  18. package/dist/esm/authhero-node.entry.js +526 -13
  19. package/dist/esm/authhero-widget.entry.js +79 -10
  20. package/dist/esm/authhero-widget.js +1 -1
  21. package/dist/esm/index.js +1 -1
  22. package/dist/esm/loader.js +1 -1
  23. package/dist/types/components/authhero-node/authhero-node.d.ts +83 -0
  24. package/dist/types/components/authhero-widget/authhero-widget.d.ts +19 -0
  25. package/dist/types/components.d.ts +18 -0
  26. package/dist/types/utils/date-format.d.ts +52 -0
  27. package/hydrate/index.js +609 -24
  28. package/hydrate/index.mjs +609 -24
  29. package/package.json +2 -2
  30. package/dist/authhero-widget/p-cdfc4555.entry.js +0 -1
  31. package/dist/authhero-widget/p-e95c436f.entry.js +0 -1
  32. package/dist/components/p-BP46GHTc.js +0 -1
@@ -236,7 +236,252 @@ function getCountryByCode(code) {
236
236
  countries.find((c) => c.code === "US"));
237
237
  }
238
238
 
239
- const authheroNodeCss = () => `:host{display:block}.input-wrapper{display:flex;flex-direction:column;position:relative;margin-top:8px;margin-bottom:16px}.input-container{position:relative;width:100%}.input-label{position:absolute;left:16px;top:50%;transform:translateY(-50%);font-size:var(--ah-font-size-label, 16px);font-weight:var(--ah-font-weight-label, 400);color:var(--ah-color-text-muted, #65676e);pointer-events:none;transition:all 0.15s ease-out;background-color:transparent;padding:0;z-index:1}.input-label.floating,.input-field:focus+.input-label,.input-field:not(:placeholder-shown)+.input-label,select.input-field+.input-label,input[type="date"].input-field+.input-label{top:-8px;transform:translateY(0);font-size:12px;background-color:var(--ah-color-bg, #ffffff);padding:0 4px;left:12px;color:var(--ah-color-text-muted, #65676e)}.input-field:focus+.input-label{color:var(--ah-color-primary, #635dff)}.required{color:var(--ah-color-error, #d03c38);margin-left:2px}.input-field{width:100%;padding:16px;font-size:16px;font-family:inherit;color:var(--ah-color-input-text, var(--ah-color-text, #1e212a));background-color:var(--ah-color-input-bg, #ffffff);border:var(--ah-input-border-width, 1px) solid var(--ah-color-border, #c9cace);border-radius:var(--ah-input-radius, 3px);outline:none;transition:border-color 0.15s ease-out, box-shadow 0.15s ease-out;box-sizing:border-box}.input-field::placeholder{color:transparent}.input-field:hover{border-color:var(--ah-color-border-hover, #65676e)}.input-field:focus{border-color:var(--ah-color-primary, #635dff);box-shadow:inset 0 0 0 1px var(--ah-color-primary, #635dff)}.input-field.has-error{border-color:var(--ah-color-error, #d03c38)}.input-field.has-error:focus{box-shadow:inset 0 0 0 1px var(--ah-color-error, #d03c38)}.input-field:disabled{background-color:var(--ah-color-bg-disabled, #f5f5f5);border-color:var(--ah-color-border-disabled, #e0e1e3);cursor:not-allowed;opacity:0.7}.password-container{position:relative;display:flex;align-items:center}.password-container .input-field{padding-right:48px}.password-toggle{position:absolute;right:12px;top:50%;transform:translateY(-50%);background:none;border:none;cursor:pointer;padding:4px;display:flex;align-items:center;justify-content:center;color:var(--ah-color-icon, var(--ah-color-text-muted, #65676e));transition:color 0.15s ease}.password-toggle:hover{color:var(--ah-color-icon, var(--ah-color-text, #1e212a))}.password-toggle svg{width:20px;height:20px}.error-text{font-size:12px;color:var(--ah-color-error, #d03c38);margin-top:4px;line-height:1.4}.helper-text{font-size:12px;color:var(--ah-color-text-muted, #65676e);margin-top:4px;line-height:1.4}.field-link{display:block;text-align:left;margin-top:8px;margin-bottom:16px}.field-link a{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none);font-size:var(--ah-font-size-link, 14px);font-weight:var(--ah-font-weight-link, 400)}.field-link a:hover{text-decoration:underline}.checkbox-wrapper{display:flex;align-items:flex-start;gap:10px;cursor:pointer;margin-bottom:16px}.checkbox-wrapper input[type="checkbox"]{width:18px;height:18px;margin:0;accent-color:var(--ah-color-primary, #635dff);cursor:pointer;flex-shrink:0}.checkbox-label{font-size:var(--ah-font-size-body, 14px);font-weight:var(--ah-font-weight-body, 400);color:var(--ah-color-text, #1e212a);line-height:1.5}.btn{display:inline-flex;align-items:center;justify-content:center;gap:10px;width:100%;padding:14px 20px;font-size:var(--ah-font-size-btn, 16px);font-weight:var(--ah-font-weight-btn, 400);font-family:inherit;line-height:1.25;text-align:center;text-decoration:none;border:none;border-radius:var(--ah-btn-radius, 3px);cursor:pointer;transition:background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;box-sizing:border-box}.btn:disabled{opacity:0.6;cursor:not-allowed}.btn:not(:disabled):active{transform:scale(0.98)}.btn:focus-visible{outline:2px solid var(--ah-color-focus-ring, var(--ah-color-primary, #635dff));outline-offset:2px}.btn-primary{background-color:var(--ah-color-primary, #635dff);color:var(--ah-color-text-on-primary, #ffffff);margin-top:12px}.btn-primary:not(:disabled):hover{background-color:var( --ah-color-primary-hover, color-mix(in srgb, var(--ah-color-primary, #635dff) 85%, black) )}.btn-secondary{background-color:var(--ah-color-bg, #ffffff);color:var(--ah-btn-secondary-text, var(--ah-color-text, #1e212a));border:var(--ah-btn-border-width, 1px) solid var(--ah-btn-secondary-border, var(--ah-color-border, #c9cace))}.btn-secondary:not(:disabled):hover{background-color:var(--ah-color-bg-hover, #f5f5f5);border-color:var(--ah-color-border-hover, #65676e)}.btn-link{background:none;border:none;color:var(--ah-color-link, #635dff);padding:8px 0;font-weight:var(--ah-font-weight-link, 400);text-decoration:none}.btn-link:hover{text-decoration:underline}.phone-input-wrapper{display:flex;align-items:stretch;gap:0;width:100%}.country-select{flex-shrink:0;width:auto;padding:12px 8px;font-size:var(--ah-font-size-body, 16px);font-family:var(--ah-font-family, inherit);border:var(--ah-input-border-width, 1px) solid var(--ah-color-border, #c9cace);border-right:none;border-radius:var(--ah-input-radius, 4px) 0 0 var(--ah-input-radius, 4px);background-color:var(--ah-color-input-bg, var(--ah-color-surface, #fff));color:var(--ah-color-input-text, var(--ah-color-text, #1e212a));cursor:pointer;appearance:none;-webkit-appearance:none;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 6px center;padding-right:22px}.country-select:focus{outline:none;border-color:var(--ah-color-primary, #635dff);box-shadow:0 0 0 1px var(--ah-color-primary, #635dff)}.country-select:disabled{opacity:0.5;cursor:not-allowed}.phone-input-wrapper .input-container{flex:1;min-width:0}.phone-input-wrapper .input-field{border-radius:0 var(--ah-input-radius, 4px) var(--ah-input-radius, 4px) 0}.phone-input-wrapper .input-label.floating,.phone-input-wrapper .input-field:focus+.input-label,.phone-input-wrapper .input-field:not(:placeholder-shown)+.input-label{left:8px}.social-buttons{display:flex;flex-direction:column;gap:12px}.btn-social{display:flex;align-items:center;justify-content:center;gap:12px;position:relative}.btn-social-badge{position:absolute;right:12px;top:0;transform:translateY(-50%);font-size:11px;font-weight:500;line-height:1;padding:4px 9px;border-radius:999px;background:var(--ah-color-last-used, var(--ah-color-primary, #635dff));color:var(--ah-color-last-used-text, var(--ah-color-text-on-primary, #fff));white-space:nowrap;pointer-events:none}.btn-social.btn-social-last-used{border-color:var(--ah-color-last-used, var(--ah-color-primary, #635dff));box-shadow:inset 0 0 0 1px var(--ah-color-last-used, var(--ah-color-primary, #635dff))}.input-badge{position:absolute;right:12px;top:0;transform:translateY(-50%);font-size:11px;font-weight:500;line-height:1;padding:4px 9px;border-radius:999px;background:var(--ah-color-last-used, var(--ah-color-primary, #635dff));color:var(--ah-color-last-used-text, var(--ah-color-text-on-primary, #fff));white-space:nowrap;pointer-events:none;z-index:2}.btn-social-content{display:flex;flex-direction:column;align-items:center;text-align:center}.btn-social-subtitle{font-size:12px;font-style:italic;opacity:0.8;margin-top:2px}.btn-social-subtitle:empty{display:none}.social-icon{width:20px;height:20px;flex-shrink:0}@media (max-width: 480px){.social-buttons:has(.btn-social:nth-child(3)){flex-direction:row;flex-wrap:nowrap;justify-content:stretch;gap:8px}.social-buttons:has(.btn-social:nth-child(3)) .btn-social{width:auto;min-width:0;padding:12px;flex:1 1 0}.social-buttons:has(.btn-social:nth-child(3)) .btn-social span{display:none}.social-buttons:has(.btn-social:nth-child(3)) .social-icon{width:24px;height:24px}}.btn-icon{width:20px;height:20px;flex-shrink:0}.btn-icon img{width:100%;height:100%;object-fit:contain}.text-title{font-size:var(--ah-font-size-title, 20px);font-weight:var(--ah-font-weight-title, 400);color:var(--ah-color-text-header, var(--ah-color-header, #1e212a));margin:8px 0;line-height:1.3}.text-title.text-success{color:var(--ah-color-success, #13a769)}.text-description{font-size:var(--ah-font-size-subtitle, 14px);font-weight:var(--ah-font-weight-subtitle, 400);color:var(--ah-color-text-muted, #65676e);margin:4px 0;line-height:1.5}.image{display:block;max-width:100%;height:auto;border-radius:4px}.image-centered{margin:0 auto 16px;width:52px;height:52px;object-fit:contain}.link{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none);font-size:var(--ah-font-size-link, 14px);transition:color 0.15s ease}.link:hover{text-decoration:underline}.link:focus-visible{outline:2px solid var(--ah-color-focus-ring, var(--ah-color-link, #635dff));outline-offset:2px;border-radius:2px}.node-error{padding:12px 16px;background-color:var(--ah-color-error-bg, #ffeaea);color:var(--ah-color-error, #d03c38);border-left:3px solid var(--ah-color-error, #d03c38);border-radius:0;font-size:14px;margin-bottom:16px}.node-success{padding:12px 16px;background-color:var(--ah-color-success-bg, #e6f9f1);color:var(--ah-color-success, #13a769);border-left:3px solid var(--ah-color-success, #13a769);border-radius:0;font-size:14px;margin-bottom:16px}.divider{display:flex;align-items:center;text-align:center;margin:16px 0}.divider::before,.divider::after{content:"";flex:1;border-bottom:1px solid var(--ah-color-border-muted, #c9cace)}.divider-text{padding:0 10px;font-size:12px;font-weight:400;color:var(--ah-color-text-muted, #65676e);text-transform:uppercase;letter-spacing:0.5px}.rich-text{font-size:var(--ah-font-size-body, 14px);font-weight:var(--ah-font-weight-body, 400);line-height:1.5;color:var(--ah-color-text, #1e212a)}.rich-text a{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none);transition:color 0.15s ease}.rich-text a:hover{text-decoration:underline}.rich-text .terms-text{margin-top:16px;text-align:center;font-size:12px;color:var(--ah-color-text-muted, #65676e)}.rich-text .terms-text a{font-size:12px}.rich-text .forgot-password-link{text-align:right;font-size:13px;margin-top:4px}.rich-text .forgot-password-link a{font-size:13px;color:var(--ah-color-link, #635dff)}.rich-text .passwordless-link{margin-top:16px;text-align:center;font-size:14px}.rich-text .passwordless-link a{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none)}.rich-text .passwordless-link a:hover{text-decoration:underline}.rich-text .signup-link{margin-top:16px;text-align:center;font-size:14px;color:var(--ah-color-text, #1e212a)}.code-field{position:relative}.code-input{position:absolute;inset:0;width:100%;height:100%;margin:0;padding:0;border:none;background:transparent;color:transparent;caret-color:transparent;font-family:inherit;letter-spacing:0;outline:none;cursor:text;-webkit-text-fill-color:transparent}.code-boxes{display:flex;align-items:center;gap:var(--ah-code-group-gap, 12px);justify-content:center}.code-group{display:flex;gap:0}.code-separator{color:var(--ah-color-text-muted, #65676e);font-size:var(--ah-code-font-size, 24px);user-select:none}.code-box-placeholder{color:var(--ah-color-text-muted, #65676e);opacity:0.4}.code-box{position:relative;flex:0 0 auto;width:var(--ah-code-box-width, 48px);height:var(--ah-code-box-height, 56px);display:flex;align-items:center;justify-content:center;font-size:var(--ah-code-font-size, 24px);font-family:inherit;color:var(--ah-color-input-text, var(--ah-color-text, #1e212a));background-color:var(--ah-color-input-bg, #ffffff);border:var(--ah-input-border-width, 1px) solid var(--ah-color-border, #c9cace);border-radius:0;transition:border-color 0.15s ease-out, box-shadow 0.15s ease-out;box-sizing:border-box}.code-box+.code-box{margin-left:calc(-1 * var(--ah-input-border-width, 1px))}.code-group .code-box:first-child{border-top-left-radius:var(--ah-input-radius, 3px);border-bottom-left-radius:var(--ah-input-radius, 3px)}.code-group .code-box:last-child{border-top-right-radius:var(--ah-input-radius, 3px);border-bottom-right-radius:var(--ah-input-radius, 3px)}.code-field:focus-within .code-box.is-active{z-index:1;border-color:var(--ah-color-primary, #635dff);box-shadow:inset 0 0 0 1px var(--ah-color-primary, #635dff)}.code-field.has-error .code-box{border-color:var(--ah-color-error, #d03c38)}.code-input:disabled{cursor:not-allowed}.code-input:disabled~.code-boxes .code-box{background-color:var(--ah-color-bg-disabled, #f5f5f5);border-color:var(--ah-color-border-disabled, #e0e1e3)}`;
239
+ /**
240
+ * Locale-aware layout for the segmented DATE input.
241
+ *
242
+ * The segment order is resolved from a static table rather than from
243
+ * `Intl.DateTimeFormat`, deliberately: the widget is server-rendered and then
244
+ * hydrated in the browser, and the two runtimes do not ship the same ICU data
245
+ * (a Workers runtime commonly falls back to en-US ordering). A static table
246
+ * gives the server and the client the same answer, so the hydrated DOM matches
247
+ * the rendered one.
248
+ */
249
+ /** Languages that write dates big-endian: year, month, day. */
250
+ const YEAR_FIRST_LANGUAGES = new Set([
251
+ "bo",
252
+ "dz",
253
+ "hu",
254
+ "ja",
255
+ "ko",
256
+ "lt",
257
+ "mn",
258
+ "sv",
259
+ "ug",
260
+ "zh",
261
+ ]);
262
+ /**
263
+ * Regions that write month before day. Month-first is essentially a US
264
+ * convention plus the places that adopted it.
265
+ */
266
+ const MONTH_FIRST_REGIONS = new Set(["us", "ph", "fm", "mh", "pw", "as", "gu"]);
267
+ /**
268
+ * Locales whose language is normally year-first but which write dates
269
+ * day-first in a particular region — Finland-Swedish is d.m.yyyy, unlike
270
+ * Sweden-Swedish.
271
+ */
272
+ const DAY_FIRST_TAGS = new Set(["sv-fi"]);
273
+ const DEFAULT_TOKENS = {
274
+ day: "DD",
275
+ month: "MM",
276
+ year: "YYYY",
277
+ };
278
+ /**
279
+ * Placeholder tokens in the language's own convention — a German field reads
280
+ * TT.MM.JJJJ, a French one JJ/MM/AAAA. Languages without an entry fall back to
281
+ * the English DD/MM/YYYY tokens.
282
+ */
283
+ const TOKENS_BY_LANGUAGE = {
284
+ cs: { day: "DD", month: "MM", year: "RRRR" },
285
+ da: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
286
+ de: { day: "TT", month: "MM", year: "JJJJ" },
287
+ es: { day: "DD", month: "MM", year: "AAAA" },
288
+ fi: { day: "PP", month: "KK", year: "VVVV" },
289
+ fr: { day: "JJ", month: "MM", year: "AAAA" },
290
+ hu: { day: "NN", month: "HH", year: "ÉÉÉÉ" },
291
+ it: { day: "GG", month: "MM", year: "AAAA" },
292
+ nb: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
293
+ nl: { day: "DD", month: "MM", year: "JJJJ" },
294
+ nn: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
295
+ no: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
296
+ pl: { day: "DD", month: "MM", year: "RRRR" },
297
+ pt: { day: "DD", month: "MM", year: "AAAA" },
298
+ ru: { day: "ДД", month: "ММ", year: "ГГГГ" },
299
+ sk: { day: "DD", month: "MM", year: "RRRR" },
300
+ sv: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
301
+ tr: { day: "GG", month: "AA", year: "YYYY" },
302
+ uk: { day: "ДД", month: "ММ", year: "РРРР" },
303
+ };
304
+ /**
305
+ * Separator by language, for languages that do not use the defaults ("/" for
306
+ * day- or month-first, "-" for year-first). Mostly the locales that write
307
+ * 14.08.2026 with dots — German, the Nordics minus Sweden, and most of
308
+ * Central/Eastern Europe.
309
+ */
310
+ const SEPARATOR_BY_LANGUAGE = {
311
+ bg: ".",
312
+ cs: ".",
313
+ da: ".",
314
+ de: ".",
315
+ et: ".",
316
+ fi: ".",
317
+ hr: ".",
318
+ hu: ".",
319
+ is: ".",
320
+ ja: "/",
321
+ ko: ".",
322
+ lv: ".",
323
+ mk: ".",
324
+ nb: ".",
325
+ nl: "-",
326
+ nn: ".",
327
+ no: ".",
328
+ pl: ".",
329
+ ro: ".",
330
+ ru: ".",
331
+ sk: ".",
332
+ sl: ".",
333
+ sr: ".",
334
+ tr: ".",
335
+ uk: ".",
336
+ zh: "/",
337
+ };
338
+ /** Full-tag overrides — Finland-Swedish writes 14.8.2026 with dots. */
339
+ const SEPARATOR_BY_TAG = {
340
+ "sv-fi": ".",
341
+ };
342
+ /**
343
+ * Split a BCP-47 tag into a lowercase language subtag and, when present, a
344
+ * two-letter region subtag. Script and variant subtags are ignored.
345
+ */
346
+ function parseTag(locale) {
347
+ const tag = (locale || "").toLowerCase().replace(/_/g, "-");
348
+ const parts = tag.split("-").filter(Boolean);
349
+ const language = parts[0] || "";
350
+ const region = parts.slice(1).find((part) => /^[a-z]{2}$/.test(part));
351
+ return { language, region };
352
+ }
353
+ /**
354
+ * Resolve the segment order for a locale. Falls back to day-month-year, which
355
+ * is what most of the world writes.
356
+ */
357
+ function getDateOrder(locale) {
358
+ const { language, region } = parseTag(locale);
359
+ if (region && MONTH_FIRST_REGIONS.has(region)) {
360
+ return ["month", "day", "year"];
361
+ }
362
+ if (region && DAY_FIRST_TAGS.has(`${language}-${region}`)) {
363
+ return ["day", "month", "year"];
364
+ }
365
+ if (YEAR_FIRST_LANGUAGES.has(language)) {
366
+ return ["year", "month", "day"];
367
+ }
368
+ // A bare "en" carries no region — treat it the way Intl does and assume
369
+ // en-US. Regional English (en-gb, en-au, …) falls through to day-first.
370
+ if (language === "en" && !region) {
371
+ return ["month", "day", "year"];
372
+ }
373
+ return ["day", "month", "year"];
374
+ }
375
+ /**
376
+ * Parse an explicit format string from the component config, e.g.
377
+ * "DD/MM/YYYY" or "YYYY-MM-DD". Returns null when the string does not name
378
+ * all three segments.
379
+ */
380
+ function parseFormat(format) {
381
+ const matches = format.match(/y+|m+|d+/gi);
382
+ if (!matches)
383
+ return null;
384
+ const order = [];
385
+ const tokens = { ...DEFAULT_TOKENS };
386
+ for (const match of matches) {
387
+ const initial = match[0].toLowerCase();
388
+ const segment = initial === "y" ? "year" : initial === "m" ? "month" : "day";
389
+ if (order.includes(segment))
390
+ continue;
391
+ order.push(segment);
392
+ // A "YY" format still collects a four-digit year — the segment holds four
393
+ // characters and `toIsoDate` rejects anything shorter, with a two-digit
394
+ // entry expanded on blur. Showing "YY" as the placeholder would promise an
395
+ // input the field does not accept, so short year tokens are widened.
396
+ tokens[segment] =
397
+ segment === "year" && match.length < 4 ? DEFAULT_TOKENS.year : match;
398
+ }
399
+ if (order.length !== 3)
400
+ return null;
401
+ const separator = format.match(/[^a-z\s]/i)?.[0] ?? "/";
402
+ return { order, tokens, separator };
403
+ }
404
+ /**
405
+ * Resolve the full layout for a DATE field. An explicit `config.format` wins;
406
+ * otherwise the locale decides the order.
407
+ */
408
+ function getDateLayout(format, locale) {
409
+ if (format) {
410
+ const parsed = parseFormat(format);
411
+ if (parsed)
412
+ return parsed;
413
+ }
414
+ const { language, region } = parseTag(locale);
415
+ const order = getDateOrder(locale);
416
+ const separator = (region ? SEPARATOR_BY_TAG[`${language}-${region}`] : undefined) ??
417
+ SEPARATOR_BY_LANGUAGE[language] ??
418
+ (order[0] === "year" ? "-" : "/");
419
+ return {
420
+ order,
421
+ tokens: TOKENS_BY_LANGUAGE[language] ?? DEFAULT_TOKENS,
422
+ separator,
423
+ };
424
+ }
425
+ /** Number of days in a given month, honouring leap years. */
426
+ function daysInMonth(year, month) {
427
+ if (month < 1 || month > 12)
428
+ return 0;
429
+ return new Date(Date.UTC(year, month, 0)).getUTCDate();
430
+ }
431
+ /** Split an ISO "YYYY-MM-DD" value into its segments. */
432
+ function parseIsoDate(value) {
433
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec((value || "").trim());
434
+ if (!match)
435
+ return null;
436
+ return { year: match[1], month: match[2], day: match[3] };
437
+ }
438
+ /**
439
+ * Build an ISO "YYYY-MM-DD" string from segment values. Returns "" unless all
440
+ * three segments are complete and form a real calendar date — a half-filled or
441
+ * impossible date (31 February) is not a value worth submitting.
442
+ */
443
+ function toIsoDate(segments) {
444
+ const { year, month, day } = segments;
445
+ if (year.length !== 4 || month.length === 0 || day.length === 0)
446
+ return "";
447
+ const y = Number(year);
448
+ const m = Number(month);
449
+ const d = Number(day);
450
+ if (!Number.isInteger(y) || !Number.isInteger(m) || !Number.isInteger(d)) {
451
+ return "";
452
+ }
453
+ if (m < 1 || m > 12)
454
+ return "";
455
+ if (d < 1 || d > daysInMonth(y, m))
456
+ return "";
457
+ return `${String(y).padStart(4, "0")}-${String(m).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
458
+ }
459
+ /**
460
+ * Expand a two-digit year into the most recent matching year at or before
461
+ * `anchorYear` — "85" becomes 1985, "05" becomes 2005. Anything that is not
462
+ * exactly two digits is returned unchanged, so a fully typed year is never
463
+ * second-guessed.
464
+ */
465
+ function expandTwoDigitYear(year, anchorYear) {
466
+ if (!/^\d{2}$/.test(year))
467
+ return year;
468
+ const century = Math.floor(anchorYear / 100) * 100;
469
+ const candidate = century + Number(year);
470
+ return String(candidate > anchorYear ? candidate - 100 : candidate);
471
+ }
472
+ /**
473
+ * The latest year a two-digit entry may expand to. `config.max` pins it when
474
+ * the field has an upper bound; otherwise we assume a date in the past (the
475
+ * birthdate case) and anchor on the current year.
476
+ */
477
+ function resolveYearAnchor(max, today) {
478
+ const parsed = parseIsoDate(max);
479
+ if (parsed)
480
+ return Number(parsed.year);
481
+ return today.getUTCFullYear();
482
+ }
483
+
484
+ const authheroNodeCss = () => `:host{display:block}.input-wrapper{display:flex;flex-direction:column;position:relative;margin-top:8px;margin-bottom:16px}.input-container{position:relative;width:100%}.input-label{position:absolute;left:16px;top:50%;transform:translateY(-50%);font-size:var(--ah-font-size-label, 16px);font-weight:var(--ah-font-weight-label, 400);color:var(--ah-color-text-muted, #65676e);pointer-events:none;transition:all 0.15s ease-out;background-color:transparent;padding:0;z-index:1}.input-label.floating,.input-field:focus+.input-label,.input-field:not(:placeholder-shown)+.input-label,select.input-field+.input-label,input[type="date"].input-field+.input-label{top:-8px;transform:translateY(0);font-size:12px;background-color:var(--ah-color-bg, #ffffff);padding:0 4px;left:12px;color:var(--ah-color-text-muted, #65676e)}.input-field:focus+.input-label{color:var(--ah-color-primary, #635dff)}.required{color:var(--ah-color-error, #d03c38);margin-left:2px}.input-field{width:100%;padding:16px;font-size:16px;font-family:inherit;color:var(--ah-color-input-text, var(--ah-color-text, #1e212a));background-color:var(--ah-color-input-bg, #ffffff);border:var(--ah-input-border-width, 1px) solid var(--ah-color-border, #c9cace);border-radius:var(--ah-input-radius, 3px);outline:none;transition:border-color 0.15s ease-out, box-shadow 0.15s ease-out;box-sizing:border-box}.input-field::placeholder{color:transparent}.input-field:hover{border-color:var(--ah-color-border-hover, #65676e)}.input-field:focus{border-color:var(--ah-color-primary, #635dff);box-shadow:inset 0 0 0 1px var(--ah-color-primary, #635dff)}.input-field.has-error{border-color:var(--ah-color-error, #d03c38)}.input-field.has-error:focus{box-shadow:inset 0 0 0 1px var(--ah-color-error, #d03c38)}.input-field:disabled{background-color:var(--ah-color-bg-disabled, #f5f5f5);border-color:var(--ah-color-border-disabled, #e0e1e3);cursor:not-allowed;opacity:0.7}.password-container{position:relative;display:flex;align-items:center}.password-container .input-field{padding-right:48px}.password-toggle{position:absolute;right:12px;top:50%;transform:translateY(-50%);background:none;border:none;cursor:pointer;padding:4px;display:flex;align-items:center;justify-content:center;color:var(--ah-color-icon, var(--ah-color-text-muted, #65676e));transition:color 0.15s ease}.password-toggle:hover{color:var(--ah-color-icon, var(--ah-color-text, #1e212a))}.password-toggle svg{width:20px;height:20px}.error-text{font-size:12px;color:var(--ah-color-error, #d03c38);margin-top:4px;line-height:1.4}.helper-text{font-size:12px;color:var(--ah-color-text-muted, #65676e);margin-top:4px;line-height:1.4}.field-link{display:block;text-align:left;margin-top:8px;margin-bottom:16px}.field-link a{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none);font-size:var(--ah-font-size-link, 14px);font-weight:var(--ah-font-weight-link, 400)}.field-link a:hover{text-decoration:underline}.checkbox-wrapper{display:flex;align-items:flex-start;gap:10px;cursor:pointer;margin-bottom:16px}.checkbox-wrapper input[type="checkbox"]{width:18px;height:18px;margin:0;accent-color:var(--ah-color-primary, #635dff);cursor:pointer;flex-shrink:0}.checkbox-label{font-size:var(--ah-font-size-body, 14px);font-weight:var(--ah-font-weight-body, 400);color:var(--ah-color-text, #1e212a);line-height:1.5}.btn{display:inline-flex;align-items:center;justify-content:center;gap:10px;width:100%;padding:14px 20px;font-size:var(--ah-font-size-btn, 16px);font-weight:var(--ah-font-weight-btn, 400);font-family:inherit;line-height:1.25;text-align:center;text-decoration:none;border:none;border-radius:var(--ah-btn-radius, 3px);cursor:pointer;transition:background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;box-sizing:border-box}.btn:disabled{opacity:0.6;cursor:not-allowed}.btn:not(:disabled):active{transform:scale(0.98)}.btn:focus-visible{outline:2px solid var(--ah-color-focus-ring, var(--ah-color-primary, #635dff));outline-offset:2px}.btn-primary{background-color:var(--ah-color-primary, #635dff);color:var(--ah-color-text-on-primary, #ffffff);margin-top:12px}.btn-primary:not(:disabled):hover{background-color:var( --ah-color-primary-hover, color-mix(in srgb, var(--ah-color-primary, #635dff) 85%, black) )}.btn-secondary{background-color:var(--ah-color-bg, #ffffff);color:var(--ah-btn-secondary-text, var(--ah-color-text, #1e212a));border:var(--ah-btn-border-width, 1px) solid var(--ah-btn-secondary-border, var(--ah-color-border, #c9cace))}.btn-secondary:not(:disabled):hover{background-color:var(--ah-color-bg-hover, #f5f5f5);border-color:var(--ah-color-border-hover, #65676e)}.btn-link{background:none;border:none;color:var(--ah-color-link, #635dff);padding:8px 0;font-weight:var(--ah-font-weight-link, 400);text-decoration:none}.btn-link:hover{text-decoration:underline}.phone-input-wrapper{display:flex;align-items:stretch;gap:0;width:100%}.country-select{flex-shrink:0;width:auto;padding:12px 8px;font-size:var(--ah-font-size-body, 16px);font-family:var(--ah-font-family, inherit);border:var(--ah-input-border-width, 1px) solid var(--ah-color-border, #c9cace);border-right:none;border-radius:var(--ah-input-radius, 4px) 0 0 var(--ah-input-radius, 4px);background-color:var(--ah-color-input-bg, var(--ah-color-surface, #fff));color:var(--ah-color-input-text, var(--ah-color-text, #1e212a));cursor:pointer;appearance:none;-webkit-appearance:none;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 6px center;padding-right:22px}.country-select:focus{outline:none;border-color:var(--ah-color-primary, #635dff);box-shadow:0 0 0 1px var(--ah-color-primary, #635dff)}.country-select:disabled{opacity:0.5;cursor:not-allowed}.phone-input-wrapper .input-container{flex:1;min-width:0}.phone-input-wrapper .input-field{border-radius:0 var(--ah-input-radius, 4px) var(--ah-input-radius, 4px) 0}.phone-input-wrapper .input-label.floating,.phone-input-wrapper .input-field:focus+.input-label,.phone-input-wrapper .input-field:not(:placeholder-shown)+.input-label{left:8px}.date-input{display:flex;align-items:center;width:100%;padding:16px;box-sizing:border-box;background-color:var(--ah-color-input-bg, #ffffff);border:var(--ah-input-border-width, 1px) solid var(--ah-color-border, #c9cace);border-radius:var(--ah-input-radius, 3px);transition:border-color 0.15s ease-out, box-shadow 0.15s ease-out}.date-input:hover{border-color:var(--ah-color-border-hover, #65676e)}.date-input:focus-within{border-color:var(--ah-color-primary, #635dff);box-shadow:inset 0 0 0 1px var(--ah-color-primary, #635dff)}.date-input.has-error{border-color:var(--ah-color-error, #d03c38)}.date-input.has-error:focus-within{box-shadow:inset 0 0 0 1px var(--ah-color-error, #d03c38)}@media (forced-colors: active){.date-input:focus-within,.date-input.has-error:focus-within{outline:2px solid Highlight;outline-offset:1px}}.date-segment{width:3.25ch;min-width:0;padding:0;font-size:16px;font-family:inherit;text-align:center;color:var(--ah-color-input-text, var(--ah-color-text, #1e212a));background:transparent;border:none;outline:none}.date-segment[data-date-segment="year"]{width:5.5ch}.date-segment::placeholder{color:var(--ah-color-text-muted, #65676e);opacity:1}.date-segment:disabled{color:var(--ah-color-text-disabled, #a0a0a0);cursor:not-allowed}.date-input:has(.date-segment:disabled){background-color:var(--ah-color-bg-disabled, #f5f5f5)}.date-separator{padding:0 4px;font-size:16px;color:var(--ah-color-text-muted, #65676e);user-select:none}.social-buttons{display:flex;flex-direction:column;gap:12px}.btn-social{display:flex;align-items:center;justify-content:center;gap:12px;position:relative}.btn-social-badge{position:absolute;right:12px;top:0;transform:translateY(-50%);font-size:11px;font-weight:500;line-height:1;padding:4px 9px;border-radius:999px;background:var(--ah-color-last-used, var(--ah-color-primary, #635dff));color:var(--ah-color-last-used-text, var(--ah-color-text-on-primary, #fff));white-space:nowrap;pointer-events:none}.btn-social.btn-social-last-used{border-color:var(--ah-color-last-used, var(--ah-color-primary, #635dff));box-shadow:inset 0 0 0 1px var(--ah-color-last-used, var(--ah-color-primary, #635dff))}.input-badge{position:absolute;right:12px;top:0;transform:translateY(-50%);font-size:11px;font-weight:500;line-height:1;padding:4px 9px;border-radius:999px;background:var(--ah-color-last-used, var(--ah-color-primary, #635dff));color:var(--ah-color-last-used-text, var(--ah-color-text-on-primary, #fff));white-space:nowrap;pointer-events:none;z-index:2}.btn-social-content{display:flex;flex-direction:column;align-items:center;text-align:center}.btn-social-subtitle{font-size:12px;font-style:italic;opacity:0.8;margin-top:2px}.btn-social-subtitle:empty{display:none}.social-icon{width:20px;height:20px;flex-shrink:0}@media (max-width: 480px){.social-buttons:has(.btn-social:nth-child(3)){flex-direction:row;flex-wrap:nowrap;justify-content:stretch;gap:8px}.social-buttons:has(.btn-social:nth-child(3)) .btn-social{width:auto;min-width:0;padding:12px;flex:1 1 0}.social-buttons:has(.btn-social:nth-child(3)) .btn-social span{display:none}.social-buttons:has(.btn-social:nth-child(3)) .social-icon{width:24px;height:24px}}.btn-icon{width:20px;height:20px;flex-shrink:0}.btn-icon img{width:100%;height:100%;object-fit:contain}.text-title{font-size:var(--ah-font-size-title, 20px);font-weight:var(--ah-font-weight-title, 400);color:var(--ah-color-text-header, var(--ah-color-header, #1e212a));margin:8px 0;line-height:1.3}.text-title.text-success{color:var(--ah-color-success, #13a769)}.text-description{font-size:var(--ah-font-size-subtitle, 14px);font-weight:var(--ah-font-weight-subtitle, 400);color:var(--ah-color-text-muted, #65676e);margin:4px 0;line-height:1.5}.image{display:block;max-width:100%;height:auto;border-radius:4px}.image-centered{margin:0 auto 16px;width:52px;height:52px;object-fit:contain}.link{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none);font-size:var(--ah-font-size-link, 14px);transition:color 0.15s ease}.link:hover{text-decoration:underline}.link:focus-visible{outline:2px solid var(--ah-color-focus-ring, var(--ah-color-link, #635dff));outline-offset:2px;border-radius:2px}.node-error{padding:12px 16px;background-color:var(--ah-color-error-bg, #ffeaea);color:var(--ah-color-error, #d03c38);border-left:3px solid var(--ah-color-error, #d03c38);border-radius:0;font-size:14px;margin-bottom:16px}.node-success{padding:12px 16px;background-color:var(--ah-color-success-bg, #e6f9f1);color:var(--ah-color-success, #13a769);border-left:3px solid var(--ah-color-success, #13a769);border-radius:0;font-size:14px;margin-bottom:16px}.divider{display:flex;align-items:center;text-align:center;margin:16px 0}.divider::before,.divider::after{content:"";flex:1;border-bottom:1px solid var(--ah-color-border-muted, #c9cace)}.divider-text{padding:0 10px;font-size:12px;font-weight:400;color:var(--ah-color-text-muted, #65676e);text-transform:uppercase;letter-spacing:0.5px}.rich-text{font-size:var(--ah-font-size-body, 14px);font-weight:var(--ah-font-weight-body, 400);line-height:1.5;color:var(--ah-color-text, #1e212a)}.rich-text a{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none);transition:color 0.15s ease}.rich-text a:hover{text-decoration:underline}.rich-text .terms-text{margin-top:16px;text-align:center;font-size:12px;color:var(--ah-color-text-muted, #65676e)}.rich-text .terms-text a{font-size:12px}.rich-text .forgot-password-link{text-align:right;font-size:13px;margin-top:4px}.rich-text .forgot-password-link a{font-size:13px;color:var(--ah-color-link, #635dff)}.rich-text .passwordless-link{margin-top:16px;text-align:center;font-size:14px}.rich-text .passwordless-link a{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none)}.rich-text .passwordless-link a:hover{text-decoration:underline}.rich-text .signup-link{margin-top:16px;text-align:center;font-size:14px;color:var(--ah-color-text, #1e212a)}.code-field{position:relative}.code-input{position:absolute;inset:0;width:100%;height:100%;margin:0;padding:0;border:none;background:transparent;color:transparent;caret-color:transparent;font-family:inherit;letter-spacing:0;outline:none;cursor:text;-webkit-text-fill-color:transparent}.code-boxes{display:flex;align-items:center;gap:var(--ah-code-group-gap, 12px);justify-content:center}.code-group{display:flex;gap:0}.code-separator{color:var(--ah-color-text-muted, #65676e);font-size:var(--ah-code-font-size, 24px);user-select:none}.code-box-placeholder{color:var(--ah-color-text-muted, #65676e);opacity:0.4}.code-box{position:relative;flex:0 0 auto;width:var(--ah-code-box-width, 48px);height:var(--ah-code-box-height, 56px);display:flex;align-items:center;justify-content:center;font-size:var(--ah-code-font-size, 24px);font-family:inherit;color:var(--ah-color-input-text, var(--ah-color-text, #1e212a));background-color:var(--ah-color-input-bg, #ffffff);border:var(--ah-input-border-width, 1px) solid var(--ah-color-border, #c9cace);border-radius:0;transition:border-color 0.15s ease-out, box-shadow 0.15s ease-out;box-sizing:border-box}.code-box+.code-box{margin-left:calc(-1 * var(--ah-input-border-width, 1px))}.code-group .code-box:first-child{border-top-left-radius:var(--ah-input-radius, 3px);border-bottom-left-radius:var(--ah-input-radius, 3px)}.code-group .code-box:last-child{border-top-right-radius:var(--ah-input-radius, 3px);border-bottom-right-radius:var(--ah-input-radius, 3px)}.code-field:focus-within .code-box.is-active{z-index:1;border-color:var(--ah-color-primary, #635dff);box-shadow:inset 0 0 0 1px var(--ah-color-primary, #635dff)}.code-field.has-error .code-box{border-color:var(--ah-color-error, #d03c38)}.code-input:disabled{cursor:not-allowed}.code-input:disabled~.code-boxes .code-box{background-color:var(--ah-color-bg-disabled, #f5f5f5);border-color:var(--ah-color-border-disabled, #e0e1e3)}`;
240
485
 
241
486
  const AuthheroNode = class {
242
487
  constructor(hostRef) {
@@ -254,6 +499,12 @@ const AuthheroNode = class {
254
499
  * Whether the component is disabled.
255
500
  */
256
501
  disabled = false;
502
+ /**
503
+ * BCP-47 locale used for locale-dependent field layout (currently the
504
+ * segment order of DATE fields). Resolved server-side so SSR and hydration
505
+ * agree; falls back to day-month-year when absent.
506
+ */
507
+ locale;
257
508
  /**
258
509
  * Whether the password field is visible.
259
510
  */
@@ -275,6 +526,15 @@ const AuthheroNode = class {
275
526
  * When true, the value is emitted as-is without dial code prefix.
276
527
  */
277
528
  telEmailMode = false;
529
+ /**
530
+ * Segment values for the DATE input, each held as typed (unpadded while the
531
+ * user is mid-entry) and normalised on blur.
532
+ */
533
+ dateSegments = {
534
+ year: "",
535
+ month: "",
536
+ day: "",
537
+ };
278
538
  /**
279
539
  * Emitted when a field value changes.
280
540
  */
@@ -286,13 +546,16 @@ const AuthheroNode = class {
286
546
  componentChanged() {
287
547
  this.initCountryFromConfig();
288
548
  this.initTelValue();
549
+ this.initDateValue();
289
550
  }
290
551
  valueChanged() {
291
552
  this.initTelValue();
553
+ this.initDateValue();
292
554
  }
293
555
  componentWillLoad() {
294
556
  this.initCountryFromConfig();
295
557
  this.initTelValue();
558
+ this.initDateValue();
296
559
  }
297
560
  componentDidLoad() {
298
561
  // Auto-focus a code field so the caret starts in the first (leftmost) box.
@@ -318,6 +581,20 @@ const AuthheroNode = class {
318
581
  }
319
582
  }
320
583
  }
584
+ /**
585
+ * The last value this field emitted for a TEL component. The widget mirrors
586
+ * every emitted value back onto the `value` prop, and that echo must not be
587
+ * re-parsed: the wire format carries only a dial code, so a country picked
588
+ * from the list would be replaced by the first entry sharing that code — a
589
+ * user who chose Canada would be silently moved to the US on their next
590
+ * keystroke.
591
+ */
592
+ lastEmittedTel;
593
+ /** Emit a TEL value and remember it, so the echo can be recognised. */
594
+ emitTelValue(value) {
595
+ this.lastEmittedTel = value;
596
+ this.fieldChange.emit({ id: this.component.id, value });
597
+ }
321
598
  /**
322
599
  * Hydrate localPhoneNumber (and selectedCountry) from the effective value
323
600
  * for TEL fields. The full value is stored as `{dialCode}{localNumber}`,
@@ -326,6 +603,10 @@ const AuthheroNode = class {
326
603
  initTelValue() {
327
604
  if (this.component?.type !== "TEL")
328
605
  return;
606
+ if (this.lastEmittedTel !== undefined &&
607
+ this.getEffectiveValue() === this.lastEmittedTel) {
608
+ return;
609
+ }
329
610
  const config = this.component.config;
330
611
  const allowEmail = config?.allow_email === true;
331
612
  const fullValue = this.getEffectiveValue();
@@ -360,11 +641,16 @@ const AuthheroNode = class {
360
641
  handleCountryChange = (e) => {
361
642
  const target = e.target;
362
643
  this.selectedCountry = getCountryByCode(target.value);
644
+ // A half-typed "+xx" prefix is replaced by the picked country, not kept
645
+ // as a local number (it would emit "+46+4").
646
+ if (this.localPhoneNumber.startsWith("+")) {
647
+ this.localPhoneNumber = "";
648
+ }
363
649
  // Re-emit the full phone number with new dial code
364
650
  const fullNumber = this.localPhoneNumber
365
651
  ? `${this.selectedCountry.dialCode}${this.localPhoneNumber}`
366
652
  : "";
367
- this.fieldChange.emit({ id: this.component.id, value: fullNumber });
653
+ this.emitTelValue(fullNumber);
368
654
  };
369
655
  /**
370
656
  * Try to detect a dial code prefix in the raw input (e.g. "+46", "0046")
@@ -402,7 +688,21 @@ const AuthheroNode = class {
402
688
  target.value = cleanedLocal;
403
689
  this.localPhoneNumber = cleanedLocal;
404
690
  const fullNumber = `${this.selectedCountry.dialCode}${cleanedLocal}`;
405
- this.fieldChange.emit({ id: this.component.id, value: fullNumber });
691
+ this.emitTelValue(fullNumber);
692
+ }
693
+ else if (value.startsWith("+")) {
694
+ // A leading "+" is an international prefix the user is still typing.
695
+ // Keep it in the field so the dial code can build up until it matches
696
+ // a country — stripping it per keystroke means "+46" never resolves to
697
+ // Sweden, since each character is discarded before the next arrives.
698
+ const cleaned = `+${value.slice(1).replace(/[^\d\s\-()]/g, "")}`;
699
+ if (cleaned !== value) {
700
+ target.value = cleaned;
701
+ }
702
+ this.localPhoneNumber = cleaned;
703
+ // Emit the partial prefix as-is; prefixing it with the (not yet chosen)
704
+ // country's dial code would produce nonsense like "+1+4".
705
+ this.emitTelValue(cleaned);
406
706
  }
407
707
  else {
408
708
  const cleaned = allowPlus
@@ -415,7 +715,7 @@ const AuthheroNode = class {
415
715
  const fullNumber = cleaned
416
716
  ? `${this.selectedCountry.dialCode}${cleaned}`
417
717
  : "";
418
- this.fieldChange.emit({ id: this.component.id, value: fullNumber });
718
+ this.emitTelValue(fullNumber);
419
719
  }
420
720
  }
421
721
  handlePhoneInput = (e) => {
@@ -435,7 +735,7 @@ const AuthheroNode = class {
435
735
  else {
436
736
  // Email or text — emit as-is
437
737
  this.localPhoneNumber = value;
438
- this.fieldChange.emit({ id: this.component.id, value });
738
+ this.emitTelValue(value);
439
739
  }
440
740
  return;
441
741
  }
@@ -446,6 +746,196 @@ const AuthheroNode = class {
446
746
  const target = e.target;
447
747
  this.fieldChange.emit({ id: this.component.id, value: target.value });
448
748
  };
749
+ // ===========================================================================
750
+ // DATE segment handling
751
+ // ===========================================================================
752
+ /**
753
+ * The last ISO value this field emitted. The widget mirrors every emitted
754
+ * value back onto the `value` prop, and that echo must not be treated as an
755
+ * external change: it would re-format the segments under the caret while
756
+ * the user is still typing (a day of "3" comes back as "03", swallowing the
757
+ * next digit).
758
+ */
759
+ lastEmittedDate;
760
+ /** Hydrate the day/month/year segments from the effective ISO value. */
761
+ initDateValue() {
762
+ if (this.component?.type !== "DATE")
763
+ return;
764
+ if (this.lastEmittedDate !== undefined &&
765
+ this.getEffectiveValue() === this.lastEmittedDate) {
766
+ return;
767
+ }
768
+ const parsed = parseIsoDate(this.getEffectiveValue());
769
+ if (parsed) {
770
+ this.dateSegments = parsed;
771
+ return;
772
+ }
773
+ // No parseable value. Only clear when we currently hold a complete date,
774
+ // i.e. this is a genuine external reset: a half-typed date emits "" and
775
+ // the parent echoes that straight back as the value prop, which would
776
+ // otherwise wipe the segment the user just typed into.
777
+ if (toIsoDate(this.dateSegments) !== "") {
778
+ this.dateSegments = { year: "", month: "", day: "" };
779
+ }
780
+ }
781
+ dateConfig() {
782
+ return this.component.config;
783
+ }
784
+ getDateLayoutForField() {
785
+ const config = this.dateConfig();
786
+ return getDateLayout(config?.format, this.locale);
787
+ }
788
+ static SEGMENT_LENGTH = {
789
+ day: 2,
790
+ month: 2,
791
+ year: 4,
792
+ };
793
+ /** Birthdate autofill tokens — the common case for a typed date. */
794
+ static SEGMENT_AUTOCOMPLETE = {
795
+ day: "bday-day",
796
+ month: "bday-month",
797
+ year: "bday-year",
798
+ };
799
+ /**
800
+ * The submittable value for the current segments: an ISO date, or "" when
801
+ * it is incomplete, impossible, or outside the field's `min`/`max`. ISO
802
+ * strings compare chronologically, so the bounds need no parsing.
803
+ */
804
+ dateIsoValue(segments) {
805
+ const iso = toIsoDate(segments);
806
+ if (!iso)
807
+ return "";
808
+ const config = this.dateConfig();
809
+ const min = config?.min;
810
+ const max = config?.max;
811
+ if (typeof min === "string" && parseIsoDate(min) && iso < min)
812
+ return "";
813
+ if (typeof max === "string" && parseIsoDate(max) && iso > max)
814
+ return "";
815
+ return iso;
816
+ }
817
+ setDateSegments(segments) {
818
+ this.dateSegments = segments;
819
+ this.lastEmittedDate = this.dateIsoValue(segments);
820
+ this.fieldChange.emit({
821
+ id: this.component.id,
822
+ value: this.lastEmittedDate,
823
+ });
824
+ }
825
+ focusDateSegment(segment) {
826
+ const input = this.host.shadowRoot?.querySelector(`input[data-date-segment="${segment}"]`);
827
+ input?.focus();
828
+ input?.select();
829
+ }
830
+ /**
831
+ * Whether typing this digit completes the segment. A segment is complete at
832
+ * its full width, and also as soon as a further digit could not produce a
833
+ * valid number — no day starts with 4 and no month starts with 2.
834
+ */
835
+ isDateSegmentComplete(segment, value) {
836
+ if (value.length >= AuthheroNode.SEGMENT_LENGTH[segment])
837
+ return true;
838
+ if (value.length !== 1)
839
+ return false;
840
+ if (segment === "day")
841
+ return Number(value) > 3;
842
+ if (segment === "month")
843
+ return Number(value) > 1;
844
+ return false;
845
+ }
846
+ handleDateSegmentInput = (segment) => (e) => {
847
+ const target = e.target;
848
+ const digits = target.value
849
+ .replace(/\D/g, "")
850
+ .slice(0, AuthheroNode.SEGMENT_LENGTH[segment]);
851
+ if (digits !== target.value) {
852
+ target.value = digits;
853
+ }
854
+ this.setDateSegments({ ...this.dateSegments, [segment]: digits });
855
+ if (this.isDateSegmentComplete(segment, digits)) {
856
+ const order = this.getDateLayoutForField().order;
857
+ const next = order[order.indexOf(segment) + 1];
858
+ if (next)
859
+ this.focusDateSegment(next);
860
+ }
861
+ };
862
+ /**
863
+ * Pad a single digit ("5" -> "05") and expand a two-digit year against the
864
+ * field's upper bound ("85" -> 1985). Shared by blur and paste so a pasted
865
+ * date is read the same way as a typed one.
866
+ */
867
+ normalizeDateSegment(segment, value) {
868
+ if (segment !== "year")
869
+ return value.padStart(2, "0");
870
+ return expandTwoDigitYear(value, resolveYearAnchor(this.dateConfig()?.max, new Date()));
871
+ }
872
+ /**
873
+ * Normalise on blur: pad a single digit ("5" -> "05") and expand a two-digit
874
+ * year against the field's upper bound ("85" -> 1985).
875
+ */
876
+ handleDateSegmentBlur = (segment) => (e) => {
877
+ const target = e.target;
878
+ const value = target.value.replace(/\D/g, "");
879
+ if (!value)
880
+ return;
881
+ const normalized = this.normalizeDateSegment(segment, value);
882
+ if (normalized === value)
883
+ return;
884
+ target.value = normalized;
885
+ this.setDateSegments({ ...this.dateSegments, [segment]: normalized });
886
+ };
887
+ /**
888
+ * Backspace at the start of an empty segment moves to the previous one, so
889
+ * the whole date can be cleared without reaching for the mouse.
890
+ */
891
+ handleDateSegmentKeyDown = (segment) => (e) => {
892
+ if (e.key === "Enter") {
893
+ e.preventDefault();
894
+ this.buttonClick.emit({ id: "submit", type: "submit", value: "next" });
895
+ return;
896
+ }
897
+ if (e.key !== "Backspace")
898
+ return;
899
+ const target = e.target;
900
+ if (target.value.length > 0 || target.selectionStart !== 0)
901
+ return;
902
+ const order = this.getDateLayoutForField().order;
903
+ const previous = order[order.indexOf(segment) - 1];
904
+ if (previous) {
905
+ e.preventDefault();
906
+ this.focusDateSegment(previous);
907
+ }
908
+ };
909
+ /**
910
+ * Pasting a whole date into any segment fills all three. An ISO value is
911
+ * read year-first; anything else follows the field's displayed order. A
912
+ * two-digit year is expanded the same way a typed one is, so "15/03/85"
913
+ * pastes as 1985 rather than falling through to the browser's own paste.
914
+ */
915
+ handleDatePaste = (e) => {
916
+ const text = e.clipboardData?.getData("text") ?? "";
917
+ const groups = text.match(/\d+/g);
918
+ if (!groups || groups.length < 3)
919
+ return;
920
+ const [first, second, third] = groups;
921
+ const isoLike = first.length === 4;
922
+ const order = isoLike
923
+ ? ["year", "month", "day"]
924
+ : this.getDateLayoutForField().order;
925
+ const segments = {
926
+ year: "",
927
+ month: "",
928
+ day: "",
929
+ };
930
+ [first, second, third].forEach((group, index) => {
931
+ const segment = order[index];
932
+ segments[segment] = this.normalizeDateSegment(segment, group.slice(0, AuthheroNode.SEGMENT_LENGTH[segment]));
933
+ });
934
+ if (!toIsoDate(segments))
935
+ return;
936
+ e.preventDefault();
937
+ this.setDateSegments(segments);
938
+ };
449
939
  handleKeyDown = (e) => {
450
940
  if (e.key === "Enter") {
451
941
  e.preventDefault();
@@ -458,7 +948,7 @@ const AuthheroNode = class {
458
948
  if (config?.allow_email === true && target.value.length === 0) {
459
949
  this.telEmailMode = true;
460
950
  this.localPhoneNumber = "";
461
- this.fieldChange.emit({ id: this.component.id, value: "" });
951
+ this.emitTelValue("");
462
952
  }
463
953
  }
464
954
  };
@@ -733,17 +1223,40 @@ const AuthheroNode = class {
733
1223
  const effectiveValue = this.getEffectiveValue();
734
1224
  return (h("div", { class: "input-wrapper", part: "input-wrapper" }, this.renderLabel(component.label, inputId, component.required), h("input", { id: inputId, class: this.getInputFieldClass(errors.length > 0), part: "input", type: "url", name: component.id, value: effectiveValue ?? "", placeholder: component.config?.placeholder, required: component.required, disabled: this.disabled, onInput: this.handleInput, onKeyDown: this.handleKeyDown }), this.renderErrors(), errors.length === 0 && this.renderHint(component.hint)));
735
1225
  }
1226
+ /**
1227
+ * DATE is rendered as three numeric segments rather than `input type=date`.
1228
+ * A native date input renders differently in every browser (Safari adds a
1229
+ * stepper), keeps its dd/mm/yyyy hint visible while half-filled, and asks
1230
+ * for a calendar gesture to reach a year decades back — all wrong for a
1231
+ * date typed from memory, which is what these fields collect.
1232
+ */
736
1233
  renderDateField(component) {
737
- const inputId = `input-${component.id}`;
738
1234
  const errors = this.getErrors();
739
- const { min, max } = component.config ?? {};
740
- // Date fields always have a value (even if placeholder format), so always float the label
741
- const hasValue = true;
742
- const effectiveValue = this.getEffectiveValue();
743
- return (h("div", { class: "input-wrapper", part: "input-wrapper" }, h("div", { class: "input-container" }, h("input", { id: inputId, class: this.getInputFieldClass(errors.length > 0), part: "input", type: "date", name: component.id, "data-input-name": component.id, value: effectiveValue ?? "", placeholder: " ", required: component.required, disabled: this.disabled, min: min, max: max, onInput: this.handleInput, onKeyDown: this.handleKeyDown }), this.renderFloatingLabel(component.label, inputId, component.required, hasValue)), this.renderErrors(), errors.length === 0 && this.renderHint(component.hint)));
1235
+ const { format } = component.config ?? {};
1236
+ const layout = getDateLayout(format, this.locale);
1237
+ const isoValue = this.dateIsoValue(this.dateSegments);
1238
+ // Every segment filled but no ISO value means the date does not exist
1239
+ // (31 February) or falls outside min/max. Flag it rather than silently
1240
+ // submitting nothing — the widget posts JSON, so the browser's own
1241
+ // constraint validation never runs.
1242
+ const isIncomplete = layout.order.some((segment) => this.dateSegments[segment].length === 0);
1243
+ const hasInvalidDate = !isoValue && !isIncomplete;
1244
+ const hasError = errors.length > 0 || hasInvalidDate;
1245
+ const firstInputId = `input-${component.id}`;
1246
+ const segmentInput = (segment) => (h("input", { key: segment, id: segment === layout.order[0] ? firstInputId : undefined, class: "date-segment", part: `input date-segment date-segment-${segment}`, type: "text", inputmode: "numeric", autocomplete: AuthheroNode.SEGMENT_AUTOCOMPLETE[segment], "data-date-segment": segment, maxlength: AuthheroNode.SEGMENT_LENGTH[segment], size: AuthheroNode.SEGMENT_LENGTH[segment], value: this.dateSegments[segment], placeholder: layout.tokens[segment], "aria-label": layout.tokens[segment], "aria-invalid": hasError ? "true" : "false", required: component.required, disabled: this.disabled, onInput: this.handleDateSegmentInput(segment), onBlur: this.handleDateSegmentBlur(segment), onKeyDown: this.handleDateSegmentKeyDown(segment), onPaste: this.handleDatePaste }));
1247
+ return (h("div", { class: "input-wrapper", part: "input-wrapper" }, h("div", { class: "input-container" }, h("div", { class: hasError ? "date-input has-error" : "date-input", part: "date-input", role: "group", "aria-label": component.label }, layout.order.map((segment, index) => [
1248
+ index > 0 && (h("span", { key: `sep-${segment}`, class: "date-separator", part: "date-separator", "aria-hidden": "true" }, layout.separator)),
1249
+ segmentInput(segment),
1250
+ ])), this.renderFloatingLabel(component.label, firstInputId, component.required, true)), h("input", { type: "hidden", name: component.id, "data-input-name": component.id, value: isoValue }), this.renderErrors(), errors.length === 0 && this.renderHint(component.hint)));
744
1251
  }
745
1252
  renderBooleanField(component) {
746
- return (h("label", { class: "checkbox-wrapper", part: "checkbox-wrapper" }, h("input", { type: "checkbox", part: "checkbox", name: component.id, checked: this.value === "true" || component.config?.default_value === true, required: component.required, disabled: this.disabled, onChange: this.handleCheckbox }), h("span", { class: "checkbox-label", part: "checkbox-label" }, component.label)));
1253
+ return (h("label", { class: "checkbox-wrapper", part: "checkbox-wrapper" }, h("input", { type: "checkbox", part: "checkbox", name: component.id, checked:
1254
+ // Once the field has a value it is authoritative — falling back to
1255
+ // the default here would keep a ticked-by-default box ticked after
1256
+ // the user unticks it.
1257
+ this.value === undefined
1258
+ ? component.config?.default_value === true
1259
+ : this.value === "true", required: component.required, disabled: this.disabled, onChange: this.handleCheckbox }), h("span", { class: "checkbox-label", part: "checkbox-label" }, component.label)));
747
1260
  }
748
1261
  renderLegalField(component) {
749
1262
  const text = component.config?.text ?? component.label ?? "";