js-draw 0.24.0 → 0.24.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/README.md +217 -0
- package/dist/bundle.js +1 -1
- package/dist/cjs/shortcuts/KeyBinding.js +1 -1
- package/dist/mjs/shortcuts/KeyBinding.mjs +1 -1
- package/package.json +3 -2
- package/src/shortcuts/KeyBinding.ts +1 -1
- package/src/tools/PanZoom.test.ts +39 -0
- package/tools/copyREADME.ts +62 -0
@@ -18,7 +18,7 @@ var KeyBinding = /** @class */ (function () {
|
|
18
18
|
var isUpperCaseKey = ((_b = keyEvent.key) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === keyEvent.key
|
19
19
|
&& ((_c = keyEvent.key) === null || _c === void 0 ? void 0 : _c.toLowerCase()) !== keyEvent.key
|
20
20
|
&& ((_d = keyEvent.key) === null || _d === void 0 ? void 0 : _d.length) === 1;
|
21
|
-
var isLowercaseKey = ((_e = keyEvent.key) === null || _e === void 0 ? void 0 : _e.toLowerCase())
|
21
|
+
var isLowercaseKey = ((_e = keyEvent.key) === null || _e === void 0 ? void 0 : _e.toLowerCase()) === keyEvent.key
|
22
22
|
&& !isUpperCaseKey
|
23
23
|
&& ((_f = keyEvent.key) === null || _f === void 0 ? void 0 : _f.length) === 1;
|
24
24
|
var ctrlKey = ((_g = keyEvent.ctrlKey) !== null && _g !== void 0 ? _g : false) || lowercaseKey === 'control';
|
@@ -16,7 +16,7 @@ var KeyBinding = /** @class */ (function () {
|
|
16
16
|
var isUpperCaseKey = ((_b = keyEvent.key) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === keyEvent.key
|
17
17
|
&& ((_c = keyEvent.key) === null || _c === void 0 ? void 0 : _c.toLowerCase()) !== keyEvent.key
|
18
18
|
&& ((_d = keyEvent.key) === null || _d === void 0 ? void 0 : _d.length) === 1;
|
19
|
-
var isLowercaseKey = ((_e = keyEvent.key) === null || _e === void 0 ? void 0 : _e.toLowerCase())
|
19
|
+
var isLowercaseKey = ((_e = keyEvent.key) === null || _e === void 0 ? void 0 : _e.toLowerCase()) === keyEvent.key
|
20
20
|
&& !isUpperCaseKey
|
21
21
|
&& ((_f = keyEvent.key) === null || _f === void 0 ? void 0 : _f.length) === 1;
|
22
22
|
var ctrlKey = ((_g = keyEvent.ctrlKey) !== null && _g !== void 0 ? _g : false) || lowercaseKey === 'control';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "js-draw",
|
3
|
-
"version": "0.24.
|
3
|
+
"version": "0.24.1",
|
4
4
|
"description": "Draw pictures using a pen, touchscreen, or mouse! JS-draw is a drawing library for JavaScript and TypeScript. ",
|
5
5
|
"types": "./dist/mjs/lib.d.ts",
|
6
6
|
"main": "./dist/cjs/lib.js",
|
@@ -71,7 +71,8 @@
|
|
71
71
|
"build": "rm -rf ./dist && mkdir dist && build-tool build",
|
72
72
|
"watch": "rm -rf ./dist && mkdir dist && build-tool watch",
|
73
73
|
"build-translation-template": "build-tool build-translation-template",
|
74
|
-
"prepack": "npm run dist && cd ../../ && npm run test && cd packages/js-draw"
|
74
|
+
"prepack": "npm run dist && cd ../../ && npm run test && cd packages/js-draw && ts-node tools/copyREADME.ts copy",
|
75
|
+
"postpack": "ts-node tools/copyREADME.ts revert"
|
75
76
|
},
|
76
77
|
"dependencies": {
|
77
78
|
"@melloware/coloris": "0.20.0",
|
@@ -60,7 +60,7 @@ export default class KeyBinding implements KeyCombination {
|
|
60
60
|
const isUpperCaseKey = keyEvent.key?.toUpperCase() === keyEvent.key
|
61
61
|
&& keyEvent.key?.toLowerCase() !== keyEvent.key
|
62
62
|
&& keyEvent.key?.length === 1;
|
63
|
-
const isLowercaseKey = keyEvent.key?.toLowerCase()
|
63
|
+
const isLowercaseKey = keyEvent.key?.toLowerCase() === keyEvent.key
|
64
64
|
&& !isUpperCaseKey
|
65
65
|
&& keyEvent.key?.length === 1;
|
66
66
|
|
@@ -307,4 +307,43 @@ describe('PanZoom', () => {
|
|
307
307
|
lastVisibleRect = editor.viewport.visibleRect;
|
308
308
|
}
|
309
309
|
});
|
310
|
+
|
311
|
+
it('"r" and "R" keyboard shortcuts should rotate the viewport in opposite directions', () => {
|
312
|
+
const editor = createEditor();
|
313
|
+
selectPanZom(editor);
|
314
|
+
editor.viewport.resetTransform(Mat33.identity);
|
315
|
+
|
316
|
+
// Returns the transformed version of [vec], treating the vector as
|
317
|
+
// starting at the center of the editor's visible region.
|
318
|
+
const transformedVec = (vec: Vec2) => {
|
319
|
+
const canvasToScreen = editor.viewport.canvasToScreenTransform;
|
320
|
+
const center = editor.viewport.visibleRect.center;
|
321
|
+
|
322
|
+
const transformedEnd = canvasToScreen.transformVec2(center.plus(vec));
|
323
|
+
const transformedStart = canvasToScreen.transformVec2(center);
|
324
|
+
return transformedEnd.minus(transformedStart);
|
325
|
+
};
|
326
|
+
|
327
|
+
const tolerableError = 0.001;
|
328
|
+
|
329
|
+
expect(transformedVec(Vec2.unitX).length()).toBeCloseTo(1);
|
330
|
+
|
331
|
+
editor.toolController.dispatchInputEvent({
|
332
|
+
kind: InputEvtType.KeyPressEvent,
|
333
|
+
ctrlKey: false,
|
334
|
+
altKey: false,
|
335
|
+
key: 'r',
|
336
|
+
});
|
337
|
+
expect(transformedVec(Vec2.unitX).length()).toBeCloseTo(1);
|
338
|
+
expect(transformedVec(Vec2.unitX)).not.objEq(Vec2.unitX, tolerableError);
|
339
|
+
|
340
|
+
editor.toolController.dispatchInputEvent({
|
341
|
+
kind: InputEvtType.KeyPressEvent,
|
342
|
+
ctrlKey: false,
|
343
|
+
altKey: false,
|
344
|
+
key: 'R',
|
345
|
+
});
|
346
|
+
expect(transformedVec(Vec2.unitX).length()).toBeCloseTo(1);
|
347
|
+
expect(transformedVec(Vec2.unitX)).objEq(Vec2.unitX, tolerableError);
|
348
|
+
});
|
310
349
|
});
|
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
// Copies this repository's root README and its resources to the js-draw folder
|
3
|
+
// prior to bundling. This allows the README to be shown on NPM.
|
4
|
+
import * as fs from 'node:fs';
|
5
|
+
import * as path from 'node:path';
|
6
|
+
|
7
|
+
// Path to the root repository
|
8
|
+
const packagePath = path.dirname(__dirname);
|
9
|
+
const rootPath = path.dirname(path.dirname(packagePath));
|
10
|
+
|
11
|
+
const relativeReadmeResourcesPath = path.join('docs', 'img', 'readme-images');
|
12
|
+
const originalReadmePath = path.join(rootPath, 'README.md');
|
13
|
+
const targetReadmePath = path.join(packagePath, 'README.md');
|
14
|
+
const originalReadmeResourcesPath = path.join(rootPath, relativeReadmeResourcesPath);
|
15
|
+
const targetReadmeResourcesPath = path.join(packagePath, relativeReadmeResourcesPath);
|
16
|
+
|
17
|
+
const lastArg = process.argv[process.argv.length - 1];
|
18
|
+
if (lastArg !== 'revert' && lastArg !== 'copy') {
|
19
|
+
console.log(`Usage: ${process.argv0} revert`);
|
20
|
+
console.log(` or ${process.argv0} copy`);
|
21
|
+
process.exit(1);
|
22
|
+
}
|
23
|
+
|
24
|
+
if (lastArg === 'copy') {
|
25
|
+
console.log('Copying README.md and its dependencies to the js-draw package...');
|
26
|
+
if (fs.existsSync(targetReadmePath)) {
|
27
|
+
console.error('ERROR: README already exists in target location. Exiting.');
|
28
|
+
console.error('Be careful running postpack: It will DELETE this README and associated resources');
|
29
|
+
process.exit(1);
|
30
|
+
}
|
31
|
+
|
32
|
+
if (fs.existsSync(targetReadmeResourcesPath)) {
|
33
|
+
console.error('ERROR: README resources directory already exists in this package. Exiting.');
|
34
|
+
console.error('Be careful running postpack: It will delete this resources directory.');
|
35
|
+
process.exit(1);
|
36
|
+
}
|
37
|
+
|
38
|
+
fs.copyFileSync(originalReadmePath, targetReadmePath);
|
39
|
+
fs.mkdirSync(targetReadmeResourcesPath, { recursive: true });
|
40
|
+
|
41
|
+
for (const filePath of fs.readdirSync(originalReadmeResourcesPath)) {
|
42
|
+
const sourcePath = path.join(originalReadmeResourcesPath, filePath);
|
43
|
+
const targetPath = path.join(targetReadmeResourcesPath, filePath);
|
44
|
+
fs.copyFileSync(sourcePath, targetPath);
|
45
|
+
}
|
46
|
+
} else {
|
47
|
+
console.log('Removing the copied README.md and its dependencies from the js-draw package...');
|
48
|
+
if (!fs.existsSync(targetReadmePath)) {
|
49
|
+
console.error('ERROR: README does not exist in target location. Exiting.');
|
50
|
+
process.exit(1);
|
51
|
+
}
|
52
|
+
|
53
|
+
if (!fs.existsSync(targetReadmeResourcesPath)) {
|
54
|
+
console.error('ERROR: README resources directory does not exist in the target location. Exiting.');
|
55
|
+
process.exit(1);
|
56
|
+
}
|
57
|
+
|
58
|
+
fs.unlinkSync(targetReadmePath);
|
59
|
+
fs.rmSync(targetReadmeResourcesPath, { recursive: true });
|
60
|
+
}
|
61
|
+
|
62
|
+
|