@shortfuse/materialdesignweb 0.8.0 → 0.9.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 +32 -24
- package/bin/mdw-css.js +1 -1
- package/components/Badge.js +12 -5
- package/components/Body.js +3 -0
- package/components/BottomAppBar.js +1 -8
- package/components/BottomSheet.js +424 -0
- package/components/Box.js +11 -49
- package/components/Button.js +61 -82
- package/components/Card.js +56 -61
- package/components/Checkbox.js +7 -25
- package/components/CheckboxIcon.js +10 -28
- package/components/Chip.js +13 -11
- package/components/Dialog.js +49 -98
- package/components/Display.js +55 -0
- package/components/Fab.js +83 -17
- package/components/FabContainer.js +48 -0
- package/components/FilterChip.js +34 -32
- package/components/Grid.js +176 -0
- package/components/Headline.js +5 -28
- package/components/Icon.js +54 -69
- package/components/IconButton.js +71 -120
- package/components/Input.js +669 -83
- package/components/InputChip.js +161 -0
- package/components/Label.js +3 -0
- package/components/List.js +1 -5
- package/components/ListItem.js +39 -23
- package/components/ListOption.js +79 -62
- package/components/Listbox.js +19 -10
- package/components/Menu.js +8 -18
- package/components/MenuItem.js +25 -26
- package/components/NavBar.js +53 -19
- package/components/NavDrawer.js +15 -15
- package/components/NavDrawerItem.js +2 -4
- package/components/NavItem.js +40 -33
- package/components/NavRail.js +23 -21
- package/components/NavRailItem.js +5 -2
- package/components/Page.js +105 -0
- package/components/Pane.js +18 -0
- package/components/Popup.js +17 -8
- package/components/Radio.js +2 -5
- package/components/RadioIcon.js +10 -14
- package/components/Ripple.js +11 -7
- package/components/Root.js +209 -0
- package/components/Scrim.js +87 -0
- package/components/Search.js +12 -20
- package/components/SegmentedButton.js +33 -36
- package/components/SegmentedButtonGroup.js +9 -3
- package/components/Select.js +6 -7
- package/components/Shape.js +5 -65
- package/components/SideSheet.js +308 -0
- package/components/Slider.js +71 -34
- package/components/Snackbar.js +22 -16
- package/components/SnackbarContainer.js +42 -0
- package/components/Surface.js +15 -10
- package/components/Switch.js +3 -16
- package/components/SwitchIcon.js +40 -32
- package/components/Tab.js +57 -38
- package/components/TabContent.js +1 -0
- package/components/TabList.js +60 -32
- package/components/TabPanel.js +1 -1
- package/components/Table.js +116 -0
- package/components/TextArea.js +16 -15
- package/components/Title.js +4 -9
- package/components/Tooltip.js +43 -21
- package/components/TopAppBar.js +56 -78
- package/constants/shapes.js +36 -0
- package/constants/typography.js +127 -0
- package/core/Composition.js +354 -192
- package/core/CompositionAdapter.js +11 -12
- package/core/CustomElement.js +588 -236
- package/core/css.js +117 -12
- package/core/customTypes.js +120 -25
- package/core/dom.js +17 -11
- package/core/jsonMergePatch.js +12 -10
- package/core/observe.js +298 -253
- package/core/optimizations.js +9 -9
- package/core/template.js +14 -57
- 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 +106 -0
- package/{theming/themableMixinLoader.js → loaders/palette.js} +4 -3
- package/loaders/theme.js +12 -0
- package/mixins/AriaReflectorMixin.js +53 -13
- package/mixins/AriaToolbarMixin.js +3 -0
- package/mixins/ControlMixin.js +76 -33
- package/mixins/DelegatesFocusMixin.js +54 -0
- package/mixins/DensityMixin.js +2 -2
- package/mixins/ElevationMixin.js +62 -0
- package/mixins/FlexableMixin.js +66 -37
- package/mixins/FormAssociatedMixin.js +60 -8
- package/mixins/HyperlinkMixin.js +66 -0
- package/mixins/InputMixin.js +205 -32
- package/mixins/KeyboardNavMixin.js +8 -6
- package/mixins/NavigationListenerMixin.js +33 -0
- package/mixins/PopupMixin.js +176 -208
- package/mixins/ResizeObserverMixin.js +16 -4
- package/mixins/RippleMixin.js +8 -6
- package/mixins/ScrollListenerMixin.js +1 -1
- package/mixins/SemiStickyMixin.js +44 -98
- package/mixins/ShapeMaskedMixin.js +117 -0
- package/mixins/ShapeMixin.js +22 -204
- package/mixins/StateMixin.js +70 -34
- package/mixins/TextFieldMixin.js +107 -143
- package/mixins/ThemableMixin.js +44 -56
- package/mixins/TooltipTriggerMixin.js +291 -359
- package/mixins/TouchTargetMixin.js +1 -1
- package/mixins/TypographyMixin.js +121 -0
- package/package.json +110 -74
- package/services/rtl.js +10 -0
- package/services/svgAlias.js +17 -0
- package/{theming/index.js → services/theme.js} +24 -174
- 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 +73 -0
- package/types/components/BottomAppBar.d.ts.map +1 -0
- package/types/components/BottomSheet.d.ts +109 -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 +714 -0
- package/types/components/Button.d.ts.map +1 -0
- package/types/components/Card.d.ts +412 -0
- package/types/components/Card.d.ts.map +1 -0
- package/types/components/Checkbox.d.ts +205 -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 +1425 -0
- package/types/components/Chip.d.ts.map +1 -0
- package/types/components/Dialog.d.ts +286 -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 +45 -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 +741 -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 +4283 -0
- package/types/components/FilterChip.d.ts.map +1 -0
- package/types/components/Grid.d.ts +37 -0
- package/types/components/Grid.d.ts.map +1 -0
- package/types/components/Headline.d.ts +47 -0
- package/types/components/Headline.d.ts.map +1 -0
- package/types/components/Icon.d.ts +103 -0
- package/types/components/Icon.d.ts.map +1 -0
- package/types/components/IconButton.d.ts +1486 -0
- package/types/components/IconButton.d.ts.map +1 -0
- package/types/components/Input.d.ts +51288 -0
- package/types/components/Input.d.ts.map +1 -0
- package/types/components/InputChip.d.ts +243 -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 +31 -0
- package/types/components/List.d.ts.map +1 -0
- package/types/components/ListItem.d.ts +349 -0
- package/types/components/ListItem.d.ts.map +1 -0
- package/types/components/ListOption.d.ts +1493 -0
- package/types/components/ListOption.d.ts.map +1 -0
- package/types/components/Listbox.d.ts +12012 -0
- package/types/components/Listbox.d.ts.map +1 -0
- package/types/components/Menu.d.ts +119 -0
- package/types/components/Menu.d.ts.map +1 -0
- package/types/components/MenuItem.d.ts +3109 -0
- package/types/components/MenuItem.d.ts.map +1 -0
- package/types/components/NavBar.d.ts +18 -0
- package/types/components/NavBar.d.ts.map +1 -0
- package/types/components/NavBarItem.d.ts +186 -0
- package/types/components/NavBarItem.d.ts.map +1 -0
- package/types/components/NavDrawer.d.ts +108 -0
- package/types/components/NavDrawer.d.ts.map +1 -0
- package/types/components/NavDrawerItem.d.ts +186 -0
- package/types/components/NavDrawerItem.d.ts.map +1 -0
- package/types/components/NavItem.d.ts +190 -0
- package/types/components/NavItem.d.ts.map +1 -0
- package/types/components/NavRail.d.ts +109 -0
- package/types/components/NavRail.d.ts.map +1 -0
- package/types/components/NavRailItem.d.ts +186 -0
- package/types/components/NavRailItem.d.ts.map +1 -0
- package/types/components/Page.d.ts +24 -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 +76 -0
- package/types/components/Popup.d.ts.map +1 -0
- package/types/components/Progress.d.ts +19 -0
- package/types/components/Progress.d.ts.map +1 -0
- package/types/components/Radio.d.ts +199 -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 +34 -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 +16 -0
- package/types/components/Search.d.ts.map +1 -0
- package/types/components/SegmentedButton.d.ts +718 -0
- package/types/components/SegmentedButton.d.ts.map +1 -0
- package/types/components/SegmentedButtonGroup.d.ts +44 -0
- package/types/components/SegmentedButtonGroup.d.ts.map +1 -0
- package/types/components/Select.d.ts +1361 -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 +106 -0
- package/types/components/SideSheet.d.ts.map +1 -0
- package/types/components/Slider.d.ts +382 -0
- package/types/components/Slider.d.ts.map +1 -0
- package/types/components/Snackbar.d.ts +65 -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 +183 -0
- package/types/components/Switch.d.ts.map +1 -0
- package/types/components/SwitchIcon.d.ts +169 -0
- package/types/components/SwitchIcon.d.ts.map +1 -0
- package/types/components/Tab.d.ts +879 -0
- package/types/components/Tab.d.ts.map +1 -0
- package/types/components/TabContent.d.ts +122 -0
- package/types/components/TabContent.d.ts.map +1 -0
- package/types/components/TabList.d.ts +6266 -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 +2 -0
- package/types/components/Table.d.ts.map +1 -0
- package/types/components/TextArea.d.ts +1394 -0
- package/types/components/TextArea.d.ts.map +1 -0
- package/types/components/Title.d.ts +47 -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 +130 -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 +252 -0
- package/types/core/Composition.d.ts.map +1 -0
- package/types/core/CompositionAdapter.d.ts +92 -0
- package/types/core/CompositionAdapter.d.ts.map +1 -0
- package/types/core/CustomElement.d.ts +302 -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 +26 -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 +113 -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 +23 -0
- package/types/mixins/AriaReflectorMixin.d.ts.map +1 -0
- package/types/mixins/AriaToolbarMixin.d.ts +32 -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 +5 -0
- package/types/mixins/DelegatesFocusMixin.d.ts.map +1 -0
- package/types/mixins/DensityMixin.d.ts +5 -0
- package/types/mixins/DensityMixin.d.ts.map +1 -0
- package/types/mixins/ElevationMixin.d.ts +33 -0
- package/types/mixins/ElevationMixin.d.ts.map +1 -0
- package/types/mixins/FlexableMixin.d.ts +13 -0
- package/types/mixins/FlexableMixin.d.ts.map +1 -0
- package/types/mixins/FormAssociatedMixin.d.ts +122 -0
- package/types/mixins/FormAssociatedMixin.d.ts.map +1 -0
- package/types/mixins/HyperlinkMixin.d.ts +22 -0
- package/types/mixins/HyperlinkMixin.d.ts.map +1 -0
- package/types/mixins/InputMixin.d.ts +179 -0
- package/types/mixins/InputMixin.d.ts.map +1 -0
- package/types/mixins/KeyboardNavMixin.d.ts +47 -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 +82 -0
- package/types/mixins/PopupMixin.d.ts.map +1 -0
- package/types/mixins/RTLObserverMixin.d.ts +7 -0
- package/types/mixins/RTLObserverMixin.d.ts.map +1 -0
- package/types/mixins/ResizeObserverMixin.d.ts +12 -0
- package/types/mixins/ResizeObserverMixin.d.ts.map +1 -0
- package/types/mixins/RippleMixin.d.ts +92 -0
- package/types/mixins/RippleMixin.d.ts.map +1 -0
- package/types/mixins/ScrollListenerMixin.d.ts +41 -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 +9 -0
- package/types/mixins/ShapeMaskedMixin.d.ts.map +1 -0
- package/types/mixins/ShapeMixin.d.ts +38 -0
- package/types/mixins/ShapeMixin.d.ts.map +1 -0
- package/types/mixins/StateMixin.d.ts +27 -0
- package/types/mixins/StateMixin.d.ts.map +1 -0
- package/types/mixins/TextFieldMixin.d.ts +1354 -0
- package/types/mixins/TextFieldMixin.d.ts.map +1 -0
- package/types/mixins/ThemableMixin.d.ts +9 -0
- package/types/mixins/ThemableMixin.d.ts.map +1 -0
- package/types/mixins/TooltipTriggerMixin.d.ts +106 -0
- package/types/mixins/TooltipTriggerMixin.d.ts.map +1 -0
- package/types/mixins/TouchTargetMixin.d.ts +3 -0
- package/types/mixins/TouchTargetMixin.d.ts.map +1 -0
- package/types/mixins/TypographyMixin.d.ts +17 -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/material-color/scheme/Scheme.js +1 -1
- package/utils/pixelmatch.js +360 -0
- package/utils/popup.js +86 -10
- package/utils/searchParams.js +19 -0
- 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,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Utility methods for mathematical operations.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* The signum function.
|
|
22
|
+
* @param {number} num
|
|
23
|
+
* @return {1|-1|0} 1 if num > 0, -1 if num < 0, and 0 if num = 0
|
|
24
|
+
*/
|
|
25
|
+
export function signum(num: number): 1 | -1 | 0;
|
|
26
|
+
/**
|
|
27
|
+
* The linear interpolation function.
|
|
28
|
+
* @param {number} start
|
|
29
|
+
* @param {number} stop
|
|
30
|
+
* @param {number} amount
|
|
31
|
+
* @return {number} start if amount = 0 and stop if amount = 1
|
|
32
|
+
*/
|
|
33
|
+
export function lerp(start: number, stop: number, amount: number): number;
|
|
34
|
+
/**
|
|
35
|
+
* Clamps an integer between two integers.
|
|
36
|
+
* @param {number} min
|
|
37
|
+
* @param {number} max
|
|
38
|
+
* @param {number} input
|
|
39
|
+
* @return {number} input when min <= input <= max, and either min or max
|
|
40
|
+
* otherwise.
|
|
41
|
+
*/
|
|
42
|
+
export function clampInt(min: number, max: number, input: number): number;
|
|
43
|
+
/**
|
|
44
|
+
* Clamps an integer between two floating-point numbers.
|
|
45
|
+
* @param {number} min
|
|
46
|
+
* @param {number} max
|
|
47
|
+
* @param {number} input
|
|
48
|
+
* @return {number} input when min <= input <= max, and either min or max
|
|
49
|
+
* otherwise.
|
|
50
|
+
*/
|
|
51
|
+
export function clampDouble(min: number, max: number, input: number): number;
|
|
52
|
+
/**
|
|
53
|
+
* Sanitizes a degree measure as an integer.
|
|
54
|
+
* @param {number} degrees
|
|
55
|
+
* @return {number} a degree measure between 0 (inclusive) and 360
|
|
56
|
+
* (exclusive).
|
|
57
|
+
*/
|
|
58
|
+
export function sanitizeDegreesInt(degrees: number): number;
|
|
59
|
+
/**
|
|
60
|
+
* Sanitizes a degree measure as a floating-point number.
|
|
61
|
+
* @param {number} degrees
|
|
62
|
+
* @return {number} a degree measure between 0.0 (inclusive) and 360.0
|
|
63
|
+
* (exclusive).
|
|
64
|
+
*/
|
|
65
|
+
export function sanitizeDegreesDouble(degrees: number): number;
|
|
66
|
+
/**
|
|
67
|
+
* Sign of direction change needed to travel from one angle to
|
|
68
|
+
* another.
|
|
69
|
+
*
|
|
70
|
+
* For angles that are 180 degrees apart from each other, both
|
|
71
|
+
* directions have the same travel distance, so either direction is
|
|
72
|
+
* shortest. The value 1.0 is returned in this case.
|
|
73
|
+
* @param {number} from The angle travel starts from, in degrees.
|
|
74
|
+
* @param {number} to The angle travel ends at, in degrees.
|
|
75
|
+
* @return {number} -1 if decreasing from leads to the shortest travel
|
|
76
|
+
* distance, 1 if increasing from leads to the shortest travel
|
|
77
|
+
* distance.
|
|
78
|
+
*/
|
|
79
|
+
export function rotationDirection(from: number, to: number): number;
|
|
80
|
+
/**
|
|
81
|
+
* Distance of two points on a circle, represented using degrees.
|
|
82
|
+
* @param {number} a
|
|
83
|
+
* @param {number} b
|
|
84
|
+
* @return {number}
|
|
85
|
+
*/
|
|
86
|
+
export function differenceDegrees(a: number, b: number): number;
|
|
87
|
+
/**
|
|
88
|
+
* Multiplies a 1x3 row vector with a 3x3 matrix.
|
|
89
|
+
* @param {number[]} row
|
|
90
|
+
* @param {number[][]} matrix
|
|
91
|
+
* @return {number[]}
|
|
92
|
+
*/
|
|
93
|
+
export function matrixMultiply(row: number[], matrix: number[][]): number[];
|
|
94
|
+
//# sourceMappingURL=math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../../utils/material-color/utils/math.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH;;GAEG;AAEH;;;;GAIG;AACH,4BAHW,MAAM,GACL,CAAC,GAAC,CAAC,CAAC,GAAC,CAAC,CAUjB;AAED;;;;;;GAMG;AACH,4BALW,MAAM,QACN,MAAM,UACN,MAAM,GACL,MAAM,CAIjB;AAED;;;;;;;GAOG;AACH,8BANW,MAAM,OACN,MAAM,SACN,MAAM,GACL,MAAM,CAWjB;AAED;;;;;;;GAOG;AACH,iCANW,MAAM,OACN,MAAM,SACN,MAAM,GACL,MAAM,CAWjB;AAED;;;;;GAKG;AACH,4CAJW,MAAM,GACL,MAAM,CASjB;AAED;;;;;GAKG;AACH,+CAJW,MAAM,GACL,MAAM,CASjB;AAED;;;;;;;;;;;;GAYG;AACH,wCANW,MAAM,MACN,MAAM,GACL,MAAM,CAOjB;AAED;;;;;GAKG;AACH,qCAJW,MAAM,KACN,MAAM,GACL,MAAM,CAIjB;AAED;;;;;GAKG;AACH,oCAJW,MAAM,EAAE,UACR,MAAM,EAAE,EAAE,GACT,MAAM,EAAE,CAOnB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Uint8Array|Uint8ClampedArray} img1
|
|
3
|
+
* @param {Uint8Array|Uint8ClampedArray} img2
|
|
4
|
+
* @param {Uint8Array|Uint8ClampedArray} output
|
|
5
|
+
* @param {number} width
|
|
6
|
+
* @param {number} height
|
|
7
|
+
* @param {typeof DEFAULT_OPTIONS} [options]
|
|
8
|
+
* @return {number}
|
|
9
|
+
*/
|
|
10
|
+
export function pixelmatch(img1: Uint8Array | Uint8ClampedArray, img2: Uint8Array | Uint8ClampedArray, output: Uint8Array | Uint8ClampedArray, width: number, height: number, options?: typeof DEFAULT_OPTIONS): number;
|
|
11
|
+
type DEFAULT_OPTIONS = Object;
|
|
12
|
+
declare namespace DEFAULT_OPTIONS {
|
|
13
|
+
let threshold: number;
|
|
14
|
+
let includeAA: boolean;
|
|
15
|
+
let alpha: number;
|
|
16
|
+
let aaColor: number[];
|
|
17
|
+
let diffColor: number[];
|
|
18
|
+
let diffColorAlt: Array<number>;
|
|
19
|
+
let diffMask: boolean;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=pixelmatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pixelmatch.d.ts","sourceRoot":"","sources":["../../utils/pixelmatch.js"],"names":[],"mappings":"AA2RA;;;;;;;;GAQG;AACH,iCARW,UAAU,GAAC,iBAAiB,QAC5B,UAAU,GAAC,iBAAiB,UAC5B,UAAU,GAAC,iBAAiB,SAC5B,MAAM,UACN,MAAM,YACN,OAAO,eAAe,GACrB,MAAM,CAqEjB;uBAtVU,MAAM;;;;;;;sBAcL,KAAK,CAAC,MAAM,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* @typedef {Object} CanAnchorPopUpOptions
|
|
12
|
+
* @prop {Element|DOMRectLike} [anchor]
|
|
13
|
+
* @prop {number|'left'|'center'|'right'} [clientX]
|
|
14
|
+
* @prop {number|'top'|'center'|'bottom'} [clientY]
|
|
15
|
+
* @prop {number} [pageX]
|
|
16
|
+
* @prop {number} [pageY]
|
|
17
|
+
* @prop {Element|{width:number, height:number}} [popup]
|
|
18
|
+
* @prop {number} [width]
|
|
19
|
+
* @prop {number} [height]
|
|
20
|
+
* @prop {number} [offsetX] Offset from anchor
|
|
21
|
+
* @prop {number} [offsetY] Offset from anchor
|
|
22
|
+
* @prop {number} [margin] Margin from page
|
|
23
|
+
* @prop {'left'|'center'|'right'} [directionX='right']
|
|
24
|
+
* @prop {'up'|'center'|'down'} [directionY='down']
|
|
25
|
+
* @prop {boolean} [force=false]
|
|
26
|
+
*/
|
|
27
|
+
/** @param {CanAnchorPopUpOptions} options */
|
|
28
|
+
export function canAnchorPopup(options: CanAnchorPopUpOptions): {
|
|
29
|
+
top: number;
|
|
30
|
+
right: number;
|
|
31
|
+
bottom: number;
|
|
32
|
+
left: number;
|
|
33
|
+
visibility: number;
|
|
34
|
+
styles: {
|
|
35
|
+
top: string;
|
|
36
|
+
bottom: string;
|
|
37
|
+
left: string;
|
|
38
|
+
right: string;
|
|
39
|
+
maxWidth: string;
|
|
40
|
+
maxHeight: string;
|
|
41
|
+
transformOrigin: string;
|
|
42
|
+
};
|
|
43
|
+
anchor?: Element | DOMRectLike;
|
|
44
|
+
clientX?: number | "left" | "center" | "right";
|
|
45
|
+
clientY?: number | "top" | "center" | "bottom";
|
|
46
|
+
pageX?: number;
|
|
47
|
+
pageY?: number;
|
|
48
|
+
popup?: Element | {
|
|
49
|
+
width: number;
|
|
50
|
+
height: number;
|
|
51
|
+
};
|
|
52
|
+
width?: number;
|
|
53
|
+
height?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Offset from anchor
|
|
56
|
+
*/
|
|
57
|
+
offsetX?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Offset from anchor
|
|
60
|
+
*/
|
|
61
|
+
offsetY?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Margin from page
|
|
64
|
+
*/
|
|
65
|
+
margin?: number;
|
|
66
|
+
directionX?: "left" | "center" | "right";
|
|
67
|
+
directionY?: "up" | "center" | "down";
|
|
68
|
+
force?: boolean;
|
|
69
|
+
};
|
|
70
|
+
export type DOMRectLike = {
|
|
71
|
+
left: number;
|
|
72
|
+
right: number;
|
|
73
|
+
top: number;
|
|
74
|
+
bottom: number;
|
|
75
|
+
width: number;
|
|
76
|
+
height: number;
|
|
77
|
+
};
|
|
78
|
+
export type CanAnchorPopUpOptions = {
|
|
79
|
+
anchor?: Element | DOMRectLike;
|
|
80
|
+
clientX?: number | "left" | "center" | "right";
|
|
81
|
+
clientY?: number | "top" | "center" | "bottom";
|
|
82
|
+
pageX?: number;
|
|
83
|
+
pageY?: number;
|
|
84
|
+
popup?: Element | {
|
|
85
|
+
width: number;
|
|
86
|
+
height: number;
|
|
87
|
+
};
|
|
88
|
+
width?: number;
|
|
89
|
+
height?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Offset from anchor
|
|
92
|
+
*/
|
|
93
|
+
offsetX?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Offset from anchor
|
|
96
|
+
*/
|
|
97
|
+
offsetY?: number;
|
|
98
|
+
/**
|
|
99
|
+
* Margin from page
|
|
100
|
+
*/
|
|
101
|
+
margin?: number;
|
|
102
|
+
directionX?: "left" | "center" | "right";
|
|
103
|
+
directionY?: "up" | "center" | "down";
|
|
104
|
+
force?: boolean;
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=popup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"popup.d.ts","sourceRoot":"","sources":["../../utils/popup.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;;GAgBG;AAEH,6CAA6C;AAC7C,wCADY,qBAAqB;;;;;;;;;;;;;;;aAhBvB,OAAO,GAAC,WAAW;cACnB,MAAM,GAAC,MAAM,GAAC,QAAQ,GAAC,OAAO;cAC9B,MAAM,GAAC,KAAK,GAAC,QAAQ,GAAC,QAAQ;YAC9B,MAAM;YACN,MAAM;YACN,OAAO,GAAC;QAAC,KAAK,EAAC,MAAM,CAAC;QAAC,MAAM,EAAC,MAAM,CAAA;KAAC;YACrC,MAAM;aACN,MAAM;;;;cACN,MAAM;;;;cACN,MAAM;;;;aACN,MAAM;iBACN,MAAM,GAAC,QAAQ,GAAC,OAAO;iBACvB,IAAI,GAAC,QAAQ,GAAC,MAAM;YACpB,OAAO;EA4LhB;;UAnNS,MAAM;WACN,MAAM;SACN,MAAM;YACN,MAAM;WACN,MAAM;YACN,MAAM;;;aAKN,OAAO,GAAC,WAAW;cACnB,MAAM,GAAC,MAAM,GAAC,QAAQ,GAAC,OAAO;cAC9B,MAAM,GAAC,KAAK,GAAC,QAAQ,GAAC,QAAQ;YAC9B,MAAM;YACN,MAAM;YACN,OAAO,GAAC;QAAC,KAAK,EAAC,MAAM,CAAC;QAAC,MAAM,EAAC,MAAM,CAAA;KAAC;YACrC,MAAM;aACN,MAAM;;;;cACN,MAAM;;;;cACN,MAAM;;;;aACN,MAAM;iBACN,MAAM,GAAC,QAAQ,GAAC,OAAO;iBACvB,IAAI,GAAC,QAAQ,GAAC,MAAM;YACpB,OAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchParams.d.ts","sourceRoot":"","sources":["../../utils/searchParams.js"],"names":[],"mappings":"AAGA,gCAAgC;AAChC,0CADa,eAAe,CAe3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["../../utils/svg.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,iCAHW,MAAM,GACL,MAAM,CAQjB"}
|
|
@@ -137,7 +137,7 @@ export default class Scheme {
|
|
|
137
137
|
onSurfaceVariant: core.n2.tone(80),
|
|
138
138
|
outline: core.n2.tone(60),
|
|
139
139
|
outlineVariant: core.n2.tone(30),
|
|
140
|
-
shadow: core.n1.tone(
|
|
140
|
+
shadow: core.n1.tone(40), // (Underlight)
|
|
141
141
|
scrim: core.n1.tone(0),
|
|
142
142
|
inverseSurface: core.n1.tone(90),
|
|
143
143
|
inverseOnSurface: core.n1.tone(20),
|
|
@@ -0,0 +1,360 @@
|
|
|
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
|
+
aaColor: [255, 255, 0],
|
|
28
|
+
diffColor: [255, 0, 0], // color of different pixels in diff output
|
|
29
|
+
/**
|
|
30
|
+
* whether to detect dark on light differences between img1 and img2 and set
|
|
31
|
+
* an alternative color to differentiate between the two
|
|
32
|
+
* @type {Array<number>}
|
|
33
|
+
*/
|
|
34
|
+
diffColorAlt: null,
|
|
35
|
+
/** draw the diff over a transparent background (a mask) */
|
|
36
|
+
diffMask: false,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {ArrayBufferView} arr
|
|
41
|
+
*/
|
|
42
|
+
function isPixelData(arr) {
|
|
43
|
+
// work around instanceof Uint8Array not working properly in some Jest environments
|
|
44
|
+
return ArrayBuffer.isView(arr) && arr.constructor.BYTES_PER_ELEMENT === 1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Check if a pixel has 3+ adjacent pixels of the same color.
|
|
49
|
+
* @param {Array<number>} img
|
|
50
|
+
* @param {number} x1
|
|
51
|
+
* @param {number} y1
|
|
52
|
+
* @param {number} width
|
|
53
|
+
* @param {number} height
|
|
54
|
+
*/
|
|
55
|
+
function hasManySiblings(img, x1, y1, width, height) {
|
|
56
|
+
const x0 = Math.max(x1 - 1, 0);
|
|
57
|
+
const y0 = Math.max(y1 - 1, 0);
|
|
58
|
+
const x2 = Math.min(x1 + 1, width - 1);
|
|
59
|
+
const y2 = Math.min(y1 + 1, height - 1);
|
|
60
|
+
const pos = (y1 * width + x1) * 4;
|
|
61
|
+
let zeroes = x1 === x0 || x1 === x2 || y1 === y0 || y1 === y2 ? 1 : 0;
|
|
62
|
+
|
|
63
|
+
// go through 8 adjacent pixels
|
|
64
|
+
for (let x = x0; x <= x2; x++) {
|
|
65
|
+
for (let y = y0; y <= y2; y++) {
|
|
66
|
+
if (x === x1 && y === y1) continue;
|
|
67
|
+
|
|
68
|
+
const pos2 = 4 * (y * width + x);
|
|
69
|
+
if (img[pos] === img[pos2]
|
|
70
|
+
&& img[pos + 1] === img[pos2 + 1]
|
|
71
|
+
&& img[pos + 2] === img[pos2 + 2]
|
|
72
|
+
&& img[pos + 3] === img[pos2 + 3]) zeroes++;
|
|
73
|
+
|
|
74
|
+
if (zeroes > 2) return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* blend semi-transparent color with white
|
|
83
|
+
* @param {number} color
|
|
84
|
+
* @param {number} alpha
|
|
85
|
+
*/
|
|
86
|
+
function blend(color, alpha) {
|
|
87
|
+
return 255 + (color - 255) * alpha;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Returns Y from RGB=>YIQ
|
|
92
|
+
* @param {number} red
|
|
93
|
+
* @param {number} green
|
|
94
|
+
* @param {number} blue
|
|
95
|
+
*/
|
|
96
|
+
function yFromRGBToYIQ(red, green, blue) {
|
|
97
|
+
return (0.298_895_31 * red) + (0.586_622_47 * green) + (0.114_482_23 * blue);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Returns I from RGB=>YIQ
|
|
102
|
+
* @param {number} red
|
|
103
|
+
* @param {number} green
|
|
104
|
+
* @param {number} blue
|
|
105
|
+
*/
|
|
106
|
+
function iFromRGBToYIQ(red, green, blue) {
|
|
107
|
+
return (0.595_977_99 * red) + (-0.274_176_1 * green) + (-0.321_801_89 * blue);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Returns Q from RGB=>YIQ
|
|
112
|
+
* @param {number} red
|
|
113
|
+
* @param {number} green
|
|
114
|
+
* @param {number} blue
|
|
115
|
+
* @return {number}
|
|
116
|
+
*/
|
|
117
|
+
function qFromRGBToYIQ(red, green, blue) {
|
|
118
|
+
return (0.211_470_17 * red) + (-0.522_617_11 * green) + (0.311_146_94 * blue);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Returns YIQ from RGB
|
|
123
|
+
* @param {number} red
|
|
124
|
+
* @param {number} green
|
|
125
|
+
* @param {number} blue
|
|
126
|
+
* @return {{y:number, i:number, q:number}}
|
|
127
|
+
*/
|
|
128
|
+
function yiqFromRGB(red, green, blue) {
|
|
129
|
+
return {
|
|
130
|
+
y: yFromRGBToYIQ(red, green, blue),
|
|
131
|
+
i: iFromRGBToYIQ(red, green, blue),
|
|
132
|
+
q: qFromRGBToYIQ(red, green, blue),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* calculate color difference according to the paper "Measuring perceived color
|
|
138
|
+
* difference using YIQ NTSC transmission color space in mobile applications"
|
|
139
|
+
* by Y. Kotsarenko and F. Ramos
|
|
140
|
+
* @param {Array<number>} img1
|
|
141
|
+
* @param {Array<number>} img2
|
|
142
|
+
* @param {number} k
|
|
143
|
+
* @param {number} m
|
|
144
|
+
* @param {boolean} [yOnly]
|
|
145
|
+
* @return {number}
|
|
146
|
+
*/
|
|
147
|
+
function colorDelta(img1, img2, k, m, yOnly) {
|
|
148
|
+
let r1 = img1[k + 0];
|
|
149
|
+
let g1 = img1[k + 1];
|
|
150
|
+
let b1 = img1[k + 2];
|
|
151
|
+
let a1 = img1[k + 3];
|
|
152
|
+
|
|
153
|
+
let r2 = img2[m + 0];
|
|
154
|
+
let g2 = img2[m + 1];
|
|
155
|
+
let b2 = img2[m + 2];
|
|
156
|
+
let a2 = img2[m + 3];
|
|
157
|
+
|
|
158
|
+
if (a1 === a2 && r1 === r2 && g1 === g2 && b1 === b2) return 0;
|
|
159
|
+
|
|
160
|
+
if (a1 < 255) {
|
|
161
|
+
a1 /= 255;
|
|
162
|
+
r1 = blend(r1, a1);
|
|
163
|
+
g1 = blend(g1, a1);
|
|
164
|
+
b1 = blend(b1, a1);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (a2 < 255) {
|
|
168
|
+
a2 /= 255;
|
|
169
|
+
r2 = blend(r2, a2);
|
|
170
|
+
g2 = blend(g2, a2);
|
|
171
|
+
b2 = blend(b2, a2);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (yOnly) {
|
|
175
|
+
return yFromRGBToYIQ(r1, g1, b1) - yFromRGBToYIQ(r2, g2, b2);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const { y: y1, i: i1, q: q1 } = yiqFromRGB(r1, g1, b1);
|
|
179
|
+
const { y: y2, i: i2, q: q2 } = yiqFromRGB(r2, g2, b2);
|
|
180
|
+
|
|
181
|
+
const y = y1 - y2;
|
|
182
|
+
const i = i1 - i2;
|
|
183
|
+
const q = q1 - q2;
|
|
184
|
+
|
|
185
|
+
const delta = (0.5053 * y * y) + (0.299 * i * i) + (0.1957 * q * q);
|
|
186
|
+
|
|
187
|
+
// encode whether the pixel lightens or darkens in the sign
|
|
188
|
+
return y1 > y2 ? -delta : delta;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @param {Uint8Array|Uint8ClampedArray} destination
|
|
193
|
+
* @param {number} index
|
|
194
|
+
* @param {number} red
|
|
195
|
+
* @param {number} green
|
|
196
|
+
* @param {number} blue
|
|
197
|
+
* @return {void}
|
|
198
|
+
*/
|
|
199
|
+
function drawPixel(destination, index, red, green, blue) {
|
|
200
|
+
destination[index + 0] = red;
|
|
201
|
+
destination[index + 1] = green;
|
|
202
|
+
destination[index + 2] = blue;
|
|
203
|
+
destination[index + 3] = 255;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @param {Uint8Array|Uint8ClampedArray} source
|
|
208
|
+
* @param {number} index
|
|
209
|
+
* @param {number} alpha
|
|
210
|
+
* @param {Uint8Array|Uint8ClampedArray} destination
|
|
211
|
+
*/
|
|
212
|
+
function drawGrayPixel(source, index, alpha, destination) {
|
|
213
|
+
const red = source[index + 0];
|
|
214
|
+
const green = source[index + 1];
|
|
215
|
+
const blue = source[index + 2];
|
|
216
|
+
const val = blend(yFromRGBToYIQ(red, green, blue), (alpha * source[index + 3]) / 255);
|
|
217
|
+
drawPixel(destination, index, val, val, val);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Check if a pixel is likely a part of anti-aliasing;
|
|
222
|
+
*
|
|
223
|
+
* Based on "Anti-aliased Pixel and Intensity Slope Detector" paper by V.
|
|
224
|
+
* Vysniauskas, 2009
|
|
225
|
+
* @param {Array<number>} img
|
|
226
|
+
* @param {number} x1
|
|
227
|
+
* @param {number} y1
|
|
228
|
+
* @param {number} width
|
|
229
|
+
* @param {number} height
|
|
230
|
+
* @param {Array<number>} img2
|
|
231
|
+
*/
|
|
232
|
+
function antialiased(img, x1, y1, width, height, img2) {
|
|
233
|
+
const x0 = Math.max(x1 - 1, 0);
|
|
234
|
+
const y0 = Math.max(y1 - 1, 0);
|
|
235
|
+
const x2 = Math.min(x1 + 1, width - 1);
|
|
236
|
+
const y2 = Math.min(y1 + 1, height - 1);
|
|
237
|
+
const pos = (y1 * width + x1) * 4;
|
|
238
|
+
let zeroes = x1 === x0 || x1 === x2 || y1 === y0 || y1 === y2 ? 1 : 0;
|
|
239
|
+
let min = 0;
|
|
240
|
+
let max = 0;
|
|
241
|
+
let minX; let minY; let maxX; let
|
|
242
|
+
maxY;
|
|
243
|
+
|
|
244
|
+
// go through 8 adjacent pixels
|
|
245
|
+
for (let x = x0; x <= x2; x++) {
|
|
246
|
+
for (let y = y0; y <= y2; y++) {
|
|
247
|
+
if (x === x1 && y === y1) continue;
|
|
248
|
+
|
|
249
|
+
// brightness delta between the center pixel and adjacent one
|
|
250
|
+
const delta = colorDelta(img, img, pos, (y * width + x) * 4, true);
|
|
251
|
+
|
|
252
|
+
// count the number of equal, darker and brighter adjacent pixels
|
|
253
|
+
if (delta === 0) {
|
|
254
|
+
zeroes++;
|
|
255
|
+
// if found more than 2 equal siblings, it's definitely not anti-aliasing
|
|
256
|
+
if (zeroes > 2) return false;
|
|
257
|
+
|
|
258
|
+
// remember the darkest pixel
|
|
259
|
+
} else if (delta < min) {
|
|
260
|
+
min = delta;
|
|
261
|
+
minX = x;
|
|
262
|
+
minY = y;
|
|
263
|
+
|
|
264
|
+
// remember the brightest pixel
|
|
265
|
+
} else if (delta > max) {
|
|
266
|
+
max = delta;
|
|
267
|
+
maxX = x;
|
|
268
|
+
maxY = y;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// if there are no both darker and brighter pixels among siblings, it's not anti-aliasing
|
|
274
|
+
if (min === 0 || max === 0) return false;
|
|
275
|
+
|
|
276
|
+
// if either the darkest or the brightest pixel has 3+ equal siblings in both images
|
|
277
|
+
// (definitely not anti-aliased), this pixel is anti-aliased
|
|
278
|
+
return (hasManySiblings(img, minX, minY, width, height)
|
|
279
|
+
&& hasManySiblings(img2, minX, minY, width, height))
|
|
280
|
+
|| (hasManySiblings(img, maxX, maxY, width, height)
|
|
281
|
+
&& hasManySiblings(img2, maxX, maxY, width, height));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* @param {Uint8Array|Uint8ClampedArray} img1
|
|
286
|
+
* @param {Uint8Array|Uint8ClampedArray} img2
|
|
287
|
+
* @param {Uint8Array|Uint8ClampedArray} output
|
|
288
|
+
* @param {number} width
|
|
289
|
+
* @param {number} height
|
|
290
|
+
* @param {typeof DEFAULT_OPTIONS} [options]
|
|
291
|
+
* @return {number}
|
|
292
|
+
*/
|
|
293
|
+
export function pixelmatch(img1, img2, output, width, height, options) {
|
|
294
|
+
if (!isPixelData(img1) || !isPixelData(img2) || (output && !isPixelData(output))) {
|
|
295
|
+
throw new Error('Image data: Uint8Array, Uint8ClampedArray or Buffer expected.');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (img1.length !== img2.length || (output && output.length !== img1.length)) {
|
|
299
|
+
// throw new Error('Image sizes do not match.');
|
|
300
|
+
return Number.POSITIVE_INFINITY;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (img1.length !== width * height * 4) {
|
|
304
|
+
// throw new Error('Image data size does not match width/height.');
|
|
305
|
+
return Number.POSITIVE_INFINITY;
|
|
306
|
+
}
|
|
307
|
+
options = { ...DEFAULT_OPTIONS, ...options };
|
|
308
|
+
|
|
309
|
+
// check if images are identical
|
|
310
|
+
const len = width * height;
|
|
311
|
+
const a32 = new Uint32Array(img1.buffer, img1.byteOffset, len);
|
|
312
|
+
const b32 = new Uint32Array(img2.buffer, img2.byteOffset, len);
|
|
313
|
+
let identical = true;
|
|
314
|
+
|
|
315
|
+
for (let i = 0; i < len; i++) {
|
|
316
|
+
if (a32[i] !== b32[i]) { identical = false; break; }
|
|
317
|
+
}
|
|
318
|
+
if (identical) { // fast path if identical
|
|
319
|
+
if (output && !options.diffMask) {
|
|
320
|
+
for (let i = 0; i < len; i++) drawGrayPixel(img1, 4 * i, options.alpha, output);
|
|
321
|
+
}
|
|
322
|
+
return 0;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// maximum acceptable square distance between two colors;
|
|
326
|
+
// 35215 is the maximum possible value for the YIQ difference metric
|
|
327
|
+
const maxDelta = 35_215 * options.threshold * options.threshold;
|
|
328
|
+
let diff = 0;
|
|
329
|
+
|
|
330
|
+
// compare each pixel of one image against the other one
|
|
331
|
+
for (let y = 0; y < height; y++) {
|
|
332
|
+
for (let x = 0; x < width; x++) {
|
|
333
|
+
const pos = (y * width + x) * 4;
|
|
334
|
+
|
|
335
|
+
// squared YUV distance between colors at this pixel position, negative if the img2 pixel is darker
|
|
336
|
+
const delta = colorDelta(img1, img2, pos, pos);
|
|
337
|
+
|
|
338
|
+
// the color difference is above the threshold
|
|
339
|
+
if (Math.abs(delta) > maxDelta) {
|
|
340
|
+
// check it's a real rendering difference or just anti-aliasing
|
|
341
|
+
if (!options.includeAA && (antialiased(img1, x, y, width, height, img2)
|
|
342
|
+
|| antialiased(img2, x, y, width, height, img1))) {
|
|
343
|
+
// one of the pixels is anti-aliasing; draw as yellow and do not count as difference
|
|
344
|
+
// note that we do not include such pixels in a mask
|
|
345
|
+
if (output && !options.diffMask) drawPixel(output, pos, ...options.aaColor);
|
|
346
|
+
} else {
|
|
347
|
+
// found substantial difference not caused by anti-aliasing; draw it as such
|
|
348
|
+
if (output) {
|
|
349
|
+
drawPixel(output, pos, ...(delta < 0 && (options.diffColorAlt || options.diffColor)));
|
|
350
|
+
}
|
|
351
|
+
diff++;
|
|
352
|
+
}
|
|
353
|
+
} else if (output // pixels are similar; draw background as grayscale image blended with white
|
|
354
|
+
&& !options.diffMask) drawGrayPixel(img1, pos, options.alpha, output);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// return the number of different pixels
|
|
359
|
+
return diff;
|
|
360
|
+
}
|