MCPcopy
hub / github.com/vuejs/core / _applyStyles

Method _applyStyles

packages/runtime-dom/src/apiCustomElement.ts:610–657  ·  view source on GitHub ↗
(
    styles: string[] | undefined,
    owner?: ConcreteComponent,
    parentComp?: ConcreteComponent,
  )

Source from the content-addressed store, hash-verified

608 }
609
610 private _applyStyles(
611 styles: string[] | undefined,
612 owner?: ConcreteComponent,
613 parentComp?: ConcreteComponent,
614 ) {
615 if (!styles) return
616 if (owner) {
617 if (owner === this._def || this._styleChildren.has(owner)) {
618 return
619 }
620 this._styleChildren.add(owner)
621 }
622
623 const nonce = this._nonce
624 const root = this.shadowRoot!
625 const insertionAnchor = parentComp
626 ? this._getStyleAnchor(parentComp) || this._getStyleAnchor(this._def)
627 : this._getRootStyleInsertionAnchor(root)
628 let last: HTMLStyleElement | null = null
629 for (let i = styles.length - 1; i >= 0; i--) {
630 const s = document.createElement('style')
631 if (nonce) s.setAttribute('nonce', nonce)
632 s.textContent = styles[i]
633
634 root.insertBefore(s, last || insertionAnchor)
635 last = s
636 if (i === 0) {
637 if (!parentComp) this._styleAnchors.set(this._def, s)
638 if (owner) this._styleAnchors.set(owner, s)
639 }
640
641 // record for HMR
642 if (__DEV__) {
643 if (owner) {
644 if (owner.__hmrId) {
645 if (!this._childStyles) this._childStyles = new Map()
646 let entry = this._childStyles.get(owner.__hmrId)
647 if (!entry) {
648 this._childStyles.set(owner.__hmrId, (entry = []))
649 }
650 entry.push(s)
651 }
652 } else {
653 ;(this._styles || (this._styles = [])).push(s)
654 }
655 }
656 }
657 }
658
659 private _getStyleAnchor(comp?: ConcreteComponent): HTMLStyleElement | null {
660 if (!comp) {

Callers 3

resolveMethod · 0.95
_createVNodeMethod · 0.95
_injectChildStyleMethod · 0.95

Calls 7

_getStyleAnchorMethod · 0.95
hasMethod · 0.80
createElementMethod · 0.80
pushMethod · 0.65
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected