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.
Files changed (93) hide show
  1. package/README.md +4 -2
  2. package/dist/iife.js +70 -60
  3. package/dist/iife.js.map +42 -42
  4. package/dist/index.js +15 -37
  5. package/dist/index.js.map +39 -39
  6. package/dist/version.d.ts +1 -1
  7. package/package.json +2 -2
  8. package/dist/ab-test.js +0 -116
  9. package/dist/babylon-3d.js +0 -292
  10. package/dist/bodymovin-player.js +0 -172
  11. package/dist/bp-loader.js +0 -26
  12. package/dist/carousel.js +0 -308
  13. package/dist/code-editor.js +0 -102
  14. package/dist/color-input.js +0 -112
  15. package/dist/data-table.js +0 -774
  16. package/dist/drag-and-drop.js +0 -386
  17. package/dist/editable-rect.js +0 -450
  18. package/dist/filter-builder.js +0 -468
  19. package/dist/float.js +0 -170
  20. package/dist/form.js +0 -466
  21. package/dist/gamepad.js +0 -115
  22. package/dist/icon-data.js +0 -308
  23. package/dist/icon-types.js +0 -1
  24. package/dist/icons.js +0 -374
  25. package/dist/index-iife.js +0 -4
  26. package/dist/live-example.js +0 -611
  27. package/dist/localize.js +0 -381
  28. package/dist/make-sorter.js +0 -119
  29. package/dist/make-sorter.test.d.ts +0 -1
  30. package/dist/make-sorter.test.js +0 -48
  31. package/dist/mapbox.js +0 -161
  32. package/dist/markdown-viewer.js +0 -173
  33. package/dist/match-shortcut.js +0 -13
  34. package/dist/match-shortcut.test.d.ts +0 -1
  35. package/dist/match-shortcut.test.js +0 -194
  36. package/dist/menu.js +0 -614
  37. package/dist/notifications.js +0 -308
  38. package/dist/password-strength.js +0 -302
  39. package/dist/playwright.config.d.ts +0 -9
  40. package/dist/playwright.config.js +0 -73
  41. package/dist/pop-float.js +0 -231
  42. package/dist/rating.js +0 -192
  43. package/dist/rich-text.js +0 -296
  44. package/dist/segmented.js +0 -298
  45. package/dist/select.js +0 -427
  46. package/dist/side-nav.js +0 -106
  47. package/dist/size-break.js +0 -118
  48. package/dist/sizer.js +0 -92
  49. package/dist/src/ab-test.d.ts +0 -14
  50. package/dist/src/babylon-3d.d.ts +0 -53
  51. package/dist/src/bodymovin-player.d.ts +0 -32
  52. package/dist/src/bp-loader.d.ts +0 -0
  53. package/dist/src/carousel.d.ts +0 -113
  54. package/dist/src/code-editor.d.ts +0 -27
  55. package/dist/src/color-input.d.ts +0 -41
  56. package/dist/src/data-table.d.ts +0 -79
  57. package/dist/src/drag-and-drop.d.ts +0 -2
  58. package/dist/src/editable-rect.d.ts +0 -97
  59. package/dist/src/filter-builder.d.ts +0 -64
  60. package/dist/src/float.d.ts +0 -18
  61. package/dist/src/form.d.ts +0 -68
  62. package/dist/src/gamepad.d.ts +0 -34
  63. package/dist/src/icon-data.d.ts +0 -309
  64. package/dist/src/icon-types.d.ts +0 -7
  65. package/dist/src/icons.d.ts +0 -17
  66. package/dist/src/index.d.ts +0 -37
  67. package/dist/src/live-example.d.ts +0 -51
  68. package/dist/src/localize.d.ts +0 -30
  69. package/dist/src/make-sorter.d.ts +0 -3
  70. package/dist/src/mapbox.d.ts +0 -24
  71. package/dist/src/markdown-viewer.d.ts +0 -15
  72. package/dist/src/match-shortcut.d.ts +0 -9
  73. package/dist/src/menu.d.ts +0 -60
  74. package/dist/src/notifications.d.ts +0 -106
  75. package/dist/src/password-strength.d.ts +0 -35
  76. package/dist/src/pop-float.d.ts +0 -10
  77. package/dist/src/rating.d.ts +0 -62
  78. package/dist/src/rich-text.d.ts +0 -28
  79. package/dist/src/segmented.d.ts +0 -80
  80. package/dist/src/select.d.ts +0 -43
  81. package/dist/src/side-nav.d.ts +0 -36
  82. package/dist/src/size-break.d.ts +0 -18
  83. package/dist/src/sizer.d.ts +0 -34
  84. package/dist/src/tab-selector.d.ts +0 -91
  85. package/dist/src/tag-list.d.ts +0 -37
  86. package/dist/src/track-drag.d.ts +0 -5
  87. package/dist/src/version.d.ts +0 -1
  88. package/dist/src/via-tag.d.ts +0 -2
  89. package/dist/tab-selector.js +0 -326
  90. package/dist/tag-list.js +0 -375
  91. package/dist/track-drag.js +0 -143
  92. package/dist/version.js +0 -1
  93. package/dist/via-tag.js +0 -102
@@ -1,450 +0,0 @@
1
- /*#
2
- # editable-rect
3
-
4
- `<xin-editable>` (`editableRect` is the `ElementCreator` and `EditableRect` is the class) is an element
5
- for allowing the adjustment of another element's position and size. Simply insert it in a `position: absolute`
6
- or `position: fixed` element and you can directly adjust its CSS positioning, including rotation.
7
-
8
- Click on an element to adjust its position, dimensions, and rotation.
9
-
10
- ```js
11
- const { editableRect, icons } = xinjsui
12
- const { elements } = xinjs
13
- const { button } = elements
14
-
15
- function showTools(event) {
16
- event.stopPropagation()
17
- event.preventDefault()
18
- }
19
-
20
- const editable = editableRect(button({class: 'more-popup', onClick: showTools}, icons.moreVertical()))
21
- preview.addEventListener('click', (event) => {
22
- const target = event.target
23
- if (['absolute', 'fixed'].includes(getComputedStyle(target).position)) {
24
- target.append(editable)
25
- } else {
26
- editable.remove()
27
- }
28
- })
29
- preview.addEventListener('change', event => console.log(event))
30
- ```
31
- ```html
32
- <div class="editable" style="top: 20px; left: 20px; width: auto; height: auto; right: 20px; bottom: 20px;">
33
- <div class="editable" style="top: 20px; left: 20px; width: 200px; height: 150px;">
34
- </div>
35
- <div class="editable" style="bottom: 20px; top: 20px; width: 300px; height: auto; right: 20px;">
36
- </div>
37
- </div>
38
- ```
39
- ```css
40
- .preview .editable {
41
- position: absolute;
42
- box-shadow: inset 0 0 0 1px #0ccc;
43
- background: #0cc1;
44
- }
45
-
46
- .preview button.more-popup {
47
- position: absolute;
48
- width: 44px;
49
- height: 44px;
50
- top: 2px;
51
- right: 2px;
52
- --text-color: black;
53
- background: transparent;
54
- box-shadow: none;
55
- }
56
-
57
- .previw button
58
- ```
59
-
60
- ## Snapping
61
-
62
- When `EditableRect.snapToGrid === true` or the shift-key is depresseed, position will snap to `EditableRect.gridSize` pixels (default = 8).
63
-
64
- Similarly `EditableRect.snapAngle === true` or the shift-key will snap rotation to increments of `EditableRect.angleSize` degrees (default = 15).
65
-
66
- ## Events
67
-
68
- After an element's position, size, or rotation are adjusted a `change` event is triggered on the element.
69
- */
70
- import { Component, elements, vars } from 'xinjs';
71
- import { icons } from './icons';
72
- import { trackDrag } from './track-drag';
73
- const { div, slot } = elements;
74
- export class EditableRect extends Component {
75
- static angleSize = 15;
76
- static gridSize = 8;
77
- static snapAngle = false;
78
- static snapToGrid = false;
79
- static styleSpec = {
80
- ':host': {
81
- '--handle-bg': '#fff4',
82
- '--handle-color': '#2228',
83
- '--handle-hover-bg': '#8ff8',
84
- '--handle-hover-color': '#222',
85
- '--handle-size': '20px',
86
- '--handle-padding': '2px',
87
- },
88
- ':host ::slotted(*)': {
89
- position: 'absolute',
90
- },
91
- ':host > :not(style,slot)': {
92
- boxSizing: 'border-box',
93
- content: '" "',
94
- position: 'absolute',
95
- display: 'flex',
96
- height: vars.handleSize,
97
- width: vars.handleSize,
98
- padding: vars.handlePadding,
99
- '--text-color': vars.handleColor,
100
- background: vars.handleBg,
101
- },
102
- ':host > .drag-size': {
103
- top: 0,
104
- bottom: 0,
105
- left: 0,
106
- right: 0,
107
- height: 'auto',
108
- width: 'auto',
109
- background: 'transparent',
110
- cursor: 'ew-resize',
111
- },
112
- ':host > [part="rotate"]': {
113
- transform: `translateY(${vars.handleSize_50})`,
114
- },
115
- ':host > [locked] > svg:first-child, :host > :not([locked]) > svg+svg': {
116
- display: 'none',
117
- },
118
- ':host .icon-unlock': {
119
- opacity: 0.5,
120
- },
121
- ':host svg': {
122
- pointerEvents: 'none',
123
- },
124
- ':host > *:hover': {
125
- '--text-color': vars.handleHoverColor,
126
- background: vars.handleHoverBg,
127
- },
128
- };
129
- static snappedCoords(event, coords) {
130
- const { gridSize } = EditableRect;
131
- return EditableRect.snapToGrid || event.shiftKey
132
- ? coords.map((v) => Math.round(v / gridSize) * gridSize)
133
- : coords;
134
- }
135
- static snappedAngle(event, a) {
136
- const { angleSize } = EditableRect;
137
- return EditableRect.snapAngle || event.shiftKey
138
- ? Math.round(a / angleSize) * angleSize
139
- : a;
140
- }
141
- get locked() {
142
- const element = this.parentElement;
143
- if (element.style.inset) {
144
- return { left: true, top: true, bottom: true, right: true };
145
- }
146
- const right = element.style.right.match(/\d/) !== null;
147
- const left = !right || element.style.left.match(/\d/) !== null;
148
- const bottom = element.style.bottom.match(/\d/) !== null;
149
- const top = !bottom || element.style.top.match(/\d/) !== null;
150
- return { left, top, bottom, right };
151
- }
152
- set locked(locks) {
153
- const { bottom, right } = locks;
154
- let { left, top } = locks;
155
- const element = this.parentElement;
156
- const l = element.offsetLeft;
157
- const t = element.offsetTop;
158
- const w = element.offsetWidth;
159
- const h = element.offsetHeight;
160
- const r = element.offsetParent.offsetWidth - l - w;
161
- const b = element.offsetParent.offsetHeight - t - h;
162
- Object.assign(element.style, {
163
- left: '',
164
- right: '',
165
- top: '',
166
- bottom: '',
167
- width: '',
168
- height: '',
169
- });
170
- if (!right)
171
- left = true;
172
- if (!bottom)
173
- top = true;
174
- if (left)
175
- element.style.left = l + 'px';
176
- if (right)
177
- element.style.right = r + 'px';
178
- if (left && right) {
179
- element.style.width = 'auto';
180
- }
181
- else {
182
- element.style.width = w + 'px';
183
- }
184
- if (top)
185
- element.style.top = t + 'px';
186
- if (bottom)
187
- element.style.bottom = b + 'px';
188
- if (top && bottom) {
189
- element.style.height = 'auto';
190
- }
191
- else {
192
- element.style.height = h + 'px';
193
- }
194
- this.queueRender();
195
- }
196
- get coords() {
197
- const { top, left, right, bottom } = this.parentElement.style;
198
- return {
199
- top: parseFloat(top),
200
- left: parseFloat(left),
201
- right: parseFloat(right),
202
- bottom: parseFloat(bottom),
203
- };
204
- }
205
- get left() {
206
- return this.parentElement.offsetLeft;
207
- }
208
- get width() {
209
- return this.parentElement.offsetWidth;
210
- }
211
- get right() {
212
- return (this.parentElement.offsetParent.offsetWidth -
213
- (this.left + this.width));
214
- }
215
- get top() {
216
- return this.parentElement.offsetTop;
217
- }
218
- get height() {
219
- return this.parentElement.offsetHeight;
220
- }
221
- get bottom() {
222
- return (this.parentElement.offsetParent.offsetHeight -
223
- (this.top + this.height));
224
- }
225
- triggerChange = () => {
226
- this.parentElement.dispatchEvent(new Event('change', {
227
- bubbles: true,
228
- composed: true,
229
- }));
230
- };
231
- adjustPosition = (event) => {
232
- // this means there will be some positioning coordinate set!
233
- const { locked } = this;
234
- this.locked = locked;
235
- const target = this.parentElement;
236
- const { top, left, bottom, right } = this.coords;
237
- trackDrag(event, (dx, dy, dragEvent) => {
238
- ;
239
- [dx, dy] = EditableRect.snappedCoords(dragEvent, [dx, dy]);
240
- if (!isNaN(top)) {
241
- target.style.top = top + dy + 'px';
242
- }
243
- if (!isNaN(bottom)) {
244
- target.style.bottom = bottom - dy + 'px';
245
- }
246
- if (!isNaN(left)) {
247
- target.style.left = left + dx + 'px';
248
- }
249
- if (!isNaN(right)) {
250
- target.style.right = right - dx + 'px';
251
- }
252
- if (dragEvent.type === 'mouseup') {
253
- this.triggerChange();
254
- return true;
255
- }
256
- });
257
- };
258
- resize = (event) => {
259
- const target = this.parentElement;
260
- const { locked } = this;
261
- this.locked = Object.assign({
262
- left: true,
263
- top: true,
264
- right: true,
265
- bottom: true,
266
- });
267
- const [right, bottom] = [this.right, this.bottom];
268
- trackDrag(event, (dx, dy, dragEvent) => {
269
- let r = right - dx;
270
- let b = bottom - dy;
271
- [r, b] = EditableRect.snappedCoords(dragEvent, [r, b]);
272
- target.style.right = r + 'px';
273
- target.style.bottom = b + 'px';
274
- if (dragEvent.type === 'mouseup') {
275
- this.locked = locked;
276
- this.triggerChange();
277
- return true;
278
- }
279
- });
280
- };
281
- adjustSize = (event) => {
282
- const target = this.parentElement;
283
- const { locked } = this;
284
- const dimension = event.target.getAttribute('part');
285
- this.locked = Object.assign({
286
- left: true,
287
- right: true,
288
- top: true,
289
- bottom: true,
290
- });
291
- const original = this[dimension];
292
- trackDrag(event, (dx, dy, dragEvent) => {
293
- const [adjusted] = EditableRect.snappedCoords(dragEvent, [
294
- original +
295
- (['left', 'right'].includes(dimension) ? dx : dy) *
296
- (['right', 'bottom'].includes(dimension) ? -1 : 1),
297
- ]);
298
- target.style[dimension] = adjusted + 'px';
299
- if (dragEvent.type === 'mouseup') {
300
- this.locked = locked;
301
- this.triggerChange();
302
- return true;
303
- }
304
- });
305
- };
306
- get rect() {
307
- return this.parentElement.getBoundingClientRect();
308
- }
309
- get center() {
310
- const rect = this.parentElement.getBoundingClientRect();
311
- return {
312
- x: rect.x + rect.width * 0.5,
313
- y: rect.y + rect.height * 0.5,
314
- };
315
- }
316
- get element() {
317
- return this.parentElement;
318
- }
319
- adjustRotation = (event) => {
320
- const { center } = this;
321
- const { transformOrigin } = this.element.style;
322
- if (!transformOrigin) {
323
- this.element.style.transformOrigin = '50% 50%';
324
- }
325
- trackDrag(event, (_dx, _dy, dragEvent) => {
326
- const { clientX, clientY } = dragEvent;
327
- const x = clientX - center.x;
328
- const y = clientY - center.y;
329
- let alpha = y > 0 ? 90 : -90;
330
- if (x !== 0) {
331
- alpha = (Math.atan2(y, x) * 180) / Math.PI;
332
- }
333
- alpha = EditableRect.snappedAngle(dragEvent, alpha);
334
- if (alpha === 0) {
335
- this.element.style.transformOrigin = '';
336
- this.element.style.transform = '';
337
- }
338
- else {
339
- this.element.style.transform = `rotate(${alpha}deg)`;
340
- }
341
- this.triggerChange();
342
- return dragEvent.type === 'mouseup';
343
- });
344
- };
345
- toggleLock = (event) => {
346
- const { locked } = this;
347
- const which = event.target.title.split(' ')[1];
348
- locked[which] = !locked[which];
349
- this.locked = locked;
350
- this.queueRender();
351
- event.stopPropagation();
352
- event.preventDefault();
353
- };
354
- content = () => [
355
- div({
356
- part: 'move',
357
- style: { top: '50%', left: '50%', transform: 'translate(-50%,-50%)' },
358
- }, icons.move()),
359
- div({
360
- part: 'left',
361
- title: 'resize left',
362
- class: 'drag-size',
363
- style: { left: '-6px', width: '8px' },
364
- }),
365
- div({
366
- part: 'right',
367
- title: 'resize right',
368
- class: 'drag-size',
369
- style: { left: 'calc(100% - 2px)', width: '8px' },
370
- }),
371
- div({
372
- part: 'top',
373
- title: 'resize top',
374
- class: 'drag-size',
375
- style: { top: '-6px', height: '8px', cursor: 'ns-resize' },
376
- }),
377
- div({
378
- part: 'bottom',
379
- title: 'resize bottom',
380
- class: 'drag-size',
381
- style: { top: 'calc(100% - 2px)', height: '8px', cursor: 'ns-resize' },
382
- }),
383
- div({
384
- part: 'resize',
385
- style: { top: '100%', left: '100%' },
386
- }, icons.resize()),
387
- div({
388
- part: 'rotate',
389
- style: { top: '50%', right: '0' },
390
- }, icons.refreshCw()),
391
- div({
392
- part: 'lockLeft',
393
- title: 'lock left',
394
- style: { top: '50%', left: 0, transform: 'translate(-100%, -50%)' },
395
- }, icons.unlock(), icons.lock()),
396
- div({
397
- part: 'lockRight',
398
- title: 'lock right',
399
- style: { top: '50%', left: '100%', transform: 'translate(0%, -50%)' },
400
- }, icons.unlock(), icons.lock()),
401
- div({
402
- part: 'lockTop',
403
- title: 'lock top',
404
- style: { top: 0, left: '50%', transform: 'translate(-50%, -100%)' },
405
- }, icons.unlock(), icons.lock()),
406
- div({
407
- part: 'lockBottom',
408
- title: 'lock bottom',
409
- style: { top: '100%', left: '50%', transform: 'translate(-50%, 0%)' },
410
- }, icons.unlock(), icons.lock()),
411
- slot(),
412
- ];
413
- constructor() {
414
- super();
415
- this.initAttributes('rotationSnap', 'positionSnap');
416
- }
417
- connectedCallback() {
418
- super.connectedCallback();
419
- const { left, right, top, bottom, lockLeft, lockRight, lockTop, lockBottom, move, resize, rotate, } = this.parts;
420
- const PASSIVE = { passive: true };
421
- [left, right, top, bottom].forEach((elt) => {
422
- elt.addEventListener('mousedown', this.adjustSize, PASSIVE);
423
- elt.addEventListener('touchstart', this.adjustSize, PASSIVE);
424
- });
425
- [lockLeft, lockRight, lockTop, lockBottom].forEach((elt) => {
426
- elt.addEventListener('click', this.toggleLock);
427
- });
428
- resize.addEventListener('mousedown', this.resize, PASSIVE);
429
- move.addEventListener('mousedown', this.adjustPosition, PASSIVE);
430
- rotate.addEventListener('mousedown', this.adjustRotation, PASSIVE);
431
- resize.addEventListener('touchstart', this.resize, PASSIVE);
432
- move.addEventListener('touchstart', this.adjustPosition, PASSIVE);
433
- rotate.addEventListener('touchstart', this.adjustRotation, PASSIVE);
434
- }
435
- render() {
436
- super.render();
437
- if (!this.parentElement) {
438
- return;
439
- }
440
- const { lockLeft, lockRight, lockTop, lockBottom } = this.parts;
441
- const { left, right, top, bottom } = this.locked;
442
- lockLeft.toggleAttribute('locked', left);
443
- lockRight.toggleAttribute('locked', right);
444
- lockTop.toggleAttribute('locked', top);
445
- lockBottom.toggleAttribute('locked', bottom);
446
- }
447
- }
448
- export const editableRect = EditableRect.elementCreator({
449
- tag: 'xin-editable',
450
- });