@shortfuse/materialdesignweb 0.5.0 → 0.7.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/README.md +155 -77
- package/bin/generate-css.js +12 -0
- package/components/Badge.css +38 -0
- package/components/Badge.js +15 -0
- package/components/Body.css +14 -0
- package/components/Body.js +7 -0
- package/components/BottomAppBar.css +23 -0
- package/components/BottomAppBar.js +25 -0
- package/components/Box.css +31 -0
- package/components/Box.js +24 -0
- package/components/Button.css +147 -0
- package/components/Button.js +95 -0
- package/components/Button.md +61 -0
- package/components/Card.css +109 -0
- package/components/Card.js +82 -0
- package/components/Checkbox.css +89 -0
- package/components/Checkbox.js +59 -0
- package/components/CheckboxIcon.css +90 -0
- package/components/CheckboxIcon.js +41 -0
- package/components/Chip.css +35 -0
- package/components/Chip.js +22 -0
- package/components/Dialog.css +235 -0
- package/components/Dialog.js +327 -0
- package/components/DialogActions.js +13 -0
- package/components/Divider.css +41 -0
- package/components/Divider.js +13 -0
- package/components/ExtendedFab.css +24 -0
- package/components/ExtendedFab.js +11 -0
- package/components/Fab.css +23 -0
- package/components/Fab.js +26 -0
- package/components/FilterChip.css +80 -0
- package/components/FilterChip.js +51 -0
- package/components/Headline.css +14 -0
- package/components/Headline.js +33 -0
- package/components/Icon.css +76 -0
- package/components/Icon.js +174 -0
- package/components/IconButton.css +150 -0
- package/components/IconButton.js +65 -0
- package/components/Input.js +16 -0
- package/components/Label.css +14 -0
- package/components/Label.js +7 -0
- package/components/Layout.css +19 -0
- package/components/Layout.js +12 -0
- package/components/List.css +12 -0
- package/components/List.js +17 -0
- package/components/ListItem.css +224 -0
- package/components/ListItem.js +112 -0
- package/components/ListOption.css +34 -0
- package/components/ListOption.js +122 -0
- package/components/ListSelect.css +9 -0
- package/components/ListSelect.js +206 -0
- package/components/Menu.css +171 -0
- package/components/Menu.js +470 -0
- package/components/MenuItem.css +53 -0
- package/components/MenuItem.js +215 -0
- package/components/Nav.css +17 -0
- package/components/Nav.js +23 -0
- package/components/NavBar.css +34 -0
- package/components/NavBar.js +88 -0
- package/components/NavBarItem.css +41 -0
- package/components/NavBarItem.js +7 -0
- package/components/NavDrawer.css +31 -0
- package/components/NavDrawer.js +13 -0
- package/components/NavDrawerItem.css +42 -0
- package/components/NavDrawerItem.js +12 -0
- package/components/NavItem.css +181 -0
- package/components/NavItem.js +83 -0
- package/components/NavRail.css +47 -0
- package/components/NavRail.js +17 -0
- package/components/NavRailItem.css +25 -0
- package/components/NavRailItem.js +7 -0
- package/components/Option.js +91 -0
- package/components/Outline.css +138 -0
- package/components/Pane.css +261 -0
- package/components/Pane.js +21 -0
- package/components/Progress.css +75 -0
- package/components/Progress.js +67 -0
- package/components/ProgressCircle.css +226 -0
- package/components/ProgressLine.css +155 -0
- package/components/Radio.css +95 -0
- package/components/Radio.js +42 -0
- package/components/RadioIcon.css +73 -0
- package/components/RadioIcon.js +37 -0
- package/components/Ripple.css +74 -0
- package/components/Ripple.js +114 -0
- package/components/SegmentedButton.css +94 -0
- package/components/SegmentedButton.js +49 -0
- package/components/SegmentedButtonGroup.css +12 -0
- package/components/SegmentedButtonGroup.js +44 -0
- package/components/Select.css +52 -0
- package/components/Select.js +71 -0
- package/components/Shape.css +132 -0
- package/components/Shape.js +25 -0
- package/components/Slider.css +307 -0
- package/components/Slider.js +206 -0
- package/components/Snackbar.css +80 -0
- package/components/Snackbar.js +75 -0
- package/components/Surface.css +10 -0
- package/components/Surface.js +23 -0
- package/components/Switch.css +64 -0
- package/components/Switch.js +127 -0
- package/components/SwitchIcon.css +178 -0
- package/components/SwitchIcon.js +89 -0
- package/components/SwitchIconAnimations.css +89 -0
- package/components/Tab.css +85 -0
- package/components/Tab.js +103 -0
- package/components/TabContent.js +151 -0
- package/components/TabList.css +129 -0
- package/components/TabList.js +309 -0
- package/components/TabPanel.js +37 -0
- package/components/TextArea.css +93 -0
- package/components/TextArea.js +229 -0
- package/components/Title.css +14 -0
- package/components/Title.js +15 -0
- package/components/Tooltip.css +40 -0
- package/components/Tooltip.js +22 -0
- package/components/TopAppBar.css +209 -0
- package/components/TopAppBar.js +201 -0
- package/core/Composition.js +988 -0
- package/core/CustomElement.js +844 -0
- package/core/ICustomElement.d.ts +288 -0
- package/core/ICustomElement.js +1 -0
- package/core/css.js +51 -0
- package/core/customTypes.js +125 -0
- package/core/dom.js +56 -154
- package/core/identify.js +40 -0
- package/core/observe.js +410 -0
- package/core/template.js +121 -0
- package/core/typings.d.ts +135 -0
- package/core/typings.js +1 -0
- package/index.js +77 -0
- package/mixins/AriaReflectorMixin.js +42 -0
- package/mixins/AriaToolbarMixin.js +13 -0
- package/mixins/ControlMixin.css +57 -0
- package/mixins/ControlMixin.js +212 -0
- package/mixins/DensityMixin.css +40 -0
- package/mixins/DensityMixin.js +11 -0
- package/mixins/FlexableMixin.css +79 -0
- package/mixins/FlexableMixin.js +32 -0
- package/mixins/FormAssociatedMixin.js +170 -0
- package/mixins/InputMixin.js +335 -0
- package/mixins/KeyboardNavMixin.js +244 -0
- package/mixins/RTLObserverMixin.js +35 -0
- package/mixins/ResizeObserverMixin.js +38 -0
- package/mixins/RippleMixin.css +12 -0
- package/mixins/RippleMixin.js +115 -0
- package/mixins/ScrollListenerMixin.js +100 -0
- package/mixins/ShapeMixin.css +135 -0
- package/mixins/ShapeMixin.js +31 -0
- package/mixins/StateMixin.css +82 -0
- package/mixins/StateMixin.js +114 -0
- package/mixins/SurfaceMixin.css +150 -0
- package/mixins/SurfaceMixin.js +32 -0
- package/mixins/TextFieldMixin.css +657 -0
- package/mixins/TextFieldMixin.js +121 -0
- package/mixins/ThemableMixin.css +204 -0
- package/mixins/ThemableMixin.js +16 -0
- package/mixins/TooltipTriggerMixin.css +27 -0
- package/mixins/TooltipTriggerMixin.js +366 -0
- package/mixins/TouchTargetMixin.css +26 -0
- package/mixins/TouchTargetMixin.js +9 -0
- package/package.json +55 -49
- package/theming/index.js +473 -0
- package/theming/loader.js +24 -0
- package/utils/cli.js +11 -0
- package/utils/color_keywords.js +151 -0
- package/utils/hct/Cam16.js +298 -0
- package/utils/hct/CorePalette.js +84 -0
- package/utils/hct/Hct.js +172 -0
- package/utils/hct/Scheme.js +587 -0
- package/utils/hct/TonalPalette.js +68 -0
- package/utils/hct/ViewingConditions.js +136 -0
- package/utils/hct/blend.js +93 -0
- package/utils/hct/colorUtils.js +302 -0
- package/utils/hct/hctSolver.js +559 -0
- package/utils/hct/helper.js +182 -0
- package/utils/hct/mathUtils.js +153 -0
- package/utils/jsonMergePatch.js +100 -0
- package/utils/jsx-runtime.js +101 -0
- package/utils/popup.js +117 -0
- package/utils/svg.js +12 -0
- package/.browserslistrc +0 -4
- package/.eslintrc.json +0 -204
- package/.stylelintrc.json +0 -645
- package/.vscode/launch.json +0 -31
- package/.vscode/settings.json +0 -3
- package/.vscode/tasks.json +0 -32
- package/CHANGELOG.md +0 -36
- package/CODE_OF_CONDUCT.md +0 -46
- package/adapters/datatable/column.js +0 -176
- package/adapters/datatable/index.js +0 -960
- package/adapters/dom/index.js +0 -586
- package/adapters/list/index.js +0 -69
- package/adapters/search/index.js +0 -495
- package/components/appbar/_spec.scss +0 -165
- package/components/appbar/_theme.scss +0 -0
- package/components/appbar/index.scss +0 -2
- package/components/banner/_spec.scss +0 -83
- package/components/banner/_theme.scss +0 -0
- package/components/banner/index.scss +0 -2
- package/components/bottomnav/README.md +0 -85
- package/components/bottomnav/_spec.scss +0 -149
- package/components/bottomnav/_theme.scss +0 -0
- package/components/bottomnav/index.js +0 -117
- package/components/bottomnav/index.scss +0 -2
- package/components/bottomnav/item.js +0 -88
- package/components/button/README.md +0 -61
- package/components/button/_spec.scss +0 -162
- package/components/button/_theme.scss +0 -42
- package/components/button/index.eta +0 -32
- package/components/button/index.js +0 -43
- package/components/button/index.pug +0 -18
- package/components/button/index.scss +0 -2
- package/components/card/_spec.scss +0 -241
- package/components/card/_theme.scss +0 -0
- package/components/card/index.scss +0 -2
- package/components/chip/_spec.scss +0 -111
- package/components/chip/_theme.scss +0 -105
- package/components/chip/index.js +0 -23
- package/components/chip/index.scss +0 -2
- package/components/chip/item.js +0 -20
- package/components/datatable/_spec.scss +0 -225
- package/components/datatable/_theme.scss +0 -128
- package/components/datatable/cell.js +0 -44
- package/components/datatable/columnheader.js +0 -46
- package/components/datatable/index.js +0 -374
- package/components/datatable/index.scss +0 -2
- package/components/datatable/row.js +0 -48
- package/components/datatable/rowheader.js +0 -18
- package/components/dialog/_spec.scss +0 -203
- package/components/dialog/_theme.scss +0 -7
- package/components/dialog/index.js +0 -601
- package/components/dialog/index.scss +0 -2
- package/components/divider/_spec.scss +0 -11
- package/components/divider/_theme.scss +0 -0
- package/components/divider/index.scss +0 -2
- package/components/elevation/_spec.scss +0 -9
- package/components/elevation/_theme.scss +0 -0
- package/components/elevation/index.scss +0 -2
- package/components/fab/_spec.scss +0 -210
- package/components/fab/_theme.scss +0 -0
- package/components/fab/index.js +0 -99
- package/components/fab/index.scss +0 -2
- package/components/grid/_spec.scss +0 -169
- package/components/grid/_theme.scss +0 -0
- package/components/grid/index.scss +0 -2
- package/components/layout/_mixins.scss +0 -11
- package/components/layout/_spec.scss +0 -916
- package/components/layout/_theme.scss +0 -19
- package/components/layout/index.js +0 -454
- package/components/layout/index.scss +0 -2
- package/components/list/_spec.scss +0 -363
- package/components/list/_theme.scss +0 -102
- package/components/list/content.js +0 -106
- package/components/list/index.js +0 -256
- package/components/list/index.scss +0 -2
- package/components/list/item.js +0 -167
- package/components/list/secondary.js +0 -45
- package/components/menu/_spec.scss +0 -329
- package/components/menu/_theme.scss +0 -0
- package/components/menu/index.js +0 -705
- package/components/menu/index.scss +0 -2
- package/components/menu/item.js +0 -231
- package/components/progress/_spec.scss +0 -156
- package/components/progress/_theme.scss +0 -0
- package/components/progress/index.js +0 -36
- package/components/progress/index.scss +0 -2
- package/components/selection/_spec.scss +0 -376
- package/components/selection/_theme.scss +0 -134
- package/components/selection/index.eta +0 -60
- package/components/selection/index.js +0 -70
- package/components/selection/index.pug +0 -30
- package/components/selection/index.scss +0 -2
- package/components/selection/input.js +0 -54
- package/components/selection/radiogroup.js +0 -40
- package/components/slider/_spec.scss +0 -59
- package/components/slider/_theme.scss +0 -0
- package/components/slider/index.scss +0 -2
- package/components/snackbar/_spec.scss +0 -150
- package/components/snackbar/_theme.scss +0 -0
- package/components/snackbar/index.js +0 -338
- package/components/snackbar/index.scss +0 -2
- package/components/tab/_spec.scss +0 -220
- package/components/tab/_theme.scss +0 -0
- package/components/tab/content.js +0 -210
- package/components/tab/index.js +0 -257
- package/components/tab/index.scss +0 -2
- package/components/tab/item.js +0 -88
- package/components/tab/list.js +0 -196
- package/components/tab/panel.js +0 -54
- package/components/textfield/README.md +0 -179
- package/components/textfield/_spec.scss +0 -763
- package/components/textfield/_theme.scss +0 -264
- package/components/textfield/index.eta +0 -74
- package/components/textfield/index.js +0 -160
- package/components/textfield/index.pug +0 -30
- package/components/textfield/index.scss +0 -2
- package/components/tooltip/_spec.scss +0 -185
- package/components/tooltip/_theme.scss +0 -0
- package/components/tooltip/index.scss +0 -2
- package/components/type/_spec.scss +0 -227
- package/components/type/_theme.scss +0 -0
- package/components/type/index.scss +0 -2
- package/core/_breakpoint.scss +0 -189
- package/core/_elevation.scss +0 -78
- package/core/_length.scss +0 -8
- package/core/_motion.scss +0 -31
- package/core/_platform.scss +0 -12
- package/core/_type.scss +0 -128
- package/core/aria/attributes.js +0 -141
- package/core/aria/button.js +0 -49
- package/core/aria/keyboard.js +0 -92
- package/core/aria/rovingtabindex.js +0 -175
- package/core/aria/tab.js +0 -59
- package/core/document/index.js +0 -39
- package/core/overlay/_spec.scss +0 -28
- package/core/overlay/_theme.scss +0 -147
- package/core/overlay/index.js +0 -95
- package/core/overlay/index.scss +0 -2
- package/core/ripple/_spec.scss +0 -196
- package/core/ripple/_theme.scss +0 -20
- package/core/ripple/index.js +0 -286
- package/core/ripple/index.scss +0 -2
- package/core/theme/_aliases.scss +0 -15
- package/core/theme/_config.scss +0 -8
- package/core/theme/_functions.scss +0 -22
- package/core/theme/_palettes.scss +0 -405
- package/core/theme/_spec.scss +0 -0
- package/core/theme/_theme.scss +0 -268
- package/core/theme/index.js +0 -50
- package/core/theme/index.scss +0 -4
- package/core/throttler.js +0 -42
- package/core/transition/index.js +0 -465
- package/docs/_flex.scss +0 -28
- package/docs/_menuoptions.js +0 -183
- package/docs/_partials/_androidnavbar.eta +0 -5
- package/docs/_partials/_androidstatusbar.eta +0 -13
- package/docs/_partials/_appbar.eta +0 -27
- package/docs/_partials/_buttontest.eta +0 -31
- package/docs/_partials/_header.eta +0 -146
- package/docs/_partials/_navlistitem.eta +0 -16
- package/docs/_partials/_target.eta +0 -1
- package/docs/_sample-utils.js +0 -88
- package/docs/_storage.js +0 -33
- package/docs/docs.scss +0 -331
- package/docs/framework.scss +0 -26
- package/docs/index.eta +0 -12
- package/docs/index.js +0 -7
- package/docs/pages/appbar.eta +0 -108
- package/docs/pages/appbar.js +0 -0
- package/docs/pages/bottomnav.eta +0 -188
- package/docs/pages/bottomnav.js +0 -118
- package/docs/pages/button.eta +0 -124
- package/docs/pages/button.js +0 -224
- package/docs/pages/card.eta +0 -90
- package/docs/pages/card.js +0 -175
- package/docs/pages/chip.eta +0 -122
- package/docs/pages/chip.js +0 -80
- package/docs/pages/color.eta +0 -143
- package/docs/pages/color.js +0 -261
- package/docs/pages/datatable.eta +0 -323
- package/docs/pages/datatable.js +0 -160
- package/docs/pages/dialog.eta +0 -184
- package/docs/pages/dialog.js +0 -174
- package/docs/pages/dom.eta +0 -26
- package/docs/pages/dom.js +0 -140
- package/docs/pages/elevation.eta +0 -35
- package/docs/pages/elevation.js +0 -0
- package/docs/pages/fab.eta +0 -99
- package/docs/pages/fab.js +0 -43
- package/docs/pages/grid.eta +0 -135
- package/docs/pages/grid.js +0 -128
- package/docs/pages/layout.eta +0 -8
- package/docs/pages/layout.js +0 -0
- package/docs/pages/list.eta +0 -465
- package/docs/pages/list.js +0 -8
- package/docs/pages/menu.eta +0 -274
- package/docs/pages/menu.js +0 -213
- package/docs/pages/overlay.eta +0 -69
- package/docs/pages/overlay.js +0 -3
- package/docs/pages/progress.eta +0 -23
- package/docs/pages/progress.js +0 -12
- package/docs/pages/ripple.eta +0 -27
- package/docs/pages/ripple.js +0 -3
- package/docs/pages/search.eta +0 -242
- package/docs/pages/search.js +0 -226
- package/docs/pages/selection.eta +0 -107
- package/docs/pages/selection.js +0 -12
- package/docs/pages/slider.eta +0 -23
- package/docs/pages/slider.js +0 -0
- package/docs/pages/snackbar.eta +0 -83
- package/docs/pages/snackbar.js +0 -157
- package/docs/pages/tab.eta +0 -407
- package/docs/pages/tab.js +0 -152
- package/docs/pages/textfield.eta +0 -487
- package/docs/pages/textfield.js +0 -257
- package/docs/pages/tooltip.eta +0 -92
- package/docs/pages/tooltip.js +0 -0
- package/docs/pages/transition.eta +0 -117
- package/docs/pages/transition.js +0 -52
- package/docs/pages/type.eta +0 -31
- package/docs/pages/type.js +0 -0
- package/docs/postrender.js +0 -41
- package/docs/prerender.js +0 -16
- package/docs/pwa/_dialogs.eta +0 -143
- package/docs/pwa/_menus.eta +0 -16
- package/docs/pwa/pwa-prerender.js +0 -3
- package/docs/pwa/pwa.eta +0 -478
- package/docs/pwa/pwa.js +0 -298
- package/docs/pwa/pwa.scss +0 -31
- package/docs/themes/theme-colored.scss +0 -15
- package/docs/themes/theme-default.scss +0 -3
- package/index.scss +0 -27
- package/jsconfig.json +0 -16
- package/scripts/deploy-docs.sh +0 -9
- package/templates/index.eta +0 -2
- package/templates/index.pug +0 -3
- package/tsconfig.json +0 -16
- package/webpack.config.js +0 -304
package/theming/index.js
ADDED
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { COLOR_KEYWORDS } from '../utils/color_keywords.js';
|
|
2
|
+
import { getScheme } from '../utils/hct/helper.js';
|
|
3
|
+
import { svgToCSSURL } from '../utils/svg.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {Object} ThemeOptions
|
|
7
|
+
* @prop {string} [color]
|
|
8
|
+
* @prop {Iterable<[string,string?]>} [custom] Map()
|
|
9
|
+
* @prop {'auto'|'light'|'dark'} [lightness='auto']
|
|
10
|
+
* @return {string}
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} shape
|
|
15
|
+
* @return {string}
|
|
16
|
+
*/
|
|
17
|
+
function getShapeMaskSVG(shape) {
|
|
18
|
+
return [
|
|
19
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">',
|
|
20
|
+
`<defs><path id="a" d="${shape}"/></defs>`,
|
|
21
|
+
'<use href="#a" transform="scale(.666)"/>',
|
|
22
|
+
'<use href="#a" transform="translate(8) scale(.666)"/>',
|
|
23
|
+
'<use href="#a" transform="matrix(.666 0 0 .666 0 8)"/>',
|
|
24
|
+
'<use href="#a" transform="matrix(.666 0 0 .666 8 8)"/>',
|
|
25
|
+
'<path d="M8 0h8v24H8Z"/><path d="M0 8h24v8H0Z"/>',
|
|
26
|
+
'</svg>',
|
|
27
|
+
].join('');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} shape
|
|
32
|
+
* @param {'top-left'|'top-right'|'bottom-left'|'bottom-right'} corner
|
|
33
|
+
* @param {boolean} [convex]
|
|
34
|
+
* @return {string}
|
|
35
|
+
*/
|
|
36
|
+
function getShapeCornerSVGs(shape, corner, convex) {
|
|
37
|
+
const path = `<path ${[
|
|
38
|
+
`d="${shape}"`,
|
|
39
|
+
'vector-effect="non-scaling-stroke"',
|
|
40
|
+
`transform-origin="${corner.replace('-', ' ')}"`,
|
|
41
|
+
'stroke-linejoin="miter"',
|
|
42
|
+
'transform="scale(2)"',
|
|
43
|
+
`stroke-width="${convex ? 4 : 2}px"`,
|
|
44
|
+
'stroke="black"',
|
|
45
|
+
'fill="none"',
|
|
46
|
+
].join(' ')}/>`;
|
|
47
|
+
|
|
48
|
+
return [
|
|
49
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">',
|
|
50
|
+
convex
|
|
51
|
+
? [
|
|
52
|
+
'<mask id="m">',
|
|
53
|
+
'<rect x="0" y="0" width="24" height="24" fill="white"/>',
|
|
54
|
+
`<path d="${shape}" transform-origin="${corner.replace('-', ' ')}" transform="scale(2)"/>`,
|
|
55
|
+
'</mask>',
|
|
56
|
+
`<g mask="url(#m)">${path}</g>`,
|
|
57
|
+
].join('')
|
|
58
|
+
: path,
|
|
59
|
+
'</svg>',
|
|
60
|
+
].join('');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @return {string}
|
|
65
|
+
*/
|
|
66
|
+
function getShapeEdgesSVGs() {
|
|
67
|
+
return [
|
|
68
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">',
|
|
69
|
+
'<rect x="0" y="0" width="24" height="24" vector-effect="non-scaling-stroke" stroke-width="2px" stroke="black" fill="none"/>',
|
|
70
|
+
'</svg>',
|
|
71
|
+
].join('');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const CIRCLE_PATH = 'M0 12A12 12 0 1012 0 12 12 0 000 12Z';
|
|
75
|
+
// const SQUIRCLE_PATH = 'M12 24C17.2583 24 20.1815 24 22.0908 22.0908 24 20.1815 24 17.2583 24 12 24 6.7417 24 3.8185 22.0908 1.9092 20.1815-0 17.2583-0 12-0 6.7417-0 3.8185-0 1.9092 1.9092-0 3.8185-0 6.7417-0 12-0 17.2583-0 20.1815 1.9092 22.0908 3.8185 24 6.7417 24 12 24Z';
|
|
76
|
+
const DIAMOND_PATH = 'M 0 12 12 0 24 12 12 24 Z';
|
|
77
|
+
const SQUIRCLE_PATH = 'M12 24C17.2583 24 20.1815 24 22.0908 22.0908 24 20.1815 24 17.2583 24 12 24 6.7417 24 3.8185 22.0908 1.9092 20.1815-0 17.2583-0 12-0 6.7417-0 3.8185-0 1.9092 1.9092-0 3.8185-0 6.7417-0 12-0 17.2583-0 20.1815 1.9092 22.0908 3.8185 24 6.7417 24 12 24Z';
|
|
78
|
+
const HALF_NOTCH_PATH = 'M0 6H6V0H18V6H24V18H18V24H6V18H0Z';
|
|
79
|
+
|
|
80
|
+
const SHAPE_ROUNDED_DEFAULT = {
|
|
81
|
+
size: {
|
|
82
|
+
extraSmall: '4px',
|
|
83
|
+
small: '8px',
|
|
84
|
+
medium: '12px',
|
|
85
|
+
large: '16px',
|
|
86
|
+
extraLarge: '28px',
|
|
87
|
+
full: '32px',
|
|
88
|
+
},
|
|
89
|
+
/** @type {string?} */
|
|
90
|
+
mask: CIRCLE_PATH, // CIRCLE_PATH
|
|
91
|
+
convex: false,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const SHAPE_CUT_DEFAULT = {
|
|
95
|
+
...SHAPE_ROUNDED_DEFAULT,
|
|
96
|
+
size: {
|
|
97
|
+
extraSmall: '4px',
|
|
98
|
+
small: '8px',
|
|
99
|
+
medium: '12px',
|
|
100
|
+
large: '16px',
|
|
101
|
+
extraLarge: '28px',
|
|
102
|
+
full: '32px',
|
|
103
|
+
},
|
|
104
|
+
mask: DIAMOND_PATH,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const SHAPE_SQUIRCLE_DEFAULT = {
|
|
108
|
+
...SHAPE_ROUNDED_DEFAULT,
|
|
109
|
+
mask: SQUIRCLE_PATH,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const SP = 1 / 16;
|
|
113
|
+
|
|
114
|
+
const TYPOGRAPHY_DEFAULT = {
|
|
115
|
+
face: {
|
|
116
|
+
brand: '"Roboto Medium", Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI Variable Display", Helvetica, "Segoe UI", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',
|
|
117
|
+
plain: '"Roboto Regular", Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", Helvetica, "Segoe UI", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',
|
|
118
|
+
weight: {
|
|
119
|
+
regular: 400,
|
|
120
|
+
medium: 500,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
scale: {
|
|
124
|
+
display: {
|
|
125
|
+
large: {
|
|
126
|
+
fontFamily: 'var(--mdw-typeface__brand)',
|
|
127
|
+
lineHeight: 64,
|
|
128
|
+
fontSize: 57,
|
|
129
|
+
letterSpacing: 0,
|
|
130
|
+
weight: 'var(--mdw-typeface__weight-regular)',
|
|
131
|
+
},
|
|
132
|
+
medium: {
|
|
133
|
+
fontFamily: 'var(--mdw-typeface__brand)',
|
|
134
|
+
lineHeight: 52,
|
|
135
|
+
fontSize: 45,
|
|
136
|
+
letterSpacing: 0,
|
|
137
|
+
weight: 'var(--mdw-typeface__weight-regular)',
|
|
138
|
+
},
|
|
139
|
+
small: {
|
|
140
|
+
fontFamily: 'var(--mdw-typeface__brand)',
|
|
141
|
+
lineHeight: 44,
|
|
142
|
+
fontSize: 36,
|
|
143
|
+
letterSpacing: 0,
|
|
144
|
+
weight: 'var(--mdw-typeface__weight-regular)',
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
headline: {
|
|
148
|
+
large: {
|
|
149
|
+
fontFamily: 'var(--mdw-typeface__brand)',
|
|
150
|
+
lineHeight: 40,
|
|
151
|
+
fontSize: 32,
|
|
152
|
+
letterSpacing: 0,
|
|
153
|
+
weight: 'var(--mdw-typeface__weight-regular)',
|
|
154
|
+
},
|
|
155
|
+
medium: {
|
|
156
|
+
fontFamily: 'var(--mdw-typeface__brand)',
|
|
157
|
+
lineHeight: 36,
|
|
158
|
+
fontSize: 28,
|
|
159
|
+
letterSpacing: 0,
|
|
160
|
+
weight: 'var(--mdw-typeface__weight-regular)',
|
|
161
|
+
},
|
|
162
|
+
small: {
|
|
163
|
+
fontFamily: 'var(--mdw-typeface__brand)',
|
|
164
|
+
lineHeight: 32,
|
|
165
|
+
fontSize: 24,
|
|
166
|
+
letterSpacing: 0,
|
|
167
|
+
weight: 'var(--mdw-typeface__weight-regular)',
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
title: {
|
|
171
|
+
large: {
|
|
172
|
+
fontFamily: 'var(--mdw-typeface__brand)',
|
|
173
|
+
lineHeight: 28,
|
|
174
|
+
fontSize: 22,
|
|
175
|
+
letterSpacing: 0,
|
|
176
|
+
weight: 'var(--mdw-typeface__weight-medium)', // Figma style has regular
|
|
177
|
+
},
|
|
178
|
+
medium: {
|
|
179
|
+
fontFamily: 'var(--mdw-typeface__plain)',
|
|
180
|
+
lineHeight: 24,
|
|
181
|
+
fontSize: 16,
|
|
182
|
+
letterSpacing: 0.15,
|
|
183
|
+
weight: 'var(--mdw-typeface__weight-medium)',
|
|
184
|
+
},
|
|
185
|
+
small: {
|
|
186
|
+
fontFamily: 'var(--mdw-typeface__plain)',
|
|
187
|
+
lineHeight: 20,
|
|
188
|
+
fontSize: 14,
|
|
189
|
+
letterSpacing: 0.1,
|
|
190
|
+
weight: 'var(--mdw-typeface__weight-medium)',
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
label: {
|
|
194
|
+
large: {
|
|
195
|
+
fontFamily: 'var(--mdw-typeface__plain)',
|
|
196
|
+
lineHeight: 20,
|
|
197
|
+
fontSize: 14,
|
|
198
|
+
letterSpacing: 0.1,
|
|
199
|
+
weight: 'var(--mdw-typeface__weight-medium)',
|
|
200
|
+
},
|
|
201
|
+
medium: {
|
|
202
|
+
fontFamily: 'var(--mdw-typeface__plain)',
|
|
203
|
+
lineHeight: 16,
|
|
204
|
+
fontSize: 12,
|
|
205
|
+
letterSpacing: 0.5,
|
|
206
|
+
weight: 'var(--mdw-typeface__weight-medium)',
|
|
207
|
+
},
|
|
208
|
+
small: {
|
|
209
|
+
fontFamily: 'var(--mdw-typeface__plain)',
|
|
210
|
+
lineHeight: 16,
|
|
211
|
+
fontSize: 11,
|
|
212
|
+
letterSpacing: 0.5,
|
|
213
|
+
weight: 'var(--mdw-typeface__weight-medium)',
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
body: {
|
|
217
|
+
large: {
|
|
218
|
+
fontFamily: 'var(--mdw-typeface__plain)',
|
|
219
|
+
lineHeight: 24,
|
|
220
|
+
fontSize: 16,
|
|
221
|
+
letterSpacing: 0.5, // Figma text has 0.15
|
|
222
|
+
weight: 'var(--mdw-typeface__weight-regular)',
|
|
223
|
+
},
|
|
224
|
+
medium: {
|
|
225
|
+
fontFamily: 'var(--mdw-typeface__plain)',
|
|
226
|
+
lineHeight: 20,
|
|
227
|
+
fontSize: 14,
|
|
228
|
+
letterSpacing: 0.25,
|
|
229
|
+
weight: 'var(--mdw-typeface__weight-regular)',
|
|
230
|
+
},
|
|
231
|
+
small: {
|
|
232
|
+
fontFamily: 'var(--mdw-typeface__brand)',
|
|
233
|
+
lineHeight: 16,
|
|
234
|
+
fontSize: 12,
|
|
235
|
+
letterSpacing: 0.4,
|
|
236
|
+
weight: 'var(--mdw-typeface__weight-regular)',
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* @param {typeof TYPOGRAPHY_DEFAULT} config
|
|
244
|
+
* @return {string}
|
|
245
|
+
*/
|
|
246
|
+
export function generateTypographyCSS(config = TYPOGRAPHY_DEFAULT) {
|
|
247
|
+
return /* css */ `
|
|
248
|
+
:root {
|
|
249
|
+
--mdw-typeface__brand: ${config.face.brand};
|
|
250
|
+
--mdw-typeface__weight-regular: ${config.face.weight.regular};
|
|
251
|
+
--mdw-typeface__weight-medium: ${config.face.weight.medium};
|
|
252
|
+
--mdw-typeface__plain: ${config.face.plain};
|
|
253
|
+
|
|
254
|
+
--mdw-typescale__display-large__font-family: ${config.scale.display.large.fontFamily};
|
|
255
|
+
--mdw-typescale__display-large__line-height: calc(${config.scale.display.large.lineHeight} * 0.0625rem);
|
|
256
|
+
--mdw-typescale__display-large__font-size: calc(${config.scale.display.large.fontSize} * 0.0625rem);
|
|
257
|
+
--mdw-typescale__display-large__letter-spacing: calc(${config.scale.display.large.letterSpacing} * 0.0625rem);
|
|
258
|
+
--mdw-typescale__display-large__font-weight: ${config.scale.display.large.weight};
|
|
259
|
+
|
|
260
|
+
--mdw-typescale__display-medium__font-family: ${config.scale.display.medium.fontFamily};
|
|
261
|
+
--mdw-typescale__display-medium__line-height: calc(${config.scale.display.medium.lineHeight} * 0.0625rem);
|
|
262
|
+
--mdw-typescale__display-medium__font-size: calc(${config.scale.display.medium.fontSize} * 0.0625rem);
|
|
263
|
+
--mdw-typescale__display-medium__letter-spacing: calc(${config.scale.display.medium.letterSpacing} * 0.0625rem);
|
|
264
|
+
--mdw-typescale__display-medium__font-weight: ${config.scale.display.medium.weight};
|
|
265
|
+
|
|
266
|
+
--mdw-typescale__display-small__font-family: ${config.scale.display.small.fontFamily};
|
|
267
|
+
--mdw-typescale__display-small__line-height: calc(${config.scale.display.small.lineHeight} * 0.0625rem);
|
|
268
|
+
--mdw-typescale__display-small__font-size: calc(${config.scale.display.small.fontSize} * 0.0625rem);
|
|
269
|
+
--mdw-typescale__display-small__letter-spacing: calc(${config.scale.display.small.letterSpacing} * 0.0625rem);
|
|
270
|
+
--mdw-typescale__display-small__font-weight: ${config.scale.display.small.weight};
|
|
271
|
+
|
|
272
|
+
--mdw-typescale__headline-large__font-family: ${config.scale.headline.large.fontFamily};
|
|
273
|
+
--mdw-typescale__headline-large__line-height: calc(${config.scale.headline.large.lineHeight} * 0.0625rem);
|
|
274
|
+
--mdw-typescale__headline-large__font-size: calc(${config.scale.headline.large.fontSize} * 0.0625rem);
|
|
275
|
+
--mdw-typescale__headline-large__letter-spacing: calc(${config.scale.headline.large.letterSpacing} * 0.0625rem);
|
|
276
|
+
--mdw-typescale__headline-large__font-weight: ${config.scale.headline.large.weight};
|
|
277
|
+
|
|
278
|
+
--mdw-typescale__headline-medium__font-family: ${config.scale.headline.medium.fontFamily};
|
|
279
|
+
--mdw-typescale__headline-medium__line-height: calc(${config.scale.headline.medium.lineHeight} * 0.0625rem);
|
|
280
|
+
--mdw-typescale__headline-medium__font-size: calc(${config.scale.headline.medium.fontSize} * 0.0625rem);
|
|
281
|
+
--mdw-typescale__headline-medium__letter-spacing: calc(${config.scale.headline.medium.letterSpacing} * 0.0625rem);
|
|
282
|
+
--mdw-typescale__headline-medium__font-weight: ${config.scale.headline.medium.weight};
|
|
283
|
+
|
|
284
|
+
--mdw-typescale__headline-small__font-family: ${config.scale.headline.small.fontFamily};
|
|
285
|
+
--mdw-typescale__headline-small__line-height: calc(${config.scale.headline.small.lineHeight} * 0.0625rem);
|
|
286
|
+
--mdw-typescale__headline-small__font-size: calc(${config.scale.headline.small.fontSize} * 0.0625rem);
|
|
287
|
+
--mdw-typescale__headline-small__letter-spacing: calc(${config.scale.headline.small.letterSpacing} * 0.0625rem);
|
|
288
|
+
--mdw-typescale__headline-small__font-weight: ${config.scale.headline.small.weight};
|
|
289
|
+
|
|
290
|
+
--mdw-typescale__title-large__font-family: ${config.scale.title.large.fontFamily};
|
|
291
|
+
--mdw-typescale__title-large__line-height: calc(${config.scale.title.large.lineHeight} * 0.0625rem);
|
|
292
|
+
--mdw-typescale__title-large__font-size: calc(${config.scale.title.large.fontSize} * 0.0625rem);
|
|
293
|
+
--mdw-typescale__title-large__letter-spacing: calc(${config.scale.title.large.letterSpacing} * 0.0625rem);
|
|
294
|
+
--mdw-typescale__title-large__font-weight: ${config.scale.title.large.weight};
|
|
295
|
+
|
|
296
|
+
--mdw-typescale__title-medium__font-family: ${config.scale.title.medium.fontFamily};
|
|
297
|
+
--mdw-typescale__title-medium__line-height: calc(${config.scale.title.medium.lineHeight} * 0.0625rem);
|
|
298
|
+
--mdw-typescale__title-medium__font-size: calc(${config.scale.title.medium.fontSize} * 0.0625rem);
|
|
299
|
+
--mdw-typescale__title-medium__letter-spacing: calc(${config.scale.title.medium.letterSpacing} * 0.0625rem);
|
|
300
|
+
--mdw-typescale__title-medium__font-weight: ${config.scale.title.medium.weight};
|
|
301
|
+
|
|
302
|
+
--mdw-typescale__title-small__font-family: ${config.scale.title.small.fontFamily};
|
|
303
|
+
--mdw-typescale__title-small__line-height: calc(${config.scale.title.small.lineHeight} * 0.0625rem);
|
|
304
|
+
--mdw-typescale__title-small__font-size: calc(${config.scale.title.small.fontSize} * 0.0625rem);
|
|
305
|
+
--mdw-typescale__title-small__letter-spacing: calc(${config.scale.title.small.letterSpacing} * 0.0625rem);
|
|
306
|
+
--mdw-typescale__title-small__font-weight: ${config.scale.title.small.weight};
|
|
307
|
+
|
|
308
|
+
--mdw-typescale__label-large__font-family: ${config.scale.label.large.fontFamily};
|
|
309
|
+
--mdw-typescale__label-large__line-height: calc(${config.scale.label.large.lineHeight} * 0.0625rem);
|
|
310
|
+
--mdw-typescale__label-large__font-size: calc(${config.scale.label.large.fontSize} * 0.0625rem);
|
|
311
|
+
--mdw-typescale__label-large__letter-spacing: calc(${config.scale.label.large.letterSpacing} * 0.0625rem);
|
|
312
|
+
--mdw-typescale__label-large__font-weight: ${config.scale.label.large.weight};
|
|
313
|
+
|
|
314
|
+
--mdw-typescale__label-medium__font-family: ${config.scale.label.medium.fontFamily};
|
|
315
|
+
--mdw-typescale__label-medium__line-height: calc(${config.scale.label.medium.lineHeight} * 0.0625rem);
|
|
316
|
+
--mdw-typescale__label-medium__font-size: calc(${config.scale.label.medium.fontSize} * 0.0625rem);
|
|
317
|
+
--mdw-typescale__label-medium__letter-spacing: calc(${config.scale.label.medium.letterSpacing} * 0.0625rem);
|
|
318
|
+
--mdw-typescale__label-medium__font-weight: ${config.scale.label.medium.weight};
|
|
319
|
+
|
|
320
|
+
--mdw-typescale__label-small__font-family: ${config.scale.label.small.fontFamily};
|
|
321
|
+
--mdw-typescale__label-small__line-height: calc(${config.scale.label.small.lineHeight} * 0.0625rem);
|
|
322
|
+
--mdw-typescale__label-small__font-size: calc(${config.scale.label.small.fontSize} * 0.0625rem);
|
|
323
|
+
--mdw-typescale__label-small__letter-spacing: calc(${config.scale.label.small.letterSpacing} * 0.0625rem);
|
|
324
|
+
--mdw-typescale__label-small__font-weight: ${config.scale.label.small.weight};
|
|
325
|
+
|
|
326
|
+
--mdw-typescale__body-large__font-family: ${config.scale.body.large.fontFamily};
|
|
327
|
+
--mdw-typescale__body-large__line-height: calc(${config.scale.body.large.lineHeight} * 0.0625rem);
|
|
328
|
+
--mdw-typescale__body-large__font-size: calc(${config.scale.body.large.fontSize} * 0.0625rem);
|
|
329
|
+
--mdw-typescale__body-large__letter-spacing: calc(${config.scale.body.large.letterSpacing} * 0.0625rem);
|
|
330
|
+
--mdw-typescale__body-large__font-weight: ${config.scale.body.large.weight};
|
|
331
|
+
|
|
332
|
+
--mdw-typescale__body-medium__font-family: ${config.scale.body.medium.fontFamily};
|
|
333
|
+
--mdw-typescale__body-medium__line-height: calc(${config.scale.body.medium.lineHeight} * 0.0625rem);
|
|
334
|
+
--mdw-typescale__body-medium__font-size: calc(${config.scale.body.medium.fontSize} * 0.0625rem);
|
|
335
|
+
--mdw-typescale__body-medium__letter-spacing: calc(${config.scale.body.medium.letterSpacing} * 0.0625rem);
|
|
336
|
+
--mdw-typescale__body-medium__font-weight: ${config.scale.body.medium.weight};
|
|
337
|
+
|
|
338
|
+
--mdw-typescale__body-small__font-family: ${config.scale.body.small.fontFamily};
|
|
339
|
+
--mdw-typescale__body-small__line-height: calc(${config.scale.body.small.lineHeight} * 0.0625rem);
|
|
340
|
+
--mdw-typescale__body-small__font-size: calc(${config.scale.body.small.fontSize} * 0.0625rem);
|
|
341
|
+
--mdw-typescale__body-small__letter-spacing: calc(${config.scale.body.small.letterSpacing} * 0.0625rem);
|
|
342
|
+
--mdw-typescale__body-small__font-weight: ${config.scale.body.small.weight};
|
|
343
|
+
}`;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** @return {string} */
|
|
347
|
+
export function generateTypographyGlobalCSS() {
|
|
348
|
+
return /* css */ `
|
|
349
|
+
:root {${['display', 'headline', 'title', 'label', 'body']
|
|
350
|
+
.map((style) => ['large', 'medium', 'small']
|
|
351
|
+
.map((size) => `--mdw-typescale__${style}-${size}__font: ${
|
|
352
|
+
[
|
|
353
|
+
`var(--mdw-typescale__${style}-${size}__font-weight)`,
|
|
354
|
+
`var(--mdw-typescale__${style}-${size}__font-size)/var(--mdw-typescale__${style}-${size}__line-height)`,
|
|
355
|
+
`var(--mdw-typescale__${style}-${size}__font-family)`,
|
|
356
|
+
].join(' ')
|
|
357
|
+
};`).join('\n'))
|
|
358
|
+
.join('\n')}}`;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* @param {typeof SHAPE_ROUNDED_DEFAULT} config
|
|
363
|
+
* @return {string}
|
|
364
|
+
*/
|
|
365
|
+
export function generateShapeCSS(config = SHAPE_ROUNDED_DEFAULT) {
|
|
366
|
+
return /* css */`
|
|
367
|
+
:root {
|
|
368
|
+
--mdw-shape__extra-small: ${config.size.extraSmall};
|
|
369
|
+
--mdw-shape__small: ${config.size.small};
|
|
370
|
+
--mdw-shape__medium: ${config.size.medium};
|
|
371
|
+
--mdw-shape__large: ${config.size.large};
|
|
372
|
+
--mdw-shape__extra-large: ${config.size.extraLarge};
|
|
373
|
+
--mdw-shape__full: ${config.size.full};
|
|
374
|
+
--mdw-shape__rounded: ${config.mask ? '0' : '1'};
|
|
375
|
+
--mdw-shape__outline__background: ${config.mask ? 'currentColor' : 'transparent'};
|
|
376
|
+
--mdw-shape__convex: ${config.convex ? '1' : '0'};
|
|
377
|
+
--mdw-shape__mask-border-source: ${config.mask ? svgToCSSURL(getShapeMaskSVG(config.mask)) : 'none'};
|
|
378
|
+
--mdw-shape__mask-image__top-left: ${config.mask ? svgToCSSURL(getShapeCornerSVGs(config.mask, 'top-left')) : 'none'};
|
|
379
|
+
--mdw-shape__mask-image__top-right: ${config.mask ? svgToCSSURL(getShapeCornerSVGs(config.mask, 'top-right')) : 'none'};
|
|
380
|
+
--mdw-shape__mask-image__bottom-right: ${config.mask ? svgToCSSURL(getShapeCornerSVGs(config.mask, 'bottom-right')) : 'none'};
|
|
381
|
+
--mdw-shape__mask-image__bottom-left: ${config.mask ? svgToCSSURL(getShapeCornerSVGs(config.mask, 'bottom-left')) : 'none'};
|
|
382
|
+
--mdw-shape__mask-image__edges: ${config.mask ? svgToCSSURL(getShapeEdgesSVGs()) : 'none'};
|
|
383
|
+
}
|
|
384
|
+
`;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* @param {string} content
|
|
389
|
+
* @return {HTMLStyleElement } element
|
|
390
|
+
*/
|
|
391
|
+
function addStyle(content) {
|
|
392
|
+
const element = document.createElement('style');
|
|
393
|
+
element.textContent = content;
|
|
394
|
+
document.head.append(element);
|
|
395
|
+
return element;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* @param {ThemeOptions} options
|
|
400
|
+
* @return {string}
|
|
401
|
+
*/
|
|
402
|
+
export function generateColorCSS({ color = '#6750A4', custom = [], lightness = 'light' }) {
|
|
403
|
+
/** @type {[string,string][]} */
|
|
404
|
+
const parsedColors = [...custom]
|
|
405
|
+
.map(([name, hex]) => [name, COLOR_KEYWORDS.get(hex) || hex || COLOR_KEYWORDS.get(name)]);
|
|
406
|
+
const scheme = getScheme(color, parsedColors);
|
|
407
|
+
if (lightness === 'dark') {
|
|
408
|
+
return scheme.dark;
|
|
409
|
+
}
|
|
410
|
+
return scheme.light;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* @param {ThemeOptions} options
|
|
415
|
+
* @return {void}
|
|
416
|
+
*/
|
|
417
|
+
export function setupTheme({ color = '#6750A4', custom = [], lightness = 'auto' }) {
|
|
418
|
+
/** @type {[string,string][]} */
|
|
419
|
+
const parsedColors = [...custom]
|
|
420
|
+
.map(([name, hex]) => [name, COLOR_KEYWORDS.get(hex) || hex || COLOR_KEYWORDS.get(name)]);
|
|
421
|
+
const scheme = getScheme(color, parsedColors);
|
|
422
|
+
if (lightness === 'dark') {
|
|
423
|
+
addStyle(scheme.dark);
|
|
424
|
+
} else {
|
|
425
|
+
addStyle(scheme.light);
|
|
426
|
+
if (lightness !== 'light') {
|
|
427
|
+
addStyle(scheme.dark).media = '(prefers-color-scheme:dark)';
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
addStyle(generateShapeCSS());
|
|
431
|
+
addStyle(generateTypographyCSS());
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* @param {URLSearchParams} searchParams
|
|
436
|
+
* @return {ThemeOptions}
|
|
437
|
+
*/
|
|
438
|
+
export function themeOptionsFromSearchParams(searchParams) {
|
|
439
|
+
const color = searchParams.get('color') || '#6750A4';
|
|
440
|
+
|
|
441
|
+
/** @type {[string,string?][]} */
|
|
442
|
+
const custom = searchParams.getAll('custom')
|
|
443
|
+
.flatMap((c) => c.split(','))
|
|
444
|
+
.map((c) => c.split(':'));
|
|
445
|
+
|
|
446
|
+
const lightness = searchParams.get('lightness') ?? 'auto';
|
|
447
|
+
return { color, custom, lightness };
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* @param {ThemeOptions} options
|
|
452
|
+
* @return {string}
|
|
453
|
+
*/
|
|
454
|
+
export function generateThemeCSS({ color = '#6750A4', custom = [], lightness = 'auto' }) {
|
|
455
|
+
const shapeCss = generateShapeCSS();
|
|
456
|
+
const typographyCss = generateTypographyCSS();
|
|
457
|
+
let colorCss;
|
|
458
|
+
if (lightness === 'light' || lightness === 'dark') {
|
|
459
|
+
colorCss = generateColorCSS({ color, custom, lightness });
|
|
460
|
+
} else {
|
|
461
|
+
colorCss = `
|
|
462
|
+
${generateColorCSS({ color, custom, lightness: 'light' })}
|
|
463
|
+
@media (prefers-color-scheme:dark) {
|
|
464
|
+
:root { color-scheme: dark; }
|
|
465
|
+
${generateColorCSS({ color, custom, lightness: 'dark' })}
|
|
466
|
+
}`;
|
|
467
|
+
}
|
|
468
|
+
return [
|
|
469
|
+
shapeCss,
|
|
470
|
+
typographyCss,
|
|
471
|
+
colorCss,
|
|
472
|
+
].join('\n');
|
|
473
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { css } from '../core/template.js';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
generateLayoutGlobalCSS,
|
|
5
|
+
generateThemeCSS,
|
|
6
|
+
generateTypographyGlobalCSS,
|
|
7
|
+
themeOptionsFromSearchParams,
|
|
8
|
+
} from './index.js';
|
|
9
|
+
|
|
10
|
+
const rules = [
|
|
11
|
+
generateThemeCSS(themeOptionsFromSearchParams(new URL(import.meta.url).searchParams)),
|
|
12
|
+
generateTypographyGlobalCSS(),
|
|
13
|
+
generateLayoutGlobalCSS(),
|
|
14
|
+
].join('\n');
|
|
15
|
+
|
|
16
|
+
const parsed = css`${rules}`;
|
|
17
|
+
if (parsed instanceof HTMLStyleElement) {
|
|
18
|
+
document.head.append(parsed);
|
|
19
|
+
} else {
|
|
20
|
+
document.adoptedStyleSheets = [
|
|
21
|
+
...document.adoptedStyleSheets,
|
|
22
|
+
parsed,
|
|
23
|
+
];
|
|
24
|
+
}
|
package/utils/cli.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** @return {URLSearchParams} */
|
|
2
|
+
export function getSearchParams() {
|
|
3
|
+
const searchParams = new URLSearchParams();
|
|
4
|
+
for (const args of process.argv.slice(2)) {
|
|
5
|
+
if (!args.startsWith('--')) continue;
|
|
6
|
+
const [key, ...values] = args.split('=');
|
|
7
|
+
const value = values ? values.join('=') : '';
|
|
8
|
+
searchParams.append(key.slice(2), value);
|
|
9
|
+
}
|
|
10
|
+
return searchParams;
|
|
11
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/color_keywords
|
|
2
|
+
export const COLOR_KEYWORDS = new Map([
|
|
3
|
+
['black', '#000000'],
|
|
4
|
+
['silver', '#c0c0c0'],
|
|
5
|
+
['gray', '#808080'],
|
|
6
|
+
['white', '#ffffff'],
|
|
7
|
+
['maroon', '#800000'],
|
|
8
|
+
['red', '#ff0000'],
|
|
9
|
+
['purple', '#800080'],
|
|
10
|
+
['fuchsia', '#ff00ff'],
|
|
11
|
+
['green', '#008000'],
|
|
12
|
+
['lime', '#00ff00'],
|
|
13
|
+
['olive', '#808000'],
|
|
14
|
+
['yellow', '#ffff00'],
|
|
15
|
+
['navy', '#000080'],
|
|
16
|
+
['blue', '#0000ff'],
|
|
17
|
+
['teal', '#008080'],
|
|
18
|
+
['aqua', '#00ffff'],
|
|
19
|
+
['orange', '#ffa500'],
|
|
20
|
+
['aliceblue', '#f0f8ff'],
|
|
21
|
+
['antiquewhite', '#faebd7'],
|
|
22
|
+
['aquamarine', '#7fffd4'],
|
|
23
|
+
['azure', '#f0ffff'],
|
|
24
|
+
['beige', '#f5f5dc'],
|
|
25
|
+
['bisque', '#ffe4c4'],
|
|
26
|
+
['blanchedalmond', '#ffebcd'],
|
|
27
|
+
['blueviolet', '#8a2be2'],
|
|
28
|
+
['brown', '#a52a2a'],
|
|
29
|
+
['burlywood', '#deb887'],
|
|
30
|
+
['cadetblue', '#5f9ea0'],
|
|
31
|
+
['chartreuse', '#7fff00'],
|
|
32
|
+
['chocolate', '#d2691e'],
|
|
33
|
+
['coral', '#ff7f50'],
|
|
34
|
+
['cornflowerblue', '#6495ed'],
|
|
35
|
+
['cornsilk', '#fff8dc'],
|
|
36
|
+
['crimson', '#dc143c'],
|
|
37
|
+
['cyan', '00ffff'],
|
|
38
|
+
['darkblue', '#00008b'],
|
|
39
|
+
['darkcyan', '#008b8b'],
|
|
40
|
+
['darkgoldenrod', '#b8860b'],
|
|
41
|
+
['darkgray', '#a9a9a9'],
|
|
42
|
+
['darkgreen', '#006400'],
|
|
43
|
+
['darkgrey', '#a9a9a9'],
|
|
44
|
+
['darkkhaki', '#bdb76b'],
|
|
45
|
+
['darkmagenta', '#8b008b'],
|
|
46
|
+
['darkolivegreen', '#556b2f'],
|
|
47
|
+
['darkorange', '#ff8c00'],
|
|
48
|
+
['darkorchid', '#9932cc'],
|
|
49
|
+
['darkred', '#8b0000'],
|
|
50
|
+
['darksalmon', '#e9967a'],
|
|
51
|
+
['darkseagreen', '#8fbc8f'],
|
|
52
|
+
['darkslateblue', '#483d8b'],
|
|
53
|
+
['darkslategray', '#2f4f4f'],
|
|
54
|
+
['darkslategrey', '#2f4f4f'],
|
|
55
|
+
['darkturquoise', '#00ced1'],
|
|
56
|
+
['darkviolet', '#9400d3'],
|
|
57
|
+
['deeppink', '#ff1493'],
|
|
58
|
+
['deepskyblue', '#00bfff'],
|
|
59
|
+
['dimgray', '#696969'],
|
|
60
|
+
['dimgrey', '#696969'],
|
|
61
|
+
['dodgerblue', '#1e90ff'],
|
|
62
|
+
['firebrick', '#b22222'],
|
|
63
|
+
['floralwhite', '#fffaf0'],
|
|
64
|
+
['forestgreen', '#228b22'],
|
|
65
|
+
['gainsboro', '#dcdcdc'],
|
|
66
|
+
['ghostwhite', '#f8f8ff'],
|
|
67
|
+
['gold', '#ffd700'],
|
|
68
|
+
['goldenrod', '#daa520'],
|
|
69
|
+
['greenyellow', '#adff2f'],
|
|
70
|
+
['grey', '#808080'],
|
|
71
|
+
['honeydew', '#f0fff0'],
|
|
72
|
+
['hotpink', '#ff69b4'],
|
|
73
|
+
['indianred', '#cd5c5c'],
|
|
74
|
+
['indigo', '#4b0082'],
|
|
75
|
+
['ivory', '#fffff0'],
|
|
76
|
+
['khaki', '#f0e68c'],
|
|
77
|
+
['lavender', '#e6e6fa'],
|
|
78
|
+
['lavenderblush', '#fff0f5'],
|
|
79
|
+
['lawngreen', '#7cfc00'],
|
|
80
|
+
['lemonchiffon', '#fffacd'],
|
|
81
|
+
['lightblue', '#add8e6'],
|
|
82
|
+
['lightcoral', '#f08080'],
|
|
83
|
+
['lightcyan', '#e0ffff'],
|
|
84
|
+
['lightgoldenrodyellow', '#fafad2'],
|
|
85
|
+
['lightgray', '#d3d3d3'],
|
|
86
|
+
['lightgreen', '#90ee90'],
|
|
87
|
+
['lightgrey', '#d3d3d3'],
|
|
88
|
+
['lightpink', '#ffb6c1'],
|
|
89
|
+
['lightsalmon', '#ffa07a'],
|
|
90
|
+
['lightseagreen', '#20b2aa'],
|
|
91
|
+
['lightskyblue', '#87cefa'],
|
|
92
|
+
['lightslategray', '#778899'],
|
|
93
|
+
['lightslategrey', '#778899'],
|
|
94
|
+
['lightsteelblue', '#b0c4de'],
|
|
95
|
+
['lightyellow', '#ffffe0'],
|
|
96
|
+
['limegreen', '#32cd32'],
|
|
97
|
+
['linen', '#faf0e6'],
|
|
98
|
+
['magenta', '#ff00ff'],
|
|
99
|
+
['mediumaquamarine', '#66cdaa'],
|
|
100
|
+
['mediumblue', '#0000cd'],
|
|
101
|
+
['mediumorchid', '#ba55d3'],
|
|
102
|
+
['mediumpurple', '#9370db'],
|
|
103
|
+
['mediumseagreen', '#3cb371'],
|
|
104
|
+
['mediumslateblue', '#7b68ee'],
|
|
105
|
+
['mediumspringgreen', '#00fa9a'],
|
|
106
|
+
['mediumturquoise', '#48d1cc'],
|
|
107
|
+
['mediumvioletred', '#c71585'],
|
|
108
|
+
['midnightblue', '#191970'],
|
|
109
|
+
['mintcream', '#f5fffa'],
|
|
110
|
+
['mistyrose', '#ffe4e1'],
|
|
111
|
+
['moccasin', '#ffe4b5'],
|
|
112
|
+
['navajowhite', '#ffdead'],
|
|
113
|
+
['oldlace', '#fdf5e6'],
|
|
114
|
+
['olivedrab', '#6b8e23'],
|
|
115
|
+
['orangered', '#ff4500'],
|
|
116
|
+
['orchid', '#da70d6'],
|
|
117
|
+
['palegoldenrod', '#eee8aa'],
|
|
118
|
+
['palegreen', '#98fb98'],
|
|
119
|
+
['paleturquoise', '#afeeee'],
|
|
120
|
+
['palevioletred', '#db7093'],
|
|
121
|
+
['papayawhip', '#ffefd5'],
|
|
122
|
+
['peachpuff', '#ffdab9'],
|
|
123
|
+
['peru', '#cd853f'],
|
|
124
|
+
['pink', '#ffc0cb'],
|
|
125
|
+
['plum', '#dda0dd'],
|
|
126
|
+
['powderblue', '#b0e0e6'],
|
|
127
|
+
['rosybrown', '#bc8f8f'],
|
|
128
|
+
['royalblue', '#4169e1'],
|
|
129
|
+
['saddlebrown', '#8b4513'],
|
|
130
|
+
['salmon', '#fa8072'],
|
|
131
|
+
['sandybrown', '#f4a460'],
|
|
132
|
+
['seagreen', '#2e8b57'],
|
|
133
|
+
['seashell', '#fff5ee'],
|
|
134
|
+
['sienna', '#a0522d'],
|
|
135
|
+
['skyblue', '#87ceeb'],
|
|
136
|
+
['slateblue', '#6a5acd'],
|
|
137
|
+
['slategray', '#708090'],
|
|
138
|
+
['slategrey', '#708090'],
|
|
139
|
+
['snow', '#fffafa'],
|
|
140
|
+
['springgreen', '#00ff7f'],
|
|
141
|
+
['steelblue', '#4682b4'],
|
|
142
|
+
['tan', '#d2b48c'],
|
|
143
|
+
['thistle', '#d8bfd8'],
|
|
144
|
+
['tomato', '#ff6347'],
|
|
145
|
+
['turquoise', '#40e0d0'],
|
|
146
|
+
['violet', '#ee82ee'],
|
|
147
|
+
['wheat', '#f5deb3'],
|
|
148
|
+
['whitesmoke', '#f5f5f5'],
|
|
149
|
+
['yellowgreen', '#9acd32'],
|
|
150
|
+
['rebeccapurple', '#663399'],
|
|
151
|
+
]);
|