(
styles: string[] | undefined,
owner?: ConcreteComponent,
parentComp?: ConcreteComponent,
)
| 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) { |
no test coverage detected