@nyris/nyris-webapp 0.3.4 → 0.3.5

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.
@@ -1,10 +0,0 @@
1
- export type NyrisAppPart = 'start' | 'camera' | 'results';
2
- export type NyrisFeedbackState = 'hidden' | 'question' | 'positive' | 'negative';
3
- export type NyrisAction =
4
- | { type: 'SHOW_START' }
5
- | { type: 'SHOW_CAMERA' }
6
- | { type: 'SHOW_RESULTS' }
7
- | { type: 'SHOW_FEEDBACK' }
8
- | { type: 'HIDE_FEEDBACK' }
9
- | { type: 'RESULT_LINK_CLICKED', position: number, url: string}
10
- | { type: 'RESULT_IMAGE_CLICKED', position: number, url: string}
@@ -1,24 +0,0 @@
1
- import NyrisAPI from "@nyris/nyris-api";
2
-
3
- export const findByImage = async (image: any, options: any, settings: any) => {
4
-
5
- try {
6
- const api = new NyrisAPI(settings);
7
- const {
8
- results,
9
- duration,
10
- requestId,
11
- categoryPredictions,
12
- codes,
13
- } = await api.findByImage(image, options);
14
- return {
15
- results,
16
- duration,
17
- requestId,
18
- categoryPredictions,
19
- codes,
20
- };
21
- } catch (error) {
22
- console.log("error findByImage", error);
23
- }
24
- };
@@ -1,15 +0,0 @@
1
- import {
2
- ImageSearchOptions,
3
- Region,
4
- Result,
5
- SearchServiceSettings,
6
- } from "./types";
7
- // import {canvasToJpgBlob, getElementSize, getThumbSizeArea, toCanvas} from "./nyris";
8
- import axios, { AxiosInstance } from "axios";
9
- import {
10
- canvasToJpgBlob,
11
- getElementSize,
12
- getThumbSizeArea,
13
- toCanvas,
14
- } from "./nyris";
15
-
@@ -1,123 +0,0 @@
1
- import loadImage from "blueimp-load-image";
2
- import { Crop, WH } from "./types";
3
-
4
- export function getElementSize(
5
- elem: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement
6
- ) {
7
- const img = elem as HTMLImageElement;
8
- const video = elem as HTMLVideoElement;
9
- return [
10
- img.naturalWidth || video.videoWidth || elem.width,
11
- img.naturalHeight || video.videoHeight || elem.height,
12
- ];
13
- }
14
-
15
- export function getThumbSizeArea(
16
- maxWidth: number,
17
- maxHeight: number,
18
- originalWidth: number,
19
- originalHeight: number
20
- ): WH {
21
- const targetArea = maxWidth * maxHeight;
22
-
23
- const aspectRatio = originalWidth / originalHeight;
24
- const width = Math.sqrt(targetArea * aspectRatio);
25
- return {
26
- w: width,
27
- h: width / aspectRatio,
28
- };
29
- }
30
-
31
- // TODO get rid of crop type
32
- export function toCanvas(
33
- elem: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement,
34
- newSize?: WH,
35
- canvas?: HTMLCanvasElement,
36
- crop?: Crop
37
- ): HTMLCanvasElement {
38
- let [ow, oh] = getElementSize(elem);
39
- if (!crop) {
40
- crop = {
41
- x: 0,
42
- y: 0,
43
- w: ow,
44
- h: oh,
45
- };
46
- }
47
- const sx = crop.x;
48
- const sy = crop.y;
49
- const sw = crop.w;
50
- const sh = crop.h;
51
-
52
- const dw = (newSize && newSize.w) || ow;
53
- const dh = (newSize && newSize.h) || oh;
54
-
55
- if (!canvas) canvas = document.createElement("canvas");
56
-
57
- canvas.width = dw;
58
- canvas.height = dh;
59
- // @ts-ignore
60
- canvas.getContext("2d").drawImage(
61
- elem,
62
- sx,
63
- sy,
64
- sw,
65
- sh,
66
- 0,
67
- 0, // dx dy
68
- dw,
69
- dh
70
- );
71
- return canvas;
72
- }
73
-
74
- export function canvasToJpgBlob(
75
- canvas: HTMLCanvasElement,
76
- quality: number
77
- ): Promise<Blob> {
78
- return new Promise((resolve, reject) => {
79
- canvas.toBlob(
80
- (blob) => {
81
- if (blob) {
82
- resolve(blob);
83
- } else {
84
- reject();
85
- }
86
- },
87
- "image/jpeg",
88
- quality
89
- );
90
- });
91
- }
92
-
93
- export const rectToCrop = ({ x1, x2, y1, y2 }: any): Crop => ({
94
- x: x1,
95
- y: y1,
96
- w: x2 - x1,
97
- h: y2 - y1,
98
- });
99
-
100
- export function fileOrBlobToCanvas(
101
- file: File | string
102
- ): Promise<HTMLCanvasElement> {
103
- return new Promise((resolve, reject) => {
104
- // File can also be an image element
105
- loadImage(
106
- file,
107
- (data) => {
108
- const c = data as HTMLCanvasElement;
109
- if (c) {
110
- resolve(c);
111
- } else {
112
- reject();
113
- }
114
- },
115
- {
116
- canvas: true,
117
- orientation: true,
118
- crossOrigin: "anonymous",
119
- }
120
- );
121
-
122
- });
123
- }