nice editor there
This commit is contained in:
parent
216951a6ea
commit
76c7e7b8a6
17 changed files with 130 additions and 80 deletions
|
|
@ -81,20 +81,7 @@ class UiInspectorField extends UiWidget {
|
|||
|
||||
this.container.appendChild(wrapper)
|
||||
|
||||
}
|
||||
|
||||
if (this.name.includes('color')) {
|
||||
|
||||
let style = window.getComputedStyle(this.widget.container)
|
||||
let val = chroma(style.getPropertyValue('--' + this.name.replace(/([A-Z])/g, (a,s)=>'-' + s.toLowerCase())).trim()).hex('rgb')
|
||||
|
||||
let picker = html`<input class="osc-inspector-color" type="color" name="${this.name}" value="${val}"/>`
|
||||
|
||||
this.container.appendChild(picker)
|
||||
|
||||
}
|
||||
|
||||
if (this.default.type.includes('boolean')) {
|
||||
} else if (this.default.type.includes('boolean')) {
|
||||
|
||||
let toggle = html`
|
||||
<osc-inspector-checkbox name="${this.name}" class="${this.widget.getProp(this.name) ? 'on' : ''}">
|
||||
|
|
@ -104,6 +91,30 @@ class UiInspectorField extends UiWidget {
|
|||
|
||||
this.container.appendChild(toggle)
|
||||
|
||||
} else if (this.name.includes('color')) {
|
||||
|
||||
let style = window.getComputedStyle(this.widget.container),
|
||||
cssName = this.widget.constructor.cssVariables.find(x=>x.js === this.name).css,
|
||||
val = '#000'
|
||||
|
||||
try {
|
||||
val = chroma(style.getPropertyValue('--' + this.name.replace(/([A-Z])/g, (a,s)=>'-' + s.toLowerCase())).trim()).hex('rgb')
|
||||
} catch(e) {console.log(e)}
|
||||
|
||||
let picker = html`<input class="osc-inspector-color" type="color" name="${this.name}" value="${val}"/>`
|
||||
|
||||
this.container.appendChild(picker)
|
||||
|
||||
} else if (stringValue === 'auto' && this.widget.constructor.cssVariables.some(x=>x.js === this.name)) {
|
||||
|
||||
let style = window.getComputedStyle(this.widget.container),
|
||||
data = this.widget.constructor.cssVariables.find(x=>x.js === this.name),
|
||||
val = style.getPropertyValue(data.css).trim()
|
||||
|
||||
if (data.toJs) val = data.toJs(val)
|
||||
|
||||
this.container.appendChild(html`<div class="computed-value">${val}</div>`)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Menu extends Widget {
|
|||
]},
|
||||
weights: {type: 'array', value: '', help: [
|
||||
'`Array` of `number` defining the weights of each value in `values`',
|
||||
'Ignored when `grid` is `true`'
|
||||
'Ignored when `mode` is `grid`'
|
||||
]}
|
||||
|
||||
})
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ var Widget = require('../common/widget'),
|
|||
html = require('nanohtml'),
|
||||
raw = require('nanohtml/raw')
|
||||
|
||||
module.exports = class Switch extends Widget {
|
||||
class Switch extends Widget {
|
||||
|
||||
static description() {
|
||||
|
||||
|
|
@ -29,6 +29,7 @@ module.exports = class Switch extends Widget {
|
|||
'- `slide`: same as `tap` but allows sliding between values',
|
||||
'- `click`: activates upon click only and allows further scrolling',
|
||||
]},
|
||||
colorTextOn: {type: 'string', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'},
|
||||
|
||||
})
|
||||
|
||||
|
|
@ -126,4 +127,11 @@ module.exports = class Switch extends Widget {
|
|||
if (options.sync) this.changed(options)
|
||||
}
|
||||
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
Switch.cssVariables = Switch.prototype.constructor.cssVariables.concat(
|
||||
{js: 'colorTextOn', css: '--color-text-on'}
|
||||
)
|
||||
|
||||
module.exports = Switch
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class Toggle extends Widget {
|
|||
|
||||
return super.defaults({
|
||||
|
||||
|
||||
_toggle: 'toggle',
|
||||
|
||||
on: {type: '*', value: 1, help: [
|
||||
|
|
@ -31,6 +32,7 @@ class Toggle extends Widget {
|
|||
'- `tap` (no release)'
|
||||
]},
|
||||
doubleTap: {type: 'boolean', value: false, help: 'Set to `true` to make the button require a double tap to be pushed instead of a single tap'},
|
||||
colorTextOn: {type: 'string', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'},
|
||||
|
||||
})
|
||||
|
||||
|
|
@ -149,6 +151,10 @@ class Toggle extends Widget {
|
|||
|
||||
}
|
||||
|
||||
Toggle.cssVariables = Toggle.prototype.constructor.cssVariables.concat(
|
||||
{js: 'colorTextOn', css: '--color-text-on'}
|
||||
)
|
||||
|
||||
Toggle.dynamicProps = Toggle.prototype.constructor.dynamicProps.concat(
|
||||
'on',
|
||||
'off',
|
||||
|
|
|
|||
|
|
@ -133,19 +133,13 @@ class Canvas extends Widget {
|
|||
|
||||
style = style || window.getComputedStyle(this.canvas)
|
||||
|
||||
this.cssVars.padding = parseFloat(style.getPropertyValue('--widget-padding')) * PXSCALE // rem unit
|
||||
|
||||
this.cssVars.colorText = style.getPropertyValue('--color-text').trim()
|
||||
this.cssVars.colorWidget = style.getPropertyValue('--color-widget').trim()
|
||||
this.cssVars.colorFill = style.getPropertyValue('--color-fill').trim()
|
||||
this.cssVars.colorStroke = style.getPropertyValue('--color-stroke').trim()
|
||||
this.cssVars.colorForeground = style.getPropertyValue('--color-foreground').trim()
|
||||
for (var data of this.constructor.cssVariables) {
|
||||
|
||||
var val = style.getPropertyValue(data.css).trim()
|
||||
this.cssVars[data.js] = data.toJs ? data.toJs(val) : val
|
||||
|
||||
this.cssVars.alphaStroke = parseFloat(style.getPropertyValue('--alpha-stroke').trim())
|
||||
this.cssVars.alphaFillOff = parseFloat(style.getPropertyValue('--alpha-fill-off').trim())
|
||||
this.cssVars.alphaFillOn = parseFloat(style.getPropertyValue('--alpha-fill-on').trim())
|
||||
this.cssVars.alphaPips = parseFloat(style.getPropertyValue('--alpha-pips').trim())
|
||||
}
|
||||
|
||||
this.fontFamily = style.getPropertyValue('font-family').trim()
|
||||
this.textAlign = style.getPropertyValue('text-align').trim()
|
||||
|
|
@ -230,6 +224,10 @@ class Canvas extends Widget {
|
|||
|
||||
}
|
||||
|
||||
Canvas.cssVariables = Canvas.prototype.constructor.cssVariables.concat(
|
||||
{js: 'alphaPips', css: '--alpha-pips', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)}
|
||||
)
|
||||
|
||||
Canvas.dynamicProps = Canvas.prototype.constructor.dynamicProps.concat(
|
||||
'on',
|
||||
'off'
|
||||
|
|
|
|||
|
|
@ -72,13 +72,13 @@ class Widget extends EventEmitter {
|
|||
_style:'style',
|
||||
|
||||
|
||||
colorText: {type: 'string', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'},
|
||||
colorWidget: {type: 'string', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'},
|
||||
colorStroke: {type: 'string', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'},
|
||||
colorFill: {type: 'string', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'},
|
||||
alphaStroke: {type: 'number', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'},
|
||||
alphaFillOff: {type: 'number', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'},
|
||||
alphaFillOn: {type: 'number', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'},
|
||||
colorText: {type: 'string', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'},
|
||||
|
||||
padding: {type: 'number', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'},
|
||||
|
||||
|
|
@ -191,10 +191,14 @@ class Widget extends EventEmitter {
|
|||
if (this.getProp('label') !== false) this.container.appendChild(this.label)
|
||||
if (this.widget) this.container.appendChild(this.widget)
|
||||
this.container._widget_instance = this
|
||||
this.setContainerStyles()
|
||||
|
||||
|
||||
this.container.classList.toggle('no-interaction', !this.getProp('interaction'))
|
||||
|
||||
this.setContainerStyles()
|
||||
this.setCssVariables()
|
||||
|
||||
|
||||
}
|
||||
|
||||
contains(widget) {
|
||||
|
|
@ -786,7 +790,7 @@ class Widget extends EventEmitter {
|
|||
case 'alphaFillOff':
|
||||
case 'alphaFillOn':
|
||||
case 'padding':
|
||||
this.setContainerStyles(['color'])
|
||||
this.setCssVariables()
|
||||
return
|
||||
|
||||
case 'precision':
|
||||
|
|
@ -815,7 +819,7 @@ class Widget extends EventEmitter {
|
|||
|
||||
}
|
||||
|
||||
setContainerStyles(styles = ['geometry', 'label', 'css', 'color', 'visibility']) {
|
||||
setContainerStyles(styles = ['geometry', 'label', 'css', 'visibility']) {
|
||||
|
||||
if (styles.includes('visibility')) {
|
||||
this.container.style.display = this.getProp('visible') ? '' : 'none'
|
||||
|
|
@ -939,22 +943,23 @@ class Widget extends EventEmitter {
|
|||
|
||||
}
|
||||
|
||||
if (styles.includes('color')) {
|
||||
|
||||
// color
|
||||
for (var cssvar of ['color-text', 'color-widget', 'color-fill', 'color-stroke', 'alpha-stroke', 'alpha-fill-on', 'alpha-fill-off']) {
|
||||
var val = this.getProp(cssvar.replace(/\-([a-z])/g, (a,s)=>s.toUpperCase()))
|
||||
this.container.style.setProperty('--' + cssvar, val !== undefined && val != 'auto' ? val : '')
|
||||
}
|
||||
this.container.style.setProperty('--widget-padding', this.getProp('padding') !== undefined && this.getProp('padding') != 'auto' ? parseFloat(this.getProp('padding')) + 'rem' : '')
|
||||
|
||||
}
|
||||
|
||||
return style
|
||||
|
||||
|
||||
}
|
||||
|
||||
setCssVariables() {
|
||||
|
||||
|
||||
for (var data of this.constructor.cssVariables) {
|
||||
|
||||
var val = this.getProp(data.js)
|
||||
this.container.style.setProperty(data.css, val !== undefined && val !== 'auto' ? data.toCss ? data.toCss(val) : val : '')
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
reCreateWidget(options={}){
|
||||
|
||||
if (!this.removed) return updateWidget(this, options)
|
||||
|
|
@ -973,6 +978,17 @@ class Widget extends EventEmitter {
|
|||
|
||||
Widget.parsersContexts = {}
|
||||
|
||||
Widget.cssVariables = [
|
||||
{js: 'colorWidget', css: '--color-widget'},
|
||||
{js: 'colorFill', css: '--color-fill'},
|
||||
{js: 'colorStroke', css: '--color-stroke'},
|
||||
{js: 'colorText', css: '--color-text'},
|
||||
{js: 'padding', css: '--widget-padding', toCss: x=>parseFloat(x) + 'rem', toJs: x=>parseFloat(x) * PXSCALE},
|
||||
{js: 'alphaFillOn', css: '--alpha-fill-on', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)},
|
||||
{js: 'alphaFillOff', css: '--alpha-fill-off', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)},
|
||||
{js: 'alphaStroke', css: '--alpha-stroke', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)}
|
||||
]
|
||||
|
||||
Widget.dynamicProps = [
|
||||
'visible',
|
||||
'label',
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class Clone extends Container() {
|
|||
props: {type: 'object', value: {}, help: 'Cloned widget\'s properties to override'},
|
||||
|
||||
}, [
|
||||
'_style', 'colorWidget', 'colorFill', 'colorStroke', 'alphaStroke', 'alphaFillOff', 'alphaFillOn', 'padding',
|
||||
'colorText', 'colorWidget', 'colorFill', 'colorStroke', 'alphaStroke', 'alphaFillOff', 'alphaFillOn', 'padding',
|
||||
'label', 'color', 'linkId',
|
||||
'_value', 'default', 'value',
|
||||
'_osc', 'precision', 'address', 'preArgs', 'target', 'bypass'
|
||||
|
|
|
|||
|
|
@ -192,15 +192,14 @@ class Modal extends Panel {
|
|||
|
||||
}
|
||||
|
||||
setContainerStyles(styles = ['geometry', 'label', 'css', 'color', 'visibility']) {
|
||||
|
||||
super.setContainerStyles(styles)
|
||||
setCssVariables() {
|
||||
|
||||
if (styles.includes('color') && this.popupContent) {
|
||||
super.setCssVariables()
|
||||
|
||||
this.popupContent.style.setProperty('--widget-padding', this.getProp('padding') != 'auto' ? parseFloat(this.getProp('padding')) + 'rem' : '')
|
||||
if (!this.popupContent) return
|
||||
|
||||
}
|
||||
this.popupContent.style.setProperty('--widget-padding', this.getProp('padding') !== 'auto' ? parseFloat(this.getProp('padding')) + 'rem' : '')
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ class Panel extends Container() {
|
|||
|
||||
style += widget.getProp('colorWidget') === 'auto' ? '' : `--color-widget:${widget.getProp('colorWidget')};`
|
||||
style += widget.getProp('colorFill') === 'auto' ? '' : `--color-fill:${widget.getProp('colorFill')};`
|
||||
style += widget.getProp('colorText') === 'auto' ? '' : `--color-text:${widget.getProp('colorText')};`
|
||||
|
||||
if (!widget.getProp('visible')) style += 'display:none;'
|
||||
|
||||
|
|
@ -200,6 +201,7 @@ class Panel extends Container() {
|
|||
this.setTraversing()
|
||||
return
|
||||
|
||||
case 'colorText':
|
||||
case 'colorWidget':
|
||||
case 'colorFill':
|
||||
case 'colorStroke':
|
||||
|
|
@ -215,15 +217,10 @@ class Panel extends Container() {
|
|||
|
||||
}
|
||||
|
||||
setContainerStyles(styles = ['geometry', 'label', 'css', 'color', 'visibility']) {
|
||||
setCssVariables() {
|
||||
|
||||
super.setContainerStyles(styles)
|
||||
|
||||
if (styles.includes('color') && this.getProp('scroll')) {
|
||||
|
||||
setScrollbarColor(this.container)
|
||||
|
||||
}
|
||||
super.setCssVariables()
|
||||
setScrollbarColor(this.container)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ class Root extends StaticProperties(Panel, {scroll: false, label: false, id: 'ro
|
|||
traversing: {type: 'boolean', value: false, help: 'Set to `true` to enable traversing gestures in this widget. Set to `smart` or `auto` to limit affected widgets by the type of the first touched widget'},
|
||||
variables: {type: '*', value: '', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
|
||||
|
||||
}, ['label', '_geometry', 'left', 'top', 'width', 'height', 'scroll'], {
|
||||
}, [
|
||||
'label',
|
||||
'_geometry', 'left', 'top', 'width', 'height',
|
||||
'colorFill', 'colorStroke', 'alphaStroke', 'alphaFillOff', 'padding'
|
||||
], {
|
||||
|
||||
tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object. A panel cannot contain widgets and tabs simultaneously'},
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,10 @@ module.exports = class Tab extends StaticProperties(Panel, {scroll: true}) {
|
|||
traversing: {type: 'boolean', value: false, help: 'Set to `true` to enable traversing gestures in this widget. Set to `smart` or `auto` to limit affected widgets by the type of the first touched widget'},
|
||||
variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
|
||||
|
||||
}, ['_geometry', 'left', 'top', 'width', 'height', 'scroll'], {
|
||||
}, [
|
||||
'_geometry', 'left', 'top', 'width', 'height',
|
||||
'colorStroke', 'alphaStroke', 'alphaFillOff', 'alphaFillOn'
|
||||
], {
|
||||
|
||||
widgets: {type: 'array', value: [], help: 'Each element of the array must be a widget object. A panel cannot contain widgets and tabs simultaneously.'},
|
||||
tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object. A panel cannot contain widgets and tabs simultaneously'},
|
||||
|
|
@ -69,6 +72,7 @@ module.exports = class Tab extends StaticProperties(Panel, {scroll: true}) {
|
|||
|
||||
case 'visible':
|
||||
case 'label':
|
||||
case 'colorText':
|
||||
case 'colorWidget':
|
||||
case 'colorFill':
|
||||
case 'colorStroke':
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
var {clip} = require('../utils'),
|
||||
Plot = require('./plot'),
|
||||
Widget = require('../common/widget')
|
||||
Widget = require('../common/widget'),
|
||||
StaticProperties = require('../mixins/static_properties')
|
||||
|
||||
module.exports = class Eq extends Plot {
|
||||
|
||||
module.exports = class Eq extends StaticProperties(Plot, {rangeX: {min: 20, max: 22050}}) {
|
||||
|
||||
static description() {
|
||||
|
||||
|
|
@ -41,18 +43,8 @@ module.exports = class Eq extends Plot {
|
|||
|
||||
constructor(options) {
|
||||
|
||||
// backward compat
|
||||
if (options.props.filters && options.props.filters.length) {
|
||||
options.props.value = options.props.filters
|
||||
delete options.props.filters
|
||||
}
|
||||
|
||||
super(options)
|
||||
|
||||
this.rangeX = {min:20,max:22050}
|
||||
this.pips.x.min = '20'
|
||||
this.pips.x.max = '22k'
|
||||
|
||||
this.resolution = clip(this.getProp('resolution'),[64,1024])
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ module.exports = class Plot extends StaticProperties(Canvas, {bypass: true, inte
|
|||
|
||||
if (this.value[i].length) {
|
||||
points.push(mapToScale(this.value[i][0], [this.rangeX.min, this.rangeX.max], [padding, this.width - padding], 0, this.logScaleX, true))
|
||||
points.push(mapToScale(this.value[i][1], [this.rangeY.min, this.rangeY.max], [this.height - 2 * PXSCALE, 2 * PXSCALE], 0, this.logScaleY, true))
|
||||
points.push(mapToScale(this.value[i][1], [this.rangeY.min, this.rangeY.max], [this.height - 2 * PXSCALE - padding, 2 * PXSCALE + padding], 0, this.logScaleY, true))
|
||||
} else {
|
||||
let nx = mapToScale(i, [0, this.value.length - 1], [padding, this.width - padding], 0, this.logScaleX, true),
|
||||
ny = mapToScale(this.value[i], [this.rangeY.min, this.rangeY.max], [this.height - 2 * PXSCALE - padding, 2 * PXSCALE + padding], 0, this. logScaleY, true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue