@rettangoli/ui 1.0.10 → 1.0.13

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rettangoli/ui",
3
- "version": "1.0.10",
3
+ "version": "1.0.13",
4
4
  "description": "A UI component library for building web interfaces.",
5
5
  "main": "dist/rettangoli-esm.min.js",
6
6
  "type": "module",
@@ -37,7 +37,7 @@
37
37
  "build": "rtgl fe build -o ./.generated/fe-entry.js && bun run esbuild.js && bun run esbuild-dev.js && npm run copy:css",
38
38
  "prepack": "npm run build",
39
39
  "vt:generate": "bun run build:dev && rtgl vt generate",
40
- "vt:docker": "bun run build:dev && bash -lc 'IMAGE=\"han4wluc/rtgl:playwright-v1.57.0-rtgl-v1.0.5\"; docker pull \"$IMAGE\" >/dev/null 2>&1 || IMAGE=\"han4wluc/rtgl:playwright-v1.57.0-rtgl-v1.0.0-rc27\"; docker run --rm --user $(id -u):$(id -g) -v \"$PWD:/app\" -w /app \"$IMAGE\" rtgl vt screenshot'",
40
+ "vt:docker": "bun run build:dev && bash -lc 'IMAGE=\"han4wluc/rtgl:playwright-v1.57.0-rtgl-v1.0.10\"; docker pull \"$IMAGE\" >/dev/null 2>&1; docker run --rm --user $(id -u):$(id -g) -v \"$PWD:/app\" -w /app \"$IMAGE\" rtgl vt screenshot'",
41
41
  "vt:report": "bun run vt:docker && rtgl vt report",
42
42
  "vt:accept": "rtgl vt accept",
43
43
  "serve": "bunx serve .rettangoli/vt/_site"
@@ -0,0 +1,155 @@
1
+ import { dimensionWithUnit } from "../common.js";
2
+ import { parseFlexBasisDimension } from "./dimensions.js";
3
+
4
+ const toCarouselFlexBasisCss = ({ numerator, denominator, gapVar }) => {
5
+ if (numerator === denominator) {
6
+ return "100%";
7
+ }
8
+
9
+ if (numerator === 1) {
10
+ return `calc((100% - ((${denominator} - 1) * ${gapVar})) / ${denominator})`;
11
+ }
12
+
13
+ return `calc(((100% - ((${denominator} - 1) * ${gapVar})) * ${numerator}) / ${denominator})`;
14
+ };
15
+
16
+ export const clampCarouselIndex = ({ index, maxIndex }) => {
17
+ if (!Number.isFinite(index)) {
18
+ return 0;
19
+ }
20
+
21
+ if (!Number.isFinite(maxIndex) || maxIndex < 0) {
22
+ return 0;
23
+ }
24
+
25
+ return Math.min(Math.max(Math.trunc(index), 0), maxIndex);
26
+ };
27
+
28
+ export const resolveCarouselBooleanAttribute = ({
29
+ value,
30
+ defaultValue = false,
31
+ }) => {
32
+ if (value === undefined || value === null) {
33
+ return defaultValue;
34
+ }
35
+
36
+ const normalizedValue = `${value}`.trim().toLowerCase();
37
+ if (normalizedValue.length === 0) {
38
+ return true;
39
+ }
40
+
41
+ if (
42
+ normalizedValue === "false" ||
43
+ normalizedValue === "0" ||
44
+ normalizedValue === "no" ||
45
+ normalizedValue === "off" ||
46
+ normalizedValue === "none"
47
+ ) {
48
+ return false;
49
+ }
50
+
51
+ return true;
52
+ };
53
+
54
+ export const resolveCarouselSnapType = (snap) => {
55
+ if (snap === undefined || snap === null) {
56
+ return "x mandatory";
57
+ }
58
+
59
+ const normalizedSnap = `${snap}`.trim().toLowerCase();
60
+ if (
61
+ normalizedSnap === "" ||
62
+ normalizedSnap === "true" ||
63
+ normalizedSnap === "1" ||
64
+ normalizedSnap === "yes"
65
+ ) {
66
+ return "x mandatory";
67
+ }
68
+
69
+ if (
70
+ normalizedSnap === "false" ||
71
+ normalizedSnap === "0" ||
72
+ normalizedSnap === "no" ||
73
+ normalizedSnap === "off" ||
74
+ normalizedSnap === "none"
75
+ ) {
76
+ return "none";
77
+ }
78
+
79
+ return "x mandatory";
80
+ };
81
+
82
+ export const resolveCarouselScrollLeft = ({
83
+ slideLeft,
84
+ slideWidth,
85
+ viewportWidth,
86
+ scrollPaddingInlineStart = 0,
87
+ scrollPaddingInlineEnd = 0,
88
+ snapAlign = "center",
89
+ maxScrollLeft = Number.POSITIVE_INFINITY,
90
+ }) => {
91
+ if (
92
+ !Number.isFinite(slideLeft) ||
93
+ !Number.isFinite(slideWidth) ||
94
+ !Number.isFinite(viewportWidth)
95
+ ) {
96
+ return 0;
97
+ }
98
+
99
+ const snapportStart = scrollPaddingInlineStart;
100
+ const snapportEnd = viewportWidth - scrollPaddingInlineEnd;
101
+ const snapportWidth = Math.max(snapportEnd - snapportStart, 0);
102
+
103
+ let targetScrollLeft;
104
+ if (snapAlign === "start") {
105
+ targetScrollLeft = slideLeft - snapportStart;
106
+ } else if (snapAlign === "end") {
107
+ targetScrollLeft = (slideLeft + slideWidth) - snapportEnd;
108
+ } else {
109
+ targetScrollLeft =
110
+ (slideLeft + (slideWidth / 2)) -
111
+ (snapportStart + (snapportWidth / 2));
112
+ }
113
+
114
+ const normalizedMaxScrollLeft = Number.isFinite(maxScrollLeft)
115
+ ? Math.max(maxScrollLeft, 0)
116
+ : Number.POSITIVE_INFINITY;
117
+
118
+ return Math.min(Math.max(targetScrollLeft, 0), normalizedMaxScrollLeft);
119
+ };
120
+
121
+ export const resolveCarouselViewportPaddingCss = ({
122
+ slideWidthCss,
123
+ snapAlign = "center",
124
+ }) => {
125
+ const normalizedSnapAlign = `${snapAlign ?? ""}`.trim().toLowerCase();
126
+ if (normalizedSnapAlign !== "center") {
127
+ return "0px";
128
+ }
129
+
130
+ const normalizedSlideWidthCss =
131
+ slideWidthCss && `${slideWidthCss}`.trim().length > 0
132
+ ? `${slideWidthCss}`.trim()
133
+ : "100%";
134
+
135
+ return `max(calc((100% - (${normalizedSlideWidthCss})) / 2), 0px)`;
136
+ };
137
+
138
+ export const resolveCarouselSlideWidthCss = ({
139
+ slideWidth,
140
+ gapVar = "var(--rtgl-carousel-gap, 0px)",
141
+ }) => {
142
+ if (slideWidth == null || `${slideWidth}`.trim() === "" || slideWidth === "f") {
143
+ return "100%";
144
+ }
145
+
146
+ const flexBasis = parseFlexBasisDimension(`${slideWidth}`.trim());
147
+ if (flexBasis) {
148
+ return toCarouselFlexBasisCss({
149
+ ...flexBasis,
150
+ gapVar,
151
+ });
152
+ }
153
+
154
+ return dimensionWithUnit(`${slideWidth}`.trim()) ?? "100%";
155
+ };
@@ -1,4 +1,5 @@
1
1
  import RettangoliButton from './primitives/button.js'
2
+ import RettangoliCarousel from './primitives/carousel.js';
2
3
  import RettangoliGrid from './primitives/grid.js';
3
4
  import RettangoliView from './primitives/view.js';
4
5
  import RettangoliText from './primitives/text.js';
@@ -18,6 +19,7 @@ import RettangoliPopover from './primitives/popover.js';
18
19
 
19
20
 
20
21
  customElements.define("rtgl-button", RettangoliButton({}));
22
+ customElements.define("rtgl-carousel", RettangoliCarousel({}));
21
23
  customElements.define("rtgl-grid", RettangoliGrid({}));
22
24
  customElements.define("rtgl-view", RettangoliView({}));
23
25
  customElements.define("rtgl-text", RettangoliText({}));
@@ -1,4 +1,5 @@
1
1
  import RettangoliButton from './primitives/button.js'
2
+ import RettangoliCarousel from './primitives/carousel.js';
2
3
  import RettangoliGrid from './primitives/grid.js';
3
4
  import RettangoliView from './primitives/view.js';
4
5
  import RettangoliText from './primitives/text.js';
@@ -18,6 +19,7 @@ import RettangoliDialog from './primitives/dialog.js';
18
19
  import RettangoliPopover from './primitives/popover.js';
19
20
 
20
21
  customElements.define("rtgl-button", RettangoliButton({}));
22
+ customElements.define("rtgl-carousel", RettangoliCarousel({}));
21
23
  customElements.define("rtgl-grid", RettangoliGrid({}));
22
24
  customElements.define("rtgl-view", RettangoliView({}));
23
25
  customElements.define("rtgl-text", RettangoliText({}));
package/src/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import RettangoliButton from './primitives/button.js'
2
+ import RettangoliCarousel from './primitives/carousel.js';
2
3
  import RettangoliGrid from './primitives/grid.js';
3
4
  import RettangoliView from './primitives/view.js';
4
5
  import RettangoliText from './primitives/text.js';
@@ -20,6 +21,7 @@ import createGlobalUI from './deps/createGlobalUI.js';
20
21
 
21
22
  export {
22
23
  RettangoliButton,
24
+ RettangoliCarousel,
23
25
  RettangoliGrid,
24
26
  RettangoliView,
25
27
  RettangoliText,