{"version":3,"file":"hyperform.esm-cc948095.js","sources":["../../../node_modules/hyperform/dist/hyperform.esm.js"],"sourcesContent":["// hyperform.js.org\nvar instances = new WeakMap();\n/**\n * wrap
s, window or document, that get treated with the global\n * hyperform()\n */\n\nfunction Wrapper(form, settings) {\n /* do not allow more than one instance per form. Otherwise we'd end\n * up with double event handlers, polyfills re-applied, ... */\n var existing = instances.get(form);\n\n if (existing) {\n existing.settings = settings;\n return existing;\n }\n\n this.form = form;\n this.settings = settings;\n this.observer = null;\n instances.set(form, this);\n}\nWrapper.prototype = {\n destroy: function destroy() {\n instances[\"delete\"](this.form);\n\n if (this._destruct) {\n this._destruct();\n }\n }\n};\n/**\n * try to get the appropriate wrapper for a specific element by looking up\n * its parent chain\n *\n * @return Wrapper | undefined\n */\n\nfunction get_wrapper(element) {\n var wrapped;\n\n if (element.form) {\n /* try a shortcut with the element's */\n wrapped = instances.get(element.form);\n }\n /* walk up the parent nodes until document (including) */\n\n\n while (!wrapped && element) {\n wrapped = instances.get(element);\n element = element.parentNode;\n }\n\n if (!wrapped) {\n /* try the global instance, if exists. This may also be undefined. */\n wrapped = instances.get(window);\n }\n\n return wrapped;\n}\n\n/**\n * filter a form's elements for the ones needing validation prior to\n * a submit\n *\n * Returns an array of form elements.\n */\n\nfunction get_validated_elements(form) {\n var wrapped_form = get_wrapper(form);\n return Array.prototype.filter.call(form.elements, function (element) {\n /* it must have a name (or validating nameless inputs is allowed) */\n if (element.getAttribute('name') || wrapped_form && wrapped_form.settings.validateNameless) {\n return true;\n }\n\n return false;\n });\n}\n\nvar registry = Object.create(null);\n/**\n * run all actions registered for a hook\n *\n * Every action gets called with a state object as `this` argument and with the\n * hook's call arguments as call arguments.\n *\n * @return mixed the returned value of the action calls or undefined\n */\n\nfunction call_hook(hook) {\n var result;\n var call_args = Array.prototype.slice.call(arguments, 1);\n\n if (hook in registry) {\n result = registry[hook].reduce(function (args) {\n return function (previousResult, currentAction) {\n var interimResult = currentAction.apply({\n state: previousResult,\n hook: hook\n }, args);\n return interimResult !== undefined ? interimResult : previousResult;\n };\n }(call_args), result);\n }\n\n return result;\n}\n/**\n * Filter a value through hooked functions\n *\n * Allows for additional parameters:\n * js> do_filter('foo', null, current_element)\n */\n\nfunction do_filter(hook, initial_value) {\n var result = initial_value;\n var call_args = Array.prototype.slice.call(arguments, 1);\n\n if (hook in registry) {\n result = registry[hook].reduce(function (previousResult, currentAction) {\n call_args[0] = previousResult;\n var interimResult = currentAction.apply({\n state: previousResult,\n hook: hook\n }, call_args);\n return interimResult !== undefined ? interimResult : previousResult;\n }, result);\n }\n\n return result;\n}\n/**\n * remove an action again\n */\n\nfunction remove_hook(hook, action) {\n if (hook in registry) {\n for (var i = 0; i < registry[hook].length; i++) {\n if (registry[hook][i] === action) {\n registry[hook].splice(i, 1);\n break;\n }\n }\n }\n}\n/**\n * add an action to a hook\n */\n\nfunction add_hook(hook, action, position) {\n if (!(hook in registry)) {\n registry[hook] = [];\n }\n\n if (position === undefined) {\n position = registry[hook].length;\n }\n\n registry[hook].splice(position, 0, action);\n}\n\n/**\n * return either the data of a hook call or the result of action, if the\n * former is undefined\n *\n * @return function a function wrapper around action\n */\n\nfunction return_hook_or (hook, action) {\n return function () {\n var data = call_hook(hook, Array.prototype.slice.call(arguments));\n\n if (data !== undefined) {\n return data;\n }\n\n return action.apply(this, arguments);\n };\n}\n\n/* the following code is borrowed from the WebComponents project, licensed\n * under the BSD license. Source:\n * \n */\n// defaultPrevented is broken in IE.\n// https://connect.microsoft.com/IE/feedback/details/790389/event-defaultprevented-returns-false-after-preventdefault-was-called\n\nvar workingDefaultPrevented = function () {\n var e = document.createEvent('Event');\n e.initEvent('foo', true, true);\n e.preventDefault();\n return e.defaultPrevented;\n}();\n\nif (!workingDefaultPrevented) {\n var origPreventDefault = window.Event.prototype.preventDefault;\n\n window.Event.prototype.preventDefault = function () {\n if (!this.cancelable) {\n return;\n }\n\n origPreventDefault.call(this);\n Object.defineProperty(this, 'defaultPrevented', {\n get: function get() {\n return true;\n },\n configurable: true\n });\n };\n}\n/* end of borrowed code */\n\n\nfunction create_event(name) {\n var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},\n _ref$bubbles = _ref.bubbles,\n bubbles = _ref$bubbles === void 0 ? true : _ref$bubbles,\n _ref$cancelable = _ref.cancelable,\n cancelable = _ref$cancelable === void 0 ? false : _ref$cancelable;\n\n var event = document.createEvent('Event');\n event.initEvent(name, bubbles, cancelable);\n return event;\n}\nfunction trigger_event (element, event) {\n var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},\n _ref2$bubbles = _ref2.bubbles,\n bubbles = _ref2$bubbles === void 0 ? true : _ref2$bubbles,\n _ref2$cancelable = _ref2.cancelable,\n cancelable = _ref2$cancelable === void 0 ? false : _ref2$cancelable;\n\n var payload = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};\n\n if (!(event instanceof window.Event)) {\n event = create_event(event, {\n bubbles: bubbles,\n cancelable: cancelable\n });\n }\n\n for (var key in payload) {\n if (payload.hasOwnProperty(key)) {\n event[key] = payload[key];\n }\n }\n\n element.dispatchEvent(event);\n return event;\n}\n\n/* and datetime-local? Spec says “Nah!” */\n\nvar dates = ['datetime', 'date', 'month', 'week', 'time'];\nvar plain_numbers = ['number', 'range'];\n/* everything that returns something meaningful for valueAsNumber and\n * can have the step attribute */\n\nvar numbers = dates.concat(plain_numbers, 'datetime-local');\n/* the spec says to only check those for syntax in validity.typeMismatch.\n * ¯\\_(ツ)_/¯ */\n\nvar type_checked = ['email', 'url'];\n/* check these for validity.badInput */\n\nvar input_checked = ['email', 'date', 'month', 'week', 'time', 'datetime', 'datetime-local', 'number', 'range', 'color'];\nvar text = ['text', 'search', 'tel', 'password'].concat(type_checked);\n/* input element types, that are candidates for the validation API.\n * Missing from this set are: button, hidden, menu (from