Files
workbuddy_skills/oil-motion/assets/step-gesture.ts
T
admin 237a09a5b0 修:draw-ui / oil-motion 原被当子模块指针收录 ⇒ 改为正常文件入库(两份内容原先对别人是空的)
一、问题(本轮实测)
`draw-ui` 与 `oil-motion` 目录里**各自带一个内嵌 `.git`** ⇒ 上一次提交把它们记成了 **gitlink(子模块指针)**
⇒ 仓库里只存了一个不属于任何远端的 commit id,**别人克隆下来这两份是空的** ✗(`git status` 显示 ` m draw-ui` / ` m oil-motion` = 子模块内容有改动)。

二、处置(可回退)
· 把两处的 `.git` **挪走**(⛔ 不是删除)⇒ `归档/内嵌git-20261008/{draw-ui,oil-motion}.git`;
· `git rm --cached` 掉那两个 gitlink,再 `git add` 两个目录 ⇒ **按正常文件入库**(内容才真的进仓库)。

三、副作用(如实记)
挪走 `.git` 后,这两个技能**不能再原地 `git pull` 取上游更新**(要更新得重新拉一份覆盖);
如需恢复其本地仓库,把 `归档/内嵌git-20261008/` 里的 `.git` 挪回原处即可。
2026-10-08 22:29:52 +08:00

79 lines
1.9 KiB
TypeScript

export type StepDirection = -1 | 1;
export type StepGestureOptions = {
threshold?: number;
idleMilliseconds?: number;
onStep: (direction: StepDirection) => void;
};
export type StepGestureAdapter = {
feed(delta: number): void;
setProgrammaticNavigation(active: boolean): void;
reset(): void;
destroy(): void;
};
export function createStepGestureAdapter(
options: StepGestureOptions,
): StepGestureAdapter {
const threshold = Math.max(1, options.threshold ?? 40);
const idleMilliseconds = Math.max(16, options.idleMilliseconds ?? 140);
let accumulated = 0;
let lockedDirection: StepDirection | 0 = 0;
let programmaticNavigation = false;
let releaseTimer = 0;
let destroyed = false;
const clearRelease = () => {
if (releaseTimer) window.clearTimeout(releaseTimer);
releaseTimer = 0;
};
const reset = () => {
clearRelease();
accumulated = 0;
lockedDirection = 0;
};
const scheduleRelease = () => {
clearRelease();
releaseTimer = window.setTimeout(reset, idleMilliseconds);
};
return {
feed(delta: number) {
if (
destroyed ||
programmaticNavigation ||
!Number.isFinite(delta) ||
delta === 0
) return;
const direction: StepDirection = delta < 0 ? -1 : 1;
if (lockedDirection === direction) {
scheduleRelease();
return;
}
if (lockedDirection === -direction) {
accumulated = 0;
lockedDirection = 0;
}
if (accumulated && Math.sign(accumulated) !== direction) accumulated = 0;
accumulated += delta;
scheduleRelease();
if (Math.abs(accumulated) < threshold) return;
accumulated = 0;
lockedDirection = direction;
options.onStep(direction);
},
setProgrammaticNavigation(active: boolean) {
programmaticNavigation = active;
if (active) reset();
},
reset,
destroy() {
destroyed = true;
reset();
},
};
}