Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rework two-color-word effect & implement blinking 重作雙色字效果與實作閃爍 #102

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

IepIweidieng
Copy link
Contributor

@IepIweidieng IepIweidieng commented Dec 13, 2021

Instead of overlaying a half of the two-color-word character, the two-color-word effect is now achieved by using two half-word pseudo elements (enabled by CSS class .o):
不再透過覆蓋雙色字的半側達成,現在雙色字已改爲透過使用兩個半型寬度的僞元素(用 CSS class .o 啟用)達成:

  • One for the left half (::before; controlled by non-prefixed CSS classes) and
    一個給左半(::before,用無前綴的 CSS classes 控制);
  • One for the right half (::after; controlled by CSS classes prefixed with 'r'),
    一個給右半(::after,用有 r 前綴的 CSS classes 控制)。

so that the two halves of the word can be controlled independently.
故全形字的兩半側可被獨立控制。

Additionally, to make the text selection appear normal, the real element is made invisible and placed on top of the pseudo elements.
此外,爲了使文字選擇看起來正常,眞實元素被弄得看不到且置在僞元素上。

This greatly reduces the number of CSS classes needed.
這大大地減少了所需的 CSS classes 數量。

See Ptt-official-app/pttbbs-web#122 for an explanation of a similar implementation.
Ptt-official-app/pttbbs-web#122 的對類似實作的說明。

The blink effect for two-color-word characters is also implemented.
雙色字的閃爍效果也被實作了。

The background color was dependent on both .b<bg> and .qq<bg> classes, which complicated the TwoColorWord blinking implementation.
原本背景的顏色同時取決於 .b<背景色>.qq<背景色> classes,複雜化了 TwoColorWord 的閃爍實作。

Therefore, the .qq<bg> classes are removed, while only the .qq class is left since it does not affect the background color.
因此 .qq<背景色> classes 已移除,而僅留下不影響背景色的 .qq class。

Since the color of two-color-word characters is now transparent, the color of hovered hyperlinks is now explicitly assigned as the color of q7 to prevent the link text with the two-color-word effect from being invisible.
由於現在雙色字的顏色是透明的,被游標指著的超鏈結的顏色現在已顯式指定爲 q7 的顏色,以避免看不到具雙色字效果的鏈結文字。

This supersedes #86.
取代 #86

Fixes 修正

This also fixes the issue that black bg on the right half of two-color characters may not be black.
也修正了雙色字右半的黑背景不黑的問題。

This issue was described in commit a75d550.
此問題已先爲 commit a75d550 所述。

This issue was caused by the HTML layout of two-color chars, e.g.:
此問題由雙色字的 HTML 排版導致,範例:

<span class="q15 b1">
    <span class="q15 b1 rb0 wpadding" data-text="" style="display: inline-block; width: 24px;"></span></span>

The "black" part of the background of the inner span is actually transparent, but the outer span has its own background (of the bg color of the left-half char), thus the "black" part of the inner span appeared to be not black.
內層 span 的背景的「黑色」部份實際上是透明的,但外層 span 有自己的背景(帶有左半雙色字的背景顏色),故內層 span 的「黑色」部份看起來並不黑。

To fix this issue, WordSegmentBuilder is specialized for two-color chars (as JavaScript class TwoColorWordBuilder) so as to instead generate such layout as:
爲了解決這個問題,WordSegmentBuilder 已對雙色字特例化(爲 JavaScript 類型 TwoColorWordBuilder)來把前述的排版改產生爲:

<span class="q15 b1 rb0 wpadding" data-text="" style="display: inline-block; width: 24px;"></span>
<span class="q15 b1"></span>

This not only avoids the unwanted background color introduced by the outer span but also eliminates the unnecessary outer span for a sole two-color char.
這不僅避免了外層 span 所導致的不想要的背景顏色,也消除了單獨出現的雙色字的不必要的外層 span。

Note that this requires the forementioned fix to TwoColorWord.js to make the un-nested span rendered expectedly. See the commit message for details.
注意這需要對 TwoColorWord.js 進行前述的修正以讓未經多層套置的 span 按預期彩現。詳見 commit 訊息。

This supersedes #101.
取代 #101

Test case

測試案例

The text of the test case is the same as #101.
測試案例的文字與 #101 中的相同。

Current behavior 目前行爲

(This is a still image 此爲靜止畫面)
image

Expected behavior 預期行爲

This screenshot is the new behavior with the corresponding fix of #101.
此畫面擷取中的是已經套用了對應 #101 的修正的新的行爲。

PttChrome 2023-01-15 TwoColorWord reimpl SampleText after

Sample text 範例文字

@IepIweidieng IepIweidieng changed the title feat(components/TwoColorWord): reimplement two-color-word effect feat(components/): reimplement two-color-word effect Dec 13, 2021
@IepIweidieng IepIweidieng changed the title feat(components/): reimplement two-color-word effect feat: reimplement two-color-word effect Dec 13, 2021
@IepIweidieng IepIweidieng changed the title feat: reimplement two-color-word effect feat: rework two-color-word effect & implement blinking Dec 13, 2021
Instead of overlaying a half of the two-color-word character,
the two-color-word effect is now achieved
by using two half-word pseudo elements (enabled by CSS class .o),
one for the left half (::before; controlled by non-prefixed CSS classes)
and one for the right half (::after; controlled by CSS classes prefixed with 'r'),
so that the two halves of the word can be controlled independently.

Additionally, to make the text selection appear normal,
the real element is made invisible and placed on top of the pseudo elements.

This greatly reduces the number of CSS classes needed.

See Ptt-official-app/pttbbs-web#122
for an explanation of a similar implementation.

The blink effect for two-color-word characters is also implemented.

The background color was dependent on both .b<bg> and .qq<bg> classes,
which complicated the TwoColorWord blinking implementation.

Therefore, the .qq<bg> classes are removed,
while only the .qq class is left since it does not affect the background color.

Since the color of two-color-word characters is now transparent,
the color of hovered hyperlinks is now explicitly assigned as the color of q7
to prevent the link text with the two-color-word effect from being invisible.
@IepIweidieng IepIweidieng changed the title feat: rework two-color-word effect & implement blinking feat: rework two-color-word effect & implement blinking 重作雙色字效果與實作閃爍 Dec 9, 2022
…visual effects

This issue was described in commit a75d550
("Fix two-color character rendering bug when the right-half is black.").

This issue was caused by the HTML layout of two-color chars, e.g.:

```html
<span class="q15 b1"> <!-- Non-black BG. -->
    <span class="q15 b1 rb0 wpadding" data-text="A" style="display: inline-block; width: 24px;">
        A
    </span> <!-- "Black" (transparent) right-half BG., appeared as non-black -->
    M
</span>
```

To fix this issue, WordSegmentBuilder is specialized for two-color chars
(as JavaScript class TwoColorWordBuilder)
so as to instead generate such layout as:

```html
<span class="q15 b1 rb0 wpadding" data-text="A" style="display: inline-block; width: 24px;">
    A
</span>
<span class="q15 b1">
    M
</span>
```

This not only avoids the unwanted background color introduced by the outer span
but also eliminates the unnecessary outer span for a sole two-color char.

Note that this requires the fix introduced in commit d6ebaab
("feat: rework two-color-word effect & implement blinking")
to make the un-nested span rendered expectedly.
@IepIweidieng IepIweidieng changed the title feat: rework two-color-word effect & implement blinking 重作雙色字效果與實作閃爍 fix: rework two-color-word effect & implement blinking 重作雙色字效果與實作閃爍 Jan 15, 2023
IepIweidieng added a commit to Ptt-official-app/pttbbs-web that referenced this pull request Mar 20, 2024
See robertabcd/PttChrome#102 for references.

* src/components/cells/Rune.tsx
    * drop the use of CSS class .halves-group
    * use react.Fragment (`<> </>`) to replace the previous outer `<span>`
    * make classNamesGroup (for styling the previous outer `<span>`)
      appended to classNames0 (for styling each two-color char)
* src/components/cells/ContentRenderer.module.css
    * drop CSS class .halves-group
    * replace .halves styling with .o styling from the PttChrome PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant