@wiajs/core 1.0.2 → 1.0.4

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/dist/core.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia core v1.0.1
2
+ * wia core v1.0.3
3
3
  * (c) 2015-2023 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
@@ -90,6 +90,750 @@ function objToParam(obj) {
90
90
  return rs;
91
91
  }
92
92
 
93
+ /* eslint-disable */
94
+ function signum(num) {
95
+ return num < 0 ? -1 : 0 === num ? 0 : 1;
96
+ }
97
+
98
+ function lerp(start, stop, amount) {
99
+ return (1 - amount) * start + amount * stop;
100
+ }
101
+
102
+ function clampInt(min, max, input) {
103
+ return input < min ? min : input > max ? max : input;
104
+ }
105
+
106
+ function sanitizeDegreesDouble(degrees) {
107
+ return (degrees %= 360) < 0 && (degrees += 360), degrees;
108
+ }
109
+
110
+ function rotationDirection(from, to) {
111
+ return sanitizeDegreesDouble(to - from) <= 180 ? 1 : -1;
112
+ }
113
+
114
+ function differenceDegrees(a, b) {
115
+ return 180 - Math.abs(Math.abs(a - b) - 180);
116
+ }
117
+
118
+ function matrixMultiply(row, matrix) {
119
+ return [ row[0] * matrix[0][0] + row[1] * matrix[0][1] + row[2] * matrix[0][2], row[0] * matrix[1][0] + row[1] * matrix[1][1] + row[2] * matrix[1][2], row[0] * matrix[2][0] + row[1] * matrix[2][1] + row[2] * matrix[2][2] ];
120
+ }
121
+
122
+ const SRGB_TO_XYZ = [ [ .41233895, .35762064, .18051042 ], [ .2126, .7152, .0722 ], [ .01932141, .11916382, .95034478 ] ], XYZ_TO_SRGB = [ [ 3.2413774792388685, -1.5376652402851851, -.49885366846268053 ], [ -.9691452513005321, 1.8758853451067872, .04156585616912061 ], [ .05562093689691305, -.20395524564742123, 1.0571799111220335 ] ], WHITE_POINT_D65 = [ 95.047, 100, 108.883 ];
123
+
124
+ function argbFromRgb(red, green, blue) {
125
+ return (255 << 24 | (255 & red) << 16 | (255 & green) << 8 | 255 & blue) >>> 0;
126
+ }
127
+
128
+ function argbFromLinrgb(linrgb) {
129
+ return argbFromRgb(delinearized(linrgb[0]), delinearized(linrgb[1]), delinearized(linrgb[2]));
130
+ }
131
+
132
+ function redFromArgb(argb) {
133
+ return argb >> 16 & 255;
134
+ }
135
+
136
+ function greenFromArgb(argb) {
137
+ return argb >> 8 & 255;
138
+ }
139
+
140
+ function blueFromArgb(argb) {
141
+ return 255 & argb;
142
+ }
143
+
144
+ function argbFromXyz(x, y, z) {
145
+ const matrix = XYZ_TO_SRGB, linearR = matrix[0][0] * x + matrix[0][1] * y + matrix[0][2] * z, linearG = matrix[1][0] * x + matrix[1][1] * y + matrix[1][2] * z, linearB = matrix[2][0] * x + matrix[2][1] * y + matrix[2][2] * z;
146
+ return argbFromRgb(delinearized(linearR), delinearized(linearG), delinearized(linearB));
147
+ }
148
+
149
+ function xyzFromArgb(argb) {
150
+ return matrixMultiply([ linearized(redFromArgb(argb)), linearized(greenFromArgb(argb)), linearized(blueFromArgb(argb)) ], SRGB_TO_XYZ);
151
+ }
152
+
153
+ function argbFromLstar(lstar) {
154
+ const component = delinearized(yFromLstar(lstar));
155
+ return argbFromRgb(component, component, component);
156
+ }
157
+
158
+ function lstarFromArgb(argb) {
159
+ return 116 * labF(xyzFromArgb(argb)[1] / 100) - 16;
160
+ }
161
+
162
+ function yFromLstar(lstar) {
163
+ return 100 * labInvf((lstar + 16) / 116);
164
+ }
165
+
166
+ function linearized(rgbComponent) {
167
+ const normalized = rgbComponent / 255;
168
+ return normalized <= .040449936 ? normalized / 12.92 * 100 : 100 * Math.pow((normalized + .055) / 1.055, 2.4);
169
+ }
170
+
171
+ function delinearized(rgbComponent) {
172
+ const normalized = rgbComponent / 100;
173
+ let delinearized = 0;
174
+ return delinearized = normalized <= .0031308 ? 12.92 * normalized : 1.055 * Math.pow(normalized, 1 / 2.4) - .055,
175
+ clampInt(0, 255, Math.round(255 * delinearized));
176
+ }
177
+
178
+ function whitePointD65() {
179
+ return WHITE_POINT_D65;
180
+ }
181
+
182
+ function labF(t) {
183
+ return t > 216 / 24389 ? Math.pow(t, 1 / 3) : (903.2962962962963 * t + 16) / 116;
184
+ }
185
+
186
+ function labInvf(ft) {
187
+ const ft3 = ft * ft * ft;
188
+ return ft3 > 216 / 24389 ? ft3 : (116 * ft - 16) / 903.2962962962963;
189
+ }
190
+
191
+ class ViewingConditions {
192
+ static make(whitePoint = whitePointD65(), adaptingLuminance = 200 / Math.PI * yFromLstar(50) / 100, backgroundLstar = 50, surround = 2, discountingIlluminant = !1) {
193
+ const xyz = whitePoint, rW = .401288 * xyz[0] + .650173 * xyz[1] + -.051461 * xyz[2], gW = -.250268 * xyz[0] + 1.204414 * xyz[1] + .045854 * xyz[2], bW = -.002079 * xyz[0] + .048952 * xyz[1] + .953127 * xyz[2], f = .8 + surround / 10, c = f >= .9 ? lerp(.59, .69, 10 * (f - .9)) : lerp(.525, .59, 10 * (f - .8));
194
+ let d = discountingIlluminant ? 1 : f * (1 - 1 / 3.6 * Math.exp((-adaptingLuminance - 42) / 92));
195
+ d = d > 1 ? 1 : d < 0 ? 0 : d;
196
+ const nc = f, rgbD = [ d * (100 / rW) + 1 - d, d * (100 / gW) + 1 - d, d * (100 / bW) + 1 - d ], k = 1 / (5 * adaptingLuminance + 1), k4 = k * k * k * k, k4F = 1 - k4, fl = k4 * adaptingLuminance + .1 * k4F * k4F * Math.cbrt(5 * adaptingLuminance), n = yFromLstar(backgroundLstar) / whitePoint[1], z = 1.48 + Math.sqrt(n), nbb = .725 / Math.pow(n, .2), ncb = nbb, rgbAFactors = [ Math.pow(fl * rgbD[0] * rW / 100, .42), Math.pow(fl * rgbD[1] * gW / 100, .42), Math.pow(fl * rgbD[2] * bW / 100, .42) ], rgbA = [ 400 * rgbAFactors[0] / (rgbAFactors[0] + 27.13), 400 * rgbAFactors[1] / (rgbAFactors[1] + 27.13), 400 * rgbAFactors[2] / (rgbAFactors[2] + 27.13) ];
197
+ return new ViewingConditions(n, (2 * rgbA[0] + rgbA[1] + .05 * rgbA[2]) * nbb, nbb, ncb, c, nc, rgbD, fl, Math.pow(fl, .25), z);
198
+ }
199
+ constructor(n, aw, nbb, ncb, c, nc, rgbD, fl, fLRoot, z) {
200
+ this.n = n, this.aw = aw, this.nbb = nbb, this.ncb = ncb, this.c = c, this.nc = nc,
201
+ this.rgbD = rgbD, this.fl = fl, this.fLRoot = fLRoot, this.z = z;
202
+ }
203
+ }
204
+
205
+ ViewingConditions.DEFAULT = ViewingConditions.make();
206
+
207
+ class Cam16 {
208
+ constructor(hue, chroma, j, q, m, s, jstar, astar, bstar) {
209
+ this.hue = hue, this.chroma = chroma, this.j = j, this.q = q, this.m = m, this.s = s,
210
+ this.jstar = jstar, this.astar = astar, this.bstar = bstar;
211
+ }
212
+ distance(other) {
213
+ const dJ = this.jstar - other.jstar, dA = this.astar - other.astar, dB = this.bstar - other.bstar, dEPrime = Math.sqrt(dJ * dJ + dA * dA + dB * dB);
214
+ return 1.41 * Math.pow(dEPrime, .63);
215
+ }
216
+ static fromInt(argb) {
217
+ return Cam16.fromIntInViewingConditions(argb, ViewingConditions.DEFAULT);
218
+ }
219
+ static fromIntInViewingConditions(argb, viewingConditions) {
220
+ const green = (65280 & argb) >> 8, blue = 255 & argb, redL = linearized((16711680 & argb) >> 16), greenL = linearized(green), blueL = linearized(blue), x = .41233895 * redL + .35762064 * greenL + .18051042 * blueL, y = .2126 * redL + .7152 * greenL + .0722 * blueL, z = .01932141 * redL + .11916382 * greenL + .95034478 * blueL, rC = .401288 * x + .650173 * y - .051461 * z, gC = -.250268 * x + 1.204414 * y + .045854 * z, bC = -.002079 * x + .048952 * y + .953127 * z, rD = viewingConditions.rgbD[0] * rC, gD = viewingConditions.rgbD[1] * gC, bD = viewingConditions.rgbD[2] * bC, rAF = Math.pow(viewingConditions.fl * Math.abs(rD) / 100, .42), gAF = Math.pow(viewingConditions.fl * Math.abs(gD) / 100, .42), bAF = Math.pow(viewingConditions.fl * Math.abs(bD) / 100, .42), rA = 400 * signum(rD) * rAF / (rAF + 27.13), gA = 400 * signum(gD) * gAF / (gAF + 27.13), bA = 400 * signum(bD) * bAF / (bAF + 27.13), a = (11 * rA + -12 * gA + bA) / 11, b = (rA + gA - 2 * bA) / 9, u = (20 * rA + 20 * gA + 21 * bA) / 20, p2 = (40 * rA + 20 * gA + bA) / 20, atanDegrees = 180 * Math.atan2(b, a) / Math.PI, hue = atanDegrees < 0 ? atanDegrees + 360 : atanDegrees >= 360 ? atanDegrees - 360 : atanDegrees, hueRadians = hue * Math.PI / 180, ac = p2 * viewingConditions.nbb, j = 100 * Math.pow(ac / viewingConditions.aw, viewingConditions.c * viewingConditions.z), q = 4 / viewingConditions.c * Math.sqrt(j / 100) * (viewingConditions.aw + 4) * viewingConditions.fLRoot, huePrime = hue < 20.14 ? hue + 360 : hue, t = 5e4 / 13 * (.25 * (Math.cos(huePrime * Math.PI / 180 + 2) + 3.8)) * viewingConditions.nc * viewingConditions.ncb * Math.sqrt(a * a + b * b) / (u + .305), alpha = Math.pow(t, .9) * Math.pow(1.64 - Math.pow(.29, viewingConditions.n), .73), c = alpha * Math.sqrt(j / 100), m = c * viewingConditions.fLRoot, s = 50 * Math.sqrt(alpha * viewingConditions.c / (viewingConditions.aw + 4)), jstar = (1 + 100 * .007) * j / (1 + .007 * j), mstar = 1 / .0228 * Math.log(1 + .0228 * m), astar = mstar * Math.cos(hueRadians), bstar = mstar * Math.sin(hueRadians);
221
+ return new Cam16(hue, c, j, q, m, s, jstar, astar, bstar);
222
+ }
223
+ static fromJch(j, c, h) {
224
+ return Cam16.fromJchInViewingConditions(j, c, h, ViewingConditions.DEFAULT);
225
+ }
226
+ static fromJchInViewingConditions(j, c, h, viewingConditions) {
227
+ const q = 4 / viewingConditions.c * Math.sqrt(j / 100) * (viewingConditions.aw + 4) * viewingConditions.fLRoot, m = c * viewingConditions.fLRoot, alpha = c / Math.sqrt(j / 100), s = 50 * Math.sqrt(alpha * viewingConditions.c / (viewingConditions.aw + 4)), hueRadians = h * Math.PI / 180, jstar = (1 + 100 * .007) * j / (1 + .007 * j), mstar = 1 / .0228 * Math.log(1 + .0228 * m), astar = mstar * Math.cos(hueRadians), bstar = mstar * Math.sin(hueRadians);
228
+ return new Cam16(h, c, j, q, m, s, jstar, astar, bstar);
229
+ }
230
+ static fromUcs(jstar, astar, bstar) {
231
+ return Cam16.fromUcsInViewingConditions(jstar, astar, bstar, ViewingConditions.DEFAULT);
232
+ }
233
+ static fromUcsInViewingConditions(jstar, astar, bstar, viewingConditions) {
234
+ const a = astar, b = bstar, m = Math.sqrt(a * a + b * b), c = (Math.exp(.0228 * m) - 1) / .0228 / viewingConditions.fLRoot;
235
+ let h = Math.atan2(b, a) * (180 / Math.PI);
236
+ h < 0 && (h += 360);
237
+ const j = jstar / (1 - .007 * (jstar - 100));
238
+ return Cam16.fromJchInViewingConditions(j, c, h, viewingConditions);
239
+ }
240
+ toInt() {
241
+ return this.viewed(ViewingConditions.DEFAULT);
242
+ }
243
+ viewed(viewingConditions) {
244
+ const alpha = 0 === this.chroma || 0 === this.j ? 0 : this.chroma / Math.sqrt(this.j / 100), t = Math.pow(alpha / Math.pow(1.64 - Math.pow(.29, viewingConditions.n), .73), 1 / .9), hRad = this.hue * Math.PI / 180, eHue = .25 * (Math.cos(hRad + 2) + 3.8), ac = viewingConditions.aw * Math.pow(this.j / 100, 1 / viewingConditions.c / viewingConditions.z), p1 = eHue * (5e4 / 13) * viewingConditions.nc * viewingConditions.ncb, p2 = ac / viewingConditions.nbb, hSin = Math.sin(hRad), hCos = Math.cos(hRad), gamma = 23 * (p2 + .305) * t / (23 * p1 + 11 * t * hCos + 108 * t * hSin), a = gamma * hCos, b = gamma * hSin, rA = (460 * p2 + 451 * a + 288 * b) / 1403, gA = (460 * p2 - 891 * a - 261 * b) / 1403, bA = (460 * p2 - 220 * a - 6300 * b) / 1403, rCBase = Math.max(0, 27.13 * Math.abs(rA) / (400 - Math.abs(rA))), rC = signum(rA) * (100 / viewingConditions.fl) * Math.pow(rCBase, 1 / .42), gCBase = Math.max(0, 27.13 * Math.abs(gA) / (400 - Math.abs(gA))), gC = signum(gA) * (100 / viewingConditions.fl) * Math.pow(gCBase, 1 / .42), bCBase = Math.max(0, 27.13 * Math.abs(bA) / (400 - Math.abs(bA))), bC = signum(bA) * (100 / viewingConditions.fl) * Math.pow(bCBase, 1 / .42), rF = rC / viewingConditions.rgbD[0], gF = gC / viewingConditions.rgbD[1], bF = bC / viewingConditions.rgbD[2];
245
+ return argbFromXyz(1.86206786 * rF - 1.01125463 * gF + .14918677 * bF, .38752654 * rF + .62144744 * gF - .00897398 * bF, -.0158415 * rF - .03412294 * gF + 1.04996444 * bF);
246
+ }
247
+ }
248
+
249
+ class HctSolver {
250
+ static sanitizeRadians(angle) {
251
+ return (angle + 8 * Math.PI) % (2 * Math.PI);
252
+ }
253
+ static trueDelinearized(rgbComponent) {
254
+ const normalized = rgbComponent / 100;
255
+ let delinearized = 0;
256
+ return delinearized = normalized <= .0031308 ? 12.92 * normalized : 1.055 * Math.pow(normalized, 1 / 2.4) - .055,
257
+ 255 * delinearized;
258
+ }
259
+ static chromaticAdaptation(component) {
260
+ const af = Math.pow(Math.abs(component), .42);
261
+ return 400 * signum(component) * af / (af + 27.13);
262
+ }
263
+ static hueOf(linrgb) {
264
+ const scaledDiscount = matrixMultiply(linrgb, HctSolver.SCALED_DISCOUNT_FROM_LINRGB), rA = HctSolver.chromaticAdaptation(scaledDiscount[0]), gA = HctSolver.chromaticAdaptation(scaledDiscount[1]), bA = HctSolver.chromaticAdaptation(scaledDiscount[2]), a = (11 * rA + -12 * gA + bA) / 11, b = (rA + gA - 2 * bA) / 9;
265
+ return Math.atan2(b, a);
266
+ }
267
+ static areInCyclicOrder(a, b, c) {
268
+ return HctSolver.sanitizeRadians(b - a) < HctSolver.sanitizeRadians(c - a);
269
+ }
270
+ static intercept(source, mid, target) {
271
+ return (mid - source) / (target - source);
272
+ }
273
+ static lerpPoint(source, t, target) {
274
+ return [ source[0] + (target[0] - source[0]) * t, source[1] + (target[1] - source[1]) * t, source[2] + (target[2] - source[2]) * t ];
275
+ }
276
+ static setCoordinate(source, coordinate, target, axis) {
277
+ const t = HctSolver.intercept(source[axis], coordinate, target[axis]);
278
+ return HctSolver.lerpPoint(source, t, target);
279
+ }
280
+ static isBounded(x) {
281
+ return 0 <= x && x <= 100;
282
+ }
283
+ static nthVertex(y, n) {
284
+ const kR = HctSolver.Y_FROM_LINRGB[0], kG = HctSolver.Y_FROM_LINRGB[1], kB = HctSolver.Y_FROM_LINRGB[2], coordA = n % 4 <= 1 ? 0 : 100, coordB = n % 2 == 0 ? 0 : 100;
285
+ if (n < 4) {
286
+ const g = coordA, b = coordB, r = (y - g * kG - b * kB) / kR;
287
+ return HctSolver.isBounded(r) ? [ r, g, b ] : [ -1, -1, -1 ];
288
+ }
289
+ if (n < 8) {
290
+ const b = coordA, r = coordB, g = (y - r * kR - b * kB) / kG;
291
+ return HctSolver.isBounded(g) ? [ r, g, b ] : [ -1, -1, -1 ];
292
+ }
293
+ {
294
+ const r = coordA, g = coordB, b = (y - r * kR - g * kG) / kB;
295
+ return HctSolver.isBounded(b) ? [ r, g, b ] : [ -1, -1, -1 ];
296
+ }
297
+ }
298
+ static bisectToSegment(y, targetHue) {
299
+ let left = [ -1, -1, -1 ], right = left, leftHue = 0, rightHue = 0, initialized = !1, uncut = !0;
300
+ for (let n = 0; n < 12; n++) {
301
+ const mid = HctSolver.nthVertex(y, n);
302
+ if (mid[0] < 0) continue;
303
+ const midHue = HctSolver.hueOf(mid);
304
+ initialized ? (uncut || HctSolver.areInCyclicOrder(leftHue, midHue, rightHue)) && (uncut = !1,
305
+ HctSolver.areInCyclicOrder(leftHue, targetHue, midHue) ? (right = mid, rightHue = midHue) : (left = mid,
306
+ leftHue = midHue)) : (left = mid, right = mid, leftHue = midHue, rightHue = midHue,
307
+ initialized = !0);
308
+ }
309
+ return [ left, right ];
310
+ }
311
+ static midpoint(a, b) {
312
+ return [ (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2 ];
313
+ }
314
+ static criticalPlaneBelow(x) {
315
+ return Math.floor(x - .5);
316
+ }
317
+ static criticalPlaneAbove(x) {
318
+ return Math.ceil(x - .5);
319
+ }
320
+ static bisectToLimit(y, targetHue) {
321
+ const segment = HctSolver.bisectToSegment(y, targetHue);
322
+ let left = segment[0], leftHue = HctSolver.hueOf(left), right = segment[1];
323
+ for (let axis = 0; axis < 3; axis++) if (left[axis] !== right[axis]) {
324
+ let lPlane = -1, rPlane = 255;
325
+ left[axis] < right[axis] ? (lPlane = HctSolver.criticalPlaneBelow(HctSolver.trueDelinearized(left[axis])),
326
+ rPlane = HctSolver.criticalPlaneAbove(HctSolver.trueDelinearized(right[axis]))) : (lPlane = HctSolver.criticalPlaneAbove(HctSolver.trueDelinearized(left[axis])),
327
+ rPlane = HctSolver.criticalPlaneBelow(HctSolver.trueDelinearized(right[axis])));
328
+ for (let i = 0; i < 8 && !(Math.abs(rPlane - lPlane) <= 1); i++) {
329
+ const mPlane = Math.floor((lPlane + rPlane) / 2), midPlaneCoordinate = HctSolver.CRITICAL_PLANES[mPlane], mid = HctSolver.setCoordinate(left, midPlaneCoordinate, right, axis), midHue = HctSolver.hueOf(mid);
330
+ HctSolver.areInCyclicOrder(leftHue, targetHue, midHue) ? (right = mid, rPlane = mPlane) : (left = mid,
331
+ leftHue = midHue, lPlane = mPlane);
332
+ }
333
+ }
334
+ return HctSolver.midpoint(left, right);
335
+ }
336
+ static inverseChromaticAdaptation(adapted) {
337
+ const adaptedAbs = Math.abs(adapted), base = Math.max(0, 27.13 * adaptedAbs / (400 - adaptedAbs));
338
+ return signum(adapted) * Math.pow(base, 1 / .42);
339
+ }
340
+ static findResultByJ(hueRadians, chroma, y) {
341
+ let j = 11 * Math.sqrt(y);
342
+ const viewingConditions = ViewingConditions.DEFAULT, tInnerCoeff = 1 / Math.pow(1.64 - Math.pow(.29, viewingConditions.n), .73), p1 = .25 * (Math.cos(hueRadians + 2) + 3.8) * (5e4 / 13) * viewingConditions.nc * viewingConditions.ncb, hSin = Math.sin(hueRadians), hCos = Math.cos(hueRadians);
343
+ for (let iterationRound = 0; iterationRound < 5; iterationRound++) {
344
+ const jNormalized = j / 100, alpha = 0 === chroma || 0 === j ? 0 : chroma / Math.sqrt(jNormalized), t = Math.pow(alpha * tInnerCoeff, 1 / .9), p2 = viewingConditions.aw * Math.pow(jNormalized, 1 / viewingConditions.c / viewingConditions.z) / viewingConditions.nbb, gamma = 23 * (p2 + .305) * t / (23 * p1 + 11 * t * hCos + 108 * t * hSin), a = gamma * hCos, b = gamma * hSin, rA = (460 * p2 + 451 * a + 288 * b) / 1403, gA = (460 * p2 - 891 * a - 261 * b) / 1403, bA = (460 * p2 - 220 * a - 6300 * b) / 1403, linrgb = matrixMultiply([ HctSolver.inverseChromaticAdaptation(rA), HctSolver.inverseChromaticAdaptation(gA), HctSolver.inverseChromaticAdaptation(bA) ], HctSolver.LINRGB_FROM_SCALED_DISCOUNT);
345
+ if (linrgb[0] < 0 || linrgb[1] < 0 || linrgb[2] < 0) return 0;
346
+ const kR = HctSolver.Y_FROM_LINRGB[0], kG = HctSolver.Y_FROM_LINRGB[1], kB = HctSolver.Y_FROM_LINRGB[2], fnj = kR * linrgb[0] + kG * linrgb[1] + kB * linrgb[2];
347
+ if (fnj <= 0) return 0;
348
+ if (4 === iterationRound || Math.abs(fnj - y) < .002) return linrgb[0] > 100.01 || linrgb[1] > 100.01 || linrgb[2] > 100.01 ? 0 : argbFromLinrgb(linrgb);
349
+ j -= (fnj - y) * j / (2 * fnj);
350
+ }
351
+ return 0;
352
+ }
353
+ static solveToInt(hueDegrees, chroma, lstar) {
354
+ if (chroma < 1e-4 || lstar < 1e-4 || lstar > 99.9999) return argbFromLstar(lstar);
355
+ const hueRadians = (hueDegrees = sanitizeDegreesDouble(hueDegrees)) / 180 * Math.PI, y = yFromLstar(lstar), exactAnswer = HctSolver.findResultByJ(hueRadians, chroma, y);
356
+ if (0 !== exactAnswer) return exactAnswer;
357
+ return argbFromLinrgb(HctSolver.bisectToLimit(y, hueRadians));
358
+ }
359
+ static solveToCam(hueDegrees, chroma, lstar) {
360
+ return Cam16.fromInt(HctSolver.solveToInt(hueDegrees, chroma, lstar));
361
+ }
362
+ }
363
+
364
+ HctSolver.SCALED_DISCOUNT_FROM_LINRGB = [ [ .001200833568784504, .002389694492170889, .0002795742885861124 ], [ .0005891086651375999, .0029785502573438758, .0003270666104008398 ], [ .00010146692491640572, .0005364214359186694, .0032979401770712076 ] ],
365
+ HctSolver.LINRGB_FROM_SCALED_DISCOUNT = [ [ 1373.2198709594231, -1100.4251190754821, -7.278681089101213 ], [ -271.815969077903, 559.6580465940733, -32.46047482791194 ], [ 1.9622899599665666, -57.173814538844006, 308.7233197812385 ] ],
366
+ HctSolver.Y_FROM_LINRGB = [ .2126, .7152, .0722 ], HctSolver.CRITICAL_PLANES = [ .015176349177441876, .045529047532325624, .07588174588720938, .10623444424209313, .13658714259697685, .16693984095186062, .19729253930674434, .2276452376616281, .2579979360165119, .28835063437139563, .3188300904430532, .350925934958123, .3848314933096426, .42057480301049466, .458183274052838, .4976837250274023, .5391024159806381, .5824650784040898, .6277969426914107, .6751227633498623, .7244668422128921, .775853049866786, .829304845476233, .8848452951698498, .942497089126609, 1.0022825574869039, 1.0642236851973577, 1.1283421258858297, 1.1946592148522128, 1.2631959812511864, 1.3339731595349034, 1.407011200216447, 1.4823302800086415, 1.5599503113873272, 1.6398909516233677, 1.7221716113234105, 1.8068114625156377, 1.8938294463134073, 1.9832442801866852, 2.075074464868551, 2.1693382909216234, 2.2660538449872063, 2.36523901573795, 2.4669114995532007, 2.5710888059345764, 2.6777882626779785, 2.7870270208169257, 2.898822059350997, 3.0131901897720907, 3.1301480604002863, 3.2497121605402226, 3.3718988244681087, 3.4967242352587946, 3.624204428461639, 3.754355295633311, 3.887192587735158, 4.022731918402185, 4.160988767090289, 4.301978482107941, 4.445716283538092, 4.592217266055746, 4.741496401646282, 4.893568542229298, 5.048448422192488, 5.20615066083972, 5.3666897647573375, 5.5300801301023865, 5.696336044816294, 5.865471690767354, 6.037501145825082, 6.212438385869475, 6.390297286737924, 6.571091626112461, 6.7548350853498045, 6.941541251256611, 7.131223617812143, 7.323895587840543, 7.5195704746346665, 7.7182615035334345, 7.919981813454504, 8.124744458384042, 8.332562408825165, 8.543448553206703, 8.757415699253682, 8.974476575321063, 9.194643831691977, 9.417930041841839, 9.644347703669503, 9.873909240696694, 10.106627003236781, 10.342513269534024, 10.58158024687427, 10.8238400726681, 11.069304815507364, 11.317986476196008, 11.569896988756009, 11.825048221409341, 12.083451977536606, 12.345119996613247, 12.610063955123938, 12.878295467455942, 13.149826086772048, 13.42466730586372, 13.702830557985108, 13.984327217668513, 14.269168601521828, 14.55736596900856, 14.848930523210871, 15.143873411576273, 15.44220572664832, 15.743938506781891, 16.04908273684337, 16.35764934889634, 16.66964922287304, 16.985093187232053, 17.30399201960269, 17.62635644741625, 17.95219714852476, 18.281524751807332, 18.614349837764564, 18.95068293910138, 19.290534541298456, 19.633915083172692, 19.98083495742689, 20.331304511189067, 20.685334046541502, 21.042933821039977, 21.404114048223256, 21.76888489811322, 22.137256497705877, 22.50923893145328, 22.884842241736916, 23.264076429332462, 23.6469514538663, 24.033477234264016, 24.42366364919083, 24.817520537484558, 25.21505769858089, 25.61628489293138, 26.021211842414342, 26.429848230738664, 26.842203703840827, 27.258287870275353, 27.678110301598522, 28.10168053274597, 28.529008062403893, 28.96010235337422, 29.39497283293396, 29.83362889318845, 30.276079891419332, 30.722335150426627, 31.172403958865512, 31.62629557157785, 32.08401920991837, 32.54558406207592, 33.010999283389665, 33.4802739966603, 33.953417292456834, 34.430438229418264, 34.911345834551085, 35.39614910352207, 35.88485700094671, 36.37747846067349, 36.87402238606382, 37.37449765026789, 37.87891309649659, 38.38727753828926, 38.89959975977785, 39.41588851594697, 39.93615253289054, 40.460400508064545, 40.98864111053629, 41.520882981230194, 42.05713473317016, 42.597404951718396, 43.141702194811224, 43.6900349931913, 44.24241185063697, 44.798841244188324, 45.35933162437017, 45.92389141541209, 46.49252901546552, 47.065252796817916, 47.64207110610409, 48.22299226451468, 48.808024568002054, 49.3971762874833, 49.9904556690408, 50.587870934119984, 51.189430279724725, 51.79514187861014, 52.40501387947288, 53.0190544071392, 53.637271562750364, 54.259673423945976, 54.88626804504493, 55.517063457223934, 56.15206766869424, 56.79128866487574, 57.43473440856916, 58.08241284012621, 58.734331877617365, 59.39049941699807, 60.05092333227251, 60.715611475655585, 61.38457167773311, 62.057811747619894, 62.7353394731159, 63.417162620860914, 64.10328893648692, 64.79372614476921, 65.48848194977529, 66.18756403501224, 66.89098006357258, 67.59873767827808, 68.31084450182222, 69.02730813691093, 69.74813616640164, 70.47333615344107, 71.20291564160104, 71.93688215501312, 72.67524319850172, 73.41800625771542, 74.16517879925733, 74.9167682708136, 75.67278210128072, 76.43322770089146, 77.1981124613393, 77.96744375590167, 78.74122893956174, 79.51947534912904, 80.30219030335869, 81.08938110306934, 81.88105503125999, 82.67721935322541, 83.4778813166706, 84.28304815182372, 85.09272707154808, 85.90692527145302, 86.72564993000343, 87.54890820862819, 88.3767072518277, 89.2090541872801, 90.04595612594655, 90.88742016217518, 91.73345337380438, 92.58406282226491, 93.43925555268066, 94.29903859396902, 95.16341895893969, 96.03240364439274, 96.9059996312159, 97.78421388448044, 98.6670533535366, 99.55452497210776 ];
367
+
368
+ class Hct {
369
+ static from(hue, chroma, tone) {
370
+ return new Hct(HctSolver.solveToInt(hue, chroma, tone));
371
+ }
372
+ static fromInt(argb) {
373
+ return new Hct(argb);
374
+ }
375
+ toInt() {
376
+ return this.argb;
377
+ }
378
+ get hue() {
379
+ return this.internalHue;
380
+ }
381
+ set hue(newHue) {
382
+ this.setInternalState(HctSolver.solveToInt(newHue, this.internalChroma, this.internalTone));
383
+ }
384
+ get chroma() {
385
+ return this.internalChroma;
386
+ }
387
+ set chroma(newChroma) {
388
+ this.setInternalState(HctSolver.solveToInt(this.internalHue, newChroma, this.internalTone));
389
+ }
390
+ get tone() {
391
+ return this.internalTone;
392
+ }
393
+ set tone(newTone) {
394
+ this.setInternalState(HctSolver.solveToInt(this.internalHue, this.internalChroma, newTone));
395
+ }
396
+ constructor(argb) {
397
+ this.argb = argb;
398
+ const cam = Cam16.fromInt(argb);
399
+ this.internalHue = cam.hue, this.internalChroma = cam.chroma, this.internalTone = lstarFromArgb(argb),
400
+ this.argb = argb;
401
+ }
402
+ setInternalState(argb) {
403
+ const cam = Cam16.fromInt(argb);
404
+ this.internalHue = cam.hue, this.internalChroma = cam.chroma, this.internalTone = lstarFromArgb(argb),
405
+ this.argb = argb;
406
+ }
407
+ }
408
+
409
+ class Blend {
410
+ static harmonize(designColor, sourceColor) {
411
+ const fromHct = Hct.fromInt(designColor), toHct = Hct.fromInt(sourceColor), differenceDegrees$1 = differenceDegrees(fromHct.hue, toHct.hue), rotationDegrees = Math.min(.5 * differenceDegrees$1, 15), outputHue = sanitizeDegreesDouble(fromHct.hue + rotationDegrees * rotationDirection(fromHct.hue, toHct.hue));
412
+ return Hct.from(outputHue, fromHct.chroma, fromHct.tone).toInt();
413
+ }
414
+ static hctHue(from, to, amount) {
415
+ const ucs = Blend.cam16Ucs(from, to, amount), ucsCam = Cam16.fromInt(ucs), fromCam = Cam16.fromInt(from);
416
+ return Hct.from(ucsCam.hue, fromCam.chroma, lstarFromArgb(from)).toInt();
417
+ }
418
+ static cam16Ucs(from, to, amount) {
419
+ const fromCam = Cam16.fromInt(from), toCam = Cam16.fromInt(to), fromJ = fromCam.jstar, fromA = fromCam.astar, fromB = fromCam.bstar, jstar = fromJ + (toCam.jstar - fromJ) * amount, astar = fromA + (toCam.astar - fromA) * amount, bstar = fromB + (toCam.bstar - fromB) * amount;
420
+ return Cam16.fromUcs(jstar, astar, bstar).toInt();
421
+ }
422
+ }
423
+
424
+ class TonalPalette {
425
+ static fromInt(argb) {
426
+ const hct = Hct.fromInt(argb);
427
+ return TonalPalette.fromHueAndChroma(hct.hue, hct.chroma);
428
+ }
429
+ static fromHueAndChroma(hue, chroma) {
430
+ return new TonalPalette(hue, chroma);
431
+ }
432
+ constructor(hue, chroma) {
433
+ this.hue = hue, this.chroma = chroma, this.cache = new Map;
434
+ }
435
+ tone(tone) {
436
+ let argb = this.cache.get(tone);
437
+ return void 0 === argb && (argb = Hct.from(this.hue, this.chroma, tone).toInt(),
438
+ this.cache.set(tone, argb)), argb;
439
+ }
440
+ }
441
+
442
+ class CorePalette {
443
+ static of(argb) {
444
+ return new CorePalette(argb, !1);
445
+ }
446
+ static contentOf(argb) {
447
+ return new CorePalette(argb, !0);
448
+ }
449
+ static fromColors(colors) {
450
+ return CorePalette.createPaletteFromColors(!1, colors);
451
+ }
452
+ static contentFromColors(colors) {
453
+ return CorePalette.createPaletteFromColors(!0, colors);
454
+ }
455
+ static createPaletteFromColors(content, colors) {
456
+ const palette = new CorePalette(colors.primary, content);
457
+ if (colors.secondary) {
458
+ const p = new CorePalette(colors.secondary, content);
459
+ palette.a2 = p.a1;
460
+ }
461
+ if (colors.tertiary) {
462
+ const p = new CorePalette(colors.tertiary, content);
463
+ palette.a3 = p.a1;
464
+ }
465
+ if (colors.error) {
466
+ const p = new CorePalette(colors.error, content);
467
+ palette.error = p.a1;
468
+ }
469
+ if (colors.neutral) {
470
+ const p = new CorePalette(colors.neutral, content);
471
+ palette.n1 = p.n1;
472
+ }
473
+ if (colors.neutralVariant) {
474
+ const p = new CorePalette(colors.neutralVariant, content);
475
+ palette.n2 = p.n2;
476
+ }
477
+ return palette;
478
+ }
479
+ constructor(argb, isContent) {
480
+ const hct = Hct.fromInt(argb), hue = hct.hue, chroma = hct.chroma;
481
+ isContent ? (this.a1 = TonalPalette.fromHueAndChroma(hue, chroma), this.a2 = TonalPalette.fromHueAndChroma(hue, chroma / 3),
482
+ this.a3 = TonalPalette.fromHueAndChroma(hue + 60, chroma / 2), this.n1 = TonalPalette.fromHueAndChroma(hue, Math.min(chroma / 12, 4)),
483
+ this.n2 = TonalPalette.fromHueAndChroma(hue, Math.min(chroma / 6, 8))) : (this.a1 = TonalPalette.fromHueAndChroma(hue, Math.max(48, chroma)),
484
+ this.a2 = TonalPalette.fromHueAndChroma(hue, 16), this.a3 = TonalPalette.fromHueAndChroma(hue + 60, 24),
485
+ this.n1 = TonalPalette.fromHueAndChroma(hue, 4), this.n2 = TonalPalette.fromHueAndChroma(hue, 8)),
486
+ this.error = TonalPalette.fromHueAndChroma(25, 84);
487
+ }
488
+ }
489
+
490
+ class Scheme {
491
+ get primary() {
492
+ return this.props.primary;
493
+ }
494
+ get onPrimary() {
495
+ return this.props.onPrimary;
496
+ }
497
+ get primaryContainer() {
498
+ return this.props.primaryContainer;
499
+ }
500
+ get onPrimaryContainer() {
501
+ return this.props.onPrimaryContainer;
502
+ }
503
+ get secondary() {
504
+ return this.props.secondary;
505
+ }
506
+ get onSecondary() {
507
+ return this.props.onSecondary;
508
+ }
509
+ get secondaryContainer() {
510
+ return this.props.secondaryContainer;
511
+ }
512
+ get onSecondaryContainer() {
513
+ return this.props.onSecondaryContainer;
514
+ }
515
+ get tertiary() {
516
+ return this.props.tertiary;
517
+ }
518
+ get onTertiary() {
519
+ return this.props.onTertiary;
520
+ }
521
+ get tertiaryContainer() {
522
+ return this.props.tertiaryContainer;
523
+ }
524
+ get onTertiaryContainer() {
525
+ return this.props.onTertiaryContainer;
526
+ }
527
+ get error() {
528
+ return this.props.error;
529
+ }
530
+ get onError() {
531
+ return this.props.onError;
532
+ }
533
+ get errorContainer() {
534
+ return this.props.errorContainer;
535
+ }
536
+ get onErrorContainer() {
537
+ return this.props.onErrorContainer;
538
+ }
539
+ get background() {
540
+ return this.props.background;
541
+ }
542
+ get onBackground() {
543
+ return this.props.onBackground;
544
+ }
545
+ get surface() {
546
+ return this.props.surface;
547
+ }
548
+ get onSurface() {
549
+ return this.props.onSurface;
550
+ }
551
+ get surfaceVariant() {
552
+ return this.props.surfaceVariant;
553
+ }
554
+ get onSurfaceVariant() {
555
+ return this.props.onSurfaceVariant;
556
+ }
557
+ get outline() {
558
+ return this.props.outline;
559
+ }
560
+ get outlineVariant() {
561
+ return this.props.outlineVariant;
562
+ }
563
+ get shadow() {
564
+ return this.props.shadow;
565
+ }
566
+ get scrim() {
567
+ return this.props.scrim;
568
+ }
569
+ get inverseSurface() {
570
+ return this.props.inverseSurface;
571
+ }
572
+ get inverseOnSurface() {
573
+ return this.props.inverseOnSurface;
574
+ }
575
+ get inversePrimary() {
576
+ return this.props.inversePrimary;
577
+ }
578
+ static light(argb) {
579
+ return Scheme.lightFromCorePalette(CorePalette.of(argb));
580
+ }
581
+ static dark(argb) {
582
+ return Scheme.darkFromCorePalette(CorePalette.of(argb));
583
+ }
584
+ static lightContent(argb) {
585
+ return Scheme.lightFromCorePalette(CorePalette.contentOf(argb));
586
+ }
587
+ static darkContent(argb) {
588
+ return Scheme.darkFromCorePalette(CorePalette.contentOf(argb));
589
+ }
590
+ static lightFromCorePalette(core) {
591
+ return new Scheme({
592
+ primary: core.a1.tone(40),
593
+ onPrimary: core.a1.tone(100),
594
+ primaryContainer: core.a1.tone(90),
595
+ onPrimaryContainer: core.a1.tone(10),
596
+ secondary: core.a2.tone(40),
597
+ onSecondary: core.a2.tone(100),
598
+ secondaryContainer: core.a2.tone(90),
599
+ onSecondaryContainer: core.a2.tone(10),
600
+ tertiary: core.a3.tone(40),
601
+ onTertiary: core.a3.tone(100),
602
+ tertiaryContainer: core.a3.tone(90),
603
+ onTertiaryContainer: core.a3.tone(10),
604
+ error: core.error.tone(40),
605
+ onError: core.error.tone(100),
606
+ errorContainer: core.error.tone(90),
607
+ onErrorContainer: core.error.tone(10),
608
+ background: core.n1.tone(99),
609
+ onBackground: core.n1.tone(10),
610
+ surface: core.n1.tone(99),
611
+ onSurface: core.n1.tone(10),
612
+ surfaceVariant: core.n2.tone(90),
613
+ onSurfaceVariant: core.n2.tone(30),
614
+ outline: core.n2.tone(50),
615
+ outlineVariant: core.n2.tone(80),
616
+ shadow: core.n1.tone(0),
617
+ scrim: core.n1.tone(0),
618
+ inverseSurface: core.n1.tone(20),
619
+ inverseOnSurface: core.n1.tone(95),
620
+ inversePrimary: core.a1.tone(80)
621
+ });
622
+ }
623
+ static darkFromCorePalette(core) {
624
+ return new Scheme({
625
+ primary: core.a1.tone(80),
626
+ onPrimary: core.a1.tone(20),
627
+ primaryContainer: core.a1.tone(30),
628
+ onPrimaryContainer: core.a1.tone(90),
629
+ secondary: core.a2.tone(80),
630
+ onSecondary: core.a2.tone(20),
631
+ secondaryContainer: core.a2.tone(30),
632
+ onSecondaryContainer: core.a2.tone(90),
633
+ tertiary: core.a3.tone(80),
634
+ onTertiary: core.a3.tone(20),
635
+ tertiaryContainer: core.a3.tone(30),
636
+ onTertiaryContainer: core.a3.tone(90),
637
+ error: core.error.tone(80),
638
+ onError: core.error.tone(20),
639
+ errorContainer: core.error.tone(30),
640
+ onErrorContainer: core.error.tone(80),
641
+ background: core.n1.tone(10),
642
+ onBackground: core.n1.tone(90),
643
+ surface: core.n1.tone(10),
644
+ onSurface: core.n1.tone(90),
645
+ surfaceVariant: core.n2.tone(30),
646
+ onSurfaceVariant: core.n2.tone(80),
647
+ outline: core.n2.tone(60),
648
+ outlineVariant: core.n2.tone(30),
649
+ shadow: core.n1.tone(0),
650
+ scrim: core.n1.tone(0),
651
+ inverseSurface: core.n1.tone(90),
652
+ inverseOnSurface: core.n1.tone(20),
653
+ inversePrimary: core.a1.tone(40)
654
+ });
655
+ }
656
+ constructor(props) {
657
+ this.props = props;
658
+ }
659
+ toJSON() {
660
+ return {
661
+ ...this.props
662
+ };
663
+ }
664
+ }
665
+
666
+ function hexFromArgb(argb) {
667
+ const r = redFromArgb(argb), g = greenFromArgb(argb), b = blueFromArgb(argb), outParts = [ r.toString(16), g.toString(16), b.toString(16) ];
668
+ for (const [i, part] of outParts.entries()) 1 === part.length && (outParts[i] = "0" + part);
669
+ return "#" + outParts.join("");
670
+ }
671
+
672
+ function argbFromHex(hex) {
673
+ const isThree = 3 === (hex = hex.replace("#", "")).length, isSix = 6 === hex.length, isEight = 8 === hex.length;
674
+ if (!isThree && !isSix && !isEight) throw new Error("unexpected hex " + hex);
675
+ let r = 0, g = 0, b = 0;
676
+ return isThree ? (r = parseIntHex(hex.slice(0, 1).repeat(2)), g = parseIntHex(hex.slice(1, 2).repeat(2)),
677
+ b = parseIntHex(hex.slice(2, 3).repeat(2))) : isSix ? (r = parseIntHex(hex.slice(0, 2)),
678
+ g = parseIntHex(hex.slice(2, 4)), b = parseIntHex(hex.slice(4, 6))) : isEight && (r = parseIntHex(hex.slice(2, 4)),
679
+ g = parseIntHex(hex.slice(4, 6)), b = parseIntHex(hex.slice(6, 8))), (255 << 24 | (255 & r) << 16 | (255 & g) << 8 | 255 & b) >>> 0;
680
+ }
681
+
682
+ function parseIntHex(value) {
683
+ return parseInt(value, 16);
684
+ }
685
+
686
+ function themeFromSourceColor(source, customColors = []) {
687
+ const palette = CorePalette.of(source);
688
+ return {
689
+ source: source,
690
+ schemes: {
691
+ light: Scheme.light(source),
692
+ dark: Scheme.dark(source)
693
+ },
694
+ palettes: {
695
+ primary: palette.a1,
696
+ secondary: palette.a2,
697
+ tertiary: palette.a3,
698
+ neutral: palette.n1,
699
+ neutralVariant: palette.n2,
700
+ error: palette.error
701
+ },
702
+ customColors: customColors.map((c => customColor(source, c)))
703
+ };
704
+ }
705
+
706
+ function customColor(source, color) {
707
+ let value = color.value;
708
+ const from = value, to = source;
709
+ color.blend && (value = Blend.harmonize(from, to));
710
+ const tones = CorePalette.of(value).a1;
711
+ return {
712
+ color: color,
713
+ value: value,
714
+ light: {
715
+ color: tones.tone(40),
716
+ onColor: tones.tone(100),
717
+ colorContainer: tones.tone(90),
718
+ onColorContainer: tones.tone(10)
719
+ },
720
+ dark: {
721
+ color: tones.tone(80),
722
+ onColor: tones.tone(20),
723
+ colorContainer: tones.tone(30),
724
+ onColorContainer: tones.tone(90)
725
+ }
726
+ };
727
+ }
728
+
729
+ // eslint-disable-next-line
730
+
731
+ /* eslint-disable */
732
+ // prettier-ignore
733
+ function toRGBA(d) {
734
+ const r = Math.round;
735
+ const l = d.length;
736
+ const rgba = {};
737
+ if (d.slice(0, 3).toLowerCase() === 'rgb') {
738
+ d = d.replace(' ', '').split(',');
739
+ rgba[0] = parseInt(d[0].slice(d[3].toLowerCase() === 'a' ? 5 : 4), 10);
740
+ rgba[1] = parseInt(d[1], 10);
741
+ rgba[2] = parseInt(d[2], 10);
742
+ rgba[3] = d[3] ? parseFloat(d[3]) : -1;
743
+ } else {
744
+ if (l < 6) d = parseInt(String(d[1]) + d[1] + d[2] + d[2] + d[3] + d[3] + (l > 4 ? String(d[4]) + d[4] : ''), 16);
745
+ else d = parseInt(d.slice(1), 16);
746
+ rgba[0] = (d >> 16) & 255;
747
+ rgba[1] = (d >> 8) & 255;
748
+ rgba[2] = d & 255;
749
+ rgba[3] = l === 9 || l === 5 ? r((((d >> 24) & 255) / 255) * 10000) / 10000 : -1;
750
+ }
751
+ return rgba;
752
+ }
753
+
754
+ // prettier-ignore
755
+ function blend(from, to, p = 0.5) {
756
+ const r = Math.round;
757
+ from = from.trim();
758
+ to = to.trim();
759
+ const b = p < 0;
760
+ p = b ? p * -1 : p;
761
+ const f = toRGBA(from);
762
+ const t = toRGBA(to);
763
+ if (to[0] === 'r') {
764
+ return 'rgb' + (to[3] === 'a' ? 'a(' : '(') +
765
+ r(((t[0] - f[0]) * p) + f[0]) + ',' +
766
+ r(((t[1] - f[1]) * p) + f[1]) + ',' +
767
+ r(((t[2] - f[2]) * p) + f[2]) + (
768
+ f[3] < 0 && t[3] < 0 ? '' : ',' + (
769
+ f[3] > -1 && t[3] > -1
770
+ ? r((((t[3] - f[3]) * p) + f[3]) * 10000) / 10000
771
+ : t[3] < 0 ? f[3] : t[3]
772
+ )
773
+ ) + ')';
774
+ }
775
+
776
+ return '#' + (0x100000000 + ((
777
+ f[3] > -1 && t[3] > -1
778
+ ? r((((t[3] - f[3]) * p) + f[3]) * 255)
779
+ : t[3] > -1 ? r(t[3] * 255) : f[3] > -1 ? r(f[3] * 255) : 255
780
+ ) * 0x1000000) +
781
+ (r(((t[0] - f[0]) * p) + f[0]) * 0x10000) +
782
+ (r(((t[1] - f[1]) * p) + f[1]) * 0x100) +
783
+ r(((t[2] - f[2]) * p) + f[2])
784
+ ).toString(16).slice(f[3] > -1 || t[3] > -1 ? 1 : 3);
785
+ }
786
+ /* eslint-enable */
787
+
788
+ const materialColors = (hexColor = '') => {
789
+ const theme = themeFromSourceColor(argbFromHex(`#${hexColor.replace('#', '')}`));
790
+ [0.05, 0.08, 0.11, 0.12, 0.14].forEach((amount, index) => {
791
+ theme.schemes.light.props[`surface${index + 1}`] = argbFromHex(
792
+ blend(
793
+ hexFromArgb(theme.schemes.light.props.surface),
794
+ hexFromArgb(theme.schemes.light.props.primary),
795
+ amount,
796
+ ),
797
+ );
798
+ theme.schemes.dark.props[`surface${index + 1}`] = argbFromHex(
799
+ blend(
800
+ hexFromArgb(theme.schemes.dark.props.surface),
801
+ hexFromArgb(theme.schemes.dark.props.primary),
802
+ amount,
803
+ ),
804
+ );
805
+ });
806
+
807
+ const name = (n) => {
808
+ return n
809
+ .split('')
810
+ .map((char) =>
811
+ char.toUpperCase() === char && char !== '-' && char !== '7'
812
+ ? `-${char.toLowerCase()}`
813
+ : char,
814
+ )
815
+ .join('');
816
+ };
817
+
818
+ const shouldSkip = (prop) => {
819
+ const skip = ['tertiary', 'shadow', 'scrim', 'error', 'background'];
820
+ return skip.filter((v) => prop.toLowerCase().includes(v)).length > 0;
821
+ };
822
+
823
+ const light = {};
824
+ const dark = {};
825
+ Object.keys(theme.schemes.light.props).forEach((prop) => {
826
+ if (shouldSkip(prop)) return;
827
+ light[name(`--f7-md-${prop}`)] = hexFromArgb(theme.schemes.light.props[prop]);
828
+ });
829
+ Object.keys(theme.schemes.dark.props).forEach((prop) => {
830
+ if (shouldSkip(prop)) return;
831
+ dark[name(`--f7-md-${prop}`)] = hexFromArgb(theme.schemes.dark.props[prop]);
832
+ });
833
+
834
+ return { light, dark };
835
+ };
836
+
93
837
  /* eslint no-control-regex: "off" */
94
838
 
95
839
  let uniqueNumber = 1;
@@ -114,7 +858,7 @@ const Utils = {
114
858
  ${[0, 1, 2, 3, 4, 5, 6, 7].map(() => '<span class="preloader-inner-line"></span>').join('')}
115
859
  </span>
116
860
  `.trim(),
117
- auroraPreloaderContent:`
861
+ pcPreloaderContent:`
118
862
  <span class="preloader-inner">
119
863
  <span class="preloader-inner-circle"></span>
120
864
  </span>
@@ -135,8 +879,14 @@ const Utils = {
135
879
  deleteProps(obj) {
136
880
  $.deleteProps(obj);
137
881
  },
138
- nextTick(callback, delay = 0) {
139
- return setTimeout(callback, delay);
882
+ requestAnimationFrame(cb) {
883
+ return $.requestAnimationFrame(cb);
884
+ },
885
+ cancelAnimationFrame(id) {
886
+ return $.cancelAnimationFrame(id);
887
+ },
888
+ nextTick(cb, delay = 0) {
889
+ return $.nextTick(cb, delay);
140
890
  },
141
891
  nextFrame(cb) {
142
892
  return $.nextFrame(cb);
@@ -144,12 +894,6 @@ const Utils = {
144
894
  now() {
145
895
  return Date.now();
146
896
  },
147
- requestAnimationFrame(cb) {
148
- return $.requestAnimationFrame(cb);
149
- },
150
- cancelAnimationFrame(id) {
151
- return $.cancelAnimationFrame(id);
152
- },
153
897
  parseUrlQuery(url) {
154
898
  return $.urlParam(url);
155
899
  },
@@ -216,10 +960,10 @@ const Utils = {
216
960
  args.splice(0, 1);
217
961
  return $.assign(to, ...args);
218
962
  },
219
- // ���෽������ʵ�������������ԡ���������
963
+ // 绑定类方法到类实例,复制类属性、方法到类
220
964
  bindMethods(instance, obj) {
221
965
  Object.keys(obj).forEach((key) => {
222
- if (this.isObject(obj[key])) {
966
+ if (Utils.isObject(obj[key])) {
223
967
  Object.keys(obj[key]).forEach((subKey) => {
224
968
  if (typeof obj[key][subKey] === 'function') {
225
969
  obj[key][subKey] = obj[key][subKey].bind(instance);
@@ -229,6 +973,14 @@ const Utils = {
229
973
  instance[key] = obj[key];
230
974
  });
231
975
  },
976
+ flattenArray(...args) {
977
+ const arr = [];
978
+ args.forEach((arg) => {
979
+ if (Array.isArray(arg)) arr.push(...flattenArray(...arg));
980
+ else arr.push(arg);
981
+ });
982
+ return arr;
983
+ },
232
984
  colorHexToRgb(hex) {
233
985
  const h = hex.replace(
234
986
  /^#?([a-f\d])([a-f\d])([a-f\d])$/i,
@@ -307,6 +1059,14 @@ const Utils = {
307
1059
 
308
1060
  return [HSB.h, HSB.s, HSB.b];
309
1061
  },
1062
+ getShadeTintColors(rgb){
1063
+ const hsl = colorRgbToHsl(...rgb);
1064
+ const hslShade = [hsl[0], hsl[1], Math.max(0, hsl[2] - 0.08)];
1065
+ const hslTint = [hsl[0], hsl[1], Math.max(0, hsl[2] + 0.08)];
1066
+ const shade = colorRgbToHex(...colorHslToRgb(...hslShade));
1067
+ const tint = colorRgbToHex(...colorHslToRgb(...hslTint));
1068
+ return { shade, tint };
1069
+ },
310
1070
  colorThemeCSSProperties(...args) {
311
1071
  let hex;
312
1072
  let rgb;
@@ -318,18 +1078,221 @@ const Utils = {
318
1078
  hex = Utils.colorRgbToHex(...rgb);
319
1079
  }
320
1080
  if (!rgb) return {};
321
- const hsl = Utils.colorRgbToHsl(...rgb);
322
- const hslShade = [hsl[0], hsl[1], Math.max(0, hsl[2] - 0.08)];
323
- const hslTint = [hsl[0], hsl[1], Math.max(0, hsl[2] + 0.08)];
324
- const shade = Utils.colorRgbToHex(...Utils.colorHslToRgb(...hslShade));
325
- const tint = Utils.colorRgbToHex(...Utils.colorHslToRgb(...hslTint));
326
- return {
327
- '--f7-theme-color': hex,
328
- '--f7-theme-color-rgb': rgb.join(', '),
329
- '--f7-theme-color-shade': shade,
330
- '--f7-theme-color-tint': tint,
331
- };
1081
+ const { light, dark } = materialColors(hex);
1082
+ const shadeTintIos = getShadeTintColors(rgb);
1083
+ const shadeTintMdLight = getShadeTintColors(colorHexToRgb(light['--f7-md-primary']));
1084
+ const shadeTintMdDark = getShadeTintColors(colorHexToRgb(dark['--f7-md-primary']));
1085
+ Object.keys(light).forEach((key) => {
1086
+ if (key.includes('surface-')) {
1087
+ light[`${key}-rgb`] = colorHexToRgb(light[key]);
1088
+ }
1089
+ });
1090
+ Object.keys(dark).forEach((key) => {
1091
+ if (key.includes('surface-')) {
1092
+ dark[`${key}-rgb`] = colorHexToRgb(dark[key]);
1093
+ }
1094
+ });
1095
+ return {
1096
+ ios: {
1097
+ '--f7-theme-color': 'var(--f7-ios-primary)',
1098
+ '--f7-theme-color-rgb': 'var(--f7-ios-primary-rgb)',
1099
+ '--f7-theme-color-shade': 'var(--f7-ios-primary-shade)',
1100
+ '--f7-theme-color-tint': 'var(--f7-ios-primary-tint)',
1101
+ },
1102
+ md: {
1103
+ '--f7-theme-color': 'var(--f7-md-primary)',
1104
+ '--f7-theme-color-rgb': 'var(--f7-md-primary-rgb)',
1105
+ '--f7-theme-color-shade': 'var(--f7-md-primary-shade)',
1106
+ '--f7-theme-color-tint': 'var(--f7-md-primary-tint)',
1107
+ },
1108
+ light: {
1109
+ '--f7-ios-primary': hex,
1110
+ '--f7-ios-primary-shade': shadeTintIos.shade,
1111
+ '--f7-ios-primary-tint': shadeTintIos.tint,
1112
+ '--f7-ios-primary-rgb': rgb.join(', '),
1113
+ '--f7-md-primary-shade': shadeTintMdLight.shade,
1114
+ '--f7-md-primary-tint': shadeTintMdLight.tint,
1115
+ '--f7-md-primary-rgb': colorHexToRgb(light['--f7-md-primary']).join(', '),
1116
+ ...light,
1117
+ },
1118
+ dark: {
1119
+ '--f7-md-primary-shade': shadeTintMdDark.shade,
1120
+ '--f7-md-primary-tint': shadeTintMdDark.tint,
1121
+ '--f7-md-primary-rgb': colorHexToRgb(dark['--f7-md-primary']).join(', '),
1122
+ ...dark,
1123
+ },
1124
+ };
332
1125
  },
1126
+ colorThemeCSSStyles(colors = {}) {
1127
+ const stringifyObject = (obj) => {
1128
+ let res = '';
1129
+ Object.keys(obj).forEach((key) => {
1130
+ res += `${key}:${obj[key]};`;
1131
+ });
1132
+ return res;
1133
+ };
1134
+ const colorVars = colorThemeCSSProperties(colors.primary);
1135
+
1136
+ const primary = [
1137
+ `:root{`,
1138
+ stringifyObject(colorVars.light),
1139
+ `--swiper-theme-color:var(--f7-theme-color);`,
1140
+ ...Object.keys(colors).map((colorName) => `--f7-color-${colorName}: ${colors[colorName]};`),
1141
+ `}`,
1142
+ `.dark{`,
1143
+ stringifyObject(colorVars.dark),
1144
+ `}`,
1145
+ `.ios, .ios .dark{`,
1146
+ stringifyObject(colorVars.ios),
1147
+ '}',
1148
+ `.md, .md .dark{`,
1149
+ stringifyObject(colorVars.md),
1150
+ '}',
1151
+ ].join('');
1152
+
1153
+ const restVars = {};
1154
+
1155
+ Object.keys(colors).forEach((colorName) => {
1156
+ const colorValue = colors[colorName];
1157
+ restVars[colorName] = colorThemeCSSProperties(colorValue);
1158
+ });
1159
+
1160
+ // rest
1161
+ let rest = '';
1162
+
1163
+ Object.keys(colors).forEach((colorName) => {
1164
+ const { light, dark, ios, md } = restVars[colorName];
1165
+
1166
+ const whiteColorVars = `
1167
+ --f7-ios-primary: #ffffff;
1168
+ --f7-ios-primary-shade: #ebebeb;
1169
+ --f7-ios-primary-tint: #ffffff;
1170
+ --f7-ios-primary-rgb: 255, 255, 255;
1171
+ --f7-md-primary-shade: #eee;
1172
+ --f7-md-primary-tint: #fff;
1173
+ --f7-md-primary-rgb: 255, 255, 255;
1174
+ --f7-md-primary: #fff;
1175
+ --f7-md-on-primary: #000;
1176
+ --f7-md-primary-container: #fff;
1177
+ --f7-md-on-primary-container: #000;
1178
+ --f7-md-secondary: #fff;
1179
+ --f7-md-on-secondary: #000;
1180
+ --f7-md-secondary-container: #555;
1181
+ --f7-md-on-secondary-container: #fff;
1182
+ --f7-md-surface: #fff;
1183
+ --f7-md-on-surface: #000;
1184
+ --f7-md-surface-variant: #333;
1185
+ --f7-md-on-surface-variant: #fff;
1186
+ --f7-md-outline: #fff;
1187
+ --f7-md-outline-variant: #fff;
1188
+ --f7-md-inverse-surface: #000;
1189
+ --f7-md-inverse-on-surface: #fff;
1190
+ --f7-md-inverse-primary: #000;
1191
+ --f7-md-surface-1: #f8f8f8;
1192
+ --f7-md-surface-2: #f1f1f1;
1193
+ --f7-md-surface-3: #e7e7e7;
1194
+ --f7-md-surface-4: #e1e1e1;
1195
+ --f7-md-surface-5: #d7d7d7;
1196
+ --f7-md-surface-variant-rgb: 51, 51, 51;
1197
+ --f7-md-on-surface-variant-rgb: 255, 255, 255;
1198
+ --f7-md-surface-1-rgb: 248, 248, 248;
1199
+ --f7-md-surface-2-rgb: 241, 241, 241;
1200
+ --f7-md-surface-3-rgb: 231, 231, 231;
1201
+ --f7-md-surface-4-rgb: 225, 225, 225;
1202
+ --f7-md-surface-5-rgb: 215, 215, 215;
1203
+ `;
1204
+ const blackColorVars = `
1205
+ --f7-ios-primary: #000;
1206
+ --f7-ios-primary-shade: #000;
1207
+ --f7-ios-primary-tint: #232323;
1208
+ --f7-ios-primary-rgb: 0, 0, 0;
1209
+ --f7-md-primary-shade: #000;
1210
+ --f7-md-primary-tint: #232323;
1211
+ --f7-md-primary-rgb: 0, 0, 0;
1212
+ --f7-md-primary: #000;
1213
+ --f7-md-on-primary: #fff;
1214
+ --f7-md-primary-container: #000;
1215
+ --f7-md-on-primary-container: #fff;
1216
+ --f7-md-secondary: #000;
1217
+ --f7-md-on-secondary: #fff;
1218
+ --f7-md-secondary-container: #aaa;
1219
+ --f7-md-on-secondary-container: #000;
1220
+ --f7-md-surface: #000;
1221
+ --f7-md-on-surface: #fff;
1222
+ --f7-md-surface-variant: #ccc;
1223
+ --f7-md-on-surface-variant: #000;
1224
+ --f7-md-outline: #000;
1225
+ --f7-md-outline-variant: #000;
1226
+ --f7-md-inverse-surface: #fff;
1227
+ --f7-md-inverse-on-surface: #000;
1228
+ --f7-md-inverse-primary: #fff;
1229
+ --f7-md-surface-1: #070707;
1230
+ --f7-md-surface-2: #161616;
1231
+ --f7-md-surface-3: #232323;
1232
+ --f7-md-surface-4: #303030;
1233
+ --f7-md-surface-5: #373737;
1234
+ --f7-md-surface-variant-rgb: 204, 204, 204;
1235
+ --f7-md-on-surface-variant-rgb: 0, 0, 0;
1236
+ --f7-md-surface-1-rgb: 7, 7, 7;
1237
+ --f7-md-surface-2-rgb: 22, 22, 22;
1238
+ --f7-md-surface-3-rgb: 35, 35, 35;
1239
+ --f7-md-surface-4-rgb: 48, 48, 48;
1240
+ --f7-md-surface-5-rgb: 55, 55, 55;
1241
+ `;
1242
+ /* eslint-disable */
1243
+ const lightString =
1244
+ colorName === 'white'
1245
+ ? whiteColorVars
1246
+ : colorName === 'black'
1247
+ ? blackColorVars
1248
+ : stringifyObject(light);
1249
+ const darkString =
1250
+ colorName === 'white'
1251
+ ? whiteColorVars
1252
+ : colorName === 'black'
1253
+ ? blackColorVars
1254
+ : stringifyObject(dark);
1255
+ /* eslint-enable */
1256
+ rest += [
1257
+ `.color-${colorName} {`,
1258
+ lightString,
1259
+ `--swiper-theme-color: var(--f7-theme-color);`,
1260
+ `}`,
1261
+ `.color-${colorName}.dark, .color-${colorName} .dark, .dark .color-${colorName} {`,
1262
+ darkString,
1263
+ `--swiper-theme-color: var(--f7-theme-color);`,
1264
+ `}`,
1265
+ `.ios .color-${colorName}, .ios.color-${colorName}, .ios .dark .color-${colorName}, .ios .dark.color-${colorName} {`,
1266
+ stringifyObject(ios),
1267
+ `}`,
1268
+ `.md .color-${colorName}, .md.color-${colorName}, .md .dark .color-${colorName}, .md .dark.color-${colorName} {`,
1269
+ stringifyObject(md),
1270
+ `}`,
1271
+
1272
+ // text color
1273
+ `.text-color-${colorName} {`,
1274
+ `--f7-theme-color-text-color: ${colors[colorName]};`,
1275
+ `}`,
1276
+
1277
+ // bg color
1278
+ `.bg-color-${colorName} {`,
1279
+ `--f7-theme-color-bg-color: ${colors[colorName]};`,
1280
+ `}`,
1281
+
1282
+ // border color
1283
+ `.border-color-${colorName} {`,
1284
+ `--f7-theme-color-border-color: ${colors[colorName]};`,
1285
+ `}`,
1286
+
1287
+ // ripple color
1288
+ `.ripple-color-${colorName} {`,
1289
+ `--f7-theme-color-ripple-color: rgba(${light['--f7-ios-primary-rgb']}, 0.3);`,
1290
+ `}`,
1291
+ ].join('');
1292
+ });
1293
+
1294
+ return `${primary}${rest}`;
1295
+ }
333
1296
  };
334
1297
 
335
1298
  /**
@@ -703,6 +1666,8 @@ class Page extends Event {
703
1666
  class Module extends Event {
704
1667
  constructor(params = {}, parents = []) {
705
1668
  super(params, parents);
1669
+ const self = this;
1670
+ self.params = params;
706
1671
  }
707
1672
 
708
1673
  // eslint-disable-next-line
@@ -858,14 +1823,8 @@ class Module extends Event {
858
1823
  * 扩展构造函数
859
1824
  * @param {*} parameters
860
1825
  */
861
- function Constructors (parameters = {}) {
862
- const {
863
- defaultSelector,
864
- constructor: Constructor,
865
- domProp,
866
- app,
867
- addMethods,
868
- } = parameters;
1826
+ function Constructors(parameters = {}) {
1827
+ const { defaultSelector, constructor: Constructor, domProp, app, addMethods } = parameters;
869
1828
  const methods = {
870
1829
  create(...args) {
871
1830
  if (app) return new Constructor(app, ...args);
@@ -887,8 +1846,7 @@ function Constructors (parameters = {}) {
887
1846
  addMethods.forEach(methodName => {
888
1847
  methods[methodName] = (el = defaultSelector, ...args) => {
889
1848
  const instance = methods.get(el);
890
- if (instance && instance[methodName])
891
- return instance[methodName](...args);
1849
+ if (instance && instance[methodName]) return instance[methodName](...args);
892
1850
  return undefined;
893
1851
  };
894
1852
  });
@@ -896,33 +1854,67 @@ function Constructors (parameters = {}) {
896
1854
  return methods;
897
1855
  }
898
1856
 
899
- function Modals (parameters = {}) {
900
- const { defaultSelector, constructor, app } = parameters;
1857
+ function Modals(parameters = {}) {
1858
+ const { defaultSelector, constructor: Constructor, app } = parameters;
901
1859
  const methods = $.extend(
902
1860
  Constructors({
903
1861
  defaultSelector,
904
- constructor,
1862
+ constructor: Constructor,
905
1863
  app,
906
1864
  domProp: 'f7Modal',
907
1865
  }),
908
1866
  {
909
- open(el, animate) {
910
- const $el = $(el);
1867
+ open(el, animate, targetEl) {
1868
+ let $el = $(el);
1869
+ if ($el.length > 1 && targetEl) {
1870
+ // check if same modal in other page
1871
+ const $targetPage = $(targetEl).parents('.page');
1872
+ if ($targetPage.length) {
1873
+ $el.each((modalEl) => {
1874
+ const $modalEl = $(modalEl);
1875
+ if ($modalEl.parents($targetPage)[0] === $targetPage[0]) {
1876
+ $el = $modalEl;
1877
+ }
1878
+ });
1879
+ }
1880
+ }
1881
+ if ($el.length > 1) {
1882
+ $el = $el.eq($el.length - 1);
1883
+ }
1884
+ if (!$el.length) return undefined;
911
1885
  let instance = $el[0].f7Modal;
912
- if (!instance)
913
- instance = new constructor(app, {el: $el});
1886
+ if (!instance) {
1887
+ const params = $el.dataset();
1888
+ instance = new Constructor(app, { el: $el, ...params });
1889
+ }
914
1890
  return instance.open(animate);
915
1891
  },
916
- close(el = defaultSelector, animate) {
917
- const $el = $(el);
918
- if ($el.length === 0)
919
- return undefined;
1892
+ close(el = defaultSelector, animate, targetEl) {
1893
+ let $el = $(el);
1894
+ if (!$el.length) return undefined;
1895
+ if ($el.length > 1) {
1896
+ // check if close link (targetEl) in this modal
1897
+ let $parentEl;
1898
+ if (targetEl) {
1899
+ const $targetEl = $(targetEl);
1900
+ if ($targetEl.length) {
1901
+ $parentEl = $targetEl.parents($el);
1902
+ }
1903
+ }
1904
+ if ($parentEl && $parentEl.length > 0) {
1905
+ $el = $parentEl;
1906
+ } else {
1907
+ $el = $el.eq($el.length - 1);
1908
+ }
1909
+ }
920
1910
  let instance = $el[0].f7Modal;
921
- if (!instance)
922
- instance = new constructor(app, {el: $el});
1911
+ if (!instance) {
1912
+ const params = $el.dataset();
1913
+ instance = new Constructor(app, { el: $el, ...params });
1914
+ }
923
1915
  return instance.close(animate);
924
1916
  },
925
- }
1917
+ },
926
1918
  );
927
1919
  return methods;
928
1920
  }
@@ -1089,6 +2081,33 @@ function loadModule(moduleToLoad) {
1089
2081
  });
1090
2082
  }
1091
2083
 
2084
+ // replace react, use by @babel/plugin-transform-react-jsx
2085
+ /* eslint-disable prefer-rest-params */
2086
+ function jsx(tag, props, ...args) {
2087
+ const attrs = props || {};
2088
+ const children = args || [];
2089
+
2090
+ const attrsString = Object.keys(attrs)
2091
+ .map((attr) => {
2092
+ if (attr[0] === '_') {
2093
+ if (attrs[attr]) return attr.replace('_', '');
2094
+ return '';
2095
+ }
2096
+ return `${attr}="${attrs[attr]}"`;
2097
+ })
2098
+ .filter((attr) => !!attr)
2099
+ .join(' ');
2100
+
2101
+ if (['path', 'img', 'circle', 'polygon', 'line', 'input'].indexOf(tag) >= 0) {
2102
+ return `<${tag} ${attrsString} />`.trim();
2103
+ }
2104
+ const childrenContent = children
2105
+ .filter((c) => !!c)
2106
+ .map((c) => (Array.isArray(c) ? c.join('') : c))
2107
+ .join('');
2108
+ return `<${tag} ${attrsString}>${childrenContent}</${tag}>`.trim();
2109
+ }
2110
+
1092
2111
  const Resize = {
1093
2112
  name: 'resize',
1094
2113
  instance: {
@@ -1307,6 +2326,7 @@ const SW$1 = {
1307
2326
  if (!('serviceWorker' in window.navigator))
1308
2327
  return;
1309
2328
  const app = this;
2329
+ if (app.device.cordova || (window.Capacitor && window.Capacitor.isNative)) return;
1310
2330
  if (!app.serviceWorker.container)
1311
2331
  return;
1312
2332
  const paths = app.params.serviceWorker.path;
@@ -1329,109 +2349,123 @@ const SW$1 = {
1329
2349
  // const $ = require('@wiajs/dom'); // dom操作库,这种引用,导致 dom的压缩、非压缩 common包都不会打入 core,保留了 require
1330
2350
 
1331
2351
 
1332
- const Support$1 = $.support;
1333
- const Device$1 = $.device;
2352
+ const {extend, nextFrame} = Utils;
2353
+ const {support, device} = $;
2354
+
2355
+ // Default
2356
+ const def = {
2357
+ version: '1.0.1',
2358
+ el: 'body',
2359
+ root: 'body',
2360
+ theme: 'auto',
2361
+ language: window.navigator.language,
2362
+ routes: [],
2363
+ name: 'App',
2364
+ lazyModulesPath: null,
2365
+ initOnDeviceReady: true,
2366
+ // init: true, // 路由加载应用时为true
2367
+ darkMode: undefined,
2368
+ iosTranslucentBars: true,
2369
+ iosTranslucentModals: true,
2370
+ component: undefined,
2371
+ componentUrl: undefined,
2372
+ userAgent: null,
2373
+ url: null,
2374
+ colors: {
2375
+ primary: '#007aff',
2376
+ red: '#ff3b30',
2377
+ green: '#4cd964',
2378
+ blue: '#2196f3',
2379
+ pink: '#ff2d55',
2380
+ yellow: '#ffcc00',
2381
+ orange: '#ff9500',
2382
+ purple: '#9c27b0',
2383
+ deeppurple: '#673ab7',
2384
+ lightblue: '#5ac8fa',
2385
+ teal: '#009688',
2386
+ lime: '#cddc39',
2387
+ deeporange: '#ff6b22',
2388
+ white: '#ffffff',
2389
+ black: '#000000',
2390
+ },
2391
+ };
1334
2392
 
1335
2393
  /**
1336
2394
  * 应用类,每个wia应用从该类继承,由 首页加载创建或者路由创建
1337
2395
  */
1338
2396
  class App extends Module {
1339
2397
  static apps = {};
1340
- constructor(opt) {
1341
- super(opt);
2398
+ constructor(opts = {}) {
2399
+ super(opts);
2400
+ // eslint-disable-next-line
2401
+ // 单例,只能一个
2402
+ if (App.instance && typeof window !== 'undefined') {
2403
+ throw new Error("App is already initialized and can't be initialized more than once");
2404
+ }
1342
2405
 
1343
- const passedParams = $.extend({}, opt);
2406
+ const passedParams = extend({}, opts);
1344
2407
 
1345
2408
  const app = this;
1346
- app.device = Device$1;
1347
- app.support = Support$1;
1348
- console.log('App constructor', {Device: Device$1, Support: Support$1});
1349
-
1350
- // Default
1351
- const def = {
1352
- version: '0.0.1',
1353
- root: 'body',
1354
- theme: 'auto',
1355
- language: window.navigator.language,
1356
- routes: [],
1357
- lazyModulesPath: null,
1358
- initOnDeviceReady: true,
1359
- // init: true, // 路由加载时,为 false,,为true
1360
- autoDarkTheme: false,
1361
- iosTranslucentBars: true,
1362
- iosTranslucentModals: true,
1363
- component: undefined,
1364
- componentUrl: undefined,
1365
- };
2409
+ $.App = App;
2410
+ App.instance = app; // 控制单例
2411
+ app.device = device;
2412
+ app.support = support;
2413
+ console.log('App constructor', {Device: device, Support: support});
1366
2414
 
1367
2415
  // Extend defaults with modules params
1368
2416
  app.useModulesParams(def);
1369
2417
 
1370
2418
  // Extend defaults with passed params
1371
- app.params = $.extend(def, opt);
1372
-
1373
- const $rootEl = $(app.params.root);
2419
+ app.params = extend(def, opts);
2420
+ // 兼容 root
2421
+ if (opts.root && !opts.el) {
2422
+ app.params.el = opts.root;
2423
+ }
1374
2424
 
1375
2425
  // 判断Page、App实例
1376
2426
  $.isPage = p => p instanceof Page;
1377
2427
  $.isApp = p => p instanceof App;
1378
2428
 
1379
- $.extend(app, {
1380
- owner: app.params.owner,
1381
- name: app.params.name,
1382
- id: `${app.params.owner}.${app.params.name}`,
1383
- // App version
1384
- version: app.params.version,
2429
+ // 参数内容赋值给app 实例
2430
+ extend(app, {
2431
+ owner: app.params.owner, // 所有者
2432
+ name: app.params.name, // App Name
2433
+ id: `${app.params.owner}.${app.params.name}`, // App id
2434
+ version: app.params.version, // App version
1385
2435
  // Routes
1386
2436
  routes: app.params.routes,
1387
2437
  // Lang
1388
2438
  language: app.params.language,
1389
- // Root
1390
- root: $rootEl,
1391
- $el: $rootEl,
1392
2439
  cfg: app.params.cfg, // app config
1393
2440
  api: app.params.api, // api config
1394
2441
 
1395
- // RTL
1396
- rtl: $rootEl.css('direction') === 'rtl',
1397
- // Theme
1398
- theme: (function getTheme() {
2442
+ // Theme 主题
2443
+ theme: (() => {
1399
2444
  if (app.params.theme === 'auto') {
1400
- if (Device$1.ios) return 'ios';
1401
- if (Device$1.desktop) return 'aurora';
2445
+ if (device.ios) return 'ios';
2446
+ if (device.desktop) return 'pc';
1402
2447
  return 'md';
1403
2448
  }
1404
2449
  return app.params.theme;
1405
2450
  })(),
2451
+
1406
2452
  // Initially passed parameters
1407
2453
  passedParams,
1408
2454
  online: window.navigator.onLine,
2455
+ colors: app.params.colors,
2456
+ darkMode: app.params.darkMode,
1409
2457
  });
1410
2458
 
1411
- // Save Root
1412
- if (app.root && app.root[0]) {
1413
- app.root[0].wia = app;
1414
- }
2459
+ if (opts.store) app.params.store = params.store;
1415
2460
 
2461
+ // 触摸事件
1416
2462
  app.touchEvents = {
1417
- start: Support$1.touch
1418
- ? 'touchstart'
1419
- : Support$1.pointerEvents
1420
- ? 'pointerdown'
1421
- : 'mousedown',
1422
- move: Support$1.touch
1423
- ? 'touchmove'
1424
- : Support$1.pointerEvents
1425
- ? 'pointermove'
1426
- : 'mousemove',
1427
- end: Support$1.touch
1428
- ? 'touchend'
1429
- : Support$1.pointerEvents
1430
- ? 'pointerup'
1431
- : 'mouseup',
2463
+ start: support.touch ? 'touchstart' : support.pointerEvents ? 'pointerdown' : 'mousedown',
2464
+ move: support.touch ? 'touchmove' : support.pointerEvents ? 'pointermove' : 'mousemove',
2465
+ end: support.touch ? 'touchend' : support.pointerEvents ? 'pointerup' : 'mouseup',
1432
2466
  };
1433
2467
 
1434
- // 加载use插入的模块类,每个模块作为app的一个属性,合并到实例。
2468
+ // 插件:插入的模块类,每个模块作为app的一个属性,合并到实例。
1435
2469
  // 模块包括相关属性及方法(如:create、get、destroy)
1436
2470
  // 调用每个模块的 create 方法
1437
2471
  app.useModules();
@@ -1439,29 +2473,9 @@ class App extends Module {
1439
2473
  // 初始化数据,Init Data & Methods
1440
2474
  app.initData();
1441
2475
 
1442
- // 自动暗黑主题,Auto Dark Theme
1443
- const DARK = '(prefers-color-scheme: dark)';
1444
- const LIGHT = '(prefers-color-scheme: light)';
1445
- app.mq = {};
1446
- if (window.matchMedia) {
1447
- app.mq.dark = window.matchMedia(DARK);
1448
- app.mq.light = window.matchMedia(LIGHT);
1449
- }
1450
- app.colorSchemeListener = function ({matches, media}) {
1451
- if (!matches) {
1452
- return;
1453
- }
1454
- const html = document.querySelector('html');
1455
- if (media === DARK) {
1456
- html.classList.add('theme-dark');
1457
- } else if (media === LIGHT) {
1458
- html.classList.remove('theme-dark');
1459
- }
1460
- };
1461
-
1462
- // app 初始化,Init
1463
- function init() {
1464
- if (Device$1.cordova && app.params.initOnDeviceReady) {
2476
+ // 应用初始化,路由跳转时不执行初始化
2477
+ if (app.params.init) {
2478
+ if (device.cordova && app.params.initOnDeviceReady) {
1465
2479
  $(document).on('deviceready', () => {
1466
2480
  app.init();
1467
2481
  });
@@ -1470,13 +2484,11 @@ class App extends Module {
1470
2484
  }
1471
2485
  }
1472
2486
 
1473
- // 应用初始化,路由跳转时不执行初始化
1474
- if (app.params.init) init();
1475
-
1476
2487
  // Return app instance
1477
2488
  return app;
1478
2489
  }
1479
2490
 
2491
+ // 应用事件
1480
2492
  // 首次加载事件,全局只触发一次
1481
2493
  load(param) {
1482
2494
  this.emit('local::load appLoad', param);
@@ -1497,6 +2509,78 @@ class App extends Module {
1497
2509
  this.emit('local::unload appUnload');
1498
2510
  }
1499
2511
 
2512
+ setColorTheme(color) {
2513
+ if (!color) return;
2514
+ const app = this;
2515
+ app.colors.primary = color;
2516
+ app.setColors();
2517
+ }
2518
+
2519
+ setColors() {
2520
+ const app = this;
2521
+ if (!app.colorsStyleEl) {
2522
+ app.colorsStyleEl = document.createElement('style');
2523
+ document.head.appendChild(app.colorsStyleEl);
2524
+ }
2525
+
2526
+ app.colorsStyleEl.textContent = app.utils.colorThemeCSSStyles(app.colors);
2527
+ }
2528
+
2529
+ /**
2530
+ * 绑定容器
2531
+ * 应用初始化时调用
2532
+ * @param {HTMLElement} rootEl
2533
+ */
2534
+ mount(rootEl) {
2535
+ const app = this;
2536
+
2537
+ const $rootEl = $(rootEl || app.params.el).eq(0);
2538
+ extend(app, {
2539
+ // Root
2540
+ root: $rootEl,
2541
+ $el: $rootEl,
2542
+ el: $rootEl?.[0],
2543
+ // RTL
2544
+ rtl: $rootEl.css('direction') === 'rtl',
2545
+ });
2546
+
2547
+ // Save Root
2548
+ if (app.root && app.root[0]) {
2549
+ app.root[0].wia = app;
2550
+ }
2551
+ if (app.$el && app.$el[0]) {
2552
+ app.$el[0].wia = app;
2553
+ }
2554
+
2555
+ app.el.f7 = app;
2556
+
2557
+ // 自动暗黑主题,Auto Dark Theme
2558
+ const DARK = '(prefers-color-scheme: dark)';
2559
+ const LIGHT = '(prefers-color-scheme: light)';
2560
+ app.mq = {};
2561
+ if (window.matchMedia) {
2562
+ app.mq.dark = window.matchMedia(DARK);
2563
+ app.mq.light = window.matchMedia(LIGHT);
2564
+ }
2565
+
2566
+ app.colorSchemeListener = ({matches, media}) => {
2567
+ if (!matches) {
2568
+ return;
2569
+ }
2570
+ const html = document.querySelector('html');
2571
+ if (media === DARK) {
2572
+ html.classList.add('dark');
2573
+ app.darkMode = true;
2574
+ app.emit('darkModeChange', true);
2575
+ } else if (media === LIGHT) {
2576
+ html.classList.remove('dark');
2577
+ app.darkMode = false;
2578
+ app.emit('darkModeChange', false);
2579
+ }
2580
+ };
2581
+ app.emit('mount');
2582
+ }
2583
+
1500
2584
  /**
1501
2585
  * 初始化数据
1502
2586
  */
@@ -1533,9 +2617,13 @@ class App extends Module {
1533
2617
  app.mq.light.addListener(app.colorSchemeListener);
1534
2618
  }
1535
2619
  if (app.mq.dark && app.mq.dark.matches) {
1536
- html.classList.add('theme-dark');
2620
+ html.classList.add('dark');
2621
+ app.darkMode = true;
2622
+ app.emit('darkModeChange', true);
1537
2623
  } else if (app.mq.light && app.mq.light.matches) {
1538
- html.classList.remove('theme-dark');
2624
+ html.classList.remove('dark');
2625
+ app.darkMode = false;
2626
+ app.emit('darkModeChange', false);
1539
2627
  }
1540
2628
  }
1541
2629
 
@@ -1547,74 +2635,111 @@ class App extends Module {
1547
2635
  if (app.mq.light) app.mq.light.removeListener(app.colorSchemeListener);
1548
2636
  }
1549
2637
 
2638
+ setDarkMode(mode) {
2639
+ const app = this;
2640
+ if (mode === 'auto') {
2641
+ app.enableAutoDarkMode();
2642
+ } else {
2643
+ app.disableAutoDarkMode();
2644
+ $('html')[mode ? 'addClass' : 'removeClass']('dark');
2645
+ app.darkMode = mode;
2646
+ }
2647
+ }
2648
+
2649
+ initAppComponent(callback) {
2650
+ const app = this;
2651
+ app.router.componentLoader(
2652
+ app.params.component,
2653
+ app.params.componentUrl,
2654
+ {componentOptions: {el: app.$el[0]}},
2655
+ el => {
2656
+ app.$el = $(el);
2657
+ app.$el[0].wia = app;
2658
+ app.$elComponent = el.f7Component;
2659
+ app.el = app.$el[0];
2660
+ if (callback) callback();
2661
+ },
2662
+ () => {}
2663
+ );
2664
+ }
2665
+
1550
2666
  // 初始化,包括控制 html 样式,wia app 启动时需要执行,切换app时,不需要
1551
- init() {
2667
+ init(rootEl) {
1552
2668
  const app = this;
1553
- if (app.initialized) return app;
2669
+ app.setColors();
2670
+ app.mount(rootEl);
1554
2671
 
1555
- $.App = App;
2672
+ const init = () => {
2673
+ if (app.initialized) return app;
1556
2674
 
1557
- if (Device$1.ios && Device$1.webView) {
1558
- // Strange hack required for iOS 8 webview to work on inputs
1559
- window.addEventListener('touchstart', () => {});
1560
- }
2675
+ app.$el.addClass('framework7-initializing');
1561
2676
 
1562
- app.root.addClass('framework7-initializing');
2677
+ // RTL attr
2678
+ if (app.rtl) {
2679
+ $('html').attr('dir', 'rtl');
2680
+ }
1563
2681
 
1564
- // RTL attr
1565
- if (app.rtl) {
1566
- $('html').attr('dir', 'rtl');
1567
- }
2682
+ // Auto Dark Mode
2683
+ if (typeof app.params.darkMode === 'undefined') {
2684
+ app.darkMode = $('html').hasClass('dark');
2685
+ } else {
2686
+ app.setDarkMode(app.params.darkMode);
2687
+ }
1568
2688
 
1569
- // Auto Dark Theme
1570
- if (app.params.autoDarkTheme) {
1571
- app.enableAutoDarkTheme();
1572
- }
2689
+ // Watch for online/offline state
2690
+ window.addEventListener('offline', () => {
2691
+ app.online = false;
2692
+ app.emit('offline');
2693
+ app.emit('connection', false);
2694
+ });
1573
2695
 
1574
- // Watch for online/offline state
1575
- window.addEventListener('offline', () => {
1576
- app.online = false;
1577
- app.emit('offline');
1578
- app.emit('connection', false);
1579
- });
2696
+ window.addEventListener('online', () => {
2697
+ app.online = true;
2698
+ app.emit('online');
2699
+ app.emit('connection', true);
2700
+ });
1580
2701
 
1581
- window.addEventListener('online', () => {
1582
- app.online = true;
1583
- app.emit('online');
1584
- app.emit('connection', true);
1585
- });
2702
+ // Root class
2703
+ app.$el.addClass('framework7-root');
1586
2704
 
1587
- // Root class
1588
- app.root.addClass('framework7-root');
2705
+ // Theme class
2706
+ $('html').removeClass('ios md pc').addClass(app.theme);
1589
2707
 
1590
- // Theme class
1591
- $('html').removeClass('ios md aurora').addClass(app.theme);
2708
+ // iOS Translucent
2709
+ if (app.params.iosTranslucentBars && app.theme === 'ios') {
2710
+ $('html').addClass('ios-translucent-bars');
2711
+ }
2712
+ if (app.params.iosTranslucentModals && app.theme === 'ios') {
2713
+ $('html').addClass('ios-translucent-modals');
2714
+ }
1592
2715
 
1593
- // iOS Translucent
1594
- if (app.params.iosTranslucentBars && app.theme === 'ios' && Device$1.ios) {
1595
- $('html').addClass('ios-translucent-bars');
1596
- }
1597
- if (app.params.iosTranslucentModals && app.theme === 'ios' && Device$1.ios) {
1598
- $('html').addClass('ios-translucent-modals');
1599
- }
2716
+ // Init class
2717
+ nextFrame(() => {
2718
+ app.$el.removeClass('framework7-initializing');
2719
+ });
1600
2720
 
1601
- // Init class
1602
- $.nextFrame(() => {
1603
- app.root.removeClass('framework7-initializing');
1604
- });
2721
+ initStyle();
1605
2722
 
1606
- initStyle();
2723
+ // Emit, init other modules
2724
+ app.initialized = true;
1607
2725
 
1608
- // Emit, init other modules
1609
- app.initialized = true;
2726
+ // 发起init 事件,模块 on 里面有 init方法的会被触发
2727
+ app.emit('init');
2728
+ };
1610
2729
 
1611
- // 发起init 事件,模块 on 里面有 init方法的会被触发
1612
- app.emit('init');
2730
+ if (app.params.component || app.params.componentUrl) {
2731
+ app.initAppComponent(() => {
2732
+ init();
2733
+ });
2734
+ } else {
2735
+ init();
2736
+ }
1613
2737
 
1614
2738
  return app;
1615
2739
  }
1616
2740
 
1617
2741
  // eslint-disable-next-line
2742
+ // 加载模块
1618
2743
  loadModule(m) {
1619
2744
  App.loadModule(m);
1620
2745
  // 模块初始化
@@ -1652,6 +2777,13 @@ class App extends Module {
1652
2777
  static get Event() {
1653
2778
  return Event;
1654
2779
  }
2780
+ static get Class() {
2781
+ return Module;
2782
+ }
2783
+
2784
+ static get Events() {
2785
+ return Event;
2786
+ }
1655
2787
  }
1656
2788
 
1657
2789
  /**
@@ -1666,8 +2798,8 @@ function initStyle() {
1666
2798
  );
1667
2799
  if (!html) return;
1668
2800
  if (
1669
- Device$1.standalone &&
1670
- Device$1.ios &&
2801
+ device.standalone &&
2802
+ device.ios &&
1671
2803
  metaStatusbar &&
1672
2804
  metaStatusbar.content === 'black-translucent'
1673
2805
  ) {
@@ -1675,17 +2807,17 @@ function initStyle() {
1675
2807
  }
1676
2808
 
1677
2809
  // Pixel Ratio
1678
- classNames.push(`device-pixel-ratio-${Math.floor(Device$1.pixelRatio)}`);
2810
+ classNames.push(`device-pixel-ratio-${Math.floor(device.pixelRatio)}`);
1679
2811
  // OS classes
1680
- if (Device$1.os && !Device$1.desktop) {
1681
- classNames.push(`device-${Device$1.os}`);
1682
- } else if (Device$1.desktop) {
2812
+ if (device.os && !device.desktop) {
2813
+ classNames.push(`device-${device.os}`);
2814
+ } else if (device.desktop) {
1683
2815
  classNames.push('device-desktop');
1684
- if (Device$1.os) {
1685
- classNames.push(`device-${Device$1.os}`);
2816
+ if (device.os) {
2817
+ classNames.push(`device-${device.os}`);
1686
2818
  }
1687
2819
  }
1688
- if (Device$1.cordova || Device$1.phonegap) {
2820
+ if (device.cordova || device.phonegap) {
1689
2821
  classNames.push('device-cordova');
1690
2822
  }
1691
2823
 
@@ -1698,17 +2830,18 @@ function initStyle() {
1698
2830
 
1699
2831
  // App 类 静态方法、属性
1700
2832
 
2833
+ App.jsx = jsx;
1701
2834
  App.ModalMethods = Modals;
1702
2835
  App.ConstructorMethods = Constructors;
1703
2836
  // 动态加载模块(base里面已经内置动态加载,这个方法应该用不上)
1704
2837
  App.loadModule = loadModule;
1705
- App.loadModules = function (modules) {
2838
+ App.loadModules = modules => {
1706
2839
  return Promise.all(modules.map(module => App.loadModule(module)));
1707
2840
  };
1708
2841
 
1709
2842
  // app 加载到 app实例的一些扩展模块
1710
- App.support = Support$1;
1711
- App.device = Device$1;
2843
+ App.support = support;
2844
+ App.device = device;
1712
2845
  App.utils = Utils;
1713
2846
 
1714
2847
  // 添加应用缺省模块
@@ -2157,33 +3290,6 @@ class Modal extends Event {
2157
3290
  }
2158
3291
  }
2159
3292
 
2160
- // replace react, use by @babel/plugin-transform-react-jsx
2161
- /* eslint-disable prefer-rest-params */
2162
- function jsx(tag, props, ...args) {
2163
- const attrs = props || {};
2164
- const children = args || [];
2165
-
2166
- const attrsString = Object.keys(attrs)
2167
- .map((attr) => {
2168
- if (attr[0] === '_') {
2169
- if (attrs[attr]) return attr.replace('_', '');
2170
- return '';
2171
- }
2172
- return `${attr}="${attrs[attr]}"`;
2173
- })
2174
- .filter((attr) => !!attr)
2175
- .join(' ');
2176
-
2177
- if (['path', 'img', 'circle', 'polygon', 'line', 'input'].indexOf(tag) >= 0) {
2178
- return `<${tag} ${attrsString} />`.trim();
2179
- }
2180
- const childrenContent = children
2181
- .filter((c) => !!c)
2182
- .map((c) => (Array.isArray(c) ? c.join('') : c))
2183
- .join('');
2184
- return `<${tag} ${attrsString}>${childrenContent}</${tag}>`.trim();
2185
- }
2186
-
2187
3293
  // export {default as Support} from './support';
2188
3294
  // export {default as Device} from './device';
2189
3295
  const Support = $.support;