ReactMaterial3/dist/react-you-ui14.mjs

505 lines
14 KiB
JavaScript

import { H as u, d as w, s as k, r as v, C as f, l as V, a as b } from "./string_utils-B4bsIQ5w.mjs";
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class C {
/**
* Blend the design color's HCT hue towards the key color's HCT
* hue, in a way that leaves the original color recognizable and
* recognizably shifted towards the key color.
*
* @param designColor ARGB representation of an arbitrary color.
* @param sourceColor ARGB representation of the main theme color.
* @return The design color with a hue shifted towards the
* system's color, a slightly warmer/cooler variant of the design
* color's hue.
*/
static harmonize(r, t) {
const e = u.fromInt(r), n = u.fromInt(t), a = w(e.hue, n.hue), o = Math.min(a * 0.5, 15), c = k(e.hue + o * v(e.hue, n.hue));
return u.from(c, e.chroma, e.tone).toInt();
}
/**
* Blends hue from one color into another. The chroma and tone of
* the original color are maintained.
*
* @param from ARGB representation of color
* @param to ARGB representation of color
* @param amount how much blending to perform; 0.0 >= and <= 1.0
* @return from, with a hue blended towards to. Chroma and tone
* are constant.
*/
static hctHue(r, t, e) {
const n = C.cam16Ucs(r, t, e), a = f.fromInt(n), o = f.fromInt(r);
return u.from(a.hue, o.chroma, V(r)).toInt();
}
/**
* Blend in CAM16-UCS space.
*
* @param from ARGB representation of color
* @param to ARGB representation of color
* @param amount how much blending to perform; 0.0 >= and <= 1.0
* @return from, blended towards to. Hue, chroma, and tone will
* change.
*/
static cam16Ucs(r, t, e) {
const n = f.fromInt(r), a = f.fromInt(t), o = n.jstar, c = n.astar, p = n.bstar, d = a.jstar, y = a.astar, l = a.bstar, g = o + (d - o) * e, S = c + (y - c) * e, H = p + (l - p) * e;
return f.fromUcs(g, S, H).toInt();
}
}
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class i {
/**
* @param argb ARGB representation of a color
* @return Tones matching that color's hue and chroma.
*/
static fromInt(r) {
const t = u.fromInt(r);
return i.fromHct(t);
}
/**
* @param hct Hct
* @return Tones matching that color's hue and chroma.
*/
static fromHct(r) {
return new i(r.hue, r.chroma, r);
}
/**
* @param hue HCT hue
* @param chroma HCT chroma
* @return Tones matching hue and chroma.
*/
static fromHueAndChroma(r, t) {
const e = new A(r, t).create();
return new i(r, t, e);
}
constructor(r, t, e) {
this.hue = r, this.chroma = t, this.keyColor = e, this.cache = /* @__PURE__ */ new Map();
}
/**
* @param tone HCT tone, measured from 0 to 100.
* @return ARGB representation of a color with that tone.
*/
tone(r) {
let t = this.cache.get(r);
return t === void 0 && (t = u.from(this.hue, this.chroma, r).toInt(), this.cache.set(r, t)), t;
}
/**
* @param tone HCT tone.
* @return HCT representation of a color with that tone.
*/
getHct(r) {
return u.fromInt(this.tone(r));
}
}
class A {
constructor(r, t) {
this.hue = r, this.requestedChroma = t, this.chromaCache = /* @__PURE__ */ new Map(), this.maxChromaValue = 200;
}
/**
* Creates a key color from a [hue] and a [chroma].
* The key color is the first tone, starting from T50, matching the given hue
* and chroma.
*
* @return Key color [Hct]
*/
create() {
let n = 0, a = 100;
for (; n < a; ) {
const o = Math.floor((n + a) / 2), c = this.maxChroma(o) < this.maxChroma(o + 1);
if (this.maxChroma(o) >= this.requestedChroma - 0.01)
if (Math.abs(n - 50) < Math.abs(a - 50))
a = o;
else {
if (n === o)
return u.from(this.hue, this.requestedChroma, n);
n = o;
}
else
c ? n = o + 1 : a = o;
}
return u.from(this.hue, this.requestedChroma, n);
}
// Find the maximum chroma for a given tone
maxChroma(r) {
if (this.chromaCache.has(r))
return this.chromaCache.get(r);
const t = u.from(this.hue, this.maxChromaValue, r).chroma;
return this.chromaCache.set(r, t), t;
}
}
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class s {
/**
* @param argb ARGB representation of a color
*/
static of(r) {
return new s(r, !1);
}
/**
* @param argb ARGB representation of a color
*/
static contentOf(r) {
return new s(r, !0);
}
/**
* Create a [CorePalette] from a set of colors
*/
static fromColors(r) {
return s.createPaletteFromColors(!1, r);
}
/**
* Create a content [CorePalette] from a set of colors
*/
static contentFromColors(r) {
return s.createPaletteFromColors(!0, r);
}
static createPaletteFromColors(r, t) {
const e = new s(t.primary, r);
if (t.secondary) {
const n = new s(t.secondary, r);
e.a2 = n.a1;
}
if (t.tertiary) {
const n = new s(t.tertiary, r);
e.a3 = n.a1;
}
if (t.error) {
const n = new s(t.error, r);
e.error = n.a1;
}
if (t.neutral) {
const n = new s(t.neutral, r);
e.n1 = n.n1;
}
if (t.neutralVariant) {
const n = new s(t.neutralVariant, r);
e.n2 = n.n2;
}
return e;
}
constructor(r, t) {
const e = u.fromInt(r), n = e.hue, a = e.chroma;
t ? (this.a1 = i.fromHueAndChroma(n, a), this.a2 = i.fromHueAndChroma(n, a / 3), this.a3 = i.fromHueAndChroma(n + 60, a / 2), this.n1 = i.fromHueAndChroma(n, Math.min(a / 12, 4)), this.n2 = i.fromHueAndChroma(n, Math.min(a / 6, 8))) : (this.a1 = i.fromHueAndChroma(n, Math.max(48, a)), this.a2 = i.fromHueAndChroma(n, 16), this.a3 = i.fromHueAndChroma(n + 60, 24), this.n1 = i.fromHueAndChroma(n, 4), this.n2 = i.fromHueAndChroma(n, 8)), this.error = i.fromHueAndChroma(25, 84);
}
}
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class m {
get primary() {
return this.props.primary;
}
get onPrimary() {
return this.props.onPrimary;
}
get primaryContainer() {
return this.props.primaryContainer;
}
get onPrimaryContainer() {
return this.props.onPrimaryContainer;
}
get secondary() {
return this.props.secondary;
}
get onSecondary() {
return this.props.onSecondary;
}
get secondaryContainer() {
return this.props.secondaryContainer;
}
get onSecondaryContainer() {
return this.props.onSecondaryContainer;
}
get tertiary() {
return this.props.tertiary;
}
get onTertiary() {
return this.props.onTertiary;
}
get tertiaryContainer() {
return this.props.tertiaryContainer;
}
get onTertiaryContainer() {
return this.props.onTertiaryContainer;
}
get error() {
return this.props.error;
}
get onError() {
return this.props.onError;
}
get errorContainer() {
return this.props.errorContainer;
}
get onErrorContainer() {
return this.props.onErrorContainer;
}
get background() {
return this.props.background;
}
get onBackground() {
return this.props.onBackground;
}
get surface() {
return this.props.surface;
}
get onSurface() {
return this.props.onSurface;
}
get surfaceVariant() {
return this.props.surfaceVariant;
}
get onSurfaceVariant() {
return this.props.onSurfaceVariant;
}
get outline() {
return this.props.outline;
}
get outlineVariant() {
return this.props.outlineVariant;
}
get shadow() {
return this.props.shadow;
}
get scrim() {
return this.props.scrim;
}
get inverseSurface() {
return this.props.inverseSurface;
}
get inverseOnSurface() {
return this.props.inverseOnSurface;
}
get inversePrimary() {
return this.props.inversePrimary;
}
/**
* @param argb ARGB representation of a color.
* @return Light Material color scheme, based on the color's hue.
*/
static light(r) {
return m.lightFromCorePalette(s.of(r));
}
/**
* @param argb ARGB representation of a color.
* @return Dark Material color scheme, based on the color's hue.
*/
static dark(r) {
return m.darkFromCorePalette(s.of(r));
}
/**
* @param argb ARGB representation of a color.
* @return Light Material content color scheme, based on the color's hue.
*/
static lightContent(r) {
return m.lightFromCorePalette(s.contentOf(r));
}
/**
* @param argb ARGB representation of a color.
* @return Dark Material content color scheme, based on the color's hue.
*/
static darkContent(r) {
return m.darkFromCorePalette(s.contentOf(r));
}
/**
* Light scheme from core palette
*/
static lightFromCorePalette(r) {
return new m({
primary: r.a1.tone(40),
onPrimary: r.a1.tone(100),
primaryContainer: r.a1.tone(90),
onPrimaryContainer: r.a1.tone(10),
secondary: r.a2.tone(40),
onSecondary: r.a2.tone(100),
secondaryContainer: r.a2.tone(90),
onSecondaryContainer: r.a2.tone(10),
tertiary: r.a3.tone(40),
onTertiary: r.a3.tone(100),
tertiaryContainer: r.a3.tone(90),
onTertiaryContainer: r.a3.tone(10),
error: r.error.tone(40),
onError: r.error.tone(100),
errorContainer: r.error.tone(90),
onErrorContainer: r.error.tone(10),
background: r.n1.tone(99),
onBackground: r.n1.tone(10),
surface: r.n1.tone(99),
onSurface: r.n1.tone(10),
surfaceVariant: r.n2.tone(90),
onSurfaceVariant: r.n2.tone(30),
outline: r.n2.tone(50),
outlineVariant: r.n2.tone(80),
shadow: r.n1.tone(0),
scrim: r.n1.tone(0),
inverseSurface: r.n1.tone(20),
inverseOnSurface: r.n1.tone(95),
inversePrimary: r.a1.tone(80)
});
}
/**
* Dark scheme from core palette
*/
static darkFromCorePalette(r) {
return new m({
primary: r.a1.tone(80),
onPrimary: r.a1.tone(20),
primaryContainer: r.a1.tone(30),
onPrimaryContainer: r.a1.tone(90),
secondary: r.a2.tone(80),
onSecondary: r.a2.tone(20),
secondaryContainer: r.a2.tone(30),
onSecondaryContainer: r.a2.tone(90),
tertiary: r.a3.tone(80),
onTertiary: r.a3.tone(20),
tertiaryContainer: r.a3.tone(30),
onTertiaryContainer: r.a3.tone(90),
error: r.error.tone(80),
onError: r.error.tone(20),
errorContainer: r.error.tone(30),
onErrorContainer: r.error.tone(80),
background: r.n1.tone(10),
onBackground: r.n1.tone(90),
surface: r.n1.tone(10),
onSurface: r.n1.tone(90),
surfaceVariant: r.n2.tone(30),
onSurfaceVariant: r.n2.tone(80),
outline: r.n2.tone(60),
outlineVariant: r.n2.tone(30),
shadow: r.n1.tone(0),
scrim: r.n1.tone(0),
inverseSurface: r.n1.tone(90),
inverseOnSurface: r.n1.tone(20),
inversePrimary: r.a1.tone(40)
});
}
constructor(r) {
this.props = r;
}
toJSON() {
return {
...this.props
};
}
}
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function I(h, r = []) {
const t = s.of(h);
return {
source: h,
schemes: {
light: m.light(h),
dark: m.dark(h)
},
palettes: {
primary: t.a1,
secondary: t.a2,
tertiary: t.a3,
neutral: t.n1,
neutralVariant: t.n2,
error: t.error
},
customColors: r.map((e) => F(h, e))
};
}
function F(h, r) {
let t = r.value;
const e = t, n = h;
r.blend && (t = C.harmonize(e, n));
const o = s.of(t).a1;
return {
color: r,
value: t,
light: {
color: o.tone(40),
onColor: o.tone(100),
colorContainer: o.tone(90),
onColorContainer: o.tone(10)
},
dark: {
color: o.tone(80),
onColor: o.tone(20),
colorContainer: o.tone(30),
onColorContainer: o.tone(90)
}
};
}
function P(h) {
const r = b(h);
return I(r);
}
export {
P as createTheme
};