@player-ui/asset-transform-plugin 0.8.0--canary.307.9645 → 0.8.0-next.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.
@@ -0,0 +1,18 @@
1
+ import type { Player, PlayerPlugin, TransformRegistry, TransformFunction, TransformFunctions } from "@player-ui/player";
2
+ import { Registry } from "@player-ui/partial-match-registry";
3
+ export * from "./utils";
4
+ export * from "./propertiesToSkip";
5
+ export type TransformType = TransformFunction<any> | TransformFunctions;
6
+ export type TransformRegistryEntries = Array<[any, TransformType]>;
7
+ export type AssetTransformInit = Registry<TransformType> | TransformRegistryEntries;
8
+ /**
9
+ * A plugin to register custom transforms on certain asset types
10
+ * This allows users to embed stateful data into transforms.
11
+ */
12
+ export declare class AssetTransformPlugin implements PlayerPlugin {
13
+ name: string;
14
+ readonly registry: TransformRegistry;
15
+ constructor(transforms: AssetTransformInit);
16
+ apply(player: Player): void;
17
+ }
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,8 @@
1
+ import type { BeforeTransformFunction } from "@player-ui/player";
2
+ /**
3
+ * Passes a property to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist
4
+ *
5
+ * @param asset - Asset to apply the transform to
6
+ */
7
+ export declare const propertiesToSkipTransform: (parameters: string[]) => BeforeTransformFunction;
8
+ //# sourceMappingURL=propertiesToSkip.d.ts.map
@@ -0,0 +1,15 @@
1
+ import type { BeforeTransformFunction, TransformFunction, TransformFunctions } from "@player-ui/player";
2
+ /**
3
+ * Helper function to make it easier to create transforms that need to be ran in
4
+ * the `beforeResolve` hook. Just like `compose`, functions are evaluated from
5
+ * right-to-left.
6
+ */
7
+ export declare function composeBefore(...args: BeforeTransformFunction<any>[]): TransformFunctions;
8
+ /**
9
+ * Performs right-to-left function evaluation of each transform function. Unlike
10
+ * other compose functions, this does not require unary arguments for all but the
11
+ * last function. The value returned from each function will be used as the value
12
+ * for the next function.
13
+ */
14
+ export declare function compose(...args: Array<TransformFunction<any> | TransformFunctions>): TransformFunctions;
15
+ //# sourceMappingURL=utils.d.ts.map
package/dist/index.cjs.js DELETED
@@ -1,123 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var partialMatchRegistry = require('@player-ui/partial-match-registry');
6
-
7
- function composeTransforms(...args) {
8
- const [fn, ...fns] = args.reverse();
9
- return (asset, options, store) => {
10
- const value = fn(asset, options, store);
11
- if (!fns.length) {
12
- return value;
13
- }
14
- return fns.reduce((prevValue, current) => {
15
- return current(prevValue, options, store);
16
- }, value);
17
- };
18
- }
19
- function composeBefore(...args) {
20
- return {
21
- beforeResolve: composeTransforms(...args)
22
- };
23
- }
24
- function compose(...args) {
25
- const beforeResolveFns = [];
26
- const resolveFns = [];
27
- for (const arg of args) {
28
- if (typeof arg === "function") {
29
- resolveFns.push(arg);
30
- } else {
31
- if (arg == null ? void 0 : arg.resolve) {
32
- resolveFns.push(arg.resolve);
33
- }
34
- if (arg == null ? void 0 : arg.beforeResolve) {
35
- beforeResolveFns.push(arg.beforeResolve);
36
- }
37
- }
38
- }
39
- return {
40
- beforeResolve: beforeResolveFns.length ? composeTransforms(...beforeResolveFns) : void 0,
41
- resolve: resolveFns.length ? composeTransforms(...resolveFns) : void 0
42
- };
43
- }
44
-
45
- var __defProp = Object.defineProperty;
46
- var __defProps = Object.defineProperties;
47
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
48
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
49
- var __hasOwnProp = Object.prototype.hasOwnProperty;
50
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
51
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
52
- var __spreadValues = (a, b) => {
53
- for (var prop in b || (b = {}))
54
- if (__hasOwnProp.call(b, prop))
55
- __defNormalProp(a, prop, b[prop]);
56
- if (__getOwnPropSymbols)
57
- for (var prop of __getOwnPropSymbols(b)) {
58
- if (__propIsEnum.call(b, prop))
59
- __defNormalProp(a, prop, b[prop]);
60
- }
61
- return a;
62
- };
63
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
64
- const propertiesToSkipTransform = (parameters) => {
65
- return (asset) => {
66
- var _a, _b, _c, _d;
67
- const skipArray = (_c = (_b = (_a = asset.plugins) == null ? void 0 : _a.stringResolver) == null ? void 0 : _b.propertiesToSkip) != null ? _c : [];
68
- const parameterArray = parameters.filter((element) => {
69
- return element !== "";
70
- });
71
- if (parameterArray.length === 0) {
72
- return asset;
73
- }
74
- if (skipArray.length > 0 && skipArray.every((arr) => parameterArray.includes(arr)) && parameterArray.every((arr) => skipArray.includes(arr))) {
75
- return asset;
76
- }
77
- const addParams = new Set([...skipArray, ...parameterArray]);
78
- return __spreadProps(__spreadValues({}, asset), {
79
- plugins: __spreadProps(__spreadValues({}, asset.plugins), {
80
- stringResolver: __spreadProps(__spreadValues({}, (_d = asset == null ? void 0 : asset.plugins) == null ? void 0 : _d.stringResolver), {
81
- propertiesToSkip: [...addParams]
82
- })
83
- })
84
- });
85
- };
86
- };
87
-
88
- function maybeCompose(maybeFn) {
89
- if (typeof maybeFn === "object") {
90
- return maybeFn;
91
- }
92
- return compose(maybeFn);
93
- }
94
- function cleanupTransformRegistry(maybeRegistry) {
95
- if (Array.isArray(maybeRegistry)) {
96
- const wrappedTransforms = maybeRegistry.map(([key, value]) => {
97
- return [key, maybeCompose(value)];
98
- });
99
- return new partialMatchRegistry.Registry(wrappedTransforms);
100
- }
101
- const registry = new partialMatchRegistry.Registry();
102
- maybeRegistry.forEach(({ key, value }) => {
103
- registry.set(key, maybeCompose(value));
104
- });
105
- return registry;
106
- }
107
- class AssetTransformPlugin {
108
- constructor(transforms) {
109
- this.name = "asset-transform";
110
- this.registry = cleanupTransformRegistry(transforms);
111
- }
112
- apply(player) {
113
- player.hooks.viewController.tap(this.name, (vc) => {
114
- this.registry.forEach(({ key, value }) => vc.transformRegistry.set(key, maybeCompose(value)));
115
- });
116
- }
117
- }
118
-
119
- exports.AssetTransformPlugin = AssetTransformPlugin;
120
- exports.compose = compose;
121
- exports.composeBefore = composeBefore;
122
- exports.propertiesToSkipTransform = propertiesToSkipTransform;
123
- //# sourceMappingURL=index.cjs.js.map
package/dist/index.d.ts DELETED
@@ -1,39 +0,0 @@
1
- import { BeforeTransformFunction, TransformFunctions, TransformFunction, PlayerPlugin, TransformRegistry, Player } from '@player-ui/player';
2
- import { Registry } from '@player-ui/partial-match-registry';
3
-
4
- /**
5
- * Helper function to make it easier to create transforms that need to be ran in
6
- * the `beforeResolve` hook. Just like `compose`, functions are evaluated from
7
- * right-to-left.
8
- */
9
- declare function composeBefore(...args: BeforeTransformFunction<any>[]): TransformFunctions;
10
- /**
11
- * Performs right-to-left function evaluation of each transform function. Unlike
12
- * other compose functions, this does not require unary arguments for all but the
13
- * last function. The value returned from each function will be used as the value
14
- * for the next function.
15
- */
16
- declare function compose(...args: Array<TransformFunction<any> | TransformFunctions>): TransformFunctions;
17
-
18
- /**
19
- * Passes a property to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist
20
- *
21
- * @param asset - Asset to apply the transform to
22
- */
23
- declare const propertiesToSkipTransform: (parameters: string[]) => BeforeTransformFunction;
24
-
25
- declare type TransformType = TransformFunction<any> | TransformFunctions;
26
- declare type TransformRegistryEntries = Array<[any, TransformType]>;
27
- declare type AssetTransformInit = Registry<TransformType> | TransformRegistryEntries;
28
- /**
29
- * A plugin to register custom transforms on certain asset types
30
- * This allows users to embed stateful data into transforms.
31
- */
32
- declare class AssetTransformPlugin implements PlayerPlugin {
33
- name: string;
34
- readonly registry: TransformRegistry;
35
- constructor(transforms: AssetTransformInit);
36
- apply(player: Player): void;
37
- }
38
-
39
- export { AssetTransformInit, AssetTransformPlugin, TransformRegistryEntries, TransformType, compose, composeBefore, propertiesToSkipTransform };