chore: update formatting

This commit is contained in:
Eana Hufwe 2024-07-30 23:32:52 +00:00 committed by GitHub
parent bf28e75dac
commit f0337595f6
21 changed files with 148 additions and 99 deletions

View file

@ -36,24 +36,35 @@ function setPosition() {
const rootRect = props.rootElement.getBoundingClientRect(); const rootRect = props.rootElement.getBoundingClientRect();
const rect = props.targetElement.getBoundingClientRect(); const rect = props.targetElement.getBoundingClientRect();
const isRtl = getComputedStyle(props.rootElement).direction === "rtl"; const isRtl = getComputedStyle(props.rootElement).direction === "rtl";
const writingMode = getComputedStyle(props.rootElement)['writing-mode']; const writingMode = getComputedStyle(props.rootElement)["writing-mode"];
const isVertical = writingMode.startsWith("vertical"); const isVertical = writingMode.startsWith("vertical");
const targetInlineSize = isVertical ? props.targetElement.offsetHeight : props.targetElement.offsetWidth; const targetInlineSize = isVertical
? props.targetElement.offsetHeight
: props.targetElement.offsetWidth;
const rectInlineSize = isVertical ? rect.height : rect.width; const rectInlineSize = isVertical ? rect.height : rect.width;
const windowInlineSize = isVertical ? window.innerHeight : window.innerWidth; const windowInlineSize = isVertical ? window.innerHeight : window.innerWidth;
const rootInsetInlineStart = const rootInsetInlineStart =
isRtl && isVertical ? rootRect.bottom : isRtl && isVertical
!isRtl && isVertical ? rootRect.top : ? rootRect.bottom
isRtl && !isVertical ? rootRect.right : : !isRtl && isVertical
rootRect.left; ? rootRect.top
: isRtl && !isVertical
? rootRect.right
: rootRect.left;
const rectInsetInlineStart = const rectInsetInlineStart =
isRtl && isVertical ? rect.bottom : isRtl && isVertical
!isRtl && isVertical ? rect.top : ? rect.bottom
isRtl && !isVertical ? rect.right : : !isRtl && isVertical
rect.left; ? rect.top
: isRtl && !isVertical
? rect.right
: rect.left;
let insetInlineStart = targetInlineSize; let insetInlineStart = targetInlineSize;
if (rootInsetInlineStart + insetInlineStart > windowInlineSize - rectInlineSize) { if (
rootInsetInlineStart + insetInlineStart >
windowInlineSize - rectInlineSize
) {
insetInlineStart = -rectInlineSize; insetInlineStart = -rectInlineSize;
} }
if (rectInsetInlineStart + insetInlineStart < 0) { if (rectInsetInlineStart + insetInlineStart < 0) {
@ -61,10 +72,13 @@ function setPosition() {
} }
const insetBlockStart = const insetBlockStart =
writingMode === "vertical-rl" ? rootRect.right - rect.right - 8: writingMode === "vertical-rl"
writingMode === "vertical-lr" ? rootRect.left - rect.left - 8 : ? rootRect.right - rect.right - 8
writingMode === "horizontal-bt" ? rect.right - rootRect.right - 8 : : writingMode === "vertical-lr"
rect.top - rootRect.top - 8; ? rootRect.left - rect.left - 8
: writingMode === "horizontal-bt"
? rect.right - rootRect.right - 8
: rect.top - rootRect.top - 8;
el.value!.style.insetInlineStart = `${insetInlineStart}px`; el.value!.style.insetInlineStart = `${insetInlineStart}px`;
el.value!.style.insetBlockStart = `${insetBlockStart}px`; el.value!.style.insetBlockStart = `${insetBlockStart}px`;
} }

View file

@ -221,7 +221,11 @@ function onBgClick() {
if (type.value === "drawer") { if (type.value === "drawer") {
maxHeight.value = window.innerHeight / 1.5; maxHeight.value = window.innerHeight / 1.5;
if (getComputedStyle(document.documentElement)["writing-mode"].startsWith("vertical")) { if (
getComputedStyle(document.documentElement)["writing-mode"].startsWith(
"vertical",
)
) {
maxHeight.value = window.innerHeight / 1.5; maxHeight.value = window.innerHeight / 1.5;
} }
} }
@ -254,7 +258,7 @@ const align = () => {
const styles = getComputedStyle(props.src); const styles = getComputedStyle(props.src);
const direction = styles.direction; const direction = styles.direction;
const writingMode = styles['writing-mode']; const writingMode = styles["writing-mode"];
if (direction === "rtl") { if (direction === "rtl") {
if (anchorX === "right") { if (anchorX === "right") {
@ -268,27 +272,27 @@ const align = () => {
const prevAnchorX = anchorX; const prevAnchorX = anchorX;
const prevAnchorY = anchorY; const prevAnchorY = anchorY;
if (prevAnchorX === "left") { if (prevAnchorX === "left") {
anchorY = "top" anchorY = "top";
} else if (prevAnchorX === "right") { } else if (prevAnchorX === "right") {
anchorY = "bottom" anchorY = "bottom";
} else if (prevAnchorX === "center") { } else if (prevAnchorX === "center") {
anchorY = "top" anchorY = "top";
} }
if (writingMode === "vertical-rl") { if (writingMode === "vertical-rl") {
if (prevAnchorY === "top") { if (prevAnchorY === "top") {
anchorX = "right" anchorX = "right";
} else if (prevAnchorY === "bottom") { } else if (prevAnchorY === "bottom") {
anchorX = "left" anchorX = "left";
} else if (prevAnchorY === "center") { } else if (prevAnchorY === "center") {
anchorX = "center" anchorX = "center";
} }
} else if (writingMode === "vertical-lr") { } else if (writingMode === "vertical-lr") {
if (prevAnchorY === "top") { if (prevAnchorY === "top") {
anchorX = "left" anchorX = "left";
} else if (prevAnchorY === "bottom") { } else if (prevAnchorY === "bottom") {
anchorX = "right" anchorX = "right";
} else if (prevAnchorY === "center") { } else if (prevAnchorY === "center") {
anchorX = "center" anchorX = "center";
} }
} }
} }
@ -313,18 +317,24 @@ const align = () => {
const windowBlockSize = isVertical ? window.innerWidth : window.innerHeight; const windowBlockSize = isVertical ? window.innerWidth : window.innerHeight;
const windowScrollBlock = isVertical ? window.scrollX : window.scrollY; const windowScrollBlock = isVertical ? window.scrollX : window.scrollY;
const insetBlockStart = const insetBlockStart =
writingMode === "vertical-rl" ? windowBlockSize - left - width : writingMode === "vertical-rl"
writingMode === "vertical-lr" ? left : ? windowBlockSize - left - width
top; : writingMode === "vertical-lr"
? left
: top;
const insetBlockEnd = const insetBlockEnd =
writingMode === "vertical-rl" ? windowBlockSize - left : writingMode === "vertical-rl"
writingMode === "vertical-lr" ? left + width : ? windowBlockSize - left
top + height; : writingMode === "vertical-lr"
? left + width
: top + height;
const blockSize = isVertical ? width : height; const blockSize = isVertical ? width : height;
const srcRectBlockStart = const srcRectBlockStart =
writingMode === "vertical-rl" ? srcRect.right : writingMode === "vertical-rl"
writingMode === "vertical-lr" ? srcRect.left : ? srcRect.right
srcRect.top; : writingMode === "vertical-lr"
? srcRect.left
: srcRect.top;
if (fixed.value) { if (fixed.value) {
// //
@ -349,7 +359,10 @@ const align = () => {
const blockEndSpace = windowBlockSize - MARGIN - insetBlockStart; const blockEndSpace = windowBlockSize - MARGIN - insetBlockStart;
const blockStartSpace = srcRectBlockStart - MARGIN; const blockStartSpace = srcRectBlockStart - MARGIN;
if (insetBlockEnd > windowBlockSize - MARGIN || blockSize > windowBlockSize - MARGIN) { if (
insetBlockEnd > windowBlockSize - MARGIN ||
blockSize > windowBlockSize - MARGIN
) {
if (props.noOverlap) { if (props.noOverlap) {
if (blockEndSpace >= blockStartSpace / 3) { if (blockEndSpace >= blockStartSpace / 3) {
maxHeight.value = blockEndSpace; maxHeight.value = blockEndSpace;
@ -378,8 +391,8 @@ const align = () => {
} }
} }
const blockEndSpace =
const blockEndSpace =windowBlockSize - MARGIN - (insetBlockStart - windowScrollBlock); windowBlockSize - MARGIN - (insetBlockStart - windowScrollBlock);
const blockStartSpace = srcRectBlockStart - MARGIN; const blockStartSpace = srcRectBlockStart - MARGIN;
// //
@ -400,7 +413,10 @@ const align = () => {
top = MARGIN; top = MARGIN;
} }
if (left > window.innerWidth - width - MARGIN && writingMode !== "vertical-lr") { if (
left > window.innerWidth - width - MARGIN &&
writingMode !== "vertical-lr"
) {
left = window.innerWidth - width - MARGIN; left = window.innerWidth - width - MARGIN;
} }
if (left < 0 && writingMode !== "vertical-rl") { if (left < 0 && writingMode !== "vertical-rl") {

View file

@ -60,7 +60,7 @@ function setPosition() {
direction = "right"; direction = "right";
} }
} }
if (getComputedStyle(el.value!)['writing-mode'].startsWith("vertical")) { if (getComputedStyle(el.value!)["writing-mode"].startsWith("vertical")) {
if (direction === "top") { if (direction === "top") {
direction = "right"; direction = "right";
} else if (direction === "bottom") { } else if (direction === "bottom") {

View file

@ -189,7 +189,11 @@ function show(_ev: MouseEvent) {
scanOptions(options); scanOptions(options);
os.popupMenu(menu, container.value!, { os.popupMenu(menu, container.value!, {
width: getComputedStyle(container.value!)['writing-mode'].startsWith('vertical') ? container.value!.offsetHeight : container.value!.offsetWidth, width: getComputedStyle(container.value!)["writing-mode"].startsWith(
"vertical",
)
? container.value!.offsetHeight
: container.value!.offsetWidth,
// onClosing: () => { // onClosing: () => {
// opening.value = false; // opening.value = false;
// }, // },

View file

@ -270,23 +270,28 @@ onMounted(() => {
if (!isTabs(props.tabs)) return; if (!isTabs(props.tabs)) return;
const tabEl = tabRefs[props.tab]; const tabEl = tabRefs[props.tab];
if (tabEl && tabHighlightEl.value) { if (tabEl && tabHighlightEl.value) {
const isVertical = getComputedStyle(tabHighlightEl.value)['writing-mode'].startsWith("vertical"); const isVertical = getComputedStyle(tabHighlightEl.value)[
"writing-mode"
].startsWith("vertical");
// offsetWidth offsetLeft getBoundingClientRect 使 // offsetWidth offsetLeft getBoundingClientRect 使
// https://developer.mozilla.org/ja/docs/Web/API/HTMLElement/offsetWidth#%E5%80%A4 // https://developer.mozilla.org/ja/docs/Web/API/HTMLElement/offsetWidth#%E5%80%A4
const tabSizeX = (isVertical ? tabEl.scrollHeight : tabEl.scrollWidth) + 20; // + the tab's padding const tabSizeX =
(isVertical ? tabEl.scrollHeight : tabEl.scrollWidth) + 20; // + the tab's padding
if (props.tabs.length > 3) { if (props.tabs.length > 3) {
tabEl.style = `--width: ${tabSizeX}px`; tabEl.style = `--width: ${tabSizeX}px`;
} }
setTimeout(() => { setTimeout(() => {
if (tabHighlightEl.value == null) return; if (tabHighlightEl.value == null) return;
let translateFunction = 'translateX'; let translateFunction = "translateX";
let translateValue = tabEl.offsetLeft; let translateValue = tabEl.offsetLeft;
if (isVertical) { if (isVertical) {
translateFunction = 'translateY'; translateFunction = "translateY";
translateValue = tabEl.offsetTop; translateValue = tabEl.offsetTop;
} }
if (getComputedStyle(tabHighlightEl.value).direction === "rtl") { if (getComputedStyle(tabHighlightEl.value).direction === "rtl") {
translateValue += isVertical ? tabEl.offsetHeight - tabEl.offsetParent.scrollHeight : tabEl.offsetWidth - tabEl.offsetParent.scrollWidth; translateValue += isVertical
? tabEl.offsetHeight - tabEl.offsetParent.scrollHeight
: tabEl.offsetWidth - tabEl.offsetParent.scrollWidth;
} }
tabHighlightEl.value.style.inlineSize = `${tabSizeX}px`; tabHighlightEl.value.style.inlineSize = `${tabSizeX}px`;
tabHighlightEl.value.style.transform = `${translateFunction}(${translateValue}px)`; tabHighlightEl.value.style.transform = `${translateFunction}(${translateValue}px)`;

View file

@ -302,9 +302,9 @@ function setSwiperRef(swiper: SwiperType) {
swiperRef = swiper; swiperRef = swiper;
syncSlide(tabs.indexOf(tab.value)); syncSlide(tabs.indexOf(tab.value));
const styles = getComputedStyle(swiper.el); const styles = getComputedStyle(swiper.el);
swiper.changeLanguageDirection(styles.direction as ("rtl" | "ltr")); swiper.changeLanguageDirection(styles.direction as "rtl" | "ltr");
if (styles['writing-mode'].startsWith('vertical')) { if (styles["writing-mode"].startsWith("vertical")) {
swiper.changeDirection('vertical'); swiper.changeDirection("vertical");
} }
} }

View file

@ -265,9 +265,9 @@ function setSwiperRef(swiper) {
swiperRef = swiper; swiperRef = swiper;
syncSlide(tabs.indexOf(tab.value)); syncSlide(tabs.indexOf(tab.value));
const styles = getComputedStyle(swiper.el); const styles = getComputedStyle(swiper.el);
swiper.changeLanguageDirection(styles.direction as ("rtl" | "ltr")); swiper.changeLanguageDirection(styles.direction as "rtl" | "ltr");
if (styles['writing-mode'].startsWith('vertical')) { if (styles["writing-mode"].startsWith("vertical")) {
swiper.changeDirection('vertical'); swiper.changeDirection("vertical");
} }
} }

View file

@ -173,19 +173,24 @@ onMounted(() => {
const rect = tabEl.getBoundingClientRect(); const rect = tabEl.getBoundingClientRect();
var inlineSize = rect.width; var inlineSize = rect.width;
var insetInlineStart = rect.left - parentRect.left; var insetInlineStart = rect.left - parentRect.left;
const isVertical = getComputedStyle(tabHighlightEl.value)['writing-mode'].startsWith("vertical"); const isVertical = getComputedStyle(tabHighlightEl.value)[
"writing-mode"
].startsWith("vertical");
if (isVertical) { if (isVertical) {
inlineSize = rect.height; inlineSize = rect.height;
} }
if (getComputedStyle(tabHighlightEl.value).direction === "rtl") { if (getComputedStyle(tabHighlightEl.value).direction === "rtl") {
if (isVertical) { if (isVertical) {
tabHighlightEl.value.style.insetBlockEnd = rect.bottom - parentRect.bottom + "px"; tabHighlightEl.value.style.insetBlockEnd =
rect.bottom - parentRect.bottom + "px";
} else { } else {
tabHighlightEl.value.style.insetInlineEnd = rect.right - parentRect.right + "px"; tabHighlightEl.value.style.insetInlineEnd =
rect.right - parentRect.right + "px";
} }
} else { } else {
if (isVertical) { if (isVertical) {
tabHighlightEl.value.style.insetBlockStart = rect.top - parentRect.top + "px"; tabHighlightEl.value.style.insetBlockStart =
rect.top - parentRect.top + "px";
} }
} }
tabHighlightEl.value.style.inlineSize = inlineSize + "px"; tabHighlightEl.value.style.inlineSize = inlineSize + "px";

View file

@ -223,9 +223,9 @@ function setSwiperRef(swiper: SwiperType) {
swiperRef = swiper; swiperRef = swiper;
syncSlide(tabs.indexOf(tab.value)); syncSlide(tabs.indexOf(tab.value));
const styles = getComputedStyle(swiper.el); const styles = getComputedStyle(swiper.el);
swiper.changeLanguageDirection(styles.direction as ("rtl" | "ltr")); swiper.changeLanguageDirection(styles.direction as "rtl" | "ltr");
if (styles['writing-mode'].startsWith('vertical')) { if (styles["writing-mode"].startsWith("vertical")) {
swiper.changeDirection('vertical'); swiper.changeDirection("vertical");
} }
} }

View file

@ -82,9 +82,9 @@ function setSwiperRef(swiper) {
swiperRef = swiper; swiperRef = swiper;
syncSlide(tabs.indexOf(tab.value)); syncSlide(tabs.indexOf(tab.value));
const styles = getComputedStyle(swiper.el); const styles = getComputedStyle(swiper.el);
swiper.changeLanguageDirection(styles.direction as ("rtl" | "ltr")); swiper.changeLanguageDirection(styles.direction as "rtl" | "ltr");
if (styles['writing-mode'].startsWith('vertical')) { if (styles["writing-mode"].startsWith("vertical")) {
swiper.changeDirection('vertical'); swiper.changeDirection("vertical");
} }
} }

View file

@ -196,9 +196,9 @@ function setSwiperRef(swiper) {
swiperRef = swiper; swiperRef = swiper;
syncSlide(tabs.indexOf(tab.value)); syncSlide(tabs.indexOf(tab.value));
const styles = getComputedStyle(swiper.el); const styles = getComputedStyle(swiper.el);
swiper.changeLanguageDirection(styles.direction as ("rtl" | "ltr")); swiper.changeLanguageDirection(styles.direction as "rtl" | "ltr");
if (styles['writing-mode'].startsWith('vertical')) { if (styles["writing-mode"].startsWith("vertical")) {
swiper.changeDirection('vertical'); swiper.changeDirection("vertical");
} }
} }

View file

@ -437,9 +437,9 @@ function setSwiperRef(swiper) {
swiperRef = swiper; swiperRef = swiper;
syncSlide(tabs.indexOf(tab.value)); syncSlide(tabs.indexOf(tab.value));
const styles = getComputedStyle(swiper.el); const styles = getComputedStyle(swiper.el);
swiper.changeLanguageDirection(styles.direction as ("rtl" | "ltr")); swiper.changeLanguageDirection(styles.direction as "rtl" | "ltr");
if (styles['writing-mode'].startsWith('vertical')) { if (styles["writing-mode"].startsWith("vertical")) {
swiper.changeDirection('vertical'); swiper.changeDirection("vertical");
} }
} }

View file

@ -242,9 +242,9 @@ function setSwiperRef(swiper) {
swiperRef = swiper; swiperRef = swiper;
syncSlide(tabs.indexOf(tab.value)); syncSlide(tabs.indexOf(tab.value));
const styles = getComputedStyle(swiper.el); const styles = getComputedStyle(swiper.el);
swiper.changeLanguageDirection(styles.direction as ("rtl" | "ltr")); swiper.changeLanguageDirection(styles.direction as "rtl" | "ltr");
if (styles['writing-mode'].startsWith('vertical')) { if (styles["writing-mode"].startsWith("vertical")) {
swiper.changeDirection('vertical'); swiper.changeDirection("vertical");
} }
} }

View file

@ -180,9 +180,9 @@ function setSwiperRef(swiper: SwiperType) {
swiperRef = swiper; swiperRef = swiper;
syncSlide(tabs.indexOf(tab.value)); syncSlide(tabs.indexOf(tab.value));
const styles = getComputedStyle(swiper.el); const styles = getComputedStyle(swiper.el);
swiper.changeLanguageDirection(styles.direction as ("rtl" | "ltr")); swiper.changeLanguageDirection(styles.direction as "rtl" | "ltr");
if (styles['writing-mode'].startsWith('vertical')) { if (styles["writing-mode"].startsWith("vertical")) {
swiper.changeDirection('vertical'); swiper.changeDirection("vertical");
} }
} }

View file

@ -157,9 +157,9 @@ function setSwiperRef(swiper) {
swiperRef = swiper; swiperRef = swiper;
syncSlide(tabs.indexOf(tab.value)); syncSlide(tabs.indexOf(tab.value));
const styles = getComputedStyle(swiper.el); const styles = getComputedStyle(swiper.el);
swiper.changeLanguageDirection(styles.direction as ("rtl" | "ltr")); swiper.changeLanguageDirection(styles.direction as "rtl" | "ltr");
if (styles['writing-mode'].startsWith('vertical')) { if (styles["writing-mode"].startsWith("vertical")) {
swiper.changeDirection('vertical'); swiper.changeDirection("vertical");
} }
} }

View file

@ -141,9 +141,9 @@ function setSwiperRef(swiper) {
swiperRef = swiper; swiperRef = swiper;
syncSlide(tabs.indexOf(tab.value)); syncSlide(tabs.indexOf(tab.value));
const styles = getComputedStyle(swiper.el); const styles = getComputedStyle(swiper.el);
swiper.changeLanguageDirection(styles.direction as ("rtl" | "ltr")); swiper.changeLanguageDirection(styles.direction as "rtl" | "ltr");
if (styles['writing-mode'].startsWith('vertical')) { if (styles["writing-mode"].startsWith("vertical")) {
swiper.changeDirection('vertical'); swiper.changeDirection("vertical");
} }
} }

View file

@ -454,9 +454,7 @@ const mergeThreadInTimeline = computed(
const mergeRenotesInTimeline = computed( const mergeRenotesInTimeline = computed(
defaultStore.makeGetterSetter("mergeRenotesInTimeline"), defaultStore.makeGetterSetter("mergeRenotesInTimeline"),
); );
const writingMode = computed( const writingMode = computed(defaultStore.makeGetterSetter("writingMode"));
defaultStore.makeGetterSetter("writingMode"),
);
// This feature (along with injectPromo) is currently disabled // This feature (along with injectPromo) is currently disabled
// function onChangeInjectFeaturedNote(v) { // function onChangeInjectFeaturedNote(v) {
@ -528,7 +526,7 @@ watch(
useEmojiCdn, useEmojiCdn,
enableTimelineStreaming, enableTimelineStreaming,
enablePullToRefresh, enablePullToRefresh,
pullToRefreshThreshold pullToRefreshThreshold,
], ],
async () => { async () => {
await reloadAsk(); await reloadAsk();

View file

@ -99,9 +99,9 @@ function setSwiperRef(swiper) {
swiperRef = swiper; swiperRef = swiper;
syncSlide(tabs.indexOf(tab.value)); syncSlide(tabs.indexOf(tab.value));
const styles = getComputedStyle(swiper.el); const styles = getComputedStyle(swiper.el);
swiper.changeLanguageDirection(styles.direction as ("rtl" | "ltr")); swiper.changeLanguageDirection(styles.direction as "rtl" | "ltr");
if (styles['writing-mode'].startsWith('vertical')) { if (styles["writing-mode"].startsWith("vertical")) {
swiper.changeDirection('vertical'); swiper.changeDirection("vertical");
} }
} }

View file

@ -310,9 +310,9 @@ function setSwiperRef(swiper) {
swiperRef = swiper; swiperRef = swiper;
syncSlide(timelineIndex(src.value)); syncSlide(timelineIndex(src.value));
const styles = getComputedStyle(swiper.el); const styles = getComputedStyle(swiper.el);
swiper.changeLanguageDirection(styles.direction as ("rtl" | "ltr")); swiper.changeLanguageDirection(styles.direction as "rtl" | "ltr");
if (styles['writing-mode'].startsWith('vertical')) { if (styles["writing-mode"].startsWith("vertical")) {
swiper.changeDirection('vertical'); swiper.changeDirection("vertical");
} }
} }

View file

@ -471,8 +471,13 @@ export const defaultStore = markRaw(
}, },
writingMode: { writingMode: {
where: "deviceAccount", where: "deviceAccount",
default: "horizontal-tb" as "horizontal-tb" | "vertical-rl" | "vertical-lr" | "vertical-rl-upright" | "vertical-lr-upright", default: "horizontal-tb" as
} | "horizontal-tb"
| "vertical-rl"
| "vertical-lr"
| "vertical-rl-upright"
| "vertical-lr-upright",
},
}), }),
); );

View file

@ -394,7 +394,9 @@ async function startGroup(): void {
onMounted(() => { onMounted(() => {
if (!isDesktop.value) { if (!isDesktop.value) {
matchMedia(`(min-inline-size: ${DESKTOP_THRESHOLD - 1}px)`).onchange = (mql) => { matchMedia(`(min-inline-size: ${DESKTOP_THRESHOLD - 1}px)`).onchange = (
mql,
) => {
if (mql.matches) isDesktop.value = true; if (mql.matches) isDesktop.value = true;
}; };
} }