@inc2734/unitone-css 0.91.1 → 0.93.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.
@@ -2,10 +2,44 @@
2
2
  --unitone--texture-color: var(--unitone--color--light-gray);
3
3
  --unitone--texture-gap: 50px;
4
4
  --unitone--texture-size: 1px;
5
+ --unitone--texture-top: 0px;
6
+ --unitone--texture-right: 0px;
7
+ --unitone--texture-bottom: 0px;
8
+ --unitone--texture-left: 0px;
9
+ --unitone--texture-border-radius: 0px;
10
+ --unitone--texture-border-top-left-radius: var(--unitone--texture-border-radius);
11
+ --unitone--texture-border-top-right-radius: var(--unitone--texture-border-radius);
12
+ --unitone--texture-border-bottom-left-radius: var(--unitone--texture-border-radius);
13
+ --unitone--texture-border-bottom-right-radius: var(--unitone--texture-border-radius);
5
14
 
6
- background-position: center;
15
+ position: relative;
7
16
 
8
- &[data-unitone-layout~="-texture\:dots"] {
17
+ @at-root {
18
+ :where(#{ & } > *) {
19
+ --unitone--position: relative;
20
+
21
+ position: var(--unitone--position);
22
+ }
23
+ }
24
+
25
+ &::before {
26
+ content: '';
27
+ position: absolute;
28
+ inset:
29
+ var(--unitone--texture-top)
30
+ var(--unitone--texture-right)
31
+ var(--unitone--texture-bottom)
32
+ var(--unitone--texture-left);
33
+ background-position: center;
34
+ border-radius:
35
+ var(--unitone--texture-border-top-left-radius)
36
+ var(--unitone--texture-border-top-right-radius)
37
+ var(--unitone--texture-border-bottom-right-radius)
38
+ var(--unitone--texture-border-bottom-left-radius);
39
+ }
40
+
41
+
42
+ &[data-unitone-layout~="-texture\:dots"]::before {
9
43
  background-image:
10
44
  radial-gradient(
11
45
  var(--unitone--texture-color) var(--unitone--texture-size),
@@ -16,7 +50,7 @@
16
50
  max(var(--unitone--texture-gap), var(--unitone--texture-size) * 2);
17
51
  }
18
52
 
19
- &[data-unitone-layout~="-texture\:offset-dots"] {
53
+ &[data-unitone-layout~="-texture\:offset-dots"]::before {
20
54
  background-image:
21
55
  radial-gradient(
22
56
  var(--unitone--texture-color) var(--unitone--texture-size),
@@ -36,7 +70,7 @@
36
70
  max(var(--unitone--texture-gap), var(--unitone--texture-size) * 3);
37
71
  }
38
72
 
39
- &[data-unitone-layout~="-texture\:grid"] {
73
+ &[data-unitone-layout~="-texture\:grid"]::before {
40
74
  background-image:
41
75
  linear-gradient(
42
76
  var(--unitone--texture-color) var(--unitone--texture-size),
@@ -52,7 +86,7 @@
52
86
  max(var(--unitone--texture-gap), var(--unitone--texture-size) * 2);
53
87
  }
54
88
 
55
- &[data-unitone-layout~="-texture\:horizontal-stripe"] {
89
+ &[data-unitone-layout~="-texture\:horizontal-stripe"]::before {
56
90
  background-image:
57
91
  linear-gradient(
58
92
  var(--unitone--texture-color) var(--unitone--texture-size),
@@ -63,7 +97,7 @@
63
97
  max(var(--unitone--texture-gap), var(--unitone--texture-size) * 2);
64
98
  }
65
99
 
66
- &[data-unitone-layout~="-texture\:vertical-stripe"] {
100
+ &[data-unitone-layout~="-texture\:vertical-stripe"]::before {
67
101
  background-image:
68
102
  linear-gradient(
69
103
  to right,
@@ -75,7 +109,7 @@
75
109
  max(var(--unitone--texture-gap), var(--unitone--texture-size) * 2);
76
110
  }
77
111
 
78
- &[data-unitone-layout~="-texture\:checker-pattern"] {
112
+ &[data-unitone-layout~="-texture\:checker-pattern"]::before {
79
113
  background-image:
80
114
  repeating-linear-gradient(
81
115
  45deg,
@@ -103,7 +137,7 @@
103
137
  calc(var(--unitone--texture-gap) * 2);
104
138
  }
105
139
 
106
- &[data-unitone-layout~="-texture\:graph-paper"] {
140
+ &[data-unitone-layout~="-texture\:graph-paper"]::before {
107
141
  background-image:
108
142
  linear-gradient(
109
143
  var(--unitone--texture-color) calc(var(--unitone--texture-size) * .8),
@@ -139,7 +173,7 @@
139
173
  calc(max(var(--unitone--texture-gap) * 3, var(--unitone--texture-size) * 30) / 5);
140
174
  }
141
175
 
142
- &[data-unitone-layout~="-texture\:slash"] {
176
+ &[data-unitone-layout~="-texture\:slash"]::before {
143
177
  background-image:
144
178
  repeating-linear-gradient(
145
179
  135deg,
@@ -153,7 +187,7 @@
153
187
  max(var(--unitone--texture-gap), var(--unitone--texture-size) * 1.5 + 2px);
154
188
  }
155
189
 
156
- &[data-unitone-layout~="-texture\:backslash"] {
190
+ &[data-unitone-layout~="-texture\:backslash"]::before {
157
191
  background-image:
158
192
  repeating-linear-gradient(
159
193
  45deg,
@@ -166,6 +200,32 @@
166
200
  max(var(--unitone--texture-gap), var(--unitone--texture-size) * 1.5 + 2px)
167
201
  max(var(--unitone--texture-gap), var(--unitone--texture-size) * 1.5 + 2px);
168
202
  }
203
+
204
+ &[data-unitone-layout~="-texture\:wave"]::before {
205
+ background-color: var(--unitone--texture-color);
206
+ border-radius: 0;
207
+ mask-image:
208
+ url('data:image/svg+xml,<svg viewBox="0 0 200 20" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none"><path d="M200 0C173.236 0 146.472 2.68557 119.611 8.05762C79.8049 16.0189 39.9025 19.999 0 19.999V0H200Z"/></svg>'),
209
+ url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="none"><rect x="0" y="0" height="100" width="100"/></svg>'),
210
+ url('data:image/svg+xml,<svg viewBox="0 0 200 20" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none"><path d="M200 19.999H0C26.7642 19.999 53.5284 17.3134 80.3887 11.9414C120.195 3.98014 160.098 2.69917e-07 200 0V19.999Z"/></svg>');
211
+ mask-composite: exclude, subtract;
212
+ mask-position:
213
+ 0 0,
214
+ 0 0,
215
+ 0 100%;
216
+ mask-size:
217
+ 100% max(40px + var(--unitone--texture-size)),
218
+ 100% 100%,
219
+ 100% max(40px + var(--unitone--texture-size));
220
+ mask-repeat:
221
+ repeat-x,
222
+ repeat,
223
+ repeat-x;
224
+ }
225
+
226
+ &[data-unitone-layout~="-texture\:solid-color"]::before {
227
+ background-color: var(--unitone--texture-color);
228
+ }
169
229
  }
170
230
 
171
231
  @mixin texture() {
@@ -1,10 +1,41 @@
1
1
  import React from 'react';
2
2
 
3
- export const Texture = ({ texture, textureColor, textureSize, style, ...props }) => {
3
+ export const Texture = ({
4
+ texture,
5
+ textureColor,
6
+ textureGap,
7
+ textureSize,
8
+ textureTop,
9
+ textureRight,
10
+ textureBottom,
11
+ textureLeft,
12
+ textureBorderRadius,
13
+ textureBorderTopLeftRadius,
14
+ textureBorderTopRightRadius,
15
+ textureBorderBottomLeftRadius,
16
+ textureBorderBottomRightRadius,
17
+ style,
18
+ ...props
19
+ }) => {
4
20
  style = {
5
21
  ...style,
6
22
  '--unitone--texture-color': '' !== textureColor ? textureColor : undefined,
23
+ '--unitone--texture-gap': '' !== textureGap ? textureGap : undefined,
7
24
  '--unitone--texture-size': '' !== textureSize ? textureSize : undefined,
25
+ '--unitone--texture-top': '' !== textureTop ? textureTop : undefined,
26
+ '--unitone--texture-right': '' !== textureRight ? textureRight : undefined,
27
+ '--unitone--texture-bottom': '' !== textureBottom ? textureBottom : undefined,
28
+ '--unitone--texture-left': '' !== textureLeft ? textureLeft : undefined,
29
+ '--unitone--texture-border-radius':
30
+ '' !== textureBorderRadius ? textureBorderRadius : undefined,
31
+ '--unitone--texture-border-top-left-radius':
32
+ '' !== textureBorderTopLeftRadius ? textureBorderTopLeftRadius : undefined,
33
+ '--unitone--texture-border-top-right-radius':
34
+ '' !== textureBorderTopRightRadius ? textureBorderTopRightRadius : undefined,
35
+ '--unitone--texture-border-bottom-left-radius':
36
+ '' !== textureBorderBottomLeftRadius ? textureBorderBottomLeftRadius : undefined,
37
+ '--unitone--texture-border-bottom-right-radius':
38
+ '' !== textureBorderBottomRightRadius ? textureBorderBottomRightRadius : undefined,
8
39
  };
9
40
 
10
41
  return (
package/src/library.js CHANGED
@@ -454,3 +454,89 @@ export const result1emPxForFireFoxObserver = (target) => {
454
454
  mutationObserver: mObserver,
455
455
  };
456
456
  };
457
+
458
+ export const setMarquee = (target) => {
459
+ const addInitializedToken = (element) => {
460
+ const layout = element.getAttribute('data-unitone-layout') ?? '';
461
+ if (layout.split(/\s+/).includes('marquee:initialized')) {
462
+ return;
463
+ }
464
+ element.setAttribute('data-unitone-layout', `${layout} marquee:initialized`.trim());
465
+ };
466
+
467
+ const removeInitializedToken = (element) => {
468
+ const layout = element.getAttribute('data-unitone-layout') ?? '';
469
+ const next = layout
470
+ .split(/\s+/)
471
+ .filter((value) => value && 'marquee:initialized' !== value)
472
+ .join(' ');
473
+ element.setAttribute('data-unitone-layout', next);
474
+ };
475
+
476
+ const getMarquees = () => target.querySelectorAll(':scope > [data-unitone-layout~="marquee"]');
477
+ let marquees = getMarquees();
478
+ if (0 === marquees.length) {
479
+ return;
480
+ }
481
+
482
+ if (1 === target.childElementCount && 1 === marquees.length) {
483
+ const marquee = marquees[0];
484
+ const clonedMarquee = marquee.cloneNode(true);
485
+ clonedMarquee.setAttribute('aria-hidden', 'true');
486
+ marquee.after(clonedMarquee);
487
+ }
488
+
489
+ marquees = getMarquees();
490
+ marquees.forEach((marquee) => {
491
+ removeInitializedToken(marquee);
492
+ });
493
+
494
+ requestAnimationFrame(() => {
495
+ if (!target?.isConnected) {
496
+ return;
497
+ }
498
+ getMarquees().forEach((marquee) => {
499
+ addInitializedToken(marquee);
500
+ });
501
+ });
502
+ };
503
+
504
+ export const marqueeResizeObserver = (target) => {
505
+ let prevWidth = 0;
506
+
507
+ setMarquee(target);
508
+
509
+ const observer = new ResizeObserver(
510
+ debounce((entries) => {
511
+ for (const entry of entries) {
512
+ const width = entry.contentRect?.width;
513
+ if (parseInt(width) !== parseInt(prevWidth)) {
514
+ prevWidth = width;
515
+ setMarquee(entry.target);
516
+ }
517
+ }
518
+ }, 250),
519
+ );
520
+
521
+ observer.observe(target);
522
+
523
+ const mObserverArgs = {
524
+ childList: true,
525
+ };
526
+
527
+ const mObserver = new MutationObserver(() => {
528
+ requestAnimationFrame(() => {
529
+ if (!target?.isConnected) {
530
+ return;
531
+ }
532
+ setMarquee(target);
533
+ });
534
+ });
535
+
536
+ mObserver.observe(target, mObserverArgs);
537
+
538
+ return {
539
+ resizeObserver: observer,
540
+ mutationObserver: mObserver,
541
+ };
542
+ };