@idraw/util 0.3.0 → 0.4.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.d.ts +26 -71
- package/dist/esm/index.js +26 -29
- package/dist/esm/lib/canvas.d.ts +15 -0
- package/dist/esm/lib/canvas.js +36 -0
- package/dist/esm/lib/check.d.ts +8 -8
- package/dist/esm/lib/check.js +32 -33
- package/dist/esm/lib/color.d.ts +1 -0
- package/dist/esm/lib/color.js +152 -1
- package/dist/esm/lib/context2d.d.ts +75 -0
- package/dist/esm/lib/context2d.js +226 -0
- package/dist/esm/lib/controller.d.ts +6 -0
- package/dist/esm/lib/controller.js +99 -0
- package/dist/esm/lib/data.d.ts +5 -1
- package/dist/esm/lib/data.js +67 -2
- package/dist/esm/lib/element.d.ts +18 -0
- package/dist/esm/lib/element.js +241 -0
- package/dist/esm/lib/event.d.ts +9 -0
- package/dist/esm/lib/event.js +50 -0
- package/dist/esm/lib/html.d.ts +3 -0
- package/dist/esm/lib/html.js +170 -0
- package/dist/esm/lib/image.d.ts +4 -0
- package/dist/esm/lib/image.js +27 -0
- package/dist/esm/lib/is.d.ts +4 -2
- package/dist/esm/lib/is.js +34 -15
- package/dist/esm/lib/istype.d.ts +1 -2
- package/dist/esm/lib/istype.js +3 -4
- package/dist/esm/lib/{loader.js → load.js} +2 -2
- package/dist/esm/lib/middleware.d.ts +3 -0
- package/dist/esm/lib/middleware.js +22 -0
- package/dist/esm/lib/number.d.ts +3 -0
- package/dist/esm/lib/number.js +4 -0
- package/dist/esm/lib/parser.js +4 -1
- package/dist/esm/lib/point.d.ts +8 -0
- package/dist/esm/lib/point.js +30 -0
- package/dist/esm/lib/rect.d.ts +2 -0
- package/dist/esm/lib/rect.js +11 -0
- package/dist/esm/lib/rotate.d.ts +13 -0
- package/dist/esm/lib/rotate.js +205 -0
- package/dist/esm/lib/store.d.ts +12 -0
- package/dist/esm/lib/store.js +22 -0
- package/dist/esm/lib/svg-path.d.ts +10 -0
- package/dist/esm/lib/svg-path.js +36 -0
- package/dist/esm/lib/uuid.d.ts +2 -0
- package/dist/esm/lib/uuid.js +27 -2
- package/dist/esm/lib/vertex.d.ts +10 -0
- package/dist/esm/lib/vertex.js +73 -0
- package/dist/esm/lib/view-calc.d.ts +49 -0
- package/dist/esm/lib/view-calc.js +167 -0
- package/dist/index.global.js +1706 -330
- package/dist/index.global.min.js +1 -1
- package/package.json +4 -4
- package/LICENSE +0 -21
- package/dist/esm/lib/context.d.ts +0 -80
- package/dist/esm/lib/context.js +0 -194
- /package/dist/esm/lib/{loader.d.ts → load.d.ts} +0 -0
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,71 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
html: (value: any) => boolean;
|
|
28
|
-
text: (value: any) => boolean;
|
|
29
|
-
fontSize: (value: any) => boolean;
|
|
30
|
-
lineHeight: (value: any) => boolean;
|
|
31
|
-
textAlign: (value: any) => boolean;
|
|
32
|
-
fontFamily: (value: any) => boolean;
|
|
33
|
-
fontWeight: (value: any) => boolean;
|
|
34
|
-
strokeWidth: (value: any) => boolean;
|
|
35
|
-
};
|
|
36
|
-
check: {
|
|
37
|
-
attrs: (attrs: any) => boolean;
|
|
38
|
-
textDesc: (desc: any) => boolean;
|
|
39
|
-
rectDesc: (desc: any) => boolean;
|
|
40
|
-
circleDesc: (desc: any) => boolean;
|
|
41
|
-
imageDesc: (desc: any) => boolean;
|
|
42
|
-
svgDesc: (desc: any) => boolean;
|
|
43
|
-
htmlDesc: (desc: any) => boolean;
|
|
44
|
-
};
|
|
45
|
-
delay: typeof delay;
|
|
46
|
-
compose: typeof compose;
|
|
47
|
-
throttle: typeof throttle;
|
|
48
|
-
loadImage: typeof loadImage;
|
|
49
|
-
loadSVG: typeof loadSVG;
|
|
50
|
-
loadHTML: typeof loadHTML;
|
|
51
|
-
downloadImageFromCanvas: typeof downloadImageFromCanvas;
|
|
52
|
-
toColorHexStr: typeof toColorHexStr;
|
|
53
|
-
toColorHexNum: typeof toColorHexNum;
|
|
54
|
-
isColorStr: typeof isColorStr;
|
|
55
|
-
createUUID: typeof createUUID;
|
|
56
|
-
istype: {
|
|
57
|
-
type(data: any, lowerCase?: boolean | undefined): string;
|
|
58
|
-
array(data: any): boolean;
|
|
59
|
-
json(data: any): boolean;
|
|
60
|
-
function(data: any): boolean;
|
|
61
|
-
asyncFunction(data: any): boolean;
|
|
62
|
-
string(data: any): boolean;
|
|
63
|
-
number(data: any): boolean;
|
|
64
|
-
undefined(data: any): boolean;
|
|
65
|
-
null(data: any): boolean;
|
|
66
|
-
promise(data: any): boolean;
|
|
67
|
-
};
|
|
68
|
-
deepClone: typeof deepClone;
|
|
69
|
-
Context: typeof Context;
|
|
70
|
-
};
|
|
71
|
-
export default _default;
|
|
1
|
+
export { delay, compose, throttle } from './lib/time';
|
|
2
|
+
export { downloadImageFromCanvas } from './lib/file';
|
|
3
|
+
export { toColorHexStr, toColorHexNum, isColorStr, colorNameToHex } from './lib/color';
|
|
4
|
+
export { createUUID, isAssetId, createAssetId } from './lib/uuid';
|
|
5
|
+
export { deepClone, sortDataAsserts } from './lib/data';
|
|
6
|
+
export { istype } from './lib/istype';
|
|
7
|
+
export { loadImage, loadSVG, loadHTML } from './lib/load';
|
|
8
|
+
export { is } from './lib/is';
|
|
9
|
+
export { check } from './lib/check';
|
|
10
|
+
export { createBoardContexts, createContext2D, createOffscreenContext2D } from './lib/canvas';
|
|
11
|
+
export { EventEmitter } from './lib/event';
|
|
12
|
+
export { calcDistance, calcSpeed, equalPoint, equalTouchPoint, vaildPoint, vaildTouchPoint, getCenterFromTwoPoints } from './lib/point';
|
|
13
|
+
export { Store } from './lib/store';
|
|
14
|
+
export { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from './lib/middleware';
|
|
15
|
+
export { Context2D } from './lib/context2d';
|
|
16
|
+
export { rotateElement, parseRadianToAngle, parseAngleToRadian, rotateElementVertexes, getElementRotateVertexes, calcElementCenter, calcElementCenterFromVertexes, rotatePointInGroup, limitAngle } from './lib/rotate';
|
|
17
|
+
export { getSelectedElementUUIDs, validateElements, calcElementsContextSize, calcElementsViewInfo, getElemenetsAssetIds, findElementFromList, findElementsFromList, updateElementInList, getGroupQueueFromList } from './lib/element';
|
|
18
|
+
export { checkRectIntersect } from './lib/rect';
|
|
19
|
+
export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView } from './lib/view-calc';
|
|
20
|
+
export { rotatePoint, rotateVertexes } from './lib/rotate';
|
|
21
|
+
export { getElementVertexes, calcElementVertexesInGroup, calcElementVertexesQueueInGroup, calcElementQueueVertexesQueueInGroup } from './lib/vertex';
|
|
22
|
+
export { calcElementSizeController } from './lib/controller';
|
|
23
|
+
export { generateSVGPath, parseSVGPath } from './lib/svg-path';
|
|
24
|
+
export { generateHTML, parseHTML } from './lib/html';
|
|
25
|
+
export { compressImage } from './lib/image';
|
|
26
|
+
export { formatNumber } from './lib/number';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
deepClone,
|
|
28
|
-
Context
|
|
29
|
-
};
|
|
1
|
+
export { delay, compose, throttle } from './lib/time';
|
|
2
|
+
export { downloadImageFromCanvas } from './lib/file';
|
|
3
|
+
export { toColorHexStr, toColorHexNum, isColorStr, colorNameToHex } from './lib/color';
|
|
4
|
+
export { createUUID, isAssetId, createAssetId } from './lib/uuid';
|
|
5
|
+
export { deepClone, sortDataAsserts } from './lib/data';
|
|
6
|
+
export { istype } from './lib/istype';
|
|
7
|
+
export { loadImage, loadSVG, loadHTML } from './lib/load';
|
|
8
|
+
export { is } from './lib/is';
|
|
9
|
+
export { check } from './lib/check';
|
|
10
|
+
export { createBoardContexts, createContext2D, createOffscreenContext2D } from './lib/canvas';
|
|
11
|
+
export { EventEmitter } from './lib/event';
|
|
12
|
+
export { calcDistance, calcSpeed, equalPoint, equalTouchPoint, vaildPoint, vaildTouchPoint, getCenterFromTwoPoints } from './lib/point';
|
|
13
|
+
export { Store } from './lib/store';
|
|
14
|
+
export { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from './lib/middleware';
|
|
15
|
+
export { Context2D } from './lib/context2d';
|
|
16
|
+
export { rotateElement, parseRadianToAngle, parseAngleToRadian, rotateElementVertexes, getElementRotateVertexes, calcElementCenter, calcElementCenterFromVertexes, rotatePointInGroup, limitAngle } from './lib/rotate';
|
|
17
|
+
export { getSelectedElementUUIDs, validateElements, calcElementsContextSize, calcElementsViewInfo, getElemenetsAssetIds, findElementFromList, findElementsFromList, updateElementInList, getGroupQueueFromList } from './lib/element';
|
|
18
|
+
export { checkRectIntersect } from './lib/rect';
|
|
19
|
+
export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView } from './lib/view-calc';
|
|
20
|
+
export { rotatePoint, rotateVertexes } from './lib/rotate';
|
|
21
|
+
export { getElementVertexes, calcElementVertexesInGroup, calcElementVertexesQueueInGroup, calcElementQueueVertexesQueueInGroup } from './lib/vertex';
|
|
22
|
+
export { calcElementSizeController } from './lib/controller';
|
|
23
|
+
export { generateSVGPath, parseSVGPath } from './lib/svg-path';
|
|
24
|
+
export { generateHTML, parseHTML } from './lib/html';
|
|
25
|
+
export { compressImage } from './lib/image';
|
|
26
|
+
export { formatNumber } from './lib/number';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ViewContent } from '@idraw/types';
|
|
2
|
+
import { Context2D } from './context2d';
|
|
3
|
+
export declare function createContext2D(opts: {
|
|
4
|
+
ctx?: CanvasRenderingContext2D;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
devicePixelRatio: number;
|
|
8
|
+
}): Context2D;
|
|
9
|
+
export declare function createOffscreenContext2D(opts: {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}): CanvasRenderingContext2D | OffscreenRenderingContext;
|
|
13
|
+
export declare function createBoardContexts(ctx: CanvasRenderingContext2D, opts?: {
|
|
14
|
+
devicePixelRatio: number;
|
|
15
|
+
}): ViewContent;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Context2D } from './context2d';
|
|
2
|
+
export function createContext2D(opts) {
|
|
3
|
+
const { width, height, ctx, devicePixelRatio } = opts;
|
|
4
|
+
let context = ctx;
|
|
5
|
+
if (!context) {
|
|
6
|
+
const canvas = document.createElement('canvas');
|
|
7
|
+
canvas.width = width * devicePixelRatio;
|
|
8
|
+
canvas.height = height * devicePixelRatio;
|
|
9
|
+
context = canvas.getContext('2d');
|
|
10
|
+
}
|
|
11
|
+
const context2d = new Context2D(context, opts);
|
|
12
|
+
return context2d;
|
|
13
|
+
}
|
|
14
|
+
export function createOffscreenContext2D(opts) {
|
|
15
|
+
const { width, height } = opts;
|
|
16
|
+
const offCanvas = new OffscreenCanvas(width, height);
|
|
17
|
+
const offRenderCtx = offCanvas.getContext('2d');
|
|
18
|
+
const offCtx = offRenderCtx.canvas.getContext('2d');
|
|
19
|
+
return offCtx;
|
|
20
|
+
}
|
|
21
|
+
export function createBoardContexts(ctx, opts) {
|
|
22
|
+
const ctxOpts = {
|
|
23
|
+
width: ctx.canvas.width,
|
|
24
|
+
height: ctx.canvas.height,
|
|
25
|
+
devicePixelRatio: (opts === null || opts === void 0 ? void 0 : opts.devicePixelRatio) || 1
|
|
26
|
+
};
|
|
27
|
+
const viewContext = createContext2D(ctxOpts);
|
|
28
|
+
const helperContext = createContext2D(ctxOpts);
|
|
29
|
+
const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
|
|
30
|
+
const content = {
|
|
31
|
+
viewContext,
|
|
32
|
+
helperContext,
|
|
33
|
+
boardContext
|
|
34
|
+
};
|
|
35
|
+
return content;
|
|
36
|
+
}
|
package/dist/esm/lib/check.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
declare function attrs(attrs: any): boolean;
|
|
2
|
-
declare function rectDesc(
|
|
3
|
-
declare function circleDesc(
|
|
4
|
-
declare function imageDesc(
|
|
5
|
-
declare function svgDesc(
|
|
6
|
-
declare function htmlDesc(
|
|
7
|
-
declare function textDesc(
|
|
8
|
-
declare const check: {
|
|
2
|
+
declare function rectDesc(detail: any): boolean;
|
|
3
|
+
declare function circleDesc(detail: any): boolean;
|
|
4
|
+
declare function imageDesc(detail: any): boolean;
|
|
5
|
+
declare function svgDesc(detail: any): boolean;
|
|
6
|
+
declare function htmlDesc(detail: any): boolean;
|
|
7
|
+
declare function textDesc(detail: any): boolean;
|
|
8
|
+
export declare const check: {
|
|
9
9
|
attrs: typeof attrs;
|
|
10
10
|
textDesc: typeof textDesc;
|
|
11
11
|
rectDesc: typeof rectDesc;
|
|
@@ -14,4 +14,4 @@ declare const check: {
|
|
|
14
14
|
svgDesc: typeof svgDesc;
|
|
15
15
|
htmlDesc: typeof htmlDesc;
|
|
16
16
|
};
|
|
17
|
-
export
|
|
17
|
+
export {};
|
package/dist/esm/lib/check.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import is from './is';
|
|
1
|
+
import { is } from './is';
|
|
2
2
|
function attrs(attrs) {
|
|
3
3
|
const { x, y, w, h, angle } = attrs;
|
|
4
4
|
if (!(is.x(x) && is.y(y) && is.w(w) && is.h(h) && is.angle(angle))) {
|
|
@@ -9,65 +9,65 @@ function attrs(attrs) {
|
|
|
9
9
|
}
|
|
10
10
|
return true;
|
|
11
11
|
}
|
|
12
|
-
function box(
|
|
13
|
-
const { borderColor, borderRadius, borderWidth } =
|
|
14
|
-
if (
|
|
12
|
+
function box(detail = {}) {
|
|
13
|
+
const { borderColor, borderRadius, borderWidth } = detail;
|
|
14
|
+
if (detail.hasOwnProperty('borderColor') && !is.color(borderColor)) {
|
|
15
15
|
return false;
|
|
16
16
|
}
|
|
17
|
-
if (
|
|
17
|
+
if (detail.hasOwnProperty('borderRadius') && !is.number(borderRadius)) {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
|
-
if (
|
|
20
|
+
if (detail.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
return true;
|
|
24
24
|
}
|
|
25
|
-
function rectDesc(
|
|
26
|
-
const {
|
|
27
|
-
if (
|
|
25
|
+
function rectDesc(detail) {
|
|
26
|
+
const { background } = detail;
|
|
27
|
+
if (detail.hasOwnProperty('background') && !is.color(background)) {
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
|
-
if (!box(
|
|
30
|
+
if (!box(detail)) {
|
|
31
31
|
return false;
|
|
32
32
|
}
|
|
33
33
|
return true;
|
|
34
34
|
}
|
|
35
|
-
function circleDesc(
|
|
36
|
-
const {
|
|
37
|
-
if (
|
|
35
|
+
function circleDesc(detail) {
|
|
36
|
+
const { background, borderColor, borderWidth } = detail;
|
|
37
|
+
if (detail.hasOwnProperty('background') && !is.color(background)) {
|
|
38
38
|
return false;
|
|
39
39
|
}
|
|
40
|
-
if (
|
|
40
|
+
if (detail.hasOwnProperty('borderColor') && !is.color(borderColor)) {
|
|
41
41
|
return false;
|
|
42
42
|
}
|
|
43
|
-
if (
|
|
43
|
+
if (detail.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
|
|
44
44
|
return false;
|
|
45
45
|
}
|
|
46
46
|
return true;
|
|
47
47
|
}
|
|
48
|
-
function imageDesc(
|
|
49
|
-
const { src } =
|
|
48
|
+
function imageDesc(detail) {
|
|
49
|
+
const { src } = detail;
|
|
50
50
|
if (!is.imageSrc(src)) {
|
|
51
51
|
return false;
|
|
52
52
|
}
|
|
53
53
|
return true;
|
|
54
54
|
}
|
|
55
|
-
function svgDesc(
|
|
56
|
-
const { svg } =
|
|
55
|
+
function svgDesc(detail) {
|
|
56
|
+
const { svg } = detail;
|
|
57
57
|
if (!is.svg(svg)) {
|
|
58
58
|
return false;
|
|
59
59
|
}
|
|
60
60
|
return true;
|
|
61
61
|
}
|
|
62
|
-
function htmlDesc(
|
|
63
|
-
const { html } =
|
|
62
|
+
function htmlDesc(detail) {
|
|
63
|
+
const { html } = detail;
|
|
64
64
|
if (!is.html(html)) {
|
|
65
65
|
return false;
|
|
66
66
|
}
|
|
67
67
|
return true;
|
|
68
68
|
}
|
|
69
|
-
function textDesc(
|
|
70
|
-
const { text, color, fontSize, lineHeight, fontFamily, textAlign, fontWeight,
|
|
69
|
+
function textDesc(detail) {
|
|
70
|
+
const { text, color, fontSize, lineHeight, fontFamily, textAlign, fontWeight, background, strokeWidth, strokeColor } = detail;
|
|
71
71
|
if (!is.text(text)) {
|
|
72
72
|
return false;
|
|
73
73
|
}
|
|
@@ -77,33 +77,33 @@ function textDesc(desc) {
|
|
|
77
77
|
if (!is.fontSize(fontSize)) {
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
|
-
if (
|
|
80
|
+
if (detail.hasOwnProperty('background') && !is.color(background)) {
|
|
81
81
|
return false;
|
|
82
82
|
}
|
|
83
|
-
if (
|
|
83
|
+
if (detail.hasOwnProperty('fontWeight') && !is.fontWeight(fontWeight)) {
|
|
84
84
|
return false;
|
|
85
85
|
}
|
|
86
|
-
if (
|
|
86
|
+
if (detail.hasOwnProperty('lineHeight') && !is.lineHeight(lineHeight)) {
|
|
87
87
|
return false;
|
|
88
88
|
}
|
|
89
|
-
if (
|
|
89
|
+
if (detail.hasOwnProperty('fontFamily') && !is.fontFamily(fontFamily)) {
|
|
90
90
|
return false;
|
|
91
91
|
}
|
|
92
|
-
if (
|
|
92
|
+
if (detail.hasOwnProperty('textAlign') && !is.textAlign(textAlign)) {
|
|
93
93
|
return false;
|
|
94
94
|
}
|
|
95
|
-
if (
|
|
95
|
+
if (detail.hasOwnProperty('strokeWidth') && !is.strokeWidth(strokeWidth)) {
|
|
96
96
|
return false;
|
|
97
97
|
}
|
|
98
|
-
if (
|
|
98
|
+
if (detail.hasOwnProperty('strokeColor') && !is.color(strokeColor)) {
|
|
99
99
|
return false;
|
|
100
100
|
}
|
|
101
|
-
if (!box(
|
|
101
|
+
if (!box(detail)) {
|
|
102
102
|
return false;
|
|
103
103
|
}
|
|
104
104
|
return true;
|
|
105
105
|
}
|
|
106
|
-
const check = {
|
|
106
|
+
export const check = {
|
|
107
107
|
attrs,
|
|
108
108
|
textDesc,
|
|
109
109
|
rectDesc,
|
|
@@ -112,4 +112,3 @@ const check = {
|
|
|
112
112
|
svgDesc,
|
|
113
113
|
htmlDesc
|
|
114
114
|
};
|
|
115
|
-
export default check;
|
package/dist/esm/lib/color.d.ts
CHANGED
package/dist/esm/lib/color.js
CHANGED
|
@@ -5,5 +5,156 @@ export function toColorHexStr(color) {
|
|
|
5
5
|
return '#' + color.toString(16);
|
|
6
6
|
}
|
|
7
7
|
export function isColorStr(color) {
|
|
8
|
-
return typeof color === 'string' && /^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color);
|
|
8
|
+
return typeof color === 'string' && (/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color) || /^[a-z]{1,}$/i.test(color));
|
|
9
|
+
}
|
|
10
|
+
const colorNameMap = {
|
|
11
|
+
aliceblue: '#f0f8ff',
|
|
12
|
+
antiquewhite: '#faebd7',
|
|
13
|
+
aqua: '#00ffff',
|
|
14
|
+
aquamarine: '#7fffd4',
|
|
15
|
+
azure: '#f0ffff',
|
|
16
|
+
beige: '#f5f5dc',
|
|
17
|
+
bisque: '#ffe4c4',
|
|
18
|
+
black: '#000000',
|
|
19
|
+
blanchedalmond: '#ffebcd',
|
|
20
|
+
blue: '#0000ff',
|
|
21
|
+
blueviolet: '#8a2be2',
|
|
22
|
+
brown: '#a52a2a',
|
|
23
|
+
burlywood: '#deb887',
|
|
24
|
+
cadetblue: '#5f9ea0',
|
|
25
|
+
chartreuse: '#7fff00',
|
|
26
|
+
chocolate: '#d2691e',
|
|
27
|
+
coral: '#ff7f50',
|
|
28
|
+
cornflowerblue: '#6495ed',
|
|
29
|
+
cornsilk: '#fff8dc',
|
|
30
|
+
crimson: '#dc143c',
|
|
31
|
+
cyan: '#00ffff',
|
|
32
|
+
darkblue: '#00008b',
|
|
33
|
+
darkcyan: '#008b8b',
|
|
34
|
+
darkgoldenrod: '#b8860b',
|
|
35
|
+
darkgray: '#a9a9a9',
|
|
36
|
+
darkgreen: '#006400',
|
|
37
|
+
darkkhaki: '#bdb76b',
|
|
38
|
+
darkmagenta: '#8b008b',
|
|
39
|
+
darkolivegreen: '#556b2f',
|
|
40
|
+
darkorange: '#ff8c00',
|
|
41
|
+
darkorchid: '#9932cc',
|
|
42
|
+
darkred: '#8b0000',
|
|
43
|
+
darksalmon: '#e9967a',
|
|
44
|
+
darkseagreen: '#8fbc8f',
|
|
45
|
+
darkslateblue: '#483d8b',
|
|
46
|
+
darkslategray: '#2f4f4f',
|
|
47
|
+
darkturquoise: '#00ced1',
|
|
48
|
+
darkviolet: '#9400d3',
|
|
49
|
+
deeppink: '#ff1493',
|
|
50
|
+
deepskyblue: '#00bfff',
|
|
51
|
+
dimgray: '#696969',
|
|
52
|
+
dodgerblue: '#1e90ff',
|
|
53
|
+
firebrick: '#b22222',
|
|
54
|
+
floralwhite: '#fffaf0',
|
|
55
|
+
forestgreen: '#228b22',
|
|
56
|
+
fuchsia: '#ff00ff',
|
|
57
|
+
gainsboro: '#dcdcdc',
|
|
58
|
+
ghostwhite: '#f8f8ff',
|
|
59
|
+
gold: '#ffd700',
|
|
60
|
+
goldenrod: '#daa520',
|
|
61
|
+
gray: '#808080',
|
|
62
|
+
green: '#008000',
|
|
63
|
+
greenyellow: '#adff2f',
|
|
64
|
+
honeydew: '#f0fff0',
|
|
65
|
+
hotpink: '#ff69b4',
|
|
66
|
+
'indianred ': '#cd5c5c',
|
|
67
|
+
indigo: '#4b0082',
|
|
68
|
+
ivory: '#fffff0',
|
|
69
|
+
khaki: '#f0e68c',
|
|
70
|
+
lavender: '#e6e6fa',
|
|
71
|
+
lavenderblush: '#fff0f5',
|
|
72
|
+
lawngreen: '#7cfc00',
|
|
73
|
+
lemonchiffon: '#fffacd',
|
|
74
|
+
lightblue: '#add8e6',
|
|
75
|
+
lightcoral: '#f08080',
|
|
76
|
+
lightcyan: '#e0ffff',
|
|
77
|
+
lightgoldenrodyellow: '#fafad2',
|
|
78
|
+
lightgrey: '#d3d3d3',
|
|
79
|
+
lightgreen: '#90ee90',
|
|
80
|
+
lightpink: '#ffb6c1',
|
|
81
|
+
lightsalmon: '#ffa07a',
|
|
82
|
+
lightseagreen: '#20b2aa',
|
|
83
|
+
lightskyblue: '#87cefa',
|
|
84
|
+
lightslategray: '#778899',
|
|
85
|
+
lightsteelblue: '#b0c4de',
|
|
86
|
+
lightyellow: '#ffffe0',
|
|
87
|
+
lime: '#00ff00',
|
|
88
|
+
limegreen: '#32cd32',
|
|
89
|
+
linen: '#faf0e6',
|
|
90
|
+
magenta: '#ff00ff',
|
|
91
|
+
maroon: '#800000',
|
|
92
|
+
mediumaquamarine: '#66cdaa',
|
|
93
|
+
mediumblue: '#0000cd',
|
|
94
|
+
mediumorchid: '#ba55d3',
|
|
95
|
+
mediumpurple: '#9370d8',
|
|
96
|
+
mediumseagreen: '#3cb371',
|
|
97
|
+
mediumslateblue: '#7b68ee',
|
|
98
|
+
mediumspringgreen: '#00fa9a',
|
|
99
|
+
mediumturquoise: '#48d1cc',
|
|
100
|
+
mediumvioletred: '#c71585',
|
|
101
|
+
midnightblue: '#191970',
|
|
102
|
+
mintcream: '#f5fffa',
|
|
103
|
+
mistyrose: '#ffe4e1',
|
|
104
|
+
moccasin: '#ffe4b5',
|
|
105
|
+
navajowhite: '#ffdead',
|
|
106
|
+
navy: '#000080',
|
|
107
|
+
oldlace: '#fdf5e6',
|
|
108
|
+
olive: '#808000',
|
|
109
|
+
olivedrab: '#6b8e23',
|
|
110
|
+
orange: '#ffa500',
|
|
111
|
+
orangered: '#ff4500',
|
|
112
|
+
orchid: '#da70d6',
|
|
113
|
+
palegoldenrod: '#eee8aa',
|
|
114
|
+
palegreen: '#98fb98',
|
|
115
|
+
paleturquoise: '#afeeee',
|
|
116
|
+
palevioletred: '#d87093',
|
|
117
|
+
papayawhip: '#ffefd5',
|
|
118
|
+
peachpuff: '#ffdab9',
|
|
119
|
+
peru: '#cd853f',
|
|
120
|
+
pink: '#ffc0cb',
|
|
121
|
+
plum: '#dda0dd',
|
|
122
|
+
powderblue: '#b0e0e6',
|
|
123
|
+
purple: '#800080',
|
|
124
|
+
rebeccapurple: '#663399',
|
|
125
|
+
red: '#ff0000',
|
|
126
|
+
rosybrown: '#bc8f8f',
|
|
127
|
+
royalblue: '#4169e1',
|
|
128
|
+
saddlebrown: '#8b4513',
|
|
129
|
+
salmon: '#fa8072',
|
|
130
|
+
sandybrown: '#f4a460',
|
|
131
|
+
seagreen: '#2e8b57',
|
|
132
|
+
seashell: '#fff5ee',
|
|
133
|
+
sienna: '#a0522d',
|
|
134
|
+
silver: '#c0c0c0',
|
|
135
|
+
skyblue: '#87ceeb',
|
|
136
|
+
slateblue: '#6a5acd',
|
|
137
|
+
slategray: '#708090',
|
|
138
|
+
snow: '#fffafa',
|
|
139
|
+
springgreen: '#00ff7f',
|
|
140
|
+
steelblue: '#4682b4',
|
|
141
|
+
tan: '#d2b48c',
|
|
142
|
+
teal: '#008080',
|
|
143
|
+
thistle: '#d8bfd8',
|
|
144
|
+
tomato: '#ff6347',
|
|
145
|
+
turquoise: '#40e0d0',
|
|
146
|
+
violet: '#ee82ee',
|
|
147
|
+
wheat: '#f5deb3',
|
|
148
|
+
white: '#ffffff',
|
|
149
|
+
whitesmoke: '#f5f5f5',
|
|
150
|
+
yellow: '#ffff00',
|
|
151
|
+
yellowgreen: '#9acd32'
|
|
152
|
+
};
|
|
153
|
+
export function colorNameToHex(name) {
|
|
154
|
+
const n = name.toLowerCase();
|
|
155
|
+
const hex = colorNameMap[n];
|
|
156
|
+
if (typeof hex === 'string') {
|
|
157
|
+
return hex;
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
9
160
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ViewContext2D, ViewContext2DOptions } from '@idraw/types';
|
|
2
|
+
export declare class Context2D implements ViewContext2D {
|
|
3
|
+
private _ctx;
|
|
4
|
+
private _devicePixelRatio;
|
|
5
|
+
constructor(ctx: CanvasRenderingContext2D, opts: ViewContext2DOptions);
|
|
6
|
+
$undoPixelRatio(num: number): number;
|
|
7
|
+
$doPixelRatio(num: number): number;
|
|
8
|
+
$getContext(): CanvasRenderingContext2D;
|
|
9
|
+
$setFont(opts: {
|
|
10
|
+
fontSize: number;
|
|
11
|
+
fontFamily?: string;
|
|
12
|
+
fontWeight?: 'bold' | number | string;
|
|
13
|
+
}): void;
|
|
14
|
+
$resize(opts: {
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
devicePixelRatio: number;
|
|
18
|
+
}): void;
|
|
19
|
+
get canvas(): HTMLCanvasElement;
|
|
20
|
+
get fillStyle(): string | CanvasGradient | CanvasPattern;
|
|
21
|
+
set fillStyle(value: string | CanvasGradient | CanvasPattern);
|
|
22
|
+
get strokeStyle(): string | CanvasGradient | CanvasPattern;
|
|
23
|
+
set strokeStyle(color: string | CanvasGradient | CanvasPattern);
|
|
24
|
+
get lineWidth(): number;
|
|
25
|
+
set lineWidth(w: number);
|
|
26
|
+
get textAlign(): CanvasTextAlign;
|
|
27
|
+
set textAlign(align: CanvasTextAlign);
|
|
28
|
+
get textBaseline(): CanvasTextBaseline;
|
|
29
|
+
set textBaseline(baseline: CanvasTextBaseline);
|
|
30
|
+
get globalAlpha(): number;
|
|
31
|
+
set globalAlpha(alpha: number);
|
|
32
|
+
get shadowColor(): string;
|
|
33
|
+
set shadowColor(color: string);
|
|
34
|
+
get shadowOffsetX(): number;
|
|
35
|
+
set shadowOffsetX(offsetX: number);
|
|
36
|
+
get shadowOffsetY(): number;
|
|
37
|
+
set shadowOffsetY(offsetY: number);
|
|
38
|
+
get shadowBlur(): number;
|
|
39
|
+
set shadowBlur(blur: number);
|
|
40
|
+
get lineCap(): CanvasLineCap;
|
|
41
|
+
set lineCap(lineCap: CanvasLineCap);
|
|
42
|
+
get globalCompositeOperation(): GlobalCompositeOperation;
|
|
43
|
+
set globalCompositeOperation(operations: GlobalCompositeOperation);
|
|
44
|
+
fill(...args: [fillRule?: CanvasFillRule | undefined] | [path: Path2D, fillRule?: CanvasFillRule | undefined]): void;
|
|
45
|
+
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean | undefined): void;
|
|
46
|
+
rect(x: number, y: number, w: number, h: number): void;
|
|
47
|
+
fillRect(x: number, y: number, w: number, h: number): void;
|
|
48
|
+
clearRect(x: number, y: number, w: number, h: number): void;
|
|
49
|
+
beginPath(): void;
|
|
50
|
+
closePath(): void;
|
|
51
|
+
lineTo(x: number, y: number): void;
|
|
52
|
+
moveTo(x: number, y: number): void;
|
|
53
|
+
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
|
|
54
|
+
getLineDash(): number[];
|
|
55
|
+
setLineDash(nums: number[]): void;
|
|
56
|
+
stroke(path?: Path2D): void;
|
|
57
|
+
translate(x: number, y: number): void;
|
|
58
|
+
rotate(angle: number): void;
|
|
59
|
+
drawImage(...args: any[]): void;
|
|
60
|
+
createPattern(image: CanvasImageSource, repetition: string | null): CanvasPattern | null;
|
|
61
|
+
measureText(text: string): TextMetrics;
|
|
62
|
+
fillText(text: string, x: number, y: number, maxWidth?: number | undefined): void;
|
|
63
|
+
strokeText(text: string, x: number, y: number, maxWidth?: number | undefined): void;
|
|
64
|
+
save(): void;
|
|
65
|
+
restore(): void;
|
|
66
|
+
scale(ratioX: number, ratioY: number): void;
|
|
67
|
+
circle(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean | undefined): void;
|
|
68
|
+
isPointInPath(x: number, y: number): boolean;
|
|
69
|
+
clip(...args: [fillRule?: CanvasFillRule | undefined] | [path: Path2D, fillRule?: CanvasFillRule | undefined]): void;
|
|
70
|
+
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
71
|
+
getTransform(): DOMMatrix2DInit;
|
|
72
|
+
createLinearGradient(x0: number, y0: number, x1: number, y1: number): CanvasGradient;
|
|
73
|
+
createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): CanvasGradient;
|
|
74
|
+
createConicGradient(startAngle: number, x: number, y: number): CanvasGradient;
|
|
75
|
+
}
|