Skip to content

Commit d9f522d

Browse files
committed
style: update style
1 parent d94ea0d commit d9f522d

17 files changed

+273
-235
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = {
44
es2021: true,
55
},
66
extends: ['plugin:vue/vue3-recommended', 'prettier', 'plugin:prettier/recommended'],
7+
parser: '@typescript-eslint/parser',
78
parserOptions: {
89
ecmaVersion: 'latest',
910
sourceType: 'module',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"lib"
5353
],
5454
"dependencies": {
55+
"@typescript-eslint/parser": "^5.59.5",
5556
"@vitejs/plugin-vue": "^4.2.3",
5657
"@vue/test-utils": "^2.3.2",
5758
"babel": "^6.23.0",

pnpm-lock.yaml

Lines changed: 24 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/LazyLoadComponent.tsx

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { DefineComponent } from 'vue'
2-
import { reactive, computed, watch, defineComponent, ExtractPropTypes } from 'vue'
3-
import PlaceholderWithoutTracking from './PlaceholderWithoutTracking.tsx'
1+
import type { DefineComponent, ExtractPropTypes } from 'vue';
2+
import { reactive, computed, watch, defineComponent } from 'vue';
3+
import PlaceholderWithoutTracking from './PlaceholderWithoutTracking.tsx';
44
import isIntersectionObserverAvailable from '../utils/intersection-observer';
5-
import PlaceholderWithTracking from './PlaceholderWithTracking.tsx'
6-
import { LazyLoadComponentPropsFunc } from "./interface.ts";
5+
import PlaceholderWithTracking from './PlaceholderWithTracking.tsx';
6+
import { LazyLoadComponentPropsFunc } from './interface.ts';
77

8-
export type LazyLoadComponentProps = Partial<ExtractPropTypes<ReturnType<typeof LazyLoadComponentPropsFunc>>>
8+
export type LazyLoadComponentProps = Partial<
9+
ExtractPropTypes<ReturnType<typeof LazyLoadComponentPropsFunc>>
10+
>;
911

1012
export default defineComponent({
1113
compatConfig: { MODE: 3 },
@@ -17,39 +19,42 @@ export default defineComponent({
1719
visible: props.visibleByDefault ?? false,
1820
loaded: false,
1921
error: false,
20-
})
21-
const isScrollTracked = computed(() => Boolean(
22-
props.scrollPosition &&
23-
Number.isFinite(props.scrollPosition.x) &&
24-
props.scrollPosition.x >= 0 &&
25-
Number.isFinite(props.scrollPosition.y) &&
26-
props.scrollPosition.y >= 0
27-
))
22+
});
23+
const isScrollTracked = computed(() =>
24+
Boolean(
25+
props.scrollPosition &&
26+
Number.isFinite(props.scrollPosition.x) &&
27+
props.scrollPosition.x >= 0 &&
28+
Number.isFinite(props.scrollPosition.y) &&
29+
props.scrollPosition.y >= 0,
30+
),
31+
);
2832

29-
watch(state,
33+
watch(
34+
state,
3035
(prevState, state) => {
3136
if (prevState.visible !== state?.visible) {
3237
props.afterLoad?.();
3338
}
3439
},
35-
{ immediate: true }
36-
)
40+
{ immediate: true },
41+
);
3742

3843
const onVisible = () => {
39-
state.visible = true
40-
props.afterLoad?.()
41-
}
44+
state.visible = true;
45+
props.afterLoad?.();
46+
};
4247

4348
if (props.visibleByDefault) {
44-
props.beforeLoad?.()
45-
props.afterLoad?.()
49+
props.beforeLoad?.();
50+
props.afterLoad?.();
4651
}
4752
return () => {
4853
if (state.visible) {
49-
return slots.default?.()
54+
return slots.default?.();
5055
}
51-
return (isScrollTracked ||
52-
(props.useIntersectionObserver && isIntersectionObserverAvailable()) ?
56+
return isScrollTracked.value ||
57+
(props.useIntersectionObserver && isIntersectionObserverAvailable()) ? (
5358
<PlaceholderWithoutTracking
5459
height={props.height}
5560
onVisible={onVisible}
@@ -59,7 +64,7 @@ export default defineComponent({
5964
useIntersectionObserver={props.useIntersectionObserver}
6065
width={props.width}
6166
/>
62-
:
67+
) : (
6368
<PlaceholderWithTracking
6469
height={props.height}
6570
onVisible={onVisible}
@@ -68,8 +73,8 @@ export default defineComponent({
6873
threshold={props.threshold}
6974
useIntersectionObserver={props.useIntersectionObserver}
7075
width={props.width}
71-
/>)
72-
}
73-
}
74-
}) as DefineComponent<LazyLoadComponentProps>
75-
76+
/>
77+
);
78+
};
79+
},
80+
}) as DefineComponent<LazyLoadComponentProps>;

src/components/LazyLoadImage.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import type { DefineComponent } from 'vue';
2-
import { ExtractPropTypes, computed, defineComponent, ref } from 'vue';
1+
import type { DefineComponent, ExtractPropTypes } from 'vue';
2+
import { computed, defineComponent, ref } from 'vue';
33
import LazyLoadComponent from './LazyLoadComponent.jsx';
44
import { LazyLoadImagePropsFunc } from './interface.js';
5-
6-
export type LazyLoadImageProps = Partial<ExtractPropTypes<ReturnType<typeof LazyLoadImagePropsFunc>>> & Partial<Omit<HTMLImageElement, 'style'>>
5+
import '../effects/index.css';
6+
export type LazyLoadImageProps = Partial<
7+
ExtractPropTypes<ReturnType<typeof LazyLoadImagePropsFunc>>
8+
> &
9+
Partial<Omit<HTMLImageElement, 'style'>>;
710

811
const LazyLoadImage = defineComponent({
912
name: 'LazyLoadImage',
@@ -14,12 +17,12 @@ const LazyLoadImage = defineComponent({
1417
const loaded = ref(false);
1518
function onImageLoad() {
1619
if (loaded.value) {
17-
return null
20+
return null;
1821
}
1922
return () => {
20-
props.afterLoad?.()
21-
loaded.value = true
22-
}
23+
props.afterLoad?.();
24+
loaded.value = true;
25+
};
2326
}
2427
function getImg() {
2528
const imgProps = computed(() => {
@@ -42,10 +45,10 @@ const LazyLoadImage = defineComponent({
4245
loadedClassName,
4346
...imgProps
4447
} = props;
45-
return imgProps
46-
})
48+
return imgProps;
49+
});
4750
// @ts-ignore
48-
return <img onLoad={onImageLoad()} {...imgProps.value} {...attrs} />
51+
return <img onLoad={onImageLoad()} {...imgProps.value} {...attrs} />;
4952
}
5053
function getLazyLoadImage() {
5154
return (
@@ -65,25 +68,26 @@ const LazyLoadImage = defineComponent({
6568
>
6669
{getImg()}
6770
</LazyLoadComponent>
68-
)
71+
);
6972
}
70-
const loadedClassName = computed(() => loaded.value ? ' lazy-load-image-loaded' : '')
73+
const loadedClassName = computed(() => (loaded.value ? ' lazy-load-image-loaded' : ''));
7174
const wrapperBackground = computed(() => {
7275
if (loaded.value || !props.placeholderSrc) {
73-
return {}
76+
return {};
7477
}
7578
return {
7679
backgroundImage: `url(${props.placeholderSrc})`,
7780
backgroundSize: '100% 100%',
78-
}
79-
})
81+
};
82+
});
8083
function getWrappedLazyLoadImage(lazyLoadImage: any) {
8184
return (
8285
<span
8386
class={
8487
props.wrapperClassName +
8588
' lazy-load-image-background ' +
86-
props.effect + loadedClassName.value
89+
props.effect +
90+
loadedClassName.value
8791
}
8892
style={{
8993
...wrapperBackground.value,
@@ -106,7 +110,7 @@ const LazyLoadImage = defineComponent({
106110
return lazyLoadImage;
107111
}
108112
return getWrappedLazyLoadImage(lazyLoadImage);
109-
}
113+
};
110114
},
111115
});
112116

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import { defineComponent } from 'vue'
2-
import { trackWindowScroll } from './trackWindowScroll.tsx'
3-
import PlaceholderWithoutTracking from './PlaceholderWithoutTracking'
4-
import { PlaceholderWithTrackingPropsFunc } from './interface.ts'
1+
import { defineComponent } from 'vue';
2+
import { trackWindowScroll } from './trackWindowScroll.tsx';
3+
import PlaceholderWithoutTracking from './PlaceholderWithoutTracking';
4+
import { PlaceholderWithTrackingPropsFunc } from './interface.ts';
55
const PlaceholderWithTracking = defineComponent({
66
name: 'PlaceholderWithTracking',
77
props: PlaceholderWithTrackingPropsFunc(),
88
setup(props) {
9-
return () => (
10-
<PlaceholderWithoutTracking {...props} />
11-
)
12-
}
13-
})
9+
return () => <PlaceholderWithoutTracking {...props} />;
10+
},
11+
});
1412

15-
export default trackWindowScroll(PlaceholderWithTracking)
13+
export default trackWindowScroll(PlaceholderWithTracking);

0 commit comments

Comments
 (0)