react-native-divkit 0.1.0-alpha.1 → 0.1.0-alpha.3

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.
Files changed (150) hide show
  1. package/README.md +200 -201
  2. package/dist/DivKit.d.ts.map +1 -1
  3. package/dist/DivKit.js +24 -7
  4. package/dist/DivKit.js.map +1 -1
  5. package/dist/actions/array.d.ts.map +1 -1
  6. package/dist/actions/array.js +1 -1
  7. package/dist/actions/array.js.map +1 -1
  8. package/dist/actions/copyToClipboard.d.ts.map +1 -1
  9. package/dist/actions/copyToClipboard.js +2 -1
  10. package/dist/actions/copyToClipboard.js.map +1 -1
  11. package/dist/actions/dict.d.ts.map +1 -1
  12. package/dist/actions/dict.js.map +1 -1
  13. package/dist/actions/updateStructure.d.ts.map +1 -1
  14. package/dist/actions/updateStructure.js.map +1 -1
  15. package/dist/components/container/DivContainer.d.ts.map +1 -1
  16. package/dist/components/container/DivContainer.js +3 -5
  17. package/dist/components/container/DivContainer.js.map +1 -1
  18. package/dist/components/image/DivImage.d.ts.map +1 -1
  19. package/dist/components/image/DivImage.js +1 -6
  20. package/dist/components/image/DivImage.js.map +1 -1
  21. package/dist/components/state/DivState.d.ts.map +1 -1
  22. package/dist/components/state/DivState.js +3 -5
  23. package/dist/components/state/DivState.js.map +1 -1
  24. package/dist/components/text/DivText.d.ts.map +1 -1
  25. package/dist/components/text/DivText.js +4 -4
  26. package/dist/components/text/DivText.js.map +1 -1
  27. package/dist/components/utilities/Background.d.ts +11 -0
  28. package/dist/components/utilities/Background.d.ts.map +1 -0
  29. package/dist/components/utilities/Background.js +73 -0
  30. package/dist/components/utilities/Background.js.map +1 -0
  31. package/dist/components/utilities/Outer.d.ts.map +1 -1
  32. package/dist/components/utilities/Outer.js +24 -10
  33. package/dist/components/utilities/Outer.js.map +1 -1
  34. package/dist/context/index.d.ts.map +1 -1
  35. package/dist/context/index.js.map +1 -1
  36. package/dist/expressions/eval.d.ts.map +1 -1
  37. package/dist/expressions/eval.js +19 -11
  38. package/dist/expressions/eval.js.map +1 -1
  39. package/dist/expressions/funcs/array.d.ts.map +1 -1
  40. package/dist/expressions/funcs/array.js +72 -168
  41. package/dist/expressions/funcs/array.js.map +1 -1
  42. package/dist/expressions/funcs/colors.d.ts.map +1 -1
  43. package/dist/expressions/funcs/colors.js.map +1 -1
  44. package/dist/expressions/funcs/customFuncs.d.ts.map +1 -1
  45. package/dist/expressions/funcs/customFuncs.js +6 -4
  46. package/dist/expressions/funcs/customFuncs.js.map +1 -1
  47. package/dist/expressions/funcs/datetime.d.ts.map +1 -1
  48. package/dist/expressions/funcs/datetime.js +1 -1
  49. package/dist/expressions/funcs/datetime.js.map +1 -1
  50. package/dist/expressions/funcs/dict.d.ts.map +1 -1
  51. package/dist/expressions/funcs/dict.js.map +1 -1
  52. package/dist/expressions/funcs/funcs.d.ts.map +1 -1
  53. package/dist/expressions/funcs/funcs.js +21 -13
  54. package/dist/expressions/funcs/funcs.js.map +1 -1
  55. package/dist/expressions/funcs/math.d.ts.map +1 -1
  56. package/dist/expressions/funcs/math.js +40 -20
  57. package/dist/expressions/funcs/math.js.map +1 -1
  58. package/dist/expressions/funcs/std.d.ts.map +1 -1
  59. package/dist/expressions/funcs/std.js +4 -4
  60. package/dist/expressions/funcs/std.js.map +1 -1
  61. package/dist/expressions/funcs/strings.d.ts.map +1 -1
  62. package/dist/expressions/funcs/strings.js +1 -2
  63. package/dist/expressions/funcs/strings.js.map +1 -1
  64. package/dist/expressions/funcs/trigonometry.js +2 -2
  65. package/dist/expressions/funcs/trigonometry.js.map +1 -1
  66. package/dist/expressions/json.d.ts +2 -2
  67. package/dist/expressions/json.d.ts.map +1 -1
  68. package/dist/expressions/json.js +6 -4
  69. package/dist/expressions/json.js.map +1 -1
  70. package/dist/expressions/utils.d.ts.map +1 -1
  71. package/dist/expressions/utils.js +9 -10
  72. package/dist/expressions/utils.js.map +1 -1
  73. package/dist/expressions/variable.d.ts.map +1 -1
  74. package/dist/expressions/variable.js +3 -7
  75. package/dist/expressions/variable.js.map +1 -1
  76. package/dist/expressions/walk.d.ts.map +1 -1
  77. package/dist/expressions/walk.js.map +1 -1
  78. package/dist/hooks/index.d.ts.map +1 -1
  79. package/dist/hooks/index.js.map +1 -1
  80. package/dist/hooks/useAction.d.ts.map +1 -1
  81. package/dist/hooks/useAction.js.map +1 -1
  82. package/dist/hooks/useDerivedFromVars.d.ts.map +1 -1
  83. package/dist/hooks/useDerivedFromVars.js.map +1 -1
  84. package/dist/hooks/useVariable.d.ts.map +1 -1
  85. package/dist/hooks/useVariable.js +4 -4
  86. package/dist/hooks/useVariable.js.map +1 -1
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js.map +1 -1
  89. package/dist/stores/createObservable.d.ts.map +1 -1
  90. package/dist/stores/createObservable.js.map +1 -1
  91. package/dist/utils/applyTemplate.d.ts +2 -2
  92. package/dist/utils/applyTemplate.d.ts.map +1 -1
  93. package/dist/utils/applyTemplate.js +13 -13
  94. package/dist/utils/applyTemplate.js.map +1 -1
  95. package/dist/utils/correctColor.d.ts.map +1 -1
  96. package/dist/utils/correctColor.js +8 -6
  97. package/dist/utils/correctColor.js.map +1 -1
  98. package/dist/utils/formatDate.d.ts.map +1 -1
  99. package/dist/utils/formatDate.js +7 -10
  100. package/dist/utils/formatDate.js.map +1 -1
  101. package/dist/utils/wrapError.d.ts.map +1 -1
  102. package/dist/utils/wrapError.js.map +1 -1
  103. package/package.json +8 -7
  104. package/src/DivKit.tsx +258 -220
  105. package/src/actions/array.ts +91 -64
  106. package/src/actions/copyToClipboard.ts +28 -19
  107. package/src/actions/dict.ts +36 -26
  108. package/src/actions/updateStructure.ts +86 -61
  109. package/src/components/README.md +38 -18
  110. package/src/components/container/DivContainer.tsx +4 -14
  111. package/src/components/image/DivImage.tsx +1 -11
  112. package/src/components/state/DivState.tsx +3 -9
  113. package/src/components/text/DivText.tsx +8 -20
  114. package/src/components/utilities/Background.tsx +120 -0
  115. package/src/components/utilities/Outer.tsx +24 -23
  116. package/src/components/utilities/README.md +37 -32
  117. package/src/context/index.ts +2 -11
  118. package/src/expressions/ast.d.ts +16 -9
  119. package/src/expressions/eval.ts +82 -37
  120. package/src/expressions/funcs/array.ts +129 -209
  121. package/src/expressions/funcs/colors.ts +1 -3
  122. package/src/expressions/funcs/customFuncs.ts +6 -4
  123. package/src/expressions/funcs/datetime.ts +10 -3
  124. package/src/expressions/funcs/dict.ts +16 -2
  125. package/src/expressions/funcs/funcs.ts +75 -89
  126. package/src/expressions/funcs/math.ts +103 -43
  127. package/src/expressions/funcs/std.ts +4 -7
  128. package/src/expressions/funcs/strings.ts +9 -25
  129. package/src/expressions/funcs/trigonometry.ts +2 -2
  130. package/src/expressions/json.ts +60 -53
  131. package/src/expressions/utils.ts +24 -22
  132. package/src/expressions/variable.ts +5 -21
  133. package/src/expressions/walk.ts +6 -3
  134. package/src/hooks/README.md +61 -53
  135. package/src/hooks/index.ts +3 -18
  136. package/src/hooks/useAction.ts +1 -3
  137. package/src/hooks/useDerivedFromVars.ts +3 -13
  138. package/src/hooks/useVariable.ts +7 -17
  139. package/src/index.ts +10 -48
  140. package/src/stores/createObservable.ts +35 -35
  141. package/src/types/alignment.d.ts +15 -6
  142. package/src/types/background.d.ts +6 -2
  143. package/src/types/base.d.ts +41 -9
  144. package/src/types/componentContext.d.ts +27 -22
  145. package/src/types/container.d.ts +1 -4
  146. package/src/types/text.d.ts +1 -1
  147. package/src/utils/applyTemplate.ts +103 -109
  148. package/src/utils/correctColor.ts +9 -8
  149. package/src/utils/formatDate.ts +175 -86
  150. package/src/utils/wrapError.ts +7 -4
@@ -7,46 +7,46 @@ export type Subscriber<T> = (value: T) => void;
7
7
  export type Unsubscriber = () => void;
8
8
 
9
9
  export class Observable<T> {
10
- private value: T;
11
- private subscribers = new Set<Subscriber<T>>();
10
+ private value: T;
11
+ private subscribers = new Set<Subscriber<T>>();
12
12
 
13
- constructor(initialValue: T) {
14
- this.value = initialValue;
15
- }
13
+ constructor(initialValue: T) {
14
+ this.value = initialValue;
15
+ }
16
16
 
17
- /**
18
- * Subscribe to value changes
19
- * @param callback Function called immediately with current value and on each change
20
- * @returns Unsubscribe function
21
- */
22
- subscribe(callback: Subscriber<T>): Unsubscriber {
23
- this.subscribers.add(callback);
24
- // Immediately call with current value (Svelte store behavior)
25
- callback(this.value);
17
+ /**
18
+ * Subscribe to value changes
19
+ * @param callback Function called immediately with current value and on each change
20
+ * @returns Unsubscribe function
21
+ */
22
+ subscribe(callback: Subscriber<T>): Unsubscriber {
23
+ this.subscribers.add(callback);
24
+ // Immediately call with current value (Svelte store behavior)
25
+ callback(this.value);
26
26
 
27
- return () => {
28
- this.subscribers.delete(callback);
29
- };
30
- }
27
+ return () => {
28
+ this.subscribers.delete(callback);
29
+ };
30
+ }
31
31
 
32
- /**
33
- * Update the value and notify all subscribers
34
- * @param newValue New value to set
35
- */
36
- set(newValue: T): void {
37
- if (this.value !== newValue) {
38
- this.value = newValue;
39
- this.subscribers.forEach(cb => cb(newValue));
32
+ /**
33
+ * Update the value and notify all subscribers
34
+ * @param newValue New value to set
35
+ */
36
+ set(newValue: T): void {
37
+ if (this.value !== newValue) {
38
+ this.value = newValue;
39
+ this.subscribers.forEach(cb => cb(newValue));
40
+ }
40
41
  }
41
- }
42
42
 
43
- /**
44
- * Get current value without subscribing
45
- * @returns Current value
46
- */
47
- get(): T {
48
- return this.value;
49
- }
43
+ /**
44
+ * Get current value without subscribing
45
+ * @returns Current value
46
+ */
47
+ get(): T {
48
+ return this.value;
49
+ }
50
50
  }
51
51
 
52
52
  /**
@@ -55,7 +55,7 @@ export class Observable<T> {
55
55
  * @returns Observable instance
56
56
  */
57
57
  export function writable<T>(initialValue: T): Observable<T> {
58
- return new Observable(initialValue);
58
+ return new Observable(initialValue);
59
59
  }
60
60
 
61
61
  /**
@@ -3,11 +3,20 @@ export type AlignmentHorizontal = 'left' | 'center' | 'right' | 'start' | 'end';
3
3
  export type AlignmentVertical = 'top' | 'center' | 'bottom' | 'baseline';
4
4
 
5
5
  export type ContentAlignmentHorizontal =
6
- 'left' | 'center' | 'right' |
7
- 'start' | 'end' |
8
- 'space-between' | 'space-around' | 'space-evenly';
6
+ | 'left'
7
+ | 'center'
8
+ | 'right'
9
+ | 'start'
10
+ | 'end'
11
+ | 'space-between'
12
+ | 'space-around'
13
+ | 'space-evenly';
9
14
 
10
15
  export type ContentAlignmentVertical =
11
- 'top' | 'center' | 'bottom' |
12
- 'space-between' | 'space-around' | 'space-evenly' |
13
- 'baseline';
16
+ | 'top'
17
+ | 'center'
18
+ | 'bottom'
19
+ | 'space-between'
20
+ | 'space-around'
21
+ | 'space-evenly'
22
+ | 'baseline';
@@ -67,5 +67,9 @@ export interface RadialBackground {
67
67
  center_y?: RadialGradientCenter;
68
68
  }
69
69
 
70
- export type Background = GradientBackground | ImageBackground |
71
- SolidBackground | RadialBackground | NinePatchImageBackground;
70
+ export type Background =
71
+ | GradientBackground
72
+ | ImageBackground
73
+ | SolidBackground
74
+ | RadialBackground
75
+ | NinePatchImageBackground;
@@ -4,12 +4,34 @@ import type { Border } from './border';
4
4
  import type { Background } from './background';
5
5
  import type { EdgeInsets } from './edgeInserts';
6
6
  import type { Dimension } from './sizes';
7
- import type { Action, AnimatorDirection, AnimatorRepeatCount, BooleanInt, DisappearAction, DivFunction, DivVariable, Interpolation, VariableTrigger, VisibilityAction } from '../../typings/common';
7
+ import type {
8
+ Action,
9
+ AnimatorDirection,
10
+ AnimatorRepeatCount,
11
+ BooleanInt,
12
+ DisappearAction,
13
+ DivFunction,
14
+ DivVariable,
15
+ Interpolation,
16
+ VariableTrigger,
17
+ VisibilityAction
18
+ } from '../../typings/common';
8
19
  import type { Focus } from './focus';
9
20
  import type { Animation } from './animation';
10
21
 
11
- export type AccessibilityType = 'none' | 'button' | 'image' | 'text' | 'edit_text' |
12
- 'header' | 'tab_bar' | 'list' | 'select' | 'checkbox' | 'radio' | 'auto';
22
+ export type AccessibilityType =
23
+ | 'none'
24
+ | 'button'
25
+ | 'image'
26
+ | 'text'
27
+ | 'edit_text'
28
+ | 'header'
29
+ | 'tab_bar'
30
+ | 'list'
31
+ | 'select'
32
+ | 'checkbox'
33
+ | 'radio'
34
+ | 'auto';
13
35
 
14
36
  export type AccessibilityMode = 'default' | 'merge' | 'exclude';
15
37
 
@@ -64,10 +86,12 @@ export interface ChangeBoundsTransition extends TransitionBase {
64
86
  type: 'change_bounds';
65
87
  }
66
88
 
67
- export type TransitionChange = ChangeBoundsTransition | {
68
- type: 'set';
69
- items: TransitionChange[];
70
- }
89
+ export type TransitionChange =
90
+ | ChangeBoundsTransition
91
+ | {
92
+ type: 'set';
93
+ items: TransitionChange[];
94
+ };
71
95
 
72
96
  export interface PivotFixedValue {
73
97
  type: 'pivot-fixed';
@@ -133,8 +157,16 @@ export type TooltipMode = TooltipModeModal | TooltipModeNonModal;
133
157
  export interface Tooltip {
134
158
  id: string;
135
159
  div: DivBaseData;
136
- position: 'left' | 'top-left' | 'top' | 'top-right' | 'right' |
137
- 'bottom-right' | 'bottom' | 'bottom-left' | 'center';
160
+ position:
161
+ | 'left'
162
+ | 'top-left'
163
+ | 'top'
164
+ | 'top-right'
165
+ | 'right'
166
+ | 'bottom-right'
167
+ | 'bottom'
168
+ | 'bottom-left'
169
+ | 'center';
138
170
  duration?: number;
139
171
  offset?: {
140
172
  x: {
@@ -28,10 +28,12 @@ export interface PagerRegisterData {
28
28
  destroy: () => void;
29
29
  }
30
30
 
31
- export type ComponentKey = string | {
32
- index: number;
33
- data: object;
34
- };
31
+ export type ComponentKey =
32
+ | string
33
+ | {
34
+ index: number;
35
+ data: object;
36
+ };
35
37
 
36
38
  export interface ComponentContext<T extends DivBaseData = DivBaseData> {
37
39
  path: string[];
@@ -70,24 +72,27 @@ export interface ComponentContext<T extends DivBaseData = DivBaseData> {
70
72
  keepComplex?: boolean,
71
73
  maxDepth?: number
72
74
  ): 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;
75
+ getJsonWithVars<T>(jsonProp: T, additionalVars?: Map<string, Variable>, keepComplex?: boolean): MaybeMissing<T>;
76
+ evalExpression(
77
+ store: Store | undefined,
78
+ expr: Node,
79
+ opts?: {
80
+ weekStartDay?: number;
81
+ storeUsedVars?: Set<string>;
82
+ }
83
+ ): ReturnType<typeof evalExpression>;
84
+ produceChildContext(
85
+ div: MaybeMissing<DivBaseData>,
86
+ opts?: {
87
+ path?: string | number | undefined;
88
+ isRootState?: boolean;
89
+ isTooltipRoot?: boolean;
90
+ fake?: number;
91
+ variables?: Map<string, Variable>;
92
+ id?: string;
93
+ key?: ComponentKey;
94
+ }
95
+ ): ComponentContext;
91
96
  dup(fakeReason: number): ComponentContext;
92
97
  getVariable(varName: string, type?: VariableType): Variable | undefined;
93
98
  getAnimator(name: string): MaybeMissing<Animator> | undefined;
@@ -1,9 +1,6 @@
1
1
  import type { DivBaseData } from './base';
2
2
  import type { DivActionableData } from './actionable';
3
- import type {
4
- ContentAlignmentHorizontal,
5
- ContentAlignmentVertical
6
- } from './alignment';
3
+ import type { ContentAlignmentHorizontal, ContentAlignmentVertical } from './alignment';
7
4
  import type { BooleanInt } from '../../typings/common';
8
5
  import type { Drawable } from './drawable';
9
6
  import type { DivAspect } from './image';
@@ -57,7 +57,7 @@ export interface TextMaskParticles {
57
57
  density?: number;
58
58
  }
59
59
 
60
- export interface TextMaskSolid{
60
+ export interface TextMaskSolid {
61
61
  type: 'solid';
62
62
  is_enabled?: boolean;
63
63
  color: string;
@@ -1,145 +1,139 @@
1
- import type { WrappedError } from "./wrapError";
2
- import type { DivBase, TemplateContext } from "../../typings/common";
3
- import type { DivBaseData } from "../types/base";
1
+ import type { WrappedError } from './wrapError';
2
+ import type { DivBase, TemplateContext } from '../../typings/common';
3
+ import type { DivBaseData } from '../types/base';
4
4
 
5
5
  export function applyTemplate<T extends DivBase>(
6
- json: T,
7
- templateContext: TemplateContext,
8
- templates: Record<string, unknown>,
9
- _logError: (error: WrappedError) => void,
6
+ json: T,
7
+ templateContext: TemplateContext,
8
+ templates: Record<string, unknown>,
9
+ _logError: (error: WrappedError) => void
10
10
  ): {
11
- json: T;
12
- templateContext: TemplateContext;
11
+ json: T;
12
+ templateContext: TemplateContext;
13
13
  };
14
14
  export function applyTemplate(
15
- json: DivBaseData,
16
- templateContext: TemplateContext,
17
- templates: Record<string, unknown>,
18
- _logError: (error: WrappedError) => void,
15
+ json: DivBaseData,
16
+ templateContext: TemplateContext,
17
+ templates: Record<string, unknown>,
18
+ _logError: (error: WrappedError) => void
19
19
  ): {
20
- json: DivBaseData;
21
- templateContext: TemplateContext;
20
+ json: DivBaseData;
21
+ templateContext: TemplateContext;
22
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
- }
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
32
 
33
- let i;
34
- const newContext: TemplateContext = {};
33
+ let i;
34
+ const newContext: TemplateContext = {};
35
35
 
36
- for (i in templateContext) {
37
- if (Object.prototype.hasOwnProperty.call(templateContext, i)) {
38
- newContext[i] = templateContext[i];
36
+ for (i in templateContext) {
37
+ if (Object.prototype.hasOwnProperty.call(templateContext, i)) {
38
+ newContext[i] = templateContext[i];
39
+ }
39
40
  }
40
- }
41
41
 
42
- for (i in json) {
43
- if (i === "type" || i === "__proto__") {
44
- continue;
45
- }
42
+ for (i in json) {
43
+ if (i === 'type' || i === '__proto__') {
44
+ continue;
45
+ }
46
46
 
47
- if (Object.prototype.hasOwnProperty.call(json, i)) {
48
- newContext[i] = json[i as keyof typeof json];
47
+ if (Object.prototype.hasOwnProperty.call(json, i)) {
48
+ newContext[i] = json[i as keyof typeof json];
49
+ }
49
50
  }
50
- }
51
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) === "$");
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
56
 
57
- simpleKeys.forEach((key) => {
58
- const item = extender[key];
57
+ simpleKeys.forEach(key => {
58
+ const item = extender[key];
59
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
- });
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
67
 
68
- templateKeys.forEach((key) => {
69
- const item = extender[key];
68
+ templateKeys.forEach(key => {
69
+ const item = extender[key];
70
70
 
71
- const val = newContext[item];
71
+ const val = newContext[item];
72
72
 
73
- if (val !== undefined) {
74
- const prop = key.substring(1);
75
- base[prop] = val;
76
- }
77
- });
73
+ if (val !== undefined) {
74
+ const prop = key.substring(1);
75
+ base[prop] = val;
76
+ }
77
+ });
78
78
 
79
- return base;
80
- }
79
+ return base;
80
+ }
81
81
 
82
- const newJson = copyTemplated({}, template);
82
+ const newJson = copyTemplated({}, template);
83
83
 
84
- for (i in json) {
85
- if (i === "type" || i === "__proto__") {
86
- continue;
87
- }
84
+ for (i in json) {
85
+ if (i === 'type' || i === '__proto__') {
86
+ continue;
87
+ }
88
88
 
89
- if (Object.prototype.hasOwnProperty.call(json, i)) {
90
- newJson[i] = json[i as keyof typeof json];
89
+ if (Object.prototype.hasOwnProperty.call(json, i)) {
90
+ newJson[i] = json[i as keyof typeof json];
91
+ }
91
92
  }
92
- }
93
93
 
94
- return {
95
- json: newJson,
96
- templateContext: newContext,
97
- };
94
+ return {
95
+ json: newJson,
96
+ templateContext: newContext
97
+ };
98
98
  }
99
99
 
100
100
  export function applyTemplatesRecursively(
101
- json: any,
102
- templates: Record<string, unknown>,
103
- logError: (error: WrappedError) => void,
101
+ json: any,
102
+ templates: Record<string, unknown>,
103
+ logError: (error: WrappedError) => void
104
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
105
+ if (!json || typeof json !== 'object') {
106
+ return json;
107
+ }
108
+
109
+ if (Array.isArray(json)) {
110
+ return json.map(item => applyTemplatesRecursively(item, templates, logError));
124
111
  }
125
- }
126
112
 
127
- // Recursively process children
128
- const result: any = {};
129
- for (const key in resolvedJson) {
130
- if (!Object.prototype.hasOwnProperty.call(resolvedJson, key)) continue;
113
+ let resolvedJson = json;
131
114
 
132
- if (key === "type") {
133
- result[key] = resolvedJson[key];
134
- continue;
115
+ // Attempt expansion if type matches a template
116
+ if (json.type && templates[json.type]) {
117
+ try {
118
+ const res = applyTemplate(json, {}, templates, logError);
119
+ resolvedJson = res.json;
120
+ } catch (_e) {
121
+ // Expansion failed
122
+ }
135
123
  }
136
124
 
137
- result[key] = applyTemplatesRecursively(
138
- resolvedJson[key],
139
- templates,
140
- logError,
141
- );
142
- }
125
+ // Recursively process children
126
+ const result: any = {};
127
+ for (const key in resolvedJson) {
128
+ if (!Object.prototype.hasOwnProperty.call(resolvedJson, key)) continue;
129
+
130
+ if (key === 'type') {
131
+ result[key] = resolvedJson[key];
132
+ continue;
133
+ }
134
+
135
+ result[key] = applyTemplatesRecursively(resolvedJson[key], templates, logError);
136
+ }
143
137
 
144
- return result;
138
+ return result;
145
139
  }
@@ -8,7 +8,7 @@ import { padLeft } from './padLeft';
8
8
  * @returns Color with opacity if it has correct format, or defaultColor elsewhere
9
9
  */
10
10
  export function correctColor(color: string | undefined, alpha = 1, defaultColor = 'transparent'): string {
11
- color = (typeof color === 'string' && color || '').toLowerCase();
11
+ color = ((typeof color === 'string' && color) || '').toLowerCase();
12
12
 
13
13
  if (color.charAt(0) !== '#') {
14
14
  return defaultColor;
@@ -24,7 +24,7 @@ export function correctColor(color: string | undefined, alpha = 1, defaultColor
24
24
  }
25
25
 
26
26
  export function correctColorWithAlpha(color: string | undefined, alpha: number, defaultColor = 'transparent'): string {
27
- color = (typeof color === 'string' && color || '').toLowerCase();
27
+ color = ((typeof color === 'string' && color) || '').toLowerCase();
28
28
 
29
29
  if (color.charAt(0) !== '#') {
30
30
  return defaultColor;
@@ -48,16 +48,18 @@ export interface ParsedColor {
48
48
 
49
49
  export function stringifyColorToCss(color: ParsedColor): string {
50
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('')}`;
51
+ return `#${[color.r, color.g, color.b]
52
+ .map(it => {
53
+ return padLeft(Math.round(it).toString(16), 2);
54
+ })
55
+ .join('')}`;
54
56
  }
55
57
 
56
58
  return `rgba(${color.r},${color.g},${color.b},${(color.a / 255).toFixed(2)})`;
57
59
  }
58
60
 
59
61
  export function parseColor(color: string): ParsedColor | null {
60
- const colorMatch = (
62
+ const colorMatch =
61
63
  // #AARRGGBB
62
64
  color.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i) ||
63
65
  // #ARGB
@@ -65,8 +67,7 @@ export function parseColor(color: string): ParsedColor | null {
65
67
  // #RRGGBB
66
68
  color.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i) ||
67
69
  // #RGB
68
- color.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i)
69
- );
70
+ color.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i);
70
71
 
71
72
  if (colorMatch) {
72
73
  // with alpha part in color