devnonla-ui 0.2.0 → 0.3.0

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.
@@ -0,0 +1,67 @@
1
+ export type SplitterSize = number | string;
2
+
3
+ export function parseSplitterSize(value: SplitterSize | undefined, container: number): number | undefined {
4
+ if (value == null || container < 0) return undefined;
5
+ if (typeof value === "number") return Number.isFinite(value) ? Math.max(0, value) : undefined;
6
+ const trimmed = value.trim();
7
+ if (!trimmed) return undefined;
8
+ if (trimmed.endsWith("%")) {
9
+ const n = Number.parseFloat(trimmed.slice(0, -1));
10
+ return Number.isFinite(n) ? Math.max(0, (n / 100) * container) : undefined;
11
+ }
12
+ const n = Number.parseFloat(trimmed);
13
+ return Number.isFinite(n) ? Math.max(0, n) : undefined;
14
+ }
15
+
16
+ export function distributeSizes(declared: Array<number | undefined>, container: number): number[] {
17
+ const count = declared.length;
18
+ if (count === 0) return [];
19
+ if (container <= 0) return declared.map((size) => size ?? 0);
20
+
21
+ let known = 0;
22
+ let unknown = 0;
23
+ for (const size of declared) {
24
+ if (size == null) unknown += 1;
25
+ else known += size;
26
+ }
27
+ const leftover = container - known;
28
+ const fill = unknown > 0 ? Math.max(0, leftover) / unknown : 0;
29
+ const sizes = declared.map((size) => size ?? fill);
30
+ const sum = sizes.reduce<number>((total, size) => total + size, 0);
31
+ if (sum <= 0) return sizes.map(() => container / count);
32
+ if (Math.abs(sum - container) > 0.5) return sizes.map((size) => (size / sum) * container);
33
+ return sizes;
34
+ }
35
+
36
+ export function scaleSizes(sizes: number[], container: number): number[] {
37
+ const count = sizes.length;
38
+ if (count === 0 || container <= 0) return sizes;
39
+ const sum = sizes.reduce<number>((total, size) => total + size, 0);
40
+ if (sum <= 0) return sizes.map(() => container / count);
41
+ return sizes.map((size) => (size / sum) * container);
42
+ }
43
+
44
+ export function applyDrag(
45
+ left: number,
46
+ right: number,
47
+ delta: number,
48
+ leftMin: number,
49
+ leftMax: number,
50
+ rightMin: number,
51
+ rightMax: number,
52
+ ): [number, number] {
53
+ const pair = left + right;
54
+ let nextLeft = Math.min(leftMax, Math.max(leftMin, left + delta));
55
+ let nextRight = pair - nextLeft;
56
+ if (nextRight < rightMin) {
57
+ nextRight = rightMin;
58
+ nextLeft = pair - nextRight;
59
+ }
60
+ if (nextRight > rightMax) {
61
+ nextRight = rightMax;
62
+ nextLeft = pair - nextRight;
63
+ }
64
+ nextLeft = Math.min(leftMax, Math.max(leftMin, nextLeft));
65
+ nextRight = pair - nextLeft;
66
+ return [Math.max(0, nextLeft), Math.max(0, nextRight)];
67
+ }
package/src/styles.css CHANGED
@@ -949,3 +949,18 @@
949
949
  .group\/scroll:hover .nonla-overlay-thumb {
950
950
  background: var(--nonla-scrollbar-thumb-hover);
951
951
  }
952
+
953
+ .nonla-color-checkered {
954
+ background-color: #fff;
955
+ background-image: conic-gradient(#d9d9d9 0.25turn, #fff 0.25turn 0.5turn, #d9d9d9 0.5turn 0.75turn, #fff 0.75turn);
956
+ background-size: 8px 8px;
957
+ }
958
+
959
+ .nonla-color-cleared {
960
+ background: linear-gradient(
961
+ to bottom left,
962
+ transparent calc(50% - 1px),
963
+ var(--destructive) calc(50% - 1px) calc(50% + 1px),
964
+ transparent calc(50% + 1px)
965
+ );
966
+ }