diff --git a/packages/animate/@types/animate.d.ts b/packages/animate/@types/animate.d.ts index 486cfdd..bbea0bf 100644 --- a/packages/animate/@types/animate.d.ts +++ b/packages/animate/@types/animate.d.ts @@ -393,7 +393,7 @@ export declare class Animate { /** * Returns an array of computed options */ - protected createArrayOfComputedOptions(optionsFromParam: IAnimationOptions, len: number): object | Keyframe[] | import("./types").TypeGeneric[]; + protected createArrayOfComputedOptions(optionsFromParam: IAnimationOptions, len: number): object | import("./types").TypeGeneric[] | Keyframe[]; /** * Creates animations out of an array of computed options */ diff --git a/packages/animate/@types/api.d.ts b/packages/animate/@types/api.d.ts index 755c614..c8bb30e 100644 --- a/packages/animate/@types/api.d.ts +++ b/packages/animate/@types/api.d.ts @@ -2,6 +2,7 @@ export * from "./types"; export * from "./utils"; export * from "./builtin-effects"; export * from "./css-properties"; +export * from "./unit-conversion"; export * from "./css-vars"; export * from "./custom-easing"; export * from "./animate"; diff --git a/packages/animate/@types/bezier-easing.d.ts b/packages/animate/@types/bezier-easing.d.ts deleted file mode 100644 index 1608d17..0000000 --- a/packages/animate/@types/bezier-easing.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * https://github.com/gre/bezier-easing - * BezierEasing - use bezier curve for transition easing function - * by Gaëtan Renaudeau 2014 - 2015 – MIT License - */ -export declare const NEWTON_ITERATIONS = 4; -export declare const NEWTON_MIN_SLOPE = 0.001; -export declare const SUBDIVISION_PRECISION = 1e-7; -export declare const SUBDIVISION_MAX_ITERATIONS = 10; -export declare const kSplineTableSize = 11; -export declare const kSampleStepSize: number; -export declare const float32ArraySupported: boolean; -export declare const A: (aA1: number, aA2: number) => number; -export declare const B: (aA1: number, aA2: number) => number; -export declare const C: (aA1: number) => number; -export declare const calcBezier: (aT: number, aA1: number, aA2: number) => number; -export declare const getSlope: (aT: number, aA1: number, aA2: number) => number; -export declare const binarySubdivide: (aX: number, aA: number, aB: number, mX1: number, mX2: number) => number; -export declare const newtonRaphsonIterate: (aX: number, aGuessT: number, mX1: number, mX2: number) => number; -export declare const bezier: (mX1: number, mY1: number, mX2: number, mY2: number) => (t: number) => number; -export default bezier; diff --git a/packages/animate/@types/builtin-effects.d.ts b/packages/animate/@types/builtin-effects.d.ts deleted file mode 100644 index 2d864a3..0000000 --- a/packages/animate/@types/builtin-effects.d.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Convert the words "from", and "to" as well as percentage or numbers to offset value between 0 and 1 - */ -export declare const parseOffset: (input: string | number) => number; -/** - * Allows you to quickly convert CSS like JSON into keyframes - * - * @param input - CSS style JSON; check the example to understand what I mean - * - * @example - * ```typescript - * let keyframes = KeyframeParse({ - * "from, 50%, to": { - * opacity: 1 - * }, - * - * "25%, 0.7": { - * opacity: 0 - * } - * }); - * - * console.log(keyframes); - * //= [ - * //= { opacity: 1, offset: 0 }, - * //= { opacity: 0, offset: 0.25 }, - * //= { opacity: 1, offset: 0.5 }, - * //= { opacity: 0, offset: 0.7 }, - * //= { opacity: 1, offset: 1 } - * //= ] - * ``` - */ -export declare const KeyframeParse: (input: object) => Keyframe[]; -/** - * I don't really want to put in the effort to create a complete list, so instead just look through the `animate.css` github and copy and paste the effects you need, into using a CSS Keyframe style JSON object, make sure to read the documentation for {@link KeyframeParse} - * - * I suggest [@shoelace-style/animations](https://www.npmjs.com/package/@shoelace-style/animations) for all your animate.css needs. - * - * or - * - * if you just need some quick effects go to [github.com/wellyshen/use-web-animations/](https://github.com/wellyshen/use-web-animations/tree/master/src/animations) and copy the `keyframes` array for the effect you want, remember to say thank you to @wellyshen for all his hardwork, 😂. - * - * @internal -*/ -export declare const EFFECTS: {}; diff --git a/packages/animate/@types/types.d.ts b/packages/animate/@types/types.d.ts deleted file mode 100644 index 13b9f44..0000000 --- a/packages/animate/@types/types.d.ts +++ /dev/null @@ -1,571 +0,0 @@ -import type { KebabCase, CamelCase, KebabCasedProperties } from "type-fest"; -export declare type TypeAnimationTarget = string | Node | NodeList | HTMLCollection | HTMLElement[] | TypeAnimationTarget[]; -export declare type TypeCallbackArgs = [number, number, HTMLElement]; -export declare type TypeGeneric = boolean | object | string | number; -export declare type TypeCSSLikeKeyframe = { - [key: string]: Keyframe & ICSSComputedTransformableProperties; -}; -export declare type TypeKeyFrameOptionsType = TypeCSSLikeKeyframe | Keyframe[] | PropertyIndexedKeyframes; -export declare type TypeCSSPropertyValue = (string | number)[]; -export declare type TypeComputedAnimationOptions = TypeGeneric | TypeGeneric[] | TypeKeyFrameOptionsType | KeyframeEffectOptions | ICSSComputedTransformableProperties; -export declare type TypeCallback = (index?: number, total?: number, element?: HTMLElement) => TypeComputedAnimationOptions; -export declare type TypeAnimationOptionTypes = TypeCallback | TypeComputedAnimationOptions; -export declare type TypeComputedOptions = { - [key: string]: TypeComputedAnimationOptions; -}; -export declare type TypeSingleValueCSSProperty = string | number | TypeCSSPropertyValue; -/** - * [Animatable CSS Properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties) - * - */ -export declare type TypeAnimatableCSSProperties = CamelCase<"-webkit-line-clamp" | "-webkit-text-fill-color" | "-webkit-text-stroke" | "-webkit-text-stroke-color" | "all" | "background" | "background-color" | "background-position" | "background-size" | "block-size" | "border" | "border-block-end" | "border-block-end-color" | "border-block-end-width" | "border-block-start" | "border-block-start-color" | "border-block-start-width" | "border-bottom" | "border-bottom-color" | "border-bottom-left-radius" | "border-bottom-right-radius" | "border-bottom-width" | "border-color" | "border-end-end-radius" | "border-end-start-radius" | "border-image-outset" | "border-image-slice" | "border-image-width" | "border-inline-end" | "border-inline-end-color" | "border-inline-end-width" | "border-inline-start" | "border-inline-start-color" | "border-inline-start-width" | "border-left" | "border-left-color" | "border-left-width" | "border-radius" | "border-right" | "border-right-color" | "border-right-width" | "border-start-end-radius" | "border-start-start-radius" | "border-top" | "border-top-color" | "border-top-left-radius" | "border-top-right-radius" | "border-top-width" | "border-width" | "bottom" | "box-shadow" | "caret-color" | "clip" | "clip-path" | "color" | "column-count" | "column-gap" | "column-rule" | "column-rule-color" | "column-rule-width" | "column-width" | "columns" | "filter" | "flex" | "flex-basis" | "flex-grow" | "flex-shrink" | "font" | "font-size" | "font-size-adjust" | "font-stretch" | "font-variation-settings" | "font-weight" | "gap" | "grid-column-gap" | "grid-gap" | "grid-row-gap" | "grid-template-columns" | "grid-template-rows" | "height" | "inline-size" | "inset" | "inset-block" | "inset-block-end" | "inset-block-start" | "inset-inline" | "inset-inline-end" | "inset-inline-start" | "left" | "letter-spacing" | "line-height" | "margin" | "margin-block-end" | "margin-block-start" | "margin-bottom" | "margin-inline-end" | "margin-inline-start" | "margin-left" | "margin-right" | "margin-top" | "mask" | "max-block-size" | "max-height" | "max-inline-size" | "max-width" | "min-block-size" | "min-height" | "min-inline-size" | "min-width" | "object-position" | "offset" | "offset-anchor" | "offset-distance" | "offset-path" | "offset-rotate" | "opacity" | "order" | "outline" | "outline-color" | "outline-offset" | "outline-width" | "padding" | "padding-block-end" | "padding-block-start" | "padding-bottom" | "padding-inline-end" | "padding-inline-start" | "padding-left" | "padding-right" | "padding-top" | "perspective" | "perspective-origin" | "right" | "rotate" | "row-gap" | "scale" | "scroll-margin" | "scroll-margin-block" | "scroll-margin-block-end" | "scroll-margin-block-start" | "scroll-margin-bottom" | "scroll-margin-inline" | "scroll-margin-inline-end" | "scroll-margin-inline-start" | "scroll-margin-left" | "scroll-margin-right" | "scroll-margin-top" | "scroll-padding" | "scroll-padding-block" | "scroll-padding-block-end" | "scroll-padding-block-start" | "scroll-padding-bottom" | "scroll-padding-inline" | "scroll-padding-inline-end" | "scroll-padding-inline-start" | "scroll-padding-left" | "scroll-padding-right" | "scroll-padding-top" | "shape-image-threshold" | "shape-margin" | "shape-outside" | "tab-size" | "text-decoration" | "text-decoration-color" | "text-decoration-thickness" | "text-emphasis" | "text-emphasis-color" | "text-indent" | "text-shadow" | "text-underline-offset" | "top" | "transform" | "transform-origin" | "translate" | "vertical-align" | "visibility" | "width" | "word-spacing" | "z-index" | "opacity">; -/** - * [SVG Presentation Attributes](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/Presentation) - */ -export declare type TypeSVGPresentationAttributes = CamelCase<"alignment-baseline" | "baseline-shift" | "clip-rule" | "color-interpolation" | "color-interpolation-filters" | "color-profile" | "color-rendering" | "cursor" | "direction" | "display" | "fill" | "fill-opacity" | "fill-rule" | "flood-color" | "flood-opacity" | "font-family" | "font-style" | "font-variant" | "kerning" | "lighting-color" | "marker-end" | "marker-mid" | "marker-start" | "overflow" | "pointer-events" | "stroke" | "stroke-dasharray" | "stroke-dashoffset" | "stroke-linecap" | "stroke-linejoin" | "stroke-miterlimit" | "stroke-opacity" | "stroke-width" | "text-anchor" | "text-rendering" | "vector-effect" | "writing-mode">; -/** - * [SVG Presentation Attributes](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/Presentation) - */ -export declare type TypeAnimatableSVGAttributes = { - [property in TypeSVGPresentationAttributes]?: TypeAnimationOptionTypes; -}; -/** - * CSS properties the `ParseTransformableCSSProperties` can parse - */ -export declare type TypeCSSTransformableProperties = { - [K in keyof ICSSComputedTransformableProperties]?: ICSSComputedTransformableProperties[K] | TypeCallback; -}; -/** - * CSS Properties that are missing from the type definition - */ -export declare type TypeMissingCSSProperties = { - /** - * Morphing SVG paths via the `d` property isn't well supported yet, as Gecko (Firefox) & Webkit (Safari) based browsers don't support it yet, and there are other limitations to what the Web Animation API will allow 😭, these limitation are covered in detail by an article published by Adobe about [the current state of SVG animation on the web](https://blog.adobe.com/en/publish/2015/06/05/the-state-of-svg-animation.html#gs.pihpjw). However, animation using paths is now viable through [Motion Path](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Motion_Path). - * - * You use it like this: - * ```ts - * // ... - * animate({ - * // ... - * // The paths have to have the same number of points, that is why the 2 paths below seem similar - * d: [ - * `path("M2,5 S2,14 4,5 S7,8 8,4")`, - * `path("M2,5 S2,-2 4,5 S7,8 8,4")` - * ] - * }) - * ``` - */ - d?: string | string[] | TypeCallback; - backdropFilter?: string | string[] | TypeCallback; - lineClamp?: number | string | (string | number)[] | TypeCallback; - maskBorder?: string | string[] | TypeCallback; - maskPosition?: number | string | (string | number)[] | TypeCallback; - maskSize?: number | string | (string | number)[] | TypeCallback; - maxLines?: number | string | (string | number)[] | TypeCallback; - offsetPosition?: number | string | (string | number)[] | TypeCallback; - scrollbarColor?: string | string[] | TypeCallback; -} & { - [K in TypeAnimatableCSSProperties]?: TypeAnimationOptionTypes; -}; -/** - * Full list of CSS & SVG Animatable Properties & Animation Options that are supported -*/ -export declare type TypeCSSAnimationOptions = { - [K in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[K] | CSSStyleDeclaration[K][] | TypeAnimationOptionTypes; -} & { - [K in keyof CSSStyleDeclaration as KebabCase]?: CSSStyleDeclaration[K] | CSSStyleDeclaration[K][] | TypeAnimationOptionTypes; -} & TypeCSSTransformableProperties & KebabCasedProperties & TypeMissingCSSProperties & KebabCasedProperties & TypeAnimatableSVGAttributes & KebabCasedProperties; -/** - * Animation options control how an animation is produced, it shouldn't be too different for those who have used `animejs`, or `jquery`'s animate method. - * - * @remark - * An animation option is an object with keys and values that are computed and passed to the `Animate` class to create animations that match the specified options. - */ -export interface IAnimationOptions extends TypeCSSAnimationOptions { - /** - * Determines the DOM elements to animate. You can pass it a CSS selector, DOM elements, or an Array of DOM Elements and/or CSS Selectors. - */ - target?: TypeAnimationTarget; - /** - * Alias of `target` - * {@link AnimationOptions.target | target } - */ - targets?: TypeAnimationTarget; - /** - * Determines the acceleration curve of your animation. Based on the easings of [easings.net](https://easings.net) - * - * Read More about easings on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/easing) - * - * - * | constant | accelerate | decelerate | accelerate-decelerate | - * | :--------- | :----------- | :------------- | :-------------------- | - * | linear | ease-in / in | ease-out / out | ease-in-out / in-out | - * | ease | in-sine | out-sine | in-out-sine | - * | steps | in-quad | out-quad | in-out-quad | - * | step-start | in-cubic | out-cubic | in-out-cubic | - * | step-end | in-quart | out-quart | in-out-quart | - * | | in-quint | out-quint | in-out-quint | - * | | in-expo | out-expo | in-out-expo | - * | | in-circ | out-circ | in-out-circ | - * | | in-back | out-back | in-out-back | - * - * You can create your own custom cubic-bezier easing curves. Similar to css you type `cubic-bezier(...)` with 4 numbers representing the shape of the bezier curve, for example, `cubic-bezier(0.47, 0, 0.745, 0.715)` this is the bezier curve for `in-sine`. - * - * *Note: the `easing` property supports the original values and functions for easing as well, for example, `steps(1)`, and etc... are supported.* - * - * *Note: you can also use camelCase when defining easing functions, e.g. `inOutCubic` to represent `in-out-cubic`* - * - * @example - * ```ts - * // cubic-bezier easing - * animate({ - * target: ".div", - * easing: "cubic-bezier(0.47, 0, 0.745, 0.715)", - * - * // or - * easing: "in-sine", - * - * // or - * easing: "inSine", - * - * transform: ["translate(0px)", "translate(500px)"], - * }); - * ``` - */ - easing?: KeyframeEffectOptions["easing"] | TypeCallback | string | string[]; - /** - * Determines the duration of your animation in milliseconds. By passing it a callback, you can define a different duration for each element. The callback takes the index of each element, the target dom element, and the total number of target elements as its argument and returns a number. - * - * @example - * ```ts - * // First element fades out in 1s, second element in 2s, etc. - * animate({ - * target: ".div", - * easing: "linear", - * duration: 1000, - * // or - * duration: (index) => (index + 1) * 1000, - * opacity: [1, 0], - * }); - * ``` - */ - duration?: KeyframeEffectOptions["duration"] | number | string | TypeCallback; - /** - * Determines the delay of your animation in milliseconds. By passing it a callback, you can define a different delay for each element. The callback takes the index of each element, the target dom element, and the total number of target elements as its argument and returns a number. - * - * @example - * ```ts - * // First element starts fading out after 1s, second element after 2s, etc. - * animate({ - * target: ".div", - * easing: "linear", - * delay: 5, - * // or - * delay: (index) => (index + 1) * 1000, - * opacity: [1, 0], - * }); - * ``` - */ - delay?: KeyframeEffectOptions["delay"] | string | number | TypeCallback; - /** - * Adds an offset ammount to the `delay`, for creating a timeline similar to `animejs` - */ - timelineOffset?: number | string; - /** - * Similar to delay but it indicates the number of milliseconds to delay **after** the full animation has played **not before**. - * - * _**Note**: `endDelay` will delay the `onfinish` method and event, but will not reserve the current state of the CSS animation, if you need to use endDelay you may need to use the `fillMode` property to reserve the changes to the animation target._ - - * @example - * ```ts - * // First element fades out but then after 1s finishes, the second element after 2s, etc. - * animate({ - * target: ".div", - * easing: "linear", - * endDelay: 1000, - * // or - * endDelay: (index) => (index + 1) * 1000, - * opacity: [1, 0], - * }); - * ``` - */ - endDelay?: KeyframeEffectOptions["endDelay"] | string | number | TypeCallback; - /** - * - * This ensures all `animations` match up to the total duration, and don't finish too early, if animations finish too early when the `.play()` method is called specific animations that are finished will restart while the rest of the animations will continue playing. - * - * _**Note**: you cannot use the `padEndDelay` option and set a value for `endDelay`, the `endDelay` value will replace the padded endDelay_ - */ - padEndDelay?: Boolean; - /** - * Determines if the animation should repeat, and how many times it should repeat. - * - * @example - * ```ts - * // Loop forever - * animate({ - * target: ".div", - * easing: "linear", - * loop: true, // If you want it to continously loop - * // or - * // loop: 5, // If you want the animation to loop 5 times - * opacity: [1, 0], - * }); - * ``` - */ - loop?: KeyframeEffectOptions["iterations"] | number | boolean | TypeCallback; - /** - * Occurs when the animation for one of the targets completes, meaning when animating many targets that finish at different times this will run multiple times. The arguments it takes is slightly different from the rest of the animation options. - * - * The animation argument represents the animation for the current target. - * - * @param element - the current target element - * @param index - the index of the current target element in `Animate.prototype.targets` - * @param total - the total number of target elements - * @param animation - the animation of the current target element - * - * **Warning**: the order of the callback's arguments are in a different order, with the target element first, and the index second. - */ - onfinish?: (element?: HTMLElement, index?: number, total?: number, animation?: Animation) => void; - /** - * Occurs when the animation for one of the targets is cancelled, meaning when animating many targets that are cancelled at different times this will run multiple times. The arguments it takes is slightly different from the rest of the animation options. - * - * The animation argument represents the animation for the current target. - * - * @param element - the current target element - * @param index - the index of the current target element in `Animate.prototype.targets` - * @param total - the total number of target elements - * @param animation - the animation of the current target element - * - * - * **Warning**: the order of the callback's arguments are in a different order, with the target element first, and the index second. - */ - oncancel?: (element?: HTMLElement, index?: number, total?: number, animation?: Animation) => void; - /** - * - * Determines if the animation should automatically play immediately after being instantiated. - */ - autoplay?: boolean; - /** - * Determines the direction of the animation; - * - `reverse` runs the animation backwards, - * - `alternate` switches direction after each iteration if the animation loops. - * - `alternate-reverse` starts the animation at what would be the end of the animation if the direction were - * - `normal` but then when the animation reaches the beginning of the animation it alternates going back to the position it started at. - */ - direction?: KeyframeEffectOptions["direction"] | PlaybackDirection; - /** - * Determines the animation playback rate. Useful in the authoring process to speed up some parts of a long sequence (value above 1) or slow down a specific animation to observe it (value between 0 to 1). - * - * _**Note**: negative numbers reverse the animation._ - */ - speed?: number | TypeCallback; - /** - * Defines how an element should look after the animation. - * - * @remark - * fillMode of: - * - `none` means the animation's effects are only visible while the animation is playing. - * - `forwards` the affected element will continue to be rendered in the state of the final animation frame. - * - `backwards` the animation's effects should be reflected by the element(s) state prior to playing. - * - `both` combining the effects of both forwards and backwards; The animation's effects should be reflected by the element(s) state prior to playing and retained after the animation has completed playing. - * - `auto` if the animation effect fill mode is being applied to is a keyframe effect. "auto" is equivalent to "none". Otherwise, the result is "both". - * - * You can learn more here on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/fill). - - * _Be careful when using fillMode, it has some problems when it comes to concurrency of animations read more on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/fill), if browser support were better I would remove fillMode and use Animation.commitStyles, I'll have to change the way `fillMode` functions later. Use the onfinish method to commit styles [onfinish](#onfinish)._ - */ - fillMode?: KeyframeEffectOptions["fill"] | FillMode; - /** - * Another way to input options for an animation, it's also used to chain animations. - * - * @remarks - * The `options` animation option is another way to declare options, it can take an instance of `Animate`, a single `Animate` instance in an Array, e.g. `[Animate]` or an object containing animation options. - * - * - * `options` extends the animation properties of an animation, but more importance is given to the actual animation options object, so, the properties from `options` will be ignored if there is already an animation option with the same name declared. - * - * - * _**Note**: you can't use this property as a method._ - * - * @example - * ```ts - * (async () => { - * // animate is Promise-like, as in it has a then() method like a Promise but it isn't a Promise. - * // animate resolves to an Array that contains the Animate instance, e.g. [Animate] - * let [options] = await animate({ - * target: ".div", - * opacity: [0, 1], - * }); - * - * animate({ - * options, - * - * // opacity overrides the opacity property from `options` - * opacity: [1, 0], - * }); - * - * console.log(options); //= Animate - * })(); - * - * // or - * (async () => { - * let options = await animate({ - * target: ".div", - * opacity: [0, 1], - * duration: 2000, - * - * }); - * - * // Remeber, the `options` animation option can handle Arrays with an Animate instance, e.g. [Animate] - * // Also, remeber that Animate resolves to an Arrays with an Animate instance, e.g. [Animate] - * // Note: the `options` animation option can only handle one Animate instance in an Array and that is alway the first element in the Array - * animate({ - * options, - * opacity: [1, 0], - * }); - * - * console.log(options); //= [Animate] - * })(); - * - * // or - * (async () => { - * let options = { - * target: ".div", - * opacity: [0, 1], - * }; - * - * await animate(options); - * animate({ - * options, - * opacity: [1, 0], - * }); - * - * console.log(options); //= { ... } - * })(); - * ``` - */ - options?: IAnimationOptions; - /** - * Contols the starting point of certain parts of an animation - * - * @remark - * The offset of the keyframe specified as a number between `0.0` and `1.0` inclusive or null. This is equivalent to specifying start and end states in percentages in CSS stylesheets using @keyframes. If this value is null or missing, the keyframe will be evenly spaced between adjacent keyframes. - * - * Read more on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats) - * - * @example - * ```ts - * animate({ - * duration: 2000, - * opacity: [ 0, 0.9, 1 ], - * easing: [ 'ease-in', 'ease-out' ], - * - * offset: [ "from", 0.8 ], // Shorthand for [ 0, 0.8, 1 ] - * // or - * offset: [ 0, "80%", "to" ], // Shorthand for [ 0, 0.8, 1 ] - * // or - * offset: [ "0", "0.8", "to" ], // Shorthand for [ 0, 0.8, 1 ] - * }); - * ``` - */ - offset?: PropertyIndexedKeyframes["offset"] | (number | string)[] | TypeCallback; - /** - * Represents the timeline of animation. It exists to pass timeline features to Animations (default is [DocumentTimeline](https://developer.mozilla.org/en-US/docs/Web/API/DocumentTimeline)). - * - * As of right now it doesn't contain any features but in the future when other timelines like the [ScrollTimeline](https://drafts.csswg.org/scroll-animations-1/#scrolltimeline), read the Google Developer article for [examples and demos of ScrollTimeLine](https://developers.google.com/web/updates/2018/10/animation-worklet#hooking_into_the_space-time_continuum_scrolltimeline) - */ - timeline?: AnimationTimeline | null; - /** - * Allows you to manually set keyframes using a `keyframe` array - * - * Read more on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/setKeyframes) - * - * @remark - * An `array` of objects (keyframes) consisting of properties and values to iterate over. This is the canonical format returned by the [getKeyframes()](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/getKeyframes) method. - * - * @example - * ```ts - * element.animate([ - * { // from - * opacity: 0, - * color: "#fff" - * }, - * { // to - * opacity: 1, - * color: "#000" - * } - * ], 2000); - * ``` - * - * Offsets for each keyframe can be specified by providing an `offset` value. - - * @example - * ```ts - * element.animate([ { opacity: 1 }, - * { opacity: 0.1, offset: 0.7 }, - * { opacity: 0 } ], - * 2000); - * ``` - * - * _**Note**: `offset` values, if provided, must be between 0.0 and 1.0 (inclusive) and arranged in ascending order._ - * - * It is not necessary to specify an offset for every keyframe. Keyframes without a specified offset will be evenly spaced between adjacent keyframes. - * - * --- - * - * The easing to apply between keyframes can be specified by providing an easing `value` as illustrated below. - * - * _**Note**: the values for easing in keyframes are limited to "ease", "ease-in", "ease-out", "ease-in-out", "linear", "steps(...)", and "cubic-bezier(...)", to get access to the predefined {@link EASINGS | easings}, you will need to use the function {@link GetEase}._ - - * @example - * ```ts - * element.animate([ { opacity: 1, easing: 'ease-out' }, - * { opacity: 0.1, easing: 'ease-in' }, - * { opacity: 0 } ], - * 2000); - * ``` - * - * In this example, the specified easing only applies from the keyframe where it is specified until the next keyframe. Any easing value specified on the options argument, however, applies across a single iteration of the animation — for the entire duration. - * - * - * `@okikio/animate` also offers another format called `CSSLikeKeyframe`, - * it basically functions the same way CSS `@keyframe` functions - * - * @example - * ```ts - * animate({ - * keyframes: { - * "from, 50%, to": { - * opacity: 1 - * }, - * - * "25%, 0.7": { - * opacity: 0 - * } - * } - * }) - * // Results in a keyframe array like this - * //= [ - * //= { opacity: 1, offset: 0 }, - * //= { opacity: 0, offset: 0.25 }, - * //= { opacity: 1, offset: 0.5 }, - * //= { opacity: 0, offset: 0.7 }, - * //= { opacity: 1, offset: 1 } - * //= ] - * ``` - */ - keyframes?: TypeCSSLikeKeyframe | ICSSComputedTransformableProperties[] & Keyframe[] | object[] | TypeCallback; - /** - * The `composite` property of a `KeyframeEffect` resolves how an element's animation impacts its underlying property values. - * - * To understand these values, take the example of a `keyframeEffect` value of `blur(2)` working on an underlying property value of `blur(3)`. - * - `replace` - The keyframeEffect overrides the underlying value it is combined with: `blur(2)` replaces `blur(3)`. - * - `add` - The keyframeEffect is added to the underlying value with which it is combined (aka additive): `blur(2) blur(3)`. - * - `accumulate` - The keyframeEffect is accumulated on to the underlying value: `blur(5)`. - * - * Read more on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/composite) - * - * I recommend reading [web.dev](https://web.dev)'s article on [web-animations](https://web.dev/web-animations/#smoother-animations-with-composite-modes). - */ - composite?: KeyframeEffectOptions["composite"] | TypeCallback; - /** - * The properties of the `extend` animation option are not interperted or computed, they are given directly to the `Web Animation API`, as way to access features that haven't been implemented in `@okikio/animate`, for example, `iterationStart`. - * - * `extend` is supposed to future proof the library if new features are added to the `Web Animation API` that you want to use, but that has not been implemented yet. - * - * _**Note**: it doesn't allow for declaring actual animation keyframes; it's just for animation timing options, and it overrides all other animation timing options that accomplish the same goal, e.g. `loop` & `iterations`, if `iterations` is a property of `extend` then `iterations` will override `loop`._ - * - * @example - * ```ts - * animate({ - * target: ".div", - * opacity: [0, 1], - * loop: 5, - * extend: { - * iterationStart: 0.5, - * // etc... - * fill: "both", // This overrides fillMode - * iteration: 2, // This overrides loop - * } - * }); - * ``` - */ - extend?: KeyframeEffectOptions | TypeCallback; - /** - * Theses are the CSS properties to be animated as Keyframes - * - * Read more on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/setKeyframes) - * - * @remark - * An `object` containing key-value pairs consisting of the property to animate and an `array` of values to iterate over. - * - * @example - * ```ts - * element.animate({ - * opacity: [ 0, 1 ], // [ from, to ] - * color: [ "#fff", "#000" ] // [ from, to ] - * }, 2000); - * ``` - * - * Using this format, the number of elements in each array does not need to be equal. The provided values will be spaced out independently. - - * @example - * ```ts - * element.animate({ - * opacity: [ 0, 1 ], // offset: 0, 1 - * backgroundColor: [ "red", "yellow", "green" ], // offset: 0, 0.5, 1 - * }, 2000); - * ``` - * - * The special keys `offset`, `easing`, and `composite` (described below) may be specified alongside the property values. - - * @example - * ```ts - * element.animate({ - * opacity: [ 0, 0.9, 1 ], - * offset: [ 0, 0.8 ], // Shorthand for [ 0, 0.8, 1 ] - * easing: [ 'ease-in', 'ease-out' ], - * }, 2000); - * ``` - * - * After generating a suitable set of keyframes from the property value lists, each supplied offset is applied to the corresponding keyframe. If there are insufficient values, or if the list contains `null` values, the keyframes without specified offsets will be evenly spaced as with the array format described above. - * - * If there are too few `easing` or `composite` values, the corresponding list will be repeated as needed. - * - * _**Note**: to use `composite` you will need to add it to the {@link AnimationOptions.extend | extend} object as an option_ - */ - [property: `--${string}`]: TypeAnimationOptionTypes; -} -export declare type TypeAnimationEvents = "update" | "play" | "pause" | "begin" | "cancel" | "finish" | "error" | "stop" | "playstate-change"; -export declare type TypePlayStates = "idle" | "running" | "paused" | "finished"; -/** - * CSS properties - */ -export interface ICSSProperties { - [key: string]: TypeSingleValueCSSProperty | Array; -} -/** - * After being computed as an animation option - */ -export interface ICSSComputedTransformableProperties { - perspective?: TypeSingleValueCSSProperty; - rotate?: TypeSingleValueCSSProperty | Array; - rotate3d?: TypeSingleValueCSSProperty | Array; - rotateX?: TypeSingleValueCSSProperty; - rotateY?: TypeSingleValueCSSProperty; - rotateZ?: TypeSingleValueCSSProperty; - translate?: TypeSingleValueCSSProperty | Array; - translate3d?: TypeSingleValueCSSProperty | Array; - translateX?: TypeSingleValueCSSProperty; - translateY?: TypeSingleValueCSSProperty; - translateZ?: TypeSingleValueCSSProperty; - scale?: TypeSingleValueCSSProperty | Array; - scale3d?: TypeSingleValueCSSProperty | Array; - scaleX?: TypeSingleValueCSSProperty; - scaleY?: TypeSingleValueCSSProperty; - scaleZ?: TypeSingleValueCSSProperty; - skew?: TypeSingleValueCSSProperty | Array; - skewX?: TypeSingleValueCSSProperty; - skewY?: TypeSingleValueCSSProperty; -} diff --git a/packages/animate/@types/utils.d.ts b/packages/animate/@types/utils.d.ts index d902caa..45805fb 100644 --- a/packages/animate/@types/utils.d.ts +++ b/packages/animate/@types/utils.d.ts @@ -24,7 +24,7 @@ export declare const trim: (str: string) => string; * For array do nothing * For everything else wrap the input in an array */ -export declare const toArr: (input: any, type?: string) => any[]; +export declare const toArr: (input: any) => any[]; /** * Checks if a value is valid/truthy; it counts empty arrays and strings as falsey, * as well as null, undefined, and NaN, everything else is valid diff --git a/packages/animate/package.json b/packages/animate/package.json index 39cbe7f..b9a633f 100644 --- a/packages/animate/package.json +++ b/packages/animate/package.json @@ -33,7 +33,7 @@ ], "scripts": { "dts": "rm -r -f @types/ && tsc --project tsconfig.json", - "pre-release": "npm dts" + "pre-release": "npm run dts" }, "repository": { "type": "git", diff --git a/packages/emitter/@types/api.d.ts b/packages/emitter/@types/api.d.ts deleted file mode 100644 index b5eb95f..0000000 --- a/packages/emitter/@types/api.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { Manager } from "@okikio/manager"; -/** - * Represents a listener callback function - */ -export declare type TypeListenerCallback = ((...args: any) => void); -/** Represents a new event listener consisting of properties like: callback, scope, name */ -export interface IListener { - readonly callback: TypeListenerCallback; - readonly scope: object; - readonly name: string; -} -/** - * Creates a new listener based on {@link IListener | IListener} - */ -export declare const newListener: ({ callback, scope, name, }: IListener) => IListener; -/** Represents a new event */ -export declare class Event extends Manager { - /** The name of the event */ - name: string; - constructor(name?: string); -} -/** Determines whether value is an pure object (not array, not function, etc...) */ -export declare const isObject: (obj: any) => boolean; -/** - * The types of values `EventEmitter.prototype.on(...), EventEmitter.prototype.once(...), and EventEmitter.prototype.off(...)` accept - */ -export declare type TypeEventInput = string | object | Array; -/** - * An Event Emitter - * */ -export declare class EventEmitter extends Manager { - constructor(); - /** Gets event, if event doesn't exist create a new one */ - getEvent(name: string): Event; - /** Creates a listener and adds it to an event */ - newListener(name: string, callback: TypeListenerCallback, scope: object): Event; - /** Adds a listener to a given event */ - on(events: TypeEventInput, callback?: TypeListenerCallback | object, scope?: object): EventEmitter; - /** Removes a listener from an event */ - removeListener(name: string, callback: TypeListenerCallback, scope: object): Event; - /** Remove a listener from a given event, or just completely remove an event */ - off(events: TypeEventInput, callback?: TypeListenerCallback | object, scope?: object): EventEmitter; - /** - * Adds a one time event listener for an event - */ - once(events: TypeEventInput, callback?: TypeListenerCallback | object, scope?: object): EventEmitter; - /** Call all listeners within an event */ - emit(events: string | Array, ...args: any): EventEmitter; - /** Clears events and event listeners */ - clear(): this; -} -export default EventEmitter; diff --git a/packages/manager/@types/api.d.ts b/packages/manager/@types/api.d.ts deleted file mode 100644 index e7f071a..0000000 --- a/packages/manager/@types/api.d.ts +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Acts as an enhanced version of the Map class with new features and changed behavior for convenience - * - * @typeParam K - the type of keys to store use to store values - * @typeParam V - the type of values to store - * */ -export declare class Manager { - /** For backward compatability and performance reasons Manager use Map to store data */ - map: Map; - constructor(value?: Array<[K, V]>); - /** Returns the Manager classes base Map */ - getMap(): Map; - /** Get a value stored in the Manager */ - get(key: K): V; - /** Returns the keys of all items stored in the Manager as an Array */ - keys(): Array; - /** Returns the values of all items stored in the Manager as an Array */ - values(): Array; - /** Set a value to the Manager using a key */ - set(key: K, value: V): Manager; - /** Adds a value to Manager, and uses the current size of the Manager as it's key, it works best when all the key in the Manager are numbers */ - add(value: V): Manager; - /** Returns the total number of items stored in the Manager */ - get size(): number; - /** An alias for size */ - get length(): number; - /** Returns the last item in the Manager who's index is a certain distance from the last item in the Manager */ - last(distance?: number): V | undefined; - /** Removes a value stored in the Manager via a key, returns true if an element in the Map object existed and has been removed, or false if the element does not exist */ - delete(key: K): boolean; - /** Removes a value stored in the Manager via a key, returns the Manager class, allowing for chains */ - remove(key: K): Manager; - /** Clear the Manager of all its contents */ - clear(): Manager; - /** Checks if the Manager contains a certain key */ - has(key: K): boolean; - /** Returns a new Iterator object that contains an array of [key, value] for each element in the Map object in insertion order. */ - entries(): IterableIterator<[K, V]>; - /** Iterates through the Managers contents, calling a callback function every iteration */ - forEach(callback: (value?: V, key?: K, map?: Map) => void, context?: object): Manager; - /** Allows for iteration via for..of, learn more: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators] */ - [Symbol.iterator](): IterableIterator<[K, V]>; -} -/** - * Calls the method of a certain name for all items that are currently installed - */ -export declare const methodCall: (manager: Manager, method: string, ...args: any) => void; -export default Manager; diff --git a/packages/native/@types/api.d.ts b/packages/native/@types/api.d.ts deleted file mode 100644 index bf04432..0000000 --- a/packages/native/@types/api.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -export * from "./config"; -export * from "./manager"; -export * from "./url"; -export * from "./history"; -export * from "./page"; -export * from "./service"; -export * from "./transition"; -export * from "./app"; -export * from "./pjax"; -export * from "./router"; diff --git a/packages/native/@types/app.d.ts b/packages/native/@types/app.d.ts deleted file mode 100644 index d1eb651..0000000 --- a/packages/native/@types/app.d.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { EventEmitter } from "@okikio/emitter"; -import { ServiceManager, Service } from "./service"; -import type { TypeEventInput } from "@okikio/emitter"; -import type { ICONFIG } from "./config"; -import type { ITransitionData } from "./transition"; -import type { TypeStateEvent } from "./pjax"; -export interface IApp extends App { -} -export declare type TypeAllEvents = "REQUEST_ERROR" | "TIMEOUT_ERROR" | "ANCHOR_HOVER" | "HOVER" | "ANCHOR_CLICK" | "CLICK" | "PREFETCH" | "POPSTATE" | "POPSTATE_BACK" | "POPSTATE_FORWARD" | "HISTORY_NEW_ITEM" | "GO" | "NAVIGATION_START" | "PAGE_LOADING" | "PAGE_LOAD_COMPLETE" | "NAVIGATION_END" | "TRANSITION_START" | "TRANSITION_END" | "BEFORE_TRANSITION_OUT" | "AFTER_TRANSITION_OUT" | "CONTENT_INSERT" | "CONTENT_REPLACED" | "BEFORE_TRANSITION_IN" | "AFTER_TRANSITION_IN" | "READY" | "ready" | "SCROLL" | "scroll" | "RESIZE" | "resize"; -export declare type TypeEmitArgs = ((ITransitionData & { - oldHref: string; - href: string; - transitionName: string; -}) | TypeStateEvent | Error | void | any)[]; -export declare type TypeAppListenerCallback = (...args: TypeEmitArgs) => void; -/** The App class starts the entire process, it controls all managers and all services */ -export declare class App { - /** An instance of the ServiceManager */ - services: ServiceManager; - /** An instance of an EventEmitter */ - emitter: EventEmitter; - /** The current Configuration's for the App */ - config: ICONFIG; - protected canResize: boolean; - protected canScroll: boolean; - constructor(config?: ICONFIG); - /** Create new instances of the ServiceManager, EventEmitter and the configurations */ - register(config?: ICONFIG): App; - protected _ready(): void; - protected _resize(): void; - protected _scroll(): void; - /** Shortcuts for getting Services */ - get(key: string): Service; - /** Shortcuts for setting Services */ - set(key: string, value: Service): App; - /** Shortcuts for adding Services */ - add(value: Service): App; - /** Initialize and boot all Services */ - boot(): App; - /** Stops all Services and clears the even emitter of all events and listeners */ - stop(): App; - /** Shortcuts to the App EventEmitter on method */ - on(events: TypeAllEvents | TypeEventInput, callback?: TypeAppListenerCallback): App; - /** Shortcuts to the App EventEmitter off method */ - off(events: TypeAllEvents | TypeEventInput, callback?: TypeAppListenerCallback): App; - /** Shortcuts to the App EventEmitter emit method */ - emit(events: TypeAllEvents | string | string[], ...args: TypeEmitArgs): App; -} diff --git a/packages/native/@types/config.d.ts b/packages/native/@types/config.d.ts deleted file mode 100644 index 0f92c33..0000000 --- a/packages/native/@types/config.d.ts +++ /dev/null @@ -1,113 +0,0 @@ -import type { TypeIgnoreURLsList } from "./pjax"; -import type { ITransition } from "./transition"; -export interface ICONFIG { - /** - * The Prefix attached to data attributes - */ - prefix?: string; - /** - * The attribute used to identify wrappers - * @default `wrapper` as in `data-wrapper` - */ - wrapperAttr?: string; - /** - * Headers to attach to fetch requests done by the PageManager - * e.g. if you only want to load a partial output containing only the wrapper - * - * @default `[]` - * @example - * ```ts - * headers: [ - * ["partial-output", "true"] - * ] - * ``` - */ - headers?: string[][]; - /** - * Attribute used to identify anchors that don't want PJAX enabled - * @default `prevent="self"` as in `data-prevent="self"` - */ - preventSelfAttr?: string; - /** - * Attribute used to identify elements that don't want PJAX enabled for themeselves and their child elements - * @default `prevent="all"` as in `data-prevent="all"` - */ - preventAllAttr?: string; - /** - * Attribute used to identify transition an anchor wants to use, the value you set will select the transition used by name - * _**Note**: transition names are case sensitive_ - * @default `transition` as in `data-transition` - */ - transitionAttr?: string; - /** - * The amount of time in milliseconds to wait before counting the PageManagers fetch requests as timed out - * @default `2000` - */ - timeout?: number; - /** - * The maximum amount of pages to have in the cache at any moment in time; - * PageManager removes pages from the cache to ensure content doesn't become stale; - * and memory usage isn't too high - * @default `5` - */ - maxPages?: number; - /** - * The resize event is debounced by this amount of time (in miliseconds) - * @default `100` - */ - resizeDelay?: number; - /** - * Ignore extra clicks of an anchor element if a transition has already started - * by default PJAX will reload the page on multiple clicks but this allows you to stop extra clicks - * from affecting the current transition - * @default `true` - */ - onTransitionPreventClick?: boolean; - /** - * Specifies which urls to always fetch from the web - * It also accepts boolean values: - * - `true` means always fetch from the web for all urls - * - `false` means always try to fetch from the cache - * @default `false` - */ - cacheIgnore?: boolean | TypeIgnoreURLsList; - /** - * Specifies which urls to not prefetch - * It also accepts boolean values: - * - `true` means don't prefetch any anchor - * - `false` means always prefetch all anchors - * @default `false` - */ - prefetchIgnore?: boolean | TypeIgnoreURLsList; - /** - * Specifies which urls to not use PJAX for - * @default `[]` - */ - preventURLs?: boolean | TypeIgnoreURLsList; - /** - * On page change (excluding popstate events, and hashes) keep current scroll position - * @default `false` - */ - stickyScroll?: boolean; - /** - * Force load a page if an error occurs - * @default `true` - */ - forceOnError?: boolean; - /** - * Don't do anything if the url has a hash - * @default `false` - */ - ignoreHashAction?: boolean; - /** - * TransitionManagers regestered transitions - * @default `[]` - */ - transitions?: Array<[string, ITransition]>; - [key: string]: any; -} -export declare const CONFIG_DEFAULTS: ICONFIG; -export declare type TypeConfigKeys = keyof typeof CONFIG_DEFAULTS | string; -export declare const newConfig: (config: ICONFIG) => ICONFIG; -/** Converts config properties into properly formatted data attributes */ -export declare const toAttr: (config: ICONFIG, value?: TypeConfigKeys, brackets?: boolean) => any; diff --git a/packages/native/@types/history.d.ts b/packages/native/@types/history.d.ts deleted file mode 100644 index 1e46064..0000000 --- a/packages/native/@types/history.d.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { Service } from "./service"; -export declare type TypeTrigger = HTMLAnchorElement | "HistoryManager" | "popstate" | "back" | "forward"; -export interface ICoords { - readonly x: number; - readonly y: number; -} -export interface IStateData { - scroll: ICoords; - [key: string]: any; -} -export interface IState { - url: string; - index?: number; - transition: string; - data: IStateData; -} -export interface IHistoryItem { - index: number; - states: IState[]; -} -/** A quick snapshot of page scroll coordinates */ -export declare const newCoords: (x?: number, y?: number) => ICoords; -/** Creates a state; a state represents the current status of the page consisting of properties like: url, transition, and data */ -export declare const newState: (state?: IState) => IState; -/** Keeps a record of the history of the App; it stores only the states of Pages */ -export declare class HistoryManager extends Service { - states: IState[]; - pointer: number; - /** Initializes the states array, and replace the history pushState data with the states array */ - init(): void; - /** Get a state based on it's index */ - get(index: number): IState; - /** Add a state to HistoryManager and change the history pushState data based on the historyAction specified */ - add(value?: IState, historyAction?: "replace" | "push"): HistoryManager; - remove(index?: number): this; - /** Replaces the states array with another states array, this is later used when going back and forward in page history */ - replace(newStates: IState[]): this; - /** Set state by index. */ - set(i: number, state: IState): IState; - /** Get the current state */ - get current(): IState; - /** Get the last state (top of the history stack). */ - get last(): IState; - /** Get the previous state. */ - get previous(): IState | null; - get length(): number; -} -export interface IHistoryManager extends HistoryManager { -} -/** Either push or replace history state */ -export declare const changeState: (action: "push" | "replace", state: IState, item: object) => void; diff --git a/packages/native/@types/manager.d.ts b/packages/native/@types/manager.d.ts deleted file mode 100644 index 4216437..0000000 --- a/packages/native/@types/manager.d.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Manager, methodCall } from "@okikio/manager"; -import { EventEmitter } from "@okikio/emitter"; -import type { ICONFIG } from "./config"; -import type { IApp } from "./app"; -export declare type TypeAdvancedManager = AdvancedManager; -/** The base class for AdvancedManager items */ -export declare class ManagerItem { - /** The AdvancedManager the ManagerItem is attached to */ - manager: TypeAdvancedManager; - /** The App the ManagerItem is attached to */ - app: IApp; - /** The Config of the App the ManagerItem is attached to */ - config: ICONFIG; - /** The EventEmitter of the App the ManagerItem is attached to */ - emitter: EventEmitter; - /** The key to where ManagerItem is stored in an AdvancedManager */ - key: any; - constructor(); - /** Run after the Manager Item has been registered */ - install(): any; - /** Register the current Manager Item's manager */ - register(manager: TypeAdvancedManager, key: any): ManagerItem; - /** Run before the ManagerItem has been unregistered */ - uninstall(): any; - /** Basically removes a ManagerItem, in order to recover the ManagerItem, it needs to be re-added to an AdvancedManager */ - unregister(): void; -} -/** A tweak to the Manager class that makes it self aware of the App class it's instantiated in */ -export declare class AdvancedManager extends Manager { - /** The App the AdvancedManager is attached to */ - app: IApp; - /** The Config of the App the AdvancedManager is attached to */ - config: ICONFIG; - /** The EventEmitter of the App the AdvancedManager is attached to */ - emitter: EventEmitter; - /** Register App details */ - constructor(app: IApp); - /** Add a ManagerItem to AdvancedManager at a specified key */ - set(key: K, value: V): this; -} -export { Manager, methodCall }; diff --git a/packages/native/@types/page.d.ts b/packages/native/@types/page.d.ts deleted file mode 100644 index 35ad84d..0000000 --- a/packages/native/@types/page.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { Manager, ManagerItem, AdvancedManager } from "./manager"; -import { Service } from "./service"; -import type { TypeIgnoreURLsList } from "./pjax"; -/** - * Parses strings to DOM - */ -export declare const PARSER: DOMParser; -/** A page represents the DOM elements that create each page */ -export declare class Page extends ManagerItem { - /** Holds the DOM of the current page */ - dom: Document; - /** Holds the wrapper element to be swapped out of each Page */ - wrapper: HTMLElement; - /** Holds the title of each page */ - title: string; - /** Holds the head element of each page */ - head: Element; - /** Holds the body element of each page */ - body: Element; - /** The URL of the current page */ - url: URL; - /** The payload of a page request */ - data: string; - /** Attr that identifies the wrapper */ - wrapperAttr: string; - constructor(url?: string | URL, dom?: string | Document); - /** Builds the page's dom, and sets the title, head, body, and wrapper properties of the Page class */ - build(): Promise; - install(): void; - uninstall(): void; -} -export interface IPage extends Page { -} -/** Controls which page to load */ -export declare class PageManager extends Service { - /** Stores all fetch requests that are currently loading */ - loading: Manager>; - pages: AdvancedManager; - /** URLs to ignore caching */ - cacheIgnore: TypeIgnoreURLsList | boolean; - constructor(); - /** Instantiate pages, and add the current page to pages */ - install(): void; - get(key: string): Page; - add(value: IPage): this; - set(key: string, value: IPage): this; - remove(key: string): this; - has(key: string): boolean; - clear(): this; - get size(): number; - keys(): string[]; - /** Load from cache or by requesting URL via a fetch request, avoid requesting for the same thing twice by storing the fetch request in "this.loading" */ - load(_url?: URL | string): Promise; - /** Starts a fetch request */ - request(url: string): Promise; -} -/** Check if url is supposed to be ignored */ -export declare const ignoreURLs: (urlString: string, ignoreList: boolean | TypeIgnoreURLsList) => boolean; -export interface IPageManager extends PageManager { -} diff --git a/packages/native/@types/pjax.d.ts b/packages/native/@types/pjax.d.ts deleted file mode 100644 index 164c885..0000000 --- a/packages/native/@types/pjax.d.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { Service } from "./service"; -import type { TypeTrigger } from "./history"; -export declare type TypeLinkEvent = MouseEvent | TouchEvent; -export declare type TypeStateEvent = TypeLinkEvent | PopStateEvent; -export declare type TypeIgnoreURLsList = Array; -/** - * Creates a barbajs based PJAX Service, for the native framework - * Based on barbajs and StartingBlocks - */ -export declare class PJAX extends Service { - /** URLs to disable PJAX for */ - preventURLs: boolean | TypeIgnoreURLsList; - /** URLs to ignore when prefetching / Whether or not to disable prefetching */ - prefetchIgnore: boolean | TypeIgnoreURLsList; - /** Current state of transitions */ - isTransitioning: boolean; - /** Ignore extra clicks of an anchor element if a transition has already started */ - onTransitionPreventClick: boolean; - /** On page change (excluding popstate events) keep current scroll position */ - stickyScroll: boolean; - /** Force load a page if an error occurs */ - forceOnError: boolean; - /** Ignore hash action if set to true */ - ignoreHashAction: boolean; - install(): void; - /** Sets the transition state to either true or false */ - transitionStart(): void; - transitionStop(): void; - init(): void; - /** Starts the PJAX Service */ - boot(): void; - /** Gets the transition to use for a certain anchor */ - getTransitionName(el: HTMLAnchorElement): string | null; - /** Checks to see if the anchor is valid */ - validLink(el: HTMLAnchorElement, event: TypeLinkEvent | KeyboardEvent, href: string): boolean; - /** Returns the href of an Anchor element */ - getHref(el: HTMLAnchorElement): string | null; - /** Check if event target is a valid anchor with an href, if so, return the anchor */ - getLink(event: TypeLinkEvent): HTMLAnchorElement; - /** When an element is clicked, get valid anchor element, go for a transition */ - onClick(event: TypeLinkEvent): void; - /** Returns the direction of the State change as a String, either the Back button or the Forward button */ - getDirection(value: number): TypeTrigger; - /** Force a page to go to a certain URL */ - force(href: string): void; - /** - * If transition is running force load page. - * Stop if currentURL is the same as new url. - * On state change, change the current state history, to reflect the direction of said state change - * Load page and page transition. - */ - go({ href, trigger, event }: { - href: string; - trigger?: TypeTrigger; - event?: TypeStateEvent; - }): Promise; - /** Load the new Page as well as a Transition; starts the Transition */ - load({ oldHref, href, trigger, transitionName, scroll, }: { - oldHref: string; - href: string; - trigger?: TypeTrigger; - transitionName?: string; - scroll?: { - x: number; - y: number; - }; - }): Promise; - /** When you hover over an anchor, prefetch the event target's href */ - onHover(event: TypeLinkEvent): Promise; - /** When History state changes, get url from State, go for a Transition. */ - onStateChange(event: PopStateEvent): void; - /** Initialize DOM Events */ - initEvents(): void; - /** Stop DOM Events */ - stopEvents(): void; -} diff --git a/packages/native/@types/router.d.ts b/packages/native/@types/router.d.ts deleted file mode 100644 index ea27e90..0000000 --- a/packages/native/@types/router.d.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Service } from "./service"; -import { Manager } from "./manager"; -export declare type TypeRouteMethod = (...args: any) => any; -export declare type TypeRouteStyle = string | RegExp | boolean | TypeRouteStyle[]; -export interface IRouteToFrom { - to?: TypeRouteStyle; - from?: TypeRouteStyle; -} -export declare type TypeRoutePath = IRouteToFrom & ({ - to: TypeRouteStyle; -} | { - from: TypeRouteStyle; -}) | TypeRouteStyle; -export interface IRoute { - path: TypeRoutePath; - method: TypeRouteMethod; -} -/** Controls what happens when certain url paths match a set of criteria */ -export declare class Router extends Service { - /** List of routes */ - protected routes: Manager; - constructor(routes?: IRoute[]); - /** Add a new route to watch for */ - add({ path, method }: IRoute): Router; - /** Convert strings into path match functions */ - parsePath(path: TypeRouteStyle): RegExp | boolean; - /** Determines if a strings counts has a path */ - isPath(input: TypeRouteStyle): boolean; - /** Parse the multiple different formats for paths, into a { from, to } object */ - parse(input: TypeRoutePath): IRouteToFrom; - /** Test if route paths are true, if so run their methods */ - route(): void; - /** Add listeners for PJAX Events */ - initEvents(): void; - /** Remove listeners for PJAX Events */ - stopEvents(): void; -} diff --git a/packages/native/@types/service.d.ts b/packages/native/@types/service.d.ts deleted file mode 100644 index dc1565d..0000000 --- a/packages/native/@types/service.d.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { AdvancedManager, ManagerItem } from "./manager"; -import { IApp } from "./app"; -/** Controls specific kinds of actions that require JS */ -export declare class Service extends ManagerItem { - /** Called before the start of a Service, represents a constructor of sorts */ - init(...args: any): any; - /** Called on start of Service */ - boot(...args: any): any; - /** Initialize events */ - initEvents(): void; - /** Stop events */ - stopEvents(): void; - /** Stop Service */ - stop(): void; -} -/** The Service Manager controls the lifecycle of all Services in an App */ -export declare class ServiceManager extends AdvancedManager { - constructor(app: IApp); - /** Call the init method for all Services */ - init(): ServiceManager; - /** Call the boot method for all Services */ - boot(): ServiceManager; - /** Call the stop method for all Services */ - stop(): ServiceManager; -} diff --git a/packages/native/@types/transition.d.ts b/packages/native/@types/transition.d.ts deleted file mode 100644 index 5b91fee..0000000 --- a/packages/native/@types/transition.d.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Manager } from "./manager"; -import { Service } from "./service"; -import type { ICoords, TypeTrigger } from "./history"; -import type { IPage } from "./page"; -/** - * The async function type, allows for smooth transition between Promises - */ -export declare type TypeAsyncFn = (value?: any) => void; -export interface ITransition { - oldPage?: IPage; - newPage?: IPage; - trigger?: TypeTrigger; - scroll?: { - x: number; - y: number; - }; - manualScroll?: boolean; - init?: (data: IInitialTransitionData) => void; - in?: (data: ITransitionData) => any; - out?: (data: ITransitionData) => any; - [key: string]: any; -} -export interface IInitialTransitionData { - trigger?: TypeTrigger; - scroll?: ICoords; - oldPage: IPage; - newPage: IPage; - ignoreHashAction: boolean; -} -export interface ITransitionData extends IInitialTransitionData { - from?: IPage; - to?: IPage; - done: TypeAsyncFn; -} -/** Auto scrolls to an elements position if the element has an hash */ -export declare const hashAction: (coords?: ICoords, hash?: string) => ICoords; -/** The Default Transition, it replaces the container with the new page container */ -export declare const TRANSITION_REPLACE: ITransition; -/** Controls which Transition between pages to use */ -export declare class TransitionManager extends Service { - transitions: Manager; - _arg: Array<[string, ITransition]>; - constructor(transitions?: Array<[string, ITransition]>); - /** On Service install set Config */ - install(): void; - get(key: string): ITransition; - set(key: string, value: ITransition): this; - add(value: ITransition): this; - has(key: string): boolean; - /** Starts a transition */ - start(name: string, data: IInitialTransitionData): Promise; -} -export interface ITransitionManager extends TransitionManager { -} diff --git a/packages/native/@types/url.d.ts b/packages/native/@types/url.d.ts deleted file mode 100644 index f534695..0000000 --- a/packages/native/@types/url.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -export declare const newURL: (url?: string | URL | Location) => URL; -/** Returns the pathname with the hash at the end */ -export declare const getHashedPath: (url: URL | string) => string; -/** Returns the actual hash without the hashtag */ -export declare const getHash: (url: URL | string) => string; -/** Removes the hash from the full URL for a clean URL string */ -export declare const clean: (url: URL | string) => string; -/** Compares two URLs to each other */ -export declare const equal: (a: URL | string, b: URL | string) => boolean;