@graupl/graupl 1.0.0-beta.47 → 1.0.0-beta.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css/graupl.css +1 -1
- package/dist/css/graupl.css.map +1 -1
- package/dist/css/utilities/block-size.css +2 -0
- package/dist/css/utilities/block-size.css.map +1 -0
- package/dist/css/utilities/clear.css +2 -0
- package/dist/css/utilities/clear.css.map +1 -0
- package/dist/css/utilities/float.css +2 -0
- package/dist/css/utilities/float.css.map +1 -0
- package/dist/css/utilities/inline-size.css +2 -0
- package/dist/css/utilities/inline-size.css.map +1 -0
- package/dist/css/utilities/placement.css +2 -0
- package/dist/css/utilities/placement.css.map +1 -0
- package/dist/css/utilities.css +1 -1
- package/dist/css/utilities.css.map +1 -1
- package/dist/js/accordion.js.map +1 -1
- package/dist/js/alert.js.map +1 -1
- package/dist/js/breadcrumb.js.map +1 -1
- package/dist/js/carousel.js.map +1 -1
- package/dist/js/component/accordion.cjs.js.map +1 -1
- package/dist/js/component/accordion.es.js.map +1 -1
- package/dist/js/component/accordion.iife.js.map +1 -1
- package/dist/js/component/alert.cjs.js.map +1 -1
- package/dist/js/component/alert.es.js.map +1 -1
- package/dist/js/component/alert.iife.js.map +1 -1
- package/dist/js/component/breadcrumb.cjs.js.map +1 -1
- package/dist/js/component/breadcrumb.es.js.map +1 -1
- package/dist/js/component/breadcrumb.iife.js.map +1 -1
- package/dist/js/component/carousel.cjs.js.map +1 -1
- package/dist/js/component/carousel.es.js.map +1 -1
- package/dist/js/component/carousel.iife.js.map +1 -1
- package/dist/js/component/disclosure.cjs.js.map +1 -1
- package/dist/js/component/disclosure.es.js.map +1 -1
- package/dist/js/component/disclosure.iife.js.map +1 -1
- package/dist/js/component/tabs.cjs.js.map +1 -1
- package/dist/js/component/tabs.es.js.map +1 -1
- package/dist/js/component/tabs.iife.js.map +1 -1
- package/dist/js/component/tooltip.cjs.js.map +1 -1
- package/dist/js/component/tooltip.es.js.map +1 -1
- package/dist/js/component/tooltip.iife.js.map +1 -1
- package/dist/js/disclosure.js.map +1 -1
- package/dist/js/generator/accordion.cjs.js.map +1 -1
- package/dist/js/generator/accordion.es.js.map +1 -1
- package/dist/js/generator/accordion.iife.js.map +1 -1
- package/dist/js/generator/alert.cjs.js.map +1 -1
- package/dist/js/generator/alert.es.js.map +1 -1
- package/dist/js/generator/alert.iife.js.map +1 -1
- package/dist/js/generator/breadcrumb.cjs.js.map +1 -1
- package/dist/js/generator/breadcrumb.es.js.map +1 -1
- package/dist/js/generator/breadcrumb.iife.js.map +1 -1
- package/dist/js/generator/carousel.cjs.js.map +1 -1
- package/dist/js/generator/carousel.es.js.map +1 -1
- package/dist/js/generator/carousel.iife.js.map +1 -1
- package/dist/js/generator/disclosure.cjs.js.map +1 -1
- package/dist/js/generator/disclosure.es.js.map +1 -1
- package/dist/js/generator/disclosure.iife.js.map +1 -1
- package/dist/js/generator/navigation.cjs.js.map +1 -1
- package/dist/js/generator/navigation.es.js.map +1 -1
- package/dist/js/generator/navigation.iife.js.map +1 -1
- package/dist/js/generator/tabs.cjs.js.map +1 -1
- package/dist/js/generator/tabs.es.js.map +1 -1
- package/dist/js/generator/tabs.iife.js.map +1 -1
- package/dist/js/generator/tooltip.cjs.js.map +1 -1
- package/dist/js/generator/tooltip.es.js.map +1 -1
- package/dist/js/generator/tooltip.iife.js.map +1 -1
- package/dist/js/graupl.js.map +1 -1
- package/dist/js/navigation.js.map +1 -1
- package/dist/js/storage/initializer.js.map +1 -1
- package/dist/js/storage/storage-manager.cjs.js.map +1 -1
- package/dist/js/storage/storage-manager.es.js.map +1 -1
- package/dist/js/storage/storage-manager.iife.js.map +1 -1
- package/dist/js/tabs.js.map +1 -1
- package/dist/js/tooltip.js.map +1 -1
- package/package.json +1 -1
- package/scss/utilities/block-size.scss +3 -0
- package/scss/utilities/clear.scss +3 -0
- package/scss/utilities/float.scss +3 -0
- package/scss/utilities/inline-size.scss +3 -0
- package/scss/utilities/placement.scss +3 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-manager.iife.js","names":["isValidInstance","contructor","elements","shouldThrow","result","status","errors","elementsType","TypeError","key","elementType","name","error","push","isValidType","type","values","valuesType","valueType","isQuerySelector","Error","document","querySelector","isValidClassList","Array","isArray","forEach","value","obj","isValidState","validStates","includes","join","isValidEvent","validEvents","isValidHoverType","validTypes","isTag","tagName","HTMLElement","tag","toLowerCase","isValidEventType","eventType","component","Object","prototype","hasOwnProperty","call","events","constructor","keys","hasValidRootDOMElement","_dom","_rootDOMElement","isValidType","isValidInstance","StorageManager","_scope","_type","_storage","_crush","constructor","scope","type","crush","initialize","window","storage","shouldThrow","status","get","key","typeCheck","Error","message","keyCheck","set","data","dataCheck","clear","dispose"],"sources":["../../../packages/core/src/js/validate.js","../../../packages/core/src/js/storage/StorageManager.js"],"sourcesContent":["/**\n * @file\n * Validation helper functions.\n */\n\n/* global Component */\n\n/**\n * Check to see if the provided elements have a specific contructor.\n *\n * The values must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * This is essentially just a wrapper function around checking instanceof with\n * more descriptive error message to help debugging.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {object} contructor - The constructor to check for.\n * @param {object} elements - The element(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isValidInstance(\n contructor,\n elements,\n { shouldThrow = true } = {}\n) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (typeof elements !== \"object\") {\n const elementsType = typeof elements;\n\n throw new TypeError(\n `Elements given to isValidInstance() must be inside of an object. \"${elementsType}\" given.`\n );\n }\n\n for (const key in elements) {\n try {\n if (!(elements[key] instanceof contructor)) {\n const elementType = typeof elements[key];\n throw new TypeError(\n `${key} must be an instance of ${contructor.name}. \"${elementType}\" given.`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Check to see if the provided values are of a specific type.\n *\n * The values must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * This is essentially just a wrapper function around checking typeof with\n * more descriptive error message to help debugging.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {string} type - The type to check for.\n * @param {object} values - The value(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isValidType(type, values, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (typeof values !== \"object\") {\n const valuesType = typeof values;\n\n throw new TypeError(\n `Values given to isValidType() must be inside of an object. \"${valuesType}\" given.`\n );\n }\n\n for (const key in values) {\n try {\n const valueType = typeof values[key];\n\n if (valueType !== type) {\n throw new TypeError(\n `${key} must be a ${type}. \"${valueType}\" given.`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Checks to see if the provided values are valid query selectors.\n *\n * The values must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {Object<string>} values - The value(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isQuerySelector(values, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (typeof values !== \"object\") {\n const type = typeof values;\n\n throw new TypeError(\n `Values given to isQuerySelector() must be inside of an object. \"${type}\" given.`\n );\n }\n\n for (const key in values) {\n try {\n try {\n if (values[key] === null) {\n throw new Error();\n }\n\n document.querySelector(values[key]);\n } catch {\n throw new TypeError(\n `${key} must be a valid query selector. \"${values[key]}\" given.`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Checks to see if the provided value is either a string or an array of strings.\n *\n * The values must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {Object<string, string[]>} values - The value(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isValidClassList(values, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (typeof values !== \"object\" || Array.isArray(values)) {\n const type = typeof values;\n\n throw new TypeError(\n `Values given to isValidClassList() must be inside of an object. \"${type}\" given.`\n );\n }\n\n for (const key in values) {\n try {\n const type = typeof values[key];\n\n if (type !== \"string\") {\n if (Array.isArray(values[key])) {\n values[key].forEach((value) => {\n if (typeof value !== \"string\") {\n throw new TypeError(\n `${key} must be a string or an array of strings. An array containing non-strings given.`\n );\n }\n });\n } else {\n throw new TypeError(\n `${key} must be a string or an array of strings. \"${type}\" given.`\n );\n }\n } else {\n const obj = {};\n obj[key] = values[key];\n\n isQuerySelector(obj);\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Check to see if the provided values are valid focus states for a menu.\n *\n * Available states are: `\"none\"`, `\"self\"`, and `\"child\"`.\n *\n * The values must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {Object<string>} values - The value(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isValidState(values, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (typeof values !== \"object\") {\n const type = typeof values;\n\n throw new TypeError(\n `Values given to isValidState() must be inside of an object. \"${type}\" given.`\n );\n }\n\n const validStates = [\"none\", \"self\", \"child\"];\n\n for (const key in values) {\n try {\n if (!validStates.includes(values[key])) {\n throw new TypeError(\n `${key} must be one of the following values: ${validStates.join(\n \", \"\n )}. \"${values[key]}\" given.`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Check to see if the provided values are valid event types for a menu.\n *\n * Available events are: `\"none\"`, `\"mouse\"`, `\"keyboard\"`, and `\"character\"`.\n *\n * The values must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {Object<string>} values - The value(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isValidEvent(values, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (typeof values !== \"object\") {\n const type = typeof values;\n\n throw new TypeError(\n `Values given to isValidEvent() must be inside of an object. \"${type}\" given.`\n );\n }\n\n const validEvents = [\"none\", \"mouse\", \"keyboard\", \"character\"];\n\n for (const key in values) {\n try {\n if (!validEvents.includes(values[key])) {\n throw new TypeError(\n `${key} must be one of the following values: ${validEvents.join(\n \", \"\n )}. \"${values[key]}\" given.`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Check to see if the provided values are valid hover types for a menu.\n *\n * Available types are: `\"off\"`, `\"on\"`, and `\"dynamic\"`.\n *\n * The values must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {Object<string>} values - The value(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isValidHoverType(values, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (typeof values !== \"object\") {\n const type = typeof values;\n\n throw new TypeError(\n `Values given to isValidHoverType() must be inside of an object. \"${type}\" given.`\n );\n }\n\n const validTypes = [\"off\", \"on\", \"dynamic\"];\n\n for (const key in values) {\n try {\n if (!validTypes.includes(values[key])) {\n throw new TypeError(\n `${key} must be one of the following values: ${validTypes.join(\n \", \"\n )}. \"${values[key]}\" given.`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Checks to see if the provided elements are using a specific tag.\n *\n * The elements must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {string} tagName - The name of the tag.\n * @param {Object<HTMLElement>} elements - The element(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isTag(tagName, elements, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (\n isValidType(\"string\", { tagName }, { shouldThrow: true }).status &&\n isValidInstance(HTMLElement, elements, { shouldThrow: true }).status\n ) {\n const tag = tagName.toLowerCase();\n\n for (const key in elements) {\n try {\n if (elements[key].tagName.toLowerCase() !== tag) {\n throw new TypeError(\n `${key} must be a <${tag}> element. <${elements[\n key\n ].tagName.toLowerCase()}> given.`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Check to see if the provided event type is valid for dispatching.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {string} eventType - The event type to check.\n * @param {Component} component - The component to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isValidEventType(\n eventType,\n component,\n { shouldThrow = true } = {}\n) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (!Object.prototype.hasOwnProperty.call(component.events, eventType)) {\n throw new TypeError(\n `Event type \"${eventType}\" is not valid for ${component.constructor.name}. Valid event types are: \"${Object.keys(component.events).join('\", ')}\".`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Check to see if the component has a valid root DOM element.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {Component} component - The component to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow=true] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function hasValidRootDOMElement(component, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n // Check to make sure the root DOM element exists in _dom.\n if (\n !Object.prototype.hasOwnProperty.call(\n component._dom,\n component._rootDOMElement\n )\n ) {\n throw new Error(\n `The root DOM element \"${component._rootDOMElement}\" does not exist in the ${component.constructor.name}'s _dom property. It must be one of the following: \"${Object.keys(\n component._dom\n ).join('\", \"')}\".`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n","/**\n * @file\n * Provides a system to get and store data in the browser.\n */\n\nimport { isValidType, isValidInstance } from \"../validate.js\";\n\n/**\n * Class representing a storage system.\n */\nclass StorageManager {\n /**\n * The scope of the storage.\n *\n * @protected\n *\n * @type {string}\n */\n _scope;\n\n /**\n * The type of storage.\n *\n * @protected\n *\n * @type {string}\n */\n _type = \"_default\";\n\n /**\n * The storage object.\n *\n * @protected\n *\n * @type {object}\n */\n _storage = {};\n\n /**\n * Whether to crush the storage instance if it already exists.\n *\n * @protected\n *\n * @type {boolean}\n */\n _crush = false;\n\n /**\n * Creates a Storage instance.\n *\n * @param {object} [options = {}] - The options for the storage.\n * @param {string} options.scope - The scope of the storage.\n * @param {?string} [options.type = null] - The type of storage.\n * @param {boolean} [options.crush = false] - Whether to crush the storage instance if it already exists.\n * @param {boolean} [options.initialize = true] - Whether to initialize the storage.\n */\n constructor({ scope, type = null, crush = false, initialize = true } = {}) {\n this._scope = scope;\n this._type = type || \"_default\";\n this._crush = crush;\n\n if (initialize) {\n this.initialize();\n }\n }\n\n /**\n * Initialize the storage.\n */\n initialize() {\n // Try to make sure the storage instance won't crush other instances of StorageManager with the same scope.\n try {\n if (!this._crush && typeof window[this.scope] !== \"undefined\") {\n if (\n isValidInstance(\n StorageManager,\n { storage: window[this.scope] },\n { shouldThrow: false }\n ).status ||\n (typeof window[this.scope].storage !== \"undefined\" &&\n typeof window[this.scope].scope !== \"undefined\" &&\n typeof window[this.scope].type !== \"undefined\")\n ) {\n this._storage = window[this.scope].storage;\n }\n }\n } catch {\n // Do nothing.\n } finally {\n window[this.scope] = this;\n }\n }\n\n /**\n * The scope of the storage.\n *\n * @readonly\n *\n * @type {string}\n *\n * @see _scope\n */\n get scope() {\n return this._scope;\n }\n\n /**\n * The type of storage.\n *\n * @type {string}\n *\n * @see _type\n */\n get type() {\n return this._type;\n }\n\n set type(type) {\n if (isValidType(\"string\", { type })) {\n this._type = type;\n }\n }\n\n /**\n * The storage object.\n *\n * @readonly\n *\n * @type {object}\n *\n * @see _storage\n */\n get storage() {\n return this._storage;\n }\n\n /**\n * Get the storage object.\n *\n * @param {object} [options = {}] - The options for getting the storage.\n * @param {string} [options.type = this.type] - The type of storage to get.\n * @param {?string} [options.key = null] - The key to get the value from.\n * @return {object} - The storage object.\n */\n get({ type = this.type, key = null } = {}) {\n const typeCheck = isValidType(\"string\", { type });\n\n if (!typeCheck.status) {\n throw new Error(`StorageManager (${this.scope}): ${typeCheck.message}`);\n }\n\n if (!this.storage[type]) {\n throw new Error(\n `StorageManager (${this.scope}): Type \"${type}\" is not initialized.`\n );\n }\n\n if (key !== null) {\n const keyCheck = isValidType(\"string\", { key });\n\n if (!keyCheck.status) {\n throw new Error(`StorageManager (${this.scope}): ${keyCheck.message}`);\n }\n\n return this.storage[type][key];\n }\n\n return this.storage[type];\n }\n\n /**\n * Set the storage object.\n *\n * @param {object} [options = {}] - The options for setting the storage.\n * @param {string} [options.type = this.type] - The type of storage to set.\n * @param {?string} [options.key = null] - The key to set the value to.\n * @param {object} [options.data = {}] - The data to set.\n */\n set({ type = this.type, key = null, data = {} } = {}) {\n const typeCheck = isValidType(\"string\", { type });\n const dataCheck = isValidType(\"object\", { data });\n\n if (!typeCheck.status) {\n throw new Error(`StorageManager (${this.scope}): ${typeCheck.message}`);\n }\n\n if (!dataCheck.status) {\n throw new Error(`StorageManager (${this.scope}): ${dataCheck.message}`);\n }\n\n if (key !== null) {\n const keyCheck = isValidType(\"string\", { key });\n\n if (!keyCheck.status) {\n throw new Error(`StorageManager (${this.scope}): ${keyCheck.message}`);\n }\n\n if (!this._storage[type]) {\n this._storage[type] = {};\n }\n\n this._storage[type][key] = data;\n } else {\n this._storage[type] = data;\n }\n }\n\n /**\n * Remove a value from the storage object.\n *\n * @param {object} [options = {}] - The options for removing from storage.\n * @param {string} [options.type = this.type] - The type of storage to remove from.\n * @param {?string} [options.key = null] - The key to remove the value from.\n */\n clear({ type = this.type, key = null } = {}) {\n const typeCheck = isValidType(\"string\", { type });\n\n if (!typeCheck.status) {\n throw new Error(`StorageManager (${this.scope}): ${typeCheck.message}`);\n }\n\n if (key !== null) {\n const keyCheck = isValidType(\"string\", { key });\n\n if (!keyCheck.status) {\n throw new Error(`StorageManager (${this.scope}): ${keyCheck.message}`);\n }\n\n delete this.storage[type][key];\n } else {\n delete this.storage[type];\n }\n }\n\n dispose() {\n delete this._storage;\n delete this;\n }\n}\n\nexport default StorageManager;\n"],"mappings":";CAwBA,SAAgBA,EACdC,GACAC,GACA,EAAEC,aAAAA,IAAc,CAAA,MAAS,EAAA,EACzB;EACA,MAAMC,IAAS;GACbC,QAAQ,CAAA;GACRC,QAAQ,EAAA;GAAA;AAGV,MAAI;AACF,OAAI,OAAOJ,KAAa,SAGtB,OAAM,IAAIM,UACR,qEAHmB,OAAON,EAAAA,UAGuD;AAIrF,QAAA,MAAWO,KAAOP,EAChB,KAAI;AACF,QAAI,EAAEA,EAASO,cAAgBR,IAAa;KAC1C,MAAMS,IAAc,OAAOR,EAASO;AACpC,WAAM,IAAID,UACR,GAAGC,EAAAA,0BAA8BR,EAAWU,KAAAA,KAAUD,EAAAA,UAAW;;YAG9DE,GAAO;AACdR,MAAOC,SAAS,CAAA,GAChBD,EAAOE,OAAOO,KAAKD,EAAAA;;WAGhBA,GAAO;AACdR,KAAOC,SAAS,CAAA,GAChBD,EAAOE,OAAOO,KAAKD,EAAAA;;AAGrB,MAAIT,KAAe,CAACC,EAAOC,OACzB,OAAMD,EAAOE,OAAO;AAGtB,SAAOF;;CAoBT,SAAgBU,EAAYC,GAAMC,GAAQ,EAAEb,aAAAA,IAAc,CAAA,MAAS,EAAA,EAAI;EACrE,MAAMC,IAAS;GACbC,QAAQ,CAAA;GACRC,QAAQ,EAAA;GAAA;AAGV,MAAI;AACF,OAAI,OAAOU,KAAW,SAGpB,OAAM,IAAIR,UACR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mBAAmB,KAAKX,MAAAA,KAAWa,EAASD,UAAAA;AAGzD,SAAKf,SAASI,OACjB,KAAKJ,SAASI,KAAQ,EAAA,GAGxB,KAAKJ,SAASI,GAAMQ,KAAOM;SAE3B,MAAKlB,SAASI,KAAQc;;EAW1BE,MAAM,EAAEhB,MAAAA,IAAO,KAAKA,MAAMQ,KAAAA,IAAM,SAAS,EAAA,EAAI;GAC3C,MAAMC,IAAYlB,EAAY,UAAU,EAAES,MAAAA,GAAM,CAAA;AAEhD,OAAI,CAACS,EAAUH,OACb,OAAM,IAAII,MAAM,mBAAmB,KAAKX,MAAAA,KAAWU,EAAUE,UAAAA;AAG/D,OAAIH,MAAQ,MAAM;IAChB,MAAMI,IAAWrB,EAAY,UAAU,EAAEiB,KAAAA,GAAK,CAAA;AAE9C,QAAI,CAACI,EAASN,OACZ,OAAM,IAAII,MAAM,mBAAmB,KAAKX,MAAAA,KAAWa,EAASD,UAAAA;AAG9D,WAAO,KAAKP,QAAQJ,GAAMQ;SAE1B,QAAO,KAAKJ,QAAQJ;;EAIxBiB,UAAU;AACR,UAAO,KAAKrB,UACZ,OAAO;;;IAAA"}
|
|
1
|
+
{"version":3,"file":"storage-manager.iife.js","names":["isValidInstance","contructor","elements","shouldThrow","result","status","errors","elementsType","TypeError","key","elementType","name","error","push","isValidType","type","values","valuesType","valueType","isQuerySelector","Error","document","querySelector","isValidClassList","Array","isArray","forEach","value","obj","isValidState","validStates","includes","join","isValidEvent","validEvents","isValidHoverType","validTypes","isTag","tagName","HTMLElement","tag","toLowerCase","isValidEventType","eventType","component","Object","prototype","hasOwnProperty","call","events","constructor","keys","hasValidRootDOMElement","_dom","_rootDOMElement","isValidType","isValidInstance","StorageManager","_scope","_type","_storage","_crush","constructor","scope","type","crush","initialize","window","storage","shouldThrow","status","get","key","typeCheck","Error","message","keyCheck","set","data","dataCheck","clear","dispose"],"sources":["../../../packages/core/src/js/validate.js","../../../packages/core/src/js/storage/StorageManager.js"],"sourcesContent":["/**\n * @file\n * Validation helper functions.\n */\n\n/* global Component */\n\n/**\n * Check to see if the provided elements have a specific contructor.\n *\n * The values must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * This is essentially just a wrapper function around checking instanceof with\n * more descriptive error message to help debugging.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {object} contructor - The constructor to check for.\n * @param {object} elements - The element(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isValidInstance(\n contructor,\n elements,\n { shouldThrow = true } = {}\n) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (typeof elements !== \"object\") {\n const elementsType = typeof elements;\n\n throw new TypeError(\n `Elements given to isValidInstance() must be inside of an object. \"${elementsType}\" given.`\n );\n }\n\n for (const key in elements) {\n try {\n if (!(elements[key] instanceof contructor)) {\n const elementType = typeof elements[key];\n throw new TypeError(\n `${key} must be an instance of ${contructor.name}. \"${elementType}\" given.`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Check to see if the provided values are of a specific type.\n *\n * The values must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * This is essentially just a wrapper function around checking typeof with\n * more descriptive error message to help debugging.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {string} type - The type to check for.\n * @param {object} values - The value(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isValidType(type, values, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (typeof values !== \"object\") {\n const valuesType = typeof values;\n\n throw new TypeError(\n `Values given to isValidType() must be inside of an object. \"${valuesType}\" given.`\n );\n }\n\n for (const key in values) {\n try {\n const valueType = typeof values[key];\n\n if (valueType !== type) {\n throw new TypeError(\n `${key} must be a ${type}. \"${valueType}\" given.`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Checks to see if the provided values are valid query selectors.\n *\n * The values must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {Object<string>} values - The value(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isQuerySelector(values, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (typeof values !== \"object\") {\n const type = typeof values;\n\n throw new TypeError(\n `Values given to isQuerySelector() must be inside of an object. \"${type}\" given.`\n );\n }\n\n for (const key in values) {\n try {\n try {\n if (values[key] === null) {\n throw new Error();\n }\n\n document.querySelector(values[key]);\n } catch {\n throw new TypeError(\n `${key} must be a valid query selector. \"${values[key]}\" given.`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Checks to see if the provided value is either a string or an array of strings.\n *\n * The values must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {Object<string, string[]>} values - The value(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isValidClassList(values, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (typeof values !== \"object\" || Array.isArray(values)) {\n const type = typeof values;\n\n throw new TypeError(\n `Values given to isValidClassList() must be inside of an object. \"${type}\" given.`\n );\n }\n\n for (const key in values) {\n try {\n const type = typeof values[key];\n\n if (type !== \"string\") {\n if (Array.isArray(values[key])) {\n values[key].forEach((value) => {\n if (typeof value !== \"string\") {\n throw new TypeError(\n `${key} must be a string or an array of strings. An array containing non-strings given.`\n );\n }\n });\n } else {\n throw new TypeError(\n `${key} must be a string or an array of strings. \"${type}\" given.`\n );\n }\n } else {\n const obj = {};\n obj[key] = values[key];\n\n isQuerySelector(obj);\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Check to see if the provided values are valid focus states for a menu.\n *\n * Available states are: `\"none\"`, `\"self\"`, and `\"child\"`.\n *\n * The values must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {Object<string>} values - The value(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isValidState(values, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (typeof values !== \"object\") {\n const type = typeof values;\n\n throw new TypeError(\n `Values given to isValidState() must be inside of an object. \"${type}\" given.`\n );\n }\n\n const validStates = [\"none\", \"self\", \"child\"];\n\n for (const key in values) {\n try {\n if (!validStates.includes(values[key])) {\n throw new TypeError(\n `${key} must be one of the following values: ${validStates.join(\n \", \"\n )}. \"${values[key]}\" given.`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Check to see if the provided values are valid event types for a menu.\n *\n * Available events are: `\"none\"`, `\"mouse\"`, `\"keyboard\"`, and `\"character\"`.\n *\n * The values must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {Object<string>} values - The value(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isValidEvent(values, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (typeof values !== \"object\") {\n const type = typeof values;\n\n throw new TypeError(\n `Values given to isValidEvent() must be inside of an object. \"${type}\" given.`\n );\n }\n\n const validEvents = [\"none\", \"mouse\", \"keyboard\", \"character\"];\n\n for (const key in values) {\n try {\n if (!validEvents.includes(values[key])) {\n throw new TypeError(\n `${key} must be one of the following values: ${validEvents.join(\n \", \"\n )}. \"${values[key]}\" given.`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Check to see if the provided values are valid hover types for a menu.\n *\n * Available types are: `\"off\"`, `\"on\"`, and `\"dynamic\"`.\n *\n * The values must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {Object<string>} values - The value(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isValidHoverType(values, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (typeof values !== \"object\") {\n const type = typeof values;\n\n throw new TypeError(\n `Values given to isValidHoverType() must be inside of an object. \"${type}\" given.`\n );\n }\n\n const validTypes = [\"off\", \"on\", \"dynamic\"];\n\n for (const key in values) {\n try {\n if (!validTypes.includes(values[key])) {\n throw new TypeError(\n `${key} must be one of the following values: ${validTypes.join(\n \", \"\n )}. \"${values[key]}\" given.`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Checks to see if the provided elements are using a specific tag.\n *\n * The elements must be provided inside of an object\n * so the variable name can be retrieved in case of errors.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {string} tagName - The name of the tag.\n * @param {Object<HTMLElement>} elements - The element(s) to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isTag(tagName, elements, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (\n isValidType(\"string\", { tagName }, { shouldThrow: true }).status &&\n isValidInstance(HTMLElement, elements, { shouldThrow: true }).status\n ) {\n const tag = tagName.toLowerCase();\n\n for (const key in elements) {\n try {\n if (elements[key].tagName.toLowerCase() !== tag) {\n throw new TypeError(\n `${key} must be a <${tag}> element. <${elements[\n key\n ].tagName.toLowerCase()}> given.`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n }\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Check to see if the provided event type is valid for dispatching.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {string} eventType - The event type to check.\n * @param {Component} component - The component to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow = true ] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function isValidEventType(\n eventType,\n component,\n { shouldThrow = true } = {}\n) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n if (!Object.prototype.hasOwnProperty.call(component.events, eventType)) {\n throw new TypeError(\n `Event type \"${eventType}\" is not valid for ${component.constructor.name}. Valid event types are: \"${Object.keys(component.events).join('\", ')}\".`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n\n/**\n * Check to see if the component has a valid root DOM element.\n *\n * Will return `{ status: true }` if the check is successful.\n *\n * @param {Component} component - The component to check.\n * @param {object} [options = {}] - Additional options.\n * @param {boolean} [options.shouldThrow=true] - Whether to throw on error or return it.\n * @return {Object<boolean, Error[]>} - The result of the check.\n */\nexport function hasValidRootDOMElement(component, { shouldThrow = true } = {}) {\n const result = {\n status: true,\n errors: [],\n };\n\n try {\n // Check to make sure the root DOM element exists in _dom.\n if (\n !Object.prototype.hasOwnProperty.call(\n component._dom,\n component._rootDOMElement\n )\n ) {\n throw new Error(\n `The root DOM element \"${component._rootDOMElement}\" does not exist in the ${component.constructor.name}'s _dom property. It must be one of the following: \"${Object.keys(\n component._dom\n ).join('\", \"')}\".`\n );\n }\n } catch (error) {\n result.status = false;\n result.errors.push(error);\n }\n\n if (shouldThrow && !result.status) {\n throw result.errors[0];\n }\n\n return result;\n}\n","/**\n * @file\n * Provides a system to get and store data in the browser.\n */\n\nimport { isValidType, isValidInstance } from \"../validate.js\";\n\n/**\n * Class representing a storage system.\n */\nclass StorageManager {\n /**\n * The scope of the storage.\n *\n * @protected\n *\n * @type {string}\n */\n _scope;\n\n /**\n * The type of storage.\n *\n * @protected\n *\n * @type {string}\n */\n _type = \"_default\";\n\n /**\n * The storage object.\n *\n * @protected\n *\n * @type {object}\n */\n _storage = {};\n\n /**\n * Whether to crush the storage instance if it already exists.\n *\n * @protected\n *\n * @type {boolean}\n */\n _crush = false;\n\n /**\n * Creates a Storage instance.\n *\n * @param {object} [options = {}] - The options for the storage.\n * @param {string} options.scope - The scope of the storage.\n * @param {?string} [options.type = null] - The type of storage.\n * @param {boolean} [options.crush = false] - Whether to crush the storage instance if it already exists.\n * @param {boolean} [options.initialize = true] - Whether to initialize the storage.\n */\n constructor({ scope, type = null, crush = false, initialize = true } = {}) {\n this._scope = scope;\n this._type = type || \"_default\";\n this._crush = crush;\n\n if (initialize) {\n this.initialize();\n }\n }\n\n /**\n * Initialize the storage.\n */\n initialize() {\n // Try to make sure the storage instance won't crush other instances of StorageManager with the same scope.\n try {\n if (!this._crush && typeof window[this.scope] !== \"undefined\") {\n if (\n isValidInstance(\n StorageManager,\n { storage: window[this.scope] },\n { shouldThrow: false }\n ).status ||\n (typeof window[this.scope].storage !== \"undefined\" &&\n typeof window[this.scope].scope !== \"undefined\" &&\n typeof window[this.scope].type !== \"undefined\")\n ) {\n this._storage = window[this.scope].storage;\n }\n }\n } catch {\n // Do nothing.\n } finally {\n window[this.scope] = this;\n }\n }\n\n /**\n * The scope of the storage.\n *\n * @readonly\n *\n * @type {string}\n *\n * @see _scope\n */\n get scope() {\n return this._scope;\n }\n\n /**\n * The type of storage.\n *\n * @type {string}\n *\n * @see _type\n */\n get type() {\n return this._type;\n }\n\n set type(type) {\n if (isValidType(\"string\", { type })) {\n this._type = type;\n }\n }\n\n /**\n * The storage object.\n *\n * @readonly\n *\n * @type {object}\n *\n * @see _storage\n */\n get storage() {\n return this._storage;\n }\n\n /**\n * Get the storage object.\n *\n * @param {object} [options = {}] - The options for getting the storage.\n * @param {string} [options.type = this.type] - The type of storage to get.\n * @param {?string} [options.key = null] - The key to get the value from.\n * @return {object} - The storage object.\n */\n get({ type = this.type, key = null } = {}) {\n const typeCheck = isValidType(\"string\", { type });\n\n if (!typeCheck.status) {\n throw new Error(`StorageManager (${this.scope}): ${typeCheck.message}`);\n }\n\n if (!this.storage[type]) {\n throw new Error(\n `StorageManager (${this.scope}): Type \"${type}\" is not initialized.`\n );\n }\n\n if (key !== null) {\n const keyCheck = isValidType(\"string\", { key });\n\n if (!keyCheck.status) {\n throw new Error(`StorageManager (${this.scope}): ${keyCheck.message}`);\n }\n\n return this.storage[type][key];\n }\n\n return this.storage[type];\n }\n\n /**\n * Set the storage object.\n *\n * @param {object} [options = {}] - The options for setting the storage.\n * @param {string} [options.type = this.type] - The type of storage to set.\n * @param {?string} [options.key = null] - The key to set the value to.\n * @param {object} [options.data = {}] - The data to set.\n */\n set({ type = this.type, key = null, data = {} } = {}) {\n const typeCheck = isValidType(\"string\", { type });\n const dataCheck = isValidType(\"object\", { data });\n\n if (!typeCheck.status) {\n throw new Error(`StorageManager (${this.scope}): ${typeCheck.message}`);\n }\n\n if (!dataCheck.status) {\n throw new Error(`StorageManager (${this.scope}): ${dataCheck.message}`);\n }\n\n if (key !== null) {\n const keyCheck = isValidType(\"string\", { key });\n\n if (!keyCheck.status) {\n throw new Error(`StorageManager (${this.scope}): ${keyCheck.message}`);\n }\n\n if (!this._storage[type]) {\n this._storage[type] = {};\n }\n\n this._storage[type][key] = data;\n } else {\n this._storage[type] = data;\n }\n }\n\n /**\n * Remove a value from the storage object.\n *\n * @param {object} [options = {}] - The options for removing from storage.\n * @param {string} [options.type = this.type] - The type of storage to remove from.\n * @param {?string} [options.key = null] - The key to remove the value from.\n */\n clear({ type = this.type, key = null } = {}) {\n const typeCheck = isValidType(\"string\", { type });\n\n if (!typeCheck.status) {\n throw new Error(`StorageManager (${this.scope}): ${typeCheck.message}`);\n }\n\n if (key !== null) {\n const keyCheck = isValidType(\"string\", { key });\n\n if (!keyCheck.status) {\n throw new Error(`StorageManager (${this.scope}): ${keyCheck.message}`);\n }\n\n delete this.storage[type][key];\n } else {\n delete this.storage[type];\n }\n }\n\n dispose() {\n delete this._storage;\n delete this;\n }\n}\n\nexport default StorageManager;\n"],"mappings":";CAwBA,SAAgBA,EACdC,GACAC,GACA,EAAEC,aAAAA,IAAc,CAAA,MAAS,EAAA,EACzB;EACA,MAAMC,IAAS;GACbC,QAAQ,CAAA;GACRC,QAAQ,EAAA;GAAA;EAGV,IAAI;GACF,IAAI,OAAOJ,KAAa,UAGt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