UNPKG

5.8 kBJavaScriptView Raw
1import { Point } from '../shapes/Point';
2/**
3 * An DOM-compatible synthetic event implementation that is "forwarded" on behalf of an original
4 * FederatedEvent or native {@link https://dom.spec.whatwg.org/#event Event}.
5 */
6
7var FederatedEvent =
8/** @class */
9function () {
10 /**
11 * The event boundary which manages this event. Propagation can only occur
12 * within the boundary's jurisdiction.
13 */
14 function FederatedEvent(manager) {
15 /**
16 * The propagation phase.
17 * @see https://developer.mozilla.org/en-US/docs/Web/API/Event/eventPhase
18 */
19 this.eventPhase = FederatedEvent.prototype.NONE;
20 /**
21 * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/bubbles
22 */
23
24 this.bubbles = true;
25 /**
26 * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/cancelBubble
27 */
28
29 this.cancelBubble = true;
30 /**
31 * @see https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelable
32 */
33
34 this.cancelable = false;
35 /** Flags whether the default response of the user agent was prevent through this event. */
36
37 this.defaultPrevented = false;
38 /** Flags whether propagation was stopped. */
39
40 this.propagationStopped = false;
41 /** Flags whether propagation was immediately stopped. */
42
43 this.propagationImmediatelyStopped = false;
44 /**
45 * The coordinates of the evnet relative to the nearest DOM layer.
46 * This is a non-standard property.
47 */
48
49 this.layer = new Point();
50 /**
51 * The coordinates of the event relative to the DOM document.
52 * This is a non-standard property.
53 * relative to the DOM document.
54 * @see https://developer.mozilla.org/zh-CN/docs/Web/API/MouseEvent/pageX
55 */
56
57 this.page = new Point();
58 /**
59 * relative to Canvas, origin is left-top
60 */
61
62 this.canvas = new Point();
63 /**
64 * relative to Viewport, account for Camera
65 */
66
67 this.viewport = new Point();
68 this.composed = false;
69 this.NONE = 0;
70 this.CAPTURING_PHASE = 1;
71 this.AT_TARGET = 2;
72 this.BUBBLING_PHASE = 3;
73 this.manager = manager;
74 }
75
76 Object.defineProperty(FederatedEvent.prototype, "name", {
77 /**
78 * @deprecated
79 */
80 get: function get() {
81 return this.type;
82 },
83 enumerable: false,
84 configurable: true
85 });
86 Object.defineProperty(FederatedEvent.prototype, "layerX", {
87 get: function get() {
88 return this.layer.x;
89 },
90 enumerable: false,
91 configurable: true
92 });
93 Object.defineProperty(FederatedEvent.prototype, "layerY", {
94 get: function get() {
95 return this.layer.y;
96 },
97 enumerable: false,
98 configurable: true
99 });
100 Object.defineProperty(FederatedEvent.prototype, "pageX", {
101 get: function get() {
102 return this.page.x;
103 },
104 enumerable: false,
105 configurable: true
106 });
107 Object.defineProperty(FederatedEvent.prototype, "pageY", {
108 get: function get() {
109 return this.page.y;
110 },
111 enumerable: false,
112 configurable: true
113 });
114 Object.defineProperty(FederatedEvent.prototype, "x", {
115 get: function get() {
116 return this.canvas.x;
117 },
118 enumerable: false,
119 configurable: true
120 });
121 Object.defineProperty(FederatedEvent.prototype, "y", {
122 get: function get() {
123 return this.canvas.y;
124 },
125 enumerable: false,
126 configurable: true
127 });
128 Object.defineProperty(FederatedEvent.prototype, "canvasX", {
129 get: function get() {
130 return this.canvas.x;
131 },
132 enumerable: false,
133 configurable: true
134 });
135 Object.defineProperty(FederatedEvent.prototype, "canvasY", {
136 get: function get() {
137 return this.canvas.y;
138 },
139 enumerable: false,
140 configurable: true
141 });
142 Object.defineProperty(FederatedEvent.prototype, "viewportX", {
143 get: function get() {
144 return this.viewport.x;
145 },
146 enumerable: false,
147 configurable: true
148 });
149 Object.defineProperty(FederatedEvent.prototype, "viewportY", {
150 get: function get() {
151 return this.viewport.y;
152 },
153 enumerable: false,
154 configurable: true
155 });
156 /**
157 * The propagation path for this event
158 * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/composedPath
159 *
160 * So composedPath()[0] represents the original target.
161 * @see https://polymer-library.polymer-project.org/3.0/docs/devguide/events#retargeting
162 */
163
164 FederatedEvent.prototype.composedPath = function () {
165 if (this.manager && (!this.path || this.path[0] !== this.target)) {
166 this.path = this.target ? this.manager.propagationPath(this.target) : [];
167 }
168
169 return this.path;
170 };
171
172 Object.defineProperty(FederatedEvent.prototype, "propagationPath", {
173 /**
174 * @deprecated
175 */
176 get: function get() {
177 return this.composedPath();
178 },
179 enumerable: false,
180 configurable: true
181 });
182 /**
183 * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/preventDefault
184 */
185
186 FederatedEvent.prototype.preventDefault = function () {
187 if (this.nativeEvent instanceof Event && this.nativeEvent.cancelable) {
188 this.nativeEvent.preventDefault();
189 }
190
191 this.defaultPrevented = true;
192 };
193 /**
194 * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/stopImmediatePropagation
195 */
196
197
198 FederatedEvent.prototype.stopImmediatePropagation = function () {
199 this.propagationImmediatelyStopped = true;
200 };
201 /**
202 * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/stopPropagation
203 */
204
205
206 FederatedEvent.prototype.stopPropagation = function () {
207 this.propagationStopped = true;
208 };
209 /**
210 * added for compatibility with DOM Event,
211 * deprecated props and methods
212 */
213
214
215 FederatedEvent.prototype.initEvent = function () {};
216
217 FederatedEvent.prototype.initUIEvent = function () {};
218
219 return FederatedEvent;
220}();
221
222export { FederatedEvent };
\No newline at end of file