@operato/app 1.0.0-alpha.19 → 1.0.0-alpha.21

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.
@@ -1,341 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import '@operato/i18n/ox-i18n.js'
6
- import '@polymer/paper-dropdown-menu/paper-dropdown-menu'
7
- import '@polymer/paper-listbox/paper-listbox'
8
- import '@polymer/paper-item/paper-item'
9
- import '@operato/input/ox-input-angle.js'
10
- import '@operato/input/ox-input-color-stops.js'
11
-
12
- import { ColorStop, OxFormField } from '@operato/input'
13
- import { css, html } from 'lit'
14
- import { customElement, property } from 'lit/decorators.js'
15
-
16
- export type GradientOption = {
17
- type: 'linear' | 'radial'
18
- rotation: number
19
- direction?:
20
- | 'left-to-right'
21
- | 'lefttop-to-rightbottom'
22
- | 'top-to-bottom'
23
- | 'righttop-to-leftbottom'
24
- | 'right-to-left'
25
- | 'rightbottom-to-lefttop'
26
- | 'bottom-to-top'
27
- | 'leftbottom-to-righttop'
28
- | 'left-to-right'
29
- | 'center-to-corner'
30
- center?: 'center' | 'left-top' | 'right-top' | 'right-bottom' | 'left-bottom'
31
- colorStops?: ColorStop[]
32
- }
33
-
34
- @customElement('ox-input-color-gradient')
35
- export class OxInputColorGradient extends OxFormField {
36
- static styles = css`
37
- :host {
38
- display: grid;
39
-
40
- grid-template-columns: repeat(10, 1fr);
41
- grid-gap: 5px;
42
- grid-auto-rows: minmax(24px, auto);
43
-
44
- align-items: center;
45
- }
46
-
47
- :host > * {
48
- align-self: stretch;
49
- }
50
-
51
- :host > label {
52
- grid-column: span 2;
53
- text-align: right;
54
- text-transform: capitalize;
55
- align-self: center;
56
- }
57
-
58
- :host > .icon-only-label {
59
- grid-column: span 1;
60
- }
61
-
62
- :host > input,
63
- :host > [editors] {
64
- grid-column: span 8;
65
- }
66
-
67
- :host > select {
68
- grid-column: span 4;
69
- height: 100%;
70
- border: 1px solid rgba(0, 0, 0, 0.2);
71
- }
72
-
73
- :host > ox-input-angle {
74
- grid-column: span 3;
75
- }
76
-
77
- ox-input-color-stops {
78
- grid-column: span 10;
79
- }
80
-
81
- .host > input[type='checkbox'] {
82
- grid-column: 3 / 4;
83
- }
84
-
85
- .host > input[type='checkbox'] ~ label {
86
- grid-column: span 7;
87
- text-align: left;
88
- }
89
-
90
- [editors] > :not([active-selector]) {
91
- display: none;
92
- }
93
-
94
- [gradient-direction] {
95
- overflow: hidden;
96
- max-width: 210px;
97
- }
98
-
99
- [gradient-direction] paper-item {
100
- background: url(/assets/images/icon-editor-gradient-direction.png) 50% 0 no-repeat;
101
- min-height: 32px;
102
- padding: 3px 5px;
103
- width: 30px;
104
- float: left;
105
- }
106
-
107
- [gradient-direction] [name='lefttop-to-rightbottom'] {
108
- background-position: 50% 4px;
109
- }
110
-
111
- [gradient-direction] [name='left-top'] {
112
- background-position: 50% 4px;
113
- }
114
-
115
- [gradient-direction] [name='top-to-bottom'] {
116
- background-position: 50% -46px;
117
- }
118
-
119
- [gradient-direction] [name='righttop-to-leftbottom'] {
120
- background-position: 50% -96px;
121
- }
122
-
123
- [gradient-direction] [name='right-top'] {
124
- background-position: 50% -96px;
125
- }
126
-
127
- [gradient-direction] [name='right-to-left'] {
128
- background-position: 50% -146px;
129
- }
130
-
131
- [gradient-direction] [name='rightbottom-to-lefttop'] {
132
- background-position: 50% -196px;
133
- }
134
-
135
- [gradient-direction] [name='right-bottom'] {
136
- background-position: 50% -196px;
137
- }
138
-
139
- [gradient-direction] [name='bottom-to-top'] {
140
- background-position: 50% -246px;
141
- }
142
-
143
- [gradient-direction] [name='leftbottom-to-righttop'] {
144
- background-position: 50% -296px;
145
- }
146
-
147
- [gradient-direction] [name='left-bottom'] {
148
- background-position: 50% -296px;
149
- }
150
-
151
- [gradient-direction] [name='left-to-right'] {
152
- background-position: 50% -346px;
153
- }
154
-
155
- [gradient-direction] [name='center-to-corner'] {
156
- background-position: 50% -396px;
157
- }
158
-
159
- [gradient-direction] [name='center'] {
160
- background-position: 50% -396px;
161
- }
162
-
163
- [gradient-direction] paper-item[focused] {
164
- background-color: rgba(255, 246, 143, 0.5);
165
- }
166
-
167
- .icon-only-label {
168
- top: 0 !important;
169
- width: 30px !important;
170
- height: 24px;
171
- background: url(/assets/images/icon-properties-label.png) no-repeat;
172
- }
173
-
174
- .icon-only-label.color {
175
- background-position: 70% -198px;
176
- }
177
- `
178
-
179
- @property({ type: Object }) value: GradientOption = {
180
- type: 'linear',
181
- direction: 'left-to-right',
182
- rotation: 0
183
- }
184
-
185
- firstUpdated() {
186
- this.renderRoot.addEventListener('change', this._onChange.bind(this))
187
- }
188
-
189
- _onChange(e: Event) {
190
- var element = e.target as HTMLElement & { type: string }
191
- var key = element.getAttribute('value-key')
192
-
193
- if (!key) {
194
- return
195
- }
196
-
197
- var value
198
-
199
- switch (element.tagName) {
200
- case 'INPUT':
201
- switch (element.type) {
202
- case 'checkbox':
203
- value = (element as HTMLInputElement).checked
204
- break
205
- case 'number':
206
- value = Number((element as HTMLInputElement).value) || 0
207
- break
208
- case 'text':
209
- value = String((element as HTMLInputElement).value)
210
- }
211
- break
212
-
213
- case 'PAPER-BUTTON':
214
- value = (element as any).active
215
- break
216
-
217
- case 'PAPER-LISTBOX':
218
- value = (element as any).selected
219
- break
220
-
221
- default:
222
- value = (element as HTMLInputElement).value
223
- break
224
- }
225
-
226
- if (key === 'rotation') {
227
- this.value = {
228
- ...this.value,
229
- rotation: value,
230
- direction: undefined
231
- }
232
- } else if (key === 'direction') {
233
- if (value) {
234
- this.value = {
235
- ...this.value,
236
- direction: value,
237
- rotation: this._convertDirectionToRotation(value)
238
- }
239
- }
240
- } else {
241
- this.value = {
242
- ...this.value,
243
- [key]: value
244
- }
245
- }
246
-
247
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
248
- }
249
-
250
- render() {
251
- var selector = (this.value && this.value.type) || 'linear'
252
- var value = this.value || {}
253
-
254
- return html`
255
- <label> <ox-i18n msgid="label.type">type</ox-i18n> </label>
256
- <select value-key="type" .value=${value.type || 'linear'}>
257
- <option>linear</option>
258
- <option>radial</option>
259
- </select>
260
-
261
- <label class="icon-only-label color"></label>
262
- <ox-input-angle value-key="rotation" .value=${value.rotation || 0}> </ox-input-angle>
263
-
264
- <label> <ox-i18n msgid="label.direction">direction</ox-i18n> </label>
265
- <div editors>
266
- <paper-dropdown-menu no-label-float="true" ?active-selector=${selector == 'linear'} .value=${value.direction}>
267
- <paper-listbox
268
- @selected-changed=${(e: Event) => this._onChange(e)}
269
- value-key="direction"
270
- slot="dropdown-content"
271
- gradient-direction
272
- .selected=${value.direction}
273
- attr-for-selected="name"
274
- >
275
- <paper-item name="lefttop-to-rightbottom"></paper-item>
276
- <paper-item name="top-to-bottom"></paper-item>
277
- <paper-item name="righttop-to-leftbottom"></paper-item>
278
- <paper-item name="right-to-left"></paper-item>
279
- <paper-item name="rightbottom-to-lefttop"></paper-item>
280
- <paper-item name="bottom-to-top"></paper-item>
281
- <paper-item name="leftbottom-to-righttop"></paper-item>
282
- <paper-item name="left-to-right"></paper-item>
283
- <paper-item name="center-to-corner"></paper-item>
284
- </paper-listbox>
285
- </paper-dropdown-menu>
286
-
287
- <paper-dropdown-menu no-label-float="true" ?active-selector=${selector == 'radial'} .value=${value.center}>
288
- <paper-listbox
289
- @selected-changed=${(e: Event) => this._onChange(e)}
290
- value-key="center"
291
- slot="dropdown-content"
292
- gradient-direction
293
- .selected=${value.center || 'center'}
294
- attr-for-selected="name"
295
- >
296
- <paper-item name="center"></paper-item>
297
- <paper-item name="left-top"></paper-item>
298
- <paper-item name="right-top"></paper-item>
299
- <paper-item name="right-bottom"></paper-item>
300
- <paper-item name="left-bottom"></paper-item>
301
- </paper-listbox>
302
- </paper-dropdown-menu>
303
- </div>
304
-
305
- <ox-input-color-stops value-key="colorStops" type="gradient" .value=${value.colorStops}> </ox-input-color-stops>
306
- `
307
- }
308
-
309
- _convertDirectionToRotation(direction: string): number {
310
- var rotation
311
- switch (direction) {
312
- case 'lefttop-to-rightbottom':
313
- rotation = 45
314
- break
315
- case 'top-to-bottom':
316
- rotation = 90
317
- break
318
- case 'righttop-to-leftbottom':
319
- rotation = 135
320
- break
321
- case 'right-to-left':
322
- rotation = 180
323
- break
324
- case 'rightbottom-to-lefttop':
325
- rotation = 215
326
- break
327
- case 'bottom-to-top':
328
- rotation = 270
329
- break
330
- case 'leftbottom-to-righttop':
331
- rotation = 315
332
- break
333
- case 'left-to-right':
334
- default:
335
- rotation = 0
336
- break
337
- }
338
-
339
- return (rotation / 360) * Math.PI * 2
340
- }
341
- }