@pathmx/core 0.5.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.
Files changed (195) hide show
  1. package/LICENSE.md +172 -0
  2. package/README.md +111 -0
  3. package/actions/actions.ts +307 -0
  4. package/actions/draft.ts +105 -0
  5. package/actions/transaction.ts +164 -0
  6. package/assets.ts +149 -0
  7. package/authority/access.ts +820 -0
  8. package/authority/actors.ts +271 -0
  9. package/authority/agents.ts +95 -0
  10. package/authority/credentials.ts +144 -0
  11. package/authority/model.ts +71 -0
  12. package/authority/sharing.ts +89 -0
  13. package/browser-bundle.ts +61 -0
  14. package/canonical.ts +41 -0
  15. package/cli/dev.ts +134 -0
  16. package/cli/export.ts +74 -0
  17. package/cli/index.ts +52 -0
  18. package/cli/lint.ts +164 -0
  19. package/cli/mv.ts +30 -0
  20. package/cli/perms.ts +182 -0
  21. package/cli/plugin-packages.ts +159 -0
  22. package/cli/plugins.ts +95 -0
  23. package/cli/query.ts +225 -0
  24. package/cli/readme.md +95 -0
  25. package/cli/release.ts +75 -0
  26. package/cli/rm.ts +22 -0
  27. package/cli/serve.ts +100 -0
  28. package/cli/tree.ts +131 -0
  29. package/cli/update.ts +78 -0
  30. package/cli/utils.ts +53 -0
  31. package/core.ts +96 -0
  32. package/database.ts +189 -0
  33. package/dependencies.ts +60 -0
  34. package/dist/pathmx.js +1224 -0
  35. package/document.ts +194 -0
  36. package/environment.ts +110 -0
  37. package/environments/bun-plugins.ts +68 -0
  38. package/environments/bun-publish.ts +194 -0
  39. package/environments/bun.ts +223 -0
  40. package/globals.d.ts +14 -0
  41. package/graph.ts +153 -0
  42. package/host/compiler.ts +314 -0
  43. package/host/create.ts +66 -0
  44. package/host/engine.ts +630 -0
  45. package/host/plugin-host.ts +487 -0
  46. package/host/render.ts +102 -0
  47. package/host/response.ts +20 -0
  48. package/host/shell.html +15 -0
  49. package/host/source-sync.ts +254 -0
  50. package/html-attributes.ts +15 -0
  51. package/html.ts +48 -0
  52. package/icons/LICENSE +43 -0
  53. package/icons/lucide.ts +54 -0
  54. package/index.ts +75 -0
  55. package/invalidation.ts +85 -0
  56. package/log.ts +84 -0
  57. package/ops/href.ts +87 -0
  58. package/ops/index.ts +9 -0
  59. package/ops/move-source.ts +114 -0
  60. package/ops/plan.ts +47 -0
  61. package/ops/remove-source.ts +70 -0
  62. package/package.json +46 -0
  63. package/path.ts +75 -0
  64. package/pattern.ts +314 -0
  65. package/perf.ts +88 -0
  66. package/plugins/actor-path.ts +43 -0
  67. package/plugins/actor-profile.ts +55 -0
  68. package/plugins/agent-browsing.ts +183 -0
  69. package/plugins/app-component.ts +23 -0
  70. package/plugins/block-layout/index.ts +78 -0
  71. package/plugins/block-layout/theme.css +90 -0
  72. package/plugins/callout/index.ts +236 -0
  73. package/plugins/callout/theme.css +138 -0
  74. package/plugins/canonical-links.ts +144 -0
  75. package/plugins/code-highlight/client.ts +89 -0
  76. package/plugins/code-highlight/index.ts +147 -0
  77. package/plugins/code-highlight/theme.css +89 -0
  78. package/plugins/context.ts +131 -0
  79. package/plugins/datatype/Datatype[wdth,wght].woff2 +0 -0
  80. package/plugins/datatype/OFL.txt +96 -0
  81. package/plugins/datatype/index.ts +287 -0
  82. package/plugins/definition-list.ts +236 -0
  83. package/plugins/directive-definitions.ts +13 -0
  84. package/plugins/embedding/client.ts +88 -0
  85. package/plugins/embedding/index.ts +43 -0
  86. package/plugins/image/index.ts +68 -0
  87. package/plugins/image/theme.css +43 -0
  88. package/plugins/include.ts +119 -0
  89. package/plugins/index.ts +91 -0
  90. package/plugins/input/authoring.ts +236 -0
  91. package/plugins/input/config.ts +85 -0
  92. package/plugins/input/index.ts +359 -0
  93. package/plugins/input/model.ts +173 -0
  94. package/plugins/input/state.ts +272 -0
  95. package/plugins/layout.ts +313 -0
  96. package/plugins/literate/client.ts +208 -0
  97. package/plugins/literate/index.ts +742 -0
  98. package/plugins/math/index.ts +140 -0
  99. package/plugins/meta.ts +42 -0
  100. package/plugins/navigation/index.ts +158 -0
  101. package/plugins/navigation/model.ts +364 -0
  102. package/plugins/preset.ts +65 -0
  103. package/plugins/query/index.ts +322 -0
  104. package/plugins/rss/index.ts +46 -0
  105. package/plugins/runtime/actions.ts +62 -0
  106. package/plugins/runtime/client.ts +8 -0
  107. package/plugins/runtime/document.ts +506 -0
  108. package/plugins/runtime/error.ts +154 -0
  109. package/plugins/runtime/heading-links.ts +31 -0
  110. package/plugins/runtime/index.ts +104 -0
  111. package/plugins/runtime/live.ts +51 -0
  112. package/plugins/runtime/navigation.ts +113 -0
  113. package/plugins/runtime/pending.ts +53 -0
  114. package/plugins/runtime/publication.ts +19 -0
  115. package/plugins/runtime/start.ts +177 -0
  116. package/plugins/runtime/static-client.ts +6 -0
  117. package/plugins/runtime/static-live.ts +188 -0
  118. package/plugins/runtime/view-transition.ts +72 -0
  119. package/plugins/runtime/viewport.ts +110 -0
  120. package/plugins/schema.ts +24 -0
  121. package/plugins/scripts.ts +140 -0
  122. package/plugins/source-preview/client.ts +256 -0
  123. package/plugins/source-preview/index.ts +132 -0
  124. package/plugins/source-preview/model.ts +11 -0
  125. package/plugins/source-preview/preview.css +107 -0
  126. package/plugins/styles.ts +145 -0
  127. package/plugins/theme/components.ts +10 -0
  128. package/plugins/theme/foundation.css +358 -0
  129. package/plugins/theme/index.ts +333 -0
  130. package/plugins/theme/prose.css +284 -0
  131. package/plugins/theme/scheme.js +63 -0
  132. package/plugins/theme/toggle.css +44 -0
  133. package/plugins/theme/view-transition.css +68 -0
  134. package/plugins/toc/client.ts +146 -0
  135. package/plugins/toc/index.ts +232 -0
  136. package/plugins/toc/theme.css +172 -0
  137. package/plugins/types.ts +538 -0
  138. package/problem.ts +41 -0
  139. package/project.ts +6 -0
  140. package/publish/build.ts +402 -0
  141. package/publish/concurrent.ts +32 -0
  142. package/publish/identity.ts +63 -0
  143. package/publish/index.ts +11 -0
  144. package/publish/location.ts +167 -0
  145. package/publish/model.ts +58 -0
  146. package/publish/plan.ts +300 -0
  147. package/publish/validate.ts +150 -0
  148. package/query/candidate-index.ts +101 -0
  149. package/query/dependency-index.ts +99 -0
  150. package/query/fields.ts +216 -0
  151. package/query/invalidation.ts +48 -0
  152. package/query/kernel.ts +776 -0
  153. package/query/model.ts +79 -0
  154. package/repository.ts +374 -0
  155. package/runtime-profile.ts +34 -0
  156. package/schema/model.ts +92 -0
  157. package/schema/registry.ts +642 -0
  158. package/schema/standard.ts +226 -0
  159. package/server/context.ts +94 -0
  160. package/server/css-imports.ts +66 -0
  161. package/server/http.ts +333 -0
  162. package/server/page.ts +21 -0
  163. package/server/protocols.ts +12 -0
  164. package/server/representations.ts +66 -0
  165. package/server/router.ts +131 -0
  166. package/server/routes.ts +202 -0
  167. package/server/serve.ts +5 -0
  168. package/server/watch.ts +120 -0
  169. package/source/blocks.ts +71 -0
  170. package/source/format.ts +164 -0
  171. package/source/index.ts +67 -0
  172. package/source/interpolate.ts +63 -0
  173. package/source/markdown/blocks.ts +46 -0
  174. package/source/markdown/comments.ts +32 -0
  175. package/source/markdown/fences.ts +67 -0
  176. package/source/markdown/headings.ts +88 -0
  177. package/source/markdown/index.ts +34 -0
  178. package/source/markdown/inline-code.ts +6 -0
  179. package/source/markdown/links.ts +326 -0
  180. package/source/markdown/lists.ts +223 -0
  181. package/source/markdown/prose.ts +74 -0
  182. package/source/markdown/scan.ts +79 -0
  183. package/source/markdown/text.ts +82 -0
  184. package/source/meta.ts +87 -0
  185. package/source/source.ts +121 -0
  186. package/source/topmatter.ts +57 -0
  187. package/source/utils.ts +21 -0
  188. package/source-diagnostic.ts +63 -0
  189. package/text-file.ts +26 -0
  190. package/util.ts +35 -0
  191. package/view/components.ts +499 -0
  192. package/view/model.ts +91 -0
  193. package/view/projection.ts +162 -0
  194. package/view/session.ts +146 -0
  195. package/view/syntax.ts +372 -0
@@ -0,0 +1,284 @@
1
+ @scope (.pmx-prose) to ([data-pmx-prose="off"]) {
2
+ :where(:scope) {
3
+ color: var(--pmx-color-fg);
4
+ line-height: var(--pmx-prose-leading);
5
+
6
+ > :where(:first-child) {
7
+ margin-block-start: 0;
8
+ }
9
+
10
+ > :where(:last-child) {
11
+ margin-block-end: 0;
12
+ }
13
+
14
+ > :where(h1, h2, h3, h4, h5, h6),
15
+ > :where(.pmx-heading) {
16
+ margin-block: calc(var(--pmx-prose-flow) * 1.8)
17
+ calc(var(--pmx-prose-flow) * 0.75);
18
+ }
19
+
20
+ > :where(h1, h2, h3, h4, h5, h6),
21
+ > :where(.pmx-heading) > :where(h1, h2, h3, h4, h5, h6) {
22
+ color: var(--pmx-color-fg);
23
+ font-family: var(--pmx-font-heading);
24
+ font-weight: 700;
25
+ line-height: 1.18;
26
+ text-wrap: balance;
27
+ scroll-margin-block-start: 0;
28
+ }
29
+
30
+ > :where(.pmx-heading) {
31
+ position: relative;
32
+ }
33
+
34
+ > :where(.pmx-heading) > :where(h1, h2, h3, h4, h5, h6) {
35
+ min-inline-size: 0;
36
+ margin: 0;
37
+ cursor: pointer;
38
+ transition: color 120ms ease-out;
39
+ }
40
+
41
+ :where(h1, h2, h3, h4, h5, h6) > a[href] {
42
+ &,
43
+ &:hover {
44
+ color: inherit;
45
+ font-weight: inherit;
46
+ text-decoration: none;
47
+ }
48
+ }
49
+
50
+ > :where(h1),
51
+ > :where(.pmx-heading.level-h1) > h1 {
52
+ font-size: 2.25em;
53
+ }
54
+ > :where(h2),
55
+ > :where(.pmx-heading.level-h2) > h2 {
56
+ font-size: 1.75em;
57
+ }
58
+ > :where(h3),
59
+ > :where(.pmx-heading.level-h3) > h3 {
60
+ font-size: 1.35em;
61
+ }
62
+ > :where(h4),
63
+ > :where(.pmx-heading.level-h4) > h4 {
64
+ font-size: 1.15em;
65
+ }
66
+ > :where(h5, h6),
67
+ > :where(.pmx-heading.level-h5) > h5,
68
+ > :where(.pmx-heading.level-h6) > h6 {
69
+ font-size: 1em;
70
+ }
71
+
72
+ .pmx-heading-anchor {
73
+ position: absolute;
74
+ inline-size: 1px;
75
+ block-size: 1px;
76
+ margin: -1px;
77
+ overflow: hidden;
78
+ clip-path: inset(50%);
79
+ white-space: nowrap;
80
+ }
81
+
82
+ :where(.pmx-heading:hover, .pmx-heading:focus-within)
83
+ > :where(h1, h2, h3, h4, h5, h6) {
84
+ color: var(--pmx-color-link);
85
+ }
86
+
87
+ .pmx-heading:has(> .pmx-heading-anchor:focus-visible)
88
+ > :where(h1, h2, h3, h4, h5, h6) {
89
+ outline: 2px solid var(--pmx-color-focus);
90
+ outline-offset: 2px;
91
+ border-radius: var(--pmx-radius-sm);
92
+ }
93
+
94
+ > :where(p, ul, ol, blockquote, pre, table, figure, hr, .pmx-code-block) {
95
+ margin-block: var(--pmx-prose-flow);
96
+ }
97
+
98
+ :where(ul, ol) {
99
+ padding-inline-start: 1.5em;
100
+ }
101
+
102
+ :where(ul) {
103
+ list-style-type: disc;
104
+
105
+ :where(ul) {
106
+ list-style-type: circle;
107
+
108
+ :where(ul) {
109
+ list-style-type: square;
110
+ }
111
+ }
112
+ }
113
+
114
+ :where(ol) {
115
+ list-style-type: decimal;
116
+ }
117
+
118
+ > :where(ul, ol) :where(ul, ol) {
119
+ margin-block: 0.35em;
120
+ }
121
+
122
+ :where(li) {
123
+ margin-block: 0.3em;
124
+
125
+ &::marker {
126
+ color: var(--pmx-color-muted);
127
+ }
128
+ }
129
+
130
+ > :where(ul:has(> li.task-list-item), ol:has(> li.task-list-item)) {
131
+ padding-inline-start: 0;
132
+ }
133
+
134
+ :where(li.task-list-item) {
135
+ position: relative;
136
+ margin-block: 0.4em;
137
+ padding-inline-start: 1.6em;
138
+ list-style: none;
139
+
140
+ &::marker {
141
+ content: "";
142
+ }
143
+ }
144
+
145
+ :where(li.task-list-item > .task-list-item-checkbox:first-child) {
146
+ position: absolute;
147
+ inset-inline-start: 0;
148
+ inset-block-start: 0.27em;
149
+ inline-size: 1.05em;
150
+ block-size: 1.05em;
151
+ margin: 0;
152
+ accent-color: var(--pmx-color-accent);
153
+ opacity: 1;
154
+ }
155
+
156
+ :where(li.task-list-item > p) {
157
+ margin-block: 0.45em;
158
+ }
159
+
160
+ :where(li.task-list-item > p:first-of-type) {
161
+ margin-block-start: 0;
162
+ }
163
+
164
+ :where(li.task-list-item > p:last-of-type) {
165
+ margin-block-end: 0;
166
+ }
167
+
168
+ > :where(blockquote) {
169
+ border-inline-start: 0.25em solid var(--pmx-color-border);
170
+ color: var(--pmx-color-muted);
171
+ padding-inline-start: 1em;
172
+ }
173
+
174
+ :where(table) {
175
+ display: block;
176
+ inline-size: 100%;
177
+ max-inline-size: 100%;
178
+ overflow-x: auto;
179
+ overscroll-behavior-inline: contain;
180
+ -webkit-overflow-scrolling: touch;
181
+ border-collapse: collapse;
182
+ }
183
+
184
+ :where(th, td) {
185
+ padding: 0.55em 0.7em;
186
+ border-bottom: 1px solid var(--pmx-color-border);
187
+ vertical-align: top;
188
+ }
189
+
190
+ :where(th) {
191
+ font-weight: 650;
192
+ text-align: start;
193
+ white-space: nowrap;
194
+ }
195
+
196
+ :where(tr > :first-child) {
197
+ position: sticky;
198
+ inset-inline-start: 0;
199
+ z-index: 1;
200
+ background: var(--pmx-color-bg);
201
+ border-inline-end: 1px solid var(--pmx-color-border);
202
+ }
203
+
204
+ :where(thead tr > :first-child) {
205
+ z-index: 2;
206
+ }
207
+
208
+ @media (max-width: 40rem) {
209
+ :where(tr > :first-child) {
210
+ min-inline-size: 8rem;
211
+ }
212
+
213
+ :where(tr > :not(:first-child)) {
214
+ min-inline-size: 12rem;
215
+ }
216
+ }
217
+
218
+ > :where(hr) {
219
+ border: 0;
220
+ border-block-start: 1px solid var(--pmx-color-border);
221
+ }
222
+
223
+ :where(a) {
224
+ color: var(--pmx-color-link);
225
+ text-decoration-line: underline;
226
+ text-decoration-color: color-mix(
227
+ in srgb,
228
+ var(--pmx-color-link) 45%,
229
+ transparent
230
+ );
231
+ text-decoration-thickness: 0.08em;
232
+ text-underline-offset: 0.16em;
233
+
234
+ &:hover {
235
+ text-decoration-color: currentColor;
236
+ }
237
+ }
238
+
239
+ :where(mark) {
240
+ background: color-mix(in oklch, var(--pmx-color-accent) 88%, transparent);
241
+ color: inherit;
242
+ }
243
+
244
+ :where(figcaption) {
245
+ color: var(--pmx-color-muted);
246
+ font-size: 0.92em;
247
+ }
248
+
249
+ :where(img) {
250
+ max-inline-size: 100%;
251
+ height: auto;
252
+ border-radius: var(--pmx-radius);
253
+ }
254
+
255
+ :where(.pmx-mermaid) {
256
+ overflow-x: auto;
257
+ }
258
+
259
+ :where(.pmx-mermaid svg) {
260
+ display: block;
261
+ max-inline-size: 100%;
262
+ block-size: auto;
263
+ margin-inline: auto;
264
+ }
265
+
266
+ :where(code) {
267
+ font-family: var(--pmx-font-mono);
268
+ font-size: 0.92em;
269
+ background: var(--pmx-code-bg);
270
+ color: var(--pmx-code-fg);
271
+ border: 1px solid var(--pmx-color-border);
272
+ border-radius: calc(var(--pmx-radius) * 0.65);
273
+ padding: 0.08em 0.3em;
274
+ }
275
+
276
+ :where(pre, .pmx-code-block) :where(code) {
277
+ font-size: 0.9em;
278
+ background: transparent;
279
+ border: 0;
280
+ border-radius: 0;
281
+ padding: 0;
282
+ }
283
+ }
284
+ }
@@ -0,0 +1,63 @@
1
+ import "./toggle.css"
2
+
3
+ const SCHEME_COOKIE = "pathmx-scheme"
4
+ const TOGGLE = ".pmx-scheme-toggle"
5
+
6
+ const labels = {
7
+ light: "Using light color scheme. Activate for dark.",
8
+ dark: "Using dark color scheme. Activate for light.",
9
+ }
10
+
11
+ function themeColors() {
12
+ return [...document.querySelectorAll('meta[name="theme-color"]')].map(
13
+ (meta) => ({
14
+ meta,
15
+ content: meta.getAttribute("content") || "",
16
+ media: meta.getAttribute("media") || "",
17
+ }),
18
+ )
19
+ }
20
+
21
+ function applyThemeColors(scheme) {
22
+ const colors = themeColors()
23
+ const light = colors.find((item) => item.media.includes("light"))
24
+ const dark = colors.find((item) => item.media.includes("dark"))
25
+ const active = scheme === "dark" ? dark?.content : light?.content
26
+ for (const item of colors) {
27
+ item.meta.setAttribute("content", active ?? item.content)
28
+ }
29
+ }
30
+
31
+ function resolvedScheme() {
32
+ const forced = document.documentElement.getAttribute("data-pmx-scheme")
33
+ if (forced === "light" || forced === "dark") return forced
34
+ return matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
35
+ }
36
+
37
+ function syncToggles(scheme) {
38
+ const label = labels[scheme]
39
+ for (const button of document.querySelectorAll(TOGGLE)) {
40
+ button.setAttribute("aria-label", label)
41
+ button.title = label
42
+ }
43
+ }
44
+
45
+ function applyScheme(scheme) {
46
+ const root = document.documentElement
47
+ root.setAttribute("data-pmx-scheme", scheme)
48
+ root.style.colorScheme = scheme
49
+ document.cookie =
50
+ SCHEME_COOKIE + "=" + scheme + "; Path=/; Max-Age=31536000; SameSite=Lax"
51
+ applyThemeColors(scheme)
52
+ syncToggles(scheme)
53
+ }
54
+
55
+ document.addEventListener("click", (event) => {
56
+ const button =
57
+ event.target instanceof Element ? event.target.closest(TOGGLE) : null
58
+ if (!button) return
59
+ applyScheme(resolvedScheme() === "dark" ? "light" : "dark")
60
+ })
61
+ document.addEventListener("pmx:render", () => syncToggles(resolvedScheme()))
62
+
63
+ syncToggles(resolvedScheme())
@@ -0,0 +1,44 @@
1
+ .pmx-scheme-toggle {
2
+ display: inline-grid;
3
+ place-items: center;
4
+ width: 2rem;
5
+ height: 2rem;
6
+ padding: 0;
7
+ border: 1px solid var(--pmx-color-border);
8
+ border-radius: var(--pmx-radius-full);
9
+ background: var(--pmx-color-bg);
10
+ color: inherit;
11
+ cursor: pointer;
12
+ }
13
+
14
+ .pmx-scheme-toggle:focus-visible {
15
+ outline: 2px solid var(--pmx-color-focus);
16
+ outline-offset: 2px;
17
+ }
18
+
19
+ .pmx-scheme-toggle [data-pmx-scheme-icon] {
20
+ display: none;
21
+ }
22
+
23
+ :root[data-pmx-scheme="light"]
24
+ .pmx-scheme-toggle
25
+ [data-pmx-scheme-icon="light"],
26
+ :root[data-pmx-scheme="dark"] .pmx-scheme-toggle [data-pmx-scheme-icon="dark"] {
27
+ display: block;
28
+ }
29
+
30
+ @media (prefers-color-scheme: light) {
31
+ :root:not([data-pmx-scheme])
32
+ .pmx-scheme-toggle
33
+ [data-pmx-scheme-icon="light"] {
34
+ display: block;
35
+ }
36
+ }
37
+
38
+ @media (prefers-color-scheme: dark) {
39
+ :root:not([data-pmx-scheme])
40
+ .pmx-scheme-toggle
41
+ [data-pmx-scheme-icon="dark"] {
42
+ display: block;
43
+ }
44
+ }
@@ -0,0 +1,68 @@
1
+ :root {
2
+ --pmx-view-transition-duration: 220ms;
3
+ --pmx-view-transition-easing: ease;
4
+ --pmx-view-transition-distance: 1.25rem;
5
+ }
6
+
7
+ @keyframes pmx-view-out-forward {
8
+ to {
9
+ opacity: 0;
10
+ transform: translateX(calc(-1 * var(--pmx-view-transition-distance)));
11
+ }
12
+ }
13
+
14
+ @keyframes pmx-view-in-forward {
15
+ from {
16
+ opacity: 0;
17
+ transform: translateX(var(--pmx-view-transition-distance));
18
+ }
19
+ }
20
+
21
+ @keyframes pmx-view-out-back {
22
+ to {
23
+ opacity: 0;
24
+ transform: translateX(var(--pmx-view-transition-distance));
25
+ }
26
+ }
27
+
28
+ @keyframes pmx-view-in-back {
29
+ from {
30
+ opacity: 0;
31
+ transform: translateX(calc(-1 * var(--pmx-view-transition-distance)));
32
+ }
33
+ }
34
+
35
+ html:active-view-transition-type(pmx-forward) ::view-transition-old(root),
36
+ html:active-view-transition-type(pmx-forward) ::view-transition-new(root),
37
+ html:active-view-transition-type(pmx-back) ::view-transition-old(root),
38
+ html:active-view-transition-type(pmx-back) ::view-transition-new(root) {
39
+ mix-blend-mode: normal;
40
+ }
41
+
42
+ html:active-view-transition-type(pmx-forward) ::view-transition-old(root) {
43
+ animation: var(--pmx-view-transition-duration)
44
+ var(--pmx-view-transition-easing) both pmx-view-out-forward;
45
+ }
46
+
47
+ html:active-view-transition-type(pmx-forward) ::view-transition-new(root) {
48
+ animation: var(--pmx-view-transition-duration)
49
+ var(--pmx-view-transition-easing) both pmx-view-in-forward;
50
+ }
51
+
52
+ html:active-view-transition-type(pmx-back) ::view-transition-old(root) {
53
+ animation: var(--pmx-view-transition-duration)
54
+ var(--pmx-view-transition-easing) both pmx-view-out-back;
55
+ }
56
+
57
+ html:active-view-transition-type(pmx-back) ::view-transition-new(root) {
58
+ animation: var(--pmx-view-transition-duration)
59
+ var(--pmx-view-transition-easing) both pmx-view-in-back;
60
+ }
61
+
62
+ @media (prefers-reduced-motion: reduce) {
63
+ ::view-transition-group(*),
64
+ ::view-transition-old(*),
65
+ ::view-transition-new(*) {
66
+ animation: none !important;
67
+ }
68
+ }
@@ -0,0 +1,146 @@
1
+ import "./theme.css"
2
+
3
+ type ScrollSpyState = {
4
+ links: HTMLAnchorElement[]
5
+ targets: HTMLElement[]
6
+ offsets: number[]
7
+ activeLine: number
8
+ }
9
+
10
+ type TocState = {
11
+ toc: HTMLElement
12
+ spy?: ScrollSpyState
13
+ }
14
+
15
+ const supportsNativeScrollSpy =
16
+ CSS.supports("scroll-target-group: auto") &&
17
+ CSS.supports("selector(a:target-current)") &&
18
+ CSS.supports("selector(a:target-before)")
19
+ const states = new Map<HTMLElement, TocState>()
20
+
21
+ function targetFor(link: HTMLAnchorElement) {
22
+ const hash = new URL(link.href).hash.slice(1)
23
+ if (!hash) return
24
+ try {
25
+ return document.getElementById(decodeURIComponent(hash)) ?? undefined
26
+ } catch {
27
+ return
28
+ }
29
+ }
30
+
31
+ function updateScrollSpy(spy: ScrollSpyState) {
32
+ const atEnd =
33
+ scrollY > 0 &&
34
+ scrollY + innerHeight >= document.documentElement.scrollHeight - 1
35
+ const position = scrollY + spy.activeLine
36
+ let low = 0
37
+ let high = spy.offsets.length
38
+ while (low < high) {
39
+ const middle = (low + high) >>> 1
40
+ if (spy.offsets[middle]! <= position) low = middle + 1
41
+ else high = middle
42
+ }
43
+ const active = atEnd ? spy.links.length - 1 : Math.max(0, low - 1)
44
+
45
+ for (const [index, link] of spy.links.entries()) {
46
+ const value =
47
+ index < active ? "passed" : index === active ? "active" : "upcoming"
48
+ link.dataset.pmxTocState = value
49
+ if (value === "active") link.setAttribute("aria-current", "location")
50
+ else link.removeAttribute("aria-current")
51
+ }
52
+ }
53
+
54
+ function measure(state: TocState) {
55
+ const rootStyle = getComputedStyle(document.documentElement)
56
+ const blockEnd = Number.parseFloat(rootStyle.scrollPaddingBlockEnd) || 0
57
+ const available = Math.max(
58
+ 0,
59
+ innerHeight - Math.max(0, state.toc.getBoundingClientRect().top) - blockEnd,
60
+ )
61
+ state.toc.style.setProperty(
62
+ "--pmx-toc-available-block-size",
63
+ `${available}px`,
64
+ )
65
+
66
+ if (!state.spy) return
67
+ const scrollOffset = Number.parseFloat(rootStyle.scrollPaddingBlockStart)
68
+ state.spy.activeLine = Math.max(
69
+ Number.isFinite(scrollOffset) ? scrollOffset : 0,
70
+ Math.min(160, Math.max(64, innerHeight * 0.2)),
71
+ )
72
+ state.spy.offsets = state.spy.targets.map(
73
+ (target) => target.getBoundingClientRect().top + scrollY,
74
+ )
75
+ updateScrollSpy(state.spy)
76
+ }
77
+
78
+ function initialize(toc: HTMLElement) {
79
+ if (states.has(toc)) return
80
+ let spy: ScrollSpyState | undefined
81
+ if (!supportsNativeScrollSpy) {
82
+ const pairs = [...toc.querySelectorAll<HTMLAnchorElement>(".pmx-toc-link")]
83
+ .map((link) => ({ link, target: targetFor(link) }))
84
+ .filter(
85
+ (pair): pair is { link: HTMLAnchorElement; target: HTMLElement } =>
86
+ pair.target != null,
87
+ )
88
+ if (pairs.length) {
89
+ spy = {
90
+ links: pairs.map(({ link }) => link),
91
+ targets: pairs.map(({ target }) => target),
92
+ offsets: [],
93
+ activeLine: 0,
94
+ }
95
+ }
96
+ }
97
+ const state = { toc, spy }
98
+ states.set(toc, state)
99
+ measure(state)
100
+ }
101
+
102
+ function reconcile() {
103
+ for (const toc of states.keys()) {
104
+ if (!toc.isConnected) states.delete(toc)
105
+ }
106
+ for (const toc of document.querySelectorAll<HTMLElement>("[data-pmx-toc]")) {
107
+ initialize(toc)
108
+ }
109
+ }
110
+
111
+ let measureFrame = 0
112
+ function scheduleMeasure() {
113
+ if (measureFrame) return
114
+ measureFrame = requestAnimationFrame(() => {
115
+ measureFrame = 0
116
+ for (const state of states.values()) measure(state)
117
+ })
118
+ }
119
+
120
+ if (!supportsNativeScrollSpy) {
121
+ let scrollFrame = 0
122
+ addEventListener(
123
+ "scroll",
124
+ () => {
125
+ if (scrollFrame) return
126
+ scrollFrame = requestAnimationFrame(() => {
127
+ scrollFrame = 0
128
+ for (const { spy } of states.values()) {
129
+ if (spy) updateScrollSpy(spy)
130
+ }
131
+ })
132
+ },
133
+ { passive: true },
134
+ )
135
+ }
136
+
137
+ const layoutObserver = new ResizeObserver(scheduleMeasure)
138
+ layoutObserver.observe(document.body)
139
+ addEventListener("resize", scheduleMeasure)
140
+ document.addEventListener("pmx:render", () =>
141
+ requestAnimationFrame(() => {
142
+ states.clear()
143
+ reconcile()
144
+ }),
145
+ )
146
+ reconcile()