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W,EAAE,QAAQ,CAAC,YAAY,CAAC,WAAW;aAC/C;SACF,CAAC;IACJ,CAAC;IAhHD,IAAI,iBAAiB;QACnB,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC;IACxC,CAAC;IAED,IAAI,iBAAiB,CAAC,KAAa;QACjC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;;AA7BM,0BAAgB,GAAG,EAAE,CAAC;AAyI/B,eAAe,SAAS,CAAC\"}","code":"/** @license\r\n *  Copyright 2016 - present The Material Motion Authors. All Rights Reserved.\r\n *\r\n *  Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\r\n *  use this file except in compliance with the License. You may obtain a copy\r\n *  of the License at\r\n *\r\n *      http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n *  Unless required by applicable law or agreed to in writing, software\r\n *  distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\r\n *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r\n *  License for the specific language governing permissions and limitations\r\n *  under the License.\r\n */\r\nimport { when, } from '../aggregators';\r\nimport { combineLatest, } from '../combineLatest';\r\nimport { subscribe, } from '../subscribe';\r\nimport { Axis, Direction, State, ThresholdRegion, } from '../enums';\r\nimport { createProperty, } from '../observables';\r\nimport { NumericSpring, } from './NumericSpring';\r\nexport var SwipeState;\r\n(function (SwipeState) {\r\n    SwipeState[\"NONE\"] = \"none\";\r\n    SwipeState[\"LEFT\"] = \"left\";\r\n    SwipeState[\"RIGHT\"] = \"right\";\r\n})(SwipeState || (SwipeState = {}));\r\n;\r\nexport class Swipeable {\r\n    constructor({ tossable, width$ }) {\r\n        this.iconSpring = new NumericSpring();\r\n        this.backgroundSpring = new NumericSpring();\r\n        // Should `State` be called `MotionState` so `state$` can be reserved for interactions?\r\n        this.swipeState$ = createProperty({ initialValue: SwipeState.NONE });\r\n        /**\r\n         * If an item is swiped past the threshold, it will animate by its own width\r\n         * + destinationMargin, in the direction of the swipe.\r\n         *\r\n         * This ensures that decoration that might overflow an item's bounds (like a\r\n         * shadow) isn't visible when it's been swiped away.\r\n         */\r\n        this.destinationMargin$ = createProperty({\r\n            initialValue: 0,\r\n        });\r\n        this.tossable = tossable;\r\n        this.width$ = width$;\r\n        this.state$ = this.tossable.state$;\r\n        tossable.draggable.axis = Axis.X;\r\n        const ICON_SPRING_INITIAL_VALUE = 0.67;\r\n        const draggable = tossable.draggable;\r\n        const spring = tossable.spring;\r\n        const draggedX$ = tossable.draggedLocation$.pluck({ path: 'x' });\r\n        this.iconSpring.initialValue = ICON_SPRING_INITIAL_VALUE;\r\n        this.direction$ = draggedX$.threshold(0).isAnyOf([ThresholdRegion.ABOVE]).rewrite({\r\n            mapping: {\r\n                true: Direction.RIGHT,\r\n                false: Direction.LEFT,\r\n            }\r\n        });\r\n        this.isThresholdMet$ = draggedX$.distanceFrom(0).threshold(Swipeable.VISUAL_THRESHOLD).isAnyOf([\r\n            ThresholdRegion.ABOVE,\r\n            ThresholdRegion.WITHIN,\r\n        ]);\r\n        this.whenThresholdCrossed$ = when(this.isThresholdMet$.dedupe());\r\n        subscribe({\r\n            sink: this.backgroundSpring.destination$,\r\n            source: this.isThresholdMet$.rewrite({\r\n                mapping: {\r\n                    true: 1,\r\n                    false: 0,\r\n                }\r\n            }),\r\n        });\r\n        subscribe({\r\n            sink: this.iconSpring.destination$,\r\n            source: this.isThresholdMet$.rewrite({\r\n                mapping: {\r\n                    true: 1,\r\n                    false: ICON_SPRING_INITIAL_VALUE,\r\n                }\r\n            }),\r\n        });\r\n        // This needs to also take velocity into consideration; right now, it only\r\n        // cares about final position.\r\n        subscribe({\r\n            sink: this.swipeState$,\r\n            source: when(draggable.state$.isAnyOf([State.AT_REST])).rewriteTo({\r\n                value$: this.isThresholdMet$.rewrite({\r\n                    mapping: {\r\n                        true: this.direction$,\r\n                        false: SwipeState.NONE,\r\n                    },\r\n                }),\r\n                onlyEmitWithUpstream: true,\r\n            }),\r\n        });\r\n        const destinationDistance$ = width$.addedBy(this.destinationMargin$);\r\n        subscribe({\r\n            sink: spring.destination$,\r\n            source: combineLatest({\r\n                x: this.swipeState$.rewrite({\r\n                    mapping: {\r\n                        [SwipeState.NONE]: 0,\r\n                        [SwipeState.LEFT]: destinationDistance$.multipliedBy(-1),\r\n                        [SwipeState.RIGHT]: destinationDistance$,\r\n                    }\r\n                }),\r\n                y: 0,\r\n            })\r\n        });\r\n        this.styleStreamsByTargetName = {\r\n            item: tossable.styleStreams,\r\n            icon: {\r\n                scale$: this.iconSpring.value$,\r\n                willChange$: tossable.styleStreams.willChange$,\r\n            },\r\n            background: {\r\n                scale$: this.backgroundSpring.value$,\r\n                willChange$: tossable.styleStreams.willChange$,\r\n            },\r\n        };\r\n    }\r\n    get destinationMargin() {\r\n        return this.destinationMargin$.read();\r\n    }\r\n    set destinationMargin(value) {\r\n        this.destinationMargin$.write(value);\r\n    }\r\n}\r\nSwipeable.VISUAL_THRESHOLD = 72;\r\nexport default Swipeable;\r\n//# sourceMappingURL=Swipeable.js.map"}
