@brillout/docpress 0.12.5 → 0.13.0

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
@@ -342,7 +342,7 @@ function NavHead({ isNavLeft }: { isNavLeft?: true }) {
342
342
  maxWidth: navMaxWidth,
343
343
  margin: 'auto',
344
344
  height: 'var(--nav-head-height)',
345
- fontSize: `min(16.96px, ${isProjectNameShort(projectName) ? '4.8cqw' : '4.5cqw'})`,
345
+ fontSize: `min(15.2px, ${isProjectNameShort(projectName) ? '4.8cqw' : '4.5cqw'})`,
346
346
  color: '#666',
347
347
  ['--icon-text-padding']: 'min(8px, 1.8cqw)',
348
348
  display: 'flex',
@@ -398,7 +398,7 @@ function NavHead({ isNavLeft }: { isNavLeft?: true }) {
398
398
  }
399
399
  @container container-nav-head (min-width: ${containerQueryMobileNav + 150}px) {
400
400
  .nav-head-content {
401
- --padding-side: 35px;
401
+ --padding-side: 25px;
402
402
  }
403
403
  }
404
404
  @media(max-width: ${containerQueryMobileNav}px) {
@@ -539,7 +539,7 @@ function MenuToggleMain(props: PropsDiv) {
539
539
  </span>
540
540
  <Style>{css`
541
541
  @media(max-width: ${containerQueryMobileNav}px) {
542
- .text-docs {
542
+ .text-docs, .caret-icon {
543
543
  display: none !important;
544
544
  }
545
545
  }
@@ -586,6 +586,14 @@ function MenuToggle({ menuId, ...props }: PropsDiv & { menuId: number }) {
586
586
  >
587
587
  <Style>{getAnimation()}</Style>
588
588
  {props.children}
589
+ <CaretIcon
590
+ style={{
591
+ width: 11,
592
+ marginLeft: 10,
593
+ flexShrink: 0,
594
+ color: '#888',
595
+ }}
596
+ />
589
597
  </div>
590
598
  )
591
599
 
@@ -614,15 +622,53 @@ function MenuToggle({ menuId, ...props }: PropsDiv & { menuId: number }) {
614
622
  transition: top 0.4s ease !important;
615
623
  z-index: -1;
616
624
  }
625
+ & .caret-icon-left,
626
+ & .caret-icon-right {
627
+ transition: transform .4s cubic-bezier(.4,0, .2, 1);
628
+ }
629
+ & .caret-icon-left {
630
+ transform-origin: 25% 50%;
631
+ }
632
+ & .caret-icon-right {
633
+ transform-origin: 75% 50%;
634
+ }
617
635
  }
618
636
  `
619
637
  }
620
638
  }
639
+ function CaretIcon({ style }: { style: React.CSSProperties }) {
640
+ return (
641
+ // - Inspired by stripe.com
642
+ // - Alternative caret SVGs: https://gist.github.com/brillout/dbf05e1fb79a34169cc2d0d5eaf58c01
643
+ // - The rounded caret (`caret.svg`) doesn't look nice when flipped:
644
+ // - https://github.com/brillout/docpress/commit/0ff937d8caf5fc439887ef495e2d2a700234dfb1
645
+ // - https://github.com/brillout/docpress/pull/39
646
+ <svg
647
+ xmlns="http://www.w3.org/2000/svg"
648
+ viewBox="0 0 9.24 5.858"
649
+ style={{
650
+ overflow: 'visible',
651
+ ...style,
652
+ }}
653
+ className="caret-icon"
654
+ >
655
+ <g className="caret-icon-left">
656
+ <path
657
+ fill="currentColor"
658
+ d="m4.001 5.24.619.618 1.237-1.237-.618-.619L4 5.241zm-4-4 4 4L5.24 4.001l-4-4L0 1.241z"
659
+ ></path>
660
+ </g>
661
+ <g className="caret-icon-right">
662
+ <path fill="currentColor" d="m5.239 5.239-.619.618L3.383 4.62l.618-.619L5.24 5.24Zm4-4-4 4L4 4l4-4z"></path>
663
+ </g>
664
+ </svg>
665
+ )
666
+ }
621
667
  function DocsIcon() {
622
668
  return (
623
669
  <img
624
670
  src={iconBooks}
625
- width={21}
671
+ width={18}
626
672
  style={{ marginRight: 'calc(var(--icon-text-padding) + 2px)' }}
627
673
  className="decolorize-5"
628
674
  />
@@ -135,6 +135,12 @@ ${/* Button style */ ''}
135
135
  &::before {
136
136
  top: 0;
137
137
  }
138
+ & .caret-icon-left {
139
+ transform: rotate(-90deg);
140
+ }
141
+ & .caret-icon-right {
142
+ transform: rotate(90deg);
143
+ }
138
144
  }
139
145
  }
140
146
  `
@@ -13,12 +13,14 @@ function Link({
13
13
  text,
14
14
  noBreadcrumb,
15
15
  doNotInferSectionTitle,
16
+ noWarning,
16
17
  children,
17
18
  }: {
18
19
  href: string
19
20
  text?: string | React.ReactNode
20
- noBreadcrumb?: true
21
- doNotInferSectionTitle?: true
21
+ noBreadcrumb?: boolean
22
+ doNotInferSectionTitle?: boolean
23
+ noWarning?: boolean
22
24
  children?: React.ReactNode
23
25
  }) {
24
26
  const pageContext = usePageContext()
@@ -30,15 +32,18 @@ function Link({
30
32
  // assertWarning(!text, 'prop `text` is deprecated')
31
33
  text = text ?? children
32
34
 
33
- const linkTextData = getLinkTextData(href, pageContext, doNotInferSectionTitle)
34
- if (!linkTextData) {
35
- text = 'LINK-TARGET-NOT-FOUND'
36
- } else if (!text) {
37
- text = getLinkText({
38
- noBreadcrumb,
39
- ...linkTextData,
40
- })
35
+ const linkTextData = getLinkTextData({ href, pageContext, doNotInferSectionTitle, noWarning })
36
+ if (!text) {
37
+ if (linkTextData) {
38
+ text = getLinkText({
39
+ noBreadcrumb,
40
+ ...linkTextData,
41
+ })
42
+ } else {
43
+ text = 'LINK-TARGET-NOT-FOUND'
44
+ }
41
45
  }
46
+
42
47
  return <a href={href}>{text}</a>
43
48
  }
44
49
 
@@ -48,7 +53,7 @@ function getLinkText({
48
53
  sectionTitle,
49
54
  isLinkOnSamePage,
50
55
  }: {
51
- noBreadcrumb: true | undefined
56
+ noBreadcrumb: boolean | undefined
52
57
  linkData: LinkData
53
58
  sectionTitle: React.JSX.Element | null
54
59
  isLinkOnSamePage: boolean
@@ -78,10 +83,20 @@ function getLinkText({
78
83
  )
79
84
  }
80
85
 
81
- function getLinkTextData(href: string, pageContext: PageContextResolved, doNotInferSectionTitle?: boolean) {
86
+ function getLinkTextData({
87
+ href,
88
+ pageContext,
89
+ doNotInferSectionTitle,
90
+ noWarning,
91
+ }: {
92
+ href: string
93
+ pageContext: PageContextResolved
94
+ doNotInferSectionTitle?: boolean
95
+ noWarning?: boolean
96
+ }) {
82
97
  const { hrefPathname, hrefHash } = parseHref(href)
83
98
 
84
- const linkData = findLinkData(hrefPathname || pageContext.urlPathname, pageContext)
99
+ const linkData = findLinkData(hrefPathname || pageContext.urlPathname, { pageContext, noWarning })
85
100
  if (!linkData) return null
86
101
  const isLinkOnSamePage = linkData.url === pageContext.urlPathname
87
102
  if (!hrefPathname) assert(isLinkOnSamePage)
@@ -90,7 +105,7 @@ function getLinkTextData(href: string, pageContext: PageContextResolved, doNotIn
90
105
  if (hrefHash) {
91
106
  assert(!hrefHash.startsWith('#'))
92
107
  if (isLinkOnSamePage) {
93
- const linkDataPageSection = findLinkData(`#${hrefHash}`, pageContext)
108
+ const linkDataPageSection = findLinkData(`#${hrefHash}`, { pageContext, noWarning })
94
109
  if (!linkDataPageSection) return null
95
110
  sectionTitle = parseMarkdownMini(linkDataPageSection.title)
96
111
  } else if ('sectionTitles' in linkData && linkData.sectionTitles) {
@@ -121,29 +136,36 @@ type LinkData = {
121
136
  linkBreadcrumb: null | string[]
122
137
  sectionTitles?: string[]
123
138
  }
124
- function findLinkData(href: string, pageContext: PageContextResolved): LinkData | null {
139
+ function findLinkData(
140
+ href: string,
141
+ { pageContext, noWarning }: { pageContext: PageContextResolved; noWarning?: boolean },
142
+ ): LinkData | null {
125
143
  assert(href.startsWith('/') || href.startsWith('#'))
126
144
  const { linksAll } = pageContext
127
145
  const linkData = linksAll.find(({ url }) => href === url)
128
146
  if (href.startsWith('#')) {
129
- assertWarning(linkData, `Couldn't find ${href} in ${pageContext.urlPathname}, does it exist?`)
147
+ if (!noWarning) {
148
+ assertWarning(linkData, `Couldn't find ${href} in ${pageContext.urlPathname}, does it exist?`)
149
+ }
130
150
  } else {
131
- assertWarning(
132
- linkData,
133
- [
134
- `Couldn't find page with URL ${pc.bold(href)}`,
135
- `— did you define it in`,
151
+ if (!noWarning) {
152
+ assertWarning(
153
+ linkData,
136
154
  [
137
- pc.cyan('docpress.config.js'),
138
- pc.dim('#{'),
139
- pc.cyan('headings'),
140
- pc.dim(','),
141
- pc.cyan('headingsDetached'),
142
- pc.dim('}'),
143
- '?',
144
- ].join(''),
145
- ].join(' '),
146
- )
155
+ `Couldn't find page with URL ${pc.bold(href)}`,
156
+ `— did you define it in`,
157
+ [
158
+ pc.cyan('docpress.config.js'),
159
+ pc.dim('#{'),
160
+ pc.cyan('headings'),
161
+ pc.dim(','),
162
+ pc.cyan('headingsDetached'),
163
+ pc.dim('}'),
164
+ '?',
165
+ ].join(''),
166
+ ].join(' '),
167
+ )
168
+ }
147
169
  }
148
170
  return linkData ?? null
149
171
  }
@@ -1,11 +1,12 @@
1
1
  export { Link };
2
2
  export type { LinkData };
3
3
  import React from 'react';
4
- declare function Link({ href, text, noBreadcrumb, doNotInferSectionTitle, children, }: {
4
+ declare function Link({ href, text, noBreadcrumb, doNotInferSectionTitle, noWarning, children, }: {
5
5
  href: string;
6
6
  text?: string | React.ReactNode;
7
- noBreadcrumb?: true;
8
- doNotInferSectionTitle?: true;
7
+ noBreadcrumb?: boolean;
8
+ doNotInferSectionTitle?: boolean;
9
+ noWarning?: boolean;
9
10
  children?: React.ReactNode;
10
11
  }): React.JSX.Element;
11
12
  type LinkData = {
@@ -16,18 +16,20 @@ import { assert, assertUsage, assertWarning, determineSectionTitle, determineSec
16
16
  import { parseMarkdownMini } from '../parseMarkdownMini';
17
17
  import pc from '@brillout/picocolors';
18
18
  function Link(_a) {
19
- var href = _a.href, text = _a.text, noBreadcrumb = _a.noBreadcrumb, doNotInferSectionTitle = _a.doNotInferSectionTitle, children = _a.children;
19
+ var href = _a.href, text = _a.text, noBreadcrumb = _a.noBreadcrumb, doNotInferSectionTitle = _a.doNotInferSectionTitle, noWarning = _a.noWarning, children = _a.children;
20
20
  var pageContext = usePageContext();
21
21
  assertUsage(href.startsWith('/') || href.startsWith('#'), "<Link href /> prop `href==='".concat(href, "'` but should start with '/' or '#'"));
22
22
  assertUsage(!text || !children, 'Cannot use both `text` or `children`');
23
23
  // assertWarning(!text, 'prop `text` is deprecated')
24
24
  text = text !== null && text !== void 0 ? text : children;
25
- var linkTextData = getLinkTextData(href, pageContext, doNotInferSectionTitle);
26
- if (!linkTextData) {
27
- text = 'LINK-TARGET-NOT-FOUND';
28
- }
29
- else if (!text) {
30
- text = getLinkText(__assign({ noBreadcrumb: noBreadcrumb }, linkTextData));
25
+ var linkTextData = getLinkTextData({ href: href, pageContext: pageContext, doNotInferSectionTitle: doNotInferSectionTitle, noWarning: noWarning });
26
+ if (!text) {
27
+ if (linkTextData) {
28
+ text = getLinkText(__assign({ noBreadcrumb: noBreadcrumb }, linkTextData));
29
+ }
30
+ else {
31
+ text = 'LINK-TARGET-NOT-FOUND';
32
+ }
31
33
  }
32
34
  return React.createElement("a", { href: href }, text);
33
35
  }
@@ -51,9 +53,10 @@ function getLinkText(_a) {
51
53
  title));
52
54
  })));
53
55
  }
54
- function getLinkTextData(href, pageContext, doNotInferSectionTitle) {
55
- var _a = parseHref(href), hrefPathname = _a.hrefPathname, hrefHash = _a.hrefHash;
56
- var linkData = findLinkData(hrefPathname || pageContext.urlPathname, pageContext);
56
+ function getLinkTextData(_a) {
57
+ var href = _a.href, pageContext = _a.pageContext, doNotInferSectionTitle = _a.doNotInferSectionTitle, noWarning = _a.noWarning;
58
+ var _b = parseHref(href), hrefPathname = _b.hrefPathname, hrefHash = _b.hrefHash;
59
+ var linkData = findLinkData(hrefPathname || pageContext.urlPathname, { pageContext: pageContext, noWarning: noWarning });
57
60
  if (!linkData)
58
61
  return null;
59
62
  var isLinkOnSamePage = linkData.url === pageContext.urlPathname;
@@ -63,7 +66,7 @@ function getLinkTextData(href, pageContext, doNotInferSectionTitle) {
63
66
  if (hrefHash) {
64
67
  assert(!hrefHash.startsWith('#'));
65
68
  if (isLinkOnSamePage) {
66
- var linkDataPageSection = findLinkData("#".concat(hrefHash), pageContext);
69
+ var linkDataPageSection = findLinkData("#".concat(hrefHash), { pageContext: pageContext, noWarning: noWarning });
67
70
  if (!linkDataPageSection)
68
71
  return null;
69
72
  sectionTitle = parseMarkdownMini(linkDataPageSection.title);
@@ -85,7 +88,8 @@ function getLinkTextData(href, pageContext, doNotInferSectionTitle) {
85
88
  }
86
89
  return { linkData: linkData, sectionTitle: sectionTitle, isLinkOnSamePage: isLinkOnSamePage };
87
90
  }
88
- function findLinkData(href, pageContext) {
91
+ function findLinkData(href, _a) {
92
+ var pageContext = _a.pageContext, noWarning = _a.noWarning;
89
93
  assert(href.startsWith('/') || href.startsWith('#'));
90
94
  var linksAll = pageContext.linksAll;
91
95
  var linkData = linksAll.find(function (_a) {
@@ -93,22 +97,26 @@ function findLinkData(href, pageContext) {
93
97
  return href === url;
94
98
  });
95
99
  if (href.startsWith('#')) {
96
- assertWarning(linkData, "Couldn't find ".concat(href, " in ").concat(pageContext.urlPathname, ", does it exist?"));
100
+ if (!noWarning) {
101
+ assertWarning(linkData, "Couldn't find ".concat(href, " in ").concat(pageContext.urlPathname, ", does it exist?"));
102
+ }
97
103
  }
98
104
  else {
99
- assertWarning(linkData, [
100
- "Couldn't find page with URL ".concat(pc.bold(href)),
101
- "\u2014 did you define it in",
102
- [
103
- pc.cyan('docpress.config.js'),
104
- pc.dim('#{'),
105
- pc.cyan('headings'),
106
- pc.dim(','),
107
- pc.cyan('headingsDetached'),
108
- pc.dim('}'),
109
- '?',
110
- ].join(''),
111
- ].join(' '));
105
+ if (!noWarning) {
106
+ assertWarning(linkData, [
107
+ "Couldn't find page with URL ".concat(pc.bold(href)),
108
+ "\u2014 did you define it in",
109
+ [
110
+ pc.cyan('docpress.config.js'),
111
+ pc.dim('#{'),
112
+ pc.cyan('headings'),
113
+ pc.dim(','),
114
+ pc.cyan('headingsDetached'),
115
+ pc.dim('}'),
116
+ '?',
117
+ ].join(''),
118
+ ].join(' '));
119
+ }
112
120
  }
113
121
  return linkData !== null && linkData !== void 0 ? linkData : null;
114
122
  }
@@ -32,7 +32,7 @@ function SearchIcon() {
32
32
  return (
33
33
  <img
34
34
  src={iconMagnifyingGlass}
35
- width={21}
35
+ width={18}
36
36
  style={{ marginRight: 'var(--icon-text-padding)' }}
37
37
  className="decolorize-7"
38
38
  />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/docpress",
3
- "version": "0.12.5",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@brillout/picocolors": "^1.0.10",