tosijs-ui 1.0.1 → 1.0.2
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 +4 -2
- package/dist/iife.js +70 -60
- package/dist/iife.js.map +42 -42
- package/dist/index.js +15 -37
- package/dist/index.js.map +39 -39
- package/dist/version.d.ts +1 -1
- package/package.json +2 -2
- package/dist/ab-test.js +0 -116
- package/dist/babylon-3d.js +0 -292
- package/dist/bodymovin-player.js +0 -172
- package/dist/bp-loader.js +0 -26
- package/dist/carousel.js +0 -308
- package/dist/code-editor.js +0 -102
- package/dist/color-input.js +0 -112
- package/dist/data-table.js +0 -774
- package/dist/drag-and-drop.js +0 -386
- package/dist/editable-rect.js +0 -450
- package/dist/filter-builder.js +0 -468
- package/dist/float.js +0 -170
- package/dist/form.js +0 -466
- package/dist/gamepad.js +0 -115
- package/dist/icon-data.js +0 -308
- package/dist/icon-types.js +0 -1
- package/dist/icons.js +0 -374
- package/dist/index-iife.js +0 -4
- package/dist/live-example.js +0 -611
- package/dist/localize.js +0 -381
- package/dist/make-sorter.js +0 -119
- package/dist/make-sorter.test.d.ts +0 -1
- package/dist/make-sorter.test.js +0 -48
- package/dist/mapbox.js +0 -161
- package/dist/markdown-viewer.js +0 -173
- package/dist/match-shortcut.js +0 -13
- package/dist/match-shortcut.test.d.ts +0 -1
- package/dist/match-shortcut.test.js +0 -194
- package/dist/menu.js +0 -614
- package/dist/notifications.js +0 -308
- package/dist/password-strength.js +0 -302
- package/dist/playwright.config.d.ts +0 -9
- package/dist/playwright.config.js +0 -73
- package/dist/pop-float.js +0 -231
- package/dist/rating.js +0 -192
- package/dist/rich-text.js +0 -296
- package/dist/segmented.js +0 -298
- package/dist/select.js +0 -427
- package/dist/side-nav.js +0 -106
- package/dist/size-break.js +0 -118
- package/dist/sizer.js +0 -92
- package/dist/src/ab-test.d.ts +0 -14
- package/dist/src/babylon-3d.d.ts +0 -53
- package/dist/src/bodymovin-player.d.ts +0 -32
- package/dist/src/bp-loader.d.ts +0 -0
- package/dist/src/carousel.d.ts +0 -113
- package/dist/src/code-editor.d.ts +0 -27
- package/dist/src/color-input.d.ts +0 -41
- package/dist/src/data-table.d.ts +0 -79
- package/dist/src/drag-and-drop.d.ts +0 -2
- package/dist/src/editable-rect.d.ts +0 -97
- package/dist/src/filter-builder.d.ts +0 -64
- package/dist/src/float.d.ts +0 -18
- package/dist/src/form.d.ts +0 -68
- package/dist/src/gamepad.d.ts +0 -34
- package/dist/src/icon-data.d.ts +0 -309
- package/dist/src/icon-types.d.ts +0 -7
- package/dist/src/icons.d.ts +0 -17
- package/dist/src/index.d.ts +0 -37
- package/dist/src/live-example.d.ts +0 -51
- package/dist/src/localize.d.ts +0 -30
- package/dist/src/make-sorter.d.ts +0 -3
- package/dist/src/mapbox.d.ts +0 -24
- package/dist/src/markdown-viewer.d.ts +0 -15
- package/dist/src/match-shortcut.d.ts +0 -9
- package/dist/src/menu.d.ts +0 -60
- package/dist/src/notifications.d.ts +0 -106
- package/dist/src/password-strength.d.ts +0 -35
- package/dist/src/pop-float.d.ts +0 -10
- package/dist/src/rating.d.ts +0 -62
- package/dist/src/rich-text.d.ts +0 -28
- package/dist/src/segmented.d.ts +0 -80
- package/dist/src/select.d.ts +0 -43
- package/dist/src/side-nav.d.ts +0 -36
- package/dist/src/size-break.d.ts +0 -18
- package/dist/src/sizer.d.ts +0 -34
- package/dist/src/tab-selector.d.ts +0 -91
- package/dist/src/tag-list.d.ts +0 -37
- package/dist/src/track-drag.d.ts +0 -5
- package/dist/src/version.d.ts +0 -1
- package/dist/src/via-tag.d.ts +0 -2
- package/dist/tab-selector.js +0 -326
- package/dist/tag-list.js +0 -375
- package/dist/track-drag.js +0 -143
- package/dist/version.js +0 -1
- package/dist/via-tag.js +0 -102
package/dist/carousel.js
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
/*#
|
|
2
|
-
# carousel
|
|
3
|
-
|
|
4
|
-
```html
|
|
5
|
-
<xin-carousel arrows dots max-visible-items=2 auto=2 snap-delay=4 snap-duration=0.5 loop>
|
|
6
|
-
<xin-icon icon="tosiFavicon" class="thing"></xin-icon>
|
|
7
|
-
<xin-icon icon="tosi" class="thing"></xin-icon>
|
|
8
|
-
<xin-icon icon="tosiUi" class="thing"></xin-icon>
|
|
9
|
-
<xin-icon icon="tosiPlatform" class="thing"></xin-icon>
|
|
10
|
-
<xin-icon icon="tosiXr" class="thing"></xin-icon>
|
|
11
|
-
<xin-icon icon="blueprint" class="thing"></xin-icon>
|
|
12
|
-
<xin-icon icon="cmy" class="thing"></xin-icon>
|
|
13
|
-
<xin-icon icon="rgb" class="thing"></xin-icon>
|
|
14
|
-
</xin-carousel>
|
|
15
|
-
```
|
|
16
|
-
```css
|
|
17
|
-
.thing {
|
|
18
|
-
--xin-icon-size: 160px;
|
|
19
|
-
height: 160px;
|
|
20
|
-
margin: 30px 0 70px;
|
|
21
|
-
position: relative;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.thing::after {
|
|
25
|
-
content: attr(icon);
|
|
26
|
-
color: white;
|
|
27
|
-
position: absolute;
|
|
28
|
-
bottom: -50px;
|
|
29
|
-
left: 50%;
|
|
30
|
-
padding: 5px 15px;
|
|
31
|
-
transform: translateX(-50%);
|
|
32
|
-
filter: drop-shadow(0 1px 1px #0008);
|
|
33
|
-
background: #0004;
|
|
34
|
-
border-radius: 5px;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
.preview xin-carousel {
|
|
38
|
-
margin: 10px;
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
This is a minimalist carousel component that supports the usual stuff.
|
|
43
|
-
|
|
44
|
-
## Attributes
|
|
45
|
-
|
|
46
|
-
- `arrows` (boolean, false by default) shows/hides the arrow paging controls
|
|
47
|
-
- `dots` (boolean, false by default) shows/hides the dot progress indicators
|
|
48
|
-
- `max-visible-items` (number, 1 by default) determines how many items are shown at once.
|
|
49
|
-
- `snap-duration` (number, 0.25 [seconds] by default) determines the time taken to scroll / snap scroll.
|
|
50
|
-
- `snap-delay` (number, 0.1 [seconds] by default)
|
|
51
|
-
- `loop` (boolean, false by default) causes next/previous buttons to loop
|
|
52
|
-
- `auto` (number, 0 [seconds] by default) if > 0, automatically advances after that many seconds (always loops!)
|
|
53
|
-
|
|
54
|
-
<xin-css-var-editor element-selector="xin-carousel"></xin-css-var-editor>
|
|
55
|
-
*/
|
|
56
|
-
import { Component as WebComponent, elements, vars, } from 'xinjs';
|
|
57
|
-
import { icons } from './icons';
|
|
58
|
-
const { button, slot, div } = elements;
|
|
59
|
-
export class XinCarousel extends WebComponent {
|
|
60
|
-
arrows = false;
|
|
61
|
-
dots = false;
|
|
62
|
-
loop = false;
|
|
63
|
-
maxVisibleItems = 1;
|
|
64
|
-
snapDelay = 0.1;
|
|
65
|
-
snapDuration = 0.25;
|
|
66
|
-
auto = 0;
|
|
67
|
-
lastAutoAdvance = Date.now();
|
|
68
|
-
interval;
|
|
69
|
-
autoAdvance = () => {
|
|
70
|
-
if (this.auto > 0 && this.auto * 1000 < Date.now() - this.lastAutoAdvance) {
|
|
71
|
-
this.forward();
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
_page = 0;
|
|
75
|
-
get page() {
|
|
76
|
-
return this._page;
|
|
77
|
-
}
|
|
78
|
-
set page(p) {
|
|
79
|
-
const { scroller, back, forward } = this.parts;
|
|
80
|
-
if (this.lastPage <= 0) {
|
|
81
|
-
forward.disabled = back.disabled = true;
|
|
82
|
-
p = 0;
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
p = Math.max(0, Math.min(this.lastPage, p));
|
|
86
|
-
p = isNaN(p) ? 0 : p;
|
|
87
|
-
}
|
|
88
|
-
if (this._page !== p) {
|
|
89
|
-
this._page = isNaN(p) ? 0 : p;
|
|
90
|
-
this.animateScroll(this._page * scroller.offsetWidth);
|
|
91
|
-
back.disabled = this.page <= 0 && !this.loop;
|
|
92
|
-
forward.disabled = this.page >= this.lastPage && !this.loop;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
get visibleItems() {
|
|
96
|
-
return [...this.children].filter((element) => getComputedStyle(element).display !== 'none');
|
|
97
|
-
}
|
|
98
|
-
get lastPage() {
|
|
99
|
-
return Math.max(Math.ceil(this.visibleItems.length / (this.maxVisibleItems || 1)) - 1, 0);
|
|
100
|
-
}
|
|
101
|
-
static styleSpec = {
|
|
102
|
-
':host': {
|
|
103
|
-
display: 'flex',
|
|
104
|
-
flexDirection: 'column',
|
|
105
|
-
position: 'relative',
|
|
106
|
-
},
|
|
107
|
-
':host svg': {
|
|
108
|
-
height: vars.carouselIconSize,
|
|
109
|
-
},
|
|
110
|
-
':host button': {
|
|
111
|
-
outline: 'none',
|
|
112
|
-
border: 'none',
|
|
113
|
-
boxShadow: 'none',
|
|
114
|
-
background: 'transparent',
|
|
115
|
-
color: vars.carouselButtonColor,
|
|
116
|
-
padding: 0,
|
|
117
|
-
},
|
|
118
|
-
':host::part(back), :host::part(forward)': {
|
|
119
|
-
position: 'absolute',
|
|
120
|
-
top: 0,
|
|
121
|
-
bottom: 0,
|
|
122
|
-
width: vars.carouseButtonWidth,
|
|
123
|
-
zIndex: 2,
|
|
124
|
-
},
|
|
125
|
-
':host::part(back)': {
|
|
126
|
-
left: 0,
|
|
127
|
-
},
|
|
128
|
-
':host::part(forward)': {
|
|
129
|
-
right: 0,
|
|
130
|
-
},
|
|
131
|
-
':host button:disabled': {
|
|
132
|
-
opacity: 0.5,
|
|
133
|
-
pointerEvents: 'none',
|
|
134
|
-
},
|
|
135
|
-
':host button:hover': {
|
|
136
|
-
color: vars.carouselButtonHoverColor,
|
|
137
|
-
},
|
|
138
|
-
':host button:active': {
|
|
139
|
-
color: vars.carouselButtonActiveColor,
|
|
140
|
-
},
|
|
141
|
-
':host::part(pager)': {
|
|
142
|
-
position: 'relative',
|
|
143
|
-
},
|
|
144
|
-
':host::part(scroller)': {
|
|
145
|
-
overflow: 'auto hidden',
|
|
146
|
-
position: 'relative',
|
|
147
|
-
},
|
|
148
|
-
':host::part(grid)': {
|
|
149
|
-
display: 'grid',
|
|
150
|
-
justifyItems: 'center',
|
|
151
|
-
},
|
|
152
|
-
':host *::-webkit-scrollbar, *::-webkit-scrollbar-thumb': {
|
|
153
|
-
display: 'none',
|
|
154
|
-
},
|
|
155
|
-
':host .dot': {
|
|
156
|
-
background: vars.carouselButtonColor,
|
|
157
|
-
borderRadius: vars.carouselDotSize,
|
|
158
|
-
height: vars.carouselDotSize,
|
|
159
|
-
width: vars.carouselDotSize,
|
|
160
|
-
transition: vars.carouselDotTransition,
|
|
161
|
-
},
|
|
162
|
-
':host .dot:not(.current):hover': {
|
|
163
|
-
background: vars.carouselButtonHoverColor,
|
|
164
|
-
height: vars.carouselDotSize150,
|
|
165
|
-
width: vars.carouselDotSize150,
|
|
166
|
-
margin: vars.carouselDotSize_25,
|
|
167
|
-
},
|
|
168
|
-
':host .dot:not(.current):active': {
|
|
169
|
-
background: vars.carouselButtonActiveColor,
|
|
170
|
-
},
|
|
171
|
-
':host .dot.current': {
|
|
172
|
-
background: vars.carouselDotCurrentColor,
|
|
173
|
-
},
|
|
174
|
-
':host::part(progress)': {
|
|
175
|
-
display: 'flex',
|
|
176
|
-
gap: vars.carouselDotSpacing,
|
|
177
|
-
justifyContent: 'center',
|
|
178
|
-
padding: vars.carouselProgressPadding,
|
|
179
|
-
},
|
|
180
|
-
};
|
|
181
|
-
easing = (t) => {
|
|
182
|
-
return Math.sin(t * Math.PI * 0.5);
|
|
183
|
-
};
|
|
184
|
-
indicateCurrent = () => {
|
|
185
|
-
const { scroller, progress } = this.parts;
|
|
186
|
-
const page = scroller.scrollLeft / scroller.offsetWidth;
|
|
187
|
-
[...progress.children].forEach((dot, index) => {
|
|
188
|
-
dot.classList.toggle('current', Math.floor(index / this.maxVisibleItems - page) === 0);
|
|
189
|
-
});
|
|
190
|
-
this.lastAutoAdvance = Date.now();
|
|
191
|
-
clearTimeout(this.snapTimer);
|
|
192
|
-
this.snapTimer = setTimeout(this.snapPosition, this.snapDelay * 1000);
|
|
193
|
-
};
|
|
194
|
-
snapPosition = () => {
|
|
195
|
-
const { scroller } = this.parts;
|
|
196
|
-
const currentPosition = Math.round(scroller.scrollLeft / scroller.offsetWidth);
|
|
197
|
-
if (currentPosition !== this.page) {
|
|
198
|
-
this.page =
|
|
199
|
-
currentPosition > this.page
|
|
200
|
-
? Math.ceil(currentPosition)
|
|
201
|
-
: Math.floor(currentPosition);
|
|
202
|
-
}
|
|
203
|
-
this.lastAutoAdvance = Date.now();
|
|
204
|
-
};
|
|
205
|
-
back = () => {
|
|
206
|
-
this.page = this.page > 0 ? this.page - 1 : this.lastPage;
|
|
207
|
-
};
|
|
208
|
-
forward = () => {
|
|
209
|
-
this.page = this.page < this.lastPage ? this.page + 1 : 0;
|
|
210
|
-
};
|
|
211
|
-
handleDotClick = (event) => {
|
|
212
|
-
const { progress } = this.parts;
|
|
213
|
-
const index = [...progress.children].indexOf(event.target);
|
|
214
|
-
if (index > -1) {
|
|
215
|
-
this.page = Math.floor(index / this.maxVisibleItems);
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
snapTimer;
|
|
219
|
-
animationFrame;
|
|
220
|
-
animateScroll(position, startingPosition = -1, timestamp = 0) {
|
|
221
|
-
cancelAnimationFrame(this.animationFrame);
|
|
222
|
-
const { scroller } = this.parts;
|
|
223
|
-
if (startingPosition === -1) {
|
|
224
|
-
startingPosition = scroller.scrollLeft;
|
|
225
|
-
timestamp = Date.now();
|
|
226
|
-
this.animationFrame = requestAnimationFrame(() => {
|
|
227
|
-
this.animateScroll(position, startingPosition, timestamp);
|
|
228
|
-
});
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
const elapsed = (Date.now() - timestamp) / 1000;
|
|
232
|
-
if (elapsed >= this.snapDuration ||
|
|
233
|
-
Math.abs(scroller.scrollLeft - position) < 2) {
|
|
234
|
-
scroller.scrollLeft = position;
|
|
235
|
-
this.animationFrame = null;
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
scroller.scrollLeft =
|
|
239
|
-
startingPosition +
|
|
240
|
-
this.easing(elapsed / this.snapDuration) * (position - startingPosition);
|
|
241
|
-
this.animationFrame = requestAnimationFrame(() => {
|
|
242
|
-
this.animateScroll(position, startingPosition, timestamp);
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
content = () => [
|
|
247
|
-
div({ part: 'pager' }, button({ title: 'previous slide', part: 'back' }, icons.chevronLeft()), div({ title: 'slides', role: 'group', part: 'scroller' }, div({ part: 'grid' }, slot())), button({ title: 'next slide', part: 'forward' }, icons.chevronRight())),
|
|
248
|
-
div({ title: 'choose slide to display', role: 'group', part: 'progress' }),
|
|
249
|
-
];
|
|
250
|
-
constructor() {
|
|
251
|
-
super();
|
|
252
|
-
this.initAttributes('dots', 'arrows', 'maxVisibleItems', 'snapDuration', 'loop', 'auto');
|
|
253
|
-
}
|
|
254
|
-
connectedCallback() {
|
|
255
|
-
super.connectedCallback();
|
|
256
|
-
this.ariaRoleDescription = 'carousel';
|
|
257
|
-
this.ariaOrientation = 'horizontal';
|
|
258
|
-
this.ariaReadOnly = 'true';
|
|
259
|
-
const { back, forward, scroller, progress } = this.parts;
|
|
260
|
-
back.addEventListener('click', this.back);
|
|
261
|
-
forward.addEventListener('click', this.forward);
|
|
262
|
-
scroller.addEventListener('scroll', this.indicateCurrent);
|
|
263
|
-
progress.addEventListener('click', this.handleDotClick);
|
|
264
|
-
this.lastAutoAdvance = Date.now();
|
|
265
|
-
this.interval = setInterval(this.autoAdvance, 100);
|
|
266
|
-
}
|
|
267
|
-
disconnectedCallback() {
|
|
268
|
-
clearInterval(this.interval);
|
|
269
|
-
}
|
|
270
|
-
render() {
|
|
271
|
-
super.render();
|
|
272
|
-
const { dots, arrows, visibleItems, lastPage } = this;
|
|
273
|
-
const { progress, back, forward, grid } = this.parts;
|
|
274
|
-
visibleItems.forEach((item) => {
|
|
275
|
-
item.role = 'group';
|
|
276
|
-
});
|
|
277
|
-
grid.style.gridTemplateColumns = `${100 / this.maxVisibleItems / (1 + this.lastPage)}% `
|
|
278
|
-
.repeat(visibleItems.length)
|
|
279
|
-
.trim();
|
|
280
|
-
grid.style.width = (1 + this.lastPage) * 100 + '%';
|
|
281
|
-
progress.textContent = '';
|
|
282
|
-
progress.append(...visibleItems.map((_, index) => button({ title: `item ${index + 1}`, class: 'dot' })));
|
|
283
|
-
this.indicateCurrent();
|
|
284
|
-
progress.style.display = dots && lastPage > 0 ? '' : 'none';
|
|
285
|
-
back.hidden = forward.hidden = !(arrows && lastPage > 0);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
export const xinCarousel = XinCarousel.elementCreator({
|
|
289
|
-
tag: 'xin-carousel',
|
|
290
|
-
styleSpec: {
|
|
291
|
-
':host': {
|
|
292
|
-
_carouselIconSize: 24,
|
|
293
|
-
_carouselButtonColor: '#0004',
|
|
294
|
-
_carouselButtonHoverColor: '#0006',
|
|
295
|
-
_carouselButtonActiveColor: '#000c',
|
|
296
|
-
_carouseButtonWidth: 48,
|
|
297
|
-
_carouselDotCurrentColor: '#0008',
|
|
298
|
-
_carouselDotSize: 8,
|
|
299
|
-
_carouselDotSpacing: vars.carouselDotSize,
|
|
300
|
-
_carouselProgressPadding: 12,
|
|
301
|
-
_carouselDotTransition: '0.125s ease-in-out',
|
|
302
|
-
},
|
|
303
|
-
':host:focus': {
|
|
304
|
-
outline: 'none',
|
|
305
|
-
boxShadow: 'none',
|
|
306
|
-
},
|
|
307
|
-
},
|
|
308
|
-
});
|
package/dist/code-editor.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/*#
|
|
2
|
-
# code
|
|
3
|
-
|
|
4
|
-
An [ACE Editor](https://ace.c9.io/) wrapper.
|
|
5
|
-
|
|
6
|
-
Sometimes, it's nice to be able to just toss a code-editor in a web-page.
|
|
7
|
-
|
|
8
|
-
`<xin-code>`'s `value` is the code it contains. Its `mode` attribute sets the language, and you can further configure
|
|
9
|
-
the ACE editor instance via its `options` property.
|
|
10
|
-
|
|
11
|
-
```html
|
|
12
|
-
<xin-code style="width: 100%; height: 100%" mode="css">
|
|
13
|
-
body {
|
|
14
|
-
box-sizing: border-box;
|
|
15
|
-
}
|
|
16
|
-
</xin-code>
|
|
17
|
-
```
|
|
18
|
-
*/
|
|
19
|
-
import { Component as WebComponent } from 'xinjs';
|
|
20
|
-
import { scriptTag } from './via-tag';
|
|
21
|
-
const ACE_BASE_URL = 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.23.2/';
|
|
22
|
-
const DEFAULT_THEME = 'ace/theme/tomorrow';
|
|
23
|
-
const makeCodeEditor = async (codeElement, mode = 'html', options = {}, theme = DEFAULT_THEME) => {
|
|
24
|
-
const { ace } = await scriptTag(`${ACE_BASE_URL}ace.min.js`);
|
|
25
|
-
ace.config.set('basePath', ACE_BASE_URL);
|
|
26
|
-
const editor = ace.edit(codeElement, {
|
|
27
|
-
mode: `ace/mode/${mode}`,
|
|
28
|
-
tabSize: 2,
|
|
29
|
-
useSoftTabs: true,
|
|
30
|
-
useWorker: false,
|
|
31
|
-
...options,
|
|
32
|
-
});
|
|
33
|
-
editor.setTheme(theme);
|
|
34
|
-
return editor;
|
|
35
|
-
};
|
|
36
|
-
export class CodeEditor extends WebComponent {
|
|
37
|
-
source = '';
|
|
38
|
-
get value() {
|
|
39
|
-
return this.editor === undefined ? this.source : this.editor.getValue();
|
|
40
|
-
}
|
|
41
|
-
set value(text) {
|
|
42
|
-
if (this.editor === undefined) {
|
|
43
|
-
this.source = text;
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
this.editor.setValue(text);
|
|
47
|
-
this.editor.clearSelection();
|
|
48
|
-
this.editor.session.getUndoManager().reset();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
mode = 'javascript';
|
|
52
|
-
disabled = false;
|
|
53
|
-
role = 'code editor';
|
|
54
|
-
get editor() {
|
|
55
|
-
return this._editor;
|
|
56
|
-
}
|
|
57
|
-
_editor;
|
|
58
|
-
_editorPromise;
|
|
59
|
-
options = {};
|
|
60
|
-
theme = DEFAULT_THEME;
|
|
61
|
-
static styleSpec = {
|
|
62
|
-
':host': {
|
|
63
|
-
display: 'block',
|
|
64
|
-
position: 'relative',
|
|
65
|
-
width: '100%',
|
|
66
|
-
height: '100%',
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
constructor() {
|
|
70
|
-
super();
|
|
71
|
-
this.initAttributes('mode', 'theme', 'disabled');
|
|
72
|
-
}
|
|
73
|
-
onResize() {
|
|
74
|
-
if (this.editor !== undefined) {
|
|
75
|
-
this.editor.resize(true);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
connectedCallback() {
|
|
79
|
-
super.connectedCallback();
|
|
80
|
-
if (this.source === '') {
|
|
81
|
-
this.value = this.textContent !== null ? this.textContent.trim() : '';
|
|
82
|
-
}
|
|
83
|
-
if (this._editorPromise === undefined) {
|
|
84
|
-
this._editorPromise = makeCodeEditor(this, this.mode, this.options, this.theme);
|
|
85
|
-
this._editorPromise.then((editor) => {
|
|
86
|
-
this._editor = editor;
|
|
87
|
-
editor.setValue(this.source, 1);
|
|
88
|
-
editor.clearSelection();
|
|
89
|
-
editor.session.getUndoManager().reset();
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
render() {
|
|
94
|
-
super.render();
|
|
95
|
-
if (this._editorPromise !== undefined) {
|
|
96
|
-
this._editorPromise.then((editor) => editor.setReadOnly(this.disabled));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
export const codeEditor = CodeEditor.elementCreator({
|
|
101
|
-
tag: 'xin-code',
|
|
102
|
-
});
|
package/dist/color-input.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/*#
|
|
2
|
-
|
|
3
|
-
# color input field
|
|
4
|
-
|
|
5
|
-
This is a color input field that supports opacity
|
|
6
|
-
|
|
7
|
-
```js
|
|
8
|
-
const colorInput = preview.querySelector('xin-color')
|
|
9
|
-
const circle = preview.querySelector('div')
|
|
10
|
-
|
|
11
|
-
colorInput.addEventListener('change', () => {
|
|
12
|
-
console.log(colorInput.value)
|
|
13
|
-
circle.style.background = colorInput.value
|
|
14
|
-
})
|
|
15
|
-
```
|
|
16
|
-
```html
|
|
17
|
-
<xin-color value="red"></xin-color>
|
|
18
|
-
<div
|
|
19
|
-
style="
|
|
20
|
-
width: 200px;
|
|
21
|
-
height: 200px;
|
|
22
|
-
background: red;
|
|
23
|
-
border-radius: 100px;
|
|
24
|
-
"
|
|
25
|
-
></div>
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<xin-css-var-editor element-selector="xin-color"></xin-css-var-editor>
|
|
30
|
-
*/
|
|
31
|
-
import { Component, elements, Color, vars, } from 'xinjs';
|
|
32
|
-
const { input } = elements;
|
|
33
|
-
const defaultColor = Color.fromCss('#8888');
|
|
34
|
-
class ColorInput extends Component {
|
|
35
|
-
value = defaultColor.rgba;
|
|
36
|
-
color = defaultColor;
|
|
37
|
-
static styleSpec = {
|
|
38
|
-
':host': {
|
|
39
|
-
_gap: 8,
|
|
40
|
-
_swatchSize: 32,
|
|
41
|
-
_cssWidth: 72,
|
|
42
|
-
_alphaWidth: 72,
|
|
43
|
-
display: 'inline-flex',
|
|
44
|
-
gap: vars.gap,
|
|
45
|
-
alignItems: 'center',
|
|
46
|
-
},
|
|
47
|
-
':host input[type="color"]': {
|
|
48
|
-
border: 0,
|
|
49
|
-
width: vars.swatchSize,
|
|
50
|
-
height: vars.swatchSize,
|
|
51
|
-
background: 'transparent',
|
|
52
|
-
},
|
|
53
|
-
':host::part(alpha)': {
|
|
54
|
-
width: vars.alphaWidth,
|
|
55
|
-
},
|
|
56
|
-
':host::part(css)': {
|
|
57
|
-
width: vars.cssWidth,
|
|
58
|
-
fontFamily: 'monospace',
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
content = [
|
|
62
|
-
input({ title: 'base color', type: 'color', part: 'rgb' }),
|
|
63
|
-
input({
|
|
64
|
-
type: 'range',
|
|
65
|
-
title: 'opacity',
|
|
66
|
-
part: 'alpha',
|
|
67
|
-
min: 0,
|
|
68
|
-
max: 1,
|
|
69
|
-
step: 0.05,
|
|
70
|
-
}),
|
|
71
|
-
input({ title: 'css color spec', part: 'css' }),
|
|
72
|
-
];
|
|
73
|
-
valueChanged = false;
|
|
74
|
-
update = (event) => {
|
|
75
|
-
const { rgb, alpha, css } = this.parts;
|
|
76
|
-
if (event.type === 'input') {
|
|
77
|
-
this.color = Color.fromCss(rgb.value);
|
|
78
|
-
this.color.a = Number(alpha.value);
|
|
79
|
-
css.value = this.color.html;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
this.color = Color.fromCss(css.value);
|
|
83
|
-
rgb.value = this.color.html.substring(0, 7);
|
|
84
|
-
alpha.value = String(this.color.a);
|
|
85
|
-
}
|
|
86
|
-
rgb.style.opacity = String(this.color.a);
|
|
87
|
-
this.value = this.color.rgba;
|
|
88
|
-
this.valueChanged = true;
|
|
89
|
-
};
|
|
90
|
-
connectedCallback() {
|
|
91
|
-
super.connectedCallback();
|
|
92
|
-
const { rgb, alpha, css } = this.parts;
|
|
93
|
-
rgb.addEventListener('input', this.update);
|
|
94
|
-
alpha.addEventListener('input', this.update);
|
|
95
|
-
css.addEventListener('change', this.update);
|
|
96
|
-
}
|
|
97
|
-
render() {
|
|
98
|
-
if (this.valueChanged) {
|
|
99
|
-
this.valueChanged = false;
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const { rgb, alpha, css } = this.parts;
|
|
103
|
-
this.color = Color.fromCss(this.value);
|
|
104
|
-
rgb.value = this.color.html.substring(0, 7);
|
|
105
|
-
rgb.style.opacity = String(this.color.a);
|
|
106
|
-
alpha.value = String(this.color.a);
|
|
107
|
-
css.value = this.color.html;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
export const colorInput = ColorInput.elementCreator({
|
|
111
|
-
tag: 'xin-color',
|
|
112
|
-
});
|