diff options
author | Mike L <cl.jeremy@qq.com> | 2021-03-19 00:43:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-19 00:43:43 +0100 |
commit | 0e5c6c4498f26982c8884030abfbc197e34b5f52 (patch) | |
tree | 6bd8aa21fc4eb26509330c25e853c39ac73d9501 /web_src/js | |
parent | c0c052bdbbb03319e63e9a3fc686e4bc3401e926 (diff) | |
download | gitea-0e5c6c4498f26982c8884030abfbc197e34b5f52.tar.gz gitea-0e5c6c4498f26982c8884030abfbc197e34b5f52.zip |
Fix CJK fonts again and misc. font issues (#14575)
* Push system-ui further down the stack, fix #12966
* Fix Firefox showing U+300x in emoji font and more
* Revert emoji font and fix long-standing Safari bug
* Exclude Safari emoji fix above 1.25x zoom
* Minor correctness/typo fix, affects only legacy platforms
* Emoji consistency for monospace (e.g. EasyMDE)
* Override paradigm; macOS/iOS-specific metric fix
* Move whitespace fix to font-face
* Handle metric calculation errors with Firefox
* One last workaround for aliased fonts in Linux
Diffstat (limited to 'web_src/js')
-rw-r--r-- | web_src/js/index.js | 15 | ||||
-rw-r--r-- | web_src/js/utils.js | 13 |
2 files changed, 27 insertions, 1 deletions
diff --git a/web_src/js/index.js b/web_src/js/index.js index 6c30d14fbb..64f4357329 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -26,7 +26,7 @@ import {initNotificationsTable, initNotificationCount} from './features/notifica import {initStopwatch} from './features/stopwatch.js'; import {createCodeEditor, createMonaco} from './features/codeeditor.js'; import {svg, svgs} from './svg.js'; -import {stripTags} from './utils.js'; +import {stripTags, mqBinarySearch} from './utils.js'; const {AppSubUrl, StaticUrlPrefix, csrf} = window.config; @@ -2519,6 +2519,19 @@ $(document).ready(async () => { .attr('title', ''); }); + // Undo Safari emoji glitch fix at high enough zoom levels + if (navigator.userAgent.match('Safari')) { + $(window).resize(() => { + const px = mqBinarySearch('width', 0, 4096, 1, 'px'); + const em = mqBinarySearch('width', 0, 1024, 0.01, 'em'); + if (em * 16 * 1.25 - px <= -1) { + $('body').addClass('safari-above125'); + } else { + $('body').removeClass('safari-above125'); + } + }); + } + // Semantic UI modules. $('.dropdown:not(.custom)').dropdown({ fullTextSearch: 'exact' diff --git a/web_src/js/utils.js b/web_src/js/utils.js index fc65644c7b..bc84745066 100644 --- a/web_src/js/utils.js +++ b/web_src/js/utils.js @@ -28,3 +28,16 @@ export function uniq(arr) { export function stripTags(text) { return text.replace(/<[^>]*>?/gm, ''); } + +// searches the inclusive range [minValue, maxValue]. +// credits: https://matthiasott.com/notes/write-your-media-queries-in-pixels-not-ems +export function mqBinarySearch(feature, minValue, maxValue, step, unit) { + if (maxValue - minValue < step) { + return minValue; + } + const mid = Math.ceil((minValue + maxValue) / 2 / step) * step; + if (matchMedia(`screen and (min-${feature}:${mid}${unit})`).matches) { + return mqBinarySearch(feature, mid, maxValue, step, unit); // feature is >= mid + } + return mqBinarySearch(feature, minValue, mid - step, step, unit); // feature is < mid +} |