@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.
Files changed (121) hide show
  1. package/LICENSE +177 -0
  2. package/NOTICE +13 -0
  3. package/README.md +24 -2
  4. package/assets/fonts/Hypography-Italic.woff2 +0 -0
  5. package/assets/fonts/Hypography-Regular.woff2 +0 -0
  6. package/assets/fonts/PPFraktionMono-Variable.ttf +0 -0
  7. package/assets/fonts/PPFraktionMonoItalic-Variable.ttf +0 -0
  8. package/assets/fonts/PPFraktionSans-Variable.ttf +0 -0
  9. package/assets/fonts/PPFraktionSansItalic-Variable.ttf +0 -0
  10. package/bin/gem-elm.js +3 -0
  11. package/dist/browser/boot.d.ts +10 -0
  12. package/dist/browser/boot.js +14 -0
  13. package/dist/browser/color-scheme.d.ts +9 -0
  14. package/dist/browser/color-scheme.js +76 -0
  15. package/dist/browser/ports.d.ts +37 -0
  16. package/dist/browser/ports.js +90 -0
  17. package/dist/browser/router.d.ts +5 -0
  18. package/dist/browser/router.js +35 -0
  19. package/dist/browser/runtime.d.ts +12 -0
  20. package/dist/browser/runtime.js +22 -0
  21. package/dist/browser/tabs.d.ts +9 -0
  22. package/dist/browser/tabs.js +69 -0
  23. package/dist/default/theme.css +4664 -0
  24. package/dist/default/theme.js +13652 -0
  25. package/dist/node/build.d.ts +16 -0
  26. package/dist/node/build.js +48 -0
  27. package/dist/node/cli.d.ts +2 -0
  28. package/dist/node/cli.js +21 -0
  29. package/elm.json +28 -0
  30. package/package.json +86 -4
  31. package/src/app/Gem/App.elm +1275 -0
  32. package/src/app/Gem/CharmSticker.elm +35 -0
  33. package/src/app/Gem/Components.elm +292 -0
  34. package/src/app/Gem/Main.elm +17 -0
  35. package/src/app/Gem/Ports.elm +32 -0
  36. package/src/app/Gem/Shell.elm +964 -0
  37. package/src/browser/theme.d.ts +1 -0
  38. package/src/core/Gem/Node.elm +219 -0
  39. package/src/core/Gem/Page.elm +409 -0
  40. package/src/core/Gem/Render.elm +472 -0
  41. package/src/core/Gem/Slots.elm +11 -0
  42. package/src/styles/docs.scss +1083 -0
  43. package/src/styles/fonts.scss +51 -0
  44. package/src/styles/gem.scss +362 -0
  45. package/src/styles/theme.scss +8 -0
  46. package/src/styles/ui/burger.scss +272 -0
  47. package/src/styles/ui/button.scss +350 -0
  48. package/src/styles/ui/charmtone.scss +70 -0
  49. package/src/styles/ui/controls-extra.scss +316 -0
  50. package/src/styles/ui/controls.scss +110 -0
  51. package/src/styles/ui/display.scss +359 -0
  52. package/src/styles/ui/dropdown.scss +341 -0
  53. package/src/styles/ui/form.scss +314 -0
  54. package/src/styles/ui/menu.scss +200 -0
  55. package/src/styles/ui/meter.scss +124 -0
  56. package/src/styles/ui/modal.scss +545 -0
  57. package/src/styles/ui/oauth.scss +50 -0
  58. package/src/styles/ui/page-nav.scss +63 -0
  59. package/src/styles/ui/reset.scss +111 -0
  60. package/src/styles/ui/scrollbar.scss +39 -0
  61. package/src/styles/ui/search.scss +164 -0
  62. package/src/styles/ui/sidebar.scss +229 -0
  63. package/src/styles/ui/squircle.scss +60 -0
  64. package/src/styles/ui/table.scss +97 -0
  65. package/src/styles/ui/theme.scss +132 -0
  66. package/src/styles/ui/toast.scss +587 -0
  67. package/src/styles/ui/toc.scss +128 -0
  68. package/src/styles/ui/typography.scss +21 -0
  69. package/src/styles/ui/ui.scss +33 -0
  70. package/src/ui/Ui/Badge.elm +51 -0
  71. package/src/ui/Ui/Banner.elm +97 -0
  72. package/src/ui/Ui/Burger.elm +259 -0
  73. package/src/ui/Ui/Button.elm +261 -0
  74. package/src/ui/Ui/Card.elm +32 -0
  75. package/src/ui/Ui/Cards.elm +15 -0
  76. package/src/ui/Ui/ChoiceGroup.elm +62 -0
  77. package/src/ui/Ui/CopyButton.elm +139 -0
  78. package/src/ui/Ui/Divider.elm +16 -0
  79. package/src/ui/Ui/Dropdown.elm +600 -0
  80. package/src/ui/Ui/Empty.elm +41 -0
  81. package/src/ui/Ui/ErrorBubble.elm +34 -0
  82. package/src/ui/Ui/Field.elm +45 -0
  83. package/src/ui/Ui/FormStatus.elm +32 -0
  84. package/src/ui/Ui/Icon.elm +381 -0
  85. package/src/ui/Ui/InlineForm.elm +51 -0
  86. package/src/ui/Ui/Input.elm +113 -0
  87. package/src/ui/Ui/KeyValue.elm +25 -0
  88. package/src/ui/Ui/ListRow.elm +67 -0
  89. package/src/ui/Ui/Loader.elm +32 -0
  90. package/src/ui/Ui/Logo/Charm.elm +21 -0
  91. package/src/ui/Ui/Logo/CharmMark.elm +32 -0
  92. package/src/ui/Ui/Logo/CharmSticker.elm +35 -0
  93. package/src/ui/Ui/Logo/Discord.elm +26 -0
  94. package/src/ui/Ui/Logo/GitHub.elm +21 -0
  95. package/src/ui/Ui/Logo/Google.elm +21 -0
  96. package/src/ui/Ui/Logo/Hexy.elm +29 -0
  97. package/src/ui/Ui/Logo/Hyper.elm +42 -0
  98. package/src/ui/Ui/Logo/Integration.elm +117 -0
  99. package/src/ui/Ui/Logo/Prism.elm +35 -0
  100. package/src/ui/Ui/Logos.elm +115 -0
  101. package/src/ui/Ui/Menu.elm +348 -0
  102. package/src/ui/Ui/Meter.elm +132 -0
  103. package/src/ui/Ui/Modal.elm +247 -0
  104. package/src/ui/Ui/Motion.elm +32 -0
  105. package/src/ui/Ui/NumberBox.elm +86 -0
  106. package/src/ui/Ui/OAuthButton.elm +39 -0
  107. package/src/ui/Ui/PageNav.elm +65 -0
  108. package/src/ui/Ui/Pager.elm +49 -0
  109. package/src/ui/Ui/Search.elm +396 -0
  110. package/src/ui/Ui/SearchBox.elm +78 -0
  111. package/src/ui/Ui/Section.elm +21 -0
  112. package/src/ui/Ui/Sidebar.elm +239 -0
  113. package/src/ui/Ui/Stat.elm +29 -0
  114. package/src/ui/Ui/Switch.elm +34 -0
  115. package/src/ui/Ui/Table.elm +89 -0
  116. package/src/ui/Ui/Tabs.elm +280 -0
  117. package/src/ui/Ui/ToC.elm +120 -0
  118. package/src/ui/Ui/Toast.elm +1145 -0
  119. package/src/ui/Ui/Toolbar.elm +31 -0
  120. package/src/ui/Ui/TwoStepConfirm.elm +159 -0
  121. package/src/ui/Ui/Typography.elm +33 -0
@@ -0,0 +1,472 @@
1
+ module Gem.Render exposing
2
+ ( Code
3
+ , CodeView
4
+ , blocks
5
+ , codeHead
6
+ , codeLines
7
+ , defaultCodeView
8
+ , inlines
9
+ , linesToText
10
+ )
11
+
12
+ {-| Nodes to Html.
13
+
14
+ The class names are the ones the kit's own docs site styles (`md-p`,
15
+ `code-block`, `code-inline`, `table-wrap`), so the default stylesheet is the
16
+ library's stylesheet and not a parallel one.
17
+
18
+ Components go through `Slots` so a theme decides what a tag means.
19
+
20
+ -}
21
+
22
+ import Gem.Slots exposing (Slots)
23
+ import Dict exposing (Dict)
24
+ import Gem.Node exposing (Block(..), Inline(..), Token)
25
+ import Html exposing (Html)
26
+ import Html.Attributes as A
27
+ import String
28
+
29
+
30
+ {-| A code block as the theme receives it. `text` is what the copy button
31
+ puts on the clipboard; `lines` is what it draws.
32
+ -}
33
+ type alias Code =
34
+ { lang : Maybe String
35
+ , title : Maybe String
36
+ , text : String
37
+ , lines : List (List Token)
38
+ }
39
+
40
+
41
+ {-| How a theme draws a code block. Supplying this is how a theme adds a copy
42
+ button, a line-number gutter, or a title bar: the node tree stays neutral.
43
+ -}
44
+ type alias CodeView msg =
45
+ Code -> Html msg
46
+
47
+
48
+ {-| Render a list of blocks.
49
+ -}
50
+ blocks : Slots msg -> CodeView msg -> List Block -> List (Html msg)
51
+ blocks slots codeView list =
52
+ List.map (block slots codeView) list
53
+
54
+
55
+ {-| Render a list of inlines.
56
+ -}
57
+ inlines : Slots msg -> List Inline -> List (Html msg)
58
+ inlines slots list =
59
+ List.map (inline slots) list
60
+
61
+
62
+ block : Slots msg -> CodeView msg -> Block -> Html msg
63
+ block slots codeView node =
64
+ case node of
65
+ Heading depth id children ->
66
+ heading depth id (inlines slots children)
67
+
68
+ Paragraph children ->
69
+ Html.p [ A.class "md-p" ] (inlines slots children)
70
+
71
+ CodeBlock code ->
72
+ codeView
73
+ { lang = code.lang
74
+ , title = code.title
75
+ , text = linesToText code.lines
76
+ , lines = code.lines
77
+ }
78
+
79
+ ListBlock list ->
80
+ listBlock slots codeView list
81
+
82
+ Quote children ->
83
+ Html.blockquote [ A.class "md-quote" ] (blocks slots codeView children)
84
+
85
+ Table table ->
86
+ tableView slots table
87
+
88
+ Rule ->
89
+ Html.hr [] []
90
+
91
+ Raw text ->
92
+ Html.p [ A.class "gem-raw" ] [ Html.text text ]
93
+
94
+ BlockComponent "code-group" _ children ->
95
+ codeGroupView codeView (codeBlocks children)
96
+
97
+ BlockComponent "ui-cards" props children ->
98
+ case cardGroups children of
99
+ Just groups ->
100
+ cardsGroupView slots codeView groups
101
+
102
+ Nothing ->
103
+ slots.component "ui-cards" props (blocks slots codeView children)
104
+
105
+ BlockComponent tag props children ->
106
+ slots.component tag props (blocks slots codeView children)
107
+
108
+
109
+ {-| The code panels inside a `<code-group>`: every direct child that is a
110
+ fenced code block, in source order.
111
+ -}
112
+ codeBlocks : List Block -> List Code
113
+ codeBlocks children =
114
+ List.filterMap
115
+ (\node ->
116
+ case node of
117
+ CodeBlock code ->
118
+ Just
119
+ { lang = code.lang
120
+ , title = code.title
121
+ , text = linesToText code.lines
122
+ , lines = code.lines
123
+ }
124
+
125
+ _ ->
126
+ Nothing
127
+ )
128
+ children
129
+
130
+
131
+ {-| A `<code-group>`: one underline tab per fenced panel, the first panel
132
+ visible. The switching itself is the theme boot's tab behavior — the
133
+ markup stays structural.
134
+ -}
135
+ codeGroupView : CodeView msg -> List Code -> Html msg
136
+ codeGroupView codeView codes =
137
+ Html.div
138
+ [ A.class "code-group", A.attribute "data-tabs" "" ]
139
+ ([ Html.nav
140
+ [ A.class "tabs underline", A.attribute "data-tabs-nav" "" ]
141
+ (List.indexedMap
142
+ (\index code ->
143
+ Html.button
144
+ [ A.type_ "button"
145
+ , A.classList [ ( "active", index == 0 ) ]
146
+ ]
147
+ [ Html.text (Maybe.withDefault (Maybe.withDefault "text" code.lang) code.title) ]
148
+ )
149
+ codes
150
+ )
151
+ ]
152
+ ++ List.indexedMap
153
+ (\index code ->
154
+ Html.div
155
+ ([ A.class "code-panel", A.attribute "data-panel" "" ]
156
+ ++ (if index > 0 then
157
+ [ A.attribute "hidden" "" ]
158
+
159
+ else
160
+ []
161
+ )
162
+ )
163
+ [ codeView { code | title = Nothing } ]
164
+ )
165
+ codes
166
+ )
167
+
168
+
169
+ {-| The groups inside a `<ui-cards>`: every labeled `<ui-cards-group>`
170
+ child, ignoring whitespace between them. `Nothing` when the band holds
171
+ no groups, so it renders as a plain grid.
172
+ -}
173
+ cardGroups : List Block -> Maybe (List { label : String, cards : List Block })
174
+ cardGroups children =
175
+ let
176
+ groupOf node =
177
+ case node of
178
+ BlockComponent "ui-cards-group" props inner ->
179
+ Just { label = Maybe.withDefault "" (Dict.get "label" props), cards = inner }
180
+
181
+ _ ->
182
+ Nothing
183
+
184
+ groups =
185
+ List.filterMap groupOf children
186
+ in
187
+ if List.isEmpty groups then
188
+ Nothing
189
+
190
+ else
191
+ Just groups
192
+
193
+
194
+ {-| A grouped `<ui-cards>`: one underline tab per set, the first set
195
+ visible. The switching is the theme boot's tab behavior.
196
+ -}
197
+ cardsGroupView :
198
+ Slots msg
199
+ -> CodeView msg
200
+ -> List { label : String, cards : List Block }
201
+ -> Html msg
202
+ cardsGroupView slots codeView groups =
203
+ Html.div
204
+ [ A.class "cards-root", A.attribute "data-tabs" "" ]
205
+ ([ Html.nav
206
+ [ A.class "tabs underline", A.attribute "data-tabs-nav" "" ]
207
+ (List.indexedMap
208
+ (\index group ->
209
+ Html.button
210
+ [ A.type_ "button"
211
+ , A.classList [ ( "active", index == 0 ) ]
212
+ ]
213
+ [ Html.text group.label ]
214
+ )
215
+ groups
216
+ )
217
+ ]
218
+ ++ List.indexedMap
219
+ (\index group ->
220
+ Html.div
221
+ ([ A.class "cards-group"
222
+ , A.attribute "data-panel" ""
223
+ , A.attribute "data-label" group.label
224
+ ]
225
+ ++ (if index > 0 then
226
+ [ A.attribute "hidden" "" ]
227
+
228
+ else
229
+ []
230
+ )
231
+ )
232
+ [ Html.div [ A.class "cards" ] (blocks slots codeView group.cards) ]
233
+ )
234
+ groups
235
+ )
236
+
237
+
238
+ inline : Slots msg -> Inline -> Html msg
239
+ inline slots node =
240
+ case node of
241
+ Text text ->
242
+ Html.text text
243
+
244
+ InlineCode text ->
245
+ Html.code [ A.class "code-inline" ] [ Html.text text ]
246
+
247
+ Strong children ->
248
+ Html.strong [] (inlines slots children)
249
+
250
+ Em children ->
251
+ Html.em [] (inlines slots children)
252
+
253
+ Del children ->
254
+ Html.del [] (inlines slots children)
255
+
256
+ Link link children ->
257
+ Html.a
258
+ (A.class "md-link"
259
+ :: A.href link.href
260
+ :: A.title (Maybe.withDefault "" link.title)
261
+ :: (if link.external then
262
+ [ A.target "_blank", A.rel "noreferrer" ]
263
+
264
+ else
265
+ []
266
+ )
267
+ )
268
+ (inlines slots children)
269
+
270
+ Image image ->
271
+ Html.img
272
+ [ A.class "md-image"
273
+ , A.src image.src
274
+ , A.alt image.alt
275
+ , A.title (Maybe.withDefault "" image.title)
276
+ ]
277
+ []
278
+
279
+ LineBreak ->
280
+ Html.br [] []
281
+
282
+ InlineComponent tag props children ->
283
+ slots.component tag props (inlines slots children)
284
+
285
+
286
+ heading : Int -> String -> List (Html msg) -> Html msg
287
+ heading depth id children =
288
+ let
289
+ attrs =
290
+ [ A.id id, A.class ("md-h" ++ String.fromInt (clamp 1 6 depth)) ]
291
+ in
292
+ case depth of
293
+ 1 ->
294
+ Html.h1 attrs children
295
+
296
+ 2 ->
297
+ Html.h2 attrs children
298
+
299
+ 3 ->
300
+ Html.h3 attrs children
301
+
302
+ 4 ->
303
+ Html.h4 attrs children
304
+
305
+ 5 ->
306
+ Html.h5 attrs children
307
+
308
+ _ ->
309
+ Html.h6 attrs children
310
+
311
+
312
+ {-| The plain code block: language label, no copy button. A theme that wants
313
+ copying supplies its own `CodeView`.
314
+ -}
315
+ defaultCodeView : CodeView msg
316
+ defaultCodeView code =
317
+ Html.div [ A.class "code-frame" ]
318
+ [ codeHead defaultLanguage code.lang code.title []
319
+ , Html.div [ A.class "code-block" ]
320
+ [ Html.pre [] [ Html.code [] (codeLines code.lines) ] ]
321
+ ]
322
+
323
+
324
+ {-| The fallback has no messages to spend on a `Ui.Button`, so the language
325
+ is the same compact secondary button markup, inert.
326
+ -}
327
+ defaultLanguage : String -> Html msg
328
+ defaultLanguage name =
329
+ Html.button
330
+ [ A.class "secondary compact code-lang"
331
+ , A.type_ "button"
332
+ , A.attribute "tabindex" "-1"
333
+ , A.attribute "aria-hidden" "true"
334
+ ]
335
+ [ Html.text name ]
336
+
337
+
338
+ {-| The code frame's head. A titled fence gets the full band: the file name,
339
+ the language as a qualifier, and the theme's controls at the right. An
340
+ untitled one gets no band at all — the controls float over the frame's top
341
+ corner and the language stays a quiet button beside them, so a plain fence
342
+ does not pay for an empty strip.
343
+ -}
344
+ codeHead : (String -> Html msg) -> Maybe String -> Maybe String -> List (Html msg) -> Html msg
345
+ codeHead language lang title actions =
346
+ case title of
347
+ Just label ->
348
+ Html.div [ A.class "code-head" ]
349
+ [ Html.div [ A.class "code-id" ]
350
+ [ Html.span [ A.class "code-title" ] [ Html.text label ]
351
+ , case lang of
352
+ Just name ->
353
+ language name
354
+
355
+ Nothing ->
356
+ Html.text ""
357
+ ]
358
+ , Html.div [ A.class "code-actions" ] actions
359
+ ]
360
+
361
+ Nothing ->
362
+ if lang == Nothing && List.isEmpty actions then
363
+ Html.text ""
364
+
365
+ else
366
+ Html.div [ A.class "code-float" ]
367
+ ([ case lang of
368
+ Just name ->
369
+ language name
370
+
371
+ Nothing ->
372
+ Html.text ""
373
+ ]
374
+ ++ (if List.isEmpty actions then
375
+ []
376
+
377
+ else
378
+ [ Html.div [ A.class "code-actions" ] actions ]
379
+ )
380
+ )
381
+
382
+
383
+ {-| Render the highlighted lines, one block-level span per line.
384
+ -}
385
+ codeLines : List (List Token) -> List (Html msg)
386
+ codeLines lines =
387
+ List.indexedMap
388
+ (\index line -> codeLine index (List.map token line))
389
+ lines
390
+
391
+
392
+ {-| The block's source, as the copy button hands it to the clipboard.
393
+ -}
394
+ linesToText : List (List Token) -> String
395
+ linesToText lines =
396
+ lines
397
+ |> List.map (\line -> line |> List.map .text |> String.concat)
398
+ |> String.join "\n"
399
+
400
+
401
+ codeLine : Int -> List (Html msg) -> Html msg
402
+ codeLine index rendered =
403
+ Html.span [ A.class "gem-code-line", A.attribute "data-line" (String.fromInt (index + 1)) ]
404
+ (if List.isEmpty rendered then
405
+ [ Html.text " " ]
406
+
407
+ else
408
+ rendered
409
+ )
410
+
411
+
412
+ token : Token -> Html msg
413
+ token value =
414
+ Html.span
415
+ ((case value.color of
416
+ Just color ->
417
+ [ A.style "color" color ]
418
+
419
+ Nothing ->
420
+ []
421
+ )
422
+ ++ (if value.italic then
423
+ [ A.style "font-style" "italic" ]
424
+
425
+ else
426
+ []
427
+ )
428
+ ++ (if value.bold then
429
+ [ A.style "font-weight" "620" ]
430
+
431
+ else
432
+ []
433
+ )
434
+ )
435
+ [ Html.text value.text ]
436
+
437
+
438
+ listBlock : Slots msg -> CodeView msg -> { ordered : Bool, start : Int, items : List (List Block) } -> Html msg
439
+ listBlock slots codeView list =
440
+ let
441
+ children =
442
+ List.map (\item -> Html.li [] (blocks slots codeView item)) list.items
443
+ in
444
+ if list.ordered then
445
+ Html.ol
446
+ (A.class "md-ol"
447
+ :: (if list.start /= 1 then
448
+ [ A.start list.start ]
449
+
450
+ else
451
+ []
452
+ )
453
+ )
454
+ children
455
+
456
+ else
457
+ Html.ul [ A.class "md-ul" ] children
458
+
459
+
460
+ tableView : Slots msg -> { head : List (List Inline), rows : List (List (List Inline)) } -> Html msg
461
+ tableView slots table =
462
+ Html.div [ A.class "table-wrap" ]
463
+ [ Html.table []
464
+ [ Html.thead []
465
+ [ Html.tr [] (List.map (\cell -> Html.th [] (inlines slots cell)) table.head) ]
466
+ , Html.tbody []
467
+ (List.map
468
+ (\row -> Html.tr [] (List.map (\cell -> Html.td [] (inlines slots cell)) row))
469
+ table.rows
470
+ )
471
+ ]
472
+ ]
@@ -0,0 +1,11 @@
1
+ module Gem.Slots exposing (Slots)
2
+
3
+ import Dict exposing (Dict)
4
+ import Html exposing (Html)
5
+
6
+
7
+ {-| A component renderer: tag, props, children.
8
+ -}
9
+ type alias Slots msg =
10
+ { component : String -> Dict String String -> List (Html msg) -> Html msg
11
+ }