native-fn 1.0.26 → 1.0.28

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 (161) hide show
  1. package/README.md +22 -192
  2. package/dist/index.d.ts +18 -27
  3. package/dist/native.cjs +27 -1400
  4. package/dist/native.min.cjs +1 -0
  5. package/dist/native.min.mjs +1 -0
  6. package/dist/native.mjs +27 -1400
  7. package/dist/native.umd.js +27 -1400
  8. package/dist/native.umd.min.js +1 -0
  9. package/dist/plugin/app/index.cjs +1025 -0
  10. package/dist/plugin/app/index.d.ts +86 -0
  11. package/dist/plugin/app/index.min.cjs +1 -0
  12. package/dist/plugin/app/index.min.mjs +1 -0
  13. package/dist/plugin/app/index.mjs +1023 -0
  14. package/dist/plugin/app/index.umd.js +1031 -0
  15. package/dist/plugin/app/index.umd.min.js +1 -0
  16. package/dist/plugin/app/src/constants/platform.d.ts +35 -0
  17. package/dist/plugin/app/src/constants/user-agent.d.ts +1 -0
  18. package/dist/plugin/app/src/plugin/app/cores/app.d.ts +3 -0
  19. package/dist/plugin/app/src/plugin/app/index.d.ts +5 -0
  20. package/dist/plugin/app/src/plugin/app/types/app.d.ts +54 -0
  21. package/dist/plugin/app/src/plugin/app/types/appModule.d.ts +54 -0
  22. package/dist/plugin/app/src/plugin/app/types/index.d.ts +1 -0
  23. package/dist/plugin/app/src/plugin/app/utils/event-listener-utils.d.ts +3 -0
  24. package/dist/plugin/app/src/plugin/platform/cores/platform.d.ts +3 -0
  25. package/dist/plugin/app/src/plugin/platform/index.d.ts +5 -0
  26. package/dist/plugin/app/src/plugin/platform/types/index.d.ts +1 -0
  27. package/dist/{src → plugin/app/src/plugin/platform}/types/platform.d.ts +1 -1
  28. package/dist/plugin/app/src/plugin/platform/types/platformModule.d.ts +13 -0
  29. package/dist/{src → plugin/app/src/plugin/theme}/constants/theme.d.ts +1 -1
  30. package/dist/plugin/app/src/plugin/theme/cores/theme.d.ts +3 -0
  31. package/dist/plugin/app/src/plugin/theme/index.d.ts +5 -0
  32. package/dist/plugin/app/src/plugin/theme/types/color.d.ts +17 -0
  33. package/dist/{src → plugin/app/src/plugin/theme}/types/easing-syntax.d.ts +1 -1
  34. package/dist/plugin/app/src/plugin/theme/types/index.d.ts +3 -0
  35. package/dist/{src → plugin/app/src/plugin/theme}/types/theme.d.ts +4 -4
  36. package/dist/plugin/app/src/plugin/theme/types/themeModule.d.ts +24 -0
  37. package/dist/{src → plugin/app/src/plugin/theme}/utils/parse-color.d.ts +1 -1
  38. package/dist/{src → plugin/app/src/plugin/theme}/utils/parse-easing-function.d.ts +1 -1
  39. package/dist/plugin/app/src/types/index.d.ts +1 -0
  40. package/dist/plugin/app/src/types/native.d.ts +14 -0
  41. package/dist/plugin/app/src/utils/assign.d.ts +1 -0
  42. package/dist/plugin/app/src/utils/create-custom-error.d.ts +1 -0
  43. package/dist/plugin/platform/index.cjs +171 -0
  44. package/dist/plugin/platform/index.d.ts +51 -0
  45. package/dist/plugin/platform/index.min.cjs +1 -0
  46. package/dist/plugin/platform/index.min.mjs +1 -0
  47. package/dist/plugin/platform/index.mjs +169 -0
  48. package/dist/plugin/platform/index.umd.js +177 -0
  49. package/dist/plugin/platform/index.umd.min.js +1 -0
  50. package/dist/plugin/platform/src/constants/platform.d.ts +35 -0
  51. package/dist/plugin/platform/src/constants/user-agent.d.ts +1 -0
  52. package/dist/plugin/platform/src/plugin/app/constants/app.d.ts +13 -0
  53. package/dist/plugin/platform/src/plugin/app/cores/app.d.ts +3 -0
  54. package/dist/plugin/platform/src/plugin/app/errors/url-open-error.d.ts +2 -0
  55. package/dist/plugin/platform/src/plugin/app/index.d.ts +5 -0
  56. package/dist/plugin/platform/src/plugin/app/types/app.d.ts +54 -0
  57. package/dist/plugin/platform/src/plugin/app/types/appModule.d.ts +54 -0
  58. package/dist/plugin/platform/src/plugin/app/types/index.d.ts +1 -0
  59. package/dist/plugin/platform/src/plugin/app/utils/event-listener-utils.d.ts +3 -0
  60. package/dist/plugin/platform/src/plugin/app/utils/try-open-url.d.ts +1 -0
  61. package/dist/plugin/platform/src/plugin/platform/cores/platform.d.ts +3 -0
  62. package/dist/plugin/platform/src/plugin/platform/index.d.ts +5 -0
  63. package/dist/plugin/platform/src/plugin/platform/types/index.d.ts +1 -0
  64. package/dist/plugin/platform/src/plugin/platform/types/platform.d.ts +13 -0
  65. package/dist/plugin/platform/src/plugin/platform/types/platformModule.d.ts +13 -0
  66. package/dist/plugin/platform/src/plugin/theme/constants/theme.d.ts +16 -0
  67. package/dist/plugin/platform/src/plugin/theme/cores/theme.d.ts +3 -0
  68. package/dist/plugin/platform/src/plugin/theme/errors/easing-error.d.ts +6 -0
  69. package/dist/plugin/platform/src/plugin/theme/errors/unsupported-color-error.d.ts +2 -0
  70. package/dist/plugin/platform/src/plugin/theme/index.d.ts +5 -0
  71. package/dist/plugin/platform/src/plugin/theme/types/color.d.ts +17 -0
  72. package/dist/plugin/platform/src/plugin/theme/types/easing-syntax.d.ts +16 -0
  73. package/dist/plugin/platform/src/plugin/theme/types/index.d.ts +3 -0
  74. package/dist/plugin/platform/src/plugin/theme/types/theme.d.ts +24 -0
  75. package/dist/plugin/platform/src/plugin/theme/types/themeModule.d.ts +24 -0
  76. package/dist/plugin/platform/src/plugin/theme/utils/parse-color.d.ts +2 -0
  77. package/dist/plugin/platform/src/plugin/theme/utils/parse-easing-function.d.ts +2 -0
  78. package/dist/plugin/platform/src/types/index.d.ts +1 -0
  79. package/dist/plugin/platform/src/types/native.d.ts +14 -0
  80. package/dist/plugin/platform/src/utils/assign.d.ts +1 -0
  81. package/dist/plugin/platform/src/utils/create-custom-error.d.ts +1 -0
  82. package/dist/plugin/theme/index.cjs +810 -0
  83. package/dist/plugin/theme/index.d.ts +75 -0
  84. package/dist/plugin/theme/index.min.cjs +1 -0
  85. package/dist/plugin/theme/index.min.mjs +1 -0
  86. package/dist/plugin/theme/index.mjs +808 -0
  87. package/dist/plugin/theme/index.umd.js +816 -0
  88. package/dist/plugin/theme/index.umd.min.js +1 -0
  89. package/dist/plugin/theme/src/constants/platform.d.ts +35 -0
  90. package/dist/plugin/theme/src/constants/user-agent.d.ts +1 -0
  91. package/dist/plugin/theme/src/plugin/app/constants/app.d.ts +13 -0
  92. package/dist/plugin/theme/src/plugin/app/cores/app.d.ts +3 -0
  93. package/dist/plugin/theme/src/plugin/app/errors/url-open-error.d.ts +2 -0
  94. package/dist/plugin/theme/src/plugin/app/index.d.ts +5 -0
  95. package/dist/plugin/theme/src/plugin/app/types/app.d.ts +54 -0
  96. package/dist/plugin/theme/src/plugin/app/types/appModule.d.ts +54 -0
  97. package/dist/plugin/theme/src/plugin/app/types/index.d.ts +1 -0
  98. package/dist/plugin/theme/src/plugin/app/utils/event-listener-utils.d.ts +3 -0
  99. package/dist/plugin/theme/src/plugin/app/utils/try-open-url.d.ts +1 -0
  100. package/dist/plugin/theme/src/plugin/platform/cores/platform.d.ts +3 -0
  101. package/dist/plugin/theme/src/plugin/platform/index.d.ts +5 -0
  102. package/dist/plugin/theme/src/plugin/platform/types/index.d.ts +1 -0
  103. package/dist/plugin/theme/src/plugin/platform/types/platform.d.ts +13 -0
  104. package/dist/plugin/theme/src/plugin/platform/types/platformModule.d.ts +13 -0
  105. package/dist/plugin/theme/src/plugin/theme/constants/theme.d.ts +16 -0
  106. package/dist/plugin/theme/src/plugin/theme/cores/theme.d.ts +3 -0
  107. package/dist/plugin/theme/src/plugin/theme/errors/easing-error.d.ts +6 -0
  108. package/dist/plugin/theme/src/plugin/theme/errors/unsupported-color-error.d.ts +2 -0
  109. package/dist/plugin/theme/src/plugin/theme/index.d.ts +5 -0
  110. package/dist/plugin/theme/src/plugin/theme/types/color.d.ts +17 -0
  111. package/dist/plugin/theme/src/plugin/theme/types/easing-syntax.d.ts +16 -0
  112. package/dist/plugin/theme/src/plugin/theme/types/index.d.ts +3 -0
  113. package/dist/plugin/theme/src/plugin/theme/types/theme.d.ts +24 -0
  114. package/dist/plugin/theme/src/plugin/theme/types/themeModule.d.ts +24 -0
  115. package/dist/plugin/theme/src/plugin/theme/utils/parse-color.d.ts +2 -0
  116. package/dist/plugin/theme/src/plugin/theme/utils/parse-easing-function.d.ts +2 -0
  117. package/dist/plugin/theme/src/types/index.d.ts +1 -0
  118. package/dist/plugin/theme/src/types/native.d.ts +14 -0
  119. package/dist/plugin/theme/src/utils/assign.d.ts +1 -0
  120. package/dist/plugin/theme/src/utils/create-custom-error.d.ts +1 -0
  121. package/dist/src/plugin/app/constants/app.d.ts +13 -0
  122. package/dist/src/plugin/app/cores/app.d.ts +3 -0
  123. package/dist/src/plugin/app/errors/url-open-error.d.ts +2 -0
  124. package/dist/src/plugin/app/index.d.ts +5 -0
  125. package/dist/src/plugin/app/types/app.d.ts +54 -0
  126. package/dist/src/plugin/app/types/appModule.d.ts +54 -0
  127. package/dist/src/plugin/app/types/index.d.ts +1 -0
  128. package/dist/src/plugin/app/utils/event-listener-utils.d.ts +3 -0
  129. package/dist/src/plugin/app/utils/try-open-url.d.ts +1 -0
  130. package/dist/src/plugin/platform/cores/platform.d.ts +3 -0
  131. package/dist/src/plugin/platform/index.d.ts +5 -0
  132. package/dist/src/plugin/platform/types/index.d.ts +1 -0
  133. package/dist/src/plugin/platform/types/platform.d.ts +13 -0
  134. package/dist/src/plugin/platform/types/platformModule.d.ts +13 -0
  135. package/dist/src/plugin/theme/constants/theme.d.ts +16 -0
  136. package/dist/src/plugin/theme/cores/theme.d.ts +3 -0
  137. package/dist/src/plugin/theme/errors/easing-error.d.ts +6 -0
  138. package/dist/src/plugin/theme/errors/unsupported-color-error.d.ts +2 -0
  139. package/dist/src/plugin/theme/index.d.ts +5 -0
  140. package/dist/src/plugin/theme/types/color.d.ts +17 -0
  141. package/dist/src/plugin/theme/types/easing-syntax.d.ts +16 -0
  142. package/dist/src/plugin/theme/types/index.d.ts +3 -0
  143. package/dist/src/plugin/theme/types/theme.d.ts +24 -0
  144. package/dist/src/plugin/theme/types/themeModule.d.ts +24 -0
  145. package/dist/src/plugin/theme/utils/parse-color.d.ts +2 -0
  146. package/dist/src/plugin/theme/utils/parse-easing-function.d.ts +2 -0
  147. package/dist/src/types/index.d.ts +1 -5
  148. package/dist/src/types/native.d.ts +14 -0
  149. package/dist/src/utils/assign.d.ts +1 -0
  150. package/package.json +8 -5
  151. package/dist/src/cores/app.d.ts +0 -3
  152. package/dist/src/cores/platform.d.ts +0 -3
  153. package/dist/src/cores/theme.d.ts +0 -3
  154. package/dist/src/types/app.d.ts +0 -44
  155. package/dist/src/types/color.d.ts +0 -17
  156. package/dist/src/utils/freeze-deep.d.ts +0 -1
  157. /package/dist/{src → plugin/app/src/plugin/app}/constants/app.d.ts +0 -0
  158. /package/dist/{src → plugin/app/src/plugin/app}/errors/url-open-error.d.ts +0 -0
  159. /package/dist/{src → plugin/app/src/plugin/app}/utils/try-open-url.d.ts +0 -0
  160. /package/dist/{src → plugin/app/src/plugin/theme}/errors/easing-error.d.ts +0 -0
  161. /package/dist/{src → plugin/app/src/plugin/theme}/errors/unsupported-color-error.d.ts +0 -0
@@ -0,0 +1,810 @@
1
+ 'use strict';
2
+
3
+ var USER_AGENT = navigator.userAgent;
4
+
5
+ var Appearances;
6
+ (function (Appearances) {
7
+ Appearances["Unknown"] = "unknown";
8
+ Appearances["Light"] = "light";
9
+ Appearances["Dark"] = "dark";
10
+ })(Appearances || (Appearances = {}));
11
+ var CHROME_VERSION = (function getChromeVersion() {
12
+ var matched = USER_AGENT.match(/chrome\/([\w.]+) mobile/i);
13
+ if (matched === null)
14
+ return NaN;
15
+ var version = parseInt(matched[1]);
16
+ if (isNaN(version))
17
+ return NaN;
18
+ return version;
19
+ })();
20
+ var MEDIA_QUERY_LIST = window.matchMedia('(prefers-color-scheme: dark)');
21
+ var SUPPORT_PREFERS_COLOR_SCHEME = MEDIA_QUERY_LIST.media !== 'not all';
22
+ var IS_FULL_SUPPORT_THEME_COLOR = isNaN(CHROME_VERSION) || CHROME_VERSION >= 92;
23
+ var CONTEXT = document.createElement('canvas').getContext('2d', { willReadFrequently: true });
24
+ var SVG_PIXEL_DATA_URL = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxIiBoZWlnaHQ9IjEiIGZpbGw9IndoaXRlIi8+PC9zdmc+';
25
+ var IS_SAMSUNG = /Samsung/i.test(USER_AGENT);
26
+ var IS_IE_MOBILE = /iemobile/i.test(USER_AGENT);
27
+ var IS_WINDOWS_PHONE = /windows phone/i.test(USER_AGENT);
28
+ var ENTRIES = [];
29
+
30
+ /******************************************************************************
31
+ Copyright (c) Microsoft Corporation.
32
+
33
+ Permission to use, copy, modify, and/or distribute this software for any
34
+ purpose with or without fee is hereby granted.
35
+
36
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
37
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
38
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
39
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
40
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
41
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
42
+ PERFORMANCE OF THIS SOFTWARE.
43
+ ***************************************************************************** */
44
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
45
+
46
+
47
+ function __values(o) {
48
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
49
+ if (m) return m.call(o);
50
+ if (o && typeof o.length === "number") return {
51
+ next: function () {
52
+ if (o && i >= o.length) o = void 0;
53
+ return { value: o && o[i++], done: !o };
54
+ }
55
+ };
56
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
57
+ }
58
+
59
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
60
+ var e = new Error(message);
61
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
62
+ };
63
+
64
+ function createCustomError(name, Base) {
65
+ if (Base === void 0) { Base = Error; }
66
+ function CustomError(message) {
67
+ if (!(this instanceof CustomError))
68
+ return new CustomError(message);
69
+ var error = new Base(message || '');
70
+ if (typeof Object.setPrototypeOf === 'function')
71
+ Object.setPrototypeOf(error, CustomError.prototype);
72
+ else
73
+ error.__proto__ = CustomError.prototype;
74
+ error.name = name;
75
+ if (message !== undefined)
76
+ error.message = message;
77
+ if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {
78
+ try {
79
+ Object.defineProperty(error, Symbol.toStringTag, {
80
+ value: name,
81
+ writable: false,
82
+ enumerable: false,
83
+ configurable: true
84
+ });
85
+ }
86
+ catch (_) {
87
+ }
88
+ }
89
+ if (typeof Error.captureStackTrace === 'function') {
90
+ Error.captureStackTrace(error, CustomError);
91
+ }
92
+ else if (Base.captureStackTrace && typeof Base.captureStackTrace === 'function') {
93
+ Base.captureStackTrace(error, CustomError);
94
+ }
95
+ else {
96
+ try {
97
+ var tempError = new Base();
98
+ if (tempError.stack)
99
+ error.stack = tempError.stack;
100
+ }
101
+ catch (_) {
102
+ }
103
+ }
104
+ return error;
105
+ }
106
+ CustomError.prototype = Object.create(Base.prototype, {
107
+ constructor: {
108
+ value: CustomError,
109
+ writable: true,
110
+ enumerable: false,
111
+ configurable: true
112
+ }
113
+ });
114
+ try {
115
+ Object.defineProperty(CustomError.prototype, 'name', {
116
+ value: name,
117
+ writable: true,
118
+ enumerable: false,
119
+ configurable: true
120
+ });
121
+ }
122
+ catch (_) {
123
+ try {
124
+ CustomError.prototype.name = name;
125
+ }
126
+ catch (_) {
127
+ }
128
+ }
129
+ try {
130
+ Object.defineProperty(CustomError, 'name', {
131
+ value: name,
132
+ writable: false,
133
+ enumerable: false,
134
+ configurable: true
135
+ });
136
+ }
137
+ catch (_) {
138
+ }
139
+ return CustomError;
140
+ }
141
+
142
+ var EasingError = createCustomError('EasingError');
143
+ var CubicBezierSyntaxError = createCustomError('CubicBezierSyntaxError', EasingError);
144
+ var LinearSyntaxError = createCustomError('LinearSyntaxError', EasingError);
145
+ var StepSyntaxError = createCustomError('StepSyntaxError', EasingError);
146
+ var UnsupportedEasingFunctionError = createCustomError('UnsupportedEasingFunctionError', EasingError);
147
+
148
+ var EASING_KEYWORD = {
149
+ 'linear': 'linear(0, 1)',
150
+ 'ease': 'cubic-bezier(0.25, 0.1, 0.25, 1)',
151
+ 'ease-in': 'cubic-bezier(0.42, 0, 1, 1)',
152
+ 'ease-out': 'cubic-bezier(0, 0, 0.58, 1)',
153
+ 'ease-in-out': 'cubic-bezier(0.42, 0, 0.58, 1)',
154
+ 'step-start': 'steps(1, jump-start)',
155
+ 'step-end': 'steps(1, jump-end)',
156
+ };
157
+ function clamp(n, min, max) {
158
+ if (n < min)
159
+ return min;
160
+ if (n > max)
161
+ return max;
162
+ return n;
163
+ }
164
+ function isEasingKeyword(easingFunction) {
165
+ return !/(linear|cubic-bezier|steps)\((.*)\)/.test(easingFunction);
166
+ }
167
+ function isCubicBezierString(easingFunction) {
168
+ return /cubic-bezier\(/.test(easingFunction);
169
+ }
170
+ function isLinearString(easingFunction) {
171
+ return /linear\(/.test(easingFunction);
172
+ }
173
+ function isStepString(easingFunction) {
174
+ return /steps\(\s*(\d+)\s*(?:,\s*(jump-start|jump-end|jump-none|jump-both|start|end)\s*)?\)$/.test(easingFunction);
175
+ }
176
+ function parseCubicBezier(easingFunction) {
177
+ var match = easingFunction.match(/cubic-bezier\((.*)\)/);
178
+ if (match === null)
179
+ throw new CubicBezierSyntaxError('Invalid cubic-bezier syntax');
180
+ var content = match[1].trim();
181
+ var split = content.split(',');
182
+ var values = [];
183
+ if (split.length !== 4)
184
+ throw new CubicBezierSyntaxError('Cubic-bezier must have exactly 4 numeric values');
185
+ for (var i = 0; i < 4; i++) {
186
+ var value = parseFloat(split[i]);
187
+ if (isNaN(value))
188
+ throw new CubicBezierSyntaxError('Cubic-bezier must have exactly 4 numeric values');
189
+ if (i % 2 === 0 && (value < 0 || value > 1))
190
+ throw new CubicBezierSyntaxError('x1 and x2 must be between 0 and 1');
191
+ values.push(value);
192
+ }
193
+ return {
194
+ x1: values[0],
195
+ y1: values[1],
196
+ x2: values[2],
197
+ y2: values[3]
198
+ };
199
+ }
200
+ function getCubicBezierValue(easingFunction) {
201
+ var cubicBezier = parseCubicBezier(easingFunction);
202
+ var x1 = cubicBezier.x1;
203
+ var x2 = cubicBezier.x2;
204
+ var y1 = cubicBezier.y1;
205
+ var y2 = cubicBezier.y2;
206
+ function findT(x, tolerance, maxIterations) {
207
+ if (tolerance === void 0) { tolerance = 1e-6; }
208
+ if (maxIterations === void 0) { maxIterations = 50; }
209
+ if (x <= 0)
210
+ return 0;
211
+ if (x >= 1)
212
+ return 1;
213
+ var t = x;
214
+ for (var i = 0; i < maxIterations; i++) {
215
+ var xt = 3 * (1 - t) * (1 - t) * t * x1 + 3 * (1 - t) * t * t * x2 + t * t * t;
216
+ var dx = 3 * (1 - t) * (1 - t) * x1 + 6 * (1 - t) * t * (x2 - x1) + 3 * t * t * (1 - x2);
217
+ if (Math.abs(dx) < tolerance)
218
+ break;
219
+ var newT = t - (xt - x) / dx;
220
+ if (Math.abs(newT - t) < tolerance) {
221
+ t = newT;
222
+ break;
223
+ }
224
+ t = Math.max(0, Math.min(1, newT));
225
+ }
226
+ return t;
227
+ }
228
+ return function (x) {
229
+ x = clamp(x, 0, 1);
230
+ if (x === 0 || x === 1)
231
+ return x;
232
+ var t = findT(x);
233
+ return 3 * (1 - t) * (1 - t) * t * y1 + 3 * (1 - t) * t * t * y2 + t * t * t;
234
+ };
235
+ }
236
+ function parseLinear(easingFunction) {
237
+ var e_1, _a;
238
+ var match = easingFunction.match(/linear\((.*)\)/);
239
+ if (match === null)
240
+ throw new LinearSyntaxError('Invalid linear syntax');
241
+ var content = match[1].trim();
242
+ if (content === '')
243
+ throw new LinearSyntaxError('Linear function must have at least one point');
244
+ var split = content.split(',');
245
+ var points = [];
246
+ for (var i = 0; i < split.length; i++) {
247
+ var part = split[i].trim();
248
+ var percentage2 = part.match(/^([+-]?\d*\.?\d+)((?:\s+[+-]?\d*\.?\d+%){2,})$/);
249
+ if (percentage2 !== null) {
250
+ var value = parseFloat(percentage2[1]);
251
+ var percents = percentage2[2].trim().split(/\s+/);
252
+ try {
253
+ for (var percents_1 = (e_1 = void 0, __values(percents)), percents_1_1 = percents_1.next(); !percents_1_1.done; percents_1_1 = percents_1.next()) {
254
+ var percent = percents_1_1.value;
255
+ points.push({
256
+ value: value,
257
+ position: parseFloat(percent) / 100,
258
+ });
259
+ }
260
+ }
261
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
262
+ finally {
263
+ try {
264
+ if (percents_1_1 && !percents_1_1.done && (_a = percents_1.return)) _a.call(percents_1);
265
+ }
266
+ finally { if (e_1) throw e_1.error; }
267
+ }
268
+ continue;
269
+ }
270
+ var percentage1 = part.match(/^([+-]?\d*\.?\d+)\s+([+-]?\d*\.?\d+)%$/);
271
+ if (percentage1 !== null) {
272
+ points.push({
273
+ position: parseFloat(percentage1[2]) / 100,
274
+ value: parseFloat(percentage1[1])
275
+ });
276
+ continue;
277
+ }
278
+ var number = part.match(/^([+-]?\d*\.?\d+)$/);
279
+ if (number !== null) {
280
+ points.push({
281
+ position: split.length === 1 ? 0 : i / (split.length - 1),
282
+ value: parseFloat(number[1])
283
+ });
284
+ continue;
285
+ }
286
+ throw new LinearSyntaxError('Invalid linear point format: \"' + part + '\"');
287
+ }
288
+ if (points.length === 0)
289
+ throw new LinearSyntaxError('No valid points found in linear function');
290
+ points.sort(function (a, b) { return a.position - b.position; });
291
+ if (points[0].position > 0)
292
+ points.unshift({ position: 0, value: 0 });
293
+ if (points[points.length - 1].position < 1)
294
+ points.push({ position: 1, value: 1 });
295
+ return points;
296
+ }
297
+ function getLinearValue(str) {
298
+ var points = parseLinear(str);
299
+ return function (t) {
300
+ t = clamp(t, 0, 1);
301
+ if (t <= points[0].position)
302
+ return points[0].value;
303
+ if (t >= points[points.length - 1].position)
304
+ return points[points.length - 1].value;
305
+ for (var i = 0; i < points.length - 1; i++) {
306
+ var p1 = points[i];
307
+ var p2 = points[i + 1];
308
+ if (t >= p1.position && t <= p2.position) {
309
+ if (p1.position === p2.position)
310
+ return p2.value;
311
+ var ratio = (t - p1.position) / (p2.position - p1.position);
312
+ return p1.value + (p2.value - p1.value) * ratio;
313
+ }
314
+ }
315
+ return points[points.length - 1].value;
316
+ };
317
+ }
318
+ function getStepValue(easingFunction) {
319
+ var match = easingFunction.match(/steps\(\s*(\d+)\s*(?:,\s*(jump-start|jump-end|jump-none|jump-both|start|end)\s*)?\)$/);
320
+ if (match === null)
321
+ throw new StepSyntaxError('Invalid steps syntax');
322
+ var count = parseInt(match[1], 10);
323
+ var position = match[2];
324
+ if (count <= 0)
325
+ throw new StepSyntaxError('Steps count must be a positive integer');
326
+ if (position === 'jump-none' && count < 2)
327
+ throw new StepSyntaxError('jump-none requires at least 2 steps');
328
+ return function (t) {
329
+ t = clamp(t, 0, 1);
330
+ switch (position) {
331
+ case 'start':
332
+ case 'jump-start':
333
+ if (t === 0)
334
+ return 1 / count;
335
+ if (t === 1)
336
+ return 1;
337
+ return Math.ceil(t * count) / count;
338
+ case undefined:
339
+ case 'end':
340
+ case 'jump-end':
341
+ if (t === 1)
342
+ return 1;
343
+ return Math.floor(t * count) / count;
344
+ case 'jump-both':
345
+ if (t === 0)
346
+ return 0;
347
+ if (t === 1)
348
+ return 1;
349
+ return Math.round(t * (count + 1)) / (count + 1);
350
+ case 'jump-none':
351
+ if (t === 0)
352
+ return 0;
353
+ if (t === 1)
354
+ return 1;
355
+ return Math.floor(t * (count - 1)) / (count - 1);
356
+ default:
357
+ throw new StepSyntaxError('Unsupported step position: \"' + position + '\"');
358
+ }
359
+ };
360
+ }
361
+ function parseEasingFunction(easingFunction) {
362
+ if (isEasingKeyword(easingFunction))
363
+ easingFunction = EASING_KEYWORD[easingFunction];
364
+ if (isCubicBezierString(easingFunction))
365
+ return getCubicBezierValue(easingFunction);
366
+ if (isLinearString(easingFunction))
367
+ return getLinearValue(easingFunction);
368
+ if (isStepString(easingFunction))
369
+ return getStepValue(easingFunction);
370
+ throw new UnsupportedEasingFunctionError('Unsupported easing function: \"' + easingFunction + '\"');
371
+ }
372
+
373
+ var UnsupportedColorError = createCustomError('UnsupportedColorError');
374
+
375
+ function parseColor(color) {
376
+ if (typeof CSS !== 'undefined' && CSS.supports && !CSS.supports('color', color))
377
+ throw new UnsupportedColorError('Unsupported color: \"' + color + '\".');
378
+ if (CONTEXT !== null) {
379
+ try {
380
+ CONTEXT.clearRect(0, 0, 1, 1);
381
+ CONTEXT.fillStyle = color;
382
+ CONTEXT.fillRect(0, 0, 1, 1);
383
+ var data = CONTEXT.getImageData(0, 0, 1, 1).data;
384
+ return {
385
+ red: data[0],
386
+ green: data[1],
387
+ blue: data[2],
388
+ alpha: parseFloat((data[3] / 255).toFixed(2))
389
+ };
390
+ }
391
+ catch (_) {
392
+ }
393
+ }
394
+ var div = document.createElement('div');
395
+ div.style.position = 'absolute';
396
+ div.style.top = '-9999px';
397
+ div.style.left = '-9999px';
398
+ div.style.width = '1px';
399
+ div.style.height = '1px';
400
+ div.style.color = color;
401
+ document.body.appendChild(div);
402
+ try {
403
+ var computedColor = window.getComputedStyle(div).color;
404
+ var legacyMatch = computedColor.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/);
405
+ var modernMatch = computedColor.match(/rgba?\(\s*(\d+)\s+(\d+)\s+(\d+)\s*(?:\/\s*([\d.]+%?))?\s*\)/);
406
+ var matched = legacyMatch || modernMatch;
407
+ if (matched === null)
408
+ throw new UnsupportedColorError('Unsupported color: \"' + color + '\".');
409
+ var red = parseInt(matched[1], 10);
410
+ var green = parseInt(matched[2], 10);
411
+ var blue = parseInt(matched[3], 10);
412
+ var alpha = 1;
413
+ if (matched[4] !== undefined) {
414
+ var alphaStr = matched[4];
415
+ if (alphaStr.charAt(alphaStr.length - 1) === '%')
416
+ alpha = parseFloat((parseFloat(alphaStr) / 100).toFixed(2));
417
+ else
418
+ alpha = parseFloat(parseFloat(alphaStr).toFixed(2));
419
+ }
420
+ if (isNaN(red) || isNaN(green) || isNaN(blue) || isNaN(alpha))
421
+ throw new UnsupportedColorError('Failed to parse color values from: \"' + color + '\".');
422
+ return {
423
+ red: red,
424
+ green: green,
425
+ blue: blue,
426
+ alpha: alpha
427
+ };
428
+ }
429
+ finally {
430
+ document.body.removeChild(div);
431
+ }
432
+ }
433
+
434
+ var themeColorMetaGroup = {};
435
+ var themeIntervalId = null;
436
+ var currentResolve = null;
437
+ var currentAppearance = null;
438
+ var appearanceIntervalId = null;
439
+ var Theme = {
440
+ setThemeColor: setThemeColor,
441
+ getThemeColor: getThemeColor,
442
+ removeThemeColor: removeThemeColor,
443
+ detectAppearance: detectAppearance,
444
+ onAppearanceChange: onAppearanceChange,
445
+ };
446
+ function getThemeColorMeta(appearance) {
447
+ if (appearance === void 0) { appearance = 'default'; }
448
+ var effective;
449
+ if (!IS_FULL_SUPPORT_THEME_COLOR || !SUPPORT_PREFERS_COLOR_SCHEME || IS_IE_MOBILE || IS_WINDOWS_PHONE)
450
+ effective = 'default';
451
+ else
452
+ effective = appearance;
453
+ var meta = themeColorMetaGroup[effective];
454
+ if (meta !== undefined)
455
+ return meta;
456
+ meta = document.createElement('meta');
457
+ if (IS_IE_MOBILE)
458
+ meta.setAttribute('name', 'msapplication-navbutton-color');
459
+ else if (IS_WINDOWS_PHONE)
460
+ meta.setAttribute('name', 'msapplication-TileColor');
461
+ else
462
+ meta.setAttribute('name', 'theme-color');
463
+ if (appearance !== 'default')
464
+ meta.setAttribute('media', '(prefers-color-scheme: ' + effective + ')');
465
+ document.head.prepend(meta);
466
+ return themeColorMetaGroup[appearance] = meta;
467
+ }
468
+ function estimateDefaultThemeColor() {
469
+ if (/version\/[\w.,]+ .*safari/i.test(USER_AGENT)) {
470
+ if (navigator.standalone) {
471
+ if (detectFromMediaQuery() === Appearances.Dark)
472
+ return '#ffffffff';
473
+ else
474
+ return '#000000ff';
475
+ }
476
+ return rgbaToHex(parseColor(window.getComputedStyle(document.body).backgroundColor));
477
+ }
478
+ if (/\b(?:crmo|crios)\/[\w.]+/i.test(USER_AGENT) || /chrome\/[\w.]+ mobile/i.test(USER_AGENT)) {
479
+ if (detectFromMediaQuery() === Appearances.Dark)
480
+ return '#28292cff';
481
+ else
482
+ return '#ffffffff';
483
+ }
484
+ return undefined;
485
+ }
486
+ function toHex(n) {
487
+ var hex = n.toString(16);
488
+ switch (hex.length) {
489
+ case 0: return '00';
490
+ case 1: return '0' + hex;
491
+ default: return hex;
492
+ }
493
+ }
494
+ function rgbaToHex(rgba) {
495
+ return '#'
496
+ + toHex(rgba.red)
497
+ + toHex(rgba.green)
498
+ + toHex(rgba.blue)
499
+ + toHex(Math.round(rgba.alpha * 255));
500
+ }
501
+ function detectFromEngine() {
502
+ return new Promise(function (resolve) {
503
+ var img = new Image();
504
+ img.onload = function () {
505
+ if (CONTEXT === null)
506
+ return resolve(Appearances.Light);
507
+ CONTEXT.drawImage(img, 0, 0);
508
+ var data = CONTEXT.getImageData(0, 0, 1, 1).data;
509
+ if ((data[0] & data[1] & data[2]) < 255)
510
+ resolve(Appearances.Dark);
511
+ else
512
+ resolve(Appearances.Light);
513
+ };
514
+ img.onerror = function () {
515
+ resolve(Appearances.Unknown);
516
+ };
517
+ img.src = SVG_PIXEL_DATA_URL;
518
+ });
519
+ }
520
+ function detectFromMediaQuery() {
521
+ if (!SUPPORT_PREFERS_COLOR_SCHEME)
522
+ return Appearances.Unknown;
523
+ if (MEDIA_QUERY_LIST.matches)
524
+ return Appearances.Dark;
525
+ return Appearances.Light;
526
+ }
527
+ function startPolling() {
528
+ detectFromEngine()
529
+ .then(function (appearance) {
530
+ currentAppearance = appearance;
531
+ });
532
+ appearanceIntervalId = window.setInterval(function () {
533
+ detectFromEngine()
534
+ .then(function (appearance) {
535
+ if (appearance !== currentAppearance) {
536
+ currentAppearance = appearance;
537
+ notify(appearance);
538
+ }
539
+ });
540
+ }, 2000);
541
+ }
542
+ function stopPolling() {
543
+ currentAppearance = null;
544
+ if (appearanceIntervalId !== null) {
545
+ clearInterval(appearanceIntervalId);
546
+ appearanceIntervalId = null;
547
+ }
548
+ }
549
+ function addListener(capture) {
550
+ currentAppearance = detectFromMediaQuery();
551
+ if (typeof MEDIA_QUERY_LIST.addEventListener === 'function')
552
+ MEDIA_QUERY_LIST.addEventListener('change', onMediaChange, capture);
553
+ else if (typeof MEDIA_QUERY_LIST.addListener === 'function')
554
+ MEDIA_QUERY_LIST.addListener(onMediaChange);
555
+ }
556
+ function removeListener(capture) {
557
+ currentAppearance = null;
558
+ if (typeof MEDIA_QUERY_LIST.removeEventListener === 'function')
559
+ MEDIA_QUERY_LIST.removeEventListener('change', onMediaChange, capture);
560
+ else if (typeof MEDIA_QUERY_LIST.removeListener === 'function')
561
+ MEDIA_QUERY_LIST.removeListener(onMediaChange);
562
+ }
563
+ function onMediaChange(ev) {
564
+ var appearance;
565
+ if (ev.matches)
566
+ appearance = Appearances.Dark;
567
+ else
568
+ appearance = Appearances.Light;
569
+ if (appearance !== currentAppearance)
570
+ notify(currentAppearance = appearance);
571
+ }
572
+ function notify(appearance) {
573
+ for (var i = 0; i < ENTRIES.length; i++) {
574
+ var entry = ENTRIES[i];
575
+ entry.fn(appearance);
576
+ if (entry.once)
577
+ removeEntry(entry);
578
+ }
579
+ }
580
+ function removeEntry(entry) {
581
+ var index = indexOfEntry(entry);
582
+ if (index !== -1)
583
+ ENTRIES.splice(index, 1);
584
+ if (ENTRIES.length === 0) {
585
+ if (IS_SAMSUNG)
586
+ stopPolling();
587
+ else
588
+ removeListener(entry.capture);
589
+ }
590
+ }
591
+ function indexOfEntry(entry) {
592
+ for (var i = 0; i < ENTRIES.length; i++)
593
+ if (ENTRIES[i].fn === entry.fn && ENTRIES[i].capture === entry.capture)
594
+ return i;
595
+ return -1;
596
+ }
597
+ function syncThemeColorMeta() {
598
+ themeColorMetaGroup = {};
599
+ var selector;
600
+ if (IS_IE_MOBILE)
601
+ selector = 'meta[name=\"msapplication-navbutton-color\"]';
602
+ else if (IS_WINDOWS_PHONE)
603
+ selector = 'meta[name=\"msapplication-TileColor\"]';
604
+ else
605
+ selector = 'meta[name=\"theme-color\"]';
606
+ var nodes = document.querySelectorAll(selector);
607
+ if (!IS_FULL_SUPPORT_THEME_COLOR || !SUPPORT_PREFERS_COLOR_SCHEME || IS_IE_MOBILE || IS_WINDOWS_PHONE) {
608
+ themeColorMetaGroup.default = nodes[0];
609
+ return;
610
+ }
611
+ for (var i = 0; i < nodes.length; i++) {
612
+ var element = nodes.item(i);
613
+ var media = element.getAttribute('media');
614
+ if (media === '(prefers-color-scheme: dark)' && themeColorMetaGroup.dark === undefined)
615
+ themeColorMetaGroup.dark = element;
616
+ else if (media === '(prefers-color-scheme: light)' && themeColorMetaGroup.light === undefined)
617
+ themeColorMetaGroup.light = element;
618
+ else if (media === null && themeColorMetaGroup.default === undefined)
619
+ themeColorMetaGroup.default = element;
620
+ if (themeColorMetaGroup.dark !== undefined && themeColorMetaGroup.light !== undefined && themeColorMetaGroup.default !== undefined)
621
+ return;
622
+ }
623
+ }
624
+ function getCurrentAppliedThemeColorMeta() {
625
+ if (IS_IE_MOBILE)
626
+ return document.querySelector('meta[name=\"msapplication-navbutton-color\"]');
627
+ if (IS_WINDOWS_PHONE)
628
+ return document.querySelector('meta[name=\"msapplication-TileColor\"]');
629
+ if (!IS_FULL_SUPPORT_THEME_COLOR || !SUPPORT_PREFERS_COLOR_SCHEME)
630
+ return document.querySelector('meta[name=\"theme-color\"]');
631
+ var nodes = document.querySelectorAll('meta[name=\"theme-color\"]');
632
+ var isDark = detectFromMediaQuery() === Appearances.Dark;
633
+ var query;
634
+ if (isDark)
635
+ query = '(prefers-color-scheme: dark)';
636
+ else
637
+ query = '(prefers-color-scheme: light)';
638
+ for (var i = 0; i < nodes.length; i++) {
639
+ var element = nodes.item(i);
640
+ if (!element.hasAttribute('content'))
641
+ continue;
642
+ var media = element.getAttribute('media');
643
+ if (media === null || media === query)
644
+ return element;
645
+ }
646
+ return null;
647
+ }
648
+ function init() {
649
+ var observer = new MutationObserver(function (mutations) {
650
+ for (var i = 0; i < mutations.length; i++) {
651
+ var mutation = mutations[i];
652
+ var addedNodes = mutation.addedNodes;
653
+ var removedNodes = mutation.removedNodes;
654
+ for (var j = 0; j < addedNodes.length; j++)
655
+ if (addedNodes[j] instanceof HTMLMetaElement)
656
+ return syncThemeColorMeta();
657
+ for (var j = 0; j < removedNodes.length; j++)
658
+ if (removedNodes[j] instanceof HTMLMetaElement)
659
+ return syncThemeColorMeta();
660
+ }
661
+ });
662
+ if (typeof MEDIA_QUERY_LIST.addEventListener === 'function')
663
+ MEDIA_QUERY_LIST.addEventListener('change', syncThemeColorMeta);
664
+ else if (typeof MEDIA_QUERY_LIST.addListener === 'function')
665
+ MEDIA_QUERY_LIST.addListener(syncThemeColorMeta);
666
+ observer.observe(document.head, { childList: true });
667
+ syncThemeColorMeta();
668
+ }
669
+ init();
670
+ function setThemeColor(color, options) {
671
+ if (options === void 0) { options = { duration: 0, easingFunction: 'linear', appearance: 'default' }; }
672
+ var duration = options.duration;
673
+ var easingFn = parseEasingFunction(options.easingFunction);
674
+ var appearance = options.appearance;
675
+ if (themeIntervalId !== null) {
676
+ window.cancelAnimationFrame(themeIntervalId);
677
+ themeIntervalId = null;
678
+ if (currentResolve !== null) {
679
+ currentResolve(getThemeColor());
680
+ currentResolve = null;
681
+ }
682
+ }
683
+ var themeColor = getThemeColor();
684
+ if (themeColor === undefined) {
685
+ if (options.defaultColor !== undefined) {
686
+ themeColor = options.defaultColor;
687
+ }
688
+ else {
689
+ if (detectFromMediaQuery() === Appearances.Dark)
690
+ themeColor = '#181818ff';
691
+ else
692
+ themeColor = '#dcdcdcff';
693
+ }
694
+ }
695
+ var startColor = parseColor(themeColor);
696
+ var endColor = parseColor(color);
697
+ return new Promise(function (resolve) {
698
+ currentResolve = resolve;
699
+ var startTime = null;
700
+ function animate(timestamp) {
701
+ if (startTime === null)
702
+ startTime = timestamp;
703
+ var elapsed = timestamp - startTime;
704
+ var t;
705
+ if (duration === 0)
706
+ t = 1;
707
+ else
708
+ t = Math.min(elapsed / duration, 1);
709
+ var easedT = easingFn(t);
710
+ var current = {
711
+ red: Math.round(startColor.red + (endColor.red - startColor.red) * easedT),
712
+ green: Math.round(startColor.green + (endColor.green - startColor.green) * easedT),
713
+ blue: Math.round(startColor.blue + (endColor.blue - startColor.blue) * easedT),
714
+ alpha: +(startColor.alpha + (endColor.alpha - startColor.alpha) * easedT).toFixed(2),
715
+ };
716
+ getThemeColorMeta(appearance).setAttribute('content', rgbaToHex(current));
717
+ if (t < 1) {
718
+ themeIntervalId = window.requestAnimationFrame(animate);
719
+ }
720
+ else {
721
+ themeIntervalId = null;
722
+ if (currentResolve !== null) {
723
+ resolve(getThemeColor());
724
+ themeIntervalId = null;
725
+ }
726
+ }
727
+ }
728
+ themeIntervalId = window.requestAnimationFrame(animate);
729
+ });
730
+ }
731
+ function getThemeColor() {
732
+ var meta = getCurrentAppliedThemeColorMeta();
733
+ if (meta !== null)
734
+ return meta.getAttribute('content');
735
+ return estimateDefaultThemeColor();
736
+ }
737
+ function removeThemeColor(appearance) {
738
+ if (appearance === void 0) { appearance = 'default'; }
739
+ var meta = themeColorMetaGroup[appearance];
740
+ if (meta !== undefined)
741
+ meta.remove();
742
+ themeColorMetaGroup[appearance] = undefined;
743
+ }
744
+ function detectAppearance() {
745
+ if (IS_SAMSUNG)
746
+ return detectFromEngine();
747
+ else
748
+ return Promise.resolve(detectFromMediaQuery());
749
+ }
750
+ function onAppearanceChange(listener, options) {
751
+ if (options === void 0) { options = false; }
752
+ var entry = { fn: listener, capture: false, once: false };
753
+ if (typeof options === 'boolean')
754
+ options = { capture: options };
755
+ if (options.capture !== undefined)
756
+ entry.capture = options.capture;
757
+ if (options.once !== undefined)
758
+ entry.once = options.once;
759
+ if (options.signal !== undefined)
760
+ entry.signal = options.signal;
761
+ var index = indexOfEntry(entry);
762
+ if (index === -1) {
763
+ ENTRIES.push(entry);
764
+ if (ENTRIES.length === 1) {
765
+ if (IS_SAMSUNG)
766
+ startPolling();
767
+ else
768
+ addListener(entry.capture);
769
+ }
770
+ this.detectAppearance()
771
+ .then(notify);
772
+ }
773
+ else if (ENTRIES[index].once && !entry.once) {
774
+ ENTRIES[index].once = false;
775
+ }
776
+ if (entry.signal !== undefined) {
777
+ if (entry.signal.aborted) {
778
+ removeEntry(entry);
779
+ }
780
+ else {
781
+ entry.signal.addEventListener('abort', function onAbort() {
782
+ if (entry.signal !== undefined)
783
+ entry.signal.removeEventListener('abort', onAbort);
784
+ removeEntry(entry);
785
+ });
786
+ }
787
+ }
788
+ return function () {
789
+ removeEntry(entry);
790
+ };
791
+ }
792
+
793
+ var ThemePlugin = {
794
+ installed: false,
795
+ name: 'Theme',
796
+ module: Theme,
797
+ constants: {
798
+ Appearances: Appearances
799
+ },
800
+ errors: {
801
+ EasingError: EasingError,
802
+ UnsupportedEasingFunctionError: UnsupportedEasingFunctionError,
803
+ StepSyntaxError: StepSyntaxError,
804
+ LinearSyntaxError: LinearSyntaxError,
805
+ CubicBezierSyntaxError: CubicBezierSyntaxError,
806
+ UnsupportedColorError: UnsupportedColorError
807
+ }
808
+ };
809
+
810
+ module.exports = ThemePlugin;