'f'
mh-two-thousand-and-two
2024-04-12 26f2711ef9461961fb953e2b497bd314ef95e345
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
 * customElements.define
 */
(function () {
  const defineProperty = Object.defineProperty
  const createElement = document.createElement
  const classes = new Map()
  const registry = new Map()
 
  if ('customElements' in window && customElements && customElements.define) {
    return
  }
 
  function HTMLBuiltIn () {
    const constructor = this.constructor
    if (!classes.has(constructor)) {
      throw new TypeError('Illegal constructor')
    }
    const is = classes.get(constructor)
    const element = createElement.call(document, is)
    return Object.setPrototypeOf(element, constructor.prototype)
  }
 
  defineProperty(HTMLBuiltIn.prototype = HTMLElement.prototype, 'constructor', {
    value: HTMLBuiltIn
  })
  defineProperty(window, 'HTMLElement', {
    configurable: true,
    value: HTMLBuiltIn
  })
  defineProperty(document, 'createElement', {
    configurable: true,
    value: function value (name, options) {
      const is = options && options.is
      const Class = is ? registry.get(is) : registry.get(name)
      return Class ? new Class() : createElement.call(document, name)
    }
  })
  defineProperty(window, 'customElements', {
    configurable: true,
    value: {
      define: function define (is, Class) {
        if (registry.has(is)) {
          throw new Error('the name "'.concat(is, '" has already been used with this registry'))
        }
        classes.set(Class, is)
        registry.set(is, Class)
      }
    }
  })
})()