summaryrefslogtreecommitdiff
path: root/packages/webapi/src/lib/CustomElementRegistry.ts
diff options
context:
space:
mode:
authorGravatar Erika <3019731+Princesseuh@users.noreply.github.com> 2023-07-27 18:24:39 +0200
committerGravatar Emanuele Stoppa <my.burning@gmail.com> 2023-08-08 11:01:45 +0100
commit148e61d2492456811f8a3c8daaab1c3429a2ffdc (patch)
tree9cf41624687e5c4f44b41c16895f10c2644caf61 /packages/webapi/src/lib/CustomElementRegistry.ts
parent7d2f311d428e3d1c8c13b9bf2a708d6435713fc2 (diff)
downloadastro-148e61d2492456811f8a3c8daaab1c3429a2ffdc.tar.gz
astro-148e61d2492456811f8a3c8daaab1c3429a2ffdc.tar.zst
astro-148e61d2492456811f8a3c8daaab1c3429a2ffdc.zip
feat: remove webapi in favor of a smaller polyfill (#7840)
* feat: remove webapi in favor of a smaller polyfill * test: remove old test * test: 🤦‍♀️ * chore: changeset
Diffstat (limited to 'packages/webapi/src/lib/CustomElementRegistry.ts')
-rw-r--r--packages/webapi/src/lib/CustomElementRegistry.ts92
1 files changed, 0 insertions, 92 deletions
diff --git a/packages/webapi/src/lib/CustomElementRegistry.ts b/packages/webapi/src/lib/CustomElementRegistry.ts
deleted file mode 100644
index 21f775d5e..000000000
--- a/packages/webapi/src/lib/CustomElementRegistry.ts
+++ /dev/null
@@ -1,92 +0,0 @@
-import * as _ from './utils'
-
-export class CustomElementRegistry {
- /** Defines a new custom element using the given tag name and HTMLElement constructor. */
- define(
- name: string,
- constructor: Function,
- options?: ElementDefinitionOptions
- ) {
- const internals = _.internalsOf<CustomElementRegistryInternals>(
- this,
- 'CustomElementRegistry',
- 'define'
- )
-
- name = String(name)
-
- if (/[A-Z]/.test(name))
- throw new SyntaxError(
- 'Custom element name cannot contain an uppercase ASCII letter'
- )
- if (!/^[a-z]/.test(name))
- throw new SyntaxError(
- 'Custom element name must have a lowercase ASCII letter as its first character'
- )
- if (!/-/.test(name))
- throw new SyntaxError('Custom element name must contain a hyphen')
-
- _.INTERNALS.set(constructor, {
- attributes: {},
- localName: name,
- } as any)
-
- internals.constructorByName.set(name, constructor)
- internals.nameByConstructor.set(constructor, name)
-
- void options
- }
-
- /** Returns the constructor associated with the given tag name. */
- get(name: string) {
- const internals = _.internalsOf<CustomElementRegistryInternals>(
- this,
- 'CustomElementRegistry',
- 'get'
- )
-
- name = String(name).toLowerCase()
-
- return internals.constructorByName.get(name)
- }
-
- getName(constructor: Function) {
- const internals = _.internalsOf<CustomElementRegistryInternals>(
- this,
- 'CustomElementRegistry',
- 'getName'
- )
-
- return internals.nameByConstructor.get(constructor)
- }
-}
-
-_.allowStringTag(CustomElementRegistry)
-
-interface CustomElementRegistryInternals {
- constructorByName: Map<string, Function>
- nameByConstructor: Map<Function, string>
-}
-
-interface ElementDefinitionOptions {
- extends?: string | undefined
-}
-
-export const initCustomElementRegistry = (
- target: Record<any, any>,
- exclude: Set<string>
-) => {
- if (exclude.has('customElements')) return
-
- const CustomElementRegistry =
- target.CustomElementRegistry || globalThis.CustomElementRegistry
-
- const customElements: CustomElementRegistry =
- target.customElements ||
- (target.customElements = new CustomElementRegistry())
-
- _.INTERNALS.set(customElements, {
- constructorByName: new Map(),
- nameByConstructor: new Map(),
- } as CustomElementRegistryInternals)
-}