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,UAA6B,CAAC,SAAS,CAAC,CAAC,CAAC;oCACtG,IAAI,CAAC,KAAK,CAAC,CAAC;gCACd,CAAC;4BACH,CAAC;wBACH,CAAC;oBACH,CAAC;gBACH,CAAC;gBACD,MAAM,EAAE,MAAM;gBACd,gBAAgB,EAAE,KAAK;aACxB,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,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 * as tslib_1 from \"tslib\";\r\nimport { isMap, isObservable, isTimestamped, } from '../typeGuards';\r\nimport { timestamp, } from './timestamp';\r\nexport const SUPPRESS_FAILURES = Symbol();\r\nexport function withRewrite(superclass) {\r\n    return class extends superclass {\r\n        rewrite({ mapping, defaultValue = SUPPRESS_FAILURES, emitOnKeyChange = true }) {\r\n            let keys;\r\n            let values;\r\n            let castKeysToStrings = false;\r\n            if (isMap(mapping)) {\r\n                keys = Array.from(mapping.keys());\r\n                values = Array.from(mapping.values());\r\n            }\r\n            else {\r\n                keys = Object.keys(mapping);\r\n                values = Object.values(mapping);\r\n                castKeysToStrings = true;\r\n            }\r\n            let upstream = this;\r\n            if (!emitOnKeyChange) {\r\n                values = values.map(value => isObservable(value)\r\n                    ? value.timestamp()\r\n                    : timestamp(value));\r\n                upstream = this.timestamp();\r\n            }\r\n            return upstream._reactiveNextOperator({\r\n                operation: ({ emit }) => (_a) => {\r\n                    var { upstream: currentKey } = _a, currentValues = tslib_1.__rest(_a, [\"upstream\"]);\r\n                    if (currentKey !== undefined) {\r\n                        let key = isTimestamped(currentKey)\r\n                            ? currentKey.value\r\n                            : currentKey;\r\n                        if (castKeysToStrings) {\r\n                            key = key.toString();\r\n                        }\r\n                        // TypeScript can't do Array<string | T>.indexOf(string | T), so we\r\n                        // force it to pick one.  Doesn't matter, since the result is a\r\n                        // number either way.\r\n                        const index = keys.indexOf(key);\r\n                        if (index === -1) {\r\n                            if (defaultValue !== SUPPRESS_FAILURES) {\r\n                                emit(defaultValue);\r\n                            }\r\n                        }\r\n                        else {\r\n                            const currentValue = currentValues[index];\r\n                            // Wait until both the currentKey and currentValue have been\r\n                            // defined before emitting.  This also presumes that the author\r\n                            // is not intentionally rewriting to undefined.\r\n                            if (currentValue !== undefined) {\r\n                                const value = isTimestamped(currentValue)\r\n                                    ? currentValue.value\r\n                                    : currentValue;\r\n                                // Prevent stale values from being emitted by only forwarding\r\n                                // values that are newer than the key, unless\r\n                                // emitOnKeyChange is set (which will omit the timestamps).\r\n                                if (!isTimestamped(currentValue) || currentValue.timestamp > currentKey.timestamp) {\r\n                                    emit(value);\r\n                                }\r\n                            }\r\n                        }\r\n                    }\r\n                },\r\n                inputs: values,\r\n                waitForAllValues: false\r\n            });\r\n        }\r\n    };\r\n}\r\n//# sourceMappingURL=rewrite.js.map","dts":{"name":"/Users/brentons/Projects/material-motion-js/packages/core/operators/rewrite.d.ts","text":"import { Constructor, Dict, MotionReactiveNextOperable, MotionTimestampable, ObservableWithMotionOperators } from '../types';\r\nexport declare type RewritableOptions<U> = Partial<{\r\n    defaultValue: U | symbol;\r\n    emitOnKeyChange: boolean;\r\n}>;\r\nexport declare type RewriteArgs<T, R, U> = RewritableOptions<U> & {\r\n    mapping: Dict<R> | Map<T, R>;\r\n};\r\nexport interface MotionRewritable<T> {\r\n    rewrite<U, R extends U | ObservableWithMotionOperators<U>>(kwargs: RewriteArgs<T, R, U>): ObservableWithMotionOperators<U>;\r\n}\r\nexport declare const SUPPRESS_FAILURES: symbol;\r\nexport declare function withRewrite<T, S extends Constructor<MotionReactiveNextOperable<T> & MotionTimestampable<T>>>(superclass: S): S & Constructor<MotionRewritable<T>>;\r\n"}}
