Skip to content

Commit

Permalink
Merge pull request #68 from Ubugeeei/67-remove-shortcuts
Browse files Browse the repository at this point in the history
#67 remove shortcuts
  • Loading branch information
ubugeeei authored Oct 19, 2023
2 parents 558c817 + a9e5159 commit 2e3e197
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 60 deletions.
4 changes: 2 additions & 2 deletions docs/introduction/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ or install partial packages (e.g. `@tecack/frontend`: [read more documentation](
```ts
import { createTecack, recognize, KANJI_DATA_SET } from "tecack";

const tecack = createTecack(document);
const tecack = createTecack();

tecack.mount("#my-canvas");

Expand All @@ -39,7 +39,7 @@ window.addEventListener("mouseup", () => {
// client
import { createTecack } from "@tecack/frontend";

const tecack = createTecack(document);
const tecack = createTecack();

tecack.mount("#my-canvas");

Expand Down
13 changes: 6 additions & 7 deletions docs/reference/apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Creates Tecack instance for drawing on canvas.
- #### Type

```ts
function createTecack(document: Document): Tecack;
function createTecack(): Tecack;

interface Tecack {
mount: (selector: string) => void | InitializeError;
Expand All @@ -22,7 +22,6 @@ Creates Tecack instance for drawing on canvas.
// redraw: () => void | CanvasCtxNotFoundError;
// normalizeLinear: () => void;
// draw: (color?: string) => void | CanvasCtxNotFoundError;
// copyStuff: () => void;
}
```

Expand All @@ -31,7 +30,7 @@ Creates Tecack instance for drawing on canvas.
```ts
import { createTecack } from "@tecack/frontend";
const tecack = createTecack(document);
const tecack = createTecack();
```

### Tecack.mount()
Expand All @@ -49,7 +48,7 @@ Mounts Tecack instance to canvas element.
```ts
import { createTecack, InitializeError } from "@tecack/frontend";
const tecack = createTecack(document);
const tecack = createTecack();
const res = tecack.mount("#my-canvas");
if (res instanceof InitializeError) {
// handle error
Expand All @@ -71,7 +70,7 @@ Deletes last stroke from canvas and instance internal data.
```ts
import { createTecack, CanvasCtxNotFoundError } from "@tecack/frontend";
const tecack = createTecack(document);
const tecack = createTecack();
tecack.mount("#my-canvas");
const deleteLastButton = document.getElementById("delete-last");
Expand All @@ -98,7 +97,7 @@ Erases all strokes from canvas and instance internal data.
```ts
import { createTecack, CanvasCtxNotFoundError } from "@tecack/frontend";
const tecack = createTecack(document);
const tecack = createTecack();
tecack.mount("#my-canvas");
const eraseButton = document.getElementById("erase");
Expand Down Expand Up @@ -126,7 +125,7 @@ You can use this data for restore strokes or backend recognition.
```ts
import { createTecack } from "@tecack/frontend";
const tecack = createTecack(document);
const tecack = createTecack();
tecack.mount("#my-canvas");
const strokes = tecack.getStrokes();
Expand Down
2 changes: 1 addition & 1 deletion examples/_basic/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { recognize } from "@tecack/backend";
import { KANJI_DATA_SET } from "@tecack/dataset";
import { HIRAGANA_DATA } from "./hiragana";

const tecack = createTecack(document);
const tecack = createTecack();
tecack.mount("#tecack-sample");

const candidateContainer = document.getElementById("candidate-container")!;
Expand Down
2 changes: 1 addition & 1 deletion examples/_simple/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createTecack, recognize, KANJI_DATA_SET } from "tecack";

const tecack = createTecack(document);
const tecack = createTecack();

tecack.mount("#my-canvas");

Expand Down
2 changes: 1 addition & 1 deletion examples/ipc/client/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "./style.css";
import { createTecack } from "@tecack/frontend";
import { encodeStroke } from "@tecack/shared";

const tecack = createTecack(document);
const tecack = createTecack();
tecack.mount("#tecack-sample");

let encode = false;
Expand Down
2 changes: 1 addition & 1 deletion examples/viewer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "./style.css";
import { createTecack } from "@tecack/frontend";
import { KANJI_DATA_SET } from "@tecack/dataset";

const tecack = createTecack(document);
const tecack = createTecack();
tecack.mount("#viewer");

const charInput = document.getElementById("char-input") as HTMLInputElement | null;
Expand Down
49 changes: 2 additions & 47 deletions packages/frontend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface Tecack {
draw: (color?: string) => void | CanvasCtxNotFoundError;
deleteLast: () => void | CanvasCtxNotFoundError;
erase: () => void | CanvasCtxNotFoundError;
copyStuff: () => void;

/**
* redraw to current canvas according to
Expand All @@ -30,7 +29,7 @@ export interface Tecack {
normalizeLinear: () => void;
}

export function createTecack(document: Document): Tecack {
export function createTecack(): Tecack {
// private properties
let _selector: string;
let _canvas: HTMLCanvasElement;
Expand Down Expand Up @@ -64,7 +63,7 @@ export function createTecack(document: Document): Tecack {
const tecack: Tecack = {
mount: selector => {
_selector = selector;
const c = document.querySelector(_selector);
const c = window.document.querySelector(_selector);
if (!c) {
return new InitializeError(`Canvas#${_selector} was not found.`);
}
Expand Down Expand Up @@ -157,8 +156,6 @@ export function createTecack(document: Document): Tecack {
_ctx.lineTo(_currX, _currY);
_ctx.strokeStyle = color ? color : "#333";
_ctx.lineCap = "round";
//Tecack.ctx.lineJoin = "round";
//Tecack.ctx.lineMiter = "round";
_ctx.lineWidth = 4;
_ctx.stroke();
_ctx.closePath();
Expand Down Expand Up @@ -279,17 +276,6 @@ export function createTecack(document: Document): Tecack {
tecack.redraw();
},

copyStuff: () => {
_s = "";
for (var i = 0, j = _recordedPattern.length; i < j; i++) {
console.log(i + 1, _recordedPattern[i], _recordedPattern[i].toString());
console.log(_recordedPattern[i]);
console.log(JSON.stringify(_recordedPattern[i]));
_s += "[" + JSON.stringify(_recordedPattern[i]) + "],";
}
_copyToClipboard(_s);
},

getStrokes: () => {
return _recordedPattern;
},
Expand All @@ -309,15 +295,6 @@ export function createTecack(document: Document): Tecack {
},
};

const _copyToClipboard = (str: string) => {
var el = document.createElement("textarea");
el.value = str;
document.body.appendChild(el);
el.select();
document.execCommand("copy");
document.body.removeChild(el);
};

const _find_x_y = (res: string, e: MouseEvent | TouchEvent): void | CanvasCtxNotFoundError => {
const isTouch = isTouchEvent(e);
var touch = isTouch ? e.changedTouches[0] : null;
Expand Down Expand Up @@ -412,28 +389,6 @@ export function createTecack(document: Document): Tecack {
return "#" + color.join("");
};

// event listener for shortcuts
document.addEventListener("keydown", function (e) {
if (_canvas && e.ctrlKey) {
switch (e.key.toLowerCase()) {
// undo
case "z":
e.preventDefault();
tecack.deleteLast();
break;

// erase
case "x":
e.preventDefault();
tecack.erase();
break;

default:
break;
}
}
});

const createCanvasError = () =>
new CanvasCtxNotFoundError(`CanvasRenderingContext2D for Canvas#${_selector} was not found.`);

Expand Down

0 comments on commit 2e3e197

Please sign in to comment.