@m2c2kit/addons 0.3.8 → 0.3.10
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/index.d.ts +178 -4
- package/dist/index.js +586 -55
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Canvas } from 'canvaskit-wasm';
|
|
2
|
-
import { CompositeOptions, Size, RgbaColor, Composite, Entity, GlobalVariables, TextOptions, IText, EntityEvent,
|
|
2
|
+
import { CompositeOptions, Size, RgbaColor, Composite, Entity, GlobalVariables, TextOptions, IText, EntityEvent, Point, CallbackOptions, ShapeOptions, LabelHorizontalAlignmentMode, Transition, StoryOptions, Story, Scene } from '@m2c2kit/core';
|
|
3
3
|
|
|
4
4
|
interface GridOptions extends CompositeOptions {
|
|
5
5
|
/** Number of rows in the grid. Must be 1 or greater */
|
|
@@ -30,7 +30,7 @@ declare class Grid extends Composite {
|
|
|
30
30
|
cellWidth: number;
|
|
31
31
|
cellHeight: number;
|
|
32
32
|
gridChildren: GridChild[];
|
|
33
|
-
private
|
|
33
|
+
private _gridBackground?;
|
|
34
34
|
/**
|
|
35
35
|
* A rectangular grid that supports placement of entities within the grid's
|
|
36
36
|
* cells.
|
|
@@ -43,6 +43,8 @@ declare class Grid extends Composite {
|
|
|
43
43
|
*/
|
|
44
44
|
constructor(options: GridOptions);
|
|
45
45
|
initialize(): void;
|
|
46
|
+
private get gridBackground();
|
|
47
|
+
private set gridBackground(value);
|
|
46
48
|
dispose(): void;
|
|
47
49
|
/**
|
|
48
50
|
* Duplicates an entity using deep copy.
|
|
@@ -60,7 +62,6 @@ declare class Grid extends Composite {
|
|
|
60
62
|
warmup(canvas: Canvas): void;
|
|
61
63
|
/**
|
|
62
64
|
* Removes all children from the grid, but retains grid lines.
|
|
63
|
-
*
|
|
64
65
|
*/
|
|
65
66
|
removeAllChildren(): void;
|
|
66
67
|
/**
|
|
@@ -205,6 +206,179 @@ declare class Dialog extends Composite {
|
|
|
205
206
|
warmup(canvas: Canvas): void;
|
|
206
207
|
}
|
|
207
208
|
|
|
209
|
+
interface DrawPadOptions extends CompositeOptions {
|
|
210
|
+
/** Size of the DrawPad */
|
|
211
|
+
size: Size;
|
|
212
|
+
/** Color of drawn lines. Default is red. */
|
|
213
|
+
lineColor?: RgbaColor;
|
|
214
|
+
/** Width of drawn lines. Default is 1 */
|
|
215
|
+
lineWidth?: number;
|
|
216
|
+
/** Background color of the DrawPad. Default is transparent. */
|
|
217
|
+
backgroundColor?: RgbaColor;
|
|
218
|
+
/** Width of the border. Default is 1 */
|
|
219
|
+
borderWidth?: number;
|
|
220
|
+
/** Color of the border. Default is black */
|
|
221
|
+
borderColor?: RgbaColor;
|
|
222
|
+
/** Does the DrawPad respond to user interaction? Default is true. */
|
|
223
|
+
isUserInteractionEnabled?: boolean;
|
|
224
|
+
/** Should drawing resume when the pointer, in a down state, returns to the DrawPad area after exiting it while drawing? Default is false. */
|
|
225
|
+
resumeDrawingOnReturn?: boolean;
|
|
226
|
+
/** Should the user be permitted to draw only one continuous line? If so, no more drawing is allowed after the first stroke ends. */
|
|
227
|
+
continuousDrawingOnly?: boolean;
|
|
228
|
+
/** If `continuousDrawingOnly`, this is the maximum pixel distance from the last stroke's end point that the user is allowed to continue drawing with a new stroke. */
|
|
229
|
+
continuousDrawingOnlyExceptionDistance?: number;
|
|
230
|
+
}
|
|
231
|
+
declare const DrawPadEventType: {
|
|
232
|
+
readonly StrokeStart: "StrokeStart";
|
|
233
|
+
readonly StrokeMove: "StrokeMove";
|
|
234
|
+
readonly StrokeEnd: "StrokeEnd";
|
|
235
|
+
};
|
|
236
|
+
type DrawPadEventType = (typeof DrawPadEventType)[keyof typeof DrawPadEventType];
|
|
237
|
+
interface DrawPadEvent extends EntityEvent {
|
|
238
|
+
type: DrawPadEventType;
|
|
239
|
+
position: Point;
|
|
240
|
+
}
|
|
241
|
+
declare const DrawPadItemEventType: {
|
|
242
|
+
readonly StrokeEnter: "StrokeEnter";
|
|
243
|
+
readonly StrokeLeave: "StrokeLeave";
|
|
244
|
+
};
|
|
245
|
+
type DrawPadItemEventType = (typeof DrawPadItemEventType)[keyof typeof DrawPadItemEventType];
|
|
246
|
+
interface DrawPadItemEvent extends EntityEvent {
|
|
247
|
+
type: DrawPadItemEventType;
|
|
248
|
+
}
|
|
249
|
+
interface StrokeInteraction {
|
|
250
|
+
/** Type of user interaction with the stroke: StrokeStart, StrokeMove, or StrokeEnd. */
|
|
251
|
+
type: DrawPadEventType;
|
|
252
|
+
/** Position on the DrawPad where the interaction occurred. In the DrawPad coordinate system, (0, 0) is the upper-left corner. */
|
|
253
|
+
position: Point;
|
|
254
|
+
/** Device ISO8601 Timestamp of the interaction. */
|
|
255
|
+
iso8601Timestamp: string;
|
|
256
|
+
}
|
|
257
|
+
type DrawPadStroke = Array<StrokeInteraction>;
|
|
258
|
+
interface DrawPadItem {
|
|
259
|
+
/**
|
|
260
|
+
* Executes a callback when a DrawPad stroke begins on or enters the DrawPadItem.
|
|
261
|
+
*
|
|
262
|
+
* @param callback - function to execute
|
|
263
|
+
* @param options - {@link CallbackOptions}
|
|
264
|
+
*/
|
|
265
|
+
onStrokeEnter(callback: (ev: DrawPadItemEvent) => void, options?: CallbackOptions): void;
|
|
266
|
+
/**
|
|
267
|
+
* Executes a callback when a DrawPad stroke leaves the DrawPadItem.
|
|
268
|
+
*
|
|
269
|
+
* @param callback - function to execute
|
|
270
|
+
* @param options - {@link CallbackOptions}
|
|
271
|
+
*/
|
|
272
|
+
onStrokeLeave(callback: (ev: DrawPadItemEvent) => void, options?: CallbackOptions): void;
|
|
273
|
+
/** Is a DrawPad stroke currently within the bounds of the DrawPad item? */
|
|
274
|
+
isStrokeWithinBounds: boolean;
|
|
275
|
+
/** Position of the DrawPadItem within the DrawPad coordinate system, in which (0, 0) is the upper-left corner. */
|
|
276
|
+
drawPadPosition: Point;
|
|
277
|
+
}
|
|
278
|
+
declare class DrawPad extends Composite {
|
|
279
|
+
compositeType: string;
|
|
280
|
+
resumeDrawingOnReturn: boolean;
|
|
281
|
+
continuousDrawingOnly: boolean;
|
|
282
|
+
continuousDrawingOnlyExceptionDistance: number | undefined;
|
|
283
|
+
private _backgroundColor;
|
|
284
|
+
private _borderColor;
|
|
285
|
+
private _borderWidth;
|
|
286
|
+
private _lineColor;
|
|
287
|
+
private _lineWidth;
|
|
288
|
+
/** The rectangular "pad" on which to draw */
|
|
289
|
+
private drawArea?;
|
|
290
|
+
/** The lines that are drawn */
|
|
291
|
+
private drawShape?;
|
|
292
|
+
private isDrawingPointerDown;
|
|
293
|
+
private pointerIsDownAndPointerLeftDrawAreaWhenDown;
|
|
294
|
+
private currentStrokesNotAllowed;
|
|
295
|
+
/** Array of strokes created on the DrawPad, with position and timestamps
|
|
296
|
+
* of all interactions with each DrawPadStroke.
|
|
297
|
+
*/
|
|
298
|
+
strokes: DrawPadStroke[];
|
|
299
|
+
/**
|
|
300
|
+
* A rectangular area on which the user can draw strokes (lines).
|
|
301
|
+
*
|
|
302
|
+
* @remarks This composite entity is composed of a rectangle Shape and
|
|
303
|
+
* another Shape that is formed from a path of points.
|
|
304
|
+
*
|
|
305
|
+
* @param options - {@link DrawPadOptions}
|
|
306
|
+
*/
|
|
307
|
+
constructor(options: DrawPadOptions);
|
|
308
|
+
initialize(): void;
|
|
309
|
+
private initializeDrawShape;
|
|
310
|
+
private initializeDrawArea;
|
|
311
|
+
private dist;
|
|
312
|
+
private handleTapDown;
|
|
313
|
+
private handleTapLeave;
|
|
314
|
+
private handleTapUpAny;
|
|
315
|
+
private handlePointerMove;
|
|
316
|
+
update(): void;
|
|
317
|
+
draw(canvas: Canvas): void;
|
|
318
|
+
private raiseDrawPadEvent;
|
|
319
|
+
private raiseDrawPadItemEvent;
|
|
320
|
+
/**
|
|
321
|
+
* Removes all strokes from the DrawPad.
|
|
322
|
+
*/
|
|
323
|
+
clear(): void;
|
|
324
|
+
warmup(canvas: Canvas): void;
|
|
325
|
+
/**
|
|
326
|
+
* Executes a callback when the user starts a stroke on the DrawPad.
|
|
327
|
+
*
|
|
328
|
+
* @param callback - function to execute
|
|
329
|
+
* @param options - {@link CallbackOptions}
|
|
330
|
+
*/
|
|
331
|
+
onStrokeStart(callback: (ev: DrawPadEvent) => void, options?: CallbackOptions): void;
|
|
332
|
+
/**
|
|
333
|
+
* Executes a callback when the user moves a stroke on the DrawPad.
|
|
334
|
+
*
|
|
335
|
+
* @param callback - function to execute
|
|
336
|
+
* @param options - {@link CallbackOptions}
|
|
337
|
+
*/
|
|
338
|
+
onStrokeMove(callback: (ev: DrawPadEvent) => void, options?: CallbackOptions): void;
|
|
339
|
+
/**
|
|
340
|
+
* Executes a callback when the user ends a stroke on the DrawPad.
|
|
341
|
+
*
|
|
342
|
+
* @param callback - function to execute
|
|
343
|
+
* @param options - {@link CallbackOptions}
|
|
344
|
+
*/
|
|
345
|
+
onStrokeEnd(callback: (ev: DrawPadEvent) => void, options?: CallbackOptions): void;
|
|
346
|
+
/**
|
|
347
|
+
* Adds an entity to the DrawPad.
|
|
348
|
+
*
|
|
349
|
+
* @remarks After the entity is added to the DrawPad, its
|
|
350
|
+
* position is adjusted to be relative to the DrawPad's coordinate
|
|
351
|
+
* system, and it is made interactive. The method returns an object
|
|
352
|
+
* which is the entity as a DrawPadItem, which has additional methods,
|
|
353
|
+
* properties, and events specific to it now being on a DrawPad. The entity
|
|
354
|
+
* now **must** be manipulated only using the DrawPadItem object. Using
|
|
355
|
+
* the original entity object will result in undefined behavior.
|
|
356
|
+
*
|
|
357
|
+
* @param entity - the entity to add to the DrawPad
|
|
358
|
+
* @returns the entity as a DrawPadItem
|
|
359
|
+
*/
|
|
360
|
+
addItem<T extends Entity>(entity: T): T & DrawPadItem;
|
|
361
|
+
/**
|
|
362
|
+
* Takes a screenshot of the DrawPad.
|
|
363
|
+
*
|
|
364
|
+
* @returns a base64-encoded string of the DrawPad's current state in
|
|
365
|
+
* PNG format.
|
|
366
|
+
*/
|
|
367
|
+
takeScreenshot(): string;
|
|
368
|
+
private arrayBufferToBase64String;
|
|
369
|
+
get backgroundColor(): RgbaColor;
|
|
370
|
+
set backgroundColor(backgroundColor: RgbaColor);
|
|
371
|
+
get borderColor(): RgbaColor;
|
|
372
|
+
set borderColor(borderColor: RgbaColor);
|
|
373
|
+
get borderWidth(): number;
|
|
374
|
+
set borderWidth(borderWidth: number);
|
|
375
|
+
get lineColor(): RgbaColor;
|
|
376
|
+
set lineColor(lineColor: RgbaColor);
|
|
377
|
+
get lineWidth(): number;
|
|
378
|
+
set lineWidth(lineWidth: number);
|
|
379
|
+
duplicate(newName?: string): DrawPad;
|
|
380
|
+
}
|
|
381
|
+
|
|
208
382
|
interface KeyConfiguration {
|
|
209
383
|
/** Width of the key in units of a regular key width. Default is 1. */
|
|
210
384
|
widthRatio?: number;
|
|
@@ -429,4 +603,4 @@ declare class Instructions extends Story {
|
|
|
429
603
|
static Create(options: InstructionsOptions): Array<Scene>;
|
|
430
604
|
}
|
|
431
605
|
|
|
432
|
-
export { Button, ButtonOptions, Dialog, DialogEvent, DialogOptions, DialogResult, Grid, GridOptions, InstructionScene, Instructions, InstructionsOptions, KeyConfiguration, KeyTapMetadata, VirtualKeyboard, VirtualKeyboardEvent, VirtualKeyboardOptions, VirtualKeyboardRow };
|
|
606
|
+
export { Button, ButtonOptions, Dialog, DialogEvent, DialogOptions, DialogResult, DrawPad, DrawPadEvent, DrawPadEventType, DrawPadItem, DrawPadItemEvent, DrawPadItemEventType, DrawPadOptions, DrawPadStroke, Grid, GridOptions, InstructionScene, Instructions, InstructionsOptions, KeyConfiguration, KeyTapMetadata, StrokeInteraction, VirtualKeyboard, VirtualKeyboardEvent, VirtualKeyboardOptions, VirtualKeyboardRow };
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { Composite, WebColors, Shape, Label, CanvasKitHelpers, EventType, Easings, Story, Transition, TransitionDirection, LabelHorizontalAlignmentMode, Scene, Dimensions, Sprite } from '@m2c2kit/core';
|
|
1
|
+
import { Composite, WebColors, Shape, Label, CanvasKitHelpers, EventType, MutablePath, Easings, Story, Transition, TransitionDirection, LabelHorizontalAlignmentMode, Scene, Dimensions, Sprite } from '@m2c2kit/core';
|
|
2
2
|
|
|
3
|
-
var __defProp$
|
|
3
|
+
var __defProp$4 = Object.defineProperty;
|
|
4
4
|
var __defProps$1 = Object.defineProperties;
|
|
5
5
|
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
6
6
|
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
7
7
|
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
9
|
-
var __defNormalProp$
|
|
9
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
10
|
var __spreadValues$1 = (a, b) => {
|
|
11
11
|
for (var prop in b || (b = {}))
|
|
12
12
|
if (__hasOwnProp$1.call(b, prop))
|
|
13
|
-
__defNormalProp$
|
|
13
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
14
14
|
if (__getOwnPropSymbols$1)
|
|
15
15
|
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
16
16
|
if (__propIsEnum$1.call(b, prop))
|
|
17
|
-
__defNormalProp$
|
|
17
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
18
18
|
}
|
|
19
19
|
return a;
|
|
20
20
|
};
|
|
21
21
|
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
22
|
-
var __publicField$
|
|
23
|
-
__defNormalProp$
|
|
22
|
+
var __publicField$4 = (obj, key, value) => {
|
|
23
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
24
|
return value;
|
|
25
25
|
};
|
|
26
26
|
class Grid extends Composite {
|
|
@@ -36,19 +36,19 @@ class Grid extends Composite {
|
|
|
36
36
|
*/
|
|
37
37
|
constructor(options) {
|
|
38
38
|
super(options);
|
|
39
|
-
__publicField$
|
|
39
|
+
__publicField$4(this, "compositeType", "grid");
|
|
40
40
|
// Grid options
|
|
41
41
|
// TODO: make getter, setter for these so they can be changed after initial construction
|
|
42
|
-
__publicField$
|
|
43
|
-
__publicField$
|
|
42
|
+
__publicField$4(this, "rows", 0);
|
|
43
|
+
__publicField$4(this, "columns", 0);
|
|
44
44
|
// default Grid is: transparent gray, red lines, line width 1
|
|
45
|
-
__publicField$
|
|
46
|
-
__publicField$
|
|
47
|
-
__publicField$
|
|
48
|
-
__publicField$
|
|
49
|
-
__publicField$
|
|
50
|
-
__publicField$
|
|
51
|
-
__publicField$
|
|
45
|
+
__publicField$4(this, "gridBackgroundColor", [0, 0, 233, 0.25]);
|
|
46
|
+
__publicField$4(this, "gridLineColor", WebColors.Red);
|
|
47
|
+
__publicField$4(this, "gridLineWidth", 1);
|
|
48
|
+
__publicField$4(this, "cellWidth");
|
|
49
|
+
__publicField$4(this, "cellHeight");
|
|
50
|
+
__publicField$4(this, "gridChildren", new Array());
|
|
51
|
+
__publicField$4(this, "_gridBackground");
|
|
52
52
|
if (options.size) {
|
|
53
53
|
this.size = options.size;
|
|
54
54
|
} else {
|
|
@@ -137,6 +137,15 @@ class Grid extends Composite {
|
|
|
137
137
|
}
|
|
138
138
|
this.needsInitialization = false;
|
|
139
139
|
}
|
|
140
|
+
get gridBackground() {
|
|
141
|
+
if (!this._gridBackground) {
|
|
142
|
+
throw new Error("gridBackground is null or undefined");
|
|
143
|
+
}
|
|
144
|
+
return this._gridBackground;
|
|
145
|
+
}
|
|
146
|
+
set gridBackground(gridBackground) {
|
|
147
|
+
this._gridBackground = gridBackground;
|
|
148
|
+
}
|
|
140
149
|
// all entities that make up grid are added as children, so they
|
|
141
150
|
// have their own dispose methods
|
|
142
151
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
@@ -185,17 +194,18 @@ class Grid extends Composite {
|
|
|
185
194
|
}
|
|
186
195
|
// override Entity.RemoveAllChildren() so that when RemoveAllChildren() is called on a Grid,
|
|
187
196
|
// it removes only entities added to the grid cells (what we call grid children), not the grid lines!
|
|
188
|
-
// note: when we upgrade to typescript 4.3+, we can mark this with override keyword to make intention explicit
|
|
189
197
|
/**
|
|
190
198
|
* Removes all children from the grid, but retains grid lines.
|
|
191
|
-
*
|
|
192
199
|
*/
|
|
193
200
|
removeAllChildren() {
|
|
194
201
|
if (this.gridChildren.length === 0) {
|
|
195
202
|
return;
|
|
196
203
|
}
|
|
197
204
|
while (this.gridChildren.length) {
|
|
198
|
-
this.gridChildren.pop();
|
|
205
|
+
const gridChild = this.gridChildren.pop();
|
|
206
|
+
if (gridChild) {
|
|
207
|
+
this.gridBackground.removeChild(gridChild.entity);
|
|
208
|
+
}
|
|
199
209
|
}
|
|
200
210
|
this.needsInitialization = true;
|
|
201
211
|
}
|
|
@@ -222,8 +232,17 @@ class Grid extends Composite {
|
|
|
222
232
|
* @param column - column position within grid at which to remove children; zero-based indexing
|
|
223
233
|
*/
|
|
224
234
|
removeAllAtCell(row, column) {
|
|
235
|
+
const gridChildrenToRemove = this.gridChildren.filter(
|
|
236
|
+
(gridChild) => gridChild.row === row && gridChild.column === column
|
|
237
|
+
);
|
|
238
|
+
if (gridChildrenToRemove.length === 0) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
this.gridBackground.removeChildren(
|
|
242
|
+
gridChildrenToRemove.map((gridChild) => gridChild.entity)
|
|
243
|
+
);
|
|
225
244
|
this.gridChildren = this.gridChildren.filter(
|
|
226
|
-
(gridChild) => gridChild.row
|
|
245
|
+
(gridChild) => gridChild.row !== row && gridChild.column !== column
|
|
227
246
|
);
|
|
228
247
|
this.needsInitialization = true;
|
|
229
248
|
}
|
|
@@ -235,9 +254,6 @@ class Grid extends Composite {
|
|
|
235
254
|
* @param entity - entity to remove
|
|
236
255
|
*/
|
|
237
256
|
removeChild(entity) {
|
|
238
|
-
if (!this.gridBackground) {
|
|
239
|
-
throw new Error("gridBackground is null or undefined");
|
|
240
|
-
}
|
|
241
257
|
this.gridBackground.removeChild(entity);
|
|
242
258
|
this.gridChildren = this.gridChildren.filter(
|
|
243
259
|
(gridChild) => gridChild.entity != entity
|
|
@@ -246,27 +262,27 @@ class Grid extends Composite {
|
|
|
246
262
|
}
|
|
247
263
|
}
|
|
248
264
|
|
|
249
|
-
var __defProp$
|
|
265
|
+
var __defProp$3 = Object.defineProperty;
|
|
250
266
|
var __defProps = Object.defineProperties;
|
|
251
267
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
252
268
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
253
269
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
254
270
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
255
|
-
var __defNormalProp$
|
|
271
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
256
272
|
var __spreadValues = (a, b) => {
|
|
257
273
|
for (var prop in b || (b = {}))
|
|
258
274
|
if (__hasOwnProp.call(b, prop))
|
|
259
|
-
__defNormalProp$
|
|
275
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
260
276
|
if (__getOwnPropSymbols)
|
|
261
277
|
for (var prop of __getOwnPropSymbols(b)) {
|
|
262
278
|
if (__propIsEnum.call(b, prop))
|
|
263
|
-
__defNormalProp$
|
|
279
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
264
280
|
}
|
|
265
281
|
return a;
|
|
266
282
|
};
|
|
267
283
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
268
|
-
var __publicField$
|
|
269
|
-
__defNormalProp$
|
|
284
|
+
var __publicField$3 = (obj, key, value) => {
|
|
285
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
270
286
|
return value;
|
|
271
287
|
};
|
|
272
288
|
class Button extends Composite {
|
|
@@ -283,15 +299,15 @@ class Button extends Composite {
|
|
|
283
299
|
*/
|
|
284
300
|
constructor(options) {
|
|
285
301
|
super(options);
|
|
286
|
-
__publicField$
|
|
302
|
+
__publicField$3(this, "compositeType", "button");
|
|
287
303
|
// Button options
|
|
288
|
-
__publicField$
|
|
289
|
-
__publicField$
|
|
290
|
-
__publicField$
|
|
291
|
-
__publicField$
|
|
292
|
-
__publicField$
|
|
293
|
-
__publicField$
|
|
294
|
-
__publicField$
|
|
304
|
+
__publicField$3(this, "_backgroundColor", WebColors.Black);
|
|
305
|
+
__publicField$3(this, "size", { width: 200, height: 50 });
|
|
306
|
+
__publicField$3(this, "cornerRadius", 9);
|
|
307
|
+
__publicField$3(this, "fontSize", 20);
|
|
308
|
+
__publicField$3(this, "text", "");
|
|
309
|
+
__publicField$3(this, "_fontColor", WebColors.White);
|
|
310
|
+
__publicField$3(this, "backgroundPaint");
|
|
295
311
|
if (options.text) {
|
|
296
312
|
this.text = options.text;
|
|
297
313
|
}
|
|
@@ -395,10 +411,10 @@ class Button extends Composite {
|
|
|
395
411
|
}
|
|
396
412
|
}
|
|
397
413
|
|
|
398
|
-
var __defProp$
|
|
399
|
-
var __defNormalProp$
|
|
400
|
-
var __publicField$
|
|
401
|
-
__defNormalProp$
|
|
414
|
+
var __defProp$2 = Object.defineProperty;
|
|
415
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
416
|
+
var __publicField$2 = (obj, key, value) => {
|
|
417
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
402
418
|
return value;
|
|
403
419
|
};
|
|
404
420
|
var DialogResult = /* @__PURE__ */ ((DialogResult2) => {
|
|
@@ -412,17 +428,17 @@ class Dialog extends Composite {
|
|
|
412
428
|
// todo: add default "behaviors" (?) like button click animation?
|
|
413
429
|
constructor(options) {
|
|
414
430
|
super(options);
|
|
415
|
-
__publicField$
|
|
416
|
-
__publicField$
|
|
417
|
-
__publicField$
|
|
418
|
-
__publicField$
|
|
419
|
-
__publicField$
|
|
420
|
-
__publicField$
|
|
421
|
-
__publicField$
|
|
422
|
-
__publicField$
|
|
423
|
-
__publicField$
|
|
424
|
-
__publicField$
|
|
425
|
-
__publicField$
|
|
431
|
+
__publicField$2(this, "compositeType", "dialog");
|
|
432
|
+
__publicField$2(this, "_backgroundColor", WebColors.White);
|
|
433
|
+
__publicField$2(this, "cornerRadius", 9);
|
|
434
|
+
__publicField$2(this, "overlayAlpha", 0.5);
|
|
435
|
+
__publicField$2(this, "contentText", "");
|
|
436
|
+
__publicField$2(this, "positiveButtonText", "");
|
|
437
|
+
__publicField$2(this, "negativeButtonText", "");
|
|
438
|
+
__publicField$2(this, "zPosition", Number.MAX_VALUE);
|
|
439
|
+
__publicField$2(this, "hidden", true);
|
|
440
|
+
__publicField$2(this, "_fontColor", WebColors.White);
|
|
441
|
+
__publicField$2(this, "backgroundPaint");
|
|
426
442
|
if (!options) {
|
|
427
443
|
return;
|
|
428
444
|
}
|
|
@@ -610,6 +626,521 @@ class Dialog extends Composite {
|
|
|
610
626
|
}
|
|
611
627
|
}
|
|
612
628
|
|
|
629
|
+
var __defProp$1 = Object.defineProperty;
|
|
630
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
631
|
+
var __publicField$1 = (obj, key, value) => {
|
|
632
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
633
|
+
return value;
|
|
634
|
+
};
|
|
635
|
+
const DrawPadEventType = {
|
|
636
|
+
StrokeStart: "StrokeStart",
|
|
637
|
+
StrokeMove: "StrokeMove",
|
|
638
|
+
StrokeEnd: "StrokeEnd"
|
|
639
|
+
};
|
|
640
|
+
const DrawPadItemEventType = {
|
|
641
|
+
StrokeEnter: "StrokeEnter",
|
|
642
|
+
StrokeLeave: "StrokeLeave"
|
|
643
|
+
};
|
|
644
|
+
class DrawPad extends Composite {
|
|
645
|
+
/**
|
|
646
|
+
* A rectangular area on which the user can draw strokes (lines).
|
|
647
|
+
*
|
|
648
|
+
* @remarks This composite entity is composed of a rectangle Shape and
|
|
649
|
+
* another Shape that is formed from a path of points.
|
|
650
|
+
*
|
|
651
|
+
* @param options - {@link DrawPadOptions}
|
|
652
|
+
*/
|
|
653
|
+
constructor(options) {
|
|
654
|
+
super(options);
|
|
655
|
+
__publicField$1(this, "compositeType", "DrawPad");
|
|
656
|
+
__publicField$1(this, "resumeDrawingOnReturn", false);
|
|
657
|
+
__publicField$1(this, "continuousDrawingOnly", false);
|
|
658
|
+
__publicField$1(this, "continuousDrawingOnlyExceptionDistance");
|
|
659
|
+
__publicField$1(this, "_backgroundColor", [0, 0, 0, 0]);
|
|
660
|
+
__publicField$1(this, "_borderColor", WebColors.Black);
|
|
661
|
+
__publicField$1(this, "_borderWidth", 1);
|
|
662
|
+
__publicField$1(this, "_lineColor", WebColors.Red);
|
|
663
|
+
__publicField$1(this, "_lineWidth", 1);
|
|
664
|
+
/** The rectangular "pad" on which to draw */
|
|
665
|
+
__publicField$1(this, "drawArea");
|
|
666
|
+
/** The lines that are drawn */
|
|
667
|
+
__publicField$1(this, "drawShape");
|
|
668
|
+
__publicField$1(this, "isDrawingPointerDown", false);
|
|
669
|
+
__publicField$1(this, "pointerIsDownAndPointerLeftDrawAreaWhenDown", false);
|
|
670
|
+
__publicField$1(this, "currentStrokesNotAllowed", false);
|
|
671
|
+
/** Array of strokes created on the DrawPad, with position and timestamps
|
|
672
|
+
* of all interactions with each DrawPadStroke.
|
|
673
|
+
*/
|
|
674
|
+
__publicField$1(this, "strokes", new Array());
|
|
675
|
+
if (options.isUserInteractionEnabled === void 0) {
|
|
676
|
+
this.isUserInteractionEnabled = true;
|
|
677
|
+
}
|
|
678
|
+
if (!options.size) {
|
|
679
|
+
throw new Error("DrawPad size must be specified");
|
|
680
|
+
}
|
|
681
|
+
this.size = options.size;
|
|
682
|
+
if (options.lineColor) {
|
|
683
|
+
this.lineColor = options.lineColor;
|
|
684
|
+
}
|
|
685
|
+
if (options.lineWidth) {
|
|
686
|
+
this.lineWidth = options.lineWidth;
|
|
687
|
+
}
|
|
688
|
+
if (options.backgroundColor) {
|
|
689
|
+
this.backgroundColor = options.backgroundColor;
|
|
690
|
+
}
|
|
691
|
+
if (options.borderColor) {
|
|
692
|
+
this.borderColor = options.borderColor;
|
|
693
|
+
}
|
|
694
|
+
if (options.borderWidth) {
|
|
695
|
+
this.borderWidth = options.borderWidth;
|
|
696
|
+
}
|
|
697
|
+
if (options.resumeDrawingOnReturn !== void 0) {
|
|
698
|
+
this.resumeDrawingOnReturn = options.resumeDrawingOnReturn;
|
|
699
|
+
}
|
|
700
|
+
if (options.continuousDrawingOnly !== void 0) {
|
|
701
|
+
this.continuousDrawingOnly = options.continuousDrawingOnly;
|
|
702
|
+
}
|
|
703
|
+
if (options.continuousDrawingOnlyExceptionDistance !== void 0) {
|
|
704
|
+
this.continuousDrawingOnlyExceptionDistance = options.continuousDrawingOnlyExceptionDistance;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
initialize() {
|
|
708
|
+
this.initializeDrawShape();
|
|
709
|
+
this.initializeDrawArea();
|
|
710
|
+
this.needsInitialization = false;
|
|
711
|
+
}
|
|
712
|
+
initializeDrawShape() {
|
|
713
|
+
if (!this.drawShape) {
|
|
714
|
+
const mutablePath = new MutablePath();
|
|
715
|
+
mutablePath.size = this.size;
|
|
716
|
+
this.drawShape = new Shape({
|
|
717
|
+
path: mutablePath
|
|
718
|
+
});
|
|
719
|
+
this.addChild(this.drawShape);
|
|
720
|
+
}
|
|
721
|
+
this.drawShape.strokeColor = this.lineColor;
|
|
722
|
+
this.drawShape.lineWidth = this.lineWidth;
|
|
723
|
+
}
|
|
724
|
+
initializeDrawArea() {
|
|
725
|
+
if (!this.drawArea) {
|
|
726
|
+
this.drawArea = new Shape({
|
|
727
|
+
rect: { size: this.size },
|
|
728
|
+
isUserInteractionEnabled: true
|
|
729
|
+
});
|
|
730
|
+
this.addChild(this.drawArea);
|
|
731
|
+
this.drawArea.onTapDown((e) => {
|
|
732
|
+
this.handleTapDown(e);
|
|
733
|
+
});
|
|
734
|
+
this.drawArea.onPointerMove((e) => {
|
|
735
|
+
this.handlePointerMove(e);
|
|
736
|
+
});
|
|
737
|
+
this.drawArea.onTapUpAny(() => {
|
|
738
|
+
this.handleTapUpAny();
|
|
739
|
+
});
|
|
740
|
+
this.drawArea.onTapLeave(() => {
|
|
741
|
+
this.handleTapLeave();
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
this.drawArea.fillColor = this.backgroundColor;
|
|
745
|
+
this.drawArea.strokeColor = this.borderColor;
|
|
746
|
+
this.drawArea.lineWidth = this.borderWidth;
|
|
747
|
+
}
|
|
748
|
+
dist(p1, p2) {
|
|
749
|
+
return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
|
|
750
|
+
}
|
|
751
|
+
handleTapDown(e) {
|
|
752
|
+
if (this.isUserInteractionEnabled) {
|
|
753
|
+
const drawShape = this.drawShape;
|
|
754
|
+
if (!drawShape) {
|
|
755
|
+
throw new Error("no draw shape");
|
|
756
|
+
}
|
|
757
|
+
const path = drawShape.path;
|
|
758
|
+
if (this.continuousDrawingOnly && path.subpaths.length !== 0) {
|
|
759
|
+
const prevPoint = path.subpaths[path.subpaths.length - 1][path.subpaths[path.subpaths.length - 1].length - 1];
|
|
760
|
+
const currentPoint = e.point;
|
|
761
|
+
if (this.continuousDrawingOnlyExceptionDistance === void 0 || this.dist(prevPoint, currentPoint) > this.continuousDrawingOnlyExceptionDistance) {
|
|
762
|
+
this.currentStrokesNotAllowed = true;
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
this.isDrawingPointerDown = true;
|
|
767
|
+
path.move(e.point);
|
|
768
|
+
const drawPadEvent = {
|
|
769
|
+
type: DrawPadEventType.StrokeStart,
|
|
770
|
+
target: this,
|
|
771
|
+
handled: false,
|
|
772
|
+
position: e.point
|
|
773
|
+
};
|
|
774
|
+
this.strokes.push([
|
|
775
|
+
{
|
|
776
|
+
type: DrawPadEventType.StrokeStart,
|
|
777
|
+
position: e.point,
|
|
778
|
+
iso8601Timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
779
|
+
}
|
|
780
|
+
]);
|
|
781
|
+
this.raiseDrawPadEvent(drawPadEvent);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
handleTapLeave() {
|
|
785
|
+
if (this.currentStrokesNotAllowed) {
|
|
786
|
+
this.isDrawingPointerDown = false;
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
if (this.resumeDrawingOnReturn === false) {
|
|
790
|
+
this.isDrawingPointerDown = false;
|
|
791
|
+
const strokeCount = this.strokes.length;
|
|
792
|
+
const strokeInteractionCount = this.strokes[strokeCount - 1].length;
|
|
793
|
+
const drawPadEvent = {
|
|
794
|
+
type: DrawPadEventType.StrokeEnd,
|
|
795
|
+
position: this.strokes[strokeCount - 1][strokeInteractionCount - 1].position,
|
|
796
|
+
target: this,
|
|
797
|
+
handled: false
|
|
798
|
+
};
|
|
799
|
+
this.strokes[strokeCount - 1].push({
|
|
800
|
+
type: DrawPadEventType.StrokeEnd,
|
|
801
|
+
position: this.strokes[strokeCount - 1][strokeInteractionCount - 1].position,
|
|
802
|
+
iso8601Timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
803
|
+
});
|
|
804
|
+
this.raiseDrawPadEvent(drawPadEvent);
|
|
805
|
+
} else {
|
|
806
|
+
this.pointerIsDownAndPointerLeftDrawAreaWhenDown = true;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
handleTapUpAny() {
|
|
810
|
+
if (this.currentStrokesNotAllowed) {
|
|
811
|
+
this.isDrawingPointerDown = false;
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
if (this.isUserInteractionEnabled) {
|
|
815
|
+
this.isDrawingPointerDown = false;
|
|
816
|
+
this.pointerIsDownAndPointerLeftDrawAreaWhenDown = false;
|
|
817
|
+
const strokeCount = this.strokes.length;
|
|
818
|
+
const strokeInteractionCount = this.strokes[strokeCount - 1].length;
|
|
819
|
+
const drawPadEvent = {
|
|
820
|
+
type: DrawPadEventType.StrokeEnd,
|
|
821
|
+
position: this.strokes[strokeCount - 1][strokeInteractionCount - 1].position,
|
|
822
|
+
target: this,
|
|
823
|
+
handled: false
|
|
824
|
+
};
|
|
825
|
+
this.strokes[strokeCount - 1].push({
|
|
826
|
+
type: DrawPadEventType.StrokeEnd,
|
|
827
|
+
position: this.strokes[strokeCount - 1][strokeInteractionCount - 1].position,
|
|
828
|
+
iso8601Timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
829
|
+
});
|
|
830
|
+
this.raiseDrawPadEvent(drawPadEvent);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
handlePointerMove(e) {
|
|
834
|
+
if (this.isUserInteractionEnabled && this.isDrawingPointerDown) {
|
|
835
|
+
const drawShape = this.drawShape;
|
|
836
|
+
if (!drawShape) {
|
|
837
|
+
throw new Error("no draw shape");
|
|
838
|
+
}
|
|
839
|
+
const path = drawShape.path;
|
|
840
|
+
if (this.isDrawingPointerDown && !this.pointerIsDownAndPointerLeftDrawAreaWhenDown) {
|
|
841
|
+
path.addLine(e.point);
|
|
842
|
+
}
|
|
843
|
+
if (this.pointerIsDownAndPointerLeftDrawAreaWhenDown) {
|
|
844
|
+
this.pointerIsDownAndPointerLeftDrawAreaWhenDown = false;
|
|
845
|
+
path.move(e.point);
|
|
846
|
+
}
|
|
847
|
+
const drawPadEvent = {
|
|
848
|
+
type: DrawPadEventType.StrokeMove,
|
|
849
|
+
target: this,
|
|
850
|
+
handled: false,
|
|
851
|
+
position: e.point
|
|
852
|
+
};
|
|
853
|
+
const strokeCount = this.strokes.length;
|
|
854
|
+
this.strokes[strokeCount - 1].push({
|
|
855
|
+
type: DrawPadEventType.StrokeMove,
|
|
856
|
+
position: e.point,
|
|
857
|
+
iso8601Timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
858
|
+
});
|
|
859
|
+
this.raiseDrawPadEvent(drawPadEvent);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
update() {
|
|
863
|
+
super.update();
|
|
864
|
+
}
|
|
865
|
+
draw(canvas) {
|
|
866
|
+
super.drawChildren(canvas);
|
|
867
|
+
}
|
|
868
|
+
raiseDrawPadEvent(event) {
|
|
869
|
+
if (this.eventListeners.length > 0) {
|
|
870
|
+
this.eventListeners.filter((listener) => listener.type === event.type).forEach((listener) => {
|
|
871
|
+
listener.callback(event);
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
raiseDrawPadItemEvent(item, event) {
|
|
876
|
+
if (item.eventListeners.length > 0) {
|
|
877
|
+
item.eventListeners.filter((listener) => listener.type === event.type).forEach((listener) => {
|
|
878
|
+
listener.callback(event);
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* Removes all strokes from the DrawPad.
|
|
884
|
+
*/
|
|
885
|
+
clear() {
|
|
886
|
+
const drawShape = this.drawShape;
|
|
887
|
+
if (!drawShape) {
|
|
888
|
+
throw new Error("no draw shape");
|
|
889
|
+
}
|
|
890
|
+
const path = drawShape.path;
|
|
891
|
+
path.clear();
|
|
892
|
+
this.strokes = new Array();
|
|
893
|
+
}
|
|
894
|
+
warmup(canvas) {
|
|
895
|
+
this.initialize();
|
|
896
|
+
this.children.filter((child) => child.isDrawable).forEach((child) => {
|
|
897
|
+
child.warmup(canvas);
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* Executes a callback when the user starts a stroke on the DrawPad.
|
|
902
|
+
*
|
|
903
|
+
* @param callback - function to execute
|
|
904
|
+
* @param options - {@link CallbackOptions}
|
|
905
|
+
*/
|
|
906
|
+
onStrokeStart(callback, options) {
|
|
907
|
+
this.addEventListener(
|
|
908
|
+
DrawPadEventType.StrokeStart,
|
|
909
|
+
callback,
|
|
910
|
+
options
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Executes a callback when the user moves a stroke on the DrawPad.
|
|
915
|
+
*
|
|
916
|
+
* @param callback - function to execute
|
|
917
|
+
* @param options - {@link CallbackOptions}
|
|
918
|
+
*/
|
|
919
|
+
onStrokeMove(callback, options) {
|
|
920
|
+
this.addEventListener(
|
|
921
|
+
DrawPadEventType.StrokeMove,
|
|
922
|
+
callback,
|
|
923
|
+
options
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Executes a callback when the user ends a stroke on the DrawPad.
|
|
928
|
+
*
|
|
929
|
+
* @param callback - function to execute
|
|
930
|
+
* @param options - {@link CallbackOptions}
|
|
931
|
+
*/
|
|
932
|
+
onStrokeEnd(callback, options) {
|
|
933
|
+
this.addEventListener(
|
|
934
|
+
DrawPadEventType.StrokeEnd,
|
|
935
|
+
callback,
|
|
936
|
+
options
|
|
937
|
+
);
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Adds an entity to the DrawPad.
|
|
941
|
+
*
|
|
942
|
+
* @remarks After the entity is added to the DrawPad, its
|
|
943
|
+
* position is adjusted to be relative to the DrawPad's coordinate
|
|
944
|
+
* system, and it is made interactive. The method returns an object
|
|
945
|
+
* which is the entity as a DrawPadItem, which has additional methods,
|
|
946
|
+
* properties, and events specific to it now being on a DrawPad. The entity
|
|
947
|
+
* now **must** be manipulated only using the DrawPadItem object. Using
|
|
948
|
+
* the original entity object will result in undefined behavior.
|
|
949
|
+
*
|
|
950
|
+
* @param entity - the entity to add to the DrawPad
|
|
951
|
+
* @returns the entity as a DrawPadItem
|
|
952
|
+
*/
|
|
953
|
+
addItem(entity) {
|
|
954
|
+
Object.defineProperty(entity, "drawPadPosition", {
|
|
955
|
+
get: function() {
|
|
956
|
+
const drawPad = entity.parent;
|
|
957
|
+
return {
|
|
958
|
+
get x() {
|
|
959
|
+
return entity.position.x + drawPad.size.width / 2;
|
|
960
|
+
},
|
|
961
|
+
set x(value) {
|
|
962
|
+
entity.position.x = value - drawPad.size.width / 2;
|
|
963
|
+
},
|
|
964
|
+
get y() {
|
|
965
|
+
return entity.position.y + drawPad.size.height / 2;
|
|
966
|
+
},
|
|
967
|
+
set y(value) {
|
|
968
|
+
entity.position.y = value - drawPad.size.height / 2;
|
|
969
|
+
}
|
|
970
|
+
};
|
|
971
|
+
},
|
|
972
|
+
set: function(value) {
|
|
973
|
+
const drawPad = entity.parent;
|
|
974
|
+
entity.position.x = value.x - drawPad.size.width / 2;
|
|
975
|
+
entity.position.y = value.y - drawPad.size.height / 2;
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
Object.defineProperty(entity, "onStrokeEnter", {
|
|
979
|
+
value: function(callback, options) {
|
|
980
|
+
this.addEventListener(
|
|
981
|
+
DrawPadItemEventType.StrokeEnter,
|
|
982
|
+
callback,
|
|
983
|
+
options
|
|
984
|
+
);
|
|
985
|
+
}
|
|
986
|
+
});
|
|
987
|
+
Object.defineProperty(entity, "onStrokeLeave", {
|
|
988
|
+
value: function(callback, options) {
|
|
989
|
+
this.addEventListener(
|
|
990
|
+
DrawPadItemEventType.StrokeLeave,
|
|
991
|
+
callback,
|
|
992
|
+
options
|
|
993
|
+
);
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
Object.defineProperty(entity, "isStrokeWithinBounds", {
|
|
997
|
+
value: false,
|
|
998
|
+
writable: true
|
|
999
|
+
});
|
|
1000
|
+
entity.onPointerDown(() => {
|
|
1001
|
+
if (this.isDrawingPointerDown) {
|
|
1002
|
+
if (entity.isStrokeWithinBounds === false) {
|
|
1003
|
+
entity.isStrokeWithinBounds = true;
|
|
1004
|
+
const drawPadItemEvent = {
|
|
1005
|
+
type: DrawPadItemEventType.StrokeEnter,
|
|
1006
|
+
target: entity
|
|
1007
|
+
};
|
|
1008
|
+
this.raiseDrawPadItemEvent(entity, drawPadItemEvent);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
});
|
|
1012
|
+
entity.onPointerMove(() => {
|
|
1013
|
+
if (this.isDrawingPointerDown) {
|
|
1014
|
+
if (entity.isStrokeWithinBounds === false) {
|
|
1015
|
+
entity.isStrokeWithinBounds = true;
|
|
1016
|
+
const drawPadItemEvent = {
|
|
1017
|
+
type: DrawPadItemEventType.StrokeEnter,
|
|
1018
|
+
target: entity
|
|
1019
|
+
};
|
|
1020
|
+
this.raiseDrawPadItemEvent(entity, drawPadItemEvent);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
entity.onPointerLeave(() => {
|
|
1025
|
+
if (this.isDrawingPointerDown) {
|
|
1026
|
+
if (entity.isStrokeWithinBounds === true) {
|
|
1027
|
+
entity.isStrokeWithinBounds = false;
|
|
1028
|
+
const drawPadItemEvent = {
|
|
1029
|
+
type: DrawPadItemEventType.StrokeLeave,
|
|
1030
|
+
target: entity
|
|
1031
|
+
};
|
|
1032
|
+
this.raiseDrawPadItemEvent(entity, drawPadItemEvent);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
});
|
|
1036
|
+
entity.onPointerUp(() => {
|
|
1037
|
+
if (entity.isStrokeWithinBounds === true) {
|
|
1038
|
+
entity.isStrokeWithinBounds = false;
|
|
1039
|
+
const drawPadItemEvent = {
|
|
1040
|
+
type: DrawPadItemEventType.StrokeLeave,
|
|
1041
|
+
target: entity
|
|
1042
|
+
};
|
|
1043
|
+
this.raiseDrawPadItemEvent(entity, drawPadItemEvent);
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
this.addChild(entity);
|
|
1047
|
+
entity.zPosition = -1;
|
|
1048
|
+
entity.position.x = entity.position.x - this.size.width / 2;
|
|
1049
|
+
entity.position.y = entity.position.y - this.size.height / 2;
|
|
1050
|
+
entity.isUserInteractionEnabled = true;
|
|
1051
|
+
return entity;
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* Takes a screenshot of the DrawPad.
|
|
1055
|
+
*
|
|
1056
|
+
* @returns a base64-encoded string of the DrawPad's current state in
|
|
1057
|
+
* PNG format.
|
|
1058
|
+
*/
|
|
1059
|
+
takeScreenshot() {
|
|
1060
|
+
const surface = this.game.surface;
|
|
1061
|
+
if (!surface) {
|
|
1062
|
+
throw new Error("no surface");
|
|
1063
|
+
}
|
|
1064
|
+
const drawArea = this.drawArea;
|
|
1065
|
+
if (!drawArea) {
|
|
1066
|
+
throw new Error("no draw area");
|
|
1067
|
+
}
|
|
1068
|
+
const sx = (drawArea.absolutePosition.x - drawArea.size.width / 2) * Globals.canvasScale;
|
|
1069
|
+
const sy = (drawArea.absolutePosition.y - drawArea.size.height / 2) * Globals.canvasScale;
|
|
1070
|
+
const sw = drawArea.size.width * Globals.canvasScale;
|
|
1071
|
+
const sh = drawArea.size.height * Globals.canvasScale;
|
|
1072
|
+
const imageInfo = {
|
|
1073
|
+
alphaType: this.game.canvasKit.AlphaType.Unpremul,
|
|
1074
|
+
colorType: this.game.canvasKit.ColorType.RGBA_8888,
|
|
1075
|
+
colorSpace: this.game.canvasKit.ColorSpace.SRGB,
|
|
1076
|
+
width: sw,
|
|
1077
|
+
height: sh
|
|
1078
|
+
};
|
|
1079
|
+
const snapshot = this.game.snapshots[0];
|
|
1080
|
+
const pixelData = snapshot.readPixels(sx, sy, imageInfo);
|
|
1081
|
+
const croppedImage = this.game.canvasKit.MakeImage(
|
|
1082
|
+
imageInfo,
|
|
1083
|
+
pixelData,
|
|
1084
|
+
pixelData.length / sh
|
|
1085
|
+
);
|
|
1086
|
+
if (!croppedImage) {
|
|
1087
|
+
throw new Error("no cropped image");
|
|
1088
|
+
}
|
|
1089
|
+
const bytes = croppedImage.encodeToBytes();
|
|
1090
|
+
if (!bytes) {
|
|
1091
|
+
throw new Error("no bytes");
|
|
1092
|
+
}
|
|
1093
|
+
croppedImage.delete();
|
|
1094
|
+
return this.arrayBufferToBase64String(bytes);
|
|
1095
|
+
}
|
|
1096
|
+
arrayBufferToBase64String(buffer) {
|
|
1097
|
+
let binary = "";
|
|
1098
|
+
const bytes = new Uint8Array(buffer);
|
|
1099
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
1100
|
+
binary += String.fromCharCode(bytes[i]);
|
|
1101
|
+
}
|
|
1102
|
+
return window.btoa(binary);
|
|
1103
|
+
}
|
|
1104
|
+
get backgroundColor() {
|
|
1105
|
+
return this._backgroundColor;
|
|
1106
|
+
}
|
|
1107
|
+
set backgroundColor(backgroundColor) {
|
|
1108
|
+
this._backgroundColor = backgroundColor;
|
|
1109
|
+
this.needsInitialization = true;
|
|
1110
|
+
}
|
|
1111
|
+
get borderColor() {
|
|
1112
|
+
return this._borderColor;
|
|
1113
|
+
}
|
|
1114
|
+
set borderColor(borderColor) {
|
|
1115
|
+
this._borderColor = borderColor;
|
|
1116
|
+
this.needsInitialization = true;
|
|
1117
|
+
}
|
|
1118
|
+
get borderWidth() {
|
|
1119
|
+
return this._borderWidth;
|
|
1120
|
+
}
|
|
1121
|
+
set borderWidth(borderWidth) {
|
|
1122
|
+
this._borderWidth = borderWidth;
|
|
1123
|
+
this.needsInitialization = true;
|
|
1124
|
+
}
|
|
1125
|
+
get lineColor() {
|
|
1126
|
+
return this._lineColor;
|
|
1127
|
+
}
|
|
1128
|
+
set lineColor(lineColor) {
|
|
1129
|
+
this._lineColor = lineColor;
|
|
1130
|
+
this.needsInitialization = true;
|
|
1131
|
+
}
|
|
1132
|
+
get lineWidth() {
|
|
1133
|
+
return this._lineWidth;
|
|
1134
|
+
}
|
|
1135
|
+
set lineWidth(lineWidth) {
|
|
1136
|
+
this._lineWidth = lineWidth;
|
|
1137
|
+
this.needsInitialization = true;
|
|
1138
|
+
}
|
|
1139
|
+
duplicate(newName) {
|
|
1140
|
+
throw new Error("Method not implemented.");
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
|
|
613
1144
|
var __defProp = Object.defineProperty;
|
|
614
1145
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
615
1146
|
var __publicField = (obj, key, value) => {
|
|
@@ -1311,7 +1842,7 @@ class Instructions extends Story {
|
|
|
1311
1842
|
}
|
|
1312
1843
|
}
|
|
1313
1844
|
|
|
1314
|
-
console.log("\u26AA @m2c2kit/addons version 0.3.
|
|
1845
|
+
console.log("\u26AA @m2c2kit/addons version 0.3.10 (291d0cee)");
|
|
1315
1846
|
|
|
1316
|
-
export { Button, Dialog, DialogResult, Grid, Instructions, VirtualKeyboard };
|
|
1847
|
+
export { Button, Dialog, DialogResult, DrawPad, DrawPadEventType, DrawPadItemEventType, Grid, Instructions, VirtualKeyboard };
|
|
1317
1848
|
//# sourceMappingURL=index.js.map
|