package.index.js.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ssr-dom-shim Show documentation
Show all versions of ssr-dom-shim Show documentation
DOM shim for Lit Server Side Rendering (SSR)
The newest version!
{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAC,oBAAoB,EAAC,MAAM,4BAA4B,CAAC;AAEhE,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,6BAA6B,GAC9B,MAAM,4BAA4B,CAAC;AAEpC,MAAM,UAAU,GAAG,IAAI,OAAO,EAG3B,CAAC;AACJ,MAAM,oBAAoB,GAAG,CAC3B,OAA6C,EAC7C,EAAE;IACF,IAAI,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,2DAA2D;AAC3D,EAAE;AACF,+EAA+E;AAC/E,iCAAiC;AACjC,+EAA+E;AAC/E,sEAAsE;AACtE,0CAA0C;AAC1C,sEAAsE;AACtE,iFAAiF;AACjF,mEAAmE;AACnE,oDAAoD;AACpD,MAAM,WAAW,GAAG,MAAM,OAAO;IAAb;QAOV,qBAAgB,GAA0B,IAAI,CAAC;QAC7C,iBAAY,GAAsB,IAAI,CAAC;QACvC,gBAAW,GAA4B,IAAI,CAAC;IAsExD,CAAC;IA9EC,IAAI,UAAU;QACZ,OAAO,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YACpE,IAAI;YACJ,KAAK;SACN,CAAC,CAAC,CAAC;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IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;gBAC3C,OAAO,CAAC,IAAI,CACV,wCAAwC,IAAI,aAAa;oBACvD,yDAAyD;oBACzD,uDAAuD;oBACvD,gEAAgE;oBAChE,gDAAgD,CACnD,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CACb,yDAAyD;oBACvD,aAAa,IAAI,4CAA4C,CAChE,CAAC;YACJ,CAAC;QACH,CAAC;QACD,mDAAmD;QAClD,IAA0C,CAAC,WAAW,GAAG,IAAI,CAAC;QAC/D,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE;YAC3B,IAAI;YACJ,0EAA0E;YAC1E,oEAAoE;YACpE,gBAAgB;YAChB,EAAE;YACF,iEAAiE;YACjE,yEAAyE;YACzE,0EAA0E;YAC1E,wEAAwE;YACxE,4BAA4B;YAC5B,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,IAAI,EAAE;SAClD,CAAC,CAAC;IACL,CAAC;IAED,GAAG,CAAC,IAAY;QACd,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChD,OAAO,UAAU,EAAE,IAAI,CAAC;IAC1B,CAAC;CACF,CAAC;AACF,MAAM,qCAAqC,GACzC,yBAAmE,CAAC;AACtE,OAAO,EAAC,qCAAqC,IAAI,qBAAqB,EAAC,CAAC;AAExE,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,qCAAqC,EAAE,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\nimport {ElementInternalsShim} from './lib/element-internals.js';\n\nexport {\n ariaMixinAttributes,\n ElementInternals,\n HYDRATE_INTERNALS_ATTR_PREFIX,\n} from './lib/element-internals.js';\n\nconst attributes = new WeakMap<\n InstanceType,\n Map\n>();\nconst attributesForElement = (\n element: InstanceType\n) => {\n let attrs = attributes.get(element);\n if (attrs === undefined) {\n attributes.set(element, (attrs = new Map()));\n }\n return attrs;\n};\n\n// The typings around the exports below are a little funky:\n//\n// 1. We want the `name` of the shim classes to match the real ones at runtime,\n// hence e.g. `class Element`.\n// 2. We can't shadow the global types with a simple class declaration, because\n// then we can't reference the global types for casting, hence e.g.\n// `const ElementShim = class Element`.\n// 3. We want to export the classes typed as the real ones, hence e.g.\n// `const ElementShimWithRealType = ElementShim as object as typeof Element;`.\n// 4. We want the exported names to match the real ones, hence e.g.\n// `export {ElementShimWithRealType as Element}`.\nconst ElementShim = class Element {\n get attributes() {\n return Array.from(attributesForElement(this)).map(([name, value]) => ({\n name,\n value,\n }));\n }\n private __shadowRootMode: null | ShadowRootMode = null;\n protected __shadowRoot: null | ShadowRoot = null;\n protected __internals: null | ElementInternals = null;\n\n get shadowRoot() {\n if (this.__shadowRootMode === 'closed') {\n return null;\n }\n return this.__shadowRoot;\n }\n get localName() {\n return (this.constructor as NamedCustomHTMLElementConstructor).__localName;\n }\n get tagName() {\n return this.localName?.toUpperCase();\n }\n setAttribute(name: string, value: unknown): void {\n // Emulate browser behavior that silently casts all values to string. E.g.\n // `42` becomes `\"42\"` and `{}` becomes `\"[object Object]\"\"`.\n attributesForElement(this).set(name, String(value));\n }\n removeAttribute(name: string) {\n attributesForElement(this).delete(name);\n }\n toggleAttribute(name: string, force?: boolean): boolean {\n // Steps reference https://dom.spec.whatwg.org/#dom-element-toggleattribute\n if (this.hasAttribute(name)) {\n // Step 5\n if (force === undefined || !force) {\n this.removeAttribute(name);\n return false;\n }\n } else {\n // Step 4\n if (force === undefined || force) {\n // Step 4.1\n this.setAttribute(name, '');\n return true;\n } else {\n // Step 4.2\n return false;\n }\n }\n // Step 6\n return true;\n }\n hasAttribute(name: string) {\n return attributesForElement(this).has(name);\n }\n attachShadow(init: ShadowRootInit): ShadowRoot {\n const shadowRoot = {host: this} as object as ShadowRoot;\n this.__shadowRootMode = init.mode;\n if (init && init.mode === 'open') {\n this.__shadowRoot = shadowRoot;\n }\n return shadowRoot;\n }\n attachInternals(): ElementInternals {\n if (this.__internals !== null) {\n throw new Error(\n `Failed to execute 'attachInternals' on 'HTMLElement': ` +\n `ElementInternals for the specified element was already attached.`\n );\n }\n const internals = new ElementInternalsShim(this as unknown as HTMLElement);\n this.__internals = internals;\n return internals as ElementInternals;\n }\n getAttribute(name: string) {\n const value = attributesForElement(this).get(name);\n return value ?? null;\n }\n};\nconst ElementShimWithRealType = ElementShim as object as typeof Element;\nexport {ElementShimWithRealType as Element};\n\nconst HTMLElementShim = class HTMLElement extends ElementShim {};\nconst HTMLElementShimWithRealType =\n HTMLElementShim as object as typeof HTMLElement;\nexport {HTMLElementShimWithRealType as HTMLElement};\n\ninterface CustomHTMLElementConstructor {\n new (): HTMLElement;\n observedAttributes?: string[];\n}\n\ninterface NamedCustomHTMLElementConstructor\n extends CustomHTMLElementConstructor {\n __localName: string;\n}\n\ntype CustomElementRegistration = {\n ctor: {new (): HTMLElement};\n observedAttributes: string[];\n};\n\nconst CustomElementRegistryShim = class CustomElementRegistry {\n private __definitions = new Map();\n\n define(name: string, ctor: CustomHTMLElementConstructor) {\n if (this.__definitions.has(name)) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n `'CustomElementRegistry' already has \"${name}\" defined. ` +\n `This may have been caused by live reload or hot module ` +\n `replacement in which case it can be safely ignored.\\n` +\n `Make sure to test your application with a production build as ` +\n `repeat registrations will throw in production.`\n );\n } else {\n throw new Error(\n `Failed to execute 'define' on 'CustomElementRegistry': ` +\n `the name \"${name}\" has already been used with this registry`\n );\n }\n }\n // Provide tagName and localName for the component.\n (ctor as NamedCustomHTMLElementConstructor).__localName = name;\n this.__definitions.set(name, {\n ctor,\n // Note it's important we read `observedAttributes` in case it is a getter\n // with side-effects, as is the case in Lit, where it triggers class\n // finalization.\n //\n // TODO(aomarks) To be spec compliant, we should also capture the\n // registration-time lifecycle methods like `connectedCallback`. For them\n // to be actually accessible to e.g. the Lit SSR element renderer, though,\n // we'd need to introduce a new API for accessing them (since `get` only\n // returns the constructor).\n observedAttributes: ctor.observedAttributes ?? [],\n });\n }\n\n get(name: string) {\n const definition = this.__definitions.get(name);\n return definition?.ctor;\n }\n};\nconst CustomElementRegistryShimWithRealType =\n CustomElementRegistryShim as object as typeof CustomElementRegistry;\nexport {CustomElementRegistryShimWithRealType as CustomElementRegistry};\n\nexport const customElements = new CustomElementRegistryShimWithRealType();\n"]}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy