mirror of
https://github.com/Matysh/houseplan-card
synced 2026-07-31 16:38:31 +00:00
A space carried an aspect ratio, and coordinates were normalised against it: x by the width, y by the height. Every geometric question therefore depended on a per-space number, and picking a canvas orientation was a decision the user had no reason to make. The render space is now NORM_W x NORM_W and a plan image is fitted into it by its OWN ratio, centred — wide plans get margins above and below, tall ones at the sides. Migration (geometry_migration.py, pure and unit-tested) runs once at setup under the write lock. Nothing about a drawing changes: the old box is padded out to a square and every coordinate re-expressed against it — rooms as rects and polygons, openings and their lengths, decor, view_box, and the marker positions in the separate layout store. In render units it is a uniform scale plus an offset, so angles and proportions are exact. cell_cm is scaled for tall plans, because the grid pitch is a fraction of the width: without it a wall would measure less than it does. is now dropped by the schema rather than accepted — a stale tab sending it would be sending coordinates from the old normalisation too, and honouring the field would not make them right. The demo fixture was migrated with the same transform, so the smokes exercise the new geometry rather than a square-native fake; six of them needed their render-space helpers updated and one its click coordinates. Not released — dev only, per the owner's instruction.
62 lines
3.6 KiB
JavaScript
62 lines
3.6 KiB
JavaScript
import { launch, checkAll, finish } from './serve.mjs';
|
||
const { page, browser } = await launch();
|
||
const res = await page.evaluate(async () => {
|
||
const out = {};
|
||
const c = window.__card;
|
||
const sr = () => c.shadowRoot || c.renderRoot;
|
||
// 1) дефолт (план есть): границ и лейблов нет
|
||
out.defaultStyled = sr().querySelectorAll('.room.styled').length;
|
||
out.defaultLabels = sr().querySelectorAll('.roomlabel').length;
|
||
// 2) включаем границы+имена+заливку по свету
|
||
c._serverCfg = { ...c._serverCfg, spaces: c._serverCfg.spaces.map((s) => s.id !== 'f1' ? s : {
|
||
...s, settings: { show_borders: true, show_names: true, room_color: '#ff8800', room_opacity: 0.8, fill_mode: 'light' },
|
||
})};
|
||
c.requestUpdate(); await c.updateComplete;
|
||
out.styled = sr().querySelectorAll('.room.styled').length;
|
||
out.labels = [...sr().querySelectorAll('.roomlabel')].map((l) => l.textContent.trim());
|
||
const liv = [...sr().querySelectorAll('.room.styled')][0];
|
||
out.livingStyle = liv.getAttribute('style');
|
||
// living: ceiling on → жёлтая; kitchen: нет light-сущностей → без заливки; bedroom light off → серая
|
||
const styles = [...sr().querySelectorAll('.room.styled')].map((r) => r.getAttribute('style'));
|
||
out.hasYellow = styles.some((s) => s.includes('#ffd45c'));
|
||
out.hasGrey = styles.some((s) => s.includes('#9aa0a6'));
|
||
out.kitchenNoFill = styles.some((s) => s.includes('--room-fill:transparent'));
|
||
// 3) lqi-заливка
|
||
c._serverCfg = { ...c._serverCfg, spaces: c._serverCfg.spaces.map((s) => s.id !== 'f1' ? s : {
|
||
...s, settings: { ...s.settings, fill_mode: 'lqi' },
|
||
})};
|
||
c.requestUpdate(); await c.updateComplete;
|
||
out.lqiFills = [...sr().querySelectorAll('.room.styled')].filter((r) => (r.getAttribute('style') || '').includes('hsl(')).length;
|
||
// 4) drag лейбла → layout rl_ (только в редакторе плана, с v1.25)
|
||
c._setMode('plan'); await c.updateComplete;
|
||
const lbl = sr().querySelector('.roomlabel');
|
||
c._labelDown({ preventDefault(){}, stopPropagation(){}, clientX: 100, clientY: 100, target: { setPointerCapture(){} }, pointerId: 5 },
|
||
c._spaceModel().rooms[0], 'f1');
|
||
c._labelMove({ clientX: 160, clientY: 140 }, c._spaceModel().rooms[0], 'f1');
|
||
c._labelUp(c._spaceModel().rooms[0]);
|
||
out.labelSaved = !!c._layout['rl_r1'];
|
||
// 5) диалог: create + draw
|
||
c._openSpaceDialog('create'); await c.updateComplete;
|
||
c._spaceDialog = { ...c._spaceDialog, title: 'Attic', source: 'draw', orientation: 'square' };
|
||
await c.updateComplete;
|
||
out.saveEnabled = !sr().querySelector('.dialog .btn.on[disabled]');
|
||
await c._saveSpaceDialog(); await c.updateComplete;
|
||
const attic = c._serverCfg.spaces.find((s) => s.title === 'Attic');
|
||
out.atticSquare = attic?.aspect === undefined; // no per-space ratio any more
|
||
out.atticSettings = attic?.settings;
|
||
out.atticNoPlan = attic ? attic.plan_url === null : null;
|
||
return out;
|
||
});
|
||
// значения зафиксированы прогоном на v1.43.1 и сверены с кодом (audit T1)
|
||
checkAll(res, {
|
||
"defaultStyled": 0,
|
||
"defaultLabels": 0,
|
||
"styled": 4,
|
||
"labels": ["Living room", "Kitchen", "Bedroom", "Hallway"],
|
||
"livingStyle": "--room-stroke:#ff8800;--room-stroke-op:0.8;--room-fill:#ffd45c;--room-fill-op:0.180",
|
||
"lqiFills": 0,
|
||
"atticSquare": true,
|
||
"atticSettings": {"show_borders": true, "show_names": true, "room_color": "#3ea6ff", "room_opacity": 0.55, "fill_mode": "none", "temp_min": 20, "temp_max": 25, "show_lqi": true, "label_temp": false, "label_hum": false, "label_lqi": false, "label_light": false},
|
||
});
|
||
await finish(browser, res);
|