feat(ShadowCss): port implementation from webcomponent.js
This commit is contained in:
committed by
Misko Hevery
parent
89b3995756
commit
d67f0299cd
@@ -4,6 +4,8 @@ import 'dart:html';
|
||||
import 'dart:js' show JsObject, context;
|
||||
|
||||
export 'dart:html' show
|
||||
CssRule,
|
||||
CssKeyframesRule,
|
||||
document,
|
||||
DocumentFragment,
|
||||
Element,
|
||||
@@ -109,6 +111,9 @@ class DOM {
|
||||
if (doc == null) doc = document;
|
||||
return doc.createElement(tagName);
|
||||
}
|
||||
static createTextNode(String text, [HtmlDocument doc = null]) {
|
||||
return new Text(text);
|
||||
}
|
||||
static createScriptTag(String attrName, String attrValue,
|
||||
[HtmlDocument doc = null]) {
|
||||
if (doc == null) doc = document;
|
||||
@@ -183,3 +188,10 @@ class DOM {
|
||||
static bool isElementNode(Node node) =>
|
||||
node.nodeType == Node.ELEMENT_NODE;
|
||||
}
|
||||
|
||||
class CSSRuleWrapper {
|
||||
static isPageRule(CssRule rule) => rule is CssPageRule;
|
||||
static isStyleRule(CssRule rule) => rule is CssStyleRule;
|
||||
static isMediaRule(CssRule rule) => rule is CssMediaRule;
|
||||
static isKeyframesRule(CssRule rule) => rule is CssKeyframesRule;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ export var StyleElement = window.HTMLStyleElement;
|
||||
export var document = window.document;
|
||||
export var location = window.location;
|
||||
export var gc = window.gc ? () => window.gc() : () => null;
|
||||
export var CssRule = window.CSSRule;
|
||||
export var CssKeyframesRule = window.CSSKeyframesRule;
|
||||
|
||||
export class DOM {
|
||||
static query(selector) {
|
||||
@@ -129,6 +131,9 @@ export class DOM {
|
||||
static createElement(tagName, doc=document) {
|
||||
return doc.createElement(tagName);
|
||||
}
|
||||
static createTextNode(text: string, doc=document) {
|
||||
return doc.createTextNode(text);
|
||||
}
|
||||
static createScriptTag(attrName:string, attrValue:string, doc=document) {
|
||||
var el = doc.createElement("SCRIPT");
|
||||
el.setAttribute(attrName, attrValue);
|
||||
@@ -215,3 +220,18 @@ export class DOM {
|
||||
return node.nodeType === Node.ELEMENT_NODE;
|
||||
}
|
||||
}
|
||||
|
||||
export class CSSRuleWrapper {
|
||||
static isPageRule(rule) {
|
||||
return rule.type === CSSRule.PAGE_RULE;
|
||||
}
|
||||
static isStyleRule(rule) {
|
||||
return rule.type === CSSRule.STYLE_RULE;
|
||||
}
|
||||
static isMediaRule(rule) {
|
||||
return rule.type === CSSRule.MEDIA_RULE;
|
||||
}
|
||||
static isKeyframesRule(rule) {
|
||||
return rule.type === CSSRule.KEYFRAMES_RULE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,10 @@ class StringWrapper {
|
||||
return s == s2;
|
||||
}
|
||||
|
||||
static String replace(String s, Pattern from, String replace) {
|
||||
return s.replaceFirst(from, replace);
|
||||
}
|
||||
|
||||
static String replaceAll(String s, RegExp from, String replace) {
|
||||
return s.replaceAll(from, replace);
|
||||
}
|
||||
|
||||
@@ -77,6 +77,14 @@ export class StringWrapper {
|
||||
return s === s2;
|
||||
}
|
||||
|
||||
static replace(s:string, from , replace:string): string {
|
||||
if (typeof(from) === "string") {
|
||||
return s.replace(from, replace);
|
||||
} else {
|
||||
return s.replace(from.single, replace);
|
||||
}
|
||||
}
|
||||
|
||||
static replaceAll(s:string, from:RegExp, replace:string):string {
|
||||
return s.replace(from.multiple, replace);
|
||||
}
|
||||
@@ -91,6 +99,9 @@ export class StringWrapper {
|
||||
|
||||
static replaceAllMapped(s:string, from:RegExp, cb:Function): string {
|
||||
return s.replace(from.multiple, function(...matches) {
|
||||
// Remove offset & string from the result array
|
||||
matches.splice(-2, 2);
|
||||
// The callback receives match, p1, ..., pn
|
||||
return cb(matches);
|
||||
});
|
||||
}
|
||||
@@ -171,7 +182,7 @@ export class NumberWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
var RegExp;
|
||||
export var RegExp;
|
||||
if (assertionsEnabled_) {
|
||||
RegExp = assert.define('RegExp', function(obj) {
|
||||
assert(obj).is(assert.structure({
|
||||
|
||||
Reference in New Issue
Block a user