refact dir

This commit is contained in:
pengfei.zhou
2019-07-17 10:48:36 +08:00
parent 69108124a0
commit f52bc08895
13 changed files with 355 additions and 2 deletions

View File

@@ -0,0 +1,63 @@
"use strict";
exports.__esModule = true;
/**
* Store color as format AARRGGBB or RRGGBB
*/
var Color = /** @class */ (function () {
function Color(v) {
this._value = 0;
this._value = v;
}
Color.parse = function (str) {
if (!str.startsWith("#")) {
throw new Error("Parse color error with " + str);
}
var val = parseInt(str.substr(1), 16);
if (str.length === 7) {
return new Color(val | 0xff000000);
}
else if (str.length === 9) {
return new Color(val);
}
else {
throw new Error("Parse color error with " + str);
}
};
Color.safeParse = function (str, defVal) {
if (defVal === void 0) { defVal = Color.TRANSPARENT; }
var color = defVal;
try {
color = Color.parse(str);
}
catch (e) {
}
finally {
return color;
}
};
Color.prototype.toModel = function () {
return this._value;
};
Color.TRANSPARENT = new Color(0);
return Color;
}());
exports.Color = Color;
var GradientOrientation;
(function (GradientOrientation) {
/** draw the gradient from the top to the bottom */
GradientOrientation[GradientOrientation["TOP_BOTTOM"] = 0] = "TOP_BOTTOM";
/** draw the gradient from the top-right to the bottom-left */
GradientOrientation[GradientOrientation["TR_BL"] = 1] = "TR_BL";
/** draw the gradient from the right to the left */
GradientOrientation[GradientOrientation["RIGHT_LEFT"] = 2] = "RIGHT_LEFT";
/** draw the gradient from the bottom-right to the top-left */
GradientOrientation[GradientOrientation["BR_TL"] = 3] = "BR_TL";
/** draw the gradient from the bottom to the top */
GradientOrientation[GradientOrientation["BOTTOM_TOP"] = 4] = "BOTTOM_TOP";
/** draw the gradient from the bottom-left to the top-right */
GradientOrientation[GradientOrientation["BL_TR"] = 5] = "BL_TR";
/** draw the gradient from the left to the right */
GradientOrientation[GradientOrientation["LEFT_RIGHT"] = 6] = "LEFT_RIGHT";
/** draw the gradient from the top-left to the bottom-right */
GradientOrientation[GradientOrientation["TL_BR"] = 7] = "TL_BR";
})(GradientOrientation = exports.GradientOrientation || (exports.GradientOrientation = {}));

View File

@@ -0,0 +1,67 @@
import { Modeling } from "./types";
/**
* Store color as format AARRGGBB or RRGGBB
*/
export class Color implements Modeling {
static TRANSPARENT = new Color(0)
_value: number = 0
constructor(v: number) {
this._value = v
}
static parse(str: string) {
if (!str.startsWith("#")) {
throw new Error(`Parse color error with ${str}`)
}
const val = parseInt(str.substr(1), 16)
if (str.length === 7) {
return new Color(val | 0xff000000)
} else if (str.length === 9) {
return new Color(val)
} else {
throw new Error(`Parse color error with ${str}`)
}
}
static safeParse(str: string, defVal: Color = Color.TRANSPARENT) {
let color = defVal
try {
color = Color.parse(str)
} catch (e) {
} finally {
return color
}
}
toModel() {
return this._value
}
}
export enum GradientOrientation {
/** draw the gradient from the top to the bottom */
TOP_BOTTOM = 0,
/** draw the gradient from the top-right to the bottom-left */
TR_BL,
/** draw the gradient from the right to the left */
RIGHT_LEFT,
/** draw the gradient from the bottom-right to the top-left */
BR_TL,
/** draw the gradient from the bottom to the top */
BOTTOM_TOP,
/** draw the gradient from the bottom-left to the top-right */
BL_TR,
/** draw the gradient from the left to the right */
LEFT_RIGHT,
/** draw the gradient from the top-left to the bottom-right */
TL_BR,
}
export interface GradientColor {
start: Color
end: Color
orientation: GradientOrientation
}

View File

@@ -0,0 +1,2 @@
"use strict";
exports.__esModule = true;

View File

@@ -0,0 +1,5 @@
export interface Modeling {
toModel(): Model
}
export type Model = string | number | boolean | Modeling | { [index: string]: Model | undefined }

View File

@@ -0,0 +1,7 @@
"use strict";
exports.__esModule = true;
var __uniqueId__ = 0;
function uniqueId() {
return "__unique_" + __uniqueId__++ + "__";
}
exports.uniqueId = uniqueId;

View File

@@ -0,0 +1,5 @@
let __uniqueId__: number = 0
export function uniqueId() {
return `__unique_${__uniqueId__++}__`;
}