@rettangoli/ui 0.1.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.
- package/README.md +49 -0
- package/dist/rettangoli-iife-layout.min.js +728 -0
- package/dist/rettangoli-iife-ui.min.js +830 -0
- package/package.json +53 -0
- package/src/common/BaseElement.js +182 -0
- package/src/common.js +190 -0
- package/src/components/dialog/dialog.handlers.js +5 -0
- package/src/components/dialog/dialog.store.js +25 -0
- package/src/components/dialog/dialog.view.yaml +44 -0
- package/src/components/dropdownMenu/dropdownMenu.handlers.js +18 -0
- package/src/components/dropdownMenu/dropdownMenu.store.js +25 -0
- package/src/components/dropdownMenu/dropdownMenu.view.yaml +54 -0
- package/src/components/form/form.handlers.js +63 -0
- package/src/components/form/form.store.js +45 -0
- package/src/components/form/form.view.yaml +174 -0
- package/src/components/navbar/navbar.examples.yaml +86 -0
- package/src/components/navbar/navbar.handlers.js +10 -0
- package/src/components/navbar/navbar.store.js +46 -0
- package/src/components/navbar/navbar.view.yaml +74 -0
- package/src/components/pageOutline/pageOutline.handlers.js +69 -0
- package/src/components/pageOutline/pageOutline.store.js +40 -0
- package/src/components/pageOutline/pageOutline.view.yaml +34 -0
- package/src/components/popover/popover.handlers.js +5 -0
- package/src/components/popover/popover.store.js +12 -0
- package/src/components/popover/popover.view.yaml +57 -0
- package/src/components/select/select.handlers.js +61 -0
- package/src/components/select/select.store.js +65 -0
- package/src/components/select/select.view.yaml +50 -0
- package/src/components/sidebar/sidebar.handlers.js +36 -0
- package/src/components/sidebar/sidebar.store.js +142 -0
- package/src/components/sidebar/sidebar.view.yaml +190 -0
- package/src/components/table/table.handlers.js +55 -0
- package/src/components/table/table.store.js +72 -0
- package/src/components/table/table.view.yaml +103 -0
- package/src/entry-iife-layout.js +15 -0
- package/src/entry-iife-ui.js +22 -0
- package/src/index.js +17 -0
- package/src/lib/uhtml.js +9 -0
- package/src/primitives/button.js +306 -0
- package/src/primitives/colorPicker.js +213 -0
- package/src/primitives/image.js +234 -0
- package/src/primitives/input.js +218 -0
- package/src/primitives/slider.js +269 -0
- package/src/primitives/svg.js +95 -0
- package/src/primitives/text.js +141 -0
- package/src/primitives/textarea.js +103 -0
- package/src/primitives/view.js +217 -0
- package/src/setup.js +16 -0
- package/src/styles/anchorStyles.js +13 -0
- package/src/styles/buttonMarginStyles.js +84 -0
- package/src/styles/cursorStyles.js +12 -0
- package/src/styles/flexChildStyles.js +43 -0
- package/src/styles/flexDirectionStyles.js +74 -0
- package/src/styles/marginStyles.js +13 -0
- package/src/styles/paddingSvgStyles.js +120 -0
- package/src/styles/scrollStyles.js +22 -0
- package/src/styles/textColorStyles.js +14 -0
- package/src/styles/textStyles.js +62 -0
- package/src/styles/viewStyles.js +114 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import {
|
|
2
|
+
css,
|
|
3
|
+
dimensionWithUnit,
|
|
4
|
+
convertObjectToCssString,
|
|
5
|
+
styleMapKeys,
|
|
6
|
+
permutateBreakpoints
|
|
7
|
+
} from "../common.js";
|
|
8
|
+
import cursorStyles from "../styles/cursorStyles.js";
|
|
9
|
+
import marginStyles from "../styles/marginStyles.js";
|
|
10
|
+
import viewStyles from "../styles/viewStyles.js";
|
|
11
|
+
import anchorStyles from "../styles/anchorStyles.js";
|
|
12
|
+
|
|
13
|
+
// Internal implementation without uhtml
|
|
14
|
+
class RettangoliImageElement extends HTMLElement {
|
|
15
|
+
static styleSheet = null;
|
|
16
|
+
|
|
17
|
+
static initializeStyleSheet() {
|
|
18
|
+
if (!RettangoliImageElement.styleSheet) {
|
|
19
|
+
RettangoliImageElement.styleSheet = new CSSStyleSheet();
|
|
20
|
+
RettangoliImageElement.styleSheet.replaceSync(css`
|
|
21
|
+
:host {
|
|
22
|
+
border-style: solid;
|
|
23
|
+
box-sizing: border-box;
|
|
24
|
+
overflow: hidden;
|
|
25
|
+
border-width: 0;
|
|
26
|
+
}
|
|
27
|
+
slot {
|
|
28
|
+
display: contents;
|
|
29
|
+
}
|
|
30
|
+
:host([of="con"]) img {
|
|
31
|
+
object-fit: contain;
|
|
32
|
+
}
|
|
33
|
+
:host([of="cov"]) img {
|
|
34
|
+
object-fit: cover;
|
|
35
|
+
}
|
|
36
|
+
:host([of="none"]) img {
|
|
37
|
+
object-fit: none;
|
|
38
|
+
}
|
|
39
|
+
img {
|
|
40
|
+
height: 100%;
|
|
41
|
+
width: 100%;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
${anchorStyles}
|
|
45
|
+
|
|
46
|
+
a {
|
|
47
|
+
display: block;
|
|
48
|
+
height: 100%;
|
|
49
|
+
width: 100%;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
:host([href]) {
|
|
53
|
+
cursor: pointer;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
${viewStyles}
|
|
57
|
+
${marginStyles}
|
|
58
|
+
${cursorStyles}
|
|
59
|
+
`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
constructor() {
|
|
64
|
+
super();
|
|
65
|
+
RettangoliImageElement.initializeStyleSheet();
|
|
66
|
+
this.shadow = this.attachShadow({ mode: "closed" });
|
|
67
|
+
this.shadow.adoptedStyleSheets = [RettangoliImageElement.styleSheet];
|
|
68
|
+
|
|
69
|
+
// Create initial DOM structure
|
|
70
|
+
this._styleElement = document.createElement('style');
|
|
71
|
+
this._imgElement = document.createElement('img');
|
|
72
|
+
this._linkElement = null;
|
|
73
|
+
|
|
74
|
+
this.shadow.appendChild(this._styleElement);
|
|
75
|
+
this._updateDOM();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static get observedAttributes() {
|
|
79
|
+
return permutateBreakpoints([...styleMapKeys, "key", "src", "href", "target", "wh", "w", "h", "hidden", "height", "width"]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
_styles = {
|
|
83
|
+
default: {},
|
|
84
|
+
sm: {},
|
|
85
|
+
md: {},
|
|
86
|
+
lg: {},
|
|
87
|
+
xl: {},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
_lastStyleString = "";
|
|
91
|
+
|
|
92
|
+
_updateDOM() {
|
|
93
|
+
const href = this.getAttribute("href");
|
|
94
|
+
const target = this.getAttribute("target");
|
|
95
|
+
|
|
96
|
+
if (href) {
|
|
97
|
+
if (!this._linkElement) {
|
|
98
|
+
// Create link wrapper
|
|
99
|
+
this._linkElement = document.createElement("a");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Update link attributes
|
|
103
|
+
this._linkElement.href = href;
|
|
104
|
+
if (target) {
|
|
105
|
+
this._linkElement.target = target;
|
|
106
|
+
} else {
|
|
107
|
+
this._linkElement.removeAttribute("target");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Wrap image in link
|
|
111
|
+
this._linkElement.appendChild(this._imgElement);
|
|
112
|
+
|
|
113
|
+
// Ensure link is in shadow DOM
|
|
114
|
+
if (this._linkElement.parentNode !== this.shadow) {
|
|
115
|
+
this.shadow.appendChild(this._linkElement);
|
|
116
|
+
}
|
|
117
|
+
} else if (this._linkElement) {
|
|
118
|
+
// Remove link wrapper
|
|
119
|
+
if (this._imgElement.parentNode === this._linkElement) {
|
|
120
|
+
this.shadow.appendChild(this._imgElement);
|
|
121
|
+
}
|
|
122
|
+
if (this._linkElement.parentNode === this.shadow) {
|
|
123
|
+
this.shadow.removeChild(this._linkElement);
|
|
124
|
+
}
|
|
125
|
+
this._linkElement = null;
|
|
126
|
+
} else {
|
|
127
|
+
// Ensure image is in shadow DOM
|
|
128
|
+
if (this._imgElement.parentNode !== this.shadow) {
|
|
129
|
+
this.shadow.appendChild(this._imgElement);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
135
|
+
// Handle href and target changes
|
|
136
|
+
if (name === "href" || name === "target") {
|
|
137
|
+
this._updateDOM();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// Reset styles for fresh calculation
|
|
141
|
+
this._styles = {
|
|
142
|
+
default: {},
|
|
143
|
+
sm: {},
|
|
144
|
+
md: {},
|
|
145
|
+
lg: {},
|
|
146
|
+
xl: {},
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
["default", "sm", "md", "lg", "xl"].forEach((size) => {
|
|
150
|
+
const addSizePrefix = (tag) => {
|
|
151
|
+
return `${size === "default" ? "" : `${size}-`}${tag}`;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const wh = this.getAttribute(addSizePrefix("wh"));
|
|
155
|
+
const width = dimensionWithUnit(
|
|
156
|
+
wh === null ? this.getAttribute(addSizePrefix("w")) : wh
|
|
157
|
+
);
|
|
158
|
+
const height = dimensionWithUnit(
|
|
159
|
+
wh === null ? this.getAttribute(addSizePrefix("h")) : wh
|
|
160
|
+
);
|
|
161
|
+
const opacity = this.getAttribute(addSizePrefix("o"));
|
|
162
|
+
const zIndex = this.getAttribute(addSizePrefix("z"));
|
|
163
|
+
|
|
164
|
+
if (zIndex !== null) {
|
|
165
|
+
this._styles[size]["z-index"] = zIndex;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (opacity !== null) {
|
|
169
|
+
this._styles[size].opacity = opacity;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (width === "f") {
|
|
173
|
+
this._styles[size].width = "var(--width-stretch)";
|
|
174
|
+
} else if (width !== undefined) {
|
|
175
|
+
this._styles[size].width = width;
|
|
176
|
+
this._styles[size]["min-width"] = width;
|
|
177
|
+
this._styles[size]["max-width"] = width;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (height === "f") {
|
|
181
|
+
this._styles[size].height = "100%";
|
|
182
|
+
} else if (height !== undefined) {
|
|
183
|
+
this._styles[size].height = height;
|
|
184
|
+
this._styles[size]["min-height"] = height;
|
|
185
|
+
this._styles[size]["max-height"] = height;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (this.hasAttribute(addSizePrefix("hidden"))) {
|
|
189
|
+
this._styles[size].display = "none !important";
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (this.hasAttribute(addSizePrefix("visible"))) {
|
|
193
|
+
this._styles[size].display = "block !important";
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Update styles only if changed
|
|
198
|
+
const newStyleString = convertObjectToCssString(this._styles);
|
|
199
|
+
if (newStyleString !== this._lastStyleString) {
|
|
200
|
+
this._styleElement.textContent = newStyleString;
|
|
201
|
+
this._lastStyleString = newStyleString;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Update img attributes
|
|
205
|
+
this._updateImageAttributes();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
_updateImageAttributes() {
|
|
209
|
+
const src = this.getAttribute("src");
|
|
210
|
+
const width = this.getAttribute("width");
|
|
211
|
+
const height = this.getAttribute("height");
|
|
212
|
+
|
|
213
|
+
if (src !== null) {
|
|
214
|
+
this._imgElement.setAttribute("src", src);
|
|
215
|
+
}
|
|
216
|
+
if (width !== null) {
|
|
217
|
+
this._imgElement.setAttribute("width", width);
|
|
218
|
+
}
|
|
219
|
+
if (height !== null) {
|
|
220
|
+
this._imgElement.setAttribute("height", height);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
connectedCallback() {
|
|
225
|
+
this._updateImageAttributes();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Export factory function to maintain API compatibility
|
|
230
|
+
export default ({ render, html }) => {
|
|
231
|
+
// Note: render and html parameters are accepted but not used
|
|
232
|
+
// This maintains backward compatibility with existing code
|
|
233
|
+
return RettangoliImageElement;
|
|
234
|
+
};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import {
|
|
2
|
+
css,
|
|
3
|
+
dimensionWithUnit,
|
|
4
|
+
convertObjectToCssString,
|
|
5
|
+
styleMapKeys,
|
|
6
|
+
permutateBreakpoints,
|
|
7
|
+
} from "../common.js";
|
|
8
|
+
import cursorStyles from "../styles/cursorStyles.js";
|
|
9
|
+
import marginStyles from "../styles/marginStyles.js";
|
|
10
|
+
|
|
11
|
+
// Internal implementation without uhtml
|
|
12
|
+
class RettangoliInputElement extends HTMLElement {
|
|
13
|
+
static styleSheet = null;
|
|
14
|
+
|
|
15
|
+
static initializeStyleSheet() {
|
|
16
|
+
if (!RettangoliInputElement.styleSheet) {
|
|
17
|
+
RettangoliInputElement.styleSheet = new CSSStyleSheet();
|
|
18
|
+
RettangoliInputElement.styleSheet.replaceSync(css`
|
|
19
|
+
:host {
|
|
20
|
+
display: contents;
|
|
21
|
+
}
|
|
22
|
+
input {
|
|
23
|
+
background-color: var(--background);
|
|
24
|
+
font-size: var(--sm-font-size);
|
|
25
|
+
font-weight: var(--sm-font-weight);
|
|
26
|
+
line-height: var(--sm-line-height);
|
|
27
|
+
letter-spacing: var(--sm-letter-spacing);
|
|
28
|
+
border: 1px solid var(--ring);
|
|
29
|
+
border-radius: var(--border-radius-lg);
|
|
30
|
+
padding-left: var(--spacing-md);
|
|
31
|
+
padding-right: var(--spacing-md);
|
|
32
|
+
height: 32px;
|
|
33
|
+
color: var(--foreground);
|
|
34
|
+
outline: none;
|
|
35
|
+
}
|
|
36
|
+
:host([s="sm"]) input {
|
|
37
|
+
font-size: var(--xs-font-size);
|
|
38
|
+
font-weight: var(--xs-font-weight);
|
|
39
|
+
line-height: var(--xs-line-height);
|
|
40
|
+
letter-spacing: var(--xs-letter-spacing);
|
|
41
|
+
padding-left: var(--spacing-sm);
|
|
42
|
+
padding-right: var(--spacing-sm);
|
|
43
|
+
height: 24px;
|
|
44
|
+
}
|
|
45
|
+
input:focus {
|
|
46
|
+
border-color: var(--foreground);
|
|
47
|
+
}
|
|
48
|
+
input:disabled {
|
|
49
|
+
cursor: not-allowed;
|
|
50
|
+
}
|
|
51
|
+
${marginStyles}
|
|
52
|
+
${cursorStyles}
|
|
53
|
+
`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
constructor() {
|
|
58
|
+
super();
|
|
59
|
+
RettangoliInputElement.initializeStyleSheet();
|
|
60
|
+
this.shadow = this.attachShadow({ mode: "closed" });
|
|
61
|
+
this.shadow.adoptedStyleSheets = [RettangoliInputElement.styleSheet];
|
|
62
|
+
|
|
63
|
+
// Initialize style tracking properties
|
|
64
|
+
this._styles = {
|
|
65
|
+
default: {},
|
|
66
|
+
sm: {},
|
|
67
|
+
md: {},
|
|
68
|
+
lg: {},
|
|
69
|
+
xl: {},
|
|
70
|
+
};
|
|
71
|
+
this._lastStyleString = "";
|
|
72
|
+
|
|
73
|
+
// Create initial DOM structure
|
|
74
|
+
this._inputElement = document.createElement('input');
|
|
75
|
+
this._styleElement = document.createElement('style');
|
|
76
|
+
|
|
77
|
+
this.shadow.appendChild(this._styleElement);
|
|
78
|
+
this.shadow.appendChild(this._inputElement);
|
|
79
|
+
|
|
80
|
+
// Bind event handler
|
|
81
|
+
this._inputElement.addEventListener('keydown', this._onChange);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static get observedAttributes() {
|
|
85
|
+
return [
|
|
86
|
+
"key",
|
|
87
|
+
"type",
|
|
88
|
+
"placeholder",
|
|
89
|
+
"disabled",
|
|
90
|
+
"s",
|
|
91
|
+
...permutateBreakpoints([
|
|
92
|
+
...styleMapKeys,
|
|
93
|
+
"wh",
|
|
94
|
+
"w",
|
|
95
|
+
"h",
|
|
96
|
+
"hidden",
|
|
97
|
+
"visible",
|
|
98
|
+
"op",
|
|
99
|
+
"z",
|
|
100
|
+
])
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
get value() {
|
|
105
|
+
return this._inputElement.value;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_onChange = (event) => {
|
|
109
|
+
this.dispatchEvent(new CustomEvent('input-keydown', {
|
|
110
|
+
detail: {
|
|
111
|
+
value: this._inputElement.value,
|
|
112
|
+
},
|
|
113
|
+
}));
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
117
|
+
// Handle input-specific attributes first
|
|
118
|
+
if (["type", "placeholder", "disabled", "s"].includes(name)) {
|
|
119
|
+
this._updateInputAttributes();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Reset styles for fresh calculation
|
|
124
|
+
this._styles = {
|
|
125
|
+
default: {},
|
|
126
|
+
sm: {},
|
|
127
|
+
md: {},
|
|
128
|
+
lg: {},
|
|
129
|
+
xl: {},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
["default", "sm", "md", "lg", "xl"].forEach((size) => {
|
|
133
|
+
const addSizePrefix = (tag) => {
|
|
134
|
+
return `${size === "default" ? "" : `${size}-`}${tag}`;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const wh = this.getAttribute(addSizePrefix("wh"));
|
|
138
|
+
const width = dimensionWithUnit(
|
|
139
|
+
wh === null ? this.getAttribute(addSizePrefix("w")) : wh,
|
|
140
|
+
);
|
|
141
|
+
const height = dimensionWithUnit(
|
|
142
|
+
wh === null ? this.getAttribute(addSizePrefix("h")) : wh,
|
|
143
|
+
);
|
|
144
|
+
const opacity = this.getAttribute(addSizePrefix("op"));
|
|
145
|
+
const zIndex = this.getAttribute(addSizePrefix("z"));
|
|
146
|
+
|
|
147
|
+
if (zIndex !== null) {
|
|
148
|
+
this._styles[size]["z-index"] = zIndex;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (opacity !== null) {
|
|
152
|
+
this._styles[size].opacity = opacity;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (width === "f") {
|
|
156
|
+
this._styles[size].width = "var(--width-stretch)";
|
|
157
|
+
} else if (width !== undefined) {
|
|
158
|
+
this._styles[size].width = width;
|
|
159
|
+
this._styles[size]["min-width"] = width;
|
|
160
|
+
this._styles[size]["max-width"] = width;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (height === "f") {
|
|
164
|
+
this._styles[size].height = "100%";
|
|
165
|
+
} else if (height !== undefined) {
|
|
166
|
+
this._styles[size].height = height;
|
|
167
|
+
this._styles[size]["min-height"] = height;
|
|
168
|
+
this._styles[size]["max-height"] = height;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (this.hasAttribute(addSizePrefix("hidden"))) {
|
|
172
|
+
this._styles[size].display = "none !important";
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (this.hasAttribute(addSizePrefix("visible"))) {
|
|
176
|
+
this._styles[size].display = "block !important";
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Update styles only if changed - targeting input element
|
|
181
|
+
const newStyleString = convertObjectToCssString(this._styles, 'input');
|
|
182
|
+
if (newStyleString !== this._lastStyleString) {
|
|
183
|
+
this._styleElement.textContent = newStyleString;
|
|
184
|
+
this._lastStyleString = newStyleString;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
_updateInputAttributes() {
|
|
189
|
+
const type = this.getAttribute("type") || "text";
|
|
190
|
+
const placeholder = this.getAttribute("placeholder");
|
|
191
|
+
const isDisabled = this.hasAttribute('disabled');
|
|
192
|
+
|
|
193
|
+
this._inputElement.setAttribute("type", type);
|
|
194
|
+
|
|
195
|
+
if (placeholder !== null) {
|
|
196
|
+
this._inputElement.setAttribute("placeholder", placeholder);
|
|
197
|
+
} else {
|
|
198
|
+
this._inputElement.removeAttribute("placeholder");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (isDisabled) {
|
|
202
|
+
this._inputElement.setAttribute("disabled", "");
|
|
203
|
+
} else {
|
|
204
|
+
this._inputElement.removeAttribute("disabled");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
connectedCallback() {
|
|
209
|
+
this._updateInputAttributes();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Export factory function to maintain API compatibility
|
|
214
|
+
export default ({ render, html }) => {
|
|
215
|
+
// Note: render and html parameters are accepted but not used
|
|
216
|
+
// This maintains backward compatibility with existing code
|
|
217
|
+
return RettangoliInputElement;
|
|
218
|
+
};
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import {
|
|
2
|
+
css,
|
|
3
|
+
dimensionWithUnit,
|
|
4
|
+
convertObjectToCssString,
|
|
5
|
+
styleMapKeys,
|
|
6
|
+
permutateBreakpoints,
|
|
7
|
+
} from "../common.js";
|
|
8
|
+
import cursorStyles from "../styles/cursorStyles.js";
|
|
9
|
+
import marginStyles from "../styles/marginStyles.js";
|
|
10
|
+
|
|
11
|
+
// Internal implementation without uhtml
|
|
12
|
+
class RettangoliSliderElement extends HTMLElement {
|
|
13
|
+
static styleSheet = null;
|
|
14
|
+
|
|
15
|
+
static initializeStyleSheet() {
|
|
16
|
+
if (!RettangoliSliderElement.styleSheet) {
|
|
17
|
+
RettangoliSliderElement.styleSheet = new CSSStyleSheet();
|
|
18
|
+
RettangoliSliderElement.styleSheet.replaceSync(css`
|
|
19
|
+
:host {
|
|
20
|
+
display: contents;
|
|
21
|
+
}
|
|
22
|
+
input[type="range"] {
|
|
23
|
+
-webkit-appearance: none;
|
|
24
|
+
appearance: none;
|
|
25
|
+
width: 200px;
|
|
26
|
+
height: 8px;
|
|
27
|
+
background: var(--muted);
|
|
28
|
+
border-radius: var(--border-radius-full);
|
|
29
|
+
outline: none;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
}
|
|
32
|
+
input[type="range"]::-webkit-slider-thumb {
|
|
33
|
+
-webkit-appearance: none;
|
|
34
|
+
appearance: none;
|
|
35
|
+
width: 20px;
|
|
36
|
+
height: 20px;
|
|
37
|
+
background: var(--foreground);
|
|
38
|
+
border-radius: 50%;
|
|
39
|
+
cursor: pointer;
|
|
40
|
+
transition: all 0.2s ease;
|
|
41
|
+
}
|
|
42
|
+
input[type="range"]::-moz-range-thumb {
|
|
43
|
+
width: 20px;
|
|
44
|
+
height: 20px;
|
|
45
|
+
background: var(--foreground);
|
|
46
|
+
border-radius: 50%;
|
|
47
|
+
cursor: pointer;
|
|
48
|
+
border: none;
|
|
49
|
+
transition: all 0.2s ease;
|
|
50
|
+
}
|
|
51
|
+
input[type="range"]:hover::-webkit-slider-thumb {
|
|
52
|
+
transform: scale(1.1);
|
|
53
|
+
}
|
|
54
|
+
input[type="range"]:hover::-moz-range-thumb {
|
|
55
|
+
transform: scale(1.1);
|
|
56
|
+
}
|
|
57
|
+
input[type="range"]:focus {
|
|
58
|
+
outline: 2px solid var(--ring);
|
|
59
|
+
outline-offset: 2px;
|
|
60
|
+
}
|
|
61
|
+
input[type="range"]:disabled {
|
|
62
|
+
cursor: not-allowed;
|
|
63
|
+
opacity: 0.5;
|
|
64
|
+
}
|
|
65
|
+
input[type="range"]:disabled::-webkit-slider-thumb {
|
|
66
|
+
cursor: not-allowed;
|
|
67
|
+
}
|
|
68
|
+
input[type="range"]:disabled::-moz-range-thumb {
|
|
69
|
+
cursor: not-allowed;
|
|
70
|
+
}
|
|
71
|
+
${marginStyles}
|
|
72
|
+
${cursorStyles}
|
|
73
|
+
`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
constructor() {
|
|
78
|
+
super();
|
|
79
|
+
RettangoliSliderElement.initializeStyleSheet();
|
|
80
|
+
this.shadow = this.attachShadow({ mode: "closed" });
|
|
81
|
+
this.shadow.adoptedStyleSheets = [RettangoliSliderElement.styleSheet];
|
|
82
|
+
|
|
83
|
+
// Initialize style tracking properties
|
|
84
|
+
this._styles = {
|
|
85
|
+
default: {},
|
|
86
|
+
sm: {},
|
|
87
|
+
md: {},
|
|
88
|
+
lg: {},
|
|
89
|
+
xl: {},
|
|
90
|
+
};
|
|
91
|
+
this._lastStyleString = "";
|
|
92
|
+
|
|
93
|
+
// Create initial DOM structure
|
|
94
|
+
this._inputElement = document.createElement('input');
|
|
95
|
+
this._inputElement.type = 'range';
|
|
96
|
+
this._styleElement = document.createElement('style');
|
|
97
|
+
|
|
98
|
+
this.shadow.appendChild(this._styleElement);
|
|
99
|
+
this.shadow.appendChild(this._inputElement);
|
|
100
|
+
|
|
101
|
+
// Bind event handlers
|
|
102
|
+
this._inputElement.addEventListener('input', this._onInput);
|
|
103
|
+
this._inputElement.addEventListener('change', this._onChange);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static get observedAttributes() {
|
|
107
|
+
return [
|
|
108
|
+
"key",
|
|
109
|
+
"value",
|
|
110
|
+
"min",
|
|
111
|
+
"max",
|
|
112
|
+
"step",
|
|
113
|
+
"disabled",
|
|
114
|
+
...permutateBreakpoints([
|
|
115
|
+
...styleMapKeys,
|
|
116
|
+
"wh",
|
|
117
|
+
"w",
|
|
118
|
+
"h",
|
|
119
|
+
"hidden",
|
|
120
|
+
"visible",
|
|
121
|
+
"op",
|
|
122
|
+
"z",
|
|
123
|
+
])
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
get value() {
|
|
128
|
+
return this._inputElement.value;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
set value(newValue) {
|
|
132
|
+
this._inputElement.value = newValue;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
_onInput = (event) => {
|
|
136
|
+
this.dispatchEvent(new CustomEvent('slider-input', {
|
|
137
|
+
detail: {
|
|
138
|
+
value: this._inputElement.value,
|
|
139
|
+
},
|
|
140
|
+
}));
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
_onChange = (event) => {
|
|
144
|
+
this.dispatchEvent(new CustomEvent('slider-change', {
|
|
145
|
+
detail: {
|
|
146
|
+
value: this._inputElement.value,
|
|
147
|
+
},
|
|
148
|
+
}));
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
152
|
+
// Handle input-specific attributes first
|
|
153
|
+
if (["value", "min", "max", "step", "disabled"].includes(name)) {
|
|
154
|
+
this._updateInputAttributes();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Reset styles for fresh calculation
|
|
159
|
+
this._styles = {
|
|
160
|
+
default: {},
|
|
161
|
+
sm: {},
|
|
162
|
+
md: {},
|
|
163
|
+
lg: {},
|
|
164
|
+
xl: {},
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
["default", "sm", "md", "lg", "xl"].forEach((size) => {
|
|
168
|
+
const addSizePrefix = (tag) => {
|
|
169
|
+
return `${size === "default" ? "" : `${size}-`}${tag}`;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const wh = this.getAttribute(addSizePrefix("wh"));
|
|
173
|
+
const width = dimensionWithUnit(
|
|
174
|
+
wh === null ? this.getAttribute(addSizePrefix("w")) : wh,
|
|
175
|
+
);
|
|
176
|
+
const height = dimensionWithUnit(
|
|
177
|
+
wh === null ? this.getAttribute(addSizePrefix("h")) : wh,
|
|
178
|
+
);
|
|
179
|
+
const opacity = this.getAttribute(addSizePrefix("op"));
|
|
180
|
+
const zIndex = this.getAttribute(addSizePrefix("z"));
|
|
181
|
+
|
|
182
|
+
if (zIndex !== null) {
|
|
183
|
+
this._styles[size]["z-index"] = zIndex;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (opacity !== null) {
|
|
187
|
+
this._styles[size].opacity = opacity;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (width === "f") {
|
|
191
|
+
this._styles[size].width = "var(--width-stretch)";
|
|
192
|
+
} else if (width !== undefined) {
|
|
193
|
+
this._styles[size].width = width;
|
|
194
|
+
this._styles[size]["min-width"] = width;
|
|
195
|
+
this._styles[size]["max-width"] = width;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (height === "f") {
|
|
199
|
+
this._styles[size].height = "100%";
|
|
200
|
+
} else if (height !== undefined) {
|
|
201
|
+
this._styles[size].height = height;
|
|
202
|
+
this._styles[size]["min-height"] = height;
|
|
203
|
+
this._styles[size]["max-height"] = height;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (this.hasAttribute(addSizePrefix("hidden"))) {
|
|
207
|
+
this._styles[size].display = "none !important";
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (this.hasAttribute(addSizePrefix("visible"))) {
|
|
211
|
+
this._styles[size].display = "block !important";
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// Update styles only if changed - targeting input element
|
|
216
|
+
const newStyleString = convertObjectToCssString(this._styles, 'input[type="range"]');
|
|
217
|
+
if (newStyleString !== this._lastStyleString) {
|
|
218
|
+
this._styleElement.textContent = newStyleString;
|
|
219
|
+
this._lastStyleString = newStyleString;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
_updateInputAttributes() {
|
|
224
|
+
const value = this.getAttribute("value");
|
|
225
|
+
const min = this.getAttribute("min");
|
|
226
|
+
const max = this.getAttribute("max");
|
|
227
|
+
const step = this.getAttribute("step");
|
|
228
|
+
const isDisabled = this.hasAttribute('disabled');
|
|
229
|
+
|
|
230
|
+
if (value !== null) {
|
|
231
|
+
this._inputElement.value = value;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (min !== null) {
|
|
235
|
+
this._inputElement.min = min;
|
|
236
|
+
} else {
|
|
237
|
+
this._inputElement.min = "0";
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (max !== null) {
|
|
241
|
+
this._inputElement.max = max;
|
|
242
|
+
} else {
|
|
243
|
+
this._inputElement.max = "100";
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (step !== null) {
|
|
247
|
+
this._inputElement.step = step;
|
|
248
|
+
} else {
|
|
249
|
+
this._inputElement.step = "1";
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (isDisabled) {
|
|
253
|
+
this._inputElement.setAttribute("disabled", "");
|
|
254
|
+
} else {
|
|
255
|
+
this._inputElement.removeAttribute("disabled");
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
connectedCallback() {
|
|
260
|
+
this._updateInputAttributes();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Export factory function to maintain API compatibility
|
|
265
|
+
export default ({ render, html }) => {
|
|
266
|
+
// Note: render and html parameters are accepted but not used
|
|
267
|
+
// This maintains backward compatibility with existing code
|
|
268
|
+
return RettangoliSliderElement;
|
|
269
|
+
};
|