@wiajs/core 1.0.2 → 1.0.3

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