refactor: update js - separate files, modules
This commit is contained in:
+4
-5
@@ -1,6 +1,6 @@
|
||||
import { $ } from './dom.js';
|
||||
import { computeHomography } from './homography.js';
|
||||
|
||||
function $(id) { return document.getElementById(id); }
|
||||
import { round, FIELD_PADDING } from './constants.js';
|
||||
|
||||
function applyBgToField(field, state) {
|
||||
if (state.bgImage) {
|
||||
@@ -33,7 +33,7 @@ export function updateLivePreview(state) {
|
||||
const cw = container.clientWidth;
|
||||
if (cw <= 0) return;
|
||||
|
||||
const maxH = window.innerHeight - 140;
|
||||
const maxH = window.innerHeight - FIELD_PADDING;
|
||||
const scaleW = cw / state.fieldW;
|
||||
const scaleH = maxH / state.fieldH;
|
||||
const scale = Math.min(scaleW, scaleH);
|
||||
@@ -54,8 +54,7 @@ export function updateLivePreview(state) {
|
||||
|
||||
const H = computeHomography(state);
|
||||
if (H) {
|
||||
const n = v => parseFloat(v.toFixed(6));
|
||||
widget.style.transform = `matrix3d(${n(H.h00)},${n(H.h10)},0,${n(H.h20)},${n(H.h01)},${n(H.h11)},0,${n(H.h21)},0,0,1,0,${n(H.h02)},${n(H.h12)},0,${n(H.h22)})`;
|
||||
widget.style.transform = `matrix3d(${round(H.h00)},${round(H.h10)},0,${round(H.h20)},${round(H.h01)},${round(H.h11)},0,${round(H.h21)},0,0,1,0,${round(H.h02)},${round(H.h12)},0,${round(H.h22)})`;
|
||||
widget.style.opacity = '1';
|
||||
} else {
|
||||
widget.style.transform = 'none';
|
||||
|
||||
Reference in New Issue
Block a user