godown 3.0.0-canary.6 → 3.0.0-canary.8

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 (168) hide show
  1. package/components/alert.d.ts +1 -1
  2. package/components/alert.d.ts.map +1 -1
  3. package/components/alert.js +8 -2
  4. package/components/alert.js.map +1 -1
  5. package/components/breath.js +2 -2
  6. package/components/breath.js.map +1 -1
  7. package/components/card.d.ts +1 -1
  8. package/components/card.d.ts.map +1 -1
  9. package/components/card.js +3 -4
  10. package/components/card.js.map +1 -1
  11. package/components/carousel.js +1 -1
  12. package/components/carousel.js.map +1 -1
  13. package/components/details.d.ts +1 -1
  14. package/components/details.js +1 -1
  15. package/components/dialog.d.ts +1 -1
  16. package/components/dialog.js +1 -1
  17. package/components/divider.d.ts +1 -1
  18. package/components/divider.js +1 -1
  19. package/components/input.d.ts +0 -1
  20. package/components/input.d.ts.map +1 -1
  21. package/components/input.js +0 -3
  22. package/components/input.js.map +1 -1
  23. package/components/layout.d.ts +1 -1
  24. package/components/layout.d.ts.map +1 -1
  25. package/components/layout.js +5 -6
  26. package/components/layout.js.map +1 -1
  27. package/components/progress.d.ts +1 -1
  28. package/components/progress.js +1 -1
  29. package/components/router.js +1 -1
  30. package/components/router.js.map +1 -1
  31. package/components/select.d.ts +1 -5
  32. package/components/select.d.ts.map +1 -1
  33. package/components/select.js +1 -8
  34. package/components/select.js.map +1 -1
  35. package/components/skeleton.d.ts.map +1 -1
  36. package/components/skeleton.js +1 -2
  37. package/components/skeleton.js.map +1 -1
  38. package/components/split.d.ts +1 -1
  39. package/components/split.d.ts.map +1 -1
  40. package/components/split.js +8 -2
  41. package/components/split.js.map +1 -1
  42. package/components/text.js +1 -1
  43. package/components/text.js.map +1 -1
  44. package/components/time.d.ts +0 -16
  45. package/components/time.d.ts.map +1 -1
  46. package/components/time.js +4 -57
  47. package/components/time.js.map +1 -1
  48. package/core/super-input.d.ts +0 -1
  49. package/core/super-input.d.ts.map +1 -1
  50. package/core/super-input.js +0 -3
  51. package/core/super-input.js.map +1 -1
  52. package/custom-elements.json +1 -1
  53. package/dev/components/alert.d.ts +1 -1
  54. package/dev/components/alert.d.ts.map +1 -1
  55. package/dev/components/alert.js +8 -2
  56. package/dev/components/alert.js.map +1 -1
  57. package/dev/components/breath.d.ts.map +1 -1
  58. package/dev/components/breath.js +2 -1
  59. package/dev/components/breath.js.map +1 -1
  60. package/dev/components/card.d.ts +1 -1
  61. package/dev/components/card.d.ts.map +1 -1
  62. package/dev/components/card.js +3 -4
  63. package/dev/components/card.js.map +1 -1
  64. package/dev/components/carousel.d.ts.map +1 -1
  65. package/dev/components/carousel.js +1 -0
  66. package/dev/components/carousel.js.map +1 -1
  67. package/dev/components/details.d.ts +1 -1
  68. package/dev/components/details.js +1 -1
  69. package/dev/components/dialog.d.ts +1 -1
  70. package/dev/components/dialog.js +1 -1
  71. package/dev/components/divider.d.ts +1 -1
  72. package/dev/components/divider.js +1 -1
  73. package/dev/components/input.d.ts +0 -1
  74. package/dev/components/input.d.ts.map +1 -1
  75. package/dev/components/input.js +0 -3
  76. package/dev/components/input.js.map +1 -1
  77. package/dev/components/layout.d.ts +1 -1
  78. package/dev/components/layout.d.ts.map +1 -1
  79. package/dev/components/layout.js +7 -6
  80. package/dev/components/layout.js.map +1 -1
  81. package/dev/components/progress.d.ts +1 -1
  82. package/dev/components/progress.js +1 -1
  83. package/dev/components/router.js +1 -1
  84. package/dev/components/router.js.map +1 -1
  85. package/dev/components/select.d.ts +1 -5
  86. package/dev/components/select.d.ts.map +1 -1
  87. package/dev/components/select.js +1 -8
  88. package/dev/components/select.js.map +1 -1
  89. package/dev/components/skeleton.d.ts.map +1 -1
  90. package/dev/components/skeleton.js +1 -2
  91. package/dev/components/skeleton.js.map +1 -1
  92. package/dev/components/split.d.ts +1 -1
  93. package/dev/components/split.d.ts.map +1 -1
  94. package/dev/components/split.js +9 -3
  95. package/dev/components/split.js.map +1 -1
  96. package/dev/components/text.js +3 -3
  97. package/dev/components/time.d.ts +0 -16
  98. package/dev/components/time.d.ts.map +1 -1
  99. package/dev/components/time.js +4 -57
  100. package/dev/components/time.js.map +1 -1
  101. package/dev/core/super-input.d.ts +0 -1
  102. package/dev/core/super-input.d.ts.map +1 -1
  103. package/dev/core/super-input.js +0 -3
  104. package/dev/core/super-input.js.map +1 -1
  105. package/package.json +9 -7
  106. package/src/alert.ts +11 -0
  107. package/src/avatar.ts +11 -0
  108. package/src/breath.ts +13 -0
  109. package/src/button.ts +11 -0
  110. package/src/card.ts +11 -0
  111. package/src/carousel.ts +11 -0
  112. package/src/components/alert.ts +282 -0
  113. package/src/components/avatar.ts +93 -0
  114. package/src/components/breath.ts +151 -0
  115. package/src/components/button.ts +276 -0
  116. package/src/components/card.ts +85 -0
  117. package/src/components/carousel.ts +166 -0
  118. package/src/components/details.ts +112 -0
  119. package/src/components/dialog.ts +160 -0
  120. package/src/components/divider.ts +44 -0
  121. package/src/components/dragbox.ts +126 -0
  122. package/src/components/flex.ts +65 -0
  123. package/src/components/form.ts +83 -0
  124. package/src/components/grid.ts +66 -0
  125. package/src/components/input.ts +71 -0
  126. package/src/components/layout.ts +84 -0
  127. package/src/components/link.ts +36 -0
  128. package/src/components/progress.ts +101 -0
  129. package/src/components/range.ts +409 -0
  130. package/src/components/rotate.ts +92 -0
  131. package/src/components/router.ts +264 -0
  132. package/src/components/select.ts +268 -0
  133. package/src/components/skeleton.ts +116 -0
  134. package/src/components/split.ts +190 -0
  135. package/src/components/switch.ts +176 -0
  136. package/src/components/text.ts +95 -0
  137. package/src/components/time.ts +77 -0
  138. package/src/components/tooltip.ts +118 -0
  139. package/src/components/typewriter.ts +147 -0
  140. package/src/core/global-style.ts +86 -0
  141. package/src/core/super-anchor.ts +52 -0
  142. package/src/core/super-input.ts +230 -0
  143. package/src/core/super-openable.ts +51 -0
  144. package/src/details.ts +11 -0
  145. package/src/dialog.ts +11 -0
  146. package/src/divider.ts +11 -0
  147. package/src/dragbox.ts +11 -0
  148. package/src/flex.ts +11 -0
  149. package/src/form.ts +11 -0
  150. package/src/grid.ts +11 -0
  151. package/src/index.ts +28 -0
  152. package/src/input.ts +13 -0
  153. package/src/layout.ts +12 -0
  154. package/src/link.ts +13 -0
  155. package/src/progress.ts +12 -0
  156. package/src/range.ts +13 -0
  157. package/src/rotate.ts +13 -0
  158. package/src/router.ts +12 -0
  159. package/src/select.ts +13 -0
  160. package/src/skeleton.ts +13 -0
  161. package/src/split.ts +13 -0
  162. package/src/switch.ts +13 -0
  163. package/src/text.ts +13 -0
  164. package/src/time.ts +13 -0
  165. package/src/tooltip.ts +13 -0
  166. package/src/typewriter.ts +11 -0
  167. package/vscode.html-custom-data.json +1 -1
  168. package/web-types.json +1 -1
@@ -0,0 +1,166 @@
1
+ import { godown } from "@godown/element/decorators/godown.js";
2
+ import { part } from "@godown/element/decorators/part.js";
3
+ import { styles } from "@godown/element/decorators/styles.js";
4
+ import { htmlSlot } from "@godown/element/directives/html-slot.js";
5
+ import { htmlStyle } from "@godown/element/directives/html-style.js";
6
+ import iconChevronLeft from "@godown/f7-icon/icons/chevron-left.js";
7
+ import iconChevronRight from "@godown/f7-icon/icons/chevron-right.js";
8
+ import { css, html } from "lit";
9
+ import { property } from "lit/decorators.js";
10
+
11
+ import { GlobalStyle } from "../core/global-style.js";
12
+
13
+ const protoName = "carousel";
14
+
15
+ /**
16
+ * {@linkcode Carousel} make the content display as a carousel.
17
+ *
18
+ * When this component is `firstUpdated`,
19
+ * clone the first and last element and make the matching element visible when switching index.
20
+ *
21
+ * Child elements should maintain the same size.
22
+ *
23
+ * If no width, it will be the width of the first element.
24
+ *
25
+ * @category display
26
+ */
27
+ @godown(protoName)
28
+ @styles(
29
+ css`
30
+ :host {
31
+ display: block;
32
+ transition: .3s;
33
+ }
34
+
35
+ [part="root"] {
36
+ overflow: hidden;
37
+ }
38
+
39
+ [part="root"],
40
+ [part="move-root"] {
41
+ height: 100%;
42
+ width: 100%;
43
+ display: flex;
44
+ position: relative;
45
+ transition: inherit;
46
+ }
47
+
48
+ [part="prev"],
49
+ [part="next"] {
50
+ height: 100%;
51
+ width: 1.5em;
52
+ z-index: 1;
53
+ position: absolute;
54
+ display: flex;
55
+ align-items: center;
56
+ justify-content: center;
57
+ user-select: none;
58
+ }
59
+
60
+ [part="prev"] {
61
+ left: 0;
62
+ }
63
+
64
+ [part="next"] {
65
+ right: 0;
66
+ }
67
+
68
+ slot::slotted(*) {
69
+ flex-shrink: 0 !important;
70
+ }
71
+ `,
72
+ )
73
+ class Carousel extends GlobalStyle {
74
+ /**
75
+ * The index of the element is displayed for the first time.
76
+ */
77
+ @property({ type: Number })
78
+ index = 0;
79
+ /**
80
+ * If autoChange > 0, the rotation will be automated.
81
+ */
82
+ @property({ type: Number })
83
+ autoChange = 0;
84
+ /**
85
+ * Element width.
86
+ */
87
+ @property()
88
+ width: string;
89
+
90
+ @part("move-root")
91
+ _moveRoot: HTMLElement;
92
+
93
+ intervalID: number;
94
+
95
+ _cloneFirst: HTMLElement | undefined;
96
+
97
+ _cloneLast: HTMLElement | undefined;
98
+
99
+ protected render() {
100
+ return [
101
+ html`<div part="root">
102
+ <i part="prev" @click="${this.prev}">${iconChevronLeft()}</i>
103
+ <div part="move-root" style="transform:${`translateX(-${this.index + 1}00%)`}">${htmlSlot()}</div>
104
+ <i part="next" @click="${this.next}">${iconChevronRight()}</i>
105
+ </div>`,
106
+ htmlStyle(`:host{width:${this.width};}`),
107
+ ];
108
+ }
109
+
110
+ protected async firstUpdated() {
111
+ await this.updateComplete;
112
+
113
+ if (this.children.length) {
114
+ this.width ||= `${(this.firstElementChild as HTMLElement).offsetWidth}px`;
115
+
116
+ this._cloneFirst?.remove();
117
+ this._cloneLast?.remove();
118
+ this._cloneLast = this.firstElementChild.cloneNode(true) as HTMLElement;
119
+ this._cloneFirst = this.lastElementChild.cloneNode(true) as HTMLElement;
120
+ this.appendChild(this._cloneLast);
121
+ this.insertBefore(this._cloneFirst, this.firstElementChild);
122
+ this.show(this.index);
123
+ }
124
+ if (this.autoChange) {
125
+ this.intervalID = window.setInterval(() => {
126
+ this.next();
127
+ }, this.autoChange);
128
+ }
129
+ }
130
+
131
+ disconnectedCallback() {
132
+ clearInterval(this.intervalID);
133
+ }
134
+
135
+ show(i: number) {
136
+ this.index = i;
137
+ }
138
+
139
+ next() {
140
+ if (this.index === this.childElementCount - 3) {
141
+ this._doTranslateX("0", true);
142
+ this.show(0);
143
+ } else {
144
+ this.show(this.index + 1);
145
+ }
146
+ }
147
+
148
+ prev() {
149
+ if (this.index === 0) {
150
+ this._doTranslateX(`-${this.childElementCount - 1}00%`, true);
151
+ this.show(this.children.length - 3);
152
+ } else {
153
+ this.show(this.index - 1);
154
+ }
155
+ }
156
+
157
+ protected _doTranslateX(xValue: string, noTransition?: boolean) {
158
+ this._moveRoot.style.transform = `translateX(${xValue})`;
159
+ if (noTransition) {
160
+ this._moveRoot.style.transition = `none`;
161
+ }
162
+ this._moveRoot.getBoundingClientRect();
163
+ }
164
+ }
165
+
166
+ export default Carousel;
@@ -0,0 +1,112 @@
1
+ import { godown } from "@godown/element/decorators/godown.js";
2
+ import { styles } from "@godown/element/decorators/styles.js";
3
+ import { htmlSlot } from "@godown/element/directives/html-slot.js";
4
+ import svgCaretDown from "@godown/f7-icon/icons/chevron-down.js";
5
+ import { css, html } from "lit";
6
+ import { property, query } from "lit/decorators.js";
7
+
8
+ import { scopePrefix } from "../core/global-style.js";
9
+ import SuperOpenable from "../core/super-openable.js";
10
+
11
+ const protoName = "details";
12
+
13
+ const cssScope = scopePrefix(protoName);
14
+
15
+ /**
16
+ * {@linkcode Details} similar to `<details>`.
17
+ *
18
+ * @category display
19
+ */
20
+ @godown(protoName)
21
+ @styles(
22
+ css`
23
+ :host {
24
+ ${cssScope}--icon-deg-open: 0deg;
25
+ ${cssScope}--icon-deg-close: 90deg;
26
+ ${cssScope}--icon-deg: 0deg;
27
+ ${cssScope}--icon-space: 0.3em;
28
+ ${cssScope}--summary-direction: row;
29
+ ${cssScope}--transition: .3s;
30
+ height: fit-content;
31
+ display: block;
32
+ transition: var(${cssScope}--transition);
33
+ }
34
+
35
+ dl {
36
+ height: 100%;
37
+ position: relative;
38
+ overflow: hidden;
39
+ }
40
+
41
+ dt {
42
+ height: 100%;
43
+ display: flex;
44
+ flex-wrap: nowrap;
45
+ justify-content: space-between;
46
+ background: inherit;
47
+ align-items: center;
48
+ flex-direction: var(${cssScope}--summary-direction);
49
+ }
50
+
51
+ dd {
52
+ display: grid;
53
+ overflow: hidden;
54
+ grid-template-rows: 0fr;
55
+ transition: var(${cssScope}--transition);
56
+ transition-property: grid-template-rows;
57
+ }
58
+
59
+ i {
60
+ display: flex;
61
+ backface-visibility: hidden;
62
+ padding: var(${cssScope}--icon-space);
63
+ transition: var(${cssScope}--transition);
64
+ transform: rotate(var(${cssScope}--icon-deg));
65
+ }
66
+
67
+ :host([open]) dd {
68
+ grid-template-rows: 1fr;
69
+ }
70
+
71
+ :host([float]) dd {
72
+ top: 100%;
73
+ position: absolute;
74
+ }
75
+
76
+ i {
77
+ transform: rotate(var(${cssScope}--icon-deg-close));
78
+ }
79
+ :host([open]) i {
80
+ transform: rotate(var(${cssScope}--icon-deg-open));
81
+ }
82
+ `,
83
+ )
84
+ class Details extends SuperOpenable {
85
+ /**
86
+ * If it is true, the summary event scope will fill the element.
87
+ */
88
+ @property({ type: Boolean })
89
+ fill = false;
90
+ /**
91
+ * Summary text.
92
+ */
93
+ @property()
94
+ summary = "";
95
+
96
+ @query("dd")
97
+ _dd: HTMLDataListElement;
98
+
99
+ protected render() {
100
+ return html`<dl part="root">
101
+ <dt part="title" @click="${this._handelClick}">
102
+ <span part="summary">${this.summary || htmlSlot("summary")} </span>
103
+ <span><i part="icon">${svgCaretDown()}</i></span>
104
+ </dt>
105
+ <dd part="details" @click=${this.fill ? () => this.toggle() : null}>
106
+ <div style="min-height: 0;">${htmlSlot()}</div>
107
+ </dd>
108
+ </dl>`;
109
+ }
110
+ }
111
+
112
+ export default Details;
@@ -0,0 +1,160 @@
1
+ import { type HandlerEvent } from "@godown/element";
2
+ import { godown } from "@godown/element/decorators/godown.js";
3
+ import { styles } from "@godown/element/decorators/styles.js";
4
+ import { htmlSlot } from "@godown/element/directives/html-slot.js";
5
+ import { css, html, type PropertyValues } from "lit";
6
+ import { property } from "lit/decorators.js";
7
+
8
+ import { cssGlobalVars, scopePrefix } from "../core/global-style.js";
9
+ import SuperOpenable, { type Direction9 } from "../core/super-openable.js";
10
+
11
+ const protoName = "dialog";
12
+ const cssScope = scopePrefix(protoName);
13
+
14
+ /**
15
+ * {@linkcode Dialog} similar to `<dialog>`.
16
+ *
17
+ * Like dialog, it listens for submit events and closes itself when the target method is "dialog".
18
+ *
19
+ * It listens for the keydown event and also closes itself when the {@linkcode key} contained in the key is pressed
20
+ *
21
+ * @category feedback
22
+ */
23
+ @godown(protoName)
24
+ @styles(
25
+ css`
26
+ :host {
27
+ ${cssScope}--background: none;
28
+ ${cssScope}--background-modal: var(${cssGlobalVars.background});
29
+ ${cssScope}--opacity-modal: 0.2;
30
+ background: var(${cssScope}--background);
31
+ pointer-events: none;
32
+ visibility: hidden;
33
+ position: fixed;
34
+ z-index: 1;
35
+ inset:0;
36
+ }
37
+
38
+ :host([open]) {
39
+ visibility: visible;
40
+ }
41
+
42
+ :host([open][modal]) [part="modal"] {
43
+ pointer-events: all;
44
+ visibility: visible;
45
+ opacity: var(${cssScope}--opacity-modal);
46
+
47
+ }
48
+
49
+ [part="modal"] {
50
+ visibility: hidden;
51
+ opacity: 0;
52
+ width: 100%;
53
+ height: 100%;
54
+ position: absolute;
55
+ background: var(${cssScope}--background-modal);
56
+ }
57
+
58
+ [part="root"] {
59
+ width: 100%;
60
+ height: 100%;
61
+ display: flex;
62
+ position: relative;
63
+ align-items: center;
64
+ justify-content: center;
65
+ }
66
+
67
+ [direction] {
68
+ pointer-events: all;
69
+ position: absolute;
70
+ }
71
+
72
+ [direction^="top"] {
73
+ top: 0;
74
+ }
75
+
76
+ [direction^="bottom"] {
77
+ bottom: 0;
78
+ }
79
+
80
+ [direction$="right"] {
81
+ right: 0%;
82
+ }
83
+
84
+ [direction$="left"] {
85
+ left: 0%;
86
+ }
87
+ `,
88
+ )
89
+ class Dialog extends SuperOpenable {
90
+ @property()
91
+ direction: Direction9 = "center";
92
+ /**
93
+ * Enable modal, blocking event penetration.
94
+ */
95
+ @property({ type: Boolean, reflect: true })
96
+ modal = false;
97
+ /**
98
+ * Close key.
99
+ */
100
+ @property()
101
+ key = "Escape";
102
+
103
+ private _modalInvoke: boolean;
104
+
105
+ protected render() {
106
+ return html`<div part="root">
107
+ <div part="modal"></div>
108
+ <div part="container" direction="${this.direction}">${htmlSlot()}</div>
109
+ </div>`;
110
+ }
111
+
112
+ showModal() {
113
+ if (!this.modal) {
114
+ this.modal = true;
115
+ this._modalInvoke = true;
116
+ }
117
+ this.show();
118
+ }
119
+
120
+ private _submitEvent: EventListenerOrEventListenerObject;
121
+ private _keydownEvent: EventListenerOrEventListenerObject;
122
+
123
+ protected updated(changedProperties: PropertyValues) {
124
+ if (changedProperties.has("open")) {
125
+ if (this.open) {
126
+ this._submitEvent = this.events.add(this, "submit", this._handelSubmit);
127
+ if (this.key) {
128
+ this._keydownEvent = this.events.add(document, "keydown", this._handleKeydown.bind(this));
129
+ }
130
+ } else {
131
+ this.events.remove(this, "submit", this._submitEvent);
132
+ this.events.remove(document, "keydown", this._keydownEvent);
133
+ }
134
+ }
135
+ }
136
+
137
+ protected _handleKeydown(e: KeyboardEvent) {
138
+ e.preventDefault();
139
+ const keys = this.key.split(/[\s,]/);
140
+ if (keys.includes(e.key) || keys.includes(e.code)) {
141
+ this.close();
142
+ }
143
+ }
144
+
145
+ protected _handelSubmit(e: HandlerEvent<HTMLFormElement>) {
146
+ if (e.target.method === "dialog") {
147
+ this.close();
148
+ }
149
+ }
150
+
151
+ close() {
152
+ if (this._modalInvoke) {
153
+ this.modal = false;
154
+ this._modalInvoke = false;
155
+ }
156
+ this.open = false;
157
+ }
158
+ }
159
+
160
+ export default Dialog;
@@ -0,0 +1,44 @@
1
+ import { godown, styles } from "@godown/element/decorators/index.js";
2
+ import { css } from "lit";
3
+ import { property } from "lit/decorators.js";
4
+
5
+ import { GlobalStyle } from "../core/global-style.js";
6
+
7
+ const protoName = "divider";
8
+
9
+ /**
10
+ * {@linkcode Divider} similar to `<hr>`.
11
+ *
12
+ * This component does not render content.
13
+ *
14
+ * @category layout
15
+ */
16
+ @godown(protoName)
17
+ @styles(
18
+ css`
19
+ :host{
20
+ width: 100%;
21
+ height: .05em;
22
+ margin: auto;
23
+ display: block;
24
+ background: currentColor;
25
+ }
26
+ :host([vertical]) {
27
+ width: .05em;
28
+ height: max(1em, 100%);
29
+ }
30
+ `,
31
+ )
32
+ class Divider extends GlobalStyle {
33
+ /**
34
+ * Vertical display.
35
+ */
36
+ @property({ type: Boolean, reflect: true })
37
+ vertical = false;
38
+
39
+ connectedCallback() {
40
+ this.createRenderRoot();
41
+ }
42
+ }
43
+
44
+ export default Divider;
@@ -0,0 +1,126 @@
1
+ import { godown } from "@godown/element/decorators/godown.js";
2
+ import { styles } from "@godown/element/decorators/styles.js";
3
+ import { htmlSlot } from "@godown/element/directives/html-slot.js";
4
+ import { EventListenerFunc } from "@godown/element/tools/events.js";
5
+ import { css, html } from "lit";
6
+ import { property } from "lit/decorators.js";
7
+
8
+ import { GlobalStyle } from "../core/global-style.js";
9
+
10
+ const protoName = "dragbox";
11
+
12
+ /**
13
+ * {@linkcode Dragbox} does not extend beyond the range of {@linkcode Dragbox.offsetsWidth} and {@linkcode Dragbox.offsetsHeight}.
14
+ *
15
+ * @category wrapper
16
+ */
17
+ @godown(protoName)
18
+ @styles(
19
+ css`
20
+ :host {
21
+ position: absolute;
22
+ display: block;
23
+ }
24
+
25
+ :host(:active) {
26
+ -webkit-user-select: none;
27
+ user-select: none;
28
+ }
29
+ `,
30
+ )
31
+ class Dragbox extends GlobalStyle {
32
+ /**
33
+ * Width of (`this.offsetParent` or `document.body`).
34
+ */
35
+ get offsetsWidth(): number {
36
+ return this.offsetParent?.clientWidth ?? document.body.offsetWidth;
37
+ }
38
+
39
+ /**
40
+ * Height of (`this.offsetParent` or `document.body`).
41
+ */
42
+ get offsetsHeight(): number {
43
+ return this.offsetParent?.clientHeight ?? document.body.offsetHeight;
44
+ }
45
+
46
+ drag: boolean;
47
+ t: number;
48
+ l: number;
49
+ cx: number;
50
+ cy: number;
51
+
52
+ /**
53
+ * Position x.
54
+ */
55
+ @property()
56
+ x = "auto";
57
+ /**
58
+ * Position y.
59
+ */
60
+ @property()
61
+ y = "auto";
62
+
63
+ protected render() {
64
+ return html`<div @mousedown="${this._handleDragStart}" @mouseup="${this._handleDragEnd}">${htmlSlot()}</div>`;
65
+ }
66
+
67
+ protected firstUpdated() {
68
+ this.reset();
69
+ }
70
+
71
+ protected _handleDragStart(e: MouseEvent) {
72
+ this.cx = e.clientX;
73
+ this.cy = e.clientY;
74
+ this.t = this.offsetTop;
75
+ this.l = this.offsetLeft;
76
+ this.drag = true;
77
+ this._handleMouseMove = this.events.add(document, "mousemove", this._handleDrag.bind(this));
78
+ this._handleMouseLeave = this.events.add(document, "mouseleave", this._handleDragEnd.bind(this));
79
+ }
80
+
81
+ _handleMouseMove: EventListenerFunc;
82
+ _handleMouseLeave: EventListenerFunc;
83
+
84
+ protected _handleDragEnd() {
85
+ this.drag = false;
86
+ this.events.remove(document, "mousemove", this._handleMouseMove);
87
+ this.events.remove(document, "mouseleave", this._handleMouseLeave);
88
+ }
89
+
90
+ protected _handleDrag(e: MouseEvent) {
91
+ if (!this.drag) {
92
+ return;
93
+ }
94
+ const nl = e.clientX - (this.cx - this.l);
95
+ const nt = e.clientY - (this.cy - this.t);
96
+ const { style, offsetsWidth, offsetsHeight, offsetWidth, offsetHeight } = this;
97
+ if (nl < 0) {
98
+ style.left = "0";
99
+ } else if (nl < offsetsWidth - offsetWidth) {
100
+ style.left = `${nl}px`;
101
+ } else {
102
+ style.left = `${offsetsWidth - offsetWidth}"px"`;
103
+ }
104
+ if (nt < 0) {
105
+ style.top = "0";
106
+ } else if (nt < offsetsHeight - offsetHeight) {
107
+ style.top = `${nt}px`;
108
+ } else {
109
+ style.top = `${offsetsHeight - offsetHeight}px`;
110
+ }
111
+ }
112
+
113
+ reset() {
114
+ const { x, y, style, offsetsWidth, offsetsHeight, offsetWidth, offsetHeight, offsetLeft, offsetTop } = this;
115
+ style.left = x || "0";
116
+ style.top = y || "0";
117
+ if (offsetLeft > offsetsWidth - offsetWidth) {
118
+ style.left = `${offsetsWidth - offsetWidth}px`;
119
+ }
120
+ if (offsetTop > offsetsHeight - offsetHeight) {
121
+ style.top = `${offsetsHeight - offsetHeight}px`;
122
+ }
123
+ }
124
+ }
125
+
126
+ export default Dragbox;
@@ -0,0 +1,65 @@
1
+ import { godown } from "@godown/element/decorators/godown.js";
2
+ import { styles } from "@godown/element/decorators/styles.js";
3
+ import { htmlSlot } from "@godown/element/directives/html-slot.js";
4
+ import { htmlStyle } from "@godown/element/directives/html-style.js";
5
+ import { joinRules } from "@godown/element/tools/css.js";
6
+ import { css } from "lit";
7
+ import { property } from "lit/decorators.js";
8
+
9
+ import { GlobalStyle } from "../core/global-style.js";
10
+
11
+ const protoName = "flex";
12
+
13
+ /**
14
+ * {@linkcode Flex} provides flex layout.
15
+ *
16
+ * @category layout
17
+ */
18
+ @godown(protoName)
19
+ @styles(css`:host {display:flex;}`)
20
+ class Flex extends GlobalStyle {
21
+ /**
22
+ * CSS property `flex-flow` (`flex-direction flex-wrap`).
23
+ */
24
+ @property({ attribute: "flex-flow" })
25
+ flexFlow: string;
26
+ /**
27
+ * CSS property `gap`.
28
+ */
29
+ @property()
30
+ gap: string;
31
+ /**
32
+ * CSS property `justify-content`.
33
+ */
34
+ @property()
35
+ content: string;
36
+ /**
37
+ * CSS property `align-items`.
38
+ */
39
+ @property()
40
+ items: string;
41
+ /**
42
+ * If true, set flex-direction to "column".
43
+ */
44
+ @property({ type: Boolean })
45
+ vertical: boolean;
46
+
47
+ protected render() {
48
+ return [
49
+ htmlSlot(),
50
+ htmlStyle(
51
+ joinRules({
52
+ ":host": {
53
+ gap: this.gap,
54
+ "flex-flow": this.flexFlow,
55
+ "flex-direction": this.vertical && "column",
56
+ "align-items": this.items,
57
+ "justify-content": this.content,
58
+ },
59
+ }),
60
+ ),
61
+ ];
62
+ }
63
+ }
64
+
65
+ export default Flex;