@wow-two-beta/fe 0.0.38 → 0.0.40

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 (71) hide show
  1. package/dist/formsEngine/AppForm.d.ts +12 -3
  2. package/dist/formsEngine/FormOperations.d.ts +18 -0
  3. package/dist/formsEngine/FormOperations.js +9 -0
  4. package/dist/formsEngine/FormOperations.js.map +1 -1
  5. package/dist/formsEngine/adapters/house/HouseFormCore.js +15 -6
  6. package/dist/formsEngine/adapters/house/HouseFormCore.js.map +1 -1
  7. package/dist/formsEngine/adapters/tanstack/TanstackFormOverlay.d.ts +4 -0
  8. package/dist/formsEngine/adapters/tanstack/TanstackFormOverlay.js +10 -1
  9. package/dist/formsEngine/adapters/tanstack/TanstackFormOverlay.js.map +1 -1
  10. package/dist/formsEngine/adapters/tanstack/UseAppForm.js +9 -6
  11. package/dist/formsEngine/adapters/tanstack/UseAppForm.js.map +1 -1
  12. package/dist/foundation/animation/animatedLayout/AnimatedLayout.d.ts +3 -3
  13. package/dist/foundation/dom/FocusTarget.d.ts +13 -0
  14. package/dist/foundation/dom/FocusTarget.js +12 -0
  15. package/dist/foundation/dom/FocusTarget.js.map +1 -0
  16. package/dist/foundation/dom/index.d.ts +1 -0
  17. package/dist/foundation/dom/index.js +3 -0
  18. package/dist/foundation/dom/index.js.map +1 -1
  19. package/dist/foundation/phone/PhoneCountries.d.ts +13 -0
  20. package/dist/foundation/phone/PhoneCountries.js +62 -0
  21. package/dist/foundation/phone/PhoneCountries.js.map +1 -0
  22. package/dist/foundation/phone/PhoneFormats.d.ts +12 -0
  23. package/dist/foundation/phone/PhoneFormats.js +32 -0
  24. package/dist/foundation/phone/PhoneFormats.js.map +1 -0
  25. package/dist/foundation/phone/PhoneNumberExtensions.d.ts +94 -0
  26. package/dist/foundation/phone/PhoneNumberExtensions.js +137 -0
  27. package/dist/foundation/phone/PhoneNumberExtensions.js.map +1 -0
  28. package/dist/foundation/phone/index.d.ts +3 -0
  29. package/dist/foundation/phone/index.js +9 -0
  30. package/dist/foundation/phone/index.js.map +1 -0
  31. package/dist/foundation/primitives/index.d.ts +1 -0
  32. package/dist/foundation/primitives/index.js +3 -0
  33. package/dist/foundation/primitives/index.js.map +1 -1
  34. package/dist/foundation/primitives/swapTransition/SwapTransition.d.ts +76 -0
  35. package/dist/foundation/primitives/swapTransition/SwapTransition.js +240 -0
  36. package/dist/foundation/primitives/swapTransition/SwapTransition.js.map +1 -0
  37. package/dist/foundation/primitives/swapTransition/index.d.ts +1 -0
  38. package/dist/foundation/validators/Formats.d.ts +15 -0
  39. package/dist/foundation/validators/Formats.js +32 -1
  40. package/dist/foundation/validators/Formats.js.map +1 -1
  41. package/dist/foundation/validators/Messages.d.ts +1 -1
  42. package/dist/foundation/validators/Messages.js +10 -0
  43. package/dist/foundation/validators/Messages.js.map +1 -1
  44. package/dist/foundation/validators/index.d.ts +1 -1
  45. package/dist/foundation/validators/index.js +2 -1
  46. package/dist/index.css +11 -0
  47. package/dist/index.js +2 -1
  48. package/dist/index.js.map +1 -1
  49. package/dist/presentation/actions/refreshButton/RefreshButton.vue.js.map +1 -1
  50. package/dist/presentation/display/animatedNumberText/AnimatedNumberText.vue.d.ts +1 -1
  51. package/dist/presentation/display/carousel/Carousel.vue.d.ts +1 -1
  52. package/dist/presentation/display/countUpText/CountUpText.vue.d.ts +1 -1
  53. package/dist/presentation/display/scrollRevealGroup/ScrollRevealGroup.vue.d.ts +2 -2
  54. package/dist/presentation/forms/field/Field.vue.js +10 -3
  55. package/dist/presentation/forms/field/Field.vue.js.map +1 -1
  56. package/dist/presentation/forms/imageCropEditor/ImageCropEditor.vue.d.ts +1 -1
  57. package/dist/presentation/forms/imageEditor/ImageEditor.vue.d.ts +1 -1
  58. package/dist/presentation/forms/index.js +2 -1
  59. package/dist/presentation/forms/index.js.map +1 -1
  60. package/dist/presentation/forms/labeledField/LabeledField.vue.js +2 -2
  61. package/dist/presentation/forms/labeledField/LabeledField.vue.js.map +1 -1
  62. package/dist/presentation/forms/phoneInput/PhoneInput.vue.d.ts +5 -9
  63. package/dist/presentation/forms/phoneInput/PhoneInput.vue.js +104 -92
  64. package/dist/presentation/forms/phoneInput/PhoneInput.vue.js.map +1 -1
  65. package/dist/presentation/forms/phoneInput/PhoneInput2.vue.js +0 -2
  66. package/dist/presentation/forms/phoneInput/PhoneInput2.vue.js.map +1 -1
  67. package/dist/presentation/forms/phoneInput/index.d.ts +2 -1
  68. package/dist/presentation/layout/navbar/Navbar.vue.js.map +1 -1
  69. package/dist/router/adapters/vueRouter/routeAnnouncer/RouteAnnouncer.vue.js +17 -5
  70. package/dist/router/adapters/vueRouter/routeAnnouncer/RouteAnnouncer.vue.js.map +1 -1
  71. package/package.json +6 -1
@@ -0,0 +1,137 @@
1
+ import { PhoneCountries } from "./PhoneCountries.js";
2
+ import { PhoneFormats } from "./PhoneFormats.js";
3
+ const PhoneNumberExtensions = {
4
+ /** @internal E.164 caps a number, dial code included, at 15 digits. */
5
+ MaxDigits: 15,
6
+ /** @internal The fewest national digits a plan outside `PhoneFormats` accepts — Austria's shortest. */
7
+ MinNationalDigits: 4,
8
+ /** @internal The group size of the fallback mask. */
9
+ GroupSize: 3,
10
+ /** @internal The mask character that takes one digit. */
11
+ DigitSlot: "X",
12
+ /** @internal Every non-digit. */
13
+ NonDigit: /\D/g,
14
+ /** @internal An E.164 value: `+`, then digits, the first not `0`. */
15
+ E164Pattern: /^\+[1-9]\d*$/,
16
+ /** Removes every non-digit. */
17
+ digitsOf(text) {
18
+ return text.replace(PhoneNumberExtensions.NonDigit, "");
19
+ },
20
+ /**
21
+ * Resolves ISO codes to known countries in the order given; unknown and repeated codes are dropped. A list with no
22
+ * known code reads as absent — every country — since a phone control with no country could hold no value.
23
+ */
24
+ resolveCountries(isos) {
25
+ if (!isos) return PhoneCountries;
26
+ const known = [...new Set(isos)].map((iso) => PhoneCountries.find((c) => c.iso === iso)).filter((c) => c !== void 0);
27
+ return known.length > 0 ? known : PhoneCountries;
28
+ },
29
+ /** Resolves the national digits a country accepts: its fixed length, else up to the E.164 cap. */
30
+ lengthOf(country) {
31
+ const format = PhoneFormats[country.iso];
32
+ if (format) return { min: format.length, max: format.length };
33
+ return {
34
+ min: PhoneNumberExtensions.MinNationalDigits,
35
+ max: PhoneNumberExtensions.MaxDigits - PhoneNumberExtensions.digitsOf(country.dial).length
36
+ };
37
+ },
38
+ /** Resolves a country's format: its `PhoneFormats` entry, else three-digit groups up to the E.164 cap. */
39
+ formatOf(country) {
40
+ const format = PhoneFormats[country.iso];
41
+ if (format) return format;
42
+ const length = PhoneNumberExtensions.lengthOf(country).max;
43
+ const slots = Array.from(
44
+ { length },
45
+ (_, index) => index > 0 && index % PhoneNumberExtensions.GroupSize === 0 ? ` ${PhoneNumberExtensions.DigitSlot}` : PhoneNumberExtensions.DigitSlot
46
+ );
47
+ return { mask: slots.join(""), length };
48
+ },
49
+ /** Lays national digits into a mask; a separator shows only once a digit follows it, extra digits trail unmasked. */
50
+ formatNational(digits, format) {
51
+ let text = "";
52
+ let next = 0;
53
+ for (const slot of format.mask) {
54
+ if (next >= digits.length) break;
55
+ if (slot === PhoneNumberExtensions.DigitSlot) {
56
+ text += digits[next];
57
+ next += 1;
58
+ } else {
59
+ text += slot;
60
+ }
61
+ }
62
+ return text + digits.slice(next);
63
+ },
64
+ /** Finds the offset just after the `count`-th digit of `text`; `0` for no digits, the end when it has fewer. */
65
+ caretAfterDigits(text, count) {
66
+ if (count <= 0) return 0;
67
+ let seen = 0;
68
+ for (let index = 0; index < text.length; index++) {
69
+ if (text[index] >= "0" && text[index] <= "9") seen += 1;
70
+ if (seen === count) return index + 1;
71
+ }
72
+ return text.length;
73
+ },
74
+ /**
75
+ * Applies one edit of the national-number field: drops non-digits, steps a deletion over a separator onto the digit
76
+ * beside it, drops typed or pasted digits past the format's length, and keeps the caret after the same digit.
77
+ */
78
+ editNational(input) {
79
+ const { format, previousDigits } = input;
80
+ let digits = PhoneNumberExtensions.digitsOf(input.text);
81
+ let before = PhoneNumberExtensions.digitsOf(input.text.slice(0, input.caret)).length;
82
+ const previousText = PhoneNumberExtensions.formatNational(previousDigits, format);
83
+ if (digits === previousDigits && previousText.length - input.text.length === 1) {
84
+ if (input.inputType === "deleteContentBackward" && before > 0) {
85
+ digits = digits.slice(0, before - 1) + digits.slice(before);
86
+ before -= 1;
87
+ } else if (input.inputType === "deleteContentForward" && before < digits.length) {
88
+ digits = digits.slice(0, before) + digits.slice(before + 1);
89
+ }
90
+ }
91
+ const excess = digits.length - Math.max(format.length, previousDigits.length);
92
+ if (excess > 0) {
93
+ const dropped = Math.min(excess, before);
94
+ digits = digits.slice(0, before - dropped) + digits.slice(before);
95
+ before -= dropped;
96
+ }
97
+ const text = PhoneNumberExtensions.formatNational(digits, format);
98
+ return { digits, text, caret: PhoneNumberExtensions.caretAfterDigits(text, before) };
99
+ },
100
+ /**
101
+ * Finds the country an E.164 value belongs to: `preferredIso` when its dial code matches (a shared `+1` or `+7` stays
102
+ * on the reader's pick), else the longest matching dial code, a shared one going to the earlier country.
103
+ */
104
+ countryOf(value, countries, preferredIso) {
105
+ if (!value.startsWith("+")) return null;
106
+ const preferred = preferredIso === void 0 ? void 0 : countries.find((c) => c.iso === preferredIso);
107
+ if (preferred && value.startsWith(preferred.dial)) return preferred;
108
+ const longestFirst = [...countries].sort((a, b) => b.dial.length - a.dial.length);
109
+ return longestFirst.find((c) => value.startsWith(c.dial)) ?? null;
110
+ },
111
+ /** Splits an E.164 value into its country and national digits; a value no country matches keeps every digit. */
112
+ split(value, countries, fallbackIso) {
113
+ if (!value) return { iso: fallbackIso, national: "" };
114
+ const country = PhoneNumberExtensions.countryOf(value, countries);
115
+ if (!country) return { iso: fallbackIso, national: PhoneNumberExtensions.digitsOf(value) };
116
+ return { iso: country.iso, national: PhoneNumberExtensions.digitsOf(value.slice(country.dial.length)) };
117
+ },
118
+ /** Reads an international number from free text (`+998 99 663-25-82`): every digit after `+`, and its country. */
119
+ parseInternational(text, countries, preferredIso) {
120
+ const e164 = `+${PhoneNumberExtensions.digitsOf(text)}`;
121
+ return { country: PhoneNumberExtensions.countryOf(e164, countries, preferredIso), e164 };
122
+ },
123
+ /**
124
+ * Strips a dial code typed without its `+` (`998996632582` for Uzbekistan): only digits that are exactly the
125
+ * country's dial code and a full fixed-length national number, a length no national number has on its own.
126
+ */
127
+ withoutDialCode(digits, country) {
128
+ const format = PhoneFormats[country.iso];
129
+ const dial = PhoneNumberExtensions.digitsOf(country.dial);
130
+ if (!format || digits.length !== dial.length + format.length || !digits.startsWith(dial)) return digits;
131
+ return digits.slice(dial.length);
132
+ }
133
+ };
134
+ export {
135
+ PhoneNumberExtensions
136
+ };
137
+ //# sourceMappingURL=PhoneNumberExtensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PhoneNumberExtensions.js","sources":["../../../src/foundation/phone/PhoneNumberExtensions.ts"],"sourcesContent":["import { PhoneCountries, type PhoneCountry } from './PhoneCountries';\nimport { PhoneFormats, type PhoneFormat } from './PhoneFormats';\n\n/** Holds a value's country and national digits. */\nexport interface PhoneNumberParts {\n /** The ISO code the value's dial prefix names, or the fallback when none of the countries matches. */\n readonly iso: string;\n /** The national digits: everything after the matched dial code, or every digit when none matched. */\n readonly national: string;\n}\n\n/** Holds the national digits a country's numbering plan accepts. */\nexport interface PhoneLengthRange {\n /** The fewest national digits. */\n readonly min: number;\n /** The most national digits. Equals `min` for a fixed-length plan. */\n readonly max: number;\n}\n\n/** Describes one edit of the national-number field, as the browser left it. */\nexport interface PhoneNationalEditInput {\n /** The field text after the browser applied the edit, separators and stray characters included. */\n readonly text: string;\n /** The caret offset in `text`. */\n readonly caret: number;\n /** The national digits before the edit. */\n readonly previousDigits: string;\n /** The `InputEvent.inputType`; `deleteContentBackward` / `deleteContentForward` step over a separator. */\n readonly inputType?: string;\n /** The country's format; its `length` caps the digits. */\n readonly format: PhoneFormat;\n}\n\n/** Holds the result of one national-number edit. */\nexport interface PhoneNationalEdit {\n /** The national digits after the edit. */\n readonly digits: string;\n /** The display text: the digits through the mask. */\n readonly text: string;\n /** The caret offset in `text`, after the same digits it followed before the edit. */\n readonly caret: number;\n}\n\n/** Holds an international number read from pasted or autofilled text. */\nexport interface PhoneInternationalNumber {\n /** The allowed country its dial prefix names, or `null` when none does. */\n readonly country: PhoneCountry | null;\n /** The E.164 value: `+` and every digit of the text. */\n readonly e164: string;\n}\n\n/** Extends E.164 phone values and their national digits: country lookup, length rules, display and editing. */\nexport const PhoneNumberExtensions = {\n /** @internal E.164 caps a number, dial code included, at 15 digits. */\n MaxDigits: 15,\n /** @internal The fewest national digits a plan outside `PhoneFormats` accepts — Austria's shortest. */\n MinNationalDigits: 4,\n /** @internal The group size of the fallback mask. */\n GroupSize: 3,\n /** @internal The mask character that takes one digit. */\n DigitSlot: 'X',\n /** @internal Every non-digit. */\n NonDigit: /\\D/g,\n /** @internal An E.164 value: `+`, then digits, the first not `0`. */\n E164Pattern: /^\\+[1-9]\\d*$/,\n\n /** Removes every non-digit. */\n digitsOf(text: string): string {\n return text.replace(PhoneNumberExtensions.NonDigit, '');\n },\n\n /**\n * Resolves ISO codes to known countries in the order given; unknown and repeated codes are dropped. A list with no\n * known code reads as absent — every country — since a phone control with no country could hold no value.\n */\n resolveCountries(isos: ReadonlyArray<string> | undefined): ReadonlyArray<PhoneCountry> {\n if (!isos) return PhoneCountries;\n\n const known = [...new Set(isos)]\n .map((iso) => PhoneCountries.find((c) => c.iso === iso))\n .filter((c): c is PhoneCountry => c !== undefined);\n return known.length > 0 ? known : PhoneCountries;\n },\n\n /** Resolves the national digits a country accepts: its fixed length, else up to the E.164 cap. */\n lengthOf(country: PhoneCountry): PhoneLengthRange {\n const format = PhoneFormats[country.iso];\n if (format) return { min: format.length, max: format.length };\n\n return {\n min: PhoneNumberExtensions.MinNationalDigits,\n max: PhoneNumberExtensions.MaxDigits - PhoneNumberExtensions.digitsOf(country.dial).length,\n };\n },\n\n /** Resolves a country's format: its `PhoneFormats` entry, else three-digit groups up to the E.164 cap. */\n formatOf(country: PhoneCountry): PhoneFormat {\n const format = PhoneFormats[country.iso];\n if (format) return format;\n\n const length = PhoneNumberExtensions.lengthOf(country).max;\n const slots = Array.from({ length }, (_, index) =>\n index > 0 && index % PhoneNumberExtensions.GroupSize === 0\n ? ` ${PhoneNumberExtensions.DigitSlot}`\n : PhoneNumberExtensions.DigitSlot,\n );\n return { mask: slots.join(''), length };\n },\n\n /** Lays national digits into a mask; a separator shows only once a digit follows it, extra digits trail unmasked. */\n formatNational(digits: string, format: PhoneFormat): string {\n let text = '';\n let next = 0;\n for (const slot of format.mask) {\n if (next >= digits.length) break;\n if (slot === PhoneNumberExtensions.DigitSlot) {\n text += digits[next];\n next += 1;\n } else {\n text += slot;\n }\n }\n\n return text + digits.slice(next);\n },\n\n /** Finds the offset just after the `count`-th digit of `text`; `0` for no digits, the end when it has fewer. */\n caretAfterDigits(text: string, count: number): number {\n if (count <= 0) return 0;\n\n let seen = 0;\n for (let index = 0; index < text.length; index++) {\n if (text[index]! >= '0' && text[index]! <= '9') seen += 1;\n if (seen === count) return index + 1;\n }\n return text.length;\n },\n\n /**\n * Applies one edit of the national-number field: drops non-digits, steps a deletion over a separator onto the digit\n * beside it, drops typed or pasted digits past the format's length, and keeps the caret after the same digit.\n */\n editNational(input: PhoneNationalEditInput): PhoneNationalEdit {\n const { format, previousDigits } = input;\n let digits = PhoneNumberExtensions.digitsOf(input.text);\n let before = PhoneNumberExtensions.digitsOf(input.text.slice(0, input.caret)).length;\n\n // A single deleted character that left the digits whole was a separator: the deletion moves on to the digit.\n const previousText = PhoneNumberExtensions.formatNational(previousDigits, format);\n if (digits === previousDigits && previousText.length - input.text.length === 1) {\n if (input.inputType === 'deleteContentBackward' && before > 0) {\n digits = digits.slice(0, before - 1) + digits.slice(before);\n before -= 1;\n } else if (input.inputType === 'deleteContentForward' && before < digits.length) {\n digits = digits.slice(0, before) + digits.slice(before + 1);\n }\n }\n\n // Digits past the cap are the ones just inserted, which sit right before the caret.\n const excess = digits.length - Math.max(format.length, previousDigits.length);\n if (excess > 0) {\n const dropped = Math.min(excess, before);\n digits = digits.slice(0, before - dropped) + digits.slice(before);\n before -= dropped;\n }\n\n const text = PhoneNumberExtensions.formatNational(digits, format);\n return { digits, text, caret: PhoneNumberExtensions.caretAfterDigits(text, before) };\n },\n\n /**\n * Finds the country an E.164 value belongs to: `preferredIso` when its dial code matches (a shared `+1` or `+7` stays\n * on the reader's pick), else the longest matching dial code, a shared one going to the earlier country.\n */\n countryOf(value: string, countries: ReadonlyArray<PhoneCountry>, preferredIso?: string): PhoneCountry | null {\n if (!value.startsWith('+')) return null;\n\n const preferred = preferredIso === undefined ? undefined : countries.find((c) => c.iso === preferredIso);\n if (preferred && value.startsWith(preferred.dial)) return preferred;\n\n // The stable sort leaves countries of one code length in list order.\n const longestFirst = [...countries].sort((a, b) => b.dial.length - a.dial.length);\n return longestFirst.find((c) => value.startsWith(c.dial)) ?? null;\n },\n\n /** Splits an E.164 value into its country and national digits; a value no country matches keeps every digit. */\n split(value: string, countries: ReadonlyArray<PhoneCountry>, fallbackIso: string): PhoneNumberParts {\n if (!value) return { iso: fallbackIso, national: '' };\n\n const country = PhoneNumberExtensions.countryOf(value, countries);\n if (!country) return { iso: fallbackIso, national: PhoneNumberExtensions.digitsOf(value) };\n\n return { iso: country.iso, national: PhoneNumberExtensions.digitsOf(value.slice(country.dial.length)) };\n },\n\n /** Reads an international number from free text (`+998 99 663-25-82`): every digit after `+`, and its country. */\n parseInternational(\n text: string,\n countries: ReadonlyArray<PhoneCountry>,\n preferredIso?: string,\n ): PhoneInternationalNumber {\n const e164 = `+${PhoneNumberExtensions.digitsOf(text)}`;\n return { country: PhoneNumberExtensions.countryOf(e164, countries, preferredIso), e164 };\n },\n\n /**\n * Strips a dial code typed without its `+` (`998996632582` for Uzbekistan): only digits that are exactly the\n * country's dial code and a full fixed-length national number, a length no national number has on its own.\n */\n withoutDialCode(digits: string, country: PhoneCountry): string {\n const format = PhoneFormats[country.iso];\n const dial = PhoneNumberExtensions.digitsOf(country.dial);\n if (!format || digits.length !== dial.length + format.length || !digits.startsWith(dial)) return digits;\n\n return digits.slice(dial.length);\n },\n} as const;\n"],"names":[],"mappings":";;AAoDO,MAAM,wBAAwB;AAAA;AAAA,EAEnC,WAAW;AAAA;AAAA,EAEX,mBAAmB;AAAA;AAAA,EAEnB,WAAW;AAAA;AAAA,EAEX,WAAW;AAAA;AAAA,EAEX,UAAU;AAAA;AAAA,EAEV,aAAa;AAAA;AAAA,EAGb,SAAS,MAAsB;AAC7B,WAAO,KAAK,QAAQ,sBAAsB,UAAU,EAAE;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,iBAAiB,MAAsE;AACrF,QAAI,CAAC,KAAM,QAAO;AAElB,UAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC,EAC5B,IAAI,CAAC,QAAQ,eAAe,KAAK,CAAC,MAAM,EAAE,QAAQ,GAAG,CAAC,EACtD,OAAO,CAAC,MAAyB,MAAM,MAAS;AACnD,WAAO,MAAM,SAAS,IAAI,QAAQ;AAAA,EACpC;AAAA;AAAA,EAGA,SAAS,SAAyC;AAChD,UAAM,SAAS,aAAa,QAAQ,GAAG;AACvC,QAAI,eAAe,EAAE,KAAK,OAAO,QAAQ,KAAK,OAAO,OAAA;AAErD,WAAO;AAAA,MACL,KAAK,sBAAsB;AAAA,MAC3B,KAAK,sBAAsB,YAAY,sBAAsB,SAAS,QAAQ,IAAI,EAAE;AAAA,IAAA;AAAA,EAExF;AAAA;AAAA,EAGA,SAAS,SAAoC;AAC3C,UAAM,SAAS,aAAa,QAAQ,GAAG;AACvC,QAAI,OAAQ,QAAO;AAEnB,UAAM,SAAS,sBAAsB,SAAS,OAAO,EAAE;AACvD,UAAM,QAAQ,MAAM;AAAA,MAAK,EAAE,OAAA;AAAA,MAAU,CAAC,GAAG,UACvC,QAAQ,KAAK,QAAQ,sBAAsB,cAAc,IACrD,IAAI,sBAA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BACE,MACA,WACA,cAC0B;AAC1B,UAAM,OAAO,IAAI,sBAAsB,SAAS,IAAI,CAAC;AACrD,WAAO,EAAE,SAAS,sBAAsB,UAAU,MAAM,WAAW,YAAY,GAAG,KAAA;AAAA,EACpF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,gBAAgB,QAAgB,SAA+B;AAC7D,UAAM,SAAS,aAAa,QAAQ,GAAG;AACvC,UAAM,OAAO,sBAAsB,SAAS,QAAQ,IAAI;AACxD,QAAI,CAAC,UAAU,OAAO,WAAW,KAAK,SAAS,OAAO,UAAU,CAAC,OAAO,WAAW,IAAI,EAAG,QAAO;AAEjG,WAAO,OAAO,MAAM,KAAK,MAAM;AAAA,EACjC;AACF;"}
@@ -0,0 +1,3 @@
1
+ export { type PhoneCountry, PhoneCountries } from './PhoneCountries';
2
+ export { type PhoneFormat, PhoneFormats } from './PhoneFormats';
3
+ export { type PhoneNumberParts, type PhoneLengthRange, type PhoneNationalEditInput, type PhoneNationalEdit, type PhoneInternationalNumber, PhoneNumberExtensions, } from './PhoneNumberExtensions';
@@ -0,0 +1,9 @@
1
+ import { PhoneCountries } from "./PhoneCountries.js";
2
+ import { PhoneFormats } from "./PhoneFormats.js";
3
+ import { PhoneNumberExtensions } from "./PhoneNumberExtensions.js";
4
+ export {
5
+ PhoneCountries,
6
+ PhoneFormats,
7
+ PhoneNumberExtensions
8
+ };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -2,6 +2,7 @@ export * from './slot';
2
2
  export * from './portal';
3
3
  export * from './visuallyHidden';
4
4
  export * from './presence';
5
+ export * from './swapTransition';
5
6
  export * from './directionProvider';
6
7
  export * from './accessibleIcon';
7
8
  export * from './focusScope';
@@ -20,6 +20,7 @@ import { Orientation, RovingFocusKey, useRovingFocusItem } from "./rovingFocusGr
20
20
  import { Presence } from "./presence/Presence.js";
21
21
  import { Primitive } from "./slot/Primitive.js";
22
22
  import { Slottable, mergeProps, renderSlotClone, renderableChildren } from "./slot/Slot.js";
23
+ import { SwapTransition, SwapTransitionAttribute } from "./swapTransition/SwapTransition.js";
23
24
  import { createCollection } from "./collection/Collection.js";
24
25
  export {
25
26
  AccessibleIcon,
@@ -48,6 +49,8 @@ export {
48
49
  default12 as ScrollLockProvider,
49
50
  default13 as ScrollViewport,
50
51
  Slottable,
52
+ SwapTransition,
53
+ SwapTransitionAttribute,
51
54
  default14 as VisuallyHidden,
52
55
  colorModeScript,
53
56
  createCollection,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,76 @@
1
+ import { SlotsType, VNode } from 'vue';
2
+ /** Present on the box while a swap runs — from the old content's fade-out to the new content's fade-in. */
3
+ export declare const SwapTransitionAttribute = "data-swapping";
4
+ /** Props for `SwapTransition`. */
5
+ export interface SwapTransitionProps {
6
+ /** Whether swaps and height changes animate. Defaults to `true`; `false` swaps instantly. */
7
+ readonly isEnabled?: boolean;
8
+ /** The height phase in milliseconds. Defaults to `200`. */
9
+ readonly duration?: number;
10
+ /** Each fade phase in milliseconds. Defaults to `120`. */
11
+ readonly fadeDuration?: number;
12
+ /** The easing curve of every phase. Defaults to the house ease-out curve. */
13
+ readonly easing?: string;
14
+ }
15
+ /**
16
+ * Swaps its content with a fade and a height animation: on a change of the single child's key or type, the old
17
+ * content fades out, the box animates to the new content's height, and the new content fades in. While shown, the box
18
+ * follows its content's own height changes the same way. The first render, `:is-enabled="false"` and
19
+ * `prefers-reduced-motion` swap and resize instantly.
20
+ *
21
+ * Renders a `div` box (caller `class`, `style` and attributes fall through to it) around a `flow-root` content
22
+ * wrapper. The leaving content is `inert`; focus inside it moves to the box as a programmatic focus target, so it
23
+ * never falls back to the document body.
24
+ */
25
+ export declare const SwapTransition: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
26
+ /** Whether swaps and height changes animate. Defaults to `true`. */
27
+ isEnabled: {
28
+ type: BooleanConstructor;
29
+ default: undefined;
30
+ };
31
+ /** The height phase in milliseconds. Defaults to `200`. */
32
+ duration: {
33
+ type: NumberConstructor;
34
+ default: undefined;
35
+ };
36
+ /** Each fade phase in milliseconds. Defaults to `120`. */
37
+ fadeDuration: {
38
+ type: NumberConstructor;
39
+ default: undefined;
40
+ };
41
+ /** The easing curve of every phase. Defaults to the house ease-out curve. */
42
+ easing: {
43
+ type: StringConstructor;
44
+ default: undefined;
45
+ };
46
+ }>, () => VNode<import('vue').RendererNode, import('vue').RendererElement, {
47
+ [key: string]: any;
48
+ }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
49
+ /** Whether swaps and height changes animate. Defaults to `true`. */
50
+ isEnabled: {
51
+ type: BooleanConstructor;
52
+ default: undefined;
53
+ };
54
+ /** The height phase in milliseconds. Defaults to `200`. */
55
+ duration: {
56
+ type: NumberConstructor;
57
+ default: undefined;
58
+ };
59
+ /** Each fade phase in milliseconds. Defaults to `120`. */
60
+ fadeDuration: {
61
+ type: NumberConstructor;
62
+ default: undefined;
63
+ };
64
+ /** The easing curve of every phase. Defaults to the house ease-out curve. */
65
+ easing: {
66
+ type: StringConstructor;
67
+ default: undefined;
68
+ };
69
+ }>> & Readonly<{}>, {
70
+ easing: string;
71
+ duration: number;
72
+ isEnabled: boolean;
73
+ fadeDuration: number;
74
+ }, SlotsType<{
75
+ default?: () => VNode[];
76
+ }>, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
@@ -0,0 +1,240 @@
1
+ import { defineComponent, shallowRef, onMounted, onBeforeUnmount, h, Transition } from "vue";
2
+ import { animate, AnimationDefaults } from "../../animation/Animate.js";
3
+ import { useReducedMotion } from "../../device/hooks/UseReducedMotion.js";
4
+ import { FocusTargetAttribute, focusTarget } from "../../dom/FocusTarget.js";
5
+ const SwapTransitionAttribute = "data-swapping";
6
+ const FadeDurationMs = 120;
7
+ const SettleSlackMs = 250;
8
+ const ContentStyle = { display: "flow-root" };
9
+ function settle(handle, ms) {
10
+ return new Promise((resolve) => {
11
+ const timer = setTimeout(() => {
12
+ handle.finish();
13
+ resolve();
14
+ }, ms + SettleSlackMs);
15
+ void handle.finished.then(() => {
16
+ clearTimeout(timer);
17
+ resolve();
18
+ });
19
+ });
20
+ }
21
+ const SwapTransition = defineComponent({
22
+ name: "SwapTransition",
23
+ props: {
24
+ /** Whether swaps and height changes animate. Defaults to `true`. */
25
+ isEnabled: { type: Boolean, default: void 0 },
26
+ /** The height phase in milliseconds. Defaults to `200`. */
27
+ duration: { type: Number, default: void 0 },
28
+ /** Each fade phase in milliseconds. Defaults to `120`. */
29
+ fadeDuration: { type: Number, default: void 0 },
30
+ /** The easing curve of every phase. Defaults to the house ease-out curve. */
31
+ easing: { type: String, default: void 0 }
32
+ },
33
+ slots: Object,
34
+ setup(props, { slots }) {
35
+ const box = shallowRef(null);
36
+ const content = shallowRef(null);
37
+ const prefersReducedMotion = useReducedMotion();
38
+ let phase = 0;
39
+ let handle = null;
40
+ let isSwapping = false;
41
+ let isEntering = false;
42
+ let isFollowing = false;
43
+ let isDisposed = false;
44
+ let lastHeight = null;
45
+ let observer = null;
46
+ const heightDuration = () => props.duration ?? AnimationDefaults.duration;
47
+ const fadeDuration = () => props.fadeDuration ?? FadeDurationMs;
48
+ const isAnimated = () => (props.isEnabled ?? true) && !prefersReducedMotion.value && document.visibilityState !== "hidden";
49
+ function stop() {
50
+ phase += 1;
51
+ handle?.cancel();
52
+ handle = null;
53
+ }
54
+ async function play(element, keyframes, duration) {
55
+ stop();
56
+ const token = phase;
57
+ const current = animate(element, keyframes, { duration, easing: props.easing });
58
+ handle = current;
59
+ await settle(current, duration);
60
+ if (token !== phase || isDisposed) return false;
61
+ handle = null;
62
+ return true;
63
+ }
64
+ async function resizeTo(boxElement, to) {
65
+ const from = boxElement.getBoundingClientRect().height;
66
+ boxElement.style.height = `${to}px`;
67
+ if (from === to) return true;
68
+ return play(boxElement, [{ height: `${from}px` }, { height: `${to}px` }], heightDuration());
69
+ }
70
+ function pin(boxElement) {
71
+ const height = boxElement.getBoundingClientRect().height;
72
+ stop();
73
+ isFollowing = false;
74
+ isSwapping = true;
75
+ boxElement.setAttribute(SwapTransitionAttribute, "");
76
+ boxElement.style.height = `${height}px`;
77
+ boxElement.style.overflow = "hidden";
78
+ }
79
+ function release() {
80
+ isSwapping = false;
81
+ isFollowing = false;
82
+ const boxElement = box.value;
83
+ if (boxElement) {
84
+ boxElement.style.height = "";
85
+ boxElement.style.overflow = "";
86
+ boxElement.removeAttribute(SwapTransitionAttribute);
87
+ }
88
+ const inner = content.value;
89
+ if (inner) {
90
+ inner.style.opacity = "";
91
+ inner.inert = false;
92
+ lastHeight = inner.getBoundingClientRect().height;
93
+ }
94
+ }
95
+ function parkFocus(boxElement, inner) {
96
+ const active = boxElement.ownerDocument.activeElement;
97
+ if (!active || !inner.contains(active)) return;
98
+ const hadTabIndex = boxElement.hasAttribute("tabindex");
99
+ const hadMarker = boxElement.hasAttribute(FocusTargetAttribute);
100
+ if (!focusTarget(boxElement)) return;
101
+ boxElement.addEventListener(
102
+ "blur",
103
+ () => {
104
+ if (!hadTabIndex) boxElement.removeAttribute("tabindex");
105
+ if (!hadMarker) boxElement.removeAttribute(FocusTargetAttribute);
106
+ },
107
+ { once: true }
108
+ );
109
+ }
110
+ function onBeforeLeave() {
111
+ const boxElement = box.value;
112
+ const inner = content.value;
113
+ if (!boxElement || !inner) return;
114
+ parkFocus(boxElement, inner);
115
+ if (!isAnimated()) return;
116
+ const opacity = getComputedStyle(inner).opacity;
117
+ pin(boxElement);
118
+ inner.style.opacity = opacity;
119
+ inner.inert = true;
120
+ }
121
+ function onLeave(_element, done) {
122
+ const inner = content.value;
123
+ if (!inner || !isSwapping) {
124
+ queueMicrotask(done);
125
+ return;
126
+ }
127
+ const from = inner.style.opacity || "1";
128
+ inner.style.opacity = "0";
129
+ if (Number(from) === 0) {
130
+ queueMicrotask(done);
131
+ return;
132
+ }
133
+ void play(inner, [{ opacity: from }, { opacity: "0" }], fadeDuration()).then(() => {
134
+ if (!isDisposed) done();
135
+ });
136
+ }
137
+ function onAfterLeave() {
138
+ const boxElement = box.value;
139
+ const inner = content.value;
140
+ if (inner) inner.inert = false;
141
+ if (!boxElement || !inner || !isSwapping || isEntering) return;
142
+ void resizeTo(boxElement, inner.getBoundingClientRect().height).then((isComplete) => {
143
+ if (isComplete) release();
144
+ });
145
+ }
146
+ function onBeforeEnter() {
147
+ isEntering = true;
148
+ const boxElement = box.value;
149
+ const inner = content.value;
150
+ if (!boxElement || !inner) return;
151
+ inner.inert = false;
152
+ if (!isAnimated()) {
153
+ if (isSwapping) {
154
+ stop();
155
+ release();
156
+ }
157
+ return;
158
+ }
159
+ pin(boxElement);
160
+ inner.style.opacity = "0";
161
+ }
162
+ function onEnter(_element, done) {
163
+ const boxElement = box.value;
164
+ const inner = content.value;
165
+ if (!boxElement || !inner || !isSwapping) {
166
+ done();
167
+ return;
168
+ }
169
+ void (async () => {
170
+ if (!await resizeTo(boxElement, inner.getBoundingClientRect().height)) return;
171
+ inner.style.opacity = "";
172
+ if (!await play(inner, [{ opacity: "0" }, { opacity: "1" }], fadeDuration())) return;
173
+ done();
174
+ })();
175
+ }
176
+ function onAfterEnter() {
177
+ isEntering = false;
178
+ release();
179
+ }
180
+ function onEnterCancelled() {
181
+ isEntering = false;
182
+ }
183
+ function onResize() {
184
+ const boxElement = box.value;
185
+ const inner = content.value;
186
+ if (!boxElement || !inner) return;
187
+ const height = inner.getBoundingClientRect().height;
188
+ const previous = lastHeight;
189
+ lastHeight = height;
190
+ if (isSwapping || previous === null || previous === height || !isAnimated()) return;
191
+ const from = isFollowing ? boxElement.getBoundingClientRect().height : previous;
192
+ stop();
193
+ isFollowing = true;
194
+ boxElement.style.height = `${height}px`;
195
+ boxElement.style.overflow = "hidden";
196
+ void play(boxElement, [{ height: `${from}px` }, { height: `${height}px` }], heightDuration()).then(
197
+ (isComplete) => {
198
+ if (isComplete && !isSwapping) release();
199
+ }
200
+ );
201
+ }
202
+ onMounted(() => {
203
+ const inner = content.value;
204
+ if (!inner || typeof ResizeObserver === "undefined") return;
205
+ lastHeight = inner.getBoundingClientRect().height;
206
+ observer = new ResizeObserver(onResize);
207
+ observer.observe(inner);
208
+ });
209
+ onBeforeUnmount(() => {
210
+ isDisposed = true;
211
+ stop();
212
+ observer?.disconnect();
213
+ observer = null;
214
+ });
215
+ return () => h("div", { ref: box }, [
216
+ h("div", { ref: content, style: ContentStyle }, [
217
+ h(
218
+ Transition,
219
+ {
220
+ mode: "out-in",
221
+ css: false,
222
+ onBeforeLeave,
223
+ onLeave,
224
+ onAfterLeave,
225
+ onBeforeEnter,
226
+ onEnter,
227
+ onAfterEnter,
228
+ onEnterCancelled
229
+ },
230
+ () => slots.default?.()
231
+ )
232
+ ])
233
+ ]);
234
+ }
235
+ });
236
+ export {
237
+ SwapTransition,
238
+ SwapTransitionAttribute
239
+ };
240
+ //# sourceMappingURL=SwapTransition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwapTransition.js","sources":["../../../../src/foundation/primitives/swapTransition/SwapTransition.ts"],"sourcesContent":["// A content swap that never jumps: the old content fades out, the box animates its height to the new content's\n// height, and the new content fades in. Between swaps the box follows its content's own height changes.\n//\n// AUTHORED AS `defineComponent` IN PLAIN TS, like `Presence`: the whole job is a render function around Vue's\n// `<Transition>` and imperative motion on two wrapper elements.\n//\n// NON-OBVIOUS DECISIONS:\n//\n// - VUE'S `<Transition mode=\"out-in\">` OWNS THE SWAP. It keeps the leaving child mounted until its leave hook\n// calls `done`, waits for it before rendering the newest child, and cancels an entering child that a newer swap\n// replaces. This component only supplies JS hooks (`css: false`); it never retains a vnode of its own.\n//\n// - THE WRAPPERS ANIMATE, NEVER THE CONTENT. The fades run on the inner wrapper and the height on the outer box,\n// so a child's own inline styles and root shape are untouched. The inner wrapper is `display: flow-root`, so a\n// child's margins stay inside the measured height in every phase.\n//\n// - COMMIT THE END, ANIMATE FROM THE START. Each phase writes its final value inline and runs a `fill: 'none'`\n// WAAPI animation from the current value (`foundation/animation` `animate`), so a cancelled or finished phase\n// always leaves the committed value behind. A swap that interrupts another reads the height and opacity on\n// screen first, so it continues from where the previous motion stood.\n//\n// - A TIMER FLOOR UNDER EVERY PHASE. A hidden document runs no animation frames, so a WAAPI `finish` may never\n// arrive while a tab is in the background; out-in would then never render the new content. Each phase settles\n// on its animation or on a timer past its duration, whichever lands first.\n\nimport {\n defineComponent,\n h,\n onBeforeUnmount,\n onMounted,\n shallowRef,\n Transition,\n type SlotsType,\n type StyleValue,\n type VNode,\n} from 'vue';\n\nimport { animate, AnimationDefaults, type AnimationHandle } from '../../animation';\nimport { useReducedMotion } from '../../device';\nimport { FocusTargetAttribute, focusTarget } from '../../dom';\n\n/** Present on the box while a swap runs — from the old content's fade-out to the new content's fade-in. */\nexport const SwapTransitionAttribute = 'data-swapping';\n\n/** The default length of each fade, in milliseconds. */\nconst FadeDurationMs = 120;\n\n/** How long past its duration a phase waits for its animation before settling on a timer instead. */\nconst SettleSlackMs = 250;\n\n/** Keeps a child's margins inside the measured content box in every phase. */\nconst ContentStyle: StyleValue = { display: 'flow-root' };\n\n/** Props for `SwapTransition`. */\nexport interface SwapTransitionProps {\n /** Whether swaps and height changes animate. Defaults to `true`; `false` swaps instantly. */\n readonly isEnabled?: boolean;\n /** The height phase in milliseconds. Defaults to `200`. */\n readonly duration?: number;\n /** Each fade phase in milliseconds. Defaults to `120`. */\n readonly fadeDuration?: number;\n /** The easing curve of every phase. Defaults to the house ease-out curve. */\n readonly easing?: string;\n}\n\n/** Settles when `handle` finishes, or `ms` plus a slack later when no animation frame runs (a hidden document). */\nfunction settle(handle: AnimationHandle, ms: number): Promise<void> {\n return new Promise((resolve) => {\n const timer = setTimeout(() => {\n handle.finish();\n resolve();\n }, ms + SettleSlackMs);\n void handle.finished.then(() => {\n clearTimeout(timer);\n resolve();\n });\n });\n}\n\n/**\n * Swaps its content with a fade and a height animation: on a change of the single child's key or type, the old\n * content fades out, the box animates to the new content's height, and the new content fades in. While shown, the box\n * follows its content's own height changes the same way. The first render, `:is-enabled=\"false\"` and\n * `prefers-reduced-motion` swap and resize instantly.\n *\n * Renders a `div` box (caller `class`, `style` and attributes fall through to it) around a `flow-root` content\n * wrapper. The leaving content is `inert`; focus inside it moves to the box as a programmatic focus target, so it\n * never falls back to the document body.\n */\nexport const SwapTransition = defineComponent({\n name: 'SwapTransition',\n\n props: {\n /** Whether swaps and height changes animate. Defaults to `true`. */\n isEnabled: { type: Boolean, default: undefined },\n /** The height phase in milliseconds. Defaults to `200`. */\n duration: { type: Number, default: undefined },\n /** Each fade phase in milliseconds. Defaults to `120`. */\n fadeDuration: { type: Number, default: undefined },\n /** The easing curve of every phase. Defaults to the house ease-out curve. */\n easing: { type: String, default: undefined },\n },\n\n slots: Object as SlotsType<{ default?: () => VNode[] }>,\n\n setup(props, { slots }) {\n const box = shallowRef<HTMLElement | null>(null);\n const content = shallowRef<HTMLElement | null>(null);\n const prefersReducedMotion = useReducedMotion();\n\n let phase = 0;\n let handle: AnimationHandle | null = null;\n let isSwapping = false;\n let isEntering = false;\n let isFollowing = false;\n let isDisposed = false;\n let lastHeight: number | null = null;\n let observer: ResizeObserver | null = null;\n\n const heightDuration = (): number => props.duration ?? AnimationDefaults.duration;\n const fadeDuration = (): number => props.fadeDuration ?? FadeDurationMs;\n const isAnimated = (): boolean =>\n (props.isEnabled ?? true) && !prefersReducedMotion.value && document.visibilityState !== 'hidden';\n\n /** Cancels the running phase; its continuation sees a newer `phase` and stops. */\n function stop(): void {\n phase += 1;\n handle?.cancel();\n handle = null;\n }\n\n /** Runs one phase; resolves `true` when it ran to its end, `false` when a newer phase or unmount replaced it. */\n async function play(element: HTMLElement, keyframes: Keyframe[], duration: number): Promise<boolean> {\n stop();\n const token = phase;\n const current = animate(element, keyframes, { duration, easing: props.easing });\n handle = current;\n await settle(current, duration);\n if (token !== phase || isDisposed) return false;\n handle = null;\n return true;\n }\n\n /** Animates the box from the height on screen to `to`, committing `to` first. */\n async function resizeTo(boxElement: HTMLElement, to: number): Promise<boolean> {\n const from = boxElement.getBoundingClientRect().height;\n boxElement.style.height = `${to}px`;\n if (from === to) return true;\n return play(boxElement, [{ height: `${from}px` }, { height: `${to}px` }], heightDuration());\n }\n\n /** Holds the box at the height on screen, stopping whatever motion ran, for the swap that starts now. */\n function pin(boxElement: HTMLElement): void {\n const height = boxElement.getBoundingClientRect().height;\n stop();\n isFollowing = false;\n isSwapping = true;\n boxElement.setAttribute(SwapTransitionAttribute, '');\n boxElement.style.height = `${height}px`;\n boxElement.style.overflow = 'hidden';\n }\n\n /** Hands the box back to its content: auto height, visible overflow, full opacity. */\n function release(): void {\n isSwapping = false;\n isFollowing = false;\n const boxElement = box.value;\n if (boxElement) {\n boxElement.style.height = '';\n boxElement.style.overflow = '';\n boxElement.removeAttribute(SwapTransitionAttribute);\n }\n const inner = content.value;\n if (inner) {\n inner.style.opacity = '';\n inner.inert = false;\n lastHeight = inner.getBoundingClientRect().height;\n }\n }\n\n /** Moves focus held inside the leaving content to the box, removing the box's focus target marks on blur. */\n function parkFocus(boxElement: HTMLElement, inner: HTMLElement): void {\n const active = boxElement.ownerDocument.activeElement;\n if (!active || !inner.contains(active)) return;\n const hadTabIndex = boxElement.hasAttribute('tabindex');\n const hadMarker = boxElement.hasAttribute(FocusTargetAttribute);\n if (!focusTarget(boxElement)) return;\n boxElement.addEventListener(\n 'blur',\n () => {\n if (!hadTabIndex) boxElement.removeAttribute('tabindex');\n if (!hadMarker) boxElement.removeAttribute(FocusTargetAttribute);\n },\n { once: true },\n );\n }\n\n function onBeforeLeave(): void {\n const boxElement = box.value;\n const inner = content.value;\n if (!boxElement || !inner) return;\n parkFocus(boxElement, inner);\n if (!isAnimated()) return;\n // A swap that cancels an entering one fades out from the opacity on screen.\n const opacity = getComputedStyle(inner).opacity;\n pin(boxElement);\n inner.style.opacity = opacity;\n inner.inert = true;\n }\n\n function onLeave(_element: Element, done: () => void): void {\n const inner = content.value;\n if (!inner || !isSwapping) {\n // Out-in renders the next child from `done`; called inside this patch, it would patch over a placeholder\n // that is not mounted yet. A microtask later the patch is over and nothing has painted.\n queueMicrotask(done);\n return;\n }\n const from = inner.style.opacity || '1';\n inner.style.opacity = '0';\n // Content still transparent (a swap that cancels one mid-height) has nothing to fade.\n if (Number(from) === 0) {\n queueMicrotask(done);\n return;\n }\n // Always finish the leave: out-in renders nothing new until `done` runs.\n void play(inner, [{ opacity: from }, { opacity: '0' }], fadeDuration()).then(() => {\n if (!isDisposed) done();\n });\n }\n\n function onAfterLeave(): void {\n const boxElement = box.value;\n const inner = content.value;\n if (inner) inner.inert = false;\n // Out-in mounts the next child before this hook runs; none (a `v-if` turned false) settles on empty content.\n if (!boxElement || !inner || !isSwapping || isEntering) return;\n void resizeTo(boxElement, inner.getBoundingClientRect().height).then((isComplete) => {\n if (isComplete) release();\n });\n }\n\n function onBeforeEnter(): void {\n isEntering = true;\n const boxElement = box.value;\n const inner = content.value;\n if (!boxElement || !inner) return;\n inner.inert = false;\n if (!isAnimated()) {\n if (isSwapping) {\n stop();\n release();\n }\n return;\n }\n pin(boxElement);\n inner.style.opacity = '0';\n }\n\n function onEnter(_element: Element, done: () => void): void {\n const boxElement = box.value;\n const inner = content.value;\n if (!boxElement || !inner || !isSwapping) {\n done();\n return;\n }\n void (async () => {\n if (!(await resizeTo(boxElement, inner.getBoundingClientRect().height))) return;\n inner.style.opacity = '';\n if (!(await play(inner, [{ opacity: '0' }, { opacity: '1' }], fadeDuration()))) return;\n done();\n })();\n }\n\n function onAfterEnter(): void {\n isEntering = false;\n release();\n }\n\n function onEnterCancelled(): void {\n // The leave hooks that follow read the height and opacity on screen before stopping this motion.\n isEntering = false;\n }\n\n /** Between swaps, animates the box from the content's previous height to its new one. */\n function onResize(): void {\n const boxElement = box.value;\n const inner = content.value;\n if (!boxElement || !inner) return;\n const height = inner.getBoundingClientRect().height;\n const previous = lastHeight;\n lastHeight = height;\n if (isSwapping || previous === null || previous === height || !isAnimated()) return;\n // Idle, the auto-height box already shows the new height; a running follow shows its own frame.\n const from = isFollowing ? boxElement.getBoundingClientRect().height : previous;\n stop();\n isFollowing = true;\n boxElement.style.height = `${height}px`;\n boxElement.style.overflow = 'hidden';\n void play(boxElement, [{ height: `${from}px` }, { height: `${height}px` }], heightDuration()).then(\n (isComplete) => {\n if (isComplete && !isSwapping) release();\n },\n );\n }\n\n // `onMounted` never runs on the server: the observer and every measurement stay client-side.\n onMounted(() => {\n const inner = content.value;\n if (!inner || typeof ResizeObserver === 'undefined') return;\n lastHeight = inner.getBoundingClientRect().height;\n observer = new ResizeObserver(onResize);\n observer.observe(inner);\n });\n\n onBeforeUnmount(() => {\n isDisposed = true;\n stop();\n observer?.disconnect();\n observer = null;\n });\n\n return () =>\n h('div', { ref: box }, [\n h('div', { ref: content, style: ContentStyle }, [\n h(\n Transition,\n {\n mode: 'out-in',\n css: false,\n onBeforeLeave,\n onLeave,\n onAfterLeave,\n onBeforeEnter,\n onEnter,\n onAfterEnter,\n onEnterCancelled,\n },\n () => slots.default?.(),\n ),\n ]),\n ]);\n },\n});\n"],"names":[],"mappings":";;;;AA0CO,MAAM,0BAA0B;AAGvC,MAAM,iBAAiB;AAGvB,MAAM,gBAAgB;AAGtB,MAAM,eAA2B,EAAE,SAAS,YAAA;AAe5C,SAAS,OAAO,QAAyB,IAA2B;AAClE,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,QAAQ,WAAW,MAAM;AAC7B,aAAO,OAAA;AACP,cAAA;AAAA,IACF,GAAG,KAAK,aAAa;AACrB,SAAK,OAAO,SAAS,KAAK,MAAM;AAC9B,mBAAa,KAAK;AAClB,cAAA;AAAA,IACF,CAAC;AAAA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AACpB,mBAAa;AACb,WAAA;AACA,gBAAU,WAAA;AACV,iBAAW;AAAA,IACb,CAAC;AAED,WAAO,MACL,EAAE,OAAO,EAAE,KAAK,OAAO;AAAA,MACrB,EAAE,OAAO,EAAE,KAAK,SAAS,OAAO,gBAAgB;AAAA,QAC9C;AAAA,UACE;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,KAAK;AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UAAA;AAAA,UAEF,MAAM,MAAM,UAAA;AAAA,QAAU;AAAA,MACxB,CACD;AAAA,IAAA,CACF;AAAA,EACL;AACF,CAAC;"}
@@ -0,0 +1 @@
1
+ export { SwapTransition, SwapTransitionAttribute, type SwapTransitionProps } from './SwapTransition';
@@ -7,3 +7,18 @@ export declare function url(message?: string): StringValidator;
7
7
  export declare function uuid(message?: string): StringValidator;
8
8
  /** Accepts a `YYYY-MM-DD` calendar date that actually exists. Not a full ISO 8601 timestamp. */
9
9
  export declare function isoDate(message?: string): StringValidator;
10
+ /** Configures the {@link phone} rule. */
11
+ export interface PhoneRuleOptions {
12
+ /** The ISO codes a number may come from — the phone control's `countries`. Every known country when omitted. */
13
+ readonly countries?: ReadonlyArray<string>;
14
+ /** Accepts the empty string a cleared phone control emits. Default `false`: an empty value fails as `required`. */
15
+ readonly isOptional?: boolean;
16
+ /** Replaces the message of a `phone` failure; the form's catalogue still renders the code first. */
17
+ readonly message?: string;
18
+ }
19
+ /**
20
+ * Accepts an E.164 phone value whose national number has its country's digit count — `+998` takes 9 digits. Fails
21
+ * with code `phone` and params `{ country, dial, length }` (a fixed-length plan) or `{ country, dial, min, max }`;
22
+ * a value that is not `+` and digits, or whose dial code names none of `countries`, fails with `phone` alone.
23
+ */
24
+ export declare function phone(options?: PhoneRuleOptions): StringValidator;
@@ -1,4 +1,6 @@
1
- import { string } from "./Primitives.js";
1
+ import { PhoneNumberExtensions } from "../phone/PhoneNumberExtensions.js";
2
+ import { invalid } from "./ValidationOutcome.js";
3
+ import { string, StringValidator } from "./Primitives.js";
2
4
  const EmailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
3
5
  const UuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$(?![\s\S])/i;
4
6
  const IsoDatePattern = /^\d{4}-\d{2}-\d{2}$(?![\s\S])/;
@@ -37,9 +39,38 @@ function isoDate(message = "must be a valid ISO date (YYYY-MM-DD)") {
37
39
  "isoDate"
38
40
  );
39
41
  }
42
+ function phone(options = {}) {
43
+ const countries = PhoneNumberExtensions.resolveCountries(options.countries);
44
+ const text = string();
45
+ return new StringValidator("phone", (value, path) => {
46
+ const parsed = text.parseAt(value, path);
47
+ if (!parsed.ok) return parsed;
48
+ const number = parsed.value;
49
+ if (number === "") {
50
+ return options.isOptional ? parsed : invalid([{ path, message: "is required", code: "required" }]);
51
+ }
52
+ const country = PhoneNumberExtensions.E164Pattern.test(number) ? PhoneNumberExtensions.countryOf(number, countries) : null;
53
+ if (!country) {
54
+ return invalid([{ path, message: options.message ?? "must be a valid phone number", code: "phone" }]);
55
+ }
56
+ const digits = number.length - country.dial.length;
57
+ const { min, max } = PhoneNumberExtensions.lengthOf(country);
58
+ if (digits >= min && digits <= max) return parsed;
59
+ const fixed = min === max;
60
+ return invalid([
61
+ {
62
+ path,
63
+ message: options.message ?? (fixed ? `must have ${min} digits after ${country.dial}` : `must have ${min} to ${max} digits after ${country.dial}`),
64
+ code: "phone",
65
+ params: fixed ? { country: country.iso, dial: country.dial, length: min } : { country: country.iso, dial: country.dial, min, max }
66
+ }
67
+ ]);
68
+ });
69
+ }
40
70
  export {
41
71
  email,
42
72
  isoDate,
73
+ phone,
43
74
  url,
44
75
  uuid
45
76
  };