mirror of
https://github.com/DavidHDev/vue-bits.git
synced 2026-03-07 14:39:30 -07:00
TS Fixes + Demo Cleanup
This commit is contained in:
@@ -42,12 +42,16 @@ function lerp(p1: number, p2: number, t: number): number {
|
||||
return p1 + (p2 - p1) * t;
|
||||
}
|
||||
|
||||
function autoBind(instance: Record<string, unknown>): void {
|
||||
const proto = Object.getPrototypeOf(instance);
|
||||
function autoBind<T extends object>(instance: T): void {
|
||||
const proto = Object.getPrototypeOf(instance) as Record<string, unknown> | null;
|
||||
if (!proto) return;
|
||||
Object.getOwnPropertyNames(proto).forEach(key => {
|
||||
if (key !== 'constructor' && typeof instance[key] === 'function') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
instance[key] = (instance[key] as any).bind(instance);
|
||||
if (key !== 'constructor') {
|
||||
const desc = Object.getOwnPropertyDescriptor(proto, key);
|
||||
if (desc && typeof desc.value === 'function') {
|
||||
const fn = desc.value as (...args: unknown[]) => unknown;
|
||||
(instance as Record<string, unknown>)[key] = fn.bind(instance);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -107,8 +111,7 @@ class Title {
|
||||
mesh!: Mesh;
|
||||
|
||||
constructor({ gl, plane, renderer, text, textColor = '#545050', font = '30px sans-serif' }: TitleProps) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
autoBind(this as any);
|
||||
autoBind(this);
|
||||
this.gl = gl;
|
||||
this.plane = plane;
|
||||
this.renderer = renderer;
|
||||
@@ -590,8 +593,9 @@ class App {
|
||||
|
||||
onWheel(e: Event) {
|
||||
const wheelEvent = e as WheelEvent;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const delta = wheelEvent.deltaY || (wheelEvent as any).wheelDelta || (wheelEvent as any).detail;
|
||||
// Support legacy wheel events if present
|
||||
const legacy = wheelEvent as unknown as { wheelDelta?: number; detail?: number };
|
||||
const delta = wheelEvent.deltaY ?? legacy.wheelDelta ?? legacy.detail ?? 0;
|
||||
this.scroll.target += delta > 0 ? this.scrollSpeed : -this.scrollSpeed;
|
||||
this.onCheckDebounce();
|
||||
}
|
||||
|
||||
@@ -156,8 +156,11 @@ void main() {
|
||||
}
|
||||
`;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function AutoBind(self: any, { include, exclude }: AutoBindOptions = {}) {
|
||||
type MethodNames<T> = {
|
||||
[K in keyof T]: T[K] extends (...args: unknown[]) => unknown ? K : never;
|
||||
}[keyof T];
|
||||
|
||||
function AutoBind<T extends object>(self: T, { include, exclude }: AutoBindOptions = {}) {
|
||||
const getAllProperties = (object: object): Set<[object, string | symbol]> => {
|
||||
const properties = new Set<[object, string | symbol]>();
|
||||
let currentObject: object | null = object;
|
||||
@@ -178,11 +181,18 @@ function AutoBind(self: any, { include, exclude }: AutoBindOptions = {}) {
|
||||
return true;
|
||||
};
|
||||
|
||||
for (const [object, key] of getAllProperties(self.constructor.prototype)) {
|
||||
const proto = Object.getPrototypeOf(self);
|
||||
if (!proto) return self;
|
||||
for (const [object, key] of getAllProperties(proto)) {
|
||||
if (key === 'constructor' || !filter(key)) continue;
|
||||
const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
|
||||
if (descriptor && typeof descriptor.value === 'function' && typeof key === 'string') {
|
||||
self[key] = self[key].bind(self);
|
||||
const current = (self as Record<string, unknown>)[key];
|
||||
if (typeof current === 'function') {
|
||||
(self as Record<MethodNames<T>, unknown>)[key as MethodNames<T>] = (
|
||||
current as (...a: unknown[]) => unknown
|
||||
).bind(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
return self;
|
||||
|
||||
@@ -59,14 +59,20 @@ let intervalId: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
const splitIntoCharacters = (text: string): string[] => {
|
||||
if (typeof Intl !== 'undefined' && 'Segmenter' in Intl) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const segmenter = new (Intl as any).Segmenter('en', { granularity: 'grapheme' });
|
||||
const IntlWithSegmenter = Intl as typeof Intl & {
|
||||
Segmenter: new (
|
||||
locales?: string | string[],
|
||||
options?: { granularity: 'grapheme' | 'word' | 'sentence' }
|
||||
) => {
|
||||
segment: (text: string) => Iterable<{ segment: string }>;
|
||||
};
|
||||
};
|
||||
const segmenter = new IntlWithSegmenter.Segmenter('en', { granularity: 'grapheme' });
|
||||
return [...segmenter.segment(text)].map(({ segment }) => segment);
|
||||
}
|
||||
|
||||
return [...text];
|
||||
};
|
||||
|
||||
const elements = computed((): WordElement[] => {
|
||||
const currentText = props.texts[currentTextIndex.value];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user