Compare commits
4 commits
73a56357d9
...
da32969f5a
Author | SHA1 | Date | |
---|---|---|---|
|
da32969f5a | ||
|
6b889666ad | ||
|
6e28d8808b | ||
|
41d15887a7 |
2 changed files with 56 additions and 41 deletions
|
@ -116,6 +116,13 @@ const Profile: Component = () => {
|
||||||
gap: 16px;
|
gap: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
& :global(a) {
|
||||||
|
color: inherit;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.acct-grp {
|
.acct-grp {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: row wrap;
|
flex-flow: row wrap;
|
||||||
|
@ -274,6 +281,7 @@ const Profile: Component = () => {
|
||||||
average: colors.hex,
|
average: colors.hex,
|
||||||
text: colors.isDark ? "white" : "black",
|
text: colors.isDark ? "white" : "black",
|
||||||
});
|
});
|
||||||
|
ins.destroy();
|
||||||
}}
|
}}
|
||||||
></img>
|
></img>
|
||||||
</div>
|
</div>
|
||||||
|
@ -309,6 +317,7 @@ const Profile: Component = () => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
class="description"
|
||||||
ref={(e) =>
|
ref={(e) =>
|
||||||
createRenderEffect(() => (e.innerHTML = description() || ""))
|
createRenderEffect(() => (e.innerHTML = description() || ""))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import type { mastodon } from "masto";
|
||||||
import {
|
import {
|
||||||
type Component,
|
type Component,
|
||||||
For,
|
For,
|
||||||
|
Index,
|
||||||
createMemo,
|
createMemo,
|
||||||
createRenderEffect,
|
createRenderEffect,
|
||||||
createSignal,
|
createSignal,
|
||||||
|
@ -103,6 +104,31 @@ const MediaAttachmentGrid: Component<{
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const itemStyle = (item: mastodon.v1.MediaAttachment) => {
|
||||||
|
const { width, height } = constraintedSize(
|
||||||
|
item.meta?.small || { width: 1, height: 1 },
|
||||||
|
{ width: 2, height: 2 },
|
||||||
|
itemMaxSize(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// I don't know why mastodon does not return this
|
||||||
|
// and the condition for it to return this.
|
||||||
|
// Anyway, It is useless now.
|
||||||
|
// My hope is the FastAverageColor, but
|
||||||
|
// we may need better tool to manage the performance impact
|
||||||
|
// before using this. See #37.
|
||||||
|
// TODO: use fast average color to extract accent color
|
||||||
|
const accentColor = item.meta?.colors?.accent;
|
||||||
|
|
||||||
|
return Object.assign(
|
||||||
|
{
|
||||||
|
width: `${width}px`,
|
||||||
|
height: `${height}px`,
|
||||||
|
},
|
||||||
|
accentColor ? { "--media-color-accent": accentColor } : {},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
css`
|
css`
|
||||||
.attachments {
|
.attachments {
|
||||||
column-count: ${columnCount().toString()};
|
column-count: ${columnCount().toString()};
|
||||||
|
@ -118,68 +144,48 @@ const MediaAttachmentGrid: Component<{
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<For each={props.attachments}>
|
<Index each={props.attachments}>
|
||||||
{(item, index) => {
|
{(item, index) => {
|
||||||
// I don't know why mastodon does not return this
|
switch (item().type) {
|
||||||
// and the condition for it to return this.
|
|
||||||
// Anyway, It is useless now.
|
|
||||||
// My hope is the FastAverageColor, but
|
|
||||||
// we may need better tool to manage the performance impact
|
|
||||||
// before using this. See #37.
|
|
||||||
// TODO: use fast average color to extract accent color
|
|
||||||
const accentColor = item.meta?.colors?.accent;
|
|
||||||
const { width, height } = item.meta?.small || {};
|
|
||||||
|
|
||||||
const size = () => {
|
|
||||||
return constraintedSize(
|
|
||||||
item.meta?.small || { width: 1, height: 1 },
|
|
||||||
{ width: 2, height: 2 },
|
|
||||||
itemMaxSize(),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
switch (item.type) {
|
|
||||||
case "image":
|
case "image":
|
||||||
return (
|
return (
|
||||||
<img
|
<img
|
||||||
src={item.previewUrl}
|
data-sort={index}
|
||||||
width={width}
|
src={item().previewUrl}
|
||||||
height={height}
|
width={item().meta?.small?.width}
|
||||||
alt={item.description || undefined}
|
height={item().meta?.small?.height}
|
||||||
onClick={[openViewerFor, index()]}
|
alt={item().description || undefined}
|
||||||
|
onClick={[openViewerFor, index]}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
style={Object.assign(
|
style={itemStyle(item())}
|
||||||
{
|
|
||||||
width: `${size().width}px`,
|
|
||||||
height: `${size().height}px`,
|
|
||||||
},
|
|
||||||
accentColor ? { "--media-color-accent": accentColor } : {},
|
|
||||||
)}
|
|
||||||
></img>
|
></img>
|
||||||
);
|
);
|
||||||
case "video":
|
case "video":
|
||||||
return (
|
return (
|
||||||
<video
|
<video
|
||||||
src={item.url || undefined}
|
data-sort={index}
|
||||||
|
src={item().url || undefined}
|
||||||
autoplay={settings().autoPlayVideos}
|
autoplay={settings().autoPlayVideos}
|
||||||
playsinline={settings().autoPlayVideos ? true : undefined}
|
playsinline={settings().autoPlayVideos ? true : undefined}
|
||||||
controls
|
controls
|
||||||
poster={item.previewUrl}
|
poster={item().previewUrl}
|
||||||
width={width}
|
width={item().meta?.small?.width}
|
||||||
height={height}
|
height={item().meta?.small?.height}
|
||||||
|
style={itemStyle(item())}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case "gifv":
|
case "gifv":
|
||||||
return (
|
return (
|
||||||
<video
|
<video
|
||||||
src={item.url || undefined}
|
src={item().url || undefined}
|
||||||
autoplay={settings().autoPlayGIFs}
|
autoplay={settings().autoPlayGIFs}
|
||||||
controls
|
controls
|
||||||
playsinline /* or safari on iOS will play in full-screen */
|
playsinline /* or safari on iOS will play in full-screen */
|
||||||
loop
|
loop
|
||||||
poster={item.previewUrl}
|
poster={item().previewUrl}
|
||||||
width={width}
|
width={item().meta?.small?.width}
|
||||||
height={height}
|
height={item().meta?.small?.height}
|
||||||
|
style={itemStyle(item())}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -188,7 +194,7 @@ const MediaAttachmentGrid: Component<{
|
||||||
return <div></div>;
|
return <div></div>;
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
</For>
|
</Index>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue