react-native-divkit 0.1.0-alpha.1
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.
- package/LICENSE +176 -0
- package/README.md +340 -0
- package/dist/DivKit.d.ts +68 -0
- package/dist/DivKit.d.ts.map +1 -0
- package/dist/DivKit.js +400 -0
- package/dist/DivKit.js.map +1 -0
- package/dist/actions/array.d.ts +8 -0
- package/dist/actions/array.d.ts.map +1 -0
- package/dist/actions/array.js +139 -0
- package/dist/actions/array.js.map +1 -0
- package/dist/actions/copyToClipboard.d.ts +22 -0
- package/dist/actions/copyToClipboard.d.ts.map +1 -0
- package/dist/actions/copyToClipboard.js +63 -0
- package/dist/actions/copyToClipboard.js.map +1 -0
- package/dist/actions/dict.d.ts +6 -0
- package/dist/actions/dict.d.ts.map +1 -0
- package/dist/actions/dict.js +58 -0
- package/dist/actions/dict.js.map +1 -0
- package/dist/actions/index.d.ts +11 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +11 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/updateStructure.d.ts +6 -0
- package/dist/actions/updateStructure.d.ts.map +1 -0
- package/dist/actions/updateStructure.js +116 -0
- package/dist/actions/updateStructure.js.map +1 -0
- package/dist/components/DivComponent.d.ts +29 -0
- package/dist/components/DivComponent.d.ts.map +1 -0
- package/dist/components/DivComponent.js +62 -0
- package/dist/components/DivComponent.js.map +1 -0
- package/dist/components/container/DivContainer.d.ts +26 -0
- package/dist/components/container/DivContainer.d.ts.map +1 -0
- package/dist/components/container/DivContainer.js +172 -0
- package/dist/components/container/DivContainer.js.map +1 -0
- package/dist/components/container/index.d.ts +3 -0
- package/dist/components/container/index.d.ts.map +1 -0
- package/dist/components/container/index.js +2 -0
- package/dist/components/container/index.js.map +1 -0
- package/dist/components/image/DivImage.d.ts +29 -0
- package/dist/components/image/DivImage.d.ts.map +1 -0
- package/dist/components/image/DivImage.js +122 -0
- package/dist/components/image/DivImage.js.map +1 -0
- package/dist/components/image/index.d.ts +3 -0
- package/dist/components/image/index.d.ts.map +1 -0
- package/dist/components/image/index.js +2 -0
- package/dist/components/image/index.js.map +1 -0
- package/dist/components/index.d.ts +14 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +11 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/state/DivState.d.ts +26 -0
- package/dist/components/state/DivState.d.ts.map +1 -0
- package/dist/components/state/DivState.js +121 -0
- package/dist/components/state/DivState.js.map +1 -0
- package/dist/components/state/index.d.ts +3 -0
- package/dist/components/state/index.d.ts.map +1 -0
- package/dist/components/state/index.js +2 -0
- package/dist/components/state/index.js.map +1 -0
- package/dist/components/text/DivText.d.ts +28 -0
- package/dist/components/text/DivText.d.ts.map +1 -0
- package/dist/components/text/DivText.js +143 -0
- package/dist/components/text/DivText.js.map +1 -0
- package/dist/components/text/index.d.ts +3 -0
- package/dist/components/text/index.d.ts.map +1 -0
- package/dist/components/text/index.js +2 -0
- package/dist/components/text/index.js.map +1 -0
- package/dist/components/utilities/Outer.d.ts +17 -0
- package/dist/components/utilities/Outer.d.ts.map +1 -0
- package/dist/components/utilities/Outer.js +210 -0
- package/dist/components/utilities/Outer.js.map +1 -0
- package/dist/components/utilities/Unknown.d.ts +11 -0
- package/dist/components/utilities/Unknown.d.ts.map +1 -0
- package/dist/components/utilities/Unknown.js +50 -0
- package/dist/components/utilities/Unknown.js.map +1 -0
- package/dist/components/utilities/index.d.ts +5 -0
- package/dist/components/utilities/index.d.ts.map +1 -0
- package/dist/components/utilities/index.js +3 -0
- package/dist/components/utilities/index.js.map +1 -0
- package/dist/context/ActionContext.d.ts +25 -0
- package/dist/context/ActionContext.d.ts.map +1 -0
- package/dist/context/ActionContext.js +20 -0
- package/dist/context/ActionContext.js.map +1 -0
- package/dist/context/DivKitContext.d.ts +33 -0
- package/dist/context/DivKitContext.d.ts.map +1 -0
- package/dist/context/DivKitContext.js +14 -0
- package/dist/context/DivKitContext.js.map +1 -0
- package/dist/context/EnabledContext.d.ts +31 -0
- package/dist/context/EnabledContext.d.ts.map +1 -0
- package/dist/context/EnabledContext.js +31 -0
- package/dist/context/EnabledContext.js.map +1 -0
- package/dist/context/StateContext.d.ts +57 -0
- package/dist/context/StateContext.d.ts.map +1 -0
- package/dist/context/StateContext.js +20 -0
- package/dist/context/StateContext.js.map +1 -0
- package/dist/context/index.d.ts +9 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +9 -0
- package/dist/context/index.js.map +1 -0
- package/dist/expressions/bigint.d.ts +8 -0
- package/dist/expressions/bigint.d.ts.map +1 -0
- package/dist/expressions/bigint.js +31 -0
- package/dist/expressions/bigint.js.map +1 -0
- package/dist/expressions/const.d.ts +15 -0
- package/dist/expressions/const.d.ts.map +1 -0
- package/dist/expressions/const.js +15 -0
- package/dist/expressions/const.js.map +1 -0
- package/dist/expressions/eval.d.ts +77 -0
- package/dist/expressions/eval.d.ts.map +1 -0
- package/dist/expressions/eval.js +459 -0
- package/dist/expressions/eval.js.map +1 -0
- package/dist/expressions/expressions.d.ts +7 -0
- package/dist/expressions/expressions.d.ts.map +1 -0
- package/dist/expressions/expressions.js +3191 -0
- package/dist/expressions/expressions.js.map +1 -0
- package/dist/expressions/funcs/array.d.ts +2 -0
- package/dist/expressions/funcs/array.d.ts.map +1 -0
- package/dist/expressions/funcs/array.js +381 -0
- package/dist/expressions/funcs/array.js.map +1 -0
- package/dist/expressions/funcs/colors.d.ts +2 -0
- package/dist/expressions/funcs/colors.d.ts.map +1 -0
- package/dist/expressions/funcs/colors.js +75 -0
- package/dist/expressions/funcs/colors.js.map +1 -0
- package/dist/expressions/funcs/customFuncs.d.ts +8 -0
- package/dist/expressions/funcs/customFuncs.d.ts.map +1 -0
- package/dist/expressions/funcs/customFuncs.js +114 -0
- package/dist/expressions/funcs/customFuncs.js.map +1 -0
- package/dist/expressions/funcs/datetime.d.ts +2 -0
- package/dist/expressions/funcs/datetime.d.ts.map +1 -0
- package/dist/expressions/funcs/datetime.js +182 -0
- package/dist/expressions/funcs/datetime.js.map +1 -0
- package/dist/expressions/funcs/dict.d.ts +2 -0
- package/dist/expressions/funcs/dict.d.ts.map +1 -0
- package/dist/expressions/funcs/dict.js +170 -0
- package/dist/expressions/funcs/dict.js.map +1 -0
- package/dist/expressions/funcs/funcs.d.ts +80 -0
- package/dist/expressions/funcs/funcs.d.ts.map +1 -0
- package/dist/expressions/funcs/funcs.js +146 -0
- package/dist/expressions/funcs/funcs.js.map +1 -0
- package/dist/expressions/funcs/index.d.ts +2 -0
- package/dist/expressions/funcs/index.d.ts.map +1 -0
- package/dist/expressions/funcs/index.js +23 -0
- package/dist/expressions/funcs/index.js.map +1 -0
- package/dist/expressions/funcs/interval.d.ts +2 -0
- package/dist/expressions/funcs/interval.d.ts.map +1 -0
- package/dist/expressions/funcs/interval.js +61 -0
- package/dist/expressions/funcs/interval.js.map +1 -0
- package/dist/expressions/funcs/math.d.ts +2 -0
- package/dist/expressions/funcs/math.d.ts.map +1 -0
- package/dist/expressions/funcs/math.js +324 -0
- package/dist/expressions/funcs/math.js.map +1 -0
- package/dist/expressions/funcs/std.d.ts +2 -0
- package/dist/expressions/funcs/std.d.ts.map +1 -0
- package/dist/expressions/funcs/std.js +293 -0
- package/dist/expressions/funcs/std.js.map +1 -0
- package/dist/expressions/funcs/stored.d.ts +4 -0
- package/dist/expressions/funcs/stored.d.ts.map +1 -0
- package/dist/expressions/funcs/stored.js +62 -0
- package/dist/expressions/funcs/stored.js.map +1 -0
- package/dist/expressions/funcs/strings.d.ts +2 -0
- package/dist/expressions/funcs/strings.d.ts.map +1 -0
- package/dist/expressions/funcs/strings.js +158 -0
- package/dist/expressions/funcs/strings.js.map +1 -0
- package/dist/expressions/funcs/trigonometry.d.ts +2 -0
- package/dist/expressions/funcs/trigonometry.d.ts.map +1 -0
- package/dist/expressions/funcs/trigonometry.js +92 -0
- package/dist/expressions/funcs/trigonometry.js.map +1 -0
- package/dist/expressions/json.d.ts +18 -0
- package/dist/expressions/json.d.ts.map +1 -0
- package/dist/expressions/json.js +271 -0
- package/dist/expressions/json.js.map +1 -0
- package/dist/expressions/parserCache.d.ts +4 -0
- package/dist/expressions/parserCache.d.ts.map +1 -0
- package/dist/expressions/parserCache.js +23 -0
- package/dist/expressions/parserCache.js.map +1 -0
- package/dist/expressions/simpleUnescapeString.d.ts +2 -0
- package/dist/expressions/simpleUnescapeString.d.ts.map +1 -0
- package/dist/expressions/simpleUnescapeString.js +61 -0
- package/dist/expressions/simpleUnescapeString.js.map +1 -0
- package/dist/expressions/utils.d.ts +29 -0
- package/dist/expressions/utils.d.ts.map +1 -0
- package/dist/expressions/utils.js +236 -0
- package/dist/expressions/utils.js.map +1 -0
- package/dist/expressions/variable.d.ts +82 -0
- package/dist/expressions/variable.d.ts.map +1 -0
- package/dist/expressions/variable.js +337 -0
- package/dist/expressions/variable.js.map +1 -0
- package/dist/expressions/walk.d.ts +7 -0
- package/dist/expressions/walk.d.ts.map +1 -0
- package/dist/expressions/walk.js +39 -0
- package/dist/expressions/walk.js.map +1 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +11 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useAction.d.ts +102 -0
- package/dist/hooks/useAction.d.ts.map +1 -0
- package/dist/hooks/useAction.js +116 -0
- package/dist/hooks/useAction.js.map +1 -0
- package/dist/hooks/useDerivedFromVars.d.ts +72 -0
- package/dist/hooks/useDerivedFromVars.d.ts.map +1 -0
- package/dist/hooks/useDerivedFromVars.js +100 -0
- package/dist/hooks/useDerivedFromVars.js.map +1 -0
- package/dist/hooks/useVariable.d.ts +86 -0
- package/dist/hooks/useVariable.d.ts.map +1 -0
- package/dist/hooks/useVariable.js +130 -0
- package/dist/hooks/useVariable.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/stores/createObservable.d.ts +38 -0
- package/dist/stores/createObservable.d.ts.map +1 -0
- package/dist/stores/createObservable.js +49 -0
- package/dist/stores/createObservable.js.map +1 -0
- package/dist/utils/applyTemplate.d.ts +8 -0
- package/dist/utils/applyTemplate.d.ts.map +1 -0
- package/dist/utils/applyTemplate.js +94 -0
- package/dist/utils/applyTemplate.js.map +1 -0
- package/dist/utils/correctColor.d.ts +18 -0
- package/dist/utils/correctColor.d.ts.map +1 -0
- package/dist/utils/correctColor.js +79 -0
- package/dist/utils/correctColor.js.map +1 -0
- package/dist/utils/escapeRegExp.d.ts +2 -0
- package/dist/utils/escapeRegExp.d.ts.map +1 -0
- package/dist/utils/escapeRegExp.js +4 -0
- package/dist/utils/escapeRegExp.js.map +1 -0
- package/dist/utils/formatDate.d.ts +6 -0
- package/dist/utils/formatDate.d.ts.map +1 -0
- package/dist/utils/formatDate.js +325 -0
- package/dist/utils/formatDate.js.map +1 -0
- package/dist/utils/padLeft.d.ts +2 -0
- package/dist/utils/padLeft.d.ts.map +1 -0
- package/dist/utils/padLeft.js +7 -0
- package/dist/utils/padLeft.js.map +1 -0
- package/dist/utils/uniq.d.ts +2 -0
- package/dist/utils/uniq.d.ts.map +1 -0
- package/dist/utils/uniq.js +4 -0
- package/dist/utils/uniq.js.map +1 -0
- package/dist/utils/wrapError.d.ts +10 -0
- package/dist/utils/wrapError.d.ts.map +1 -0
- package/dist/utils/wrapError.js +9 -0
- package/dist/utils/wrapError.js.map +1 -0
- package/package.json +58 -0
- package/src/DivKit.tsx +542 -0
- package/src/actions/array.ts +170 -0
- package/src/actions/copyToClipboard.ts +82 -0
- package/src/actions/dict.ts +71 -0
- package/src/actions/index.ts +11 -0
- package/src/actions/updateStructure.ts +134 -0
- package/src/components/DivComponent.tsx +75 -0
- package/src/components/README.md +230 -0
- package/src/components/container/DivContainer.tsx +222 -0
- package/src/components/container/index.ts +2 -0
- package/src/components/image/DivImage.tsx +172 -0
- package/src/components/image/index.ts +2 -0
- package/src/components/index.ts +20 -0
- package/src/components/state/DivState.tsx +146 -0
- package/src/components/state/index.ts +2 -0
- package/src/components/text/DivText.tsx +186 -0
- package/src/components/text/index.ts +2 -0
- package/src/components/utilities/Outer.tsx +239 -0
- package/src/components/utilities/README.md +175 -0
- package/src/components/utilities/Unknown.tsx +60 -0
- package/src/components/utilities/index.ts +4 -0
- package/src/context/ActionContext.tsx +37 -0
- package/src/context/DivKitContext.tsx +54 -0
- package/src/context/EnabledContext.tsx +50 -0
- package/src/context/StateContext.tsx +75 -0
- package/src/context/index.ts +33 -0
- package/src/expressions/ast.d.ts +101 -0
- package/src/expressions/bigint.ts +38 -0
- package/src/expressions/const.ts +16 -0
- package/src/expressions/eval.ts +669 -0
- package/src/expressions/expressions.peggy +235 -0
- package/src/expressions/expressions.ts +2854 -0
- package/src/expressions/funcs/array.ts +412 -0
- package/src/expressions/funcs/colors.ts +100 -0
- package/src/expressions/funcs/customFuncs.ts +139 -0
- package/src/expressions/funcs/datetime.ts +232 -0
- package/src/expressions/funcs/dict.ts +207 -0
- package/src/expressions/funcs/funcs.ts +323 -0
- package/src/expressions/funcs/index.ts +23 -0
- package/src/expressions/funcs/interval.ts +76 -0
- package/src/expressions/funcs/math.ts +395 -0
- package/src/expressions/funcs/std.ts +392 -0
- package/src/expressions/funcs/stored.ts +62 -0
- package/src/expressions/funcs/strings.ts +200 -0
- package/src/expressions/funcs/trigonometry.ts +108 -0
- package/src/expressions/json.ts +367 -0
- package/src/expressions/parserCache.ts +32 -0
- package/src/expressions/simpleUnescapeString.ts +57 -0
- package/src/expressions/utils.ts +271 -0
- package/src/expressions/variable.ts +429 -0
- package/src/expressions/walk.ts +43 -0
- package/src/hooks/README.md +265 -0
- package/src/hooks/index.ts +28 -0
- package/src/hooks/useAction.ts +152 -0
- package/src/hooks/useDerivedFromVars.ts +187 -0
- package/src/hooks/useVariable.ts +157 -0
- package/src/index.ts +97 -0
- package/src/stores/createObservable.ts +64 -0
- package/src/types/alignment.d.ts +13 -0
- package/src/types/background.d.ts +71 -0
- package/src/types/base.d.ts +224 -0
- package/src/types/border.d.ts +46 -0
- package/src/types/componentContext.d.ts +98 -0
- package/src/types/container.d.ts +40 -0
- package/src/types/edgeInserts.d.ts +9 -0
- package/src/types/general.d.ts +3 -0
- package/src/types/image.d.ts +33 -0
- package/src/types/imageScale.d.ts +1 -0
- package/src/types/layoutParams.d.ts +27 -0
- package/src/types/sizes.d.ts +37 -0
- package/src/types/state.d.ts +19 -0
- package/src/types/text.d.ts +126 -0
- package/src/utils/applyTemplate.ts +145 -0
- package/src/utils/correctColor.ts +102 -0
- package/src/utils/escapeRegExp.ts +3 -0
- package/src/utils/formatDate.ts +385 -0
- package/src/utils/padLeft.ts +6 -0
- package/src/utils/uniq.ts +3 -0
- package/src/utils/wrapError.ts +21 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Action, TemplateContext } from '../../typings/common';
|
|
2
|
+
import type { MaybeMissing } from '../expressions/json';
|
|
3
|
+
import type { Variable, VariableType } from '../expressions/variable';
|
|
4
|
+
import type { WrappedError } from '../utils/wrapError';
|
|
5
|
+
import type { Animator, DivBaseData } from './base';
|
|
6
|
+
import type { Store } from '../../typings/store';
|
|
7
|
+
import type { evalExpression } from '../expressions/eval';
|
|
8
|
+
import type { Node } from '../expressions/ast';
|
|
9
|
+
import type { CustomFunctions } from '../expressions/funcs/customFuncs';
|
|
10
|
+
|
|
11
|
+
interface Readable<T> {
|
|
12
|
+
subscribe(run: (value: T) => void): () => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type StateSetter = (stateId: string) => Promise<ComponentContext | undefined>;
|
|
16
|
+
|
|
17
|
+
export interface PagerData {
|
|
18
|
+
instId: string;
|
|
19
|
+
size: number;
|
|
20
|
+
currentItem: number;
|
|
21
|
+
scrollToPagerItem(index: number): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type PagerListener = (data: PagerData) => void;
|
|
25
|
+
|
|
26
|
+
export interface PagerRegisterData {
|
|
27
|
+
update: PagerListener;
|
|
28
|
+
destroy: () => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type ComponentKey = string | {
|
|
32
|
+
index: number;
|
|
33
|
+
data: object;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export interface ComponentContext<T extends DivBaseData = DivBaseData> {
|
|
37
|
+
path: string[];
|
|
38
|
+
parent?: ComponentContext;
|
|
39
|
+
|
|
40
|
+
json: MaybeMissing<T>;
|
|
41
|
+
origJson?: MaybeMissing<DivBaseData> | undefined;
|
|
42
|
+
templateContext: TemplateContext;
|
|
43
|
+
variables?: Map<string, Variable>;
|
|
44
|
+
selfVariables?: Set<string>;
|
|
45
|
+
customFunctions?: CustomFunctions;
|
|
46
|
+
isRootState?: boolean;
|
|
47
|
+
isTooltipRoot?: boolean;
|
|
48
|
+
fakeElement?: number;
|
|
49
|
+
parentContext?: ComponentContext;
|
|
50
|
+
id: string;
|
|
51
|
+
animators?: Record<string, MaybeMissing<Animator>>;
|
|
52
|
+
states?: Record<string, StateSetter[]>;
|
|
53
|
+
pagers?: Map<string | undefined, PagerData | null>;
|
|
54
|
+
pagerListeners?: Map<string | undefined, PagerListener[]>;
|
|
55
|
+
key?: ComponentKey;
|
|
56
|
+
|
|
57
|
+
logError(error: WrappedError): void;
|
|
58
|
+
execAnyActions(
|
|
59
|
+
actions: MaybeMissing<Action[]> | undefined,
|
|
60
|
+
opts?: {
|
|
61
|
+
processUrls?: boolean;
|
|
62
|
+
node?: HTMLElement;
|
|
63
|
+
logType?: string;
|
|
64
|
+
additionalVars?: Map<string, Variable>;
|
|
65
|
+
}
|
|
66
|
+
): Promise<void>;
|
|
67
|
+
getDerivedFromVars<T>(
|
|
68
|
+
jsonProp: T,
|
|
69
|
+
additionalVars?: Map<string, Variable>,
|
|
70
|
+
keepComplex?: boolean,
|
|
71
|
+
maxDepth?: number
|
|
72
|
+
): Readable<MaybeMissing<T>>;
|
|
73
|
+
getJsonWithVars<T>(
|
|
74
|
+
jsonProp: T,
|
|
75
|
+
additionalVars?: Map<string, Variable>,
|
|
76
|
+
keepComplex?: boolean
|
|
77
|
+
): MaybeMissing<T>;
|
|
78
|
+
evalExpression(store: Store | undefined, expr: Node, opts?: {
|
|
79
|
+
weekStartDay?: number;
|
|
80
|
+
storeUsedVars?: Set<string>;
|
|
81
|
+
}): ReturnType<typeof evalExpression>;
|
|
82
|
+
produceChildContext(div: MaybeMissing<DivBaseData>, opts?: {
|
|
83
|
+
path?: string | number | undefined;
|
|
84
|
+
isRootState?: boolean;
|
|
85
|
+
isTooltipRoot?: boolean;
|
|
86
|
+
fake?: number;
|
|
87
|
+
variables?: Map<string, Variable>;
|
|
88
|
+
id?: string;
|
|
89
|
+
key?: ComponentKey;
|
|
90
|
+
}): ComponentContext;
|
|
91
|
+
dup(fakeReason: number): ComponentContext;
|
|
92
|
+
getVariable(varName: string, type?: VariableType): Variable | undefined;
|
|
93
|
+
getAnimator(name: string): MaybeMissing<Animator> | undefined;
|
|
94
|
+
registerState(stateId: string, setState: StateSetter): () => void;
|
|
95
|
+
registerPager(pagerId: string | undefined): PagerRegisterData;
|
|
96
|
+
listenPager(pagerId: string | undefined, listener: PagerListener): () => void;
|
|
97
|
+
destroy(): void;
|
|
98
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { DivBaseData } from './base';
|
|
2
|
+
import type { DivActionableData } from './actionable';
|
|
3
|
+
import type {
|
|
4
|
+
ContentAlignmentHorizontal,
|
|
5
|
+
ContentAlignmentVertical
|
|
6
|
+
} from './alignment';
|
|
7
|
+
import type { BooleanInt } from '../../typings/common';
|
|
8
|
+
import type { Drawable } from './drawable';
|
|
9
|
+
import type { DivAspect } from './image';
|
|
10
|
+
import type { EdgeInsets } from './edgeInserts';
|
|
11
|
+
import type { CollectionItemBuilder } from './itemBuilder';
|
|
12
|
+
|
|
13
|
+
export type ContainerOrientation = 'vertical' | 'horizontal' | 'overlap';
|
|
14
|
+
|
|
15
|
+
export type ContainerLayoutMode = 'no_wrap' | 'wrap';
|
|
16
|
+
|
|
17
|
+
export interface ContainerSeparator {
|
|
18
|
+
show_at_start?: BooleanInt;
|
|
19
|
+
show_at_end?: BooleanInt;
|
|
20
|
+
show_between?: BooleanInt;
|
|
21
|
+
style: Drawable;
|
|
22
|
+
margins?: EdgeInsets;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface DivContainerData extends DivBaseData, DivActionableData {
|
|
26
|
+
type: 'container';
|
|
27
|
+
content_alignment_horizontal?: ContentAlignmentHorizontal;
|
|
28
|
+
content_alignment_vertical?: ContentAlignmentVertical;
|
|
29
|
+
orientation?: ContainerOrientation;
|
|
30
|
+
items: DivBaseData[];
|
|
31
|
+
// auto_animations_enabled
|
|
32
|
+
layout_mode?: ContainerLayoutMode;
|
|
33
|
+
separator?: ContainerSeparator;
|
|
34
|
+
line_separator?: ContainerSeparator;
|
|
35
|
+
item_spacing?: number;
|
|
36
|
+
line_spacing?: number;
|
|
37
|
+
item_builder?: CollectionItemBuilder;
|
|
38
|
+
aspect?: DivAspect;
|
|
39
|
+
clip_to_bounds?: BooleanInt;
|
|
40
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DivBaseData } from './base';
|
|
2
|
+
import type { DivActionableData } from './actionable';
|
|
3
|
+
import type { AlignmentHorizontal, AlignmentVertical } from './alignment';
|
|
4
|
+
import type { FadeTransition } from './base';
|
|
5
|
+
import type { Filter } from './filter';
|
|
6
|
+
import type { ImageScale } from './imageScale';
|
|
7
|
+
import type { BooleanInt } from '../../typings/common';
|
|
8
|
+
|
|
9
|
+
export type TintMode = 'source_in' | 'source_atop' | 'darken' | 'lighten' | 'multiply' | 'screen';
|
|
10
|
+
|
|
11
|
+
export interface DivAspect {
|
|
12
|
+
ratio: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface DivImageData extends DivBaseData, DivActionableData {
|
|
16
|
+
type: 'image' | 'gif';
|
|
17
|
+
|
|
18
|
+
image_url?: string;
|
|
19
|
+
gif_url?: string;
|
|
20
|
+
placeholder_color?: string;
|
|
21
|
+
scale?: ImageScale;
|
|
22
|
+
content_alignment_horizontal?: AlignmentHorizontal;
|
|
23
|
+
content_alignment_vertical?: AlignmentVertical;
|
|
24
|
+
preview?: string;
|
|
25
|
+
preview_url?: string;
|
|
26
|
+
preload_required?: BooleanInt;
|
|
27
|
+
aspect?: DivAspect;
|
|
28
|
+
high_priority_preview_show?: BooleanInt;
|
|
29
|
+
tint_color?: string;
|
|
30
|
+
tint_mode?: TintMode;
|
|
31
|
+
appearance_animation?: FadeTransition;
|
|
32
|
+
filters?: Filter[];
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ImageScale = 'fill' | 'no_scale' | 'fit' | 'stretch';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Orientation } from './orientation';
|
|
2
|
+
|
|
3
|
+
export type Align = 'start' | 'center' | 'end';
|
|
4
|
+
export type AlignPlusBaseline = Align | 'baseline';
|
|
5
|
+
export type ScrollSnap = 'start' | 'center' | 'end';
|
|
6
|
+
|
|
7
|
+
export interface LayoutParams {
|
|
8
|
+
parentHAlign?: Align;
|
|
9
|
+
parentVAlign?: AlignPlusBaseline;
|
|
10
|
+
parentContainerOrientation?: Orientation;
|
|
11
|
+
parentContainerKnownWidth?: boolean;
|
|
12
|
+
parentContainerKnownHeight?: boolean;
|
|
13
|
+
parentContainerWrap?: boolean;
|
|
14
|
+
parentHorizontalWrapContent?: boolean;
|
|
15
|
+
parentVerticalWrapContent?: boolean;
|
|
16
|
+
stretchWidth?: boolean;
|
|
17
|
+
stretchHeight?: boolean;
|
|
18
|
+
treatMatchParentAs100?: boolean;
|
|
19
|
+
overlapParent?: boolean;
|
|
20
|
+
gridArea?: {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
colSpan: number;
|
|
24
|
+
rowSpan: number;
|
|
25
|
+
};
|
|
26
|
+
scrollSnap?: ScrollSnap;
|
|
27
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { BooleanInt } from '../../typings/common';
|
|
2
|
+
|
|
3
|
+
export interface FixedSize {
|
|
4
|
+
type: 'fixed';
|
|
5
|
+
value: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface MatchParentSize {
|
|
9
|
+
type: 'match_parent';
|
|
10
|
+
weight?: number;
|
|
11
|
+
min_size?: ConstraintSize;
|
|
12
|
+
max_size?: ConstraintSize;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ConstraintSize {
|
|
16
|
+
value: number;
|
|
17
|
+
// unit
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface WrapContentSize {
|
|
21
|
+
type: 'wrap_content';
|
|
22
|
+
constrained?: BooleanInt;
|
|
23
|
+
min_size?: ConstraintSize;
|
|
24
|
+
max_size?: ConstraintSize;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type Size = FixedSize | MatchParentSize | WrapContentSize;
|
|
28
|
+
|
|
29
|
+
export interface Dimension {
|
|
30
|
+
value: number;
|
|
31
|
+
// unit
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface PercentageSize {
|
|
35
|
+
type: 'percentage';
|
|
36
|
+
value: number;
|
|
37
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DivBaseData } from './base';
|
|
2
|
+
import type { DivActionableData } from './actionable';
|
|
3
|
+
import type { BooleanInt } from '../../typings/common';
|
|
4
|
+
|
|
5
|
+
export interface State {
|
|
6
|
+
state_id: string;
|
|
7
|
+
div?: DivBaseData;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface DivStateData extends DivBaseData, DivActionableData {
|
|
11
|
+
type: 'state';
|
|
12
|
+
states: State[];
|
|
13
|
+
state_id_variable?: string;
|
|
14
|
+
/** @deprecated */
|
|
15
|
+
div_id?: string;
|
|
16
|
+
default_state_id?: string;
|
|
17
|
+
// transition_animation_selector
|
|
18
|
+
clip_to_bounds?: BooleanInt;
|
|
19
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { DivBaseData } from './base';
|
|
2
|
+
import type { DivActionableData } from './actionable';
|
|
3
|
+
import type { Action } from '../../typings/common';
|
|
4
|
+
import type { FixedSize } from './sizes';
|
|
5
|
+
import type { AlignmentHorizontal, AlignmentVertical } from './alignment';
|
|
6
|
+
import type { GradientBackground, SolidBackground } from './background';
|
|
7
|
+
import type { BooleanInt } from '../../typings/common';
|
|
8
|
+
import type { TintMode } from './image';
|
|
9
|
+
import type { Shadow, Stroke } from './border';
|
|
10
|
+
import type { EdgeInsets } from './edgeInserts';
|
|
11
|
+
import type { FontVariationSettings } from './fontVariationSettings';
|
|
12
|
+
|
|
13
|
+
export type FontWeight = 'light' | 'regular' | 'medium' | 'bold';
|
|
14
|
+
|
|
15
|
+
export type LineStyle = 'none' | 'single';
|
|
16
|
+
|
|
17
|
+
export type Truncate = 'none' | 'end';
|
|
18
|
+
|
|
19
|
+
export interface TextStyles {
|
|
20
|
+
font_size?: number;
|
|
21
|
+
font_family?: string;
|
|
22
|
+
// font_size_unit
|
|
23
|
+
font_feature_settings?: string;
|
|
24
|
+
letter_spacing?: number;
|
|
25
|
+
font_weight?: FontWeight;
|
|
26
|
+
font_weight_value?: number;
|
|
27
|
+
text_color?: string;
|
|
28
|
+
underline?: LineStyle;
|
|
29
|
+
strike?: LineStyle;
|
|
30
|
+
line_height?: number;
|
|
31
|
+
text_shadow?: Shadow;
|
|
32
|
+
font_variation_settings?: FontVariationSettings;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface CloudBackground {
|
|
36
|
+
type: 'cloud';
|
|
37
|
+
color: string;
|
|
38
|
+
corner_radius: number;
|
|
39
|
+
paddings?: EdgeInsets;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type RangeBackground = SolidBackground | CloudBackground;
|
|
43
|
+
|
|
44
|
+
export interface TextRangeBorder {
|
|
45
|
+
stroke?: Stroke;
|
|
46
|
+
corner_radius?: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type TextVerticalAlignment = 'top' | 'center' | 'bottom' | 'baseline';
|
|
50
|
+
|
|
51
|
+
export interface TextMaskParticles {
|
|
52
|
+
type: 'particles';
|
|
53
|
+
is_enabled?: boolean;
|
|
54
|
+
color: string;
|
|
55
|
+
is_animated?: boolean;
|
|
56
|
+
particle_size?: FixedSize;
|
|
57
|
+
density?: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface TextMaskSolid{
|
|
61
|
+
type: 'solid';
|
|
62
|
+
is_enabled?: boolean;
|
|
63
|
+
color: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type TextMask = TextMaskParticles | TextMaskSolid;
|
|
67
|
+
|
|
68
|
+
export interface TextRange extends TextStyles {
|
|
69
|
+
start?: number;
|
|
70
|
+
end?: number;
|
|
71
|
+
actions?: Action[];
|
|
72
|
+
top_offset?: number;
|
|
73
|
+
border?: TextRangeBorder;
|
|
74
|
+
background?: RangeBackground;
|
|
75
|
+
alignment_vertical?: TextVerticalAlignment;
|
|
76
|
+
baseline_offset?: number;
|
|
77
|
+
mask?: TextMask;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type TextIndexingDirection = 'normal' | 'reversed';
|
|
81
|
+
|
|
82
|
+
export type TextImageAccessibilityType = 'none' | 'button' | 'image' | 'text' | 'auto';
|
|
83
|
+
|
|
84
|
+
export interface TextImageAccessibility {
|
|
85
|
+
description?: string;
|
|
86
|
+
type?: TextImageAccessibilityType;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface TextImage {
|
|
90
|
+
start: number;
|
|
91
|
+
url: string;
|
|
92
|
+
width?: FixedSize;
|
|
93
|
+
height?: FixedSize;
|
|
94
|
+
tint_color?: string;
|
|
95
|
+
tint_mode?: TintMode;
|
|
96
|
+
preload_required?: BooleanInt;
|
|
97
|
+
alignment_vertical?: TextVerticalAlignment;
|
|
98
|
+
indexing_direction?: TextIndexingDirection;
|
|
99
|
+
accessibility?: TextImageAccessibility;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
103
|
+
export interface TextEllipsis {
|
|
104
|
+
// text
|
|
105
|
+
// actions
|
|
106
|
+
// ranges
|
|
107
|
+
// images
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface DivTextData extends DivBaseData, DivActionableData, TextStyles {
|
|
111
|
+
type: 'text';
|
|
112
|
+
// font_size_unit;
|
|
113
|
+
max_lines?: number;
|
|
114
|
+
// min_hidden_lines;
|
|
115
|
+
auto_ellipsize?: BooleanInt;
|
|
116
|
+
text_alignment_horizontal?: AlignmentHorizontal;
|
|
117
|
+
text_alignment_vertical?: AlignmentVertical;
|
|
118
|
+
focused_text_color?: string;
|
|
119
|
+
text_gradient?: GradientBackground;
|
|
120
|
+
text: string;
|
|
121
|
+
ranges?: TextRange[];
|
|
122
|
+
images?: TextImage[];
|
|
123
|
+
// ellipsis;
|
|
124
|
+
selectable?: BooleanInt;
|
|
125
|
+
truncate?: Truncate;
|
|
126
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { WrappedError } from "./wrapError";
|
|
2
|
+
import type { DivBase, TemplateContext } from "../../typings/common";
|
|
3
|
+
import type { DivBaseData } from "../types/base";
|
|
4
|
+
|
|
5
|
+
export function applyTemplate<T extends DivBase>(
|
|
6
|
+
json: T,
|
|
7
|
+
templateContext: TemplateContext,
|
|
8
|
+
templates: Record<string, unknown>,
|
|
9
|
+
_logError: (error: WrappedError) => void,
|
|
10
|
+
): {
|
|
11
|
+
json: T;
|
|
12
|
+
templateContext: TemplateContext;
|
|
13
|
+
};
|
|
14
|
+
export function applyTemplate(
|
|
15
|
+
json: DivBaseData,
|
|
16
|
+
templateContext: TemplateContext,
|
|
17
|
+
templates: Record<string, unknown>,
|
|
18
|
+
_logError: (error: WrappedError) => void,
|
|
19
|
+
): {
|
|
20
|
+
json: DivBaseData;
|
|
21
|
+
templateContext: TemplateContext;
|
|
22
|
+
} {
|
|
23
|
+
const template = templates[json.type];
|
|
24
|
+
|
|
25
|
+
if (!template) {
|
|
26
|
+
// If template is missing, treat it as a standard component
|
|
27
|
+
return {
|
|
28
|
+
json,
|
|
29
|
+
templateContext,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let i;
|
|
34
|
+
const newContext: TemplateContext = {};
|
|
35
|
+
|
|
36
|
+
for (i in templateContext) {
|
|
37
|
+
if (Object.prototype.hasOwnProperty.call(templateContext, i)) {
|
|
38
|
+
newContext[i] = templateContext[i];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
for (i in json) {
|
|
43
|
+
if (i === "type" || i === "__proto__") {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (Object.prototype.hasOwnProperty.call(json, i)) {
|
|
48
|
+
newContext[i] = json[i as keyof typeof json];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function copyTemplated(base: any, extender: any) {
|
|
53
|
+
const keys = Object.keys(extender).filter((key) => key !== "__proto__");
|
|
54
|
+
const simpleKeys = keys.filter((key) => key.charAt(0) !== "$");
|
|
55
|
+
const templateKeys = keys.filter((key) => key.charAt(0) === "$");
|
|
56
|
+
|
|
57
|
+
simpleKeys.forEach((key) => {
|
|
58
|
+
const item = extender[key];
|
|
59
|
+
|
|
60
|
+
if (typeof item === "object" && item !== null) {
|
|
61
|
+
base[key] = Array.isArray(item) ? [] : {};
|
|
62
|
+
copyTemplated(base[key], item);
|
|
63
|
+
} else {
|
|
64
|
+
base[key] = item;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
templateKeys.forEach((key) => {
|
|
69
|
+
const item = extender[key];
|
|
70
|
+
|
|
71
|
+
const val = newContext[item];
|
|
72
|
+
|
|
73
|
+
if (val !== undefined) {
|
|
74
|
+
const prop = key.substring(1);
|
|
75
|
+
base[prop] = val;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return base;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const newJson = copyTemplated({}, template);
|
|
83
|
+
|
|
84
|
+
for (i in json) {
|
|
85
|
+
if (i === "type" || i === "__proto__") {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (Object.prototype.hasOwnProperty.call(json, i)) {
|
|
90
|
+
newJson[i] = json[i as keyof typeof json];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
json: newJson,
|
|
96
|
+
templateContext: newContext,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function applyTemplatesRecursively(
|
|
101
|
+
json: any,
|
|
102
|
+
templates: Record<string, unknown>,
|
|
103
|
+
logError: (error: WrappedError) => void,
|
|
104
|
+
): any {
|
|
105
|
+
if (!json || typeof json !== "object") {
|
|
106
|
+
return json;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (Array.isArray(json)) {
|
|
110
|
+
return json.map((item) =>
|
|
111
|
+
applyTemplatesRecursively(item, templates, logError),
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let resolvedJson = json;
|
|
116
|
+
|
|
117
|
+
// Attempt expansion if type matches a template
|
|
118
|
+
if (json.type && templates[json.type]) {
|
|
119
|
+
try {
|
|
120
|
+
const res = applyTemplate(json, {}, templates, logError);
|
|
121
|
+
resolvedJson = res.json;
|
|
122
|
+
} catch (_e) {
|
|
123
|
+
// Expansion failed
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Recursively process children
|
|
128
|
+
const result: any = {};
|
|
129
|
+
for (const key in resolvedJson) {
|
|
130
|
+
if (!Object.prototype.hasOwnProperty.call(resolvedJson, key)) continue;
|
|
131
|
+
|
|
132
|
+
if (key === "type") {
|
|
133
|
+
result[key] = resolvedJson[key];
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
result[key] = applyTemplatesRecursively(
|
|
138
|
+
resolvedJson[key],
|
|
139
|
+
templates,
|
|
140
|
+
logError,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { padLeft } from './padLeft';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts color from app format (ARGB) to css format (RGBA)
|
|
5
|
+
* @param color Color with format #RGB, #ARGB, #RRGGBB, #AARRGGBB
|
|
6
|
+
* @param alpha Color additional opacity
|
|
7
|
+
* @param defaultColor Default color value, used if input color is incorrect
|
|
8
|
+
* @returns Color with opacity if it has correct format, or defaultColor elsewhere
|
|
9
|
+
*/
|
|
10
|
+
export function correctColor(color: string | undefined, alpha = 1, defaultColor = 'transparent'): string {
|
|
11
|
+
color = (typeof color === 'string' && color || '').toLowerCase();
|
|
12
|
+
|
|
13
|
+
if (color.charAt(0) !== '#') {
|
|
14
|
+
return defaultColor;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const parsedColor = parseColor(color);
|
|
18
|
+
if (parsedColor) {
|
|
19
|
+
parsedColor.a *= alpha;
|
|
20
|
+
return stringifyColorToCss(parsedColor);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return defaultColor;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function correctColorWithAlpha(color: string | undefined, alpha: number, defaultColor = 'transparent'): string {
|
|
27
|
+
color = (typeof color === 'string' && color || '').toLowerCase();
|
|
28
|
+
|
|
29
|
+
if (color.charAt(0) !== '#') {
|
|
30
|
+
return defaultColor;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const parsedColor = parseColor(color);
|
|
34
|
+
if (parsedColor) {
|
|
35
|
+
parsedColor.a = alpha;
|
|
36
|
+
return stringifyColorToCss(parsedColor);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return defaultColor;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ParsedColor {
|
|
43
|
+
a: number;
|
|
44
|
+
r: number;
|
|
45
|
+
g: number;
|
|
46
|
+
b: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function stringifyColorToCss(color: ParsedColor): string {
|
|
50
|
+
if (color.a === 255) {
|
|
51
|
+
return `#${[color.r, color.g, color.b].map(it => {
|
|
52
|
+
return padLeft(Math.round(it).toString(16), 2);
|
|
53
|
+
}).join('')}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return `rgba(${color.r},${color.g},${color.b},${(color.a / 255).toFixed(2)})`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function parseColor(color: string): ParsedColor | null {
|
|
60
|
+
const colorMatch = (
|
|
61
|
+
// #AARRGGBB
|
|
62
|
+
color.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i) ||
|
|
63
|
+
// #ARGB
|
|
64
|
+
color.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])$/i) ||
|
|
65
|
+
// #RRGGBB
|
|
66
|
+
color.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i) ||
|
|
67
|
+
// #RGB
|
|
68
|
+
color.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i)
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
if (colorMatch) {
|
|
72
|
+
// with alpha part in color
|
|
73
|
+
if (colorMatch.length === 5) {
|
|
74
|
+
const [_, a, r, g, b] = colorMatch;
|
|
75
|
+
const redPart = r.length === 2 ? r : r + r;
|
|
76
|
+
const greenPart = g.length === 2 ? g : g + g;
|
|
77
|
+
const bluePart = b.length === 2 ? b : b + b;
|
|
78
|
+
const alphaPart = a.length === 2 ? a : a + a;
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
a: parseInt(alphaPart, 16),
|
|
82
|
+
r: parseInt(redPart, 16),
|
|
83
|
+
g: parseInt(greenPart, 16),
|
|
84
|
+
b: parseInt(bluePart, 16)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const [_, r, g, b] = colorMatch;
|
|
89
|
+
const redPart = r.length === 2 ? r : r + r;
|
|
90
|
+
const greenPart = g.length === 2 ? g : g + g;
|
|
91
|
+
const bluePart = b.length === 2 ? b : b + b;
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
a: 255,
|
|
95
|
+
r: parseInt(redPart, 16),
|
|
96
|
+
g: parseInt(greenPart, 16),
|
|
97
|
+
b: parseInt(bluePart, 16)
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return null;
|
|
102
|
+
}
|