@solidrt/core 0.0.20 → 0.0.21
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/package.json +2 -2
- package/src/color.ts +21 -1
- package/src/environment.ts +28 -1
- package/src/index.ts +1 -1
- package/src/types.d.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidrt/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Antoine van Wel",
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"colord": "^2.9.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@solidrt/flux-types": "0.0.
|
|
30
|
+
"@solidrt/flux-types": "0.0.21"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@solidjs/signals": "2.0.0-beta.15",
|
package/src/color.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { colord, extend } from "colord"
|
|
2
2
|
import namesPlugin from "colord/plugins/names"
|
|
3
|
-
|
|
3
|
+
import mixPlugin from "colord/plugins/mix"
|
|
4
|
+
extend([namesPlugin, mixPlugin])
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Parses a CSS color string (named, hex, `rgb()`, `hsl()`, ...) into a packed
|
|
@@ -13,6 +14,25 @@ export function parseColor(color: string): number {
|
|
|
13
14
|
return (((r & 0xFF) << 24) | ((g & 0xFF) << 16) | ((b & 0xFF) << 8) | ((a * 255) & 0xFF)) >>> 0
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Mixes two CSS colors in the CIE LAB color space; `t` is the fraction of `b`
|
|
19
|
+
* (0 = pure `a`, 1 = pure `b`). Returns an opaque hex string. Use it to derive
|
|
20
|
+
* semantic tones (muted text, subtle borders) instead of alpha overlays, so
|
|
21
|
+
* the resulting color does not depend on what is drawn beneath it.
|
|
22
|
+
*/
|
|
23
|
+
export function mixColors(a: string, b: string, t: number): string {
|
|
24
|
+
return colord(a).mix(b, t).toHex()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Perceived brightness of a CSS color, 0 (black) to 1 (white), YIQ-weighted.
|
|
29
|
+
* Compare a text color against its backdrop to decide rendering polarity,
|
|
30
|
+
* e.g. whether a label sits light-on-dark (see typeWeight in components).
|
|
31
|
+
*/
|
|
32
|
+
export function brightness(color: string): number {
|
|
33
|
+
return colord(color).brightness()
|
|
34
|
+
}
|
|
35
|
+
|
|
16
36
|
// A color stop: `offset` is 0..1 along the gradient, `color` any CSS color string.
|
|
17
37
|
export type GradientStop = { offset: number; color: string }
|
|
18
38
|
|
package/src/environment.ts
CHANGED
|
@@ -55,6 +55,19 @@ function ensureOrientationState() {
|
|
|
55
55
|
orientationAccessor = orientation
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
let textScaleAccessor: (() => number) | undefined
|
|
59
|
+
|
|
60
|
+
function ensureTextScaleState() {
|
|
61
|
+
if (textScaleAccessor) return
|
|
62
|
+
let [scale, setScale] = createSignal(1)
|
|
63
|
+
// Sticky, like systemTheme. Guard nonsense values: a runtime bug reporting
|
|
64
|
+
// 0 or a negative would otherwise collapse all text.
|
|
65
|
+
on("textScale", (e: { scale?: number }) => {
|
|
66
|
+
setScale(typeof e.scale === "number" && e.scale > 0 ? e.scale : 1)
|
|
67
|
+
})
|
|
68
|
+
textScaleAccessor = scale
|
|
69
|
+
}
|
|
70
|
+
|
|
58
71
|
let mouseSeenAccessor: (() => boolean) | undefined
|
|
59
72
|
let touchSeenAccessor: (() => boolean) | undefined
|
|
60
73
|
|
|
@@ -127,11 +140,25 @@ export let env = {
|
|
|
127
140
|
ensureDevicesState()
|
|
128
141
|
return devicesAccessor!()
|
|
129
142
|
},
|
|
130
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* The OS-level dark/light preference. Starts "unknown" and resolves once
|
|
145
|
+
* the runtime's `systemTheme` event fires - read it in a tracked scope
|
|
146
|
+
* (JSX, memo, effect); a top-level/untracked read will freeze at
|
|
147
|
+
* "unknown" and never see the resolved value.
|
|
148
|
+
*/
|
|
131
149
|
get systemTheme(): SystemTheme {
|
|
132
150
|
ensureSystemThemeState()
|
|
133
151
|
return systemThemeAccessor!()
|
|
134
152
|
},
|
|
153
|
+
/**
|
|
154
|
+
* The OS text scaling preference (Dynamic Type / font scale), as a
|
|
155
|
+
* multiplier. 1 until a runtime reports it via the sticky `textScale`
|
|
156
|
+
* event; no runtime does yet.
|
|
157
|
+
*/
|
|
158
|
+
get textScale(): number {
|
|
159
|
+
ensureTextScaleState()
|
|
160
|
+
return textScaleAccessor!()
|
|
161
|
+
},
|
|
135
162
|
/** Orientation of the display the window is on. */
|
|
136
163
|
get orientation(): Orientation {
|
|
137
164
|
ensureOrientationState()
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./renderer"
|
|
2
2
|
export { setFocus, getFocusedNodeId, measureText, getBoundingBox } from "./core"
|
|
3
3
|
export type { BoundingBox } from "./core"
|
|
4
|
-
export { parseColor, createLinearGradient, createRadialGradient } from "./color"
|
|
4
|
+
export { parseColor, mixColors, brightness, createLinearGradient, createRadialGradient } from "./color"
|
|
5
5
|
export type { Gradient, GradientStop } from "./color"
|
|
6
6
|
export { onFrame, onLayout, onResize, onWindowFocus, onWindowBlur } from "./window"
|
|
7
7
|
export { setPointerCapture, releasePointerCapture } from "./window"
|
package/src/types.d.ts
CHANGED
|
@@ -136,6 +136,9 @@ export interface TransformProps {
|
|
|
136
136
|
y?: number
|
|
137
137
|
cx?: number
|
|
138
138
|
cy?: number
|
|
139
|
+
// Group opacity in 0..1: children are composited together, then faded as a
|
|
140
|
+
// whole (CSS `opacity`). Does not affect hit testing.
|
|
141
|
+
opacity?: number
|
|
139
142
|
scrollX?: number
|
|
140
143
|
scrollY?: number
|
|
141
144
|
}
|