rettangoli-ui 0.1.0-rc1 → 0.1.0-rc3
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 +16 -27
- package/dist/rettangoli-iife-layout.min.js +360 -284
- package/dist/rettangoli-iife-ui.min.js +382 -548
- package/package.json +13 -5
- 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 +24 -0
- package/src/components/dialog/dialog.view.yaml +40 -0
- package/src/components/form/form.handlers.js +30 -0
- package/src/components/form/form.store.js +45 -0
- package/src/components/form/form.view.yaml +47 -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 +17 -0
- package/src/components/popover/popover.store.js +37 -0
- package/src/components/popover/popover.view.yaml +50 -0
- package/src/components/select/select.handlers.js +15 -0
- package/src/components/select/select.store.js +25 -0
- package/src/components/select/select.view.yaml +38 -0
- package/src/components/sidebar/sidebar.handlers.js +36 -0
- package/src/components/sidebar/sidebar.store.js +125 -0
- package/src/components/sidebar/sidebar.view.yaml +186 -0
- package/src/entry-iife-layout.js +15 -0
- package/src/entry-iife-ui.js +18 -0
- package/src/index.js +17 -0
- package/src/lib/uhtml.js +9 -0
- package/src/primitives/button.js +263 -0
- package/src/primitives/image.js +234 -0
- package/src/primitives/input.js +208 -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 +215 -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 +119 -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,208 @@
|
|
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
|
+
input:focus {
|
37
|
+
border-color: var(--foreground);
|
38
|
+
}
|
39
|
+
input:disabled {
|
40
|
+
cursor: not-allowed;
|
41
|
+
}
|
42
|
+
${marginStyles}
|
43
|
+
${cursorStyles}
|
44
|
+
`);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
constructor() {
|
49
|
+
super();
|
50
|
+
RettangoliInputElement.initializeStyleSheet();
|
51
|
+
this.shadow = this.attachShadow({ mode: "closed" });
|
52
|
+
this.shadow.adoptedStyleSheets = [RettangoliInputElement.styleSheet];
|
53
|
+
|
54
|
+
// Initialize style tracking properties
|
55
|
+
this._styles = {
|
56
|
+
default: {},
|
57
|
+
sm: {},
|
58
|
+
md: {},
|
59
|
+
lg: {},
|
60
|
+
xl: {},
|
61
|
+
};
|
62
|
+
this._lastStyleString = "";
|
63
|
+
|
64
|
+
// Create initial DOM structure
|
65
|
+
this._inputElement = document.createElement('input');
|
66
|
+
this._styleElement = document.createElement('style');
|
67
|
+
|
68
|
+
this.shadow.appendChild(this._styleElement);
|
69
|
+
this.shadow.appendChild(this._inputElement);
|
70
|
+
|
71
|
+
// Bind event handler
|
72
|
+
this._inputElement.addEventListener('keydown', this._onChange);
|
73
|
+
}
|
74
|
+
|
75
|
+
static get observedAttributes() {
|
76
|
+
return [
|
77
|
+
"key",
|
78
|
+
"type",
|
79
|
+
"placeholder",
|
80
|
+
"disabled",
|
81
|
+
...permutateBreakpoints([
|
82
|
+
...styleMapKeys,
|
83
|
+
"wh",
|
84
|
+
"w",
|
85
|
+
"h",
|
86
|
+
"hidden",
|
87
|
+
"visible",
|
88
|
+
"op",
|
89
|
+
"z",
|
90
|
+
])
|
91
|
+
];
|
92
|
+
}
|
93
|
+
|
94
|
+
get value() {
|
95
|
+
return this._inputElement.value;
|
96
|
+
}
|
97
|
+
|
98
|
+
_onChange = (event) => {
|
99
|
+
this.dispatchEvent(new CustomEvent('input-keydown', {
|
100
|
+
detail: {
|
101
|
+
value: this._inputElement.value,
|
102
|
+
},
|
103
|
+
}));
|
104
|
+
};
|
105
|
+
|
106
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
107
|
+
// Handle input-specific attributes first
|
108
|
+
if (["type", "placeholder", "disabled"].includes(name)) {
|
109
|
+
this._updateInputAttributes();
|
110
|
+
return;
|
111
|
+
}
|
112
|
+
|
113
|
+
// Reset styles for fresh calculation
|
114
|
+
this._styles = {
|
115
|
+
default: {},
|
116
|
+
sm: {},
|
117
|
+
md: {},
|
118
|
+
lg: {},
|
119
|
+
xl: {},
|
120
|
+
};
|
121
|
+
|
122
|
+
["default", "sm", "md", "lg", "xl"].forEach((size) => {
|
123
|
+
const addSizePrefix = (tag) => {
|
124
|
+
return `${size === "default" ? "" : `${size}-`}${tag}`;
|
125
|
+
};
|
126
|
+
|
127
|
+
const wh = this.getAttribute(addSizePrefix("wh"));
|
128
|
+
const width = dimensionWithUnit(
|
129
|
+
wh === null ? this.getAttribute(addSizePrefix("w")) : wh,
|
130
|
+
);
|
131
|
+
const height = dimensionWithUnit(
|
132
|
+
wh === null ? this.getAttribute(addSizePrefix("h")) : wh,
|
133
|
+
);
|
134
|
+
const opacity = this.getAttribute(addSizePrefix("op"));
|
135
|
+
const zIndex = this.getAttribute(addSizePrefix("z"));
|
136
|
+
|
137
|
+
if (zIndex !== null) {
|
138
|
+
this._styles[size]["z-index"] = zIndex;
|
139
|
+
}
|
140
|
+
|
141
|
+
if (opacity !== null) {
|
142
|
+
this._styles[size].opacity = opacity;
|
143
|
+
}
|
144
|
+
|
145
|
+
if (width === "f") {
|
146
|
+
this._styles[size].width = "var(--width-stretch)";
|
147
|
+
} else if (width !== undefined) {
|
148
|
+
this._styles[size].width = width;
|
149
|
+
this._styles[size]["min-width"] = width;
|
150
|
+
this._styles[size]["max-width"] = width;
|
151
|
+
}
|
152
|
+
|
153
|
+
if (height === "f") {
|
154
|
+
this._styles[size].height = "100%";
|
155
|
+
} else if (height !== undefined) {
|
156
|
+
this._styles[size].height = height;
|
157
|
+
this._styles[size]["min-height"] = height;
|
158
|
+
this._styles[size]["max-height"] = height;
|
159
|
+
}
|
160
|
+
|
161
|
+
if (this.hasAttribute(addSizePrefix("hidden"))) {
|
162
|
+
this._styles[size].display = "none !important";
|
163
|
+
}
|
164
|
+
|
165
|
+
if (this.hasAttribute(addSizePrefix("visible"))) {
|
166
|
+
this._styles[size].display = "block !important";
|
167
|
+
}
|
168
|
+
});
|
169
|
+
|
170
|
+
// Update styles only if changed - targeting input element
|
171
|
+
const newStyleString = convertObjectToCssString(this._styles, 'input');
|
172
|
+
if (newStyleString !== this._lastStyleString) {
|
173
|
+
this._styleElement.textContent = newStyleString;
|
174
|
+
this._lastStyleString = newStyleString;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
_updateInputAttributes() {
|
179
|
+
const type = this.getAttribute("type") || "text";
|
180
|
+
const placeholder = this.getAttribute("placeholder");
|
181
|
+
const isDisabled = this.hasAttribute('disabled');
|
182
|
+
|
183
|
+
this._inputElement.setAttribute("type", type);
|
184
|
+
|
185
|
+
if (placeholder !== null) {
|
186
|
+
this._inputElement.setAttribute("placeholder", placeholder);
|
187
|
+
} else {
|
188
|
+
this._inputElement.removeAttribute("placeholder");
|
189
|
+
}
|
190
|
+
|
191
|
+
if (isDisabled) {
|
192
|
+
this._inputElement.setAttribute("disabled", "");
|
193
|
+
} else {
|
194
|
+
this._inputElement.removeAttribute("disabled");
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
connectedCallback() {
|
199
|
+
this._updateInputAttributes();
|
200
|
+
}
|
201
|
+
}
|
202
|
+
|
203
|
+
// Export factory function to maintain API compatibility
|
204
|
+
export default ({ render, html }) => {
|
205
|
+
// Note: render and html parameters are accepted but not used
|
206
|
+
// This maintains backward compatibility with existing code
|
207
|
+
return RettangoliInputElement;
|
208
|
+
};
|
@@ -0,0 +1,95 @@
|
|
1
|
+
import { css, dimensionWithUnit } from "../common.js";
|
2
|
+
import flexChildStyles from "../styles/flexChildStyles.js";
|
3
|
+
import paddingSvgStyles from "../styles/paddingSvgStyles.js";
|
4
|
+
import cursorStyles from "../styles/cursorStyles.js";
|
5
|
+
import textColorStyles from "../styles/textColorStyles.js";
|
6
|
+
|
7
|
+
// Internal implementation without uhtml
|
8
|
+
class RettangoliSvgElement extends HTMLElement {
|
9
|
+
static styleSheet = null;
|
10
|
+
static _icons = {};
|
11
|
+
|
12
|
+
static initializeStyleSheet() {
|
13
|
+
if (!RettangoliSvgElement.styleSheet) {
|
14
|
+
RettangoliSvgElement.styleSheet = new CSSStyleSheet();
|
15
|
+
RettangoliSvgElement.styleSheet.replaceSync(css`
|
16
|
+
:host {
|
17
|
+
color: var(--foreground);
|
18
|
+
}
|
19
|
+
${textColorStyles}
|
20
|
+
${paddingSvgStyles}
|
21
|
+
${flexChildStyles}
|
22
|
+
${cursorStyles}
|
23
|
+
`);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
constructor() {
|
28
|
+
super();
|
29
|
+
RettangoliSvgElement.initializeStyleSheet();
|
30
|
+
this.shadow = this.attachShadow({ mode: "closed" });
|
31
|
+
this.shadow.adoptedStyleSheets = [RettangoliSvgElement.styleSheet];
|
32
|
+
}
|
33
|
+
|
34
|
+
static get observedAttributes() {
|
35
|
+
return ["key", "svg", "w", "h", "wh"];
|
36
|
+
}
|
37
|
+
|
38
|
+
static get icons() {
|
39
|
+
return RettangoliSvgElement._icons;
|
40
|
+
}
|
41
|
+
|
42
|
+
static addIcon(iconName, icon) {
|
43
|
+
RettangoliSvgElement._icons[iconName] = icon;
|
44
|
+
}
|
45
|
+
|
46
|
+
connectedCallback() {
|
47
|
+
this._updateSizing();
|
48
|
+
this._render();
|
49
|
+
}
|
50
|
+
|
51
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
52
|
+
this._updateSizing();
|
53
|
+
this._render();
|
54
|
+
}
|
55
|
+
|
56
|
+
_updateSizing() {
|
57
|
+
const wh = this.getAttribute("wh");
|
58
|
+
const width = dimensionWithUnit(
|
59
|
+
wh === null ? this.getAttribute("w") : wh
|
60
|
+
);
|
61
|
+
const height = dimensionWithUnit(
|
62
|
+
wh === null ? this.getAttribute("h") : wh
|
63
|
+
);
|
64
|
+
|
65
|
+
if (width) {
|
66
|
+
this.style.width = width;
|
67
|
+
}
|
68
|
+
if (height) {
|
69
|
+
this.style.height = height;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
_render() {
|
74
|
+
try {
|
75
|
+
const iconName = this.getAttribute("svg");
|
76
|
+
const svgStringContent =
|
77
|
+
RettangoliSvgElement._icons[iconName] ||
|
78
|
+
(window["rtglIcons"] || {})[iconName];
|
79
|
+
if (svgStringContent) {
|
80
|
+
this.shadow.innerHTML = svgStringContent;
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
} catch (error) {
|
84
|
+
console.log("error in rtgl-svg render", error);
|
85
|
+
}
|
86
|
+
this.shadow.innerHTML = "";
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
// Export factory function to maintain API compatibility
|
91
|
+
export default ({ render, html }) => {
|
92
|
+
// Note: render and html parameters are accepted but not used
|
93
|
+
// This maintains backward compatibility with existing code
|
94
|
+
return RettangoliSvgElement;
|
95
|
+
};
|
@@ -0,0 +1,141 @@
|
|
1
|
+
import { css, dimensionWithUnit } from "../common.js";
|
2
|
+
import cursorStyles from "../styles/cursorStyles.js";
|
3
|
+
import textStyles from "../styles/textStyles.js";
|
4
|
+
import textColorStyles from "../styles/textColorStyles.js";
|
5
|
+
import marginStyles from "../styles/marginStyles.js";
|
6
|
+
|
7
|
+
// Internal implementation without uhtml
|
8
|
+
class RettangoliTextElement extends HTMLElement {
|
9
|
+
static styleSheet = null;
|
10
|
+
|
11
|
+
static initializeStyleSheet() {
|
12
|
+
if (!RettangoliTextElement.styleSheet) {
|
13
|
+
RettangoliTextElement.styleSheet = new CSSStyleSheet();
|
14
|
+
RettangoliTextElement.styleSheet.replaceSync(css`
|
15
|
+
:host {
|
16
|
+
display: block;
|
17
|
+
font-size: var(--md-font-size);
|
18
|
+
font-weight: var(--md-font-weight);
|
19
|
+
line-height: var(--md-line-height);
|
20
|
+
letter-spacing: var(--md-letter-spacing);
|
21
|
+
}
|
22
|
+
slot {
|
23
|
+
display: contents;
|
24
|
+
}
|
25
|
+
:host ::slotted(a) {
|
26
|
+
text-decoration: var(--anchor-text-decoration);
|
27
|
+
color: var(--anchor-color);
|
28
|
+
}
|
29
|
+
:host ::slotted(a:hover) {
|
30
|
+
text-decoration: var(--anchor-text-decoration-hover);
|
31
|
+
color: var(--anchor-color-hover);
|
32
|
+
}
|
33
|
+
:host([href]) {
|
34
|
+
cursor: pointer;
|
35
|
+
position: relative;
|
36
|
+
}
|
37
|
+
:host([href]) a {
|
38
|
+
position: absolute;
|
39
|
+
top: 0;
|
40
|
+
left: 0;
|
41
|
+
right: 0;
|
42
|
+
bottom: 0;
|
43
|
+
z-index: 1;
|
44
|
+
}
|
45
|
+
${textStyles}
|
46
|
+
${textColorStyles}
|
47
|
+
${marginStyles}
|
48
|
+
${cursorStyles}
|
49
|
+
`);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
constructor() {
|
54
|
+
super();
|
55
|
+
RettangoliTextElement.initializeStyleSheet();
|
56
|
+
this.shadow = this.attachShadow({ mode: "closed" });
|
57
|
+
this.shadow.adoptedStyleSheets = [RettangoliTextElement.styleSheet];
|
58
|
+
|
59
|
+
// Create initial DOM structure
|
60
|
+
this._slotElement = document.createElement('slot');
|
61
|
+
this._linkElement = null;
|
62
|
+
this._updateDOM();
|
63
|
+
}
|
64
|
+
|
65
|
+
static get observedAttributes() {
|
66
|
+
return ["key", "w", "ellipsis", "href", "target"];
|
67
|
+
}
|
68
|
+
|
69
|
+
connectedCallback() {
|
70
|
+
this._updateStyling();
|
71
|
+
this._updateDOM();
|
72
|
+
}
|
73
|
+
|
74
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
75
|
+
if (name === "href" || name === "target") {
|
76
|
+
this._updateDOM();
|
77
|
+
} else {
|
78
|
+
this._updateStyling();
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
_updateStyling() {
|
83
|
+
const width = dimensionWithUnit(this.getAttribute("w"));
|
84
|
+
const ellipsis = this.hasAttribute("ellipsis");
|
85
|
+
|
86
|
+
if (ellipsis) {
|
87
|
+
this.style.overflow = "hidden";
|
88
|
+
this.style.textOverflow = "ellipsis";
|
89
|
+
this.style.whiteSpace = "nowrap";
|
90
|
+
} else {
|
91
|
+
this.style.overflow = "";
|
92
|
+
this.style.textOverflow = "";
|
93
|
+
this.style.whiteSpace = "";
|
94
|
+
}
|
95
|
+
|
96
|
+
if (width === "f") {
|
97
|
+
this.style.width = "var(--width-stretch)";
|
98
|
+
} else if (width !== undefined) {
|
99
|
+
this.style.width = width;
|
100
|
+
} else {
|
101
|
+
this.style.width = "";
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
_updateDOM() {
|
106
|
+
const href = this.getAttribute("href");
|
107
|
+
const target = this.getAttribute("target");
|
108
|
+
|
109
|
+
// Ensure slot is always in the shadow DOM
|
110
|
+
if (this._slotElement.parentNode !== this.shadow) {
|
111
|
+
this.shadow.appendChild(this._slotElement);
|
112
|
+
}
|
113
|
+
|
114
|
+
if (href) {
|
115
|
+
if (!this._linkElement) {
|
116
|
+
// Create link overlay only if it doesn't exist
|
117
|
+
this._linkElement = document.createElement("a");
|
118
|
+
this.shadow.appendChild(this._linkElement);
|
119
|
+
}
|
120
|
+
|
121
|
+
// Update link attributes
|
122
|
+
this._linkElement.href = href;
|
123
|
+
if (target) {
|
124
|
+
this._linkElement.target = target;
|
125
|
+
} else {
|
126
|
+
this._linkElement.removeAttribute("target");
|
127
|
+
}
|
128
|
+
} else if (this._linkElement) {
|
129
|
+
// Remove link overlay
|
130
|
+
this.shadow.removeChild(this._linkElement);
|
131
|
+
this._linkElement = null;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
// Export factory function to maintain API compatibility
|
137
|
+
export default ({ render, html }) => {
|
138
|
+
// Note: render and html parameters are accepted but not used
|
139
|
+
// This maintains backward compatibility with existing code
|
140
|
+
return RettangoliTextElement;
|
141
|
+
};
|