Document local setup and OCR workflow

This commit is contained in:
2026-08-11 16:51:48 +03:00
parent 37399dd365
commit f9271d4ab9
11 changed files with 3158 additions and 1 deletions
+4
View File
@@ -0,0 +1,4 @@
node_modules/
dist/
.DS_Store
npm-debug.log*
+32
View File
@@ -0,0 +1,32 @@
# Product
## Register
product
## Users
Пользователь Lineage II запускает утилиту рядом с несколькими окнами игры и хочет быстро проверить, какие данные удалось извлечь с экрана. На первом этапе это инструмент для владельца проекта, а не публичный продукт.
## Product Purpose
Приложение подключает одно или несколько выбранных окон, позволяет откалибровать области распознавания на снимке и показывает извлечённые названия, цены и количества. Успех прототипа означает, что весь путь от выбора окна до видимого результата работает локально на macOS и Windows.
## Brand Personality
Нейтральный, утилитарный, спокойный.
## Anti-references
Не имитировать интерфейс Lineage II, не превращать инструмент в декоративный игровой оверлей, не использовать маркетинговые dashboard-шаблоны и лишнюю анимацию.
## Design Principles
- Показывать реальный захваченный кадр и реальный результат, а не скрывать состояние процесса.
- Вести пользователя по прямому пути: источник, калибровка, результат.
- Сохранять интерфейс компактным и предсказуемым при нескольких окнах.
- Оставлять настраиваемыми только параметры, которые зависят от реального изображения.
## Accessibility & Inclusion
Использовать стандартное управление с клавиатуры, заметный фокус, текстовые подписи для состояний и уважать системную настройку уменьшенного движения. Специальный уровень WCAG для прототипа не задан.
+39 -1
View File
@@ -1,2 +1,40 @@
# l2-market-parser
# L2 Market Parser
Кроссплатформенный локальный прототип для захвата нескольких окон Lineage II, калибровки областей на скриншоте и OCR-распознавания результата.
## Запуск
Нужен Node.js 20 или новее и Chrome либо Edge.
```bash
npm install
npm run dev
```
Открой адрес, который напечатает Vite, обычно `http://127.0.0.1:5173`.
На macOS браузеру потребуется разрешение **System Settings → Privacy & Security → Screen & System Audio Recording**. После выдачи разрешения браузер иногда нужно перезапустить.
## Сценарий
1. В разделе «Источники» нажми «Добавить окно» для каждого окна игры.
2. В разделе «Калибровка» сделай снимок или загрузи готовый скриншот.
3. Выдели маленький неизменяемый элемент торгового окна как якорь.
4. Выдели области названия, цены и количества.
5. Сохрани калибровку и нажми «Распознать все».
Калибровка хранится в `localStorage` текущего браузера. При первом OCR Tesseract.js загружает английскую языковую модель и кеширует её в браузере.
## Ограничения прототипа
- Источники выбираются вручную после каждого обновления страницы.
- Одна калибровка рассчитана на один масштаб интерфейса Lineage II.
- Распознавание запускается вручную, фонового сканирования и отправки на сервер пока нет.
- Для нескольких строк товара нужно отдельно выделить поля каждой строки.
## Проверки
```bash
npm test
npm run build
```
+134
View File
@@ -0,0 +1,134 @@
<!doctype html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="light dark" />
<title>L2 Market Parser</title>
</head>
<body>
<div id="app" class="app-shell">
<header class="app-header">
<div>
<p class="eyebrow">Локальный прототип</p>
<h1>L2 Market Parser</h1>
</div>
<div id="global-status" class="status" data-tone="neutral" role="status" aria-live="polite">
Готов к работе
</div>
</header>
<nav class="step-nav" aria-label="Разделы">
<button class="step-nav__item is-active" type="button" data-view="sources" aria-current="page">
<span>1</span> Источники
</button>
<button class="step-nav__item" type="button" data-view="calibration">
<span>2</span> Калибровка
</button>
<button class="step-nav__item" type="button" data-view="results">
<span>3</span> Результат
</button>
</nav>
<main>
<section id="view-sources" class="view is-active" aria-labelledby="sources-title">
<div class="section-heading">
<div>
<p class="eyebrow">Захват экрана</p>
<h2 id="sources-title">Окна игры</h2>
<p>Добавь каждое окно отдельно. Браузер спросит, какое окно разрешено захватывать.</p>
</div>
<button id="add-source" class="button button--primary" type="button">Добавить окно</button>
</div>
<div id="source-list" class="source-list"></div>
</section>
<section id="view-calibration" class="view" aria-labelledby="calibration-title" hidden>
<div class="section-heading section-heading--compact">
<div>
<p class="eyebrow">Образец интерфейса</p>
<h2 id="calibration-title">Калибровка</h2>
<p>Сначала отметь небольшой неизменяемый якорь, затем области с названием и ценой.</p>
</div>
<div class="button-row">
<select id="calibration-source" aria-label="Окно для снимка"></select>
<button id="capture-reference" class="button" type="button">Снимок из окна</button>
<label class="button file-button">
Загрузить скриншот
<input id="reference-file" type="file" accept="image/*" />
</label>
</div>
</div>
<div class="calibration-layout">
<div class="canvas-stage">
<div id="canvas-empty" class="empty-state">
<strong>Нужен скриншот</strong>
<span>Сделай снимок выбранного окна или загрузи готовое изображение.</span>
</div>
<canvas id="calibration-canvas" hidden></canvas>
</div>
<aside class="inspector" aria-label="Настройки калибровки">
<div class="field-stack">
<label for="region-type">Что выделяем</label>
<select id="region-type">
<option value="anchor">Якорь окна торговли</option>
<option value="item">Название предмета</option>
<option value="price">Цена</option>
<option value="quantity">Количество</option>
<option value="text">Другой текст</option>
</select>
</div>
<div class="field-stack">
<label for="region-label">Подпись поля</label>
<input id="region-label" type="text" placeholder="Например, Цена 1" />
</div>
<p id="draw-hint" class="hint">Протяни рамку вокруг небольшого постоянного элемента торгового окна.</p>
<div class="field-stack">
<div class="range-label">
<label for="match-threshold">Порог совпадения</label>
<output id="threshold-value" for="match-threshold">0.80</output>
</div>
<input id="match-threshold" type="range" min="0.50" max="0.99" step="0.01" value="0.80" />
</div>
<div class="inspector__section">
<div class="inspector__title">
<h3>Области</h3>
<span id="region-count">0</span>
</div>
<div id="region-list" class="region-list"></div>
</div>
<div class="inspector__actions">
<button id="save-calibration" class="button button--primary" type="button">Сохранить</button>
<button id="clear-calibration" class="button button--quiet" type="button">Сбросить</button>
</div>
</aside>
</div>
</section>
<section id="view-results" class="view" aria-labelledby="results-title" hidden>
<div class="section-heading">
<div>
<p class="eyebrow">Проверка пайплайна</p>
<h2 id="results-title">Распознанные данные</h2>
<p>Для каждого окна ищется якорь, затем OCR читает откалиброванные области.</p>
</div>
<div class="button-row">
<button id="copy-results" class="button" type="button" disabled>Копировать JSON</button>
<button id="recognize-all" class="button button--primary" type="button">Распознать все</button>
</div>
</div>
<div id="results-list" class="results-list"></div>
</section>
</main>
</div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
+1246
View File
File diff suppressed because it is too large Load Diff
+18
View File
@@ -0,0 +1,18 @@
{
"name": "l2-market-parser",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite --host 127.0.0.1",
"build": "vite build",
"test": "node --test"
},
"dependencies": {
"@techstark/opencv-js": "5.0.0-release.1",
"tesseract.js": "7.0.0"
},
"devDependencies": {
"vite": "^7.3.6"
}
}
+705
View File
@@ -0,0 +1,705 @@
import "./style.css";
import {
isCalibrationReady,
isRectInside,
rectFromPoints,
resolveFieldRect,
} from "./parser.js";
import {
findAnchor,
onOcrProgress,
recognizeField,
terminateVision,
} from "./vision.js";
const STORAGE_KEY = "l2-market-parser.calibration.v1";
const fieldNames = {
item: "Название",
price: "Цена",
quantity: "Количество",
text: "Текст",
};
function emptyCalibration() {
return { anchor: null, fields: [], threshold: 0.8 };
}
function loadCalibration() {
try {
const saved = JSON.parse(localStorage.getItem(STORAGE_KEY));
return saved?.anchor && Array.isArray(saved.fields)
? { ...emptyCalibration(), ...saved }
: emptyCalibration();
} catch {
return emptyCalibration();
}
}
const state = {
sources: [],
selectedSourceId: null,
referenceCanvas: null,
calibration: loadCalibration(),
drawing: null,
results: [],
busy: false,
};
const elements = {
status: document.querySelector("#global-status"),
nav: [...document.querySelectorAll("[data-view]")],
views: [...document.querySelectorAll(".view")],
addSource: document.querySelector("#add-source"),
sourceList: document.querySelector("#source-list"),
calibrationSource: document.querySelector("#calibration-source"),
captureReference: document.querySelector("#capture-reference"),
referenceFile: document.querySelector("#reference-file"),
canvasEmpty: document.querySelector("#canvas-empty"),
canvas: document.querySelector("#calibration-canvas"),
regionType: document.querySelector("#region-type"),
regionLabel: document.querySelector("#region-label"),
drawHint: document.querySelector("#draw-hint"),
threshold: document.querySelector("#match-threshold"),
thresholdValue: document.querySelector("#threshold-value"),
regionCount: document.querySelector("#region-count"),
regionList: document.querySelector("#region-list"),
saveCalibration: document.querySelector("#save-calibration"),
clearCalibration: document.querySelector("#clear-calibration"),
recognizeAll: document.querySelector("#recognize-all"),
copyResults: document.querySelector("#copy-results"),
resultsList: document.querySelector("#results-list"),
};
function setStatus(message, tone = "neutral") {
elements.status.textContent = message;
elements.status.dataset.tone = tone;
}
function showView(name) {
elements.nav.forEach((button) => {
const active = button.dataset.view === name;
button.classList.toggle("is-active", active);
active
? button.setAttribute("aria-current", "page")
: button.removeAttribute("aria-current");
});
elements.views.forEach((view) => {
const active = view.id === `view-${name}`;
view.classList.toggle("is-active", active);
view.hidden = !active;
});
}
function selectedSource() {
return state.sources.find((source) => source.id === state.selectedSourceId);
}
async function waitForVideo(video) {
if (video.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && video.videoWidth) return;
await new Promise((resolve, reject) => {
const timeout = window.setTimeout(() => reject(new Error("Нет кадров от выбранного окна")), 5000);
video.addEventListener(
"loadeddata",
() => {
window.clearTimeout(timeout);
resolve();
},
{ once: true },
);
});
}
async function addSource() {
if (!navigator.mediaDevices?.getDisplayMedia) {
setStatus("Браузер не поддерживает захват экрана", "error");
return;
}
try {
setStatus("Выбери окно игры в системном окне", "working");
const stream = await navigator.mediaDevices.getDisplayMedia({
video: { frameRate: { ideal: 5, max: 10 } },
audio: false,
});
const track = stream.getVideoTracks()[0];
const video = document.createElement("video");
video.autoplay = true;
video.muted = true;
video.playsInline = true;
video.srcObject = stream;
await video.play();
await waitForVideo(video);
const source = {
id: crypto.randomUUID(),
name: track.label || `Окно ${state.sources.length + 1}`,
stream,
video,
active: true,
};
track.addEventListener("ended", () => {
source.active = false;
renderSources();
setStatus(`Захват «${source.name}» остановлен`, "neutral");
});
state.sources.push(source);
state.selectedSourceId = source.id;
renderSources();
setStatus(`Добавлено: ${source.name}`, "success");
} catch (error) {
if (error.name === "NotAllowedError") {
setStatus("Захват отменён или не разрешён", "error");
} else {
setStatus(error.message || "Не удалось добавить окно", "error");
}
}
}
function removeSource(sourceId) {
const source = state.sources.find((item) => item.id === sourceId);
source?.stream.getTracks().forEach((track) => track.stop());
state.sources = state.sources.filter((item) => item.id !== sourceId);
state.selectedSourceId = state.sources.find((item) => item.active)?.id ?? null;
renderSources();
}
function chooseSource(sourceId) {
state.selectedSourceId = sourceId;
renderSources();
}
function sourceEmptyState() {
const empty = document.createElement("div");
empty.className = "empty-state empty-state--wide";
const title = document.createElement("strong");
title.textContent = "Нет подключённых окон";
const text = document.createElement("span");
text.textContent = "Нажми «Добавить окно» и выбери первое окно Lineage II.";
empty.append(title, text);
return empty;
}
function renderSources() {
elements.sourceList.replaceChildren();
if (!state.sources.length) {
elements.sourceList.append(sourceEmptyState());
}
state.sources.forEach((source, index) => {
const row = document.createElement("article");
row.className = "source-row";
row.classList.toggle("is-selected", source.id === state.selectedSourceId);
const preview = document.createElement("div");
preview.className = "source-row__preview";
const video = document.createElement("video");
video.autoplay = true;
video.muted = true;
video.playsInline = true;
video.srcObject = source.stream;
preview.append(video);
const info = document.createElement("div");
info.className = "source-row__info";
const kicker = document.createElement("span");
kicker.textContent = `Источник ${index + 1}`;
const name = document.createElement("h3");
name.textContent = source.name;
const stateText = document.createElement("p");
stateText.textContent = source.active
? `${source.video.videoWidth} × ${source.video.videoHeight}, захват активен`
: "Захват остановлен";
info.append(kicker, name, stateText);
const actions = document.createElement("div");
actions.className = "source-row__actions";
const calibrate = document.createElement("button");
calibrate.className = "button";
calibrate.type = "button";
calibrate.textContent = "Калибровать";
calibrate.disabled = !source.active;
calibrate.addEventListener("click", () => {
chooseSource(source.id);
showView("calibration");
});
const select = document.createElement("button");
select.className = "button button--quiet";
select.type = "button";
select.textContent = source.id === state.selectedSourceId ? "Выбрано" : "Выбрать";
select.disabled = !source.active || source.id === state.selectedSourceId;
select.addEventListener("click", () => chooseSource(source.id));
const remove = document.createElement("button");
remove.className = "button button--quiet";
remove.type = "button";
remove.textContent = "Убрать";
remove.addEventListener("click", () => removeSource(source.id));
actions.append(calibrate, select, remove);
row.append(preview, info, actions);
elements.sourceList.append(row);
});
elements.calibrationSource.replaceChildren();
if (!state.sources.some((source) => source.active)) {
const option = document.createElement("option");
option.value = "";
option.textContent = "Нет активных окон";
elements.calibrationSource.append(option);
} else {
state.sources
.filter((source) => source.active)
.forEach((source) => {
const option = document.createElement("option");
option.value = source.id;
option.textContent = source.name;
option.selected = source.id === state.selectedSourceId;
elements.calibrationSource.append(option);
});
}
elements.captureReference.disabled = !selectedSource()?.active;
}
async function captureSource(source) {
if (!source?.active) throw new Error("Сначала выбери активное окно");
await waitForVideo(source.video);
const canvas = document.createElement("canvas");
canvas.width = source.video.videoWidth;
canvas.height = source.video.videoHeight;
canvas.getContext("2d", { willReadFrequently: true }).drawImage(source.video, 0, 0);
return canvas;
}
function setReference(canvas) {
state.referenceCanvas = canvas;
elements.canvas.width = canvas.width;
elements.canvas.height = canvas.height;
elements.canvas.hidden = false;
elements.canvasEmpty.hidden = true;
drawCalibration();
setStatus(`Снимок готов: ${canvas.width} × ${canvas.height}`, "success");
}
async function captureReference() {
try {
setStatus("Делаю снимок выбранного окна", "working");
setReference(await captureSource(selectedSource()));
} catch (error) {
setStatus(error.message, "error");
}
}
async function loadReferenceFile(file) {
if (!file) return;
try {
const bitmap = await createImageBitmap(file);
const canvas = document.createElement("canvas");
canvas.width = bitmap.width;
canvas.height = bitmap.height;
canvas.getContext("2d", { willReadFrequently: true }).drawImage(bitmap, 0, 0);
bitmap.close();
setReference(canvas);
} catch {
setStatus("Не удалось открыть изображение", "error");
}
}
function canvasPoint(event) {
const bounds = elements.canvas.getBoundingClientRect();
return {
x: Math.max(
0,
Math.min(elements.canvas.width, ((event.clientX - bounds.left) / bounds.width) * elements.canvas.width),
),
y: Math.max(
0,
Math.min(elements.canvas.height, ((event.clientY - bounds.top) / bounds.height) * elements.canvas.height),
),
};
}
function cropCanvas(source, rect) {
const canvas = document.createElement("canvas");
canvas.width = rect.width;
canvas.height = rect.height;
canvas
.getContext("2d", { willReadFrequently: true })
.drawImage(source, rect.x, rect.y, rect.width, rect.height, 0, 0, rect.width, rect.height);
return canvas;
}
function addRegion(rect) {
const type = elements.regionType.value;
if (type === "anchor") {
state.calibration.anchor = {
...rect,
image: cropCanvas(state.referenceCanvas, rect).toDataURL("image/png"),
};
state.calibration.fields = [];
elements.regionType.value = "item";
updateDrawHint();
setStatus("Якорь выбран. Теперь отметь поля", "success");
} else {
const anchor = state.calibration.anchor;
if (!anchor) {
setStatus("Сначала выдели якорь", "error");
return;
}
const sameTypeCount = state.calibration.fields.filter((field) => field.type === type).length;
state.calibration.fields.push({
id: crypto.randomUUID(),
type,
label: elements.regionLabel.value.trim() || `${fieldNames[type]} ${sameTypeCount + 1}`,
offsetX: rect.x - anchor.x,
offsetY: rect.y - anchor.y,
width: rect.width,
height: rect.height,
});
elements.regionLabel.value = "";
setStatus("Область добавлена", "success");
}
renderCalibration();
}
function fieldAbsoluteRect(field) {
return resolveFieldRect(
{ x: state.calibration.anchor.x, y: state.calibration.anchor.y },
field,
);
}
function drawBox(context, rect, label, color, dashed = false) {
context.save();
context.strokeStyle = color;
context.fillStyle = color;
context.lineWidth = Math.max(2, elements.canvas.width / 900);
context.setLineDash(dashed ? [10, 7] : []);
context.strokeRect(rect.x, rect.y, rect.width, rect.height);
if (label) {
context.font = `${Math.max(13, elements.canvas.width / 90)}px system-ui`;
const width = context.measureText(label).width + 14;
const y = Math.max(0, rect.y - 25);
context.fillRect(rect.x, y, width, 25);
context.fillStyle = "oklch(0.98 0.004 250)";
context.fillText(label, rect.x + 7, y + 17);
}
context.restore();
}
function drawCalibration() {
if (!state.referenceCanvas) return;
const context = elements.canvas.getContext("2d");
context.clearRect(0, 0, elements.canvas.width, elements.canvas.height);
context.drawImage(state.referenceCanvas, 0, 0);
if (state.calibration.anchor) {
drawBox(context, state.calibration.anchor, "Якорь", "oklch(0.72 0.16 65)");
state.calibration.fields.forEach((field) => {
drawBox(context, fieldAbsoluteRect(field), field.label, "oklch(0.65 0.17 250)");
});
}
if (state.drawing) {
const rect = rectFromPoints(state.drawing.start, state.drawing.current);
drawBox(context, rect, "", "oklch(0.75 0.18 150)", true);
}
}
function updateDrawHint() {
const hints = {
anchor: "Протяни рамку вокруг небольшого постоянного элемента торгового окна.",
item: "Выдели только строку с названием предмета.",
price: "Выдели цену вместе с разделителями разрядов.",
quantity: "Выдели количество предметов.",
text: "Выдели одну строку текста.",
};
elements.drawHint.textContent = hints[elements.regionType.value];
}
function renderCalibration() {
elements.threshold.value = String(state.calibration.threshold);
elements.thresholdValue.value = state.calibration.threshold.toFixed(2);
elements.regionCount.textContent = String(
state.calibration.fields.length + (state.calibration.anchor ? 1 : 0),
);
elements.regionList.replaceChildren();
if (!state.calibration.anchor) {
const note = document.createElement("p");
note.className = "muted-copy";
note.textContent = "Якорь ещё не выбран.";
elements.regionList.append(note);
} else {
const anchor = document.createElement("div");
anchor.className = "region-row";
anchor.innerHTML = "<span><strong>Якорь</strong><small>Шаблон поиска</small></span>";
elements.regionList.append(anchor);
}
state.calibration.fields.forEach((field) => {
const row = document.createElement("div");
row.className = "region-row";
const copy = document.createElement("span");
const name = document.createElement("strong");
name.textContent = field.label;
const type = document.createElement("small");
type.textContent = fieldNames[field.type];
copy.append(name, type);
const remove = document.createElement("button");
remove.className = "icon-button";
remove.type = "button";
remove.textContent = "×";
remove.setAttribute("aria-label", `Удалить ${field.label}`);
remove.addEventListener("click", () => {
state.calibration.fields = state.calibration.fields.filter((item) => item.id !== field.id);
renderCalibration();
drawCalibration();
});
row.append(copy, remove);
elements.regionList.append(row);
});
drawCalibration();
}
function saveCalibration() {
if (!isCalibrationReady(state.calibration)) {
setStatus("Для сохранения нужны якорь и хотя бы одно поле", "error");
return;
}
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(state.calibration));
setStatus("Калибровка сохранена в браузере", "success");
} catch {
setStatus("Браузер не смог сохранить калибровку", "error");
}
}
function clearCalibration() {
state.calibration = emptyCalibration();
localStorage.removeItem(STORAGE_KEY);
renderCalibration();
setStatus("Калибровка сброшена", "neutral");
}
function imageToCanvas(dataUrl) {
return new Promise((resolve, reject) => {
const image = new Image();
image.onload = () => {
const canvas = document.createElement("canvas");
canvas.width = image.naturalWidth;
canvas.height = image.naturalHeight;
canvas.getContext("2d").drawImage(image, 0, 0);
resolve(canvas);
};
image.onerror = reject;
image.src = dataUrl;
});
}
function renderResults() {
elements.resultsList.replaceChildren();
elements.copyResults.disabled = !state.results.length;
if (!state.results.length) {
const empty = document.createElement("div");
empty.className = "empty-state empty-state--wide";
const title = document.createElement("strong");
title.textContent = "Результатов пока нет";
const text = document.createElement("span");
text.textContent = "Подключи окна, сохрани калибровку и запусти распознавание.";
empty.append(title, text);
elements.resultsList.append(empty);
return;
}
state.results.forEach((result) => {
const section = document.createElement("section");
section.className = "result-group";
const header = document.createElement("header");
const heading = document.createElement("div");
const title = document.createElement("h3");
title.textContent = result.source;
const meta = document.createElement("p");
meta.textContent = result.found
? `Якорь найден, совпадение ${(result.score * 100).toFixed(1)}%`
: `Якорь не найден, лучшее совпадение ${(result.score * 100).toFixed(1)}%`;
heading.append(title, meta);
const badge = document.createElement("span");
badge.className = "result-badge";
badge.dataset.tone = result.found ? "success" : "error";
badge.textContent = result.found ? "Распознано" : "Не найдено";
header.append(heading, badge);
section.append(header);
if (result.error) {
const error = document.createElement("p");
error.className = "result-error";
error.textContent = result.error;
section.append(error);
} else if (result.fields?.length) {
const table = document.createElement("table");
table.innerHTML = "<thead><tr><th>Поле</th><th>Значение</th><th>OCR</th><th>Уверенность</th></tr></thead>";
const body = document.createElement("tbody");
result.fields.forEach((field) => {
const row = document.createElement("tr");
const label = document.createElement("td");
label.textContent = field.label;
const value = document.createElement("td");
value.textContent =
typeof field.value === "number" ? field.value.toLocaleString("ru-RU") : field.value || "Не распознано";
const raw = document.createElement("td");
raw.textContent = field.text || "пусто";
const confidence = document.createElement("td");
confidence.textContent = `${field.confidence}%`;
row.append(label, value, raw, confidence);
body.append(row);
});
table.append(body);
section.append(table);
}
elements.resultsList.append(section);
});
}
async function recognizeAll() {
const activeSources = state.sources.filter((source) => source.active);
if (!activeSources.length) {
setStatus("Сначала добавь хотя бы одно окно", "error");
return;
}
if (!isCalibrationReady(state.calibration)) {
setStatus("Сначала сохрани якорь и области распознавания", "error");
return;
}
if (state.busy) return;
state.busy = true;
elements.recognizeAll.disabled = true;
elements.recognizeAll.textContent = "Распознаю…";
state.results = [];
renderResults();
onOcrProgress((progress) => {
if (progress.status === "recognizing text") {
setStatus(`OCR: ${Math.round((progress.progress || 0) * 100)}%`, "working");
}
});
try {
const template = await imageToCanvas(state.calibration.anchor.image);
for (const source of activeSources) {
setStatus(`Ищу торговое окно: ${source.name}`, "working");
const frame = await captureSource(source);
const match = await findAnchor(frame, template);
const result = {
source: source.name,
capturedAt: new Date().toISOString(),
score: match.score,
found: match.score >= state.calibration.threshold,
fields: [],
};
if (!result.found) {
result.error = "Проверь масштаб интерфейса, выбранный якорь или уменьши порог совпадения.";
} else {
for (const field of state.calibration.fields) {
const rect = resolveFieldRect(match, field);
if (!isRectInside(rect, frame.width, frame.height)) {
result.fields.push({
...field,
text: "",
value: null,
confidence: 0,
error: "Область вышла за границы кадра",
});
continue;
}
setStatus(`${source.name}: ${field.label}`, "working");
result.fields.push({ ...field, ...(await recognizeField(frame, rect, field.type)) });
}
}
state.results.push(result);
renderResults();
}
setStatus("Распознавание завершено", "success");
} catch (error) {
setStatus(error.message || "Ошибка распознавания", "error");
} finally {
state.busy = false;
elements.recognizeAll.disabled = false;
elements.recognizeAll.textContent = "Распознать все";
}
}
async function copyResults() {
try {
await navigator.clipboard.writeText(JSON.stringify(state.results, null, 2));
setStatus("JSON скопирован", "success");
} catch {
setStatus("Не удалось скопировать JSON", "error");
}
}
elements.nav.forEach((button) => button.addEventListener("click", () => showView(button.dataset.view)));
elements.addSource.addEventListener("click", addSource);
elements.calibrationSource.addEventListener("change", (event) => chooseSource(event.target.value));
elements.captureReference.addEventListener("click", captureReference);
elements.referenceFile.addEventListener("change", (event) => loadReferenceFile(event.target.files[0]));
elements.regionType.addEventListener("change", updateDrawHint);
elements.threshold.addEventListener("input", (event) => {
state.calibration.threshold = Number(event.target.value);
elements.thresholdValue.value = state.calibration.threshold.toFixed(2);
});
elements.saveCalibration.addEventListener("click", saveCalibration);
elements.clearCalibration.addEventListener("click", clearCalibration);
elements.recognizeAll.addEventListener("click", recognizeAll);
elements.copyResults.addEventListener("click", copyResults);
elements.canvas.addEventListener("pointerdown", (event) => {
if (!state.referenceCanvas) return;
elements.canvas.setPointerCapture(event.pointerId);
const point = canvasPoint(event);
state.drawing = { start: point, current: point };
drawCalibration();
});
elements.canvas.addEventListener("pointermove", (event) => {
if (!state.drawing) return;
state.drawing.current = canvasPoint(event);
drawCalibration();
});
elements.canvas.addEventListener("pointerup", (event) => {
if (!state.drawing) return;
state.drawing.current = canvasPoint(event);
const rect = rectFromPoints(state.drawing.start, state.drawing.current);
state.drawing = null;
if (rect.width >= 4 && rect.height >= 4) addRegion(rect);
drawCalibration();
});
window.addEventListener("beforeunload", () => {
state.sources.forEach((source) => source.stream.getTracks().forEach((track) => track.stop()));
terminateVision();
});
renderSources();
renderCalibration();
renderResults();
updateDrawHint();
+52
View File
@@ -0,0 +1,52 @@
export function rectFromPoints(start, end) {
return {
x: Math.round(Math.min(start.x, end.x)),
y: Math.round(Math.min(start.y, end.y)),
width: Math.round(Math.abs(end.x - start.x)),
height: Math.round(Math.abs(end.y - start.y)),
};
}
export function resolveFieldRect(anchorPosition, field) {
return {
x: Math.round(anchorPosition.x + field.offsetX),
y: Math.round(anchorPosition.y + field.offsetY),
width: Math.round(field.width),
height: Math.round(field.height),
};
}
export function normalizeOcrText(text) {
return text.replace(/\s+/g, " ").trim();
}
export function parseFieldValue(type, text) {
const normalized = normalizeOcrText(text);
if (type !== "price" && type !== "quantity") {
return normalized;
}
const digits = normalized.replace(/\D/g, "");
return digits ? Number(digits) : null;
}
export function isCalibrationReady(calibration) {
return Boolean(
calibration?.anchor?.image &&
calibration.anchor.width >= 4 &&
calibration.anchor.height >= 4 &&
calibration.fields?.length,
);
}
export function isRectInside(rect, width, height) {
return (
rect.x >= 0 &&
rect.y >= 0 &&
rect.width > 0 &&
rect.height > 0 &&
rect.x + rect.width <= width &&
rect.y + rect.height <= height
);
}
+754
View File
@@ -0,0 +1,754 @@
:root {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
color: oklch(0.24 0.012 255);
background: oklch(0.965 0.006 250);
font-synthesis: none;
--background: oklch(0.965 0.006 250);
--surface: oklch(0.99 0.004 250);
--surface-raised: oklch(1 0.003 250);
--surface-muted: oklch(0.935 0.008 250);
--text: oklch(0.24 0.012 255);
--text-muted: oklch(0.52 0.018 255);
--border: oklch(0.86 0.012 250);
--border-strong: oklch(0.74 0.02 250);
--accent: oklch(0.58 0.16 250);
--accent-hover: oklch(0.52 0.17 250);
--accent-soft: oklch(0.93 0.035 250);
--success: oklch(0.54 0.13 155);
--success-soft: oklch(0.93 0.04 155);
--error: oklch(0.56 0.18 25);
--error-soft: oklch(0.94 0.04 25);
--warning: oklch(0.68 0.15 75);
--focus: oklch(0.66 0.18 250);
--shadow: 0 14px 40px oklch(0.32 0.025 250 / 0.08);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-width: 320px;
min-height: 100vh;
background: var(--background);
color: var(--text);
}
button,
input,
select {
font: inherit;
}
button,
select,
input[type="range"],
.file-button {
cursor: pointer;
}
button:focus-visible,
input:focus-visible,
select:focus-visible,
.file-button:has(input:focus-visible) {
outline: 3px solid color-mix(in oklch, var(--focus), transparent 50%);
outline-offset: 2px;
}
button:disabled {
cursor: not-allowed;
opacity: 0.52;
}
h1,
h2,
h3,
p {
margin-block-start: 0;
}
h1 {
margin-block-end: 0;
font-size: 1.45rem;
line-height: 1.15;
letter-spacing: -0.025em;
}
h2 {
margin-block-end: 0.45rem;
font-size: 1.75rem;
line-height: 1.15;
letter-spacing: -0.035em;
}
h3 {
margin-block-end: 0.25rem;
font-size: 1rem;
}
.app-shell {
width: min(1480px, 100%);
min-height: 100vh;
margin-inline: auto;
padding: 28px clamp(18px, 3vw, 48px) 56px;
}
.app-header {
display: flex;
min-height: 62px;
align-items: center;
justify-content: space-between;
gap: 24px;
}
.eyebrow {
margin-block-end: 5px;
color: var(--text-muted);
font-size: 0.72rem;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.status {
display: grid;
width: 270px;
min-height: 38px;
place-items: center;
padding: 8px 14px;
border: 1px solid var(--border);
border-radius: 999px;
background: var(--surface);
color: var(--text-muted);
font-size: 0.84rem;
text-align: center;
transition: background-color 180ms cubic-bezier(0.22, 1, 0.36, 1),
border-color 180ms cubic-bezier(0.22, 1, 0.36, 1);
}
.status[data-tone="working"] {
border-color: color-mix(in oklch, var(--accent), transparent 55%);
background: var(--accent-soft);
color: var(--accent-hover);
}
.status[data-tone="success"] {
border-color: color-mix(in oklch, var(--success), transparent 55%);
background: var(--success-soft);
color: var(--success);
}
.status[data-tone="error"] {
border-color: color-mix(in oklch, var(--error), transparent 55%);
background: var(--error-soft);
color: var(--error);
}
.step-nav {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
margin-block: 30px 42px;
border-block-end: 1px solid var(--border);
}
.step-nav__item {
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
min-height: 54px;
border: 0;
border-block-end: 2px solid transparent;
background: transparent;
color: var(--text-muted);
font-weight: 650;
}
.step-nav__item span {
display: grid;
width: 24px;
height: 24px;
place-items: center;
border: 1px solid var(--border-strong);
border-radius: 50%;
font-size: 0.75rem;
}
.step-nav__item:hover {
color: var(--text);
}
.step-nav__item.is-active {
border-block-end-color: var(--accent);
color: var(--accent);
}
.step-nav__item.is-active span {
border-color: var(--accent);
background: var(--accent);
color: oklch(0.98 0.004 250);
}
.view[hidden] {
display: none;
}
.section-heading {
display: flex;
align-items: end;
justify-content: space-between;
gap: 32px;
margin-block-end: 28px;
}
.section-heading > div:first-child {
max-width: 70ch;
}
.section-heading p:last-child {
margin-block-end: 0;
color: var(--text-muted);
line-height: 1.55;
}
.section-heading--compact {
align-items: center;
}
.button-row {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: flex-end;
gap: 9px;
}
.button,
select,
input[type="text"] {
min-height: 40px;
border: 1px solid var(--border-strong);
border-radius: 9px;
background: var(--surface-raised);
color: var(--text);
}
.button {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 8px 14px;
font-weight: 650;
white-space: nowrap;
}
.button:hover:not(:disabled) {
border-color: var(--accent);
}
.button--primary {
border-color: var(--accent);
background: var(--accent);
color: oklch(0.98 0.004 250);
}
.button--primary:hover:not(:disabled) {
border-color: var(--accent-hover);
background: var(--accent-hover);
}
.button--quiet {
border-color: transparent;
background: transparent;
color: var(--text-muted);
}
.button--quiet:hover:not(:disabled) {
border-color: var(--border);
background: var(--surface-muted);
color: var(--text);
}
select,
input[type="text"] {
padding-inline: 11px;
}
.file-button input {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
.source-list {
display: grid;
gap: 12px;
}
.source-row {
display: grid;
grid-template-columns: 220px minmax(220px, 1fr) auto;
align-items: center;
gap: 22px;
padding: 14px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--surface);
transition: border-color 180ms cubic-bezier(0.22, 1, 0.36, 1),
box-shadow 180ms cubic-bezier(0.22, 1, 0.36, 1);
}
.source-row.is-selected {
border-color: color-mix(in oklch, var(--accent), transparent 35%);
box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent), transparent 88%);
}
.source-row__preview {
aspect-ratio: 16 / 9;
overflow: hidden;
border-radius: 8px;
background: oklch(0.18 0.01 255);
}
.source-row__preview video {
width: 100%;
height: 100%;
object-fit: contain;
}
.source-row__info span {
color: var(--text-muted);
font-size: 0.72rem;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.source-row__info h3 {
margin-block: 5px;
}
.source-row__info p {
margin: 0;
color: var(--text-muted);
font-size: 0.85rem;
}
.source-row__actions {
display: flex;
align-items: center;
gap: 5px;
}
.empty-state {
display: grid;
place-items: center;
gap: 8px;
min-height: 260px;
padding: 32px;
color: var(--text-muted);
text-align: center;
}
.empty-state strong {
color: var(--text);
font-size: 1rem;
}
.empty-state--wide {
min-height: 300px;
border: 1px dashed var(--border-strong);
border-radius: 14px;
background: color-mix(in oklch, var(--surface), transparent 30%);
}
.calibration-layout {
display: grid;
grid-template-columns: minmax(0, 1fr) 310px;
min-height: 620px;
overflow: hidden;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--surface);
box-shadow: var(--shadow);
}
.canvas-stage {
display: grid;
min-width: 0;
min-height: 620px;
max-height: calc(100vh - 260px);
place-items: center;
overflow: auto;
padding: 24px;
background-color: oklch(0.91 0.008 250);
background-image: linear-gradient(45deg, oklch(0.88 0.008 250) 25%, transparent 25%),
linear-gradient(-45deg, oklch(0.88 0.008 250) 25%, transparent 25%),
linear-gradient(45deg, transparent 75%, oklch(0.88 0.008 250) 75%),
linear-gradient(-45deg, transparent 75%, oklch(0.88 0.008 250) 75%);
background-position: 0 0, 0 8px, 8px -8px, -8px 0;
background-size: 16px 16px;
}
#calibration-canvas {
display: block;
max-width: 100%;
max-height: 100%;
border-radius: 4px;
box-shadow: 0 8px 30px oklch(0.2 0.02 255 / 0.2);
cursor: crosshair;
touch-action: none;
}
.inspector {
display: flex;
flex-direction: column;
gap: 20px;
padding: 24px;
border-inline-start: 1px solid var(--border);
background: var(--surface);
}
.field-stack {
display: grid;
gap: 7px;
}
.field-stack label,
.range-label label {
color: var(--text-muted);
font-size: 0.78rem;
font-weight: 700;
}
.hint {
min-height: 58px;
margin: 0;
padding: 11px 12px;
border: 1px solid var(--border);
border-radius: 9px;
background: var(--surface-muted);
color: var(--text-muted);
font-size: 0.82rem;
line-height: 1.45;
}
.range-label {
display: flex;
justify-content: space-between;
gap: 12px;
}
.range-label output {
color: var(--text);
font-variant-numeric: tabular-nums;
font-weight: 700;
}
input[type="range"] {
width: 100%;
accent-color: var(--accent);
}
.inspector__section {
min-height: 0;
flex: 1;
overflow: auto;
border-block-start: 1px solid var(--border);
padding-block-start: 18px;
}
.inspector__title {
display: flex;
align-items: center;
justify-content: space-between;
margin-block-end: 10px;
}
.inspector__title h3 {
margin: 0;
}
.inspector__title span {
display: grid;
min-width: 24px;
height: 24px;
place-items: center;
border-radius: 999px;
background: var(--surface-muted);
color: var(--text-muted);
font-size: 0.75rem;
}
.region-list {
display: grid;
gap: 6px;
}
.region-row {
display: flex;
min-height: 48px;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 8px 9px;
border-radius: 8px;
}
.region-row:hover {
background: var(--surface-muted);
}
.region-row span {
display: grid;
gap: 2px;
}
.region-row strong {
font-size: 0.84rem;
}
.region-row small {
color: var(--text-muted);
font-size: 0.72rem;
}
.icon-button {
display: grid;
width: 30px;
height: 30px;
place-items: center;
border: 0;
border-radius: 7px;
background: transparent;
color: var(--text-muted);
font-size: 1.2rem;
}
.icon-button:hover {
background: var(--error-soft);
color: var(--error);
}
.muted-copy {
color: var(--text-muted);
font-size: 0.82rem;
}
.inspector__actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
padding-block-start: 2px;
}
.results-list {
display: grid;
gap: 18px;
}
.result-group {
overflow: hidden;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--surface);
}
.result-group > header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 18px 20px;
border-block-end: 1px solid var(--border);
}
.result-group header h3 {
margin-block-end: 3px;
}
.result-group header p {
margin: 0;
color: var(--text-muted);
font-size: 0.82rem;
}
.result-badge {
padding: 6px 9px;
border-radius: 999px;
font-size: 0.75rem;
font-weight: 700;
}
.result-badge[data-tone="success"] {
background: var(--success-soft);
color: var(--success);
}
.result-badge[data-tone="error"] {
background: var(--error-soft);
color: var(--error);
}
.result-error {
margin: 0;
padding: 22px 20px;
color: var(--error);
}
table {
width: 100%;
border-collapse: collapse;
font-size: 0.86rem;
}
th,
td {
padding: 12px 20px;
border-block-end: 1px solid var(--border);
text-align: start;
}
th {
background: var(--surface-muted);
color: var(--text-muted);
font-size: 0.72rem;
letter-spacing: 0.05em;
text-transform: uppercase;
}
tbody tr:last-child td {
border-block-end: 0;
}
td:nth-child(2),
td:nth-child(4) {
font-variant-numeric: tabular-nums;
font-weight: 650;
}
@media (max-width: 960px) {
.section-heading {
align-items: start;
flex-direction: column;
}
.button-row {
justify-content: flex-start;
}
.source-row {
grid-template-columns: 180px 1fr;
}
.source-row__actions {
grid-column: 1 / -1;
justify-content: flex-end;
}
.calibration-layout {
grid-template-columns: 1fr;
}
.inspector {
border-block-start: 1px solid var(--border);
border-inline-start: 0;
}
}
@media (max-width: 640px) {
.app-shell {
padding-inline: 14px;
}
.app-header {
align-items: start;
flex-direction: column;
}
.status {
width: 100%;
}
.step-nav {
margin-block: 22px 30px;
}
.step-nav__item {
flex-direction: column;
gap: 5px;
font-size: 0.76rem;
}
.source-row {
grid-template-columns: 1fr;
}
.source-row__actions {
grid-column: auto;
flex-wrap: wrap;
justify-content: flex-start;
}
.button-row,
.button-row > * {
width: 100%;
}
.canvas-stage {
min-height: 360px;
padding: 12px;
}
.result-group {
overflow-x: auto;
}
table {
min-width: 680px;
}
}
@media (prefers-color-scheme: dark) {
:root {
color: oklch(0.9 0.009 250);
background: oklch(0.18 0.012 255);
--background: oklch(0.18 0.012 255);
--surface: oklch(0.225 0.014 255);
--surface-raised: oklch(0.255 0.015 255);
--surface-muted: oklch(0.28 0.016 255);
--text: oklch(0.9 0.009 250);
--text-muted: oklch(0.68 0.018 250);
--border: oklch(0.34 0.018 255);
--border-strong: oklch(0.43 0.022 255);
--accent: oklch(0.7 0.15 250);
--accent-hover: oklch(0.75 0.13 250);
--accent-soft: oklch(0.3 0.05 250);
--success: oklch(0.72 0.12 155);
--success-soft: oklch(0.29 0.045 155);
--error: oklch(0.72 0.15 25);
--error-soft: oklch(0.3 0.05 25);
--warning: oklch(0.78 0.13 75);
--shadow: 0 18px 48px oklch(0.08 0.015 255 / 0.28);
}
.canvas-stage {
background-color: oklch(0.16 0.01 255);
background-image: linear-gradient(45deg, oklch(0.2 0.012 255) 25%, transparent 25%),
linear-gradient(-45deg, oklch(0.2 0.012 255) 25%, transparent 25%),
linear-gradient(45deg, transparent 75%, oklch(0.2 0.012 255) 75%),
linear-gradient(-45deg, transparent 75%, oklch(0.2 0.012 255) 75%);
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
}
}
+124
View File
@@ -0,0 +1,124 @@
import { createWorker, PSM } from "tesseract.js";
import { normalizeOcrText, parseFieldValue } from "./parser.js";
let cvPromise;
let workerPromise;
let progressListener = () => {};
export function onOcrProgress(listener) {
progressListener = listener;
}
async function getOpenCv() {
if (!cvPromise) {
cvPromise = import("@techstark/opencv-js").then(async ({ default: module }) => {
const cv = module instanceof Promise ? await module : module;
if (cv.Mat) return cv;
await new Promise((resolve) => {
cv.onRuntimeInitialized = resolve;
});
return cv;
});
}
return cvPromise;
}
async function getOcrWorker() {
if (!workerPromise) {
workerPromise = createWorker("eng", 1, {
logger: (message) => progressListener(message),
});
}
return workerPromise;
}
export async function findAnchor(sourceCanvas, templateCanvas) {
if (
templateCanvas.width > sourceCanvas.width ||
templateCanvas.height > sourceCanvas.height
) {
return { x: 0, y: 0, score: 0 };
}
const cv = await getOpenCv();
const source = cv.imread(sourceCanvas);
const template = cv.imread(templateCanvas);
const sourceGray = new cv.Mat();
const templateGray = new cv.Mat();
const result = new cv.Mat();
try {
cv.cvtColor(source, sourceGray, cv.COLOR_RGBA2GRAY);
cv.cvtColor(template, templateGray, cv.COLOR_RGBA2GRAY);
cv.matchTemplate(sourceGray, templateGray, result, cv.TM_CCOEFF_NORMED);
const match = cv.minMaxLoc(result);
return {
x: match.maxLoc.x,
y: match.maxLoc.y,
score: Number.isFinite(match.maxVal) ? match.maxVal : 0,
};
} finally {
source.delete();
template.delete();
sourceGray.delete();
templateGray.delete();
result.delete();
}
}
function prepareOcrCrop(sourceCanvas, rect) {
const scale = 3;
const canvas = document.createElement("canvas");
canvas.width = rect.width * scale;
canvas.height = rect.height * scale;
const context = canvas.getContext("2d", { willReadFrequently: true });
context.imageSmoothingEnabled = false;
context.filter = "grayscale(1) contrast(2)";
context.drawImage(
sourceCanvas,
rect.x,
rect.y,
rect.width,
rect.height,
0,
0,
canvas.width,
canvas.height,
);
return canvas;
}
export async function recognizeField(sourceCanvas, rect, type) {
const worker = await getOcrWorker();
const numbersOnly = type === "price" || type === "quantity";
await worker.setParameters({
tessedit_pageseg_mode: PSM.SINGLE_LINE,
tessedit_char_whitelist: numbersOnly ? "0123456789,. " : "",
preserve_interword_spaces: "1",
});
const image = prepareOcrCrop(sourceCanvas, rect);
const { data } = await worker.recognize(image);
const text = normalizeOcrText(data.text);
return {
text,
value: parseFieldValue(type, text),
confidence: Math.round(data.confidence ?? 0),
};
}
export async function terminateVision() {
if (!workerPromise) return;
const worker = await workerPromise;
await worker.terminate();
workerPromise = null;
}
+50
View File
@@ -0,0 +1,50 @@
import test from "node:test";
import assert from "node:assert/strict";
import {
isCalibrationReady,
isRectInside,
parseFieldValue,
rectFromPoints,
resolveFieldRect,
} from "../src/parser.js";
test("normalizes a reverse drag into a positive rectangle", () => {
assert.deepEqual(rectFromPoints({ x: 140, y: 90 }, { x: 20, y: 30 }), {
x: 20,
y: 30,
width: 120,
height: 60,
});
});
test("moves calibrated fields together with the detected anchor", () => {
assert.deepEqual(
resolveFieldRect(
{ x: 400, y: 250 },
{ offsetX: 32, offsetY: 80, width: 180, height: 24 },
),
{ x: 432, y: 330, width: 180, height: 24 },
);
});
test("parses formatted prices and rejects empty numeric OCR", () => {
assert.equal(parseFieldValue("price", "1 250,000 adena"), 1250000);
assert.equal(parseFieldValue("quantity", "not found"), null);
assert.equal(parseFieldValue("item", " Soulshot: S-grade\n"), "Soulshot: S-grade");
});
test("requires an anchor image and at least one field", () => {
assert.equal(isCalibrationReady({ anchor: null, fields: [] }), false);
assert.equal(
isCalibrationReady({
anchor: { image: "data:image/png;base64,x", width: 20, height: 10 },
fields: [{ id: "price" }],
}),
true,
);
});
test("detects OCR rectangles outside the captured frame", () => {
assert.equal(isRectInside({ x: 10, y: 10, width: 20, height: 20 }, 100, 100), true);
assert.equal(isRectInside({ x: 90, y: 10, width: 20, height: 20 }, 100, 100), false);
});