/** @license * Copyright 2016 - present The Material Motion Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ import $$observable from 'symbol-observable'; // We re-export everything we import, so dependents don't need to know about // indefinite-observable. import { Disconnect, NextChannel, Observable, Observer, Subscription, } from 'indefinite-observable'; export { Connect, Disconnect, NextChannel, Observable, Observer, ObserverOrNext, Subscription, } from 'indefinite-observable'; export { MotionAddable, MotionAppendUnitable, MotionClampable, MotionDebounceable, MotionDeduplicable, MotionDivisible, MotionFilterable, MotionFlattenable, MotionInvertible, MotionIsAnyOfable, MotionLoggable, MotionMappable, MotionMathOperable, MotionMeasurable, MotionMemorable, MotionMergeable, MotionMulticastable, MotionMultipliable, MotionNextOperable, MotionPluckable, MotionPolarizable, MotionReactiveMappable, MotionReactiveNextOperable, MotionReadable, MotionRenameable, MotionRewritable, MotionRewriteRangeable, MotionRewriteToable, MotionSeedable, MotionSubtractable, MotionTappable, MotionThresholdRangeable, MotionThresholdable, MotionTimestampable, MotionWindowable, ObservableWithFoundationalMotionOperators, ObservableWithMotionOperators, } from './operators' import { ObservableWithMotionOperators, } from './operators'; import { State, } from './enums'; export type Constructor = new(...args: Array) => T; export type Predicate = (value: T) => boolean; export interface Subject extends Observable { next(value: T): void; } export type Operation = (values: { upstream: T } & D) => void; export type EmittingOperation = (kwargs: { emit: NextChannel }) => Operation; export type MathOperation = (a: number, b: number) => number; export type Dimensions = { width: number, height: number, }; export type Point2D = { x: number, y: number, }; export type PolarCoords = { angle: number, distance: number, }; export interface Spring { readonly destination$: ObservableWithMotionOperators; destination: T; readonly initialValue$: ObservableWithMotionOperators; initialValue: T; readonly initialVelocity$: ObservableWithMotionOperators; initialVelocity: T; readonly stiffness$: ObservableWithMotionOperators; stiffness: number; readonly damping$: ObservableWithMotionOperators; damping: number; readonly threshold$: ObservableWithMotionOperators; threshold: number; readonly enabled$: ObservableWithMotionOperators; enabled: boolean; readonly state$: ObservableWithMotionOperators; readonly state: State; value$: ObservableWithMotionOperators; } /** * There are 2 competing input events on the Web: `PointerEvent`s and * `TouchEvent`s. Our gesture system only needs 4 properties: x, y, type and an * ID. In both models, x and y are provided (both relative to the page and the * viewport). `TouchEvent` calls its ID `identifier`; whereas, `PointerEvent` * uses `pointerId`. * * `PartialPointerEvent` is the subset we care about. `PointerEvent` already * has this shape. `TouchEvent` can be trivially converted by extracting the * touches and renaming `identifier` to `pointerId`. */ export type PartialPointerEvent = Point2D & { pointerId?: number, // Can be undefined for MouseEvent // Uses string rather than ('pointerdown' | 'pointermove' | 'pointerup') // because the PointerEvent.type is a string and it makes life easier if we // match that. type: string, }; export type PointerEventStreams = { down$: ObservableWithMotionOperators, move$: ObservableWithMotionOperators, up$: ObservableWithMotionOperators, cancel$: ObservableWithMotionOperators, contextMenu$: ObservableWithMotionOperators, capturedClick$: ObservableWithMotionOperators, capturedDragStart$: ObservableWithMotionOperators, }; export type Read = () => T; export interface ScopedReadable { read: Read; } export type Write = (value: T) => void; export interface ScopedWritable { write: Write; } export type TouchActionStyleStreams = { readonly touchAction$: ObservableWithMotionOperators, }; export type WillChangeStyleStreams = { readonly willChange$: ObservableWithMotionOperators, }; export type DimensionsStyleStreams = WillChangeStyleStreams & { readonly dimensions$: ObservableWithMotionOperators>, }; export type TranslateStyleStreams = WillChangeStyleStreams & { readonly translate$: ObservableWithMotionOperators>, }; export type RotateStyleStreams = WillChangeStyleStreams & { readonly rotate$: ObservableWithMotionOperators, }; export type ScaleStyleStreams = WillChangeStyleStreams & { readonly scale$: ObservableWithMotionOperators, }; export type OpacityStyleStreams = WillChangeStyleStreams & { readonly opacity$: ObservableWithMotionOperators, }; export type BoxShadowStyleStreams = { readonly boxShadow$: ObservableWithMotionOperators, }; export type BorderRadiusStyleStreams = { readonly borderRadius$: ObservableWithMotionOperators | Array>, }; export type StyleStreams = TouchActionStyleStreams & WillChangeStyleStreams & DimensionsStyleStreams & TranslateStyleStreams & ScaleStyleStreams & OpacityStyleStreams & BoxShadowStyleStreams & BorderRadiusStyleStreams; export type EqualityCheck = (a: any, b: any) => boolean; export interface Timestamped { value: T, timestamp: number, }; export type MaybeReactive = { [K in keyof D]: D[K] | Observable }; /** * `Array` has both members and methods. `MaybeReactive` iterates over all the * keys in an object. `MaybeReactive>` allows you to * represent an array with potentially reactive members without worrying about * the methods. */ export type NumericallyKeyed = { [index: number]: T, }; export type Dict = { [index: string]: T, }; export type NumericDict = Dict; export type StreamDict = Dict>; export type SubjectDict = Dict>; export type SubscriptionDict = Dict;