@ax-design/reveal-highlight 0.4.0 → 0.4.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/LICENSE +21 -21
- package/README.md +76 -227
- package/build/CustomElements.d.ts +2 -0
- package/build/CustomElements.d.ts.map +1 -1
- package/build/main.js +32 -32
- package/es/CustomElements.d.ts +2 -0
- package/es/CustomElements.d.ts.map +1 -1
- package/es/CustomElements.js +99 -77
- package/es/CustomElements.js.map +1 -1
- package/es/SvgConfig.js +70 -70
- package/es/tsconfig.tsbuildinfo +1 -0
- package/package.json +12 -8
- package/src/BaseConfig.ts +310 -310
- package/src/CanvasConfig.ts +415 -415
- package/src/ComputedStyleStorage.ts +89 -89
- package/src/CustomElements.ts +272 -247
- package/src/Profiler.ts +44 -44
- package/src/RevealBoundryStore.ts +291 -291
- package/src/RevealStateManager.ts +78 -78
- package/src/SvgConfig.ts +422 -422
- package/src/config.ts +26 -26
- package/src/cssTypedOM.d.ts +52 -52
- package/src/index.ts +219 -219
- package/src/utils/extractRGBValue.ts +58 -58
- package/src/utils/isValidateBorderDecorationType.ts +8 -8
- package/src/utils/types.ts +105 -105
- package/src/variables.ts +1 -1
- package/.prettierrc +0 -6
- package/.travis.yml +0 -26
- package/docs/demo/index.html +0 -992
- package/docs/demo/ng.html +0 -992
- package/docs/demo/performance-inspector.html +0 -60
- package/docs/demo/shapes-demo.html +0 -93
- package/docs/demo/single-unit.html +0 -39
- package/docs/logo.png +0 -0
- package/docs/logo.svg +0 -1
- package/docs/screen-record.gif +0 -0
- package/docs/src/logo.afdesign +0 -0
- package/rollup.config.js +0 -14
- package/tsconfig.json +0 -18
package/src/CustomElements.ts
CHANGED
|
@@ -1,247 +1,272 @@
|
|
|
1
|
-
import { RevealStateManager } from './RevealStateManager.js';
|
|
2
|
-
import { RevealBoundaryStore } from './RevealBoundryStore.js';
|
|
3
|
-
import { config } from './config.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
private
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (oldStorage
|
|
55
|
-
this.dispatchEvent(new CustomEvent(AxRevealBoundary.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
this.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
this.
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
svg
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
1
|
+
import { RevealStateManager } from './RevealStateManager.js';
|
|
2
|
+
import { RevealBoundaryStore } from './RevealBoundryStore.js';
|
|
3
|
+
import { config } from './config.js';
|
|
4
|
+
|
|
5
|
+
function closest(dom: Element, selector: string): Element | null {
|
|
6
|
+
const r = dom.closest(selector);
|
|
7
|
+
if (r) return r;
|
|
8
|
+
const host = findParentShadowRoot(dom)?.host;
|
|
9
|
+
if (!host) return null;
|
|
10
|
+
return closest(host, selector)
|
|
11
|
+
}
|
|
12
|
+
function findParentShadowRoot(x: Node | undefined | null): ShadowRoot | null {
|
|
13
|
+
if (!x) return null;
|
|
14
|
+
if (x.parentNode && x.parentNode.nodeType === document.DOCUMENT_FRAGMENT_NODE) return x.parentNode as ShadowRoot;
|
|
15
|
+
return findParentShadowRoot(x.parentNode);
|
|
16
|
+
}
|
|
17
|
+
class ServerSideHTMLElement {
|
|
18
|
+
root = {
|
|
19
|
+
innerHTML: '',
|
|
20
|
+
querySelector: (_x: string) => null,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
attachShadow = () => null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const PatchedHTMLElement =
|
|
27
|
+
typeof globalThis.Window === 'undefined' ? ((ServerSideHTMLElement as unknown) as typeof HTMLElement) : HTMLElement;
|
|
28
|
+
|
|
29
|
+
export class AxRevealProvider extends PatchedHTMLElement {
|
|
30
|
+
static readonly ElementName = 'ax-reveal-provider';
|
|
31
|
+
readonly stateManager = new RevealStateManager();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class AxRevealBoundary extends PatchedHTMLElement {
|
|
35
|
+
static readonly ElementName = 'ax-reveal-bound';
|
|
36
|
+
|
|
37
|
+
static readonly removeStorageEvent = 'removeStorage';
|
|
38
|
+
static readonly attachStorageEvent = 'attachStorage';
|
|
39
|
+
static readonly replaceStorageEvent = 'replaceStorage';
|
|
40
|
+
|
|
41
|
+
private root = this.attachShadow({ mode: 'open' });
|
|
42
|
+
|
|
43
|
+
static readonly stateManager = new RevealStateManager();
|
|
44
|
+
|
|
45
|
+
private _storage!: RevealBoundaryStore | undefined;
|
|
46
|
+
|
|
47
|
+
private get storage() {
|
|
48
|
+
return this._storage;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private set storage(newStorage) {
|
|
52
|
+
const oldStorage = this._storage;
|
|
53
|
+
|
|
54
|
+
if (oldStorage) {
|
|
55
|
+
this.dispatchEvent(new CustomEvent(AxRevealBoundary.removeStorageEvent, { detail: oldStorage }));
|
|
56
|
+
AxRevealBoundary.stateManager.removeBoundary(oldStorage);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (newStorage) {
|
|
60
|
+
this._storage = newStorage;
|
|
61
|
+
this.dispatchEvent(new CustomEvent(AxRevealBoundary.attachStorageEvent, { detail: newStorage }));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (oldStorage && newStorage) {
|
|
65
|
+
this.dispatchEvent(
|
|
66
|
+
new CustomEvent(AxRevealBoundary.replaceStorageEvent, {
|
|
67
|
+
detail: { old: oldStorage, new: newStorage },
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public waitForStorage(f: (storage: RevealBoundaryStore) => void) {
|
|
74
|
+
if (this.storage === undefined) {
|
|
75
|
+
this.addEventListener(AxRevealBoundary.attachStorageEvent, () => f(this.storage!), { once: true });
|
|
76
|
+
} else {
|
|
77
|
+
f(this.storage);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private appendStorage(force = false) {
|
|
82
|
+
if (!force && this.storage) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const parent = closest(this, AxRevealProvider.ElementName) as AxRevealProvider;
|
|
87
|
+
const stateManager = parent ? parent.stateManager : AxRevealBoundary.stateManager;
|
|
88
|
+
|
|
89
|
+
this.storage = stateManager.newBoundary(this);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Update the position of your pointer.
|
|
94
|
+
* @param ev Pointer event from the listener.
|
|
95
|
+
*/
|
|
96
|
+
updatePointerPosition = (ev: PointerEvent) => {
|
|
97
|
+
this.waitForStorage((storage) => {
|
|
98
|
+
storage.clientX = ev.clientX;
|
|
99
|
+
storage.clientY = ev.clientY;
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
handlePointerEnter = () => this.waitForStorage((storage) => storage.onPointerEnterBoundary());
|
|
104
|
+
handlePointerLeave = () => this.waitForStorage((storage) => storage.onPointerLeaveBoundary());
|
|
105
|
+
handlePointerMove = this.updatePointerPosition;
|
|
106
|
+
handlePointerUp = (ev: PointerEvent) => {
|
|
107
|
+
if (ev.pointerType === 'mouse') {
|
|
108
|
+
this.waitForStorage((storage) => storage.switchAnimation());
|
|
109
|
+
} else {
|
|
110
|
+
this.waitForStorage((storage) => storage.clearAll(false));
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
handlePointerDown = (ev: PointerEvent) =>
|
|
114
|
+
this.waitForStorage((storage) => {
|
|
115
|
+
this.updatePointerPosition(ev);
|
|
116
|
+
storage.initializeAnimation();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
connectedCallback() {
|
|
120
|
+
this.appendStorage(true);
|
|
121
|
+
if (config.borderDetectionMode === 'strictEdge') {
|
|
122
|
+
this.addEventListener('pointerenter', this.handlePointerEnter);
|
|
123
|
+
this.addEventListener('pointerleave', this.handlePointerLeave);
|
|
124
|
+
this.addEventListener('pointermove', this.handlePointerMove);
|
|
125
|
+
}
|
|
126
|
+
this.addEventListener('pointerdown', this.handlePointerDown);
|
|
127
|
+
this.addEventListener('pointerup', this.handlePointerUp);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
disconnectedCallback() {
|
|
131
|
+
this.storage = undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
constructor() {
|
|
135
|
+
super();
|
|
136
|
+
this.root.innerHTML = `
|
|
137
|
+
<div>
|
|
138
|
+
<slot></slot>
|
|
139
|
+
</div>`;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export class AxReveal extends PatchedHTMLElement {
|
|
144
|
+
static readonly ElementName = 'ax-reveal';
|
|
145
|
+
private root = this.attachShadow({ mode: 'open' });
|
|
146
|
+
private canvas: HTMLCanvasElement;
|
|
147
|
+
private boundary!: AxRevealBoundary;
|
|
148
|
+
|
|
149
|
+
adoptedCallback() {
|
|
150
|
+
this.disconnectedCallback();
|
|
151
|
+
this.connectedCallback();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
handlePointerDown = (ev: PointerEvent) => {
|
|
155
|
+
this.setPointerCapture(ev.pointerId);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
disconnectedCallback() {
|
|
159
|
+
this.boundary && this.boundary.waitForStorage((storage) => storage.removeReveal(this.canvas));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
connectedCallback() {
|
|
163
|
+
this.boundary = closest(this, AxRevealBoundary.ElementName) as AxRevealBoundary;
|
|
164
|
+
if (!this.boundary)
|
|
165
|
+
throw new SyntaxError(
|
|
166
|
+
'You must use ' + AxRevealBoundary.ElementName + ' as the boundary of reveal highlight!'
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
this.boundary.waitForStorage((storage) => setTimeout(() => storage.addReveal(this.canvas, this), 0));
|
|
170
|
+
this.addEventListener('pointerdown', this.handlePointerDown);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
constructor() {
|
|
174
|
+
super();
|
|
175
|
+
this.root.innerHTML = `
|
|
176
|
+
<div class="ax-reveal">
|
|
177
|
+
<canvas></canvas>
|
|
178
|
+
<div class="content"><slot></slot></div>
|
|
179
|
+
</div>
|
|
180
|
+
<style>
|
|
181
|
+
.ax-reveal { display: content; }
|
|
182
|
+
.ax-reveal * { user-drag: none; -webkit-user-drag: none; touch-action: none; user-select: none; }
|
|
183
|
+
.content { position: relative; }
|
|
184
|
+
canvas { top: 0; left: 0; pointer-events: none; width: 100%; height: 100%; position: absolute; }
|
|
185
|
+
:host { display: inline-block; position: relative; }
|
|
186
|
+
:host([block]) { display: block; }
|
|
187
|
+
:host([inline-block]) { display: inline-block; }
|
|
188
|
+
:host([flex]) { display: flex; }
|
|
189
|
+
:host([inline-flex]) { display: inline-flex; }
|
|
190
|
+
:host([grid]) { display: grid; }
|
|
191
|
+
:host([inline-grid]) { display: inline-grid; }
|
|
192
|
+
::slotted(*) { user-drag: none; -webkit-user-drag: none; touch-action: none; user-select: none; }
|
|
193
|
+
::slotted(button) { outline:none; }
|
|
194
|
+
</style>`;
|
|
195
|
+
this.canvas = this.root.querySelector('canvas')!;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export class AxRevealNg extends PatchedHTMLElement {
|
|
200
|
+
static readonly ElementName = 'ax-reveal-ng';
|
|
201
|
+
private root = this.attachShadow({ mode: 'open' });
|
|
202
|
+
private svg: SVGElement;
|
|
203
|
+
private boundary!: AxRevealBoundary;
|
|
204
|
+
|
|
205
|
+
adoptedCallback() {
|
|
206
|
+
this.disconnectedCallback();
|
|
207
|
+
this.connectedCallback();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
handlePointerDown = (ev: PointerEvent) => {
|
|
211
|
+
this.setPointerCapture(ev.pointerId);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
disconnectedCallback() {
|
|
215
|
+
this.boundary && this.boundary.waitForStorage((storage) => storage.removeReveal(this.svg));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
connectedCallback() {
|
|
219
|
+
this.boundary = closest(this, AxRevealBoundary.ElementName) as AxRevealBoundary;
|
|
220
|
+
if (!this.boundary)
|
|
221
|
+
throw new SyntaxError(
|
|
222
|
+
'You must use ' + AxRevealBoundary.ElementName + ' as the boundary of reveal highlight!'
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
this.boundary.waitForStorage((storage) => setTimeout(() => storage.addReveal(this.svg, this), 0));
|
|
226
|
+
this.addEventListener('pointerdown', this.handlePointerDown);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
constructor() {
|
|
230
|
+
super();
|
|
231
|
+
this.root.innerHTML = `
|
|
232
|
+
<div class="ax-reveal">
|
|
233
|
+
<svg>
|
|
234
|
+
<defs>
|
|
235
|
+
<radialGradient id="borderGrad" gradientUnits="userSpaceOnUse" r="10">
|
|
236
|
+
<stop id="borderCenter" offset="0%" />
|
|
237
|
+
<stop id="borderOut" offset="100%" />
|
|
238
|
+
</radialGradient>
|
|
239
|
+
<radialGradient id="fillGrad" gradientUnits="userSpaceOnUse" r="10">
|
|
240
|
+
<stop id="fillCenter" offset="0%" />
|
|
241
|
+
<stop id="fillOut" offset="100%" />
|
|
242
|
+
</radialGradient>
|
|
243
|
+
<radialGradient id="rippleGrad" gradientUnits="userSpaceOnUse" r="10">
|
|
244
|
+
<stop id="rippleCenter" offset="0%" />
|
|
245
|
+
<stop id="rippleMiddle" offset="0%" />
|
|
246
|
+
<stop id="rippleOut" offset="0%" />
|
|
247
|
+
</radialGradient>
|
|
248
|
+
</defs>
|
|
249
|
+
<path id="borderPath" fill="url(#borderGrad)" />
|
|
250
|
+
<path id="fillPath" fill="url(#fillGrad)" />
|
|
251
|
+
<path id="ripplePath" fill="url(#rippleGrad)" />
|
|
252
|
+
</svg>
|
|
253
|
+
<div class="content"><slot></slot></div>
|
|
254
|
+
</div>
|
|
255
|
+
<style>
|
|
256
|
+
.ax-reveal { display: contents; }
|
|
257
|
+
.ax-reveal * { user-drag: none; -webkit-user-drag: none; touch-action: none; user-select: none; }
|
|
258
|
+
.content { position: relative; }
|
|
259
|
+
svg { top: 0; left: 0; pointer-events: none; width: 100%; height: 100%; position: absolute; }
|
|
260
|
+
:host { display: inline-block; position: relative; }
|
|
261
|
+
:host([block]) { display: block; }
|
|
262
|
+
:host([inline-block]) { display: inline-block; }
|
|
263
|
+
:host([flex]) { display: flex; }
|
|
264
|
+
:host([inline-flex]) { display: inline-flex; }
|
|
265
|
+
:host([grid]) { display: grid; }
|
|
266
|
+
:host([inline-grid]) { display: inline-grid; }
|
|
267
|
+
::slotted(*) { user-drag: none; -webkit-user-drag: none; touch-action: none; user-select: none; }
|
|
268
|
+
::slotted(button) { outline:none; }
|
|
269
|
+
</style>`;
|
|
270
|
+
this.svg = this.root.querySelector('svg')!;
|
|
271
|
+
}
|
|
272
|
+
}
|
package/src/Profiler.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
interface ProfilerLog {
|
|
2
|
-
time: number;
|
|
3
|
-
task: string;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
const downloadText = (filename: string, text: string) => {
|
|
7
|
-
const element = document.createElement('a');
|
|
8
|
-
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
|
|
9
|
-
element.setAttribute('download', filename);
|
|
10
|
-
|
|
11
|
-
element.style.display = 'none';
|
|
12
|
-
|
|
13
|
-
element.click();
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export class Profiler {
|
|
17
|
-
private baseline: number = 0;
|
|
18
|
-
logs: ProfilerLog[] = [];
|
|
19
|
-
|
|
20
|
-
setBaseline() {
|
|
21
|
-
this.baseline = performance.now();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
mark(task: string = 'unknown') {
|
|
25
|
-
const time = performance.now() - this.baseline;
|
|
26
|
-
|
|
27
|
-
this.logs.push({
|
|
28
|
-
time,
|
|
29
|
-
task,
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
this.baseline = performance.now();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
dumpAsCsv() {
|
|
36
|
-
let result = 'task,tile\n';
|
|
37
|
-
|
|
38
|
-
for (let i = 0; i < this.logs.length; i++) {
|
|
39
|
-
result += `${this.logs[i].task},${this.logs[i].time}\n`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
downloadText('axRevealHighlightProfileDetail.csv', result);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
interface ProfilerLog {
|
|
2
|
+
time: number;
|
|
3
|
+
task: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const downloadText = (filename: string, text: string) => {
|
|
7
|
+
const element = document.createElement('a');
|
|
8
|
+
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
|
|
9
|
+
element.setAttribute('download', filename);
|
|
10
|
+
|
|
11
|
+
element.style.display = 'none';
|
|
12
|
+
|
|
13
|
+
element.click();
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export class Profiler {
|
|
17
|
+
private baseline: number = 0;
|
|
18
|
+
logs: ProfilerLog[] = [];
|
|
19
|
+
|
|
20
|
+
setBaseline() {
|
|
21
|
+
this.baseline = performance.now();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
mark(task: string = 'unknown') {
|
|
25
|
+
const time = performance.now() - this.baseline;
|
|
26
|
+
|
|
27
|
+
this.logs.push({
|
|
28
|
+
time,
|
|
29
|
+
task,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
this.baseline = performance.now();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
dumpAsCsv() {
|
|
36
|
+
let result = 'task,tile\n';
|
|
37
|
+
|
|
38
|
+
for (let i = 0; i < this.logs.length; i++) {
|
|
39
|
+
result += `${this.logs[i].task},${this.logs[i].time}\n`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
downloadText('axRevealHighlightProfileDetail.csv', result);
|
|
43
|
+
}
|
|
44
|
+
}
|