-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1188@minor: Adds support for Document.adoptedStyleSheets and ShadowR…
…oot.adoptedStyleSheets to Window.getComputedStyle().
- Loading branch information
1 parent
bf76491
commit 805fde6
Showing
10 changed files
with
186 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import IShadowRoot from '../src/nodes/shadow-root/IShadowRoot.js'; | ||
import HTMLElement from '../src/nodes/html-element/HTMLElement.js'; | ||
import CSSStyleSheet from '../src/css/CSSStyleSheet.js'; | ||
|
||
/** | ||
* CustomElement test class. | ||
*/ | ||
export default class AdoptedStyleSheetCustomElement extends HTMLElement { | ||
public static observedAttributesCallCount = 0; | ||
public static shadowRootMode = 'open'; | ||
public changedAttributes: Array<{ | ||
name: string; | ||
oldValue: string | null; | ||
newValue: string | null; | ||
}> = []; | ||
private internalShadowRoot: IShadowRoot; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
constructor() { | ||
super(); | ||
this.internalShadowRoot = this.attachShadow({ | ||
mode: AdoptedStyleSheetCustomElement.shadowRootMode | ||
}); | ||
const styleSheet = new CSSStyleSheet(); | ||
styleSheet.replaceSync(` | ||
:host { | ||
display: block; | ||
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; | ||
} | ||
span { | ||
color: pink; | ||
} | ||
.propKey { | ||
color: yellow; | ||
} | ||
`); | ||
this.internalShadowRoot.adoptedStyleSheets = [styleSheet]; | ||
|
||
// Test to create a node while constructing this node. | ||
this.ownerDocument.createElement('div'); | ||
} | ||
|
||
/** | ||
* Returns a list of observed attributes. | ||
* | ||
* @returns Observered attributes. | ||
*/ | ||
public static get observedAttributes(): string[] { | ||
this.observedAttributesCallCount++; | ||
return ['key1', 'key2']; | ||
} | ||
|
||
/** | ||
* @override | ||
*/ | ||
public attributeChangedCallback(name: string, oldValue: string, newValue: string): void { | ||
this.changedAttributes.push({ name, oldValue, newValue }); | ||
} | ||
|
||
/** | ||
* @override | ||
*/ | ||
public connectedCallback(): void { | ||
this.internalShadowRoot.innerHTML = ` | ||
<div> | ||
<span class="propKey"> | ||
key1 is "${this.getAttribute('key1')}" and key2 is "${this.getAttribute( | ||
'key2' | ||
)}". | ||
</span> | ||
<span class="children">${this.childNodes | ||
.map( | ||
(child) => | ||
'#' + child['nodeType'] + (child['tagName'] || '') + child.textContent | ||
) | ||
.join(', ')}</span> | ||
<span><slot></slot></span> | ||
</div> | ||
`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.