routie dev init since i didn't adhere to any proper guidance up until now
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
||||
@layer vuetify-components {
|
||||
.v-parallax {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
.v-parallax--active > .v-img__img {
|
||||
will-change: transform;
|
||||
}
|
||||
}
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
|
||||
export declare const makeVParallaxProps: <Defaults extends {
|
||||
class?: unknown;
|
||||
style?: unknown;
|
||||
scale?: unknown;
|
||||
} = {}>(defaults?: Defaults | undefined) => {
|
||||
class: unknown extends Defaults["class"] ? import("vue").PropType<any> : {
|
||||
type: import("vue").PropType<unknown extends Defaults["class"] ? any : any>;
|
||||
default: unknown extends Defaults["class"] ? any : any;
|
||||
};
|
||||
style: unknown extends Defaults["style"] ? {
|
||||
type: import("vue").PropType<import("vue").StyleValue>;
|
||||
default: null;
|
||||
} : Omit<{
|
||||
type: import("vue").PropType<import("vue").StyleValue>;
|
||||
default: null;
|
||||
}, "default" | "type"> & {
|
||||
type: import("vue").PropType<unknown extends Defaults["style"] ? import("vue").StyleValue : Defaults["style"] | import("vue").StyleValue>;
|
||||
default: unknown extends Defaults["style"] ? import("vue").StyleValue : Defaults["style"] | NonNullable<import("vue").StyleValue>;
|
||||
};
|
||||
scale: unknown extends Defaults["scale"] ? {
|
||||
type: (NumberConstructor | StringConstructor)[];
|
||||
default: number;
|
||||
} : Omit<{
|
||||
type: (NumberConstructor | StringConstructor)[];
|
||||
default: number;
|
||||
}, "default" | "type"> & {
|
||||
type: import("vue").PropType<unknown extends Defaults["scale"] ? string | number : string | number | Defaults["scale"]>;
|
||||
default: unknown extends Defaults["scale"] ? string | number : Defaults["scale"] | NonNullable<string | number>;
|
||||
};
|
||||
};
|
||||
export declare const VParallax: {
|
||||
new (...args: any[]): import("vue").CreateComponentPublicInstanceWithMixins<{
|
||||
style: string | false | import("vue").StyleValue[] | import("vue").CSSProperties | null;
|
||||
scale: string | number;
|
||||
} & {
|
||||
class?: any;
|
||||
} & {
|
||||
$children?: {
|
||||
default?: (() => import("vue").VNodeChild) | undefined;
|
||||
placeholder?: (() => import("vue").VNodeChild) | undefined;
|
||||
error?: (() => import("vue").VNodeChild) | undefined;
|
||||
sources?: (() => import("vue").VNodeChild) | undefined;
|
||||
} | {
|
||||
$stable?: boolean;
|
||||
} | (() => import("vue").VNodeChild) | import("vue").VNodeChild;
|
||||
'v-slots'?: {
|
||||
default?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
placeholder?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
error?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
sources?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
} | undefined;
|
||||
} & {
|
||||
"v-slot:default"?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
"v-slot:error"?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
"v-slot:placeholder"?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
"v-slot:sources"?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, {
|
||||
style: import("vue").StyleValue;
|
||||
scale: string | number;
|
||||
}, true, {}, import("vue").SlotsType<Partial<{
|
||||
default: () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
||||
[key: string]: any;
|
||||
}>[];
|
||||
placeholder: () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
||||
[key: string]: any;
|
||||
}>[];
|
||||
error: () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
||||
[key: string]: any;
|
||||
}>[];
|
||||
sources: () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
||||
[key: string]: any;
|
||||
}>[];
|
||||
}>>, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, {}, any, import("vue").ComponentProvideOptions, {
|
||||
P: {};
|
||||
B: {};
|
||||
D: {};
|
||||
C: {};
|
||||
M: {};
|
||||
Defaults: {};
|
||||
}, {
|
||||
style: string | false | import("vue").StyleValue[] | import("vue").CSSProperties | null;
|
||||
scale: string | number;
|
||||
} & {
|
||||
class?: any;
|
||||
} & {
|
||||
$children?: {
|
||||
default?: (() => import("vue").VNodeChild) | undefined;
|
||||
placeholder?: (() => import("vue").VNodeChild) | undefined;
|
||||
error?: (() => import("vue").VNodeChild) | undefined;
|
||||
sources?: (() => import("vue").VNodeChild) | undefined;
|
||||
} | {
|
||||
$stable?: boolean;
|
||||
} | (() => import("vue").VNodeChild) | import("vue").VNodeChild;
|
||||
'v-slots'?: {
|
||||
default?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
placeholder?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
error?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
sources?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
} | undefined;
|
||||
} & {
|
||||
"v-slot:default"?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
"v-slot:error"?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
"v-slot:placeholder"?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
"v-slot:sources"?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
}, {}, {}, {}, {}, {
|
||||
style: import("vue").StyleValue;
|
||||
scale: string | number;
|
||||
}>;
|
||||
__isFragment?: never;
|
||||
__isTeleport?: never;
|
||||
__isSuspense?: never;
|
||||
} & import("vue").ComponentOptionsBase<{
|
||||
style: string | false | import("vue").StyleValue[] | import("vue").CSSProperties | null;
|
||||
scale: string | number;
|
||||
} & {
|
||||
class?: any;
|
||||
} & {
|
||||
$children?: {
|
||||
default?: (() => import("vue").VNodeChild) | undefined;
|
||||
placeholder?: (() => import("vue").VNodeChild) | undefined;
|
||||
error?: (() => import("vue").VNodeChild) | undefined;
|
||||
sources?: (() => import("vue").VNodeChild) | undefined;
|
||||
} | {
|
||||
$stable?: boolean;
|
||||
} | (() => import("vue").VNodeChild) | import("vue").VNodeChild;
|
||||
'v-slots'?: {
|
||||
default?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
placeholder?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
error?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
sources?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
} | undefined;
|
||||
} & {
|
||||
"v-slot:default"?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
"v-slot:error"?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
"v-slot:placeholder"?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
"v-slot:sources"?: false | (() => import("vue").VNodeChild) | undefined;
|
||||
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, {
|
||||
style: import("vue").StyleValue;
|
||||
scale: string | number;
|
||||
}, {}, string, import("vue").SlotsType<Partial<{
|
||||
default: () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
||||
[key: string]: any;
|
||||
}>[];
|
||||
placeholder: () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
||||
[key: string]: any;
|
||||
}>[];
|
||||
error: () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
||||
[key: string]: any;
|
||||
}>[];
|
||||
sources: () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
||||
[key: string]: any;
|
||||
}>[];
|
||||
}>>, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, import("vue").ComponentProvideOptions> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & import("../../util/index.js").FilterPropsOptions<{
|
||||
class: import("vue").PropType<any>;
|
||||
style: {
|
||||
type: import("vue").PropType<import("vue").StyleValue>;
|
||||
default: null;
|
||||
};
|
||||
scale: {
|
||||
type: (NumberConstructor | StringConstructor)[];
|
||||
default: number;
|
||||
};
|
||||
}, import("vue").ExtractPropTypes<{
|
||||
class: import("vue").PropType<any>;
|
||||
style: {
|
||||
type: import("vue").PropType<import("vue").StyleValue>;
|
||||
default: null;
|
||||
};
|
||||
scale: {
|
||||
type: (NumberConstructor | StringConstructor)[];
|
||||
default: number;
|
||||
};
|
||||
}>>;
|
||||
export type VParallax = InstanceType<typeof VParallax>;
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
import { normalizeClass as _normalizeClass, normalizeStyle as _normalizeStyle, createVNode as _createVNode } from "vue";
|
||||
// Styles
|
||||
import "./VParallax.css";
|
||||
|
||||
// Components
|
||||
import { VImg } from "../VImg/index.js"; // Composables
|
||||
import { useDisplay } from "../../composables/index.js";
|
||||
import { makeComponentProps } from "../../composables/component.js";
|
||||
import { useIntersectionObserver } from "../../composables/intersectionObserver.js";
|
||||
import { useResizeObserver } from "../../composables/resizeObserver.js"; // Utilities
|
||||
import { computed, onBeforeUnmount, ref, watch, watchEffect } from 'vue';
|
||||
import { clamp, genericComponent, getScrollParent, PREFERS_REDUCED_MOTION, propsFactory, useRender } from "../../util/index.js"; // Types
|
||||
function floor(val) {
|
||||
return Math.floor(Math.abs(val)) * Math.sign(val);
|
||||
}
|
||||
export const makeVParallaxProps = propsFactory({
|
||||
scale: {
|
||||
type: [Number, String],
|
||||
default: 0.5
|
||||
},
|
||||
...makeComponentProps()
|
||||
}, 'VParallax');
|
||||
export const VParallax = genericComponent()({
|
||||
name: 'VParallax',
|
||||
props: makeVParallaxProps(),
|
||||
setup(props, {
|
||||
slots
|
||||
}) {
|
||||
const {
|
||||
intersectionRef,
|
||||
isIntersecting
|
||||
} = useIntersectionObserver();
|
||||
const {
|
||||
resizeRef,
|
||||
contentRect
|
||||
} = useResizeObserver();
|
||||
const {
|
||||
height: displayHeight
|
||||
} = useDisplay();
|
||||
const root = ref();
|
||||
watchEffect(() => {
|
||||
intersectionRef.value = resizeRef.value = root.value?.$el;
|
||||
});
|
||||
let scrollParent;
|
||||
watch(isIntersecting, val => {
|
||||
if (val) {
|
||||
scrollParent = getScrollParent(intersectionRef.value);
|
||||
scrollParent = scrollParent === document.scrollingElement ? document : scrollParent;
|
||||
scrollParent.addEventListener('scroll', onScroll, {
|
||||
passive: true
|
||||
});
|
||||
onScroll();
|
||||
} else {
|
||||
scrollParent.removeEventListener('scroll', onScroll);
|
||||
}
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
scrollParent?.removeEventListener('scroll', onScroll);
|
||||
});
|
||||
watch(displayHeight, onScroll);
|
||||
watch(() => contentRect.value?.height, onScroll);
|
||||
const scale = computed(() => {
|
||||
return 1 - clamp(Number(props.scale));
|
||||
});
|
||||
let frame = -1;
|
||||
function onScroll() {
|
||||
if (!isIntersecting.value || PREFERS_REDUCED_MOTION()) return;
|
||||
cancelAnimationFrame(frame);
|
||||
frame = requestAnimationFrame(() => {
|
||||
const el = (root.value?.$el).querySelector('.v-img__img');
|
||||
if (!el) return;
|
||||
const scrollHeight = scrollParent instanceof Document ? document.documentElement.clientHeight : scrollParent.clientHeight;
|
||||
const scrollPos = scrollParent instanceof Document ? window.scrollY : scrollParent.scrollTop;
|
||||
const top = intersectionRef.value.getBoundingClientRect().top + scrollPos;
|
||||
const height = contentRect.value.height;
|
||||
const center = top + (height - scrollHeight) / 2;
|
||||
const translate = floor((scrollPos - center) * scale.value);
|
||||
const sizeScale = Math.max(1, (scale.value * (scrollHeight - height) + height) / height);
|
||||
el.style.setProperty('transform', `translateY(${translate}px) scale(${sizeScale})`);
|
||||
});
|
||||
}
|
||||
useRender(() => _createVNode(VImg, {
|
||||
"class": _normalizeClass(['v-parallax', {
|
||||
'v-parallax--active': isIntersecting.value
|
||||
}, props.class]),
|
||||
"style": _normalizeStyle(props.style),
|
||||
"ref": root,
|
||||
"cover": true,
|
||||
"onLoadstart": onScroll,
|
||||
"onLoad": onScroll
|
||||
}, slots));
|
||||
return {};
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=VParallax.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+9
@@ -0,0 +1,9 @@
|
||||
@use '../../styles/tools'
|
||||
|
||||
@include tools.layer('components')
|
||||
.v-parallax
|
||||
position: relative
|
||||
overflow: hidden
|
||||
|
||||
&--active > .v-img__img
|
||||
will-change: transform
|
||||
+1
@@ -0,0 +1 @@
|
||||
export { VParallax } from './VParallax.js';
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export { VParallax } from "./VParallax.js";
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","names":["VParallax"],"sources":["../../../src/components/VParallax/index.ts"],"sourcesContent":["export { VParallax } from './VParallax'\n"],"mappings":"SAASA,SAAS","ignoreList":[]}
|
||||
Reference in New Issue
Block a user