(self["webpackChunk_core_volunteer_app"] = self["webpackChunk_core_volunteer_app"] || []).push([["vendors-node_modules_gopd_index_js-node_modules_has-symbols_index_js-node_modules_hasown_inde-de185c"],{ /***/ "../../../node_modules/gopd/gOPD.js": /*!******************************************!*\ !*** ../../../node_modules/gopd/gOPD.js ***! \******************************************/ /***/ ((module) => { "use strict"; /** @type {import('./gOPD')} */ module.exports = Object.getOwnPropertyDescriptor; /***/ }), /***/ "../../../node_modules/gopd/index.js": /*!*******************************************!*\ !*** ../../../node_modules/gopd/index.js ***! \*******************************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; /** @type {import('.')} */ var $gOPD = __webpack_require__(/*! ./gOPD */ "../../../node_modules/gopd/gOPD.js"); if ($gOPD) { try { $gOPD([], 'length'); } catch (e) { // IE 8 has a broken gOPD $gOPD = null; } } module.exports = $gOPD; /***/ }), /***/ "../../../node_modules/has-symbols/index.js": /*!**************************************************!*\ !*** ../../../node_modules/has-symbols/index.js ***! \**************************************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; var origSymbol = typeof Symbol !== 'undefined' && Symbol; var hasSymbolSham = __webpack_require__(/*! ./shams */ "../../../node_modules/has-symbols/shams.js"); /** @type {import('.')} */ module.exports = function hasNativeSymbols() { if (typeof origSymbol !== 'function') { return false; } if (typeof Symbol !== 'function') { return false; } if (typeof origSymbol('foo') !== 'symbol') { return false; } if (typeof Symbol('bar') !== 'symbol') { return false; } return hasSymbolSham(); }; /***/ }), /***/ "../../../node_modules/has-symbols/shams.js": /*!**************************************************!*\ !*** ../../../node_modules/has-symbols/shams.js ***! \**************************************************/ /***/ ((module) => { "use strict"; /** @type {import('./shams')} */ /* eslint complexity: [2, 18], max-statements: [2, 33] */ module.exports = function hasSymbols() { if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; } if (typeof Symbol.iterator === 'symbol') { return true; } /** @type {{ [k in symbol]?: unknown }} */ var obj = {}; var sym = Symbol('test'); var symObj = Object(sym); if (typeof sym === 'string') { return false; } if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; } if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; } // temp disabled per https://github.com/ljharb/object.assign/issues/17 // if (sym instanceof Symbol) { return false; } // temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4 // if (!(symObj instanceof Symbol)) { return false; } // if (typeof Symbol.prototype.toString !== 'function') { return false; } // if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; } var symVal = 42; obj[sym] = symVal; for (var _ in obj) { return false; } // eslint-disable-line no-restricted-syntax, no-unreachable-loop if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; } if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; } var syms = Object.getOwnPropertySymbols(obj); if (syms.length !== 1 || syms[0] !== sym) { return false; } if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; } if (typeof Object.getOwnPropertyDescriptor === 'function') { // eslint-disable-next-line no-extra-parens var descriptor = /** @type {PropertyDescriptor} */ (Object.getOwnPropertyDescriptor(obj, sym)); if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; } } return true; }; /***/ }), /***/ "../../../node_modules/hasown/index.js": /*!*********************************************!*\ !*** ../../../node_modules/hasown/index.js ***! \*********************************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; var call = Function.prototype.call; var $hasOwn = Object.prototype.hasOwnProperty; var bind = __webpack_require__(/*! function-bind */ "../../../node_modules/function-bind/index.js"); /** @type {import('.')} */ module.exports = bind.call(call, $hasOwn); /***/ }), /***/ "../../../node_modules/immer/dist/immer.mjs": /*!**************************************************!*\ !*** ../../../node_modules/immer/dist/immer.mjs ***! \**************************************************/ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ Immer: () => (/* binding */ Immer2), /* harmony export */ applyPatches: () => (/* binding */ applyPatches), /* harmony export */ castDraft: () => (/* binding */ castDraft), /* harmony export */ castImmutable: () => (/* binding */ castImmutable), /* harmony export */ createDraft: () => (/* binding */ createDraft), /* harmony export */ current: () => (/* binding */ current), /* harmony export */ enableMapSet: () => (/* binding */ enableMapSet), /* harmony export */ enablePatches: () => (/* binding */ enablePatches), /* harmony export */ finishDraft: () => (/* binding */ finishDraft), /* harmony export */ freeze: () => (/* binding */ freeze), /* harmony export */ immerable: () => (/* binding */ DRAFTABLE), /* harmony export */ isDraft: () => (/* binding */ isDraft), /* harmony export */ isDraftable: () => (/* binding */ isDraftable), /* harmony export */ nothing: () => (/* binding */ NOTHING), /* harmony export */ original: () => (/* binding */ original), /* harmony export */ produce: () => (/* binding */ produce), /* harmony export */ produceWithPatches: () => (/* binding */ produceWithPatches), /* harmony export */ setAutoFreeze: () => (/* binding */ setAutoFreeze), /* harmony export */ setUseStrictIteration: () => (/* binding */ setUseStrictIteration), /* harmony export */ setUseStrictShallowCopy: () => (/* binding */ setUseStrictShallowCopy) /* harmony export */ }); // src/utils/env.ts var NOTHING = Symbol.for("immer-nothing"); var DRAFTABLE = Symbol.for("immer-draftable"); var DRAFT_STATE = Symbol.for("immer-state"); // src/utils/errors.ts var errors = true ? [ // All error codes, starting by 0: function(plugin) { return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`; }, function(thing) { return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`; }, "This object has been frozen and should not be mutated", function(data) { return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data; }, "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.", "Immer forbids circular references", "The first or second argument to `produce` must be a function", "The third argument to `produce` must be a function or undefined", "First argument to `createDraft` must be a plain object, an array, or an immerable object", "First argument to `finishDraft` must be a draft returned by `createDraft`", function(thing) { return `'current' expects a draft, got: ${thing}`; }, "Object.defineProperty() cannot be used on an Immer draft", "Object.setPrototypeOf() cannot be used on an Immer draft", "Immer only supports deleting array indices", "Immer only supports setting array indices and the 'length' property", function(thing) { return `'original' expects a draft, got: ${thing}`; } // Note: if more errors are added, the errorOffset in Patches.ts should be increased // See Patches.ts for additional errors ] : 0; function die(error, ...args) { if (true) { const e = errors[error]; const msg = isFunction(e) ? e.apply(null, args) : e; throw new Error(`[Immer] ${msg}`); } // removed by dead control flow } // src/utils/common.ts var O = Object; var getPrototypeOf = O.getPrototypeOf; var CONSTRUCTOR = "constructor"; var PROTOTYPE = "prototype"; var CONFIGURABLE = "configurable"; var ENUMERABLE = "enumerable"; var WRITABLE = "writable"; var VALUE = "value"; var isDraft = (value) => !!value && !!value[DRAFT_STATE]; function isDraftable(value) { if (!value) return false; return isPlainObject(value) || isArray(value) || !!value[DRAFTABLE] || !!value[CONSTRUCTOR]?.[DRAFTABLE] || isMap(value) || isSet(value); } var objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString(); var cachedCtorStrings = /* @__PURE__ */ new WeakMap(); function isPlainObject(value) { if (!value || !isObjectish(value)) return false; const proto = getPrototypeOf(value); if (proto === null || proto === O[PROTOTYPE]) return true; const Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR]; if (Ctor === Object) return true; if (!isFunction(Ctor)) return false; let ctorString = cachedCtorStrings.get(Ctor); if (ctorString === void 0) { ctorString = Function.toString.call(Ctor); cachedCtorStrings.set(Ctor, ctorString); } return ctorString === objectCtorString; } function original(value) { if (!isDraft(value)) die(15, value); return value[DRAFT_STATE].base_; } function each(obj, iter, strict = true) { if (getArchtype(obj) === 0 /* Object */) { const keys = strict ? Reflect.ownKeys(obj) : O.keys(obj); keys.forEach((key) => { iter(key, obj[key], obj); }); } else { obj.forEach((entry, index) => iter(index, entry, obj)); } } function getArchtype(thing) { const state = thing[DRAFT_STATE]; return state ? state.type_ : isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */; } var has = (thing, prop, type = getArchtype(thing)) => type === 2 /* Map */ ? thing.has(prop) : O[PROTOTYPE].hasOwnProperty.call(thing, prop); var get = (thing, prop, type = getArchtype(thing)) => ( // @ts-ignore type === 2 /* Map */ ? thing.get(prop) : thing[prop] ); var set = (thing, propOrOldValue, value, type = getArchtype(thing)) => { if (type === 2 /* Map */) thing.set(propOrOldValue, value); else if (type === 3 /* Set */) { thing.add(value); } else thing[propOrOldValue] = value; }; function is(x, y) { if (x === y) { return x !== 0 || 1 / x === 1 / y; } else { return x !== x && y !== y; } } var isArray = Array.isArray; var isMap = (target) => target instanceof Map; var isSet = (target) => target instanceof Set; var isObjectish = (target) => typeof target === "object"; var isFunction = (target) => typeof target === "function"; var isBoolean = (target) => typeof target === "boolean"; var getProxyDraft = (value) => { if (!isObjectish(value)) return null; return value?.[DRAFT_STATE]; }; var latest = (state) => state.copy_ || state.base_; var getValue = (value) => { const proxyDraft = getProxyDraft(value); return proxyDraft ? proxyDraft.copy_ ?? proxyDraft.base_ : value; }; var getFinalValue = (state) => state.modified_ ? state.copy_ : state.base_; function shallowCopy(base, strict) { if (isMap(base)) { return new Map(base); } if (isSet(base)) { return new Set(base); } if (isArray(base)) return Array[PROTOTYPE].slice.call(base); const isPlain = isPlainObject(base); if (strict === true || strict === "class_only" && !isPlain) { const descriptors = O.getOwnPropertyDescriptors(base); delete descriptors[DRAFT_STATE]; let keys = Reflect.ownKeys(descriptors); for (let i = 0; i < keys.length; i++) { const key = keys[i]; const desc = descriptors[key]; if (desc[WRITABLE] === false) { desc[WRITABLE] = true; desc[CONFIGURABLE] = true; } if (desc.get || desc.set) descriptors[key] = { [CONFIGURABLE]: true, [WRITABLE]: true, // could live with !!desc.set as well here... [ENUMERABLE]: desc[ENUMERABLE], [VALUE]: base[key] }; } return O.create(getPrototypeOf(base), descriptors); } else { const proto = getPrototypeOf(base); if (proto !== null && isPlain) { return { ...base }; } const obj = O.create(proto); return O.assign(obj, base); } } function freeze(obj, deep = false) { if (isFrozen(obj) || isDraft(obj)) return obj; if (getArchtype(obj) > 1) { O.defineProperties(obj, { set: dontMutateMethodOverride, add: dontMutateMethodOverride, clear: dontMutateMethodOverride, delete: dontMutateMethodOverride }); } O.freeze(obj); if (deep) each( obj, (_key, value) => { freeze(value, true); }, false ); return obj; } function dontMutateFrozenCollections() { die(2); } var dontMutateMethodOverride = { [VALUE]: dontMutateFrozenCollections }; function isFrozen(obj) { if (obj === null || !isObjectish(obj)) return true; return O.isFrozen(obj); } // src/utils/plugins.ts var PluginMapSet = "MapSet"; var PluginPatches = "Patches"; var plugins = {}; function getPlugin(pluginKey) { const plugin = plugins[pluginKey]; if (!plugin) { die(0, pluginKey); } return plugin; } var isPluginLoaded = (pluginKey) => !!plugins[pluginKey]; function loadPlugin(pluginKey, implementation) { if (!plugins[pluginKey]) plugins[pluginKey] = implementation; } // src/core/scope.ts var currentScope; var getCurrentScope = () => currentScope; var createScope = (parent_, immer_) => ({ drafts_: [], parent_, immer_, // Whenever the modified draft contains a draft from another scope, we // need to prevent auto-freezing so the unowned draft can be finalized. canAutoFreeze_: true, unfinalizedDrafts_: 0, handledSet_: /* @__PURE__ */ new Set(), processedForPatches_: /* @__PURE__ */ new Set(), mapSetPlugin_: isPluginLoaded(PluginMapSet) ? getPlugin(PluginMapSet) : void 0 }); function usePatchesInScope(scope, patchListener) { if (patchListener) { scope.patchPlugin_ = getPlugin(PluginPatches); scope.patches_ = []; scope.inversePatches_ = []; scope.patchListener_ = patchListener; } } function revokeScope(scope) { leaveScope(scope); scope.drafts_.forEach(revokeDraft); scope.drafts_ = null; } function leaveScope(scope) { if (scope === currentScope) { currentScope = scope.parent_; } } var enterScope = (immer2) => currentScope = createScope(currentScope, immer2); function revokeDraft(draft) { const state = draft[DRAFT_STATE]; if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */) state.revoke_(); else state.revoked_ = true; } // src/core/finalize.ts function processResult(result, scope) { scope.unfinalizedDrafts_ = scope.drafts_.length; const baseDraft = scope.drafts_[0]; const isReplaced = result !== void 0 && result !== baseDraft; if (isReplaced) { if (baseDraft[DRAFT_STATE].modified_) { revokeScope(scope); die(4); } if (isDraftable(result)) { result = finalize(scope, result); } const { patchPlugin_ } = scope; if (patchPlugin_) { patchPlugin_.generateReplacementPatches_( baseDraft[DRAFT_STATE].base_, result, scope ); } } else { result = finalize(scope, baseDraft); } maybeFreeze(scope, result, true); revokeScope(scope); if (scope.patches_) { scope.patchListener_(scope.patches_, scope.inversePatches_); } return result !== NOTHING ? result : void 0; } function finalize(rootScope, value) { if (isFrozen(value)) return value; const state = value[DRAFT_STATE]; if (!state) { const finalValue = handleValue(value, rootScope.handledSet_, rootScope); return finalValue; } if (!isSameScope(state, rootScope)) { return value; } if (!state.modified_) { return state.base_; } if (!state.finalized_) { const { callbacks_ } = state; if (callbacks_) { while (callbacks_.length > 0) { const callback = callbacks_.pop(); callback(rootScope); } } generatePatchesAndFinalize(state, rootScope); } return state.copy_; } function maybeFreeze(scope, value, deep = false) { if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) { freeze(value, deep); } } function markStateFinalized(state) { state.finalized_ = true; state.scope_.unfinalizedDrafts_--; } var isSameScope = (state, rootScope) => state.scope_ === rootScope; var EMPTY_LOCATIONS_RESULT = []; function updateDraftInParent(parent, draftValue, finalizedValue, originalKey) { const parentCopy = latest(parent); const parentType = parent.type_; if (originalKey !== void 0) { const currentValue = get(parentCopy, originalKey, parentType); if (currentValue === draftValue) { set(parentCopy, originalKey, finalizedValue, parentType); return; } } if (!parent.draftLocations_) { const draftLocations = parent.draftLocations_ = /* @__PURE__ */ new Map(); each(parentCopy, (key, value) => { if (isDraft(value)) { const keys = draftLocations.get(value) || []; keys.push(key); draftLocations.set(value, keys); } }); } const locations = parent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT; for (const location of locations) { set(parentCopy, location, finalizedValue, parentType); } } function registerChildFinalizationCallback(parent, child, key) { parent.callbacks_.push(function childCleanup(rootScope) { const state = child; if (!state || !isSameScope(state, rootScope)) { return; } rootScope.mapSetPlugin_?.fixSetContents(state); const finalizedValue = getFinalValue(state); updateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key); generatePatchesAndFinalize(state, rootScope); }); } function generatePatchesAndFinalize(state, rootScope) { const shouldFinalize = state.modified_ && !state.finalized_ && (state.type_ === 3 /* Set */ || (state.assigned_?.size ?? 0) > 0); if (shouldFinalize) { const { patchPlugin_ } = rootScope; if (patchPlugin_) { const basePath = patchPlugin_.getPath(state); if (basePath) { patchPlugin_.generatePatches_(state, basePath, rootScope); } } markStateFinalized(state); } } function handleCrossReference(target, key, value) { const { scope_ } = target; if (isDraft(value)) { const state = value[DRAFT_STATE]; if (isSameScope(state, scope_)) { state.callbacks_.push(function crossReferenceCleanup() { prepareCopy(target); const finalizedValue = getFinalValue(state); updateDraftInParent(target, value, finalizedValue, key); }); } } else if (isDraftable(value)) { target.callbacks_.push(function nestedDraftCleanup() { const targetCopy = latest(target); if (get(targetCopy, key, target.type_) === value) { if (scope_.drafts_.length > 1 && (target.assigned_.get(key) ?? false) === true && target.copy_) { handleValue( get(target.copy_, key, target.type_), scope_.handledSet_, scope_ ); } } }); } } function handleValue(target, handledSet, rootScope) { if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) { return target; } if (isDraft(target) || handledSet.has(target) || !isDraftable(target) || isFrozen(target)) { return target; } handledSet.add(target); each(target, (key, value) => { if (isDraft(value)) { const state = value[DRAFT_STATE]; if (isSameScope(state, rootScope)) { const updatedValue = getFinalValue(state); set(target, key, updatedValue, target.type_); markStateFinalized(state); } } else if (isDraftable(value)) { handleValue(value, handledSet, rootScope); } }); return target; } // src/core/proxy.ts function createProxyProxy(base, parent) { const baseIsArray = isArray(base); const state = { type_: baseIsArray ? 1 /* Array */ : 0 /* Object */, // Track which produce call this is associated with. scope_: parent ? parent.scope_ : getCurrentScope(), // True for both shallow and deep changes. modified_: false, // Used during finalization. finalized_: false, // Track which properties have been assigned (true) or deleted (false). // actually instantiated in `prepareCopy()` assigned_: void 0, // The parent draft state. parent_: parent, // The base state. base_: base, // The base proxy. draft_: null, // set below // The base copy with any updated values. copy_: null, // Called by the `produce` function. revoke_: null, isManual_: false, // `callbacks` actually gets assigned in `createProxy` callbacks_: void 0 }; let target = state; let traps = objectTraps; if (baseIsArray) { target = [state]; traps = arrayTraps; } const { revoke, proxy } = Proxy.revocable(target, traps); state.draft_ = proxy; state.revoke_ = revoke; return [proxy, state]; } var objectTraps = { get(state, prop) { if (prop === DRAFT_STATE) return state; const source = latest(state); if (!has(source, prop, state.type_)) { return readPropFromProto(state, source, prop); } const value = source[prop]; if (state.finalized_ || !isDraftable(value)) { return value; } if (value === peek(state.base_, prop)) { prepareCopy(state); const childKey = state.type_ === 1 /* Array */ ? +prop : prop; const childDraft = createProxy(state.scope_, value, state, childKey); return state.copy_[childKey] = childDraft; } return value; }, has(state, prop) { return prop in latest(state); }, ownKeys(state) { return Reflect.ownKeys(latest(state)); }, set(state, prop, value) { const desc = getDescriptorFromProto(latest(state), prop); if (desc?.set) { desc.set.call(state.draft_, value); return true; } if (!state.modified_) { const current2 = peek(latest(state), prop); const currentState = current2?.[DRAFT_STATE]; if (currentState && currentState.base_ === value) { state.copy_[prop] = value; state.assigned_.set(prop, false); return true; } if (is(value, current2) && (value !== void 0 || has(state.base_, prop, state.type_))) return true; prepareCopy(state); markChanged(state); } if (state.copy_[prop] === value && // special case: handle new props with value 'undefined' (value !== void 0 || prop in state.copy_) || // special case: NaN Number.isNaN(value) && Number.isNaN(state.copy_[prop])) return true; state.copy_[prop] = value; state.assigned_.set(prop, true); handleCrossReference(state, prop, value); return true; }, deleteProperty(state, prop) { prepareCopy(state); if (peek(state.base_, prop) !== void 0 || prop in state.base_) { state.assigned_.set(prop, false); markChanged(state); } else { state.assigned_.delete(prop); } if (state.copy_) { delete state.copy_[prop]; } return true; }, // Note: We never coerce `desc.value` into an Immer draft, because we can't make // the same guarantee in ES5 mode. getOwnPropertyDescriptor(state, prop) { const owner = latest(state); const desc = Reflect.getOwnPropertyDescriptor(owner, prop); if (!desc) return desc; return { [WRITABLE]: true, [CONFIGURABLE]: state.type_ !== 1 /* Array */ || prop !== "length", [ENUMERABLE]: desc[ENUMERABLE], [VALUE]: owner[prop] }; }, defineProperty() { die(11); }, getPrototypeOf(state) { return getPrototypeOf(state.base_); }, setPrototypeOf() { die(12); } }; var arrayTraps = {}; each(objectTraps, (key, fn) => { arrayTraps[key] = function() { const args = arguments; args[0] = args[0][0]; return fn.apply(this, args); }; }); arrayTraps.deleteProperty = function(state, prop) { if ( true && isNaN(parseInt(prop))) die(13); return arrayTraps.set.call(this, state, prop, void 0); }; arrayTraps.set = function(state, prop, value) { if ( true && prop !== "length" && isNaN(parseInt(prop))) die(14); return objectTraps.set.call(this, state[0], prop, value, state[0]); }; function peek(draft, prop) { const state = draft[DRAFT_STATE]; const source = state ? latest(state) : draft; return source[prop]; } function readPropFromProto(state, source, prop) { const desc = getDescriptorFromProto(source, prop); return desc ? VALUE in desc ? desc[VALUE] : ( // This is a very special case, if the prop is a getter defined by the // prototype, we should invoke it with the draft as context! desc.get?.call(state.draft_) ) : void 0; } function getDescriptorFromProto(source, prop) { if (!(prop in source)) return void 0; let proto = getPrototypeOf(source); while (proto) { const desc = Object.getOwnPropertyDescriptor(proto, prop); if (desc) return desc; proto = getPrototypeOf(proto); } return void 0; } function markChanged(state) { if (!state.modified_) { state.modified_ = true; if (state.parent_) { markChanged(state.parent_); } } } function prepareCopy(state) { if (!state.copy_) { state.assigned_ = /* @__PURE__ */ new Map(); state.copy_ = shallowCopy( state.base_, state.scope_.immer_.useStrictShallowCopy_ ); } } // src/core/immerClass.ts var Immer2 = class { constructor(config) { this.autoFreeze_ = true; this.useStrictShallowCopy_ = false; this.useStrictIteration_ = false; /** * The `produce` function takes a value and a "recipe function" (whose * return value often depends on the base state). The recipe function is * free to mutate its first argument however it wants. All mutations are * only ever applied to a __copy__ of the base state. * * Pass only a function to create a "curried producer" which relieves you * from passing the recipe function every time. * * Only plain objects and arrays are made mutable. All other objects are * considered uncopyable. * * Note: This function is __bound__ to its `Immer` instance. * * @param {any} base - the initial state * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified * @param {Function} patchListener - optional function that will be called with all the patches produced here * @returns {any} a new state, or the initial state if nothing was modified */ this.produce = (base, recipe, patchListener) => { if (isFunction(base) && !isFunction(recipe)) { const defaultBase = recipe; recipe = base; const self = this; return function curriedProduce(base2 = defaultBase, ...args) { return self.produce(base2, (draft) => recipe.call(this, draft, ...args)); }; } if (!isFunction(recipe)) die(6); if (patchListener !== void 0 && !isFunction(patchListener)) die(7); let result; if (isDraftable(base)) { const scope = enterScope(this); const proxy = createProxy(scope, base, void 0); let hasError = true; try { result = recipe(proxy); hasError = false; } finally { if (hasError) revokeScope(scope); else leaveScope(scope); } usePatchesInScope(scope, patchListener); return processResult(result, scope); } else if (!base || !isObjectish(base)) { result = recipe(base); if (result === void 0) result = base; if (result === NOTHING) result = void 0; if (this.autoFreeze_) freeze(result, true); if (patchListener) { const p = []; const ip = []; getPlugin(PluginPatches).generateReplacementPatches_(base, result, { patches_: p, inversePatches_: ip }); patchListener(p, ip); } return result; } else die(1, base); }; this.produceWithPatches = (base, recipe) => { if (isFunction(base)) { return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args)); } let patches, inversePatches; const result = this.produce(base, recipe, (p, ip) => { patches = p; inversePatches = ip; }); return [result, patches, inversePatches]; }; if (isBoolean(config?.autoFreeze)) this.setAutoFreeze(config.autoFreeze); if (isBoolean(config?.useStrictShallowCopy)) this.setUseStrictShallowCopy(config.useStrictShallowCopy); if (isBoolean(config?.useStrictIteration)) this.setUseStrictIteration(config.useStrictIteration); } createDraft(base) { if (!isDraftable(base)) die(8); if (isDraft(base)) base = current(base); const scope = enterScope(this); const proxy = createProxy(scope, base, void 0); proxy[DRAFT_STATE].isManual_ = true; leaveScope(scope); return proxy; } finishDraft(draft, patchListener) { const state = draft && draft[DRAFT_STATE]; if (!state || !state.isManual_) die(9); const { scope_: scope } = state; usePatchesInScope(scope, patchListener); return processResult(void 0, scope); } /** * Pass true to automatically freeze all copies created by Immer. * * By default, auto-freezing is enabled. */ setAutoFreeze(value) { this.autoFreeze_ = value; } /** * Pass true to enable strict shallow copy. * * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties. */ setUseStrictShallowCopy(value) { this.useStrictShallowCopy_ = value; } /** * Pass false to use faster iteration that skips non-enumerable properties * but still handles symbols for compatibility. * * By default, strict iteration is enabled (includes all own properties). */ setUseStrictIteration(value) { this.useStrictIteration_ = value; } shouldUseStrictIteration() { return this.useStrictIteration_; } applyPatches(base, patches) { let i; for (i = patches.length - 1; i >= 0; i--) { const patch = patches[i]; if (patch.path.length === 0 && patch.op === "replace") { base = patch.value; break; } } if (i > -1) { patches = patches.slice(i + 1); } const applyPatchesImpl = getPlugin(PluginPatches).applyPatches_; if (isDraft(base)) { return applyPatchesImpl(base, patches); } return this.produce( base, (draft) => applyPatchesImpl(draft, patches) ); } }; function createProxy(rootScope, value, parent, key) { const [draft, state] = isMap(value) ? getPlugin(PluginMapSet).proxyMap_(value, parent) : isSet(value) ? getPlugin(PluginMapSet).proxySet_(value, parent) : createProxyProxy(value, parent); const scope = parent?.scope_ ?? getCurrentScope(); scope.drafts_.push(draft); state.callbacks_ = parent?.callbacks_ ?? []; state.key_ = key; if (parent && key !== void 0) { registerChildFinalizationCallback(parent, state, key); } else { state.callbacks_.push(function rootDraftCleanup(rootScope2) { rootScope2.mapSetPlugin_?.fixSetContents(state); const { patchPlugin_ } = rootScope2; if (state.modified_ && patchPlugin_) { patchPlugin_.generatePatches_(state, [], rootScope2); } }); } return draft; } // src/core/current.ts function current(value) { if (!isDraft(value)) die(10, value); return currentImpl(value); } function currentImpl(value) { if (!isDraftable(value) || isFrozen(value)) return value; const state = value[DRAFT_STATE]; let copy; let strict = true; if (state) { if (!state.modified_) return state.base_; state.finalized_ = true; copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_); strict = state.scope_.immer_.shouldUseStrictIteration(); } else { copy = shallowCopy(value, true); } each( copy, (key, childValue) => { set(copy, key, currentImpl(childValue)); }, strict ); if (state) { state.finalized_ = false; } return copy; } // src/plugins/patches.ts function enablePatches() { const errorOffset = 16; if (true) { errors.push( 'Sets cannot have "replace" patches.', function(op) { return "Unsupported patch operation: " + op; }, function(path) { return "Cannot apply patch, path doesn't resolve: " + path; }, "Patching reserved attributes like __proto__, prototype and constructor is not allowed" ); } function getPath(state, path = []) { if ("key_" in state && state.key_ !== void 0) { const parentCopy = state.parent_.copy_ ?? state.parent_.base_; const proxyDraft = getProxyDraft(get(parentCopy, state.key_)); const valueAtKey = get(parentCopy, state.key_); if (valueAtKey === void 0) { return null; } if (valueAtKey !== state.draft_ && valueAtKey !== state.base_ && valueAtKey !== state.copy_) { return null; } if (proxyDraft != null && proxyDraft.base_ !== state.base_) { return null; } const isSet2 = state.parent_.type_ === 3 /* Set */; let key; if (isSet2) { const setParent = state.parent_; key = Array.from(setParent.drafts_.keys()).indexOf(state.key_); } else { key = state.key_; } if (!(isSet2 && parentCopy.size > key || has(parentCopy, key))) { return null; } path.push(key); } if (state.parent_) { return getPath(state.parent_, path); } path.reverse(); try { resolvePath(state.copy_, path); } catch (e) { return null; } return path; } function resolvePath(base, path) { let current2 = base; for (let i = 0; i < path.length - 1; i++) { const key = path[i]; current2 = get(current2, key); if (!isObjectish(current2) || current2 === null) { throw new Error(`Cannot resolve path at '${path.join("/")}'`); } } return current2; } const REPLACE = "replace"; const ADD = "add"; const REMOVE = "remove"; function generatePatches_(state, basePath, scope) { if (state.scope_.processedForPatches_.has(state)) { return; } state.scope_.processedForPatches_.add(state); const { patches_, inversePatches_ } = scope; switch (state.type_) { case 0 /* Object */: case 2 /* Map */: return generatePatchesFromAssigned( state, basePath, patches_, inversePatches_ ); case 1 /* Array */: return generateArrayPatches( state, basePath, patches_, inversePatches_ ); case 3 /* Set */: return generateSetPatches( state, basePath, patches_, inversePatches_ ); } } function generateArrayPatches(state, basePath, patches, inversePatches) { let { base_, assigned_ } = state; let copy_ = state.copy_; if (copy_.length < base_.length) { ; [base_, copy_] = [copy_, base_]; [patches, inversePatches] = [inversePatches, patches]; } for (let i = 0; i < base_.length; i++) { const copiedItem = copy_[i]; const baseItem = base_[i]; if (assigned_?.get(i.toString()) && copiedItem !== baseItem) { const childState = copiedItem?.[DRAFT_STATE]; if (childState && childState.modified_) { continue; } const path = basePath.concat([i]); patches.push({ op: REPLACE, path, // Need to maybe clone it, as it can in fact be the original value // due to the base/copy inversion at the start of this function value: clonePatchValueIfNeeded(copiedItem) }); inversePatches.push({ op: REPLACE, path, value: clonePatchValueIfNeeded(baseItem) }); } } for (let i = base_.length; i < copy_.length; i++) { const path = basePath.concat([i]); patches.push({ op: ADD, path, // Need to maybe clone it, as it can in fact be the original value // due to the base/copy inversion at the start of this function value: clonePatchValueIfNeeded(copy_[i]) }); } for (let i = copy_.length - 1; base_.length <= i; --i) { const path = basePath.concat([i]); inversePatches.push({ op: REMOVE, path }); } } function generatePatchesFromAssigned(state, basePath, patches, inversePatches) { const { base_, copy_, type_ } = state; each(state.assigned_, (key, assignedValue) => { const origValue = get(base_, key, type_); const value = get(copy_, key, type_); const op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD; if (origValue === value && op === REPLACE) return; const path = basePath.concat(key); patches.push( op === REMOVE ? { op, path } : { op, path, value: clonePatchValueIfNeeded(value) } ); inversePatches.push( op === ADD ? { op: REMOVE, path } : op === REMOVE ? { op: ADD, path, value: clonePatchValueIfNeeded(origValue) } : { op: REPLACE, path, value: clonePatchValueIfNeeded(origValue) } ); }); } function generateSetPatches(state, basePath, patches, inversePatches) { let { base_, copy_ } = state; let i = 0; base_.forEach((value) => { if (!copy_.has(value)) { const path = basePath.concat([i]); patches.push({ op: REMOVE, path, value }); inversePatches.unshift({ op: ADD, path, value }); } i++; }); i = 0; copy_.forEach((value) => { if (!base_.has(value)) { const path = basePath.concat([i]); patches.push({ op: ADD, path, value }); inversePatches.unshift({ op: REMOVE, path, value }); } i++; }); } function generateReplacementPatches_(baseValue, replacement, scope) { const { patches_, inversePatches_ } = scope; patches_.push({ op: REPLACE, path: [], value: replacement === NOTHING ? void 0 : replacement }); inversePatches_.push({ op: REPLACE, path: [], value: baseValue }); } function applyPatches_(draft, patches) { patches.forEach((patch) => { const { path, op } = patch; let base = draft; for (let i = 0; i < path.length - 1; i++) { const parentType = getArchtype(base); let p = path[i]; if (typeof p !== "string" && typeof p !== "number") { p = "" + p; } if ((parentType === 0 /* Object */ || parentType === 1 /* Array */) && (p === "__proto__" || p === CONSTRUCTOR)) die(errorOffset + 3); if (isFunction(base) && p === PROTOTYPE) die(errorOffset + 3); base = get(base, p); if (!isObjectish(base)) die(errorOffset + 2, path.join("/")); } const type = getArchtype(base); const value = deepClonePatchValue(patch.value); const key = path[path.length - 1]; switch (op) { case REPLACE: switch (type) { case 2 /* Map */: return base.set(key, value); case 3 /* Set */: die(errorOffset); default: return base[key] = value; } case ADD: switch (type) { case 1 /* Array */: return key === "-" ? base.push(value) : base.splice(key, 0, value); case 2 /* Map */: return base.set(key, value); case 3 /* Set */: return base.add(value); default: return base[key] = value; } case REMOVE: switch (type) { case 1 /* Array */: return base.splice(key, 1); case 2 /* Map */: return base.delete(key); case 3 /* Set */: return base.delete(patch.value); default: return delete base[key]; } default: die(errorOffset + 1, op); } }); return draft; } function deepClonePatchValue(obj) { if (!isDraftable(obj)) return obj; if (isArray(obj)) return obj.map(deepClonePatchValue); if (isMap(obj)) return new Map( Array.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)]) ); if (isSet(obj)) return new Set(Array.from(obj).map(deepClonePatchValue)); const cloned = Object.create(getPrototypeOf(obj)); for (const key in obj) cloned[key] = deepClonePatchValue(obj[key]); if (has(obj, DRAFTABLE)) cloned[DRAFTABLE] = obj[DRAFTABLE]; return cloned; } function clonePatchValueIfNeeded(obj) { if (isDraft(obj)) { return deepClonePatchValue(obj); } else return obj; } loadPlugin(PluginPatches, { applyPatches_, generatePatches_, generateReplacementPatches_, getPath }); } // src/plugins/mapset.ts function enableMapSet() { class DraftMap extends Map { constructor(target, parent) { super(); this[DRAFT_STATE] = { type_: 2 /* Map */, parent_: parent, scope_: parent ? parent.scope_ : getCurrentScope(), modified_: false, finalized_: false, copy_: void 0, assigned_: void 0, base_: target, draft_: this, isManual_: false, revoked_: false, callbacks_: [] }; } get size() { return latest(this[DRAFT_STATE]).size; } has(key) { return latest(this[DRAFT_STATE]).has(key); } set(key, value) { const state = this[DRAFT_STATE]; assertUnrevoked(state); if (!latest(state).has(key) || latest(state).get(key) !== value) { prepareMapCopy(state); markChanged(state); state.assigned_.set(key, true); state.copy_.set(key, value); state.assigned_.set(key, true); } return this; } delete(key) { if (!this.has(key)) { return false; } const state = this[DRAFT_STATE]; assertUnrevoked(state); prepareMapCopy(state); markChanged(state); if (state.base_.has(key)) { state.assigned_.set(key, false); } else { state.assigned_.delete(key); } state.copy_.delete(key); return true; } clear() { const state = this[DRAFT_STATE]; assertUnrevoked(state); if (latest(state).size) { prepareMapCopy(state); markChanged(state); state.assigned_ = /* @__PURE__ */ new Map(); each(state.base_, (key) => { state.assigned_.set(key, false); }); state.copy_.clear(); } } forEach(cb, thisArg) { const state = this[DRAFT_STATE]; latest(state).forEach((_value, key, _map) => { cb.call(thisArg, this.get(key), key, this); }); } get(key) { const state = this[DRAFT_STATE]; assertUnrevoked(state); const value = latest(state).get(key); if (state.finalized_ || !isDraftable(value)) { return value; } if (value !== state.base_.get(key)) { return value; } const draft = createProxy(state.scope_, value, state, key); prepareMapCopy(state); state.copy_.set(key, draft); return draft; } keys() { return latest(this[DRAFT_STATE]).keys(); } values() { const iterator = this.keys(); return { [Symbol.iterator]: () => this.values(), next: () => { const r = iterator.next(); if (r.done) return r; const value = this.get(r.value); return { done: false, value }; } }; } entries() { const iterator = this.keys(); return { [Symbol.iterator]: () => this.entries(), next: () => { const r = iterator.next(); if (r.done) return r; const value = this.get(r.value); return { done: false, value: [r.value, value] }; } }; } [(DRAFT_STATE, Symbol.iterator)]() { return this.entries(); } } function proxyMap_(target, parent) { const map = new DraftMap(target, parent); return [map, map[DRAFT_STATE]]; } function prepareMapCopy(state) { if (!state.copy_) { state.assigned_ = /* @__PURE__ */ new Map(); state.copy_ = new Map(state.base_); } } class DraftSet extends Set { constructor(target, parent) { super(); this[DRAFT_STATE] = { type_: 3 /* Set */, parent_: parent, scope_: parent ? parent.scope_ : getCurrentScope(), modified_: false, finalized_: false, copy_: void 0, base_: target, draft_: this, drafts_: /* @__PURE__ */ new Map(), revoked_: false, isManual_: false, assigned_: void 0, callbacks_: [] }; } get size() { return latest(this[DRAFT_STATE]).size; } has(value) { const state = this[DRAFT_STATE]; assertUnrevoked(state); if (!state.copy_) { return state.base_.has(value); } if (state.copy_.has(value)) return true; if (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value))) return true; return false; } add(value) { const state = this[DRAFT_STATE]; assertUnrevoked(state); if (!this.has(value)) { prepareSetCopy(state); markChanged(state); state.copy_.add(value); } return this; } delete(value) { if (!this.has(value)) { return false; } const state = this[DRAFT_STATE]; assertUnrevoked(state); prepareSetCopy(state); markChanged(state); return state.copy_.delete(value) || (state.drafts_.has(value) ? state.copy_.delete(state.drafts_.get(value)) : ( /* istanbul ignore next */ false )); } clear() { const state = this[DRAFT_STATE]; assertUnrevoked(state); if (latest(state).size) { prepareSetCopy(state); markChanged(state); state.copy_.clear(); } } values() { const state = this[DRAFT_STATE]; assertUnrevoked(state); prepareSetCopy(state); return state.copy_.values(); } entries() { const state = this[DRAFT_STATE]; assertUnrevoked(state); prepareSetCopy(state); return state.copy_.entries(); } keys() { return this.values(); } [(DRAFT_STATE, Symbol.iterator)]() { return this.values(); } forEach(cb, thisArg) { const iterator = this.values(); let result = iterator.next(); while (!result.done) { cb.call(thisArg, result.value, result.value, this); result = iterator.next(); } } } function proxySet_(target, parent) { const set2 = new DraftSet(target, parent); return [set2, set2[DRAFT_STATE]]; } function prepareSetCopy(state) { if (!state.copy_) { state.copy_ = /* @__PURE__ */ new Set(); state.base_.forEach((value) => { if (isDraftable(value)) { const draft = createProxy(state.scope_, value, state, value); state.drafts_.set(value, draft); state.copy_.add(draft); } else { state.copy_.add(value); } }); } } function assertUnrevoked(state) { if (state.revoked_) die(3, JSON.stringify(latest(state))); } function fixSetContents(target) { if (target.type_ === 3 /* Set */ && target.copy_) { const copy = new Set(target.copy_); target.copy_.clear(); copy.forEach((value) => { target.copy_.add(getValue(value)); }); } } loadPlugin(PluginMapSet, { proxyMap_, proxySet_, fixSetContents }); } // src/immer.ts var immer = new Immer2(); var produce = immer.produce; var produceWithPatches = /* @__PURE__ */ immer.produceWithPatches.bind( immer ); var setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer); var setUseStrictShallowCopy = /* @__PURE__ */ immer.setUseStrictShallowCopy.bind( immer ); var setUseStrictIteration = /* @__PURE__ */ immer.setUseStrictIteration.bind( immer ); var applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer); var createDraft = /* @__PURE__ */ immer.createDraft.bind(immer); var finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer); var castDraft = (value) => value; var castImmutable = (value) => value; //# sourceMappingURL=immer.mjs.map /***/ }), /***/ "../../../node_modules/internmap/src/index.js": /*!****************************************************!*\ !*** ../../../node_modules/internmap/src/index.js ***! \****************************************************/ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ InternMap: () => (/* binding */ InternMap), /* harmony export */ InternSet: () => (/* binding */ InternSet) /* harmony export */ }); class InternMap extends Map { constructor(entries, key = keyof) { super(); Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}}); if (entries != null) for (const [key, value] of entries) this.set(key, value); } get(key) { return super.get(intern_get(this, key)); } has(key) { return super.has(intern_get(this, key)); } set(key, value) { return super.set(intern_set(this, key), value); } delete(key) { return super.delete(intern_delete(this, key)); } } class InternSet extends Set { constructor(values, key = keyof) { super(); Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}}); if (values != null) for (const value of values) this.add(value); } has(value) { return super.has(intern_get(this, value)); } add(value) { return super.add(intern_set(this, value)); } delete(value) { return super.delete(intern_delete(this, value)); } } function intern_get({_intern, _key}, value) { const key = _key(value); return _intern.has(key) ? _intern.get(key) : value; } function intern_set({_intern, _key}, value) { const key = _key(value); if (_intern.has(key)) return _intern.get(key); _intern.set(key, value); return value; } function intern_delete({_intern, _key}, value) { const key = _key(value); if (_intern.has(key)) { value = _intern.get(key); _intern.delete(key); } return value; } function keyof(value) { return value !== null && typeof value === "object" ? value.valueOf() : value; } /***/ }), /***/ "../../../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js": /*!****************************************************************************!*\ !*** ../../../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js ***! \****************************************************************************/ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { /*! * * jsPDF AutoTable plugin v3.8.4 * * Copyright (c) 2024 Simon Bengtsson, https://github.com/simonbengtsson/jsPDF-AutoTable * Licensed under the MIT License. * http://opensource.org/licenses/mit-license * */ (function webpackUniversalModuleDefinition(root, factory) { if(true) module.exports = factory((function webpackLoadOptionalExternalModule() { try { return __webpack_require__(/*! jspdf */ "../../../node_modules/jspdf/dist/jspdf.es.min.js"); } catch(e) {} }())); else // removed by dead control flow { var i, a; } })(typeof globalThis !== 'undefined' ? globalThis : typeof this !== 'undefined' ? this : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : __webpack_require__.g , function(__WEBPACK_EXTERNAL_MODULE__964__) { return /******/ (function() { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ 172: /***/ (function(__unused_webpack_module, exports) { var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", ({ value: true })); exports.CellHookData = exports.HookData = void 0; var HookData = /** @class */ (function () { function HookData(doc, table, cursor) { this.table = table; this.pageNumber = table.pageNumber; this.pageCount = this.pageNumber; this.settings = table.settings; this.cursor = cursor; this.doc = doc.getDocument(); } return HookData; }()); exports.HookData = HookData; var CellHookData = /** @class */ (function (_super) { __extends(CellHookData, _super); function CellHookData(doc, table, cell, row, column, cursor) { var _this = _super.call(this, doc, table, cursor) || this; _this.cell = cell; _this.row = row; _this.column = column; _this.section = row.section; return _this; } return CellHookData; }(HookData)); exports.CellHookData = CellHookData; /***/ }), /***/ 340: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { Object.defineProperty(exports, "__esModule", ({ value: true })); var htmlParser_1 = __webpack_require__(4); var autoTableText_1 = __webpack_require__(136); var documentHandler_1 = __webpack_require__(744); var inputParser_1 = __webpack_require__(776); var tableDrawer_1 = __webpack_require__(664); var tableCalculator_1 = __webpack_require__(972); function default_1(jsPDF) { // eslint-disable-next-line @typescript-eslint/no-explicit-any jsPDF.API.autoTable = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var options; if (args.length === 1) { options = args[0]; } else { console.error('Use of deprecated autoTable initiation'); options = args[2] || {}; options.columns = args[0]; options.body = args[1]; } var input = (0, inputParser_1.parseInput)(this, options); var table = (0, tableCalculator_1.createTable)(this, input); (0, tableDrawer_1.drawTable)(this, table); return this; }; // Assign false to enable `doc.lastAutoTable.finalY || 40` sugar jsPDF.API.lastAutoTable = false; jsPDF.API.previousAutoTable = false; // deprecated in v3 jsPDF.API.autoTable.previous = false; // deprecated in v3 jsPDF.API.autoTableText = function (text, x, y, styles) { (0, autoTableText_1.default)(text, x, y, styles, this); }; jsPDF.API.autoTableSetDefaults = function (defaults) { documentHandler_1.DocHandler.setDefaults(defaults, this); return this; }; jsPDF.autoTableSetDefaults = function (defaults, doc) { documentHandler_1.DocHandler.setDefaults(defaults, doc); }; jsPDF.API.autoTableHtmlToJson = function (tableElem, includeHiddenElements) { var _a; if (includeHiddenElements === void 0) { includeHiddenElements = false; } if (typeof window === 'undefined') { console.error('Cannot run autoTableHtmlToJson in non browser environment'); return null; } var doc = new documentHandler_1.DocHandler(this); var _b = (0, htmlParser_1.parseHtml)(doc, tableElem, window, includeHiddenElements, false), head = _b.head, body = _b.body; var columns = ((_a = head[0]) === null || _a === void 0 ? void 0 : _a.map(function (c) { return c.content; })) || []; return { columns: columns, rows: body, data: body }; }; /** * @deprecated */ jsPDF.API.autoTableEndPosY = function () { console.error('Use of deprecated function: autoTableEndPosY. Use doc.lastAutoTable.finalY instead.'); var prev = this.lastAutoTable; if (prev && prev.finalY) { return prev.finalY; } else { return 0; } }; /** * @deprecated */ jsPDF.API.autoTableAddPageContent = function (hook) { console.error('Use of deprecated function: autoTableAddPageContent. Use jsPDF.autoTableSetDefaults({didDrawPage: () => {}}) instead.'); if (!jsPDF.API.autoTable.globalDefaults) { jsPDF.API.autoTable.globalDefaults = {}; } jsPDF.API.autoTable.globalDefaults.addPageContent = hook; return this; }; /** * @deprecated */ jsPDF.API.autoTableAddPage = function () { console.error('Use of deprecated function: autoTableAddPage. Use doc.addPage()'); this.addPage(); return this; }; } exports["default"] = default_1; /***/ }), /***/ 136: /***/ (function(__unused_webpack_module, exports) { Object.defineProperty(exports, "__esModule", ({ value: true })); /** * Improved text function with halign and valign support * Inspiration from: http://stackoverflow.com/questions/28327510/align-text-right-using-jspdf/28433113#28433113 */ function default_1(text, x, y, styles, doc) { styles = styles || {}; var PHYSICAL_LINE_HEIGHT = 1.15; var k = doc.internal.scaleFactor; var fontSize = doc.internal.getFontSize() / k; var lineHeightFactor = doc.getLineHeightFactor ? doc.getLineHeightFactor() : PHYSICAL_LINE_HEIGHT; var lineHeight = fontSize * lineHeightFactor; var splitRegex = /\r\n|\r|\n/g; var splitText = ''; var lineCount = 1; if (styles.valign === 'middle' || styles.valign === 'bottom' || styles.halign === 'center' || styles.halign === 'right') { splitText = typeof text === 'string' ? text.split(splitRegex) : text; lineCount = splitText.length || 1; } // Align the top y += fontSize * (2 - PHYSICAL_LINE_HEIGHT); if (styles.valign === 'middle') y -= (lineCount / 2) * lineHeight; else if (styles.valign === 'bottom') y -= lineCount * lineHeight; if (styles.halign === 'center' || styles.halign === 'right') { var alignSize = fontSize; if (styles.halign === 'center') alignSize *= 0.5; if (splitText && lineCount >= 1) { for (var iLine = 0; iLine < splitText.length; iLine++) { doc.text(splitText[iLine], x - doc.getStringUnitWidth(splitText[iLine]) * alignSize, y); y += lineHeight; } return doc; } x -= doc.getStringUnitWidth(text) * alignSize; } if (styles.halign === 'justify') { doc.text(text, x, y, { maxWidth: styles.maxWidth || 100, align: 'justify', }); } else { doc.text(text, x, y); } return doc; } exports["default"] = default_1; /***/ }), /***/ 420: /***/ (function(__unused_webpack_module, exports) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.getPageAvailableWidth = exports.parseSpacing = exports.getFillStyle = exports.addTableBorder = exports.getStringWidth = void 0; function getStringWidth(text, styles, doc) { doc.applyStyles(styles, true); var textArr = Array.isArray(text) ? text : [text]; var widestLineWidth = textArr .map(function (text) { return doc.getTextWidth(text); }) .reduce(function (a, b) { return Math.max(a, b); }, 0); return widestLineWidth; } exports.getStringWidth = getStringWidth; function addTableBorder(doc, table, startPos, cursor) { var lineWidth = table.settings.tableLineWidth; var lineColor = table.settings.tableLineColor; doc.applyStyles({ lineWidth: lineWidth, lineColor: lineColor }); var fillStyle = getFillStyle(lineWidth, false); if (fillStyle) { doc.rect(startPos.x, startPos.y, table.getWidth(doc.pageSize().width), cursor.y - startPos.y, fillStyle); } } exports.addTableBorder = addTableBorder; function getFillStyle(lineWidth, fillColor) { var drawLine = lineWidth > 0; var drawBackground = fillColor || fillColor === 0; if (drawLine && drawBackground) { return 'DF'; // Fill then stroke } else if (drawLine) { return 'S'; // Only stroke (transparent background) } else if (drawBackground) { return 'F'; // Only fill, no stroke } else { return null; } } exports.getFillStyle = getFillStyle; function parseSpacing(value, defaultValue) { var _a, _b, _c, _d; value = value || defaultValue; if (Array.isArray(value)) { if (value.length >= 4) { return { top: value[0], right: value[1], bottom: value[2], left: value[3], }; } else if (value.length === 3) { return { top: value[0], right: value[1], bottom: value[2], left: value[1], }; } else if (value.length === 2) { return { top: value[0], right: value[1], bottom: value[0], left: value[1], }; } else if (value.length === 1) { value = value[0]; } else { value = defaultValue; } } if (typeof value === 'object') { if (typeof value.vertical === 'number') { value.top = value.vertical; value.bottom = value.vertical; } if (typeof value.horizontal === 'number') { value.right = value.horizontal; value.left = value.horizontal; } return { left: (_a = value.left) !== null && _a !== void 0 ? _a : defaultValue, top: (_b = value.top) !== null && _b !== void 0 ? _b : defaultValue, right: (_c = value.right) !== null && _c !== void 0 ? _c : defaultValue, bottom: (_d = value.bottom) !== null && _d !== void 0 ? _d : defaultValue, }; } if (typeof value !== 'number') { value = defaultValue; } return { top: value, right: value, bottom: value, left: value }; } exports.parseSpacing = parseSpacing; function getPageAvailableWidth(doc, table) { var margins = parseSpacing(table.settings.margin, 0); return doc.pageSize().width - (margins.left + margins.right); } exports.getPageAvailableWidth = getPageAvailableWidth; /***/ }), /***/ 796: /***/ (function(__unused_webpack_module, exports) { var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", ({ value: true })); exports.getTheme = exports.defaultStyles = exports.HtmlRowInput = void 0; var HtmlRowInput = /** @class */ (function (_super) { __extends(HtmlRowInput, _super); function HtmlRowInput(element) { var _this = _super.call(this) || this; _this._element = element; return _this; } return HtmlRowInput; }(Array)); exports.HtmlRowInput = HtmlRowInput; // Base style for all themes function defaultStyles(scaleFactor) { return { font: 'helvetica', // helvetica, times, courier fontStyle: 'normal', // normal, bold, italic, bolditalic overflow: 'linebreak', // linebreak, ellipsize, visible or hidden fillColor: false, // Either false for transparent, rbg array e.g. [255, 255, 255] or gray level e.g 200 textColor: 20, halign: 'left', // left, center, right, justify valign: 'top', // top, middle, bottom fontSize: 10, cellPadding: 5 / scaleFactor, // number or {top,left,right,left,vertical,horizontal} lineColor: 200, lineWidth: 0, cellWidth: 'auto', // 'auto'|'wrap'|number minCellHeight: 0, minCellWidth: 0, }; } exports.defaultStyles = defaultStyles; function getTheme(name) { var themes = { striped: { table: { fillColor: 255, textColor: 80, fontStyle: 'normal' }, head: { textColor: 255, fillColor: [41, 128, 185], fontStyle: 'bold' }, body: {}, foot: { textColor: 255, fillColor: [41, 128, 185], fontStyle: 'bold' }, alternateRow: { fillColor: 245 }, }, grid: { table: { fillColor: 255, textColor: 80, fontStyle: 'normal', lineWidth: 0.1, }, head: { textColor: 255, fillColor: [26, 188, 156], fontStyle: 'bold', lineWidth: 0, }, body: {}, foot: { textColor: 255, fillColor: [26, 188, 156], fontStyle: 'bold', lineWidth: 0, }, alternateRow: {}, }, plain: { head: { fontStyle: 'bold' }, foot: { fontStyle: 'bold' }, }, }; return themes[name]; } exports.getTheme = getTheme; /***/ }), /***/ 903: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.parseCss = void 0; // Limitations // - No support for border spacing // - No support for transparency var common_1 = __webpack_require__(420); function parseCss(supportedFonts, element, scaleFactor, style, window) { var result = {}; var pxScaleFactor = 96 / 72; var backgroundColor = parseColor(element, function (elem) { return window.getComputedStyle(elem)['backgroundColor']; }); if (backgroundColor != null) result.fillColor = backgroundColor; var textColor = parseColor(element, function (elem) { return window.getComputedStyle(elem)['color']; }); if (textColor != null) result.textColor = textColor; var padding = parsePadding(style, scaleFactor); if (padding) result.cellPadding = padding; var borderColorSide = 'borderTopColor'; var finalScaleFactor = pxScaleFactor * scaleFactor; var btw = style.borderTopWidth; if (style.borderBottomWidth === btw && style.borderRightWidth === btw && style.borderLeftWidth === btw) { var borderWidth = (parseFloat(btw) || 0) / finalScaleFactor; if (borderWidth) result.lineWidth = borderWidth; } else { result.lineWidth = { top: (parseFloat(style.borderTopWidth) || 0) / finalScaleFactor, right: (parseFloat(style.borderRightWidth) || 0) / finalScaleFactor, bottom: (parseFloat(style.borderBottomWidth) || 0) / finalScaleFactor, left: (parseFloat(style.borderLeftWidth) || 0) / finalScaleFactor, }; // Choose border color of first available side // could be improved by supporting object as lineColor if (!result.lineWidth.top) { if (result.lineWidth.right) { borderColorSide = 'borderRightColor'; } else if (result.lineWidth.bottom) { borderColorSide = 'borderBottomColor'; } else if (result.lineWidth.left) { borderColorSide = 'borderLeftColor'; } } } var borderColor = parseColor(element, function (elem) { return window.getComputedStyle(elem)[borderColorSide]; }); if (borderColor != null) result.lineColor = borderColor; var accepted = ['left', 'right', 'center', 'justify']; if (accepted.indexOf(style.textAlign) !== -1) { result.halign = style.textAlign; } accepted = ['middle', 'bottom', 'top']; if (accepted.indexOf(style.verticalAlign) !== -1) { result.valign = style.verticalAlign; } var res = parseInt(style.fontSize || ''); if (!isNaN(res)) result.fontSize = res / pxScaleFactor; var fontStyle = parseFontStyle(style); if (fontStyle) result.fontStyle = fontStyle; var font = (style.fontFamily || '').toLowerCase(); if (supportedFonts.indexOf(font) !== -1) { result.font = font; } return result; } exports.parseCss = parseCss; function parseFontStyle(style) { var res = ''; if (style.fontWeight === 'bold' || style.fontWeight === 'bolder' || parseInt(style.fontWeight) >= 700) { res = 'bold'; } if (style.fontStyle === 'italic' || style.fontStyle === 'oblique') { res += 'italic'; } return res; } function parseColor(element, styleGetter) { var cssColor = realColor(element, styleGetter); if (!cssColor) return null; var rgba = cssColor.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d*))?\)$/); if (!rgba || !Array.isArray(rgba)) { return null; } var color = [ parseInt(rgba[1]), parseInt(rgba[2]), parseInt(rgba[3]), ]; var alpha = parseInt(rgba[4]); if (alpha === 0 || isNaN(color[0]) || isNaN(color[1]) || isNaN(color[2])) { return null; } return color; } function realColor(elem, styleGetter) { var bg = styleGetter(elem); if (bg === 'rgba(0, 0, 0, 0)' || bg === 'transparent' || bg === 'initial' || bg === 'inherit') { if (elem.parentElement == null) { return null; } return realColor(elem.parentElement, styleGetter); } else { return bg; } } function parsePadding(style, scaleFactor) { var val = [ style.paddingTop, style.paddingRight, style.paddingBottom, style.paddingLeft, ]; var pxScaleFactor = 96 / (72 / scaleFactor); var linePadding = (parseInt(style.lineHeight) - parseInt(style.fontSize)) / scaleFactor / 2; var inputPadding = val.map(function (n) { return parseInt(n || '0') / pxScaleFactor; }); var padding = (0, common_1.parseSpacing)(inputPadding, 0); if (linePadding > padding.top) { padding.top = linePadding; } if (linePadding > padding.bottom) { padding.bottom = linePadding; } return padding; } /***/ }), /***/ 744: /***/ (function(__unused_webpack_module, exports) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.DocHandler = void 0; var globalDefaults = {}; var DocHandler = /** @class */ (function () { function DocHandler(jsPDFDocument) { this.jsPDFDocument = jsPDFDocument; this.userStyles = { // Black for versions of jspdf without getTextColor textColor: jsPDFDocument.getTextColor ? this.jsPDFDocument.getTextColor() : 0, fontSize: jsPDFDocument.internal.getFontSize(), fontStyle: jsPDFDocument.internal.getFont().fontStyle, font: jsPDFDocument.internal.getFont().fontName, // 0 for versions of jspdf without getLineWidth lineWidth: jsPDFDocument.getLineWidth ? this.jsPDFDocument.getLineWidth() : 0, // Black for versions of jspdf without getDrawColor lineColor: jsPDFDocument.getDrawColor ? this.jsPDFDocument.getDrawColor() : 0, }; } DocHandler.setDefaults = function (defaults, doc) { if (doc === void 0) { doc = null; } if (doc) { doc.__autoTableDocumentDefaults = defaults; } else { globalDefaults = defaults; } }; DocHandler.unifyColor = function (c) { if (Array.isArray(c)) { return c; } else if (typeof c === 'number') { return [c, c, c]; } else if (typeof c === 'string') { return [c]; } else { return null; } }; DocHandler.prototype.applyStyles = function (styles, fontOnly) { // Font style needs to be applied before font // https://github.com/simonbengtsson/jsPDF-AutoTable/issues/632 var _a, _b, _c; if (fontOnly === void 0) { fontOnly = false; } if (styles.fontStyle) this.jsPDFDocument.setFontStyle && this.jsPDFDocument.setFontStyle(styles.fontStyle); var _d = this.jsPDFDocument.internal.getFont(), fontStyle = _d.fontStyle, fontName = _d.fontName; if (styles.font) fontName = styles.font; if (styles.fontStyle) { fontStyle = styles.fontStyle; var availableFontStyles = this.getFontList()[fontName]; if (availableFontStyles && availableFontStyles.indexOf(fontStyle) === -1) { // Common issue was that the default bold in headers // made custom fonts not work. For example: // https://github.com/simonbengtsson/jsPDF-AutoTable/issues/653 this.jsPDFDocument.setFontStyle && this.jsPDFDocument.setFontStyle(availableFontStyles[0]); fontStyle = availableFontStyles[0]; } } this.jsPDFDocument.setFont(fontName, fontStyle); if (styles.fontSize) this.jsPDFDocument.setFontSize(styles.fontSize); if (fontOnly) { return; // Performance improvement } var color = DocHandler.unifyColor(styles.fillColor); if (color) (_a = this.jsPDFDocument).setFillColor.apply(_a, color); color = DocHandler.unifyColor(styles.textColor); if (color) (_b = this.jsPDFDocument).setTextColor.apply(_b, color); color = DocHandler.unifyColor(styles.lineColor); if (color) (_c = this.jsPDFDocument).setDrawColor.apply(_c, color); if (typeof styles.lineWidth === 'number') { this.jsPDFDocument.setLineWidth(styles.lineWidth); } }; DocHandler.prototype.splitTextToSize = function (text, size, opts) { return this.jsPDFDocument.splitTextToSize(text, size, opts); }; /** * Adds a rectangle to the PDF * @param x Coordinate (in units declared at inception of PDF document) against left edge of the page * @param y Coordinate (in units declared at inception of PDF document) against upper edge of the page * @param width Width (in units declared at inception of PDF document) * @param height Height (in units declared at inception of PDF document) * @param fillStyle A string specifying the painting style or null. Valid styles include: 'S' [default] - stroke, 'F' - fill, and 'DF' (or 'FD') - fill then stroke. */ DocHandler.prototype.rect = function (x, y, width, height, fillStyle) { // null is excluded from fillStyle possible values because it isn't needed // and is prone to bugs as it's used to postpone setting the style // https://rawgit.com/MrRio/jsPDF/master/docs/jsPDF.html#rect return this.jsPDFDocument.rect(x, y, width, height, fillStyle); }; DocHandler.prototype.getLastAutoTable = function () { return this.jsPDFDocument.lastAutoTable || null; }; DocHandler.prototype.getTextWidth = function (text) { return this.jsPDFDocument.getTextWidth(text); }; DocHandler.prototype.getDocument = function () { return this.jsPDFDocument; }; DocHandler.prototype.setPage = function (page) { this.jsPDFDocument.setPage(page); }; DocHandler.prototype.addPage = function () { return this.jsPDFDocument.addPage(); }; DocHandler.prototype.getFontList = function () { return this.jsPDFDocument.getFontList(); }; DocHandler.prototype.getGlobalOptions = function () { return globalDefaults || {}; }; DocHandler.prototype.getDocumentOptions = function () { return this.jsPDFDocument.__autoTableDocumentDefaults || {}; }; DocHandler.prototype.pageSize = function () { var pageSize = this.jsPDFDocument.internal.pageSize; // JSPDF 1.4 uses get functions instead of properties on pageSize if (pageSize.width == null) { pageSize = { width: pageSize.getWidth(), height: pageSize.getHeight(), }; } return pageSize; }; DocHandler.prototype.scaleFactor = function () { return this.jsPDFDocument.internal.scaleFactor; }; DocHandler.prototype.getLineHeightFactor = function () { var doc = this.jsPDFDocument; return doc.getLineHeightFactor ? doc.getLineHeightFactor() : 1.15; }; DocHandler.prototype.getLineHeight = function (fontSize) { return (fontSize / this.scaleFactor()) * this.getLineHeightFactor(); }; DocHandler.prototype.pageNumber = function () { var pageInfo = this.jsPDFDocument.internal.getCurrentPageInfo(); if (!pageInfo) { // Only recent versions of jspdf has pageInfo return this.jsPDFDocument.internal.getNumberOfPages(); } return pageInfo.pageNumber; }; return DocHandler; }()); exports.DocHandler = DocHandler; /***/ }), /***/ 4: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.parseHtml = void 0; var cssParser_1 = __webpack_require__(903); var config_1 = __webpack_require__(796); function parseHtml(doc, input, window, includeHiddenHtml, useCss) { var _a, _b; if (includeHiddenHtml === void 0) { includeHiddenHtml = false; } if (useCss === void 0) { useCss = false; } var tableElement; if (typeof input === 'string') { tableElement = window.document.querySelector(input); } else { tableElement = input; } var supportedFonts = Object.keys(doc.getFontList()); var scaleFactor = doc.scaleFactor(); var head = [], body = [], foot = []; if (!tableElement) { console.error('Html table could not be found with input: ', input); return { head: head, body: body, foot: foot }; } for (var i = 0; i < tableElement.rows.length; i++) { var element = tableElement.rows[i]; var tagName = (_b = (_a = element === null || element === void 0 ? void 0 : element.parentElement) === null || _a === void 0 ? void 0 : _a.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase(); var row = parseRowContent(supportedFonts, scaleFactor, window, element, includeHiddenHtml, useCss); if (!row) continue; if (tagName === 'thead') { head.push(row); } else if (tagName === 'tfoot') { foot.push(row); } else { // Add to body both if parent is tbody or table body.push(row); } } return { head: head, body: body, foot: foot }; } exports.parseHtml = parseHtml; function parseRowContent(supportedFonts, scaleFactor, window, row, includeHidden, useCss) { var resultRow = new config_1.HtmlRowInput(row); for (var i = 0; i < row.cells.length; i++) { var cell = row.cells[i]; var style_1 = window.getComputedStyle(cell); if (includeHidden || style_1.display !== 'none') { var cellStyles = void 0; if (useCss) { cellStyles = (0, cssParser_1.parseCss)(supportedFonts, cell, scaleFactor, style_1, window); } resultRow.push({ rowSpan: cell.rowSpan, colSpan: cell.colSpan, styles: cellStyles, _element: cell, content: parseCellContent(cell), }); } } var style = window.getComputedStyle(row); if (resultRow.length > 0 && (includeHidden || style.display !== 'none')) { return resultRow; } } function parseCellContent(orgCell) { // Work on cloned node to make sure no changes are applied to html table var cell = orgCell.cloneNode(true); // Remove extra space and line breaks in markup to make it more similar to // what would be shown in html cell.innerHTML = cell.innerHTML.replace(/\n/g, '').replace(/ +/g, ' '); // Preserve
tags as line breaks in the pdf cell.innerHTML = cell.innerHTML .split(//) //start with ''. .map(function (part) { return part.trim(); }) .join('\n'); // innerText for ie return cell.innerText || cell.textContent || ''; } /***/ }), /***/ 776: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.parseInput = void 0; var htmlParser_1 = __webpack_require__(4); var polyfills_1 = __webpack_require__(356); var common_1 = __webpack_require__(420); var documentHandler_1 = __webpack_require__(744); var inputValidator_1 = __webpack_require__(792); function parseInput(d, current) { var doc = new documentHandler_1.DocHandler(d); var document = doc.getDocumentOptions(); var global = doc.getGlobalOptions(); (0, inputValidator_1.default)(doc, global, document, current); var options = (0, polyfills_1.assign)({}, global, document, current); var win; if (typeof window !== 'undefined') { win = window; } var styles = parseStyles(global, document, current); var hooks = parseHooks(global, document, current); var settings = parseSettings(doc, options); var content = parseContent(doc, options, win); return { id: current.tableId, content: content, hooks: hooks, styles: styles, settings: settings, }; } exports.parseInput = parseInput; function parseStyles(gInput, dInput, cInput) { var styleOptions = { styles: {}, headStyles: {}, bodyStyles: {}, footStyles: {}, alternateRowStyles: {}, columnStyles: {}, }; var _loop_1 = function (prop) { if (prop === 'columnStyles') { var global_1 = gInput[prop]; var document_1 = dInput[prop]; var current = cInput[prop]; styleOptions.columnStyles = (0, polyfills_1.assign)({}, global_1, document_1, current); } else { var allOptions = [gInput, dInput, cInput]; var styles = allOptions.map(function (opts) { return opts[prop] || {}; }); styleOptions[prop] = (0, polyfills_1.assign)({}, styles[0], styles[1], styles[2]); } }; for (var _i = 0, _a = Object.keys(styleOptions); _i < _a.length; _i++) { var prop = _a[_i]; _loop_1(prop); } return styleOptions; } function parseHooks(global, document, current) { var allOptions = [global, document, current]; var result = { didParseCell: [], willDrawCell: [], didDrawCell: [], willDrawPage: [], didDrawPage: [], }; for (var _i = 0, allOptions_1 = allOptions; _i < allOptions_1.length; _i++) { var options = allOptions_1[_i]; if (options.didParseCell) result.didParseCell.push(options.didParseCell); if (options.willDrawCell) result.willDrawCell.push(options.willDrawCell); if (options.didDrawCell) result.didDrawCell.push(options.didDrawCell); if (options.willDrawPage) result.willDrawPage.push(options.willDrawPage); if (options.didDrawPage) result.didDrawPage.push(options.didDrawPage); } return result; } function parseSettings(doc, options) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; var margin = (0, common_1.parseSpacing)(options.margin, 40 / doc.scaleFactor()); var startY = (_a = getStartY(doc, options.startY)) !== null && _a !== void 0 ? _a : margin.top; var showFoot; if (options.showFoot === true) { showFoot = 'everyPage'; } else if (options.showFoot === false) { showFoot = 'never'; } else { showFoot = (_b = options.showFoot) !== null && _b !== void 0 ? _b : 'everyPage'; } var showHead; if (options.showHead === true) { showHead = 'everyPage'; } else if (options.showHead === false) { showHead = 'never'; } else { showHead = (_c = options.showHead) !== null && _c !== void 0 ? _c : 'everyPage'; } var useCss = (_d = options.useCss) !== null && _d !== void 0 ? _d : false; var theme = options.theme || (useCss ? 'plain' : 'striped'); var horizontalPageBreak = !!options.horizontalPageBreak; var horizontalPageBreakRepeat = (_e = options.horizontalPageBreakRepeat) !== null && _e !== void 0 ? _e : null; return { includeHiddenHtml: (_f = options.includeHiddenHtml) !== null && _f !== void 0 ? _f : false, useCss: useCss, theme: theme, startY: startY, margin: margin, pageBreak: (_g = options.pageBreak) !== null && _g !== void 0 ? _g : 'auto', rowPageBreak: (_h = options.rowPageBreak) !== null && _h !== void 0 ? _h : 'auto', tableWidth: (_j = options.tableWidth) !== null && _j !== void 0 ? _j : 'auto', showHead: showHead, showFoot: showFoot, tableLineWidth: (_k = options.tableLineWidth) !== null && _k !== void 0 ? _k : 0, tableLineColor: (_l = options.tableLineColor) !== null && _l !== void 0 ? _l : 200, horizontalPageBreak: horizontalPageBreak, horizontalPageBreakRepeat: horizontalPageBreakRepeat, horizontalPageBreakBehaviour: (_m = options.horizontalPageBreakBehaviour) !== null && _m !== void 0 ? _m : 'afterAllRows', }; } function getStartY(doc, userStartY) { var previous = doc.getLastAutoTable(); var sf = doc.scaleFactor(); var currentPage = doc.pageNumber(); var isSamePageAsPreviousTable = false; if (previous && previous.startPageNumber) { var endingPage = previous.startPageNumber + previous.pageNumber - 1; isSamePageAsPreviousTable = endingPage === currentPage; } if (typeof userStartY === 'number') { return userStartY; } else if (userStartY == null || userStartY === false) { if (isSamePageAsPreviousTable && (previous === null || previous === void 0 ? void 0 : previous.finalY) != null) { // Some users had issues with overlapping tables when they used multiple // tables without setting startY so setting it here to a sensible default. return previous.finalY + 20 / sf; } } return null; } function parseContent(doc, options, window) { var head = options.head || []; var body = options.body || []; var foot = options.foot || []; if (options.html) { var hidden = options.includeHiddenHtml; if (window) { var htmlContent = (0, htmlParser_1.parseHtml)(doc, options.html, window, hidden, options.useCss) || {}; head = htmlContent.head || head; body = htmlContent.body || head; foot = htmlContent.foot || head; } else { console.error('Cannot parse html in non browser environment'); } } var columns = options.columns || parseColumns(head, body, foot); return { columns: columns, head: head, body: body, foot: foot, }; } function parseColumns(head, body, foot) { var firstRow = head[0] || body[0] || foot[0] || []; var result = []; Object.keys(firstRow) .filter(function (key) { return key !== '_element'; }) .forEach(function (key) { var colSpan = 1; var input; if (Array.isArray(firstRow)) { input = firstRow[parseInt(key)]; } else { input = firstRow[key]; } if (typeof input === 'object' && !Array.isArray(input)) { colSpan = (input === null || input === void 0 ? void 0 : input.colSpan) || 1; } for (var i = 0; i < colSpan; i++) { var id = void 0; if (Array.isArray(firstRow)) { id = result.length; } else { id = key + (i > 0 ? "_".concat(i) : ''); } var rowResult = { dataKey: id }; result.push(rowResult); } }); return result; } /***/ }), /***/ 792: /***/ (function(__unused_webpack_module, exports) { Object.defineProperty(exports, "__esModule", ({ value: true })); function default_1(doc, global, document, current) { var _loop_1 = function (options) { if (options && typeof options !== 'object') { console.error('The options parameter should be of type object, is: ' + typeof options); } if (typeof options.extendWidth !== 'undefined') { options.tableWidth = options.extendWidth ? 'auto' : 'wrap'; console.error('Use of deprecated option: extendWidth, use tableWidth instead.'); } if (typeof options.margins !== 'undefined') { if (typeof options.margin === 'undefined') options.margin = options.margins; console.error('Use of deprecated option: margins, use margin instead.'); } if (options.startY && typeof options.startY !== 'number') { console.error('Invalid value for startY option', options.startY); delete options.startY; } if (!options.didDrawPage && (options.afterPageContent || options.beforePageContent || options.afterPageAdd)) { console.error('The afterPageContent, beforePageContent and afterPageAdd hooks are deprecated. Use didDrawPage instead'); options.didDrawPage = function (data) { doc.applyStyles(doc.userStyles); if (options.beforePageContent) options.beforePageContent(data); doc.applyStyles(doc.userStyles); if (options.afterPageContent) options.afterPageContent(data); doc.applyStyles(doc.userStyles); if (options.afterPageAdd && data.pageNumber > 1) { ; data.afterPageAdd(data); } doc.applyStyles(doc.userStyles); }; } ; [ 'createdHeaderCell', 'drawHeaderRow', 'drawRow', 'drawHeaderCell', ].forEach(function (name) { if (options[name]) { console.error("The \"".concat(name, "\" hook has changed in version 3.0, check the changelog for how to migrate.")); } }); [ ['showFoot', 'showFooter'], ['showHead', 'showHeader'], ['didDrawPage', 'addPageContent'], ['didParseCell', 'createdCell'], ['headStyles', 'headerStyles'], ].forEach(function (_a) { var current = _a[0], deprecated = _a[1]; if (options[deprecated]) { console.error("Use of deprecated option ".concat(deprecated, ". Use ").concat(current, " instead")); options[current] = options[deprecated]; } }); [ ['padding', 'cellPadding'], ['lineHeight', 'rowHeight'], 'fontSize', 'overflow', ].forEach(function (o) { var deprecatedOption = typeof o === 'string' ? o : o[0]; var style = typeof o === 'string' ? o : o[1]; if (typeof options[deprecatedOption] !== 'undefined') { if (typeof options.styles[style] === 'undefined') { options.styles[style] = options[deprecatedOption]; } console.error('Use of deprecated option: ' + deprecatedOption + ', use the style ' + style + ' instead.'); } }); for (var _b = 0, _c = [ 'styles', 'bodyStyles', 'headStyles', 'footStyles', ]; _b < _c.length; _b++) { var styleProp = _c[_b]; checkStyles(options[styleProp] || {}); } var columnStyles = options['columnStyles'] || {}; for (var _d = 0, _e = Object.keys(columnStyles); _d < _e.length; _d++) { var key = _e[_d]; checkStyles(columnStyles[key] || {}); } }; for (var _i = 0, _a = [global, document, current]; _i < _a.length; _i++) { var options = _a[_i]; _loop_1(options); } } exports["default"] = default_1; function checkStyles(styles) { if (styles.rowHeight) { console.error('Use of deprecated style rowHeight. It is renamed to minCellHeight.'); if (!styles.minCellHeight) { styles.minCellHeight = styles.rowHeight; } } else if (styles.columnWidth) { console.error('Use of deprecated style columnWidth. It is renamed to cellWidth.'); if (!styles.cellWidth) { styles.cellWidth = styles.columnWidth; } } } /***/ }), /***/ 260: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Column = exports.Cell = exports.Row = exports.Table = void 0; var config_1 = __webpack_require__(796); var HookData_1 = __webpack_require__(172); var common_1 = __webpack_require__(420); var Table = /** @class */ (function () { function Table(input, content) { this.pageNumber = 1; // Deprecated, use pageNumber instead // Not using getter since: // https://github.com/simonbengtsson/jsPDF-AutoTable/issues/596 this.pageCount = 1; this.id = input.id; this.settings = input.settings; this.styles = input.styles; this.hooks = input.hooks; this.columns = content.columns; this.head = content.head; this.body = content.body; this.foot = content.foot; } Table.prototype.getHeadHeight = function (columns) { return this.head.reduce(function (acc, row) { return acc + row.getMaxCellHeight(columns); }, 0); }; Table.prototype.getFootHeight = function (columns) { return this.foot.reduce(function (acc, row) { return acc + row.getMaxCellHeight(columns); }, 0); }; Table.prototype.allRows = function () { return this.head.concat(this.body).concat(this.foot); }; Table.prototype.callCellHooks = function (doc, handlers, cell, row, column, cursor) { for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) { var handler = handlers_1[_i]; var data = new HookData_1.CellHookData(doc, this, cell, row, column, cursor); var result = handler(data) === false; // Make sure text is always string[] since user can assign string cell.text = Array.isArray(cell.text) ? cell.text : [cell.text]; if (result) { return false; } } return true; }; Table.prototype.callEndPageHooks = function (doc, cursor) { doc.applyStyles(doc.userStyles); for (var _i = 0, _a = this.hooks.didDrawPage; _i < _a.length; _i++) { var handler = _a[_i]; handler(new HookData_1.HookData(doc, this, cursor)); } }; Table.prototype.callWillDrawPageHooks = function (doc, cursor) { for (var _i = 0, _a = this.hooks.willDrawPage; _i < _a.length; _i++) { var handler = _a[_i]; handler(new HookData_1.HookData(doc, this, cursor)); } }; Table.prototype.getWidth = function (pageWidth) { if (typeof this.settings.tableWidth === 'number') { return this.settings.tableWidth; } else if (this.settings.tableWidth === 'wrap') { var wrappedWidth = this.columns.reduce(function (total, col) { return total + col.wrappedWidth; }, 0); return wrappedWidth; } else { var margin = this.settings.margin; return pageWidth - margin.left - margin.right; } }; return Table; }()); exports.Table = Table; var Row = /** @class */ (function () { function Row(raw, index, section, cells, spansMultiplePages) { if (spansMultiplePages === void 0) { spansMultiplePages = false; } this.height = 0; this.raw = raw; if (raw instanceof config_1.HtmlRowInput) { this.raw = raw._element; this.element = raw._element; } this.index = index; this.section = section; this.cells = cells; this.spansMultiplePages = spansMultiplePages; } Row.prototype.getMaxCellHeight = function (columns) { var _this = this; return columns.reduce(function (acc, column) { var _a; return Math.max(acc, ((_a = _this.cells[column.index]) === null || _a === void 0 ? void 0 : _a.height) || 0); }, 0); }; Row.prototype.hasRowSpan = function (columns) { var _this = this; return (columns.filter(function (column) { var cell = _this.cells[column.index]; if (!cell) return false; return cell.rowSpan > 1; }).length > 0); }; Row.prototype.canEntireRowFit = function (height, columns) { return this.getMaxCellHeight(columns) <= height; }; Row.prototype.getMinimumRowHeight = function (columns, doc) { var _this = this; return columns.reduce(function (acc, column) { var cell = _this.cells[column.index]; if (!cell) return 0; var lineHeight = doc.getLineHeight(cell.styles.fontSize); var vPadding = cell.padding('vertical'); var oneRowHeight = vPadding + lineHeight; return oneRowHeight > acc ? oneRowHeight : acc; }, 0); }; return Row; }()); exports.Row = Row; var Cell = /** @class */ (function () { function Cell(raw, styles, section) { var _a, _b; this.contentHeight = 0; this.contentWidth = 0; this.wrappedWidth = 0; this.minReadableWidth = 0; this.minWidth = 0; this.width = 0; this.height = 0; this.x = 0; this.y = 0; this.styles = styles; this.section = section; this.raw = raw; var content = raw; if (raw != null && typeof raw === 'object' && !Array.isArray(raw)) { this.rowSpan = raw.rowSpan || 1; this.colSpan = raw.colSpan || 1; content = (_b = (_a = raw.content) !== null && _a !== void 0 ? _a : raw.title) !== null && _b !== void 0 ? _b : raw; if (raw._element) { this.raw = raw._element; } } else { this.rowSpan = 1; this.colSpan = 1; } // Stringify 0 and false, but not undefined or null var text = content != null ? '' + content : ''; var splitRegex = /\r\n|\r|\n/g; this.text = text.split(splitRegex); } Cell.prototype.getTextPos = function () { var y; if (this.styles.valign === 'top') { y = this.y + this.padding('top'); } else if (this.styles.valign === 'bottom') { y = this.y + this.height - this.padding('bottom'); } else { var netHeight = this.height - this.padding('vertical'); y = this.y + netHeight / 2 + this.padding('top'); } var x; if (this.styles.halign === 'right') { x = this.x + this.width - this.padding('right'); } else if (this.styles.halign === 'center') { var netWidth = this.width - this.padding('horizontal'); x = this.x + netWidth / 2 + this.padding('left'); } else { x = this.x + this.padding('left'); } return { x: x, y: y }; }; // TODO (v4): replace parameters with only (lineHeight) Cell.prototype.getContentHeight = function (scaleFactor, lineHeightFactor) { if (lineHeightFactor === void 0) { lineHeightFactor = 1.15; } var lineCount = Array.isArray(this.text) ? this.text.length : 1; var lineHeight = (this.styles.fontSize / scaleFactor) * lineHeightFactor; var height = lineCount * lineHeight + this.padding('vertical'); return Math.max(height, this.styles.minCellHeight); }; Cell.prototype.padding = function (name) { var padding = (0, common_1.parseSpacing)(this.styles.cellPadding, 0); if (name === 'vertical') { return padding.top + padding.bottom; } else if (name === 'horizontal') { return padding.left + padding.right; } else { return padding[name]; } }; return Cell; }()); exports.Cell = Cell; var Column = /** @class */ (function () { function Column(dataKey, raw, index) { this.wrappedWidth = 0; this.minReadableWidth = 0; this.minWidth = 0; this.width = 0; this.dataKey = dataKey; this.raw = raw; this.index = index; } Column.prototype.getMaxCustomCellWidth = function (table) { var max = 0; for (var _i = 0, _a = table.allRows(); _i < _a.length; _i++) { var row = _a[_i]; var cell = row.cells[this.index]; if (cell && typeof cell.styles.cellWidth === 'number') { max = Math.max(max, cell.styles.cellWidth); } } return max; }; return Column; }()); exports.Column = Column; /***/ }), /***/ 356: /***/ (function(__unused_webpack_module, exports) { /* eslint-disable @typescript-eslint/no-unused-vars */ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.assign = void 0; // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign function assign(target, s, s1, s2, s3) { if (target == null) { throw new TypeError('Cannot convert undefined or null to object'); } var to = Object(target); for (var index = 1; index < arguments.length; index++) { // eslint-disable-next-line prefer-rest-params var nextSource = arguments[index]; if (nextSource != null) { // Skip over if undefined or null for (var nextKey in nextSource) { // Avoid bugs when hasOwnProperty is shadowed if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { to[nextKey] = nextSource[nextKey]; } } } } return to; } exports.assign = assign; /***/ }), /***/ 972: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.createTable = void 0; var documentHandler_1 = __webpack_require__(744); var models_1 = __webpack_require__(260); var widthCalculator_1 = __webpack_require__(324); var config_1 = __webpack_require__(796); var polyfills_1 = __webpack_require__(356); function createTable(jsPDFDoc, input) { var doc = new documentHandler_1.DocHandler(jsPDFDoc); var content = parseContent(input, doc.scaleFactor()); var table = new models_1.Table(input, content); (0, widthCalculator_1.calculateWidths)(doc, table); doc.applyStyles(doc.userStyles); return table; } exports.createTable = createTable; function parseContent(input, sf) { var content = input.content; var columns = createColumns(content.columns); // If no head or foot is set, try generating it with content from columns if (content.head.length === 0) { var sectionRow = generateSectionRow(columns, 'head'); if (sectionRow) content.head.push(sectionRow); } if (content.foot.length === 0) { var sectionRow = generateSectionRow(columns, 'foot'); if (sectionRow) content.foot.push(sectionRow); } var theme = input.settings.theme; var styles = input.styles; return { columns: columns, head: parseSection('head', content.head, columns, styles, theme, sf), body: parseSection('body', content.body, columns, styles, theme, sf), foot: parseSection('foot', content.foot, columns, styles, theme, sf), }; } function parseSection(sectionName, sectionRows, columns, styleProps, theme, scaleFactor) { var rowSpansLeftForColumn = {}; var result = sectionRows.map(function (rawRow, rowIndex) { var skippedRowForRowSpans = 0; var cells = {}; var colSpansAdded = 0; var columnSpansLeft = 0; for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) { var column = columns_1[_i]; if (rowSpansLeftForColumn[column.index] == null || rowSpansLeftForColumn[column.index].left === 0) { if (columnSpansLeft === 0) { var rawCell = void 0; if (Array.isArray(rawRow)) { rawCell = rawRow[column.index - colSpansAdded - skippedRowForRowSpans]; } else { rawCell = rawRow[column.dataKey]; } var cellInputStyles = {}; if (typeof rawCell === 'object' && !Array.isArray(rawCell)) { cellInputStyles = (rawCell === null || rawCell === void 0 ? void 0 : rawCell.styles) || {}; } var styles = cellStyles(sectionName, column, rowIndex, theme, styleProps, scaleFactor, cellInputStyles); var cell = new models_1.Cell(rawCell, styles, sectionName); // dataKey is not used internally no more but keep for // backwards compat in hooks cells[column.dataKey] = cell; cells[column.index] = cell; columnSpansLeft = cell.colSpan - 1; rowSpansLeftForColumn[column.index] = { left: cell.rowSpan - 1, times: columnSpansLeft, }; } else { columnSpansLeft--; colSpansAdded++; } } else { rowSpansLeftForColumn[column.index].left--; columnSpansLeft = rowSpansLeftForColumn[column.index].times; skippedRowForRowSpans++; } } return new models_1.Row(rawRow, rowIndex, sectionName, cells); }); return result; } function generateSectionRow(columns, section) { var sectionRow = {}; columns.forEach(function (col) { if (col.raw != null) { var title = getSectionTitle(section, col.raw); if (title != null) sectionRow[col.dataKey] = title; } }); return Object.keys(sectionRow).length > 0 ? sectionRow : null; } function getSectionTitle(section, column) { if (section === 'head') { if (typeof column === 'object') { return column.header || column.title || null; } else if (typeof column === 'string' || typeof column === 'number') { return column; } } else if (section === 'foot' && typeof column === 'object') { return column.footer; } return null; } function createColumns(columns) { return columns.map(function (input, index) { var _a, _b; var key; if (typeof input === 'object') { key = (_b = (_a = input.dataKey) !== null && _a !== void 0 ? _a : input.key) !== null && _b !== void 0 ? _b : index; } else { key = index; } return new models_1.Column(key, input, index); }); } function cellStyles(sectionName, column, rowIndex, themeName, styles, scaleFactor, cellInputStyles) { var theme = (0, config_1.getTheme)(themeName); var sectionStyles; if (sectionName === 'head') { sectionStyles = styles.headStyles; } else if (sectionName === 'body') { sectionStyles = styles.bodyStyles; } else if (sectionName === 'foot') { sectionStyles = styles.footStyles; } var otherStyles = (0, polyfills_1.assign)({}, theme.table, theme[sectionName], styles.styles, sectionStyles); var columnStyles = styles.columnStyles[column.dataKey] || styles.columnStyles[column.index] || {}; var colStyles = sectionName === 'body' ? columnStyles : {}; var rowStyles = sectionName === 'body' && rowIndex % 2 === 0 ? (0, polyfills_1.assign)({}, theme.alternateRow, styles.alternateRowStyles) : {}; var defaultStyle = (0, config_1.defaultStyles)(scaleFactor); var themeStyles = (0, polyfills_1.assign)({}, defaultStyle, otherStyles, rowStyles, colStyles); return (0, polyfills_1.assign)(themeStyles, cellInputStyles); } /***/ }), /***/ 664: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.addPage = exports.drawTable = void 0; var common_1 = __webpack_require__(420); var models_1 = __webpack_require__(260); var documentHandler_1 = __webpack_require__(744); var polyfills_1 = __webpack_require__(356); var autoTableText_1 = __webpack_require__(136); var tablePrinter_1 = __webpack_require__(224); function drawTable(jsPDFDoc, table) { var settings = table.settings; var startY = settings.startY; var margin = settings.margin; var cursor = { x: margin.left, y: startY, }; var sectionsHeight = table.getHeadHeight(table.columns) + table.getFootHeight(table.columns); var minTableBottomPos = startY + margin.bottom + sectionsHeight; if (settings.pageBreak === 'avoid') { var rows = table.body; var tableHeight = rows.reduce(function (acc, row) { return acc + row.height; }, 0); minTableBottomPos += tableHeight; } var doc = new documentHandler_1.DocHandler(jsPDFDoc); if (settings.pageBreak === 'always' || (settings.startY != null && minTableBottomPos > doc.pageSize().height)) { nextPage(doc); cursor.y = margin.top; } table.callWillDrawPageHooks(doc, cursor); var startPos = (0, polyfills_1.assign)({}, cursor); table.startPageNumber = doc.pageNumber(); if (settings.horizontalPageBreak) { // managed flow for split columns printTableWithHorizontalPageBreak(doc, table, startPos, cursor); } else { // normal flow doc.applyStyles(doc.userStyles); if (settings.showHead === 'firstPage' || settings.showHead === 'everyPage') { table.head.forEach(function (row) { return printRow(doc, table, row, cursor, table.columns); }); } doc.applyStyles(doc.userStyles); table.body.forEach(function (row, index) { var isLastRow = index === table.body.length - 1; printFullRow(doc, table, row, isLastRow, startPos, cursor, table.columns); }); doc.applyStyles(doc.userStyles); if (settings.showFoot === 'lastPage' || settings.showFoot === 'everyPage') { table.foot.forEach(function (row) { return printRow(doc, table, row, cursor, table.columns); }); } } (0, common_1.addTableBorder)(doc, table, startPos, cursor); table.callEndPageHooks(doc, cursor); table.finalY = cursor.y; jsPDFDoc.lastAutoTable = table; jsPDFDoc.previousAutoTable = table; // Deprecated if (jsPDFDoc.autoTable) jsPDFDoc.autoTable.previous = table; // Deprecated doc.applyStyles(doc.userStyles); } exports.drawTable = drawTable; function printTableWithHorizontalPageBreak(doc, table, startPos, cursor) { // calculate width of columns and render only those which can fit into page var allColumnsCanFitResult = (0, tablePrinter_1.calculateAllColumnsCanFitInPage)(doc, table); var settings = table.settings; if (settings.horizontalPageBreakBehaviour === 'afterAllRows') { allColumnsCanFitResult.forEach(function (colsAndIndexes, index) { doc.applyStyles(doc.userStyles); // add page to print next columns in new page if (index > 0) { // When adding a page here, make sure not to print the footers // because they were already printed before on this same loop addPage(doc, table, startPos, cursor, colsAndIndexes.columns, true); } else { // print head for selected columns printHead(doc, table, cursor, colsAndIndexes.columns); } // print body & footer for selected columns printBody(doc, table, startPos, cursor, colsAndIndexes.columns); printFoot(doc, table, cursor, colsAndIndexes.columns); }); } else { var lastRowIndexOfLastPage_1 = -1; var firstColumnsToFitResult = allColumnsCanFitResult[0]; var _loop_1 = function () { // Print the first columns, taking note of the last row printed var lastPrintedRowIndex = lastRowIndexOfLastPage_1; if (firstColumnsToFitResult) { doc.applyStyles(doc.userStyles); var firstColumnsToFit = firstColumnsToFitResult.columns; if (lastRowIndexOfLastPage_1 >= 0) { // When adding a page here, make sure not to print the footers // because they were already printed before on this same loop addPage(doc, table, startPos, cursor, firstColumnsToFit, true); } else { printHead(doc, table, cursor, firstColumnsToFit); } lastPrintedRowIndex = printBodyWithoutPageBreaks(doc, table, lastRowIndexOfLastPage_1 + 1, cursor, firstColumnsToFit); printFoot(doc, table, cursor, firstColumnsToFit); } // Check how many rows were printed, so that the next columns would not print more rows than that var maxNumberOfRows = lastPrintedRowIndex - lastRowIndexOfLastPage_1; // Print the next columns, never exceding maxNumberOfRows allColumnsCanFitResult.slice(1).forEach(function (colsAndIndexes) { doc.applyStyles(doc.userStyles); // When adding a page here, make sure not to print the footers // because they were already printed before on this same loop addPage(doc, table, startPos, cursor, colsAndIndexes.columns, true); printBodyWithoutPageBreaks(doc, table, lastRowIndexOfLastPage_1 + 1, cursor, colsAndIndexes.columns, maxNumberOfRows); printFoot(doc, table, cursor, colsAndIndexes.columns); }); lastRowIndexOfLastPage_1 = lastPrintedRowIndex; }; while (lastRowIndexOfLastPage_1 < table.body.length - 1) { _loop_1(); } } } function printHead(doc, table, cursor, columns) { var settings = table.settings; doc.applyStyles(doc.userStyles); if (settings.showHead === 'firstPage' || settings.showHead === 'everyPage') { table.head.forEach(function (row) { return printRow(doc, table, row, cursor, columns); }); } } function printBody(doc, table, startPos, cursor, columns) { doc.applyStyles(doc.userStyles); table.body.forEach(function (row, index) { var isLastRow = index === table.body.length - 1; printFullRow(doc, table, row, isLastRow, startPos, cursor, columns); }); } function printBodyWithoutPageBreaks(doc, table, startRowIndex, cursor, columns, maxNumberOfRows) { doc.applyStyles(doc.userStyles); maxNumberOfRows = maxNumberOfRows !== null && maxNumberOfRows !== void 0 ? maxNumberOfRows : table.body.length; var endRowIndex = Math.min(startRowIndex + maxNumberOfRows, table.body.length); var lastPrintedRowIndex = -1; table.body.slice(startRowIndex, endRowIndex).forEach(function (row, index) { var isLastRow = startRowIndex + index === table.body.length - 1; var remainingSpace = getRemainingPageSpace(doc, table, isLastRow, cursor); if (row.canEntireRowFit(remainingSpace, columns)) { printRow(doc, table, row, cursor, columns); lastPrintedRowIndex = startRowIndex + index; } }); return lastPrintedRowIndex; } function printFoot(doc, table, cursor, columns) { var settings = table.settings; doc.applyStyles(doc.userStyles); if (settings.showFoot === 'lastPage' || settings.showFoot === 'everyPage') { table.foot.forEach(function (row) { return printRow(doc, table, row, cursor, columns); }); } } function getRemainingLineCount(cell, remainingPageSpace, doc) { var lineHeight = doc.getLineHeight(cell.styles.fontSize); var vPadding = cell.padding('vertical'); var remainingLines = Math.floor((remainingPageSpace - vPadding) / lineHeight); return Math.max(0, remainingLines); } function modifyRowToFit(row, remainingPageSpace, table, doc) { var cells = {}; row.spansMultiplePages = true; row.height = 0; var rowHeight = 0; for (var _i = 0, _a = table.columns; _i < _a.length; _i++) { var column = _a[_i]; var cell = row.cells[column.index]; if (!cell) continue; if (!Array.isArray(cell.text)) { cell.text = [cell.text]; } var remainderCell = new models_1.Cell(cell.raw, cell.styles, cell.section); remainderCell = (0, polyfills_1.assign)(remainderCell, cell); remainderCell.text = []; var remainingLineCount = getRemainingLineCount(cell, remainingPageSpace, doc); if (cell.text.length > remainingLineCount) { remainderCell.text = cell.text.splice(remainingLineCount, cell.text.length); } var scaleFactor = doc.scaleFactor(); var lineHeightFactor = doc.getLineHeightFactor(); cell.contentHeight = cell.getContentHeight(scaleFactor, lineHeightFactor); if (cell.contentHeight >= remainingPageSpace) { cell.contentHeight = remainingPageSpace; remainderCell.styles.minCellHeight -= remainingPageSpace; } if (cell.contentHeight > row.height) { row.height = cell.contentHeight; } remainderCell.contentHeight = remainderCell.getContentHeight(scaleFactor, lineHeightFactor); if (remainderCell.contentHeight > rowHeight) { rowHeight = remainderCell.contentHeight; } cells[column.index] = remainderCell; } var remainderRow = new models_1.Row(row.raw, -1, row.section, cells, true); remainderRow.height = rowHeight; for (var _b = 0, _c = table.columns; _b < _c.length; _b++) { var column = _c[_b]; var remainderCell = remainderRow.cells[column.index]; if (remainderCell) { remainderCell.height = remainderRow.height; } var cell = row.cells[column.index]; if (cell) { cell.height = row.height; } } return remainderRow; } function shouldPrintOnCurrentPage(doc, row, remainingPageSpace, table) { var pageHeight = doc.pageSize().height; var margin = table.settings.margin; var marginHeight = margin.top + margin.bottom; var maxRowHeight = pageHeight - marginHeight; if (row.section === 'body') { // Should also take into account that head and foot is not // on every page with some settings maxRowHeight -= table.getHeadHeight(table.columns) + table.getFootHeight(table.columns); } var minRowHeight = row.getMinimumRowHeight(table.columns, doc); var minRowFits = minRowHeight < remainingPageSpace; if (minRowHeight > maxRowHeight) { console.error("Will not be able to print row ".concat(row.index, " correctly since it's minimum height is larger than page height")); return true; } if (!minRowFits) { return false; } var rowHasRowSpanCell = row.hasRowSpan(table.columns); var rowHigherThanPage = row.getMaxCellHeight(table.columns) > maxRowHeight; if (rowHigherThanPage) { if (rowHasRowSpanCell) { console.error("The content of row ".concat(row.index, " will not be drawn correctly since drawing rows with a height larger than the page height and has cells with rowspans is not supported.")); } return true; } if (rowHasRowSpanCell) { // Currently a new page is required whenever a rowspan row don't fit a page. return false; } if (table.settings.rowPageBreak === 'avoid') { return false; } // In all other cases print the row on current page return true; } function printFullRow(doc, table, row, isLastRow, startPos, cursor, columns) { var remainingSpace = getRemainingPageSpace(doc, table, isLastRow, cursor); if (row.canEntireRowFit(remainingSpace, columns)) { // The row fits in the current page printRow(doc, table, row, cursor, columns); } else if (shouldPrintOnCurrentPage(doc, row, remainingSpace, table)) { // The row gets split in two here, each piece in one page var remainderRow = modifyRowToFit(row, remainingSpace, table, doc); printRow(doc, table, row, cursor, columns); addPage(doc, table, startPos, cursor, columns); printFullRow(doc, table, remainderRow, isLastRow, startPos, cursor, columns); } else { // The row get printed entirelly on the next page addPage(doc, table, startPos, cursor, columns); printFullRow(doc, table, row, isLastRow, startPos, cursor, columns); } } function printRow(doc, table, row, cursor, columns) { cursor.x = table.settings.margin.left; for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) { var column = columns_1[_i]; var cell = row.cells[column.index]; if (!cell) { cursor.x += column.width; continue; } doc.applyStyles(cell.styles); cell.x = cursor.x; cell.y = cursor.y; var result = table.callCellHooks(doc, table.hooks.willDrawCell, cell, row, column, cursor); if (result === false) { cursor.x += column.width; continue; } drawCellRect(doc, cell, cursor); var textPos = cell.getTextPos(); (0, autoTableText_1.default)(cell.text, textPos.x, textPos.y, { halign: cell.styles.halign, valign: cell.styles.valign, maxWidth: Math.ceil(cell.width - cell.padding('left') - cell.padding('right')), }, doc.getDocument()); table.callCellHooks(doc, table.hooks.didDrawCell, cell, row, column, cursor); cursor.x += column.width; } cursor.y += row.height; } function drawCellRect(doc, cell, cursor) { var cellStyles = cell.styles; // https://github.com/simonbengtsson/jsPDF-AutoTable/issues/774 // TODO (v4): better solution? doc.getDocument().setFillColor(doc.getDocument().getFillColor()); if (typeof cellStyles.lineWidth === 'number') { // Draw cell background with normal borders var fillStyle = (0, common_1.getFillStyle)(cellStyles.lineWidth, cellStyles.fillColor); if (fillStyle) { doc.rect(cell.x, cursor.y, cell.width, cell.height, fillStyle); } } else if (typeof cellStyles.lineWidth === 'object') { // Draw cell background if (cellStyles.fillColor) { doc.rect(cell.x, cursor.y, cell.width, cell.height, 'F'); } // Draw cell individual borders drawCellBorders(doc, cell, cursor, cellStyles.lineWidth); } } /** * Draw all specified borders. Borders are centered on cell's edge and lengthened * to overlap with neighbours to create sharp corners. * @param doc * @param cell * @param cursor * @param fillColor * @param lineWidth */ function drawCellBorders(doc, cell, cursor, lineWidth) { var x1, y1, x2, y2; if (lineWidth.top) { x1 = cursor.x; y1 = cursor.y; x2 = cursor.x + cell.width; y2 = cursor.y; if (lineWidth.right) { x2 += 0.5 * lineWidth.right; } if (lineWidth.left) { x1 -= 0.5 * lineWidth.left; } drawLine(lineWidth.top, x1, y1, x2, y2); } if (lineWidth.bottom) { x1 = cursor.x; y1 = cursor.y + cell.height; x2 = cursor.x + cell.width; y2 = cursor.y + cell.height; if (lineWidth.right) { x2 += 0.5 * lineWidth.right; } if (lineWidth.left) { x1 -= 0.5 * lineWidth.left; } drawLine(lineWidth.bottom, x1, y1, x2, y2); } if (lineWidth.left) { x1 = cursor.x; y1 = cursor.y; x2 = cursor.x; y2 = cursor.y + cell.height; if (lineWidth.top) { y1 -= 0.5 * lineWidth.top; } if (lineWidth.bottom) { y2 += 0.5 * lineWidth.bottom; } drawLine(lineWidth.left, x1, y1, x2, y2); } if (lineWidth.right) { x1 = cursor.x + cell.width; y1 = cursor.y; x2 = cursor.x + cell.width; y2 = cursor.y + cell.height; if (lineWidth.top) { y1 -= 0.5 * lineWidth.top; } if (lineWidth.bottom) { y2 += 0.5 * lineWidth.bottom; } drawLine(lineWidth.right, x1, y1, x2, y2); } function drawLine(width, x1, y1, x2, y2) { doc.getDocument().setLineWidth(width); doc.getDocument().line(x1, y1, x2, y2, 'S'); } } function getRemainingPageSpace(doc, table, isLastRow, cursor) { var bottomContentHeight = table.settings.margin.bottom; var showFoot = table.settings.showFoot; if (showFoot === 'everyPage' || (showFoot === 'lastPage' && isLastRow)) { bottomContentHeight += table.getFootHeight(table.columns); } return doc.pageSize().height - cursor.y - bottomContentHeight; } function addPage(doc, table, startPos, cursor, columns, suppressFooter) { if (columns === void 0) { columns = []; } if (suppressFooter === void 0) { suppressFooter = false; } doc.applyStyles(doc.userStyles); if (table.settings.showFoot === 'everyPage' && !suppressFooter) { table.foot.forEach(function (row) { return printRow(doc, table, row, cursor, columns); }); } // Add user content just before adding new page ensure it will // be drawn above other things on the page table.callEndPageHooks(doc, cursor); var margin = table.settings.margin; (0, common_1.addTableBorder)(doc, table, startPos, cursor); nextPage(doc); table.pageNumber++; table.pageCount++; cursor.x = margin.left; cursor.y = margin.top; startPos.y = margin.top; // call didAddPage hooks before any content is added to the page table.callWillDrawPageHooks(doc, cursor); if (table.settings.showHead === 'everyPage') { table.head.forEach(function (row) { return printRow(doc, table, row, cursor, columns); }); doc.applyStyles(doc.userStyles); } } exports.addPage = addPage; function nextPage(doc) { var current = doc.pageNumber(); doc.setPage(current + 1); var newCurrent = doc.pageNumber(); if (newCurrent === current) { doc.addPage(); return true; } return false; } /***/ }), /***/ 224: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.calculateAllColumnsCanFitInPage = void 0; var common_1 = __webpack_require__(420); // get columns can be fit into page function getColumnsCanFitInPage(doc, table, config) { var _a; if (config === void 0) { config = {}; } // Get page width var remainingWidth = (0, common_1.getPageAvailableWidth)(doc, table); // Get column data key to repeat var repeatColumnsMap = new Map(); var colIndexes = []; var columns = []; var horizontalPageBreakRepeat = []; table.settings.horizontalPageBreakRepeat; if (Array.isArray(table.settings.horizontalPageBreakRepeat)) { horizontalPageBreakRepeat = table.settings.horizontalPageBreakRepeat; // It can be a single value of type string or number (even number: 0) } else if (typeof table.settings.horizontalPageBreakRepeat === 'string' || typeof table.settings.horizontalPageBreakRepeat === 'number') { horizontalPageBreakRepeat = [table.settings.horizontalPageBreakRepeat]; } // Code to repeat the given column in split pages horizontalPageBreakRepeat.forEach(function (field) { var col = table.columns.find(function (item) { return item.dataKey === field || item.index === field; }); if (col && !repeatColumnsMap.has(col.index)) { repeatColumnsMap.set(col.index, true); colIndexes.push(col.index); columns.push(table.columns[col.index]); remainingWidth -= col.wrappedWidth; } }); var first = true; var i = (_a = config === null || config === void 0 ? void 0 : config.start) !== null && _a !== void 0 ? _a : 0; // make sure couter is initiated outside the loop while (i < table.columns.length) { // Prevent duplicates if (repeatColumnsMap.has(i)) { i++; continue; } var colWidth = table.columns[i].wrappedWidth; // Take at least one column even if it doesn't fit if (first || remainingWidth >= colWidth) { first = false; colIndexes.push(i); columns.push(table.columns[i]); remainingWidth -= colWidth; } else { break; } i++; } return { colIndexes: colIndexes, columns: columns, lastIndex: i - 1 }; } function calculateAllColumnsCanFitInPage(doc, table) { var allResults = []; for (var i = 0; i < table.columns.length; i++) { var result = getColumnsCanFitInPage(doc, table, { start: i }); if (result.columns.length) { allResults.push(result); i = result.lastIndex; } } return allResults; } exports.calculateAllColumnsCanFitInPage = calculateAllColumnsCanFitInPage; /***/ }), /***/ 324: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.ellipsize = exports.resizeColumns = exports.calculateWidths = void 0; var common_1 = __webpack_require__(420); /** * Calculate the column widths */ function calculateWidths(doc, table) { calculate(doc, table); var resizableColumns = []; var initialTableWidth = 0; table.columns.forEach(function (column) { var customWidth = column.getMaxCustomCellWidth(table); if (customWidth) { // final column width column.width = customWidth; } else { // initial column width (will be resized) column.width = column.wrappedWidth; resizableColumns.push(column); } initialTableWidth += column.width; }); // width difference that needs to be distributed var resizeWidth = table.getWidth(doc.pageSize().width) - initialTableWidth; // first resize attempt: with respect to minReadableWidth and minWidth if (resizeWidth) { resizeWidth = resizeColumns(resizableColumns, resizeWidth, function (column) { return Math.max(column.minReadableWidth, column.minWidth); }); } // second resize attempt: ignore minReadableWidth but respect minWidth if (resizeWidth) { resizeWidth = resizeColumns(resizableColumns, resizeWidth, function (column) { return column.minWidth; }); } resizeWidth = Math.abs(resizeWidth); if (!table.settings.horizontalPageBreak && resizeWidth > 0.1 / doc.scaleFactor()) { // Table can't get smaller due to custom-width or minWidth restrictions // We can't really do much here. Up to user to for example // reduce font size, increase page size or remove custom cell widths // to allow more columns to be reduced in size resizeWidth = resizeWidth < 1 ? resizeWidth : Math.round(resizeWidth); console.warn("Of the table content, ".concat(resizeWidth, " units width could not fit page")); } applyColSpans(table); fitContent(table, doc); applyRowSpans(table); } exports.calculateWidths = calculateWidths; function calculate(doc, table) { var sf = doc.scaleFactor(); var horizontalPageBreak = table.settings.horizontalPageBreak; var availablePageWidth = (0, common_1.getPageAvailableWidth)(doc, table); table.allRows().forEach(function (row) { for (var _i = 0, _a = table.columns; _i < _a.length; _i++) { var column = _a[_i]; var cell = row.cells[column.index]; if (!cell) continue; var hooks = table.hooks.didParseCell; table.callCellHooks(doc, hooks, cell, row, column, null); var padding = cell.padding('horizontal'); cell.contentWidth = (0, common_1.getStringWidth)(cell.text, cell.styles, doc) + padding; // Using [^\S\u00A0] instead of \s ensures that we split the text on all // whitespace except non-breaking spaces (\u00A0). We need to preserve // them in the split process to ensure correct word separation and width // calculation. var longestWordWidth = (0, common_1.getStringWidth)(cell.text.join(' ').split(/[^\S\u00A0]+/), cell.styles, doc); cell.minReadableWidth = longestWordWidth + cell.padding('horizontal'); if (typeof cell.styles.cellWidth === 'number') { cell.minWidth = cell.styles.cellWidth; cell.wrappedWidth = cell.styles.cellWidth; } else if (cell.styles.cellWidth === 'wrap' || horizontalPageBreak === true) { // cell width should not be more than available page width if (cell.contentWidth > availablePageWidth) { cell.minWidth = availablePageWidth; cell.wrappedWidth = availablePageWidth; } else { cell.minWidth = cell.contentWidth; cell.wrappedWidth = cell.contentWidth; } } else { // auto var defaultMinWidth = 10 / sf; cell.minWidth = cell.styles.minCellWidth || defaultMinWidth; cell.wrappedWidth = cell.contentWidth; if (cell.minWidth > cell.wrappedWidth) { cell.wrappedWidth = cell.minWidth; } } } }); table.allRows().forEach(function (row) { for (var _i = 0, _a = table.columns; _i < _a.length; _i++) { var column = _a[_i]; var cell = row.cells[column.index]; // For now we ignore the minWidth and wrappedWidth of colspan cells when calculating colspan widths. // Could probably be improved upon however. if (cell && cell.colSpan === 1) { column.wrappedWidth = Math.max(column.wrappedWidth, cell.wrappedWidth); column.minWidth = Math.max(column.minWidth, cell.minWidth); column.minReadableWidth = Math.max(column.minReadableWidth, cell.minReadableWidth); } else { // Respect cellWidth set in columnStyles even if there is no cells for this column // or if the column only have colspan cells. Since the width of colspan cells // does not affect the width of columns, setting columnStyles cellWidth enables the // user to at least do it manually. // Note that this is not perfect for now since for example row and table styles are // not accounted for var columnStyles = table.styles.columnStyles[column.dataKey] || table.styles.columnStyles[column.index] || {}; var cellWidth = columnStyles.cellWidth || columnStyles.minCellWidth; if (cellWidth && typeof cellWidth === 'number') { column.minWidth = cellWidth; column.wrappedWidth = cellWidth; } } if (cell) { // Make sure all columns get at least min width even though width calculations are not based on them if (cell.colSpan > 1 && !column.minWidth) { column.minWidth = cell.minWidth; } if (cell.colSpan > 1 && !column.wrappedWidth) { column.wrappedWidth = cell.minWidth; } } } }); } /** * Distribute resizeWidth on passed resizable columns */ function resizeColumns(columns, resizeWidth, getMinWidth) { var initialResizeWidth = resizeWidth; var sumWrappedWidth = columns.reduce(function (acc, column) { return acc + column.wrappedWidth; }, 0); for (var i = 0; i < columns.length; i++) { var column = columns[i]; var ratio = column.wrappedWidth / sumWrappedWidth; var suggestedChange = initialResizeWidth * ratio; var suggestedWidth = column.width + suggestedChange; var minWidth = getMinWidth(column); var newWidth = suggestedWidth < minWidth ? minWidth : suggestedWidth; resizeWidth -= newWidth - column.width; column.width = newWidth; } resizeWidth = Math.round(resizeWidth * 1e10) / 1e10; // Run the resizer again if there's remaining width needs // to be distributed and there're columns that can be resized if (resizeWidth) { var resizableColumns = columns.filter(function (column) { return resizeWidth < 0 ? column.width > getMinWidth(column) // check if column can shrink : true; // check if column can grow }); if (resizableColumns.length) { resizeWidth = resizeColumns(resizableColumns, resizeWidth, getMinWidth); } } return resizeWidth; } exports.resizeColumns = resizeColumns; function applyRowSpans(table) { var rowSpanCells = {}; var colRowSpansLeft = 1; var all = table.allRows(); for (var rowIndex = 0; rowIndex < all.length; rowIndex++) { var row = all[rowIndex]; for (var _i = 0, _a = table.columns; _i < _a.length; _i++) { var column = _a[_i]; var data = rowSpanCells[column.index]; if (colRowSpansLeft > 1) { colRowSpansLeft--; delete row.cells[column.index]; } else if (data) { data.cell.height += row.height; colRowSpansLeft = data.cell.colSpan; delete row.cells[column.index]; data.left--; if (data.left <= 1) { delete rowSpanCells[column.index]; } } else { var cell = row.cells[column.index]; if (!cell) { continue; } cell.height = row.height; if (cell.rowSpan > 1) { var remaining = all.length - rowIndex; var left = cell.rowSpan > remaining ? remaining : cell.rowSpan; rowSpanCells[column.index] = { cell: cell, left: left, row: row }; } } } } } function applyColSpans(table) { var all = table.allRows(); for (var rowIndex = 0; rowIndex < all.length; rowIndex++) { var row = all[rowIndex]; var colSpanCell = null; var combinedColSpanWidth = 0; var colSpansLeft = 0; for (var columnIndex = 0; columnIndex < table.columns.length; columnIndex++) { var column = table.columns[columnIndex]; // Width and colspan colSpansLeft -= 1; if (colSpansLeft > 1 && table.columns[columnIndex + 1]) { combinedColSpanWidth += column.width; delete row.cells[column.index]; } else if (colSpanCell) { var cell = colSpanCell; delete row.cells[column.index]; colSpanCell = null; cell.width = column.width + combinedColSpanWidth; } else { var cell = row.cells[column.index]; if (!cell) continue; colSpansLeft = cell.colSpan; combinedColSpanWidth = 0; if (cell.colSpan > 1) { colSpanCell = cell; combinedColSpanWidth += column.width; continue; } cell.width = column.width + combinedColSpanWidth; } } } } function fitContent(table, doc) { var rowSpanHeight = { count: 0, height: 0 }; for (var _i = 0, _a = table.allRows(); _i < _a.length; _i++) { var row = _a[_i]; for (var _b = 0, _c = table.columns; _b < _c.length; _b++) { var column = _c[_b]; var cell = row.cells[column.index]; if (!cell) continue; doc.applyStyles(cell.styles, true); var textSpace = cell.width - cell.padding('horizontal'); if (cell.styles.overflow === 'linebreak') { // Add one pt to textSpace to fix rounding error cell.text = doc.splitTextToSize(cell.text, textSpace + 1 / doc.scaleFactor(), { fontSize: cell.styles.fontSize }); } else if (cell.styles.overflow === 'ellipsize') { cell.text = ellipsize(cell.text, textSpace, cell.styles, doc, '...'); } else if (cell.styles.overflow === 'hidden') { cell.text = ellipsize(cell.text, textSpace, cell.styles, doc, ''); } else if (typeof cell.styles.overflow === 'function') { var result = cell.styles.overflow(cell.text, textSpace); if (typeof result === 'string') { cell.text = [result]; } else { cell.text = result; } } cell.contentHeight = cell.getContentHeight(doc.scaleFactor(), doc.getLineHeightFactor()); var realContentHeight = cell.contentHeight / cell.rowSpan; if (cell.rowSpan > 1 && rowSpanHeight.count * rowSpanHeight.height < realContentHeight * cell.rowSpan) { rowSpanHeight = { height: realContentHeight, count: cell.rowSpan }; } else if (rowSpanHeight && rowSpanHeight.count > 0) { if (rowSpanHeight.height > realContentHeight) { realContentHeight = rowSpanHeight.height; } } if (realContentHeight > row.height) { row.height = realContentHeight; } } rowSpanHeight.count--; } } function ellipsize(text, width, styles, doc, overflow) { return text.map(function (str) { return ellipsizeStr(str, width, styles, doc, overflow); }); } exports.ellipsize = ellipsize; function ellipsizeStr(text, width, styles, doc, overflow) { var precision = 10000 * doc.scaleFactor(); width = Math.ceil(width * precision) / precision; if (width >= (0, common_1.getStringWidth)(text, styles, doc)) { return text; } while (width < (0, common_1.getStringWidth)(text + overflow, styles, doc)) { if (text.length <= 1) { break; } text = text.substring(0, text.length - 1); } return text.trim() + overflow; } /***/ }), /***/ 964: /***/ (function(module) { if(typeof __WEBPACK_EXTERNAL_MODULE__964__ === 'undefined') { var e = new Error("Cannot find module 'undefined'"); e.code = 'MODULE_NOT_FOUND'; throw e; } module.exports = __WEBPACK_EXTERNAL_MODULE__964__; /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __nested_webpack_require_95387__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __nested_webpack_require_95387__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ var __nested_webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. !function() { var exports = __nested_webpack_exports__; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Cell = exports.Column = exports.Row = exports.Table = exports.CellHookData = exports.__drawTable = exports.__createTable = exports.applyPlugin = void 0; var applyPlugin_1 = __nested_webpack_require_95387__(340); var inputParser_1 = __nested_webpack_require_95387__(776); var tableDrawer_1 = __nested_webpack_require_95387__(664); var tableCalculator_1 = __nested_webpack_require_95387__(972); var models_1 = __nested_webpack_require_95387__(260); Object.defineProperty(exports, "Table", ({ enumerable: true, get: function () { return models_1.Table; } })); var HookData_1 = __nested_webpack_require_95387__(172); Object.defineProperty(exports, "CellHookData", ({ enumerable: true, get: function () { return HookData_1.CellHookData; } })); var models_2 = __nested_webpack_require_95387__(260); Object.defineProperty(exports, "Cell", ({ enumerable: true, get: function () { return models_2.Cell; } })); Object.defineProperty(exports, "Column", ({ enumerable: true, get: function () { return models_2.Column; } })); Object.defineProperty(exports, "Row", ({ enumerable: true, get: function () { return models_2.Row; } })); // export { applyPlugin } didn't export applyPlugin // to index.d.ts for some reason function applyPlugin(jsPDF) { (0, applyPlugin_1.default)(jsPDF); } exports.applyPlugin = applyPlugin; function autoTable(d, options) { var input = (0, inputParser_1.parseInput)(d, options); var table = (0, tableCalculator_1.createTable)(d, input); (0, tableDrawer_1.drawTable)(d, table); } // Experimental export function __createTable(d, options) { var input = (0, inputParser_1.parseInput)(d, options); return (0, tableCalculator_1.createTable)(d, input); } exports.__createTable = __createTable; function __drawTable(d, table) { (0, tableDrawer_1.drawTable)(d, table); } exports.__drawTable = __drawTable; try { // eslint-disable-next-line @typescript-eslint/no-var-requires var jsPDF = __nested_webpack_require_95387__(964); // Webpack imported jspdf instead of jsPDF for some reason // while it seemed to work everywhere else. if (jsPDF.jsPDF) jsPDF = jsPDF.jsPDF; applyPlugin(jsPDF); } catch (error) { // Importing jspdf in nodejs environments does not work as of jspdf // 1.5.3 so we need to silence potential errors to support using for example // the nodejs jspdf dist files with the exported applyPlugin } exports["default"] = autoTable; }(); /******/ return __nested_webpack_exports__; /******/ })() ; }); /***/ }) }]); //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoianMvdmVuZG9ycy1ub2RlX21vZHVsZXNfZ29wZF9pbmRleF9qcy1ub2RlX21vZHVsZXNfaGFzLXN5bWJvbHNfaW5kZXhfanMtbm9kZV9tb2R1bGVzX2hhc293bl9pbmRlLWRlMTg1Yy52b2x1bnRlZXJhcGkuMjM3ZjI0Y2I0Mzg2ZjAyMGI2MzkuYnVuZGxlLmpzIiwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFhOztBQUViLFdBQVcsa0JBQWtCO0FBQzdCOzs7Ozs7Ozs7Ozs7QUNIYTs7QUFFYixXQUFXLGFBQWE7QUFDeEIsWUFBWSxtQkFBTyxDQUFDLGtEQUFROztBQUU1QjtBQUNBO0FBQ0E7QUFDQSxHQUFHO0FBQ0g7QUFDQTtBQUNBO0FBQ0E7O0FBRUE7Ozs7Ozs7Ozs7OztBQ2RhOztBQUViO0FBQ0Esb0JBQW9CLG1CQUFPLENBQUMsMkRBQVM7O0FBRXJDLFdBQVcsYUFBYTtBQUN4QjtBQUNBLHlDQUF5QztBQUN6QyxxQ0FBcUM7QUFDckMsOENBQThDO0FBQzlDLDBDQUEwQzs7QUFFMUM7QUFDQTs7Ozs7Ozs7Ozs7O0FDYmE7O0FBRWIsV0FBVyxtQkFBbUI7QUFDOUI7QUFDQTtBQUNBLDJGQUEyRjtBQUMzRiw0Q0FBNEM7O0FBRTVDLGNBQWMsMkJBQTJCO0FBQ3pDO0FBQ0E7QUFDQTtBQUNBLGdDQUFnQzs7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gICAgICAgIH0gZmluYWxseSB7XG4gICAgICAgICAgaWYgKGhhc0Vycm9yKVxuICAgICAgICAgICAgcmV2b2tlU2NvcGUoc2NvcGUpO1xuICAgICAgICAgIGVsc2VcbiAgICAgICAgICAgIGxlYXZlU2NvcGUoc2NvcGUpO1xuICAgICAgICB9XG4gICAgICAgIHVzZVBhdGNoZXNJblNjb3BlKHNjb3BlLCBwYXRjaExpc3RlbmVyKTtcbiAgICAgICAgcmV0dXJuIHByb2Nlc3NSZXN1bHQocmVzdWx0LCBzY29wZSk7XG4gICAgICB9IGVsc2UgaWYgKCFiYXNlIHx8ICFpc09iamVjdGlzaChiYXNlKSkge1xuICAgICAgICByZXN1bHQgPSByZWNpcGUoYmFzZSk7XG4gICAgICAgIGlmIChyZXN1bHQgPT09IHZvaWQgMClcbiAgICAgICAgICByZXN1bHQgPSBiYXNlO1xuICAgICAgICBpZiAocmVzdWx0ID09PSBOT1RISU5HKVxuICAgICAgICAgIHJlc3VsdCA9IHZvaWQgMDtcbiAgICAgICAgaWYgKHRoaXMuYXV0b0ZyZWV6ZV8pXG4gICAgICAgICAgZnJlZXplKHJlc3VsdCwgdHJ1ZSk7XG4gICAgICAgIGlmIChwYXRjaExpc3RlbmVyKSB7XG4gICAgICAgICAgY29uc3QgcCA9IFtdO1xuICAgICAgICAgIGNvbnN0IGlwID0gW107XG4gICAgICAgICAgZ2V0UGx1Z2luKFBsdWdpblBhdGNoZXMpLmdlbmVyYXRlUmVwbGFjZW1lbnRQYXRjaGVzXyhiYXNlLCByZXN1bHQsIHtcbiAgICAgICAgICAgIHBhdGNoZXNfOiBwLFxuICAgICAgICAgICAgaW52ZXJzZVBhdGNoZXNfOiBpcFxuICAgICAgICAgIH0pO1xuICAgICAgICAgIHBhdGNoTGlzdGVuZXIocCwgaXApO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgICB9IGVsc2VcbiAgICAgICAgZGllKDEsIGJhc2UpO1xuICAgIH07XG4gIC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IHAgPT09IFBST1RPVFlQRSlcbiAgICAgICAgICBkaWUoZXJyb3JPZmZzZXQgKyAzKTtcbiAgICAgICAgYmFzZSA9IGdldChiYXNlLCBwKTtcbiAgICAgICAgaWYgKCFpc09iamVjdGlzaChiYXNlKSlcbiAgICAgICAgICBkaWUoZXJyb3JPZmZzZXQgKyAyLCBwYXRoLmpvaW4oXCIvXCIpKTtcbiAgICAgIH1cbiAgICAgIGNvbnN0IHR5cGUgPSBnZXRBcmNodHlwZShiYXNlKTtcbiAgICAgIGNvbnN0IHZhbHVlID0gZGVlcENsb25lUGF0Y2hWYWx1ZShwYXRjaC52YWx1ZSk7XG4gICAgICBjb25zdCBrZXkgPSBwYXRoW3BhdGgubGVuZ3RoIC0gMV07XG4gICAgICBzd2l0Y2ggKG9wKSB7XG4gICAgICAgIGNhc2UgUkVQTEFDRTpcbiAgICAgICAgICBzd2l0Y2ggKHR5cGUpIHtcbiAgICAgICAgICAgIGNhc2UgMiAvKiBNYXAgKi86XG4gICAgICAgICAgICAgIHJldHVybiBiYXNlLnNldChrZXksIHZhbHVlKTtcbiAgICAgICAgICAgIGNhc2UgMyAvKiBTZXQgKi86XG4gICAgICAgICAgICAgIGRpZShlcnJvck9mZnNldCk7XG4gICAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgICByZXR1cm4gYmFzZVtrZXldID0gdmFsdWU7XG4gICAgICAgICAgfVxuICAgICAgICBjYXNlIEFERDpcbiAgICAgICAgICBzd2l0Y2ggKHR5cGUpIHtcbiAgICAgICAgICAgIGNhc2UgMSAvKiBBcnJheSAqLzpcbiAgICAgICAgICAgICAgcmV0dXJuIGtleSA9PT0gXCItXCIgPyBiYXNlLnB1c2godmFsdWUpIDogYmFzZS5zcGxpY2Uoa2V5LCAwLCB2YWx1ZSk7XG4gICAgICAgICAgICBjYXNlIDIgLyogTWFwICovOlxuICAgICAgICAgICAgICByZXR1cm4gYmFzZS5zZXQoa2V5LCB2YWx1ZSk7XG4gICAgICAgICAgICBjYXNlIDMgLyogU2V0ICovOlxuICAgICAgICAgICAgICByZXR1cm4gYmFzZS5hZGQodmFsdWUpO1xuICAgICAgICAgICAgZGVmYXVsdDpcbiAgICAgICAgICAgICAgcmV0dXJuIGJhc2Vba2V5XSA9IHZhbHVlO1xuICAgICAgICAgIH1cbiAgICAgICAgY2FzZSBSRU1PVkU6XG4gICAgICAgICAgc3dpdGNoICh0eXBlKSB7XG4gICAgICAgICAgICBjYXNlIDEgLyogQXJyYXkgKi86XG4gICAgICAgICAgICAgIHJldHVybiBiYXNlLnNwbGljZShrZXksIDEpO1xuICAgICAgICAgICAgY2FzZSAyIC8qIE1hcCAqLzpcbiAgICAgICAgICAgICAgcmV0dXJuIGJhc2UuZGVsZXRlKGtleSk7XG4gICAgICAgICAgICBjYXNlIDMgLyogU2V0ICovOlxuICAgICAgICAgICAgICByZXR1cm4gYmFzZS5kZWxldGUocGF0Y2gudmFsdWUpO1xuICAgICAgICAgICAgZGVmYXVsdDpcbiAgICAgICAgICAgICAgcmV0dXJuIGRlbGV0ZSBiYXNlW2tleV07XG4gICAgICAgICAgfVxuICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgIGRpZShlcnJvck9mZnNldCArIDEsIG9wKTtcbiAgICAgIH1cbiAgICB9KTtcbiAgICByZXR1cm4gZHJhZnQ7XG4gIH1cbiAgZnVuY3Rpb24gZGVlcENsb25lUGF0Y2hWYWx1ZShvYmopIHtcbiAgICBpZiAoIWlzRHJhZnRhYmxlKG9iaikpXG4gICAgICByZXR1cm4gb2JqO1xuICAgIGlmIChpc0FycmF5KG9iaikpXG4gICAgICByZXR1cm4gb2JqLm1hcChkZWVwQ2xvbmVQYXRjaFZhbHVlKTtcbiAgICBpZiAoaXNNYXAob2JqKSlcbiAgICAgIHJldHVybiBuZXcgTWFwKFxuICAgICAgICBBcnJheS5mcm9tKG9iai5lbnRyaWVzKCkpLm1hcCgoW2ssIHZdKSA9PiBbaywgZGVlcENsb25lUGF0Y2hWYWx1ZSh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h0OiAoKSA9PiB7XG4gICAgICAgICAgY29uc3QgciA9IGl0ZXJhdG9yLm5leHQoKTtcbiAgICAgICAgICBpZiAoci5kb25lKVxuICAgICAgICAgICAgcmV0dXJuIHI7XG4gICAgICAgICAgY29uc3QgdmFsdWUgPSB0aGlzLmdldChyLnZhbHVlKTtcbiAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgZG9uZTogZmFsc2UsXG4gICAgICAgICAgICB2YWx1ZVxuICAgICAgICAgIH07XG4gICAgICAgIH1cbiAgICAgIH07XG4gICAgfVxuICAgIGVudHJpZXMoKSB7XG4gICAgICBjb25zdCBpdGVyYXRvciA9IHRoaXMua2V5cygpO1xuICAgICAgcmV0dXJuIHtcbiAgICAgICAgW1N5bWJvbC5pdGVyYXRvcl06ICgpID0+IHRoaXMuZW50cmllcygpLFxuICAgICAgICBuZXh0OiAoKSA9PiB7XG4gICAgICAgICAgY29uc3QgciA9IGl0ZXJhdG9yLm5leHQoKTtcbiAgICAgICAgICBpZiAoci5kb25lKVxuICAgICAgICAgICAgcmV0dXJuIHI7XG4gICAgICAgICAgY29uc3QgdmFsdWUgPSB0aGlzLmdldChyLnZhbHVlKTtcbiAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgZG9uZTogZmFsc2UsXG4gICAgICAgICAgICB2YWx1ZTogW3IudmFsdWUsIHZhbHVlXVxuICAgICAgICAgIH07XG4gICAgICAgIH1cbiAgICAgIH07XG4gICAgfVxuICAgIFsoRFJBRlRfU1RBVEUsIFN5bWJvbC5pdGVyYXRvcildKCkge1xuICAgICAgcmV0dXJuIHRoaXMuZW50cmllcygpO1xuICAgIH1cbiAgfVxuICBmdW5jdGlvbiBwcm94eU1hcF8odGFyZ2V0LCBwYXJlbnQpIHtcbiAgICBjb25zdCBtYXAgPSBuZXcgRHJhZnRNYXAodGFyZ2V0LCBwYXJlbnQpO1xuICAgIHJldHVybiBbbWFwLCBtYXBbRFJBRlRfU1RBVEVdXTtcbiAgfVxuICBm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R1cm4ge1xuICAgICAgICAgICAgICAgIHRvcDogdmFsdWVbMF0sXG4gICAgICAgICAgICAgICAgcmlnaHQ6IHZhbHVlWzFdLFxuICAgICAgICAgICAgICAgIGJvdHRvbTogdmFsdWVbMl0sXG4gICAgICAgICAgICAgICAgbGVmdDogdmFsdWVbM10sXG4gICAgICAgICAgICB9O1xuICAgICAgICB9XG4gICAgICAgIGVsc2UgaWYgKHZhbHVlLmxlbmd0aCA9PT0gMykge1xuICAgICAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgICAgICB0b3A6IHZhbHVlWzBdLFxuICAgICAgICAgICAgICAgIHJpZ2h0OiB2YWx1ZVsxXSxcbiAgICAgICAgICAgICAgICBib3R0b206IHZhbHVlWzJdLFxuICAgICAgICAgICAgICAgIGxlZnQ6IHZhbHVlWzFdLFxuICAgICAgICAgICAgfTtcbiAgICAgICAgfVxuICAgICAgICBlbHNlIGlmICh2YWx1ZS5sZW5ndGggPT09IDIpIHtcbiAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgICAgdG9wOiB2YWx1ZVswXSxcbiAgICAgICAgICAgICAgICByaWdodDogdmFsdWVbMV0sXG4gICAgICAgICAgICAgICAgYm90dG9tOiB2YWx1ZVswXSxcbiAgICAgICAgICAgICAgICBsZWZ0OiB2YWx1ZVsxXSxcbiAgICAgICAgICAgIH07XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSBpZiAodmFsdWUubGVuZ3RoID09PSAxKSB7XG4gICAgICAgICAgICB2YWx1ZSA9IHZhbHVlWzBdO1xuICAgICAgICB9XG4gICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgdmFsdWUgPSBkZWZhdWx0VmFsdWU7XG4gICAgICAgIH1cbiAgICB9XG4gICAgaWYgKHR5cGVvZiB2YWx1ZSA9PT0gJ29iamVjdCcpIHtcbiAgICAgICAgaWYgKHR5cGVvZiB2YWx1ZS52ZXJ0aWNhbCA9PT0gJ251bWJlcicpIHtcbiAgICAgICAgIC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ICAgICAgdGFibGU6IHsgZmlsbENvbG9yOiAyNTUsIHRleHRDb2xvcjogODAsIGZvbnRTdHlsZTogJ25vcm1hbCcgfSxcbiAgICAgICAgICAgIGhlYWQ6IHsgdGV4dENvbG9yOiAyNTUsIGZpbGxDb2xvcjogWzQxLCAxMjgsIDE4NV0sIGZvbnRTdHlsZTogJ2JvbGQnIH0sXG4gICAgICAgICAgICBib2R5OiB7fSxcbiAgICAgICAgICAgIGZvb3Q6IHsgdGV4dENvbG9yOiAyNTUsIGZpbGxDb2xvcjogWzQxLCAxMjgsIDE4NV0sIGZvbnRTdHlsZTogJ2JvbGQnIH0sXG4gICAgICAgICAgICBhbHRlcm5hdGVSb3c6IHsgZmlsbENvbG9yOiAyNDUgfSxcbiAgICAgICAgfSxcbiAgICAgICAgZ3JpZDoge1xuICAgICAgICAgICAgdGFibGU6IHtcbiAgICAgICAgICAgICAgICBmaWxsQ29sb3I6IDI1NSxcbiAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IDgwLFxuICAgICAgICAgICAgICAgIGZvbnRTdHlsZTogJ25vcm1hbCcsXG4gICAgICAgICAgICAgICAgbGluZVdpZHRoOiAwLjEsXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgaGVhZDoge1xuICAgICAgICAgICAgICAgIHRleHRDb2xvcjogMjU1LFxuICAgICAgICAgICAgICAgIGZpbGxDb2xvcjogWzI2LCAxODgsIDE1Nl0sXG4gICAgICAgICAgICAgICAgZm9udFN0eWxlOiAnYm9sZCcsXG4gICAgICAgICAgICAgICAgbGluZVdpZHRoOiAwLFxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIGJvZHk6IHt9LFxuICAgICAgICAgICAgZm9vdDoge1xuICAgICAgICAgICAgICAgIHRleHRDb2xvcjogMjU1LFxuICAgICAgICAgICAgICAgIGZpbGxDb2xvcjogWzI2LCAxODgsIDE1Nl0sXG4gICAgICAgICAgICAgICAgZm9udFN0eWxlOiAnYm9sZCcsXG4gICAgICAgICAg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ICAgdGhpcy5qc1BERkRvY3VtZW50ID0ganNQREZEb2N1bWVudDtcbiAgICAgICAgdGhpcy51c2VyU3R5bGVzID0ge1xuICAgICAgICAgICAgLy8gQmxhY2sgZm9yIHZlcnNpb25zIG9mIGpzcGRmIHdpdGhvdXQgZ2V0VGV4dENvbG9yXG4gICAgICAgICAgICB0ZXh0Q29sb3I6IGpzUERGRG9jdW1lbnQuZ2V0VGV4dENvbG9yXG4gICAgICAgICAgICAgICAgPyB0aGlzLmpzUERGRG9jdW1lbnQuZ2V0VGV4dENvbG9yKClcbiAgICAgICAgICAgICAgICA6IDAsXG4gICAgICAgICAgICBmb250U2l6ZToganNQREZEb2N1bWVudC5pbnRlcm5hbC5nZXRGb250U2l6ZSgpLFxuICAgICAgICAgICAgZm9udFN0eWxlOiBqc1BERkRvY3VtZW50LmludGVybmFsLmdldEZvbnQoKS5mb250U3R5bGUsXG4gICAgICAgICAgICBmb250OiBqc1BERkRvY3VtZW50LmludGVybmFsLmdldEZvbnQoKS5mb250TmFtZSxcbiAgICAgICAgICAgIC8vIDAgZm9yIHZlcnNpb25zIG9mIGpzcGRmIHdpdGhvdXQgZ2V0TGluZVdpZHRoXG4gICAgICAgICAgICBsaW5lV2lkdGg6IGpzUERGRG9jdW1lbnQuZ2V0TGluZVdpZHRoXG4gICAgICAgICAgICAgICAgPyB0aGlzLmpzUERGRG9jdW1lbnQuZ2V0TGluZVdpZHRoKClcbiAgICAgICAgICAgICAgICA6IDAsXG4gICAgICAgICAgICAvLyBCbGFjayBmb3IgdmVyc2lvbnMgb2YganNwZGYgd2l0aG91dCBnZXREcmF3Q29sb3JcbiAgICAgICAgICAgIGxpbmVDb2xvcjoganNQREZEb2N1bWVudC5nZXREcmF3Q29sb3JcbiAgICAgICAgICAgICAgICA/IHRoaXMuanNQREZEb2N1bWVudC5nZXREcmF3Q29sb3IoKVxuICAgICAgICAgICAgICAgIDogMCxcbiAgICAgICAgfTtcbiAgICB9XG4gICAgRG9jSGFuZGxlci5zZXREZWZhdWx0cyA9IGZ1bmN0aW9uIChkZWZhdWx0cywgZG9jKSB7XG4gICAgICAgIGlmIChkb2MgPT09IHZvaWQgMCkgeyBkb2MgPSBudWxsOyB9XG4gICAgICAgIGlmIChkb2MpIHtcbiAgICAgICAgICAgIGRvYy5fX2F1dG9UYWJsZURvY3VtZW50RGVmYXVsdHMgPSBkZWZhdWx0cztcbiAgICAgICAgfVxuICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgIGdsb2JhbERlZmF1bHRzID0gZGVmYXVsdHM7XG4gICAgICAgIH1cbiAgICB9O1xuICAgIERvY0hhbmRsZXIudW5pZnlDb2xvciA9IGZ1bmN0aW9uIChjKSB7XG4gICAgICAgIGlmIChBcnJheS5pc0FycmF5KGMpKSB7XG4gICAgICAgICAgICByZXR1cm4gYztcbiAgICAgICAgfVxuICAgICAgICBlbHNlIGlmICh0eXBlb2YgYyA9PT0gJ251bWJlcicpIHtcbiAgICAgICAgICAgIHJldHVybiBbYywgYywgY107XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSBpZiAodHlwZW9mIGMgPT09ICdzdHJpbmcnKSB7XG4gICAgICAgICAgICByZXR1cm4gW2NdO1xuICAgICAgICB9XG4gICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIG51bGw7XG4gICAgICAgIH1cbiAgICB9O1xuICAgIERvY0hhbmRsZXIucHJvdG90eXBlLmFwcGx5U3R5bGVzID0gZnVuY3Rpb24gKHN0eWxlcywgZm9udE9ubHkpIHtcbiAgICAgICAgLy8gRm9udCBzdHlsZSBuZWVkcyB0byBiZSBhcHBsaWVkIGJlZm9yZSBmb250XG4gICAgICAgIC8vIGh0dHBzOi8vZ2l0aHViLmNvbS9zaW1vbmJlbmd0c3Nvbi9qc1BERi1BdXRvVGFibGUvaXNzdWVzLzYzMlxuICAgICAgICB2YXIgX2EsIF9iLCBfYztcbiAgICAgICAgaWYgKGZvbnRPbmx5ID09PSB2b2lkIDApIHsgZm9udE9ubHkgPSBmYWxzZTsgfVxuICAgICAgICBpZiAoc3R5bGVzLmZvbnRTdHlsZSlcbiAgICAgICAgICAgIHRoaXMuanNQREZEb2N1bWVudC5zZXRGb250U3R5bGUgJiZcbiAgICAgICAgICAgICAgICB0aGlzLmpzUERGRG9jdW1lbnQuc2V0Rm9udFN0eWxlKHN0eWxlcy5mb250U3R5bGUpO1xuICAgICAgICB2YXIgX2QgPSB0aGlzLmpzUERGRG9jdW1lbnQuaW50ZXJuYWwuZ2V0Rm9udCgpLCBmb250U3R5bGUgPSBfZC5mb250U3R5bGUsIGZvbnROYW1lID0gX2QuZm9udE5hbWU7XG4gICAgICAgIGlmIChzdHlsZXMuZm9udClcbiAgICAgICAgICAgIGZvbnROYW1lID0gc3R5bGVzLmZvbnQ7XG4gICAgICAgIGlmIChzdHlsZXMuZm9udFN0eWxlKSB7XG4gICAgICAgICAgICBmb250U3R5bGUgPSBzdHlsZXMuZm9udFN0eWxlO1xuICAgICAgICAgICAgdmFyIGF2YWlsYWJsZUZvbnRTdHlsZXMgPSB0aGlzLmdldEZvbnRMaXN0KClbZm9udE5hbWVdO1xuICAgICAgICAgICAgaWYgKGF2YWlsYWJsZUZvbnRTdHlsZXMgJiZcbiAgICAgICAgICAgICAgICBhdmFpbGFibGVGb250U3R5bGVzLmluZGV4T2YoZm9udFN0eWxlKSA9PT0gLTEpIHtcbiAgICAgICAgICAgICAgICAvLyBDb21tb24gaXNzdWUgd2FzIHRoYXQgdGhlIGRlZmF1bHQgYm9sZCBpbiBoZWFkZXJzXG4gICAgICAgICAgICAgICAgLy8gbWFkZSBjdXN0b20gZm9udHMgbm90IHdvcmsuIEZvciBleGFtcGxlOlxuICAgICAgICAgICAgICAgIC8vIGh0dHBzOi8vZ2l0aHViLmNvbS9zaW1vbmJlbmd0c3Nvbi9qc1BERi1BdXRvVGFibGUvaXNzdWVzLzY1M1xuICAgICAgICAgICAgICAgIHRoaXMuanNQREZEb2N1bWVudC5zZXRGb250U3R5bGUgJiZcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5qc1BERkRvY3VtZW50LnNldEZvbnRTdHlsZShhdmFpbGFibGVGb250U3R5bGVzWzBdKTtcbiAgICAgICAgICAgICAgICBmb250U3R5bGUgPSBhdmFpbGFibGVGb250U3R5bGVzWzBdO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHRoaXMuanNQREZEb2N1bWVudC5zZXRGb250KGZvbnROYW1lLCBmb250U3R5bGUpO1xuICAgICAgICBpZiAoc3R5bGVzLmZvbnRTaXplKVxuICAgICAgICAgICAgdGhpcy5qc1BERkRvY3VtZW50LnNldEZvbnRTaXplKHN0eWxlcy5mb250U2l6ZSk7XG4gICAgICAgIGlmIChmb250T25seSkge1xuICAgICAgICAgICAgcmV0dXJuOyAvLyBQZXJmb3JtYW5jZSBpbXByb3ZlbWVudFxuICAgICAgICB9XG4gICAgICAgIHZhciBjb2xvciA9IERvY0hhbmRsZXIudW5pZnlDb2xvcihzdHlsZXMuZmlsbENvbG9yKTtcbiAgICAgICAgaWYgKGNvbG9yKVxuICAgICAgICAgICAgKF9hID0gdGhpcy5qc1BERkRvY3VtZW50KS5zZXRGaWxsQ29sb3IuYXBwbHkoX2EsIGNvbG9yKTtcbiAgICAgICAgY29sb3IgPSBEb2NIYW5kbGVyLnVuaWZ5Q29sb3Ioc3R5bGVzLnRleHRDb2xvcik7XG4gICAgICAgIGlmIChjb2xvcilcbiAgICAgICAgICAgIChfYiA9IHRoaXMuanNQREZEb2N1bWVudCkuc2V0VGV4dENvbG9yLmFwcGx5KF9iLCBjb2xvcik7XG4gICAgICAgIGNvbG9yID0gRG9jSGFuZGxlci51bmlmeUNvbG9yKHN0eWxlcy5saW5lQ29sb3IpO1xuICAgICAgICBpZiAoY29sb3IpXG4gICAgICAgICAgICAoX2MgPSB0aGlzLmpzUERGRG9jdW1lbnQpLnNldERyYXdDb2xvci5hcHBseShfYywgY29sb3IpO1xuICAgICAgICBpZiAodHlwZW9mIHN0eWxl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0LmtleXMoZmlyc3RSb3cpXG4gICAgICAgIC5maWx0ZXIoZnVuY3Rpb24gKGtleSkgeyByZXR1cm4ga2V5ICE9PSAnX2VsZW1lbnQnOyB9KVxuICAgICAgICAuZm9yRWFjaChmdW5jdGlvbiAoa2V5KSB7XG4gICAgICAgIHZhciBjb2xTcGFuID0gMTtcbiAgICAgICAgdmFyIGlucHV0O1xuICAgICAgICBpZiAoQXJyYXkuaXNBcnJheShmaXJzdFJvdykpIHtcbiAgICAgICAgICAgIGlucHV0ID0gZmlyc3RSb3dbcGFyc2VJbnQoa2V5KV07XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICBpbnB1dCA9IGZpcnN0Um93W2tleV07XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHR5cGVvZiBpbnB1dCA9PT0gJ29iamVjdCcgJiYgIUFycmF5LmlzQXJyYXkoaW5wdXQpKSB7XG4gICAgICAgICAgICBjb2xTcGFuID0gKGlucHV0ID09PSBudWxsIHx8IGlucHV0ID09PSB2b2lkIDAgPyB2b2lkIDAgOiBpbnB1dC5jb2xTcGFuKSB8fCAxO1xuICAgICAgICB9XG4gICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgY29sU3BhbjsgaSsrKSB7XG4gICAgICAgICAgICB2YXIgaWQgPSB2b2lkIDA7XG4gICAgICAgICAgICBpZiAoQXJyYXkuaXNBcnJheShmaXJzdFJvdykpIHtcbiAgICAgICAgICAgICAgICBpZCA9IHJlc3VsdC5sZW5ndGg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICBpZCA9IGtleSArIChpID4gMCA/IFwiX1wiLmNvbmNhdChpKSA6ICcnKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciByb3dSZXN1bHQgPSB7IGRhdGFLZXk6IGlkIH07XG4gICAgICAgICAgICByZXN1bHQucHVzaChyb3dSZXN1bHQpO1xuICAgICAgICB9XG4gICA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AgICAgICAgICAgZG9jLmFwcGx5U3R5bGVzKGRvYy51c2VyU3R5bGVzKTtcbiAgICAgICAgICAgICAgICBpZiAob3B0aW9ucy5hZnRlclBhZ2VDb250ZW50KVxuICAgICAgICAgICAgICAgICAgICBvcHRpb25zLmFmdGVyUGFnZUNvbnRlbnQoZGF0YSk7XG4gICAgICAgICAgICAgICAgZG9jLmFwcGx5U3R5bGVzKGRvYy51c2VyU3R5bGVzKTtcbiAgICAgICAgICAgICAgICBpZiAob3B0aW9ucy5hZnRlclBhZ2VBZGQgJiYgZGF0YS5wYWdlTnVtYmVyID4gMSkge1xuICAgICAgICAgICAgICAgICAgICA7XG4gICAgICAgICAgICAgICAgICAgIGRhdGEuYWZ0ZXJQYWdlQWRkKGRhdGEpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBkb2MuYXBwbHlTdHlsZXMoZG9jLnVzZXJTdHlsZXMpO1xuICAgICAgICAgICAgfTtcbiAgICAgICAgfVxuICAgICAgICA7XG4gICAgICAgIFtcbiAgICAgICAgICAgICdjcmVhdGVkSGVhZGVyQ2VsbCcsXG4gICAgICAgICAgICAnZHJhd0hlYWRlclJvdycsXG4gICAgICAgICAgICAnZHJhd1JvdycsXG4gICAgICAgICAgICAnZHJhd0hlYWRlckNlbGwnLFxuICAgICAgICBdLmZvckVhY2goZnVuY3Rpb24gKG5hbWUpIHtcbiAgICAgICAgICAgIGlmIChvcHRpb25zW25hbWVdKSB7XG4gICAgICAgICAgICAgICAgY29uc29sZS5lcnJvcihcIlRoZSBcXFwiXCIuY29uY2F0KG5hbWUsIFwiXFxcIiBob29rIGhhcyBjaGFuZ2VkIGluIHZlcnNpb24gMy4wLCBjaGVjayB0aGUgY2hhbmdlbG9nIGZvciBob3cgdG8gbWlncmF0ZS5cIikpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgICAgW1xuICAgICAgICAgICAgWydzaG93Rm9vdCcsICdzaG93Rm9vdGVyJ10sXG4gIC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AodHlwZW9mIG9wdGlvbnNbZGVwcmVjYXRlZE9wdGlvbl0gIT09ICd1bmRlZmluZWQnKSB7XG4gICAgICAgICAgICAgICAgaWYgKHR5cGVvZiBvcHRpb25zLnN0eWxlc1tzdHlsZV0gPT09ICd1bmRlZmluZWQnKSB7XG4gICAgICAgICAgICAgICAgICAgIG9wdGlvbnMuc3R5bGVzW3N0eWxlXSA9IG9wdGlvbnNbZGVwcmVjYXRlZE9wdGlvbl07XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoJ1VzZSBvZiBkZXByZWNhdGVkIG9wdGlvbjogJyArXG4gICAgICAgICAgICAgICAgICAgIGRlcHJlY2F0ZWRPcHRpb24gK1xuICAgICAgICAgICAgICAgICAgICAnLCB1c2UgdGhlIHN0eWxlICcgK1xuICAgICAgICAgICAgICAgICAgICBzdHlsZSArXG4gICAgICAgICAgICAgICAgICAgICcgaW5zdGVhZC4nKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICAgIGZvciAodmFyIF9iID0gMCwgX2MgPSBbXG4gICAgICAgICAgICAnc3R5bGVzJyxcbiAgICAgICAgICAgICdib2R5U3R5bGVzJyxcbiAgICAgICAgICAgICdoZWFkU3R5bGVzJyxcbiAgICAgICAgICAgICdmb290U3R5bGVzJyxcbiAgICAgICAgXTsgX2IgPCBfYy5sZW5ndGg7IF9iKyspIHtcbiAgICAgICAgICAgIHZhciBzdHlsZVByb3AgPSBfY1tfYl07XG4gICAgICAgICAgICBjaGVja1N0eWxlcyhvcHRpb25zW3N0eWxlUHJvcF0gfHwge30pO1xuICAgICAgICB9XG4gICAgICAgIHZhciBjb2x1bW5TdHlsZXMgPSBvcHRpb25zWydjb2x1bW5TdHlsZXMnXSB8fCB7fTtcbiAgICAgICAgZm9yICh2YXIgX2QgPSAwLCBfZSA9IE9iamVjdC5rZXlzKGNvbHVtblN0eWxlcyk7IF9kIDwgX2UubGVuZ3RoOyBf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ZWxsID0gLyoqIEBjbGFzcyAqLyAoZnVuY3Rpb24gKCkge1xuICAgIGZ1bmN0aW9uIENlbGwocmF3LCBzdHlsZXMsIHNlY3Rpb24pIHtcbiAgICAgICAgdmFyIF9hLCBfYjtcbiAgICAgICAgdGhpcy5jb250ZW50SGVpZ2h0ID0gMDtcbiAgICAgICAgdGhpcy5jb250ZW50V2lkdGggPSAwO1xuICAgICAgICB0aGlzLndyYXBwZWRXaWR0aCA9IDA7XG4gICAgICAgIHRoaXMubWluUmVhZGFibGVXaWR0aCA9IDA7XG4gICAgICAgIHRoaXMubWluV2lkdGggPSAwO1xuICAgICAgICB0aGlzLndpZHRoID0gMDtcbiAgICAgICAgdGhpcy5oZWlnaHQgPSAwO1xuICAgICAgICB0aGlzLnggPSAwO1xuICAgICAgICB0aGlzLnkgPSAwO1xuICAgICAgICB0aGlzLnN0eWxlcyA9IHN0eWxlcztcbiAgICAgICAgdGhpcy5zZWN0aW9uID0gc2VjdGlvbjtcbiAgICAgICAgdGhpcy5yYXcgPSByYXc7XG4gICAgICAgIHZhciBjb250ZW50ID0gcmF3O1xuICAgICAgICBpZiAocmF3ICE9IG51bGwgJiYgdHlwZW9mIHJhdyA9PT0gJ29iamVjdCcgJiYgIUFycmF5LmlzQXJyYXkocmF3KSkge1xuICAgICAgICAgICAgdGhpcy5yb3dTcGFuID0gcmF3LnJvd1NwYW4gfHwgMTtcbiAgICAgICAgICAgIHRoaXMuY29sU3BhbiA9IHJhdy5jb2xTcGFuIHx8IDE7XG4gICAgICAgICAgICBjb250ZW50ID0gKF9iID0gKF9hID0gcmF3LmNvbnRlbnQpICE9PSBudWxsICYmIF9hICE9PSB2b2lkIDAgPyBfYSA6IHJhdy50aXRsZSkgIT09IG51bGwgJiYgX2IgIT09IHZvaWQgMCA/IF9iIDogcmF3O1xuICAgICAgICAgICAgaWYgKHJhdy5fZWxlbWVudCkge1xuICAgICAgICAgICAgICAgIHRoaXMucmF3ID0gcmF3Ll9lbGVtZW50O1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5yb3dTcGFuID0gMTtcbiAgICAgICAgICAgIHRoaXMuY29sU3BhbiA9IDE7XG4gICAgICAgIH1cbiAgICAgICAgLy8gU3RyaW5naWZ5IDAgYW5kIGZhbHNlLCBidXQgbm90IHVuZGVmaW5lZCBvciBudWxsXG4gICAgICAgIHZhciB0ZXh0ID0gY29udGVudCAhPSBudWxsID8gJycgKyBjb250ZW50IDogJyc7XG4gICAgICAgIHZhciBzcGxpdFJlZ2V4ID0gL1xcclxcbnxcXHJ8XFxuL2c7XG4gICAgICAgIHRoaXMudGV4dCA9IHRleHQuc3BsaXQoc3BsaXRSZWdleCk7XG4gICAgfVxuICAgIENlbGwucHJvdG90eXBlLmdldFRleHRQb3MgPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgIHZhciB5O1xuICAgICAgICBpZiAodGhpcy5zdHlsZXMudmFsaWduID09PSAndG9wJykge1xuICAgICAgICAgICAgeSA9IHRoaXMueSArIHRoaXMucGFkZGluZygndG9wJyk7XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSBpZiAodGhpcy5zdHlsZXMudmFsaWduID09PSAnYm90dG9tJykge1xuICAgICAgICAgICAgeSA9IHRoaXMueSArIHRoaXMuaGVpZ2h0IC0gdGhpcy5wYWRkaW5nKCdib3R0b20nKTtcbiAgICAgICAgfVxuICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgIHZhciBuZXRIZWlnaHQgPSB0aGlzLmhlaWdodCAtIHRoaXMucGFkZGluZygndmVydGljYWwnKTtcbiAgICAgICAgICAgIHkgPSB0aGlzLnkgKyBuZXRIZWlnaHQgLyAyICsgdGhpcy5wYWRkaW5nKCd0b3AnKTtcbiAgICAgICAgfVxuICAgICAgICB2YXIgeDtcbiAgICAgICAgaWYgKHRoaXMuc3R5bGVzLmhhbGlnbiA9PT0gJ3JpZ2h0Jykge1xuICAgICAgICAgICAgeCA9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tbnMsIHN0eWxlUHJvcHMsIHRoZW1lLCBzY2FsZUZhY3Rvcikge1xuICAgIHZhciByb3dTcGFuc0xlZnRGb3JDb2x1bW4gPSB7fTtcbiAgICB2YXIgcmVzdWx0ID0gc2VjdGlvblJvd3MubWFwKGZ1bmN0aW9uIChyYXdSb3csIHJvd0luZGV4KSB7XG4gICAgICAgIHZhciBza2lwcGVkUm93Rm9yUm93U3BhbnMgPSAwO1xuICAgICAgICB2YXIgY2VsbHMgPSB7fTtcbiAgICAgICAgdmFyIGNvbFNwYW5zQWRkZWQgPSAwO1xuICAgICAgICB2YXIgY29sdW1uU3BhbnNMZWZ0ID0gMDtcbiAgICAgICAgZm9yICh2YXIgX2kgPSAwLCBjb2x1bW5zXzEgPSBjb2x1bW5zOyBfaSA8IGNvbHVtbnNfMS5sZW5ndGg7IF9pKyspIHtcbiAgICAgICAgICAgIHZhciBjb2x1bW4gPSBjb2x1bW5zXzFbX2ldO1xuICAgICAgICAgICAgaWYgKHJvd1NwYW5zTGVmdEZvckNvbHVtbltjb2x1bW4uaW5kZXhdID09IG51bGwgfHxcbiAgICAgICAgICAgICAgICByb3dTcGFuc0xlZnRGb3JDb2x1bW5bY29sdW1uLmluZGV4XS5sZWZ0ID09PSAwKSB7XG4gICAgICAgICAgICAgICAgaWYgKGNvbHVtblNwYW5zTGVmdCA9PT0gMCkge1xuICAgICAgICAgICAgICAgICAgICB2YXIgcmF3Q2VsbCA9IHZvaWQgMDtcbiAgICAgICAgICAgICAgICAgICAgaWYgKEFycmF5LmlzQXJyYXkocmF3Um93KSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgcmF3Q2VsbCA9XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmF3Um93W2NvbHVtbi5pbmRleCAtIGNvbFNwYW5zQWRkZWQgLSBza2lwcGVkUm93Rm9yUm93U3BhbnNdO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgcmF3Q2VsbCA9IHJhd1Jvd1tjb2x1bW4uZGF0YUtleV07XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgdmFyIGNlbGxJbnB1dFN0eWxlcyA9IHt9O1xuICAgICAgICAgICAgICAgICAgICBpZiAodHlwZW9mIHJhd0NlbGwgPT09ICdvYmplY3QnICYmICFBcnJheS5pc0FycmF5KHJhd0NlbGwpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBjZWxsSW5wdXRTdHlsZXMgPSAocmF3Q2VsbCA9PT0gbnVsbCB8fCByYXdDZWxsID09PSB2b2lkIDAgPyB2b2lkIDAgOiByYXdDZWxsLnN0eWxlcykgfHwge307XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgdmFyIHN0eWxlcyA9IGNlbGxTdHlsZXMoc2VjdGlvbk5hbWUsIGNvbHVtbiwgcm93SW5kZXgsIHRoZW1lLCBzdHlsZVByb3BzLCBzY2FsZUZhY3RvciwgY2VsbElucHV0U3R5bGVzKTtcbiAgICAgICAgICAgICAgICAgICAgdmFyIGNlbGwgPSBuZXcgbW9kZWxzXzEuQ2VsbChyYXdDZWxsLCBzdHlsZXMsIHNlY3Rpb25OYW1lKTtcbiAgICAgICAgICAgICAgICAgICAgLy8gZGF0YUtleSBpcyBub3QgdXNlZCBpbnRlcm5hbGx5IG5vIG1vcmUgYnV0IGtlZXAgZm9yXG4gICAgICAgICAgICAgICAgICAgIC8vIGJhY2t3YXJkcyBjb21wYXQgaW4gaG9va3NcbiAgICAgICAgICAgICAgICAgICAgY2VsbHNbY29sdW1uLmRhdGFLZXldID0gY2VsbDtcbiAgICAgICAgICAgICAgICAgICAgY2VsbHNbY29sdW1uLmluZGV4XSA9IGNlbGw7XG4gICAgICAgICAgICAgICAgICAgIGNvbHVtblNwYW5zTGVmdCA9IGNlbGwuY29sU3BhbiAtIDE7XG4gICAgICAgICAgICAgICAgICAgIHJvd1NwYW5zTGVmdEZvckNvbHVtbltjb2x1bW4uaW5kZXhdID0ge1xuICAgICAgICAgICAgICAgICAgICAgICAgbGVmdDogY2VsbC5yb3dTcGFuIC0gMSxcbiAgICAgICAgICAgICAgICAgICAgICAgIHRpbWVzOiBjb2x1bW5TcGFuc0xlZnQsXG4gICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBjb2x1bW5TcGFuc0xlZnQtLTtcbiAgICAgICAgICAgICAgICAgICAgY29sU3BhbnNBZGRlZCsrO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgIHJvd1NwYW5zTGVmdEZvckNvbHVtbltjb2x1bW4uaW5kZXhdLmxlZnQtLTtcbiAgICAgICAgICAgICAgICBjb2x1bW5TcGFuc0xlZnQgPSByb3dTcGFuc0xlZnRGb3JDb2x1bW5bY29sdW1uLmluZGV4XS50aW1lcztcbiAgICAgICAgICAgICAgICBza2lwcGVkUm93Rm9yUm93U3BhbnMrKztcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gbmV3IG1vZGVsc18xLlJvdyhyYXdSb3csIHJvd0luZGV4LCBzZWN0aW9uTmFtZSwgY2VsbHMpO1xuICAgIH0pO1xuICAgIHJldHVybiByZXN1bHQ7XG59XG5mdW5jdGlvbiBnZW5lcmF0ZVNlY3Rpb25Sb3coY29sdW1ucywgc2VjdGlvbikge1xuICAgIHZhciBzZWN0aW9uUm93ID0ge307XG4gICAgY29sdW1ucy5mb3JFYWNoKGZ1bmN0aW9uIChjb2wpIHtcbiAgICAgICAgaWYgKGNvbC5yYXcgIT0gbnVsbCkge1xuICAgICAgICAgICAgdmFyIHRpdGxlID0gZ2V0U2VjdGlvblRpdGxlKHNlY3Rpb24sIGNvbC5yYXcpO1xuICAgICAgICAgICAgaWYgKHRpdGxlICE9IG51bGwpXG4gICAgICAgICAgICAgICAgc2VjdGlvblJvd1tjb2wuZGF0YUtleV0gPSB0aXRsZTtcbiAgICAgICAgfVxuICAgIH0pO1xuICAgIHJldHVybiBPYmplY3Qua2V5cyhzZWN0aW9uUm93KS5sZW5ndGggPiAwID8gc2VjdGlvblJvdyA6IG51bGw7XG59XG5mdW5jdGlvbiBnZXRTZWN0aW9uVGl0bGUoc2VjdGlvbiwgY29sdW1uKSB7XG4gICAgaWYgKHNlY3Rpb24gPT09ICdoZWFkJykge1xuICAgICAgICBpZiAodHlwZW9mIGNvbHVtbiA9PT0gJ29iamVjdCcpIHtcbiAgICAgICAgICAgIHJldHVybiBjb2x1bW4uaGVhZGVyIHx8IGNvbHVtbi50aXRsZSB8fCBudWxsO1xuICAgICAgICB9XG4gICAgICAgIGVsc2UgaWYgKHR5cGVvZiBjb2x1bW4gPT09ICdzdHJpbmcnIHx8IHR5cGVvZiBjb2x1bW4gPT09ICdudW1iZXInKSB7XG4gICAgICAgICAgICByZXR1cm4gY29sdW1uO1xuICAgICAgICB9XG4gICAgfVxuICAgIGVsc2UgaWYgKHNlY3Rpb24gPT09ICdmb290JyAmJiB0eXBlb2YgY29sdW1uID09PSAnb2JqZWN0Jykge1xuICAgICAgICByZXR1cm4gY29sdW1uLmZvb3RlcjtcbiAgICB9XG4gICAgcmV0dXJuIG51bGw7XG59XG5mdW5jdGlvbiBjcmVhdGVDb2x1bW5zKGNvbHVtbnMpIHtcbiAgICByZXR1cm4gY29sdW1ucy5tYXAoZnVuY3Rpb24gKGlucHV0LCBpbmRleCkge1xuICAgICAgICB2YXIgX2EsIF9iO1xuICAgICAgICB2YXIga2V5O1xuICAgICAgICBpZiAodHlwZW9mIGlucHV0ID09PSAnb2JqZWN0Jykge1xuICAgICAgICAgICAga2V5ID0gKF9iID0gKF9hID0gaW5wdXQuZGF0YUtleSkgIT09IG51bGwgJiYgX2EgIT09IHZvaWQgMCA/IF9hIDogaW5wdX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Nob3VsZCBub3QgYmUgbW9yZSB0aGFuIGF2YWlsYWJsZSBwYWdlIHdpZHRoXG4gICAgICAgICAgICAgICAgaWYgKGNlbGwuY29udGVudFdpZHRoID4gYXZhaWxhYmxlUGFnZVdpZHRoKSB7XG4gICAgICAgICAgICAgICAgICAgIGNlbGwubWluV2lkdGggPSBhdmFpbGFibGVQYWdlV2lkdGg7XG4gICAgICAgICAgICAgICAgICAgIGNlbGwud3JhcHBlZFdpZHRoID0gYXZhaWxhYmxlUGFnZVdpZHRoO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgY2VsbC5taW5XaWR0aCA9IGNlbGwuY29udGVudFdpZHRoO1xuICAgICAgICAgICAgICAgICAgICBjZWxsLndyYXBwZWRXaWR0aCA9IGNlbGwuY29udGVudFdpZHRoO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIGF1dG9cbiAgICAgICAgICAgICAgICB2YXIgZGVmYXVsdE1pbldpZHRoID0gMTAgLyBzZjtcbiAgICAgICAgICAgICAgICBjZWxsLm1pbldpZHRoID0gY2VsbC5zdHlsZXMubWluQ2VsbFdpZHRoIHx8IGRlZmF1bHRNaW5XaWR0aDtcbiAgICAgICAgICAgICAgICBjZWxsLndyYXBwZWRXaWR0aCA9IGNlbGwuY29udGVudFdpZHRoO1xuICAgICAgICAgICAgICAgIGlmIChjZWxsLm1pbldpZHRoID4gY2VsbC53cmFwcGVkV2lkdGgpIHtcbiAgICAgICAgICAgICAgICAgICAgY2VsbC53cmFwcGVkV2lkdGggPSBjZWxsLm1pbldpZHRoO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH0pO1xuICAgIHRhYmxlLmFsbFJvd3MoKS5mb3JFYWNoKGZ1bmN0aW9uIChyb3cpIHtcbiAgICAgIC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aWR0aCBvZiBjb2xzcGFuIGNlbGxzXG4gICAgICAgICAgICAgICAgLy8gZG9lcyBub3QgYWZmZWN0IHRoZSB3aWR0aCBvZiBjb2x1bW5zLCBzZXR0aW5nIGNvbHVtblN0eWxlcyBjZWxsV2lkdGggZW5hYmxlcyB0aGVcbiAgICAgICAgICAgICAgICAvLyB1c2VyIHRvIGF0IGxlYXN0IGRvIGl0IG1hbnVhbGx5LlxuICAgICAgICAgICAgICAgIC8vIE5vdGUgdGhhdCB0aGlzIGlzIG5vdCBwZXJmZWN0IGZvciBub3cgc2luY2UgZm9yIGV4YW1wbGUgcm93IGFuZCB0YWJsZSBzdHlsZXMgYXJlXG4gICAgICAgICAgICAgICAgLy8gbm90IGFjY291bnRlZCBmb3JcbiAgICAgICAgICAgICAgICB2YXIgY29sdW1uU3R5bGVzID0gdGFibGUuc3R5bGVzLmNvbHVtblN0eWxlc1tjb2x1bW4uZGF0YUtleV0gfHxcbiAgICAgICAgICAgICAgICAgICAgdGFibGUuc3R5bGVzLmNvbHVtblN0eWxlc1tjb2x1bW4uaW5kZXhdIHx8XG4gICAgICAgICAgICAgICAgICAgIHt9O1xuICAgICAgICAgICAgICAgIHZhciBjZWxsV2lkdGggPSBjb2x1bW5TdHlsZXMuY2VsbFdpZHRoIHx8IGNvbHVtblN0eWxlcy5taW5DZWxsV2lkdGg7XG4gICAgICAgICAgICAgICAgaWYgKGNlbGxXaWR0aCAmJiB0eXBlb2YgY2VsbFdpZHRoID09PSAnbnVtYmVyJykge1xuICAgICAgICAgICAgICAgICAgICBjb2x1bW4ubWluV2lkdGggPSBjZWxsV2lkdGg7XG4gICAgICAgICAgICAgICAgICAgIGNvbHVtbi53cmFwcGVkV2lkdGggPSBjZWxsV2lkdGg7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKGNlbGwpIHtcbiAgICAgICAgICAgICAgICAvLyBNYWtlIHN1cmUgYWxsIGNvbHVtbnMgZ2V0IG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kZWxldGUgcm93LmNlbGxzW2NvbHVtbi5pbmRleF07XG4gICAgICAgICAgICAgICAgZGF0YS5sZWZ0LS07XG4gICAgICAgICAgICAgICAgaWYgKGRhdGEubGVmdCA8PSAxKSB7XG4gICAgICAgICAgICAgICAgICAgIGRlbGV0ZSByb3dTcGFuQ2VsbHNbY29sdW1uLmluZGV4XTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICB2YXIgY2VsbCA9IHJvdy5jZWxsc1tjb2x1bW4uaW5kZXhdO1xuICAgICAgICAgICAgICAgIGlmICghY2VsbCkge1xuICAgICAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgY2VsbC5oZWlnaHQgPSByb3cuaGVpZ2h0O1xuICAgICAgICAgICAgICAgIGlmIChjZWxsLnJvd1NwYW4gPiAxKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciByZW1haW5pbmcgPSBhbGwubGVuZ3RoIC0gcm93SW5kZXg7XG4gICAgICAgICAgICAgICAgICAgIHZhciBsZWZ0ID0gY2VsbC5yb3dTcGFuID4gcmVtYWluaW5nID8gcmVtYWluaW5nIDogY2VsbC5yb3dTcGFuO1xuICAgICAgICAgICAgICAgICAgICByb3dTcGFuQ2VsbHNbY29sdW1uLmluZGV4XSA9IHsgY2VsbDogY2VsbCwgbGVmdDogbGVmdCwgcm93OiByb3cgfTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59XG5mdW5jdGlvbiBhcHBseUNvbFNwYW5zKHRhYmxlKSB7XG4gICAgdmFyIGFsbCA9IHRhYmxlLmFsbFJvd3MoKTtcbiAgICBmb3IgKHZhciByb3dJbmRleCA9IDA7IHJvd0luZGV4IDwgYWxsLmxlbmd0aDsgcm93SW5kZXgrKykge1xuICAgICAgICB2YXIgcm93ID0gYWxsW3Jvd0luZGV4XTtcbiAgICAgICAgdmFyIGNvbFNwYW5DZWxsID0gbnVsbDtcbiAgICAgICAgdmFyIGNvbWJpbmVkQ29sU3BhbldpZHRoID0gMDtcbiAgICAgICAgdmFyIGNvbFNwYW5zTGVmdCA9IDA7XG4gICAgICAgIGZvciAodmFyIGNvbHVtbkluZGV4ID0gMDsgY29sdW1uSW5kZXggPCB0YWJsZS5jb2x1bW5zLmxlbmd0aDsgY29sdW1uSW5kZXgrKykge1xuICAgICAgICAgICAgdmFyIGNvbHVtbiA9IHRhYmxlLmNvbHVtbnNbY29sdW1uSW5kZXhdO1xuICAgICAgICAgICAgLy8gV2lkdGggYW5kIGNvbHNwYW5cbiAgICAgICAgICAgIGNvbFNwYW5zTGVmdCAtPSAxO1xuICAgICAgICAgICAgaWYgKGNvbFNwYW5zTGVmdCA+IDEgJiYgdGFibGUuY29sdW1uc1tjb2x1bW5JbmRleCArIDFdKSB7XG4gICAgICAgICAgICAgICAgY29tYmluZWRDb2xTcGFuV2lkdGggKz0gY29sdW1uLndpZHRoO1xuICAgICAgICAgICAgICAgIGRlbGV0ZSByb3cuY2VsbHNbY29sdW1uLmluZGV4XTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVsc2UgaWYgKGNvbFNwYW5DZWxsKSB7XG4gICAgICAgICAgICAgICAgdmFyIGNlbGwgPSBjb2xTcGFuQ2VsbDtcbiAgICAgICAgICAgICAgICBkZWxldGUgcm93LmNlbGxzW2NvbHVtbi5pbmRleF07XG4gICAgICAgICAgICAgICAgY29sU3BhbkNlbGwgPSBudWxsO1xuICAgICAgICAgICAgICAgIGNlbGwud2lkdGggPSBjb2x1bW4ud2lkdGggKyBjb21iaW5lZENvbFNwYW5XaWR0aDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgIHZhciBjZWxsID0gcm93LmNlbGxzW2NvbHVtbi5pbmRleF07XG4gICAgICAgICAgICAgICAgaWYgKCFjZWxsKVxuICAgICAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgICAgICBjb2xTcGFuc0xlZnQgPSBjZWxsLmNvbFNwYW47XG4gICAgICAgICAgICAgICAgY29tYmluZWRDb2xTcGFuV2lkdGggPSAwO1xuICAgICAgICAgICAgICAgIGlmIChjZWxsLmNvbFNwYW4gPiAxKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbFNwYW5DZWxsID0gY2VsbDtcbiAgICAgICAgICAgICAgICAgICAgY29tYmluZWRDb2xTcGFuV2lkdGggKz0gY29sdW1uLndpZHRoO1xuICAgICAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgY2VsbC53aWR0aCA9IGNvbHVtbi53aWR0aCArIGNvbWJpbmVkQ29sU3BhbldpZHRoO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxufVxuZnVuY3Rpb24gZml0Q29udGVudCh0YWJsZSwgZG9jKSB7XG4gICAgdmFyIHJvd1NwYW5IZWlnaHQgPSB7IGNvdW50OiAwLCBoZWlnaHQ6IDAgfTtcbiAgICBmb3IgKHZhciBfaSA9IDAsIF9hID0gdGFibGUuYWxsUm93cygpOyBfaSA8IF9hLmxlbmd0aDsgX2krKykge1xuICAgICAgICB2YXIgcm93ID0gX2FbX2ldO1xuICAgICAgICBmb3IgKHZhciBfYiA9IDAsIF9jID0gdGFibGUuY29sdW1uczsgX2IgPCBfYy5sZW5ndGg7IF9iKyspIHtcbiAgICAgICAgICAgIHZhciBjb2x1bW4gPSBfY1tfYl07XG4gICAgICAgICAgICB2YXIgY2VsbCA9IHJvdy5jZWxsc1tjb2x1bW4uaW5kZXhdO1xuICAgICAgICAgICAgaWYgKCFjZWxsKVxuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgZG9jLmFwcGx5U3R5bGVzKGNlbGwuc3R5bGVzLCB0cnVlKTtcbiAgICAgICAgICAgI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N0cmluZycpIHtcbiAgICAgICAgICAgICAgICAgICAgY2VsbC50ZXh0ID0gW3Jlc3VsdF07XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBjZWxsLnRleHQgPSByZXN1bHQ7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY2VsbC5jb250ZW50SGVpZ2h0ID0gY2VsbC5nZXRDb250ZW50SGVpZ2h0KGRvYy5zY2FsZUZhY3RvcigpLCBkb2MuZ2V0TGluZUhlaWdodEZhY3RvcigpKTtcbiAgICAgICAgICAgIHZhciByZWFsQ29udGVudEhlaWdodCA9IGNlbGwuY29udGVudEhlaWdodCAvIGNlbGwucm93U3BhbjtcbiAgICAgICAgICAgIGlmIChjZWxsLnJvd1NwYW4gPiAxICYmXG4gICAgICAgICAgICAgICAgcm93U3BhbkhlaWdodC5jb3VudCAqIHJvd1NwYW5IZWlnaHQuaGVpZ2h0IDxcbiAgICAgICAgICAgICAgICAgICAgcmVhbENvbnRlbnRIZWlnaHQgKiBjZWxsLnJvd1NwYW4pIHtcbiAgICAgICAgICAgICAgICByb3dTcGFuSGVpZ2h0ID0geyBoZWlnaHQ6IHJlYWxDb250ZW50SGVpZ2h0LCBjb3VudDogY2VsbC5yb3dTcGFuIH07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBlbHNlIGlmIChyb3dTcGFuSGVpZ2h0ICYmIHJvd1NwYW5IZWlnaHQuY291bnQgPiAwKSB7XG4gICAgICAgICAgICAgICAgaWYgKHJvd1NwYW5IZWlnaHQuaGVpZ2h0ID4gcmVhbENvbnRlbnRIZWlnaHQpIHtcbiAgICAgICAgICAgICAgICAgICAgcmVhbENvbnRlbnRIZWlnaHQgPSByb3dTcGFuSGVpZ2h0LmhlaWdodDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAocmVhbENvbnRlbnRIZW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