@leafer/debug 1.0.0-beta.15 → 1.0.0-beta.16
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 +4 -3
- package/src/Debug.ts +68 -0
- package/src/Run.ts +51 -0
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/debug",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.16",
|
|
4
4
|
"description": "@leafer/debug",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.ts",
|
|
8
8
|
"types": "types/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
|
+
"src",
|
|
10
11
|
"types",
|
|
11
12
|
"dist"
|
|
12
13
|
],
|
|
@@ -21,9 +22,9 @@
|
|
|
21
22
|
"leaferjs"
|
|
22
23
|
],
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@leafer/math": "1.0.0-beta.
|
|
25
|
+
"@leafer/math": "1.0.0-beta.16"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@leafer/interface": "1.0.0-beta.
|
|
28
|
+
"@leafer/interface": "1.0.0-beta.16"
|
|
28
29
|
}
|
|
29
30
|
}
|
package/src/Debug.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { IBooleanMap } from '@leafer/interface'
|
|
2
|
+
|
|
3
|
+
export class Debug {
|
|
4
|
+
|
|
5
|
+
static enable: boolean
|
|
6
|
+
|
|
7
|
+
static filterList: string[] = []
|
|
8
|
+
static excludeList: string[] = []
|
|
9
|
+
|
|
10
|
+
// other
|
|
11
|
+
static showRepaint: boolean
|
|
12
|
+
static showHitView: boolean | string | string[]
|
|
13
|
+
static showBoundsView: boolean | string | string[]
|
|
14
|
+
|
|
15
|
+
public name: string
|
|
16
|
+
|
|
17
|
+
public repeatMap: IBooleanMap = {}
|
|
18
|
+
|
|
19
|
+
constructor(name: string) {
|
|
20
|
+
this.name = name
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static get(name: string): Debug {
|
|
24
|
+
return new Debug(name)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static set filter(name: string | string[]) {
|
|
28
|
+
if (!name) name = []
|
|
29
|
+
else if (typeof name === 'string') name = [name]
|
|
30
|
+
this.filterList = name
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static set exclude(name: string | string[]) {
|
|
34
|
+
if (!name) name = []
|
|
35
|
+
else if (typeof name === 'string') name = [name]
|
|
36
|
+
this.excludeList = name
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
log(...messages: unknown[]): void {
|
|
41
|
+
if (D.enable) {
|
|
42
|
+
if (D.filterList.length && D.filterList.every(name => name !== this.name)) return
|
|
43
|
+
if (D.excludeList.length && D.excludeList.some(name => name === this.name)) return
|
|
44
|
+
console.log('%c' + this.name, 'color:#21ae62', ...messages)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
warn(...messages: unknown[]): void {
|
|
49
|
+
if (D.enable) console.warn(this.name, ...messages)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
repeat(name: string, ...messages: unknown[]) {
|
|
53
|
+
if (!this.repeatMap[name]) {
|
|
54
|
+
this.warn('repeat:' + name, ...messages)
|
|
55
|
+
this.repeatMap[name] = true
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
error(...messages: unknown[]): void {
|
|
60
|
+
try {
|
|
61
|
+
throw new Error()
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error(this.name, ...messages, e)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const D = Debug
|
package/src/Run.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { IncrementId } from '@leafer/math'
|
|
2
|
+
import { Debug } from './Debug'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
interface ids {
|
|
6
|
+
[name: string]: number
|
|
7
|
+
}
|
|
8
|
+
interface names {
|
|
9
|
+
[name: string]: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const debug = Debug.get('RunTime')
|
|
14
|
+
|
|
15
|
+
export class Run {
|
|
16
|
+
|
|
17
|
+
static currentId: number
|
|
18
|
+
static currentTime: number
|
|
19
|
+
static currentName: string
|
|
20
|
+
|
|
21
|
+
static idMap: ids = {}
|
|
22
|
+
static nameMap: names = {}
|
|
23
|
+
static nameToIdMap: ids = {}
|
|
24
|
+
|
|
25
|
+
static start(name: string, microsecond?: boolean): number {
|
|
26
|
+
const id = IncrementId.create(IncrementId.RUNTIME)
|
|
27
|
+
R.currentId = R.idMap[id] = microsecond ? performance.now() : Date.now()
|
|
28
|
+
R.currentName = R.nameMap[id] = name
|
|
29
|
+
R.nameToIdMap[name] = id
|
|
30
|
+
return id
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static end(id: number, microsecond?: boolean): void {
|
|
34
|
+
const time = R.idMap[id]
|
|
35
|
+
const name = R.nameMap[id]
|
|
36
|
+
R.idMap[id] = R.nameMap[id] = R.nameToIdMap[name] = undefined
|
|
37
|
+
|
|
38
|
+
if (microsecond) {
|
|
39
|
+
debug.log(name, performance.now() - time, 'µs')
|
|
40
|
+
} else {
|
|
41
|
+
debug.log(name, Date.now() - time, 'ms')
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static endOfName(name: string, microsecond?: boolean): void {
|
|
46
|
+
const id = R.nameToIdMap[name]
|
|
47
|
+
if (id !== undefined) R.end(id, microsecond)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const R = Run
|