@shortfuse/materialdesignweb 0.2.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.browserslistrc +2 -1
- package/.eslintrc.json +188 -30
- package/.stylelintrc.json +643 -2
- package/.vscode/launch.json +20 -5
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +36 -0
- package/README.md +82 -2
- package/adapters/datatable/column.js +176 -0
- package/adapters/datatable/index.js +253 -437
- package/adapters/dom/index.js +586 -0
- package/adapters/list/index.js +36 -113
- package/adapters/search/index.js +153 -180
- package/components/appbar/_spec.scss +165 -0
- package/components/appbar/_theme.scss +0 -0
- package/components/appbar/index.scss +2 -0
- package/components/banner/_spec.scss +83 -0
- package/components/banner/_theme.scss +0 -0
- package/components/banner/index.scss +2 -0
- package/components/bottomnav/README.md +4 -4
- package/components/bottomnav/_spec.scss +149 -0
- package/components/bottomnav/_theme.scss +0 -0
- package/components/bottomnav/index.js +100 -120
- package/components/bottomnav/index.scss +2 -0
- package/components/bottomnav/item.js +88 -0
- package/components/button/README.md +16 -22
- package/components/button/_spec.scss +162 -0
- package/components/button/_theme.scss +42 -0
- package/components/button/index.eta +32 -0
- package/components/button/index.js +37 -48
- package/components/button/index.pug +18 -0
- package/components/button/index.scss +2 -0
- package/components/card/_spec.scss +241 -0
- package/components/card/_theme.scss +0 -0
- package/components/card/index.scss +2 -0
- package/components/chip/_spec.scss +111 -0
- package/components/chip/_theme.scss +105 -0
- package/components/chip/index.js +23 -0
- package/components/chip/index.scss +2 -0
- package/components/chip/item.js +20 -0
- package/components/datatable/_spec.scss +225 -0
- package/components/datatable/_theme.scss +128 -0
- package/components/datatable/cell.js +44 -0
- package/components/datatable/columnheader.js +46 -0
- package/components/datatable/index.js +339 -443
- package/components/datatable/index.scss +2 -0
- package/components/datatable/row.js +48 -0
- package/components/datatable/rowheader.js +18 -0
- package/components/dialog/_spec.scss +203 -0
- package/components/dialog/_theme.scss +7 -0
- package/components/dialog/index.js +512 -437
- package/components/dialog/index.scss +2 -0
- package/components/divider/_spec.scss +11 -0
- package/components/divider/_theme.scss +0 -0
- package/components/divider/index.scss +2 -0
- package/components/elevation/_spec.scss +9 -0
- package/components/elevation/_theme.scss +0 -0
- package/components/elevation/index.scss +2 -0
- package/components/fab/{style.scss → _spec.scss} +104 -79
- package/components/fab/_theme.scss +0 -0
- package/components/fab/index.js +85 -79
- package/components/fab/index.scss +2 -0
- package/components/grid/_spec.scss +169 -0
- package/components/grid/_theme.scss +0 -0
- package/components/grid/index.scss +2 -0
- package/components/layout/_mixins.scss +11 -0
- package/components/layout/_spec.scss +916 -0
- package/components/layout/_theme.scss +19 -0
- package/components/layout/index.js +454 -0
- package/components/layout/index.scss +2 -0
- package/components/list/_spec.scss +363 -0
- package/components/list/_theme.scss +102 -0
- package/components/list/content.js +106 -0
- package/components/list/index.js +234 -79
- package/components/list/index.scss +2 -0
- package/components/list/item.js +167 -0
- package/components/list/secondary.js +45 -0
- package/components/menu/_spec.scss +329 -0
- package/components/menu/_theme.scss +0 -0
- package/components/menu/index.js +636 -651
- package/components/menu/index.scss +2 -0
- package/components/menu/item.js +231 -0
- package/components/progress/_spec.scss +156 -0
- package/components/progress/_theme.scss +0 -0
- package/components/progress/index.js +29 -13
- package/components/progress/index.scss +2 -0
- package/components/selection/_spec.scss +376 -0
- package/components/selection/_theme.scss +134 -0
- package/components/selection/index.eta +60 -0
- package/components/selection/index.js +70 -0
- package/components/selection/index.pug +30 -0
- package/components/selection/index.scss +2 -0
- package/components/selection/input.js +54 -0
- package/components/selection/radiogroup.js +40 -0
- package/components/slider/{style.scss → _spec.scss} +31 -34
- package/components/slider/_theme.scss +0 -0
- package/components/slider/index.scss +2 -0
- package/components/snackbar/_spec.scss +150 -0
- package/components/snackbar/_theme.scss +0 -0
- package/components/snackbar/index.js +293 -206
- package/components/snackbar/index.scss +2 -0
- package/components/tab/_spec.scss +220 -0
- package/components/tab/_theme.scss +0 -0
- package/components/tab/content.js +210 -0
- package/components/tab/index.js +229 -213
- package/components/tab/index.scss +2 -0
- package/components/tab/item.js +88 -0
- package/components/tab/list.js +196 -0
- package/components/tab/panel.js +54 -0
- package/components/textfield/README.md +4 -4
- package/components/textfield/_spec.scss +763 -0
- package/components/textfield/_theme.scss +264 -0
- package/components/textfield/index.eta +74 -0
- package/components/textfield/index.js +132 -138
- package/components/textfield/index.pug +30 -0
- package/components/textfield/index.scss +2 -0
- package/components/tooltip/_spec.scss +185 -0
- package/components/tooltip/_theme.scss +0 -0
- package/components/tooltip/index.scss +2 -0
- package/components/type/_spec.scss +227 -0
- package/components/type/_theme.scss +0 -0
- package/components/type/index.scss +2 -0
- package/core/_breakpoint.scss +189 -0
- package/core/_elevation.scss +78 -0
- package/core/_length.scss +8 -0
- package/core/_motion.scss +31 -0
- package/core/_platform.scss +12 -0
- package/core/_type.scss +128 -0
- package/core/aria/attributes.js +141 -0
- package/core/aria/button.js +49 -0
- package/core/aria/keyboard.js +92 -0
- package/core/aria/rovingtabindex.js +175 -0
- package/core/aria/tab.js +59 -0
- package/core/document/index.js +39 -0
- package/core/dom.js +180 -0
- package/core/overlay/_spec.scss +28 -0
- package/core/overlay/_theme.scss +147 -0
- package/core/overlay/index.js +95 -0
- package/core/overlay/index.scss +2 -0
- package/core/ripple/_spec.scss +196 -0
- package/core/ripple/_theme.scss +20 -0
- package/core/ripple/index.js +286 -0
- package/core/ripple/index.scss +2 -0
- package/core/theme/_aliases.scss +15 -0
- package/core/theme/_config.scss +8 -0
- package/core/theme/_functions.scss +22 -0
- package/{components/theming/palettes.scss → core/theme/_palettes.scss} +173 -151
- package/core/theme/_spec.scss +0 -0
- package/core/theme/_theme.scss +268 -0
- package/core/theme/index.js +50 -0
- package/core/theme/index.scss +4 -0
- package/core/throttler.js +42 -0
- package/core/transition/index.js +465 -0
- package/docs/_flex.scss +28 -0
- package/docs/_menuoptions.js +183 -0
- package/docs/_partials/_androidnavbar.eta +5 -0
- package/docs/_partials/_androidstatusbar.eta +13 -0
- package/docs/_partials/_appbar.eta +27 -0
- package/docs/_partials/_buttontest.eta +31 -0
- package/docs/_partials/_header.eta +146 -0
- package/docs/_partials/_navlistitem.eta +16 -0
- package/docs/_partials/_target.eta +1 -0
- package/docs/_sample-utils.js +88 -0
- package/docs/{src/storage.js → _storage.js} +0 -0
- package/docs/docs.scss +331 -0
- package/docs/framework.scss +26 -0
- package/docs/index.eta +12 -0
- package/docs/index.js +7 -0
- package/docs/pages/appbar.eta +108 -0
- package/docs/pages/appbar.js +0 -0
- package/docs/pages/bottomnav.eta +188 -0
- package/docs/pages/bottomnav.js +118 -0
- package/docs/pages/button.eta +124 -0
- package/docs/pages/button.js +224 -0
- package/docs/pages/card.eta +90 -0
- package/docs/pages/card.js +175 -0
- package/docs/pages/chip.eta +122 -0
- package/docs/pages/chip.js +80 -0
- package/docs/pages/color.eta +143 -0
- package/docs/pages/color.js +261 -0
- package/docs/pages/datatable.eta +323 -0
- package/docs/pages/datatable.js +160 -0
- package/docs/pages/dialog.eta +184 -0
- package/docs/{src/components → pages}/dialog.js +35 -48
- package/docs/pages/dom.eta +26 -0
- package/docs/pages/dom.js +140 -0
- package/docs/pages/elevation.eta +35 -0
- package/docs/pages/elevation.js +0 -0
- package/docs/pages/fab.eta +99 -0
- package/docs/{src/components → pages}/fab.js +6 -13
- package/docs/pages/grid.eta +135 -0
- package/docs/pages/grid.js +128 -0
- package/docs/pages/layout.eta +8 -0
- package/docs/pages/layout.js +0 -0
- package/docs/pages/list.eta +465 -0
- package/docs/pages/list.js +8 -0
- package/docs/pages/menu.eta +274 -0
- package/docs/{src/components → pages}/menu.js +26 -42
- package/docs/pages/overlay.eta +69 -0
- package/docs/pages/overlay.js +3 -0
- package/docs/pages/progress.eta +23 -0
- package/docs/{src/components → pages}/progress.js +2 -4
- package/docs/pages/ripple.eta +27 -0
- package/docs/pages/ripple.js +3 -0
- package/docs/pages/search.eta +242 -0
- package/docs/pages/search.js +226 -0
- package/docs/pages/selection.eta +107 -0
- package/docs/pages/selection.js +12 -0
- package/docs/pages/slider.eta +23 -0
- package/docs/pages/slider.js +0 -0
- package/docs/pages/snackbar.eta +83 -0
- package/docs/{src/components → pages}/snackbar.js +31 -36
- package/docs/pages/tab.eta +407 -0
- package/docs/pages/tab.js +152 -0
- package/docs/pages/textfield.eta +487 -0
- package/docs/{src/components → pages}/textfield.js +41 -45
- package/docs/pages/tooltip.eta +92 -0
- package/docs/pages/tooltip.js +0 -0
- package/docs/pages/transition.eta +117 -0
- package/docs/pages/transition.js +52 -0
- package/docs/pages/type.eta +31 -0
- package/docs/pages/type.js +0 -0
- package/docs/postrender.js +41 -0
- package/docs/prerender.js +16 -0
- package/docs/pwa/_dialogs.eta +143 -0
- package/docs/pwa/_menus.eta +16 -0
- package/docs/pwa/pwa-prerender.js +3 -0
- package/docs/pwa/pwa.eta +478 -0
- package/docs/pwa/pwa.js +298 -0
- package/docs/pwa/pwa.scss +31 -0
- package/docs/themes/theme-colored.scss +15 -0
- package/docs/themes/theme-default.scss +3 -0
- package/index.scss +27 -0
- package/jsconfig.json +8 -2
- package/package.json +54 -27
- package/scripts/deploy-docs.sh +9 -0
- package/templates/index.eta +2 -0
- package/templates/index.pug +3 -0
- package/tsconfig.json +16 -0
- package/utils/function.js +3 -0
- package/webpack.config.js +224 -68
- package/_index.scss +0 -4
- package/components/all-components.scss +0 -21
- package/components/bottomnav/style.scss +0 -190
- package/components/bottomnav/theming.scss +0 -76
- package/components/button/style.scss +0 -315
- package/components/button/theming.scss +0 -134
- package/components/card/style.scss +0 -175
- package/components/card/theming.scss +0 -43
- package/components/common/dom.js +0 -51
- package/components/common/functions.scss +0 -174
- package/components/common/mixins.scss +0 -122
- package/components/common/motion.scss +0 -36
- package/components/common/type.scss +0 -104
- package/components/common/variables.scss +0 -46
- package/components/datatable/style.scss +0 -257
- package/components/datatable/theming.scss +0 -119
- package/components/dialog/style.scss +0 -159
- package/components/dialog/theming.scss +0 -29
- package/components/divider/style.scss +0 -7
- package/components/divider/theming.scss +0 -20
- package/components/elevation/style.scss +0 -32
- package/components/layout/style.scss +0 -223
- package/components/list/style.scss +0 -358
- package/components/list/theming.scss +0 -83
- package/components/menu/style.scss +0 -280
- package/components/menu/theming.scss +0 -80
- package/components/navdrawer/index.js +0 -200
- package/components/navdrawer/style.scss +0 -595
- package/components/navdrawer/theming.scss +0 -62
- package/components/progress/style.scss +0 -136
- package/components/ripple/index.js +0 -63
- package/components/ripple/ripple.scss +0 -122
- package/components/selection/style.scss +0 -320
- package/components/selection/theming.scss +0 -98
- package/components/snackbar/style.scss +0 -212
- package/components/switch/style.scss +0 -3
- package/components/tab/style.scss +0 -275
- package/components/tab/theming.scss +0 -34
- package/components/template/theming.scss +0 -31
- package/components/textfield/style.scss +0 -795
- package/components/textfield/theming.scss +0 -256
- package/components/theming/globals.scss +0 -25
- package/components/theming/theming.scss +0 -559
- package/components/toolbar/style.scss +0 -190
- package/components/toolbar/theming.scss +0 -32
- package/components/tooltip/style.scss +0 -135
- package/components/type/style.scss +0 -167
- package/components/type/theming.scss +0 -25
- package/docs/bottomnav.html +0 -1
- package/docs/bottomnav.min.js +0 -2
- package/docs/bottomnav.min.js.map +0 -1
- package/docs/button.html +0 -1
- package/docs/button.min.js +0 -2
- package/docs/button.min.js.map +0 -1
- package/docs/card.html +0 -1
- package/docs/card.min.js +0 -2
- package/docs/card.min.js.map +0 -1
- package/docs/components.min.css +0 -1
- package/docs/components.min.js +0 -2
- package/docs/components.min.js.map +0 -1
- package/docs/datatable.html +0 -1
- package/docs/datatable.min.js +0 -2
- package/docs/datatable.min.js.map +0 -1
- package/docs/dialog.html +0 -1
- package/docs/dialog.min.js +0 -2
- package/docs/dialog.min.js.map +0 -1
- package/docs/docs.min.css +0 -1
- package/docs/docs.min.js +0 -2
- package/docs/docs.min.js.map +0 -1
- package/docs/elevation.html +0 -1
- package/docs/elevation.min.js +0 -2
- package/docs/elevation.min.js.map +0 -1
- package/docs/fab.html +0 -1
- package/docs/fab.min.js +0 -2
- package/docs/fab.min.js.map +0 -1
- package/docs/index.html +0 -1
- package/docs/index.min.js +0 -2
- package/docs/index.min.js.map +0 -1
- package/docs/layout.html +0 -1
- package/docs/layout.min.js +0 -2
- package/docs/layout.min.js.map +0 -1
- package/docs/list.html +0 -1
- package/docs/list.min.js +0 -2
- package/docs/list.min.js.map +0 -1
- package/docs/menu.html +0 -1
- package/docs/menu.min.js +0 -2
- package/docs/menu.min.js.map +0 -1
- package/docs/navdrawer.html +0 -1
- package/docs/navdrawer.min.js +0 -2
- package/docs/navdrawer.min.js.map +0 -1
- package/docs/prerender.min.js +0 -2
- package/docs/prerender.min.js.map +0 -1
- package/docs/progress.html +0 -1
- package/docs/progress.min.js +0 -2
- package/docs/progress.min.js.map +0 -1
- package/docs/search.html +0 -1
- package/docs/search.min.js +0 -2
- package/docs/search.min.js.map +0 -1
- package/docs/selection.html +0 -1
- package/docs/selection.min.js +0 -2
- package/docs/selection.min.js.map +0 -1
- package/docs/slider.html +0 -1
- package/docs/slider.min.js +0 -2
- package/docs/slider.min.js.map +0 -1
- package/docs/snackbar.html +0 -1
- package/docs/snackbar.min.js +0 -2
- package/docs/snackbar.min.js.map +0 -1
- package/docs/src/components/bottomnav.js +0 -16
- package/docs/src/components/bottomnav.pug +0 -112
- package/docs/src/components/button.js +0 -156
- package/docs/src/components/button.pug +0 -194
- package/docs/src/components/card.js +0 -136
- package/docs/src/components/card.pug +0 -133
- package/docs/src/components/datatable.js +0 -183
- package/docs/src/components/datatable.pug +0 -324
- package/docs/src/components/dialog.pug +0 -138
- package/docs/src/components/elevation.js +0 -3
- package/docs/src/components/elevation.pug +0 -17
- package/docs/src/components/fab.pug +0 -84
- package/docs/src/components/layout.js +0 -116
- package/docs/src/components/layout.pug +0 -104
- package/docs/src/components/list.js +0 -15
- package/docs/src/components/list.pug +0 -293
- package/docs/src/components/menu.pug +0 -292
- package/docs/src/components/navdrawer.js +0 -112
- package/docs/src/components/navdrawer.pug +0 -113
- package/docs/src/components/progress.pug +0 -17
- package/docs/src/components/search.js +0 -206
- package/docs/src/components/search.pug +0 -149
- package/docs/src/components/selection.js +0 -6
- package/docs/src/components/selection.pug +0 -116
- package/docs/src/components/slider.js +0 -3
- package/docs/src/components/slider.pug +0 -19
- package/docs/src/components/snackbar.pug +0 -145
- package/docs/src/components/tab.js +0 -137
- package/docs/src/components/tab.pug +0 -329
- package/docs/src/components/textfield.pug +0 -416
- package/docs/src/components/toolbar.js +0 -6
- package/docs/src/components/toolbar.pug +0 -86
- package/docs/src/components/tooltip.js +0 -6
- package/docs/src/components/tooltip.pug +0 -76
- package/docs/src/components/type.js +0 -6
- package/docs/src/components/type.pug +0 -34
- package/docs/src/components.scss +0 -1
- package/docs/src/docs.scss +0 -284
- package/docs/src/index.js +0 -3
- package/docs/src/index.pug +0 -6
- package/docs/src/menuoptions.js +0 -136
- package/docs/src/mixins.pug +0 -139
- package/docs/src/prerender.js +0 -26
- package/docs/src/sample-utils.js +0 -108
- package/docs/src/targetHandler.js +0 -50
- package/docs/src/theming.ie11.scss +0 -18
- package/docs/src/theming.scss +0 -18
- package/docs/tab.html +0 -1
- package/docs/tab.min.js +0 -2
- package/docs/tab.min.js.map +0 -1
- package/docs/textfield.html +0 -2
- package/docs/textfield.min.js +0 -2
- package/docs/textfield.min.js.map +0 -1
- package/docs/theming.ie11.min.css +0 -1
- package/docs/theming.ie11.min.js +0 -2
- package/docs/theming.ie11.min.js.map +0 -1
- package/docs/theming.min.css +0 -1
- package/docs/theming.min.js +0 -2
- package/docs/theming.min.js.map +0 -1
- package/docs/toolbar.html +0 -1
- package/docs/toolbar.min.js +0 -2
- package/docs/toolbar.min.js.map +0 -1
- package/docs/tooltip.html +0 -1
- package/docs/tooltip.min.js +0 -2
- package/docs/tooltip.min.js.map +0 -1
- package/docs/type.html +0 -1
- package/docs/type.min.js +0 -2
- package/docs/type.min.js.map +0 -1
- package/index.js +0 -16
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
// https://material.io/design/navigation/navigation-transitions.html
|
|
2
|
+
|
|
3
|
+
const EXPAND_DURATION_MS = 300;
|
|
4
|
+
const COLLAPSE_DURATION_MS = 250;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {Object} ShapeTranformDetails
|
|
8
|
+
* @prop {number} originWidth
|
|
9
|
+
* @prop {number} originHeight
|
|
10
|
+
* @prop {number} translateX
|
|
11
|
+
* @prop {number} translateY
|
|
12
|
+
* @prop {number} scaleX
|
|
13
|
+
* @prop {number} scaleY
|
|
14
|
+
* @prop {function():string} toString
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} px
|
|
19
|
+
* @return {number}
|
|
20
|
+
*/
|
|
21
|
+
function pxToInteger(px) {
|
|
22
|
+
if (!px) {
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
return Number.parseInt(px, 10);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} stringValue
|
|
30
|
+
* @param {number} scaleX
|
|
31
|
+
* @param {number} scaleY
|
|
32
|
+
* @return {string}
|
|
33
|
+
*/
|
|
34
|
+
function convertBoxShadow(stringValue, scaleX, scaleY) {
|
|
35
|
+
/**
|
|
36
|
+
* @param {string} shadow
|
|
37
|
+
* @return {string}
|
|
38
|
+
*/
|
|
39
|
+
function convertShadow(shadow) {
|
|
40
|
+
let inset = '';
|
|
41
|
+
let offsetX = '';
|
|
42
|
+
let offsetY = '';
|
|
43
|
+
let blurRadius = '';
|
|
44
|
+
let spreadRadius = '';
|
|
45
|
+
let color = '';
|
|
46
|
+
for (const value of shadow.trim().split(' ')) {
|
|
47
|
+
if (value.toLowerCase() === 'inset') {
|
|
48
|
+
inset = value;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (value.includes('(') || !value.match(/\d/).length) {
|
|
52
|
+
color = value;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const numberValue = pxToInteger(value);
|
|
56
|
+
if (!offsetX) {
|
|
57
|
+
offsetX = `${numberValue / scaleX}${value.replace(/[\d.\\]/g, '')}`;
|
|
58
|
+
} else if (!offsetY) {
|
|
59
|
+
offsetY = `${numberValue / scaleY}${value.replace(/[\d.\\]/g, '')}`;
|
|
60
|
+
} else if (!blurRadius) {
|
|
61
|
+
blurRadius = `${numberValue / (scaleX * scaleY)}${value.replace(/[\d.\\-]/g, '')}`;
|
|
62
|
+
} else {
|
|
63
|
+
spreadRadius = `${numberValue / (scaleX * scaleY)}${value.replace(/[\d.\\-]/g, '')}`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return [
|
|
67
|
+
inset,
|
|
68
|
+
offsetX,
|
|
69
|
+
offsetY,
|
|
70
|
+
blurRadius,
|
|
71
|
+
spreadRadius,
|
|
72
|
+
color,
|
|
73
|
+
].filter(Boolean).join(' ');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!stringValue) {
|
|
77
|
+
return '';
|
|
78
|
+
}
|
|
79
|
+
return stringValue
|
|
80
|
+
// Strip spaces from anything parenthesized
|
|
81
|
+
.replace(/\([^)]+\)/g, (substring) => substring.replace(/ /g, ''))
|
|
82
|
+
// Split shadows by commas no inside parentheses
|
|
83
|
+
.match(/[^(,]+\([^)]+\)?[^,]*(|$)/g)
|
|
84
|
+
// Convert values
|
|
85
|
+
.map((shadow) => convertShadow(shadow))
|
|
86
|
+
// Rejoin shadows
|
|
87
|
+
.join(', ');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {string} value
|
|
92
|
+
* @param {number} length
|
|
93
|
+
* @return {number}
|
|
94
|
+
*/
|
|
95
|
+
function parsePercentage(value, length) {
|
|
96
|
+
const numValue = pxToInteger(value);
|
|
97
|
+
if (!value.includes('%')) {
|
|
98
|
+
return numValue;
|
|
99
|
+
}
|
|
100
|
+
return ((numValue * length) / 100);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @param {string} stringValue
|
|
105
|
+
* @param {number} width
|
|
106
|
+
* @param {number} height
|
|
107
|
+
* @return {{horizontal:number, vertical:number}}
|
|
108
|
+
*/
|
|
109
|
+
function convertBorderRadius(stringValue, width, height) {
|
|
110
|
+
if (!stringValue) {
|
|
111
|
+
return {
|
|
112
|
+
horizontal: 0,
|
|
113
|
+
vertical: 0,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const split = stringValue.split(' ');
|
|
118
|
+
if (split.length === 1) {
|
|
119
|
+
return {
|
|
120
|
+
horizontal: parsePercentage(stringValue, width),
|
|
121
|
+
vertical: parsePercentage(stringValue, height),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
horizontal: parsePercentage(split[0], width),
|
|
126
|
+
vertical: parsePercentage(split[1], height),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @param {HTMLElement} targetElement
|
|
132
|
+
* @param {HTMLElement} originElement
|
|
133
|
+
* @param {CSSStyleDeclaration} [originStyle]
|
|
134
|
+
* @return {ShapeTranformDetails}
|
|
135
|
+
*/
|
|
136
|
+
export function getShapeTransform(targetElement, originElement, originStyle) {
|
|
137
|
+
const originRect = originElement.getBoundingClientRect();
|
|
138
|
+
const targetRect = targetElement.getBoundingClientRect();
|
|
139
|
+
const originCSSStyle = originStyle || window.getComputedStyle(originElement);
|
|
140
|
+
|
|
141
|
+
let originX = originRect.left;
|
|
142
|
+
let originWidth = originRect.width;
|
|
143
|
+
let originY = originRect.top;
|
|
144
|
+
let originHeight = originRect.height;
|
|
145
|
+
if (originCSSStyle.boxSizing === 'border-box') {
|
|
146
|
+
const paddingTop = pxToInteger(originCSSStyle.paddingTop);
|
|
147
|
+
const paddingRight = pxToInteger(originCSSStyle.paddingRight);
|
|
148
|
+
const paddingBottom = pxToInteger(originCSSStyle.paddingBottom);
|
|
149
|
+
const paddingLeft = pxToInteger(originCSSStyle.paddingLeft);
|
|
150
|
+
originX += paddingLeft;
|
|
151
|
+
originWidth -= (paddingLeft + paddingRight);
|
|
152
|
+
originY += paddingTop;
|
|
153
|
+
originHeight -= (paddingTop + paddingBottom);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
originWidth,
|
|
158
|
+
originHeight,
|
|
159
|
+
translateX: originX - targetRect.left,
|
|
160
|
+
translateY: originY - targetRect.top,
|
|
161
|
+
scaleX: originWidth / targetRect.width,
|
|
162
|
+
scaleY: originHeight / targetRect.height,
|
|
163
|
+
toString() {
|
|
164
|
+
return [
|
|
165
|
+
`translateX(${this.translateX}px)`,
|
|
166
|
+
`translateY(${this.translateY}px)`,
|
|
167
|
+
`scaleX(${this.scaleX})`,
|
|
168
|
+
`scaleY(${this.scaleY})`,
|
|
169
|
+
].join(' ');
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @param {HTMLElement} element
|
|
176
|
+
* @param {string} property
|
|
177
|
+
* @param {function(TransitionEvent):void} callback
|
|
178
|
+
* @param {number} [expectedDuration]
|
|
179
|
+
* @return {Function} removeListener
|
|
180
|
+
*/
|
|
181
|
+
function buildTransitionEndListener(element, property, callback, expectedDuration) {
|
|
182
|
+
let hasEnded = false;
|
|
183
|
+
const onTransitionEnd = (/** @type {TransitionEvent} */ event) => {
|
|
184
|
+
if (event.propertyName !== property) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
hasEnded = true;
|
|
188
|
+
element.removeEventListener('transitionend', onTransitionEnd);
|
|
189
|
+
callback(event);
|
|
190
|
+
};
|
|
191
|
+
element.addEventListener('transitionend', onTransitionEnd);
|
|
192
|
+
if (expectedDuration) {
|
|
193
|
+
setTimeout(() => {
|
|
194
|
+
element.removeEventListener('transitionend', onTransitionEnd);
|
|
195
|
+
if (!hasEnded) {
|
|
196
|
+
callback(null);
|
|
197
|
+
}
|
|
198
|
+
}, expectedDuration + 500);
|
|
199
|
+
}
|
|
200
|
+
return () => {
|
|
201
|
+
element.removeEventListener('transitionend', onTransitionEnd);
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @typedef {Object} TransitionElementOptions
|
|
207
|
+
* @prop {HTMLElement} fromShapeElement
|
|
208
|
+
* @prop {HTMLElement} toShapeElement
|
|
209
|
+
* @prop {HTMLElement} fromContentElement
|
|
210
|
+
* @prop {HTMLElement} toContentElement
|
|
211
|
+
* @prop {number} [duration=250|300] (250ms collapse or 300ms expand)
|
|
212
|
+
* @prop {boolean} [revertFrom=false] Revert from elements on completion
|
|
213
|
+
* @prop {function(TransitionElementOptions):any} [onTransitionEnd]
|
|
214
|
+
* @prop {function(TransitionElementOptions):any} [onComplete]
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @param {TransitionElementOptions} options
|
|
219
|
+
* @return {function():void} revertAllElements()
|
|
220
|
+
*/
|
|
221
|
+
export function transitionElement(options) {
|
|
222
|
+
const toStyleSyle = window.getComputedStyle(options.toShapeElement);
|
|
223
|
+
|
|
224
|
+
const shapeTransform = getShapeTransform(options.fromShapeElement, options.toShapeElement, toStyleSyle);
|
|
225
|
+
const contentTransform = getShapeTransform(options.toContentElement, options.fromContentElement);
|
|
226
|
+
|
|
227
|
+
const transitionProperties = [
|
|
228
|
+
'transition',
|
|
229
|
+
'transform-origin',
|
|
230
|
+
'transform',
|
|
231
|
+
'background-color',
|
|
232
|
+
'border-radius',
|
|
233
|
+
'box-shadow',
|
|
234
|
+
'z-index',
|
|
235
|
+
'filter',
|
|
236
|
+
'opacity',
|
|
237
|
+
'visibility',
|
|
238
|
+
];
|
|
239
|
+
|
|
240
|
+
/** @type {Record<string,string>} */
|
|
241
|
+
const oldFromShapeProperties = {};
|
|
242
|
+
/** @type {Record<string,string>} */
|
|
243
|
+
const oldToShapeProperties = {};
|
|
244
|
+
/** @type {Record<string,string>} */
|
|
245
|
+
const oldFromContentProperties = {};
|
|
246
|
+
/** @type {Record<string,string>} */
|
|
247
|
+
const oldToContentProperties = {};
|
|
248
|
+
/** @type {Record<string,string>} */
|
|
249
|
+
const newFromShapeProperties = {};
|
|
250
|
+
for (const prop of transitionProperties) {
|
|
251
|
+
oldFromShapeProperties[prop] = options.fromShapeElement.style.getPropertyValue(prop);
|
|
252
|
+
oldToShapeProperties[prop] = options.toShapeElement.style.getPropertyValue(prop);
|
|
253
|
+
oldFromContentProperties[prop] = options.fromContentElement.style.getPropertyValue(prop);
|
|
254
|
+
oldToContentProperties[prop] = options.toContentElement.style.getPropertyValue(prop);
|
|
255
|
+
if (prop === 'box-shadow') {
|
|
256
|
+
newFromShapeProperties[prop] = convertBoxShadow(
|
|
257
|
+
toStyleSyle.getPropertyValue(prop),
|
|
258
|
+
shapeTransform.scaleX,
|
|
259
|
+
shapeTransform.scaleY,
|
|
260
|
+
);
|
|
261
|
+
} else if (prop === 'border-radius') {
|
|
262
|
+
const topLeft = convertBorderRadius(
|
|
263
|
+
toStyleSyle.getPropertyValue('border-top-left-radius'),
|
|
264
|
+
shapeTransform.originWidth,
|
|
265
|
+
shapeTransform.originHeight,
|
|
266
|
+
);
|
|
267
|
+
const topRight = convertBorderRadius(
|
|
268
|
+
toStyleSyle.getPropertyValue('border-top-right-radius'),
|
|
269
|
+
shapeTransform.originWidth,
|
|
270
|
+
shapeTransform.originHeight,
|
|
271
|
+
);
|
|
272
|
+
const bottomLeft = convertBorderRadius(
|
|
273
|
+
toStyleSyle.getPropertyValue('border-bottom-left-radius'),
|
|
274
|
+
shapeTransform.originWidth,
|
|
275
|
+
shapeTransform.originHeight,
|
|
276
|
+
);
|
|
277
|
+
const bottomRight = convertBorderRadius(
|
|
278
|
+
toStyleSyle.getPropertyValue('border-bottom-right-radius'),
|
|
279
|
+
shapeTransform.originWidth,
|
|
280
|
+
shapeTransform.originHeight,
|
|
281
|
+
);
|
|
282
|
+
const horizontalRadii = [
|
|
283
|
+
`${topLeft.horizontal / shapeTransform.scaleX}px`,
|
|
284
|
+
`${topRight.horizontal / shapeTransform.scaleX}px`,
|
|
285
|
+
`${bottomLeft.horizontal / shapeTransform.scaleX}px`,
|
|
286
|
+
`${bottomRight.horizontal / shapeTransform.scaleX}px`,
|
|
287
|
+
].join(' ');
|
|
288
|
+
const verticalRadii = [
|
|
289
|
+
`${topLeft.vertical / shapeTransform.scaleY}px`,
|
|
290
|
+
`${topRight.vertical / shapeTransform.scaleY}px`,
|
|
291
|
+
`${bottomLeft.vertical / shapeTransform.scaleY}px`,
|
|
292
|
+
`${bottomRight.vertical / shapeTransform.scaleY}px`,
|
|
293
|
+
].join(' ');
|
|
294
|
+
newFromShapeProperties[prop] = `${horizontalRadii} / ${verticalRadii}`;
|
|
295
|
+
} else {
|
|
296
|
+
newFromShapeProperties[prop] = toStyleSyle.getPropertyValue(prop);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
options.fromShapeElement.setAttribute('mdw-transition-busy', '');
|
|
301
|
+
options.toShapeElement.setAttribute('mdw-transition-busy', '');
|
|
302
|
+
options.toContentElement.setAttribute('mdw-transition-busy', '');
|
|
303
|
+
options.fromContentElement.setAttribute('mdw-transition-busy', '');
|
|
304
|
+
|
|
305
|
+
// Hide toContentElement and overlay over fromContentElement immediately
|
|
306
|
+
options.toContentElement.style.setProperty('opacity', '0');
|
|
307
|
+
options.toContentElement.style.setProperty('transition', 'none');
|
|
308
|
+
options.toContentElement.style.setProperty('transform-origin', '0 0 0');
|
|
309
|
+
options.toContentElement.style.setProperty('transform', contentTransform.toString());
|
|
310
|
+
options.toContentElement.style.setProperty('z-index', '9');
|
|
311
|
+
options.toContentElement.style.setProperty('visibility', 'visible');
|
|
312
|
+
|
|
313
|
+
options.fromContentElement.style.setProperty('opacity', '1');
|
|
314
|
+
|
|
315
|
+
options.fromShapeElement.style.setProperty('transition', 'none');
|
|
316
|
+
options.fromShapeElement.style.setProperty('transform-origin', '0 0 0');
|
|
317
|
+
options.fromShapeElement.style.setProperty('transform', 'none');
|
|
318
|
+
options.fromShapeElement.style.setProperty('z-index', '8');
|
|
319
|
+
|
|
320
|
+
options.toShapeElement.style.setProperty('background-color', 'transparent');
|
|
321
|
+
options.toShapeElement.style.setProperty('filter', 'none');
|
|
322
|
+
options.toShapeElement.style.setProperty('box-shadow', 'none');
|
|
323
|
+
options.toShapeElement.style.setProperty('visibility', 'visible');
|
|
324
|
+
|
|
325
|
+
const revertFunction = () => {
|
|
326
|
+
for (const prop of transitionProperties) {
|
|
327
|
+
if (oldFromShapeProperties[prop] == null) {
|
|
328
|
+
options.fromShapeElement.style.removeProperty(prop);
|
|
329
|
+
} else {
|
|
330
|
+
options.fromShapeElement.style.setProperty(prop, oldFromShapeProperties[prop]);
|
|
331
|
+
}
|
|
332
|
+
if (oldToShapeProperties[prop] == null) {
|
|
333
|
+
options.toShapeElement.style.removeProperty(prop);
|
|
334
|
+
} else {
|
|
335
|
+
options.toShapeElement.style.setProperty(prop, oldToShapeProperties[prop]);
|
|
336
|
+
}
|
|
337
|
+
if (oldFromContentProperties[prop] == null) {
|
|
338
|
+
options.fromContentElement.style.removeProperty(prop);
|
|
339
|
+
} else {
|
|
340
|
+
options.fromContentElement.style.setProperty(prop, oldFromContentProperties[prop]);
|
|
341
|
+
}
|
|
342
|
+
if (oldToContentProperties[prop] == null) {
|
|
343
|
+
options.toContentElement.style.removeProperty(prop);
|
|
344
|
+
} else {
|
|
345
|
+
options.toContentElement.style.setProperty(prop, oldToContentProperties[prop]);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
requestAnimationFrame(() => {
|
|
351
|
+
requestAnimationFrame(() => {
|
|
352
|
+
const calculatedDuration = options.duration
|
|
353
|
+
?? ((shapeTransform.scaleX * shapeTransform.scaleY >= 1) ? EXPAND_DURATION_MS : COLLAPSE_DURATION_MS);
|
|
354
|
+
const totalDuration = calculatedDuration.toString(10);
|
|
355
|
+
const fadeInTime = (calculatedDuration * 0.7).toString(10);
|
|
356
|
+
const fadeOutTime = (calculatedDuration * 0.3).toString(10);
|
|
357
|
+
const transformTransition = transitionProperties
|
|
358
|
+
.filter((prop) => prop !== 'transform-origin' && prop !== 'opacity' && prop !== 'transition')
|
|
359
|
+
.map((prop) => `${prop} ${totalDuration}ms cubic-bezier(0.4, 0.0, 0.2, 1) 0s`)
|
|
360
|
+
.join(', ');
|
|
361
|
+
const fadeInTransition = `opacity ${fadeInTime}ms cubic-bezier(0.0, 0.0, 0.2, 1) ${fadeOutTime}ms`;
|
|
362
|
+
const fadeOutTransition = [
|
|
363
|
+
`opacity ${fadeOutTime}ms cubic-bezier(0.0, 0.0, 0.2, 1) 0ms`,
|
|
364
|
+
`visibility ${fadeOutTime}ms cubic-bezier(0.0, 0.0, 0.2, 1) 0ms`,
|
|
365
|
+
].join(', ');
|
|
366
|
+
|
|
367
|
+
options.fromShapeElement.style.setProperty('transition', transformTransition);
|
|
368
|
+
for (const prop of transitionProperties) {
|
|
369
|
+
switch (prop) {
|
|
370
|
+
case 'transform': {
|
|
371
|
+
options.fromShapeElement.style.setProperty('transform', shapeTransform.toString());
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
case 'transition': continue;
|
|
375
|
+
case 'transform-origin':
|
|
376
|
+
options.fromShapeElement.style.setProperty('transform-origin', '0 0 0');
|
|
377
|
+
continue;
|
|
378
|
+
case 'z-index':
|
|
379
|
+
options.fromShapeElement.style.setProperty('z-index', '8');
|
|
380
|
+
continue;
|
|
381
|
+
case 'visibility':
|
|
382
|
+
options.fromShapeElement.style.setProperty('visibility', 'hidden');
|
|
383
|
+
continue;
|
|
384
|
+
default:
|
|
385
|
+
if (newFromShapeProperties[prop] == null) {
|
|
386
|
+
options.fromShapeElement.style.removeProperty(prop);
|
|
387
|
+
} else {
|
|
388
|
+
options.fromShapeElement.style.setProperty(prop, newFromShapeProperties[prop]);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
requestAnimationFrame(() => {
|
|
394
|
+
buildTransitionEndListener(options.fromShapeElement, 'transform', () => {
|
|
395
|
+
for (const prop of transitionProperties) {
|
|
396
|
+
if (prop === 'transition') {
|
|
397
|
+
options.toShapeElement.style.setProperty('transition', 'none');
|
|
398
|
+
options.toContentElement.style.setProperty('transition', 'none');
|
|
399
|
+
} else {
|
|
400
|
+
if (oldToShapeProperties[prop] == null) {
|
|
401
|
+
options.toShapeElement.style.removeProperty(prop);
|
|
402
|
+
} else {
|
|
403
|
+
options.toShapeElement.style.setProperty(prop, oldToShapeProperties[prop]);
|
|
404
|
+
}
|
|
405
|
+
if (oldToContentProperties[prop] == null) {
|
|
406
|
+
options.toContentElement.style.removeProperty(prop);
|
|
407
|
+
} else {
|
|
408
|
+
options.toContentElement.style.setProperty(prop, oldToContentProperties[prop]);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (prop === 'visibility' && !options.revertFrom) continue;
|
|
413
|
+
|
|
414
|
+
if (oldFromContentProperties[prop] == null) {
|
|
415
|
+
options.fromContentElement.style.removeProperty(prop);
|
|
416
|
+
} else {
|
|
417
|
+
options.fromContentElement.style.setProperty(prop, oldFromContentProperties[prop]);
|
|
418
|
+
}
|
|
419
|
+
if (oldFromShapeProperties[prop] == null) {
|
|
420
|
+
options.fromShapeElement.style.removeProperty(prop);
|
|
421
|
+
} else {
|
|
422
|
+
options.fromShapeElement.style.setProperty(prop, oldFromShapeProperties[prop]);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (options.onTransitionEnd) {
|
|
426
|
+
options.onTransitionEnd(options);
|
|
427
|
+
}
|
|
428
|
+
requestAnimationFrame(() => {
|
|
429
|
+
if (oldToShapeProperties.transition == null) {
|
|
430
|
+
options.toShapeElement.style.removeProperty('transition');
|
|
431
|
+
} else {
|
|
432
|
+
options.toShapeElement.style.setProperty('transition', oldToShapeProperties.transition);
|
|
433
|
+
}
|
|
434
|
+
if (oldToContentProperties.transition == null) {
|
|
435
|
+
options.toContentElement.style.removeProperty('transition');
|
|
436
|
+
} else {
|
|
437
|
+
options.toContentElement.style.setProperty('transition', oldToContentProperties.transition);
|
|
438
|
+
}
|
|
439
|
+
options.fromShapeElement.removeAttribute('mdw-transition-busy');
|
|
440
|
+
options.toShapeElement.removeAttribute('mdw-transition-busy');
|
|
441
|
+
options.toContentElement.removeAttribute('mdw-transition-busy');
|
|
442
|
+
options.fromContentElement.removeAttribute('mdw-transition-busy');
|
|
443
|
+
if (options.onComplete) {
|
|
444
|
+
options.onComplete(options);
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
}, calculatedDuration);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
// Fade out fromContent while shaping into new content
|
|
451
|
+
options.fromContentElement.style.setProperty('transition', fadeOutTransition);
|
|
452
|
+
options.fromContentElement.style.setProperty('opacity', '0');
|
|
453
|
+
options.fromContentElement.style.setProperty('visibility', 'hidden');
|
|
454
|
+
|
|
455
|
+
options.toContentElement.style.setProperty('transition', [
|
|
456
|
+
transformTransition,
|
|
457
|
+
fadeInTransition,
|
|
458
|
+
].join(', '));
|
|
459
|
+
options.toContentElement.style.setProperty('opacity', '1');
|
|
460
|
+
options.toContentElement.style.setProperty('transform', 'none');
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
return revertFunction;
|
|
465
|
+
}
|
package/docs/_flex.scss
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
.display-flex {
|
|
2
|
+
display: flex;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.flex-column {
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
[flex-column] {
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
[flex-justify-content="center"] {
|
|
15
|
+
justify-content: center;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
[flex-align-items="center"] {
|
|
19
|
+
align-items: center;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.flex-wrap {
|
|
23
|
+
flex-wrap: wrap;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.flex-1 {
|
|
27
|
+
flex: 1;
|
|
28
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { getStorageItem, removeStorageItem, setStorageItem } from './_storage.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {boolean} value
|
|
5
|
+
* @param {Element} [button]
|
|
6
|
+
* @return {void}
|
|
7
|
+
*/
|
|
8
|
+
export function setRTLMode(value, button) {
|
|
9
|
+
if (value) {
|
|
10
|
+
document.documentElement.dir = 'rtl';
|
|
11
|
+
setStorageItem('rtlmode', 'true');
|
|
12
|
+
} else {
|
|
13
|
+
// Explicit LTR is required for Safari to support repeated toggling
|
|
14
|
+
document.documentElement.dir = 'ltr';
|
|
15
|
+
removeStorageItem('rtlmode');
|
|
16
|
+
}
|
|
17
|
+
if (button) {
|
|
18
|
+
button.setAttribute('aria-pressed', value ? 'true' : 'false');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @return {boolean} */
|
|
23
|
+
export function isDarkMode() {
|
|
24
|
+
const userPreference = getStorageItem('darkmode');
|
|
25
|
+
if (userPreference == null) {
|
|
26
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
27
|
+
}
|
|
28
|
+
return userPreference === 'true';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {boolean} value
|
|
33
|
+
* @param {Element} [button]
|
|
34
|
+
* @return {void}
|
|
35
|
+
*/
|
|
36
|
+
export function setDarkMode(value, button) {
|
|
37
|
+
if (value) {
|
|
38
|
+
document.documentElement.setAttribute('mdw-dark', '');
|
|
39
|
+
document.documentElement.removeAttribute('mdw-light');
|
|
40
|
+
} else {
|
|
41
|
+
document.documentElement.setAttribute('mdw-light', '');
|
|
42
|
+
document.documentElement.removeAttribute('mdw-dark');
|
|
43
|
+
}
|
|
44
|
+
const stringValue = (value ? 'true' : 'false');
|
|
45
|
+
if (button) {
|
|
46
|
+
button.setAttribute('aria-pressed', stringValue);
|
|
47
|
+
}
|
|
48
|
+
setStorageItem('darkmode', stringValue);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {boolean} value
|
|
53
|
+
* @param {Element} [button]
|
|
54
|
+
* @return {void}
|
|
55
|
+
*/
|
|
56
|
+
export function setAltTheme(value, button) {
|
|
57
|
+
const items = document.head.getElementsByTagName('link');
|
|
58
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
59
|
+
const stylesheet = items.item(i);
|
|
60
|
+
if (stylesheet.href.includes(value ? 'theme-colored' : 'theme-default')) {
|
|
61
|
+
stylesheet.disabled = false;
|
|
62
|
+
}
|
|
63
|
+
if (stylesheet.href.includes(value ? 'theme-default' : 'theme-colored')) {
|
|
64
|
+
stylesheet.disabled = true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const stringValue = (value ? 'true' : 'false');
|
|
69
|
+
if (button) {
|
|
70
|
+
button.setAttribute('aria-pressed', stringValue);
|
|
71
|
+
}
|
|
72
|
+
const statusBarAttribute = document.head.getElementsByTagName('meta').namedItem('theme-color');
|
|
73
|
+
if (statusBarAttribute) {
|
|
74
|
+
statusBarAttribute.setAttribute('content', value ? '#FF5722' : '#E91E63');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
setStorageItem('alttheme', stringValue);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @param {string} value
|
|
82
|
+
* @param {Element} [button]
|
|
83
|
+
* @return {void}
|
|
84
|
+
*/
|
|
85
|
+
export function setFontSize(value, button) {
|
|
86
|
+
if (value) {
|
|
87
|
+
document.documentElement.style.setProperty('font-size', value);
|
|
88
|
+
setStorageItem('fontsize', value);
|
|
89
|
+
} else {
|
|
90
|
+
document.documentElement.style.removeProperty('font-size');
|
|
91
|
+
removeStorageItem('fontsize');
|
|
92
|
+
}
|
|
93
|
+
if (button) {
|
|
94
|
+
button.setAttribute('aria-pressed', value ? 'true' : 'false');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {Element} [element]
|
|
100
|
+
* @return {void}
|
|
101
|
+
*/
|
|
102
|
+
function setupRTLMode(element) {
|
|
103
|
+
if (getStorageItem('rtlmode') === 'true') {
|
|
104
|
+
setRTLMode(true, element);
|
|
105
|
+
}
|
|
106
|
+
if (!element) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
element.addEventListener('click', () => {
|
|
110
|
+
if (document.documentElement.dir === 'rtl') {
|
|
111
|
+
setRTLMode(false, element);
|
|
112
|
+
} else {
|
|
113
|
+
setRTLMode(true, element);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @param {Element} [element]
|
|
120
|
+
* @return {void}
|
|
121
|
+
*/
|
|
122
|
+
function setupAltTheme(element) {
|
|
123
|
+
if (getStorageItem('alttheme') === 'true') {
|
|
124
|
+
setAltTheme(true, element);
|
|
125
|
+
}
|
|
126
|
+
if (!element) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
element.addEventListener('click', () => {
|
|
130
|
+
if (getStorageItem('alttheme') !== 'true') {
|
|
131
|
+
setAltTheme(true, element);
|
|
132
|
+
} else {
|
|
133
|
+
setAltTheme(false, element);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @param {Element} [element]
|
|
140
|
+
* @return {void}
|
|
141
|
+
*/
|
|
142
|
+
function setupDarkMode(element) {
|
|
143
|
+
if (isDarkMode()) {
|
|
144
|
+
setDarkMode(true, element);
|
|
145
|
+
}
|
|
146
|
+
if (!element) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
element.addEventListener('click', () => {
|
|
150
|
+
if (document.documentElement.hasAttribute('mdw-dark')) {
|
|
151
|
+
setDarkMode(false, element);
|
|
152
|
+
} else {
|
|
153
|
+
setDarkMode(true, element);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @param {Element} element
|
|
160
|
+
* @return {void}
|
|
161
|
+
*/
|
|
162
|
+
function setupLargeFontMode(element) {
|
|
163
|
+
const fontsize = getStorageItem('fontsize');
|
|
164
|
+
setFontSize(fontsize, element);
|
|
165
|
+
if (!element) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
element.addEventListener('click', () => {
|
|
169
|
+
if (document.documentElement.style.getPropertyValue('font-size')) {
|
|
170
|
+
setFontSize(null, element);
|
|
171
|
+
} else {
|
|
172
|
+
setFontSize('200%', element);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** @return {void} */
|
|
178
|
+
export function setupMenuOptions() {
|
|
179
|
+
setupAltTheme(document.getElementById('altThemeButton'));
|
|
180
|
+
setupRTLMode(document.getElementById('rtlButton'));
|
|
181
|
+
setupDarkMode(document.getElementById('darkModeButton'));
|
|
182
|
+
setupLargeFontMode(document.getElementById('largeFontButton'));
|
|
183
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<div <%~ Object.entries({
|
|
2
|
+
'class': 'androidstatusbar mdw-theme',
|
|
3
|
+
'mdw-surface': it?.surface,
|
|
4
|
+
'mdw-light': it?.light,
|
|
5
|
+
'mdw-dark': it?.dark
|
|
6
|
+
}).map(([key, value]) => {
|
|
7
|
+
if (value === true) return key;
|
|
8
|
+
if (value === false || value == null) return false;
|
|
9
|
+
return `${key}="${value}"`
|
|
10
|
+
}).filter(v=>v).join(' ')-%>>
|
|
11
|
+
<div>12:30</div>
|
|
12
|
+
<i class="material-icons" style="letter-spacing:2px;padding:0 2px;"></i>
|
|
13
|
+
</div>
|