diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index d5c4aac71..9bb79d6b0 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -10,7 +10,24 @@ I'm very open to contributions, big and small! For general instructions on submi ## Changes to the plugin -In order to build the project, you will first need to install [npm](https://www.npmjs.org), and then run `npm install` to install the project's dependencies. At this point, the included `demo.html` should be working, if you open it in your browser. Then you should make your changes in the `src` directory, and be sure to run the relevant build script before committing your changes - if you've modified the JS, you'll need to run `npm run build:js`, or if you've modified the CSS, it's `npm run build:css`. +In order to build the project, you will first need to install [npm](https://www.npmjs.org), and then run `npm install` to install the project's dependencies. + +If you want to try out a demo playground for the component: +1. Start the server by running `npm run server`. +2. Open the demo page in your browser at the address printed to your console. + +**Tests** are broken up into two parts. We are currently porting the existing test suite from Grunt & Jasmine to Jest. +- To run all tests, run `npm test`. +- To only run the new tests, run `npm run jest`. +- To only run the old tests, run `npx grunt jasmine:test`. +- To run & debug the old tests interactively in your browser, run: `npx grunt jasmine:interactive` and load the URL it prints out in your browser. + +**Any time you make changes, you’ll need to re-build the plugin.** Most tests run against the builds, so after making changes, you’ll need to do a build before running tests. +- To do a complete build, run `npm run build` +- To build just the JS: + - `npm run build:js` runs various checks (linting, etc.) and then builds. + - `npm run build:jsfast` *just* builds the JS. This is useful when iterating and testing small changes. Make sure you eventually do a full build with all the checks, though! +- To build just the CSS, run `npm run build:css`. ## Updating to a new version of libphonenumber diff --git a/.npmrc b/.npmrc new file mode 100644 index 000000000..05d694f2b --- /dev/null +++ b/.npmrc @@ -0,0 +1,3 @@ +# Jest uses the `vm` module, which does not have production ready module support +# yet. This option lets us use dynamic imports. +node-options='--experimental-vm-modules' diff --git a/Gruntfile.js b/Gruntfile.js index e11585b53..c667ffe44 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -28,8 +28,21 @@ module.exports = function(grunt) { // just vue grunt.registerTask('vue', ['replace:vueWithUtils', 'shell:buildVue', 'replace:removeImport']); + // Run tests with a server so that async imports/fetches work. + grunt.registerTask('jasmine:test', ['connect:test', 'jasmine']); + grunt.registerTask('jasmine:interactive', () => { + grunt.event.once('connect.test.listening', (host, port) => { + const origin = `http://${host === '::' ? 'localhost' : host}:${port}`; + console.log(` + To view and debug tests in your browser, go to ${origin}/spec.html + To play with a demo of the package, go to ${origin}/demo.html + `); + }); + grunt.task.run('connect:test:keepalive'); + }); + // Travis CI - grunt.registerTask('travis', ['jasmine']); + grunt.registerTask('travis', ['jasmine:test']); // bump version number in 3 files, rebuild js to update headers, then commit, tag and push grunt.registerTask('version', ['shell:test', 'bump-only', 'js', 'bump-commit']); grunt.registerTask('version:minor', ['shell:test', 'bump-only:minor', 'js', 'bump-commit']); diff --git a/README.md b/README.md index 5df0c98be..f88eff583 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ _Note: We have now dropped support for all versions of Internet Explorer because ``` @@ -109,10 +109,21 @@ _Note: We have now dropped support for all versions of Internet Explorer because const input = document.querySelector("#phone"); intlTelInput(input, { - utilsScript: "path/to/utils.js" + loadUtilsOnInit: () => import("intl-tel-input/utils") }); ``` +Most bundlers (such as Webpack, Vite, or Parcel) will see this and place the [utilities script](#utilities-script) in a separate bundle and load it asynchronously, only when needed. If this doesn’t work with your bundler or you want to load the utils module from some other location (such as a CDN) you can set the `loadUtilsOnInit` option to the URL to load from as a string. For example: + +```js +import intlTelInput from 'intl-tel-input'; + +const input = document.querySelector("#phone"); +intlTelInput(input, { + loadUtilsOnInit: `https://cdn.jsdelivr.net/npm/intl-tel-input@${intlTelInput.version}/build/js/utils.js`; +}); +``` + ## Getting Started (Not using a bundler) 1. Download the [latest release](https://github.com/jackocnr/intl-tel-input/releases/latest), or better yet install it with [npm](https://www.npmjs.com/package/intl-tel-input) @@ -137,7 +148,7 @@ _Note: We have now dropped support for all versions of Internet Explorer because ``` @@ -304,6 +315,15 @@ intlTelInput(input, { Type: `String` Default: `""` Set the initial country selection by specifying its country code e.g. `"us"` for the United States. (Be careful not to do this unless you are sure of the user's country, as it can lead to tricky issues if set incorrectly and the user auto-fills their national number and submits the form without checking - in certain cases, this can pass validation and you can end up storing a number with the wrong dial code). You can also set `initialCountry` to `"auto"`, which will look up the user's country based on their IP address (requires the `geoIpLookup` option - [see example](https://intl-tel-input.com/examples/lookup-country.html)). Note that however you use `initialCountry`, it will not update the country selection if the input already contains a number with an international dial code. +**loadUtilsOnInit** +Type: `String` or `() => Promise` Default: `""` Example: `"/build/js/utils.js"` + +This is one way to (lazy) load the included utils.js (to enable formatting/validation etc) - see [Loading The Utilities Script](#loading-the-utilities-script) for more options. You will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `loadUtilsOnInit` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@24.5.2/build/js/utils.js"`. The script is loaded via a [dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) statement, which means the URL cannot be relative - it must be absolute. + +Alternatively, this can be a function that returns a promise for the utils module. When using a bundler like Webpack, this can be used to tell the bundler that the utils script should be kept in a separate file from the rest of your code. For example: `{ loadUtilsOnInit: () => import("intl-tel-input/utils") }`. + +The script is only fetched when you initialise the plugin, and additionally, only when the page has finished loading (on the window load event) to prevent blocking (the script is ~260KB). When instantiating the plugin, a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) object is returned under the `promise` instance property, so you can do something like `iti.promise.then(callback)` to know when initialisation requests like this have finished. See [Utilities Script](#utilities-script) for more information. + **nationalMode** Type: `Boolean` Default: `true` Format numbers in the national format, rather than the international format. This applies to placeholder numbers, and when displaying users' existing numbers. Note that it's fine for users to type their numbers in national format - as long as they have selected the right country, you can use `getNumber` to extract a full international number - [see example](https://intl-tel-input.com/examples/national-mode.html). It is recommended to leave this option enabled, to encourage users to enter their numbers in national format as this is usually more familiar to them and so it creates a better user experience. @@ -334,9 +354,10 @@ As the user types in the input, ignore any irrelevant characters. The user can o Type: `Boolean` Default: `true on mobile devices, false otherwise` Control when the country list appears as a fullscreen popup vs an inline dropdown. By default, it will appear as a fullscreen popup on mobile devices (based on user-agent and screen width), to make better use of the limited space (similar to how a native `").wrap("div"); - }); - - afterEach(function() { - intlTeardown(); - }); - - it("init vanilla plugin does not start loading the utils script", function() { - iti = window.intlTelInput(input[0]); - - expect(window.intlTelInput.startedLoadingUtilsScript).toEqual(false); - }); - - it("init plugin with utilsScript before documentReady event does not inject the script", function() { - window.intlTelInput.documentReady = () => false; - iti = window.intlTelInput(input[0], { - utilsScript: url, - }); - - expect(window.intlTelInput.startedLoadingUtilsScript).toEqual(false); - }); - - it("faking documentReady then init plugin with utilsScript does inject the script", function() { - window.intlTelInput.documentReady = () => true; - iti = window.intlTelInput(input[0], { - utilsScript: url, - }); - - expect(window.intlTelInput.startedLoadingUtilsScript).toEqual(true); - }); - -}); diff --git a/src/spec/tests/static/loadUtils.js b/src/spec/tests/static/loadUtils.js deleted file mode 100644 index fed0791ce..000000000 --- a/src/spec/tests/static/loadUtils.js +++ /dev/null @@ -1,217 +0,0 @@ -// TODO: figure out how to spy on dynamic import to test this, as currently the dyanmic import is failing in the test env. - -// "use strict"; - -// describe("loadUtils:", function() { - -// beforeEach(function() { -// intlSetup(); -// //* Must be in markup for utils loaded handler to work. -// input = $("").appendTo("body"); -// }); - -// afterEach(function() { -// intlTeardown(); -// }); - - - -// describe("calling loadUtils before init plugin", function() { - -// var url = "build/js/utils.js?v=1", -// resolved = false; - -// beforeEach(function(done) { -// var promise = window.intlTelInput.loadUtils(url); -// promise.then(function() { -// resolved = true; -// done(); -// }); -// }); - -// afterEach(function() { -// resolved = false; -// }); - -// it("starts loading the utils", function() { -// expect(window.intlTelInput.startedLoadingUtilsScript).toEqual(true); -// }); - -// it("does resolve the promise", function() { -// expect(resolved).toEqual(true); -// }); - - - -// describe("then init plugin with utilsScript option", function() { - -// var resolved2 = false; - -// beforeEach(function(done) { -// iti = window.intlTelInput(input[0], { -// utilsScript: "some/other/url/ok", -// }); -// iti.promise.then(function() { -// resolved2 = true; -// done(); -// }); -// }); - -// afterEach(function() { -// resolved2 = false; -// }); - -// // TODO: spy on dynamic imports to check if this fired again -// // it("does not start loading the utils", function() { -// // expect($("script.iti-load-utils").length).toEqual(1); -// // expect($("script.iti-load-utils").attr("src")).toEqual(url); -// // }); - -// it("does resolve the promise immediately", function() { -// expect(resolved2).toEqual(true); -// }); - -// }); - -// }); - - - -// describe("init plugin with utilsScript option, but force documentReady=false so it wont fire", function() { - -// var url2 = "build/js/utils.js?v=2", -// resolved = false; - -// beforeEach(function(done) { -// window.intlTelInput.documentReady = () => false; -// iti = window.intlTelInput(input[0], { -// utilsScript: "some/other/url/ok", -// }); -// iti.promise.then(function() { -// resolved = true; -// done(); -// }); -// }); - -// afterEach(function() { -// resolved = false; -// }); - -// it("does not start loading the utils", function() { -// expect(window.intlTelInput.startedLoadingUtilsScript).toEqual(false); -// }); - -// it("does not resolve the promise", function() { -// expect(resolved).toEqual(false); -// }); - - - -// describe("calling loadUtils", function() { - -// var resolved2 = false; - -// beforeEach(function(done) { -// var promise = window.intlTelInput.loadUtils(url2); -// promise.then(function() { -// resolved2 = true; -// done(); -// }); -// }); - -// afterEach(function() { -// resolved2 = false; -// }); - -// it("does start loading the utils", function() { -// expect(window.intlTelInput.startedLoadingUtilsScript).toEqual(true); -// }); - -// it("does resolve the promise", function() { -// expect(resolved2).toEqual(true); -// }); - - - -// describe("then init another plugin instance with utilsScript option", function() { - -// var iti2, -// input2, -// resolved3 = false; - -// beforeEach(function(done) { -// input2 = $("").appendTo("body"); -// iti2 = window.intlTelInput(input2[0], { -// utilsScript: "test/url/three/utils.js", -// }); -// iti2.promise.then(function() { -// resolved3 = true; -// done(); -// }); -// }); - -// afterEach(function() { -// resolved3 = false; -// iti2.destroy(); -// input2.remove(); -// iti2 = input2 = null; -// }); - -// // TODO: spy on dynamic imports to check if this fired again -// // it("does not inject another script", function() { -// // expect($("script.iti-load-utils").length).toEqual(1); -// // expect($("script.iti-load-utils").attr("src")).toEqual(url2); -// // }); - -// it("does resolve the promise immediately", function() { -// expect(resolved3).toEqual(true); -// }); - -// }); - -// }); - -// }); - - - -// describe("force documentReady=true then init plugin with utilsScript", function() { - -// var url3 = "build/js/utils.js?v=3", -// resolved = false; - -// beforeEach(function(done) { -// window.intlTelInput.documentReady = () => true; -// iti = window.intlTelInput(input[0], { -// utilsScript: url3, -// }); -// //* Wait for the request to finish so we don't interfere with other tests. -// iti.promise.then(function() { -// resolved = true; -// done(); -// }); -// }); - -// afterEach(function() { -// resolved = false; -// }); - -// it("resolves the promise immediately", function() { -// expect(resolved).toEqual(true); -// }); - -// it("starts loading the utils", function() { -// expect(window.intlTelInput.startedLoadingUtilsScript).toEqual(true); -// }); - -// // TODO: spy on dynamic imports to check if this fired again -// // it("then calling loadUtils does not inject another script", function() { -// // window.intlTelInput.loadUtils("this/is/a/test"); - -// // expect($("script.iti-load-utils").length).toEqual(1); -// // expect($("script.iti-load-utils").attr("src")).toEqual(url3); -// // }); - -// }); - -// }); diff --git a/tests/helpers/helpers.js b/tests/helpers/helpers.js index a40036f97..98df81543 100644 --- a/tests/helpers/helpers.js +++ b/tests/helpers/helpers.js @@ -1,5 +1,9 @@ require("@testing-library/jest-dom"); -const intlTelInput = require("intlTelInputWithUtils.js"); +const intlTelInputWithUtils = require("intlTelInputWithUtils.js"); + +/** @typedef {typeof import("intl-tel-input").default} IntlTelInputInterface */ +/** @typedef {import("intl-tel-input").Iti} Iti */ +/** @typedef {import("intl-tel-input").SomeOptions} SomeOptions */ exports.totalCountries = 244; @@ -17,19 +21,61 @@ exports.injectInput = ({ inputValue = "", disabled = false } = injectInputDefaul return input; }; -const initPluginDefaults = { input: null, options: {}, inputValue: "" }; - -exports.initPlugin = ({ input = null, options = {}, inputValue = "" } = initPluginDefaults) => { +/** + * Create an intl-tel-input instance to test. + * @param {{intlTelInput?: IntlTelInputInterface, input?: any, inputValue?: string, options?: SomeOptions}} options + * @returns {{input: HTMLInputElement, iti: Iti, container: HTMLElement}} + */ +exports.initPlugin = ({ intlTelInput = intlTelInputWithUtils, input = null, inputValue = "", options = {} } = {}) => { const inputToUse = input || exports.injectInput({ inputValue }); const iti = intlTelInput(inputToUse, options); const container = inputToUse.parentElement; return { input: inputToUse, iti, container }; }; +/** + * Tear down a standard test environment. Optionally takes an intl-tel-input + * instance to tear down, or a copy of the whole library in which to tear down + * all instances. + * @param {Iti|IntlTelInputInterface} iti + */ exports.teardown = (iti) => { - iti.destroy(); + let toDestroy = []; + if (iti?.instances) { + toDestroy = Object.values(iti.instances); + } else if (iti) { + toDestroy = [iti]; + } + + for (const instance of toDestroy) { + // Tests might intentionally set up an instance wrong, so ignore any + // rejections of the instance's promise (otherwise the unhandled + // rejection causes the test to fail). But don't *wait*, since the test + // may also create a state where the promise will never fulfill. + instance.promise.catch(() => {}); + + instance.destroy(); + } + document.body.innerHTML = ""; - jest.clearAllMocks(); + jest.restoreAllMocks(); +}; + +/** + * @param {IntlTelInputInterface} intlTelInput + */ +exports.resetPackageAfterEach = (intlTelInput = intlTelInputWithUtils) => { + const originalUtils = intlTelInput.utils; + + afterEach(function() { + try { + exports.teardown(intlTelInput); + } finally { + // Reset package-wide state. + intlTelInput.utils = originalUtils; + intlTelInput.startedLoadingUtilsScript = false; + } + }); }; exports.getCountryListLength = (container) => { @@ -87,4 +133,4 @@ exports.selectCountryAndTypePlaceholderNumberAsync = async (container, iso2, use }; // strip formatting chars like space, dash, brackets (leaving just numerics and optional plus) -exports.stripFormattingChars = (str) => str.replace(/[^0-9+]/g, ""); \ No newline at end of file +exports.stripFormattingChars = (str) => str.replace(/[^0-9+]/g, ""); diff --git a/tests/helpers/matchers.js b/tests/helpers/matchers.js new file mode 100644 index 000000000..f0f280c0f --- /dev/null +++ b/tests/helpers/matchers.js @@ -0,0 +1,24 @@ +/** Test whether something is a promise. Works across realms. */ +function toBeAPromise(actual) { + const pass = Object.prototype.toString.call(actual) === "[object Promise]"; + return { + pass, + message: () => `expected ${this.utils.printReceived(actual)}${pass ? " not" : ""} to be a promise`, + }; +} + +async function toBePending(actual) { + const pending = Symbol(); + const resolution = await Promise.race([actual, Promise.resolve(pending)]); + const pass = resolution === pending; + + return { + pass, + message: () => `expected ${this.utils.printReceived(actual)}${pass ? " not" : ""} to be a pending`, + }; +} + +expect.extend({ + toBeAPromise, + toBePending, +}); diff --git a/tests/options/loadUtilsOnInit.test.js b/tests/options/loadUtilsOnInit.test.js new file mode 100644 index 000000000..9cc449a81 --- /dev/null +++ b/tests/options/loadUtilsOnInit.test.js @@ -0,0 +1,127 @@ +/** + * @jest-environment jsdom + */ + +const intlTelInput = require("intl-tel-input"); +const { initPlugin, resetPackageAfterEach } = require("../helpers/helpers"); + +describe("loadUtilsOnInit", () => { + resetPackageAfterEach(intlTelInput); + + const loadUtilsOnInit = "intl-tel-input/utils"; + + it("does not load the utils script if `loadUtilsOnInit` option is not set", async () => { + const { iti } = initPlugin({ intlTelInput }); + + expect(intlTelInput).toHaveProperty("startedLoadingUtilsScript", false); + + await iti.promise; + + expect(intlTelInput).toHaveProperty("startedLoadingUtilsScript", false); + }); + + it("loads the utils script successfully", async () => { + expect(intlTelInput).not.toHaveProperty("utils.isValidNumber"); + + const { iti } = initPlugin({ + intlTelInput, + options: { loadUtilsOnInit }, + }); + + await iti.promise; + expect(intlTelInput).toHaveProperty("utils.isValidNumber"); + }); + + it("waits until the page is loaded before loading utils", async () => { + jest.spyOn(intlTelInput, "documentReady").mockReturnValue(false); + + const { iti } = initPlugin({ + intlTelInput, + options: { loadUtilsOnInit }, + }); + + expect(intlTelInput).toHaveProperty("startedLoadingUtilsScript", false); + + const loadEvent = new Event("load"); + window.dispatchEvent(loadEvent); + + expect(intlTelInput).toHaveProperty("startedLoadingUtilsScript", true); + + await iti.promise; + }); + + it("loads utils immediately if page is already finished loading", async function() { + jest.spyOn(intlTelInput, "documentReady").mockReturnValue(true); + + const { iti } = initPlugin({ + intlTelInput, + options: { loadUtilsOnInit }, + }); + + expect(intlTelInput).toHaveProperty("startedLoadingUtilsScript", true); + + await iti.promise; + }); + + it("rejects with an error if the utils script cannot load", async function() { + jest.spyOn(intlTelInput, "documentReady").mockReturnValue(true); + + const { iti } = initPlugin({ + intlTelInput, + options: { loadUtilsOnInit: "/some/incorrect/url" }, + }); + + expect(intlTelInput).toHaveProperty("startedLoadingUtilsScript", true); + + await expect(iti.promise).rejects.toThrow(); + }); + + it("works if loadUtilsOnInit is a function", async function() { + const mockUtils = { default: { mockUtils: true } }; + jest.spyOn(intlTelInput, "documentReady").mockReturnValue(true); + + const { iti } = initPlugin({ + intlTelInput, + options: { + async loadUtilsOnInit () { + return mockUtils; + }, + }, + }); + + expect(intlTelInput).toHaveProperty("startedLoadingUtilsScript", true); + await iti.promise; + + expect(intlTelInput.utils).toBe(mockUtils.default); + }); + + describe("in 'withUtils' builds", () => { + const intlTelInput = require("intl-tel-input/intlTelInputWithUtils"); + resetPackageAfterEach(intlTelInput); + + it("ignores the `loadUtilsOnInit` option and does not load", async () => { + const { iti } = initPlugin({ + intlTelInput, + options: { loadUtilsOnInit }, + }); + + expect(intlTelInput).toHaveProperty("startedLoadingUtilsScript", false); + + await iti.promise; + + expect(intlTelInput).toHaveProperty("startedLoadingUtilsScript", false); + }); + + it("Raises an informative error when `utils` is missing", async () => { + delete intlTelInput.utils; + const { iti } = initPlugin({ + intlTelInput, + options: { loadUtilsOnInit }, + }); + + expect(intlTelInput).toHaveProperty("startedLoadingUtilsScript", true); + await expect(iti.promise).rejects.toThrow("INTENTIONALLY BROKEN"); + }); + }); + +}); diff --git a/tests/static/loadUtils.test.js b/tests/static/loadUtils.test.js new file mode 100644 index 000000000..4d8025d44 --- /dev/null +++ b/tests/static/loadUtils.test.js @@ -0,0 +1,198 @@ +/** + * @jest-environment jsdom + */ + +const intlTelInput = require("intl-tel-input"); +const { initPlugin, resetPackageAfterEach } = require("../helpers/helpers"); +require("../helpers/matchers"); + +describe("loadUtils", function() { + resetPackageAfterEach(intlTelInput); + + describe("calling loadUtils before init plugin", () => { + + let url = "./utils.js?v=1"; + let loadResult; + + beforeEach(() => { + loadResult = intlTelInput.loadUtils(url); + loadResult.catch(() => {}); + }); + + it("starts loading the utils", () => { + expect(intlTelInput).toHaveProperty("startedLoadingUtilsScript", true); + }); + + it("resolves the promise", async () => { + expect(loadResult).toBeAPromise(); + await expect(loadResult).resolves.toBe(true); + }); + + it("installs the utils module at intlTelInput.utils", async () => { + await loadResult; + + expect(intlTelInput).toHaveProperty("utils.isValidNumber"); + }); + + describe("then init plugin with loadUtilsOnInit option", () => { + + it("resolves the instance's promise", async () => { + const { iti } = initPlugin({ + intlTelInput, + options: { loadUtilsOnInit: "some/other/url/ok" } + }); + await iti.promise; + }); + + }); + + }); + + + + describe("init plugin with loadUtilsOnInit option, but force documentReady=false so it wont fire", function() { + /** @type {jest.Mock<() => Promise>} */ + let utilsLoader; + /** @type {intlTelInput.Iti} */ + let iti; + + beforeEach(function() { + jest.spyOn(intlTelInput, "documentReady").mockReturnValue(false); + utilsLoader = jest.fn(async () => import("intl-tel-input/utils")); + + ({ iti } = initPlugin({ + intlTelInput, + options: { loadUtilsOnInit: utilsLoader }, + })); + }); + + it("does not start loading the utils", function() { + expect(intlTelInput).toHaveProperty("startedLoadingUtilsScript", false); + }); + + it("does not resolve the promise", async function() { + await expect(iti.promise).toBePending(); + }); + + + + describe("calling loadUtils", function() { + /** @type {Promise} */ + let loadUtilsPromise; + + beforeEach(async function() { + loadUtilsPromise = intlTelInput.loadUtils(utilsLoader); + }); + + it("starts loading the utils", function() { + expect(intlTelInput).toHaveProperty("startedLoadingUtilsScript", true); + }); + + it("resolves the promise", async function() { + await expect(loadUtilsPromise).resolves.toBe(true); + }); + + + + describe("then init another plugin instance with loadUtilsOnInit option", function() { + + beforeEach(async function() { + // Wait for previous load to finish. + await loadUtilsPromise; + + initPlugin({ + intlTelInput, + options: { loadUtilsOnInit: utilsLoader }, + }); + }); + + it("only loads once", function() { + expect(utilsLoader).toHaveBeenCalledTimes(1); + }); + + }); + + }); + + }); + + + + describe("force documentReady=true then init plugin with loadUtilsOnInit", function() { + + const url3 = "./utils.js?v=3"; + /** @type {intlTelInput.Iti} */ + let iti; + + beforeEach(function() { + jest.spyOn(intlTelInput, "documentReady").mockReturnValue(true); + ({ iti } = initPlugin({ + intlTelInput, + options: { loadUtilsOnInit: url3 }, + })); + }); + + it("resolves the promise immediately", async function() { + await expect(iti.promise).resolves.toBeInstanceOf(Array); + }); + + it("starts loading the utils", function() { + expect(intlTelInput).toHaveProperty("startedLoadingUtilsScript", true); + }); + + }); + + + + describe("calling with a function", function() { + const mockUtils = { default: { mymodule: "fakeutils" } }; + + it("uses the object the function resolves with", async () => { + const result = await intlTelInput.loadUtils(async () => mockUtils); + + expect(result).toEqual(true); + expect(intlTelInput.utils).toBe(mockUtils.default); + }); + + it("rejects if the function rejects", async () => { + const loadPromise = intlTelInput.loadUtils(async () => { + throw new Error("Uhoh!"); + }); + + await expect(loadPromise).rejects.toThrow("Uhoh!"); + }); + + it("rejects if the function throws", async () => { + const loadPromise = intlTelInput.loadUtils(() => { + throw new Error("Uhoh!"); + }); + + await expect(loadPromise).rejects.toThrow("Uhoh!"); + }); + + it("rejects if the function returns a non-promise", async () => { + const loadPromise = intlTelInput.loadUtils(() => ({ + anObject: "That is not a promise", + })); + + await expect(loadPromise).rejects.toThrow(); + }); + + it("rejects if the function resolves to a non-object", async () => { + const loadPromise = intlTelInput.loadUtils(async () => "Hello!"); + + await expect(loadPromise).rejects.toThrow(); + }); + + it("does not call the function a second time", async () => { + const loader = jest.fn(async () => mockUtils); + + await intlTelInput.loadUtils(loader); + await intlTelInput.loadUtils(loader); + + expect(loader).toHaveBeenCalledTimes(1); + }); + + }); + +}); diff --git a/vue/build/IntlTelInput.mjs b/vue/build/IntlTelInput.mjs index 709b017ce..7199c038e 100644 --- a/vue/build/IntlTelInput.mjs +++ b/vue/build/IntlTelInput.mjs @@ -1,4 +1,4 @@ -import { mergeModels as D, useModel as x, ref as v, onMounted as E, watch as M, onUnmounted as F, withDirectives as B, openBlock as O, createElementBlock as V, mergeProps as z, vModelText as R } from "vue"; +import { mergeModels as D, useModel as x, ref as v, onMounted as E, watch as M, onUnmounted as O, withDirectives as F, openBlock as B, createElementBlock as V, mergeProps as z, vModelText as R } from "vue"; const N = [ [ "af", @@ -1318,7 +1318,7 @@ for (let u = 0; u < N.length; u++) { nodeById: {} }; } -const $ = { +const j = { ad: "Andorra", ae: "United Arab Emirates", af: "Afghanistan", @@ -1561,7 +1561,7 @@ const $ = { za: "South Africa", zm: "Zambia", zw: "Zimbabwe" -}, j = { +}, $ = { selectedCountryAriaLabel: "Selected country", noCountrySelected: "No country selected", countryListAriaLabel: "List of countries", @@ -1572,10 +1572,10 @@ const $ = { // additional countries (not supported by country-list library) ac: "Ascension Island", xk: "Kosovo" -}, k = { ...$, ...j }; +}, k = { ...j, ...$ }; for (let u = 0; u < b.length; u++) b[u].name = k[b[u].iso2]; -let K = 0; +let U = 0; const T = { //* Whether or not to allow the dropdown. allowDropdown: !0, @@ -1607,6 +1607,8 @@ const T = { i18n: {}, //* Initial country. initialCountry: "", + //* Specify the path to the libphonenumber script to enable validation/formatting. + loadUtilsOnInit: "", //* National vs international formatting for numbers e.g. placeholders and displaying existing numbers. nationalMode: !0, //* Display only these countries. @@ -1627,11 +1629,11 @@ const T = { navigator.userAgent ) || window.innerWidth <= 500 ) : !1, - //* Specify the path to the libphonenumber script to enable validation/formatting. + //* Deprecated! Use `loadUtilsOnInit` instead. utilsScript: "", //* The number type to enforce during validation. validationNumberType: "MOBILE" -}, U = [ +}, K = [ "800", "822", "833", @@ -1649,11 +1651,11 @@ const T = { "887", "888", "889" -], w = (u) => u.replace(/\D/g, ""), A = (u = "") => u.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), S = (u) => { - const t = w(u); +], I = (u) => u.replace(/\D/g, ""), A = (u = "") => u.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), S = (u) => { + const t = I(u); if (t.charAt(0) === "1") { const e = t.substr(1, 3); - return U.indexOf(e) !== -1; + return K.indexOf(e) !== -1; } return !1; }, H = (u, t, e, i) => { @@ -1670,13 +1672,13 @@ const T = { }, y = (u, t, e) => { const i = document.createElement(u); return t && Object.entries(t).forEach(([s, n]) => i.setAttribute(s, n)), e && e.appendChild(i), i; -}, _ = (u) => { - const { instances: t } = l; - Object.values(t).forEach((e) => e[u]()); +}, _ = (u, ...t) => { + const { instances: e } = l; + Object.values(e).forEach((i) => i[u](...t)); }; class G { constructor(t, e = {}) { - this.id = K++, this.telInput = t, this.highlightedItem = null, this.options = Object.assign({}, T, e), this.hadInitialPlaceholder = !!t.getAttribute("placeholder"); + this.id = U++, this.telInput = t, this.highlightedItem = null, this.options = Object.assign({}, T, e), this.hadInitialPlaceholder = !!t.getAttribute("placeholder"); } //* Can't be private as it's called from intlTelInput convenience wrapper. _init() { @@ -1936,10 +1938,12 @@ class G { } //* Init many requests: utils script / geo ip lookup. _initRequests() { - const { utilsScript: t, initialCountry: e, geoIpLookup: i } = this.options; - t && !l.utils ? l.documentReady() ? l.loadUtils(t) : window.addEventListener("load", () => { - l.loadUtils(t); - }) : this.resolveUtilsScriptPromise(), e === "auto" && i && !this.selectedCountryData.iso2 ? this._loadAutoCountry() : this.resolveAutoCountryPromise(); + let { loadUtilsOnInit: t, utilsScript: e, initialCountry: i, geoIpLookup: s } = this.options; + !t && e && (console.warn("intl-tel-input: The `utilsScript` option is deprecated and will be removed in a future release! Please use the `loadUtilsOnInit` option instead."), t = e), t && !l.utils ? (this._handlePageLoad = () => { + var o; + window.removeEventListener("load", this._handlePageLoad), (o = l.loadUtils(t)) == null || o.catch(() => { + }); + }, l.documentReady() ? this._handlePageLoad() : window.addEventListener("load", this._handlePageLoad)) : this.resolveUtilsScriptPromise(), i === "auto" && s && !this.selectedCountryData.iso2 ? this._loadAutoCountry() : this.resolveAutoCountryPromise(); } //* Perform the geo ip lookup. _loadAutoCountry() { @@ -1971,8 +1975,8 @@ class G { p || c && !t ? a = !0 : /[^+0-9]/.test(this.telInput.value) || (a = !1); const d = (r == null ? void 0 : r.detail) && r.detail.isSetNumber && !s; if (e && !a && !d) { - const C = this.telInput.selectionStart || 0, m = this.telInput.value.substring(0, C).replace(/[^+0-9]/g, "").length, f = (r == null ? void 0 : r.inputType) === "deleteContentForward", g = this._formatNumberAsYouType(), I = H(m, g, C, f); - this.telInput.value = g, this.telInput.setSelectionRange(I, I); + const C = this.telInput.selectionStart || 0, m = this.telInput.value.substring(0, C).replace(/[^+0-9]/g, "").length, f = (r == null ? void 0 : r.inputType) === "deleteContentForward", g = this._formatNumberAsYouType(), w = H(m, g, C, f); + this.telInput.value = g, this.telInput.setSelectionRange(w, w); } }, this.telInput.addEventListener("input", this._handleInputEvent), (t || i) && (this._handleKeydownEvent = (r) => { if (r.key && r.key.length === 1 && !r.altKey && !r.ctrlKey && !r.metaKey) { @@ -1981,13 +1985,13 @@ class G { return; } if (t) { - const p = this.telInput.value, c = p.charAt(0) === "+", d = !c && this.telInput.selectionStart === 0 && r.key === "+", C = /^[0-9]$/.test(r.key), h = i ? C : d || C, m = p.slice(0, this.telInput.selectionStart) + r.key + p.slice(this.telInput.selectionEnd), f = this._getFullNumber(m), g = l.utils.getCoreNumber(f, this.selectedCountryData.iso2), I = this.maxCoreNumberLength && g.length > this.maxCoreNumberLength; + const p = this.telInput.value, c = p.charAt(0) === "+", d = !c && this.telInput.selectionStart === 0 && r.key === "+", C = /^[0-9]$/.test(r.key), h = i ? C : d || C, m = p.slice(0, this.telInput.selectionStart) + r.key + p.slice(this.telInput.selectionEnd), f = this._getFullNumber(m), g = l.utils.getCoreNumber(f, this.selectedCountryData.iso2), w = this.maxCoreNumberLength && g.length > this.maxCoreNumberLength; let L = !1; if (c) { const P = this.selectedCountryData.iso2; L = this._getCountryFromNumber(f) !== P; } - (!h || I && !L && !d) && r.preventDefault(); + (!h || w && !L && !d) && r.preventDefault(); } } }, this.telInput.addEventListener("keydown", this._handleKeydownEvent)); @@ -2127,9 +2131,9 @@ class G { let i = e ? t.substring(e) : t; const s = this.selectedCountryData.dialCode; i && s === "1" && i.charAt(0) !== "+" && (i.charAt(0) !== "1" && (i = `1${i}`), i = `+${i}`), this.options.separateDialCode && s && i.charAt(0) !== "+" && (i = `+${s}${i}`); - const o = this._getDialCode(i, !0), a = w(i); + const o = this._getDialCode(i, !0), a = I(i); if (o) { - const r = this.dialCodeToIso2Map[w(o)], p = r.indexOf(this.selectedCountryData.iso2) !== -1 && a.length <= o.length - 1; + const r = this.dialCodeToIso2Map[I(o)], p = r.indexOf(this.selectedCountryData.iso2) !== -1 && a.length <= o.length - 1; if (!(s === "1" && S(a)) && !p) { for (let d = 0; d < r.length; d++) if (r[d]) @@ -2259,7 +2263,7 @@ class G { ), this.countryList.removeEventListener( "mouseover", this._handleMouseoverCountryList - ), this.countryList.removeEventListener("click", this._handleClickCountryList), this.options.dropdownContainer && (this.options.useFullscreenPopup || window.removeEventListener("scroll", this._handleWindowScroll), this.dropdown.parentNode && this.dropdown.parentNode.removeChild(this.dropdown)), this._trigger("close:countrydropdown"); + ), this.countryList.removeEventListener("click", this._handleClickCountryList), this.options.dropdownContainer && (this.options.useFullscreenPopup || window.removeEventListener("scroll", this._handleWindowScroll), this.dropdown.parentNode && this.dropdown.parentNode.removeChild(this.dropdown)), this._handlePageLoad && window.removeEventListener("load", this._handlePageLoad), this._trigger("close:countrydropdown"); } //* Check if an element is visible within it's container, else scroll until it is. _scrollTo(t) { @@ -2307,7 +2311,7 @@ class G { _getFullNumber(t) { const e = t || this.telInput.value.trim(), { dialCode: i } = this.selectedCountryData; let s; - const n = w(e); + const n = I(e); return this.options.separateDialCode && e.charAt(0) !== "+" && i && n ? s = `+${i}` : s = "", s + e; } //* Remove the dial code if separateDialCode is enabled also cap the length if the input has a maxlength attribute @@ -2450,17 +2454,35 @@ class G { this.telInput.disabled = t, t ? this.selectedCountry.setAttribute("disabled", "true") : this.selectedCountry.removeAttribute("disabled"); } } -const W = (u) => !l.utils && !l.startedLoadingUtilsScript ? (l.startedLoadingUtilsScript = !0, new Promise((t, e) => { - import( - /* webpackIgnore: true */ - /* @vite-ignore */ - u - ).then(({ default: i }) => { - l.utils = i, _("handleUtils"), t(!0); - }).catch(() => { - _("rejectUtilsScriptPromise"), e(); - }); -})) : null, l = Object.assign( +const W = (u) => { + if (!l.utils && !l.startedLoadingUtilsScript) { + let t; + if (typeof u == "string") + t = import( + /* webpackIgnore: true */ + /* @vite-ignore */ + u + ); + else if (typeof u == "function") + try { + if (t = u(), !(t instanceof Promise)) + throw new TypeError(`The function passed to loadUtils must return a promise for the utilities module, not ${typeof t}`); + } catch (e) { + return Promise.reject(e); + } + else + return Promise.reject(new TypeError(`The argument passed to loadUtils must be a URL string or a function that returns a promise for the utilities module, not ${typeof u}`)); + return l.startedLoadingUtilsScript = !0, t.then((e) => { + const i = e == null ? void 0 : e.default; + if (!i || typeof i != "object") + throw typeof u == "string" ? new TypeError(`The module loaded from ${u} did not set utils as its default export.`) : new TypeError("The loader function passed to loadUtils did not resolve to a module object with utils as its default export."); + return l.utils = i, _("handleUtils"), !0; + }).catch((e) => { + throw _("rejectUtilsScriptPromise", e), e; + }); + } + return null; +}, l = Object.assign( (u, t) => { const e = new G(u, t); return e._init(), u.setAttribute("data-intl-tel-input-id", e.id.toString()), l.instances[e.id] = e, e; @@ -2479,6 +2501,8 @@ const W = (u) => !l.utils && !l.startedLoadingUtilsScript ? (l.startedLoadingUti //* A map from instance ID to instance object. instances: {}, loadUtils: W, + startedLoadingUtilsScript: !1, + startedLoadingAutoCountry: !1, version: "24.5.2" } ), J = { @@ -2535,10 +2559,10 @@ const W = (u) => !l.utils && !l.startedLoadingUtilsScript ? (l.startedLoadingUti var m; return (m = a.value) == null ? void 0 : m.setDisabled(h); } - ), F(() => { + ), O(() => { var h; return (h = a.value) == null ? void 0 : h.destroy(); - }), t({ instance: a, input: o }), (h, m) => B((O(), V("input", z({ + }), t({ instance: a, input: o }), (h, m) => F((B(), V("input", z({ ref_key: "input", ref: o, "onUpdate:modelValue": m[0] || (m[0] = (f) => i.value = f), diff --git a/vue/build/IntlTelInputWithUtils.mjs b/vue/build/IntlTelInputWithUtils.mjs index c9c4b5c1f..d4ca8900b 100644 --- a/vue/build/IntlTelInputWithUtils.mjs +++ b/vue/build/IntlTelInputWithUtils.mjs @@ -1,5 +1,5 @@ -import { mergeModels as n2, useModel as A2, ref as I1, onMounted as L2, watch as T2, onUnmounted as E2, withDirectives as D2, openBlock as M2, createElementBlock as x2, mergeProps as P2, vModelText as R2 } from "vue"; -const i2 = [ +import { mergeModels as i2, useModel as T2, ref as I1, onMounted as N2, watch as A2, onUnmounted as E2, withDirectives as D2, openBlock as M2, createElementBlock as P2, mergeProps as x2, vModelText as R2 } from "vue"; +const n2 = [ [ "af", // Afghanistan @@ -1306,8 +1306,8 @@ const i2 = [ "263" ] ], H = []; -for (let y = 0; y < i2.length; y++) { - const e = i2[y]; +for (let y = 0; y < n2.length; y++) { + const e = n2[y]; H[y] = { name: "", // this is now populated in the plugin @@ -1607,6 +1607,8 @@ const u2 = { i18n: {}, //* Initial country. initialCountry: "", + //* Specify the path to the libphonenumber script to enable validation/formatting. + loadUtilsOnInit: "", //* National vs international formatting for numbers e.g. placeholders and displaying existing numbers. nationalMode: !0, //* Display only these countries. @@ -1627,7 +1629,7 @@ const u2 = { navigator.userAgent ) || window.innerWidth <= 500 ) : !1, - //* Specify the path to the libphonenumber script to enable validation/formatting. + //* Deprecated! Use `loadUtilsOnInit` instead. utilsScript: "", //* The number type to enforce during validation. validationNumberType: "MOBILE" @@ -1652,43 +1654,43 @@ const u2 = { ], f1 = (y) => y.replace(/\D/g, ""), r2 = (y = "") => y.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), s2 = (y) => { const e = f1(y); if (e.charAt(0) === "1") { - const n = e.substr(1, 3); - return G2.indexOf(n) !== -1; + const i = e.substr(1, 3); + return G2.indexOf(i) !== -1; } return !1; -}, F2 = (y, e, n, r) => { - if (n === 0 && !r) +}, U2 = (y, e, i, n) => { + if (i === 0 && !n) return 0; let o = 0; for (let a = 0; a < e.length; a++) { - if (/[+0-9]/.test(e[a]) && o++, o === y && !r) + if (/[+0-9]/.test(e[a]) && o++, o === y && !n) return a + 1; - if (r && o === y + 1) + if (n && o === y + 1) return a; } return e.length; -}, T = (y, e, n) => { - const r = document.createElement(y); - return e && Object.entries(e).forEach(([o, a]) => r.setAttribute(o, a)), n && n.appendChild(r), r; -}, $1 = (y) => { - const { instances: e } = C; - Object.values(e).forEach((n) => n[y]()); +}, A = (y, e, i) => { + const n = document.createElement(y); + return e && Object.entries(e).forEach(([o, a]) => n.setAttribute(o, a)), i && i.appendChild(n), n; +}, $1 = (y, ...e) => { + const { instances: i } = m; + Object.values(i).forEach((n) => n[y](...e)); }; -class U2 { - constructor(e, n = {}) { - this.id = O2++, this.telInput = e, this.highlightedItem = null, this.options = Object.assign({}, u2, n), this.hadInitialPlaceholder = !!e.getAttribute("placeholder"); +class F2 { + constructor(e, i = {}) { + this.id = O2++, this.telInput = e, this.highlightedItem = null, this.options = Object.assign({}, u2, i), this.hadInitialPlaceholder = !!e.getAttribute("placeholder"); } //* Can't be private as it's called from intlTelInput convenience wrapper. _init() { this.options.useFullscreenPopup && (this.options.fixDropdownWidth = !1), this.options.onlyCountries.length === 1 && (this.options.initialCountry = this.options.onlyCountries[0]), this.options.separateDialCode && (this.options.nationalMode = !1), this.options.allowDropdown && !this.options.showFlags && !this.options.separateDialCode && (this.options.nationalMode = !1), this.options.useFullscreenPopup && !this.options.dropdownContainer && (this.options.dropdownContainer = document.body), this.isAndroid = typeof navigator < "u" ? /Android/i.test(navigator.userAgent) : !1, this.isRTL = !!this.telInput.closest("[dir=rtl]"); const e = this.options.allowDropdown || this.options.separateDialCode; this.showSelectedCountryOnLeft = this.isRTL ? !e : e, this.options.separateDialCode && (this.isRTL ? this.originalPaddingRight = this.telInput.style.paddingRight : this.originalPaddingLeft = this.telInput.style.paddingLeft), this.options.i18n = { ...o2, ...this.options.i18n }; - const n = new Promise((o, a) => { + const i = new Promise((o, a) => { this.resolveAutoCountryPromise = o, this.rejectAutoCountryPromise = a; - }), r = new Promise((o, a) => { + }), n = new Promise((o, a) => { this.resolveUtilsScriptPromise = o, this.rejectUtilsScriptPromise = a; }); - this.promise = Promise.all([n, r]), this.selectedCountryData = {}, this._processCountryData(), this._generateMarkup(), this._setInitialState(), this._initListeners(), this._initRequests(); + this.promise = Promise.all([i, n]), this.selectedCountryData = {}, this._processCountryData(), this._generateMarkup(), this._setInitialState(), this._initListeners(), this._initRequests(); } //******************** //* PRIVATE METHODS @@ -1699,41 +1701,41 @@ class U2 { } //* Sort countries by countryOrder option (if present), then name. _sortCountries() { - this.options.countryOrder && (this.options.countryOrder = this.options.countryOrder.map((e) => e.toLowerCase())), this.countries.sort((e, n) => { - const { countryOrder: r } = this.options; - if (r) { - const o = r.indexOf(e.iso2), a = r.indexOf(n.iso2), c = o > -1, g = a > -1; + this.options.countryOrder && (this.options.countryOrder = this.options.countryOrder.map((e) => e.toLowerCase())), this.countries.sort((e, i) => { + const { countryOrder: n } = this.options; + if (n) { + const o = n.indexOf(e.iso2), a = n.indexOf(i.iso2), c = o > -1, g = a > -1; if (c || g) return c && g ? o - a : c ? -1 : 1; } - return e.name.localeCompare(n.name); + return e.name.localeCompare(i.name); }); } //* Add a dial code to this.dialCodeToIso2Map. - _addToDialCodeMap(e, n, r) { - n.length > this.dialCodeMaxLen && (this.dialCodeMaxLen = n.length), this.dialCodeToIso2Map.hasOwnProperty(n) || (this.dialCodeToIso2Map[n] = []); - for (let a = 0; a < this.dialCodeToIso2Map[n].length; a++) - if (this.dialCodeToIso2Map[n][a] === e) + _addToDialCodeMap(e, i, n) { + i.length > this.dialCodeMaxLen && (this.dialCodeMaxLen = i.length), this.dialCodeToIso2Map.hasOwnProperty(i) || (this.dialCodeToIso2Map[i] = []); + for (let a = 0; a < this.dialCodeToIso2Map[i].length; a++) + if (this.dialCodeToIso2Map[i][a] === e) return; - const o = r !== void 0 ? r : this.dialCodeToIso2Map[n].length; - this.dialCodeToIso2Map[n][o] = e; + const o = n !== void 0 ? n : this.dialCodeToIso2Map[i].length; + this.dialCodeToIso2Map[i][o] = e; } //* Process onlyCountries or excludeCountries array if present. _processAllCountries() { - const { onlyCountries: e, excludeCountries: n } = this.options; + const { onlyCountries: e, excludeCountries: i } = this.options; if (e.length) { - const r = e.map( + const n = e.map( (o) => o.toLowerCase() ); this.countries = H.filter( - (o) => r.indexOf(o.iso2) > -1 + (o) => n.indexOf(o.iso2) > -1 ); - } else if (n.length) { - const r = n.map( + } else if (i.length) { + const n = i.map( (o) => o.toLowerCase() ); this.countries = H.filter( - (o) => r.indexOf(o.iso2) === -1 + (o) => n.indexOf(o.iso2) === -1 ); } else this.countries = H; @@ -1741,28 +1743,28 @@ class U2 { //* Translate Countries by object literal provided on config. _translateCountryNames() { for (let e = 0; e < this.countries.length; e++) { - const n = this.countries[e].iso2.toLowerCase(); - this.options.i18n.hasOwnProperty(n) && (this.countries[e].name = this.options.i18n[n]); + const i = this.countries[e].iso2.toLowerCase(); + this.options.i18n.hasOwnProperty(i) && (this.countries[e].name = this.options.i18n[i]); } } //* Generate this.dialCodes and this.dialCodeToIso2Map. _processDialCodes() { this.dialCodes = {}, this.dialCodeMaxLen = 0, this.dialCodeToIso2Map = {}; for (let e = 0; e < this.countries.length; e++) { - const n = this.countries[e]; - this.dialCodes[n.dialCode] || (this.dialCodes[n.dialCode] = !0), this._addToDialCodeMap(n.iso2, n.dialCode, n.priority); + const i = this.countries[e]; + this.dialCodes[i.dialCode] || (this.dialCodes[i.dialCode] = !0), this._addToDialCodeMap(i.iso2, i.dialCode, i.priority); } for (let e = 0; e < this.countries.length; e++) { - const n = this.countries[e]; - if (n.areaCodes) { - const r = this.dialCodeToIso2Map[n.dialCode][0]; - for (let o = 0; o < n.areaCodes.length; o++) { - const a = n.areaCodes[o]; + const i = this.countries[e]; + if (i.areaCodes) { + const n = this.dialCodeToIso2Map[i.dialCode][0]; + for (let o = 0; o < i.areaCodes.length; o++) { + const a = i.areaCodes[o]; for (let c = 1; c < a.length; c++) { - const g = n.dialCode + a.substr(0, c); - this._addToDialCodeMap(r, g), this._addToDialCodeMap(n.iso2, g); + const g = i.dialCode + a.substr(0, c); + this._addToDialCodeMap(n, g), this._addToDialCodeMap(i.iso2, g); } - this._addToDialCodeMap(n.iso2, n.dialCode + a); + this._addToDialCodeMap(i.iso2, i.dialCode + a); } } } @@ -1773,8 +1775,8 @@ class U2 { this.telInput.classList.add("iti__tel-input"), !this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete")) && this.telInput.setAttribute("autocomplete", "off"); const { allowDropdown: e, - separateDialCode: n, - showFlags: r, + separateDialCode: i, + showFlags: n, containerClass: o, hiddenInput: a, dropdownContainer: c, @@ -1784,14 +1786,14 @@ class U2 { i18n: _ } = this.options; let I = "iti"; - e && (I += " iti--allow-dropdown"), r && (I += " iti--show-flags"), o && (I += ` ${o}`), f || (I += " iti--inline-dropdown"); - const N = T("div", { class: I }); - if ((v = this.telInput.parentNode) == null || v.insertBefore(N, this.telInput), e || r || n) { - this.countryContainer = T( + e && (I += " iti--allow-dropdown"), n && (I += " iti--show-flags"), o && (I += ` ${o}`), f || (I += " iti--inline-dropdown"); + const L = A("div", { class: I }); + if ((v = this.telInput.parentNode) == null || v.insertBefore(L, this.telInput), e || n || i) { + this.countryContainer = A( "div", { class: "iti__country-container" }, - N - ), this.showSelectedCountryOnLeft ? this.countryContainer.style.left = "0px" : this.countryContainer.style.right = "0px", e ? (this.selectedCountry = T( + L + ), this.showSelectedCountryOnLeft ? this.countryContainer.style.left = "0px" : this.countryContainer.style.right = "0px", e ? (this.selectedCountry = A( "button", { type: "button", @@ -1803,30 +1805,30 @@ class U2 { role: "combobox" }, this.countryContainer - ), this.telInput.disabled && this.selectedCountry.setAttribute("disabled", "true")) : this.selectedCountry = T( + ), this.telInput.disabled && this.selectedCountry.setAttribute("disabled", "true")) : this.selectedCountry = A( "div", { class: "iti__selected-country" }, this.countryContainer ); - const A = T("div", { class: "iti__selected-country-primary" }, this.selectedCountry); - if (this.selectedCountryInner = T("div", { class: "iti__flag" }, A), this.selectedCountryA11yText = T( + const T = A("div", { class: "iti__selected-country-primary" }, this.selectedCountry); + if (this.selectedCountryInner = A("div", { class: "iti__flag" }, T), this.selectedCountryA11yText = A( "span", { class: "iti__a11y-text" }, this.selectedCountryInner - ), e && (this.dropdownArrow = T( + ), e && (this.dropdownArrow = A( "div", { class: "iti__arrow", "aria-hidden": "true" }, - A - )), n && (this.selectedDialCode = T( + T + )), i && (this.selectedDialCode = A( "div", { class: "iti__selected-dial-code" }, this.selectedCountry )), e) { const M = g ? "" : "iti--flexible-dropdown-width"; - if (this.dropdownContent = T("div", { + if (this.dropdownContent = A("div", { id: `iti-${this.id}__dropdown-content`, class: `iti__dropdown-content iti__hide ${M}` - }), b && (this.searchInput = T( + }), b && (this.searchInput = A( "input", { type: "text", @@ -1840,11 +1842,11 @@ class U2 { autocomplete: "off" }, this.dropdownContent - ), this.searchResultsA11yText = T( + ), this.searchResultsA11yText = A( "span", { class: "iti__a11y-text" }, this.dropdownContent - )), this.countryList = T( + )), this.countryList = A( "ul", { class: "iti__country-list", @@ -1855,48 +1857,48 @@ class U2 { this.dropdownContent ), this._appendListItems(), b && this._updateSearchResultsText(), c) { let O = "iti iti--container"; - f ? O += " iti--fullscreen-popup" : O += " iti--inline-dropdown", this.dropdown = T("div", { class: O }), this.dropdown.appendChild(this.dropdownContent); + f ? O += " iti--fullscreen-popup" : O += " iti--inline-dropdown", this.dropdown = A("div", { class: O }), this.dropdown.appendChild(this.dropdownContent); } else this.countryContainer.appendChild(this.dropdownContent); } } - if (N.appendChild(this.telInput), this._updateInputPadding(), a) { - const A = this.telInput.getAttribute("name") || "", M = a(A); - M.phone && (this.hiddenInput = T("input", { + if (L.appendChild(this.telInput), this._updateInputPadding(), a) { + const T = this.telInput.getAttribute("name") || "", M = a(T); + M.phone && (this.hiddenInput = A("input", { type: "hidden", name: M.phone - }), N.appendChild(this.hiddenInput)), M.country && (this.hiddenInputCountry = T("input", { + }), L.appendChild(this.hiddenInput)), M.country && (this.hiddenInputCountry = A("input", { type: "hidden", name: M.country - }), N.appendChild(this.hiddenInputCountry)); + }), L.appendChild(this.hiddenInputCountry)); } } //* For each country: add a country list item
  • to the countryList
      container. _appendListItems() { for (let e = 0; e < this.countries.length; e++) { - const n = this.countries[e], r = e === 0 ? "iti__highlight" : "", o = T( + const i = this.countries[e], n = e === 0 ? "iti__highlight" : "", o = A( "li", { - id: `iti-${this.id}__item-${n.iso2}`, - class: `iti__country ${r}`, + id: `iti-${this.id}__item-${i.iso2}`, + class: `iti__country ${n}`, tabindex: "-1", role: "option", - "data-dial-code": n.dialCode, - "data-country-code": n.iso2, + "data-dial-code": i.dialCode, + "data-country-code": i.iso2, "aria-selected": "false" }, this.countryList ); - n.nodeById[this.id] = o; + i.nodeById[this.id] = o; let a = ""; - this.options.showFlags && (a += `
      `), a += `${n.name}`, a += `+${n.dialCode}`, o.insertAdjacentHTML("beforeend", a); + this.options.showFlags && (a += `
      `), a += `${i.name}`, a += `+${i.dialCode}`, o.insertAdjacentHTML("beforeend", a); } } //* Set the initial state of the input value and the selected country by: //* 1. Extracting a dial code from the given number //* 2. Using explicit initialCountry _setInitialState(e = !1) { - const n = this.telInput.getAttribute("value"), r = this.telInput.value, a = n && n.charAt(0) === "+" && (!r || r.charAt(0) !== "+") ? n : r, c = this._getDialCode(a), g = s2(a), { initialCountry: f, geoIpLookup: b } = this.options, _ = f === "auto" && b; + const i = this.telInput.getAttribute("value"), n = this.telInput.value, a = i && i.charAt(0) === "+" && (!n || n.charAt(0) !== "+") ? i : n, c = this._getDialCode(a), g = s2(a), { initialCountry: f, geoIpLookup: b } = this.options, _ = f === "auto" && b; if (c && !g) this._updateCountryFromNumber(a); else if (!_ || e) { @@ -1921,14 +1923,14 @@ class U2 { } //* initialise the dropdown listeners. _initDropdownListeners() { - this._handleLabelClick = (n) => { - this.dropdownContent.classList.contains("iti__hide") ? this.telInput.focus() : n.preventDefault(); + this._handleLabelClick = (i) => { + this.dropdownContent.classList.contains("iti__hide") ? this.telInput.focus() : i.preventDefault(); }; const e = this.telInput.closest("label"); e && e.addEventListener("click", this._handleLabelClick), this._handleClickSelectedCountry = () => { this.dropdownContent.classList.contains("iti__hide") && !this.telInput.disabled && !this.telInput.readOnly && this._openDropdown(); - }, this.selectedCountry.addEventListener("click", this._handleClickSelectedCountry), this._handleCountryContainerKeydown = (n) => { - this.dropdownContent.classList.contains("iti__hide") && ["ArrowUp", "ArrowDown", " ", "Enter"].includes(n.key) && (n.preventDefault(), n.stopPropagation(), this._openDropdown()), n.key === "Tab" && this._closeDropdown(); + }, this.selectedCountry.addEventListener("click", this._handleClickSelectedCountry), this._handleCountryContainerKeydown = (i) => { + this.dropdownContent.classList.contains("iti__hide") && ["ArrowUp", "ArrowDown", " ", "Enter"].includes(i.key) && (i.preventDefault(), i.stopPropagation(), this._openDropdown()), i.key === "Tab" && this._closeDropdown(); }, this.countryContainer.addEventListener( "keydown", this._handleCountryContainerKeydown @@ -1936,17 +1938,19 @@ class U2 { } //* Init many requests: utils script / geo ip lookup. _initRequests() { - const { utilsScript: e, initialCountry: n, geoIpLookup: r } = this.options; - e && !C.utils ? C.documentReady() ? C.loadUtils(e) : window.addEventListener("load", () => { - C.loadUtils(e); - }) : this.resolveUtilsScriptPromise(), n === "auto" && r && !this.selectedCountryData.iso2 ? this._loadAutoCountry() : this.resolveAutoCountryPromise(); + let { loadUtilsOnInit: e, utilsScript: i, initialCountry: n, geoIpLookup: o } = this.options; + !e && i && (console.warn("intl-tel-input: The `utilsScript` option is deprecated and will be removed in a future release! Please use the `loadUtilsOnInit` option instead."), e = i), e && !m.utils ? (this._handlePageLoad = () => { + var c; + window.removeEventListener("load", this._handlePageLoad), (c = m.loadUtils(e)) == null || c.catch(() => { + }); + }, m.documentReady() ? this._handlePageLoad() : window.addEventListener("load", this._handlePageLoad)) : this.resolveUtilsScriptPromise(), n === "auto" && o && !this.selectedCountryData.iso2 ? this._loadAutoCountry() : this.resolveAutoCountryPromise(); } //* Perform the geo ip lookup. _loadAutoCountry() { - C.autoCountry ? this.handleAutoCountry() : C.startedLoadingAutoCountry || (C.startedLoadingAutoCountry = !0, typeof this.options.geoIpLookup == "function" && this.options.geoIpLookup( + m.autoCountry ? this.handleAutoCountry() : m.startedLoadingAutoCountry || (m.startedLoadingAutoCountry = !0, typeof this.options.geoIpLookup == "function" && this.options.geoIpLookup( (e = "") => { - const n = e.toLowerCase(); - n && this._getCountryData(n, !0) ? (C.autoCountry = n, setTimeout(() => $1("handleAutoCountry"))) : (this._setInitialState(!0), $1("rejectAutoCountryPromise")); + const i = e.toLowerCase(); + i && this._getCountryData(i, !0) ? (m.autoCountry = i, setTimeout(() => $1("handleAutoCountry"))) : (this._setInitialState(!0), $1("rejectAutoCountryPromise")); }, () => { this._setInitialState(!0), $1("rejectAutoCountryPromise"); @@ -1958,68 +1962,68 @@ class U2 { } //* Initialize the tel input listeners. _initTelInputListeners() { - const { strictMode: e, formatAsYouType: n, separateDialCode: r, formatOnDisplay: o, allowDropdown: a, countrySearch: c } = this.options; + const { strictMode: e, formatAsYouType: i, separateDialCode: n, formatOnDisplay: o, allowDropdown: a, countrySearch: c } = this.options; let g = !1; new RegExp("\\p{L}", "u").test(this.telInput.value) && (g = !0), this._handleInputEvent = (f) => { - if (this.isAndroid && (f == null ? void 0 : f.data) === "+" && r && a && c) { - const N = this.telInput.selectionStart || 0, v = this.telInput.value.substring(0, N - 1), A = this.telInput.value.substring(N); - this.telInput.value = v + A, this._openDropdownWithPlus(); + if (this.isAndroid && (f == null ? void 0 : f.data) === "+" && n && a && c) { + const L = this.telInput.selectionStart || 0, v = this.telInput.value.substring(0, L - 1), T = this.telInput.value.substring(L); + this.telInput.value = v + T, this._openDropdownWithPlus(); return; } this._updateCountryFromNumber(this.telInput.value) && this._triggerCountryChange(); const b = (f == null ? void 0 : f.data) && /[^+0-9]/.test(f.data), _ = (f == null ? void 0 : f.inputType) === "insertFromPaste" && this.telInput.value; b || _ && !e ? g = !0 : /[^+0-9]/.test(this.telInput.value) || (g = !1); const I = (f == null ? void 0 : f.detail) && f.detail.isSetNumber && !o; - if (n && !g && !I) { - const N = this.telInput.selectionStart || 0, A = this.telInput.value.substring(0, N).replace(/[^+0-9]/g, "").length, M = (f == null ? void 0 : f.inputType) === "deleteContentForward", O = this._formatNumberAsYouType(), Z = F2(A, O, N, M); + if (i && !g && !I) { + const L = this.telInput.selectionStart || 0, T = this.telInput.value.substring(0, L).replace(/[^+0-9]/g, "").length, M = (f == null ? void 0 : f.inputType) === "deleteContentForward", O = this._formatNumberAsYouType(), Z = U2(T, O, L, M); this.telInput.value = O, this.telInput.setSelectionRange(Z, Z); } - }, this.telInput.addEventListener("input", this._handleInputEvent), (e || r) && (this._handleKeydownEvent = (f) => { + }, this.telInput.addEventListener("input", this._handleInputEvent), (e || n) && (this._handleKeydownEvent = (f) => { if (f.key && f.key.length === 1 && !f.altKey && !f.ctrlKey && !f.metaKey) { - if (r && a && c && f.key === "+") { + if (n && a && c && f.key === "+") { f.preventDefault(), this._openDropdownWithPlus(); return; } if (e) { - const b = this.telInput.value, _ = b.charAt(0) === "+", I = !_ && this.telInput.selectionStart === 0 && f.key === "+", N = /^[0-9]$/.test(f.key), v = r ? N : I || N, A = b.slice(0, this.telInput.selectionStart) + f.key + b.slice(this.telInput.selectionEnd), M = this._getFullNumber(A), O = C.utils.getCoreNumber(M, this.selectedCountryData.iso2), Z = this.maxCoreNumberLength && O.length > this.maxCoreNumberLength; - let n1 = !1; + const b = this.telInput.value, _ = b.charAt(0) === "+", I = !_ && this.telInput.selectionStart === 0 && f.key === "+", L = /^[0-9]$/.test(f.key), v = n ? L : I || L, T = b.slice(0, this.telInput.selectionStart) + f.key + b.slice(this.telInput.selectionEnd), M = this._getFullNumber(T), O = m.utils.getCoreNumber(M, this.selectedCountryData.iso2), Z = this.maxCoreNumberLength && O.length > this.maxCoreNumberLength; + let i1 = !1; if (_) { const p1 = this.selectedCountryData.iso2; - n1 = this._getCountryFromNumber(M) !== p1; + i1 = this._getCountryFromNumber(M) !== p1; } - (!v || Z && !n1 && !I) && f.preventDefault(); + (!v || Z && !i1 && !I) && f.preventDefault(); } } }, this.telInput.addEventListener("keydown", this._handleKeydownEvent)); } //* Adhere to the input's maxlength attr. _cap(e) { - const n = parseInt(this.telInput.getAttribute("maxlength") || "", 10); - return n && e.length > n ? e.substr(0, n) : e; + const i = parseInt(this.telInput.getAttribute("maxlength") || "", 10); + return i && e.length > i ? e.substr(0, i) : e; } //* Trigger a custom event on the input. - _trigger(e, n = {}) { - const r = new CustomEvent(e, { + _trigger(e, i = {}) { + const n = new CustomEvent(e, { bubbles: !0, cancelable: !0, - detail: n + detail: i }); - this.telInput.dispatchEvent(r); + this.telInput.dispatchEvent(n); } //* Open the dropdown. _openDropdown() { - const { fixDropdownWidth: e, countrySearch: n } = this.options; - if (e && (this.dropdownContent.style.width = `${this.telInput.offsetWidth}px`), this.dropdownContent.classList.remove("iti__hide"), this.selectedCountry.setAttribute("aria-expanded", "true"), this._setDropdownPosition(), n) { - const r = this.countryList.firstElementChild; - r && (this._highlightListItem(r, !1), this.countryList.scrollTop = 0), this.searchInput.focus(); + const { fixDropdownWidth: e, countrySearch: i } = this.options; + if (e && (this.dropdownContent.style.width = `${this.telInput.offsetWidth}px`), this.dropdownContent.classList.remove("iti__hide"), this.selectedCountry.setAttribute("aria-expanded", "true"), this._setDropdownPosition(), i) { + const n = this.countryList.firstElementChild; + n && (this._highlightListItem(n, !1), this.countryList.scrollTop = 0), this.searchInput.focus(); } this._bindDropdownListeners(), this.dropdownArrow.classList.add("iti__arrow--up"), this._trigger("open:countrydropdown"); } //* Set the dropdown position _setDropdownPosition() { if (this.options.dropdownContainer && this.options.dropdownContainer.appendChild(this.dropdown), !this.options.useFullscreenPopup) { - const e = this.telInput.getBoundingClientRect(), n = this.telInput.offsetHeight; - this.options.dropdownContainer && (this.dropdown.style.top = `${e.top + n}px`, this.dropdown.style.left = `${e.left}px`, this._handleWindowScroll = () => this._closeDropdown(), window.addEventListener("scroll", this._handleWindowScroll)); + const e = this.telInput.getBoundingClientRect(), i = this.telInput.offsetHeight; + this.options.dropdownContainer && (this.dropdown.style.top = `${e.top + i}px`, this.dropdown.style.left = `${e.left}px`, this._handleWindowScroll = () => this._closeDropdown(), window.addEventListener("scroll", this._handleWindowScroll)); } } //* We only bind dropdown listeners when the dropdown is open. @@ -2043,10 +2047,10 @@ class U2 { "click", this._handleClickOffToClose ); - let n = "", r = null; + let i = "", n = null; if (this._handleKeydownOnDropdown = (o) => { - ["ArrowUp", "ArrowDown", "Enter", "Escape"].includes(o.key) && (o.preventDefault(), o.stopPropagation(), o.key === "ArrowUp" || o.key === "ArrowDown" ? this._handleUpDownKey(o.key) : o.key === "Enter" ? this._handleEnterKey() : o.key === "Escape" && this._closeDropdown()), !this.options.countrySearch && /^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(o.key) && (o.stopPropagation(), r && clearTimeout(r), n += o.key.toLowerCase(), this._searchForCountry(n), r = setTimeout(() => { - n = ""; + ["ArrowUp", "ArrowDown", "Enter", "Escape"].includes(o.key) && (o.preventDefault(), o.stopPropagation(), o.key === "ArrowUp" || o.key === "ArrowDown" ? this._handleUpDownKey(o.key) : o.key === "Enter" ? this._handleEnterKey() : o.key === "Escape" && this._closeDropdown()), !this.options.countrySearch && /^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(o.key) && (o.stopPropagation(), n && clearTimeout(n), i += o.key.toLowerCase(), this._searchForCountry(i), n = setTimeout(() => { + i = ""; }, 1e3)); }, document.addEventListener("keydown", this._handleKeydownOnDropdown), this.options.countrySearch) { const o = () => { @@ -2063,40 +2067,40 @@ class U2 { } //* Hidden search (countrySearch disabled): Find the first list item whose name starts with the query string. _searchForCountry(e) { - for (let n = 0; n < this.countries.length; n++) { - const r = this.countries[n]; - if (r.name.substr(0, e.length).toLowerCase() === e) { - const a = r.nodeById[this.id]; + for (let i = 0; i < this.countries.length; i++) { + const n = this.countries[i]; + if (n.name.substr(0, e.length).toLowerCase() === e) { + const a = n.nodeById[this.id]; this._highlightListItem(a, !1), this._scrollTo(a); break; } } } //* Country search enabled: Filter the countries according to the search query. - _filterCountries(e, n = !1) { - let r = !0; + _filterCountries(e, i = !1) { + let n = !0; this.countryList.innerHTML = ""; const o = r2(e); for (let a = 0; a < this.countries.length; a++) { const c = this.countries[a], g = r2(c.name), f = c.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((_) => _[0]).join("").toLowerCase(), b = `+${c.dialCode}`; - if (n || g.includes(o) || b.includes(o) || c.iso2.includes(o) || f.includes(o)) { + if (i || g.includes(o) || b.includes(o) || c.iso2.includes(o) || f.includes(o)) { const _ = c.nodeById[this.id]; - _ && this.countryList.appendChild(_), r && (this._highlightListItem(_, !1), r = !1); + _ && this.countryList.appendChild(_), n && (this._highlightListItem(_, !1), n = !1); } } - r && this._highlightListItem(null, !1), this.countryList.scrollTop = 0, this._updateSearchResultsText(); + n && this._highlightListItem(null, !1), this.countryList.scrollTop = 0, this._updateSearchResultsText(); } //* Update search results text (for a11y). _updateSearchResultsText() { - const { i18n: e } = this.options, n = this.countryList.childElementCount; - let r; - n === 0 ? r = e.zeroSearchResults : n === 1 ? r = e.oneSearchResult : r = e.multipleSearchResults.replace("${count}", n.toString()), this.searchResultsA11yText.textContent = r; + const { i18n: e } = this.options, i = this.countryList.childElementCount; + let n; + i === 0 ? n = e.zeroSearchResults : i === 1 ? n = e.oneSearchResult : n = e.multipleSearchResults.replace("${count}", i.toString()), this.searchResultsA11yText.textContent = n; } //* Highlight the next/prev item in the list (and ensure it is visible). _handleUpDownKey(e) { - var r, o; - let n = e === "ArrowUp" ? (r = this.highlightedItem) == null ? void 0 : r.previousElementSibling : (o = this.highlightedItem) == null ? void 0 : o.nextElementSibling; - !n && this.countryList.childElementCount > 1 && (n = e === "ArrowUp" ? this.countryList.lastElementChild : this.countryList.firstElementChild), n && (this._scrollTo(n), this._highlightListItem(n, !1)); + var n, o; + let i = e === "ArrowUp" ? (n = this.highlightedItem) == null ? void 0 : n.previousElementSibling : (o = this.highlightedItem) == null ? void 0 : o.nextElementSibling; + !i && this.countryList.childElementCount > 1 && (i = e === "ArrowUp" ? this.countryList.lastElementChild : this.countryList.firstElementChild), i && (this._scrollTo(i), this._highlightListItem(i, !1)); } //* Select the currently highlighted item. _handleEnterKey() { @@ -2105,29 +2109,29 @@ class U2 { //* Update the input's value to the given val (format first if possible) //* NOTE: this is called from _setInitialState, handleUtils and setNumber. _updateValFromNumber(e) { - let n = e; - if (this.options.formatOnDisplay && C.utils && this.selectedCountryData) { - const r = this.options.nationalMode || n.charAt(0) !== "+" && !this.options.separateDialCode, { NATIONAL: o, INTERNATIONAL: a } = C.utils.numberFormat, c = r ? o : a; - n = C.utils.formatNumber( - n, + let i = e; + if (this.options.formatOnDisplay && m.utils && this.selectedCountryData) { + const n = this.options.nationalMode || i.charAt(0) !== "+" && !this.options.separateDialCode, { NATIONAL: o, INTERNATIONAL: a } = m.utils.numberFormat, c = n ? o : a; + i = m.utils.formatNumber( + i, this.selectedCountryData.iso2, c ); } - n = this._beforeSetNumber(n), this.telInput.value = n; + i = this._beforeSetNumber(i), this.telInput.value = i; } //* Check if need to select a new country based on the given number //* Note: called from _setInitialState, keyup handler, setNumber. _updateCountryFromNumber(e) { - const n = this._getCountryFromNumber(e); - return n !== null ? this._setCountry(n) : !1; + const i = this._getCountryFromNumber(e); + return i !== null ? this._setCountry(i) : !1; } _getCountryFromNumber(e) { - const n = e.indexOf("+"); - let r = n ? e.substring(n) : e; + const i = e.indexOf("+"); + let n = i ? e.substring(i) : e; const o = this.selectedCountryData.dialCode; - r && o === "1" && r.charAt(0) !== "+" && (r.charAt(0) !== "1" && (r = `1${r}`), r = `+${r}`), this.options.separateDialCode && o && r.charAt(0) !== "+" && (r = `+${o}${r}`); - const c = this._getDialCode(r, !0), g = f1(r); + n && o === "1" && n.charAt(0) !== "+" && (n.charAt(0) !== "1" && (n = `1${n}`), n = `+${n}`), this.options.separateDialCode && o && n.charAt(0) !== "+" && (n = `+${o}${n}`); + const c = this._getDialCode(n, !0), g = f1(n); if (c) { const f = this.dialCodeToIso2Map[f1(c)], b = f.indexOf(this.selectedCountryData.iso2) !== -1 && g.length <= c.length - 1; if (!(o === "1" && s2(g)) && !b) { @@ -2136,42 +2140,42 @@ class U2 { return f[I]; } } else { - if (r.charAt(0) === "+" && g.length) + if (n.charAt(0) === "+" && g.length) return ""; - if ((!r || r === "+") && !this.selectedCountryData.iso2) + if ((!n || n === "+") && !this.selectedCountryData.iso2) return this.defaultCountry; } return null; } //* Remove highlighting from other list items and highlight the given item. - _highlightListItem(e, n) { - const r = this.highlightedItem; - if (r && (r.classList.remove("iti__highlight"), r.setAttribute("aria-selected", "false")), this.highlightedItem = e, this.highlightedItem) { + _highlightListItem(e, i) { + const n = this.highlightedItem; + if (n && (n.classList.remove("iti__highlight"), n.setAttribute("aria-selected", "false")), this.highlightedItem = e, this.highlightedItem) { this.highlightedItem.classList.add("iti__highlight"), this.highlightedItem.setAttribute("aria-selected", "true"); const o = this.highlightedItem.getAttribute("id") || ""; this.selectedCountry.setAttribute("aria-activedescendant", o), this.options.countrySearch && this.searchInput.setAttribute("aria-activedescendant", o); } - n && this.highlightedItem.focus(); + i && this.highlightedItem.focus(); } //* Find the country data for the given iso2 code //* the ignoreOnlyCountriesOption is only used during init() while parsing the onlyCountries array - _getCountryData(e, n) { - for (let r = 0; r < this.countries.length; r++) - if (this.countries[r].iso2 === e) - return this.countries[r]; - if (n) + _getCountryData(e, i) { + for (let n = 0; n < this.countries.length; n++) + if (this.countries[n].iso2 === e) + return this.countries[n]; + if (i) return null; throw new Error(`No country data for '${e}'`); } //* Update the selected country, dial code (if separateDialCode), placeholder, title, and active list item. //* Note: called from _setInitialState, _updateCountryFromNumber, _selectListItem, setCountry. _setCountry(e) { - const { separateDialCode: n, showFlags: r, i18n: o } = this.options, a = this.selectedCountryData.iso2 ? this.selectedCountryData : {}; + const { separateDialCode: i, showFlags: n, i18n: o } = this.options, a = this.selectedCountryData.iso2 ? this.selectedCountryData : {}; if (this.selectedCountryData = e ? this._getCountryData(e, !1) || {} : {}, this.selectedCountryData.iso2 && (this.defaultCountry = this.selectedCountryData.iso2), this.selectedCountryInner) { let c = "", g = ""; - e && r ? (c = `iti__flag iti__${e}`, g = `${this.selectedCountryData.name} +${this.selectedCountryData.dialCode}`) : (c = "iti__flag iti__globe", g = o.noCountrySelected), this.selectedCountryInner.className = c, this.selectedCountryA11yText.textContent = g; + e && n ? (c = `iti__flag iti__${e}`, g = `${this.selectedCountryData.name} +${this.selectedCountryData.dialCode}`) : (c = "iti__flag iti__globe", g = o.noCountrySelected), this.selectedCountryInner.className = c, this.selectedCountryA11yText.textContent = g; } - if (this._setSelectedCountryTitleAttribute(e, n), n) { + if (this._setSelectedCountryTitleAttribute(e, i), i) { const c = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : ""; this.selectedDialCode.innerHTML = c, this._updateInputPadding(); } @@ -2180,34 +2184,34 @@ class U2 { //* Update the input padding to make space for the selected country/dial code. _updateInputPadding() { if (this.selectedCountry) { - const n = (this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth()) + 6; - this.showSelectedCountryOnLeft ? this.telInput.style.paddingLeft = `${n}px` : this.telInput.style.paddingRight = `${n}px`; + const i = (this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth()) + 6; + this.showSelectedCountryOnLeft ? this.telInput.style.paddingLeft = `${i}px` : this.telInput.style.paddingRight = `${i}px`; } } //* Update the maximum valid number length for the currently selected country. _updateMaxLength() { - const { strictMode: e, placeholderNumberType: n, validationNumberType: r } = this.options, { iso2: o } = this.selectedCountryData; - if (e && C.utils) + const { strictMode: e, placeholderNumberType: i, validationNumberType: n } = this.options, { iso2: o } = this.selectedCountryData; + if (e && m.utils) if (o) { - const a = C.utils.numberType[n]; - let c = C.utils.getExampleNumber( + const a = m.utils.numberType[i]; + let c = m.utils.getExampleNumber( o, !1, a, !0 ), g = c; - for (; C.utils.isPossibleNumber(c, o, r); ) + for (; m.utils.isPossibleNumber(c, o, n); ) g = c, c += "0"; - const f = C.utils.getCoreNumber(g, o); + const f = m.utils.getCoreNumber(g, o); this.maxCoreNumberLength = f.length, o === "by" && (this.maxCoreNumberLength = f.length + 1); } else this.maxCoreNumberLength = null; } - _setSelectedCountryTitleAttribute(e = null, n) { + _setSelectedCountryTitleAttribute(e = null, i) { if (!this.selectedCountry) return; - let r; - e && !n ? r = `${this.selectedCountryData.name}: +${this.selectedCountryData.dialCode}` : e ? r = this.selectedCountryData.name : r = "Unknown", this.selectedCountry.setAttribute("title", r); + let n; + e && !i ? n = `${this.selectedCountryData.name}: +${this.selectedCountryData.dialCode}` : e ? n = this.selectedCountryData.name : n = "Unknown", this.selectedCountry.setAttribute("title", n); } //* When the input is in a hidden container during initialisation, we must inject some markup //* into the end of the DOM to calculate the correct offsetWidth. @@ -2217,11 +2221,11 @@ class U2 { if (this.telInput.parentNode) { const e = this.telInput.parentNode.cloneNode(!1); e.style.visibility = "hidden", document.body.appendChild(e); - const n = this.countryContainer.cloneNode(); - e.appendChild(n); - const r = this.selectedCountry.cloneNode(!0); - n.appendChild(r); - const o = r.offsetWidth; + const i = this.countryContainer.cloneNode(); + e.appendChild(i); + const n = this.selectedCountry.cloneNode(!0); + i.appendChild(n); + const o = n.offsetWidth; return document.body.removeChild(e), o; } return 0; @@ -2230,15 +2234,15 @@ class U2 { _updatePlaceholder() { const { autoPlaceholder: e, - placeholderNumberType: n, - nationalMode: r, + placeholderNumberType: i, + nationalMode: n, customPlaceholder: o } = this.options, a = e === "aggressive" || !this.hadInitialPlaceholder && e === "polite"; - if (C.utils && a) { - const c = C.utils.numberType[n]; - let g = this.selectedCountryData.iso2 ? C.utils.getExampleNumber( + if (m.utils && a) { + const c = m.utils.numberType[i]; + let g = this.selectedCountryData.iso2 ? m.utils.getExampleNumber( this.selectedCountryData.iso2, - r, + n, c ) : ""; g = this._beforeSetNumber(g), typeof o == "function" && (g = o(g, this.selectedCountryData)), this.telInput.setAttribute("placeholder", g); @@ -2246,10 +2250,10 @@ class U2 { } //* Called when the user selects a list item from the dropdown. _selectListItem(e) { - const n = this._setCountry( + const i = this._setCountry( e.getAttribute("data-country-code") ); - this._closeDropdown(), this._updateDialCode(e.getAttribute("data-dial-code")), this.telInput.focus(), n && this._triggerCountryChange(); + this._closeDropdown(), this._updateDialCode(e.getAttribute("data-dial-code")), this.telInput.focus(), i && this._triggerCountryChange(); } //* Close the dropdown and unbind any listeners. _closeDropdown() { @@ -2259,41 +2263,41 @@ class U2 { ), this.countryList.removeEventListener( "mouseover", this._handleMouseoverCountryList - ), this.countryList.removeEventListener("click", this._handleClickCountryList), this.options.dropdownContainer && (this.options.useFullscreenPopup || window.removeEventListener("scroll", this._handleWindowScroll), this.dropdown.parentNode && this.dropdown.parentNode.removeChild(this.dropdown)), this._trigger("close:countrydropdown"); + ), this.countryList.removeEventListener("click", this._handleClickCountryList), this.options.dropdownContainer && (this.options.useFullscreenPopup || window.removeEventListener("scroll", this._handleWindowScroll), this.dropdown.parentNode && this.dropdown.parentNode.removeChild(this.dropdown)), this._handlePageLoad && window.removeEventListener("load", this._handlePageLoad), this._trigger("close:countrydropdown"); } //* Check if an element is visible within it's container, else scroll until it is. _scrollTo(e) { - const n = this.countryList, r = document.documentElement.scrollTop, o = n.offsetHeight, a = n.getBoundingClientRect().top + r, c = a + o, g = e.offsetHeight, f = e.getBoundingClientRect().top + r, b = f + g, _ = f - a + n.scrollTop; + const i = this.countryList, n = document.documentElement.scrollTop, o = i.offsetHeight, a = i.getBoundingClientRect().top + n, c = a + o, g = e.offsetHeight, f = e.getBoundingClientRect().top + n, b = f + g, _ = f - a + i.scrollTop; if (f < a) - n.scrollTop = _; + i.scrollTop = _; else if (b > c) { const I = o - g; - n.scrollTop = _ - I; + i.scrollTop = _ - I; } } //* Replace any existing dial code with the new one //* Note: called from _selectListItem and setCountry _updateDialCode(e) { - const n = this.telInput.value, r = `+${e}`; + const i = this.telInput.value, n = `+${e}`; let o; - if (n.charAt(0) === "+") { - const a = this._getDialCode(n); - a ? o = n.replace(a, r) : o = r, this.telInput.value = o; + if (i.charAt(0) === "+") { + const a = this._getDialCode(i); + a ? o = i.replace(a, n) : o = n, this.telInput.value = o; } } //* Try and extract a valid international dial code from a full telephone number. //* Note: returns the raw string inc plus character and any whitespace/dots etc. - _getDialCode(e, n) { - let r = ""; + _getDialCode(e, i) { + let n = ""; if (e.charAt(0) === "+") { let o = ""; for (let a = 0; a < e.length; a++) { const c = e.charAt(a); if (!isNaN(parseInt(c, 10))) { - if (o += c, n) - this.dialCodeToIso2Map[o] && (r = e.substr(0, a + 1)); + if (o += c, i) + this.dialCodeToIso2Map[o] && (n = e.substr(0, a + 1)); else if (this.dialCodes[o]) { - r = e.substr(0, a + 1); + n = e.substr(0, a + 1); break; } if (o.length === this.dialCodeMaxLen) @@ -2301,27 +2305,27 @@ class U2 { } } } - return r; + return n; } //* Get the input val, adding the dial code if separateDialCode is enabled. _getFullNumber(e) { - const n = e || this.telInput.value.trim(), { dialCode: r } = this.selectedCountryData; + const i = e || this.telInput.value.trim(), { dialCode: n } = this.selectedCountryData; let o; - const a = f1(n); - return this.options.separateDialCode && n.charAt(0) !== "+" && r && a ? o = `+${r}` : o = "", o + n; + const a = f1(i); + return this.options.separateDialCode && i.charAt(0) !== "+" && n && a ? o = `+${n}` : o = "", o + i; } //* Remove the dial code if separateDialCode is enabled also cap the length if the input has a maxlength attribute _beforeSetNumber(e) { - let n = e; + let i = e; if (this.options.separateDialCode) { - let r = this._getDialCode(n); - if (r) { - r = `+${this.selectedCountryData.dialCode}`; - const o = n[r.length] === " " || n[r.length] === "-" ? r.length + 1 : r.length; - n = n.substr(o); + let n = this._getDialCode(i); + if (n) { + n = `+${this.selectedCountryData.dialCode}`; + const o = i[n.length] === " " || i[n.length] === "-" ? n.length + 1 : n.length; + i = i.substr(o); } } - return this._cap(n); + return this._cap(i); } //* Trigger the 'countrychange' event. _triggerCountryChange() { @@ -2329,19 +2333,19 @@ class U2 { } //* Format the number as the user types. _formatNumberAsYouType() { - const e = this._getFullNumber(), n = C.utils ? C.utils.formatNumberAsYouType(e, this.selectedCountryData.iso2) : e, { dialCode: r } = this.selectedCountryData; - return this.options.separateDialCode && this.telInput.value.charAt(0) !== "+" && n.includes(`+${r}`) ? (n.split(`+${r}`)[1] || "").trim() : n; + const e = this._getFullNumber(), i = m.utils ? m.utils.formatNumberAsYouType(e, this.selectedCountryData.iso2) : e, { dialCode: n } = this.selectedCountryData; + return this.options.separateDialCode && this.telInput.value.charAt(0) !== "+" && i.includes(`+${n}`) ? (i.split(`+${n}`)[1] || "").trim() : i; } //************************** //* SECRET PUBLIC METHODS //************************** //* This is called when the geoip call returns. handleAutoCountry() { - this.options.initialCountry === "auto" && C.autoCountry && (this.defaultCountry = C.autoCountry, this.selectedCountryData.iso2 || this.selectedCountryInner.classList.contains("iti__globe") || this.setCountry(this.defaultCountry), this.resolveAutoCountryPromise()); + this.options.initialCountry === "auto" && m.autoCountry && (this.defaultCountry = m.autoCountry, this.selectedCountryData.iso2 || this.selectedCountryInner.classList.contains("iti__globe") || this.setCountry(this.defaultCountry), this.resolveAutoCountryPromise()); } //* This is called when the utils request completes. handleUtils() { - C.utils && (this.telInput.value && this._updateValFromNumber(this.telInput.value), this.selectedCountryData.iso2 && (this._updatePlaceholder(), this._updateMaxLength())), this.resolveUtilsScriptPromise(); + m.utils && (this.telInput.value && this._updateValFromNumber(this.telInput.value), this.selectedCountryData.iso2 && (this._updatePlaceholder(), this._updateMaxLength())), this.resolveUtilsScriptPromise(); } //******************** //* PUBLIC METHODS @@ -2349,7 +2353,7 @@ class U2 { //* Remove plugin. destroy() { var a, c; - const { allowDropdown: e, separateDialCode: n } = this.options; + const { allowDropdown: e, separateDialCode: i } = this.options; if (e) { this._closeDropdown(), this.selectedCountry.removeEventListener( "click", @@ -2361,25 +2365,25 @@ class U2 { const g = this.telInput.closest("label"); g && g.removeEventListener("click", this._handleLabelClick); } - const { form: r } = this.telInput; - this._handleHiddenInputSubmit && r && r.removeEventListener("submit", this._handleHiddenInputSubmit), this.telInput.removeEventListener("input", this._handleInputEvent), this._handleKeydownEvent && this.telInput.removeEventListener("keydown", this._handleKeydownEvent), this.telInput.removeAttribute("data-intl-tel-input-id"), n && (this.isRTL ? this.telInput.style.paddingRight = this.originalPaddingRight : this.telInput.style.paddingLeft = this.originalPaddingLeft); + const { form: n } = this.telInput; + this._handleHiddenInputSubmit && n && n.removeEventListener("submit", this._handleHiddenInputSubmit), this.telInput.removeEventListener("input", this._handleInputEvent), this._handleKeydownEvent && this.telInput.removeEventListener("keydown", this._handleKeydownEvent), this.telInput.removeAttribute("data-intl-tel-input-id"), i && (this.isRTL ? this.telInput.style.paddingRight = this.originalPaddingRight : this.telInput.style.paddingLeft = this.originalPaddingLeft); const o = this.telInput.parentNode; - (a = o == null ? void 0 : o.parentNode) == null || a.insertBefore(this.telInput, o), (c = o == null ? void 0 : o.parentNode) == null || c.removeChild(o), delete C.instances[this.id]; + (a = o == null ? void 0 : o.parentNode) == null || a.insertBefore(this.telInput, o), (c = o == null ? void 0 : o.parentNode) == null || c.removeChild(o), delete m.instances[this.id]; } //* Get the extension from the current number. getExtension() { - return C.utils ? C.utils.getExtension( + return m.utils ? m.utils.getExtension( this._getFullNumber(), this.selectedCountryData.iso2 ) : ""; } //* Format the number to the given format. getNumber(e) { - if (C.utils) { - const { iso2: n } = this.selectedCountryData; - return C.utils.formatNumber( + if (m.utils) { + const { iso2: i } = this.selectedCountryData; + return m.utils.formatNumber( this._getFullNumber(), - n, + i, e ); } @@ -2387,7 +2391,7 @@ class U2 { } //* Get the type of the entered number e.g. landline/mobile. getNumberType() { - return C.utils ? C.utils.getNumberType( + return m.utils ? m.utils.getNumberType( this._getFullNumber(), this.selectedCountryData.iso2 ) : -99; @@ -2398,9 +2402,9 @@ class U2 { } //* Get the validation error. getValidationError() { - if (C.utils) { + if (m.utils) { const { iso2: e } = this.selectedCountryData; - return C.utils.getValidationError(this._getFullNumber(), e); + return m.utils.getValidationError(this._getFullNumber(), e); } return -99; } @@ -2408,39 +2412,39 @@ class U2 { isValidNumber() { if (!this.selectedCountryData.iso2) return !1; - const e = this._getFullNumber(), n = e.search(new RegExp("\\p{L}", "u")); - if (n > -1) { - const r = e.substring(0, n), o = this._utilsIsPossibleNumber(r), a = this._utilsIsPossibleNumber(e); + const e = this._getFullNumber(), i = e.search(new RegExp("\\p{L}", "u")); + if (i > -1) { + const n = e.substring(0, i), o = this._utilsIsPossibleNumber(n), a = this._utilsIsPossibleNumber(e); return o && a; } return this._utilsIsPossibleNumber(e); } _utilsIsPossibleNumber(e) { - return C.utils ? C.utils.isPossibleNumber(e, this.selectedCountryData.iso2, this.options.validationNumberType) : null; + return m.utils ? m.utils.isPossibleNumber(e, this.selectedCountryData.iso2, this.options.validationNumberType) : null; } //* Validate the input val (precise) isValidNumberPrecise() { if (!this.selectedCountryData.iso2) return !1; - const e = this._getFullNumber(), n = e.search(new RegExp("\\p{L}", "u")); - if (n > -1) { - const r = e.substring(0, n), o = this._utilsIsValidNumber(r), a = this._utilsIsValidNumber(e); + const e = this._getFullNumber(), i = e.search(new RegExp("\\p{L}", "u")); + if (i > -1) { + const n = e.substring(0, i), o = this._utilsIsValidNumber(n), a = this._utilsIsValidNumber(e); return o && a; } return this._utilsIsValidNumber(e); } _utilsIsValidNumber(e) { - return C.utils ? C.utils.isValidNumber(e, this.selectedCountryData.iso2) : null; + return m.utils ? m.utils.isValidNumber(e, this.selectedCountryData.iso2) : null; } //* Update the selected country, and update the input val accordingly. setCountry(e) { - const n = e == null ? void 0 : e.toLowerCase(), r = this.selectedCountryData.iso2; - (e && n !== r || !e && r) && (this._setCountry(n), this._updateDialCode(this.selectedCountryData.dialCode), this._triggerCountryChange()); + const i = e == null ? void 0 : e.toLowerCase(), n = this.selectedCountryData.iso2; + (e && i !== n || !e && n) && (this._setCountry(i), this._updateDialCode(this.selectedCountryData.dialCode), this._triggerCountryChange()); } //* Set the input value and update the country. setNumber(e) { - const n = this._updateCountryFromNumber(e); - this._updateValFromNumber(e), n && this._triggerCountryChange(), this._trigger("input", { isSetNumber: !0 }); + const i = this._updateCountryFromNumber(e); + this._updateValFromNumber(e), i && this._triggerCountryChange(), this._trigger("input", { isSetNumber: !0 }); } //* Set the placeholder number typ setPlaceholderNumberType(e) { @@ -2450,20 +2454,34 @@ class U2 { this.telInput.disabled = e, e ? this.selectedCountry.setAttribute("disabled", "true") : this.selectedCountry.removeAttribute("disabled"); } } -const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUtilsScript = !0, new Promise((e, n) => { - import_INTENTIONALLY_BROKEN( - /* webpackIgnore: true */ - /* @vite-ignore */ - y - ).then(({ default: r }) => { - C.utils = r, $1("handleUtils"), e(!0); - }).catch(() => { - $1("rejectUtilsScriptPromise"), n(); - }); -})) : null, C = Object.assign( +const V2 = (y) => { + if (!m.utils && !m.startedLoadingUtilsScript) { + let e; + if (typeof y == "string") + e = Promise.reject(new Error("INTENTIONALLY BROKEN: this build of intl-tel-input includes the utilities module inline, but it has incorrectly attempted to load the utilities separately. If you are seeing this message, something is broken!")); + else if (typeof y == "function") + try { + if (e = y(), !(e instanceof Promise)) + throw new TypeError(`The function passed to loadUtils must return a promise for the utilities module, not ${typeof e}`); + } catch (i) { + return Promise.reject(i); + } + else + return Promise.reject(new TypeError(`The argument passed to loadUtils must be a URL string or a function that returns a promise for the utilities module, not ${typeof y}`)); + return m.startedLoadingUtilsScript = !0, e.then((i) => { + const n = i == null ? void 0 : i.default; + if (!n || typeof n != "object") + throw typeof y == "string" ? new TypeError(`The module loaded from ${y} did not set utils as its default export.`) : new TypeError("The loader function passed to loadUtils did not resolve to a module object with utils as its default export."); + return m.utils = n, $1("handleUtils"), !0; + }).catch((i) => { + throw $1("rejectUtilsScriptPromise", i), i; + }); + } + return null; +}, m = Object.assign( (y, e) => { - const n = new U2(y, e); - return n._init(), y.setAttribute("data-intl-tel-input-id", n.id.toString()), C.instances[n.id] = n, n; + const i = new F2(y, e); + return i._init(), y.setAttribute("data-intl-tel-input-id", i.id.toString()), m.instances[i.id] = i, i; }, { defaults: u2, @@ -2474,11 +2492,13 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt //* A getter for the plugin instance. getInstance: (y) => { const e = y.getAttribute("data-intl-tel-input-id"); - return e ? C.instances[e] : null; + return e ? m.instances[e] : null; }, //* A map from instance ID to instance object. instances: {}, loadUtils: V2, + startedLoadingUtilsScript: !1, + startedLoadingAutoCountry: !1, version: "24.5.2" } ); @@ -2488,20 +2508,20 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt d = d.split("."); var $ = y; d[0] in $ || typeof $.execScript > "u" || $.execScript("var " + d[0]); - for (var i; d.length && (i = d.shift()); ) d.length || t === void 0 ? $[i] && $[i] !== Object.prototype[i] ? $ = $[i] : $ = $[i] = {} : $[i] = t; + for (var r; d.length && (r = d.shift()); ) d.length || t === void 0 ? $[r] && $[r] !== Object.prototype[r] ? $ = $[r] : $ = $[r] = {} : $[r] = t; } - function n(d, t) { + function i(d, t) { function $() { } - $.prototype = t.prototype, d.ma = t.prototype, d.prototype = new $(), d.prototype.constructor = d, d.sa = function(i, s, u) { + $.prototype = t.prototype, d.ma = t.prototype, d.prototype = new $(), d.prototype.constructor = d, d.sa = function(r, s, u) { for (var l = Array(arguments.length - 2), h = 2; h < arguments.length; h++) l[h - 2] = arguments[h]; - return t.prototype[s].apply(i, l); + return t.prototype[s].apply(r, l); }; } - function r(d) { + function n(d) { const t = []; let $ = 0; - for (const i in d) t[$++] = d[i]; + for (const r in d) t[$++] = d[r]; return t; } var o = class { @@ -2546,20 +2566,20 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt } } new I(); - function N(d, t) { + function L(d, t) { switch (this.g = d, this.l = !!t.aa, this.h = t.i, this.s = t.type, this.o = !1, this.h) { case M: case O: case Z: - case n1: + case i1: case p1: - case A: + case T: case v: this.o = !0; } this.j = t.defaultValue; } - var v = 1, A = 2, M = 3, O = 4, Z = 6, n1 = 16, p1 = 18; + var v = 1, T = 2, M = 3, O = 4, Z = 6, i1 = 16, p1 = 18; function v1(d, t) { for (this.h = d, this.g = {}, d = 0; d < t.length; d++) { var $ = t[d]; @@ -2567,52 +2587,52 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt } } function l2(d) { - return d = r(d.g), d.sort(function(t, $) { + return d = n(d.g), d.sort(function(t, $) { return t.g - $.g; }), d; } - function P() { + function x() { this.h = {}, this.j = this.m().g, this.g = this.l = null; } - P.prototype.has = function(d) { + x.prototype.has = function(d) { return R(this, d.g); - }, P.prototype.get = function(d, t) { + }, x.prototype.get = function(d, t) { return p(this, d.g, t); - }, P.prototype.set = function(d, t) { + }, x.prototype.set = function(d, t) { E(this, d.g, t); - }, P.prototype.add = function(d, t) { + }, x.prototype.add = function(d, t) { w1(this, d.g, t); }; function S1(d, t) { - for (var $ = l2(d.m()), i = 0; i < $.length; i++) { - var s = $[i], u = s.g; + for (var $ = l2(d.m()), r = 0; r < $.length; r++) { + var s = $[r], u = s.g; if (R(t, u)) { d.g && delete d.g[s.g]; var l = s.h == 11 || s.h == 10; if (s.l) { - s = x(t, u); + s = P(t, u); for (var h = 0; h < s.length; h++) w1(d, u, l ? s[h].clone() : s[h]); - } else s = i1(t, u), l ? (l = i1(d, u)) ? S1(l, s) : E(d, u, s.clone()) : E(d, u, s); + } else s = n1(t, u), l ? (l = n1(d, u)) ? S1(l, s) : E(d, u, s.clone()) : E(d, u, s); } } } - P.prototype.clone = function() { + x.prototype.clone = function() { var d = new this.constructor(); return d != this && (d.h = {}, d.g && (d.g = {}), S1(d, this)), d; }; function R(d, t) { return d.h[t] != null; } - function i1(d, t) { + function n1(d, t) { var $ = d.h[t]; if ($ == null) return null; if (d.l) { if (!(t in d.g)) { - var i = d.l, s = d.j[t]; + var r = d.l, s = d.j[t]; if ($ != null) if (s.l) { - for (var u = [], l = 0; l < $.length; l++) u[l] = i.h(s, $[l]); + for (var u = [], l = 0; l < $.length; l++) u[l] = r.h(s, $[l]); $ = u; - } else $ = i.h(s, $); + } else $ = r.h(s, $); return d.g[t] = $; } return d.g[t]; @@ -2620,8 +2640,8 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt return $; } function p(d, t, $) { - var i = i1(d, t); - return d.j[t].l ? i[$ || 0] : i; + var r = n1(d, t); + return d.j[t].l ? r[$ || 0] : r; } function S(d, t) { if (R(d, t)) d = p(d, t); @@ -2637,10 +2657,10 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt } return d; } - function x(d, t) { - return i1(d, t) || []; + function P(d, t) { + return n1(d, t) || []; } - function U(d, t) { + function F(d, t) { return d.j[t].l ? R(d, t) ? d.h[t].length : 0 : R(d, t) ? 1 : 0; } function E(d, t, $) { @@ -2650,8 +2670,8 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt d.h[t] || (d.h[t] = []), d.h[t].push($), d.g && delete d.g[t]; } function r1(d, t) { - var $ = [], i; - for (i in t) i != 0 && $.push(new N(i, t[i])); + var $ = [], r; + for (r in t) r != 0 && $.push(new L(r, t[r])); return new v1(d, $); } function s1() { @@ -2659,7 +2679,7 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt s1.prototype.g = function(d) { throw new d.h(), Error("Unimplemented"); }, s1.prototype.h = function(d, t) { - if (d.h == 11 || d.h == 10) return t instanceof P ? t : this.g(d.s.prototype.m(), t); + if (d.h == 11 || d.h == 10) return t instanceof x ? t : this.g(d.s.prototype.m(), t); if (d.h == 14) return typeof t == "string" && b1.test(t) && (d = Number(t), 0 < d) ? d : t; if (!d.o) return t; if (d = d.s, d === String) { @@ -2670,55 +2690,55 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt var b1 = /^-?[0-9]+$/; function g1() { } - n(g1, s1), g1.prototype.g = function(d, t) { + i(g1, s1), g1.prototype.g = function(d, t) { return d = new d.h(), d.l = this, d.h = t, d.g = {}, d; }; function q() { } - n(q, g1), q.prototype.h = function(d, t) { + i(q, g1), q.prototype.h = function(d, t) { return d.h == 8 ? !!t : s1.prototype.h.apply(this, arguments); }, q.prototype.g = function(d, t) { return q.ma.g.call(this, d, t); }; - function L(d, t) { + function N(d, t) { d != null && this.g.apply(this, arguments); } - L.prototype.h = "", L.prototype.set = function(d) { + N.prototype.h = "", N.prototype.set = function(d) { this.h = "" + d; - }, L.prototype.g = function(d, t, $) { - if (this.h += String(d), t != null) for (let i = 1; i < arguments.length; i++) this.h += arguments[i]; + }, N.prototype.g = function(d, t, $) { + if (this.h += String(d), t != null) for (let r = 1; r < arguments.length; r++) this.h += arguments[r]; return this; }; function B(d) { d.h = ""; } - L.prototype.toString = function() { + N.prototype.toString = function() { return this.h; }; function j() { - P.call(this); + x.call(this); } - n(j, P); - var N1 = null; + i(j, x); + var L1 = null; function w() { - P.call(this); + x.call(this); } - n(w, P); - var A1 = null; + i(w, x); + var T1 = null; function W() { - P.call(this); + x.call(this); } - n(W, P); - var L1 = null; + i(W, x); + var N1 = null; j.prototype.m = function() { - var d = N1; - return d || (N1 = d = r1(j, { 0: { name: "NumberFormat", ia: "i18n.phonenumbers.NumberFormat" }, 1: { name: "pattern", required: !0, i: 9, type: String }, 2: { name: "format", required: !0, i: 9, type: String }, 3: { name: "leading_digits_pattern", aa: !0, i: 9, type: String }, 4: { name: "national_prefix_formatting_rule", i: 9, type: String }, 6: { name: "national_prefix_optional_when_formatting", i: 8, defaultValue: !1, type: Boolean }, 5: { name: "domestic_carrier_code_formatting_rule", i: 9, type: String } })), d; + var d = L1; + return d || (L1 = d = r1(j, { 0: { name: "NumberFormat", ia: "i18n.phonenumbers.NumberFormat" }, 1: { name: "pattern", required: !0, i: 9, type: String }, 2: { name: "format", required: !0, i: 9, type: String }, 3: { name: "leading_digits_pattern", aa: !0, i: 9, type: String }, 4: { name: "national_prefix_formatting_rule", i: 9, type: String }, 6: { name: "national_prefix_optional_when_formatting", i: 8, defaultValue: !1, type: Boolean }, 5: { name: "domestic_carrier_code_formatting_rule", i: 9, type: String } })), d; }, j.m = j.prototype.m, w.prototype.m = function() { - var d = A1; - return d || (A1 = d = r1(w, { 0: { name: "PhoneNumberDesc", ia: "i18n.phonenumbers.PhoneNumberDesc" }, 2: { name: "national_number_pattern", i: 9, type: String }, 9: { name: "possible_length", aa: !0, i: 5, type: Number }, 10: { name: "possible_length_local_only", aa: !0, i: 5, type: Number }, 6: { name: "example_number", i: 9, type: String } })), d; + var d = T1; + return d || (T1 = d = r1(w, { 0: { name: "PhoneNumberDesc", ia: "i18n.phonenumbers.PhoneNumberDesc" }, 2: { name: "national_number_pattern", i: 9, type: String }, 9: { name: "possible_length", aa: !0, i: 5, type: Number }, 10: { name: "possible_length_local_only", aa: !0, i: 5, type: Number }, 6: { name: "example_number", i: 9, type: String } })), d; }, w.m = w.prototype.m, W.prototype.m = function() { - var d = L1; - return d || (L1 = d = r1(W, { + var d = N1; + return d || (N1 = d = r1(W, { 0: { name: "PhoneMetadata", ia: "i18n.phonenumbers.PhoneMetadata" }, 1: { name: "general_desc", i: 11, type: w }, 2: { name: "fixed_line", i: 11, type: w }, @@ -2757,13 +2777,13 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt })), d; }, W.m = W.prototype.m; function V() { - P.call(this); + x.call(this); } - n(V, P); - var T1 = null, a2 = { ra: 0, qa: 1, pa: 5, oa: 10, na: 20 }; + i(V, x); + var A1 = null, a2 = { ra: 0, qa: 1, pa: 5, oa: 10, na: 20 }; V.prototype.m = function() { - var d = T1; - return d || (T1 = d = r1(V, { 0: { name: "PhoneNumber", ia: "i18n.phonenumbers.PhoneNumber" }, 1: { name: "country_code", required: !0, i: 5, type: Number }, 2: { name: "national_number", required: !0, i: 4, type: Number }, 3: { name: "extension", i: 9, type: String }, 4: { name: "italian_leading_zero", i: 8, type: Boolean }, 8: { name: "number_of_leading_zeros", i: 5, defaultValue: 1, type: Number }, 5: { name: "raw_input", i: 9, type: String }, 6: { name: "country_code_source", i: 14, defaultValue: 0, type: a2 }, 7: { + var d = A1; + return d || (A1 = d = r1(V, { 0: { name: "PhoneNumber", ia: "i18n.phonenumbers.PhoneNumber" }, 1: { name: "country_code", required: !0, i: 5, type: Number }, 2: { name: "national_number", required: !0, i: 4, type: Number }, 3: { name: "extension", i: 9, type: String }, 4: { name: "italian_leading_zero", i: 8, type: Boolean }, 8: { name: "number_of_leading_zeros", i: 5, defaultValue: 1, type: Number }, 5: { name: "raw_input", i: 9, type: String }, 6: { name: "country_code_source", i: 14, defaultValue: 0, type: a2 }, 7: { name: "preferred_domestic_carrier_code", i: 9, type: String @@ -8015,8 +8035,8 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt function M1() { return ";ext=" + Y("20") + "|[  \\t,]*(?:e?xt(?:ensi(?:ó?|ó))?n?|e?xtn?|доб|anexo)[:\\..]?[  \\t,-]*" + (Y("20") + "#?|[  \\t,]*(?:[xx##~~]|int|int)[:\\..]?[  \\t,-]*") + (Y("9") + "#?|[- ]+") + (Y("6") + "#|[  \\t]*(?:,{2}|;)[:\\..]?[  \\t,-]*") + (Y("15") + "#?|[  \\t]*(?:,)+[:\\..]?[  \\t,-]*") + (Y("9") + "#?"); } - var x1 = new RegExp("(?:" + M1() + ")$", "i"), I2 = new RegExp("^[0-90-9٠-٩۰-۹]{2}$|^[++]*(?:[-x‐-―−ー--/  ­​⁠ ()()[].\\[\\]/~⁓∼~*]*[0-90-9٠-٩۰-۹]){3,}[-x‐-―−ー--/  ­​⁠ ()()[].\\[\\]/~⁓∼~*A-Za-z0-90-9٠-٩۰-۹]*(?:" + M1() + ")?$", "i"), v2 = /(\$\d)/, S2 = /^\(?\$1\)?$/; - function P1(d) { + var P1 = new RegExp("(?:" + M1() + ")$", "i"), I2 = new RegExp("^[0-90-9٠-٩۰-۹]{2}$|^[++]*(?:[-x‐-―−ー--/  ­​⁠ ()()[].\\[\\]/~⁓∼~*]*[0-90-9٠-٩۰-۹]){3,}[-x‐-―−ー--/  ­​⁠ ()()[].\\[\\]/~⁓∼~*A-Za-z0-90-9٠-٩۰-۹]*(?:" + M1() + ")?$", "i"), v2 = /(\$\d)/, S2 = /^\(?\$1\)?$/; + function x1(d) { return 2 > d.length ? !1 : G(I2, d); } function R1(d) { @@ -8027,10 +8047,10 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt B(d), d.g(t); } function k1(d) { - return d != null && (U(d, 9) != 1 || x(d, 9)[0] != -1); + return d != null && (F(d, 9) != 1 || P(d, 9)[0] != -1); } function o1(d, t) { - for (var $ = new L(), i, s = d.length, u = 0; u < s; ++u) i = d.charAt(u), i = t[i.toUpperCase()], i != null && $.g(i); + for (var $ = new N(), r, s = d.length, u = 0; u < s; ++u) r = d.charAt(u), r = t[r.toUpperCase()], r != null && $.g(r); return $.toString(); } function O1(d) { @@ -8045,17 +8065,17 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt if (0 < $.length) return $; } $ = S(d, 1); - var i = t1(d); - if (t == 0) return G1($, 0, i, ""); - if (!($ in X)) return i; + var r = t1(d); + if (t == 0) return G1($, 0, r, ""); + if (!($ in X)) return r; var s = d1(this, $, e1($)); d = R(d, 3) && p(d, 3).length != 0 ? t == 3 ? ";ext=" + p(d, 3) : R(s, 13) ? p(s, 13) + S(d, 3) : " ext. " + S(d, 3) : ""; d: { - s = x(s, 20).length == 0 || t == 2 ? x(s, 19) : x(s, 20); + s = P(s, 20).length == 0 || t == 2 ? P(s, 19) : P(s, 20); for (var u, l = s.length, h = 0; h < l; ++h) { u = s[h]; - var m = U(u, 3); - if ((m == 0 || i.search(p(u, 3, m - 1)) == 0) && (m = new RegExp(p(u, 1)), G(m, i))) { + var C = F(u, 3); + if ((C == 0 || r.search(p(u, 3, C - 1)) == 0) && (C = new RegExp(p(u, 1)), G(C, r))) { s = u; break d; } @@ -8065,7 +8085,7 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt return s != null && (l = s, s = S(l, 2), u = new RegExp(p(l, 1)), S( l, 5 - ), l = S(l, 4), i = t == 2 && l != null && 0 < l.length ? i.replace(u, s.replace(v2, l)) : i.replace(u, s), t == 3 && (i = i.replace(RegExp("^[-x‐-―−ー--/  ­​⁠ ()()[].\\[\\]/~⁓∼~]+"), ""), i = i.replace(RegExp("[-x‐-―−ー--/  ­​⁠ ()()[].\\[\\]/~⁓∼~]+", "g"), "-"))), G1($, t, i, d); + ), l = S(l, 4), r = t == 2 && l != null && 0 < l.length ? r.replace(u, s.replace(v2, l)) : r.replace(u, s), t == 3 && (r = r.replace(RegExp("^[-x‐-―−ー--/  ­​⁠ ()()[].\\[\\]/~⁓∼~]+"), ""), r = r.replace(RegExp("[-x‐-―−ー--/  ­​⁠ ()()[].\\[\\]/~⁓∼~]+", "g"), "-"))), G1($, t, r, d); }; function d1(d, t, $) { return $ == "001" ? K(d, "" + t) : K(d, $); @@ -8075,16 +8095,16 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt var t = "" + p(d, 2); return R(d, 4) && p(d, 4) && 0 < S(d, 8) ? Array(S(d, 8) + 1).join("0") + t : t; } - function G1(d, t, $, i) { + function G1(d, t, $, r) { switch (t) { case 0: - return "+" + d + $ + i; + return "+" + d + $ + r; case 1: - return "+" + d + " " + $ + i; + return "+" + d + " " + $ + r; case 3: - return "tel:+" + d + "-" + $ + i; + return "tel:+" + d + "-" + $ + r; default: - return $ + i; + return $ + r; } } function l1(d, t) { @@ -8129,25 +8149,25 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt } function k(d, t) { var $ = d.length; - return 0 < U(t, 9) && x(t, 9).indexOf($) == -1 ? !1 : G(S(t, 2), d); + return 0 < F(t, 9) && P(t, 9).indexOf($) == -1 ? !1 : G(S(t, 2), d); } - function F1(d, t) { + function U1(d, t) { if (t == null) return null; var $ = S(t, 1); if ($ = X[$], $ == null) d = null; else if ($.length == 1) d = $[0]; else d: { t = t1(t); - for (var i, s = $.length, u = 0; u < s; u++) { - i = $[u]; - var l = K(d, i); + for (var r, s = $.length, u = 0; u < s; u++) { + r = $[u]; + var l = K(d, r); if (R(l, 23)) { if (t.search(p(l, 23)) == 0) { - d = i; + d = r; break d; } } else if (m1(t, l) != -1) { - d = i; + d = r; break d; } } @@ -8158,28 +8178,28 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt function e1(d) { return d = X[d], d == null ? "ZZ" : d[0]; } - function U1(d, t) { + function F1(d, t) { if (d = K(d, t), d == null) throw Error("Invalid region code: " + t); return S(d, 10); } - function a1(d, t, $, i) { - var s = l1($, i), u = U(s, 9) == 0 ? x(p($, 1), 9) : x(s, 9); - if (s = x(s, 10), i == 2) if (k1(l1($, 0))) d = l1($, 1), k1(d) && (u = u.concat(U(d, 9) == 0 ? x(p($, 1), 9) : x(d, 9)), u.sort(), s.length == 0 ? s = x(d, 10) : (s = s.concat(x(d, 10)), s.sort())); + function a1(d, t, $, r) { + var s = l1($, r), u = F(s, 9) == 0 ? P(p($, 1), 9) : P(s, 9); + if (s = P(s, 10), r == 2) if (k1(l1($, 0))) d = l1($, 1), k1(d) && (u = u.concat(F(d, 9) == 0 ? P(p($, 1), 9) : P(d, 9)), u.sort(), s.length == 0 ? s = P(d, 10) : (s = s.concat(P(d, 10)), s.sort())); else return a1(d, t, $, 1); return u[0] == -1 ? 5 : (t = t.length, -1 < s.indexOf(t) ? 4 : ($ = u[0], $ == t ? 0 : $ > t ? 2 : u[u.length - 1] < t ? 3 : -1 < u.indexOf(t, 1) ? 0 : 5)); } function J(d, t, $) { - var i = t1(t); - return t = S(t, 1), t in X ? (t = d1(d, t, e1(t)), a1(d, i, t, $)) : 1; + var r = t1(t); + return t = S(t, 1), t in X ? (t = d1(d, t, e1(t)), a1(d, r, t, $)) : 1; } function V1(d, t) { if (d = d.toString(), d.length == 0 || d.charAt(0) == "0") return 0; - for (var $, i = d.length, s = 1; 3 >= s && s <= i; ++s) if ($ = parseInt(d.substring(0, s), 10), $ in X) return t.g(d.substring(s)), $; + for (var $, r = d.length, s = 1; 3 >= s && s <= r; ++s) if ($ = parseInt(d.substring(0, s), 10), $ in X) return t.g(d.substring(s)), $; return 0; } - function K1(d, t, $, i, s, u) { + function K1(d, t, $, r, s, u) { if (t.length == 0) return 0; - t = new L(t); + t = new N(t); var l; $ != null && (l = p($, 11)), l == null && (l = "NonMatch"); var h = t.toString(); @@ -8188,26 +8208,26 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt else { if (h = new RegExp(l), B1(t), l = t.toString(), l.search(h) == 0) { h = l.match(h)[0].length; - var m = l.substring(h).match(D1); - m && m[1] != null && 0 < m[1].length && o1(m[1], C1) == "0" ? l = !1 : (B(t), t.g(l.substring(h)), l = !0); + var C = l.substring(h).match(D1); + C && C[1] != null && 0 < C[1].length && o1(C[1], C1) == "0" ? l = !1 : (B(t), t.g(l.substring(h)), l = !0); } else l = !1; l = l ? 5 : 20; } if (s && E(u, 6, l), l != 20) { if (2 >= t.h.length) throw Error("Phone number too short after IDD"); - if (d = V1(t, i), d != 0) return E(u, 1, d), d; + if (d = V1(t, r), d != 0) return E(u, 1, d), d; throw Error("Invalid country calling code"); } - return $ != null && (l = S($, 10), h = "" + l, m = t.toString(), m.lastIndexOf(h, 0) == 0 && (h = new L(m.substring(h.length)), m = p($, 1), m = new RegExp(S(m, 2)), H1(h, $, null), h = h.toString(), !G(m, t.toString()) && G(m, h) || a1(d, t.toString(), $, -1) == 3)) ? (i.g(h), s && E(u, 6, 10), E(u, 1, l), l) : (E(u, 1, 0), 0); + return $ != null && (l = S($, 10), h = "" + l, C = t.toString(), C.lastIndexOf(h, 0) == 0 && (h = new N(C.substring(h.length)), C = p($, 1), C = new RegExp(S(C, 2)), H1(h, $, null), h = h.toString(), !G(C, t.toString()) && G(C, h) || a1(d, t.toString(), $, -1) == 3)) ? (r.g(h), s && E(u, 6, 10), E(u, 1, l), l) : (E(u, 1, 0), 0); } function H1(d, t, $) { - var i = d.toString(), s = i.length, u = p(t, 15); + var r = d.toString(), s = r.length, u = p(t, 15); if (s != 0 && u != null && u.length != 0) { var l = new RegExp("^(?:" + u + ")"); - if (s = l.exec(i)) { + if (s = l.exec(r)) { u = new RegExp(S(p(t, 1), 2)); - var h = G(u, i), m = s.length - 1; - t = p(t, 16), t == null || t.length == 0 || s[m] == null || s[m].length == 0 ? (!h || G(u, i.substring(s[0].length))) && ($ != null && 0 < m && s[m] != null && $.g(s[1]), d.set(i.substring(s[0].length))) : (i = i.replace(l, t), (!h || G(u, i)) && ($ != null && 0 < m && $.g(s[1]), d.set(i))); + var h = G(u, r), C = s.length - 1; + t = p(t, 16), t == null || t.length == 0 || s[C] == null || s[C].length == 0 ? (!h || G(u, r.substring(s[0].length))) && ($ != null && 0 < C && s[C] != null && $.g(s[1]), d.set(r.substring(s[0].length))) : (r = r.replace(l, t), (!h || G(u, r)) && ($ != null && 0 < C && $.g(s[1]), d.set(r))); } } } @@ -8215,10 +8235,10 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt if (!u1($) && 0 < t.length && t.charAt(0) != "+") throw Error("Invalid country calling code"); return j1(d, t, $, !0); } - function j1(d, t, $, i) { + function j1(d, t, $, r) { if (t == null) throw Error("The string supplied did not seem to be a phone number"); if (250 < t.length) throw Error("The string supplied is too long to be a phone number"); - var s = new L(), u = t.indexOf(";phone-context="); + var s = new N(), u = t.indexOf(";phone-context="); if (u === -1) u = null; else if (u += 15, u >= t.length) u = ""; else { @@ -8226,73 +8246,73 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt u = l !== -1 ? t.substring(u, l) : t.substring(u); } var h = u; - if (h == null ? l = !0 : h.length === 0 ? l = !1 : (l = y2.exec(h), h = _2.exec(h), l = l !== null || h !== null), !l || (u != null ? (u.charAt(0) === "+" && s.g(u), u = t.indexOf("tel:"), s.g(t.substring(0 <= u ? u + 4 : 0, t.indexOf(";phone-context=")))) : (u = s.g, l = t ?? "", h = l.search(p2), 0 <= h ? (l = l.substring(h), l = l.replace(C2, ""), h = l.search(g2), 0 <= h && (l = l.substring(0, h))) : l = "", u.call(s, l)), u = s.toString(), l = u.indexOf(";isub="), 0 < l && (B(s), s.g(u.substring(0, l))), !P1(s.toString()))) throw Error("The string supplied did not seem to be a phone number"); + if (h == null ? l = !0 : h.length === 0 ? l = !1 : (l = y2.exec(h), h = _2.exec(h), l = l !== null || h !== null), !l || (u != null ? (u.charAt(0) === "+" && s.g(u), u = t.indexOf("tel:"), s.g(t.substring(0 <= u ? u + 4 : 0, t.indexOf(";phone-context=")))) : (u = s.g, l = t ?? "", h = l.search(p2), 0 <= h ? (l = l.substring(h), l = l.replace(C2, ""), h = l.search(g2), 0 <= h && (l = l.substring(0, h))) : l = "", u.call(s, l)), u = s.toString(), l = u.indexOf(";isub="), 0 < l && (B(s), s.g(u.substring(0, l))), !x1(s.toString()))) throw Error("The string supplied did not seem to be a phone number"); if (u = s.toString(), !(u1($) || u != null && 0 < u.length && Q.test(u))) throw Error("Invalid country calling code"); - u = new V(), i && E(u, 5, t); + u = new V(), r && E(u, 5, t); d: { - if (t = s.toString(), l = t.search(x1), 0 <= l && P1(t.substring(0, l))) { - h = t.match(x1); - for (var m = h.length, F = 1; F < m; ++F) if (h[F] != null && 0 < h[F].length) { - B(s), s.g(t.substring(0, l)), t = h[F]; + if (t = s.toString(), l = t.search(P1), 0 <= l && x1(t.substring(0, l))) { + h = t.match(P1); + for (var C = h.length, U = 1; U < C; ++U) if (h[U] != null && 0 < h[U].length) { + B(s), s.g(t.substring(0, l)), t = h[U]; break d; } } t = ""; } - 0 < t.length && E(u, 3, t), l = K(d, $), t = new L(), h = 0, m = s.toString(); + 0 < t.length && E(u, 3, t), l = K(d, $), t = new N(), h = 0, C = s.toString(); try { - h = K1(d, m, l, t, i, u); + h = K1(d, C, l, t, r, u); } catch (_1) { - if (_1.message == "Invalid country calling code" && Q.test(m)) { - if (m = m.replace(Q, ""), h = K1(d, m, l, t, i, u), h == 0) throw _1; + if (_1.message == "Invalid country calling code" && Q.test(C)) { + if (C = C.replace(Q, ""), h = K1(d, C, l, t, r, u), h == 0) throw _1; } else throw _1; } if (h != 0 ? (s = e1(h), s != $ && (l = d1(d, h, s))) : (B1(s), t.g(s.toString()), $ != null ? (h = S(l, 10), E( u, 1, h - )) : i && (delete u.h[6], u.g && delete u.g[6])), 2 > t.h.length || (l != null && ($ = new L(), s = new L(t.toString()), H1(s, l, $), d = a1(d, s.toString(), l, -1), d != 2 && d != 4 && d != 5 && (t = s, i && 0 < $.toString().length && E(u, 7, $.toString()))), i = t.toString(), d = i.length, 2 > d)) throw Error("The string supplied is too short to be a phone number"); + )) : r && (delete u.h[6], u.g && delete u.g[6])), 2 > t.h.length || (l != null && ($ = new N(), s = new N(t.toString()), H1(s, l, $), d = a1(d, s.toString(), l, -1), d != 2 && d != 4 && d != 5 && (t = s, r && 0 < $.toString().length && E(u, 7, $.toString()))), r = t.toString(), d = r.length, 2 > d)) throw Error("The string supplied is too short to be a phone number"); if (17 < d) throw Error("The string supplied is too long to be a phone number"); - if (1 < i.length && i.charAt(0) == "0") { - for (E(u, 4, !0), d = 1; d < i.length - 1 && i.charAt(d) == "0"; ) d++; + if (1 < r.length && r.charAt(0) == "0") { + for (E(u, 4, !0), d = 1; d < r.length - 1 && r.charAt(d) == "0"; ) d++; d != 1 && E(u, 8, d); } - return E(u, 2, parseInt(i, 10)), u; + return E(u, 2, parseInt(r, 10)), u; } function G(d, t) { return !!((d = typeof d == "string" ? t.match("^(?:" + d + ")$") : t.match(d)) && d[0].length == t.length); } function w2(d) { - this.fa = RegExp(" "), this.ja = "", this.v = new L(), this.da = "", this.s = new L(), this.ba = new L(), this.u = !0, this.ea = this.ca = this.la = !1, this.ga = D.g(), this.$ = 0, this.h = new L(), this.ha = !1, this.o = "", this.g = new L(), this.j = [], this.ka = d, this.l = Z1(this, this.ka); + this.fa = RegExp(" "), this.ja = "", this.v = new N(), this.da = "", this.s = new N(), this.ba = new N(), this.u = !0, this.ea = this.ca = this.la = !1, this.ga = D.g(), this.$ = 0, this.h = new N(), this.ha = !1, this.o = "", this.g = new N(), this.j = [], this.ka = d, this.l = Z1(this, this.ka); } var W1 = new W(); E(W1, 11, "NA"); var b2 = RegExp("^[-x‐-―−ー--/  ­​⁠ ()()[].\\[\\]/~⁓∼~]*\\$1[-x‐-―−ー--/  ­​⁠ ()()[].\\[\\]/~⁓∼~]*(\\$\\d[-x‐-―−ー--/  ­​⁠ ()()[].\\[\\]/~⁓∼~]*)*$"), z1 = /[- ]/; function Z1(d, t) { var $ = d.ga; - return t = u1(t) ? U1($, t) : 0, d = K(d.ga, e1(t)), d ?? W1; + return t = u1(t) ? F1($, t) : 0, d = K(d.ga, e1(t)), d ?? W1; } function Y1(d) { for (var t = d.j.length, $ = 0; $ < t; ++$) { - var i = d.j[$], s = S(i, 1); + var r = d.j[$], s = S(r, 1); if (d.da == s) return !1; - var u = d, l = i, h = S(l, 1); + var u = d, l = r, h = S(l, 1); B(u.v); - var m = u; + var C = u; l = S(l, 2); - var F = "999999999999999".match(h)[0]; - if (F.length < m.g.h.length ? m = "" : (m = F.replace(new RegExp(h, "g"), l), m = m.replace(RegExp("9", "g"), " ")), 0 < m.length ? (u.v.g(m), u = !0) : u = !1, u) return d.da = s, d.ha = z1.test(p(i, 4)), d.$ = 0, !0; + var U = "999999999999999".match(h)[0]; + if (U.length < C.g.h.length ? C = "" : (C = U.replace(new RegExp(h, "g"), l), C = C.replace(RegExp("9", "g"), " ")), 0 < C.length ? (u.v.g(C), u = !0) : u = !1, u) return d.da = s, d.ha = z1.test(p(r, 4)), d.$ = 0, !0; } return d.u = !1; } function J1(d, t) { - for (var $ = [], i = t.length - 3, s = d.j.length, u = 0; u < s; ++u) { + for (var $ = [], r = t.length - 3, s = d.j.length, u = 0; u < s; ++u) { var l = d.j[u]; - U(l, 3) == 0 ? $.push(d.j[u]) : (l = p(l, 3, Math.min(i, U(l, 3) - 1)), t.search(l) == 0 && $.push(d.j[u])); + F(l, 3) == 0 ? $.push(d.j[u]) : (l = p(l, 3, Math.min(r, F(l, 3) - 1)), t.search(l) == 0 && $.push(d.j[u])); } d.j = $; } - function N2(d, t) { + function L2(d, t) { d.s.g(t); var $ = t; if (D1.test($) || d.s.h.length == 1 && f2.test($) ? (t == "+" ? ($ = t, d.ba.g(t)) : ($ = C1[t], d.ba.g($), d.g.g($)), t = $) : (d.u = !1, d.la = !0), !d.u) { @@ -8319,8 +8339,8 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt return d.u = !0, d.ea = !1, d.j = [], d.$ = 0, B(d.v), d.da = "", y1(d); } function X1(d) { - for (var t = d.g.toString(), $ = d.j.length, i = 0; i < $; ++i) { - var s = d.j[i], u = S(s, 1); + for (var t = d.g.toString(), $ = d.j.length, r = 0; r < $; ++r) { + var s = d.j[r], u = S(s, 1); if (new RegExp("^(?:" + u + ")$").test(t) && (d.ha = z1.test(p(s, 4)), s = t.replace(new RegExp(u, "g"), p(s, 2)), s = h1(d, s), o1(s, h2) == d.ba)) return s; } return ""; @@ -8332,7 +8352,7 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt function y1(d) { var t = d.g.toString(); if (3 <= t.length) { - for (var $ = d.ca && d.o.length == 0 && 0 < U(d.l, 20) ? x(d.l, 20) : x(d.l, 19), i = $.length, s = 0; s < i; ++s) { + for (var $ = d.ca && d.o.length == 0 && 0 < F(d.l, 20) ? P(d.l, 20) : P(d.l, 19), r = $.length, s = 0; s < r; ++s) { var u = $[s]; 0 < d.o.length && O1(S(u, 4)) && !p(u, 6) && !R(u, 5) || (d.o.length != 0 || d.ca || O1(S(u, 4)) || p(u, 6)) && b2.test(S(u, 2)) && d.j.push(u); } @@ -8343,16 +8363,16 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt function Q1(d) { var t = d.g.toString(), $ = t.length; if (0 < $) { - for (var i = "", s = 0; s < $; s++) i = $2(d, t.charAt(s)); - return d.u ? h1(d, i) : d.s.toString(); + for (var r = "", s = 0; s < $; s++) r = $2(d, t.charAt(s)); + return d.u ? h1(d, r) : d.s.toString(); } return d.h.toString(); } function d2(d) { var t = d.g.toString(), $ = 0; - if (p(d.l, 10) != 1) var i = !1; - else i = d.g.toString(), i = i.charAt(0) == "1" && i.charAt(1) != "0" && i.charAt(1) != "1"; - return i ? ($ = 1, d.h.g("1").g(" "), d.ca = !0) : R(d.l, 15) && (i = new RegExp("^(?:" + p(d.l, 15) + ")"), i = t.match(i), i != null && i[0] != null && 0 < i[0].length && (d.ca = !0, $ = i[0].length, d.h.g(t.substring(0, $)))), B(d.g), d.g.g(t.substring($)), t.substring(0, $); + if (p(d.l, 10) != 1) var r = !1; + else r = d.g.toString(), r = r.charAt(0) == "1" && r.charAt(1) != "0" && r.charAt(1) != "1"; + return r ? ($ = 1, d.h.g("1").g(" "), d.ca = !0) : R(d.l, 15) && (r = new RegExp("^(?:" + p(d.l, 15) + ")"), r = t.match(r), r != null && r[0] != null && 0 < r[0].length && (d.ca = !0, $ = r[0].length, d.h.g(t.substring(0, $)))), B(d.g), d.g.g(t.substring($)), t.substring(0, $); } function t2(d) { var t = d.ba.toString(), $ = new RegExp("^(?:\\+|" + p(d.l, 11) + ")"); @@ -8360,23 +8380,23 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt } function e2(d) { if (d.g.h.length == 0) return !1; - var t = new L(), $ = V1(d.g, t); + var t = new N(), $ = V1(d.g, t); return $ == 0 ? !1 : (B(d.g), d.g.g(t.toString()), t = e1($), t == "001" ? d.l = K(d.ga, "" + $) : t != d.ka && (d.l = Z1(d, t)), d.h.g("" + $).g(" "), d.o = "", !0); } function $2(d, t) { var $ = d.v.toString(); if (0 <= $.substring(d.$).search(d.fa)) { - var i = $.search(d.fa); - return t = $.replace(d.fa, t), B(d.v), d.v.g(t), d.$ = i, t.substring(0, d.$ + 1); + var r = $.search(d.fa); + return t = $.replace(d.fa, t), B(d.v), d.v.g(t), d.$ = r, t.substring(0, d.$ + 1); } return d.j.length == 1 && (d.u = !1), d.da = "", d.s.toString(); } const c1 = { FIXED_LINE: 0, MOBILE: 1, FIXED_LINE_OR_MOBILE: 2, TOLL_FREE: 3, PREMIUM_RATE: 4, SHARED_COST: 5, VOIP: 6, PERSONAL_NUMBER: 7, PAGER: 8, UAN: 9, VOICEMAIL: 10, UNKNOWN: -1 }; e("intlTelInputUtilsTemp", {}), e("intlTelInputUtilsTemp.formatNumberAsYouType", (d, t) => { try { - const $ = d.replace(/[^+0-9]/g, ""), i = new w2(t); + const $ = d.replace(/[^+0-9]/g, ""), r = new w2(t); t = ""; - for (let s = 0; s < $.length; s++) i.ja = N2(i, $.charAt(s)), t = i.ja; + for (let s = 0; s < $.length; s++) r.ja = L2(r, $.charAt(s)), t = r.ja; return t; } catch { return d; @@ -8384,16 +8404,16 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt }), e("intlTelInputUtilsTemp.formatNumber", (d, t, $) => { try { const s = D.g(), u = z(s, d, t); - var i = J(s, u, -1); - return i == 0 || i == 4 ? s.format(u, typeof $ > "u" ? 0 : $) : d; + var r = J(s, u, -1); + return r == 0 || r == 4 ? s.format(u, typeof $ > "u" ? 0 : $) : d; } catch { return d; } - }), e("intlTelInputUtilsTemp.getExampleNumber", (d, t, $, i) => { + }), e("intlTelInputUtilsTemp.getExampleNumber", (d, t, $, r) => { try { - const m = D.g(); + const C = D.g(); d: { - var s = m; + var s = C; if (u1(d)) { var u = l1(K(s, d), $); try { @@ -8406,7 +8426,7 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt } h = null; } - return m.format(h, i ? 0 : t ? 2 : 1); + return C.format(h, r ? 0 : t ? 2 : 1); } catch { return ""; } @@ -8419,11 +8439,11 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt }), e("intlTelInputUtilsTemp.getNumberType", (d, t) => { try { const l = D.g(), h = z(l, d, t); - var $ = F1(l, h), i = d1(l, S(h, 1), $); - if (i == null) var s = -1; + var $ = U1(l, h), r = d1(l, S(h, 1), $); + if (r == null) var s = -1; else { var u = t1(h); - s = m1(u, i); + s = m1(u, r); } return s; } catch { @@ -8432,18 +8452,18 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt }), e("intlTelInputUtilsTemp.getValidationError", (d, t) => { if (!t) return 1; try { - const $ = D.g(), i = z($, d, t); - return J($, i, -1); + const $ = D.g(), r = z($, d, t); + return J($, r, -1); } catch ($) { return $.message === "Invalid country calling code" ? 1 : 3 >= d.length || $.message === "Phone number too short after IDD" || $.message === "The string supplied is too short to be a phone number" ? 2 : $.message === "The string supplied is too long to be a phone number" ? 3 : -99; } }), e("intlTelInputUtilsTemp.isValidNumber", (d, t) => { try { - const m = D.g(); - var $ = z(m, d, t), i = F1(m, $); - d = m; - var s = S($, 1), u = d1(d, s, i); - if (u == null || i != "001" && s != U1(d, i)) var l = !1; + const C = D.g(); + var $ = z(C, d, t), r = U1(C, $); + d = C; + var s = S($, 1), u = d1(d, s, r); + if (u == null || r != "001" && s != F1(d, r)) var l = !1; else { var h = t1($); l = m1(h, u) != -1; @@ -8454,16 +8474,16 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt } }), e("intlTelInputUtilsTemp.isPossibleNumber", (d, t, $) => { try { - const i = D.g(), s = z(i, d, t); + const r = D.g(), s = z(r, d, t); if ($) { - const u = J(i, s, c1[$]) === 0; + const u = J(r, s, c1[$]) === 0; if ($ === "FIXED_LINE_OR_MOBILE") { - const l = J(i, s, c1.MOBILE) === 0, h = J(i, s, c1.FIXED_LINE) === 0; + const l = J(r, s, c1.MOBILE) === 0, h = J(r, s, c1.FIXED_LINE) === 0; return l || h || u; } return u; } - return J(i, s, -1) === 0; + return J(r, s, -1) === 0; } catch { return !1; } @@ -8477,10 +8497,10 @@ const V2 = (y) => !C.utils && !C.startedLoadingUtilsScript ? (C.startedLoadingUt })(); const K2 = window.intlTelInputUtilsTemp; delete window.intlTelInputUtilsTemp; -C.utils = K2; +m.utils = K2; const j2 = { __name: "IntlTelInputWithUtils", - props: /* @__PURE__ */ n2({ + props: /* @__PURE__ */ i2({ disabled: { type: Boolean, default: !1 @@ -8504,14 +8524,14 @@ const j2 = { }, modelModifiers: {} }), - emits: /* @__PURE__ */ n2([ + emits: /* @__PURE__ */ i2([ "changeNumber", "changeCountry", "changeValidity", "changeErrorCode" ], ["update:modelValue"]), - setup(y, { expose: e, emit: n }) { - const r = A2(y, "modelValue"), o = y, a = n, c = I1(), g = I1(), f = I1(!1), b = () => g.value ? o.options.strictMode ? g.value.isValidNumberPrecise() : g.value.isValidNumber() : null, _ = () => { + setup(y, { expose: e, emit: i }) { + const n = T2(y, "modelValue"), o = y, a = i, c = I1(), g = I1(), f = I1(!1), b = () => g.value ? o.options.strictMode ? g.value.isValidNumberPrecise() : g.value.isValidNumber() : null, _ = () => { let v = b(); f.value !== v && (f.value = v, a("changeValidity", !!v), a( "changeErrorCode", @@ -8520,30 +8540,30 @@ const j2 = { }, I = () => { var v; a("changeNumber", ((v = g.value) == null ? void 0 : v.getNumber()) ?? ""), _(); - }, N = () => { + }, L = () => { var v; a("changeCountry", ((v = g.value) == null ? void 0 : v.getSelectedCountryData().iso2) ?? ""), I(), _(); }; - return L2(() => { - c.value && (g.value = C(c.value, o.options), o.value && g.value.setNumber(o.value), o.disabled && g.value.setDisabled(o.disabled)); - }), T2( + return N2(() => { + c.value && (g.value = m(c.value, o.options), o.value && g.value.setNumber(o.value), o.disabled && g.value.setDisabled(o.disabled)); + }), A2( () => o.disabled, (v) => { - var A; - return (A = g.value) == null ? void 0 : A.setDisabled(v); + var T; + return (T = g.value) == null ? void 0 : T.setDisabled(v); } ), E2(() => { var v; return (v = g.value) == null ? void 0 : v.destroy(); - }), e({ instance: g, input: c }), (v, A) => D2((M2(), x2("input", P2({ + }), e({ instance: g, input: c }), (v, T) => D2((M2(), P2("input", x2({ ref_key: "input", ref: c, - "onUpdate:modelValue": A[0] || (A[0] = (M) => r.value = M), + "onUpdate:modelValue": T[0] || (T[0] = (M) => n.value = M), type: "tel", - onCountrychange: N, + onCountrychange: L, onInput: I }, y.inputProps), null, 16)), [ - [R2, r.value] + [R2, n.value] ]); } };