chore(packaging): move files to match target file structure
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
library angular.core.facade.async;
|
||||
|
||||
import 'dart:async';
|
||||
export 'dart:async' show Future;
|
||||
|
||||
class PromiseWrapper {
|
||||
static Future resolve(obj) => new Future.value(obj);
|
||||
|
||||
static Future reject(obj) => new Future.error(obj);
|
||||
|
||||
static Future<List> all(List<Future> promises) => Future.wait(promises);
|
||||
|
||||
static Future then(Future promise, success(value), Function onError) {
|
||||
if (success == null) return promise.catchError(onError);
|
||||
return promise.then(success, onError: onError);
|
||||
}
|
||||
|
||||
static _Completer completer() => new _Completer(new Completer());
|
||||
|
||||
static void setTimeout(fn(), int millis) {
|
||||
new Timer(new Duration(milliseconds: millis), fn);
|
||||
}
|
||||
}
|
||||
|
||||
class _Completer {
|
||||
final Completer c;
|
||||
|
||||
_Completer(this.c);
|
||||
|
||||
Future get promise => c.future;
|
||||
|
||||
void complete(v) {
|
||||
c.complete(v);
|
||||
}
|
||||
|
||||
void reject(v) {
|
||||
c.completeError(v);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import {int} from 'facade/src/lang';
|
||||
import {List} from 'facade/src/collection';
|
||||
export var Promise = window.Promise;
|
||||
|
||||
export class PromiseWrapper {
|
||||
static resolve(obj):Promise {
|
||||
return Promise.resolve(obj);
|
||||
}
|
||||
|
||||
static reject(obj):Promise {
|
||||
return Promise.reject(obj);
|
||||
}
|
||||
|
||||
static all(promises:List):Promise {
|
||||
if (promises.length == 0) return Promise.resolve([]);
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
static then(promise:Promise, success:Function, rejection:Function):Promise {
|
||||
return promise.then(success, rejection);
|
||||
}
|
||||
|
||||
static completer() {
|
||||
var resolve;
|
||||
var reject;
|
||||
|
||||
var p = new Promise(function(res, rej) {
|
||||
resolve = res;
|
||||
reject = rej;
|
||||
});
|
||||
|
||||
return {
|
||||
promise: p,
|
||||
complete: resolve,
|
||||
reject: reject
|
||||
};
|
||||
}
|
||||
|
||||
static setTimeout(fn:Function, millis:int) {
|
||||
window.setTimeout(fn, millis);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
library facade.collection;
|
||||
|
||||
import 'dart:collection' show HashMap, IterableBase, Iterator;
|
||||
export 'dart:core' show Map, List, Set;
|
||||
import 'dart:math' show max, min;
|
||||
|
||||
class MapIterator extends Iterator<List> {
|
||||
final Iterator _iterator;
|
||||
final Map _map;
|
||||
|
||||
MapIterator(Map map)
|
||||
: _map = map,
|
||||
_iterator = map.keys.iterator;
|
||||
|
||||
bool moveNext() => _iterator.moveNext();
|
||||
|
||||
List get current {
|
||||
return _iterator.current != null
|
||||
? [_iterator.current, _map[_iterator.current]]
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
class IterableMap extends IterableBase<List> {
|
||||
final Map _map;
|
||||
|
||||
IterableMap(Map map) : _map = map;
|
||||
|
||||
Iterator<List> get iterator => new MapIterator(_map);
|
||||
}
|
||||
|
||||
class MapWrapper {
|
||||
static HashMap create() => new HashMap();
|
||||
static HashMap clone(Map m) => new HashMap.from(m);
|
||||
static HashMap createFromStringMap(HashMap m) => m;
|
||||
static HashMap createFromPairs(List pairs) => pairs.fold({}, (m, p) {
|
||||
m[p[0]] = p[1];
|
||||
return m;
|
||||
});
|
||||
static get(Map m, k) => m[k];
|
||||
static void set(Map m, k, v) {
|
||||
m[k] = v;
|
||||
}
|
||||
static contains(Map m, k) => m.containsKey(k);
|
||||
static forEach(Map m, fn(v, k)) {
|
||||
m.forEach((k, v) => fn(v, k));
|
||||
}
|
||||
static int size(Map m) => m.length;
|
||||
static void delete(Map m, k) {
|
||||
m.remove(k);
|
||||
}
|
||||
static void clear(Map m) {
|
||||
m.clear();
|
||||
}
|
||||
static Iterable iterable(Map m) => new IterableMap(m);
|
||||
static Iterable keys(Map m) => m.keys;
|
||||
static Iterable values(Map m) => m.values;
|
||||
}
|
||||
|
||||
// TODO: how to export StringMap=Map as a type?
|
||||
class StringMapWrapper {
|
||||
static HashMap create() => new HashMap();
|
||||
static get(Map map, key) => map[key];
|
||||
static void set(Map map, key, value) {
|
||||
map[key] = value;
|
||||
}
|
||||
static void forEach(Map m, fn(v, k)) {
|
||||
m.forEach((k, v) => fn(v, k));
|
||||
}
|
||||
static bool isEmpty(Map m) => m.isEmpty;
|
||||
}
|
||||
|
||||
class ListWrapper {
|
||||
static List clone(List l) => new List.from(l);
|
||||
static List create() => new List();
|
||||
static List createFixedSize(int size) => new List(size);
|
||||
static get(List m, int k) => m[k];
|
||||
static void set(List m, int k, v) {
|
||||
m[k] = v;
|
||||
}
|
||||
static bool contains(List m, k) => m.contains(k);
|
||||
static List map(list, fn(item)) => list.map(fn).toList();
|
||||
static List filter(List list, bool fn(item)) => list.where(fn).toList();
|
||||
static find(List list, bool fn(item)) =>
|
||||
list.firstWhere(fn, orElse: () => null);
|
||||
static bool any(List list, bool fn(item)) => list.any(fn);
|
||||
static void forEach(Iterable list, fn(item)) {
|
||||
list.forEach(fn);
|
||||
}
|
||||
static reduce(List list, fn(a, b), init) {
|
||||
return list.fold(init, fn);
|
||||
}
|
||||
static first(List list) => list.isEmpty ? null : list.first;
|
||||
static last(List list) => list.isEmpty ? null : list.last;
|
||||
static List reversed(List list) => list.reversed.toList();
|
||||
static void push(List l, e) {
|
||||
l.add(e);
|
||||
}
|
||||
static List concat(List a, List b) {
|
||||
a.addAll(b);
|
||||
return a;
|
||||
}
|
||||
static bool isList(l) => l is List;
|
||||
static void insert(List l, int index, value) {
|
||||
l.insert(index, value);
|
||||
}
|
||||
static void removeAt(List l, int index) {
|
||||
l.removeAt(index);
|
||||
}
|
||||
static void removeAll(List list, List items) {
|
||||
for (var i = 0; i < items.length; ++i) {
|
||||
list.remove(items[i]);
|
||||
}
|
||||
}
|
||||
static bool remove(List list, item) => list.remove(item);
|
||||
static void clear(List l) {
|
||||
l.clear();
|
||||
}
|
||||
static String join(List l, String s) => l.join(s);
|
||||
static bool isEmpty(Iterable list) => list.isEmpty;
|
||||
static void fill(List l, value, [int start = 0, int end]) {
|
||||
// JS semantics
|
||||
// see https://github.com/google/traceur-compiler/blob/81880cd3f17bac7de90a4cd0339e9f1a9f61d24c/src/runtime/polyfills/Array.js#L94
|
||||
int len = l.length;
|
||||
start = start < 0 ? max(len + start, 0) : min(start, len);
|
||||
if (end == null) {
|
||||
end = len;
|
||||
} else {
|
||||
end = end < 0 ? max(len + end, 0) : min(end, len);
|
||||
}
|
||||
l.fillRange(start, end, value);
|
||||
}
|
||||
static bool equals(List a, List b) {
|
||||
if (a.length != b.length) return false;
|
||||
for (var i = 0; i < a.length; ++i) {
|
||||
if (a[i] != b[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool isListLikeIterable(obj) => obj is Iterable;
|
||||
|
||||
void iterateListLike(iter, fn(item)) {
|
||||
assert(iter is Iterable);
|
||||
for (var item in iter) {
|
||||
fn(item);
|
||||
}
|
||||
}
|
||||
|
||||
class SetWrapper {
|
||||
static Set createFromList(List l) => new Set.from(l);
|
||||
static bool has(Set s, key) => s.contains(key);
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
import {int, isJsObject} from 'facade/src/lang';
|
||||
|
||||
export var List = window.Array;
|
||||
export var Map = window.Map;
|
||||
export var Set = window.Set;
|
||||
|
||||
export class MapWrapper {
|
||||
static create():Map { return new Map(); }
|
||||
static clone(m:Map):Map { return new Map(m); }
|
||||
static createFromStringMap(stringMap):Map {
|
||||
var result = MapWrapper.create();
|
||||
for (var prop in stringMap) {
|
||||
MapWrapper.set(result, prop, stringMap[prop]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
static createFromPairs(pairs:List):Map {return new Map(pairs);}
|
||||
static get(m, k) { return m.get(k); }
|
||||
static set(m, k, v) { m.set(k,v); }
|
||||
static contains(m, k) { return m.has(k); }
|
||||
static forEach(m, fn) {
|
||||
m.forEach(fn);
|
||||
}
|
||||
static size(m) {return m.size;}
|
||||
static delete(m, k) { m.delete(k); }
|
||||
static clear(m) { m.clear(); }
|
||||
static iterable(m) { return m; }
|
||||
static keys(m) { return m.keys(); }
|
||||
static values(m) { return m.values(); }
|
||||
}
|
||||
|
||||
// TODO: cannot export StringMap as a type as Dart does not support renaming types...
|
||||
/**
|
||||
* Wraps Javascript Objects
|
||||
*/
|
||||
export class StringMapWrapper {
|
||||
static create():Object {
|
||||
// Note: We are not using Object.create(null) here due to
|
||||
// performance!
|
||||
// http://jsperf.com/ng2-object-create-null
|
||||
return { };
|
||||
}
|
||||
static get(map, key) {
|
||||
return map.hasOwnProperty(key) ? map[key] : undefined;
|
||||
}
|
||||
static set(map, key, value) {
|
||||
map[key] = value;
|
||||
}
|
||||
static isEmpty(map) {
|
||||
for (var prop in map) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static forEach(map, callback) {
|
||||
for (var prop in map) {
|
||||
if (map.hasOwnProperty(prop)) {
|
||||
callback(map[prop], prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static merge(m1, m2) {
|
||||
var m = {};
|
||||
|
||||
for (var attr in m1) {
|
||||
if (m1.hasOwnProperty(attr)){
|
||||
m[attr] = m1[attr];
|
||||
}
|
||||
}
|
||||
|
||||
for (var attr in m2) {
|
||||
if (m2.hasOwnProperty(attr)){
|
||||
m[attr] = m2[attr];
|
||||
}
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
export class ListWrapper {
|
||||
static create():List { return new List(); }
|
||||
static createFixedSize(size):List { return new List(size); }
|
||||
static get(m, k) { return m[k]; }
|
||||
static set(m, k, v) { m[k] = v; }
|
||||
static clone(array:List) {
|
||||
return array.slice(0);
|
||||
}
|
||||
static map(array, fn) {
|
||||
return array.map(fn);
|
||||
}
|
||||
static forEach(array, fn) {
|
||||
for(var p of array) {
|
||||
fn(p);
|
||||
}
|
||||
}
|
||||
static push(array, el) {
|
||||
array.push(el);
|
||||
}
|
||||
static first(array) {
|
||||
if (!array) return null;
|
||||
return array[0];
|
||||
}
|
||||
static last(array) {
|
||||
if (!array || array.length == 0) return null;
|
||||
return array[array.length - 1];
|
||||
}
|
||||
static find(list:List, pred:Function) {
|
||||
for (var i = 0 ; i < list.length; ++i) {
|
||||
if (pred(list[i])) return list[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
static reduce(list:List, fn:Function, init) {
|
||||
return list.reduce(fn, init);
|
||||
}
|
||||
static filter(array, pred:Function) {
|
||||
return array.filter(pred);
|
||||
}
|
||||
static any(list:List, pred:Function) {
|
||||
for (var i = 0 ; i < list.length; ++i) {
|
||||
if (pred(list[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static contains(list:List, el) {
|
||||
return list.indexOf(el) !== -1;
|
||||
}
|
||||
static reversed(array) {
|
||||
var a = ListWrapper.clone(array);
|
||||
return a.reverse();
|
||||
}
|
||||
static concat(a, b) {return a.concat(b);}
|
||||
static isList(list) {
|
||||
return Array.isArray(list);
|
||||
}
|
||||
static insert(list, index:int, value) {
|
||||
list.splice(index, 0, value);
|
||||
}
|
||||
static removeAt(list, index:int) {
|
||||
var res = list[index];
|
||||
list.splice(index, 1);
|
||||
return res;
|
||||
}
|
||||
static removeAll(list, items) {
|
||||
for (var i = 0; i < items.length; ++i) {
|
||||
var index = list.indexOf(items[i]);
|
||||
list.splice(index, 1);
|
||||
}
|
||||
}
|
||||
static remove(list, el): boolean {
|
||||
var index = list.indexOf(el);
|
||||
if (index > -1) {
|
||||
list.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static clear(list) {
|
||||
list.splice(0, list.length);
|
||||
}
|
||||
static join(list, s) {
|
||||
return list.join(s);
|
||||
}
|
||||
static isEmpty(list) {
|
||||
return list.length == 0;
|
||||
}
|
||||
static fill(list:List, value, start:int = 0, end:int = undefined) {
|
||||
list.fill(value, start, end);
|
||||
}
|
||||
static equals(a:List, b:List):boolean {
|
||||
if(a.length != b.length) return false;
|
||||
for (var i = 0; i < a.length; ++i) {
|
||||
if (a[i] !== b[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export function isListLikeIterable(obj):boolean {
|
||||
if (!isJsObject(obj)) return false;
|
||||
return ListWrapper.isList(obj) ||
|
||||
(!(obj instanceof Map) && // JS Map are iterables but return entries as [k, v]
|
||||
Symbol.iterator in obj); // JS Iterable have a Symbol.iterator prop
|
||||
}
|
||||
|
||||
export function iterateListLike(obj, fn:Function) {
|
||||
for (var item of obj) {
|
||||
fn(item);
|
||||
}
|
||||
}
|
||||
|
||||
export class SetWrapper {
|
||||
static createFromList(lst:List) { return new Set(lst); }
|
||||
static has(s:Set, key):boolean { return s.has(key); }
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
library angular.core.facade.dom;
|
||||
|
||||
import 'dart:html';
|
||||
import 'dart:js' show JsObject, context;
|
||||
|
||||
export 'dart:html' show DocumentFragment, Node, Element, TemplateElement, Text, document, location, window;
|
||||
|
||||
// TODO(tbosch): Is there a builtin one? Why is Dart
|
||||
// removing unknown elements by default?
|
||||
class IdentitySanitizer implements NodeTreeSanitizer {
|
||||
void sanitizeTree(Node node) {}
|
||||
}
|
||||
|
||||
final _window = context['window'];
|
||||
final _gc = context['gc'];
|
||||
|
||||
void gc() {
|
||||
if (_gc != null) {
|
||||
_gc.apply(const []);
|
||||
}
|
||||
}
|
||||
|
||||
final identitySanitizer = new IdentitySanitizer();
|
||||
|
||||
class DOM {
|
||||
static query(String selector) => document.querySelector(selector);
|
||||
|
||||
static Element querySelector(el, String selector) =>
|
||||
el.querySelector(selector);
|
||||
|
||||
static ElementList querySelectorAll(el, String selector) =>
|
||||
el.querySelectorAll(selector);
|
||||
|
||||
static void on(EventTarget element, String event, callback(arg)) {
|
||||
// due to https://code.google.com/p/dart/issues/detail?id=17406
|
||||
// addEventListener misses zones so we use element.on.
|
||||
element.on[event].listen(callback);
|
||||
}
|
||||
static void dispatchEvent(EventTarget el, Event evt) {
|
||||
el.dispatchEvent(evt);
|
||||
}
|
||||
static MouseEvent createMouseEvent(String eventType) =>
|
||||
new MouseEvent(eventType, canBubble: true);
|
||||
static createEvent(eventType) =>
|
||||
new Event(eventType, canBubble: true);
|
||||
static String getInnerHTML(Element el) => el.innerHtml;
|
||||
static String getOuterHTML(Element el) => el.outerHtml;
|
||||
static void setInnerHTML(Element el, String value) {
|
||||
el.innerHtml = value;
|
||||
}
|
||||
static Node firstChild(el) => el.firstChild;
|
||||
static Node nextSibling(Node el) => el.nextNode;
|
||||
static Element parentElement(Node el) => el.parent;
|
||||
static List<Node> childNodes(Node el) => el.childNodes;
|
||||
static List childNodesAsList(Node el) => childNodes(el).toList();
|
||||
static void clearNodes(Node el) {
|
||||
el.nodes = const [];
|
||||
}
|
||||
static void appendChild(Node el, Node node) {
|
||||
el.append(node);
|
||||
}
|
||||
static void removeChild(Element el, Node node) {
|
||||
node.remove();
|
||||
}
|
||||
static void insertBefore(Node el, Node node) {
|
||||
el.parentNode.insertBefore(node, el);
|
||||
}
|
||||
static void insertAllBefore(Node el, Iterable<Node> nodes) {
|
||||
el.parentNode.insertAllBefore(nodes, el);
|
||||
}
|
||||
static void insertAfter(Node el, Node node) {
|
||||
el.parentNode.insertBefore(node, el.nextNode);
|
||||
}
|
||||
static String getText(Node el) => el.text;
|
||||
static void setText(Text text, String value) {
|
||||
text.text = value;
|
||||
}
|
||||
static TemplateElement createTemplate(String html) {
|
||||
var t = new TemplateElement();
|
||||
t.setInnerHtml(html, treeSanitizer: identitySanitizer);
|
||||
return t;
|
||||
}
|
||||
static Element createElement(String tagName, [HtmlDocument doc = null]) {
|
||||
if (doc == null) doc = document;
|
||||
return doc.createElement(tagName);
|
||||
}
|
||||
static createScriptTag(String attrName, String attrValue,
|
||||
[HtmlDocument doc = null]) {
|
||||
if (doc == null) doc = document;
|
||||
var el = doc.createElement("SCRIPT");
|
||||
el.setAttribute(attrName, attrValue);
|
||||
return el;
|
||||
}
|
||||
static clone(Node node) => node.clone(true);
|
||||
static bool hasProperty(Element element, String name) =>
|
||||
new JsObject.fromBrowserObject(element).hasProperty(name);
|
||||
static List<Node> getElementsByClassName(Element element, String name) =>
|
||||
element.getElementsByClassName(name);
|
||||
static List<Node> getElementsByTagName(Element element, String name) =>
|
||||
element.querySelectorAll(name);
|
||||
static List<String> classList(Element element) => element.classes.toList();
|
||||
static void addClass(Element element, String classname) {
|
||||
element.classes.add(classname);
|
||||
}
|
||||
static void removeClass(Element element, String classname) {
|
||||
element.classes.remove(classname);
|
||||
}
|
||||
static bool hasClass(Element element, String classname) =>
|
||||
element.classes.contains(classname);
|
||||
|
||||
static String tagName(Element element) => element.tagName;
|
||||
|
||||
static Map<String, String> attributeMap(Element element) =>
|
||||
element.attributes;
|
||||
|
||||
static String getAttribute(Element element, String attribute) =>
|
||||
element.getAttribute(attribute);
|
||||
|
||||
static Node templateAwareRoot(Element el) =>
|
||||
el is TemplateElement ? el.content : el;
|
||||
|
||||
static HtmlDocument createHtmlDocument() =>
|
||||
document.implementation.createHtmlDocument('fakeTitle');
|
||||
|
||||
static HtmlDocument defaultDoc() => document;
|
||||
static bool elementMatches(n, String selector) =>
|
||||
n is Element && n.matches(selector);
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
export var window = frames.window;
|
||||
export var DocumentFragment = window.DocumentFragment;
|
||||
export var Node = window.Node;
|
||||
export var NodeList = window.NodeList;
|
||||
export var Text = window.Text;
|
||||
export var Element = window.HTMLElement;
|
||||
export var TemplateElement = window.HTMLTemplateElement;
|
||||
export var document = window.document;
|
||||
export var location = window.location;
|
||||
export var gc = window.gc ? () => window.gc() : () => null;
|
||||
|
||||
import {List, MapWrapper, ListWrapper} from 'facade/src/collection';
|
||||
|
||||
export class DOM {
|
||||
static query(selector) {
|
||||
return document.querySelector(selector);
|
||||
}
|
||||
static querySelector(el, selector:string):Node {
|
||||
return el.querySelector(selector);
|
||||
}
|
||||
static querySelectorAll(el, selector:string):NodeList {
|
||||
return el.querySelectorAll(selector);
|
||||
}
|
||||
static on(el, evt, listener) {
|
||||
el.addEventListener(evt, listener, false);
|
||||
}
|
||||
static dispatchEvent(el, evt) {
|
||||
el.dispatchEvent(evt);
|
||||
}
|
||||
static createMouseEvent(eventType) {
|
||||
var evt = new MouseEvent(eventType);
|
||||
evt.initEvent(eventType, true, true);
|
||||
return evt;
|
||||
}
|
||||
static createEvent(eventType) {
|
||||
return new Event(eventType, true);
|
||||
}
|
||||
static getInnerHTML(el) {
|
||||
return el.innerHTML;
|
||||
}
|
||||
static getOuterHTML(el) {
|
||||
return el.outerHTML;
|
||||
}
|
||||
static firstChild(el):Node {
|
||||
return el.firstChild;
|
||||
}
|
||||
static nextSibling(el):Node {
|
||||
return el.nextSibling;
|
||||
}
|
||||
static parentElement(el) {
|
||||
return el.parentElement;
|
||||
}
|
||||
static childNodes(el):NodeList {
|
||||
return el.childNodes;
|
||||
}
|
||||
static childNodesAsList(el):List {
|
||||
var childNodes = el.childNodes;
|
||||
var res = ListWrapper.createFixedSize(childNodes.length);
|
||||
for (var i=0; i<childNodes.length; i++) {
|
||||
res[i] = childNodes[i];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
static clearNodes(el) {
|
||||
el.innerHTML = "";
|
||||
}
|
||||
static appendChild(el, node) {
|
||||
el.appendChild(node);
|
||||
}
|
||||
static removeChild(el, node) {
|
||||
el.removeChild(node);
|
||||
}
|
||||
static insertBefore(el, node) {
|
||||
el.parentNode.insertBefore(node, el);
|
||||
}
|
||||
static insertAllBefore(el, nodes) {
|
||||
ListWrapper.forEach(nodes, (n) => {
|
||||
el.parentNode.insertBefore(n, el);
|
||||
});
|
||||
}
|
||||
static insertAfter(el, node) {
|
||||
el.parentNode.insertBefore(node, el.nextSibling);
|
||||
}
|
||||
static setInnerHTML(el, value) {
|
||||
el.innerHTML = value;
|
||||
}
|
||||
static getText(el: Element) {
|
||||
return el.textContent;
|
||||
}
|
||||
static setText(text:Text, value:string) {
|
||||
text.nodeValue = value;
|
||||
}
|
||||
static createTemplate(html) {
|
||||
var t = document.createElement('template');
|
||||
t.innerHTML = html;
|
||||
return t;
|
||||
}
|
||||
static createElement(tagName, doc=document) {
|
||||
return doc.createElement(tagName);
|
||||
}
|
||||
static createScriptTag(attrName:string, attrValue:string, doc=document) {
|
||||
var el = doc.createElement("SCRIPT");
|
||||
el.setAttribute(attrName, attrValue);
|
||||
return el;
|
||||
}
|
||||
static clone(node:Node) {
|
||||
return node.cloneNode(true);
|
||||
}
|
||||
static hasProperty(element:Element, name:string) {
|
||||
return name in element;
|
||||
}
|
||||
static getElementsByClassName(element:Element, name:string) {
|
||||
return element.getElementsByClassName(name);
|
||||
}
|
||||
static getElementsByTagName(element:Element, name:string) {
|
||||
return element.getElementsByTagName(name);
|
||||
}
|
||||
static classList(element:Element):List {
|
||||
return Array.prototype.slice.call(element.classList, 0);
|
||||
}
|
||||
static addClass(element:Element, classname:string) {
|
||||
element.classList.add(classname);
|
||||
}
|
||||
static removeClass(element:Element, classname:string) {
|
||||
element.classList.remove(classname);
|
||||
}
|
||||
static hasClass(element:Element, classname:string) {
|
||||
return element.classList.contains(classname);
|
||||
}
|
||||
static tagName(element:Element):string {
|
||||
return element.tagName;
|
||||
}
|
||||
static attributeMap(element:Element) {
|
||||
var res = MapWrapper.create();
|
||||
var elAttrs = element.attributes;
|
||||
for (var i = 0; i < elAttrs.length; i++) {
|
||||
var attrib = elAttrs[i];
|
||||
MapWrapper.set(res, attrib.name, attrib.value);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
static getAttribute(element:Element, attribute:string) {
|
||||
return element.getAttribute(attribute);
|
||||
}
|
||||
static templateAwareRoot(el:Element):Node {
|
||||
return el instanceof TemplateElement ? el.content : el;
|
||||
}
|
||||
static createHtmlDocument() {
|
||||
return document.implementation.createHTMLDocument();
|
||||
}
|
||||
static defaultDoc() {
|
||||
return document;
|
||||
}
|
||||
static elementMatches(n, selector:string):boolean {
|
||||
return n instanceof Element && n.matches(selector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
library angular.core.facade.lang;
|
||||
|
||||
export 'dart:core' show Type, RegExp;
|
||||
import 'dart:math' as math;
|
||||
|
||||
class Math {
|
||||
static final _random = new math.Random();
|
||||
static int floor(num n) => n.floor();
|
||||
static double random() => _random.nextDouble();
|
||||
}
|
||||
|
||||
class FIELD {
|
||||
final String definition;
|
||||
const FIELD(this.definition);
|
||||
}
|
||||
|
||||
class CONST {
|
||||
const CONST();
|
||||
}
|
||||
class ABSTRACT {
|
||||
const ABSTRACT();
|
||||
}
|
||||
class IMPLEMENTS {
|
||||
final interfaceClass;
|
||||
const IMPLEMENTS(this.interfaceClass);
|
||||
}
|
||||
|
||||
bool isPresent(obj) => obj != null;
|
||||
bool isBlank(obj) => obj == null;
|
||||
bool isString(obj) => obj is String;
|
||||
|
||||
String stringify(obj) => obj.toString();
|
||||
|
||||
class StringWrapper {
|
||||
static String fromCharCode(int code) {
|
||||
return new String.fromCharCode(code);
|
||||
}
|
||||
|
||||
static int charCodeAt(String s, int index) {
|
||||
return s.codeUnitAt(index);
|
||||
}
|
||||
|
||||
static List<String> split(String s, RegExp regExp) {
|
||||
var parts = <String>[];
|
||||
var lastEnd = 0;
|
||||
regExp.allMatches(s).forEach((match) {
|
||||
parts.add(s.substring(lastEnd, match.start));
|
||||
lastEnd = match.end;
|
||||
for (var i = 0; i < match.groupCount; i++) {
|
||||
parts.add(match.group(i + 1));
|
||||
}
|
||||
});
|
||||
parts.add(s.substring(lastEnd));
|
||||
return parts;
|
||||
}
|
||||
|
||||
static bool equals(String s, String s2) {
|
||||
return s == s2;
|
||||
}
|
||||
|
||||
static String replaceAll(String s, RegExp from, String replace) {
|
||||
return s.replaceAll(from, replace);
|
||||
}
|
||||
|
||||
static startsWith(String s, String start) {
|
||||
return s.startsWith(start);
|
||||
}
|
||||
|
||||
static String substring(String s, int start, [int end]) {
|
||||
return s.substring(start, end);
|
||||
}
|
||||
}
|
||||
|
||||
class StringJoiner {
|
||||
final List<String> _parts = <String>[];
|
||||
|
||||
void add(String part) {
|
||||
_parts.add(part);
|
||||
}
|
||||
|
||||
String toString() => _parts.join("");
|
||||
}
|
||||
|
||||
class NumberWrapper {
|
||||
static int parseIntAutoRadix(String text) {
|
||||
return int.parse(text);
|
||||
}
|
||||
|
||||
static int parseInt(String text, int radix) {
|
||||
return int.parse(text, radix: radix);
|
||||
}
|
||||
|
||||
static double parseFloat(String text) {
|
||||
return double.parse(text);
|
||||
}
|
||||
|
||||
static double get NaN => double.NAN;
|
||||
|
||||
static bool isNaN(num value) => value.isNaN;
|
||||
|
||||
static bool isInteger(value) => value is int;
|
||||
}
|
||||
|
||||
class RegExpWrapper {
|
||||
static RegExp create(String regExpStr) {
|
||||
return new RegExp(regExpStr);
|
||||
}
|
||||
static Match firstMatch(RegExp regExp, String input) {
|
||||
return regExp.firstMatch(input);
|
||||
}
|
||||
static Iterator<Match> matcher(RegExp regExp, String input) {
|
||||
return regExp.allMatches(input).iterator;
|
||||
}
|
||||
}
|
||||
|
||||
class RegExpMatcherWrapper {
|
||||
static Match next(Iterator<Match> matcher) {
|
||||
if (matcher.moveNext()) {
|
||||
return matcher.current;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class FunctionWrapper {
|
||||
static apply(Function fn, posArgs) {
|
||||
return Function.apply(fn, posArgs);
|
||||
}
|
||||
}
|
||||
|
||||
class BaseException extends Error {
|
||||
final String message;
|
||||
|
||||
BaseException(this.message);
|
||||
|
||||
String toString() {
|
||||
return this.message;
|
||||
}
|
||||
}
|
||||
|
||||
const _NAN_KEY = const Object();
|
||||
|
||||
// Dart can have identical(str1, str2) == false while str1 == str2
|
||||
bool looseIdentical(a, b) =>
|
||||
a is String && b is String ? a == b : identical(a, b);
|
||||
|
||||
// Dart compare map keys by equality and we can have NaN != NaN
|
||||
dynamic getMapKey(value) {
|
||||
if (value is! num) return value;
|
||||
return value.isNaN ? _NAN_KEY : value;
|
||||
}
|
||||
|
||||
dynamic normalizeBlank(obj) {
|
||||
return isBlank(obj) ? null : obj;
|
||||
}
|
||||
|
||||
bool isJsObject(o) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool assertionsEnabled() {
|
||||
try {
|
||||
assert(false);
|
||||
return false;
|
||||
} catch (e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
import {assert} from 'rtts_assert/rtts_assert';
|
||||
export {proxy} from 'rtts_assert/rtts_assert';
|
||||
|
||||
export var Type = Function;
|
||||
export var Math = window.Math;
|
||||
|
||||
// global assert support, as Dart has it...
|
||||
// TODO: `assert` calls need to be removed in production code!
|
||||
window.assert = assert;
|
||||
|
||||
export class FIELD {
|
||||
constructor(definition) {
|
||||
this.definition = definition;
|
||||
}
|
||||
}
|
||||
|
||||
export class CONST {}
|
||||
export class ABSTRACT {}
|
||||
export class IMPLEMENTS {}
|
||||
|
||||
|
||||
export function isPresent(obj):boolean {
|
||||
return obj !== undefined && obj !== null;
|
||||
}
|
||||
|
||||
export function isBlank(obj):boolean {
|
||||
return obj === undefined || obj === null;
|
||||
}
|
||||
|
||||
export function isString(obj):boolean {
|
||||
return typeof obj === "string";
|
||||
}
|
||||
|
||||
export function stringify(token):string {
|
||||
if (typeof token === 'string') {
|
||||
return token;
|
||||
}
|
||||
|
||||
if (token === undefined || token === null) {
|
||||
return '' + token;
|
||||
}
|
||||
|
||||
if (token.name) {
|
||||
return token.name;
|
||||
}
|
||||
|
||||
return token.toString();
|
||||
}
|
||||
|
||||
export class StringWrapper {
|
||||
static fromCharCode(code:int):string {
|
||||
return String.fromCharCode(code);
|
||||
}
|
||||
|
||||
static charCodeAt(s:string, index:int) {
|
||||
return s.charCodeAt(index);
|
||||
}
|
||||
|
||||
static split(s:string, regExp:RegExp) {
|
||||
return s.split(regExp.multiple);
|
||||
}
|
||||
|
||||
static equals(s:string, s2:string):boolean {
|
||||
return s === s2;
|
||||
}
|
||||
|
||||
static replaceAll(s:string, from:RegExp, replace:string):string {
|
||||
return s.replace(from.multiple, replace);
|
||||
}
|
||||
|
||||
static startsWith(s:string, start:string) {
|
||||
return s.startsWith(start);
|
||||
}
|
||||
|
||||
static substring(s:string, start:int, end:int = undefined) {
|
||||
return s.substring(start, end);
|
||||
}
|
||||
}
|
||||
|
||||
export class StringJoiner {
|
||||
constructor() {
|
||||
this.parts = [];
|
||||
}
|
||||
|
||||
add(part:string) {
|
||||
this.parts.push(part);
|
||||
}
|
||||
|
||||
toString():string {
|
||||
return this.parts.join("");
|
||||
}
|
||||
}
|
||||
|
||||
export class NumberParseError extends Error {
|
||||
constructor(message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class NumberWrapper {
|
||||
static parseIntAutoRadix(text:string):int {
|
||||
var result:int = parseInt(text);
|
||||
if (isNaN(result)) {
|
||||
throw new NumberParseError("Invalid integer literal when parsing " + text);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static parseInt(text:string, radix:int):int {
|
||||
if (radix == 10) {
|
||||
if (/^(\-|\+)?[0-9]+$/.test(text)) {
|
||||
return parseInt(text, radix);
|
||||
}
|
||||
} else if (radix == 16) {
|
||||
if (/^(\-|\+)?[0-9ABCDEFabcdef]+$/.test(text)) {
|
||||
return parseInt(text, radix);
|
||||
}
|
||||
} else {
|
||||
var result:int = parseInt(text, radix);
|
||||
if (!isNaN(result)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
throw new NumberParseError("Invalid integer literal when parsing " + text + " in base " + radix);
|
||||
}
|
||||
|
||||
// TODO: NaN is a valid literal but is returned by parseFloat to indicate an error.
|
||||
static parseFloat(text:string):number {
|
||||
return parseFloat(text);
|
||||
}
|
||||
|
||||
static get NaN():number {
|
||||
return NaN;
|
||||
}
|
||||
|
||||
static isNaN(value):boolean {
|
||||
return isNaN(value);
|
||||
}
|
||||
|
||||
static isInteger(value):boolean {
|
||||
return Number.isInteger(value);
|
||||
}
|
||||
}
|
||||
|
||||
export function int() {};
|
||||
int.assert = function(value) {
|
||||
return value == null || typeof value == 'number' && value === Math.floor(value);
|
||||
}
|
||||
|
||||
export var RegExp = assert.define('RegExp', function(obj) {
|
||||
assert(obj).is(assert.structure({
|
||||
single: window.RegExp,
|
||||
multiple: window.RegExp
|
||||
}));
|
||||
});
|
||||
|
||||
export class RegExpWrapper {
|
||||
static create(regExpStr):RegExp {
|
||||
return {
|
||||
multiple: new window.RegExp(regExpStr, 'g'),
|
||||
single: new window.RegExp(regExpStr)
|
||||
};
|
||||
}
|
||||
static firstMatch(regExp, input) {
|
||||
return input.match(regExp.single);
|
||||
}
|
||||
static matcher(regExp, input) {
|
||||
return {
|
||||
re: regExp.multiple,
|
||||
input: input
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class RegExpMatcherWrapper {
|
||||
static next(matcher) {
|
||||
return matcher.re.exec(matcher.input);
|
||||
}
|
||||
}
|
||||
|
||||
export class FunctionWrapper {
|
||||
static apply(fn:Function, posArgs) {
|
||||
return fn.apply(null, posArgs);
|
||||
}
|
||||
}
|
||||
|
||||
// No subclass so that we preserve error stack.
|
||||
export var BaseException = Error;
|
||||
|
||||
// JS has NaN !== NaN
|
||||
export function looseIdentical(a, b):boolean {
|
||||
return a === b ||
|
||||
typeof a === "number" && typeof b === "number" && isNaN(a) && isNaN(b);
|
||||
}
|
||||
|
||||
// JS considers NaN is the same as NaN for map Key (while NaN !== NaN otherwise)
|
||||
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
|
||||
export function getMapKey(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
export function normalizeBlank(obj) {
|
||||
return isBlank(obj) ? null : obj;
|
||||
}
|
||||
|
||||
export function isJsObject(o):boolean {
|
||||
return o !== null && (typeof o === "function" || typeof o === "object");
|
||||
}
|
||||
|
||||
export function assertionsEnabled():boolean {
|
||||
try {
|
||||
var x:int = "string";
|
||||
return false;
|
||||
} catch (e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export function print(obj) {
|
||||
console.log(obj);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
library angular.core.facade.math;
|
||||
|
||||
import 'dart:math' as math;
|
||||
|
||||
class Math {
|
||||
static num pow(num x, num exponent) {
|
||||
return math.pow(x, exponent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export var Math = window.Math;
|
||||
Reference in New Issue
Block a user