@charmland/gem 0.0.0-stage → 0.1.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/LICENSE +177 -0
- package/NOTICE +13 -0
- package/README.md +24 -2
- package/assets/fonts/Hypography-Italic.woff2 +0 -0
- package/assets/fonts/Hypography-Regular.woff2 +0 -0
- package/assets/fonts/PPFraktionMono-Variable.ttf +0 -0
- package/assets/fonts/PPFraktionMonoItalic-Variable.ttf +0 -0
- package/assets/fonts/PPFraktionSans-Variable.ttf +0 -0
- package/assets/fonts/PPFraktionSansItalic-Variable.ttf +0 -0
- package/bin/gem-elm.js +3 -0
- package/dist/browser/boot.d.ts +10 -0
- package/dist/browser/boot.js +14 -0
- package/dist/browser/color-scheme.d.ts +9 -0
- package/dist/browser/color-scheme.js +76 -0
- package/dist/browser/ports.d.ts +37 -0
- package/dist/browser/ports.js +90 -0
- package/dist/browser/router.d.ts +5 -0
- package/dist/browser/router.js +35 -0
- package/dist/browser/runtime.d.ts +12 -0
- package/dist/browser/runtime.js +22 -0
- package/dist/browser/tabs.d.ts +9 -0
- package/dist/browser/tabs.js +69 -0
- package/dist/default/theme.css +4664 -0
- package/dist/default/theme.js +13652 -0
- package/dist/node/build.d.ts +16 -0
- package/dist/node/build.js +48 -0
- package/dist/node/cli.d.ts +2 -0
- package/dist/node/cli.js +21 -0
- package/elm.json +28 -0
- package/package.json +86 -4
- package/src/app/Gem/App.elm +1275 -0
- package/src/app/Gem/CharmSticker.elm +35 -0
- package/src/app/Gem/Components.elm +292 -0
- package/src/app/Gem/Main.elm +17 -0
- package/src/app/Gem/Ports.elm +32 -0
- package/src/app/Gem/Shell.elm +964 -0
- package/src/browser/theme.d.ts +1 -0
- package/src/core/Gem/Node.elm +219 -0
- package/src/core/Gem/Page.elm +409 -0
- package/src/core/Gem/Render.elm +472 -0
- package/src/core/Gem/Slots.elm +11 -0
- package/src/styles/docs.scss +1083 -0
- package/src/styles/fonts.scss +51 -0
- package/src/styles/gem.scss +362 -0
- package/src/styles/theme.scss +8 -0
- package/src/styles/ui/burger.scss +272 -0
- package/src/styles/ui/button.scss +350 -0
- package/src/styles/ui/charmtone.scss +70 -0
- package/src/styles/ui/controls-extra.scss +316 -0
- package/src/styles/ui/controls.scss +110 -0
- package/src/styles/ui/display.scss +359 -0
- package/src/styles/ui/dropdown.scss +341 -0
- package/src/styles/ui/form.scss +314 -0
- package/src/styles/ui/menu.scss +200 -0
- package/src/styles/ui/meter.scss +124 -0
- package/src/styles/ui/modal.scss +545 -0
- package/src/styles/ui/oauth.scss +50 -0
- package/src/styles/ui/page-nav.scss +63 -0
- package/src/styles/ui/reset.scss +111 -0
- package/src/styles/ui/scrollbar.scss +39 -0
- package/src/styles/ui/search.scss +164 -0
- package/src/styles/ui/sidebar.scss +229 -0
- package/src/styles/ui/squircle.scss +60 -0
- package/src/styles/ui/table.scss +97 -0
- package/src/styles/ui/theme.scss +132 -0
- package/src/styles/ui/toast.scss +587 -0
- package/src/styles/ui/toc.scss +128 -0
- package/src/styles/ui/typography.scss +21 -0
- package/src/styles/ui/ui.scss +33 -0
- package/src/ui/Ui/Badge.elm +51 -0
- package/src/ui/Ui/Banner.elm +97 -0
- package/src/ui/Ui/Burger.elm +259 -0
- package/src/ui/Ui/Button.elm +261 -0
- package/src/ui/Ui/Card.elm +32 -0
- package/src/ui/Ui/Cards.elm +15 -0
- package/src/ui/Ui/ChoiceGroup.elm +62 -0
- package/src/ui/Ui/CopyButton.elm +139 -0
- package/src/ui/Ui/Divider.elm +16 -0
- package/src/ui/Ui/Dropdown.elm +600 -0
- package/src/ui/Ui/Empty.elm +41 -0
- package/src/ui/Ui/ErrorBubble.elm +34 -0
- package/src/ui/Ui/Field.elm +45 -0
- package/src/ui/Ui/FormStatus.elm +32 -0
- package/src/ui/Ui/Icon.elm +381 -0
- package/src/ui/Ui/InlineForm.elm +51 -0
- package/src/ui/Ui/Input.elm +113 -0
- package/src/ui/Ui/KeyValue.elm +25 -0
- package/src/ui/Ui/ListRow.elm +67 -0
- package/src/ui/Ui/Loader.elm +32 -0
- package/src/ui/Ui/Logo/Charm.elm +21 -0
- package/src/ui/Ui/Logo/CharmMark.elm +32 -0
- package/src/ui/Ui/Logo/CharmSticker.elm +35 -0
- package/src/ui/Ui/Logo/Discord.elm +26 -0
- package/src/ui/Ui/Logo/GitHub.elm +21 -0
- package/src/ui/Ui/Logo/Google.elm +21 -0
- package/src/ui/Ui/Logo/Hexy.elm +29 -0
- package/src/ui/Ui/Logo/Hyper.elm +42 -0
- package/src/ui/Ui/Logo/Integration.elm +117 -0
- package/src/ui/Ui/Logo/Prism.elm +35 -0
- package/src/ui/Ui/Logos.elm +115 -0
- package/src/ui/Ui/Menu.elm +348 -0
- package/src/ui/Ui/Meter.elm +132 -0
- package/src/ui/Ui/Modal.elm +247 -0
- package/src/ui/Ui/Motion.elm +32 -0
- package/src/ui/Ui/NumberBox.elm +86 -0
- package/src/ui/Ui/OAuthButton.elm +39 -0
- package/src/ui/Ui/PageNav.elm +65 -0
- package/src/ui/Ui/Pager.elm +49 -0
- package/src/ui/Ui/Search.elm +396 -0
- package/src/ui/Ui/SearchBox.elm +78 -0
- package/src/ui/Ui/Section.elm +21 -0
- package/src/ui/Ui/Sidebar.elm +239 -0
- package/src/ui/Ui/Stat.elm +29 -0
- package/src/ui/Ui/Switch.elm +34 -0
- package/src/ui/Ui/Table.elm +89 -0
- package/src/ui/Ui/Tabs.elm +280 -0
- package/src/ui/Ui/ToC.elm +120 -0
- package/src/ui/Ui/Toast.elm +1145 -0
- package/src/ui/Ui/Toolbar.elm +31 -0
- package/src/ui/Ui/TwoStepConfirm.elm +159 -0
- package/src/ui/Ui/Typography.elm +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
package/NOTICE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2026 Charmbracelet, Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @charmland/gem
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Gem's prebuilt default theme, browser and Node runtimes, Elm application sources, UI kit, Sass styles, and assets.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @charmland/gem
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
`@charmland/gem` deliberately has no root export. A default JavaScript entry generated by `@charmland/gem-vite` is equivalent to:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import content from "virtual:gem/content";
|
|
17
|
+
import { boot } from "@charmland/gem/boot";
|
|
18
|
+
import "@charmland/gem/theme.css";
|
|
19
|
+
|
|
20
|
+
boot(content);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Public entrypoints include `@charmland/gem/boot`, `runtime`, `router`, `build`, `theme.js`, `theme.css`, and `css`. Elm and Sass sources are available through `source/core/*`, `source/app/*`, `source/ui/*`, `source/styles/*`, and `source/elm.json`; bundled font files use `fonts/*`.
|
|
24
|
+
|
|
25
|
+
Default use does not need the Elm compiler. Elm is needed only to customize and recompile Gem's Elm sources, using the `gem-elm` CLI or `compileElm` from `@charmland/gem/build`. See the [Gem documentation](https://github.com/charmbracelet/gem#readme) for custom themes and components.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/bin/gem-elm.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boots the compiled theme and connects the ports: clipboard, theme
|
|
3
|
+
* persistence, chatbot links, per-page meta and the scroll position.
|
|
4
|
+
*/
|
|
5
|
+
import "@charmland/gem/theme.js";
|
|
6
|
+
import type { BootFlags } from "@charmland/gem-compiler/types";
|
|
7
|
+
import type { ElmApp } from "./runtime.js";
|
|
8
|
+
export declare function boot(flags: BootFlags, node?: HTMLElement): ElmApp;
|
|
9
|
+
export { connectPorts, installTabs } from "./runtime.js";
|
|
10
|
+
export type { ElmApp, ElmProgram } from "./runtime.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boots the compiled theme and connects the ports: clipboard, theme
|
|
3
|
+
* persistence, chatbot links, per-page meta and the scroll position.
|
|
4
|
+
*/
|
|
5
|
+
import "@charmland/gem/theme.js";
|
|
6
|
+
import { start } from "./runtime.js";
|
|
7
|
+
export function boot(flags, node) {
|
|
8
|
+
const Elm = globalThis.Elm;
|
|
9
|
+
if (!Elm?.Gem?.Main) {
|
|
10
|
+
throw new Error("gem: the theme bundle did not expose Elm.Gem.Main");
|
|
11
|
+
}
|
|
12
|
+
return start(Elm.Gem.Main, flags, node);
|
|
13
|
+
}
|
|
14
|
+
export { connectPorts, installTabs } from "./runtime.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BootFlags } from "@charmland/gem-compiler/types";
|
|
2
|
+
import type { ElmApp } from "./ports.js";
|
|
3
|
+
export declare function prepareColorScheme(flags: BootFlags): BootFlags;
|
|
4
|
+
export declare function connectColorScheme(app: ElmApp): void;
|
|
5
|
+
/**
|
|
6
|
+
* One listener, attached once: it only repaints while the preference is
|
|
7
|
+
* "system", so picking light or dark by hand keeps the OS change ignored.
|
|
8
|
+
*/
|
|
9
|
+
export declare function watchSystem(): void;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const THEME_KEY = "gem-theme";
|
|
2
|
+
/** The stored preference is what the user picked; "system" is resolved late. */
|
|
3
|
+
let preference = null;
|
|
4
|
+
let allowSystem = false;
|
|
5
|
+
export function prepareColorScheme(flags) {
|
|
6
|
+
allowSystem = Boolean(flags.theme.system);
|
|
7
|
+
const stored = readTheme();
|
|
8
|
+
preference = normalizeTheme(stored);
|
|
9
|
+
if (stored !== null && stored !== preference)
|
|
10
|
+
storeTheme(preference);
|
|
11
|
+
else if (stored === null && !allowSystem)
|
|
12
|
+
storeTheme(preference);
|
|
13
|
+
applyTheme();
|
|
14
|
+
return {
|
|
15
|
+
...flags,
|
|
16
|
+
theme: { ...flags.theme, mode: preference },
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function connectColorScheme(app) {
|
|
20
|
+
app.ports?.saveTheme?.subscribe((theme) => {
|
|
21
|
+
preference = normalizeTheme(theme);
|
|
22
|
+
storeTheme(preference);
|
|
23
|
+
applyTheme();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function normalizeTheme(theme) {
|
|
27
|
+
if (theme === "light" || theme === "dark")
|
|
28
|
+
return theme;
|
|
29
|
+
if (theme === "system" && allowSystem)
|
|
30
|
+
return "system";
|
|
31
|
+
// Without the system tab there is nothing to point at, so the OS is read
|
|
32
|
+
// once and the resolved mode becomes the stored preference.
|
|
33
|
+
return allowSystem ? "system" : systemTheme();
|
|
34
|
+
}
|
|
35
|
+
/** The OS preference, as the browser reports it. */
|
|
36
|
+
function systemTheme() {
|
|
37
|
+
if (typeof window.matchMedia !== "function")
|
|
38
|
+
return "dark";
|
|
39
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
40
|
+
}
|
|
41
|
+
/** Paint the resolved mode. `data-theme` never says "system". */
|
|
42
|
+
function applyTheme() {
|
|
43
|
+
const root = document.documentElement;
|
|
44
|
+
const resolved = preference === "system" ? systemTheme() : preference === "light" ? "light" : "dark";
|
|
45
|
+
root.setAttribute("data-theme", resolved);
|
|
46
|
+
root.style.colorScheme = resolved;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* One listener, attached once: it only repaints while the preference is
|
|
50
|
+
* "system", so picking light or dark by hand keeps the OS change ignored.
|
|
51
|
+
*/
|
|
52
|
+
export function watchSystem() {
|
|
53
|
+
if (typeof window.matchMedia !== "function")
|
|
54
|
+
return;
|
|
55
|
+
window
|
|
56
|
+
.matchMedia("(prefers-color-scheme: dark)")
|
|
57
|
+
.addEventListener("change", () => {
|
|
58
|
+
if (preference === "system")
|
|
59
|
+
applyTheme();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function readTheme() {
|
|
63
|
+
try {
|
|
64
|
+
return localStorage.getItem(THEME_KEY);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function storeTheme(theme) {
|
|
71
|
+
try {
|
|
72
|
+
localStorage.setItem(THEME_KEY, theme);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface ElmApp {
|
|
2
|
+
ports?: {
|
|
3
|
+
copyToClipboard?: {
|
|
4
|
+
subscribe(callback: (text: string) => void): void;
|
|
5
|
+
};
|
|
6
|
+
copyMarkdown?: {
|
|
7
|
+
subscribe(callback: (url: string) => void): void;
|
|
8
|
+
};
|
|
9
|
+
saveTheme?: {
|
|
10
|
+
subscribe(callback: (theme: string) => void): void;
|
|
11
|
+
};
|
|
12
|
+
openExternal?: {
|
|
13
|
+
subscribe(callback: (url: string) => void): void;
|
|
14
|
+
};
|
|
15
|
+
setMeta?: {
|
|
16
|
+
subscribe(callback: (meta: MetaFlags) => void): void;
|
|
17
|
+
};
|
|
18
|
+
onScroll?: {
|
|
19
|
+
send(offset: number): void;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface MetaFlags {
|
|
24
|
+
title: string;
|
|
25
|
+
description: string;
|
|
26
|
+
keywords: string;
|
|
27
|
+
url: string;
|
|
28
|
+
image: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Subscribes the clipboard port. A custom entry that boots its own app must
|
|
32
|
+
* call this too, or copy buttons silently do nothing.
|
|
33
|
+
*/
|
|
34
|
+
export declare function connectPorts(app: ElmApp): void;
|
|
35
|
+
export declare function connectExternal(app: ElmApp): void;
|
|
36
|
+
export declare function connectMeta(app: ElmApp): void;
|
|
37
|
+
export declare function connectScroll(app: ElmApp): void;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscribes the clipboard port. A custom entry that boots its own app must
|
|
3
|
+
* call this too, or copy buttons silently do nothing.
|
|
4
|
+
*/
|
|
5
|
+
export function connectPorts(app) {
|
|
6
|
+
app.ports?.copyToClipboard?.subscribe((text) => writeClipboard(text));
|
|
7
|
+
app.ports?.copyMarkdown?.subscribe((url) => {
|
|
8
|
+
fetch(url)
|
|
9
|
+
.then((response) => (response.ok ? response.text() : Promise.reject(response.status)))
|
|
10
|
+
.then(writeClipboard)
|
|
11
|
+
.catch(() => { });
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export function connectExternal(app) {
|
|
15
|
+
app.ports?.openExternal?.subscribe((url) => {
|
|
16
|
+
window.open(url, "_blank", "noopener");
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function connectMeta(app) {
|
|
20
|
+
app.ports?.setMeta?.subscribe(({ title, description, keywords, url, image }) => {
|
|
21
|
+
document.title = title;
|
|
22
|
+
const upsert = (name, content, attribute = "name") => {
|
|
23
|
+
if (!content)
|
|
24
|
+
return;
|
|
25
|
+
let element = document.head.querySelector(`meta[${attribute}="${name}"]`);
|
|
26
|
+
if (!element) {
|
|
27
|
+
element = document.createElement("meta");
|
|
28
|
+
element.setAttribute(attribute, name);
|
|
29
|
+
document.head.appendChild(element);
|
|
30
|
+
}
|
|
31
|
+
element.setAttribute("content", content);
|
|
32
|
+
};
|
|
33
|
+
const canonical = `${window.location.origin}${url || "/"}`;
|
|
34
|
+
let link = document.head.querySelector('link[rel="canonical"]');
|
|
35
|
+
if (!link) {
|
|
36
|
+
link = document.createElement("link");
|
|
37
|
+
link.setAttribute("rel", "canonical");
|
|
38
|
+
document.head.appendChild(link);
|
|
39
|
+
}
|
|
40
|
+
link.setAttribute("href", canonical);
|
|
41
|
+
upsert("description", description);
|
|
42
|
+
upsert("keywords", keywords);
|
|
43
|
+
upsert("og:title", title, "property");
|
|
44
|
+
upsert("og:description", description, "property");
|
|
45
|
+
upsert("og:url", canonical, "property");
|
|
46
|
+
upsert("og:image", `${window.location.origin}${image}`, "property");
|
|
47
|
+
upsert("twitter:title", title);
|
|
48
|
+
upsert("twitter:description", description);
|
|
49
|
+
upsert("twitter:image", `${window.location.origin}${image}`);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export function connectScroll(app) {
|
|
53
|
+
const port = app.ports?.onScroll;
|
|
54
|
+
if (!port)
|
|
55
|
+
return;
|
|
56
|
+
let queued = false;
|
|
57
|
+
const send = () => {
|
|
58
|
+
if (queued)
|
|
59
|
+
return;
|
|
60
|
+
queued = true;
|
|
61
|
+
requestAnimationFrame(() => {
|
|
62
|
+
queued = false;
|
|
63
|
+
port.send(window.scrollY);
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
window.addEventListener("scroll", send, { passive: true });
|
|
67
|
+
}
|
|
68
|
+
function writeClipboard(text) {
|
|
69
|
+
if (navigator.clipboard && window.isSecureContext) {
|
|
70
|
+
navigator.clipboard.writeText(text).catch(() => legacyCopy(text));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
legacyCopy(text);
|
|
74
|
+
}
|
|
75
|
+
function legacyCopy(text) {
|
|
76
|
+
const area = document.createElement("textarea");
|
|
77
|
+
area.value = text;
|
|
78
|
+
area.setAttribute("readonly", "");
|
|
79
|
+
area.style.position = "fixed";
|
|
80
|
+
area.style.top = "-1000px";
|
|
81
|
+
area.style.opacity = "0";
|
|
82
|
+
document.body.appendChild(area);
|
|
83
|
+
area.select();
|
|
84
|
+
try {
|
|
85
|
+
document.execCommand("copy");
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
}
|
|
89
|
+
document.body.removeChild(area);
|
|
90
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delegated anchor handling for prerendered pages. Elm only attaches its own
|
|
3
|
+
* interceptor to nodes it created, so the HTML from the build needs this.
|
|
4
|
+
*/
|
|
5
|
+
export function installLinkInterception() {
|
|
6
|
+
if (typeof document === "undefined")
|
|
7
|
+
return () => { };
|
|
8
|
+
const handler = (event) => {
|
|
9
|
+
if (event.defaultPrevented)
|
|
10
|
+
return;
|
|
11
|
+
if (event.button !== 0)
|
|
12
|
+
return;
|
|
13
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
|
|
14
|
+
return;
|
|
15
|
+
const target = event.target;
|
|
16
|
+
const anchor = target instanceof Element ? target.closest("a") : null;
|
|
17
|
+
if (!anchor)
|
|
18
|
+
return;
|
|
19
|
+
if (anchor.target && anchor.target !== "_self")
|
|
20
|
+
return;
|
|
21
|
+
if (anchor.hasAttribute("download"))
|
|
22
|
+
return;
|
|
23
|
+
const href = anchor.getAttribute("href");
|
|
24
|
+
if (!href)
|
|
25
|
+
return;
|
|
26
|
+
const url = new URL(anchor.href, window.location.href);
|
|
27
|
+
if (url.origin !== window.location.origin)
|
|
28
|
+
return;
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
window.history.pushState({}, "", url.pathname + url.search + url.hash);
|
|
31
|
+
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
32
|
+
};
|
|
33
|
+
document.addEventListener("click", handler);
|
|
34
|
+
return () => document.removeEventListener("click", handler);
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BootFlags } from "@charmland/gem-compiler/types";
|
|
2
|
+
import type { ElmApp } from "./ports.js";
|
|
3
|
+
export interface ElmProgram<App extends ElmApp = ElmApp> {
|
|
4
|
+
init(options: {
|
|
5
|
+
flags: BootFlags;
|
|
6
|
+
node: HTMLElement;
|
|
7
|
+
}): App;
|
|
8
|
+
}
|
|
9
|
+
export type { ElmApp, MetaFlags } from "./ports.js";
|
|
10
|
+
export { connectPorts } from "./ports.js";
|
|
11
|
+
export { installTabs } from "./tabs.js";
|
|
12
|
+
export declare function start<App extends ElmApp>(program: ElmProgram<App>, flags: BootFlags, node?: HTMLElement): App;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { connectColorScheme, prepareColorScheme, watchSystem } from "./color-scheme.js";
|
|
2
|
+
import { connectExternal, connectMeta, connectPorts, connectScroll } from "./ports.js";
|
|
3
|
+
import { installLinkInterception } from "./router.js";
|
|
4
|
+
import { installTabs, observeTabs } from "./tabs.js";
|
|
5
|
+
export { connectPorts } from "./ports.js";
|
|
6
|
+
export { installTabs } from "./tabs.js";
|
|
7
|
+
export function start(program, flags, node) {
|
|
8
|
+
const app = program.init({
|
|
9
|
+
flags: prepareColorScheme(flags),
|
|
10
|
+
node: node ?? document.body,
|
|
11
|
+
});
|
|
12
|
+
connectPorts(app);
|
|
13
|
+
connectColorScheme(app);
|
|
14
|
+
connectExternal(app);
|
|
15
|
+
connectMeta(app);
|
|
16
|
+
connectScroll(app);
|
|
17
|
+
watchSystem();
|
|
18
|
+
installLinkInterception();
|
|
19
|
+
installTabs();
|
|
20
|
+
observeTabs();
|
|
21
|
+
return app;
|
|
22
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tab behavior for structural `[data-tabs]` containers — code groups
|
|
3
|
+
* and grouped card bands. Elm renders the underline nav and the panels;
|
|
4
|
+
* this owns the switching and the sliding paint (the same `.tab-slide`
|
|
5
|
+
* the kit's tabs stylesheet styles).
|
|
6
|
+
*/
|
|
7
|
+
export declare function installTabs(root?: ParentNode): void;
|
|
8
|
+
/** Re-run the upgrade pass as Elm renders new pages and panels. */
|
|
9
|
+
export declare function observeTabs(): void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tab behavior for structural `[data-tabs]` containers — code groups
|
|
3
|
+
* and grouped card bands. Elm renders the underline nav and the panels;
|
|
4
|
+
* this owns the switching and the sliding paint (the same `.tab-slide`
|
|
5
|
+
* the kit's tabs stylesheet styles).
|
|
6
|
+
*/
|
|
7
|
+
export function installTabs(root = document) {
|
|
8
|
+
root.querySelectorAll("[data-tabs]").forEach((container) => {
|
|
9
|
+
if (container.dataset.tabsReady)
|
|
10
|
+
return;
|
|
11
|
+
const nav = container.querySelector("[data-tabs-nav]");
|
|
12
|
+
const buttons = nav ? Array.from(nav.querySelectorAll("button")) : [];
|
|
13
|
+
const panels = Array.from(container.querySelectorAll("[data-panel]"));
|
|
14
|
+
if (!nav || buttons.length === 0 || panels.length === 0)
|
|
15
|
+
return;
|
|
16
|
+
container.dataset.tabsReady = "true";
|
|
17
|
+
const slide = document.createElement("i");
|
|
18
|
+
slide.className = "tab-slide";
|
|
19
|
+
nav.prepend(slide);
|
|
20
|
+
const ink = (index) => {
|
|
21
|
+
const button = buttons[index];
|
|
22
|
+
if (!button)
|
|
23
|
+
return;
|
|
24
|
+
const navBox = nav.getBoundingClientRect();
|
|
25
|
+
const box = button.getBoundingClientRect();
|
|
26
|
+
slide.style.setProperty("--tab-x", `${box.left - navBox.left}px`);
|
|
27
|
+
slide.style.setProperty("--tab-y", `${box.top - navBox.top}px`);
|
|
28
|
+
slide.style.setProperty("--tab-w", `${box.width}px`);
|
|
29
|
+
slide.style.setProperty("--tab-h", `${box.height}px`);
|
|
30
|
+
};
|
|
31
|
+
const select = (index) => {
|
|
32
|
+
buttons.forEach((button, i) => button.classList.toggle("active", i === index));
|
|
33
|
+
panels.forEach((panel, i) => panel.toggleAttribute("hidden", i !== index));
|
|
34
|
+
ink(index);
|
|
35
|
+
};
|
|
36
|
+
buttons.forEach((button, index) => button.addEventListener("click", () => select(index)));
|
|
37
|
+
select(Math.max(0, buttons.findIndex((button) => button.classList.contains("active"))));
|
|
38
|
+
container.ink = ink;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
let tabsObserved = false;
|
|
42
|
+
/** Re-run the upgrade pass as Elm renders new pages and panels. */
|
|
43
|
+
export function observeTabs() {
|
|
44
|
+
if (tabsObserved || typeof document === "undefined")
|
|
45
|
+
return;
|
|
46
|
+
tabsObserved = true;
|
|
47
|
+
const rerun = () => installTabs(document);
|
|
48
|
+
const reink = () => {
|
|
49
|
+
document.querySelectorAll("[data-tabs]").forEach((container) => {
|
|
50
|
+
const ink = container.ink;
|
|
51
|
+
if (!ink)
|
|
52
|
+
return;
|
|
53
|
+
const buttons = Array.from(container.querySelectorAll("[data-tabs-nav] button"));
|
|
54
|
+
const index = buttons.findIndex((button) => button.classList.contains("active"));
|
|
55
|
+
if (index >= 0)
|
|
56
|
+
ink(index);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
new MutationObserver(() => requestAnimationFrame(rerun)).observe(document.body, {
|
|
60
|
+
childList: true,
|
|
61
|
+
subtree: true,
|
|
62
|
+
});
|
|
63
|
+
window.addEventListener("popstate", () => requestAnimationFrame(rerun));
|
|
64
|
+
window.addEventListener("resize", reink);
|
|
65
|
+
// The first ink lands before the webfonts swap in; the buttons keep
|
|
66
|
+
// their text but change width, which leaves the slide a few pixels
|
|
67
|
+
// off its tab. Re-measure once the faces are ready.
|
|
68
|
+
document.fonts?.ready.then(reink).catch(() => { });
|
|
69
|
+
}
|