tailwindcss-3d-styles 1.2.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.
Potentially problematic release.
This version of tailwindcss-3d-styles might be problematic. Click here for more details.
- package/LICENSE.md +21 -0
- package/README.md +586 -0
- package/common/index.js +4 -0
- package/css-animations/base.js +19 -0
- package/css-animations/bounce-and-spin.js +121 -0
- package/css-animations/bounce.js +106 -0
- package/css-animations/index.js +8 -0
- package/css-animations/spin.js +106 -0
- package/css-utilities/backface.js +40 -0
- package/css-utilities/base.js +23 -0
- package/css-utilities/index.js +14 -0
- package/css-utilities/perspective-origin.js +39 -0
- package/css-utilities/perspective.js +69 -0
- package/css-utilities/scale.js +124 -0
- package/css-utilities/transform-box.js +43 -0
- package/css-utilities/transform-core.js +71 -0
- package/css-utilities/transform-style.js +40 -0
- package/css-utilities/transform.js +204 -0
- package/css-utilities/translate.js +104 -0
- package/index.js +94 -0
- package/package.json +19 -0
- package/types/common/index.d.ts +7 -0
- package/types/css-animations/base.d.ts +4 -0
- package/types/css-animations/bounce-and-spin.d.ts +19 -0
- package/types/css-animations/bounce.d.ts +15 -0
- package/types/css-animations/index.d.ts +12 -0
- package/types/css-animations/spin.d.ts +16 -0
- package/types/css-utilities/backface.d.ts +9 -0
- package/types/css-utilities/base.d.ts +6 -0
- package/types/css-utilities/index.d.ts +18 -0
- package/types/css-utilities/perspective-origin.d.ts +6 -0
- package/types/css-utilities/perspective.d.ts +26 -0
- package/types/css-utilities/scale.d.ts +24 -0
- package/types/css-utilities/transform-box.d.ts +12 -0
- package/types/css-utilities/transform-core.d.ts +5 -0
- package/types/css-utilities/transform-style.d.ts +9 -0
- package/types/css-utilities/transform.d.ts +38 -0
- package/types/css-utilities/translate.d.ts +24 -0
- package/types/index.d.ts +11 -0
- package/types/utils/css-value.d.ts +48 -0
- package/types/utils/dimension.d.ts +3 -0
- package/types/utils/ensure.d.ts +5 -0
- package/types/utils/generate-guard.d.ts +8 -0
- package/types/utils/lodash-transformers.d.ts +6 -0
- package/utils/css-value.js +386 -0
- package/utils/dimension.js +34 -0
- package/utils/ensure.js +33 -0
- package/utils/generate-guard.js +75 -0
- package/utils/lodash-transformers.js +108 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ResolvableTo } from 'tailwindcss/types/config';
|
|
2
|
+
import { type KeyValuePair } from '@/common';
|
|
3
|
+
declare module '@/css-utilities' {
|
|
4
|
+
interface CSSUtility {
|
|
5
|
+
defaultTheme?: ResolvableTo<KeyValuePair<string, any>>;
|
|
6
|
+
utilities: () => void;
|
|
7
|
+
normaliseFunctionValues?: (values: Record<string, any>) => string;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export * from './backface';
|
|
11
|
+
export * from './perspective';
|
|
12
|
+
export * from './perspective-origin';
|
|
13
|
+
export * from './scale';
|
|
14
|
+
export * from './transform';
|
|
15
|
+
export * from './transform-box';
|
|
16
|
+
export * from './transform-core';
|
|
17
|
+
export * from './transform-style';
|
|
18
|
+
export * from './translate';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type CSSUtility } from '@/css-utilities';
|
|
2
|
+
import { Base } from '@/css-utilities/base';
|
|
3
|
+
export declare class PerspectiveOrigin extends Base implements CSSUtility {
|
|
4
|
+
static defaultTheme: (import("tailwindcss/types/config").ResolvableTo<import("tailwindcss/types/config").KeyValuePair<string, string>> | undefined) & Record<"bottom" | "center" | "left" | "right" | "top" | "top-right" | "bottom-right" | "bottom-left" | "top-left", string>;
|
|
5
|
+
utilities: () => void;
|
|
6
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type CSSUtility } from '@/css-utilities';
|
|
2
|
+
import { Base } from '@/css-utilities/base';
|
|
3
|
+
import { type UnsafeCSSValue } from '@/utils/css-value';
|
|
4
|
+
import { type Dimension } from '@/utils/dimension';
|
|
5
|
+
interface NormaliseFunctionValuesOptions {
|
|
6
|
+
dimension?: Dimension;
|
|
7
|
+
perspective?: UnsafeCSSValue;
|
|
8
|
+
}
|
|
9
|
+
interface PerspectiveDeclarations {
|
|
10
|
+
perspective: string;
|
|
11
|
+
}
|
|
12
|
+
export declare class Perspective extends Base implements CSSUtility {
|
|
13
|
+
static defaultTheme: {
|
|
14
|
+
none: string;
|
|
15
|
+
250: string;
|
|
16
|
+
500: string;
|
|
17
|
+
750: string;
|
|
18
|
+
1000: string;
|
|
19
|
+
};
|
|
20
|
+
static defaultFunctionValues: Required<Omit<NormaliseFunctionValuesOptions, 'dimension'>>;
|
|
21
|
+
static normaliseFunctionValues: ({ dimension, perspective, }?: NormaliseFunctionValuesOptions) => string;
|
|
22
|
+
static declarations: (values?: NormaliseFunctionValuesOptions) => PerspectiveDeclarations;
|
|
23
|
+
static legacyDeclarations: () => import("@/css-utilities").TransformDeclarations;
|
|
24
|
+
utilities: () => void;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type CSSUtility } from '@/css-utilities';
|
|
2
|
+
import { Base } from '@/css-utilities/base';
|
|
3
|
+
import { type UnsafeCSSValue } from '@/utils/css-value';
|
|
4
|
+
import { type Dimension } from '@/utils/dimension';
|
|
5
|
+
interface NormaliseFunctionValuesOptions {
|
|
6
|
+
dimension?: Dimension;
|
|
7
|
+
scaleX?: UnsafeCSSValue;
|
|
8
|
+
scaleY?: UnsafeCSSValue;
|
|
9
|
+
scaleZ?: UnsafeCSSValue;
|
|
10
|
+
}
|
|
11
|
+
interface ScaleDeclarations {
|
|
12
|
+
scale: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class Scale extends Base implements CSSUtility {
|
|
15
|
+
private isProcessableValue;
|
|
16
|
+
private isProcessableValues;
|
|
17
|
+
private normaliseValues;
|
|
18
|
+
static defaultFunctionValues: Required<Omit<NormaliseFunctionValuesOptions, 'dimension'>>;
|
|
19
|
+
static normaliseFunctionValues: ({ dimension, scaleX, scaleY, scaleZ, }?: NormaliseFunctionValuesOptions) => string;
|
|
20
|
+
static declarations: (values?: NormaliseFunctionValuesOptions) => ScaleDeclarations;
|
|
21
|
+
static legacyDeclarations: () => import("@/css-utilities").TransformDeclarations;
|
|
22
|
+
utilities: () => void;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type CSSUtility } from '@/css-utilities';
|
|
2
|
+
import { Base } from '@/css-utilities/base';
|
|
3
|
+
export declare class TransformBox extends Base implements CSSUtility {
|
|
4
|
+
static defaultTheme: {
|
|
5
|
+
content: string;
|
|
6
|
+
border: string;
|
|
7
|
+
fill: string;
|
|
8
|
+
stroke: string;
|
|
9
|
+
view: string;
|
|
10
|
+
};
|
|
11
|
+
utilities: () => void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type CSSUtility } from '@/css-utilities';
|
|
2
|
+
import { Base } from '@/css-utilities/base';
|
|
3
|
+
import { type UnsafeCSSValue } from '@/utils/css-value';
|
|
4
|
+
import { type Dimension } from '@/utils/dimension';
|
|
5
|
+
interface NormaliseFunctionValuesOptions {
|
|
6
|
+
dimension?: Dimension;
|
|
7
|
+
rotateX?: UnsafeCSSValue;
|
|
8
|
+
rotateY?: UnsafeCSSValue;
|
|
9
|
+
skewX?: UnsafeCSSValue;
|
|
10
|
+
skewY?: UnsafeCSSValue;
|
|
11
|
+
}
|
|
12
|
+
interface NormaliseLegacyFunctionValuesOptions extends NormaliseFunctionValuesOptions {
|
|
13
|
+
translateX?: UnsafeCSSValue;
|
|
14
|
+
translateY?: UnsafeCSSValue;
|
|
15
|
+
translateZ?: UnsafeCSSValue;
|
|
16
|
+
rotateZ?: UnsafeCSSValue;
|
|
17
|
+
scaleX?: UnsafeCSSValue;
|
|
18
|
+
scaleY?: UnsafeCSSValue;
|
|
19
|
+
scaleZ?: UnsafeCSSValue;
|
|
20
|
+
perspective?: UnsafeCSSValue;
|
|
21
|
+
}
|
|
22
|
+
export interface TransformDeclarations {
|
|
23
|
+
'--webkit-transform': string;
|
|
24
|
+
transform: string;
|
|
25
|
+
}
|
|
26
|
+
export declare class Transform extends Base implements CSSUtility {
|
|
27
|
+
private isProcessableValue;
|
|
28
|
+
private isProcessableValues;
|
|
29
|
+
private normaliseValues;
|
|
30
|
+
static defaultFunctionValues: Required<Omit<NormaliseFunctionValuesOptions, 'dimension'>>;
|
|
31
|
+
static defaultLegacyFunctionValues: Required<Omit<NormaliseLegacyFunctionValuesOptions, 'dimension'>>;
|
|
32
|
+
static normaliseFunctionValues: ({ dimension, rotateX, rotateY, skewX, skewY, }?: NormaliseFunctionValuesOptions) => string;
|
|
33
|
+
static normaliseLegacyFunctionValues: ({ dimension, translateX, translateY, translateZ, rotateX, rotateY, rotateZ, skewX, skewY, scaleX, scaleY, scaleZ, perspective, }?: NormaliseLegacyFunctionValuesOptions) => string;
|
|
34
|
+
static declarations: (values?: NormaliseFunctionValuesOptions) => TransformDeclarations;
|
|
35
|
+
static legacyDeclarations: (values?: NormaliseLegacyFunctionValuesOptions) => TransformDeclarations;
|
|
36
|
+
utilities: () => void;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type CSSUtility } from '@/css-utilities';
|
|
2
|
+
import { Base } from '@/css-utilities/base';
|
|
3
|
+
import { type UnsafeCSSValue } from '@/utils/css-value';
|
|
4
|
+
import { type Dimension } from '@/utils/dimension';
|
|
5
|
+
interface NormaliseFunctionValuesOptions {
|
|
6
|
+
dimension?: Dimension;
|
|
7
|
+
translateX?: UnsafeCSSValue;
|
|
8
|
+
translateY?: UnsafeCSSValue;
|
|
9
|
+
translateZ?: UnsafeCSSValue;
|
|
10
|
+
}
|
|
11
|
+
interface TranslateDeclarations {
|
|
12
|
+
translate: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class Translate extends Base implements CSSUtility {
|
|
15
|
+
private isProcessableValue;
|
|
16
|
+
private isProcessableValues;
|
|
17
|
+
private normaliseValues;
|
|
18
|
+
static defaultFunctionValues: Required<Omit<NormaliseFunctionValuesOptions, 'dimension'>>;
|
|
19
|
+
static normaliseFunctionValues: ({ dimension, translateX, translateY, translateZ, }?: NormaliseFunctionValuesOptions) => string;
|
|
20
|
+
static declarations: (values?: NormaliseFunctionValuesOptions) => TranslateDeclarations;
|
|
21
|
+
static legacyDeclarations: () => import("@/css-utilities").TransformDeclarations;
|
|
22
|
+
utilities: () => void;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface PluginOptions {
|
|
2
|
+
legacy?: boolean;
|
|
3
|
+
}
|
|
4
|
+
declare const tailwindCss3d: {
|
|
5
|
+
(options: PluginOptions): {
|
|
6
|
+
handler: import("tailwindcss/types/config").PluginCreator;
|
|
7
|
+
config?: Partial<import("tailwindcss/types/config").Config>;
|
|
8
|
+
};
|
|
9
|
+
__isOptionsFunction: true;
|
|
10
|
+
};
|
|
11
|
+
export = tailwindCss3d;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare const VALID_LENGTH_UNITS: string[];
|
|
2
|
+
export declare const VALID_ANGLE_UNITS: string[];
|
|
3
|
+
export declare const VALID_TIME_UNITS: string[];
|
|
4
|
+
export type UnsafeCSSValue = string | number | undefined;
|
|
5
|
+
export declare const toStringValue: (value: UnsafeCSSValue) => string | undefined;
|
|
6
|
+
export declare const toNumericValue: (value: UnsafeCSSValue) => number | undefined;
|
|
7
|
+
interface NumericValueAndUnit {
|
|
8
|
+
value: number | undefined;
|
|
9
|
+
unit: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare const toNumericValueAndUnit: (value: UnsafeCSSValue, validUnits?: string | string[]) => NumericValueAndUnit;
|
|
12
|
+
type NormaliseUnionValueFunction = (value: UnsafeCSSValue, defaultValue?: UnsafeCSSValue, allowedValues?: string | string[]) => string | undefined;
|
|
13
|
+
export declare const normaliseUnionValue: NormaliseUnionValueFunction;
|
|
14
|
+
interface Limit {
|
|
15
|
+
limit: number;
|
|
16
|
+
inclusive?: boolean;
|
|
17
|
+
adjustBy?: number;
|
|
18
|
+
}
|
|
19
|
+
interface NormaliseUnitValueOptions {
|
|
20
|
+
defaultNil?: '0' | 'none' | '';
|
|
21
|
+
allowNone?: boolean;
|
|
22
|
+
allowVar?: boolean;
|
|
23
|
+
allowCalc?: boolean;
|
|
24
|
+
defaultUnit?: string;
|
|
25
|
+
validUnits?: string[];
|
|
26
|
+
disallowValues?: number | number[];
|
|
27
|
+
allowDecimal?: boolean;
|
|
28
|
+
upperLimit?: number | Limit;
|
|
29
|
+
lowerLimit?: number | Limit;
|
|
30
|
+
}
|
|
31
|
+
type NormaliseUnitValueFunction = (value: UnsafeCSSValue, defaultValue?: UnsafeCSSValue, options?: NormaliseUnitValueOptions) => string;
|
|
32
|
+
export declare const normaliseUnitValue: NormaliseUnitValueFunction;
|
|
33
|
+
interface NormaliseAlphaValueOptions {
|
|
34
|
+
percentage?: NormaliseUnitValueOptions;
|
|
35
|
+
number?: NormaliseUnitValueOptions;
|
|
36
|
+
}
|
|
37
|
+
type NormaliseAlphaValueFunction = (value: UnsafeCSSValue, defaultValue?: UnsafeCSSValue, options?: NormaliseAlphaValueOptions) => string | undefined;
|
|
38
|
+
export declare const normaliseAlphaValue: NormaliseAlphaValueFunction;
|
|
39
|
+
export declare const normaliseAngleValue: NormaliseUnitValueFunction;
|
|
40
|
+
export declare const normaliseAnglePercentageValue: NormaliseUnitValueFunction;
|
|
41
|
+
export declare const normaliseLengthValue: NormaliseUnitValueFunction;
|
|
42
|
+
export declare const normaliseLengthPercentageValue: NormaliseUnitValueFunction;
|
|
43
|
+
export declare const normaliseNumberValue: NormaliseUnitValueFunction;
|
|
44
|
+
export declare const normaliseNumberPercentageValue: NormaliseUnitValueFunction;
|
|
45
|
+
export declare const normalisePercentageValue: NormaliseUnitValueFunction;
|
|
46
|
+
export declare const normaliseTimeValue: NormaliseUnitValueFunction;
|
|
47
|
+
export declare const normaliseTimePercentageValue: NormaliseUnitValueFunction;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type Primitives = string | number | bigint | boolean | symbol | undefined | object | ((...args: any[]) => any);
|
|
2
|
+
type PrimitiveStrings = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function';
|
|
3
|
+
export declare const ensure: <T extends Primitives>(type: PrimitiveStrings | PrimitiveStrings[], maybe: any, fallback: T) => T;
|
|
4
|
+
export declare const ensureBoolean: (maybe: any, fallback: boolean) => boolean;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type GuardTest = (arg: any) => boolean;
|
|
2
|
+
type GuardTests = GuardTest | GuardTest[];
|
|
3
|
+
type GuardTestGroups = GuardTests[];
|
|
4
|
+
export declare const generateGuard: <T>(...testGroups: GuardTestGroups) => (maybe?: unknown) => maybe is T;
|
|
5
|
+
export declare const isGuardTest: (maybe?: unknown) => maybe is GuardTest;
|
|
6
|
+
export declare const isGuardTests: (maybe?: unknown) => maybe is GuardTests;
|
|
7
|
+
export declare const isGuardTestGroups: (maybe?: unknown) => maybe is GuardTests;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type RecordAny = Record<string, any>;
|
|
2
|
+
export declare const axesModifier: <T extends RecordAny>(axes?: string | string[], silentModifier?: string) => (result: T, value: any, modifier: string) => void;
|
|
3
|
+
export declare const nameModifier: <T extends RecordAny>(name?: string, silentModifier?: string) => (result: T, value: any, modifier: string) => void;
|
|
4
|
+
export declare const signModifier: <T extends RecordAny>(signs?: string | string[]) => (result: T, value: any, modifier: string) => void;
|
|
5
|
+
export declare const addDurationWithGravity: <T extends RecordAny>() => (result: T, value: any, modifier: string) => void;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get VALID_ANGLE_UNITS () {
|
|
13
|
+
return VALID_ANGLE_UNITS;
|
|
14
|
+
},
|
|
15
|
+
get VALID_LENGTH_UNITS () {
|
|
16
|
+
return VALID_LENGTH_UNITS;
|
|
17
|
+
},
|
|
18
|
+
get VALID_TIME_UNITS () {
|
|
19
|
+
return VALID_TIME_UNITS;
|
|
20
|
+
},
|
|
21
|
+
get normaliseAlphaValue () {
|
|
22
|
+
return normaliseAlphaValue;
|
|
23
|
+
},
|
|
24
|
+
get normaliseAnglePercentageValue () {
|
|
25
|
+
return normaliseAnglePercentageValue;
|
|
26
|
+
},
|
|
27
|
+
get normaliseAngleValue () {
|
|
28
|
+
return normaliseAngleValue;
|
|
29
|
+
},
|
|
30
|
+
get normaliseLengthPercentageValue () {
|
|
31
|
+
return normaliseLengthPercentageValue;
|
|
32
|
+
},
|
|
33
|
+
get normaliseLengthValue () {
|
|
34
|
+
return normaliseLengthValue;
|
|
35
|
+
},
|
|
36
|
+
get normaliseNumberPercentageValue () {
|
|
37
|
+
return normaliseNumberPercentageValue;
|
|
38
|
+
},
|
|
39
|
+
get normaliseNumberValue () {
|
|
40
|
+
return normaliseNumberValue;
|
|
41
|
+
},
|
|
42
|
+
get normalisePercentageValue () {
|
|
43
|
+
return normalisePercentageValue;
|
|
44
|
+
},
|
|
45
|
+
get normaliseTimePercentageValue () {
|
|
46
|
+
return normaliseTimePercentageValue;
|
|
47
|
+
},
|
|
48
|
+
get normaliseTimeValue () {
|
|
49
|
+
return normaliseTimeValue;
|
|
50
|
+
},
|
|
51
|
+
get normaliseUnionValue () {
|
|
52
|
+
return normaliseUnionValue;
|
|
53
|
+
},
|
|
54
|
+
get normaliseUnitValue () {
|
|
55
|
+
return normaliseUnitValue;
|
|
56
|
+
},
|
|
57
|
+
get toNumericValue () {
|
|
58
|
+
return toNumericValue;
|
|
59
|
+
},
|
|
60
|
+
get toNumericValueAndUnit () {
|
|
61
|
+
return toNumericValueAndUnit;
|
|
62
|
+
},
|
|
63
|
+
get toStringValue () {
|
|
64
|
+
return toStringValue;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
var _object_spread = require("@swc/helpers/_/_object_spread");
|
|
68
|
+
var _to_consumable_array = require("@swc/helpers/_/_to_consumable_array");
|
|
69
|
+
var _lodash = require("lodash");
|
|
70
|
+
var _generateguard = require("./generate-guard");
|
|
71
|
+
var VALID_LENGTH_UNITS = [
|
|
72
|
+
'ch',
|
|
73
|
+
'em',
|
|
74
|
+
'ex',
|
|
75
|
+
'ic',
|
|
76
|
+
'rem',
|
|
77
|
+
'vh',
|
|
78
|
+
'vw',
|
|
79
|
+
'vmax',
|
|
80
|
+
'vmin',
|
|
81
|
+
'vb',
|
|
82
|
+
'vi',
|
|
83
|
+
'cqw',
|
|
84
|
+
'cqh',
|
|
85
|
+
'cqi',
|
|
86
|
+
'cqb',
|
|
87
|
+
'cqmin',
|
|
88
|
+
'cqmax',
|
|
89
|
+
'px',
|
|
90
|
+
'cm',
|
|
91
|
+
'mm',
|
|
92
|
+
'Q',
|
|
93
|
+
'in',
|
|
94
|
+
'pc',
|
|
95
|
+
'pt'
|
|
96
|
+
];
|
|
97
|
+
var VALID_ANGLE_UNITS = [
|
|
98
|
+
'deg',
|
|
99
|
+
'grad',
|
|
100
|
+
'rad',
|
|
101
|
+
'turn'
|
|
102
|
+
];
|
|
103
|
+
var VALID_TIME_UNITS = [
|
|
104
|
+
's',
|
|
105
|
+
'ms'
|
|
106
|
+
];
|
|
107
|
+
var toStringValue = function(value) {
|
|
108
|
+
if ((0, _lodash.isString)(value)) {
|
|
109
|
+
return value.trim();
|
|
110
|
+
}
|
|
111
|
+
if ((0, _lodash.isFinite)(value)) {
|
|
112
|
+
return String(value);
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
};
|
|
116
|
+
var toNumericValue = function(value) {
|
|
117
|
+
if ((0, _lodash.isFinite)(value)) {
|
|
118
|
+
return Number(value);
|
|
119
|
+
}
|
|
120
|
+
if ((0, _lodash.isString)(value)) {
|
|
121
|
+
var trimmed = value.trim();
|
|
122
|
+
if (trimmed === '') {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
var maybeNumber = Number(trimmed);
|
|
126
|
+
if (isNaN(maybeNumber)) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
return maybeNumber;
|
|
130
|
+
}
|
|
131
|
+
return undefined;
|
|
132
|
+
};
|
|
133
|
+
var toNumericValueAndUnit = function(value, validUnits) {
|
|
134
|
+
var stringValue = toStringValue(value);
|
|
135
|
+
var evaluated = {
|
|
136
|
+
value: undefined,
|
|
137
|
+
unit: undefined
|
|
138
|
+
};
|
|
139
|
+
if ((0, _lodash.isUndefined)(stringValue)) {
|
|
140
|
+
return evaluated;
|
|
141
|
+
}
|
|
142
|
+
if (stringValue === '') {
|
|
143
|
+
return evaluated;
|
|
144
|
+
}
|
|
145
|
+
var strippedStringValue = stringValue.replace(/\s/g, '');
|
|
146
|
+
var safeValidUnits = (0, _lodash.chain)(validUnits).castArray().uniq().filter((0, _generateguard.generateGuard)([
|
|
147
|
+
_lodash.isString,
|
|
148
|
+
function(maybe) {
|
|
149
|
+
return maybe !== '';
|
|
150
|
+
}
|
|
151
|
+
])).value();
|
|
152
|
+
if (safeValidUnits.length > 0) {
|
|
153
|
+
var unitsUnion = safeValidUnits.join('|');
|
|
154
|
+
var unitsMatch = strippedStringValue.match(new RegExp("(?:".concat(unitsUnion, ")$")));
|
|
155
|
+
if ((0, _lodash.isArray)(unitsMatch) && unitsMatch.length === 1) {
|
|
156
|
+
evaluated.unit = unitsMatch[0];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Simple numbers without units
|
|
160
|
+
var numberValue = toNumericValue(strippedStringValue);
|
|
161
|
+
if ((0, _lodash.isNumber)(numberValue)) {
|
|
162
|
+
evaluated.value = numberValue;
|
|
163
|
+
return evaluated;
|
|
164
|
+
}
|
|
165
|
+
var unitlessStringValue = (0, _lodash.isString)(evaluated.unit) ? strippedStringValue.replace(new RegExp("".concat(evaluated.unit, "$")), '') : strippedStringValue;
|
|
166
|
+
var unitlessNumberValue = toNumericValue(unitlessStringValue);
|
|
167
|
+
if ((0, _lodash.isNumber)(unitlessNumberValue)) {
|
|
168
|
+
evaluated.value = unitlessNumberValue;
|
|
169
|
+
return evaluated;
|
|
170
|
+
}
|
|
171
|
+
var rescueStringValue = unitlessStringValue.replace(/[^\d.-]/g, '').replace(/\b-/g, '');
|
|
172
|
+
var rescueNumberValue = toNumericValue(rescueStringValue);
|
|
173
|
+
if ((0, _lodash.isNumber)(rescueNumberValue)) {
|
|
174
|
+
evaluated.value = rescueNumberValue;
|
|
175
|
+
return evaluated;
|
|
176
|
+
}
|
|
177
|
+
return evaluated;
|
|
178
|
+
};
|
|
179
|
+
var normaliseUnionValue = function(value, defaultValue, allowedValues) {
|
|
180
|
+
var safeValue = toStringValue(value);
|
|
181
|
+
var safeDefaultValue = toStringValue(defaultValue);
|
|
182
|
+
if ((0, _lodash.isUndefined)(safeValue)) {
|
|
183
|
+
return safeDefaultValue;
|
|
184
|
+
}
|
|
185
|
+
var safeAllowedValues = (0, _lodash.chain)(defaultValue).castArray().concat(allowedValues !== null && allowedValues !== void 0 ? allowedValues : []).uniq().filter(_lodash.isString).map(_lodash.trim).value();
|
|
186
|
+
var matchedIndex = (0, _lodash.chain)(safeAllowedValues).map(_lodash.toLower).indexOf((0, _lodash.toLower)(safeValue)).value();
|
|
187
|
+
if (matchedIndex !== -1) {
|
|
188
|
+
return safeAllowedValues[matchedIndex];
|
|
189
|
+
}
|
|
190
|
+
return safeDefaultValue;
|
|
191
|
+
};
|
|
192
|
+
var isLimit = (0, _generateguard.generateGuard)([
|
|
193
|
+
_lodash.isPlainObject,
|
|
194
|
+
function(maybe) {
|
|
195
|
+
return (0, _lodash.isNumber)((0, _lodash.get)(maybe, 'limit'));
|
|
196
|
+
},
|
|
197
|
+
function(maybe) {
|
|
198
|
+
return (0, _lodash.has)(maybe, 'inclusive') ? (0, _lodash.isBoolean)((0, _lodash.get)(maybe, 'inclusive')) : true;
|
|
199
|
+
},
|
|
200
|
+
function(maybe) {
|
|
201
|
+
return (0, _lodash.has)(maybe, 'adjustBy') ? (0, _lodash.isNumber)((0, _lodash.get)(maybe, 'adjustBy')) : true;
|
|
202
|
+
}
|
|
203
|
+
]);
|
|
204
|
+
// Not a type guard
|
|
205
|
+
var isVar = function(maybe) {
|
|
206
|
+
return /^var\(\s*--[a-zA-Z0-9-]+\s*(,\s*.+)?\s*\)$/.test(maybe);
|
|
207
|
+
};
|
|
208
|
+
// Not a type guard
|
|
209
|
+
var isCalc = function(maybe) {
|
|
210
|
+
return /^calc\(\s*(?:var\(\s*--[a-zA-Z0-9-]+\s*(,\s*.+)?\s*\)|[0-9]+[a-zA-Z%]*)\s+[*/+-]\s+(?:var\(\s*--[a-zA-Z0-9-]+\s*(,\s*.+)?\s*\)|[0-9]+[a-zA-Z%]*)\s*\)$/.test(maybe);
|
|
211
|
+
};
|
|
212
|
+
var normaliseUnitValue = function(value, defaultValue, options) {
|
|
213
|
+
var safeValue = toStringValue(value);
|
|
214
|
+
var safeDefaultValue = toStringValue(defaultValue);
|
|
215
|
+
var _ref = (0, _lodash.isObject)(options) && (0, _lodash.isPlainObject)(options) ? options : {}, defaultNil = _ref.defaultNil, allowNone = _ref.allowNone, allowVar = _ref.allowVar, allowCalc = _ref.allowCalc, defaultUnit = _ref.defaultUnit, validUnits = _ref.validUnits, disallowValues = _ref.disallowValues, allowDecimal = _ref.allowDecimal, upperLimit = _ref.upperLimit, lowerLimit = _ref.lowerLimit;
|
|
216
|
+
var safeDefaultNil = (0, _lodash.isString)(defaultNil) && (0, _lodash.includes)([
|
|
217
|
+
'0',
|
|
218
|
+
'none',
|
|
219
|
+
''
|
|
220
|
+
], defaultNil) ? defaultNil : '0';
|
|
221
|
+
if ((0, _lodash.isUndefined)(safeValue)) {
|
|
222
|
+
return safeDefaultValue !== null && safeDefaultValue !== void 0 ? safeDefaultValue : safeDefaultNil;
|
|
223
|
+
}
|
|
224
|
+
var safeAllowNone = (0, _lodash.isBoolean)(allowNone) ? allowNone : true;
|
|
225
|
+
if (safeAllowNone && safeValue.toLowerCase() === 'none') {
|
|
226
|
+
return 'none';
|
|
227
|
+
}
|
|
228
|
+
var safeAllowVar = (0, _lodash.isBoolean)(allowVar) ? allowVar : true;
|
|
229
|
+
// Return a var() if that is allowed - fairly coarse validation
|
|
230
|
+
if (safeValue.startsWith('var(')) {
|
|
231
|
+
return safeAllowVar && isVar(safeValue) ? safeValue : safeDefaultValue !== null && safeDefaultValue !== void 0 ? safeDefaultValue : safeDefaultNil;
|
|
232
|
+
}
|
|
233
|
+
var safeAllowCalc = (0, _lodash.isBoolean)(allowCalc) ? allowCalc : false;
|
|
234
|
+
// Return a calc() if that is allowed - fairly coarse validation
|
|
235
|
+
if (safeValue.startsWith('calc(')) {
|
|
236
|
+
return safeAllowCalc && isCalc(safeValue) ? safeValue : safeDefaultValue !== null && safeDefaultValue !== void 0 ? safeDefaultValue : safeDefaultNil;
|
|
237
|
+
}
|
|
238
|
+
var _toStringValue;
|
|
239
|
+
var safeDefaultUnit = (_toStringValue = toStringValue(defaultUnit)) !== null && _toStringValue !== void 0 ? _toStringValue : '';
|
|
240
|
+
var safeValidUnits = (0, _lodash.chain)(safeDefaultUnit).castArray().concat(validUnits !== null && validUnits !== void 0 ? validUnits : []).filter(_lodash.isString).value();
|
|
241
|
+
// Get the number value and unit from the string
|
|
242
|
+
var _toNumericValueAndUnit = toNumericValueAndUnit(safeValue, safeValidUnits), safeNumberValue = _toNumericValueAndUnit.value, unit = _toNumericValueAndUnit.unit;
|
|
243
|
+
var _ref1;
|
|
244
|
+
var safeUnit = (_ref1 = unit !== null && unit !== void 0 ? unit : defaultUnit) !== null && _ref1 !== void 0 ? _ref1 : '';
|
|
245
|
+
// From here on we are dealing with number values
|
|
246
|
+
if (!(0, _lodash.isNumber)(safeNumberValue)) {
|
|
247
|
+
return safeDefaultValue !== null && safeDefaultValue !== void 0 ? safeDefaultValue : safeDefaultNil;
|
|
248
|
+
}
|
|
249
|
+
var safeDisallowValues = (0, _lodash.chain)(disallowValues).castArray().filter(_lodash.isNumber).value();
|
|
250
|
+
var safeAllowDecimal = (0, _lodash.isBoolean)(allowDecimal) ? allowDecimal : true;
|
|
251
|
+
// Set up an integer value
|
|
252
|
+
var safeIntegerValue = Math.round(safeNumberValue);
|
|
253
|
+
// Check the value isn't disallowed
|
|
254
|
+
// - use integer value if decimals are not allowed
|
|
255
|
+
if ((0, _lodash.includes)(safeDisallowValues, safeAllowDecimal ? safeNumberValue : safeIntegerValue)) {
|
|
256
|
+
return safeDefaultValue !== null && safeDefaultValue !== void 0 ? safeDefaultValue : safeDefaultNil;
|
|
257
|
+
}
|
|
258
|
+
var evaluated = {
|
|
259
|
+
value: safeAllowDecimal ? safeNumberValue : safeIntegerValue,
|
|
260
|
+
unit: safeUnit
|
|
261
|
+
};
|
|
262
|
+
var safeUpperLimit = (0, _lodash.isNumber)(upperLimit) ? {
|
|
263
|
+
limit: upperLimit,
|
|
264
|
+
inclusive: true,
|
|
265
|
+
adjustBy: 1
|
|
266
|
+
} : isLimit(upperLimit) ? {
|
|
267
|
+
limit: upperLimit.limit,
|
|
268
|
+
inclusive: (0, _lodash.isBoolean)(upperLimit.inclusive) ? upperLimit.inclusive : true,
|
|
269
|
+
adjustBy: (0, _lodash.isNumber)(upperLimit.adjustBy) && upperLimit.adjustBy !== 0 ? upperLimit.adjustBy : 1
|
|
270
|
+
} : false;
|
|
271
|
+
// Set the evaluated value within the upper limit
|
|
272
|
+
if (safeUpperLimit) {
|
|
273
|
+
if (safeUpperLimit.inclusive) {
|
|
274
|
+
if (safeNumberValue > safeUpperLimit.limit) {
|
|
275
|
+
evaluated.value = safeUpperLimit.limit;
|
|
276
|
+
}
|
|
277
|
+
} else {
|
|
278
|
+
if (safeNumberValue >= safeUpperLimit.limit) {
|
|
279
|
+
evaluated.value = safeUpperLimit.limit - safeUpperLimit.adjustBy;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
var safeLowerLimit = (0, _lodash.isNumber)(lowerLimit) ? {
|
|
284
|
+
limit: lowerLimit,
|
|
285
|
+
inclusive: true,
|
|
286
|
+
adjustBy: 1
|
|
287
|
+
} : isLimit(lowerLimit) ? {
|
|
288
|
+
limit: lowerLimit.limit,
|
|
289
|
+
inclusive: (0, _lodash.isBoolean)(lowerLimit.inclusive) ? lowerLimit.inclusive : true,
|
|
290
|
+
adjustBy: (0, _lodash.isNumber)(lowerLimit.adjustBy) && lowerLimit.adjustBy !== 0 ? lowerLimit.adjustBy : 1
|
|
291
|
+
} : false;
|
|
292
|
+
// Set the evaluated value within the lower limit
|
|
293
|
+
if (safeLowerLimit) {
|
|
294
|
+
if (safeLowerLimit.inclusive) {
|
|
295
|
+
if (safeNumberValue < safeLowerLimit.limit) {
|
|
296
|
+
evaluated.value = safeLowerLimit.limit;
|
|
297
|
+
}
|
|
298
|
+
} else {
|
|
299
|
+
if (safeNumberValue <= safeLowerLimit.limit) {
|
|
300
|
+
evaluated.value = safeLowerLimit.limit + safeLowerLimit.adjustBy;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (evaluated.value === 0 && defaultNil) {
|
|
305
|
+
return defaultNil;
|
|
306
|
+
}
|
|
307
|
+
return "".concat(String(evaluated.value)).concat(evaluated.unit);
|
|
308
|
+
};
|
|
309
|
+
var normaliseAlphaValue = function(value, defaultValue, options) {
|
|
310
|
+
var safeValue = toStringValue(value);
|
|
311
|
+
var safeDefaultValue = toStringValue(defaultValue);
|
|
312
|
+
if ((0, _lodash.isUndefined)(safeValue)) {
|
|
313
|
+
return safeDefaultValue;
|
|
314
|
+
}
|
|
315
|
+
if (safeValue.indexOf('%') !== -1) {
|
|
316
|
+
return normalisePercentageValue(value, defaultValue, _object_spread._({
|
|
317
|
+
lowerLimit: 0,
|
|
318
|
+
upperLimit: 100
|
|
319
|
+
}, options === null || options === void 0 ? void 0 : options.percentage));
|
|
320
|
+
}
|
|
321
|
+
return normaliseNumberValue(value, defaultValue, _object_spread._({
|
|
322
|
+
lowerLimit: 0,
|
|
323
|
+
upperLimit: 1
|
|
324
|
+
}, options === null || options === void 0 ? void 0 : options.number));
|
|
325
|
+
};
|
|
326
|
+
var normaliseAngleValue = function(value, defaultValue, options) {
|
|
327
|
+
return normaliseUnitValue(value, defaultValue, _object_spread._({
|
|
328
|
+
defaultUnit: 'deg',
|
|
329
|
+
validUnits: VALID_ANGLE_UNITS
|
|
330
|
+
}, options));
|
|
331
|
+
};
|
|
332
|
+
var normaliseAnglePercentageValue = function(value, defaultValue, options) {
|
|
333
|
+
return normaliseUnitValue(value, defaultValue, _object_spread._({
|
|
334
|
+
defaultUnit: 'deg',
|
|
335
|
+
validUnits: _to_consumable_array._(VALID_ANGLE_UNITS).concat([
|
|
336
|
+
'%'
|
|
337
|
+
])
|
|
338
|
+
}, options));
|
|
339
|
+
};
|
|
340
|
+
var normaliseLengthValue = function(value, defaultValue, options) {
|
|
341
|
+
return normaliseUnitValue(value, defaultValue, _object_spread._({
|
|
342
|
+
defaultUnit: 'px',
|
|
343
|
+
validUnits: VALID_LENGTH_UNITS
|
|
344
|
+
}, options));
|
|
345
|
+
};
|
|
346
|
+
var normaliseLengthPercentageValue = function(value, defaultValue, options) {
|
|
347
|
+
return normaliseUnitValue(value, defaultValue, _object_spread._({
|
|
348
|
+
defaultUnit: 'px',
|
|
349
|
+
validUnits: _to_consumable_array._(VALID_LENGTH_UNITS).concat([
|
|
350
|
+
'%'
|
|
351
|
+
])
|
|
352
|
+
}, options));
|
|
353
|
+
};
|
|
354
|
+
var normaliseNumberValue = function(value, defaultValue, options) {
|
|
355
|
+
return normaliseUnitValue(value, defaultValue, options);
|
|
356
|
+
};
|
|
357
|
+
var normaliseNumberPercentageValue = function(value, defaultValue, options) {
|
|
358
|
+
return normaliseUnitValue(value, defaultValue, _object_spread._({
|
|
359
|
+
validUnits: [
|
|
360
|
+
'',
|
|
361
|
+
'%'
|
|
362
|
+
]
|
|
363
|
+
}, options));
|
|
364
|
+
};
|
|
365
|
+
var normalisePercentageValue = function(value, defaultValue, options) {
|
|
366
|
+
return normaliseUnitValue(value, defaultValue, _object_spread._({
|
|
367
|
+
defaultUnit: '%',
|
|
368
|
+
validUnits: [
|
|
369
|
+
'%'
|
|
370
|
+
]
|
|
371
|
+
}, options));
|
|
372
|
+
};
|
|
373
|
+
var normaliseTimeValue = function(value, defaultValue, options) {
|
|
374
|
+
return normaliseUnitValue(value, defaultValue, _object_spread._({
|
|
375
|
+
defaultUnit: 's',
|
|
376
|
+
validUnits: VALID_TIME_UNITS
|
|
377
|
+
}, options));
|
|
378
|
+
};
|
|
379
|
+
var normaliseTimePercentageValue = function(value, defaultValue, options) {
|
|
380
|
+
return normaliseUnitValue(value, defaultValue, _object_spread._({
|
|
381
|
+
defaultUnit: 's',
|
|
382
|
+
validUnits: _to_consumable_array._(VALID_TIME_UNITS).concat([
|
|
383
|
+
'%'
|
|
384
|
+
])
|
|
385
|
+
}, options));
|
|
386
|
+
};
|