(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : (factory()); }(this, (function () { 'use strict'; // @ts-nocheck (function (undefined) { // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js var detect = ( // In IE8, defineProperty could only act on DOM elements, so full support // for the feature requires the ability to set a property on an arbitrary object 'defineProperty' in Object && (function() { try { var a = {}; Object.defineProperty(a, 'test', {value:42}); return true; } catch(e) { return false } }()) ); if (detect) return // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always (function (nativeDefineProperty) { var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__'); var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine'; var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value'; Object.defineProperty = function defineProperty(object, property, descriptor) { // Where native support exists, assume it if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) { return nativeDefineProperty(object, property, descriptor); } if (object === null || !(object instanceof Object || typeof object === 'object')) { throw new TypeError('Object.defineProperty called on non-object'); } if (!(descriptor instanceof Object)) { throw new TypeError('Property description must be an object'); } var propertyString = String(property); var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor; var getterType = 'get' in descriptor && typeof descriptor.get; var setterType = 'set' in descriptor && typeof descriptor.set; // handle descriptor.get if (getterType) { if (getterType !== 'function') { throw new TypeError('Getter must be a function'); } if (!supportsAccessors) { throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); } if (hasValueOrWritable) { throw new TypeError(ERR_VALUE_ACCESSORS); } Object.__defineGetter__.call(object, propertyString, descriptor.get); } else { object[propertyString] = descriptor.value; } // handle descriptor.set if (setterType) { if (setterType !== 'function') { throw new TypeError('Setter must be a function'); } if (!supportsAccessors) { throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); } if (hasValueOrWritable) { throw new TypeError(ERR_VALUE_ACCESSORS); } Object.__defineSetter__.call(object, propertyString, descriptor.set); } // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above if ('value' in descriptor) { object[propertyString] = descriptor.value; } return object; }; }(Object.defineProperty)); }) .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); // @ts-nocheck (function(undefined) { // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Function/prototype/bind/detect.js var detect = 'bind' in Function.prototype; if (detect) return // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Function.prototype.bind&flags=always Object.defineProperty(Function.prototype, 'bind', { value: function bind(that) { // .length is 1 // add necessary es5-shim utilities var $Array = Array; var $Object = Object; var ObjectPrototype = $Object.prototype; var ArrayPrototype = $Array.prototype; var Empty = function Empty() {}; var to_string = ObjectPrototype.toString; var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, tryFunctionObject = function tryFunctionObject(value) { try { fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]'; isCallable = function isCallable(value) { if (typeof value !== 'function') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; }; var array_slice = ArrayPrototype.slice; var array_concat = ArrayPrototype.concat; var array_push = ArrayPrototype.push; var max = Math.max; // /add necessary es5-shim utilities // 1. Let Target be the this value. var target = this; // 2. If IsCallable(Target) is false, throw a TypeError exception. if (!isCallable(target)) { throw new TypeError('Function.prototype.bind called on incompatible ' + target); } // 3. Let A be a new (possibly empty) internal list of all of the // argument values provided after thisArg (arg1, arg2 etc), in order. // XXX slicedArgs will stand in for "A" if used var args = array_slice.call(arguments, 1); // for normal call // 4. Let F be a new native ECMAScript object. // 11. Set the [[Prototype]] internal property of F to the standard // built-in Function prototype object as specified in 15.3.3.1. // 12. Set the [[Call]] internal property of F as described in // 15.3.4.5.1. // 13. Set the [[Construct]] internal property of F as described in // 15.3.4.5.2. // 14. Set the [[HasInstance]] internal property of F as described in // 15.3.4.5.3. var bound; var binder = function () { if (this instanceof bound) { // 15.3.4.5.2 [[Construct]] // When the [[Construct]] internal method of a function object, // F that was created using the bind function is called with a // list of arguments ExtraArgs, the following steps are taken: // 1. Let target be the value of F's [[TargetFunction]] // internal property. // 2. If target has no [[Construct]] internal method, a // TypeError exception is thrown. // 3. Let boundArgs be the value of F's [[BoundArgs]] internal // property. // 4. Let args be a new list containing the same values as the // list boundArgs in the same order followed by the same // values as the list ExtraArgs in the same order. // 5. Return the result of calling the [[Construct]] internal // method of target providing args as the arguments. var result = target.apply( this, array_concat.call(args, array_slice.call(arguments)) ); if ($Object(result) === result) { return result; } return this; } else { // 15.3.4.5.1 [[Call]] // When the [[Call]] internal method of a function object, F, // which was created using the bind function is called with a // this value and a list of arguments ExtraArgs, the following // steps are taken: // 1. Let boundArgs be the value of F's [[BoundArgs]] internal // property. // 2. Let boundThis be the value of F's [[BoundThis]] internal // property. // 3. Let target be the value of F's [[TargetFunction]] internal // property. // 4. Let args be a new list containing the same values as the // list boundArgs in the same order followed by the same // values as the list ExtraArgs in the same order. // 5. Return the result of calling the [[Call]] internal method // of target providing boundThis as the this value and // providing args as the arguments. // equiv: target.call(this, ...boundArgs, ...args) return target.apply( that, array_concat.call(args, array_slice.call(arguments)) ); } }; // 15. If the [[Class]] internal property of Target is "Function", then // a. Let L be the length property of Target minus the length of A. // b. Set the length own property of F to either 0 or L, whichever is // larger. // 16. Else set the length own property of F to 0. var boundLength = max(0, target.length - args.length); // 17. Set the attributes of the length own property of F to the values // specified in 15.3.5.1. var boundArgs = []; for (var i = 0; i < boundLength; i++) { array_push.call(boundArgs, '$' + i); } // XXX Build a dynamic function with desired amount of arguments is the only // way to set the length property of a function. // In environments where Content Security Policies enabled (Chrome extensions, // for ex.) all use of eval or Function costructor throws an exception. // However in all of these environments Function.prototype.bind exists // and so this code will never be executed. bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder); if (target.prototype) { Empty.prototype = target.prototype; bound.prototype = new Empty(); // Clean up dangling references. Empty.prototype = null; } // TODO // 18. Set the [[Extensible]] internal property of F to true. // TODO // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3). // 20. Call the [[DefineOwnProperty]] internal method of F with // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]: // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and // false. // 21. Call the [[DefineOwnProperty]] internal method of F with // arguments "arguments", PropertyDescriptor {[[Get]]: thrower, // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false}, // and false. // TODO // NOTE Function objects created using Function.prototype.bind do not // have a prototype property or the [[Code]], [[FormalParameters]], and // [[Scope]] internal properties. // XXX can't delete prototype in pure-js. // 22. Return F. return bound; } }); }) .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); }))); //# sourceMappingURL=bind.js.map