@wistia/kaleidoscope 0.0.6 → 0.0.7
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/CHANGELOG.md +10 -0
- package/dist/{color-BY2NrNVz.js → color-BgYVUbOQ.js} +3 -3
- package/dist/{color-BY2NrNVz.js.map → color-BgYVUbOQ.js.map} +1 -1
- package/dist/{engine-DeOUPRa0.js → engine-DHDkDPaV.js} +385 -80
- package/dist/engine-DHDkDPaV.js.map +1 -0
- package/dist/entries/color.js +3 -3
- package/dist/entries/engine.js +2 -2
- package/dist/entries/styleRegistry.js +2 -2
- package/dist/entries/validate.js +2 -2
- package/dist/entries/vocabulary.js +3 -3
- package/dist/{getColorLightnessClassification--FSkjXEx.js → getColorLightnessClassification-C6BXD8Da.js} +2 -2
- package/dist/{getColorLightnessClassification--FSkjXEx.js.map → getColorLightnessClassification-C6BXD8Da.js.map} +1 -1
- package/dist/{guards-t_cf_IOV.js → guards-BJfumKYK.js} +2 -2
- package/dist/{guards-t_cf_IOV.js.map → guards-BJfumKYK.js.map} +1 -1
- package/dist/index.js +8 -8
- package/dist/{styleRegistry-CT4jvu4h.js → styleRegistry-Dcho9r3B.js} +31 -31
- package/dist/styleRegistry-Dcho9r3B.js.map +1 -0
- package/dist/{styleVocabulary-DcxbkEvK.js → styleVocabulary-DMhXOr4F.js} +2 -2
- package/dist/{styleVocabulary-DcxbkEvK.js.map → styleVocabulary-DMhXOr4F.js.map} +1 -1
- package/dist/{typography-BA9Pz8Im.js → typography-BLPIIq_8.js} +2 -2
- package/dist/{typography-BA9Pz8Im.js.map → typography-BLPIIq_8.js.map} +1 -1
- package/dist/{validate-D-OR7_3g.js → validate-BkOpEpch.js} +5 -5
- package/dist/{validate-D-OR7_3g.js.map → validate-BkOpEpch.js.map} +1 -1
- package/package.json +2 -2
- package/styles/glass-dark.json +13 -13
- package/styles/glass-light.json +16 -16
- package/dist/engine-DeOUPRa0.js.map +0 -1
- package/dist/styleRegistry-CT4jvu4h.js.map +0 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
|
|
2
2
|
/*
|
|
3
|
-
* @license @wistia/kaleidoscope v0.0.
|
|
3
|
+
* @license @wistia/kaleidoscope v0.0.7
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) 2026, Wistia, Inc. and its affiliates.
|
|
6
6
|
*
|
|
7
7
|
* This source code is unlicensed, all rights reserved.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { c as getBestColorForText, d as colorContrastRatiosByShape, f as Color, h as clamp, n as buildBrandedColorScale, o as getBrandLightBackgroundColor, s as getBrandDarkBackgroundColor, t as getColorLightnessClassification, u as adjustColorForProperContrast } from "./getColorLightnessClassification
|
|
11
|
-
import { l as ORNAMENTAL_BORDER_STYLES, n as TYPE_ROLES, o as STACKABLE_ON, s as SURFACE_NAMES } from "./typography-
|
|
12
|
-
import { n as isOneOf } from "./guards-
|
|
10
|
+
import { c as getBestColorForText, d as colorContrastRatiosByShape, f as Color, h as clamp, n as buildBrandedColorScale, o as getBrandLightBackgroundColor, s as getBrandDarkBackgroundColor, t as getColorLightnessClassification, u as adjustColorForProperContrast } from "./getColorLightnessClassification-C6BXD8Da.js";
|
|
11
|
+
import { l as ORNAMENTAL_BORDER_STYLES, n as TYPE_ROLES, o as STACKABLE_ON, s as SURFACE_NAMES } from "./typography-BLPIIq_8.js";
|
|
12
|
+
import { n as isOneOf } from "./guards-BJfumKYK.js";
|
|
13
13
|
// src/brandTokens.ts
|
|
14
14
|
/** The Brand Kit tokens a Style document can reference, each as `$<name>`. */
|
|
15
15
|
const BRAND_TOKEN_NAMES = [
|
|
@@ -130,6 +130,7 @@ const resolveAnchors = (style, tokens) => {
|
|
|
130
130
|
primary: resolveSingleColor(colors.primary, tokens),
|
|
131
131
|
ground: colors.ground === void 0 ? null : resolveSingleColor(colors.ground, tokens)
|
|
132
132
|
},
|
|
133
|
+
gradientStops: colors.gradientStops?.map((stop) => resolveSingleColor(stop, tokens)) ?? null,
|
|
133
134
|
scales: {
|
|
134
135
|
pageBackground: scaleBeforeTone(colors.pageBackground, tokens),
|
|
135
136
|
primary: scaleBeforeTone(colors.primary, tokens),
|
|
@@ -194,11 +195,11 @@ const ELEVATION_SLOTS = {
|
|
|
194
195
|
surfaces: SURFACE_NAMES,
|
|
195
196
|
initialValues: { "box-shadow": "none" }
|
|
196
197
|
};
|
|
197
|
-
|
|
198
|
+
/** The elevation's shadow, if it casts one, with any layers the treatment draws after it. */
|
|
199
|
+
const elevationSlots = ({ depth, hardness }, treatmentLayers = []) => {
|
|
198
200
|
const shadow = depth === "none" ? void 0 : SHADOWS[hardness]?.[depth];
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return { "box-shadow": `${x}px ${y}px ${blur}px rgba(0, 0, 0, ${alpha})` };
|
|
201
|
+
const layers = [...shadow === void 0 ? [] : [`${shadow.x}px ${shadow.y}px ${shadow.blur}px rgba(0, 0, 0, ${shadow.alpha})`], ...treatmentLayers];
|
|
202
|
+
return layers.length === 0 ? {} : { "box-shadow": layers.join(", ") };
|
|
202
203
|
};
|
|
203
204
|
const elevationGaps = ({ elevation: { depth, hardness, source } }) => {
|
|
204
205
|
if (depth === "none") return [];
|
|
@@ -287,9 +288,332 @@ const flat = ({ anchors, parent, settings }) => {
|
|
|
287
288
|
if (parent !== null && solid.contrast(parent.solid) < 1.1) solid = stepAlong(scale, start, offset + 1);
|
|
288
289
|
return flatFill(solid, scale, parent);
|
|
289
290
|
};
|
|
291
|
+
// src/private/engine/constants/glass.ts
|
|
292
|
+
const GLASS_LIGHT_COLOR = "#ffffff";
|
|
293
|
+
const GLASS_SHADE_COLOR = "#000000";
|
|
294
|
+
const GLASS_SHEEN_ANGLE = "135deg";
|
|
295
|
+
const GLASS_SHEEN_STOPS = [
|
|
296
|
+
0,
|
|
297
|
+
45,
|
|
298
|
+
100
|
|
299
|
+
];
|
|
300
|
+
/** Panel inputs are the panel's text color at these alphas. Placeholders. */
|
|
301
|
+
const GLASS_INPUT_ALPHA = .08;
|
|
302
|
+
const GLASS_INPUT_FOCUS_ALPHA = .2;
|
|
303
|
+
const BACKDROP_FILTER = "blur(10px) saturate(180%)";
|
|
304
|
+
/** From the Phase 1 carousel sandbox. */
|
|
305
|
+
const DARK_CONTAINER = {
|
|
306
|
+
backdropFilter: BACKDROP_FILTER,
|
|
307
|
+
counterEdge: ["inset -1px -1px 1px 0", .13],
|
|
308
|
+
edge: "inset 0 0 3px 0",
|
|
309
|
+
edgeAlpha: .3,
|
|
310
|
+
groundAlpha: .25,
|
|
311
|
+
hoverGroundAlpha: .25,
|
|
312
|
+
innerShade: [
|
|
313
|
+
"inset 0 4px 20px",
|
|
314
|
+
GLASS_SHADE_COLOR,
|
|
315
|
+
.1
|
|
316
|
+
],
|
|
317
|
+
liftsParent: false,
|
|
318
|
+
sheen: [
|
|
319
|
+
.25,
|
|
320
|
+
.1,
|
|
321
|
+
.02
|
|
322
|
+
],
|
|
323
|
+
specular: ["inset 0 7px 2px -6px", "inset 10px 6px 3px -10px"],
|
|
324
|
+
specularAlpha: .55
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* The design file gives panel and card one fill; a card has a finer edge and a denser hover. A
|
|
328
|
+
* shadow can't scale with its element, so the smaller tiers keep one soft highlight.
|
|
329
|
+
*/
|
|
330
|
+
const DARK_CARD = {
|
|
331
|
+
backdropFilter: BACKDROP_FILTER,
|
|
332
|
+
counterEdge: ["inset -1px -1px 1px 0", .11],
|
|
333
|
+
edge: "inset 0 0 2px 0",
|
|
334
|
+
edgeAlpha: .28,
|
|
335
|
+
groundAlpha: .25,
|
|
336
|
+
hoverGroundAlpha: .37,
|
|
337
|
+
innerShade: [
|
|
338
|
+
"inset 0 4px 20px",
|
|
339
|
+
GLASS_SHADE_COLOR,
|
|
340
|
+
.1
|
|
341
|
+
],
|
|
342
|
+
liftsParent: false,
|
|
343
|
+
sheen: [
|
|
344
|
+
.2,
|
|
345
|
+
.08,
|
|
346
|
+
.02
|
|
347
|
+
],
|
|
348
|
+
specular: ["inset 0 1px 2px 0"],
|
|
349
|
+
specularAlpha: .25
|
|
350
|
+
};
|
|
351
|
+
const DARK_CONTROL = {
|
|
352
|
+
backdropFilter: null,
|
|
353
|
+
counterEdge: ["inset -1px -1px 1px 0", .09],
|
|
354
|
+
edge: "inset 0 0 2px 0",
|
|
355
|
+
edgeAlpha: .22,
|
|
356
|
+
groundAlpha: .08,
|
|
357
|
+
hoverGroundAlpha: .25,
|
|
358
|
+
innerShade: null,
|
|
359
|
+
liftsParent: true,
|
|
360
|
+
sheen: [
|
|
361
|
+
.15,
|
|
362
|
+
.08,
|
|
363
|
+
.02
|
|
364
|
+
],
|
|
365
|
+
specular: ["inset 0 1px 2px 0"],
|
|
366
|
+
specularAlpha: .2
|
|
367
|
+
};
|
|
368
|
+
/** The design file has no light glass. A denser ground, and every shadow layer is white. */
|
|
369
|
+
const LIGHT_CONTAINER = {
|
|
370
|
+
...DARK_CONTAINER,
|
|
371
|
+
counterEdge: ["inset -1px -1px 1px 0", .7],
|
|
372
|
+
edge: "inset 1px 1px 0 0",
|
|
373
|
+
edgeAlpha: .75,
|
|
374
|
+
groundAlpha: .45,
|
|
375
|
+
hoverGroundAlpha: .45,
|
|
376
|
+
innerShade: [
|
|
377
|
+
"inset 0 4px 20px",
|
|
378
|
+
GLASS_LIGHT_COLOR,
|
|
379
|
+
.35
|
|
380
|
+
],
|
|
381
|
+
specularAlpha: .9
|
|
382
|
+
};
|
|
383
|
+
const LIGHT_CARD = {
|
|
384
|
+
...DARK_CARD,
|
|
385
|
+
counterEdge: ["inset -1px -1px 1px 0", .6],
|
|
386
|
+
edgeAlpha: .85,
|
|
387
|
+
groundAlpha: .45,
|
|
388
|
+
hoverGroundAlpha: .62,
|
|
389
|
+
innerShade: [
|
|
390
|
+
"inset 0 4px 20px",
|
|
391
|
+
GLASS_LIGHT_COLOR,
|
|
392
|
+
.3
|
|
393
|
+
],
|
|
394
|
+
specularAlpha: .8
|
|
395
|
+
};
|
|
396
|
+
const LIGHT_CONTROL = {
|
|
397
|
+
...DARK_CONTROL,
|
|
398
|
+
counterEdge: ["inset -1px -1px 1px 0", .45],
|
|
399
|
+
edgeAlpha: .7,
|
|
400
|
+
groundAlpha: .35,
|
|
401
|
+
hoverGroundAlpha: .6,
|
|
402
|
+
liftsParent: false,
|
|
403
|
+
specularAlpha: .5
|
|
404
|
+
};
|
|
405
|
+
const GLASS_TIERS = {
|
|
406
|
+
dark: {
|
|
407
|
+
page: DARK_CONTAINER,
|
|
408
|
+
panel: DARK_CONTAINER,
|
|
409
|
+
card: DARK_CARD,
|
|
410
|
+
buttonPrimary: DARK_CONTROL,
|
|
411
|
+
buttonSecondary: DARK_CONTROL
|
|
412
|
+
},
|
|
413
|
+
light: {
|
|
414
|
+
page: LIGHT_CONTAINER,
|
|
415
|
+
panel: LIGHT_CONTAINER,
|
|
416
|
+
card: LIGHT_CARD,
|
|
417
|
+
buttonPrimary: LIGHT_CONTROL,
|
|
418
|
+
buttonSecondary: LIGHT_CONTROL
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
// src/private/engine/rules/text.ts
|
|
422
|
+
const TEXT_SLOTS = {
|
|
423
|
+
surfaces: SURFACE_NAMES,
|
|
424
|
+
initialValues: { "text-color": "canvastext" }
|
|
425
|
+
};
|
|
426
|
+
const CONTENT_TEXT_SLOTS = {
|
|
427
|
+
surfaces: surfacesWhere("holdsContent"),
|
|
428
|
+
initialValues: {
|
|
429
|
+
"heading-text-color": "canvastext",
|
|
430
|
+
"low-emphasis-text-color": "canvastext"
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
const HOVER_TEXT_SLOTS = {
|
|
434
|
+
surfaces: surfacesWhere("interactive"),
|
|
435
|
+
initialValues: { "text-color-hover": "canvastext" }
|
|
436
|
+
};
|
|
437
|
+
const CONTENT_HOVER_TEXT_SLOTS = {
|
|
438
|
+
surfaces: surfacesWhere("interactive").filter((surface) => SURFACES[surface].holdsContent),
|
|
439
|
+
initialValues: {
|
|
440
|
+
"heading-text-color-hover": "canvastext",
|
|
441
|
+
"low-emphasis-text-color-hover": "canvastext"
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
const isPreference = (textColor) => typeof textColor === "object" && "source" in textColor;
|
|
445
|
+
const isLiteral = (textColor) => typeof textColor === "string" && (textColor.startsWith("#") || textColor.startsWith("rgb"));
|
|
446
|
+
/**
|
|
447
|
+
* `derive` allows text color to be calculated by the engine so we can pick a color with appropriate contrast.
|
|
448
|
+
* A preferred color starts from a reference point (a color anchor) and adjusts it until it meets required contrast rule
|
|
449
|
+
* A literal is used as written, with no contrast guarantee.
|
|
450
|
+
*/
|
|
451
|
+
const resolveTextColor = (textColor, solid, anchors) => {
|
|
452
|
+
if (isLiteral(textColor)) return new Color(textColor);
|
|
453
|
+
if (!isPreference(textColor)) return getBestColorForText({ backgroundColor: solid });
|
|
454
|
+
const { offset, source } = textColor;
|
|
455
|
+
const preferred = stepAlong(anchorScale(source, anchors), anchorColor(source, anchors), offset);
|
|
456
|
+
return adjustColorForProperContrast({
|
|
457
|
+
foregroundColor: preferred,
|
|
458
|
+
backgroundColor: solid
|
|
459
|
+
});
|
|
460
|
+
};
|
|
461
|
+
const textSlots = (surface, text) => ({
|
|
462
|
+
"text-color": text.toHex(),
|
|
463
|
+
...SURFACES[surface].holdsContent ? {
|
|
464
|
+
"heading-text-color": text.toHex(),
|
|
465
|
+
"low-emphasis-text-color": text.withAlpha(LOW_EMPHASIS_TEXT_ALPHA).toRgba()
|
|
466
|
+
} : {}
|
|
467
|
+
});
|
|
468
|
+
/**
|
|
469
|
+
* The same text slots with a `-hover` suffix, moved only as far as the hovered fill needs. A literal
|
|
470
|
+
* stays as written.
|
|
471
|
+
*/
|
|
472
|
+
const hoverTextSlots = (surface, textColor, text, solidHover) => {
|
|
473
|
+
const readable = isLiteral(textColor) ? text : adjustColorForProperContrast({
|
|
474
|
+
foregroundColor: text,
|
|
475
|
+
backgroundColor: solidHover
|
|
476
|
+
});
|
|
477
|
+
return Object.fromEntries(Object.entries(textSlots(surface, readable)).map(([slot, value]) => [`${slot}-hover`, value]));
|
|
478
|
+
};
|
|
479
|
+
const textGaps = ({ textColor }) => textColor === "derive" || isPreference(textColor) || isLiteral(textColor) ? [] : [`textColor: ${JSON.stringify(textColor)}`];
|
|
480
|
+
// src/private/engine/treatments/glassy.ts
|
|
481
|
+
const LIGHT = new Color(GLASS_LIGHT_COLOR);
|
|
482
|
+
/** `top` laid over `under`, flattened to the opaque color the eye sees. */
|
|
483
|
+
const composite = (top, under) => new Color([
|
|
484
|
+
top.r * top.a + under.r * (1 - top.a),
|
|
485
|
+
top.g * top.a + under.g * (1 - top.a),
|
|
486
|
+
top.b * top.a + under.b * (1 - top.a),
|
|
487
|
+
1
|
|
488
|
+
]);
|
|
489
|
+
const sheen = ({ sheen: alphas }) => {
|
|
490
|
+
const stops = alphas.map((alpha, index) => `${LIGHT.withAlpha(alpha).toRgba()} ${GLASS_SHEEN_STOPS[index] ?? 100}%`);
|
|
491
|
+
return `linear-gradient(${GLASS_SHEEN_ANGLE}, ${stops.join(", ")})`;
|
|
492
|
+
};
|
|
493
|
+
/** Inner shade, then the edge, then the specular highlights and the fainter edge opposite them. */
|
|
494
|
+
const glassShadowLayers = (tier) => [
|
|
495
|
+
...tier.innerShade === null ? [] : [`${tier.innerShade[0]} ${new Color(tier.innerShade[1]).withAlpha(tier.innerShade[2]).toRgba()}`],
|
|
496
|
+
`${tier.edge} ${LIGHT.withAlpha(tier.edgeAlpha).toRgba()}`,
|
|
497
|
+
...tier.specular.map((geometry) => `${geometry} ${LIGHT.withAlpha(tier.specularAlpha).toRgba()}`),
|
|
498
|
+
`${tier.counterEdge[0]} ${LIGHT.withAlpha(tier.counterEdge[1]).toRgba()}`
|
|
499
|
+
];
|
|
500
|
+
/**
|
|
501
|
+
* A translucent ground under a sheen. `solid` is that ground flattened over the parent, so text and
|
|
502
|
+
* children resolve against what the eye sees.
|
|
503
|
+
*/
|
|
504
|
+
const glassy = ({ anchors, parent, settings, surface }) => {
|
|
505
|
+
const { offset, source } = settings.backgroundColor;
|
|
506
|
+
const sourceColor = source === "parent" ? parent?.solid ?? anchorColor("anchors.colors.pageBackground", anchors) : anchorColor(source, anchors);
|
|
507
|
+
const tone = (anchors.colors.ground ?? sourceColor).luminance() < .2 ? "dark" : "light";
|
|
508
|
+
const tier = GLASS_TIERS[tone][surface];
|
|
509
|
+
const inherited = source === "parent" ? parent?.scale ?? null : anchors.scales[anchorName(source)];
|
|
510
|
+
const base = stepAlong(inherited ?? scaleOf(sourceColor), sourceColor, offset);
|
|
511
|
+
const under = parent?.solid ?? base;
|
|
512
|
+
const ground = (tier.liftsParent ? resolveTextColor(settings.textColor, under, anchors) : base).withAlpha(tier.groundAlpha);
|
|
513
|
+
const image = sheen(tier);
|
|
514
|
+
return {
|
|
515
|
+
solid: composite(ground, under),
|
|
516
|
+
scale: null,
|
|
517
|
+
fill: {
|
|
518
|
+
"background-color": ground.toRgba(),
|
|
519
|
+
"background-image": image,
|
|
520
|
+
...tier.backdropFilter === null ? {} : { "backdrop-filter": tier.backdropFilter }
|
|
521
|
+
},
|
|
522
|
+
hover: () => {
|
|
523
|
+
const groundHover = base.withAlpha(tier.hoverGroundAlpha);
|
|
524
|
+
return {
|
|
525
|
+
solid: composite(groundHover, under),
|
|
526
|
+
slots: {
|
|
527
|
+
"background-color-hover": groundHover.toRgba(),
|
|
528
|
+
"background-image-hover": image
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
},
|
|
532
|
+
tintedBy: (text) => ({
|
|
533
|
+
inputFills: {
|
|
534
|
+
"input-background-color": text.withAlpha(GLASS_INPUT_ALPHA).toRgba(),
|
|
535
|
+
"input-background-color-focus": text.withAlpha(GLASS_INPUT_FOCUS_ALPHA).toRgba()
|
|
536
|
+
},
|
|
537
|
+
shadowLayers: glassShadowLayers(tier)
|
|
538
|
+
})
|
|
539
|
+
};
|
|
540
|
+
};
|
|
541
|
+
// src/private/engine/constants/gradient.ts
|
|
542
|
+
/**
|
|
543
|
+
* `glows`: soft orbs in the stop colors over the surface's own fill. A dark fill swallows them, so
|
|
544
|
+
* there they are stronger and fuller. Placeholder.
|
|
545
|
+
*/
|
|
546
|
+
const GLOWS = {
|
|
547
|
+
alpha: .42,
|
|
548
|
+
size: "62% 56%",
|
|
549
|
+
fadeStop: 70,
|
|
550
|
+
darkFillLuminance: .2,
|
|
551
|
+
dark: {
|
|
552
|
+
alpha: .72,
|
|
553
|
+
size: "72% 66%",
|
|
554
|
+
midAlphaFactor: .6,
|
|
555
|
+
midStop: 38,
|
|
556
|
+
fadeStop: 72
|
|
557
|
+
},
|
|
558
|
+
positions: [
|
|
559
|
+
"14% 16%",
|
|
560
|
+
"86% 22%",
|
|
561
|
+
"62% 92%",
|
|
562
|
+
"10% 80%",
|
|
563
|
+
"48% 50%",
|
|
564
|
+
"94% 66%"
|
|
565
|
+
]
|
|
566
|
+
};
|
|
567
|
+
// src/private/engine/treatments/gradient.ts
|
|
568
|
+
const glowLayer = (stop, position, onDark) => {
|
|
569
|
+
if (onDark) {
|
|
570
|
+
const { alpha, fadeStop, midAlphaFactor, midStop, size } = GLOWS.dark;
|
|
571
|
+
return `radial-gradient(${size} at ${position}, ${stop.withAlpha(alpha).toRgba()} 0%, ${stop.withAlpha(alpha * midAlphaFactor).toRgba()} ${midStop}%, transparent ${fadeStop}%)`;
|
|
572
|
+
}
|
|
573
|
+
return `radial-gradient(${GLOWS.size} at ${position}, ${stop.withAlpha(GLOWS.alpha).toRgba()} 0%, transparent ${GLOWS.fadeStop}%)`;
|
|
574
|
+
};
|
|
575
|
+
const glowsImage = (stops, fill) => {
|
|
576
|
+
const onDark = fill.luminance() < GLOWS.darkFillLuminance;
|
|
577
|
+
return stops.map((stop, index) => glowLayer(stop, GLOWS.positions[index % GLOWS.positions.length] ?? "center", onDark)).join(", ");
|
|
578
|
+
};
|
|
579
|
+
/**
|
|
580
|
+
* Gradient layers over the surface's own fill. The fill is `solid`: it is what text is solved
|
|
581
|
+
* against, so nothing derives a color from the layers moving over it.
|
|
582
|
+
*/
|
|
583
|
+
const gradient = ({ anchors, parent, settings }) => {
|
|
584
|
+
const { gradientStops } = anchors;
|
|
585
|
+
if (gradientStops === null) throw new Error("anchors.colors.gradientStops is referenced but not declared");
|
|
586
|
+
const { from, offset, source } = settings.backgroundColor;
|
|
587
|
+
const sourceColor = source === "parent" ? parent?.solid ?? anchorColor("anchors.colors.pageBackground", anchors) : anchorColor(source, anchors);
|
|
588
|
+
const scale = (source === "parent" ? parent?.scale ?? null : anchors.scales[anchorName(source)]) ?? scaleOf(sourceColor);
|
|
589
|
+
const start = from === "parent" && parent !== null ? parent.solid : sourceColor;
|
|
590
|
+
const solid = stepAlong(scale, start, offset);
|
|
591
|
+
const image = glowsImage(gradientStops, solid);
|
|
592
|
+
return {
|
|
593
|
+
solid,
|
|
594
|
+
scale,
|
|
595
|
+
fill: {
|
|
596
|
+
"background-color": solid.toHex(),
|
|
597
|
+
"background-image": image
|
|
598
|
+
},
|
|
599
|
+
hover: () => ({
|
|
600
|
+
solid,
|
|
601
|
+
slots: {
|
|
602
|
+
"background-color-hover": solid.toHex(),
|
|
603
|
+
"background-image-hover": image
|
|
604
|
+
}
|
|
605
|
+
})
|
|
606
|
+
};
|
|
607
|
+
};
|
|
608
|
+
/** Only `glows` so far. */
|
|
609
|
+
const gradientGaps = ({ gradientShape }) => gradientShape === void 0 || gradientShape.kind === "glows" ? [] : [`gradientShape: ${gradientShape.kind}`];
|
|
290
610
|
// src/private/engine/treatments/index.ts
|
|
291
611
|
/** The treatments the engine can paint. A Style using any other is not supported yet. */
|
|
292
|
-
const TREATMENT_FUNCTIONS = {
|
|
612
|
+
const TREATMENT_FUNCTIONS = {
|
|
613
|
+
flat,
|
|
614
|
+
glassy,
|
|
615
|
+
gradient
|
|
616
|
+
};
|
|
293
617
|
// src/private/engine/rules/fill.ts
|
|
294
618
|
/**
|
|
295
619
|
* A surface's fill. `background-image` holds layers drawn over `background-color` — glass sheens,
|
|
@@ -310,7 +634,18 @@ const HOVER_FILL_SLOTS = {
|
|
|
310
634
|
"background-image-hover": "none"
|
|
311
635
|
}
|
|
312
636
|
};
|
|
313
|
-
|
|
637
|
+
/** Glass has a fixed ground that its parent shows through, so it can't count from its parent. */
|
|
638
|
+
const fromGaps = ({ backgroundColor: { from }, treatment }) => treatment === "glassy" && from === "parent" ? ["backgroundColor.from: parent"] : [];
|
|
639
|
+
/** Inverting repaints a surface as a flat fill, so no other treatment can invert. */
|
|
640
|
+
const invertGaps = ({ backgroundColor: { invert }, treatment }) => treatment === "flat" || invert === "never" ? [] : [`backgroundColor.invert: ${invert}`];
|
|
641
|
+
const fillGaps = (settings) => {
|
|
642
|
+
const { treatment } = settings;
|
|
643
|
+
return [
|
|
644
|
+
...Object.hasOwn(TREATMENT_FUNCTIONS, treatment) ? [] : [`treatment: ${treatment}`],
|
|
645
|
+
...fromGaps(settings),
|
|
646
|
+
...invertGaps(settings)
|
|
647
|
+
];
|
|
648
|
+
};
|
|
314
649
|
// src/private/engine/constants/motion.ts
|
|
315
650
|
/** How long a surface takes to move between states. Placeholder. */
|
|
316
651
|
const TRANSITION_DURATIONS = {
|
|
@@ -326,21 +661,39 @@ const TRANSITIONED_PROPERTIES = [
|
|
|
326
661
|
"color"
|
|
327
662
|
];
|
|
328
663
|
const TRANSITION_EASING = "ease";
|
|
664
|
+
/** How long one drift takes per speed. */
|
|
665
|
+
const DRIFT_DURATIONS = {
|
|
666
|
+
slow: "10s",
|
|
667
|
+
medium: "6s",
|
|
668
|
+
fast: "3s"
|
|
669
|
+
};
|
|
329
670
|
// src/private/engine/rules/motion.ts
|
|
330
671
|
const MOTION_SLOTS = {
|
|
331
672
|
surfaces: SURFACE_NAMES,
|
|
332
|
-
initialValues: {
|
|
333
|
-
transition: "none",
|
|
334
|
-
animation: "none"
|
|
335
|
-
}
|
|
673
|
+
initialValues: { transition: "none" }
|
|
336
674
|
};
|
|
337
|
-
|
|
675
|
+
/**
|
|
676
|
+
* Only how long a page's drift takes. The contract is CSS variables only, so each consumer writes
|
|
677
|
+
* its own `@keyframes` and the layer that moves. `0s` means the page is still. Other surfaces have
|
|
678
|
+
* no animation slots until a Style first animates one.
|
|
679
|
+
*/
|
|
680
|
+
const PAGE_ANIMATION_SLOTS = {
|
|
681
|
+
surfaces: ["page"],
|
|
682
|
+
initialValues: { "animation-duration": "0s" }
|
|
683
|
+
};
|
|
684
|
+
const transitionSlots = (transition) => {
|
|
338
685
|
const duration = TRANSITION_DURATIONS[transition];
|
|
339
686
|
if (duration === null) return {};
|
|
340
687
|
return { transition: TRANSITIONED_PROPERTIES.map((property) => `${property} ${duration} ${TRANSITION_EASING}`).join(", ") };
|
|
341
688
|
};
|
|
342
|
-
/**
|
|
343
|
-
const
|
|
689
|
+
/** `motionGaps` only lets `drift` through on the page, so this never names another surface's slot. */
|
|
690
|
+
const driftSlots = ({ ambient, speed }) => ambient === "drift" ? { "animation-duration": DRIFT_DURATIONS[speed] } : {};
|
|
691
|
+
const motionSlots = (motion) => ({
|
|
692
|
+
...transitionSlots(motion.transition),
|
|
693
|
+
...driftSlots(motion)
|
|
694
|
+
});
|
|
695
|
+
/** Only the page drifts so far, and nothing pulses. */
|
|
696
|
+
const motionGaps = ({ motion: { ambient } }, surface) => ambient === "none" || ambient === "drift" && surface === "page" ? [] : [`motion.ambient: ${ambient}`];
|
|
344
697
|
// src/private/engine/rules/panelInput.ts
|
|
345
698
|
/** The form fields inside a panel. */
|
|
346
699
|
const PANEL_INPUT_SLOTS = {
|
|
@@ -351,10 +704,12 @@ const PANEL_INPUT_SLOTS = {
|
|
|
351
704
|
"input-border-color-focus": "transparent"
|
|
352
705
|
}
|
|
353
706
|
};
|
|
354
|
-
/** Inputs step off the panel's fill
|
|
355
|
-
const panelInputSlots = (solid, anchors) => ({
|
|
356
|
-
|
|
357
|
-
|
|
707
|
+
/** Inputs step off the panel's fill unless given `fills`, and take the primary color when focused. */
|
|
708
|
+
const panelInputSlots = (solid, anchors, fills) => ({
|
|
709
|
+
...fills ?? {
|
|
710
|
+
"input-background-color": stepFrom(solid, 1).toHex(),
|
|
711
|
+
"input-background-color-focus": stepFrom(solid, 2).toHex()
|
|
712
|
+
},
|
|
358
713
|
"input-border-color-focus": anchorColor("anchors.colors.primary", anchors).toHex()
|
|
359
714
|
});
|
|
360
715
|
// src/private/engine/constants/radius.ts
|
|
@@ -372,59 +727,6 @@ const RADIUS_SLOTS = {
|
|
|
372
727
|
initialValues: { "border-radius": "0" }
|
|
373
728
|
};
|
|
374
729
|
const radiusSlots = (surface, { source }, anchors) => ({ "border-radius": source === "anchors.dimensions.borderRadius" ? `${Math.round(anchors.borderRadius * RADIUS_FACTORS[surface])}px` : `${anchors.dimension(source)}px` });
|
|
375
|
-
// src/private/engine/rules/text.ts
|
|
376
|
-
const TEXT_SLOTS = {
|
|
377
|
-
surfaces: SURFACE_NAMES,
|
|
378
|
-
initialValues: { "text-color": "canvastext" }
|
|
379
|
-
};
|
|
380
|
-
const CONTENT_TEXT_SLOTS = {
|
|
381
|
-
surfaces: surfacesWhere("holdsContent"),
|
|
382
|
-
initialValues: {
|
|
383
|
-
"heading-text-color": "canvastext",
|
|
384
|
-
"low-emphasis-text-color": "canvastext"
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
const HOVER_TEXT_SLOTS = {
|
|
388
|
-
surfaces: surfacesWhere("interactive"),
|
|
389
|
-
initialValues: { "text-color-hover": "canvastext" }
|
|
390
|
-
};
|
|
391
|
-
const CONTENT_HOVER_TEXT_SLOTS = {
|
|
392
|
-
surfaces: surfacesWhere("interactive").filter((surface) => SURFACES[surface].holdsContent),
|
|
393
|
-
initialValues: {
|
|
394
|
-
"heading-text-color-hover": "canvastext",
|
|
395
|
-
"low-emphasis-text-color-hover": "canvastext"
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
const isPreference = (textColor) => typeof textColor === "object" && "source" in textColor;
|
|
399
|
-
/**
|
|
400
|
-
* `derive` allows text color to be calculated by the engine so we can pick a color with appropriate contrast.
|
|
401
|
-
* A preferred color starts from a reference point (a color anchor) and adjusts it until it meets required contrast rules.
|
|
402
|
-
*/
|
|
403
|
-
const resolveTextColor = (textColor, solid, anchors) => {
|
|
404
|
-
if (!isPreference(textColor)) return getBestColorForText({ backgroundColor: solid });
|
|
405
|
-
const { offset, source } = textColor;
|
|
406
|
-
const preferred = stepAlong(anchorScale(source, anchors), anchorColor(source, anchors), offset);
|
|
407
|
-
return adjustColorForProperContrast({
|
|
408
|
-
foregroundColor: preferred,
|
|
409
|
-
backgroundColor: solid
|
|
410
|
-
});
|
|
411
|
-
};
|
|
412
|
-
const textSlots = (surface, text) => ({
|
|
413
|
-
"text-color": text.toHex(),
|
|
414
|
-
...SURFACES[surface].holdsContent ? {
|
|
415
|
-
"heading-text-color": text.toHex(),
|
|
416
|
-
"low-emphasis-text-color": text.withAlpha(LOW_EMPHASIS_TEXT_ALPHA).toRgba()
|
|
417
|
-
} : {}
|
|
418
|
-
});
|
|
419
|
-
/** The same text slots with a `-hover` suffix, moved only as far as the hovered fill needs. */
|
|
420
|
-
const hoverTextSlots = (surface, text, solidHover) => {
|
|
421
|
-
const readable = adjustColorForProperContrast({
|
|
422
|
-
foregroundColor: text,
|
|
423
|
-
backgroundColor: solidHover
|
|
424
|
-
});
|
|
425
|
-
return Object.fromEntries(Object.entries(textSlots(surface, readable)).map(([slot, value]) => [`${slot}-hover`, value]));
|
|
426
|
-
};
|
|
427
|
-
const textGaps = ({ textColor }) => textColor === "derive" || isPreference(textColor) ? [] : [`textColor: ${JSON.stringify(textColor)}`];
|
|
428
730
|
// src/private/engine/constants/typography.ts
|
|
429
731
|
/** Letter spacing for `case: upper`, which reads cramped at the spacing set for mixed case. */
|
|
430
732
|
const UPPERCASE_LETTER_SPACING = "0.05em";
|
|
@@ -465,7 +767,8 @@ const SURFACE_SLOT_FRAGMENTS = [
|
|
|
465
767
|
BORDER_SLOTS,
|
|
466
768
|
ELEVATION_SLOTS,
|
|
467
769
|
RADIUS_SLOTS,
|
|
468
|
-
MOTION_SLOTS
|
|
770
|
+
MOTION_SLOTS,
|
|
771
|
+
PAGE_ANIMATION_SLOTS
|
|
469
772
|
];
|
|
470
773
|
const surfaceContract = () => Object.fromEntries(SURFACE_GROUPS.flatMap(({ prefix, surface }) => SURFACE_SLOT_FRAGMENTS.filter(({ surfaces }) => surfaces.includes(surface)).flatMap(({ initialValues }) => Object.entries(initialValues).map(([slot, value]) => [surfaceVariable(prefix, slot), value]))));
|
|
471
774
|
// src/kaleidoscopeContract.ts
|
|
@@ -526,6 +829,7 @@ const evaluateSurface = (style, surface, anchors, parent) => {
|
|
|
526
829
|
const { text, treated } = invertWhenIndistinct(settings, painted, resolveTextColor(settings.textColor, painted.solid, anchors), parent);
|
|
527
830
|
const spec = SURFACES[surface];
|
|
528
831
|
const hover = treated.hover(text);
|
|
832
|
+
const tinted = treated.tintedBy?.(text);
|
|
529
833
|
return {
|
|
530
834
|
solid: treated.solid,
|
|
531
835
|
scale: treated.scale,
|
|
@@ -533,12 +837,12 @@ const evaluateSurface = (style, surface, anchors, parent) => {
|
|
|
533
837
|
...treated.fill,
|
|
534
838
|
...spec.interactive ? {
|
|
535
839
|
...hover.slots,
|
|
536
|
-
...hoverTextSlots(surface, text, hover.solid)
|
|
840
|
+
...hoverTextSlots(surface, settings.textColor, text, hover.solid)
|
|
537
841
|
} : {},
|
|
538
842
|
...textSlots(surface, text),
|
|
539
|
-
...spec.mayContainForm ? panelInputSlots(treated.solid, anchors) : {},
|
|
843
|
+
...spec.mayContainForm ? panelInputSlots(treated.solid, anchors, tinted?.inputFills) : {},
|
|
540
844
|
...borderSlots(settings.border, treated.solid, anchors),
|
|
541
|
-
...elevationSlots(settings.elevation),
|
|
845
|
+
...elevationSlots(settings.elevation, tinted?.shadowLayers),
|
|
542
846
|
...radiusSlots(surface, settings.radius, anchors),
|
|
543
847
|
...motionSlots(settings.motion)
|
|
544
848
|
}
|
|
@@ -564,6 +868,7 @@ const textureGaps = ({ texture: { kind } }) => kind === "none" ? [] : [`texture.
|
|
|
564
868
|
// src/private/engine/support.ts
|
|
565
869
|
const GAP_FINDERS = [
|
|
566
870
|
fillGaps,
|
|
871
|
+
gradientGaps,
|
|
567
872
|
textGaps,
|
|
568
873
|
borderGaps,
|
|
569
874
|
elevationGaps,
|
|
@@ -571,7 +876,7 @@ const GAP_FINDERS = [
|
|
|
571
876
|
textureGaps
|
|
572
877
|
];
|
|
573
878
|
/** The rules in `style` the engine cannot resolve yet, as `<surface>.<setting>: <value>`. */
|
|
574
|
-
const findUnsupportedRules = (style) => SURFACE_NAMES.flatMap((surface) => GAP_FINDERS.flatMap((findGaps) => findGaps(style.surfaces[surface])).map((gap) => `${surface}.${gap}`));
|
|
879
|
+
const findUnsupportedRules = (style) => SURFACE_NAMES.flatMap((surface) => GAP_FINDERS.flatMap((findGaps) => findGaps(style.surfaces[surface], surface)).map((gap) => `${surface}.${gap}`));
|
|
575
880
|
// src/getKaleidoscopeStyles.ts
|
|
576
881
|
const resolveAgainstDefaultValues = (resolved) => ({
|
|
577
882
|
...KALEIDOSCOPE_CONTRACT,
|
|
@@ -658,4 +963,4 @@ const serializeKaleidoscopeStyles = (variables, selector) => {
|
|
|
658
963
|
};
|
|
659
964
|
export { BRAND_TOKEN_NAMES as a, VARIABLE_PREFIX as i, getKaleidoscopeStyles as n, DEFAULT_BRAND_TOKENS as o, KALEIDOSCOPE_CONTRACT as r, serializeKaleidoscopeStyles as t };
|
|
660
965
|
|
|
661
|
-
//# sourceMappingURL=engine-
|
|
966
|
+
//# sourceMappingURL=engine-DHDkDPaV.js.map
|