@phreshos/react-ui 0.1.40 → 0.1.41
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/surface/grain.d.ts
CHANGED
|
@@ -4,6 +4,15 @@
|
|
|
4
4
|
* without also fading that layer's backdrop.
|
|
5
5
|
*/
|
|
6
6
|
export declare function grainImage(seed: number, amount: number, opacity: number): string;
|
|
7
|
+
/**
|
|
8
|
+
* One grain texture as a shared class. Its name comes from the texture's own
|
|
9
|
+
* parameters, so server and browser rendering agree on it, and the rule is
|
|
10
|
+
* written once however many Surfaces use it instead of inline on each.
|
|
11
|
+
*/
|
|
12
|
+
export declare function grainTexture(seed: number, amount: number, opacity: number): Readonly<{
|
|
13
|
+
name: string;
|
|
14
|
+
rule: string;
|
|
15
|
+
}>;
|
|
7
16
|
/**
|
|
8
17
|
* One texture serves every Surface. Each Surface tiles it from its own origin,
|
|
9
18
|
* so neighbours never align, and equal paints can share one generated class.
|
package/dist/surface/grain.js
CHANGED
|
@@ -20,6 +20,15 @@ export function grainImage(seed, amount, opacity) {
|
|
|
20
20
|
resources.set(key, resource);
|
|
21
21
|
return resource;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* One grain texture as a shared class. Its name comes from the texture's own
|
|
25
|
+
* parameters, so server and browser rendering agree on it, and the rule is
|
|
26
|
+
* written once however many Surfaces use it instead of inline on each.
|
|
27
|
+
*/
|
|
28
|
+
export function grainTexture(seed, amount, opacity) {
|
|
29
|
+
const name = `phreshos-grain-${seed}-${amount}-${Math.round(opacity * 1_000)}`.replace(/[^a-z0-9-]/gi, "_");
|
|
30
|
+
return { name, rule: `:where(.${name}) { --phreshos-surface-grain: ${grainImage(seed, amount, opacity)} }` };
|
|
31
|
+
}
|
|
23
32
|
/**
|
|
24
33
|
* One texture serves every Surface. Each Surface tiles it from its own origin,
|
|
25
34
|
* so neighbours never align, and equal paints can share one generated class.
|
package/dist/surface/surface.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createElement, forwardRef, useId, useInsertionEffect } from "react";
|
|
|
3
3
|
import { canvasDarkness, colorOpacity, contrast, mixColor, readableColor, recessColor, resolveColor } from "../foundation/color.js";
|
|
4
4
|
import { resolveRadius } from "../foundation/radius.js";
|
|
5
5
|
import { useVisual } from "../foundation/visual.js";
|
|
6
|
-
import {
|
|
6
|
+
import { grainSeed, grainSize, grainTexture } from "./grain.js";
|
|
7
7
|
import { flushPaintRules, paintClass, usePaintClasses } from "./paint-class.js";
|
|
8
8
|
import { resolveMaterialOptions } from "./material-options.js";
|
|
9
9
|
import { resolveShadowOptions, shadowStyle } from "./shadow-options.js";
|
|
@@ -35,10 +35,10 @@ export const SurfaceView = forwardRef(function Surface({ as: Element = "div", co
|
|
|
35
35
|
return createElement(Element, {
|
|
36
36
|
...properties,
|
|
37
37
|
ref,
|
|
38
|
-
className: [surfaceClass, painted, dimmedClass(interaction?.disabled ?? false), className].filter(Boolean).join(" "),
|
|
38
|
+
className: [surfaceClass, paint.grain?.name, painted, dimmedClass(interaction?.disabled ?? false), className].filter(Boolean).join(" "),
|
|
39
39
|
// Without a document (server rendering), the same declarations travel inline.
|
|
40
40
|
style: painted === undefined ? { ...inlineDeclarations(declarations), ...style } : style
|
|
41
|
-
}, _jsx(SurfaceStyle, {}), paint.distortion > 0 && _jsx(Refraction, { identity: identity, distortion: paint.distortion }), children);
|
|
41
|
+
}, _jsx(SurfaceStyle, {}), paint.grain && _jsx(GrainStyle, { grain: paint.grain }), paint.distortion > 0 && _jsx(Refraction, { identity: identity, distortion: paint.distortion }), children);
|
|
42
42
|
});
|
|
43
43
|
function inlineDeclarations(declarations) {
|
|
44
44
|
const result = {};
|
|
@@ -94,8 +94,8 @@ export function surfacePaint(visual, color, depth, options, shadowOptions, inter
|
|
|
94
94
|
? [material.backdrop > 0 ? `blur(${material.backdrop}px)` : "", material.saturation !== 1 ? `saturate(${material.saturation})` : ""].filter(Boolean).join(" ")
|
|
95
95
|
: "";
|
|
96
96
|
const grain = level >= materialLevel.basic && material.grain > 0 && material.grainAmount > 0
|
|
97
|
-
?
|
|
98
|
-
:
|
|
97
|
+
? grainTexture(grainSeed, material.grainAmount, level === materialLevel.basic ? material.grain * material.opacity : material.grain)
|
|
98
|
+
: null;
|
|
99
99
|
const ringBase = interaction?.invalid
|
|
100
100
|
? colors.danger
|
|
101
101
|
: !clear && (contrast(base, colors.background) ?? 1) >= 1.6 ? base : colors.primary;
|
|
@@ -135,9 +135,11 @@ export function surfacePaint(visual, color, depth, options, shadowOptions, inter
|
|
|
135
135
|
ring: colorOpacity(ringBase, 0.34),
|
|
136
136
|
shadow: [hairline, outer === "none" ? null : outer].filter(Boolean).join(", ") || "none",
|
|
137
137
|
distortion: level >= materialLevel.full && translucent ? material.distortion : 0,
|
|
138
|
+
grain,
|
|
138
139
|
variables: {
|
|
139
140
|
"--phreshos-surface-paint": translucent ? colorOpacity(fill, opacity) : fill,
|
|
140
|
-
|
|
141
|
+
// A grain texture arrives through its shared class; without one the layer is empty.
|
|
142
|
+
...(grain === null ? { "--phreshos-surface-grain": "none" } : {}),
|
|
141
143
|
"--phreshos-surface-frost": frost || "none",
|
|
142
144
|
"--phreshos-surface-rim": rim,
|
|
143
145
|
"--phreshos-surface-spill-top": spill("top"),
|
|
@@ -243,6 +245,10 @@ const stylesheet = `
|
|
|
243
245
|
mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
|
|
244
246
|
}
|
|
245
247
|
`;
|
|
248
|
+
/** One rule per grain texture, hoisted and deduplicated by React like the stylesheet below. */
|
|
249
|
+
function GrainStyle({ grain }) {
|
|
250
|
+
return _jsx("style", { href: grain.name, precedence: "phreshos", children: grain.rule });
|
|
251
|
+
}
|
|
246
252
|
/** React hoists and deduplicates this stylesheet, including inside portals. */
|
|
247
253
|
function SurfaceStyle() {
|
|
248
254
|
return _jsx("style", { href: "phreshos-react-ui-surface", precedence: "phreshos", children: stylesheet });
|