@shortfuse/materialdesignweb 0.8.0 → 0.9.1
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 +50 -198
- package/bin/mdw-css.js +1 -1
- package/components/Badge.js +15 -5
- package/components/Body.js +7 -0
- package/components/BottomAppBar.js +7 -10
- package/components/BottomSheet.js +472 -0
- package/components/Box.js +11 -49
- package/components/Button.js +81 -82
- package/components/Card.js +74 -62
- package/components/Checkbox.js +15 -25
- package/components/CheckboxIcon.js +19 -31
- package/components/Chip.js +18 -13
- package/components/Dialog.js +70 -100
- package/components/DialogActions.js +4 -0
- package/components/Display.js +64 -0
- package/components/Divider.js +5 -0
- package/components/Fab.js +94 -17
- package/components/FabContainer.js +57 -0
- package/components/FilterChip.js +43 -32
- package/components/Grid.js +187 -0
- package/components/Headline.js +9 -28
- package/components/Icon.js +80 -71
- package/components/IconButton.js +77 -120
- package/components/Input.js +745 -86
- package/components/InputChip.js +193 -0
- package/components/Label.js +7 -0
- package/components/List.js +11 -5
- package/components/ListItem.js +92 -23
- package/components/ListOption.js +143 -65
- package/components/Listbox.js +57 -17
- package/components/Menu.js +39 -27
- package/components/MenuItem.js +49 -36
- package/components/NavBar.js +66 -21
- package/components/NavBarItem.js +5 -0
- package/components/NavDrawer.js +33 -16
- package/components/NavDrawerItem.js +7 -4
- package/components/NavItem.js +61 -34
- package/components/NavRail.js +32 -21
- package/components/NavRailItem.js +10 -2
- package/components/Page.js +119 -0
- package/components/Pane.js +24 -0
- package/components/Popup.js +23 -8
- package/components/Progress.js +25 -5
- package/components/Radio.js +8 -7
- package/components/RadioIcon.js +24 -15
- package/components/Ripple.js +25 -7
- package/components/Root.js +225 -0
- package/components/Scrim.js +95 -0
- package/components/Search.js +30 -25
- package/components/SegmentedButton.js +53 -40
- package/components/SegmentedButtonGroup.js +15 -12
- package/components/Select.js +19 -10
- package/components/Shape.js +10 -66
- package/components/SideSheet.js +337 -0
- package/components/Slider.js +93 -36
- package/components/Snackbar.js +52 -20
- package/components/SnackbarContainer.js +51 -0
- package/components/Surface.js +20 -10
- package/components/Switch.js +21 -18
- package/components/SwitchIcon.js +62 -33
- package/components/Tab.js +78 -38
- package/components/TabContent.js +33 -12
- package/components/TabList.js +95 -34
- package/components/TabPanel.js +10 -1
- package/components/Table.js +151 -0
- package/components/TextArea.js +48 -16
- package/components/Title.js +8 -9
- package/components/Tooltip.js +51 -22
- package/components/TopAppBar.js +71 -78
- package/constants/shapes.js +36 -0
- package/constants/typography.js +127 -0
- package/core/Composition.js +391 -201
- package/core/CompositionAdapter.js +35 -18
- package/core/CustomElement.js +634 -254
- package/core/css.js +117 -12
- package/core/customTypes.js +161 -49
- package/core/dom.js +18 -11
- package/core/jsonMergePatch.js +27 -11
- package/core/observe.js +308 -256
- package/core/optimizations.js +9 -9
- package/core/template.js +14 -57
- package/dist/CustomElement.min.js +2 -0
- package/dist/CustomElement.min.js.map +7 -0
- package/dist/core/CustomElement.min.js +2 -0
- package/dist/core/CustomElement.min.js.map +7 -0
- package/dist/index.min.js +85 -115
- package/dist/index.min.js.map +4 -4
- package/dist/meta.json +1 -1
- package/dom/HTMLOptionsCollectionProxy.js +108 -0
- package/{theming/themableMixinLoader.js → loaders/palette.js} +4 -3
- package/loaders/theme.js +12 -0
- package/mixins/AriaReflectorMixin.js +64 -15
- package/mixins/AriaToolbarMixin.js +6 -0
- package/mixins/ControlMixin.js +79 -33
- package/mixins/DelegatesFocusMixin.js +62 -0
- package/mixins/DensityMixin.js +7 -3
- package/mixins/ElevationMixin.js +61 -0
- package/mixins/FlexableMixin.js +87 -39
- package/mixins/FormAssociatedMixin.js +76 -10
- package/mixins/HyperlinkMixin.js +76 -0
- package/mixins/InputMixin.js +227 -32
- package/mixins/KeyboardNavMixin.js +11 -7
- package/mixins/NavigationListenerMixin.js +33 -0
- package/mixins/PopupMixin.js +216 -219
- package/mixins/RTLObserverMixin.js +2 -0
- package/mixins/ResizeObserverMixin.js +18 -4
- package/mixins/RippleMixin.js +11 -7
- package/mixins/ScrollListenerMixin.js +14 -2
- package/mixins/SemiStickyMixin.js +51 -98
- package/mixins/ShapeMaskedMixin.js +125 -0
- package/mixins/ShapeMixin.js +30 -203
- package/mixins/StateMixin.js +74 -34
- package/mixins/TextFieldMixin.js +128 -145
- package/mixins/ThemableMixin.js +57 -56
- package/mixins/TooltipTriggerMixin.js +305 -359
- package/mixins/TouchTargetMixin.js +5 -2
- package/mixins/TypographyMixin.js +128 -0
- package/package.json +125 -81
- package/services/rtl.js +10 -0
- package/services/svgAlias.js +17 -0
- package/{theming/index.js → services/theme.js} +25 -176
- package/types/bin/mdw-css.d.ts +3 -0
- package/types/bin/mdw-css.d.ts.map +1 -0
- package/types/components/Badge.d.ts +39 -0
- package/types/components/Badge.d.ts.map +1 -0
- package/types/components/Body.d.ts +29 -0
- package/types/components/Body.d.ts.map +1 -0
- package/types/components/BottomAppBar.d.ts +72 -0
- package/types/components/BottomAppBar.d.ts.map +1 -0
- package/types/components/BottomSheet.d.ts +135 -0
- package/types/components/BottomSheet.d.ts.map +1 -0
- package/types/components/Box.d.ts +16 -0
- package/types/components/Box.d.ts.map +1 -0
- package/types/components/Button.d.ts +245 -0
- package/types/components/Button.d.ts.map +1 -0
- package/types/components/Card.d.ts +147 -0
- package/types/components/Card.d.ts.map +1 -0
- package/types/components/Checkbox.d.ts +207 -0
- package/types/components/Checkbox.d.ts.map +1 -0
- package/types/components/CheckboxIcon.d.ts +44 -0
- package/types/components/CheckboxIcon.d.ts.map +1 -0
- package/types/components/Chip.d.ts +248 -0
- package/types/components/Chip.d.ts.map +1 -0
- package/types/components/Dialog.d.ts +103 -0
- package/types/components/Dialog.d.ts.map +1 -0
- package/types/components/DialogActions.d.ts +4 -0
- package/types/components/DialogActions.d.ts.map +1 -0
- package/types/components/Display.d.ts +46 -0
- package/types/components/Display.d.ts.map +1 -0
- package/types/components/Divider.d.ts +10 -0
- package/types/components/Divider.d.ts.map +1 -0
- package/types/components/Fab.d.ts +273 -0
- package/types/components/Fab.d.ts.map +1 -0
- package/types/components/FabContainer.d.ts +10 -0
- package/types/components/FabContainer.d.ts.map +1 -0
- package/types/components/FilterChip.d.ts +256 -0
- package/types/components/FilterChip.d.ts.map +1 -0
- package/types/components/Grid.d.ts +38 -0
- package/types/components/Grid.d.ts.map +1 -0
- package/types/components/Headline.d.ts +46 -0
- package/types/components/Headline.d.ts.map +1 -0
- package/types/components/Icon.d.ts +55 -0
- package/types/components/Icon.d.ts.map +1 -0
- package/types/components/IconButton.d.ts +284 -0
- package/types/components/IconButton.d.ts.map +1 -0
- package/types/components/Input.d.ts +2528 -0
- package/types/components/Input.d.ts.map +1 -0
- package/types/components/InputChip.d.ts +85 -0
- package/types/components/InputChip.d.ts.map +1 -0
- package/types/components/Label.d.ts +29 -0
- package/types/components/Label.d.ts.map +1 -0
- package/types/components/List.d.ts +35 -0
- package/types/components/List.d.ts.map +1 -0
- package/types/components/ListItem.d.ts +124 -0
- package/types/components/ListItem.d.ts.map +1 -0
- package/types/components/ListOption.d.ts +158 -0
- package/types/components/ListOption.d.ts.map +1 -0
- package/types/components/Listbox.d.ts +763 -0
- package/types/components/Listbox.d.ts.map +1 -0
- package/types/components/Menu.d.ts +130 -0
- package/types/components/Menu.d.ts.map +1 -0
- package/types/components/MenuItem.d.ts +232 -0
- package/types/components/MenuItem.d.ts.map +1 -0
- package/types/components/NavBar.d.ts +20 -0
- package/types/components/NavBar.d.ts.map +1 -0
- package/types/components/NavBarItem.d.ts +97 -0
- package/types/components/NavBarItem.d.ts.map +1 -0
- package/types/components/NavDrawer.d.ts +107 -0
- package/types/components/NavDrawer.d.ts.map +1 -0
- package/types/components/NavDrawerItem.d.ts +97 -0
- package/types/components/NavDrawerItem.d.ts.map +1 -0
- package/types/components/NavItem.d.ts +99 -0
- package/types/components/NavItem.d.ts.map +1 -0
- package/types/components/NavRail.d.ts +108 -0
- package/types/components/NavRail.d.ts.map +1 -0
- package/types/components/NavRailItem.d.ts +97 -0
- package/types/components/NavRailItem.d.ts.map +1 -0
- package/types/components/Page.d.ts +25 -0
- package/types/components/Page.d.ts.map +1 -0
- package/types/components/Pane.d.ts +44 -0
- package/types/components/Pane.d.ts.map +1 -0
- package/types/components/Popup.d.ts +78 -0
- package/types/components/Popup.d.ts.map +1 -0
- package/types/components/Progress.d.ts +21 -0
- package/types/components/Progress.d.ts.map +1 -0
- package/types/components/Radio.d.ts +201 -0
- package/types/components/Radio.d.ts.map +1 -0
- package/types/components/RadioIcon.d.ts +46 -0
- package/types/components/RadioIcon.d.ts.map +1 -0
- package/types/components/Ripple.d.ts +35 -0
- package/types/components/Ripple.d.ts.map +1 -0
- package/types/components/Root.d.ts +68 -0
- package/types/components/Root.d.ts.map +1 -0
- package/types/components/Scrim.d.ts +6 -0
- package/types/components/Scrim.d.ts.map +1 -0
- package/types/components/Search.d.ts +516 -0
- package/types/components/Search.d.ts.map +1 -0
- package/types/components/SegmentedButton.d.ts +252 -0
- package/types/components/SegmentedButton.d.ts.map +1 -0
- package/types/components/SegmentedButtonGroup.d.ts +43 -0
- package/types/components/SegmentedButtonGroup.d.ts.map +1 -0
- package/types/components/Select.d.ts +158 -0
- package/types/components/Select.d.ts.map +1 -0
- package/types/components/Shape.d.ts +10 -0
- package/types/components/Shape.d.ts.map +1 -0
- package/types/components/SideSheet.d.ts +111 -0
- package/types/components/SideSheet.d.ts.map +1 -0
- package/types/components/Slider.d.ts +203 -0
- package/types/components/Slider.d.ts.map +1 -0
- package/types/components/Snackbar.d.ts +73 -0
- package/types/components/Snackbar.d.ts.map +1 -0
- package/types/components/SnackbarContainer.d.ts +6 -0
- package/types/components/SnackbarContainer.d.ts.map +1 -0
- package/types/components/Surface.d.ts +45 -0
- package/types/components/Surface.d.ts.map +1 -0
- package/types/components/Switch.d.ts +187 -0
- package/types/components/Switch.d.ts.map +1 -0
- package/types/components/SwitchIcon.d.ts +61 -0
- package/types/components/SwitchIcon.d.ts.map +1 -0
- package/types/components/Tab.d.ts +139 -0
- package/types/components/Tab.d.ts.map +1 -0
- package/types/components/TabContent.d.ts +124 -0
- package/types/components/TabContent.d.ts.map +1 -0
- package/types/components/TabList.d.ts +1111 -0
- package/types/components/TabList.d.ts.map +1 -0
- package/types/components/TabPanel.d.ts +28 -0
- package/types/components/TabPanel.d.ts.map +1 -0
- package/types/components/Table.d.ts +25 -0
- package/types/components/Table.d.ts.map +1 -0
- package/types/components/TextArea.d.ts +201 -0
- package/types/components/TextArea.d.ts.map +1 -0
- package/types/components/Title.d.ts +46 -0
- package/types/components/Title.d.ts.map +1 -0
- package/types/components/Tooltip.d.ts +49 -0
- package/types/components/Tooltip.d.ts.map +1 -0
- package/types/components/TopAppBar.d.ts +129 -0
- package/types/components/TopAppBar.d.ts.map +1 -0
- package/types/constants/colorKeywords.d.ts +2 -0
- package/types/constants/colorKeywords.d.ts.map +1 -0
- package/types/constants/shapes.d.ts +38 -0
- package/types/constants/shapes.d.ts.map +1 -0
- package/types/constants/typography.d.ts +212 -0
- package/types/constants/typography.d.ts.map +1 -0
- package/types/core/Composition.d.ts +260 -0
- package/types/core/Composition.d.ts.map +1 -0
- package/types/core/CompositionAdapter.d.ts +114 -0
- package/types/core/CompositionAdapter.d.ts.map +1 -0
- package/types/core/CustomElement.d.ts +304 -0
- package/types/core/CustomElement.d.ts.map +1 -0
- package/types/core/css.d.ts +44 -0
- package/types/core/css.d.ts.map +1 -0
- package/types/core/customTypes.d.ts +22 -0
- package/types/core/customTypes.d.ts.map +1 -0
- package/types/core/dom.d.ts +32 -0
- package/types/core/dom.d.ts.map +1 -0
- package/types/core/jsonMergePatch.d.ts +31 -0
- package/types/core/jsonMergePatch.d.ts.map +1 -0
- package/types/core/observe.d.ts +114 -0
- package/types/core/observe.d.ts.map +1 -0
- package/types/core/optimizations.d.ts +7 -0
- package/types/core/optimizations.d.ts.map +1 -0
- package/types/core/template.d.ts +47 -0
- package/types/core/template.d.ts.map +1 -0
- package/types/core/uid.d.ts +6 -0
- package/types/core/uid.d.ts.map +1 -0
- package/types/dom/HTMLOptionsCollectionProxy.d.ts +18 -0
- package/types/dom/HTMLOptionsCollectionProxy.d.ts.map +1 -0
- package/types/index.d.ts +88 -0
- package/types/index.d.ts.map +1 -0
- package/types/loaders/palette.d.ts +2 -0
- package/types/loaders/palette.d.ts.map +1 -0
- package/types/loaders/theme.d.ts +2 -0
- package/types/loaders/theme.d.ts.map +1 -0
- package/types/mixins/AriaReflectorMixin.d.ts +31 -0
- package/types/mixins/AriaReflectorMixin.d.ts.map +1 -0
- package/types/mixins/AriaToolbarMixin.d.ts +34 -0
- package/types/mixins/AriaToolbarMixin.d.ts.map +1 -0
- package/types/mixins/ControlMixin.d.ts +124 -0
- package/types/mixins/ControlMixin.d.ts.map +1 -0
- package/types/mixins/DelegatesFocusMixin.d.ts +13 -0
- package/types/mixins/DelegatesFocusMixin.d.ts.map +1 -0
- package/types/mixins/DensityMixin.d.ts +8 -0
- package/types/mixins/DensityMixin.d.ts.map +1 -0
- package/types/mixins/ElevationMixin.d.ts +32 -0
- package/types/mixins/ElevationMixin.d.ts.map +1 -0
- package/types/mixins/FlexableMixin.d.ts +14 -0
- package/types/mixins/FlexableMixin.d.ts.map +1 -0
- package/types/mixins/FormAssociatedMixin.d.ts +123 -0
- package/types/mixins/FormAssociatedMixin.d.ts.map +1 -0
- package/types/mixins/HyperlinkMixin.d.ts +25 -0
- package/types/mixins/HyperlinkMixin.d.ts.map +1 -0
- package/types/mixins/InputMixin.d.ts +173 -0
- package/types/mixins/InputMixin.d.ts.map +1 -0
- package/types/mixins/KeyboardNavMixin.d.ts +46 -0
- package/types/mixins/KeyboardNavMixin.d.ts.map +1 -0
- package/types/mixins/NavigationListenerMixin.d.ts +8 -0
- package/types/mixins/NavigationListenerMixin.d.ts.map +1 -0
- package/types/mixins/PopupMixin.d.ts +98 -0
- package/types/mixins/PopupMixin.d.ts.map +1 -0
- package/types/mixins/RTLObserverMixin.d.ts +8 -0
- package/types/mixins/RTLObserverMixin.d.ts.map +1 -0
- package/types/mixins/ResizeObserverMixin.d.ts +13 -0
- package/types/mixins/ResizeObserverMixin.d.ts.map +1 -0
- package/types/mixins/RippleMixin.d.ts +94 -0
- package/types/mixins/RippleMixin.d.ts.map +1 -0
- package/types/mixins/ScrollListenerMixin.d.ts +46 -0
- package/types/mixins/ScrollListenerMixin.d.ts.map +1 -0
- package/types/mixins/SemiStickyMixin.d.ts +50 -0
- package/types/mixins/SemiStickyMixin.d.ts.map +1 -0
- package/types/mixins/ShapeMaskedMixin.d.ts +12 -0
- package/types/mixins/ShapeMaskedMixin.d.ts.map +1 -0
- package/types/mixins/ShapeMixin.d.ts +39 -0
- package/types/mixins/ShapeMixin.d.ts.map +1 -0
- package/types/mixins/StateMixin.d.ts +29 -0
- package/types/mixins/StateMixin.d.ts.map +1 -0
- package/types/mixins/TextFieldMixin.d.ts +153 -0
- package/types/mixins/TextFieldMixin.d.ts.map +1 -0
- package/types/mixins/ThemableMixin.d.ts +10 -0
- package/types/mixins/ThemableMixin.d.ts.map +1 -0
- package/types/mixins/TooltipTriggerMixin.d.ts +114 -0
- package/types/mixins/TooltipTriggerMixin.d.ts.map +1 -0
- package/types/mixins/TouchTargetMixin.d.ts +6 -0
- package/types/mixins/TouchTargetMixin.d.ts.map +1 -0
- package/types/mixins/TypographyMixin.d.ts +20 -0
- package/types/mixins/TypographyMixin.d.ts.map +1 -0
- package/types/services/rtl.d.ts +3 -0
- package/types/services/rtl.d.ts.map +1 -0
- package/types/services/svgAlias.d.ts +13 -0
- package/types/services/svgAlias.d.ts.map +1 -0
- package/types/services/theme.d.ts +45 -0
- package/types/services/theme.d.ts.map +1 -0
- package/types/utils/cli.d.ts +3 -0
- package/types/utils/cli.d.ts.map +1 -0
- package/types/utils/function.d.ts +3 -0
- package/types/utils/function.d.ts.map +1 -0
- package/types/utils/jsx-runtime.d.ts +20 -0
- package/types/utils/jsx-runtime.d.ts.map +1 -0
- package/types/utils/material-color/blend.d.ts +34 -0
- package/types/utils/material-color/blend.d.ts.map +1 -0
- package/types/utils/material-color/hct/Cam16.d.ts +142 -0
- package/types/utils/material-color/hct/Cam16.d.ts.map +1 -0
- package/types/utils/material-color/hct/Hct.d.ts +93 -0
- package/types/utils/material-color/hct/Hct.d.ts.map +1 -0
- package/types/utils/material-color/hct/ViewingConditions.d.ts +69 -0
- package/types/utils/material-color/hct/ViewingConditions.d.ts.map +1 -0
- package/types/utils/material-color/hct/hctSolver.d.ts +30 -0
- package/types/utils/material-color/hct/hctSolver.d.ts.map +1 -0
- package/types/utils/material-color/helper.d.ts +8 -0
- package/types/utils/material-color/helper.d.ts.map +1 -0
- package/types/utils/material-color/palettes/CorePalette.d.ts +75 -0
- package/types/utils/material-color/palettes/CorePalette.d.ts.map +1 -0
- package/types/utils/material-color/palettes/TonalPalette.d.ts +38 -0
- package/types/utils/material-color/palettes/TonalPalette.d.ts.map +1 -0
- package/types/utils/material-color/scheme/Scheme.d.ts +264 -0
- package/types/utils/material-color/scheme/Scheme.d.ts.map +1 -0
- package/types/utils/material-color/utils/color.d.ts +172 -0
- package/types/utils/material-color/utils/color.d.ts.map +1 -0
- package/types/utils/material-color/utils/math.d.ts +94 -0
- package/types/utils/material-color/utils/math.d.ts.map +1 -0
- package/types/utils/pixelmatch.d.ts +22 -0
- package/types/utils/pixelmatch.d.ts.map +1 -0
- package/types/utils/popup.d.ts +106 -0
- package/types/utils/popup.d.ts.map +1 -0
- package/types/utils/searchParams.d.ts +3 -0
- package/types/utils/searchParams.d.ts.map +1 -0
- package/types/utils/svg.d.ts +7 -0
- package/types/utils/svg.d.ts.map +1 -0
- package/utils/jsx-runtime.js +9 -4
- package/utils/material-color/scheme/Scheme.js +1 -1
- package/utils/pixelmatch.js +363 -0
- package/utils/popup.js +86 -10
- package/utils/searchParams.js +22 -0
- package/components/Button.md +0 -61
- package/components/ExtendedFab.js +0 -32
- package/components/Layout.js +0 -504
- package/components/Nav.js +0 -38
- package/core/DomAdapter.js +0 -586
- package/core/ICustomElement.d.ts +0 -291
- package/core/ICustomElement.js +0 -1
- package/core/test.js +0 -126
- package/core/typings.d.ts +0 -142
- package/core/typings.js +0 -1
- package/mixins/SurfaceMixin.js +0 -127
- package/theming/loader.js +0 -22
- /package/{utils/color_keywords.js → constants/colorKeywords.js} +0 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license ISC License
|
|
3
|
+
* Copyright (c) 2019, Mapbox
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
6
|
+
* with or without fee is hereby granted, provided that the above copyright notice
|
|
7
|
+
* and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
11
|
+
* FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
13
|
+
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
14
|
+
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
15
|
+
* THIS SOFTWARE.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** @enum {Object} */
|
|
19
|
+
const DEFAULT_OPTIONS = {
|
|
20
|
+
/* matching threshold (0 to 1); smaller is more sensitive */
|
|
21
|
+
threshold: 0.1,
|
|
22
|
+
/* whether to skip anti-aliasing detection */
|
|
23
|
+
includeAA: false,
|
|
24
|
+
/** opacity of original image in diff output */
|
|
25
|
+
alpha: 0.1,
|
|
26
|
+
/* color of anti-aliased pixels in diff output */
|
|
27
|
+
/** @type {[number,number,number]} */
|
|
28
|
+
aaColor: [255, 255, 0],
|
|
29
|
+
/** @type {[number,number,number]} */
|
|
30
|
+
diffColor: [255, 0, 0], // color of different pixels in diff output
|
|
31
|
+
/**
|
|
32
|
+
* whether to detect dark on light differences between img1 and img2 and set
|
|
33
|
+
* an alternative color to differentiate between the two
|
|
34
|
+
* @type {[number,number,number]}
|
|
35
|
+
*/
|
|
36
|
+
diffColorAlt: null,
|
|
37
|
+
/** draw the diff over a transparent background (a mask) */
|
|
38
|
+
diffMask: false,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {ArrayBufferView} arr
|
|
43
|
+
*/
|
|
44
|
+
function isPixelData(arr) {
|
|
45
|
+
// work around instanceof Uint8Array not working properly in some Jest environments
|
|
46
|
+
// @ts-ignore Bad typings
|
|
47
|
+
return ArrayBuffer.isView(arr) && (arr).constructor.BYTES_PER_ELEMENT === 1;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Check if a pixel has 3+ adjacent pixels of the same color.
|
|
52
|
+
* @param {ArrayLike<number>} img
|
|
53
|
+
* @param {number} x1
|
|
54
|
+
* @param {number} y1
|
|
55
|
+
* @param {number} width
|
|
56
|
+
* @param {number} height
|
|
57
|
+
*/
|
|
58
|
+
function hasManySiblings(img, x1, y1, width, height) {
|
|
59
|
+
const x0 = Math.max(x1 - 1, 0);
|
|
60
|
+
const y0 = Math.max(y1 - 1, 0);
|
|
61
|
+
const x2 = Math.min(x1 + 1, width - 1);
|
|
62
|
+
const y2 = Math.min(y1 + 1, height - 1);
|
|
63
|
+
const pos = (y1 * width + x1) * 4;
|
|
64
|
+
let zeroes = x1 === x0 || x1 === x2 || y1 === y0 || y1 === y2 ? 1 : 0;
|
|
65
|
+
|
|
66
|
+
// go through 8 adjacent pixels
|
|
67
|
+
for (let x = x0; x <= x2; x++) {
|
|
68
|
+
for (let y = y0; y <= y2; y++) {
|
|
69
|
+
if (x === x1 && y === y1) continue;
|
|
70
|
+
|
|
71
|
+
const pos2 = 4 * (y * width + x);
|
|
72
|
+
if (img[pos] === img[pos2]
|
|
73
|
+
&& img[pos + 1] === img[pos2 + 1]
|
|
74
|
+
&& img[pos + 2] === img[pos2 + 2]
|
|
75
|
+
&& img[pos + 3] === img[pos2 + 3]) zeroes++;
|
|
76
|
+
|
|
77
|
+
if (zeroes > 2) return true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* blend semi-transparent color with white
|
|
86
|
+
* @param {number} color
|
|
87
|
+
* @param {number} alpha
|
|
88
|
+
*/
|
|
89
|
+
function blend(color, alpha) {
|
|
90
|
+
return 255 + (color - 255) * alpha;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Returns Y from RGB=>YIQ
|
|
95
|
+
* @param {number} red
|
|
96
|
+
* @param {number} green
|
|
97
|
+
* @param {number} blue
|
|
98
|
+
*/
|
|
99
|
+
function yFromRGBToYIQ(red, green, blue) {
|
|
100
|
+
return (0.298_895_31 * red) + (0.586_622_47 * green) + (0.114_482_23 * blue);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Returns I from RGB=>YIQ
|
|
105
|
+
* @param {number} red
|
|
106
|
+
* @param {number} green
|
|
107
|
+
* @param {number} blue
|
|
108
|
+
*/
|
|
109
|
+
function iFromRGBToYIQ(red, green, blue) {
|
|
110
|
+
return (0.595_977_99 * red) + (-0.274_176_1 * green) + (-0.321_801_89 * blue);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Returns Q from RGB=>YIQ
|
|
115
|
+
* @param {number} red
|
|
116
|
+
* @param {number} green
|
|
117
|
+
* @param {number} blue
|
|
118
|
+
* @return {number}
|
|
119
|
+
*/
|
|
120
|
+
function qFromRGBToYIQ(red, green, blue) {
|
|
121
|
+
return (0.211_470_17 * red) + (-0.522_617_11 * green) + (0.311_146_94 * blue);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Returns YIQ from RGB
|
|
126
|
+
* @param {number} red
|
|
127
|
+
* @param {number} green
|
|
128
|
+
* @param {number} blue
|
|
129
|
+
* @return {{y:number, i:number, q:number}}
|
|
130
|
+
*/
|
|
131
|
+
function yiqFromRGB(red, green, blue) {
|
|
132
|
+
return {
|
|
133
|
+
y: yFromRGBToYIQ(red, green, blue),
|
|
134
|
+
i: iFromRGBToYIQ(red, green, blue),
|
|
135
|
+
q: qFromRGBToYIQ(red, green, blue),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* calculate color difference according to the paper "Measuring perceived color
|
|
141
|
+
* difference using YIQ NTSC transmission color space in mobile applications"
|
|
142
|
+
* by Y. Kotsarenko and F. Ramos
|
|
143
|
+
* @param {ArrayLike<number>} img1
|
|
144
|
+
* @param {ArrayLike<number>} img2
|
|
145
|
+
* @param {number} k
|
|
146
|
+
* @param {number} m
|
|
147
|
+
* @param {boolean} [yOnly]
|
|
148
|
+
* @return {number}
|
|
149
|
+
*/
|
|
150
|
+
function colorDelta(img1, img2, k, m, yOnly) {
|
|
151
|
+
let r1 = img1[k + 0];
|
|
152
|
+
let g1 = img1[k + 1];
|
|
153
|
+
let b1 = img1[k + 2];
|
|
154
|
+
let a1 = img1[k + 3];
|
|
155
|
+
|
|
156
|
+
let r2 = img2[m + 0];
|
|
157
|
+
let g2 = img2[m + 1];
|
|
158
|
+
let b2 = img2[m + 2];
|
|
159
|
+
let a2 = img2[m + 3];
|
|
160
|
+
|
|
161
|
+
if (a1 === a2 && r1 === r2 && g1 === g2 && b1 === b2) return 0;
|
|
162
|
+
|
|
163
|
+
if (a1 < 255) {
|
|
164
|
+
a1 /= 255;
|
|
165
|
+
r1 = blend(r1, a1);
|
|
166
|
+
g1 = blend(g1, a1);
|
|
167
|
+
b1 = blend(b1, a1);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (a2 < 255) {
|
|
171
|
+
a2 /= 255;
|
|
172
|
+
r2 = blend(r2, a2);
|
|
173
|
+
g2 = blend(g2, a2);
|
|
174
|
+
b2 = blend(b2, a2);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (yOnly) {
|
|
178
|
+
return yFromRGBToYIQ(r1, g1, b1) - yFromRGBToYIQ(r2, g2, b2);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const { y: y1, i: i1, q: q1 } = yiqFromRGB(r1, g1, b1);
|
|
182
|
+
const { y: y2, i: i2, q: q2 } = yiqFromRGB(r2, g2, b2);
|
|
183
|
+
|
|
184
|
+
const y = y1 - y2;
|
|
185
|
+
const i = i1 - i2;
|
|
186
|
+
const q = q1 - q2;
|
|
187
|
+
|
|
188
|
+
const delta = (0.5053 * y * y) + (0.299 * i * i) + (0.1957 * q * q);
|
|
189
|
+
|
|
190
|
+
// encode whether the pixel lightens or darkens in the sign
|
|
191
|
+
return y1 > y2 ? -delta : delta;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @param {Uint8Array|Uint8ClampedArray} destination
|
|
196
|
+
* @param {number} index
|
|
197
|
+
* @param {number} red
|
|
198
|
+
* @param {number} green
|
|
199
|
+
* @param {number} blue
|
|
200
|
+
* @return {void}
|
|
201
|
+
*/
|
|
202
|
+
function drawPixel(destination, index, red, green, blue) {
|
|
203
|
+
destination[index + 0] = red;
|
|
204
|
+
destination[index + 1] = green;
|
|
205
|
+
destination[index + 2] = blue;
|
|
206
|
+
destination[index + 3] = 255;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* @param {Uint8Array|Uint8ClampedArray} source
|
|
211
|
+
* @param {number} index
|
|
212
|
+
* @param {number} alpha
|
|
213
|
+
* @param {Uint8Array|Uint8ClampedArray} destination
|
|
214
|
+
*/
|
|
215
|
+
function drawGrayPixel(source, index, alpha, destination) {
|
|
216
|
+
const red = source[index + 0];
|
|
217
|
+
const green = source[index + 1];
|
|
218
|
+
const blue = source[index + 2];
|
|
219
|
+
const val = blend(yFromRGBToYIQ(red, green, blue), (alpha * source[index + 3]) / 255);
|
|
220
|
+
drawPixel(destination, index, val, val, val);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Check if a pixel is likely a part of anti-aliasing;
|
|
225
|
+
*
|
|
226
|
+
* Based on "Anti-aliased Pixel and Intensity Slope Detector" paper by V.
|
|
227
|
+
* Vysniauskas, 2009
|
|
228
|
+
* @param {ArrayLike<number>} img
|
|
229
|
+
* @param {number} x1
|
|
230
|
+
* @param {number} y1
|
|
231
|
+
* @param {number} width
|
|
232
|
+
* @param {number} height
|
|
233
|
+
* @param {ArrayLike<number>} img2
|
|
234
|
+
*/
|
|
235
|
+
function antialiased(img, x1, y1, width, height, img2) {
|
|
236
|
+
const x0 = Math.max(x1 - 1, 0);
|
|
237
|
+
const y0 = Math.max(y1 - 1, 0);
|
|
238
|
+
const x2 = Math.min(x1 + 1, width - 1);
|
|
239
|
+
const y2 = Math.min(y1 + 1, height - 1);
|
|
240
|
+
const pos = (y1 * width + x1) * 4;
|
|
241
|
+
let zeroes = x1 === x0 || x1 === x2 || y1 === y0 || y1 === y2 ? 1 : 0;
|
|
242
|
+
let min = 0;
|
|
243
|
+
let max = 0;
|
|
244
|
+
let minX; let minY; let maxX; let
|
|
245
|
+
maxY;
|
|
246
|
+
|
|
247
|
+
// go through 8 adjacent pixels
|
|
248
|
+
for (let x = x0; x <= x2; x++) {
|
|
249
|
+
for (let y = y0; y <= y2; y++) {
|
|
250
|
+
if (x === x1 && y === y1) continue;
|
|
251
|
+
|
|
252
|
+
// brightness delta between the center pixel and adjacent one
|
|
253
|
+
const delta = colorDelta(img, img, pos, (y * width + x) * 4, true);
|
|
254
|
+
|
|
255
|
+
// count the number of equal, darker and brighter adjacent pixels
|
|
256
|
+
if (delta === 0) {
|
|
257
|
+
zeroes++;
|
|
258
|
+
// if found more than 2 equal siblings, it's definitely not anti-aliasing
|
|
259
|
+
if (zeroes > 2) return false;
|
|
260
|
+
|
|
261
|
+
// remember the darkest pixel
|
|
262
|
+
} else if (delta < min) {
|
|
263
|
+
min = delta;
|
|
264
|
+
minX = x;
|
|
265
|
+
minY = y;
|
|
266
|
+
|
|
267
|
+
// remember the brightest pixel
|
|
268
|
+
} else if (delta > max) {
|
|
269
|
+
max = delta;
|
|
270
|
+
maxX = x;
|
|
271
|
+
maxY = y;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// if there are no both darker and brighter pixels among siblings, it's not anti-aliasing
|
|
277
|
+
if (min === 0 || max === 0) return false;
|
|
278
|
+
|
|
279
|
+
// if either the darkest or the brightest pixel has 3+ equal siblings in both images
|
|
280
|
+
// (definitely not anti-aliased), this pixel is anti-aliased
|
|
281
|
+
return (hasManySiblings(img, minX, minY, width, height)
|
|
282
|
+
&& hasManySiblings(img2, minX, minY, width, height))
|
|
283
|
+
|| (hasManySiblings(img, maxX, maxY, width, height)
|
|
284
|
+
&& hasManySiblings(img2, maxX, maxY, width, height));
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* @param {Uint8Array|Uint8ClampedArray} img1
|
|
289
|
+
* @param {Uint8Array|Uint8ClampedArray} img2
|
|
290
|
+
* @param {Uint8Array|Uint8ClampedArray} output
|
|
291
|
+
* @param {number} width
|
|
292
|
+
* @param {number} height
|
|
293
|
+
* @param {typeof DEFAULT_OPTIONS} [options]
|
|
294
|
+
* @return {number}
|
|
295
|
+
*/
|
|
296
|
+
export function pixelmatch(img1, img2, output, width, height, options) {
|
|
297
|
+
if (!isPixelData(img1) || !isPixelData(img2) || (output && !isPixelData(output))) {
|
|
298
|
+
throw new Error('Image data: Uint8Array, Uint8ClampedArray or Buffer expected.');
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (img1.length !== img2.length || (output && output.length !== img1.length)) {
|
|
302
|
+
// throw new Error('Image sizes do not match.');
|
|
303
|
+
return Number.POSITIVE_INFINITY;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (img1.length !== width * height * 4) {
|
|
307
|
+
// throw new Error('Image data size does not match width/height.');
|
|
308
|
+
return Number.POSITIVE_INFINITY;
|
|
309
|
+
}
|
|
310
|
+
options = { ...DEFAULT_OPTIONS, ...options };
|
|
311
|
+
|
|
312
|
+
// check if images are identical
|
|
313
|
+
const len = width * height;
|
|
314
|
+
const a32 = new Uint32Array(img1.buffer, img1.byteOffset, len);
|
|
315
|
+
const b32 = new Uint32Array(img2.buffer, img2.byteOffset, len);
|
|
316
|
+
let identical = true;
|
|
317
|
+
|
|
318
|
+
for (let i = 0; i < len; i++) {
|
|
319
|
+
if (a32[i] !== b32[i]) { identical = false; break; }
|
|
320
|
+
}
|
|
321
|
+
if (identical) { // fast path if identical
|
|
322
|
+
if (output && !options.diffMask) {
|
|
323
|
+
for (let i = 0; i < len; i++) drawGrayPixel(img1, 4 * i, options.alpha, output);
|
|
324
|
+
}
|
|
325
|
+
return 0;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// maximum acceptable square distance between two colors;
|
|
329
|
+
// 35215 is the maximum possible value for the YIQ difference metric
|
|
330
|
+
const maxDelta = 35_215 * options.threshold * options.threshold;
|
|
331
|
+
let diff = 0;
|
|
332
|
+
|
|
333
|
+
// compare each pixel of one image against the other one
|
|
334
|
+
for (let y = 0; y < height; y++) {
|
|
335
|
+
for (let x = 0; x < width; x++) {
|
|
336
|
+
const pos = (y * width + x) * 4;
|
|
337
|
+
|
|
338
|
+
// squared YUV distance between colors at this pixel position, negative if the img2 pixel is darker
|
|
339
|
+
const delta = colorDelta(img1, img2, pos, pos);
|
|
340
|
+
|
|
341
|
+
// the color difference is above the threshold
|
|
342
|
+
if (Math.abs(delta) > maxDelta) {
|
|
343
|
+
// check it's a real rendering difference or just anti-aliasing
|
|
344
|
+
if (!options.includeAA && (antialiased(img1, x, y, width, height, img2)
|
|
345
|
+
|| antialiased(img2, x, y, width, height, img1))) {
|
|
346
|
+
// one of the pixels is anti-aliasing; draw as yellow and do not count as difference
|
|
347
|
+
// note that we do not include such pixels in a mask
|
|
348
|
+
if (output && !options.diffMask) drawPixel(output, pos, ...options.aaColor);
|
|
349
|
+
} else {
|
|
350
|
+
// found substantial difference not caused by anti-aliasing; draw it as such
|
|
351
|
+
if (output) {
|
|
352
|
+
drawPixel(output, pos, ...(delta < 0 && (options.diffColorAlt || options.diffColor)));
|
|
353
|
+
}
|
|
354
|
+
diff++;
|
|
355
|
+
}
|
|
356
|
+
} else if (output // pixels are similar; draw background as grayscale image blended with white
|
|
357
|
+
&& !options.diffMask) drawGrayPixel(img1, pos, options.alpha, output);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// return the number of different pixels
|
|
362
|
+
return diff;
|
|
363
|
+
}
|
package/utils/popup.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} DOMRectLike
|
|
3
|
+
* @prop {number} left
|
|
4
|
+
* @prop {number} right
|
|
5
|
+
* @prop {number} top
|
|
6
|
+
* @prop {number} bottom
|
|
7
|
+
* @prop {number} width
|
|
8
|
+
* @prop {number} height
|
|
9
|
+
*/
|
|
10
|
+
|
|
1
11
|
/**
|
|
2
12
|
* @typedef {Object} CanAnchorPopUpOptions
|
|
3
|
-
* @prop {Element|
|
|
13
|
+
* @prop {Element|DOMRectLike} [anchor]
|
|
4
14
|
* @prop {number|'left'|'center'|'right'} [clientX]
|
|
5
15
|
* @prop {number|'top'|'center'|'bottom'} [clientY]
|
|
6
16
|
* @prop {number} [pageX]
|
|
7
17
|
* @prop {number} [pageY]
|
|
8
|
-
* @prop {Element|
|
|
18
|
+
* @prop {Element|{width:number, height:number}} [popup]
|
|
9
19
|
* @prop {number} [width]
|
|
10
20
|
* @prop {number} [height]
|
|
11
21
|
* @prop {number} [offsetX] Offset from anchor
|
|
@@ -19,9 +29,24 @@
|
|
|
19
29
|
/** @param {CanAnchorPopUpOptions} options */
|
|
20
30
|
export function canAnchorPopup(options) {
|
|
21
31
|
let { pageX, pageY, directionX, directionY } = options;
|
|
32
|
+
const pageWidth = document.documentElement.clientWidth;
|
|
33
|
+
const pageHeight = document.documentElement.clientHeight;
|
|
22
34
|
if (pageX == null || pageY == null) {
|
|
23
35
|
const { clientX, clientY, anchor } = options;
|
|
24
|
-
|
|
36
|
+
let rect;
|
|
37
|
+
if (anchor) {
|
|
38
|
+
rect = anchor instanceof Element ? anchor.getBoundingClientRect() : anchor;
|
|
39
|
+
} else {
|
|
40
|
+
rect = {
|
|
41
|
+
left: 0,
|
|
42
|
+
width: pageWidth,
|
|
43
|
+
right: pageWidth,
|
|
44
|
+
top: 0,
|
|
45
|
+
bottom: pageHeight,
|
|
46
|
+
height: pageHeight,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
25
50
|
if (pageX == null) {
|
|
26
51
|
switch (clientX) {
|
|
27
52
|
case 'left':
|
|
@@ -72,7 +97,7 @@ export function canAnchorPopup(options) {
|
|
|
72
97
|
height = popup.clientHeight;
|
|
73
98
|
} else {
|
|
74
99
|
width = popup.width;
|
|
75
|
-
height = popup.
|
|
100
|
+
height = popup.height;
|
|
76
101
|
}
|
|
77
102
|
}
|
|
78
103
|
|
|
@@ -81,42 +106,84 @@ export function canAnchorPopup(options) {
|
|
|
81
106
|
let bottom;
|
|
82
107
|
let left;
|
|
83
108
|
const margin = options.margin ?? 0;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
109
|
+
|
|
110
|
+
let pageTop = margin;
|
|
111
|
+
let pageBottom = -margin;
|
|
112
|
+
let pageLeft = margin;
|
|
113
|
+
let pageRight = -margin;
|
|
114
|
+
|
|
115
|
+
if (window.visualViewport) {
|
|
116
|
+
pageTop += window.visualViewport.offsetTop;
|
|
117
|
+
pageBottom += window.visualViewport.offsetTop + window.visualViewport.height;
|
|
118
|
+
pageLeft += window.visualViewport.offsetLeft;
|
|
119
|
+
pageRight += window.visualViewport.offsetLeft + window.visualViewport.width;
|
|
120
|
+
} else {
|
|
121
|
+
pageBottom += pageHeight;
|
|
122
|
+
pageRight += pageWidth;
|
|
123
|
+
}
|
|
88
124
|
|
|
89
125
|
const offsetX = options.offsetX ?? 0;
|
|
90
126
|
const offsetY = options.offsetY ?? 0;
|
|
91
127
|
pageX += offsetX;
|
|
92
128
|
pageY += offsetY;
|
|
93
129
|
|
|
130
|
+
let cssTop = 'auto';
|
|
131
|
+
let cssRight = 'auto';
|
|
132
|
+
let cssBottom = 'auto';
|
|
133
|
+
let cssLeft = 'auto';
|
|
134
|
+
let maxHeight = null;
|
|
135
|
+
let maxWidth = null;
|
|
136
|
+
|
|
94
137
|
switch (directionY) {
|
|
95
138
|
case 'up':
|
|
96
139
|
bottom = Math.min(pageY, pageBottom);
|
|
97
140
|
top = Math.max(bottom - height, pageTop);
|
|
141
|
+
cssBottom = `${pageHeight - bottom}px`;
|
|
142
|
+
if (top === pageTop) {
|
|
143
|
+
maxHeight = `${bottom - pageTop}px`;
|
|
144
|
+
}
|
|
98
145
|
break;
|
|
99
146
|
case 'center':
|
|
100
147
|
top = Math.max(pageY - height / 2, pageTop);
|
|
101
148
|
bottom = Math.min(pageY + height / 2, pageBottom);
|
|
149
|
+
cssTop = `${top}px`;
|
|
150
|
+
if (bottom === pageBottom) {
|
|
151
|
+
maxHeight = `${pageBottom - pageTop}px`;
|
|
152
|
+
}
|
|
102
153
|
break;
|
|
103
154
|
default:
|
|
104
155
|
top = Math.max(pageY, pageTop);
|
|
105
156
|
bottom = Math.min(top + height, pageBottom);
|
|
157
|
+
cssTop = `${top}px`;
|
|
158
|
+
if (bottom === pageBottom) {
|
|
159
|
+
maxHeight = `${pageBottom - top}px`;
|
|
160
|
+
}
|
|
106
161
|
}
|
|
107
162
|
|
|
108
163
|
switch (directionX) {
|
|
109
164
|
case 'left':
|
|
110
165
|
right = Math.min(pageX, pageRight);
|
|
111
166
|
left = Math.max(right - width, pageLeft);
|
|
167
|
+
cssRight = `${pageWidth - right}px`;
|
|
168
|
+
if (left === pageLeft) {
|
|
169
|
+
maxWidth = `${right - pageLeft}px`;
|
|
170
|
+
}
|
|
112
171
|
break;
|
|
113
172
|
case 'center':
|
|
114
173
|
left = Math.max(pageX - width / 2, pageLeft);
|
|
115
174
|
right = Math.min(pageX + width / 2, pageRight);
|
|
175
|
+
cssLeft = `${left}px`;
|
|
176
|
+
if (right === pageRight) {
|
|
177
|
+
maxWidth = `${pageRight - pageLeft}px`;
|
|
178
|
+
}
|
|
116
179
|
break;
|
|
117
180
|
default:
|
|
118
181
|
left = Math.max(pageX, pageLeft);
|
|
119
182
|
right = Math.min(left + width, pageRight);
|
|
183
|
+
cssLeft = `${left}px`;
|
|
184
|
+
if (right === pageRight) {
|
|
185
|
+
maxWidth = `${pageRight - left}px`;
|
|
186
|
+
}
|
|
120
187
|
}
|
|
121
188
|
|
|
122
189
|
// compute area
|
|
@@ -125,6 +192,8 @@ export function canAnchorPopup(options) {
|
|
|
125
192
|
|
|
126
193
|
const visibility = realSize / fullSize;
|
|
127
194
|
|
|
195
|
+
const transformOriginX = directionX === 'center' ? 'center' : (directionX === 'left' ? 'right' : 'left');
|
|
196
|
+
const transformOriginY = directionY === 'center' ? 'center' : (directionY === 'up' ? 'bottom' : 'top');
|
|
128
197
|
return {
|
|
129
198
|
...options,
|
|
130
199
|
top,
|
|
@@ -132,7 +201,14 @@ export function canAnchorPopup(options) {
|
|
|
132
201
|
bottom,
|
|
133
202
|
left,
|
|
134
203
|
visibility,
|
|
135
|
-
|
|
136
|
-
|
|
204
|
+
styles: {
|
|
205
|
+
top: cssTop,
|
|
206
|
+
bottom: cssBottom,
|
|
207
|
+
left: cssLeft,
|
|
208
|
+
right: cssRight,
|
|
209
|
+
maxWidth,
|
|
210
|
+
maxHeight,
|
|
211
|
+
transformOrigin: `${transformOriginY} ${transformOriginX}`,
|
|
212
|
+
},
|
|
137
213
|
};
|
|
138
214
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** @type {URLSearchParams} */
|
|
2
|
+
let currentSearchParams = null;
|
|
3
|
+
|
|
4
|
+
/** @return {URLSearchParams} */
|
|
5
|
+
export function getCurrentSearchParams() {
|
|
6
|
+
if (!currentSearchParams) {
|
|
7
|
+
let url;
|
|
8
|
+
try {
|
|
9
|
+
url = import.meta.url;
|
|
10
|
+
} catch {}
|
|
11
|
+
if (!url) {
|
|
12
|
+
try {
|
|
13
|
+
url = /** @type {HTMLScriptElement} */ (document.currentScript).src;
|
|
14
|
+
} catch {}
|
|
15
|
+
}
|
|
16
|
+
if (!url) {
|
|
17
|
+
return new URLSearchParams();
|
|
18
|
+
}
|
|
19
|
+
currentSearchParams = new URL(url).searchParams;
|
|
20
|
+
}
|
|
21
|
+
return currentSearchParams;
|
|
22
|
+
}
|
package/components/Button.md
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# Syntax
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
## Elevated
|
|
5
|
-
```html
|
|
6
|
-
<mdw-button elevated>Elevated</mdw-button>
|
|
7
|
-
<mdw-button disabled elevated>Elevated (disabled)</mdw-button>
|
|
8
|
-
<mdw-button elevated icon=search>Elevated icon</mdw-button>
|
|
9
|
-
<mdw-button elevated color=surface ink=tertiary>Elevated Surface-Tertiary</mdw-button>
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
## Filled
|
|
13
|
-
```html
|
|
14
|
-
<mdw-button filled>Filled button</mdw-button>
|
|
15
|
-
<mdw-button disabled filled>Filled button (Disabled)</mdw-button>
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Filled Tonal
|
|
19
|
-
```html
|
|
20
|
-
<mdw-button filled=tonal>Filled tonal button</mdw-button>
|
|
21
|
-
<mdw-button disabled filled=tonal>Filled tonal button (Disabled)</mdw-button>
|
|
22
|
-
<mdw-button filled=tonal icon=search>Filled tonal button</mdw-button>
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Outlined
|
|
26
|
-
```html
|
|
27
|
-
<mdw-button outlined>Outlined</mdw-button>
|
|
28
|
-
<mdw-button outlined icon=add>Outlined icon</mdw-button>
|
|
29
|
-
<mdw-button outlinedsurface icon=add>Outlined surface icon</mdw-button>
|
|
30
|
-
<mdw-button disabled outlined>Outlined (Disabled)</mdw-button>
|
|
31
|
-
<mdw-button disabled outlined icon=add>Outlined icon (Disabled)</mdw-button>
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Text
|
|
35
|
-
```html
|
|
36
|
-
<mdw-button>Text</mdw-button>
|
|
37
|
-
<mdw-button ink=tertiary icon=add>Tertiary</mdw-button>
|
|
38
|
-
<mdw-button ink=tertiary disabled>Text (Disabled)</mdw-button>
|
|
39
|
-
<mdw-button ink=primary disabled icon=add>Icon text (Disabled)</mdw-button>
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Custom
|
|
43
|
-
```html
|
|
44
|
-
<mdw-button ink=yellow>Custom text</mdw-button>
|
|
45
|
-
<mdw-button elevated ink=yellow>Custom elevated</mdw-button>
|
|
46
|
-
<mdw-button filled color=yellow>Custom filled</mdw-button>
|
|
47
|
-
<mdw-button filled=tonal icon=add color=yellow-container>Custom tonal</mdw-button>
|
|
48
|
-
<mdw-button outlined ink=yellow>Custom outlined</mdw-button>
|
|
49
|
-
<mdw-button disabled outlined>Outlined (Disabled)</mdw-button>
|
|
50
|
-
<mdw-button disabled outlined icon=add>Outlined icon (Disabled)</mdw-button>
|
|
51
|
-
<mdw-button disabled ink=yellow>Custom text</mdw-button>
|
|
52
|
-
<mdw-button disabled elevated=yellow>Custom elevated</mdw-button>
|
|
53
|
-
<mdw-button disabled filled color=yellow>Custom filled</mdw-button>
|
|
54
|
-
<mdw-button disabled filled=tonal icon=add color=yellow-container>Custom tonal</mdw-button>
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
```js
|
|
58
|
-
import Button from "components/Button.js";
|
|
59
|
-
|
|
60
|
-
Button.register()
|
|
61
|
-
```
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import Button from './Button.js';
|
|
2
|
-
|
|
3
|
-
export default Button
|
|
4
|
-
.extend()
|
|
5
|
-
.css`
|
|
6
|
-
/* https://m3.material.io/components/extended-fab/specs */
|
|
7
|
-
|
|
8
|
-
:host {
|
|
9
|
-
--mdw-bg: var(--mdw-color__surface-container-high);
|
|
10
|
-
--mdw-ink: var(--mdw-color__primary);
|
|
11
|
-
--mdw-shape__size: 16px;
|
|
12
|
-
--mdw-surface__shadow__resting: var(--mdw-surface__shadow__3);
|
|
13
|
-
--mdw-surface__shadow__raised: var(--mdw-surface__shadow__4);
|
|
14
|
-
min-inline-size: 48px;
|
|
15
|
-
padding: calc(16px + (var(--mdw-density) * 2px));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
#icon {
|
|
19
|
-
font-size: 24px;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
:host(:where([lowered])) {
|
|
23
|
-
--mdw-bg: var(--mdw-color__surface-container-low);
|
|
24
|
-
--mdw-surface__shadow__resting: var(--mdw-surface__shadow__1);
|
|
25
|
-
--mdw-surface__shadow__raised: var(--mdw-surface__shadow__2);
|
|
26
|
-
}
|
|
27
|
-
`
|
|
28
|
-
.observe({
|
|
29
|
-
filled: { empty: 'tonal' },
|
|
30
|
-
elevated: { type: 'boolean', empty: true },
|
|
31
|
-
})
|
|
32
|
-
.autoRegister('mdw-extended-fab');
|