UNPKG

@xpadev-net/niconicomments

Version:

NiconiComments is a comment drawing library that is somewhat compatible with the official Nico Nico Douga player.

1,384 lines (1,336 loc) 192 kB
/*! niconicomments.js v0.2.73 (c) 2021 xpadev-net https://xpadev.net Released under the MIT License. */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.NiconiComments = factory()); })(this, (function () { 'use strict'; let imageCache = {}; const resetImageCache = () => { imageCache = {}; }; let nicoScripts = { reverse: [], default: [], replace: [], ban: [], seekDisable: [], jump: [], }; const resetNicoScripts = () => { nicoScripts = { reverse: [], default: [], replace: [], ban: [], seekDisable: [], jump: [], }; }; let plugins = []; const setPlugins = (input) => { plugins = input; }; var index$4 = /*#__PURE__*/Object.freeze({ __proto__: null, get imageCache () { return imageCache; }, get nicoScripts () { return nicoScripts; }, get plugins () { return plugins; }, resetImageCache: resetImageCache, resetNicoScripts: resetNicoScripts, setPlugins: setPlugins }); let isDebug = false; const setIsDebug = (val) => { isDebug = val; }; let defaultConfig; const updateConfig = (config) => { defaultConfig = config; }; const defaultOptions = { config: {}, debug: false, enableLegacyPiP: false, format: "default", formatted: false, keepCA: false, mode: "default", scale: 1, showCollision: false, showCommentCount: false, showFPS: false, useLegacy: false, video: undefined, lazy: false, }; let config; let options; const setConfig = (value) => { config = value; }; const setOptions = (value) => { options = value; }; var config$1 = /*#__PURE__*/Object.freeze({ __proto__: null, get config () { return config; }, get defaultConfig () { return defaultConfig; }, defaultOptions: defaultOptions, get options () { return options; }, setConfig: setConfig, setOptions: setOptions, updateConfig: updateConfig }); class CanvasRenderingContext2DError extends Error { constructor(options = {}) { super("CanvasRenderingContext2DError", options); } } CanvasRenderingContext2DError.prototype.name = "CanvasRenderingContext2DError"; class InvalidFormatError extends Error { constructor(options = {}) { super("InvalidFormatError", options); } } InvalidFormatError.prototype.name = "InvalidFormatError"; class InvalidOptionError extends Error { constructor(options = {}) { super("Invalid option\nPlease check document: https://xpadev-net.github.io/niconicomments/#p_options", options); } } InvalidOptionError.prototype.name = "InvalidOptionError"; class NotImplementedError extends Error { pluginName; methodName; constructor(pluginName, methodName, options = {}) { super("NotImplementedError", options); this.pluginName = pluginName; this.methodName = methodName; } } NotImplementedError.prototype.name = "NotImplementedError"; var index$3 = /*#__PURE__*/Object.freeze({ __proto__: null, CanvasRenderingContext2DError: CanvasRenderingContext2DError, InvalidFormatError: InvalidFormatError, InvalidOptionError: InvalidOptionError, NotImplementedError: NotImplementedError }); const arrayPush = (_array, key, push) => { let array = _array; if (!array) { array = {}; } if (!array[Number(key)]) { array[Number(key)] = []; } array[Number(key)]?.push(push); }; const arrayEqual = (a, b) => { if (a.length !== b.length) return false; for (let i = 0, n = a.length; i < n; ++i) { if (a[i] !== b[i]) return false; } return true; }; const hex2rgb = (_hex) => { let hex = _hex; if (hex.startsWith("#")) hex = hex.slice(1); if (hex.length === 3) hex = hex.slice(0, 1) + hex.slice(0, 1) + hex.slice(1, 2) + hex.slice(1, 2) + hex.slice(2, 3) + hex.slice(2, 3); return [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map((str) => Number.parseInt(str, 16)); }; const hex2rgba = (_hex) => { let hex = _hex; if (hex.startsWith("#")) hex = hex.slice(1); if (hex.length === 4) hex = hex.slice(0, 1) + hex.slice(0, 1) + hex.slice(1, 2) + hex.slice(1, 2) + hex.slice(2, 3) + hex.slice(2, 3) + hex.slice(3, 4) + hex.slice(3, 4); return [ hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6), hex.slice(4, 6), ].map((str, index) => { if (index === 3) return Number.parseInt(str, 16) / 256; return Number.parseInt(str, 16); }); }; const getStrokeColor = (comment) => { if (comment.strokeColor) { const color = comment.strokeColor.slice(1); const length = color.length; if (length === 3 || length === 6) { return `rgba(${hex2rgb(color).join(",")},${config.contextStrokeOpacity})`; } if (length === 4 || length === 8) { return `rgba(${hex2rgba(color).join(",")})`; } } return `rgba(${hex2rgb(comment.color === "#000000" ? config.contextStrokeInversionColor : config.contextStrokeColor).join(",")},${config.contextStrokeOpacity})`; }; function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; } function _createClass(e, r, t) { return Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var n = 0, F = function () {}; return { s: F, n: function () { return n >= r.length ? { done: !0 } : { done: !1, value: r[n++] }; }, e: function (r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function () { t = t.call(r); }, n: function () { var r = t.next(); return a = r.done, r; }, e: function (r) { u = !0, o = r; }, f: function () { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _possibleConstructorReturn(t, e) { if (e && ("object" == typeof e || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function (t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); } // src/error/ValiError/ValiError.ts var ValiError = /*#__PURE__*/function (_Error) { /** * Creates a Valibot error with useful information. * * @param issues The error issues. */ function ValiError(issues) { var _this; _classCallCheck(this, ValiError); _this = _callSuper(this, ValiError, [issues[0].message]); _defineProperty(_this, "issues", void 0); _this.name = "ValiError"; _this.issues = issues; return _this; } _inherits(ValiError, _Error); return _createClass(ValiError); }(/*#__PURE__*/_wrapNativeSuper(Error)); // src/utils/actionIssue/actionIssue.ts function actionIssue(context, reference, input, label, received) { return { issues: [{ context: context, reference: reference, input: input, label: label, received: received }] }; } // src/utils/actionOutput/actionOutput.ts function actionOutput(output) { return { output: output }; } // src/utils/defaultArgs/defaultArgs.ts function defaultArgs(arg1, arg2) { return Array.isArray(arg1) ? [void 0, arg1] : [arg1, arg2]; } // src/storages/globalConfig/globalConfig.ts var store; function getGlobalConfig(config) { var _config$lang, _store, _config$abortEarly, _store2, _config$abortPipeEarl, _store3, _config$skipPipe, _store4; return { lang: (_config$lang = config === null || config === void 0 ? void 0 : config.lang) !== null && _config$lang !== void 0 ? _config$lang : (_store = store) === null || _store === void 0 ? void 0 : _store.lang, message: config === null || config === void 0 ? void 0 : config.message, abortEarly: (_config$abortEarly = config === null || config === void 0 ? void 0 : config.abortEarly) !== null && _config$abortEarly !== void 0 ? _config$abortEarly : (_store2 = store) === null || _store2 === void 0 ? void 0 : _store2.abortEarly, abortPipeEarly: (_config$abortPipeEarl = config === null || config === void 0 ? void 0 : config.abortPipeEarly) !== null && _config$abortPipeEarl !== void 0 ? _config$abortPipeEarl : (_store3 = store) === null || _store3 === void 0 ? void 0 : _store3.abortPipeEarly, skipPipe: (_config$skipPipe = config === null || config === void 0 ? void 0 : config.skipPipe) !== null && _config$skipPipe !== void 0 ? _config$skipPipe : (_store4 = store) === null || _store4 === void 0 ? void 0 : _store4.skipPipe }; } // src/storages/globalMessage/globalMessage.ts var store2; function getGlobalMessage(lang) { var _store5; return (_store5 = store2) === null || _store5 === void 0 ? void 0 : _store5.get(lang); } // src/storages/schemaMessage/schemaMessage.ts var store3; function getSchemaMessage(lang) { var _store7; return (_store7 = store3) === null || _store7 === void 0 ? void 0 : _store7.get(lang); } // src/storages/specificMessage/specificMessage.ts var store4; function getSpecificMessage(reference, lang) { var _store9; return (_store9 = store4) === null || _store9 === void 0 || (_store9 = _store9.get(reference)) === null || _store9 === void 0 ? void 0 : _store9.get(lang); } // src/utils/i18n/i18n.ts function i18n(schema, context, reference, config, issue) { var _ref3, _ref4, _ref5, _ref6, _context$message; var message = (_ref3 = (_ref4 = (_ref5 = (_ref6 = (_context$message = context.message) !== null && _context$message !== void 0 ? _context$message : getSpecificMessage(reference, issue.lang)) !== null && _ref6 !== void 0 ? _ref6 : schema ? getSchemaMessage(issue.lang) : null) !== null && _ref5 !== void 0 ? _ref5 : config === null || config === void 0 ? void 0 : config.message) !== null && _ref4 !== void 0 ? _ref4 : getGlobalMessage(issue.lang)) !== null && _ref3 !== void 0 ? _ref3 : issue.message; return typeof message === "function" ? message(issue) : message; } // src/utils/schemaResult/schemaResult.ts function schemaResult(typed, output, issues) { return { typed: typed, output: output, issues: issues }; } // src/utils/stringify/stringify.ts function stringify(input) { var type = _typeof(input); if (type === "object") { type = input ? Object.getPrototypeOf(input).constructor.name : "null"; } return type === "string" ? "\"".concat(input, "\"") : type === "number" || type === "bigint" || type === "boolean" ? "".concat(input) : type; } // src/utils/pipeResult/utils/pipeIssue/pipeIssue.ts function pipeIssue(context, config, issue) { var _issue$received; var received = (_issue$received = issue.received) !== null && _issue$received !== void 0 ? _issue$received : stringify(issue.input); var schemaIssue2 = { reason: context.type, context: issue.context.type, expected: issue.context.expects, received: received, message: "Invalid ".concat(issue.label, ": ").concat(issue.context.expects ? "Expected ".concat(issue.context.expects, " but r") : "R", "eceived ").concat(received), input: issue.input, requirement: issue.context.requirement, path: issue.path, lang: config === null || config === void 0 ? void 0 : config.lang, abortEarly: config === null || config === void 0 ? void 0 : config.abortEarly, abortPipeEarly: config === null || config === void 0 ? void 0 : config.abortPipeEarly, skipPipe: config === null || config === void 0 ? void 0 : config.skipPipe }; schemaIssue2.message = i18n(false, issue.context, issue.reference, config, schemaIssue2); return schemaIssue2; } // src/utils/pipeResult/pipeResult.ts function pipeResult(context, input, config, issues) { if (context.pipe && !(config !== null && config !== void 0 && config.skipPipe)) { var _iterator = _createForOfIteratorHelper(context.pipe), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var action = _step.value; var result = action._parse(input); if (result.issues) { var _iterator2 = _createForOfIteratorHelper(result.issues), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var actionIssue2 = _step2.value; var schemaIssue2 = pipeIssue(context, config, actionIssue2); issues ? issues.push(schemaIssue2) : issues = [schemaIssue2]; } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } if (config !== null && config !== void 0 && config.abortEarly || config !== null && config !== void 0 && config.abortPipeEarly) { break; } } else { input = result.output; } } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } } return schemaResult(true, input, issues); } function restAndDefaultArgs(arg1, arg2, arg3) { if (!arg1 || _typeof(arg1) === "object" && !Array.isArray(arg1)) { var _defaultArgs = defaultArgs(arg2, arg3), _defaultArgs2 = _slicedToArray(_defaultArgs, 2), error2 = _defaultArgs2[0], pipe2 = _defaultArgs2[1]; return [arg1, error2, pipe2]; } var _defaultArgs3 = defaultArgs(arg1, arg2), _defaultArgs4 = _slicedToArray(_defaultArgs3, 2), error = _defaultArgs4[0], pipe = _defaultArgs4[1]; return [void 0, error, pipe]; } // src/utils/schemaIssue/schemaIssue.ts function schemaIssue(context, reference, input, config, other) { var _other$expected, _other$reason; var received = stringify(input); var expected = (_other$expected = other === null || other === void 0 ? void 0 : other.expected) !== null && _other$expected !== void 0 ? _other$expected : context.expects; var issue = { reason: (_other$reason = other === null || other === void 0 ? void 0 : other.reason) !== null && _other$reason !== void 0 ? _other$reason : "type", context: context.type, expected: expected, received: received, message: "Invalid type: Expected ".concat(expected, " but received ").concat(received), input: input, path: other === null || other === void 0 ? void 0 : other.path, issues: other === null || other === void 0 ? void 0 : other.issues, lang: config === null || config === void 0 ? void 0 : config.lang, abortEarly: config === null || config === void 0 ? void 0 : config.abortEarly, abortPipeEarly: config === null || config === void 0 ? void 0 : config.abortPipeEarly, skipPipe: config === null || config === void 0 ? void 0 : config.skipPipe }; issue.message = i18n(true, context, reference, config, issue); return { typed: false, output: input, issues: [issue] }; } // src/methods/getDefault/getDefault.ts function getDefault(schema) { return typeof schema["default"] === "function" ? schema["default"]() : schema["default"]; } function is(schema, input, config) { var _getGlobalConfig; return !schema._parse(input, { abortEarly: true, skipPipe: (_getGlobalConfig = getGlobalConfig(config)) === null || _getGlobalConfig === void 0 ? void 0 : _getGlobalConfig.skipPipe }).issues; } // src/schemas/array/array.ts function array(item, arg2, arg3) { var _defaultArgs5 = defaultArgs(arg2, arg3), _defaultArgs6 = _slicedToArray(_defaultArgs5, 2), message = _defaultArgs6[0], pipe = _defaultArgs6[1]; return { type: "array", expects: "Array", async: false, item: item, message: message, pipe: pipe, _parse: function _parse(input, config) { if (Array.isArray(input)) { var typed = true; var issues; var output = []; for (var key = 0; key < input.length; key++) { var value2 = input[key]; var result = this.item._parse(value2, config); if (result.issues) { var pathItem = { type: "array", origin: "value", input: input, key: key, value: value2 }; var _iterator7 = _createForOfIteratorHelper(result.issues), _step7; try { for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { var _issues; var issue = _step7.value; if (issue.path) { issue.path.unshift(pathItem); } else { issue.path = [pathItem]; } (_issues = issues) === null || _issues === void 0 || _issues.push(issue); } } catch (err) { _iterator7.e(err); } finally { _iterator7.f(); } if (!issues) { issues = result.issues; } if (config !== null && config !== void 0 && config.abortEarly) { typed = false; break; } } if (!result.typed) { typed = false; } output.push(result.output); } if (typed) { return pipeResult(this, output, config, issues); } return schemaResult(false, output, issues); } return schemaIssue(this, array, input, config); } }; } // src/schemas/boolean/boolean.ts function _boolean(arg1, arg2) { var _defaultArgs17 = defaultArgs(arg1, arg2), _defaultArgs18 = _slicedToArray(_defaultArgs17, 2), message = _defaultArgs18[0], pipe = _defaultArgs18[1]; return { type: "boolean", expects: "boolean", async: false, message: message, pipe: pipe, _parse: function _parse(input, config) { if (typeof input === "boolean") { return pipeResult(this, input, config); } return schemaIssue(this, _boolean, input, config); } }; } // src/schemas/instance/instance.ts function instance(class_, arg2, arg3) { var _defaultArgs25 = defaultArgs(arg2, arg3), _defaultArgs26 = _slicedToArray(_defaultArgs25, 2), message = _defaultArgs26[0], pipe = _defaultArgs26[1]; return { type: "instance", expects: class_.name, async: false, "class": class_, message: message, pipe: pipe, _parse: function _parse(input, config) { if (input instanceof this["class"]) { return pipeResult(this, input, config); } return schemaIssue(this, instance, input, config); } }; } // src/schemas/intersect/utils/mergeOutputs/mergeOutputs.ts function mergeOutputs(output1, output2) { if (_typeof(output1) === _typeof(output2)) { if (output1 === output2 || output1 instanceof Date && output2 instanceof Date && +output1 === +output2) { return { output: output1 }; } if (Array.isArray(output1) && Array.isArray(output2)) { if (output1.length === output2.length) { var array2 = []; for (var index = 0; index < output1.length; index++) { var result = mergeOutputs(output1[index], output2[index]); if (result.invalid) { return result; } array2.push(result.output); } return { output: array2 }; } return { invalid: true }; } if (output1 && output2 && output1.constructor === Object && output2.constructor === Object) { var object2 = _objectSpread2(_objectSpread2({}, output1), output2); for (var key in output1) { if (key in output2) { var _result = mergeOutputs(output1[key], output2[key]); if (_result.invalid) { return _result; } object2[key] = _result.output; } } return { output: object2 }; } } return { invalid: true }; } // src/schemas/intersect/intersect.ts function intersect(options, arg2, arg3) { var _defaultArgs29 = defaultArgs(arg2, arg3), _defaultArgs30 = _slicedToArray(_defaultArgs29, 2), message = _defaultArgs30[0], pipe = _defaultArgs30[1]; return { type: "intersect", expects: _toConsumableArray(new Set(options.map(function (option) { return option.expects; }))).join(" & "), async: false, options: options, message: message, pipe: pipe, _parse: function _parse(input, config) { var typed = true; var issues; var output; var outputs = []; var _iterator9 = _createForOfIteratorHelper(this.options), _step9; try { for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { var schema = _step9.value; var _result2 = schema._parse(input, config); if (_result2.issues) { if (issues) { var _iterator10 = _createForOfIteratorHelper(_result2.issues), _step10; try { for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) { var issue = _step10.value; issues.push(issue); } } catch (err) { _iterator10.e(err); } finally { _iterator10.f(); } } else { issues = _result2.issues; } if (config !== null && config !== void 0 && config.abortEarly) { typed = false; break; } } if (!_result2.typed) { typed = false; } outputs.push(_result2.output); } } catch (err) { _iterator9.e(err); } finally { _iterator9.f(); } if (typed) { output = outputs[0]; for (var index = 1; index < outputs.length; index++) { var result = mergeOutputs(output, outputs[index]); if (result.invalid) { return schemaIssue(this, intersect, input, config); } output = result.output; } return pipeResult(this, output, config, issues); } return schemaResult(false, output, issues); } }; } // src/schemas/literal/literal.ts function literal(literal_, message) { return { type: "literal", expects: stringify(literal_), async: false, literal: literal_, message: message, _parse: function _parse(input, config) { if (input === this.literal) { return schemaResult(true, input); } return schemaIssue(this, literal, input, config); } }; } // src/schemas/nullable/nullable.ts function nullable(wrapped, default_) { return { type: "nullable", expects: "".concat(wrapped.expects, " | null"), async: false, wrapped: wrapped, "default": default_, _parse: function _parse(input, config) { if (input === null) { var override = getDefault(this); if (override === void 0) { return schemaResult(true, input); } input = override; } return this.wrapped._parse(input, config); } }; } // src/schemas/number/number.ts function number(arg1, arg2) { var _defaultArgs37 = defaultArgs(arg1, arg2), _defaultArgs38 = _slicedToArray(_defaultArgs37, 2), message = _defaultArgs38[0], pipe = _defaultArgs38[1]; return { type: "number", expects: "number", async: false, message: message, pipe: pipe, _parse: function _parse(input, config) { if (typeof input === "number" && !isNaN(input)) { return pipeResult(this, input, config); } return schemaIssue(this, number, input, config); } }; } // src/schemas/object/object.ts function object(entries, arg2, arg3, arg4) { var _restAndDefaultArgs = restAndDefaultArgs(arg2, arg3, arg4), _restAndDefaultArgs2 = _slicedToArray(_restAndDefaultArgs, 3), rest = _restAndDefaultArgs2[0], message = _restAndDefaultArgs2[1], pipe = _restAndDefaultArgs2[2]; var cachedEntries; return { type: "object", expects: "Object", async: false, entries: entries, rest: rest, message: message, pipe: pipe, _parse: function _parse(input, config) { if (input && _typeof(input) === "object") { var _cachedEntries; cachedEntries = (_cachedEntries = cachedEntries) !== null && _cachedEntries !== void 0 ? _cachedEntries : Object.entries(this.entries); var typed = true; var issues; var output = {}; var _iterator16 = _createForOfIteratorHelper(cachedEntries), _step16; try { for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) { var _step16$value = _slicedToArray(_step16.value, 2), _key = _step16$value[0], schema = _step16$value[1]; var _value = input[_key]; var _result3 = schema._parse(_value, config); if (_result3.issues) { var _pathItem3 = { type: "object", origin: "value", input: input, key: _key, value: _value }; var _iterator18 = _createForOfIteratorHelper(_result3.issues), _step18; try { for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) { var _issues7; var _issue2 = _step18.value; if (_issue2.path) { _issue2.path.unshift(_pathItem3); } else { _issue2.path = [_pathItem3]; } (_issues7 = issues) === null || _issues7 === void 0 || _issues7.push(_issue2); } } catch (err) { _iterator18.e(err); } finally { _iterator18.f(); } if (!issues) { issues = _result3.issues; } if (config !== null && config !== void 0 && config.abortEarly) { typed = false; break; } } if (!_result3.typed) { typed = false; } if (_result3.output !== void 0 || _key in input) { output[_key] = _result3.output; } } } catch (err) { _iterator16.e(err); } finally { _iterator16.f(); } if (this.rest && !(config !== null && config !== void 0 && config.abortEarly && issues)) { for (var key in input) { if (!(key in this.entries)) { var value2 = input[key]; var result = this.rest._parse(value2, config); if (result.issues) { var pathItem = { type: "object", origin: "value", input: input, key: key, value: value2 }; var _iterator17 = _createForOfIteratorHelper(result.issues), _step17; try { for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) { var _issues6; var issue = _step17.value; if (issue.path) { issue.path.unshift(pathItem); } else { issue.path = [pathItem]; } (_issues6 = issues) === null || _issues6 === void 0 || _issues6.push(issue); } } catch (err) { _iterator17.e(err); } finally { _iterator17.f(); } if (!issues) { issues = result.issues; } if (config !== null && config !== void 0 && config.abortEarly) { typed = false; break; } } if (!result.typed) { typed = false; } output[key] = result.output; } } } if (typed) { return pipeResult(this, output, config, issues); } return schemaResult(false, output, issues); } return schemaIssue(this, object, input, config); } }; } // src/schemas/optional/optional.ts function optional(wrapped, default_) { return { type: "optional", expects: "".concat(wrapped.expects, " | undefined"), async: false, wrapped: wrapped, "default": default_, _parse: function _parse(input, config) { if (input === void 0) { var override = getDefault(this); if (override === void 0) { return schemaResult(true, input); } input = override; } return this.wrapped._parse(input, config); } }; } // src/schemas/string/string.ts function string(arg1, arg2) { var _defaultArgs41 = defaultArgs(arg1, arg2), _defaultArgs42 = _slicedToArray(_defaultArgs41, 2), message = _defaultArgs42[0], pipe = _defaultArgs42[1]; return { type: "string", expects: "string", async: false, message: message, pipe: pipe, _parse: function _parse(input, config) { if (typeof input === "string") { return pipeResult(this, input, config); } return schemaIssue(this, string, input, config); } }; } // src/schemas/record/utils/recordArgs/recordArgs.ts function recordArgs(arg1, arg2, arg3, arg4) { if (_typeof(arg2) === "object" && !Array.isArray(arg2)) { var _defaultArgs45 = defaultArgs(arg3, arg4), _defaultArgs46 = _slicedToArray(_defaultArgs45, 2), message2 = _defaultArgs46[0], pipe2 = _defaultArgs46[1]; return [arg1, arg2, message2, pipe2]; } var _defaultArgs47 = defaultArgs(arg2, arg3), _defaultArgs48 = _slicedToArray(_defaultArgs47, 2), message = _defaultArgs48[0], pipe = _defaultArgs48[1]; return [string(), arg1, message, pipe]; } // src/schemas/record/values.ts var BLOCKED_KEYS = ["__proto__", "prototype", "constructor"]; // src/schemas/record/record.ts function record(arg1, arg2, arg3, arg4) { var _recordArgs = recordArgs(arg1, arg2, arg3, arg4), _recordArgs2 = _slicedToArray(_recordArgs, 4), key = _recordArgs2[0], value2 = _recordArgs2[1], message = _recordArgs2[2], pipe = _recordArgs2[3]; return { type: "record", expects: "Object", async: false, key: key, value: value2, message: message, pipe: pipe, _parse: function _parse(input, config) { if (input && _typeof(input) === "object") { var typed = true; var issues; var output = {}; for (var _i = 0, _Object$entries = Object.entries(input); _i < _Object$entries.length; _i++) { var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), inputKey = _Object$entries$_i[0], inputValue = _Object$entries$_i[1]; if (!BLOCKED_KEYS.includes(inputKey)) { var pathItem = void 0; var keyResult = this.key._parse(inputKey, config); if (keyResult.issues) { pathItem = { type: "record", origin: "key", input: input, key: inputKey, value: inputValue }; var _iterator21 = _createForOfIteratorHelper(keyResult.issues), _step21; try { for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) { var _issues10; var issue = _step21.value; issue.path = [pathItem]; (_issues10 = issues) === null || _issues10 === void 0 || _issues10.push(issue); } } catch (err) { _iterator21.e(err); } finally { _iterator21.f(); } if (!issues) { issues = keyResult.issues; } if (config !== null && config !== void 0 && config.abortEarly) { typed = false; break; } } var valueResult = this.value._parse(inputValue, config); if (valueResult.issues) { var _pathItem4; pathItem = (_pathItem4 = pathItem) !== null && _pathItem4 !== void 0 ? _pathItem4 : { type: "record", origin: "value", input: input, key: inputKey, value: inputValue }; var _iterator22 = _createForOfIteratorHelper(valueResult.issues), _step22; try { for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) { var _issues11; var _issue3 = _step22.value; if (_issue3.path) { _issue3.path.unshift(pathItem); } else { _issue3.path = [pathItem]; } (_issues11 = issues) === null || _issues11 === void 0 || _issues11.push(_issue3); } } catch (err) { _iterator22.e(err); } finally { _iterator22.f(); } if (!issues) { issues = valueResult.issues; } if (config !== null && config !== void 0 && config.abortEarly) { typed = false; break; } } if (!keyResult.typed || !valueResult.typed) { typed = false; } if (keyResult.typed) { output[keyResult.output] = valueResult.output; } } } if (typed) { return pipeResult(this, output, config, issues); } return schemaResult(false, output, issues); } return schemaIssue(this, record, input, config); } }; } // src/schemas/union/utils/subissues/subissues.ts function subissues(results) { var issues; if (results) { var _iterator31 = _createForOfIteratorHelper(results), _step31; try { for (_iterator31.s(); !(_step31 = _iterator31.n()).done;) { var result = _step31.value; if (issues) { var _iterator32 = _createForOfIteratorHelper(result.issues), _step32; try { for (_iterator32.s(); !(_step32 = _iterator32.n()).done;) { var issue = _step32.value; issues.push(issue); } } catch (err) { _iterator32.e(err); } finally { _iterator32.f(); } } else { issues = result.issues; } } } catch (err) { _iterator31.e(err); } finally { _iterator31.f(); } } return issues; } // src/schemas/union/union.ts function union(options, arg2, arg3) { var _defaultArgs57 = defaultArgs(arg2, arg3), _defaultArgs58 = _slicedToArray(_defaultArgs57, 2), message = _defaultArgs58[0], pipe = _defaultArgs58[1]; return { type: "union", expects: _toConsumableArray(new Set(options.map(function (option) { return option.expects; }))).join(" | "), async: false, options: options, message: message, pipe: pipe, _parse: function _parse(input, config) { var _typedResults, _untypedResults; var validResult; var untypedResults; var typedResults; var _iterator33 = _createForOfIteratorHelper(this.options), _step33; try { for (_iterator33.s(); !(_step33 = _iterator33.n()).done;) { var schema = _step33.value; var result = schema._parse(input, config); if (result.typed) { if (!result.issues) { validResult = result; break; } else { typedResults ? typedResults.push(result) : typedResults = [result]; } } else { untypedResults ? untypedResults.push(result) : untypedResults = [result]; } } } catch (err) { _iterator33.e(err); } finally { _iterator33.f(); } if (validResult) { return pipeResult(this, validResult.output, config); } if ((_typedResults = typedResults) !== null && _typedResults !== void 0 && _typedResults.length) { var firstResult = typedResults[0]; return pipeResult(this, firstResult.output, config, // Hint: If there is more than one typed result, we use a general // union issue with subissues because the issues could contradict // each other. typedResults.length === 1 ? firstResult.issues : schemaIssue(this, union, input, config, { reason: "union", issues: subissues(typedResults) }).issues); } if (((_untypedResults = untypedResults) === null || _untypedResults === void 0 ? void 0 : _untypedResults.length) === 1) { return untypedResults[0]; } return schemaIssue(this, union, input, config, { issues: subissues(untypedResults) }); } }; } // src/schemas/unknown/unknown.ts function unknown(pipe) { return { type: "unknown", expects: "unknown", async: false, pipe: pipe, _parse: function _parse(input, conf