@leafer/canvas-web 1.0.0-rc.3 → 1.0.0-rc.30
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/package.json +3 -3
- package/src/LeaferCanvas.ts +39 -30
- package/types/index.d.ts +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/canvas-web",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.30",
|
|
4
4
|
"description": "@leafer/canvas-web",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.0.0-rc.
|
|
25
|
+
"@leafer/core": "1.0.0-rc.30"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.0.0-rc.
|
|
28
|
+
"@leafer/interface": "1.0.0-rc.30"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/LeaferCanvas.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IAutoBounds, ISizeData, IScreenSizeData, IResizeEventListener
|
|
2
|
-
import { LeaferCanvasBase, canvasSizeAttrs, ResizeEvent, DataHelper, Platform, Debug
|
|
1
|
+
import { IAutoBounds, ISizeData, IScreenSizeData, IResizeEventListener } from '@leafer/interface'
|
|
2
|
+
import { LeaferCanvasBase, canvasSizeAttrs, ResizeEvent, DataHelper, Platform, Debug } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
const debug = Debug.get('LeaferCanvas')
|
|
@@ -9,6 +9,25 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
9
9
|
declare public view: HTMLCanvasElement
|
|
10
10
|
declare public parentView: HTMLElement
|
|
11
11
|
|
|
12
|
+
public set zIndex(zIndex: number) {
|
|
13
|
+
const { style } = this.view
|
|
14
|
+
style.zIndex = zIndex as unknown as string
|
|
15
|
+
this.setAbsolute(this.view)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public set childIndex(index: number) {
|
|
19
|
+
const { view, parentView } = this
|
|
20
|
+
if (view && parentView) {
|
|
21
|
+
const beforeNode = parentView.children[index]
|
|
22
|
+
if (beforeNode) {
|
|
23
|
+
this.setAbsolute(beforeNode as HTMLCanvasElement)
|
|
24
|
+
parentView.insertBefore(view, beforeNode)
|
|
25
|
+
} else {
|
|
26
|
+
parentView.appendChild(beforeNode)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
12
31
|
protected resizeObserver: ResizeObserver
|
|
13
32
|
protected autoBounds: IAutoBounds
|
|
14
33
|
protected resizeListener: IResizeEventListener
|
|
@@ -21,8 +40,13 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
21
40
|
style.display || (style.display = 'block')
|
|
22
41
|
this.parentView = this.view.parentElement
|
|
23
42
|
|
|
43
|
+
if (this.parentView) {
|
|
44
|
+
const pStyle = this.parentView.style
|
|
45
|
+
pStyle.webkitUserSelect = pStyle.userSelect = 'none' // fix safari: use webkitUserSelect
|
|
46
|
+
}
|
|
47
|
+
|
|
24
48
|
if (Platform.syncDomFont && !this.parentView) { // fix: firefox default font
|
|
25
|
-
|
|
49
|
+
style.display = 'none'
|
|
26
50
|
document.body.appendChild(this.view)
|
|
27
51
|
}
|
|
28
52
|
|
|
@@ -41,27 +65,6 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
41
65
|
this.view = document.createElement('canvas')
|
|
42
66
|
}
|
|
43
67
|
|
|
44
|
-
public setCursor(cursor: ICursorType | ICursorType[]): void {
|
|
45
|
-
const list: ICursorType[] = []
|
|
46
|
-
this.eachCursor(cursor, list)
|
|
47
|
-
if (typeof list[list.length - 1] === 'object') list.push('default')
|
|
48
|
-
this.view.style.cursor = list.map(item => (typeof item === 'object') ? `url(${item.url}) ${item.x || 0} ${item.y || 0}` : item).join(',')
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
protected eachCursor(cursor: ICursorType | ICursorType[], list: ICursorType[], level = 0): void {
|
|
52
|
-
level++
|
|
53
|
-
if (cursor instanceof Array) {
|
|
54
|
-
cursor.forEach(item => this.eachCursor(item, list, level))
|
|
55
|
-
} else {
|
|
56
|
-
const custom = typeof cursor === 'string' && Cursor.get(cursor)
|
|
57
|
-
if (custom && level < 2) {
|
|
58
|
-
this.eachCursor(custom, list, level)
|
|
59
|
-
} else {
|
|
60
|
-
list.push(cursor)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
68
|
protected __createViewFrom(inputView: string | object): void {
|
|
66
69
|
let find: unknown = (typeof inputView === 'string') ? document.getElementById(inputView) : inputView as HTMLElement
|
|
67
70
|
if (find) {
|
|
@@ -85,9 +88,7 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
85
88
|
const view = this.view
|
|
86
89
|
|
|
87
90
|
if (parent.hasChildNodes()) {
|
|
88
|
-
|
|
89
|
-
style.position = 'absolute'
|
|
90
|
-
style.top = style.left = '0px'
|
|
91
|
+
this.setAbsolute(view)
|
|
91
92
|
parent.style.position || (parent.style.position = 'relative')
|
|
92
93
|
}
|
|
93
94
|
|
|
@@ -99,6 +100,12 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
|
|
103
|
+
protected setAbsolute(view: HTMLCanvasElement): void {
|
|
104
|
+
const { style } = view
|
|
105
|
+
style.position = 'absolute'
|
|
106
|
+
style.top = style.left = '0px'
|
|
107
|
+
}
|
|
108
|
+
|
|
102
109
|
public updateViewSize(): void {
|
|
103
110
|
const { width, height, pixelRatio } = this
|
|
104
111
|
|
|
@@ -106,9 +113,8 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
106
113
|
style.width = width + 'px'
|
|
107
114
|
style.height = height + 'px'
|
|
108
115
|
|
|
109
|
-
this.view.width = width * pixelRatio
|
|
110
|
-
this.view.height = height * pixelRatio
|
|
111
|
-
|
|
116
|
+
this.view.width = Math.ceil(width * pixelRatio)
|
|
117
|
+
this.view.height = Math.ceil(height * pixelRatio)
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
public updateClientBounds(): void {
|
|
@@ -129,6 +135,9 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
129
135
|
if (parent) {
|
|
130
136
|
this.resizeObserver.observe(parent)
|
|
131
137
|
this.checkAutoBounds(parent.getBoundingClientRect())
|
|
138
|
+
} else {
|
|
139
|
+
this.checkAutoBounds(this.view)
|
|
140
|
+
debug.warn('no parent')
|
|
132
141
|
}
|
|
133
142
|
|
|
134
143
|
} catch {
|
package/types/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { IAutoBounds, IResizeEventListener,
|
|
1
|
+
import { IAutoBounds, IResizeEventListener, ISizeData } from '@leafer/interface';
|
|
2
2
|
import { LeaferCanvasBase } from '@leafer/core';
|
|
3
3
|
|
|
4
4
|
declare class LeaferCanvas extends LeaferCanvasBase {
|
|
5
5
|
view: HTMLCanvasElement;
|
|
6
6
|
parentView: HTMLElement;
|
|
7
|
+
set zIndex(zIndex: number);
|
|
8
|
+
set childIndex(index: number);
|
|
7
9
|
protected resizeObserver: ResizeObserver;
|
|
8
10
|
protected autoBounds: IAutoBounds;
|
|
9
11
|
protected resizeListener: IResizeEventListener;
|
|
@@ -13,9 +15,8 @@ declare class LeaferCanvas extends LeaferCanvasBase {
|
|
|
13
15
|
set hittable(hittable: boolean);
|
|
14
16
|
get hittable(): boolean;
|
|
15
17
|
protected __createView(): void;
|
|
16
|
-
setCursor(cursor: ICursorType | ICursorType[]): void;
|
|
17
|
-
protected eachCursor(cursor: ICursorType | ICursorType[], list: ICursorType[], level?: number): void;
|
|
18
18
|
protected __createViewFrom(inputView: string | object): void;
|
|
19
|
+
protected setAbsolute(view: HTMLCanvasElement): void;
|
|
19
20
|
updateViewSize(): void;
|
|
20
21
|
updateClientBounds(): void;
|
|
21
22
|
startAutoLayout(autoBounds: IAutoBounds, listener: IResizeEventListener): void;
|