@brillout/docpress 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Layout.tsx CHANGED
@@ -7,7 +7,7 @@ import { EditPageNote } from './components/EditPageNote'
7
7
  import { parseTitle } from './parseTitle'
8
8
  import { usePageContext } from './renderer/usePageContext'
9
9
  import { Links } from './Links'
10
- import { hotkeyMenuOpen, toggleMenuModal } from './MenuModal'
10
+ import { toggleMenuModal } from './MenuModal'
11
11
  import { MenuModal } from './MenuModal'
12
12
  import { autoScrollNav_SSR } from './autoScrollNav'
13
13
  import { SearchLink } from './docsearch/SearchLink'
@@ -28,13 +28,13 @@ const mainViewMax = mainViewWidthMax + mainViewPadding * 2
28
28
  const containerQuerySpacing = mainViewMax + navWidthMax + blockMargin
29
29
  const containerQueryMobile = mainViewMax + navWidthMin
30
30
 
31
- // Avoid blank whitespace at the bottom of the page with almost no content
32
- const blankBuster1: React.CSSProperties = {
31
+ // Avoid whitespace at the bottom of pages with almost no content
32
+ const whitespaceBuster1: React.CSSProperties = {
33
33
  minHeight: '100vh',
34
34
  display: 'flex',
35
35
  flexDirection: 'column',
36
36
  }
37
- const blankBuster2: React.CSSProperties = {
37
+ const whitespaceBuster2: React.CSSProperties = {
38
38
  flexGrow: 1,
39
39
  }
40
40
 
@@ -50,21 +50,26 @@ function Layout({ children }: { children: React.ReactNode }) {
50
50
  }
51
51
 
52
52
  return (
53
- <>
53
+ <div
54
+ style={{
55
+ ['--bg-color']: '#f5f5f7',
56
+ ['--block-margin']: `${blockMargin}px`,
57
+ ['--icon-padding']: '8px',
58
+ }}
59
+ >
60
+ <MenuModal />
54
61
  <div
55
62
  className={isLandingPage ? '' : 'doc-page'}
56
63
  style={{
57
- ['--bg-color']: '#f5f5f7',
58
- ['--block-margin']: `${blockMargin}px`,
59
- ['--icon-padding']: '8px',
60
- ...blankBuster1,
64
+ // We don't add `container` to `body` nor `html` beacuse in Firefox it breaks the `position: fixed` of <MenuModal>
65
+ // https://stackoverflow.com/questions/74601420/css-container-inline-size-and-fixed-child
66
+ containerType: 'inline-size',
67
+ ...whitespaceBuster1,
61
68
  }}
62
69
  >
63
70
  {content}
64
- <MenuModal />
65
71
  </div>
66
- <style>{css`body { container-type: inline-size; }`}</style>
67
- </>
72
+ </div>
68
73
  )
69
74
  }
70
75
 
@@ -75,7 +80,7 @@ function LayoutDocsPage({ children }: { children: React.ReactNode }) {
75
80
  <>
76
81
  <style>{getStyle()}</style>
77
82
  <NavMobile />
78
- <div style={{ display: 'flex', ...blankBuster2 }}>
83
+ <div style={{ display: 'flex', ...whitespaceBuster2 }}>
79
84
  <NavLeft />
80
85
  <div className="low-prio-grow" style={{ width: 0, maxWidth: 50, background: 'var(--bg-color)' }} />
81
86
  <PageContent>{children}</PageContent>
@@ -190,7 +195,7 @@ function PageContent({ children }: { children: React.ReactNode }) {
190
195
  function NavMobile() {
191
196
  return (
192
197
  <div id="nav-mobile">
193
- <NavigationHeader headerHeight={50} headerPadding={10} style={{ justifyContent: 'center' }} />
198
+ <NavigationHeader headerHeight={70} headerPadding={12} style={{ justifyContent: 'center' }} />
194
199
  </div>
195
200
  )
196
201
  }
package/MenuModal.tsx CHANGED
@@ -8,6 +8,9 @@ import { NavigationContent } from './navigation/Navigation'
8
8
  import { css } from './utils/css'
9
9
  import { containerQueryMobile } from './Layout'
10
10
  import { Links } from './Links'
11
+ import { isBrowser } from './utils/isBrowser'
12
+
13
+ initCloseListeners()
11
14
 
12
15
  function MenuModal() {
13
16
  return (
@@ -19,7 +22,14 @@ function MenuModal() {
19
22
  style={{
20
23
  position: 'fixed',
21
24
  width: '100%',
25
+ /* Do this once Firefox supports `dvh`: https://caniuse.com/?search=dvh
26
+ * - Then also replace all `vh` values with `dvh` values.
27
+ * - https://stackoverflow.com/questions/37112218/css3-100vh-not-constant-in-mobile-browser/72245072#72245072
28
+ height: '100dh',
29
+ /*/
22
30
  height: '100vh',
31
+ maxHeight: '100dvh',
32
+ //*/
23
33
  top: 0,
24
34
  left: 0,
25
35
  zIndex: 9999,
@@ -32,8 +42,10 @@ function MenuModal() {
32
42
  // Place <LinksBottom /> to the bottom
33
43
  display: 'flex',
34
44
  flexDirection: 'column',
35
- minHeight: '100vh',
45
+ minHeight: '100dvh',
36
46
  justifyContent: 'space-between',
47
+ // We don't set `container` to parent beacuse of a Chrome bug (showing a blank <MenuModal>)
48
+ containerType: 'inline-size',
37
49
  }}
38
50
  >
39
51
  <Nav />
@@ -136,3 +148,29 @@ function autoScroll() {
136
148
  function closeMenuModal() {
137
149
  document.documentElement.classList.remove('menu-modal-show')
138
150
  }
151
+
152
+ function initCloseListeners() {
153
+ if (!isBrowser()) return
154
+ document.addEventListener('click', onLinkClick)
155
+ // It's redundant (and onLinkClick() is enough), but just to be sure.
156
+ addEventListener('hashchange', closeMenuModal)
157
+ }
158
+ function onLinkClick(ev: MouseEvent) {
159
+ if (ev.altKey || ev.ctrlKey || ev.metaKey || ev.shiftKey) return
160
+ const linkTag = findLinkTag(ev.target as HTMLElement)
161
+ if (!linkTag) return
162
+ const href = linkTag.getAttribute('href')
163
+ if (!href) return
164
+ if (!href.startsWith('/') && !href.startsWith('#')) return
165
+ closeMenuModal()
166
+ }
167
+ function findLinkTag(target: HTMLElement): null | HTMLElement {
168
+ while (target.tagName !== 'A') {
169
+ const { parentNode } = target
170
+ if (!parentNode) {
171
+ return null
172
+ }
173
+ target = parentNode as HTMLElement
174
+ }
175
+ return target
176
+ }
@@ -1,13 +1,12 @@
1
1
  import React from 'react'
2
2
  import { RepoLink } from './RepoLink'
3
- import { Emoji } from '../utils/server'
4
3
 
5
4
  export { EditPageNote }
6
5
 
7
6
  function EditPageNote({ pageContext }: { pageContext: { urlPathname: string } }) {
8
7
  const text = (
9
8
  <>
10
- <Emoji name="writing-hang" /> Edit this page
9
+ <span style={{ fontFamily: 'emoji' }}>✍</span> Edit this page
11
10
  </>
12
11
  )
13
12
  return (
@@ -1,11 +1,22 @@
1
+ /* `@media (pointer: fine)`
2
+ * - Don't show tooltip on mobile devices:
3
+ * - https://stackoverflow.com/questions/23885255/how-to-remove-ignore-hover-css-style-on-touch-devices/64553121#64553121
4
+ */
5
+ @media (hover: hover) and (pointer: fine) {
6
+ .colorize-on-hover:hover [class^='decolorize-'],
7
+ .colorize-on-hover:hover [class*=' decolorize-'] {
8
+ filter: grayscale(0) opacity(1) !important;
9
+ }
10
+ .link-hover-animation a:hover {
11
+ color: black !important;
12
+ background-color: var(--active-color);
13
+ }
14
+ }
15
+
1
16
  .colorize-on-hover [class^='decolorize-'],
2
17
  .colorize-on-hover [class*=' decolorize-'] {
3
18
  transition: filter 0.3s ease-in-out;
4
19
  }
5
- .colorize-on-hover:hover [class^='decolorize-'],
6
- .colorize-on-hover:hover [class*=' decolorize-'] {
7
- filter: grayscale(0) opacity(1) !important;
8
- }
9
20
 
10
21
  .decolorize-7 {
11
22
  filter: grayscale(1) opacity(0.7);
@@ -24,10 +35,6 @@
24
35
  transition: all 0.3s ease-in-out !important;
25
36
  transition-property: color, background-color !important;
26
37
  }
27
- .link-hover-animation a:hover {
28
- color: black !important;
29
- background-color: var(--active-color);
30
- }
31
38
  body {
32
39
  --active-color: rgba(0, 0, 0, 0.03);
33
40
  }
package/css/heading.css CHANGED
@@ -62,10 +62,16 @@ h3 { font-size: 1.25em }
62
62
  padding-left: 26px;
63
63
  margin-left: -26px;
64
64
  }
65
- .doc-page h2[id]:hover::before,
66
- .doc-page h3[id]:hover::before {
67
- content: '#';
68
- position: absolute;
69
- left: calc(-1 * (0.75em - 26px));
70
- color: #aaa;
65
+ /* `@media (pointer: fine)`
66
+ * - Don't show tooltip on mobile devices:
67
+ * - https://stackoverflow.com/questions/23885255/how-to-remove-ignore-hover-css-style-on-touch-devices/64553121#64553121
68
+ */
69
+ @media (hover: hover) and (pointer: fine) {
70
+ .doc-page h2[id]:hover::before,
71
+ .doc-page h3[id]:hover::before {
72
+ content: '#';
73
+ position: absolute;
74
+ left: calc(-1 * (0.75em - 26px));
75
+ color: #aaa;
76
+ }
71
77
  }
package/css/tooltip.css CHANGED
@@ -1,23 +1,29 @@
1
- [aria-label] {
2
- position: relative;
3
- }
4
- [aria-label]:hover::before {
5
- font-family: monospace;
6
- font-size: 12px;
7
- content: attr(aria-label);
8
- position: absolute;
9
- top: 100%;
10
- left: 50%;
11
- transform: translate(-50%, 0);
12
- margin-top: 5px;
13
- background: #fdfdfd;
14
- padding: 3px 10px;
15
- box-shadow: rgb(0 0 0 / 8%) 2px 4px 7px 0px;
16
- border-radius: 5px;
17
- color: #333;
18
- letter-spacing: -0.02em;
19
- border: 1px solid #e3e3e3;
20
- }
21
- [data-label-shift]::before {
22
- margin-left: -10px;
1
+ /* `@media (pointer: fine)`
2
+ * - Don't show tooltip on mobile devices:
3
+ * - https://stackoverflow.com/questions/23885255/how-to-remove-ignore-hover-css-style-on-touch-devices/64553121#64553121
4
+ */
5
+ @media (hover: hover) and (pointer: fine) {
6
+ [aria-label] {
7
+ position: relative;
8
+ }
9
+ [aria-label]:hover::before {
10
+ font-family: monospace;
11
+ font-size: 12px;
12
+ content: attr(aria-label);
13
+ position: absolute;
14
+ top: 100%;
15
+ left: 50%;
16
+ transform: translate(-50%, 0);
17
+ margin-top: 5px;
18
+ background: #fdfdfd;
19
+ padding: 3px 10px;
20
+ box-shadow: rgb(0 0 0 / 8%) 2px 4px 7px 0px;
21
+ border-radius: 5px;
22
+ color: #333;
23
+ letter-spacing: -0.02em;
24
+ border: 1px solid #e3e3e3;
25
+ }
26
+ [data-label-shift]::before {
27
+ margin-left: -10px;
28
+ }
23
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/docpress",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@brillout/picocolors": "^1.0.10",
@@ -52,6 +52,7 @@ function applyHead(pageContext: PageContextClient) {
52
52
  }
53
53
 
54
54
  function onRenderStart() {
55
+ // It's redundant (and onLinkClick() is enough), but just to be sure.
55
56
  closeMenuModal()
56
57
  }
57
58