Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
1673 esurio
Sharkey
Commits
81ba841f
Unverified
Commit
81ba841f
authored
1 year ago
by
tamaina
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
perf(frontend): MkMediaListのアスペクト比制限を調整 (#11377)
parent
0404d9c1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/frontend/src/components/MkMediaList.vue
+44
-19
44 additions, 19 deletions
packages/frontend/src/components/MkMediaList.vue
packages/frontend/src/pages/settings/general.vue
+1
-0
1 addition, 0 deletions
packages/frontend/src/pages/settings/general.vue
with
45 additions
and
19 deletions
packages/frontend/src/components/MkMediaList.vue
+
44
−
19
View file @
81ba841f
<
template
>
<div>
<div
ref=
"root"
>
<XBanner
v-for=
"media in mediaList.filter(media => !previewable(media))"
:key=
"media.id"
:media=
"media"
/>
<div
v-if=
"mediaList.filter(media => previewable(media)).length > 0"
:class=
"$style.container"
>
<div
...
...
@@ -23,7 +23,7 @@
</template>
<
script
lang=
"ts"
setup
>
import
{
onMounted
,
watch
,
shallowRef
}
from
'
vue
'
;
import
{
onMounted
,
shallowRef
}
from
'
vue
'
;
import
*
as
misskey
from
'
misskey-js
'
;
import
PhotoSwipeLightbox
from
'
photoswipe/lightbox
'
;
import
PhotoSwipe
from
'
photoswipe
'
;
...
...
@@ -34,19 +34,26 @@ import XVideo from '@/components/MkMediaVideo.vue';
import
*
as
os
from
'
@/os
'
;
import
{
FILE_TYPE_BROWSERSAFE
}
from
'
@/const
'
;
import
{
defaultStore
}
from
'
@/store
'
;
import
{
getScrollContainer
,
getBodyScrollHeight
}
from
'
@/scripts/scroll
'
;
const
props
=
defineProps
<
{
mediaList
:
misskey
.
entities
.
DriveFile
[];
raw
?:
boolean
;
}
>
();
const
root
=
shallowRef
<
HTMLDivElement
>
();
const
container
=
shallowRef
<
HTMLElement
|
null
|
undefined
>
(
undefined
);
const
gallery
=
shallowRef
<
HTMLDivElement
>
();
const
pswpZIndex
=
os
.
claimZIndex
(
'
middle
'
);
document
.
documentElement
.
style
.
setProperty
(
'
--mk-pswp-root-z-index
'
,
pswpZIndex
.
toString
());
const
count
=
$computed
(()
=>
props
.
mediaList
.
filter
(
media
=>
previewable
(
media
)).
length
);
/**
* アスペクト比をmediaListWithOneImageAppearanceに基づいていい感じに調整する
* aspect-ratioではなくheightを使う
*/
function
calcAspectRatio
()
{
if
(
!
gallery
.
value
)
return
;
if
(
!
gallery
.
value
||
!
root
.
value
)
return
;
let
img
=
props
.
mediaList
[
0
];
...
...
@@ -55,28 +62,46 @@ function calcAspectRatio() {
return
;
}
// アスペクト比上限設定では、横長の場合は高さを縮小させる
const
ratioMax
=
(
ratio
:
number
)
=>
`
${
Math
.
max
(
ratio
,
img
.
properties
.
width
/
img
.
properties
.
height
).
toString
()}
/ 1`
;
const
width
=
gallery
.
value
.
clientWidth
;
const
heightMin
=
(
ratio
:
number
)
=>
{
const
imgResizeRatio
=
width
/
img
.
properties
.
width
;
const
imgDrawHeight
=
img
.
properties
.
height
*
imgResizeRatio
;
const
maxHeight
=
width
*
ratio
;
const
height
=
Math
.
min
(
imgDrawHeight
,
maxHeight
);
if
(
_DEV_
)
console
.
log
(
'
Image height calculated:
'
,
{
width
,
properties
:
img
.
properties
,
imgResizeRatio
,
imgDrawHeight
,
maxHeight
,
height
});
return
`
${
height
}
px`
;
};
switch
(
defaultStore
.
state
.
mediaListWithOneImageAppearance
)
{
case
'
16_9
'
:
gallery
.
value
.
style
.
aspectRatio
=
ratioMax
(
16
/
9
);
gallery
.
value
.
style
.
height
=
heightMin
(
9
/
16
);
break
;
case
'
1_1
'
:
gallery
.
value
.
style
.
aspectRatio
=
ratioMax
(
1
);
gallery
.
value
.
style
.
height
=
heightMin
(
1
);
break
;
case
'
2_3
'
:
gallery
.
value
.
style
.
aspectRatio
=
ratioMax
(
2
/
3
);
gallery
.
value
.
style
.
height
=
heightMin
(
3
/
2
);
break
;
default
:
gallery
.
value
.
style
.
aspectRatio
=
''
;
default
:
{
if
(
!
container
.
value
)
container
.
value
=
getScrollContainer
(
root
.
value
);
const
maxHeight
=
Math
.
max
(
64
,
(
container
.
value
?
container
.
value
.
clientHeight
:
getBodyScrollHeight
())
*
0.5
||
360
);
if
(
width
===
0
||
!
maxHeight
)
return
;
const
imgResizeRatio
=
width
/
img
.
properties
.
width
;
const
imgDrawHeight
=
img
.
properties
.
height
*
imgResizeRatio
;
gallery
.
value
.
style
.
height
=
`
${
Math
.
max
(
64
,
Math
.
min
(
imgDrawHeight
,
maxHeight
))}
px`
;
gallery
.
value
.
style
.
minHeight
=
'
initial
'
;
gallery
.
value
.
style
.
maxHeight
=
'
initial
'
;
break
;
}
}
}
watch
([
defaultStore
.
reactiveState
.
mediaListWithOneImageAppearance
,
gallery
],
()
=>
calcAspectRatio
());
gallery
.
value
.
style
.
aspectRatio
=
'
initial
'
;
}
onMounted
(()
=>
{
calcAspectRatio
();
const
lightbox
=
new
PhotoSwipeLightbox
({
dataSource
:
props
.
mediaList
.
filter
(
media
=>
{
...
...
@@ -203,7 +228,7 @@ const previewable = (file: misskey.entities.DriveFile): boolean => {
&
.n1
{
grid-template-rows
:
1fr
;
// default (expand)
// default
but fallback
(expand)
min-height
:
64px
;
max-height
:
clamp
(
64px
,
...
...
@@ -212,20 +237,20 @@ const previewable = (file: misskey.entities.DriveFile): boolean => {
);
&
.n116_9
{
min-height
:
none
;
max-height
:
none
;
min-height
:
initial
;
max-height
:
initial
;
aspect-ratio
:
16
/
9
;
// fallback
}
&
.n11_1
{
min-height
:
none
;
max-height
:
none
;
min-height
:
initial
;
max-height
:
initial
;
aspect-ratio
:
1
/
1
;
// fallback
}
&
.n12_3
{
min-height
:
none
;
max-height
:
none
;
min-height
:
initial
;
max-height
:
initial
;
aspect-ratio
:
2
/
3
;
// fallback
}
}
...
...
This diff is collapsed.
Click to expand it.
packages/frontend/src/pages/settings/general.vue
+
1
−
0
View file @
81ba841f
...
...
@@ -258,6 +258,7 @@ watch([
showGapBetweenNotesInTimeline
,
instanceTicker
,
overridedDeviceKind
,
mediaListWithOneImageAppearance
,
],
async
()
=>
{
await
reloadAsk
();
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment