diff --git a/src/Web/index.html b/src/Web/index.html index f077ee3..75dc8ca 100644 --- a/src/Web/index.html +++ b/src/Web/index.html @@ -1,365 +1,531 @@ + + - + + window.spark = new MouseSpark(); + + // C# 通信接口 + + let lastBoomX = -1, lastBoomY = -1; + let lastBoomTime = 0; + let lastMoveX = -1, lastMoveY = -1; + + window.currentInputMode = "mouse"; + window.enableAlwaysTrailEffect = false; + window.effectiveAlwaysTrail = false; + + window.setInputContext = (mode, alwaysTrailEnabled) => { + window.currentInputMode = mode === "touch" ? "touch" : "mouse"; + window.enableAlwaysTrailEffect = Boolean(alwaysTrailEnabled); + window.effectiveAlwaysTrail = window.currentInputMode === "mouse" && window.enableAlwaysTrailEffect; + }; + + window.setInputContext("mouse", false); + + // 接收 C# 传来的物理百分比 (0.0 ~ 1.0),由前端根据真实的画布宽度自行计算 + window.externalBoom = (percentX, percentY) => { + const now = Date.now(); + if (percentX === lastBoomX && percentY === lastBoomY && (now - lastBoomTime) < 25) return; + lastBoomX = percentX; + lastBoomY = percentY; + lastBoomTime = now; + + // 百分比乘以 WebView 当前真实的内部宽度 + const cx = percentX * window.innerWidth; + const cy = percentY * window.innerHeight; + window.dispatchEvent(new MouseEvent('mousedown', { clientX: cx, clientY: cy, bubbles: true })); + }; + + window.externalMove = (percentX, percentY) => { + if (percentX === lastMoveX && percentY === lastMoveY) return; + lastMoveX = percentX; + lastMoveY = percentY; + + // 方法与上述相同 + const cx = percentX * window.innerWidth; + const cy = percentY * window.innerHeight; + window.dispatchEvent(new MouseEvent('mousemove', { clientX: cx, clientY: cy, bubbles: true })); + }; + + window.externalUp = () => { + window.dispatchEvent(new MouseEvent('mouseup', { bubbles: true })); + }; + + window.updateColor = (rgbString) => { + if (window.spark) { + window.spark.color = rgbString; + window.spark.ringsEndColor = ringsEndColorFromRgb(rgbString); + } + }; + + window.updateEffectSettings = (scale, opacity, trailSpeed, clickSpeed) => { + if (!window.spark) return; + window.spark.scale = Math.max(0.5, Math.min(3, Number(scale) || 1.5)); + window.spark.opacity = Math.max(0.1, Math.min(1, Number(opacity) || 1.0)); + let t = Number(trailSpeed); + if (!Number.isFinite(t)) t = 1.0; + let c = Number(clickSpeed); + if (!Number.isFinite(c)) c = t; + window.spark.trailSpeed = Math.max(0.2, Math.min(3, t)); + window.spark.clickSpeed = Math.max(0.2, Math.min(3, c)); + }; + - + \ No newline at end of file