v1 refactor wip

This commit is contained in:
bordun 2020-02-23 12:34:22 +01:00
parent e57cd32438
commit 9c2a624aa0
109 changed files with 5639 additions and 4272 deletions

View file

@ -14,8 +14,7 @@ var handleClick = function(event) {
if (!EDITING) return
if (!event.detail[multiSelectKey] && event.type !== 'fast-right-click' && (
event.target.classList.contains('ui-resizable-handle') ||
event.target.classList.contains('ui-draggable-handle') ||
event.target.classList.contains('no-widget-select') ||
event.target.id === 'open-toggle'
)) { return }
@ -74,13 +73,6 @@ var handleClick = function(event) {
var clickX = Math.round((eventData.offsetX + eventData.target.scrollLeft) / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH,
clickY = Math.round((eventData.offsetY + eventData.target.scrollTop) / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH
actions.push({
label: icon('expand') + ' ' + locales('editor_editparent'),
action: ()=>{
editor.select(parent)
}
})
if (type === 'widget') {
actions.push({
@ -129,7 +121,7 @@ var handleClick = function(event) {
}
actions.push({
label: icon('box') + ' ' + locales('editor_wrap'),
label: icon('layer-group') + ' ' + locales('editor_wrap'),
action: wrapActions
})

View file

@ -3,14 +3,8 @@ var widgetManager = require('../managers/widgets'),
stateManager = require('../managers/state'),
parser = require('../parser'),
Panel,
sidepanel,
editor,
scrollState = {},
sidepanelScroll
DOM.ready(()=>{
sidepanel = DOM.get('#sidepanel')[0]
})
scrollState = {}
function updateWidget(widget, options={}) {
@ -25,6 +19,8 @@ function updateWidget(widget, options={}) {
var edited = widget.updateProps(options.changedProps, null, {fromEditor: true}) || widget
editor.widgetTree.updateTree(editor.selectedWidgets)
if (editor.selectedWidgets.includes(widget) && !options.preventSelect) {
editor.select(edited)
}
@ -67,13 +63,13 @@ function updateWidget(widget, options={}) {
var index = widget.parent.children.indexOf(widget)
// list widgets to remove
removedChildren = removedChildren.filter(x => x !== undefined)
var removedWidgets = reuseChildren ?
removedChildren.map(x => x.getAllChildren().concat(x)).concat(widget).reduce((a,b)=>a.concat(b), []) :
widget.getAllChildren().concat(widget)
// save state
if (stateManager.queueCounter === 0) {
sidepanelScroll = sidepanel.scrollTop
scrollState = {}
}
stateManager.incrementQueue()
@ -135,7 +131,6 @@ function updateWidget(widget, options={}) {
// restore state
stateManager.decrementQueue()
if (stateManager.queueCounter === 0) {
sidepanel.scrollTop = sidepanelScroll
for (let id in scrollState) {
for (let w of widgetManager.getWidgetById(id)) {
if (w.scroll) w.scroll(scrollState[id])
@ -143,6 +138,8 @@ function updateWidget(widget, options={}) {
}
}
editor.widgetTree.updateTree(editor.selectedWidgets)
if (editor.selectedWidgets.includes(widget) && !options.preventSelect) {
editor.select(newWidget)
}

View file

@ -14,9 +14,9 @@ module.exports = function editField(editor, widget, propName, defaultValue){
error = widget.errors[propName]
let field = html`
<div class="input-wrapper ${widget.errors[propName] ? 'error' : ''} ${disabled ? 'disabled' : ''}" title="${locales('editor_click_for_help')}">
<label class="btn ${error ? 'error' : ''}">${propName}</label>
</div>
<osc-inspector-field class="${widget.errors[propName] ? 'error' : ''} ${disabled ? 'disabled' : ''}" title="${locales('editor_click_for_help')}">
<label class="${error ? 'error' : ''}">${propName}</label>
</osc-inspector-field>
`
let input
@ -69,12 +69,14 @@ module.exports = function editField(editor, widget, propName, defaultValue){
}
})
field.appendChild(input)
if (defaultValue.type.includes('boolean')) {
let toggle = html`
<span class="checkbox ${widget.getProp(propName) ? 'on' : ''}">
<osc-inspector-checkbox class="${widget.getProp(propName) ? 'on' : ''}">
${raw(icon('check'))}
</span>
</osc-inspector-checkbox>
`
toggle.addEventListener('click', ()=>{
@ -91,7 +93,6 @@ module.exports = function editField(editor, widget, propName, defaultValue){
}
field.appendChild(input)
}
var lock,

View file

@ -1,49 +1,87 @@
var {widgets} = require('../widgets/'),
editField = require('./edit-field'),
var editField = require('./edit-field'),
{updateWidget, incrementWidget} = require('./data-workers'),
keyboardJS = require('keyboardjs'),
{diff, diffToWidget} = require('./diff'),
widgetManager = require('../managers/widgets'),
{deepCopy} = require('../utils'),
{defaults} = require('../widgets/'),
macOs = (navigator.platform || '').match('Mac'),
SelectArea = require('./select-area'),
UiSelectArea = require('../ui/ui-selectarea'),
UiInspector = require('../ui/ui-inspector'),
UiTree = require('../ui/ui-tree'),
UiDragResize = require('../ui/ui-dragresize'),
sidepanel = require('../ui/ui-sidepanel'),
html = require('nanohtml'),
sessionManager
const HISTORY_SIZE = 50
var Editor = class Editor {
constructor() {
this.wrapper = html`
<div class="editor-container">
<div class="form" id="editor-form">
</div>
</div>
`
this.inspector = new UiInspector({selector: '#osc-inspector'})
this.inspector.on('update', (event)=>{
this.form = DOM.get(this.wrapper, '.form')[0]
this.form.addEventListener('fast-click', (e)=>{
if (e.target.classList.contains('separator')) {
var name = e.target.getAttribute('data-name'),
foldedIndex = this.foldedCategories.indexOf(name)
e.target.parentNode.classList.toggle('folded', foldedIndex < 0)
if (foldedIndex > -1) {
this.foldedCategories.splice(foldedIndex, 1)
var {propName, value} = event,
newWidgets = []
for (var w of this.selectedWidgets) {
if (propName === 'address' && value === '') {
// special case
w.props[propName] = '/' + w.props.id
} else {
this.foldedCategories.push(name)
w.props[propName] = value !== '' ? value : deepCopy(defaults[w.props.type][propName].value)
}
newWidgets.push(updateWidget(w, {changedProps: [propName], preventSelect: this.selectedWidgets.length > 1}))
}
this.pushHistory()
if (newWidgets.length > 1) this.select(newWidgets)
})
this.defaults = {}
for (var k in widgets) {
this.defaults[k] = widgets[k].defaults()
}
this.widgetTree = new UiTree({selector: '#osc-tree'})
this.widgetTree.on('sorted', (event)=>{
var {widget, oldIndex, newIndex} = event,
propName = widget.props.tabs.length ? 'tabs' : 'widgets'
if (widget.props[propName].length < 2) return
widget.props[propName].splice(newIndex, 0, widget.props[propName].splice(oldIndex, 1)[0])
var indices = [newIndex, oldIndex]
if (Math.abs(oldIndex - newIndex) > 1) {
for (var i = Math.min(newIndex, oldIndex) + 1; i < Math.max(newIndex, oldIndex); i++) {
indices.push(i)
}
}
var container = updateWidget(widget, {removedIndexes: indices, addedIndexes: indices, preventSelect: true})
this.pushHistory({removedIndexes: indices, addedIndexes: indices})
this.select(container.children[newIndex])
})
this.oscContainer = DOM.get('#osc-container')[0]
this.widgetDragResize = new UiDragResize({})
this.widgetDragResize.on('move', (e)=>{
var dX = Math.round((e.left - e.initLeft) / GRIDWIDTH) * GRIDWIDTH,
dY = Math.round((e.top - e.initTop) / GRIDWIDTH) * GRIDWIDTH
this.moveWidget(dX, dY)
})
this.widgetDragResize.on('resize', (e)=>{
var dX = Math.round((e.width - e.initWidth) / GRIDWIDTH) * GRIDWIDTH,
dY = Math.round((e.height - e.initHeight) / GRIDWIDTH) * GRIDWIDTH
this.resizeWidget(dX, dY)
})
this.selectedWidgets = []
@ -62,8 +100,6 @@ var Editor = class Editor {
this.historyState = -1
this.historySession = null
this.foldedCategories = []
this.mousePosition = {x:0, y:0}
this.mouveMoveHandler = this.mouseMove.bind(this)
@ -128,7 +164,7 @@ var Editor = class Editor {
})
this.selectarea = new SelectArea('.widget:not(.not-editable), .tablink', (elements)=>{
this.selectarea = new UiSelectArea('[data-widget]:not(.not-editable)', (elements)=>{
elements = elements.map(e => widgetManager.getWidgetByElement(e, ':not(.not-editable)')).filter(e => e)
@ -225,6 +261,7 @@ var Editor = class Editor {
if (!this.selectedWidgets.length) return
this.unselect()
this.selectedWidgets = []
this.inspector.clear()
break
case 'mod + a':
@ -285,15 +322,15 @@ var Editor = class Editor {
break
case 'f2':
var input = DOM.get(this.form, 'textarea[name="label"]')[0]
if (input) {
var folded = input.closest('.category.folded')
if (folded) DOM.dispatchEvent(DOM.get(folded, '.separator'), 'fast-click')
input.focus()
input.setSelectionRange(0, input.value.length)
}
break
// case 'f2':
// var input = DOM.get(this.form, 'textarea[name="label"]')[0]
// if (input) {
// var folded = input.closest('.category.folded')
// if (folded) DOM.dispatchEvent(DOM.get(folded, '.separator'), 'fast-click')
// input.focus()
// input.setSelectionRange(0, input.value.length)
// }
// break
}
@ -307,40 +344,44 @@ var Editor = class Editor {
EDITING = true
this.enabled = true
DOM.get('.editor-root')[0].setAttribute('data-widget', DOM.get('.root-container')[0].getAttribute('data-widget'))
DOM.get('.editor-root')[0].classList.remove('disabled')
DOM.get('.disable-editor')[0].classList.remove('on')
DOM.get('.enable-editor')[0].classList.add('on')
// DOM.get('.disable-editor')[0].classList.remove('on')
// DOM.get('.enable-editor')[0].classList.add('on')
//
document.body.classList.add('editor-enabled')
document.body.classList.toggle('no-grid', GRIDWIDTH == 1)
// document.body.classList.toggle('no-grid', GRIDWIDTH == 1)
//
//
// GRIDWIDTH = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--grid-width'))
//
// var gridForm = html`
// <div class="form" id="grid-width-form">
// <div class="separator"><span>Grid</span></div>
// <div class="input-wrapper">
// <label>Width</label>
// <input class="input no-keybinding" type="number" id="grid-width-input" step="1" min="1" max="100" value="${GRIDWIDTH}"/>
// </div>
// </div>
// `
//
// DOM.each(gridForm, '#grid-width-input', (input)=>{
// DOM.addEventListener(input, 'keyup mouseup change mousewheel', (e)=>{
// setTimeout(()=>{
// var v = Math.max(Math.min(parseInt(input.value), 100), 1)
// if (isNaN(v)) return
// input.value = v
// GRIDWIDTH = v
// document.body.classList.toggle('no-grid', GRIDWIDTH == 1)
// document.documentElement.style.setProperty('--grid-width', GRIDWIDTH)
// })
// })
// })
//
// DOM.get(document, '.editor-menu')[0].appendChild(gridForm)
this.widgetTree.updateTree(this.selectedWidgets)
GRIDWIDTH = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--grid-width'))
var gridForm = html`
<div class="form" id="grid-width-form">
<div class="separator"><span>Grid</span></div>
<div class="input-wrapper">
<label>Width</label>
<input class="input no-keybinding" type="number" id="grid-width-input" step="1" min="1" max="100" value="${GRIDWIDTH}"/>
</div>
</div>
`
DOM.each(gridForm, '#grid-width-input', (input)=>{
DOM.addEventListener(input, 'keyup mouseup change mousewheel', (e)=>{
setTimeout(()=>{
var v = Math.max(Math.min(parseInt(input.value), 100), 1)
if (isNaN(v)) return
input.value = v
GRIDWIDTH = v
document.body.classList.toggle('no-grid', GRIDWIDTH == 1)
document.documentElement.style.setProperty('--grid-width', GRIDWIDTH)
})
})
})
DOM.get(document, '.editor-menu')[0].appendChild(gridForm)
sidepanel.left.enable()
sidepanel.right.enable()
keyboardJS.setContext('editing')
@ -357,7 +398,6 @@ var Editor = class Editor {
this.unselect()
this.selectedWidgets = []
DOM.get('.editor-root')[0].classList.add('disabled')
DOM.get('.disable-editor')[0].classList.add('on')
DOM.get('.enable-editor')[0].classList.remove('on')
document.body.classList.remove('editor-enabled')
@ -369,6 +409,11 @@ var Editor = class Editor {
document.body.removeEventListener('mousemove', this.mouveMoveHandler)
sidepanel.left.disable()
sidepanel.right.disable()
this.widgetTree.clear()
this.inspector.clear()
this.selectarea.disable()
}
@ -376,16 +421,14 @@ var Editor = class Editor {
unselect() {
DOM.get('#editor')[0].innerHTML = ''
this.form.innerHTML = ''
this.widgetDragResize.clear()
this.inspector.clear()
DOM.each(document, '.editing', (element)=>{
element.classList.remove('editing')
})
$('.widget.ui-resizable').resizable('destroy')
$('.widget.ui-draggable').draggable('destroy').find('.ui-draggable-handle').remove()
this.widgetTree.select([])
}
@ -428,81 +471,18 @@ var Editor = class Editor {
if (this.selectedWidgets.length > 0 && !options.fromLasso) {
this.createEditForm()
this.inspector.inspect(this.selectedWidgets)
this.createSelectionBlock()
} else {
this.inspector.clear()
}
}
createEditForm(){
var widget = this.selectedWidgets[0],
props = this.defaults[widget.props.type],
multi = this.selectedWidgets.length > 1
this.form.appendChild(html`
<div class="separator">
<span class="${this.selectedWidgets.length > 1 ? 'accent' : ''}">
Widget${multi ? 's' : ''}: ${multi ? this.selectedWidgets.length + ' selected': widget.getProp('id')}
</span>
</div>
`)
let category
for (let propName in props) {
let field,
shared = true
for (var w of this.selectedWidgets) {
if (this.defaults[w.props.type][propName] === undefined) {
shared = false
}
}
if (!shared) continue
if (propName.indexOf('_') === 0 && propName !== '_props') {
if (category) this.form.appendChild(category)
category = html`<div class="category ${this.foldedCategories.indexOf(props[propName]) > -1 ? 'folded' : ''}"></div>`
field = html`<div class="separator" data-name="${props[propName]}"><span>${props[propName]}</span></div>`
} else if (widget.props[propName] === undefined) {
continue
} else {
if (widget.parent !== widgetManager && widget.parent.getProp('type') === 'strip') {
// special case for widgets in strips
if (propName === 'top' || propName === 'left' || propName === (widget.parent.getProp('horizontal') ? 'height' : 'width')) continue
}
field = editField(this, widget, propName, props[propName])
if (!field) continue
}
if (category) {
category.appendChild(field)
} else {
this.form.appendChild(field)
}
}
if (category) this.form.appendChild(category)
this.wrapper.appendChild(this.form)
DOM.get('#editor')[0].appendChild(this.wrapper)
}
createSelectionBlock(){
for (let widget of this.selectedWidgets) {
@ -510,59 +490,8 @@ var Editor = class Editor {
item.classList.add('editing')
})
}
var widget = this.selectedWidgets[0]
if (widget.props.height !== undefined || widget.props.width !== undefined) {
let $container = $(widget.container)
$container.resizable({
handles: 's, e, se',
helper: 'ui-helper',
resize: (event, ui)=>{
ui.size.height = Math.round(ui.size.height / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH * PXSCALE
ui.size.width = Math.round(ui.size.width / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH * PXSCALE
},
stop: (event, ui)=>{
var deltaH = ui.size.height - ui.originalSize.height,
deltaW = ui.size.width - ui.originalSize.width
this.resizeWidget(deltaW, deltaH, ui)
},
grid: [GRIDWIDTH * PXSCALE, GRIDWIDTH * PXSCALE]
})
}
if (widget.props.top !== undefined && widget.parent.getProp('type') !== 'strip') {
let $container = $(widget.container)
$container.draggable({
cursor:'-webkit-grabbing',
drag: (event, ui)=>{
ui.position.top = Math.round(ui.position.top / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH * PXSCALE
ui.position.left = Math.round(ui.position.left / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH * PXSCALE
},
stop: (event, ui)=>{
event.preventDefault()
var deltaX = (ui.helper.position().left + $container.parent().scrollLeft()) / PXSCALE - widget.container.offsetLeft / PXSCALE,
deltaY = (ui.helper.position().top + $container.parent().scrollTop()) / PXSCALE - widget.container.offsetTop / PXSCALE
this.moveWidget(deltaX, deltaY)
ui.helper.remove()
},
handle:'.ui-draggable-handle, > .label',
grid: [GRIDWIDTH * PXSCALE, GRIDWIDTH * PXSCALE],
helper:()=>{
return $('<div class="ui-helper"></div>').css({height:$container.outerHeight(),width:$container.outerWidth()})
}
}).append('<div class="ui-draggable-handle"></div>')
}
this.widgetTree.select(this.selectedWidgets)
this.widgetDragResize.create(this.selectedWidgets)
}
@ -717,10 +646,12 @@ var Editor = class Editor {
}
}
this.select(updateWidget(parent, {
preventSelect: true,
removedIndexes
}))
var container = updateWidget(parent, {preventSelect: true, removedIndexes})
if (container.children.length) {
this.select(container.children[Math.min(index.pop(), container.children.length - 1)])
} else {
this.select(container)
}
this.pushHistory({removedIndexes})
}
@ -781,13 +712,13 @@ var Editor = class Editor {
for (var w of this.selectedWidgets) {
var newTop = parseInt(w.container.offsetTop) / PXSCALE + deltaY
var newTop = Math.max(parseInt(w.container.offsetTop) / PXSCALE + deltaY, 0)
if (typeof w.props.top === 'string' && w.props.top.indexOf('%') > -1) {
w.props.top = (100 * PXSCALE * newTop / w.container.parentNode.offsetHeight).toFixed(2) + '%'
} else {
w.props.top = newTop
}
var newLeft = parseInt(w.container.offsetLeft) / PXSCALE + deltaX
var newLeft = Math.max(parseInt(w.container.offsetLeft) / PXSCALE + deltaX, 0)
if (typeof w.props.left === 'string' && w.props.left.indexOf('%') > -1) {
w.props.left = (100 * PXSCALE * newLeft / w.container.parentNode.offsetWidth).toFixed(2) + '%'
} else {
@ -890,6 +821,9 @@ var Editor = class Editor {
if (this.selectedWidgets[0] && !widgetManager.widgets[this.selectedWidgets[0].hash]) {
this.unselect()
this.selectedWidgets = []
this.inspector.clear()
} else if (this.selectedWidgets[0]) {
this.widgetDragResize.create(this.selectedWidgets)
}
}

View file

@ -0,0 +1,43 @@
module.exports = (element, callback, options={})=>{
var lastTapTime = 0,
lastTapX,
lastTapY
element.addEventListener(options.click ? 'click' : 'fast-click', (event)=>{
if (event.capturedByEditor && !options.ignoreEditorCapture) return
var tapTime = Date.now(),
tapLength = tapTime - lastTapTime,
eventData = options.click ? event : event.detail
if (
tapLength < DOUBLE_TAP_TIME &&
Math.abs(lastTapX - eventData.pageX) < 20 &&
Math.abs(lastTapY - eventData.pageY) < 20 &&
(!options.click || event.pageX !== 0) // prevent fake click emitted with keyboard focus events
) {
// execute callback at next cycle to ensure draginit events are resolved first
setTimeout(()=>{
callback(event.detail)
}, 0)
lastTapTime = 0
// prevent touchend
if (!options.click) event.detail.preventOriginalEvent = true
} else {
lastTapTime = tapTime
lastTapX = eventData.pageX
lastTapY = eventData.pageY
}
})
}

View file

@ -33,9 +33,4 @@ window.JSON.parseFlex = require('json5').parse
window.DOM = require('./dom')
window.$ = require('jquery/dist/jquery.slim.min.js')
require('../libs/jquery.ui')
require('../libs/jquery.touch')
require('cardinal-spline-js/curve.min.js')

View file

@ -93,11 +93,11 @@ module.exports = {
setTimeout(()=>{
var root = widgetManager.getWidgetById('root')[0]
if (root) root.reCreateWidget()
},100)
if (root) root.onPropChanged('color')
},200)
GRIDWIDTH = getComputedStyle(document.documentElement).getPropertyValue('--grid-width')
GRIDWIDTH = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--grid-width'))
},
readOnly: function(){
@ -132,8 +132,6 @@ module.exports = {
history: editor.history,
historyState: editor.historyState,
editorEnabled: editor.enabled,
sidepanelOpened: document.getElementById('sidepanel').classList.contains('sidepanel-open'),
traversing: document.getElementById('container')._traversing
})
// reload page and hold backup id

View file

@ -12,7 +12,6 @@ module.exports = {
// editor context-menu
editor_editparent: 'Edit parent',
editor_copy: 'Copy',
editor_cut: 'Cut',
editor_wrap: 'Wrap in',

View file

@ -11,15 +11,14 @@ module.exports = {
editor_export: 'Exporter',
// editor context-menu
editor_editparent: 'Éditer parent',
editor_copy: 'Copier',
editor_cut: 'Couper',
editor_wrap: 'Grouper dans',
editor_paste: 'Coller',
editor_pasteindent: 'ID + 1',
editor_clone: 'Clone',
editor_addwidget: 'Nouveau widget',
editor_addtab: 'Nouvel onglet',
editor_addwidget: 'Ajouter widget',
editor_addtab: 'Ajouter onglet',
editor_delete: 'Supprimer',
editor_click_for_help: 'Cliquer sur le nom de la propriété pour afficher l\'aide',

View file

@ -11,7 +11,6 @@ module.exports = { // @https://github.com/suhr
editor_export: 'Export',
// editor context-menu
editor_editparent: 'К родителю',
editor_copy: 'Копировать',
editor_cut: 'Вырезать',
editor_wrap: 'Обернуть в',

View file

@ -31,7 +31,7 @@ var SessionManager = class SessionManager {
this.lock = true
var container = DOM.get('#container')[0],
var container = DOM.get('#osc-container')[0],
loader = loading(locales('loading_session'))
setTimeout(()=>{
@ -49,7 +49,7 @@ var SessionManager = class SessionManager {
parser.reset()
parser.parse({
data: this.session,
parentNode: DOM.get('#container')[0]
parentNode: DOM.get('#osc-container')[0]
})
editor.clearHistory()

View file

@ -6,7 +6,7 @@ class ContextMenu {
constructor(){
this.menu = null
this.root = document.body
this.root = DOM.get('osc-workspace')[0]
this.clickHandler = (e)=>{
if (this.menu && !this.menu.contains(e.target)) this.close()
}
@ -116,12 +116,12 @@ class ContextMenu {
if (width + position.left > totalWidth) {
menu.style.right = parent ? '100%' : '0'
menu.style.left = 'auto'
menu.style.marginRight = '2rem'
menu.style.marginRight = '1rem'
}
if (height + position.top > totalHeight) {
menu.style.top = 'auto'
menu.style.bottom = '2rem'
menu.style.bottom = '0rem'
}
}

View file

@ -1,6 +1,16 @@
require('./zoom')
require('./lobby').create()
require('./sidepanel')
// require('./sidepanel')
require('../events/click')
require('./ios')
require('./notifications')
require('./ui-workspace')
// require('./ui-sidepanel')
var UiModal = require('./ui-modal')
module.exports = {
uiModal: new UiModal({selector: 'osc-modal-container'})
}

View file

@ -0,0 +1,19 @@
var chroma = require('chroma-js')
module.exports = (container)=>{
setTimeout(()=>{
var computedStyle = window.getComputedStyle(container),
color = computedStyle.getPropertyValue('--color-fill').trim(),
alpha = parseFloat(computedStyle.getPropertyValue('--alpha-scrollbar')),
alphaOn = parseFloat(computedStyle.getPropertyValue('--alpha-scrollbar-on'))
if (color) {
container.style.setProperty('--color-scrollbar', chroma(color).alpha(alpha).css())
container.style.setProperty('--color-scrollbar-on', chroma(color).alpha(alphaOn).css())
}
})
}

View file

@ -277,7 +277,7 @@ if (fullscreen.isEnabled) {
}
// open / close / toggle
/*
var sidepaneLock = false
function sidepanelOpen() {
@ -350,9 +350,11 @@ document.addEventListener('keydown', function(e){
// Sidepanel resize
var sidepanelWidth
$('#sidepanel-handle').draggable({
$('osc-panel-container sidepanel-handle').draggable({
cursor:'col-resize',
start: ()=>{
sidepanelWidth = parseInt(sidepanelContainer.offsetWidth) / PXSCALE
@ -377,3 +379,10 @@ module.exports = {
close: sidepanelClose,
toggle: sidepanelToggle
}
*/
module.exports = {
open: ()=>{},
close: ()=>{},
toggle: ()=>{}
}

View file

@ -0,0 +1,190 @@
var UiWidget = require('./ui-widget'),
html = require('nanohtml'),
Tab, Root, Modal
class UiDragResize extends UiWidget {
constructor(options) {
Tab = require('../widgets/containers/tab')
Root = require('../widgets/containers/root')
Modal = require('../widgets/containers/modal')
super(options)
this.container = html`
<div id="drag-resize">
<div class="position-handle"></div>
<div class="helper"></div>
<div class="no-widget-select handle nw" data-action="left,top"></div>
<div class="no-widget-select handle e" data-action="width"></div>
<div class="no-widget-select handle s" data-action="height"></div>
<div class="no-widget-select handle se" data-action="width,height"></div>
</div>
`
this.initLeft = 0
this.initTop = 0
this.initWidth = 0
this.initHeight = 0
this.left = 0
this.top = 0
this.width = 0
this.height = 0
this.mounted = false
this.handles = DOM.get(this.container, '.handle')
this.dragging = null
this.on('draginit', (event)=>{
var node = event.target
if (!this.handles.includes(node)) return
this.initLeft = this.left
this.initTop = this.top
this.initWidth = this.width
this.initHeight = this.height
this.container.classList.add('dragging')
this.dragging = node.getAttribute('data-action').split(',')
event.traversing = false // stop traversing here
}, {element: this.container})
this.on('drag', (event)=>{
if (!this.dragging) return
for (var k of this.dragging) {
switch (k) {
case 'left':
case 'width':
this[k] += event.movementX / PXSCALE
break
case 'top':
case 'height':
this[k] += event.movementY / PXSCALE
break
}
}
this.updateCss(true)
}, {element: this.container})
this.on('dragend', (event)=>{
this.container.classList.remove('dragging')
this.left = Math.max(0, this.left)
this.top = Math.max(0, this.top)
this.trigger(this.dragging.indexOf('left') > -1 ? 'move' : 'resize', this)
this.dragging = null
}, {element: this.container})
// handles appear on top of modal widgets
// very special case fix here...
this.watchedModalWidget = null
this.checkModalState = (e)=>{
if (e.widget !== this.watchedModalWidget) return
console.log(e.widget.value)
this.container.style.display = e.widget.value ? 'none' : ''
}
}
clear() {
if (!this.mounted) return
if (this.watchedModalWidget) {
// reset modal widget fix
this.watchedModalWidget.off('change', this.checkModalState)
this.watchedModalWidget = null
this.container.style.display = ''
}
this.container.parentNode.removeChild(this.container)
this.mounted = false
}
create(widgets) {
this.clear()
var widget = widgets[0]
if (widget instanceof Modal) {
// modal widget fix
this.watchedModalWidget = widget
widget.on('change', this.checkModalState)
if (widget.getValue()) this.container.style.display = 'none'
}
if (
widget instanceof Tab ||
widget instanceof Root ||
!widget.getProp('visible')
) return
var handlesVisibility = [
!(widget instanceof Tab) && widget.parent.getProp('layout') === 'default', // nw
widget.parent.getProp('layout') !== 'vertical', // e
widget.parent.getProp('layout') !== 'horizontal', // s
]
handlesVisibility.push(handlesVisibility[1] && handlesVisibility[2]) // se
for (var i in handlesVisibility) {
this.handles[i].style.display = handlesVisibility[i] ? '' : 'none'
}
var parent = widget.parentNode,
lefts = widgets.map(w => w.container.offsetLeft),
tops = widgets.map(w => w.container.offsetTop),
rights = widgets.map(w => w.container.offsetLeft + w.container.offsetWidth),
bottoms = widgets.map(w => w.container.offsetTop + w.container.offsetHeight)
this.left = Math.min(...lefts) / PXSCALE
this.top = Math.min(...tops) / PXSCALE
this.width = (Math.max(...rights) - Math.min(...lefts)) / PXSCALE
this.height = (Math.max(...bottoms) - Math.min(...tops)) / PXSCALE
this.updateCss()
parent.appendChild(this.container)
this.mounted = true
}
updateCss(grid) {
for (var k of ['top', 'left', 'width', 'height']) {
var val = this[k]
if (k === 'width' || k === 'height') val = Math.max(10 * PXSCALE, val)
if (grid) val = Math.round(val / GRIDWIDTH) * GRIDWIDTH
this.container.style.setProperty('--' + k, val + 'rem')
}
}
}
module.exports = UiDragResize

View file

@ -0,0 +1,120 @@
var UiWidget = require('./ui-widget'),
{categories} = require('../widgets/'),
html = require('nanohtml'),
raw = require('nanohtml/raw'),
{icon, Popup} = require('../ui/utils')
class UiInspectorField extends UiWidget {
constructor(options) {
super(options)
this.name = options.name
this.widget = options.widget
this.value = options.value
this.default = options.default
this.container = html`<osc-inspector-field></osc-inspector-field>`
this.label = this.container.appendChild(html`<label>${this.name}</label>`)
if (this.name === 'type') this.createTypeSelect()
else this.createInput()
}
createTypeSelect() {
if (this.widget.props.type == 'tab' || this.widget.props.type == 'root') {
this.container.appendChild(html`
<textarea class="no-keybinding" name="${this.name}" rows="1" disabled>${this.value}</textarea>
`)
return
}
this.createInput()
var select = html`<select class="no-keybinding" name="${this.name}"/>`
for (let cname in categories) {
var optGroup = html`<optgroup label="${cname}"></optgroup>`
for (let wtype of categories[cname]) {
optGroup.appendChild(html`<option ${wtype == this.value ? 'selected' : ''} value="${wtype}">${wtype}</option>`)
}
select.appendChild(optGroup)
}
var wrapper = html`<osc-inspector-select></osc-inspector-select>`
wrapper.appendChild(select)
this.container.appendChild(wrapper)
}
createInput() {
var stringValue = typeof this.value !== 'string' ?
JSON.stringify(this.value, null, ' ').replace(/\n\s\s\s\s/g, ' ').replace(/\n\s\s(\}|\])/g, ' $1') : this.value
var input = html`<textarea class="no-keybinding" name="${this.name}" rows="${stringValue.split('\n').length}">${stringValue}</textarea>`
this.container.appendChild(input)
if (this.default.choices) {
let wrapper = html`<osc-inspector-select></osc-inspector-select>`,
select = wrapper.appendChild(html`<select class="no-keybinding" name="${this.name}"/>`)
for (let choice of this.default.choices) {
select.appendChild(html`<option ${choice == this.value ? 'selected' : ''} value="${choice}">${choice}</option>`)
}
this.container.appendChild(wrapper)
}
if (this.name.includes('color')) {
let picker = html`<input class="osc-inspector-color" type="color" name="${this.name}" value="${this.value}"/>`
this.container.appendChild(picker)
}
if (this.default.type.includes('boolean')) {
let toggle = html`
<osc-inspector-checkbox class="${this.widget.getProp(this.name) ? 'on' : ''}">
${raw(icon('check'))}
</osc-inspector-checkbox>
`
toggle.addEventListener('click', ()=>{
if (this.name === 'label' && !this.widget.getProp(this.name) === true) {
// special case
input.value = 'auto'
} else {
input.value = !this.widget.getProp(this.name)
}
DOM.dispatchEvent(input, 'change')
})
this.container.appendChild(toggle)
}
}
}
module.exports = UiInspectorField

View file

@ -0,0 +1,188 @@
var UiWidget = require('./ui-widget'),
UiInspectorField = require('./ui-inspector-field'),
morph = require('nanomorph'),
{widgets, defaults} = require('../widgets/'),
{deepCopy} = require('../utils'),
html = require('nanohtml')
class UiInspector extends UiWidget {
constructor(options) {
super(options)
this.mounted = false
this.foldedCategories = []
this.container.addEventListener('fast-click', (e)=>{
if (e.target.classList.contains('category-header')) {
var name = e.target.getAttribute('data-name'),
foldedIndex = this.foldedCategories.indexOf(name)
e.target.parentNode.classList.toggle('folded', foldedIndex < 0)
if (foldedIndex > -1) {
this.foldedCategories.splice(foldedIndex, 1)
} else {
this.foldedCategories.push(name)
}
}
})
this.container.addEventListener('change', this.onChange.bind(this))
this.container.addEventListener('keydown', this.onKeydown.bind(this))
this.container.addEventListener('input', this.textAutoHeight.bind(this))
this.container.addEventListener('focus', this.textAutoHeight.bind(this))
this.lock = false
}
clear() {
this.container.innerHTML = ''
this.mounted = false
}
inspect(widgets) {
var content = html`<div></div>`
var widget = widgets[0],
props = defaults[widget.props.type],
multi = widgets.length > 1
// this.form.appendChild(html`
// <div class="separator">
// <span class="${this.selectedWidgets.length > 1 ? 'accent' : ''}">
// Widget${multi ? 's' : ''}: ${multi ? this.selectedWidgets.length + ' selected': widget.getProp('id')}
// </span>
// </div>
// `)
let category
for (let propName in props) {
if (propName === 'tabs' || propName === 'widgets') continue
let field,
shared = true
for (var w of widgets) {
if (defaults[w.props.type][propName] === undefined) {
shared = false
}
}
if (!shared) continue
if (propName.indexOf('_') === 0 && propName !== '_props') {
if (category) content.appendChild(category)
category = html`<osc-inspector-category class="${this.foldedCategories.indexOf(props[propName]) > -1 ? 'folded' : ''}"></osc-inspector-category>`
field = html`<div class="category-header" data-name="${props[propName]}">${props[propName]}</div>`
} else if (widget.props[propName] === undefined) {
continue
} else {
// if (widget.parent !== widgetManager && widget.parent.getProp('type') === 'strip') {
// // special case for widgets in strips
// if (propName === 'top' || propName === 'left' || propName === (widget.parent.getProp('horizontal') ? 'height' : 'width')) continue
// }
field = new UiInspectorField({
parent: this,
widget: widget,
name: propName,
value: widget.props[propName],
default: defaults[w.props.type][propName]
}).container
if (!field) continue
}
if (category) {
category.appendChild(field)
} else {
content.appendChild(field)
}
}
if (category) content.appendChild(category)
if (this.mounted) {
morph(this.container.firstChild, content)
} else {
this.container.appendChild(content)
}
this.mounted = true
}
onChange(event) {
if (this.lock) return
this.lock = true
var input = event.target
input.blur()
var v
var str = input.value.replace(/[‟”]/g, '"').replace(/[‘’]/g, '\'') // convert invalid quote characters
try {
v = JSON.parseFlex(str)
if (typeof v === 'string') {
// escape backslashes in simple strings only
v = JSON.parseFlex(str.replace(/\\/g, '__BACKSLASH__'))
v = v.replace(/__BACKSLASH__/g, '\\')
}
} catch(err) {
v = str
}
this.trigger('update', {
propName: input.name,
value: v
})
this.lock = false
}
onKeydown(event) {
var input = event.target
if (event.keyCode === 13 && !event.shiftKey) {
event.preventDefault()
DOM.dispatchEvent(input, 'change')
}
}
textAutoHeight(event) {
var input = event.target
input.setAttribute('rows',0)
input.setAttribute('rows', input.value.split('\n').length)
}
}
module.exports = UiInspector

View file

@ -0,0 +1,97 @@
var UiWidget = require('./ui-widget'),
html = require('nanohtml'),
raw = require('nanohtml/raw'),
{iconify} = require('../ui/utils')
class UiModalWindow {
constructor(options) {
this.container = html`
<osc-modal-window class="${options.class || ''}">
<inner>
${options.content}
</inner>
</osc-modal-window>
`
if (options.label) {
this.container.appendChild(html`<label>${raw(iconify(options.label))}</label>`)
}
this.opened = false
}
open(z) {
this.opened = true
this.container.classList.add('on')
this.container.style.zIndex = z
}
close() {
this.opened = false
this.container.classList.remove('on')
}
}
class UiModal extends UiWidget {
constructor(options) {
super(options)
this.modals = {}
this.openedModals = []
}
create(id, options) {
if (this.modals[id]) this.destroy(id)
this.modals[id] = new UiModalWindow(options)
this.container.appendChild(this.modals[id].container)
}
destroy(id) {
if (!this.modals[id]) return
this.close(id)
this.container.removeChild(this.modals[id].container)
delete this.modals[id]
}
open(id) {
if (!this.modals[id]) return
if (this.openedModals.includes(id)) this.close(id)
this.openedModals.push(id)
this.modals[id].open(this.openedModals.length)
}
close(id) {
if (!this.modals[id] || !this.openedModals.includes(id)) return
this.openedModals.splice(this.openedModals.indexOf(id), 1)
this.modals[id].close()
}
}
module.exports = UiModal

View file

@ -1,6 +1,6 @@
var html = require('nanohtml')
class SelectArea {
class UiSelectArea {
constructor(selector, callback){
@ -13,8 +13,7 @@ class SelectArea {
this.rectSize = [0, 0]
this.elements = []
this.rect = html`<div class="select-area hidden"></div>`
document.body.appendChild(this.rect)
this.rect = document.body.appendChild(html`<div class="select-area hidden"></div>`)
this.selector = selector
this.callback = callback
@ -126,4 +125,4 @@ class SelectArea {
}
module.exports = SelectArea
module.exports = UiSelectArea

View file

@ -0,0 +1,112 @@
var UiWidget = require('./ui-widget')
class UiSidePanel extends UiWidget {
constructor(options) {
super(options)
this.resizeDirection = this.container.classList.contains('left') ? 1 : -1
this.resizeHandle = DOM.get(this.container, '.resize-handle')[0]
this.toggleButton = DOM.get(this.container, '.toggle-button')[0]
this.content = DOM.get(this.container, 'osc-panel-inner')[0]
this.minWidth = 250
this.width = 250
this.disabled = true
this.minimized = false
this.init = false
this.on('drag', (event)=>{
this.width += this.resizeDirection * event.movementX / PXSCALE
this.container.style.width = this.width + 'rem'
}, {element: this.resizeHandle})
this.on('dragend', (event)=>{
this.width = parseInt(this.container.offsetWidth) / PXSCALE
DOM.dispatchEvent(window, 'resize')
}, {element: this.resizeHandle})
this.toggleButton.addEventListener('click', ()=>{
if (this.disabled) return
if (this.minimized) this.restore()
else this.minimize()
})
}
enable() {
this.container.classList.remove('disabled')
this.disabled = false
if (!this.minimized) this.open()
}
disable() {
this.container.classList.add('disabled')
this.disabled = false
this.close()
}
minimize() {
if (this.minimized) return
this.minimized = true
this.close()
}
restore() {
if (!this.minimized) return
this.minimized = false
this.open()
}
open() {
this.container.style.width = this.width + 'rem'
this.container.style.minWidth = this.minWidth + 'rem'
this.container.classList.remove('minimized')
DOM.dispatchEvent(window, 'resize')
}
close() {
this.container.style.width = 0
this.container.style.minWidth = 0
this.container.classList.add('minimized')
DOM.dispatchEvent(window, 'resize')
}
}
var leftUiSidePanel = new UiSidePanel({selector: 'osc-panel-container.right'}),
rightUiSidePanel = new UiSidePanel({selector: 'osc-panel-container.left'})
module.exports = {
left: leftUiSidePanel,
right: rightUiSidePanel
}

View file

@ -0,0 +1,159 @@
var UiWidget = require('./ui-widget'),
html = require('nanohtml'),
doubleClick = require('../events/double-click'),
Sortable = require('sortablejs'),
morph = require('nanomorph'),
Panel, widgetManager
class UiTree extends UiWidget {
constructor(options) {
Panel = require('../widgets/containers/panel')
widgetManager = require('../managers/widgets')
super(options)
this.mounted = false
this.list = this.container.appendChild(html`<ol style="--depth: 1"></ol`)
this.dragDummy = html`<span></span>`
this.expanded = {root: true}
this.container.addEventListener('fast-click', (event)=>{
var node = event.target
if (node.classList.contains('toggle')) {
var exp = node.parentNode.classList.toggle('expanded')
if (exp) {
this.expanded[node.parentNode.getAttribute('data-id')] = true
} else {
delete this.expanded[node.parentNode.getAttribute('data-id')]
}
}
})
doubleClick(this.container, (event)=>{
var node = event.target
if (node.classList.contains('container')) {
var exp = node.classList.toggle('expanded')
if (exp) {
this.expanded[node.getAttribute('data-id')] = true
} else {
delete this.expanded[node.getAttribute('data-id')]
}
}
}, {ignoreEditorCapture: true})
this.sortables = []
this.sortCallback = (event)=>{
var widget = widgetManager.widgets[event.to.parentNode.getAttribute('data-widget')]
if (!widget) return
this.trigger('sorted', {
widget: widget,
oldIndex: event.oldIndex,
newIndex: event.newIndex
})
}
}
clear() {
this.list.innerHTML = ''
this.mounted = false
for (var s of this.sortables) {
s.destroy()
}
this.sortables = []
}
updateTree(selectedWidgets) {
for (var s of this.sortables) {
s.destroy()
}
this.sortables = []
var content = this.parseWidgets(widgetManager.getWidgetById('root')[0], selectedWidgets)
// morph DOM
if (this.mounted) {
morph(this.list.firstChild, content)
} else {
this.list.appendChild(content)
}
// sortable lists
DOM.each(this.list, 'ol', (el)=>{
this.sortables.push(new Sortable(el, {
group: {
name: 'group-' + el.parentNode.getAttribute('data-widget'),
pull: false,
put: false
},
onEnd: this.sortCallback,
setData: (dataTransfer)=>{
dataTransfer.setDragImage(this.dragDummy, 0, 0)
},
}))
})
this.mounted = true
}
select() {
// hint selection in folded containers
DOM.each(this.list, '.contains-editing', (element)=>{
element.classList.remove('contains-editing')
})
var selected = DOM.get(this.list, '.editing')[0]
if (selected) {
var node = selected.parentNode
while (node && node !== this.list) {
if (node.classList.contains('container')) {
node.classList.add('contains-editing')
}
node = node.parentNode
}
}
}
parseWidgets(widget, selectedWidgets, depth = 1) {
var selected = selectedWidgets.includes(widget),
id = widget.getProp('id'),
node = html`<li class="${selected ? 'editing' : ''} ${!widget.getProp('visible') ? 'invisible' : ''}"
data-widget="${widget.hash}"
data-id="${id}"">
${id}</li>`
if (widget instanceof Panel) {
node.insertBefore(html`<span class="toggle no-widget-select"></span>`, node.childNodes[0])
node.classList.add('container')
if (this.expanded[id]) node.classList.add('expanded')
var sublist = node.appendChild(html`<ol style="--depth:${++depth};"></ol>`)
for (let child of widget.children) {
sublist.appendChild(this.parseWidgets(child, selectedWidgets, depth))
}
}
return node
}
}
module.exports = UiTree

View file

@ -0,0 +1,16 @@
var EventEmitter = require('../events/event-emitter')
class UiWidget extends EventEmitter {
constructor(options) {
super()
this.container = options.selector ? DOM.get(options.selector)[0] : options.element
this.parent = options.parent
}
}
module.exports = UiWidget

View file

@ -0,0 +1,16 @@
var UiWidget = require('./ui-widget'),
setScrollbarColor = require('./scrollbar-color')
class UiWorksapce extends UiWidget {
constructor(options) {
super(options)
setScrollbarColor(this.container)
}
}
module.exports = new UiWorksapce({selector: 'osc-workspace'})

View file

@ -19,23 +19,18 @@ class Menu extends Widget {
_menu:'menu',
size: {type: 'number|array', value: 200, help: [
'- If `circular` is `true`: diameter (in px)',
'- If `circular` is `false`: square size or `[width, height]` array',
'- If `layout` is `circular`: diameter (in px)',
'- Else: square size or `[width, height]` array',
]},
circular: {type: 'boolean', value: true, help: [
'Defines whether the menu should be rendered in a circle or in a box'
layout: {type: 'string', value: 'circular', choices: ['circular', 'horizontal', 'vertical', 'grid'], help: [
'Defines whether the menu\'s layout should be rendered in a circle or in a box'
]},
vertical: {type: 'boolean|number', value: false, help: [
'If `circular` is `false`, set this to `true` for vertical layout',
'Ignored when `grid` is `true`'
]},
grid: {type: 'boolean|number', value: false, help: [
'- If `circular` is `false`, set this to `true` for grid layout',
'- Can be a `number` to define the number of columns'
columns: {type: 'number', value: '', help: [
'If `layout` is `grid`, defines the number of columns'
]},
toggle: {type: 'boolean', value: false, help: 'Set to `true` to make the menu stay opened after mouse/touch release'},
doubleTap: {type: 'boolean', value: false, help: 'Set to `true` to make the menu require a double tap to be opened instead of a single tap'},
values: {type: 'array|object', value: {'Value 1':1,'Value 2':2}, help: [
values: {type: 'array|object', value: [1, 2, 3], help: [
'`Array` of possible values to switch between : `[1,2,3]`',
'`Object` of label:value pairs. Numeric labels must be prepended or appended with a white space (or any other non-numeric character) otherwise the order of the values won\'t be kept',
]},
@ -50,12 +45,19 @@ class Menu extends Widget {
constructor(options) {
super({...options, html: html`<div class="toggle"></div>`})
super({...options, html: html`
<inner>
</inner>
this.menu = this.widget.appendChild(html`<div class="menu"></div>`)
`})
this.menu = html`<menu></menu>`
this.opened = false
this.values = []
this.stringValues = []
this.selected = -1
this.value = undefined
@ -63,7 +65,6 @@ class Menu extends Widget {
this.parentScroll = [0,0]
this.opened = false
if (this.getProp('doubleTap')) {
@ -121,7 +122,6 @@ class Menu extends Widget {
} else {
this.menu.classList.add('norelease')
this.toggleCloseHandler = (e)=>{
if (!this.opened || this.menu.contains(e.target)) return
this.close()
@ -137,23 +137,22 @@ class Menu extends Widget {
open(e) {
if (this.opened) return
this.opened = true
var off = this.scrollOffset()
this.menu.style.setProperty('--x', (e.offsetX - off[0]) / PXSCALE + 'rem')
this.menu.style.setProperty('--y', (e.offsetY - off[1]) / PXSCALE + 'rem')
this.menu.classList.add('show')
this.widget.classList.add('on')
this.container.classList.add('on')
this.widget.appendChild(this.menu)
}
close() {
if (!this.opened) return
this.opened = false
this.menu.classList.remove('show')
DOM.each(this.menu, '.active', (el)=>{el.classList.remove('active')})
this.container.classList.remove('on')
this.widget.classList.remove('on')
this.widget.removeChild(this.menu)
}
@ -187,7 +186,7 @@ class Menu extends Widget {
var nval = 0,
i = 0,
circular = this.getProp('circular'),
circular = this.getProp('layout') === 'circular',
values = this.getProp('values'),
weights = this.getProp('weights'),
totalWeight
@ -197,7 +196,7 @@ class Menu extends Widget {
}
this.values = []
this.widget.removeChild(this.menu)
if (this.opened) this.widget.removeChild(this.menu)
this.menu.innerHTML = ''
@ -211,6 +210,11 @@ class Menu extends Widget {
let angle = Math.min(360 * weights[i] / totalWeight, 120),
skew = 90 - angle
this.values.push(values[k])
if (typeof values[k] == 'object') {
this.stringValues.push(JSON.stringify(values[k]))
} else {
this.stringValues.push(0)
}
this.menu.appendChild(html`
<div class="item" style="${circular ? `transform: rotate(${ac}deg) skew(${skew}deg)` : `flex: ${weights[i]}`}">
<div style="${circular ? `transform: skew(${-skew}deg) rotate(${-90 + angle / 2}deg)` : ''}"><span style="${circular ? `transform: rotate(${-ac + 90 - angle / 2}deg)` : ''}">${raw(iconify(parseFloat(k) != k ? k : values[k]))}</span></div>
@ -224,20 +228,18 @@ class Menu extends Widget {
this.setValue(this.value)
this.widget.appendChild(this.menu)
if (!this.getProp('circular') && this.getProp('grid')) {
this.container.style.setProperty('--grid-columns', this.getProp('grid') === true ? parseInt(nval / 2) : parseInt(this.getProp('grid')))
}
if (this.opened) this.widget.appendChild(this.menu)
}
setMode() {
this.container.classList.toggle('box', !this.getProp('circular'))
this.container.classList.toggle('circular', this.getProp('circular'))
this.container.classList.toggle('grid', this.getProp('grid') && !this.getProp('circular'))
this.container.classList.toggle('vertical', this.getProp('vertical') && !this.getProp('circular'))
var layout = this.getProp('layout')
this.container.classList.toggle('box', layout !== 'circular')
this.container.classList.toggle('circular', layout === 'circular')
this.container.classList.toggle('grid', layout === 'grid')
this.container.classList.toggle('vertical', layout === 'vertical')
this.container.style.setProperty('--grid-columns', this.getProp('columns') === '' ? parseInt(this.values.length / 2) : parseInt(this.getProp('columns')))
}
@ -257,22 +259,6 @@ class Menu extends Widget {
}
scrollOffset() {
var parent = this.parent,
scrollOffset = [0,0]
while (parent && parent.props && parent.getProp('type') !== 'tab') {
scrollOffset[0] += parent.widget.scrollLeft
scrollOffset[1] += parent.widget.scrollTop
parent = parent.parent
if (parent.getProp('type') === 'modal') break
}
return scrollOffset
}
setValue(v,options={}) {
var i = this.values.indexOf(v)
@ -284,6 +270,7 @@ class Menu extends Widget {
DOM.each(this.menu, '.on', (el)=>{el.classList.remove('on')})
if (i > -1) DOM.get(this.menu, '.item')[i].classList.add('on')
this.widget.textContent = this.stringValues[i] || this.value
if (options.send) this.sendValue()
if (options.sync) this.changed(options)
@ -299,16 +286,12 @@ class Menu extends Widget {
case 'size':
this.setSize()
return
case 'vertical':
this.setMode()
return
case 'circular':
this.setMode()
case 'layout':
this.parseValues()
return
case 'grid':
this.setMode()
if (this.getProp('grid') === true) this.parseValues()
return
case 'columns':
this.setMode()
return
case 'values':
this.parseValues()
@ -333,9 +316,8 @@ class Menu extends Widget {
Menu.dynamicProps = Menu.prototype.constructor.dynamicProps.concat(
'size',
'circular',
'vertical',
'grid',
'layout',
'columns',
'values'
)

View file

@ -1,160 +0,0 @@
var Widget = require('../common/widget'),
doubletab = require('../mixins/double_tap'),
osc = require('../../osc'),
html = require('nanohtml')
class Push extends Widget {
static description() {
return 'On / off button that turns off when released.'
}
static defaults() {
return super.defaults({
_push: 'push',
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'},
on: {type: '*', value: 1, help: [
'Set to `null` to send send no argument in the osc message',
'Can be an `object` if the type needs to be specified (see preArgs)'
]},
off: {type: '*', value: 0, help: [
'Set to `null` to send send no argument in the osc message',
'Can be an `object` if the type needs to be specified (see preArgs)'
]},
norelease: {type: 'boolean', value: false, help: 'Set to `true` to prevent sending any osc message when releasing the button'},
}, ['default'])
}
constructor(options) {
super({...options, html: html`<div class="toggle"></div>`})
this.state = 0
this.active = null
this.lastChanged = 'state'
if (this.getProp('doubleTap')) {
doubletab(this.widget, ()=>{
if (this.active) return
this.setValuePrivate(this.getProp('on'),{send:true,sync:true})
})
} else {
this.on('draginit',()=>{
if (this.active) return
this.setValuePrivate(this.getProp('on'),{send:true,sync:true})
}, {element: this.widget})
}
this.on('dragend',()=>{
if (!this.active) return
this.setValuePrivate(this.getProp('off'),{send:true,sync:true})
}, {element: this.widget})
this.value = this.getProp('off')
}
updateValue(){
this.value = this[this.lastChanged] ?
this.getProp('on') != null && this.getProp('on').value !== undefined ? this.getProp('on').value : this.getProp('on')
:
this.getProp('off') != null && this.getProp('off').value !== undefined ? this.getProp('off').value : this.getProp('off')
}
setValuePrivate(v,options={}) {
if (typeof v == 'object' && v !== null) v = v.value
if (v===this.getProp('on') || (this.getProp('on') != null && v === this.getProp('on').value && v !== undefined)) {
this.widget.classList.add('active')
this.container.classList.add('active')
this.active = options
this.lastChanged = 'active'
this.updateValue()
if (options.send) this.sendValue()
if (options.sync) this.changed(options)
} else if (v===this.getProp('off') || (this.getProp('off') != null && v === this.getProp('off').value && v !== undefined)) {
this.widget.classList.remove('active')
this.container.classList.remove('active')
this.active = null
this.lastChanged = 'active'
this.updateValue()
if (options.send) this.sendValue(null, {syncOnly: this.getProp('norelease')})
if (options.sync) this.changed(options)
}
}
setValue(v,options={}) {
if (!options.fromExternal) {
if (!options.fromState) this.setValuePrivate(v,options)
return
}
if (typeof v == 'object' && v !== null) v = v.value
if (v===this.getProp('on') || (this.getProp('on') != null && v === this.getProp('on').value && v !== undefined)) {
this.widget.classList.add('on')
this.container.classList.add('on')
this.state = 1
if (options.send) this.sendValue()
this.lastChanged = 'state'
if (options.sync) this.changed(options)
} else if (v===this.getProp('off') || (this.getProp('off') != null && v === this.getProp('off').value && v !== undefined)) {
this.widget.classList.remove('on')
this.container.classList.remove('on')
this.state = 0
if (options.send) this.sendValue()
this.lastChanged = 'state'
if (options.sync) this.changed(options)
}
}
sendValue(overrides, options={}) {
if (!options.syncOnly) {
super.sendValue(overrides, options)
} else {
osc.sync({
h: this.hash,
v: this.value
})
}
}
onRemove() {
if (this.active) this.setValuePrivate(this.getProp('off'), this.active)
super.onRemove()
}
}
Push.dynamicProps = Push.prototype.constructor.dynamicProps.concat(
'on',
'off',
'norelease'
)
module.exports = Push

View file

@ -23,7 +23,12 @@ module.exports = class Switch extends Widget {
'`Array` of possible values to switch between : `[1,2,3]`',
'`Object` of `"label":value` pairs. Numeric labels must be prepended or appended with a white space (or any other non-numeric character) otherwise the order of the values won\'t be kept',
]},
traversing: {type: 'boolean', value: true, help: 'Set to `false` to disable traversing gestures'},
mode: {type: 'string', value: 'tap', choices: ['tap', 'slide', 'click'], help: [
'Interraction mode:',
'- `tap`: activates when the pointer is down but prevents further scrolling',
'- `slide`: same as `tap` but allows sliding between values',
'- `click`: activates upon click only and allows further scrolling',
]},
})
@ -31,10 +36,9 @@ module.exports = class Switch extends Widget {
constructor(options) {
super({...options, html: html`<div class="switch"></div>`})
super({...options, html: html`<inner></inner>`})
if (this.getProp('horizontal')) this.widget.classList.add('horizontal')
if (this.getProp('horizontal')) this.container.classList.add('horizontal')
this.values = []
this.stringValues = []
@ -61,7 +65,7 @@ module.exports = class Switch extends Widget {
if (this.getProp('showValues') && !isArray) label = label + ': ' + (this.stringValues[this.stringValues.length - 1] || values[k])
this.widget.appendChild(html`
<div class="value"> ${raw(iconify(label))}</div>
<value> ${raw(iconify(label))}</value>
`)
}
@ -92,10 +96,15 @@ module.exports = class Switch extends Widget {
}
this.on('draginit', dragCallback , {element: this.widget})
this.on('drag', (e)=>{
if (this.getProp('traversing') || e.traversing) dragCallback(e, true)
} , {element: this.widget})
if (this.getProp('mode') === 'tap' || this.getProp('mode') === 'slide') {
this.on('draginit', dragCallback , {element: this.widget})
this.on('drag', (e)=>{
if (this.getProp('mode') === 'slide' || e.traversing) dragCallback(e, true)
} , {element: this.widget})
} else {
this.widget.addEventListener('click', dragCallback)
}
}
@ -109,7 +118,7 @@ module.exports = class Switch extends Widget {
if (i!=-1) {
this.value = this.values[i]
DOM.get(this.widget, '.value')[i].classList.add('on')
DOM.get(this.widget, 'value')[i].classList.add('on')
if (options.send) this.sendValue(this.value)
if (options.sync) this.changed(options)
} else {

View file

@ -16,8 +16,6 @@ class Toggle extends Widget {
_toggle: 'toggle',
doubleTap: {type: 'boolean', value: false, help: 'Set to `true` to make the button require a double tap to be toggled instead of a single tap'},
led: {type: 'boolean', value: false, help: 'Set to `true` to display the toggle\'s state with a led'},
on: {type: '*', value: 1, help: [
'Set to `null` to send send no argument in the osc message',
'Can be an `object` if the type needs to be specified (see preArgs)'
@ -25,7 +23,14 @@ class Toggle extends Widget {
off: {type: '*', value: 0, help: [
'Set to `null` to send send no argument in the osc message',
'Can be an `object` if the type needs to be specified (see preArgs)'
]}
]},
mode: {type: 'string', value: 'toggle', choices: ['toggle', 'push', 'tap'], help: [
'Interraction mode:',
'- `toggle` (classic on/off switch)',
'- `push` (press & release)',
'- `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'},
})
@ -33,65 +38,121 @@ class Toggle extends Widget {
constructor(options) {
super({...options, html: html`<div class="toggle"></div>`})
super({...options, html: html`<inner></inner>`})
this.state = 0
this.active = false
if (this.getProp('led')) this.container.classList.add('led')
if (this.getProp('doubleTap')) {
var tap = this.getProp('mode') === 'tap',
push = this.getProp('mode') === 'push' || tap
doubletab(this.widget, ()=>{
var newVal = this.state?this.getProp('off'):this.getProp('on')
this.setValue(newVal,{sync:true,send:true})
})
if (push) {
if (this.getProp('doubleTap')) {
doubletab(this.container, ()=>{
this.setValue(this.getProp('on'), {sync: true, send: true})
})
} else {
this.on('draginit',()=>{
if (this.active) return
this.active = true
this.setValue(this.getProp('on'), {sync: true, send: true})
}, {element: this.container})
}
this.on('dragend',()=>{
this.active = false
this.setValue(this.getProp('off'), {sync: true, send: !tap})
}, {element: this.container})
} else {
this.on('draginit',()=>{
if (this.active) return
this.active = true
var newVal = this.state?this.getProp('off'):this.getProp('on')
this.setValue(newVal,{sync:true,send:true})
}, {element: this.widget})
if (this.getProp('doubleTap')) {
this.on('dragend',()=>{
this.active = false
}, {element: this.widget})
doubletab(this.container, ()=>{
this.setValue(this.state ? this.getProp('off') : this.getProp('on'), {sync: true, send: true})
})
} else {
this.on('draginit',()=>{
if (this.active) return
this.active = true
this.setValue(this.state ? this.getProp('off') : this.getProp('on'), {sync: true, send: true})
}, {element: this.container})
this.on('dragend',()=>{
this.active = false
}, {element: this.container})
}
}
this.value = this.getProp('off')
}
setValue(v,options={}) {
if (typeof v == 'object' && v !== null) v = v.value
if (v===this.getProp('on') || (this.getProp('on') != null && v === this.getProp('on').value && v !== undefined)) {
this.widget.classList.add('on')
this.container.classList.add('on')
this.state = 1
this.value = this.getProp('on')
if (options.send) this.sendValue()
} else if (v===this.getProp('off') || (this.getProp('off') != null && v === this.getProp('off').value && v !== undefined)) {
this.widget.classList.remove('on')
this.container.classList.remove('on')
this.state = 0
this.value = this.getProp('off')
if (options.send) this.sendValue()
}
if (options.sync) this.changed(options)
}
onRemove() {
if (this.active && this.getProp('mode') === 'push') this.setValue(this.getProp('off'), {sync: true, send: true})
super.onRemove()
}
}
Toggle.dynamicProps = Toggle.prototype.constructor.dynamicProps.concat(
'on',
'off'
'off',
'norelease'
)
module.exports = Toggle

View file

@ -1,4 +1,6 @@
var Widget = require('./widget')
var Widget = require('./widget'),
resize = require('../../events/resize')
class CanvasQueue {
@ -65,12 +67,13 @@ class Canvas extends Widget {
super(options)
this.canvas = DOM.get(this.widget, 'canvas')[0]
this.canvas = DOM.get(this.container, 'canvas')[0]
this.ctx = this.canvas.getContext('2d',{
desynchronized: true,
lowLatency: true,
alpha: true
alpha: true,
preserveDrawingBuffer: true // avoid flickering
})
this.height = undefined
@ -82,6 +85,7 @@ class Canvas extends Widget {
this.visible = false
this.colors = {}
this.cssVars = {}
this.on('resize', this.resizeHandleProxy.bind(this), {element: this.canvas})
@ -121,7 +125,7 @@ class Canvas extends Widget {
if (!this.visible) this.visible = true
requestAnimationFrame(this.draw.bind(this))
this.batchDraw()
}
@ -129,6 +133,20 @@ class Canvas extends Widget {
style = style || window.getComputedStyle(this.canvas)
this.cssVars.padding = parseFloat(style.getPropertyValue('--widget-padding')) * PXSCALE // rem unit
this.cssVars.colorWidget = style.getPropertyValue('--color-widget')
this.cssVars.colorFill = style.getPropertyValue('--color-fill')
this.cssVars.colorStroke = style.getPropertyValue('--color-stroke')
this.cssVars.colorForeground = style.getPropertyValue('--color-foreground')
this.cssVars.alphaStroke = parseFloat(style.getPropertyValue('--alpha-stroke'))
this.cssVars.alphaFillOff = parseFloat(style.getPropertyValue('--alpha-fill-off'))
this.cssVars.alphaFillOn = parseFloat(style.getPropertyValue('--alpha-fill-on'))
this.colors.custom = style.getPropertyValue('--color-custom')
this.colors.track = style.getPropertyValue('--color-track')
this.colors.text = style.getPropertyValue('--color-text')
@ -188,11 +206,20 @@ class Canvas extends Widget {
switch (propName) {
case 'color':
this.cacheCanvasStyle()
this.batchDraw()
case 'css':
case 'colorWidget':
case 'colorFill':
case 'colorStroke':
case 'alphaStroke':
case 'alphaFillOff':
case 'alphaFillOn':
setTimeout(()=>{
this.cacheCanvasStyle()
this.batchDraw()
},10)
return
case 'padding':
resize.check(this.widget)
}
return ret

View file

@ -45,13 +45,15 @@ class Widget extends EventEmitter {
var defaults = {
_widget:'widget',
type: {type: 'string', value: 'auto', help: ''},
id: {type: 'string', value: 'auto', help: 'Widgets sharing the same `id` will act as clones and update each other\'s value(s) without sending extra osc messages.' },
linkId: {type: 'string|array', value: '', help: [
'Widgets sharing the same `linkId` update each other\'s value(s) AND send their respective osc messages.',
'When prefixed with >>, the `linkId` will make the widget act as a master (sending but not receiving)',
'When prefixed with <<, the `linkId` will make the widget act as a slave (receiving but not sending)'
label: {type: 'string|boolean', value: 'auto', help: [
'Set to `false` to hide completely',
'Insert icons using the prefix ^ followed by the icon\'s name : ^play, ^pause, etc (see https://fontawesome.com/icons?d=gallery&s=solid&m=free)'
]},
visible: {type: 'boolean', value: true, help: 'Set to `false` to hide the widget.'},
_geometry:'geometry',
@ -68,17 +70,29 @@ class Widget extends EventEmitter {
_style:'style',
label: {type: 'string|boolean', value: 'auto', help: [
'Set to `false` to hide completely',
'Insert icons using the prefix ^ followed by the icon\'s name : ^play, ^pause, etc (see https://fontawesome.com/icons?d=gallery&s=solid&m=free)'
]},
color: {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.'},
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.'},
css: {type: 'string', value: '', help: 'CSS rules. See <a href="https://openstagecontrol.ammd.net/docs/css-tips/">documentation</a>.'},
_value: 'value',
default: {type: '*', value: '', help: 'If set, the widget will be initialized with this value when the session is loaded.'},
value: {type: '*', value: '', help: 'Define the widget\'s value depending on other widget\'s values / properties using property inheritance and property maths'},
value: {type: '*', value: '', help: 'Define the widget\'s value depending on other widget\'s values / properties using the advanced property syntax'},
linkId: {type: 'string|array', value: '', help: [
'Widgets sharing the same `linkId` update each other\'s value(s) AND send their respective osc messages.',
'When prefixed with >>, the `linkId` will make the widget act as a master (sending but not receiving)',
'When prefixed with <<, the `linkId` will make the widget act as a slave (receiving but not sending)'
]},
_osc: 'osc',
@ -118,7 +132,8 @@ class Widget extends EventEmitter {
}
for (var m in push) {
alterDefaults[m] = push[m]
if (!alterDefaults[m]) alterDefaults[m] = []
Object.assign(alterDefaults[m], push[m])
}
alterDefaults._props = function() {
@ -167,19 +182,15 @@ class Widget extends EventEmitter {
this.precision = Math.min(20,Math.max(this.getProp('precision', undefined, false),0))
}
if (options.container) {
this.container = html`
<div class="widget ${options.props.type}-container" id="${this.hash}" data-widget="${this.hash}"></div>
`
this.label = html`<div class="label"></div>`
this.container.appendChild(this.label)
this.container.appendChild(this.widget)
this.container._widget_instance = this
this.setContainerStyles()
} else {
this.container = dummyDOM
}
this.container = html`
<div class="widget ${options.props.type}-container" id="${this.hash}" data-widget="${this.hash}"></div>
`
this.label = html`<label></label>`
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()
}
@ -586,35 +597,9 @@ class Widget extends EventEmitter {
propValue = propValue.replace(/#\{(?:[^{}]|\{[^{}]*\})*\}/g, (m)=>{
// one bracket nesting allowed, if we need two: #\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\}
// if (!this.mathjsDeprecationWarned) {
// this.mathjsDeprecationWarned = true
// ipc.send('error', `Warning: Widget#${this.getProp('id')} MathJS syntax (#{}) is deprecated and will be removed in the future. Consider using the Javascript syntax instead.`)
// }
//TODO: js one-liner
// unescape brackets (not needed anymore, just here for backward compatibility)
m = m.replace(/\\(\{|\})/g, '$1')
// espace multiline strings
m = m.replace(/`([^`]*)`/g, (m)=>{
return m.replace(/"/g,'\\"').replace(/\n/g,'\\n').replace(/`/g,'"')
})
if (!this.parsers[m]) this.parsers[m] = math.compile(m.substr(2, m.length - 3).trim())
for (var k in defaultScope) {
if (mathscope[k] === undefined) mathscope[k] = defaultScope[k]
}
let r = this.parsers[m].eval(mathscope)
if (r instanceof math.type.ResultSet && !r.entries.length) {
r = ''
} else if (typeof r === 'object' && r !== null && r.valueOf) {
r = r.valueOf()
if (Array.isArray(r) && r.length == 1) r = r[0]
}
return typeof r != 'string' ? JSON.stringify(r) : r
return ''
})
} catch (err) {
console.log((this.getProp('id') || this.props.id) + '.' + propName + ': #{} error:\n' + err)
@ -758,6 +743,11 @@ class Widget extends EventEmitter {
resize.check(this.container)
return
case 'visible':
this.setContainerStyles(['visibility'])
resize.check(this.container)
return
case 'label':
this.setContainerStyles(['label'])
if (oldPropValue === false || this.getProp('label') === false) {
@ -774,7 +764,13 @@ class Widget extends EventEmitter {
}
return
case 'color':
case 'colorWidget':
case 'colorFill':
case 'colorStroke':
case 'alphaStroke':
case 'alphaFillOff':
case 'alphaFillOn':
case 'padding':
this.setContainerStyles(['color'])
return
@ -808,11 +804,16 @@ class Widget extends EventEmitter {
}
setContainerStyles(styles = ['geometry', 'label', 'css', 'color']) {
setContainerStyles(styles = ['geometry', 'label', 'css', 'color', 'visibility']) {
if (styles.includes('visibility')) {
this.container.style.display = this.getProp('visible') ? '' : 'none'
}
if (styles.includes('geometry')) {
// geometry
var absolutePos = false
for (let d of ['width', 'height', 'top', 'left']) {
let val = this.getProp(d),
geometry
@ -827,9 +828,12 @@ class Widget extends EventEmitter {
this.container.style[d] = geometry
if (d === 'width') this.container.style.minWidth = geometry
if (d === 'height') this.container.style.minHeight = geometry
this.container.classList.toggle('absolute-position', geometry && (d === 'top' || d === 'left'))
absolutePos = absolutePos || geometry && (d === 'top' || d === 'left')
}
}
this.container.classList.toggle('absolute-position', absolutePos)
}
@ -838,6 +842,7 @@ class Widget extends EventEmitter {
// label
if (this.getProp('label') === false) {
this.container.classList.add('nolabel')
this.label.innerHTML = ''
} else {
this.container.classList.remove('nolabel')
var label = this.getProp('label') == 'auto'?
@ -845,6 +850,7 @@ class Widget extends EventEmitter {
iconify(this.getProp('label'))
this.label.innerHTML = label
this.container.appendChild(this.label)
}
}
@ -925,10 +931,18 @@ class Widget extends EventEmitter {
if (styles.includes('color')) {
// color
this.container.style.setProperty('--color-custom', this.getProp('color') && this.getProp('color') != 'auto' ? this.getProp('color') : '')
this.container.style.setProperty('--color-widget', this.getProp('colorWidget') != 'auto' ? this.getProp('colorWidget') : '')
this.container.style.setProperty('--color-fill', this.getProp('colorFill') != 'auto' ? this.getProp('colorFill') : '')
this.container.style.setProperty('--color-stroke', this.getProp('colorStroke') != 'auto' ? this.getProp('colorStroke') : '')
this.container.style.setProperty('--alpha-stroke', this.getProp('alphaStroke') != 'auto' ? parseFloat(this.getProp('alphaStroke')) : '')
this.container.style.setProperty('--alpha-fill-on', this.getProp('alphaFillOn') != 'auto' ? parseFloat(this.getProp('alphaFillOn')) : '')
this.container.style.setProperty('--alpha-fill-off', this.getProp('alphaFillOff') != 'auto' ? parseFloat(this.getProp('alphaFillOff')) : '')
this.container.style.setProperty('--widget-padding', this.getProp('padding') != 'auto' ? parseFloat(this.getProp('padding')) + 'rem' : '')
}
return style
}
@ -951,14 +965,26 @@ class Widget extends EventEmitter {
Widget.parsersContexts = {}
Widget.dynamicProps = [
'visible',
'label',
'top',
'left',
'height',
'width',
'label',
'colorWidget',
'colorFill',
'colorStroke',
'alphaStroke',
'alphaFillOff',
'alphaFillOn',
'padding',
'css',
'value',
'color',
'precision',
'address',
'preArgs',

View file

@ -26,13 +26,14 @@ class Modal extends Panel {
popupHeight: {type: 'number|percentage', value: '80%', help: 'Modal popup\'s size'},
popupLeft: {type: 'number|percentage', value: 'auto', help: 'Modal popup\'s position'},
popupTop: {type: 'number|percentage', value: 'auto', help: 'Modal popup\'s position'},
layout: {type: 'string', value: 'default', choices: ['default', 'vertical', 'horizontal'], help:''},
scroll: {type: 'boolean', value: true, help: 'Set to `false` to disable scrollbars'},
variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
}, [], {
_chidlren:'children',
variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
widgets: {type: 'array', value: [], help: 'Each element of the array must be a widget object'},
value: {type: 'integer', value: '', help: [
'Defines the modal\'s state:`0` for closed, `1` for opened'
@ -52,12 +53,13 @@ class Modal extends Panel {
<div class="popup">
<div class="popup-wrapper">
<div class="popup-title closable"><span class="popup-label"></span><span class="closer">${raw(icon('times'))}</span></div>
<div class="popup-content"></div>
<div class="popup-content widget panel-container not-editable contains-widgets"></div>
</div>
</div>
`
this.container.appendChild(this.popup)
this.popupContent = DOM.get(this.popup, '.popup-content')[0]
// convert dimensions / coordinates to rem
var geometry = {}
@ -109,6 +111,12 @@ class Modal extends Panel {
this.init = false
this.labelChange = true
this.popupContent.classList.add('layout-' + this.getProp('layout'))
this.popupContent.style.setProperty('--widget-padding', this.getProp('padding') != 'auto' ? parseFloat(this.getProp('padding')) + 'rem' : '')
}
setValue(v, options={}) {
@ -118,7 +126,7 @@ class Modal extends Panel {
this.value = v ? 1 : 0
if (!this.init && this.value) {
DOM.get(this.popup, '.popup-content')[0].appendChild(this.widget)
this.popupContent.appendChild(this.widget)
this.init = true
}
@ -195,7 +203,7 @@ class Modal extends Panel {
if (!this.popup) return
var label = this.getProp('popupLabel') ? iconify(this.getProp('popupLabel')) : DOM.get(this.container, '> .label')[0].innerHTML
var label = this.getProp('popupLabel') ? iconify(this.getProp('popupLabel')) : this.label.innerHTML
DOM.get(this.popup, '.popup-title .popup-label')[0].innerHTML = label
this.labelChange = false
@ -221,6 +229,18 @@ class Modal extends Panel {
}
setContainerStyles(styles = ['geometry', 'label', 'css', 'color', 'visibility']) {
super.setContainerStyles(styles)
if (styles.includes('color') && this.popupContent) {
this.popupContent.style.setProperty('--widget-padding', this.getProp('padding') != 'auto' ? parseFloat(this.getProp('padding')) + 'rem' : '')
}
}
}
Modal.dynamicProps = Modal.prototype.constructor.dynamicProps.concat(

View file

@ -2,7 +2,9 @@ var Container = require('../common/container'),
widgetManager = require('../../managers/widgets'),
parser = require('../../parser'),
html = require('nanohtml'),
raw = require('nanohtml/raw')
raw = require('nanohtml/raw'),
{enableTraversingGestures, disableTraversingGestures} = require('../../events/drag'),
setScrollbarColor = require('../../ui/scrollbar-color')
class Panel extends Container() {
@ -19,18 +21,19 @@ class Panel extends Container() {
_panel:'panel',
scroll: {type: 'boolean', value: true, help: 'Set to `false` to disable scrollbars'},
border: {type: 'boolean', value: true, help: 'By default, widgets in panels/strip have their border disabled, except for panels and strips. Set to `false` to apply this rule to the panel too'},
layout: {type: 'string', value: 'default', choices: ['default', 'vertical', 'horizontal'], help:''},
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'},
}, [], {
_children:'children',
variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
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'},
value: {type: 'integer', value: '', help: [
'Defines currently opened tab in the widget',
'Defines currently widgeted tab in the widget',
'A tab can be opened only by setting its parent\'s value'
]},
@ -44,31 +47,41 @@ class Panel extends Container() {
super({...options, html: html`<div class="panel"></div>`})
if (this.getProp('scroll') === false) this.widget.classList.add('noscroll')
if (this.getProp('border') === false) this.container.classList.add('noborder')
if (this.getProp('tabs') && this.getProp('tabs').length) this.widget.classList.add('has-tabs')
if (this.getProp('scroll') === false) this.container.classList.add('noscroll')
this.container.classList.add('layout-' + this.getProp('layout'))
if (this.getProp('tabs') && this.getProp('tabs').length) {
this.container.classList.add('contains-tabs')
} else {
this.container.classList.add('contains-widgets')
}
this.value = -1
this.tabs = []
if (this.getProp('tabs') && this.getProp('tabs').length) {
this.widget.appendChild(html`<div class="navigation"><ul class="tablist"></ul></div>`)
this.navigation = DOM.get(this.widget, '.tablist')[0]
this.wrapper = this.widget.appendChild(html`<div class="tabs-wrapper"></div>`)
this.navigation = this.widget.appendChild(html`<div class="navigation"></div>`)
this.children = options.children || new Array(this.getProp('tabs').length)
for (let i = 0; i < this.children.length; i++) {
if (this.children[i]) {
this.wrapper.appendChild(this.children[i].container)
this.widget.appendChild(this.children[i].container)
this.children[i].mounted = true
this.children[i].parent = this
this.children[i].parentNode = this.wrapper
this.children[i].parentNode = this.widget
} else {
parser.parse({
data: this.getProp('tabs')[i],
parentNode: this.wrapper,
parentNode: this.widget,
parent: this,
tab: true,
index: i
@ -130,6 +143,7 @@ class Panel extends Container() {
}
if (this.getProp('traversing')) this.setTraversing()
}
@ -138,16 +152,21 @@ class Panel extends Container() {
this.navigation.innerHTML = ''
this.tabs = []
DOM.each(this.wrapper, '> .widget', (tab)=>{
DOM.each(this.widget, '> .widget', (tab)=>{
let widget = widgetManager.getWidgetByElement(tab),
style = widget.getProp('color') == 'auto' ? '' : `--color-custom:${widget.getProp('color')}`
style = ''
style += widget.getProp('colorWidget') === 'auto' ? '' : `--color-widget:${widget.getProp('colorWidget')};`
style += widget.getProp('colorFill') === 'auto' ? '' : `--color-fill:${widget.getProp('colorFill')};`
if (!widget.getProp('visible')) style += 'display:none;'
this.tabs.push(widget)
this.navigation.appendChild(html`
<li class="tablink" data-widget="${widget.hash}" style="${style}">
<a><span>${raw(DOM.get(tab, '> .label')[0].innerHTML)}</span></a>
</li>
<div class="tablink" data-widget="${widget.hash}" style="${style}">
${widget.label.innerHTML}
</div>
`)
})
@ -167,7 +186,7 @@ class Panel extends Container() {
this.value = v
this.tabs[v].show()
DOM.each(this.navigation, 'li', (el)=>{el.classList.remove('on')})[v].classList.add('on')
DOM.each(this.navigation, 'div', (el)=>{el.classList.remove('on')})[v].classList.add('on')
if (options.send) this.sendValue()
if (options.sync) this.changed(options)
@ -192,9 +211,18 @@ class Panel extends Container() {
switch (propName) {
case 'color':
case 'traversing':
this.setTraversing()
return
case 'colorWidget':
case 'colorFill':
case 'colorStroke':
case 'alphaStroke':
case 'alphaFillOff':
case 'alphaFillOn':
for (var w of this.children) {
if (w) w.onPropChanged('color')
if (w) w.onPropChanged(propName)
}
return
@ -202,6 +230,30 @@ class Panel extends Container() {
}
setContainerStyles(styles = ['geometry', 'label', 'css', 'color', 'visibility']) {
super.setContainerStyles(styles)
if (styles.includes('color') && this.getProp('scroll')) {
setScrollbarColor(this.container)
}
}
setTraversing(update) {
var traversing = this.getProp('traversing')
disableTraversingGestures(this.widget)
if (traversing) {
enableTraversingGestures(this.widget, {smart: typeof traversing === 'string' && traversing.match(/smart|auto/)})
}
}
onRemove() {
this.off('resize')
@ -211,7 +263,8 @@ class Panel extends Container() {
}
Panel.dynamicProps = Panel.prototype.constructor.dynamicProps.concat(
'variables'
'variables',
'traversing'
)
module.exports = Panel

View file

@ -1,11 +1,11 @@
var Panel = require('./panel'),
Widget = require('../common/widget'),
StaticProperties = require('../mixins/static_properties'),
{icon} = require('../../ui/utils'),
{enableTraversingGestures, disableTraversingGestures} = require('../../events/drag'),
html = require('nanohtml'),
raw = require('nanohtml/raw')
class Root extends Panel {
class Root extends StaticProperties(Panel, {scroll: false, label: false, id: 'root'}) {
static description() {
@ -15,17 +15,22 @@ class Root extends Panel {
static defaults() {
return Widget.defaults({}, ['label', '_geometry', 'left', 'top', 'width', 'height'], {
return Widget.defaults({
_panel:'panel',
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'], {
_children:'children',
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'},
tabs: {type: 'array', value: [{}], help: 'Each element of the array must be a tab object'},
id: {type: 'string', value: 'root', help: 'Widgets sharing the same id will act as clones and update each other\'s value(s) without sending extra osc messages' },
tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object. A panel cannot contain widgets and tabs simultaneously'},
value: {type: 'integer', value: '', help: [
'Defines currently opened tab in the widget',
'Defines currently widgeted tab in the widget',
'A tab can be opened only by setting its parent\'s value'
]},
@ -36,22 +41,15 @@ class Root extends Panel {
constructor(options) {
options.root = true
options.props.id = 'root'
options.props.scroll = true
options.props.label = false
super(options)
this.widget.classList.add('root')
this.disabledProps.push('id')
DOM.each(this.widget, '> .navigation', (el)=>{
el.classList.add('main')
})
if (this.getProp('traversing')) this.setTraversing()
}
createNavigation() {
@ -59,43 +57,15 @@ class Root extends Panel {
super.createNavigation()
this.navigation.appendChild(html`
<li class="not-editable">
<a id="open-toggle" class="${DOM.get('#sidepanel')[0].classList.contains('sidepanel-open')?'sidepanel-open':''}">${raw(icon('bars'))}</a>
</li>
<div class="tools not-editable">${raw(icon('expand'))}></div>
<div class="tools not-editable">${raw(icon('pen'))}></div>
<div class="tools not-editable">${raw(icon('ellipsis-v'))}></div>
`)
}
setTraversing(update) {
var traversing = this.getProp('traversing')
disableTraversingGestures(this.widget)
if (traversing) {
enableTraversingGestures(this.widget, {smart: typeof traversing === 'string' && traversing.match(/smart|auto/)})
}
}
onPropChanged(propName, options, oldPropValue) {
if (super.onPropChanged(...arguments)) return true
switch (propName) {
case 'traversing':
this.setTraversing()
return
}
}
}
Root.dynamicProps = Root.prototype.constructor.dynamicProps.concat(
'traversing'
)
module.exports = Root

View file

@ -1,66 +0,0 @@
var Panel = require('./panel'),
Widget = require('../common/widget')
module.exports = class Strip extends Panel {
static description() {
return 'Widget container that display its children in a single column or row.'
}
static defaults() {
return Widget.defaults({
_strip: 'strip',
scroll: {type: 'boolean', value: true, help: 'Set to `false` to disable scrollbars'},
horizontal: {type: 'boolean', value: false, help: 'Set to `true` to display widgets horizontally'},
stretch: {type: 'boolean', value: false, help: 'Set to `true` to stretch widgets evenly'},
border: {type: 'boolean', value: true, help: 'By default, widgets in panels/strip have their border disabled, except for panels and strips. Set to `false` to apply this rule to the panel too'},
spacing: {type: 'integer|percentage', value: 0, help: 'Adds space between widgets. Percents are always relative to the strips width'}
}, [], {
_children:'children',
variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
widgets: {type: 'array', value: [], help: [
'Each element of the array must be a widget object',
'- By default, children widgets that don\'t have an explicit `width`/`height` set will be shrinked to respect the sizes specified by others',
'- Adding `flex:1;` to a children\'s `css` will give it the ability the fill the remaining space',
'- Multiple children can have a `flex:x;` css property (`x` will ponderate their expansion)'
]}
})
}
constructor(options) {
var defaults = Panel.defaults()._props()
for (var k in defaults) {
if (!options.props.hasOwnProperty(k))
options.props[k] = defaults[k]
}
super(options)
this.disabledProps = []
if (this.getProp('spacing')) {
var spacing = this.getProp('spacing')
if (!isNaN(spacing)) spacing += 'rem'
this.widget.style.setProperty('--spacing', spacing)
}
this.container.classList.add(this.getProp('horizontal') ? 'horizontal' : 'vertical')
if (this.getProp('stretch')) this.container.classList.add('stretch')
}
setValue(){}
getValue(){}
}

View file

@ -1,8 +1,9 @@
var Panel = require('./panel'),
Widget = require('../common/widget'),
StaticProperties = require('../mixins/static_properties'),
resize = require('../../events/resize')
module.exports = class Tab extends Panel {
module.exports = class Tab extends StaticProperties(Panel, {scroll: true}) {
static description() {
@ -16,18 +17,20 @@ module.exports = class Tab extends Panel {
_tab:'tab',
detached: {type: 'boolean', value: true, help: 'Set to `false` if the tab contains `frame` widgets that should not be reloaded when the tab opens'}
detached: {type: 'boolean', value: true, help: 'Set to `false` if the tab contains `frame` widgets that should not be reloaded when the tab opens'},
layout: {type: 'string', value: 'default', choices: ['default', 'vertical', 'horizontal'], help:''},
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'], {
}, ['_geometry', 'left', 'top', 'width', 'height', 'scroll'], {
_children:'children',
variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
widgets: {type: 'array', value: [], help: 'Each element of the array must be a widget object. A tab cannot contain widgets and tabs simultaneously'},
tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object. A tab cannot contain widgets and tabs simultaneously'},
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'},
value: {type: 'integer', value: '', help: [
'Defines currently opened tab in the widget',
'Defines currently widgeted tab in the widget',
'A tab can be opened only by setting its parent\'s value'
]},
@ -37,12 +40,9 @@ module.exports = class Tab extends Panel {
constructor(options) {
options.props.scroll = true
super(options)
this.container.classList.add('show')
this.widget.classList.add('tab')
this.detached = false
@ -69,8 +69,14 @@ module.exports = class Tab extends Panel {
switch (propName) {
case 'visible':
case 'label':
case 'color':
case 'colorWidget':
case 'colorFill':
case 'colorStroke':
case 'alphaStroke':
case 'alphaFillOff':
case 'alphaFillOn':
if (this.parent.createNavigation) this.parent.createNavigation()
return

View file

@ -20,7 +20,7 @@ class Frame extends StaticProperties(Widget, {bypass: true}) {
border: {type: 'boolean', value: true, help: 'Set to `false` to disable the borders and background-color'},
}, ['color', 'precision', 'bypass'], {
}, ['precision', 'bypass'], {
label: {type: 'string|boolean', value: 'auto', help: [
'Set to `false` to hide completely',
@ -37,7 +37,11 @@ class Frame extends StaticProperties(Widget, {bypass: true}) {
constructor(options) {
super({...options, html: html`<div class="frame"><iframe src="" sandbox="allow-scripts"></iframe></div>`})
super({...options, html: html`
<inner>
<iframe src="" sandbox="allow-scripts"></iframe>
</inner>`
})
if (!this.getProp('border')) this.container.classList.add('noborder')

View file

@ -31,16 +31,13 @@ class Html extends StaticProperties(Widget, {bypass: true}) {
]},
border: {type: 'boolean', value: true, help: 'Set to `false` to disable the borders and background-color'},
}, ['color', 'precision', 'bypass'], {})
}, ['precision', 'bypass'], {})
}
constructor(options) {
super({...options, html: html`
<div class="html">
</div>
`})
super({...options, html: html`<inner></inner>`})
if (!this.getProp('border')) this.container.classList.add('noborder')

View file

@ -27,7 +27,7 @@ module.exports = class Image extends StaticProperties(Widget, {bypass: true}) {
'When true, sending `reload` to the widget reloads its image without changing its value'
]}
}, ['color', 'precision', 'bypass'], {
}, ['precision', 'bypass'], {
value: {type: 'string', value: '', help: [
'- File `url` or `path` (relative to the session file location by default, falling back to absolute path)',
@ -40,7 +40,7 @@ module.exports = class Image extends StaticProperties(Widget, {bypass: true}) {
constructor(options) {
super({...options, html: html`<div class="image"></div>`})
super({...options, html: html`<inner></inner>`})
if (!this.getProp('border')) this.container.classList.add('noborder')
@ -93,7 +93,6 @@ module.exports = class Image extends StaticProperties(Widget, {bypass: true}) {
onRemove() {
if (this.bindedOnStreamUpdate) ipc.off('video', this.bindedOnStreamUpdate)
super.onRemove()
}

View file

@ -26,16 +26,16 @@ class Svg extends StaticProperties(Widget, {bypass: true}) {
border: {type: 'boolean', value: true, help: 'Set to `false` to disable the borders and background-color'},
}, ['color', 'precision', 'bypass'], {})
}, ['precision', 'bypass'], {})
}
constructor(options) {
super({...options, html: html`
<div class="svg">
<inner>
<svg></svg>
</div>
</inner>
`})
this.height = undefined

View file

@ -1,10 +1,119 @@
var {clip} = require('../utils'),
Plot = require('./plot')
module.exports = class Eq extends Plot {
static description() {
return 'Draws frequency response between from from an array of filter objects.'
}
static defaults() {
return super.defaults({
_eq:'eq',
pips: {type: 'boolean', value: true, help: 'Set to false to hide the scale'},
resolution: {type: 'number', value: 128, help: 'Defines the number of points used to compute the frequency response'},
rangeY: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'},
origin: {type: 'number|boolean', value: 'auto', help: 'Defines the y axis origin. Set to `false` to disable it'},
logScaleX: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (base 10). Set to a `number` to define the logarithm\'s base.'},
smooth: {type: 'boolean|number', value: false, help: 'Set to `true` to make the line smooth. Float values are also acceptable (works fine between `0` and `0.5`)'},
}, ['precision', 'bypass'], {
value: {type: 'array', value: '', help: [
'Each item must be an object with the following properties',
'- `type`: string ("highpass", "highshelf", "lowpass", "lowshelf", "peak" or "notch")',
'- `freq`: number (filter\'s resonant frequency)',
'- `q`: number (Q factor)',
'- `gain`: number',
'- `on`: boolean',
]}
})
}
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])
}
setValue(v, options={}) {
if (typeof v == 'string') {
try {
v = JSON.parseFlex(v)
} catch(err) {}
}
if (Array.isArray(v)) {
var filters = v,
eqResponse = []
if (v.length === this.resolution) {
eqResponse = v
} else {
for (let i in filters) {
var filterResponse
if (!filters[i].type) filters[i].type = 'peak'
if (!filters[i].on) {
filterResponse = calcBiquad({type:'peak',freq:1,gain:0,q:1},!this.getProp('logScaleX'), this.resolution)
} else {
filterResponse = calcBiquad(filters[i],!this.getProp('logScaleX'), this.resolution)
}
for (var k in filterResponse) {
if (eqResponse[k]===undefined) {
eqResponse[k]=[0,0]
}
eqResponse[k] = [filterResponse[k][0], eqResponse[k][1]+filterResponse[k][1]]
}
}
}
if (eqResponse.length) super.setValue(eqResponse, options)
}
}
}
//
// calcBiquad
//
// Dec 14, 2010 njr
// original @ Nigel Redmon
module.exports = function(options,linear,resolution) {
function calcBiquad(options,linear,resolution) {
var {type, freq, q, gain} = options,
Fs = 44100,
a0,a1,a2,b1,b2,norm,

View file

@ -0,0 +1,246 @@
var {mapToScale} = require('../utils'),
Canvas = require('../common/canvas'),
html = require('nanohtml'),
StaticProperties = require('../mixins/static_properties')
module.exports = class Plot extends StaticProperties(Canvas, {bypass: true}) {
static description() {
return 'XY coordinates plot.'
}
static defaults() {
return super.defaults({
_plot:'plot',
rangeX: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the x axis'},
rangeY: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'},
logScaleX: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (base 10). Set to a `number` to define the logarithm\'s base.'},
logScaleY: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (base 10). Set to a `number` to define the logarithm\'s base.'},
origin: {type: 'number', value: 'auto', help: 'Defines the y axis origin. Set to `false` to disable it.'},
dots: {type: 'boolean', value: true, help: ''},
bars: {type: 'boolean', value: false, help: 'Set to `true` to use draw bars instead (disables `logScaleX` and forces `x axis` even spacing)'},
smooth: {type: 'boolean|number', value: false, help: 'Set to `true` to make the line smooth. Float values are also acceptable (works fine between `0` and `0.5`)'},
pips:{type: 'boolean', value: true, help: 'Set to `false` to hide the scale'},
}, ['precision', 'bypass'], {
value: {type: 'array|string', value: '', help: [
'- `Array` of `y` values',
'- `Array` of `[x, y]` `array` values',
'- `String` `array`',
'- `String` `object` to update specific coordinates only: `{0:1, 4:0}` will change the 1st and 5th points\' coordinates',
]}
})
}
constructor(options) {
super({...options, html: html`
<inner>
<canvas></canvas>
</inner>
`})
this.value = []
this.rangeX = this.getProp('rangeX') || {min:0,max:1}
this.rangeY = this.getProp('rangeY') || {min:0,max:1}
this.logScaleX = this.getProp('logScaleX')
this.logScaleY = this.getProp('logScaleY')
this.pips = {
x : {
min: Math.abs(this.rangeX.min)>=1000?this.rangeY.min/1000+'k':this.rangeX.min,
max: Math.abs(this.rangeX.max)>=1000?this.rangeY.max/1000+'k':this.rangeX.max
},
y : {
min: Math.abs(this.rangeY.min)>=1000?this.rangeY.min/1000+'k':this.rangeY.min,
max: Math.abs(this.rangeY.max)>=1000?this.rangeY.max/1000+'k':this.rangeY.max
}
}
this.smooth = this.getProp('smooth') === true ? 0.25 : this.getProp('smooth') === false ? 0 : parseFloat(this.getProp('smooth')) || 0
}
draw() {
this.ctx.clearRect(0,0,this.width,this.height)
if (this.getProp('bars')) {
this.draw_bars()
} else {
var points = this.draw_line()
if (this.getProp('dots')) {
this.draw_dots(points)
}
}
if (this.getProp('pips')) this.draw_pips()
}
draw_pips() {
this.ctx.globalAlpha = 1
this.ctx.fillStyle = this.colors.textFade
var margin = this.cssVars.padding
if (margin < this.fontSize * 1.5) return
if (this.pips.x) {
this.ctx.textAlign = 'center'
this.ctx.fillText(this.pips.x.min, margin, this.height - margin / 2)
this.ctx.fillText(this.pips.x.max, this.width - margin, this.height - margin / 2)
}
if (this.pips.y) {
this.ctx.textAlign = 'right'
this.ctx.fillText(this.pips.y.min, margin / 2 + this.fontSize / 2, this.height - margin)
this.ctx.fillText(this.pips.y.max, margin / 2 + this.fontSize / 2, margin)
}
}
draw_line() {
var points = [],
padding = this.cssVars.padding + PXSCALE,
x, y
for (let i in this.value) {
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))
} 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)
if (x !== nx || y !== ny) {
points.push(nx)
points.push(ny)
x = nx
y = ny
}
}
}
if (points.length < 4) return points
this.ctx.beginPath()
if (this.getProp('smooth')) {
this.ctx.curve(points, this.smooth, Math.round(this.width/(points.length/2 - 1)))
} else {
this.ctx.moveTo(points[0], points[1])
let i
for (i = 2; i < points.length - 2; i += 2) {
this.ctx.lineTo(points[i], points[i + 1])
}
this.ctx.lineTo(points[i], points[i + 1])
}
this.ctx.globalAlpha = 1
this.ctx.lineWidth = 2 * PXSCALE
this.ctx.strokeStyle = this.cssVars.colorWidget
this.ctx.stroke()
if (this.getProp('origin') !== false) {
var origin = mapToScale(this.getProp('origin'), [this.rangeY.min, this.rangeY.max], [this.height - padding, padding], 0, this.getProp('logScaleY'), true)
this.ctx.globalAlpha = this.cssVars.alphaFillOn
this.ctx.fillStyle = this.cssVars.colorFill
this.ctx.lineTo(this.width - padding, origin)
this.ctx.lineTo(padding, origin)
this.ctx.closePath()
this.ctx.fill()
}
return points
}
draw_dots(points) {
this.ctx.globalAlpha = 1
this.ctx.fillStyle = this.cssVars.colorWidget
this.ctx.strokeStyle = this.cssVars.colorForeground
this.ctx.lineWidth = 2 * PXSCALE
for (var i = 0; i < points.length; i += 2) {
this.ctx.beginPath()
this.ctx.arc(points[i], points[i + 1], 3 * PXSCALE, 0, 2*Math.PI)
this.ctx.fill()
this.ctx.stroke()
}
}
draw_bars() {
var barWidth = Math.round(this.width / this.value.length),
offset = Math.round((this.width - barWidth * this.value.length) / 2)
var origin = mapToScale(this.getProp('origin') !== false ? this.getProp('origin') : this.rangeY.min, [this.rangeY.min,this.rangeY.max],[this.height,0],0,this.getProp('logScaleY'),true)
this.ctx.beginPath()
for (let i in this.value) {
var y = mapToScale(this.value[i].length ? this.value[i][1] : this.value[i],[this.rangeY.min,this.rangeY.max],[this.height-2*PXSCALE,2*PXSCALE],0,this.logScaleY,true)
this.ctx.rect(offset + i * barWidth, Math.min(y, origin), barWidth - PXSCALE, Math.abs(Math.min(y - origin)))
}
this.ctx.globalAlpha = 0.4
this.ctx.fillStyle = this.colors.custom
this.ctx.fill()
}
setValue(v, options={}) {
if (typeof v == 'string') {
try {
v = JSON.parseFlex(v)
} catch(err) {}
}
if (typeof v == 'object' && v !== null) {
if (Array.isArray(v)) {
this.value = v
} else {
for (var i in v) {
if (!isNaN(i)) this.value[i] = v[i]
}
}
this.batchDraw()
if (options.sync) this.changed(options)
}
}
}

View file

@ -1,7 +1,10 @@
var {clip} = require('../utils'),
_plots_base = require('./_plots_base')
Widget = require('../common/widget'),
Plot = require('./plot'),
StaticProperties = require('../mixins/static_properties')
module.exports = class Visualizer extends _plots_base {
module.exports = class Visualizer extends StaticProperties(Plot, {rangeX: {min: '', max: ''}, dots: false, smooth: false}) {
static description() {
@ -11,15 +14,14 @@ module.exports = class Visualizer extends _plots_base {
static defaults() {
return super.defaults({
return Widget.defaults({
_visualizer:'visualizer',
duration: {type: 'number', value: 1, help: 'Defines visualization duration in seconds'},
range: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'},
rangeY: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'},
origin: {type: 'number', value: 'auto', help: 'Defines the y axis origin. Set to `false` to disable it'},
logScale: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (base 10). Set to a `number` to define the logarithm\'s base.'},
smooth: {type: 'boolean|number', value: false, help: 'Set to `true` to make the line smooth. Float values are also acceptable (works fine between `0` and `0.5`)'},
logScaleY: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (base 10). Set to a `number` to define the logarithm\'s base.'},
pips:{type: 'boolean', value: true, help: 'Set to `false` to hide the scale'},
}, ['precision', 'bypass'], {})
@ -28,20 +30,9 @@ module.exports = class Visualizer extends _plots_base {
constructor(options) {
// backward compat
if (options.props.widgetId) {
options.props.value = '@{' + options.props.widgetId + '}'
delete options.props.widgetId
}
super(options)
this.fps = CANVAS_FRAMERATE
this.pips.y.min = Math.abs(this.getProp('range').min) >= 1000? this.getProp('range').min/1000+'k' : this.getProp('range').min
this.pips.y.max = Math.abs(this.getProp('range').max) >= 1000? this.getProp('range').max/1000+'k' : this.getProp('range').max
this.pips.x = false
this.rangeY = this.getProp('range') || {min:0,max:1}
this.logScaleY = this.getProp('logScale')
this.length = Math.round(clip(this.fps * this.getProp('duration'), [8, 4096]))
this.value = new Array(this.length).fill(this.rangeY.min)
this.cancel = false

View file

@ -11,15 +11,15 @@ module.exports.widgets = {
// buttons
toggle: require('./buttons/toggle'),
push: require('./buttons/push'),
switch: require('./buttons/switch'),
dropdown: require('./buttons/dropdown'),
menu: require('./buttons/menu'),
dropdown: require('./buttons/dropdown'), // redo as menu derivate ?
menu: require('./buttons/menu'), // redo using canvas
// pads
xy: require('./pads/xy'),
rgb: require('./pads/rgb'),
multixy: require('./pads/multixy'),
canvas: require('./pads/canvas'), // implement...
// matrices
matrix: require('./matrices/matrix'),
@ -27,21 +27,22 @@ module.exports.widgets = {
patchbay: require('./matrices/patchbay').PatchBay,
patchbaynode: require('./matrices/patchbay').PatchBayNode,
// plots
led: require('./plots/led'),
rgbled: require('./plots/rgbled'),
plot: require('./plots/plot'),
eq: require('./plots/eq'),
visualizer: require('./plots/visualizer'),
meter: require('./plots/meter'),
text: require('./plots/text'),
image: require('./plots/image'),
svg: require('./plots/svg'),
html: require('./plots/html'),
frame: require('./plots/frame'),
// indicators
led: require('./indicators/led'),
text: require('./indicators/text'),
// graphs
plot: require('./graphs/plot'),
eq: require('./graphs/eq'),
visualizer: require('./graphs/visualizer'),
// frames
image: require('./frames/image'),
svg: require('./frames/svg'),
html: require('./frames/html'),
frame: require('./frames/frame'),
// containers
strip: require('./containers/strip'),
panel: require('./containers/panel'),
modal: require('./containers/modal'),
clone: require('./containers/clone'),
@ -61,12 +62,20 @@ module.exports.widgets = {
}
module.exports.categories = {
'Sliders':['fader','knob', 'encoder', 'range'],
'Buttons':['toggle','push','switch', 'dropdown', 'menu'],
'Pads':['xy','rgb','multixy'],
'Buttons':['toggle', 'switch', 'dropdown', 'menu'],
'Containers':['panel', 'modal', 'clone'],
'Frames':['frame', 'svg', 'html', 'image'],
'Graphs':['plot','eq','visualizer'],
'Indicator':['led', 'text'],
'Inputs':['input', 'keys', 'script', 'gyroscope', 'file'],
'Matrices':['matrix', 'keyboard', 'patchbay'],
'Plots':['plot','eq','visualizer','led', 'rgbled','meter','text', 'image', 'svg', 'html', 'frame'],
'Containers':['panel','strip','modal', 'clone'],
'Pads':['xy','rgb','multixy', 'canvas'],
'Sliders':['fader','knob', 'encoder', 'range'],
'Switchers':['state', 'switcher','crossfader'],
'Inputs':['input', 'keys', 'script', 'gyroscope', 'file']
}
var defaults = {}
for (var k in module.exports.widgets) {
defaults[k] = module.exports.widgets[k].defaults()
}
module.exports.defaults = defaults

View file

@ -0,0 +1,102 @@
var {mapToScale, clip} = require('../utils'),
Widget = require('../common/widget'),
html = require('nanohtml'),
StaticProperties = require('../mixins/static_properties')
module.exports = class Led extends StaticProperties(Widget, {bypass: true}) {
static description() {
return 'Intensity display.'
}
static defaults() {
return super.defaults({
_led:'led',
mode: {type: 'string', value: 'intensity', choices: ['intensity', 'color'], help: [
''
]},
range: {type: 'object', value: {min:0,max:1}, help: 'Value to led intensity mapping range'},
logScale: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale (base 10). Set to a `number` to define the logarithm\'s base.'},
borderRadius: {type: 'string', value: '', help: 'Css border-radius property.'},
}, ['precision', 'bypass'], {
value: {type: 'number|array|string', value: '', help: [
'- `Number`: if `mode` is set to `intensity`',
'- `Array`: `[r, g, b]` (`r`, `g` and `b` between `0` and `255`)',
'- `Array`: `[r, g, b, alpha]` (`alpha` between `0` and `255`)',
'- `String`: CSS color',
]}
})
}
constructor(options) {
super({...options, html: html`<inner></inner>`})
this.setValueIntensity(this.getProp('mode') === 'intensity' ? this.getProp('range').min : 1)
var bR = this.getProp('borderRadius')
if (parseInt(bR) == bR) bR += 'rem'
this.container.style.setProperty('--border-radius', bR)
}
setValue(v, options={}) {
var ret = this.getProp('mode') === 'intensity' ? this.setValueIntensity(v) : this.setValueColor(v)
if (options.sync && ret !== false) this.changed(options)
}
setValueIntensity(v) {
if (typeof v != 'number') return false
this.value = v
this.container.style.setProperty('--opacity', mapToScale(v,[this.getProp('range').min,this.getProp('range').max],[0,1],false,this.getProp('logScale'),true))
}
setValueColor(v) {
var c = ''
if (Array.isArray(v) && v.length >= 3) {
for (let i in [0,1,2]) {
v[i] = parseInt(clip(v[i],[0,255]))
}
v[3] = clip(v[3] != undefined ? v[3] : 1,[0,1])
c = `rgba(${v[0]}, ${v[1]}, ${v[2]}, ${v[3]})`
} else if (typeof v == 'string') {
c = v
} else {
return false
}
this.value = v
this.container .style.setProperty('--color-led', c)
}
}

View file

@ -22,7 +22,7 @@ module.exports = class Text extends StaticProperties(Widget, {bypass: true}) {
'Set to `true` to wrap long lines automatically.',
'This will not break overflowing words by default, word-breaking can be enabled by adding `word-break: break-all;` to the `css` property',
]},
align: {type: 'string', value: '', help: 'Set to `left` or `right` to change text alignment (otherwise center)'},
align: {type: 'string', value: 'center', choices: ['center', 'left', 'right'], help: 'Css text-align property.'},
}, ['precision', 'bypass'], {})
@ -30,17 +30,15 @@ module.exports = class Text extends StaticProperties(Widget, {bypass: true}) {
constructor(options) {
// backward compat
if (options.props.widgetId) {
options.props.value = '@{' + options.props.widgetId + '}'
delete options.props.widgetId
}
super({...options, html: html`<div class="text"></div>`})
super({...options, html: html`<inner></inner>`})
this.text = this.widget.appendChild(html`<div></div>`)
if (this.getProp('vertical')) this.text.classList.add('vertical')
if (this.getProp('align') === 'left') this.text.classList.add('left')
if (this.getProp('align') === 'right') this.text.classList.add('right')
if (this.getProp('wrap')) this.text.classList.add('wrap')
if (this.getProp('vertical')) this.widget.classList.add('vertical')
if (this.getProp('align') === 'left') this.widget.classList.add('left')
if (this.getProp('align') === 'right') this.widget.classList.add('right')
if (this.getProp('wrap')) this.widget.classList.add('wrap')
this.defaultValue = this.getProp('default') || ( this.getProp('label')===false ?
this.getProp('id'):
@ -61,9 +59,9 @@ module.exports = class Text extends StaticProperties(Widget, {bypass: true}) {
var s = String(this.value)
if (s.indexOf('^') > -1) {
this.widget.innerHTML = iconify(s.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g,'<br/>'))
this.text.innerHTML = iconify(s.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g,'<br/>'))
} else {
this.widget.textContent = s.replace(/\n/g,'\r\n')
this.text.textContent = s.replace(/\n/g,'\r\n')
}
if (options.sync) this.changed(options)

View file

@ -3,7 +3,7 @@ var Widget = require('../common/widget'),
raw = require('nanohtml/raw'),
{remoteBrowse, icon} = require('../../ui/utils')
module.exports = class Input extends Widget {
module.exports = class File extends Widget {
static description() {

View file

@ -16,8 +16,7 @@ module.exports = class Input extends Canvas {
_input:'input',
vertical: {type: 'boolean', value: false, help: 'Set to `true` to display the text vertically'},
align: {type: 'string', value: '', help: 'Set to `left` or `right` to change text alignment (otherwise center)'},
align: {type: 'string', value: 'center', choices: ['center', 'left', 'right'], help: 'Set to `left` or `right` to change text alignment (otherwise center)'},
unit: {type: 'string', value: '', help: 'Unit will be appended to the displayed widget\'s value (it doesn\'t affect osc messages)'},
editable: {type: 'boolean', value: true, help: 'Set to `false` to make the input non-editable'},
asYouType: {type: 'boolean', value: false, help: 'Set to `true` to make the input send its value at each keystroke'}
@ -29,9 +28,9 @@ module.exports = class Input extends Canvas {
constructor(options) {
super({...options, html: html`
<div class="input">
<inner>
<canvas></canvas>
</div>
</inner>
`})
this.value = ''
@ -104,17 +103,17 @@ module.exports = class Input extends Canvas {
super.resizeHandle(event)
if (this.getProp('vertical')){
var ratio = CANVAS_SCALING * this.scaling
this.ctx.setTransform(1, 0, 0, 1, 0, 0)
this.ctx.rotate(-Math.PI/2)
this.ctx.translate(-this.height * ratio, 0)
if (ratio != 1) this.ctx.scale(ratio, ratio)
}
// if (this.getProp('vertical')){
//
// var ratio = CANVAS_SCALING * this.scaling
//
// this.ctx.setTransform(1, 0, 0, 1, 0, 0)
// this.ctx.rotate(-Math.PI/2)
// this.ctx.translate(-this.height * ratio, 0)
//
//
// if (ratio != 1) this.ctx.scale(ratio, ratio)
// }
}
@ -138,8 +137,8 @@ module.exports = class Input extends Canvas {
draw() {
var v = this.stringValue,
width = this.getProp('vertical') ? this.height : this.width,
height = !this.getProp('vertical') ? this.height : this.width
width = this.width,
height = this.height
if (this.getProp('unit') && v.length) v += ' ' + this.getProp('unit')

View file

@ -38,16 +38,10 @@ class Keys extends Widget {
constructor(options) {
super({...options, html: html`
<div class="keys">
${raw(icon('keyboard'))}
</div>
`})
super({...options, html: null})
if (this.getProp('binding')) {
this.widget.appendChild(html`<span>${this.getProp('binding')}</span>`)
this.keyDownHandler = this.keyDown.bind(this)
this.keyUpHandler = this.keyUp.bind(this)
@ -79,7 +73,7 @@ class Keys extends Widget {
keyDown(e) {
if (e.target && e.target.classList.contains('no-keybinding')) return
if (e.target && (e.target.tagName === 'INPUT' || e.target.tabName === 'TEXTAREA' || e.target.tabName === 'SELECT')) return
if (!this.getProp('repeat') && e) e.preventRepeat()
@ -104,9 +98,6 @@ class Keys extends Widget {
}
this.showKeydown()
}
@ -135,20 +126,6 @@ class Keys extends Widget {
}
this.showKeyup()
}
showKeydown(){
this.widget.style.setProperty('--opacity', 1)
}
showKeyup(){
this.widget.style.setProperty('--opacity', 0.75)
}
setValue(v, options = {}) {

View file

@ -0,0 +1,172 @@
var Canvas = require('../common/canvas'),
html = require('nanohtml')
class CanvasWidget extends Canvas {
static description() {
return 'KANVA !'
}
static defaults() {
return super.defaults({
_canvas:'canvas',
valueLength: {type: 'number', value: 1, help: ' '},
multiTouch: {type: 'boolean', value: false, help: ' '},
sensitivity: {type: 'number', value: 1, help: ' '},
snap: {type: 'boolean', value: true, help: ' '},
coordsToValue: {type: 'script', value: '', help: ' '},
valueToCoords: {type: 'script', value: '', help: ' '},
draw: {type: 'script', value: '', help: ' '},
autoClear: {type: 'boolean', value: true, help: ' '},
}, [], {})
}
constructor(options) {
super({...options, html: html`
<div class="canvas">
<canvas></canvas>
</div>
`})
this.nextTouch = 0
this.value = 1
this.touchMap = {}
this.touchCoords = []
for (var i = 0; i < this.getProp('valueLength'); i++) {
this.touchCoords.push([0,0])
}
this.localContext = {}
this.on('draginit',(e)=>{
if (this.touchMap[e.pointerId] !== undefined) return
this.touchMap[e.pointerId] = this.nextTouch++
if (this.getProp('snap')) this.touchCoords[this.touchMap[e.pointerId]] = [e.offsetX, e.offsetY]
this.touchCallback(e)
}, {element: this.widget, multitouch: this.getProp('multiTouch')})
this.on('drag',(e)=>{
if (this.touchMap[e.pointerId] === undefined) return
console.log(this.touchMap[e.pointerId])
this.touchCoords[this.touchMap[e.pointerId]][0] += e.movementX / e.inertia * this.getProp('sensitivity')
this.touchCoords[this.touchMap[e.pointerId]][1] += e.movementY / e.inertia * this.getProp('sensitivity')
this.touchCallback(e)
}, {element: this.widget, multitouch: this.getProp('multiTouch')})
this.on('dragend',(e)=>{
if (this.touchMap[e.pointerId] === undefined) return
delete this.touchMap[e.pointerId]
this.nextTouch--
this.touchCallback(e)
}, {element: this.widget, multitouch: this.getProp('multiTouch')})
}
touchCallback() {
var value = this.resolveProp('coordsToValue', undefined, false, false, false, {
coords: this.touchCoords,
value: this.value,
width: this.width,
height: this.height,
local: this.localContext
})
if (value !== undefined) this.setValue(value, {send: true, sync: true, dragged: true})
}
setValue(v, options={}) {
if (v === null || v === undefined || ((v.length || 1) !== this.getProp('valueLength'))) return
this.value = v
if (!options.dragged) {
var coords = this.resolveProp('valueToCoords', undefined, false, false, false, {
coords: this.touchCoords,
value: this.value,
width: this.width,
height: this.height,
local: this.localContext
}) || this.touchCoords
this.touchCoords = coords === undefined ? this.touchCoords : coords
}
this.batchDraw()
if (options.send) this.sendValue()
if (options.sync) this.changed(options)
}
draw() {
if (this.getProp('autoClear')) this.clear()
this.resolveProp('draw', undefined, false, false, false, {
ctx: this.ctx,
coords: this.touchCoords,
value: this.value,
colors: this.colors,
width: this.width,
height: this.height,
})
if (this.getProp('autoClear')) this.clearRect = [0, 0, this.width, this.height]
}
}
CanvasWidget.parsersContexts.coordsToValue = CanvasWidget.parsersContexts.valueToCoords = {
coords: [[]],
value: [],
width: 100,
height: 100,
local: {}
}
CanvasWidget.parsersContexts.draw = {
value: [],
coords: [[]],
colors: {},
width: 100,
height: 100,
ctx: ()=>{}
}
CanvasWidget.dynamicProps = CanvasWidget.prototype.constructor.dynamicProps.concat([
'draw',
'sensitivity'
])
module.exports = CanvasWidget

View file

@ -50,14 +50,7 @@ module.exports = class MultiXy extends Pad {
'Can be set as an `object` to specify a different address : `[\'/0/x\', \'/0/y\', \'/1/x\', \'/2/y\']`',
'Note: the widget will only respond to its original osc address, not to the splitted version'
]},
css: {type: 'string', value: '', help: [
'Available CSS variables:',
'- `--background: background;`: sets the dragging area\'s background',
'- `--pips-color: color;`',
'- `--pips-opacity: number;`',
'- `--color-text: point-color;`',
'Pads can be targetted individually with the .pad-X selector (where X is the pad\'s index)',
]}
})
}
@ -88,9 +81,8 @@ module.exports = class MultiXy extends Pad {
sensitivity: this.getProp('sensitivity'),
input:false
}, parent: this})
this.pads[i].sendValue = ()=>{}
this.pads[i].widget.classList.add('pad-' + i)
this.wrapper.appendChild(this.pads[i].widget)
this.pads[i].canvas.classList.add('pad-' + i)
this.widget.append(this.pads[i].canvas)
}
@ -100,7 +92,7 @@ module.exports = class MultiXy extends Pad {
this.padsCoords = []
this.touchMap = {}
touchstate(this, {element: this.wrapper, multitouch: true})
touchstate(this, {element: this.widget, multitouch: true})
this.on('draginit',(e)=>{
@ -134,7 +126,7 @@ module.exports = class MultiXy extends Pad {
this.pads[id].trigger('draginit', e)
}, {element: this.wrapper, multitouch: true})
}, {element: this.widget, multitouch: true})
this.on('drag',(e)=>{
@ -144,7 +136,7 @@ module.exports = class MultiXy extends Pad {
this.pads[i].trigger('drag', e)
}, {element: this.wrapper[0], multitouch: true})
}, {element: this.widget, multitouch: true})
this.on('dragend',(e)=>{
@ -158,7 +150,7 @@ module.exports = class MultiXy extends Pad {
delete this.touchMap[e.pointerId]
}, {element: this.wrapper, multitouch: true})
}, {element: this.widget, multitouch: true})
this.on('change',(e)=>{
if (e.widget == this) return
@ -176,9 +168,16 @@ module.exports = class MultiXy extends Pad {
}
resizeHandle() {
resizeHandle(event){
super.resizeHandle(event)
for (var k in this.pads) {
this.pads[k].width = this.width
this.pads[k].height = this.height
this.pads[k].padPadding = this.padPadding
}
super.resizeHandle(...arguments)
this.updateHandlesPosition()
}
@ -199,7 +198,7 @@ module.exports = class MultiXy extends Pad {
this.clear()
for (var i=0;i<this.npoints;i++) {
var margin = (this.pointSize + 1) * PXSCALE,
var margin = this.padPadding,
x = clip(this.pads[i].faders.x.percent,[0,100]) / 100 * (this.width - 2 * margin) + margin,
y = (100 - clip(this.pads[i].faders.y.percent,[0,100])) / 100 * (this.height - 2 * margin) + margin,
t = (this.labels ? this.getProp('points')[i] : i) + '',
@ -207,7 +206,7 @@ module.exports = class MultiXy extends Pad {
this.ctx.globalAlpha = 1
this.ctx.fillStyle = this.pads[i].colors.text
this.ctx.fillText(t, x + 0.5 * PXSCALE, y + 0.5 * PXSCALE)
this.ctx.fillText(t, x + 0.5 * PXSCALE, y + PXSCALE)
this.clearRect[i] = [x - length / 2, y - this.fontSize / 2, length, this.fontSize + 2 * PXSCALE]
@ -273,9 +272,14 @@ module.exports = class MultiXy extends Pad {
switch (propName) {
case 'color':
case 'colorWidget':
case 'colorFill':
case 'colorStroke':
case 'alphaStroke':
case 'alphaFillOff':
case 'alphaFillOn':
for (var w of this.pads) {
w.onPropChanged('color')
w.onPropChanged(propName)
}
return

View file

@ -6,17 +6,12 @@ class Pad extends Canvas {
constructor(options) {
super({...options, html: html`
<div class="pad">
<div class="wrapper">
<canvas></canvas>
</div>
</div>
<inner>
<canvas></canvas>
</inner>
`})
this.wrapper = DOM.get(this.widget, '.wrapper')[0]
this.pointSize = parseInt(this.getProp('pointSize'))
this.widget.style.setProperty('--pointSize', this.pointSize + 'rem')
this.canvas.style.setProperty('--pointSize', parseInt(this.getProp('pointSize')) + 'rem')
}
@ -26,9 +21,8 @@ class Pad extends Canvas {
super.cacheCanvasStyle(style)
this.colors.pips = style.getPropertyValue('--color-pips') || this.colors.custom
this.colors.pipsOpacity = style.getPropertyValue('--pips-opacity')
this.colors.pointOpacity = style.getPropertyValue('--point-opacity')
this.pointSize = parseFloat(style.getPropertyValue('--pointSize')) * PXSCALE
this.padPadding = (this.cssVars.padding + PXSCALE)
}

View file

@ -1,11 +1,17 @@
var Pad = require('./pad'),
Fader = require('./_fake_fader'),
doubletab = require('../mixins/double_tap'),
Input = require('../inputs/input'),
touchstate = require('../mixins/touch_state')
var faderDefaults = Fader.defaults()._props()
class XyFader extends Fader {
draw(){}
batchDraw(){}
}
module.exports = class Xy extends Pad {
static description() {
@ -31,7 +37,6 @@ module.exports = class Xy extends Pad {
rangeY: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'},
logScaleX: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (base 10). Set to a `number` to define the logarithm\'s base.'},
logScaleY: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (base 10). Set to a `number` to define the logarithm\'s base.'},
input: {type: 'boolean', value: true, help: 'Set to false to hide the built-in input widget'},
doubleTap: {type: 'boolean|string', value: false, help: [
'Set to `true` to make the fader reset to its default value when receiving a double tap.',
'Can also be an osc address, which case the widget will just send an osc message: `/<doubleTap> <preArgs>`'
@ -46,13 +51,6 @@ module.exports = class Xy extends Pad {
'Can be set as an `object` to specify a different address : [\'/osc_address_x\', \'/osc_address_y\']',
'Note: the widget will only respond to its original osc address, not to the splitted version'
]},
css: {type: 'string', value: '', help: [
'Available CSS variables:',
'- `--background: background;`: sets the dragging area\'s background',
'- `--pips-color: color;`',
'- `--pips-opacity: number;`',
'- `--point-opacity: number;`',
]}
})
@ -63,58 +61,36 @@ module.exports = class Xy extends Pad {
super(options)
this.faders = {
x: new Fader({props:{
x: new XyFader({props:{
...faderDefaults,
id:0,
compact:true,
pips:false,
horizontal:true,
height:'100%',
width:'100%',
default:this.getProp('default').length === 2 ? this.getProp('default')[0] : '',
snap:this.getProp('snap'),
range:this.getProp('rangeX'),
origin:'auto',
precision:this.getProp('precision'),
logScale:this.getProp('logScaleX'),
sensitivity: this.getProp('sensitivity'),
input:false
}, cancelDraw: true, parent: this}),
y: new Fader({props:{
}, parent: this}),
y: new XyFader({props:{
...faderDefaults,
id:1,
compact:true,
pips:false,
horizontal:false,
height:'100%',
width:'100%',
default:this.getProp('default').length === 2 ? this.getProp('default')[1] : '',
snap:this.getProp('snap'),
range:this.getProp('rangeY'),
origin:'auto',
precision:this.getProp('precision'),
logScale:this.getProp('logScaleY'),
sensitivity: this.getProp('sensitivity'),
input:false
}, cancelDraw: true, parent: this}),
}, parent: this}),
}
this.faders.x.margin = this.faders.y.margin = this.pointSize + 1
this.value = [this.faders.x.value, this.faders.y.value]
this.wrapper.appendChild(this.faders.x.widget)
this.wrapper.appendChild(this.faders.y.widget)
this.faders.x.on('change',(e)=>{
this.on('change',(e)=>{
if (e.widget == this) return
e.stopPropagation = true
})
this.faders.y.on('change',(e)=>{
e.stopPropagation = true
})
touchstate(this, {element: this.wrapper})
touchstate(this, {element: this.canvas})
this.active = false
this.on('draginit',(e)=>{
@ -123,13 +99,13 @@ module.exports = class Xy extends Pad {
this.faders.x.trigger('draginit', e)
this.faders.y.trigger('draginit', e)
this.dragHandle()
}, {element: this.wrapper})
}, {element: this.canvas})
this.on('drag',(e)=>{
this.faders.x.trigger('drag', e)
this.faders.y.trigger('drag', e)
this.dragHandle()
}, {element: this.wrapper})
}, {element: this.canvas})
this.on('dragend', (e)=>{
e.stopPropagation = true
@ -141,7 +117,7 @@ module.exports = class Xy extends Pad {
} else {
this.batchDraw()
}
}, {element: this.wrapper})
}, {element: this.canvas})
if (this.getProp('doubleTap')) {
@ -153,7 +129,7 @@ module.exports = class Xy extends Pad {
} else {
doubletab(this.wrapper, ()=>{
doubletab(this.widget, ()=>{
this.faders.x.setValue(this.faders.x.getSpringValue(), {sync: false, send:false, dragged:true})
this.faders.y.setValue(this.faders.y.getSpringValue(), {sync: false, send:false, dragged:true})
this.setValue([this.faders.x.getSpringValue(),this.faders.y.getSpringValue()],{sync:true, send:true})
@ -163,21 +139,6 @@ module.exports = class Xy extends Pad {
}
if (this.getProp('input')) {
this.input = new Input({
props:{...Input.defaults()._props(), precision:this.getProp('precision'), unit:this.getProp('unit')},
parent:this, parentNode:this.widget
})
this.widget.appendChild(this.input.widget)
this.input.on('change', (e)=>{
e.stopPropagation = true
this.setValue(this.input.getValue(), {sync:true, send:true})
this.showValue()
})
}
this.setValue([0,0])
}
@ -196,6 +157,19 @@ module.exports = class Xy extends Pad {
}
resizeHandle(event){
super.resizeHandle(event)
for (var k in this.faders) {
this.faders[k].width = this.width
this.faders[k].height = this.height
this.faders[k].gaugePadding = this.padPadding
}
}
setValue(v, options={}) {
@ -217,72 +191,97 @@ module.exports = class Xy extends Pad {
this.batchDraw()
this.showValue()
}
draw() {
var pointSize = this.pointSize * PXSCALE,
margin = (this.pointSize + 1) * PXSCALE,
var pointSize = this.pointSize,
margin = this.padPadding,
x = this.faders.x.percentToCoord(this.faders.x.percent),
y = this.faders.y.percentToCoord(this.faders.y.percent)
this.clear()
this.ctx.lineWidth = PXSCALE
this.ctx.fillStyle = this.colors.custom
this.ctx.fillStyle = this.cssVars.colorFill
this.ctx.globalAlpha = this.cssVars.alphaFillOn
this.ctx.beginPath()
this.ctx.arc(x, y, pointSize - 3 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
var pipsDrawn = false
if (this.getProp('pips')) {
this.ctx.strokeStyle = this.colors.pips
this.ctx.globalAlpha = this.colors.pipsOpacity
var pipTexts = margin >= this.fontSize * 1.5
this.ctx.lineWidth = PXSCALE
this.ctx.fillStyle = this.colors.textFade
this.ctx.strokeStyle = this.cssVars.colorStroke
this.ctx.globalAlpha = 1
this.ctx.beginPath()
for (var pip of this.faders.x.rangeKeys.concat(this.faders.x.valueToPercent(this.faders.x.originValue))) {
for (let i in this.faders.x.rangeKeys) {
let pip = this.faders.x.rangeKeys[i],
px = Math.round(0.5 * this.faders.x.percentToCoord(pip)) * 2
if (parseInt(px) === px) px -= 0.5
if (pipTexts) {
this.ctx.textAlign = 'center'
let label = this.faders.x.rangeLabels[i]
this.ctx.fillText(label, px, this.height - margin / 2)
pipsDrawn = true
}
if (pip == 0 || pip == 100) continue
var xpip = Math.round(2 * this.faders.x.percentToCoord(pip)) / 2
if (xpip === parseInt(xpip)) xpip -= 0.5
this.ctx.moveTo(xpip, margin)
this.ctx.lineTo(xpip, this.height - margin)
this.ctx.moveTo(px, margin)
this.ctx.lineTo(px, this.height - margin)
pipsDrawn = true
}
for (pip of this.faders.y.rangeKeys.concat(this.faders.y.valueToPercent(this.faders.y.originValue))) {
for (let i in this.faders.y.rangeKeys) {
let pip = this.faders.y.rangeKeys[i],
py = Math.round(0.5 * this.faders.y.percentToCoord(pip)) * 2
if (parseInt(py) === py) py -= 0.5
if (pipTexts) {
this.ctx.textAlign = 'right'
let label = this.faders.y.rangeLabels[i]
this.ctx.fillText(label, margin / 2 + this.fontSize / 2, py)
pipsDrawn = true
}
if (pip == 0 || pip == 100) continue
var ypip = Math.round(2 * this.faders.y.percentToCoord(pip)) / 2
if (ypip === parseInt(ypip)) ypip -= 0.5
this.ctx.moveTo(margin, ypip)
this.ctx.lineTo(this.width - margin, ypip)
this.ctx.moveTo(margin, py)
this.ctx.lineTo(this.width - margin, py)
pipsDrawn = true
}
this.ctx.globalAlpha = this.cssVars.alphaStroke
this.ctx.stroke()
} else {
this.clearRect = [x - margin - PXSCALE, y - margin - PXSCALE, (margin + PXSCALE) * 2, (margin + PXSCALE) * 2]
}
if (!pipsDrawn) this.clearRect = [x - this.pointSize - 2 * PXSCALE, y - this.pointSize - 2 * PXSCALE, (this.pointSize + PXSCALE) * 4, (this.pointSize + PXSCALE) * 4]
this.ctx.strokeStyle = this.colors.custom
this.ctx.globalAlpha = this.active ? 1 : 0.7
this.ctx.lineWidth = 2 * PXSCALE
this.ctx.strokeStyle = this.cssVars.colorStroke
this.ctx.globalAlpha = this.active ? 1 : 0.75
this.ctx.lineWidth = 1.5 * PXSCALE
this.ctx.beginPath()
this.ctx.arc(x, y, pointSize, Math.PI * 2, false)
this.ctx.stroke()
this.ctx.fillStyle = this.colors.custom
this.ctx.globalAlpha = this.colors.pointOpacity
this.ctx.beginPath()
this.ctx.arc(x, y, pointSize / 1.5, Math.PI * 2, false)
this.ctx.fill()
}
showValue() {
if (this.getProp('input')) this.input.setValue(this.value)
}
getSplit() {
@ -295,29 +294,12 @@ module.exports = class Xy extends Pad {
}
onPropChanged(propName, options, oldPropValue) {
if (super.onPropChanged(...arguments)) return true
switch (propName) {
case 'color':
for (var w of [this.faders.x, this.faders.y]) {
w.onPropChanged('color')
}
if (this.input) this.input.onPropChanged('color')
return
}
}
onRemove() {
this.faders.x.onRemove()
this.faders.y.onRemove()
if (this.input) this.input.onRemove()
super.onRemove()
}
}

View file

@ -1,209 +0,0 @@
var {mapToScale} = require('../utils'),
Canvas = require('../common/canvas'),
html = require('nanohtml'),
StaticProperties = require('../mixins/static_properties')
module.exports = class _plots_base extends StaticProperties(Canvas, {bypass: true}) {
constructor(options) {
super({...options, html: html`
<div class="plot">
<canvas></canvas>
</div>
`})
this.value = []
this.rangeX = this.getProp('rangeX') || {min:0,max:1}
this.rangeY = this.getProp('rangeY') || {min:0,max:1}
this.logScaleX = this.getProp('logScaleX')
this.logScaleY = this.getProp('logScaleY')
this.pips = {
x : {
min: Math.abs(this.rangeX.min)>=1000?this.rangeY.min/1000+'k':this.rangeX.min,
max: Math.abs(this.rangeX.max)>=1000?this.rangeY.max/1000+'k':this.rangeX.max
},
y : {
min: Math.abs(this.rangeY.min)>=1000?this.rangeY.min/1000+'k':this.rangeY.min,
max: Math.abs(this.rangeY.max)>=1000?this.rangeY.max/1000+'k':this.rangeY.max
}
}
this.smooth = this.getProp('smooth') === true ? 0.25 : this.getProp('smooth') === false ? 0 : parseFloat(this.getProp('smooth')) || 0
}
resizeHandle() {
this.updateData()
super.resizeHandle(...arguments)
}
draw() {
this.ctx.clearRect(0,0,this.width,this.height)
if (this.getProp('bars')) {
this.draw_bars()
} else {
var points = this.draw_line()
if (this.getProp('dots')) {
this.draw_dots(points)
}
}
if (this.getProp('pips')) this.draw_pips()
}
draw_pips() {
this.ctx.globalAlpha = 1
this.ctx.fillStyle = this.colors.text
if (this.pips.x) {
this.ctx.textBaseline = 'bottom'
this.ctx.textAlign = 'left'
this.ctx.fillText(this.pips.x.min,(this.pips.y?12:2)*PXSCALE,this.height)
this.ctx.textAlign = 'right'
this.ctx.fillText(this.pips.x.max,this.width-2*PXSCALE,this.height)
}
if (this.pips.y) {
this.ctx.save()
this.ctx.translate(0, this.height)
this.ctx.rotate(-Math.PI/2)
this.ctx.textBaseline = 'top'
this.ctx.textAlign = 'left'
this.ctx.fillText(this.pips.y.min,(this.pips.x?12:2)*PXSCALE,2*PXSCALE)
this.ctx.textAlign = 'right'
this.ctx.fillText(this.pips.y.max,this.height-2*PXSCALE,2*PXSCALE)
this.ctx.rotate(Math.PI/2)
this.ctx.restore()
}
}
draw_line() {
var points = []
for (let i in this.value) {
if (this.value[i].length) {
points.push(mapToScale(this.value[i][0],[this.rangeX.min,this.rangeX.max],[0,this.width],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))
} else {
points.push(mapToScale(i,[0,this.value.length-1],[0,this.width],0,this.logScaleX,true))
points.push(mapToScale(this.value[i],[this.rangeY.min,this.rangeY.max],[this.height-2*PXSCALE,2*PXSCALE],0,this.logScaleY,true))
}
}
if (points.length < 4) return points
this.ctx.beginPath()
this.ctx.curve(points, this.smooth, Math.round(this.width/(points.length/2 - 1)))
this.ctx.globalAlpha = 0.7
this.ctx.lineWidth = 2 * PXSCALE
this.ctx.strokeStyle = this.colors.custom
this.ctx.stroke()
if (this.getProp('origin') !== false) {
var origin = mapToScale(this.getProp('origin'), [this.rangeY.min,this.rangeY.max],[this.height,0],0,this.getProp('logScaleY'),true)
this.ctx.globalAlpha = 0.1
this.ctx.fillStyle = this.colors.custom
this.ctx.lineTo(this.width,origin)
this.ctx.lineTo(0,origin)
this.ctx.closePath()
this.ctx.fill()
}
return points
}
draw_dots(points) {
this.ctx.globalAlpha = 1
this.ctx.fillStyle = this.colors.custom
this.ctx.strokeStyle = this.colors.track
this.ctx.lineWidth = 2 * PXSCALE
for (var i = 0; i < points.length; i += 2) {
this.ctx.beginPath()
this.ctx.arc(points[i], points[i + 1], 3 * PXSCALE, 0, 2*Math.PI)
this.ctx.fill()
this.ctx.stroke()
}
}
draw_bars() {
var barWidth = Math.round(this.width / this.value.length),
offset = Math.round((this.width - barWidth * this.value.length) / 2)
var origin = mapToScale(this.getProp('origin') !== false ? this.getProp('origin') : this.rangeY.min, [this.rangeY.min,this.rangeY.max],[this.height,0],0,this.getProp('logScaleY'),true)
this.ctx.beginPath()
for (let i in this.value) {
var y = mapToScale(this.value[i].length ? this.value[i][1] : this.value[i],[this.rangeY.min,this.rangeY.max],[this.height-2*PXSCALE,2*PXSCALE],0,this.logScaleY,true)
this.ctx.rect(offset + i * barWidth, Math.min(y, origin), barWidth - PXSCALE, Math.abs(Math.min(y - origin)))
}
this.ctx.globalAlpha = 0.4
this.ctx.fillStyle = this.colors.custom
this.ctx.fill()
}
setValue(v, options={}) {
if (typeof v == 'string') {
try {
v = JSON.parseFlex(v)
} catch(err) {}
}
if (typeof v == 'object' && v !== null) {
if (Array.isArray(v)) {
this.value = v
} else {
for (var i in v) {
if (!isNaN(i)) this.value[i] = v[i]
}
}
this.batchDraw()
if (options.sync) this.changed(options)
}
}
updateData() {
// update the coordinates to draw
}
}

View file

@ -1,109 +0,0 @@
var {clip} = require('../utils'),
_biquad_response = require('./_biquad_response'),
_plots_base = require('./_plots_base')
module.exports = class Eq extends _plots_base {
static description() {
return 'Draws frequency response between from from an array of filter objects.'
}
static defaults() {
return super.defaults({
_eq:'eq',
pips: {type: 'boolean', value: true, help: 'Set to false to hide the scale'},
resolution: {type: 'number', value: 128, help: 'Defines the number of points used to compute the frequency response'},
rangeY: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'},
origin: {type: 'number|boolean', value: 'auto', help: 'Defines the y axis origin. Set to `false` to disable it'},
logScaleX: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (base 10). Set to a `number` to define the logarithm\'s base.'},
smooth: {type: 'boolean|number', value: false, help: 'Set to `true` to make the line smooth. Float values are also acceptable (works fine between `0` and `0.5`)'},
}, ['precision', 'bypass'], {
value: {type: 'array', value: '', help: [
'Each item must be an object with the following properties',
'- `type`: string ("highpass", "highshelf", "lowpass", "lowshelf", "peak" or "notch")',
'- `freq`: number (filter\'s resonant frequency)',
'- `q`: number (Q factor)',
'- `gain`: number',
'- `on`: boolean',
]}
})
}
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])
}
setValue(v, options={}) {
if (typeof v == 'string') {
try {
v = JSON.parseFlex(v)
} catch(err) {}
}
if (Array.isArray(v)) {
var filters = v,
eqResponse = []
if (v.length === this.resolution) {
eqResponse = v
} else {
for (let i in filters) {
var filterResponse
if (!filters[i].type) filters[i].type = 'peak'
if (!filters[i].on) {
filterResponse = _biquad_response({type:'peak',freq:1,gain:0,q:1},!this.getProp('logScaleX'), this.resolution)
} else {
filterResponse = _biquad_response(filters[i],!this.getProp('logScaleX'), this.resolution)
}
for (var k in filterResponse) {
if (eqResponse[k]===undefined) {
eqResponse[k]=[0,0]
}
eqResponse[k] = [filterResponse[k][0], eqResponse[k][1]+filterResponse[k][1]]
}
}
}
if (eqResponse.length) super.setValue(eqResponse, options)
}
}
}

View file

@ -1,52 +0,0 @@
var {mapToScale} = require('../utils'),
Widget = require('../common/widget'),
html = require('nanohtml'),
StaticProperties = require('../mixins/static_properties')
module.exports = class Led extends StaticProperties(Widget, {bypass: true}) {
static description() {
return 'Intensity display.'
}
static defaults() {
return super.defaults({
_led:'led',
range: {type: 'object', value: {min:0,max:1}, help: 'Value to led intensity mapping range'},
logScale: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale (base 10). Set to a `number` to define the logarithm\'s base.'},
}, ['precision', 'bypass'], {})
}
constructor(options) {
// backward compat
if (options.props.widgetId) {
options.props.value = '@{' + options.props.widgetId + '}'
delete options.props.widgetId
}
super({...options, html: html`<div class="led"></div>`})
this.setValue(this.getProp('range').min)
}
setValue(v, options={}) {
if (typeof v != 'number') return
this.value = v
this.widget.style.setProperty('--opacity', mapToScale(v,[this.getProp('range').min,this.getProp('range').max],[0,1],false,this.getProp('logScale'),true))
if (options.sync) this.changed(options)
}
}

View file

@ -1,65 +0,0 @@
var Fader = require('../sliders/fader'),
Widget = require('../common/widget'),
StaticProperties = require('../mixins/static_properties')
module.exports = class Meter extends StaticProperties(Fader, {bypass: true, compact: true, input: false}) {
static description() {
return 'Non-interactable fader.'
}
static defaults() {
return Widget.defaults({
_meter:'meter',
range: {type: 'object', value: {min:0,max:1}, help: 'See fader\'s `range`'},
logScale: {type: 'boolean', value: false, help: 'See fader\'s `logScale`'},
origin: {type: 'number', value: 'auto', help: 'See fader\'s `origin`'},
unit: {type: 'string', value: 'auto', help: 'See fader\'s `unit`'},
alignRight: {type: 'boolean', value: false, help: 'See fader\'s `alignRight`'},
horizontal: {type: 'boolean', value: false, help: 'See fader\'s `horizontal`'},
pips: {type: 'boolean', value: false, help: 'See fader\'s `pips`'},
dashed: {type: 'boolean', value: false, help: 'See fader\'s `dashed`'},
gradient: {type: 'array|object', value: [], help: [
'When set, the meter\'s gauge will be filled with a linear color gradient',
'- each item must be a CSS color string.',
'- as an `object`: each key must be a number between 0 and 1',
'- each item must be a CSS color string.',
'Examples: `[\'blue\', \'red\']`, {\'0\': \'blue\', \'0.9\': \'blue\', \'1\': \'red\'} '
]},
}, ['precision', 'bypass'], {
css: {type: 'string', value: '', help: [
'Available CSS variables:',
'- `--color-gauge: color;`',
'- `--color-knob: color;`',
'- `--color-pips: color;`',
'- `--gauge-opacity: number;`'
]},
})
}
constructor(options) {
// backward compat
if (options.props.widgetId) {
options.props.value = '@{' + options.props.widgetId + '}'
delete options.props.widgetId
}
super(options)
this.widget.classList.add('meter')
this.off(/drag(.*)?/)
}
}

View file

@ -1,53 +0,0 @@
var _plots_base = require('./_plots_base')
module.exports = class Plot extends _plots_base {
static description() {
return 'XY coordinates plot.'
}
static defaults() {
return super.defaults({
_plot:'plot',
rangeX: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the x axis'},
rangeY: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'},
logScaleX: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (base 10). Set to a `number` to define the logarithm\'s base.'},
logScaleY: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (base 10). Set to a `number` to define the logarithm\'s base.'},
origin: {type: 'number', value: 'auto', help: 'Defines the y axis origin. Set to `false` to disable it.'},
dots: {type: 'boolean', value: true, help: ''},
bars: {type: 'boolean', value: false, help: 'Set to `true` to use draw bars instead (disables `logScaleX` and forces `x axis` even spacing)'},
smooth: {type: 'boolean|number', value: false, help: 'Set to `true` to make the line smooth. Float values are also acceptable (works fine between `0` and `0.5`)'},
pips:{type: 'boolean', value: true, help: 'Set to `false` to hide the scale'},
}, ['precision', 'bypass'], {
value: {type: 'array|string', value: '', help: [
'- `Array` of `y` values',
'- `Array` of `[x, y]` `array` values',
'- `String` `array`',
'- `String` `object` to update specific coordinates only: `{0:1, 4:0}` will change the 1st and 5th points\' coordinates',
]}
})
}
constructor(options) {
// backward compat
if (options.props.points && options.props.points.length) {
options.props.value = options.props.points
delete options.props.points
}
super(options)
}
}

View file

@ -1,79 +0,0 @@
var Widget = require('../common/widget'),
{clip} = require('../utils'),
html = require('nanohtml'),
StaticProperties = require('../mixins/static_properties')
module.exports = class Rbgled extends StaticProperties(Widget, {bypass: true}) {
static description() {
return 'Rgb / rgba color display'
}
static defaults() {
return super.defaults({}, ['color', 'precision', 'bypass'], {
value: {type: 'array|string', value: '', help: [
'- `Array`: `[r, g, b]` (`r`, `g` and `b` between `0` and `255`)',
'- `Array`: `[r, g, b, alpha]` (`alpha` between `0` and `255`)',
'- `String`: CSS color',
]}
})
}
constructor(options) {
// backward compat
if (options.props.widgetId) {
options.props.value = '@{' + options.props.widgetId + '}'
delete options.props.widgetId
}
super({...options, html: html`
<div class="led">
</div>
`})
this.setValue([0,0,0,0])
}
setValue(v, options={}) {
var c = ''
if (Array.isArray(v) && v.length >= 3) {
for (let i in [0,1,2]) {
v[i] = parseInt(clip(v[i],[0,255]))
}
v[3] = clip(v[3] != undefined ? v[3] : 1,[0,1])
c = `rgba(${v[0]}, ${v[1]}, ${v[2]}, ${v[3]})`
} else if (typeof v == 'string') {
c = v
} else {
return
}
this.value = v
this.widget.style.setProperty('--color-led', c)
if (options.sync) this.changed(options)
}
}

View file

@ -0,0 +1,20 @@
var {mapToScale} = require('../utils'),
Widget = require('../common/widget'),
StaticProperties = require('../mixins/static_properties')
module.exports = class Script extends StaticProperties(Widget, {visible: false}) {
constructor(options) {
super(options)
// compile script
}
runScript() {
}
}

View file

@ -2,32 +2,11 @@ var {clip} = require('../utils'),
Knob = require('./knob'),
Widget = require('../common/widget'),
doubletab = require('../mixins/double_tap'),
html = require('nanohtml')
html = require('nanohtml'),
StaticProperties = require('../mixins/static_properties')
var EncoderKnob = class extends Knob {
draginitHandle(e) {
this.percent = clip(this.percent,[0,100])
this.lastOffsetX = e.offsetX
this.lastOffsetY = e.offsetY
if (!(e.traversing || this.getProp('snap'))) return
this.percent = this.angleToPercent(this.coordsToAngle(e.offsetX, e.offsetY))
this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true, draginit:!e.traversing})
}
mousewheelHandle(){}
}
var DisplayKnob = class extends Knob {
}
module.exports = class Encoder extends Widget {
module.exports = class Encoder extends StaticProperties(Knob, {angle: 360, range: {min: 0, max: 1}, sensitivity: 1, steps: ''}) {
static description() {
@ -37,11 +16,10 @@ module.exports = class Encoder extends Widget {
static defaults() {
return super.defaults({
return Widget.defaults({
_encoder: 'encoder',
compact: {type: 'boolean', value: false, help: 'Set to `true` to display a compact alternative for the widget.'},
ticks: {type: 'number', value: 360, help: 'defines the granularity / verbosity of the encoder (number of step for a 360° arc)'},
back: {type: '*', value: -1, help: 'Defines which value is sent when rotating the encoder anticlockwise'},
forth: {type: '*', value: 1, help: 'Defines which value is sent when rotating the encoder clockwise'},
@ -50,7 +28,11 @@ module.exports = class Encoder extends Widget {
'- Set to `null` to send send no argument in the osc message',
'- Can be an `object` if the type needs to be specified'
]},
snap: {type: 'boolean', value: false, help: 'By default, dragging the widget will modify it\'s value starting from its last value. Setting this to `true` will make it snap directly to the mouse/touch position'},
mode: {type: 'string', value: 'circular', choices: ['circular', 'snap', 'vertical'], help: [
'- `circular`: relative move in circular motion',
'- `snap`: snap to touch position and move in vertical motion',
'- `vertical`: relative move in vertical motion',
]},
doubleTap: {type: 'boolean', value: false, help: [
'Set to `true` to make the fader reset to its `default` value when receiving a double tap.',
'Can also be an osc address, in which case the widget will just send an osc message (`/<doubleTap> <preArgs>`)'
@ -66,217 +48,213 @@ module.exports = class Encoder extends Widget {
constructor(options) {
super({...options, html: html`
<div class="encoder">
<div class="wrapper">
</div>
</div>
`})
super(options)
this.wrapper = DOM.get(this.widget, '.wrapper')[0]
this.ticks = Math.abs(parseInt(this.getProp('ticks')) || 360)
this.previousPercent = 50
this.percent = 50
this.setValue(this.getProp('release'), {dragged: true})
this.knob = new EncoderKnob({props:{
label:false,
angle:360,
snap:true,
range:{min:0,max:this.ticks},
pips:false,
}, parent: this})
}
this.knob.batchDraw = ()=>{}
angleToPercent(angle, snap) {
this.display = new DisplayKnob({props:{
label:false,
angle:360,
range:{min:0,max:this.ticks},
origin:this.ticks/2,
pips:false,
compact: this.getProp('compact')
}, parent: this})
// knob.js without clipping
if (snap) return super.angleToPercent(angle)
this.knob.widget.classList.add('drag-knob')
this.display.widget.classList.add('display-knob')
var percent = angle - (360 - this.maxAngle) / 2 / this.maxAngle * 100
if (percent < 0) percent += 100
else if (percent > 100) percent -= 100
this.wrapper.appendChild(this.knob.widget)
this.wrapper.appendChild(this.display.widget)
return percent
this.knob.setValue(this.ticks/2)
this.display.setValue(this.ticks/2)
}
this.previousValue = this.ticks/2
percentToAngle(percent, snap) {
this.on('change',(e)=>{
// knob.js without clipping
if (snap) return super.percentToAngle(percent)
if (e.widget == this) return
return 2 * Math.PI * percent / 100 * (this.maxAngle / 360) // angle relative to maxAngle
+ Math.PI / 2 // quarter circle offset
+ Math.PI * (1 - this.maxAngle / 360) // centering offset depending on maxAngle
e.stopPropagation = true
var value = this.knob.getValue()
var direction
if (value < this.previousValue)
direction = this.getProp('back')
if (value > this.previousValue)
direction = this.getProp('forth')
if ((this.ticks * .75 < value && value < this.ticks) && (0 < this.previousValue && this.previousValue < this.ticks / 4))
direction = this.getProp('back')
if ((0 < value && value < this.ticks / 4) && (this.ticks * .75 < this.previousValue && this.previousValue < this.ticks))
direction = this.getProp('forth')
}
if (direction !== undefined && (Math.round(value) != Math.round(this.previousValue))) this.setValue(direction, {sync:true, send:true, dragged: e.options.dragged, draginit: e.options.draginit})
draginitHandle(e) {
this.previousValue = value
// knob.js without clipping + extra case for snap
})
this.lastOffsetX = e.offsetX
this.lastOffsetY = e.offsetY
this.knob.on('draginit', (e)=>{
if (this.getProp('touchAddress') && this.getProp('touchAddress').length
&& e.target == this.wrapper)
this.sendValue({
address:this.getProp('touchAddress'),
v:1
})
})
if (this.getProp('mode') === 'snap') {
this.knob.on('dragend', (e)=>{
if (this.getProp('release') !== '' && this.value !== this.getProp('release')) {
this.knob.setValue(this.ticks/2)
this.display.setValue(this.ticks/2)
this.setValue(this.getProp('release'), {sync:true, send:true, dragged:false})
}
if (
this.getProp('touchAddress') && this.getProp('touchAddress').length
&& e.target == this.wrapper
) {
this.sendValue({
address:this.getProp('touchAddress'),
v:0
})
}
})
if (this.getProp('doubleTap')) {
doubletab(this.wrapper, ()=>{
this.knob.setValue(this.ticks/2)
this.display.setValue(this.ticks/2)
if (this.getProp('release') !== '' && this.value !== this.getProp('release')) {
this.setValue(this.getProp('release'), {sync:true, send:true, dragged:false})
}
})
this.setPercent(this.angleToPercent(this.coordsToAngle(e.offsetX, e.offsetY), true))
}
this.wrapper.addEventListener('mousewheel', (e)=>{
if (e.wheelDeltaX || e.wheelDelta == 0) return
var direction = e.wheelDelta / Math.abs(e.wheelDelta)
}
this.display.setValue(this.display.value + direction)
this.setValue(direction < 0 ? this.getProp('back') : this.getProp('forth'), {sync:true, send:true})
dragHandle(e) {
// knob.js without clipping + extra case for snap
if ((this.getProp('mode') === 'vertical' && !e.traversing) || e.ctrlKey) {
// vertical
this.setPercent(-100 * (e.movementY / e.inertia * this.getProp('sensitivity')) / this.height + this.percent)
} else {
// snap or circular
var offsetX = this.lastOffsetX + e.movementX / e.inertia,
offsetY = this.lastOffsetY + e.movementY / e.inertia
if (true || e.traversing && this.getProp('mode') === 'circular') {
// circular
var diff = this.angleToPercent(this.coordsToAngle(offsetX, offsetY), true) - this.angleToPercent(this.coordsToAngle(this.lastOffsetX, this.lastOffsetY), true)
if (Math.abs(diff) < 50 && diff !== 0) this.setPercent(this.percent + diff)
} else {
// snap
this.setPercent(this.angleToPercent(this.coordsToAngle(offsetX, offsetY), true))
if (this.getProp('release') !== '' && this.value !== this.getProp('release')) {
this.knob.setValue(this.ticks/2)
this.display.setValue(this.ticks/2)
this.setValue(this.getProp('release'), {sync:true, send:true, dragged:false})
}
this.lastOffsetX = offsetX
this.lastOffsetY = offsetY
}
}
dragendHandle(e, data, traversing) {
if (this.getProp('release') === '') return
this.previousPercent = 50
this.percent = 50
this.setValue(this.getProp('release'), {sync: true, send: true, dragged: true})
}
mousewheelHandle(e) {
if (e.wheelDeltaX) return
e.preventDefault()
e.stopPropagation()
var direction = e.wheelDelta / Math.abs(e.wheelDelta),
increment = e.ctrlKey?0.25:1
this.setPercent(this.percent + Math.max(increment, 10 / Math.pow(10, this.precision + 1)) * direction)
}
setPercent(percent) {
var div = 100 / this.getProp('ticks')
percent = Math.round(percent / div) * div
this.previousPercent = this.percent
this.percent = percent
if (this.percent === this.previousPercent) return
var dir = this.percent > this.previousPercent
if (
(this.percent >= 0 && this.percent < 25 && this.previousPercent > 75 && this.previousPercent <= 100) ||
(this.previousPercent >= 0 && this.previousPercent < 25 && this.percent > 75 && this.percent <= 100)
) dir = !dir
var val = dir ? this.getProp('forth') : this.getProp('back')
this.setValue(val, {
sync: true,
send: true,
dragged: true,
})
}
getSpringValue() {
return this.getProp('release')
}
setValue(v,options={}) {
if (this.getProp('snap') || (!this.getProp('snap') && !options.draginit)) {
if (options.fromLocal && v === this.getProp('release')) {
this.percent = 50
this.previousPercent = 50
} else if (
!options.dragged ||
(v !== this.getProp('forth') && v !== this.getProp('back') && (this.getProp('release') === '' && v !== this.getProp('release')))
var match = true
) return
if (v === this.getProp('back')) {
this.value = this.getProp('back')
} else if (v === this.getProp('forth')) {
this.value = this.getProp('forth')
} else if (v === this.getProp('release') && this.getProp('release') !== '') {
this.value = this.getProp('release')
} else {
match = false
}
this.value = v
}
this.batchDraw()
if (options.sync && match) this.changed(options)
if (options.send && match && !(!this.getProp('snap') && options.draginit)) this.sendValue()
if (options.dragged || options.draginit) this.updateDisplay(options.draginit)
if (options.send) this.sendValue()
if (options.sync) this.changed(options)
}
updateDisplay(init){
draw() {
if (this.getProp('snap')) {
this.display.setValue(this.knob.value)
return
var percent = this.percent,
d = this.percentToAngle(percent),
angle = 2 * Math.PI / 16,
min = this.percentToAngle(0),
max = this.percentToAngle(100),
minRadius = this.minDimension / 6,
maxRadius = this.minDimension / 2 - PXSCALE,
gaugeWidth = maxRadius - minRadius,
gaugeRadius = maxRadius - gaugeWidth / 2
this.clear()
// fill
this.ctx.globalAlpha = this.cssVars.alphaFill
this.ctx.strokeStyle = this.cssVars.colorFill
this.ctx.lineWidth = gaugeWidth - this.gaugePadding * 2
if (this.cssVars.alphaFillOff) {
this.ctx.globalAlpha = this.cssVars.alphaFillOff
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, min, max)
this.ctx.stroke()
}
if (init) {
this.offset = this.knob.value - this.display.value
} else {
var v = this.knob.value - this.offset,
updateOffset
if (v > this.ticks) {
v = this.ticks - v
updateOffset = true
} else if (v < 0) {
v = v + this.ticks
updateOffset = true
}
this.display.setValue(v)
if (updateOffset) {
this.offset = this.knob.value - this.display.value
}
if (this.cssVars.alphaFillOn) {
this.ctx.globalAlpha = this.cssVars.alphaFillOn
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, d - angle, d + angle)
this.ctx.stroke()
}
if (this.offset > this.ticks) this.offset = this.ticks - this.offset
if (this.offset < 0) this.offset = this.offset + this.ticks
// stroke
}
this.ctx.globalAlpha = this.cssVars.alphaStroke
this.ctx.strokeStyle = this.cssVars.colorStroke
this.ctx.lineWidth = PXSCALE
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, minRadius, 0, 2 * Math.PI)
this.ctx.stroke()
onPropChanged(propName, options, oldPropValue) {
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, maxRadius, 0, 2 * Math.PI)
this.ctx.stroke()
if (super.onPropChanged(...arguments)) return true
switch (propName) {
case 'color':
for (var w of [this.knob, this.display]) {
w.onPropChanged('color')
}
return
}
}
onRemove() {
this.knob.onRemove()
this.display.onRemove()
super.onRemove()
}
}

View file

@ -20,14 +20,14 @@ module.exports = class Fader extends Slider {
horizontal: {type: 'boolean', value: false, help: 'Set to `true` to display the fader horizontally'},
alignRight: {type: 'boolean', value: false, help: 'Set to `true` to invert the pip\'s and fader\'s position'},
pips: {type: 'boolean', value: true, help: 'Set to `false` to hide the scale'},
input: {type: 'boolean', value: true, help: 'Set to `false` to hide the built-in input'},
meter: {type: 'boolean', value: false, help: [
'Set to true to display a vu-meter next in the fader',
'- the meter\'s `id` will be the same as the widget\'s with `/meter` appended to it',
'- the meter\'s `address` will be the same as the widget\'s with `/meter` appended to it'
]},
compact: {type: 'boolean', value: false, help: 'Set to `true` to display a compact alternative for the widget. If `input` is `true`, the input can be focused with a right-click (mouse only). Disables `pips` when enabled.'},
dashed: {type: 'boolean', value: false, help: 'Set to `true` to display a dashed gauge'},
gradient: {type: 'array|object', value: [], help: [
'When set, the meter\'s gauge will be filled with a linear color gradient',
'- each item must be a CSS color string.',
'- as an `object`: each key must be a number between 0 and 1',
'- each item must be a CSS color string.',
'Examples: `[\'blue\', \'red\']`, {\'0\': \'blue\', \'0.9\': \'blue\', \'1\': \'red\'} '
]},
snap: {type: 'boolean', value: false, help: 'By default, dragging the widget will modify it\'s value starting from its last value. Setting this to `true` will make it snap directly to the mouse/touch position'},
spring: {type: 'boolean', value: false, help: 'When set to `true`, the widget will go back to its `default` value when released'},
doubleTap: {type: 'boolean', value: false, help: [
@ -48,21 +48,12 @@ module.exports = class Fader extends Slider {
'- `number`: define a number of evenly spaced steps',
'- `array`: use arbitrary values',
]},
unit: {type: 'string', value: '', help: 'Unit will be appended to the displayed widget\'s value (it doesn\'t affect osc messages)'},
origin: {type: 'number', value: 'auto', help: 'Defines the starting point\'s value of the fader\'s gauge'},
}, [], {
touchAddress: {type: 'string', value:'', help: 'OSC address for touched state messages: `/touchAddress [preArgs] 0/1`'},
meterAddress: {type: 'string', value:'', help: 'OSC address for the built-in meter'},
css: {type: 'string', value: '', help: [
'Available CSS variables:',
'- `--color-gauge: color;`',
'- `--color-knob: color;`',
'- `--color-pips: color;`',
'- `--gauge-opacity: number;`',
'- `--gauge-width: number;` (2-16, requires a manual resize to take effect)'
]}
})
}
@ -72,50 +63,18 @@ module.exports = class Fader extends Slider {
super(options)
this.widget.classList.add('fader')
this.margin = 22
this.gaugeWidth = 2
this.gaugeGradient = null
if (this.getProp('horizontal')) {
this.widget.classList.add('horizontal')
this.container.classList.add('horizontal')
}
if (this.getProp('compact')) {
this.margin = 0
}
if (this.getProp('alignRight') && !this.getProp('horizontal')) {
this.widget.classList.add('align-right')
}
if (this.getProp('meter')) {
var data = {
type:'meter',
id: this.getProp('id') + '/meter',
label:false,
horizontal:this.getProp('horizontal'),
range:this.getProp('range'),
logScale:this.getProp('logScale'),
address: '#{@{parent.meterAddress} ? @{parent.meterAddress} : concat(@{parent.address}, "/meter")}',
preArgs: '@{parent.preArgs}',
target: '@{parent.target}',
color: '@{parent.color}',
pips:false,
dashed:true
}
var meter = parser.parse({
data: data,
parentNode: this.wrapper,
parent: this
})
meter.container.classList.add('not-editable')
this.children.push(meter)
this.widget.classList.add('has-meter')
}
if (this.getProp('pips')) {
if (false && this.getProp('pips')) {
this.widget.classList.add('has-pips')
@ -139,7 +98,7 @@ module.exports = class Fader extends Slider {
}
this.wrapper.appendChild(pips)
this.widget.appendChild(pips)
}
@ -155,12 +114,12 @@ module.exports = class Fader extends Slider {
if (!(e.traversing || this.getProp('snap')) || e.ctrlKey) return
this.percent = this.getProp('horizontal')?
(e.offsetX - this.margin * PXSCALE) / (this.width - (this.margin * PXSCALE * 2)) * 100:
(this.height - e.offsetY - this.margin * PXSCALE) / (this.height - (this.margin * PXSCALE * 2)) * 100
(e.offsetX - this.gaugePadding) / (this.width - this.gaugePadding * 2) * 100:
(this.height - e.offsetY - this.gaugePadding) / (this.height - this.gaugePadding * 2) * 100
// this.percent = clip(this.percent,[0,100])
this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
this.setValue(this.percentToValue(this.percent), {send: true, sync: true, dragged: true})
}
@ -169,8 +128,8 @@ module.exports = class Fader extends Slider {
super.dragHandle(...arguments)
this.percent = this.getProp('horizontal')?
this.percent + ( e.movementX/(this.width - this.margin * PXSCALE * 2)) * 100 / e.inertia * this.getProp('sensitivity'):
this.percent + (-e.movementY/(this.height - this.margin * PXSCALE * 2)) * 100 / e.inertia * this.getProp('sensitivity')
this.percent + ( e.movementX / (this.width - this.gaugePadding * 2)) * 100 / e.inertia * this.getProp('sensitivity'):
this.percent + (-e.movementY / (this.height - this.gaugePadding * 2)) * 100 / e.inertia * this.getProp('sensitivity')
this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
@ -179,9 +138,9 @@ module.exports = class Fader extends Slider {
percentToCoord(percent) {
if (this.getProp('horizontal')) {
return clip(percent / 100,[0,1]) * (this.width - 2 * PXSCALE * this.margin) + this.margin * PXSCALE
return clip(percent / 100,[0,1]) * (this.width - this.gaugePadding * 2) + this.gaugePadding
} else {
return (this.height - this.margin * PXSCALE) - clip(percent / 100, [0,1]) * (this.height - 2 * PXSCALE * this.margin)
return (this.height - this.gaugePadding) - clip(percent / 100, [0,1]) * (this.height - this.gaugePadding * 2)
}
}
@ -190,14 +149,12 @@ module.exports = class Fader extends Slider {
var ratio = CANVAS_SCALING * this.scaling
if (this.getProp('compact') && this.getProp('horizontal')) {
event.height = 1 / ratio
}
// if (this.getProp('compact') && this.getProp('horizontal')) {
// event.height = 1 / ratio
// }
super.resizeHandle(event)
this.gaugeWidth = Math.max(2, Math.min(16, parseInt(event.style.getPropertyValue('--gauge-width')) || 2))
if (this.getProp('horizontal')){
this.ctx.setTransform(1, 0, 0, 1, 0, 0)
this.ctx.rotate(-Math.PI/2)
@ -223,7 +180,7 @@ module.exports = class Fader extends Slider {
for (var i in colors) {
grad.addColorStop(i / (colors.length - 1), colors[i])
}
this.colors.gradient = grad
this.gaugeGradient = grad
} else {
@ -232,7 +189,7 @@ module.exports = class Fader extends Slider {
grad.addColorStop(clip(k, [0, 1]), colors[k])
}
}
this.colors.gradient = grad
this.gaugeGradient = grad
}
} catch(err) {
@ -243,7 +200,6 @@ module.exports = class Fader extends Slider {
}
}
@ -255,103 +211,58 @@ module.exports = class Fader extends Slider {
var percent = this.getProp('steps') ? this.valueToPercent(this.value) : this.percent,
d = Math.round(this.percentToCoord(percent)),
o = Math.round(this.percentToCoord(this.valueToPercent(this.originValue))),
m = Math.round(this.getProp('horizontal') ? this.height / 2 : this.width / 2)
m = this.getProp('horizontal') ? this.height / 2 : this.width / 2
// sharp border trick
if (width % 2 && parseInt(m) === m) m -= 0.5
var dashed = this.getProp('dashed')
this.clear()
if (this.getProp('compact')) {
this.ctx.strokeStyle = this.gaugeGradient || this.cssVars.colorFill
this.ctx.lineWidth = Math.round(width - this.gaugePadding * 2)
this.ctx.globalAlpha = this.colors.gaugeOpacity || (dashed ? .3 : .2) + 0.2 * Math.abs(d-o) / (d<o?o:height-o)
if (dashed) this.ctx.setLineDash([PXSCALE, PXSCALE])
this.ctx.strokeStyle = this.colors.gradient || this.colors.gauge
if (this.cssVars.alphaFillOff) {
this.ctx.globalAlpha = this.cssVars.alphaFillOff
this.ctx.beginPath()
this.ctx.moveTo(m, o)
this.ctx.lineTo(m, d)
this.ctx.lineWidth = width + 2 * PXSCALE
if (dashed) this.ctx.setLineDash([PXSCALE, PXSCALE])
this.ctx.moveTo(m, height - this.gaugePadding)
this.ctx.lineTo(m, this.gaugePadding)
this.ctx.stroke()
if (dashed) this.ctx.setLineDash([])
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.knob
this.ctx.rect(0, Math.min(d, height - PXSCALE), width, PXSCALE)
this.ctx.fill()
this.clearRect = [0, 0, width, height]
} else {
this.ctx.lineWidth = (this.gaugeWidth + 4) * PXSCALE
this.ctx.beginPath()
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.colors.light
this.ctx.moveTo(m, this.margin * PXSCALE - 2 * PXSCALE)
this.ctx.lineTo(m, height - this.margin * PXSCALE + 2 * PXSCALE)
this.ctx.stroke()
this.ctx.lineWidth = (this.gaugeWidth + 2) * PXSCALE
this.ctx.beginPath()
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.colors.bg
this.ctx.moveTo(m, this.margin * PXSCALE - 1 * PXSCALE)
this.ctx.lineTo(m, height - this.margin * PXSCALE + 1 * PXSCALE)
this.ctx.stroke()
this.ctx.lineWidth = this.gaugeWidth * PXSCALE
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.track
this.ctx.moveTo(m, this.margin * PXSCALE)
this.ctx.lineTo(m, height - this.margin * PXSCALE)
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.globalAlpha = 0.7
this.ctx.strokeStyle = this.colors.gauge
this.ctx.moveTo(m, o)
this.ctx.lineTo(m, d)
if (dashed) this.ctx.setLineDash([PXSCALE, PXSCALE])
this.ctx.stroke()
if (dashed) this.ctx.setLineDash([])
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.rect(m - 9 * PXSCALE, d - 15 * PXSCALE, 18 * PXSCALE, 30 * PXSCALE)
this.ctx.lineWidth = PXSCALE
this.ctx.fillStyle = this.colors.bg
this.ctx.fill()
this.ctx.beginPath()
this.ctx.rect(m - 8 * PXSCALE, d - 14 * PXSCALE, 16 * PXSCALE, 28 * PXSCALE)
this.ctx.fillStyle = this.colors.raised
this.ctx.fill()
this.ctx.lineWidth = PXSCALE
this.ctx.beginPath()
this.ctx.rect(m - 7.5 * PXSCALE, d - 13.5 * PXSCALE, 15 * PXSCALE, 27 * PXSCALE)
this.ctx.lineWidth = PXSCALE
this.ctx.strokeStyle = this.colors.light
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.rect(m - 8 * PXSCALE, d - 14 * PXSCALE, 16 * PXSCALE, PXSCALE)
this.ctx.lineWidth = PXSCALE
this.ctx.fillStyle = this.colors.light
this.ctx.fill()
this.ctx.beginPath()
this.ctx.rect(m - 4 * PXSCALE, d, 8 * PXSCALE, PXSCALE)
this.ctx.fillStyle = this.colors.knob
this.ctx.fill()
this.clearRect = [width / 2 - 11 * PXSCALE, 0, 22 * PXSCALE, height]
}
if (this.cssVars.alphaFillOn) {
this.ctx.globalAlpha = this.cssVars.alphaFillOn
this.ctx.beginPath()
this.ctx.moveTo(m, o)
this.ctx.lineTo(m, d)
this.ctx.stroke()
}
if (dashed) this.ctx.setLineDash([])
this.ctx.globalAlpha = this.cssVars.alphaStroke
this.ctx.strokeStyle = this.cssVars.colorStroke
this.ctx.beginPath()
this.ctx.moveTo(0, 0)
this.ctx.lineTo(width, 0)
this.ctx.lineTo(width, height)
this.ctx.lineTo(0, height)
this.ctx.closePath()
this.ctx.lineWidth = 2 * PXSCALE
this.ctx.stroke()
this.ctx.globalAlpha = 1
this.ctx.fillStyle = this.cssVars.colorFill
this.ctx.beginPath()
this.ctx.rect(this.gaugePadding, Math.min(d, height - 3 * PXSCALE), width - this.gaugePadding * 2, PXSCALE)
this.ctx.fill()
this.clearRect = [0, 0, width, height]
}

View file

@ -16,8 +16,6 @@ module.exports = class Knob extends Slider {
_knob:'knob',
pips: {type: 'boolean', value: false, help: 'Set to `true` to show the scale\'s breakpoints'},
input: {type: 'boolean', value: true, help: 'Set to `false` to hide the built-in input'},
compact: {type: 'boolean', value: false, help: 'Set to `true` to display a compact alternative for the widget. If `input` is `true`, the input can be focused with a right-click (mouse only). Disables `pips` when enabled.'},
dashed: {type: 'boolean', value: false, help: 'Set to `true` to display a dashed gauge'},
angle: {type: 'number', value: 270, help: 'Defines the angle\'s width of the knob, in degrees'},
snap: {type: 'boolean', value: false, help: 'By default, dragging the widget will modify it\'s value starting from its last value. Setting this to `true` will make it snap directly to the mouse/touch position'},
@ -40,18 +38,11 @@ module.exports = class Knob extends Slider {
'- `number`: define a number of evenly spaced steps',
'- `array`: use arbitrary values',
]},
unit: {type: 'string', value: '', help: 'Unit will be appended to the displayed widget\'s value (it doesn\'t affect osc messages)'},
origin: {type: 'number', value: 'auto', help: 'Defines the starting point\'s value of the knob\'s gauge'},
}, [], {
touchAddress: {type: 'string', value:'', help: 'OSC address for touched state messages: `/touchAddress [preArgs] 0/1`'},
css: {type: 'string', value: '', help: [
'Available CSS variables:',
'- `--color-gauge: color;`',
'- `--color-knob: color;`',
'- `--color-pips: color;`'
]}
})
@ -69,11 +60,6 @@ module.exports = class Knob extends Slider {
this.maxAngle = this.getProp('angle')
// calculate lost height factor
var a = (1 - Math.sin((Math.max(this.maxAngle,247.5) - 180) / 2 * Math.PI / 180)) / 3
this.lostHeightFactor = a / 4
if (this.getProp('pips')) {
this.widget.classList.add('has-pips')
@ -110,7 +96,7 @@ module.exports = class Knob extends Slider {
if (!(e.traversing || this.getProp('snap')) || e.ctrlKey) {
// vertical
this.percent = -100 * (e.movementY / e.inertia * this.getProp('sensitivity')) / this.height + this.percent
this.percent = -100 * (e.movementY / e.inertia * this.getProp('sensitivity')) / this.minDimension + this.percent
} else {
//snap
@ -175,7 +161,7 @@ module.exports = class Knob extends Slider {
this.minDimension = Math.min(this.width, this.height)
this.wrapper.style.top = (this.minDimension) * this.lostHeightFactor - (this.getProp('label') === false ? 0 : this.gaugeWidth / 4) + 'px'
this.widget.style.top = this.minDimension - (this.getProp('label') === false ? 0 : this.gaugeWidth / 4) + 'px'
}
@ -188,100 +174,89 @@ module.exports = class Knob extends Slider {
max = this.percentToAngle(100),
dashed = this.getProp('dashed'),
pips = this.getProp('pips'),
gaugeWidth = Math.max(7 * PXSCALE, this.minDimension / 20),
gaugeRadius = this.minDimension / 2 - gaugeWidth / 2 - 2 * PXSCALE,
knobRadius = gaugeRadius - gaugeWidth,
rad = PXSCALE / gaugeRadius / 2
minRadius = this.minDimension / 6,
maxRadius = this.minDimension / 2 - (pips ? this.fontSize * 1.5 : PXSCALE),
gaugeWidth = maxRadius - minRadius,
gaugeRadius = maxRadius - gaugeWidth / 2
this.clear()
if (this.getProp('compact')) {
pips = false
gaugeWidth = this.minDimension / 4
gaugeRadius = this.minDimension / 2 - gaugeWidth / 2
// fill
this.ctx.strokeStyle = this.cssVars.colorFill
this.ctx.lineWidth = gaugeWidth - this.gaugePadding * 2
if (this.cssVars.alphaFillOff) {
this.ctx.globalAlpha = this.cssVars.alphaFillOff
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, min, max)
this.ctx.stroke()
}
if (pips) {
gaugeRadius -= this.fontSize * PXSCALE * 1.5 + gaugeWidth / 2
knobRadius = gaugeRadius - gaugeWidth
}
this.ctx.clearRect(0,0,this.width,this.height)
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.colors.light
this.ctx.lineWidth = gaugeWidth
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, min - 4 * rad, max + 4 * rad)
this.ctx.stroke()
this.ctx.strokeStyle = this.colors.bg
this.ctx.lineWidth = gaugeWidth - 2 * PXSCALE
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, min - 2 * rad, max + 2 * rad)
this.ctx.stroke()
if (dashed) this.ctx.setLineDash([1.5 * PXSCALE, 1.5 * PXSCALE])
this.ctx.strokeStyle = this.colors.track
this.ctx.lineWidth = gaugeWidth - 4.5 * PXSCALE
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, min, max)
this.ctx.stroke()
this.ctx.globalAlpha = 0.7
this.ctx.strokeStyle = this.colors.gauge
this.ctx.lineWidth = gaugeWidth - 4.5 * PXSCALE
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, o, d, o > d)
this.ctx.stroke()
if (this.cssVars.alphaFillOn) {
this.ctx.globalAlpha = this.cssVars.alphaFillOn
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, o, d, o > d)
this.ctx.stroke()
}
if (dashed) this.ctx.setLineDash([])
if (this.getProp('compact')) {
this.ctx.globalAlpha = 1
let r1 = gaugeRadius - gaugeWidth / 2 + 2 * PXSCALE,
r2 = gaugeRadius + gaugeWidth / 2 - 2 * PXSCALE,
a = 2 * Math.PI - d
this.ctx.beginPath()
this.ctx.moveTo(r1 * Math.cos(a) + this.width / 2, this.height / 2 - r1 * Math.sin(a))
this.ctx.lineTo(r2 * Math.cos(a) + this.width / 2, this.height / 2 - r2 * Math.sin(a))
// stroke
this.ctx.lineWidth = PXSCALE
this.ctx.strokeStyle = this.colors.knob
this.ctx.stroke()
return
}
this.ctx.globalAlpha = this.cssVars.alphaStroke
this.ctx.strokeStyle = this.cssVars.colorStroke
this.ctx.lineWidth = PXSCALE
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, minRadius, 0, 2 * Math.PI)
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, maxRadius, 0, 2 * Math.PI)
this.ctx.stroke()
// knob
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.cssVars.colorFill
this.ctx.lineWidth = 1.5 * PXSCALE
let r1 = minRadius + this.gaugePadding,
r2 = maxRadius - this.gaugePadding,
a = 2 * Math.PI - d
this.ctx.beginPath()
this.ctx.moveTo(r1 * Math.cos(a) + this.width / 2, this.height / 2 - r1 * Math.sin(a))
this.ctx.lineTo(r2 * Math.cos(a) + this.width / 2, this.height / 2 - r2 * Math.sin(a))
this.ctx.stroke()
// pips
if (pips) {
this.ctx.globalAlpha = 1
this.ctx.lineWidth = 1.5 * PXSCALE
this.ctx.strokeStyle = this.cssVars.colorStroke
for (var pip of this.rangeKeys.concat(this.valueToPercent(this.originValue))) {
let a = this.percentToAngle(pip)
let r1 = maxRadius,
r2 = r1 + 4 * PXSCALE,
a = 2 * Math.PI - this.percentToAngle(pip)
this.ctx.lineWidth = gaugeWidth + 2 * PXSCALE
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, a - 4.5 * rad, a + 4.5 * rad)
this.ctx.strokeStyle = this.colors.fg
this.ctx.stroke()
this.ctx.strokeStyle = this.colors.light
this.ctx.stroke()
this.ctx.lineWidth = gaugeWidth + 1.5 * PXSCALE
this.ctx.strokeStyle = this.colors.pips
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, a - 2 * rad, a + 2 * rad)
this.ctx.moveTo(r1 * Math.cos(a) + this.width / 2, this.height / 2 - r1 * Math.sin(a))
this.ctx.lineTo(r2 * Math.cos(a) + this.width / 2, this.height / 2 - r2 * Math.sin(a))
this.ctx.stroke()
}
var radius = gaugeRadius + this.fontSize * PXSCALE + gaugeWidth / 2
var radius = maxRadius + this.fontSize * 1.5
this.ctx.fillStyle = this.colors.textFade
for (var p in this.pipTexts) {
if (this.pipTexts[p] == undefined) continue
@ -294,46 +269,6 @@ module.exports = class Knob extends Slider {
}
// knob
this.ctx.lineWidth = PXSCALE
this.ctx.fillStyle = this.colors.raised
this.ctx.beginPath()
this.ctx.globalAlpha = 1
this.ctx.arc(this.width / 2, this.height / 2, knobRadius, 0, Math.PI * 2)
this.ctx.fill()
this.ctx.strokeStyle = this.colors.bg
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.globalAlpha = 1
this.ctx.arc(this.width / 2, this.height / 2, knobRadius - PXSCALE * 1.5, 0, Math.PI * 2)
this.ctx.strokeStyle = this.colors.light
this.ctx.stroke()
var g = this.ctx.createLinearGradient(this.width / 2, this.height / 2 - knobRadius / 2,this.width / 2, this.height / 2 + knobRadius / 2)
g.addColorStop(0.5, 'transparent')
g.addColorStop(0, this.colors.light || 'transparent')
this.ctx.strokeStyle = g
this.ctx.stroke()
// cursor
this.ctx.globalAlpha = 1
let r1 = knobRadius - PXSCALE,
r2 = knobRadius / 4,
a = 2 * Math.PI - d
this.ctx.beginPath()
this.ctx.moveTo(r1 * Math.cos(a) + this.width / 2, this.height / 2 - r1 * Math.sin(a))
this.ctx.lineTo(r2 * Math.cos(a) + this.width / 2, this.height / 2 - r2 * Math.sin(a))
this.ctx.lineWidth = gaugeWidth - 4.5 * PXSCALE
this.ctx.strokeStyle = this.colors.knob
this.ctx.stroke()
}
}

View file

@ -1,5 +1,5 @@
var {clip} = require('../utils'),
Widget = require('../common/widget'),
Canvas = require('../common/canvas'),
Fader = require('./fader'),
Input = require('../inputs/input'),
touchstate = require('../mixins/touch_state'),
@ -7,172 +7,7 @@ var {clip} = require('../utils'),
var faderDefaults = Fader.defaults()._props()
var RangeFader = class RangeFader extends Fader {
constructor(options) {
super(options)
this.cancelDraw = options.cancelDraw
}
sendValue() {}
draginitHandle() {
this.percent = clip(this.percent,[
this.valueToPercent(this.rangeValsMin),
this.valueToPercent(this.rangeValsMax)
])
super.draginitHandle(...arguments)
}
draw() {
if (this.cancelDraw || !this.parent.faders) return
var width = this.getProp('horizontal') ? this.height : this.width,
height = !this.getProp('horizontal') ? this.height : this.width
var d = Math.round(this.percentToCoord(this.valueToPercent(this.parent.faders[this.getProp('horizontal')?0:1].value))),
d2 = Math.round(this.percentToCoord(this.valueToPercent(this.parent.faders[this.getProp('horizontal')?1:0].value))),
m = Math.round(this.getProp('horizontal') ? this.height / 2 : this.width / 2)
var dashed = this.getProp('dashed')
this.clear()
if (this.getProp('compact')) {
this.ctx.globalAlpha = this.colors.gaugeOpacity || (dashed ? .3 : .2) + 0.2 * Math.abs(d-d2) / height
this.ctx.strokeStyle = this.colors.gauge
this.ctx.beginPath()
this.ctx.moveTo(m, d2)
this.ctx.lineTo(m, d)
this.ctx.lineWidth = width + 2 * PXSCALE
if (dashed) this.ctx.setLineDash([PXSCALE, PXSCALE])
this.ctx.stroke()
if (dashed) this.ctx.setLineDash([])
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.knob
this.ctx.rect(0, Math.min(d, height - PXSCALE), width, PXSCALE)
this.ctx.rect(0, Math.min(d2, height - PXSCALE), width, PXSCALE)
this.ctx.fill()
this.clearRect = [0, 0, width, height]
} else {
this.ctx.lineWidth = 6 * PXSCALE
this.ctx.beginPath()
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.colors.light
this.ctx.moveTo(m, this.margin * PXSCALE - 2 * PXSCALE)
this.ctx.lineTo(m, height - this.margin * PXSCALE + 2 * PXSCALE)
this.ctx.stroke()
this.ctx.lineWidth = 4 * PXSCALE
this.ctx.beginPath()
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.colors.bg
this.ctx.moveTo(m, this.margin * PXSCALE - 1 * PXSCALE)
this.ctx.lineTo(m, height - this.margin * PXSCALE + 1 * PXSCALE)
this.ctx.stroke()
this.ctx.lineWidth = 2 * PXSCALE
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.track
this.ctx.moveTo(m, this.margin * PXSCALE)
this.ctx.lineTo(m, height - this.margin * PXSCALE)
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.globalAlpha = 0.7
this.ctx.strokeStyle = this.colors.gauge
this.ctx.moveTo(m, d2)
this.ctx.lineTo(m, d)
if (dashed) this.ctx.setLineDash([PXSCALE, PXSCALE])
this.ctx.stroke()
if (dashed) this.ctx.setLineDash([])
this.ctx.globalAlpha = 1
// high knob bg
this.ctx.beginPath()
this.ctx.rect(m - 9 * PXSCALE, d - 14 * PXSCALE, 18 * PXSCALE, 16 * PXSCALE)
this.ctx.lineWidth = PXSCALE
this.ctx.fillStyle = this.colors.bg
this.ctx.fill()
// low knob bg
this.ctx.beginPath()
this.ctx.rect(m - 9 * PXSCALE, d2 - PXSCALE, 18 * PXSCALE, 16 * PXSCALE)
this.ctx.lineWidth = PXSCALE
this.ctx.fillStyle = this.colors.bg
this.ctx.fill()
// high knob
this.ctx.beginPath()
this.ctx.rect(m - 8 * PXSCALE, d - 13 * PXSCALE, 16 * PXSCALE, 14 * PXSCALE)
this.ctx.fillStyle = this.colors.raised
this.ctx.fill()
this.ctx.lineWidth = PXSCALE
this.ctx.beginPath()
this.ctx.rect(m - 7.5 * PXSCALE, d - 12.5 * PXSCALE, 15 * PXSCALE, 13.5 * PXSCALE)
this.ctx.lineWidth = PXSCALE
this.ctx.strokeStyle = this.colors.light
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.rect(m - 8 * PXSCALE, d - 13 * PXSCALE, 16 * PXSCALE, PXSCALE)
this.ctx.lineWidth = PXSCALE
this.ctx.fillStyle = this.colors.light
this.ctx.fill()
this.ctx.beginPath()
this.ctx.rect(m - 4 * PXSCALE, d, 8 * PXSCALE, PXSCALE)
this.ctx.fillStyle = this.colors.knob
this.ctx.fill()
// low knob
this.ctx.beginPath()
this.ctx.rect(m - 8 * PXSCALE, d2, 16 * PXSCALE, 14 * PXSCALE)
this.ctx.fillStyle = this.colors.raised
this.ctx.fill()
this.ctx.lineWidth = PXSCALE
this.ctx.beginPath()
this.ctx.rect(m - 7.5 * PXSCALE, d2, 15 * PXSCALE, 13.5 * PXSCALE)
this.ctx.lineWidth = PXSCALE
this.ctx.strokeStyle = this.colors.light
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.rect(m - 4 * PXSCALE, d2, 8 * PXSCALE, PXSCALE)
this.ctx.fillStyle = this.colors.knob
this.ctx.fill()
this.clearRect = [width / 2 - 11 * PXSCALE, 0, 22 * PXSCALE, height]
}
}
}
class Range extends Widget {
class Range extends Fader {
static description() {
@ -180,94 +15,43 @@ class Range extends Widget {
}
static defaults() {
return super.defaults({
_range:'range',
range: {type: 'object', value: {min:0,max:1}, help: 'See fader\'s `range`'},
horizontal: {type: 'boolean', value: false, help: 'See fader\'s `horizontal`'},
alignRight: {type: 'boolean', value: false, help: 'See fader\'s `alignRight`'},
input: {type: 'boolean', value: true, help: 'See fader\'s `input`'},
compact: {type: 'boolean', value: false, help: 'See fader\'s `compact`'},
pips: {type: 'boolean', value: true, help: 'See fader\'s `pips`'},
snap: {type: 'boolean', value: false, help: 'See fader\'s `snap`'},
spring: {type: 'boolean', value: false, help: 'See fader\'s `spring`'},
logScale: {type: 'boolean', value: false, help: 'See fader\'s `logScale`'},
sensitivity: {type: 'number', value: 1, help: 'See fader\'s `sensitivity`'},
}, [], {
touchAddress: {type: 'string', value: '', help: 'See fader\'s `touchAddress`'},
split: {type: 'boolean|object', value: false, help: [
'Set to `true` to send separate osc messages for `low` and `high` handles. The `address` will be the same as the widget\'s with `/low` or `/high` appended to it',
'Can be set as an object to specify a different `address` : `[\'/osc_address_low\', \'/osc_address_high\']`',
'Note: the widget will only respond to its original osc address, not to the splitted version'
]},
css: {type: 'string', value: '', help: [
'Available CSS variables:',
'- `--color-gauge: color;`',
'- `--color-knob: color;`',
'- `--color-pips: color;`',
'- `--gauge-opacity: number;`'
]}
})
}
constructor(options) {
options.multitouch = true
super({...options, html: html`
<div class="range">
<div class="wrapper"></div>
</div>
<canvas></canvas>
`})
this.wrapper = DOM.get(this.widget, '.wrapper')[0]
this.faders = [
new RangeFader({props:{
new Fader({props:{
...faderDefaults,
compact:this.getProp('compact'),
pips:false,
alignRight:false,
visible: false,
horizontal:this.getProp('horizontal'),
height:'100%',
width:'100%',
default:this.getProp('default').length === 2 ? this.getProp('default')[0] : this.getProp('range').min,
snap:this.getProp('snap'),
spring:this.getProp('spring'),
range:this.getProp('range'),
origin:'auto',
precision:this.getProp('precision'),
logScale:this.getProp('logScale'),
sensitivity:this.getProp('sensitivity'),
input:false
}, cancelDraw: true, parent: this}),
new RangeFader({props:{
}, parent: this}),
new Fader({props:{
...faderDefaults,
compact:this.getProp('compact'),
pips:this.getProp('pips'),
alignRight:this.getProp('alignRight'),
pips:false,
visible: false,
horizontal:this.getProp('horizontal'),
height:'100%',
width:'100%',
default:this.getProp('default').length === 2 ? this.getProp('default')[1] : this.getProp('range').max,
snap:this.getProp('snap'),
spring:this.getProp('spring'),
range:this.getProp('range'),
origin:'auto',
precision:this.getProp('precision'),
logScale:this.getProp('logScale'),
sensitivity:this.getProp('sensitivity'),
input:false
}, cancelDraw: false, parent: this})
}, parent: this})
]
this.wrapper.appendChild(this.faders[0].widget)
this.wrapper.appendChild(this.faders[1].widget)
this.on('change',(e)=>{
@ -286,110 +70,6 @@ class Range extends Widget {
this.touchMap = {}
touchstate(this, {element: this.wrapper, multitouch: true})
this.on('draginit',(e)=>{
var id
if (!this.touchMap[e.pointerId]) {
var ndiff, diff = -1
for (var i in this.faders) {
if (Object.values(this.touchMap).indexOf(i) != -1) continue
var coord = this.faders[i].percentToCoord(this.faders[i].valueToPercent(this.faders[i].value)) - (this.getProp('horizontal') ? -1 : 1) * (i == 0 ? -20 : 20)
ndiff = this.getProp('horizontal')?
Math.abs(e.offsetX - coord) :
Math.abs(e.offsetY - coord)
if (diff == -1 || ndiff < diff) {
id = i
diff = ndiff
}
}
this.touchMap[e.pointerId] = id
} else if (e.traversing) {
id = this.touchMap[e.pointerId]
}
if (!id) return
e.stopPropagation = true
this.faders[id].trigger('draginit', e)
}, {element: this.wrapper, multitouch: true})
this.on('drag',(e)=>{
var i = this.touchMap[e.pointerId]
if (!i) return
if (e.shiftKey) {
this.faders[0].trigger('drag', e)
this.faders[1].trigger('drag', e)
} else {
this.faders[i].trigger('drag', e)
}
}, {element: this.wrapper, multitouch: true})
this.on('dragend',(e)=>{
var i = this.touchMap[e.pointerId]
if (!i) return
e.stopPropagation = true
this.faders[i].trigger('dragend', e)
delete this.touchMap[e.pointerId]
}, {element: this.wrapper, multitouch: true})
if (this.getProp('input')) {
this.input = new Input({
props:{...Input.defaults()._props(),
precision:this.getProp('precision'),
unit:this.getProp('unit'),
vertical: this.getProp('compact') && !this.getProp('horizontal')
},
parent:this, parentNode:this.widget,
})
this.widget.appendChild(this.input.widget)
this.input.on('change', (e)=>{
e.stopPropagation = true
this.setValue(this.input.getValue(), {sync:true, send:true})
this.showValue()
})
}
if (this.getProp('horizontal')) {
this.widget.classList.add('horizontal')
this.container.classList.add('horizontal')
}
if (this.getProp('alignRight') && !this.getProp('horizontal')) {
this.widget.classList.add('align-right')
}
if (this.getProp('compact')) {
this.widget.classList.add('compact')
}
if (this.getProp('pips')) {
this.widget.classList.add('has-pips')
}
this.setValue([
this.faders[0].rangeValsMin,
this.faders[1].rangeValsMax
@ -397,7 +77,96 @@ class Range extends Widget {
}
resizeHandle(event){
super.resizeHandle(event)
for (var f of this.faders) {
f.width = this.width
f.height = this.height
f.gaugePadding = this.gaugePadding
}
}
draginitHandle(e) {
var id
if (!this.touchMap[e.pointerId]) {
var ndiff, diff = -1
for (var i in this.faders) {
if (Object.values(this.touchMap).indexOf(i) != -1) continue
var coord = this.faders[i].percentToCoord(this.faders[i].valueToPercent(this.faders[i].value)) - (this.getProp('horizontal') ? -1 : 1) * (i == 0 ? -20 : 20)
ndiff = this.getProp('horizontal')?
Math.abs(e.offsetX - coord) :
Math.abs(e.offsetY - coord)
if (diff == -1 || ndiff < diff) {
id = i
diff = ndiff
}
}
this.touchMap[e.pointerId] = id
} else if (e.traversing) {
id = this.touchMap[e.pointerId]
}
if (!id) return
for (var f of this.faders) {
f.percent = clip(f.percent,[
f.valueToPercent(f.rangeValsMin),
f.valueToPercent(f.rangeValsMax)
])
}
e.stopPropagation = true
this.faders[id].trigger('draginit', e)
}
dragHandle(e) {
var i = this.touchMap[e.pointerId]
if (!i) return
if (e.shiftKey) {
this.faders[0].trigger('drag', e)
this.faders[1].trigger('drag', e)
} else {
this.faders[i].trigger('drag', e)
}
}
dragendHandle(e) {
var i = this.touchMap[e.pointerId]
if (!i) return
e.stopPropagation = true
this.faders[i].trigger('dragend', e)
delete this.touchMap[e.pointerId]
}
setValue(v, options={}) {
if (!v || !v.length || v.length!=2) return
@ -408,7 +177,6 @@ class Range extends Widget {
this.faders[0].setValue(v[0])
this.faders[1].setValue(v[1])
}
this.value = [
this.faders[0].getValue(),
this.faders[1].getValue()
@ -418,16 +186,7 @@ class Range extends Widget {
if (options.send) this.sendValue()
if (options.sync) this.changed(options)
this.faders[1].batchDraw()
this.showValue()
}
showValue() {
if (this.getProp('input')) this.input.setValue(this.value)
this.batchDraw()
}
@ -441,32 +200,91 @@ class Range extends Widget {
}
onPropChanged(propName, options, oldPropValue) {
draw() {
if (super.onPropChanged(...arguments)) return true
switch (propName) {
var width = this.getProp('horizontal') ? this.height : this.width,
height = !this.getProp('horizontal') ? this.height : this.width,
fader = this.faders[0]
case 'color':
for (var w of this.faders) {
w.onPropChanged('color')
}
return
var d = Math.round(fader.percentToCoord(fader.valueToPercent(this.faders[this.getProp('horizontal')?0:1].value))),
d2 = Math.round(fader.percentToCoord(fader.valueToPercent(this.faders[this.getProp('horizontal')?1:0].value))),
m = Math.round(this.getProp('horizontal') ? this.height / 2 : this.width / 2)
// sharp border trick
if (width % 2 && parseInt(m) === m) m -= 0.5
var dashed = this.getProp('dashed')
this.clear()
this.ctx.strokeStyle = this.gaugeGradient || this.cssVars.colorFill
this.ctx.lineWidth = Math.round(width - this.gaugePadding * 2)
if (this.cssVars.alphaFillOff) {
this.ctx.globalAlpha = this.cssVars.alphaFillOff
this.ctx.beginPath()
this.ctx.moveTo(m, height - this.gaugePadding)
this.ctx.lineTo(m, this.gaugePadding)
this.ctx.stroke()
}
if (dashed) {
this.ctx.lineDashOffset = d % 2 ? PXSCALE : 0 // avoid flickering
this.ctx.setLineDash([PXSCALE, PXSCALE])
}
if (this.cssVars.alphaFillOn) {
this.ctx.globalAlpha = this.cssVars.alphaFillOn
this.ctx.beginPath()
this.ctx.moveTo(m, d)
this.ctx.lineTo(m, d2)
this.ctx.stroke()
}
if (dashed) this.ctx.setLineDash([])
this.ctx.globalAlpha = this.cssVars.alphaStroke
this.ctx.strokeStyle = this.cssVars.colorStroke
this.ctx.beginPath()
this.ctx.moveTo(0, 0)
this.ctx.lineTo(width, 0)
this.ctx.lineTo(width, height)
this.ctx.lineTo(0, height)
this.ctx.closePath()
this.ctx.lineWidth = 2 * PXSCALE
this.ctx.stroke()
this.ctx.globalAlpha = 1
this.ctx.fillStyle = this.cssVars.colorFill
this.ctx.beginPath()
this.ctx.rect(this.gaugePadding, Math.min(d, height - 3 * PXSCALE), width - this.gaugePadding * 2, PXSCALE)
this.ctx.fill()
this.ctx.beginPath()
this.ctx.rect(this.gaugePadding, Math.min(d2, height - 3 * PXSCALE), width - this.gaugePadding * 2, PXSCALE)
this.ctx.fill()
this.clearRect = [0, 0, width, height]
}
onRemove() {
this.faders[0].onRemove()
this.faders[1].onRemove()
if (this.input) this.input.onRemove()
super.onRemove()
}
}
Range.dynamicProps = Range.prototype.constructor.dynamicProps.filter(n => n !== 'precision')
Range.dynamicProps = Range.prototype.constructor.dynamicProps
.filter(n => !['spring', 'precision'].includes(n))
module.exports = Range

View file

@ -2,7 +2,6 @@ var {clip, mapToScale} = require('../utils'),
Canvas = require('../common/canvas'),
touchstate = require('../mixins/touch_state'),
doubletab = require('../mixins/double_tap'),
Input = require('../inputs/input'),
html = require('nanohtml')
class Slider extends Canvas {
@ -10,20 +9,13 @@ class Slider extends Canvas {
constructor(options) {
super({...options, html: html`
<div class="slider">
<div class="wrapper">
<canvas></canvas>
</div>
</div>
<canvas></canvas>
`})
this.wrapper = DOM.get(this.widget, '.wrapper')[0]
this.value = undefined
this.percent = 0
this.unit = this.getProp('unit') ? ' ' + this.getProp('unit') : ''
this.gaugePadding = 0
this.rangeKeys = []
this.rangeVals = []
@ -68,48 +60,13 @@ class Slider extends Canvas {
}
this.wrapper.addEventListener('mousewheel',this.mousewheelHandleProxy.bind(this))
this.widget.addEventListener('mousewheel',this.mousewheelHandleProxy.bind(this))
this.on('draginit', this.draginitHandleProxy.bind(this), {element:this.wrapper})
this.on('drag', this.dragHandleProxy.bind(this), {element:this.wrapper})
this.on('dragend', this.dragendHandleProxy.bind(this), {element:this.wrapper})
this.on('draginit', this.draginitHandleProxy.bind(this), {element:this.widget, multitouch: options.multitouch})
this.on('drag', this.dragHandleProxy.bind(this), {element:this.widget, multitouch: options.multitouch})
this.on('dragend', this.dragendHandleProxy.bind(this), {element:this.widget, multitouch: options.multitouch})
touchstate(this, {element: this.wrapper})
if (this.getProp('input')) {
this.input = new Input({
props:{
...Input.defaults()._props(),
precision:this.getProp('precision'),
unit:this.getProp('unit'),
vertical: this.getProp('type') == 'fader' && this.getProp('compact') && !this.getProp('horizontal')
},
parent:this, parentNode:this.widget
})
this.input.sendValue = ()=>{}
this.widget.appendChild(this.input.widget)
this.input.on('change', (e)=>{
e.stopPropagation = true
this.setValue(this.input.getValue(), {sync:true, send:true})
this.showValue()
})
}
if (this.getProp('compact')) {
this.widget.classList.add('compact')
if (this.getProp('input')) {
this.widget.addEventListener('fast-right-click', (e)=>{
if (e.detail.button == 2 && !EDITING) {
// Mouse only
this.input.focus()
}
})
}
}
touchstate(this, {element: this.widget, multitouch: options.multitouch})
this.setSteps()
@ -190,9 +147,12 @@ class Slider extends Canvas {
this.colors.pips = style.getPropertyValue('--color-pips') || this.colors.custom
this.colors.gaugeOpacity = style.getPropertyValue('--gauge-opacity')
this.gaugePadding = this.cssVars.padding + PXSCALE
}
getSpringValue() {
return this.getProp('default') !== '' ? this.getProp('default') : this.originValue
@ -249,19 +209,11 @@ class Slider extends Canvas {
this.batchDraw()
this.showValue()
if (options.send) this.sendValue()
if (options.sync) this.changed(options)
}
showValue() {
if (this.getProp('input')) this.input.setValue(this.value)
}
setSteps() {
if (this.getProp('steps')) {
@ -280,9 +232,6 @@ class Slider extends Canvas {
switch (propName) {
case 'color':
if (this.input) this.input.onPropChanged('color')
return
case 'steps':
this.setSteps()
return
@ -292,8 +241,9 @@ class Slider extends Canvas {
}
onRemove() {
if (this.input) this.input.onRemove()
super.onRemove()
}
}

View file

@ -1,6 +1,6 @@
var Widget = require('../common/widget'),
Push = require('../buttons/push'),
pushDefaults = Push.defaults()._props(),
Toggle = require('../buttons/toggle'),
pushDefaults = Toggle.defaults()._props(),
html = require('nanohtml'),
stateManager = require('../../managers/state'),
widgetManager = require('../../managers/widgets'),
@ -53,8 +53,8 @@ class State extends Widget {
if (this.getProp('horizontal')) this.widget.classList.add('horizontal')
this.saveButton = new Push({props: {...pushDefaults, type: 'push', label: this.getProp('saveLabel')}, parent: this, container: true})
this.loadButton = new Push({props: {...pushDefaults, type: 'push', label: this.getProp('loadLabel')}, parent: this, container: true})
this.saveButton = new Toggle({props: {...pushDefaults, type: 'toggle', mode: 'push', label: this.getProp('saveLabel')}, parent: this, container: true})
this.loadButton = new Toggle({props: {...pushDefaults, type: 'toggle', mode: 'push', label: this.getProp('loadLabel')}, parent: this, container: true})
this.saveButton.container.classList.add('not-editable', 'value')
this.loadButton.container.classList.add('not-editable', 'value', 'disabled')

View file

@ -91,7 +91,7 @@ module.exports = {
parser.isLocal = ()=>{
return parser.hostname.match(localUrlRe)
}
return (url)=>{
parser.href = url
return parser
@ -99,41 +99,6 @@ module.exports = {
})(),
math: (()=>{
var math = require('mathjs/dist/math.min.js').create({
matrix: 'Array'
})
math.import({
unpack: function(a) { return Array.isArray(a) ? a.toString() : a },
indexOf: function(a, x) { return a.indexOf(x) },
pad: function(x, padding) {
var str = String(x),
[int, dec] = str.split('.')
while (int.length < padding) {
int = '0' + int
}
return dec ? int + '.' + dec : int
},
length: function(x) { return x.length },
values: function(x) { return Object.values(x) },
keys: function(x) { return Object.keys(x) },
extend: function(x, y) { return Object.assign(x, y) },
timestamp: function() { return Date.now() },
// basic relationnal to keep alphabetical string comparison (v4 change)
equal: function(a, b) { return a == b },
unequal: function(a, b) { return a != b },
smaller: function(a, b) { return a < b },
larger: function(a, b) { return a > b },
smallerEq: function(a, b) { return a <= b },
largerEq: function(a, b) { return a >= b }
}, {override:true})
// set math's parser array index base to zero
math.expression.mathWithTransform = Object.assign({}, math)
return math
})(),
evaljs: (function(){
var sandbox = document.createElement('iframe'),
@ -162,7 +127,7 @@ module.exports = {
sandbox.contentWindow.console = console
sandbox.contentWindow.setTimeout =
sandbox.contentWindow.setInterval = ()=>{
throw 'setTimeout and setInterval can\'t be used in formulas'
throw 'setTimeout and setInterval can\'t be used in the JS sandbox'
}
sandbox.contentWindow.global = {}

View file

@ -1,183 +0,0 @@
/*!
* jQuery UI Touch Punch 0.2.3
*
* Copyright 2011–2014, Dave Furfero
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Depends:
* jquery.ui.widget.js
* jquery.ui.mouse.js
*/
(function ($) {
// Detect touch support
$.support.touch = 'ontouchend' in document;
// Ignore browsers without touch support
if (!$.support.touch) {
return;
}
var mouseProto = $.ui.mouse.prototype,
_mouseInit = mouseProto._mouseInit,
_mouseDestroy = mouseProto._mouseDestroy,
touchHandled;
/**
* Simulate a mouse event based on a corresponding touch event
* @param {Object} event A touch event
* @param {String} simulatedType The corresponding mouse event
*/
function simulateMouseEvent (event, simulatedType) {
// Ignore multi-touch events
if (event.originalEvent.touches.length > 1) {
return;
}
event.preventDefault();
var touch = event.originalEvent.changedTouches[0],
simulatedEvent = document.createEvent('MouseEvents');
// Initialize the simulated mouse event using the touch event's coordinates
simulatedEvent.initMouseEvent(
simulatedType, // type
true, // bubbles
true, // cancelable
window, // view
1, // detail
touch.screenX, // screenX
touch.screenY, // screenY
touch.clientX, // clientX
touch.clientY, // clientY
false, // ctrlKey
false, // altKey
false, // shiftKey
false, // metaKey
0, // button
null // relatedTarget
);
// osc: add a flag to prevent fast-click
simulatedEvent.touchPunch = true
// Dispatch the simulated event to the target element
event.target.dispatchEvent(simulatedEvent);
}
/**
* Handle the jQuery UI widget's touchstart events
* @param {Object} event The widget element's touchstart event
*/
mouseProto._touchStart = function (event) {
var self = this;
// Ignore the event if another widget is already being handled
if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) {
return;
}
// Set the flag to prevent other widgets from inheriting the touch event
touchHandled = true;
// Track movement to determine if interaction was a click
self._touchMoved = false;
// Simulate the mouseover event
simulateMouseEvent(event, 'mouseover');
// Simulate the mousemove event
simulateMouseEvent(event, 'mousemove');
// Simulate the mousedown event
simulateMouseEvent(event, 'mousedown');
};
/**
* Handle the jQuery UI widget's touchmove events
* @param {Object} event The document's touchmove event
*/
mouseProto._touchMove = function (event) {
// Ignore event if not handled
if (!touchHandled) {
return;
}
// Interaction was not a click
this._touchMoved = true;
// Simulate the mousemove event
simulateMouseEvent(event, 'mousemove');
};
/**
* Handle the jQuery UI widget's touchend events
* @param {Object} event The document's touchend event
*/
mouseProto._touchEnd = function (event) {
// Ignore event if not handled
if (!touchHandled) {
return;
}
// Simulate the mouseup event
simulateMouseEvent(event, 'mouseup');
// Simulate the mouseout event
simulateMouseEvent(event, 'mouseout');
// If the touch interaction did not move, it should trigger a click
if (!this._touchMoved) {
// Simulate the click event
simulateMouseEvent(event, 'click');
}
// Unset the flag to allow other widgets to inherit the touch event
touchHandled = false;
};
/**
* A duck punch of the $.ui.mouse _mouseInit method to support touch events.
* This method extends the widget with bound touch event handlers that
* translate touch events to mouse events and pass them to the widget's
* original mouse event handling methods.
*/
mouseProto._mouseInit = function () {
var self = this;
// Delegate the touch handlers to the widget's element
self.element.bind({
touchstart: $.proxy(self, '_touchStart'),
touchmove: $.proxy(self, '_touchMove'),
touchend: $.proxy(self, '_touchEnd')
});
// Call the original $.ui.mouse init method
_mouseInit.call(self);
};
/**
* Remove the touch event handlers
*/
mouseProto._mouseDestroy = function () {
var self = this;
// Delegate the touch handlers to the widget's element
self.element.unbind({
touchstart: $.proxy(self, '_touchStart'),
touchmove: $.proxy(self, '_touchMove'),
touchend: $.proxy(self, '_touchEnd')
});
// Call the original $.ui.mouse destroy method
_mouseDestroy.call(self);
};
})($);

File diff suppressed because one or more lines are too long

View file

@ -1,293 +1,10 @@
#editor {
box-shadow: 0 0 0 1rem var(--color-light) inset;
background: var(--color-fg);
padding: 1rem 8rem 8rem;
margin-top: 2rem;
flex-shrink:0;
&:empty {
padding:0;
margin: 0;
}
ul {
padding: 4rem;
list-style:none;
li {
margin-bottom: 4rem;
position: relative;
&:last-child {
margin: 0;
}
}
}
.form {
margin-top: 10rem;
}
}
.form {
line-height: 18rem;
.input-wrapper {
display: flex;
// margin-bottom:4rem;
margin-top: -1rem;
// box-shadow: 0 0 0 1 var(--color-bg);
background:var(--color-bg);
align-items: stretch;
z-index: 1;
border-bottom: 1rem solid var(--color-bg);
position: relative;
justify-content: center;
text-transform: none;
font-weight: 500;
&:last-child {
margin-bottom:0;
}
&.disabled {
label {
opacity: .8;
}
}
label {
flex-shrink: 0;
padding: 6rem 7rem 4rem;
min-width: 29%;
margin: 1rem;
margin-bottom: 0;
margin-right: 0;
&:not(.btn) {
background: var(--color-fg);
box-shadow: 1rem 0 0 0 var(--color-bg) inset;
margin: 0;
margin-top: 1rem;
}
&.dynamic:after {
content:"\f0e7";
font-family: FontAwesome;
vertical-align:super;
font-size: 75%;
opacity: 0.75!important;
position: absolute;
margin-top: -4rem;
}
}
.input {
background: var(--color-bg);
flex: 1 1 100%;
padding:5rem;
border-top:1rem solid var(--color-fg);
border-radius: 0;
-webkit-appearance:none;
cursor: initial;
width: 1px;
}
.column {
padding: 2rem;
ul {
padding: 0!important;
overflow: auto;
li:not(:last-child) {
margin-bottom: 2rem!important;
}
.sortable-placeholder {
background: transparent;
&:after {
content:"|";
color: transparent;
}
}
li i {
pointer-events: none
}
}
.btn + span {
position: absolute;
right:0rem;
top:0rem;
padding:8rem;
opacity: 0.6;
cursor: pointer;
&:hover {
opacity: 1;
}
}
}
.checkbox {
line-height: 18rem;
height: 18rem;
width: 18rem;
position: absolute;
right:5rem;
top:6rem;
cursor: pointer;
background: var(--color-fg);
text-align: center;
box-shadow: 0 0 0 1rem var(--color-light) inset;
display: flex;
align-items: center;
justify-content: center;
i {
color: transparent;
margin-top: -1rem;
margin-left: 1rem;
}
&.on i {
color:var(--color-accent);
}
}
}
label {
display: block;
font-size: 10rem;
// background: var(--color-track);
}
.info {
color:var(--color-text-fade);
margin-bottom:10rem;
}
.input {
display:block;
border:0;
font:inherit;
color:var(--color-text);
width:auto;
.btn {
background: var(--color-raised);
box-shadow: 0 0 0 1rem var(--color-light) inset,
0 0 0 1rem var(--color-bg);
&:not(:last-child){
cursor: -webkit-grab;
cursor: grab;
}
}
}
textarea {
display:block;
border:0;
font:inherit;
background: none;
color:var(--color-text);
width:100%;
padding:5rem;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
border-top:1rem solid var(--color-fg);
resize: none;
font-size: 12rem!important;
-webkit-user-select: text;
user-select: text;
--scrollbar-size: 6rem;
&::-webkit-scrollbar-button {
width:1rem!important;
}
}
.error label{
color: red;
}
.select-wrapper {
position: relative;
margin: 2rem;
flex: 1 1 100%;
&:after{
content:"\f107";
font-family: FontAwesome;
position: absolute;
padding:5rem;
right:0;
top:1rem;
font-size: 20rem;
pointer-events: none;
}
.input {
border:0;
width: 100%;
cursor: pointer;
background: var(--color-fg);
box-shadow: 0 0 0 1rem var(--color-light) inset;
}
}
select {
-webkit-appearance:none;
-moz-appearance:none;
appearance:none;
font-size: 12rem!important;
}
.submit {
margin-top:30rem;
}
.separator {
line-height: 30rem;
height: 30rem;
margin-top: 10rem;
position: relative;
display: flex;
align-items: center;
border: 1rem solid var(--color-bg);
box-shadow: 0 0 0 1rem var(--color-light) inset;
padding: 0 10rem;
span {
text-transform: lowercase;
font-variant: small-caps;
position: relative;
display: block;
width:100%;
text-align:center;
pointer-events: none;
text-overflow:ellipsis;
overflow:hidden;
&.accent {
color: var(--color-accent);
}
}
}
.separator + .input-wrapper .input {
border-top-color:transparent;
}
.category {
.separator {
cursor: pointer;
}
.separator:before {
font-family: FontAwesome;
content: "\f0d7";
line-height: 30rem;
width:30rem;
text-align: center;
position: absolute;
opacity: 0.6;
}
&.folded {
.separator:before {
content: "\f0da";
}
.input-wrapper {
display: none;
}
}
}
}
// sticky editor header
.editor-container .form > .separator {
background: var(--color-fg);
position: sticky;
top:10rem;
box-shadow: 0 0 0 1rem var(--color-light) inset,
0 -10rem 0 0 var(--color-fg);
z-index: 10;
}
.widget.editing {
z-index: 9999!important;
// overflow: visible;
}
.widget.editing:after, li.editing a:after, a.editing:before, .content.editing:before, #container.editing:before{
.widget.editing:after,
.tablink.editing:after,
.modal-container.editing .popup-wrapper:after {
content:"";
z-index: 999!important;
position: absolute;
@ -309,194 +26,17 @@
opacity: 1!important;
}
.context-menu {
position:fixed;
z-index: 999999999;
background: var(--color-raised);
box-shadow: 0 0 4rem 1rem var(--color-bg);
text-transform: none;
.item {
color:var(--color-text)
}
.context-menu {
position: absolute;
left:100%;
top:0;
opacity:0;
pointer-events: none;
margin-left: 2rem;
&:before {
content:"";
position: absolute;
top:0;
bottom:0;
left:-2rem;
width:2rem;
}
}
> .item {
padding: 10rem 15rem 10rem 10rem;
position:relative;
cursor: pointer;
i {
margin-right:5rem;
width: 15rem;
text-align: center;
}
&.focus, &:focus {
> .context-menu {
pointer-events: auto;
opacity: 1;
}
&:after {
content:"";
position: absolute;
left:0;
top:0;
width: 100%;
height:100%;
background:var(--color-accent);
opacity: 0.5;
z-index: -1;
}
}
&.has-sub:before {
content:"\f105";
display: block;
font-family: FontAwesome;
float:right;
margin-right:-10rem;
padding-left: 10rem;
}
}
}
.ui-resizable-handle {
position: absolute;
z-index: 10000;
display: flex;
justify-content: center;
align-items: center;
background: var(--color-accent);
width:8rem;
height:8rem;
padding: 1rem;
background-clip: content-box;
&:after {
content:"";
position: absolute;
}
&.ui-resizable-se {
content:"";
bottom: 1rem;
right: 1rem;
cursor: se-resize;
&:after {
top:-5rem;
right:-1rem;
left:-5rem;
bottom:-1rem;
}
}
&.ui-resizable-e {
top: 50%;
margin-top:-4rem;
right: 1rem;
cursor: e-resize;
&:after {
top:-5rem;
right:-1rem;
left:-5rem;
bottom:-5rem;
}
}
&.ui-resizable-s {
bottom: 1rem;
left: 50%;
margin-left:-4rem;
cursor: s-resize;
&:after {
top:-5rem;
right:-5rem;
left:-5rem;
bottom:-1rem;
}
}
}
.ui-helper {
z-index: 10000!important;
opacity: 1!important;
&:before {
content:"";
position: absolute;
top:1rem;
left:1rem;
right:0;
bottom:0;
border:1rem solid var(--color-accent);
--opa1: rgba(0,0,0, 1);
--opa2: rgba(0,0,0, 0.2);
--opa3: rgba(0,0,0, 0.8);
-webkit-mask: linear-gradient(to right, var(--opa1) 10rem, var(--opa1) 10rem, var(--opa2) 10rem, var(--opa2) calc(100% - 10rem), var(--opa1) calc(100% - 10rem), var(--opa1)),
linear-gradient(to bottom, var(--opa2) 10rem, var(--opa2) 10rem, var(--opa3) 10rem, var(--opa3) calc(100% - 10rem), var(--opa2) calc(100% - 10rem), var(--opa2)) ;
-webkit-mask-composite: xor;
}
&:after {
content:"";
position: absolute;
top:1rem;
left:1rem;
right:0;
bottom:0;
background: var(--color-accent);
opacity: .25;
}
}
.ui-draggable-handle:not(.label) {
position: absolute;
top: 1rem;
left: 1rem;
z-index: 100000;
height:8rem;
width: 8rem;
display: flex;
justify-content: center;
align-items: center;
background: var(--color-accent);
padding: 1rem;
background-clip: content-box;
&:after {
content:"";
position: absolute;
top:-1rem;
right:-5rem;
left:-1rem;
bottom:-5rem;
}
}
.ui-draggable-handle {
cursor: -webkit-grab;
&:active {
cursor:-webkit-grabbing;
}
}
// GRID
.editor-enabled {
&:not(.no-grid) {
.tab:not(.has-tabs), .panel {
.panel {
background-image: linear-gradient(to bottom, var(--color-grid) 1rem, transparent 1rem),
linear-gradient(to right, var(--color-grid) 1rem, transparent 1rem);
--size: calc(var(--grid-width) * 1rem);
background-size: var(--size) var(--size);
background-attachment: local;
background-position: 0 0;
background-position: 0rem 0;
}
}
@ -542,21 +82,3 @@
}
// selectable
.select-area {
position:fixed;
z-index:999999;
border: 1rem solid var(--color-accent);
pointer-events: none;
&:after {
content:"";
position: absolute;
top:0;left:0;
right:0;bottom:0;
background: var(--color-accent);
opacity: 0.2;
}
&.hidden {
display: none;
}
}

View file

@ -1,9 +1,8 @@
@import 'reset';
@import 'scrollbars';
@import 'mixins';
@import 'layout';
@import 'notifications';
@import 'ui';
@import 'editor';
@import 'sidepanel';
@ -59,12 +58,12 @@ body {
font-size:11rem;
line-height:100%;
font-weight: 500;
text-transform: uppercase;
// text-transform: uppercase;
letter-spacing: 1rem;
}
.btn {
background: var(--color-raised);
background: var(--color-foreground);
display: block;
padding:15rem;
position: relative;
@ -72,7 +71,6 @@ body {
text-overflow: ellipsis;
overflow: hidden;
cursor: pointer;
box-shadow: 0 0 0 1rem var(--color-light) inset;
&.small {
padding:8rem;
padding-right: 15rem;
@ -493,98 +491,6 @@ body {
.popup {
position: fixed;
top:0;
left:0;
right:0;
bottom:0;
padding:10%;
align-items:center;
justify-content: center;
z-index:1000000;
transform: translate3d(0,0,0);
display: none;
&.show {
display: flex;
}
&:before {
content: "";
position: absolute;
top:0;
left:0;
right:0;
bottom:0;
background:var(--color-bg);
opacity: .5;
}
.popup-title {
position: relative;
background:var(--color-raised);
border-bottom: 1rem solid var(--color-bg);
box-shadow: 0 0 0 1rem var(--color-light) inset;
height:46rem;
flex-shrink: 0;
display: flex;
padding:0 15rem;
align-items: center;
.title {
flex:1;
overflow: hidden;
text-overflow: ellipsis;
}
i {
margin-right: 5rem;
}
&.closable {
padding-right: 0;
}
.popup-label {
flex:1;
}
.closer {
padding:0 15rem;
height: 100%;
flex-shrink: 0;
display: flex;
align-items: center;
text-align: center;
color:var(--color-text-fade);
cursor: pointer;
i {
pointer-events: none;
}
}
}
.popup-wrapper {
display: flex;
flex-direction: column;
align-items: stretch;
width:auto;
max-width:600rem;
max-height: 100%;
position: relative;
overflow: hidden;
box-shadow: 1rem 0 0 0 var(--color-bg),
0 1rem 0 0 var(--color-bg),
1rem 1rem 0 0 var(--color-bg),
0 1rem 0 0 var(--color-light) inset;
border-left:1rem solid var(--color-bg);
border-top:1rem solid var(--color-bg);
.popup-content {
height:100%;
width:100%;
flex:1;
padding:10rem;
overflow-y:auto;
white-space: normal;
background:var(--color-fg);
box-shadow: 0 0 0 1rem var(--color-light) inset;
text-transform: none;
position: relative;
}
}
}
.error-stack {
> span {

View file

@ -1,139 +0,0 @@
body {
background:var(--color-bg);
}
#container {
position: absolute;
top:0;
left:0;
bottom:0;
right:0;
display:flex;
flex-direction: column;
background:var(--color-bg);
padding:2rem;
opacity: 0;
transition: opacity .1s;
min-width: 45rem;
&.show {
opacity: 1;
}
&.sidepanel-open {
right:var(--sidepanel-size);
}
}
.navigation {
height:var(--nav-height);
margin-bottom: 1rem;
margin-left: 1rem;
flex-shrink:0;
// font-weight:bold;
text-transform: uppercase;
background: transparent;
height:calc(var(--nav-height) - 2rem);
&:after {
background: var(--color-bg);
}
a.on {
border-color: var(--color-bg);
}
&.main {
li:last-child {
width:var(--nav-height);
max-width:var(--nav-height);
min-width:var(--nav-height);
i {
margin:0 auto;
}
}
}
ul {
list-style:none;
display: flex;
overflow: hidden;
height:100%;
li {
display:block;
min-width:0;
flex: 1 1 100%;
cursor:pointer;
height:100%;
margin-right: 1rem;
&:last-child {
margin-right:0;
margin-left: auto;
i {
font-size: 14rem;
}
}
a {
background: var(--color-raised);
pointer-events: none;
padding: 0 5rem;
height:100%;
display: flex;
align-items: center;
overflow:hidden;
text-align:center;
position:relative;
box-shadow: 0 0 0 1rem var(--color-light) inset;
letter-spacing: 1rem;
font-size: 109%;
white-space: pre;
span {
display:block;
width:100%;
padding: 2rem 0;
-webkit-mask: linear-gradient(to left, rgba(0, 0, 0, 0), #000000 10rem) no-repeat;
}
}
#open-toggle {
pointer-events: auto;
i {
pointer-events: none;
font-size:13rem;
}
}
&.on a, .sidepanel-open {
position: relative;
z-index: 0;
// background:var(--color-fg);
color: var(--color-custom);
&:before {
content: "";
position: absolute;
top:0;
left: 0;
right: 0;
bottom: 0;
opacity: 0.4;
background: radial-gradient( ellipse at center, transparent, var(--color-bg));
}
&:after {
content:"";
position: absolute;
top:0;
left: 0;
right: 0;
bottom: 0;
opacity: 0.3;
box-shadow: 0 0 0 1rem var(--color-custom) inset;
border-radius: inherit;
z-index: -1;
}
}
}
.parent + li a {
padding-left: calc(5rem + 0.5 * var(--nav-height));
}
}
}

32
src/scss/mixins.scss Normal file
View file

@ -0,0 +1,32 @@
@mixin pseudo-stroke($z: 0) {
&:before {
content:"";
position: absolute;
border: 1rem solid var(--color-stroke);
opacity: var(--alpha-stroke);
top: 0;
left: 0;
right: 0;
bottom: 0;
pointer-events: none;
z-index: $z;
border-radius: inherit;
}
}
@mixin pseudo-fill($z: 0) {
&:after {
content:"";
position: absolute;
background: var(--color-fill);
opacity: var(--alpha-fill);
top: 1rem;
left: 1rem;
right: 1rem;
bottom: 1rem;
pointer-events: none;
margin: var(--widget-padding);
z-index: $z;
border-radius: inherit;
}
}

View file

@ -1,88 +0,0 @@
::-webkit-scrollbar {
width: var(--scrollbar-size);
height:var(--scrollbar-size);
opacity:1;
}
::-webkit-scrollbar-track-piece {
background: var(--color-bg);
&:vertical {
border-left:2rem solid var(--color-bg);
}
&:horizontal {
border-top:2rem solid var(--color-bg);
}
}
::-webkit-scrollbar-corner {
background: var(--color-fg);
border-left:2rem solid var(--color-bg);
border-top:2rem solid var(--color-bg);
}
::-webkit-scrollbar-thumb {
background: var(--color-raised);
&:vertical {
border-left:2rem solid var(--color-bg);
}
&:horizontal {
border-top:2rem solid var(--color-bg);
}
}
@mixin arrow($r) {
background-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="50px" width="50px"><g stroke="rgba(255,255,255,0.5)" transform="rotate('+$r+' 25 25)"><line x1="16" y1="20" x2="25" y2="29" stroke-width="2" /><line x1="25" y1="29" x2="34" y2="20" stroke-width="2" /></g></svg>');
background-blend-mode: difference, normal;
}
::-webkit-scrollbar-button:decrement:start, ::-webkit-scrollbar-button:increment:end {
background:var(--color-fg);
height:var(--scrollbar-size);
width: var(--scrollbar-size);
display: block;
color:red;
background-size:contain;
background-position: center;
&:vertical {
&:decrement:start {
border-left:2rem solid var(--color-bg);
border-bottom:1rem solid var(--color-bg);
@include arrow(180)
}
&:increment:end {
border-left:2rem solid var(--color-bg);
border-top:1rem solid var(--color-bg);
@include arrow(0)
}
}
&:horizontal {
&:decrement:start {
border-right:1rem solid var(--color-bg);
border-top:2rem solid var(--color-bg);
@include arrow(90)
}
&:increment:end {
border-left:1rem solid var(--color-bg);
border-top:2rem solid var(--color-bg);
@include arrow(-90)
}
}
}
// ::-webkit-resizer {
// border-left:2rem solid var(--color-bg);
// border-top:2rem solid var(--color-bg);
// background:var(--color-fg);
// background-size:contain;
// background-position: 2rem 2rem;
// @include arrow(-45)
// }

View file

@ -1,56 +1,56 @@
#sidepanel {
position:absolute;
z-index: 999999;
width:var(--sidepanel-size);
max-width: calc(100% - 45rem);
min-width: 300rem;
border-top: 2rem solid var(--color-bg);
border-bottom: 2rem solid var(--color-bg);
border-right: 2rem solid var(--color-bg);
top:0;
right:0;
bottom:0;
margin-right:calc(-1 * var(--sidepanel-size));
background:var(--color-bg);
transition:transform .25s, opacity .25s;
transform: translate3d(0,0,0);
opacity: 0;
box-shadow: 0 0 15rem 0 rgba(black, 0.3);
display: flex;
flex-direction: column;
#sidepanel-wrapper {
overflow-y: auto;
overflow-x: visible;
display: flex;
flex-direction: column;
flex:1;
}
&.sidepanel-open {
transform: translate3d(calc(-1 * var(--sidepanel-size)),0,0);
opacity: 1;
}
&.hide {
z-index: -1;
pointer-events: none;
margin-right: 0;
}
.navigation {
margin-bottom:2rem;
margin-left: 0;
li {
cursor:default;
}
a {
text-transform: none;
color: var(--color-accent);
justify-content: center;
}
}
//
// #sidepanel {
// position:absolute;
// z-index: 999999;
// width:var(--sidepanel-size);
// max-width: calc(100% - 45rem);
// min-width: 300rem;
// border-top: 2rem solid var(--color-bg);
// border-bottom: 2rem solid var(--color-bg);
// border-right: 2rem solid var(--color-bg);
// top:0;
// right:0;
// bottom:0;
// margin-right:calc(-1 * var(--sidepanel-size));
// background:var(--color-bg);
// transition:transform .25s, opacity .25s;
// transform: translate3d(0,0,0);
// opacity: 0;
// box-shadow: 0 0 15rem 0 rgba(black, 0.3);
// display: flex;
// flex-direction: column;
//
// #sidepanel-wrapper {
// overflow-y: auto;
// overflow-x: visible;
// display: flex;
// flex-direction: column;
// flex:1;
// }
//
// &.sidepanel-open {
// transform: translate3d(calc(-1 * var(--sidepanel-size)),0,0);
// opacity: 1;
// }
//
// &.hide {
// z-index: -1;
// pointer-events: none;
// margin-right: 0;
// }
//
// .navigation {
// margin-bottom:2rem;
// margin-left: 0;
// li {
// cursor:default;
// }
// a {
// text-transform: none;
// color: var(--color-accent);
// justify-content: center;
// }
// }
#options {
box-shadow: 0 0 0 1rem var(--color-light) inset;
@ -68,7 +68,7 @@
}
}
}
// }
.actions {
padding:0.5rem;
background:var(--color-bg);
@ -146,23 +146,3 @@
}
}
#sidepanel-handle {
width: 6rem;
position: fixed;
top:-1rem!important;
bottom:-1rem!important;
left:-1rem!important;
height: auto!important;
background-color: var(--color-custom);
cursor: col-resize;
transition: opacity .25s;
opacity: 0;
&:hover, &.ui-draggable-dragging {
opacity: 0.2;
}
}
#sidepanel.resizing {
transition: none;
}

View file

@ -12,7 +12,7 @@ $text: white;
--color-text-fade: #{transparentize($text, .6)};
--color-accent: #{$accent};
--color-grid: #{transparentize($accent, 0.95)};
// --color-grid: #{transparentize($accent, 0.95)};
--color-bg: #{$base};
--color-track: #{desaturate(mix($base, $tone, 95), 2)};
@ -37,7 +37,27 @@ $text: white;
--nav-height:40rem;
--sidepanel-size:300rem;
--scrollbar-size:20rem;
--grid-width:10;
--color-foreground: #{$base};
--color-background: #{mix($base, black, 85)};
--color-grid: rgba(0,0,0, 0.1);
--color-context-menu: #{mix($base, white, 95)};
--color-context-menu-text: #{transparentize($text, .2)};
--alpha-scrollbar: 0.25;
--alpha-scrollbar-on: 0.5;
--scrollbar-size:12rem;
--color-text: #{transparentize($text, .4)};
--color-widget: var(--color-accent);
}

9
src/scss/ui.scss Normal file
View file

@ -0,0 +1,9 @@
@import 'ui/scrollbars';
@import 'ui/workspaces';
@import 'ui/notifications';
@import 'ui/inspector';
@import 'ui/tree';
@import 'ui/dragresize';
@import 'ui/selectarea';
@import 'ui/contextmenu';
@import 'ui/modal';

View file

@ -0,0 +1,60 @@
$line-height: 30rem;
.context-menu {
position:fixed;
z-index: 999999999;
background: var(--color-context-menu);
box-shadow: 0 0 0 1rem rgba(0, 0, 0, 0.1) inset;
text-transform: none;
color: var(--color-context-menu-text);
line-height: $line-height;
--widget-padding: 0rem;
.context-menu {
position: absolute;
left:100%;
top:0;
opacity:0;
pointer-events: none;
margin-left: 1rem;
&:before {
content:"";
position: absolute;
top:0;
bottom:0;
left:-2rem;
width:2rem;
}
}
> .item {
padding-left: 15rem;
padding-right: 25rem;
position:relative;
cursor: pointer;
i {
margin-right:5rem;
width: 15rem;
text-align: center;
margin-left: -5rem;
}
&.focus, &:focus {
> .context-menu {
pointer-events: auto;
opacity: 1;
}
@include pseudo-fill($z: -1);
color: var(--color-context-menu);
}
&.has-sub:before {
content:"\f105";
display: block;
font-family: FontAwesome;
float:right;
margin-right:-20rem;
width: 15rem;
text-align: center;
position: relative;
}
}
}

View file

@ -0,0 +1,80 @@
#drag-resize {
--color-fill: var(--color-accent);
--color-stroke: var(--color-accent);
position: absolute;
z-index: 99999999;
top: var(--top);
left: var(--left);
.helper {
position: absolute;
top:0;
left:0;
width: var(--width);
height: var(--height);
pointer-events: none;
--alpha-fill: 0.5;
--widget-padding: -1rem;
opacity: 0.5;
display: none;
border: 1rem solid var(--color-stroke);
@include pseudo-fill();
}
&.dragging .helper {
display: block;
}
.handle {
$size: 10rem;
position: absolute;
background: var(--color-fill);
width: $size;
height: $size;
border: 2rem solid transparent;
background-clip: content-box;
// opacity: 0.75;
&.nw {
cursor: move;
}
&.e {
top: calc(var(--height) / 2);
left: var(--width);
margin-left: -$size;
margin-top: -$size / 2;
cursor: e-resize;
}
&.se {
top: var(--height);
left: var(--width);
margin-left: -$size;
margin-top: -$size;
cursor: se-resize;
}
&.s {
top: var(--height);
left: calc(var(--width) / 2);
margin-left: -$size / 2;
margin-top: -$size;
cursor: s-resize;
}
}
}

226
src/scss/ui/inspector.scss Normal file
View file

@ -0,0 +1,226 @@
$header-height: 22rem;
$field-height: 22rem;
$padding: 8rem;
#osc-inspector {
// padding: $padding;
--widget-padding: -1rem;
}
osc-inspector-field {
display: flex;
flex-direction: row;
line-height: $field-height;
margin-top: 4rem;
label {
width: 90rem;
order: 35;
text-transform: none;
padding-left: 8rem;
cursor: help;
}
textarea {
font-family: mono;
line-height: $field-height - 8rem;
padding: 5rem 6rem 3rem;
flex: 1;
overflow-x: auto;
overflow-y: hidden;
resize: none;
white-space: pre;
display: block;
background: var(--color-foreground);
cursor: text;
-webkit-appearance:none;
-moz-appearance:none;
appearance:none;
--scrollbar-size: 6rem;
&::-webkit-scrollbar-thumb:horizontal {
// border-top: 4rem solid var(--color-foreground);
cursor: normal;
}
}
}
osc-inspector-category {
--alpha-fill: 0.25;
margin-top: 2rem;
display: block;
padding: 0 8rem;
&:first-child {
margin-top: 0
}
.category-header {
position: relative;
text-transform: none;
cursor: pointer;
// color: var(--color-background);
height: $header-height;
line-height: $header-height + 1;
// padding: 0 8rem;
@include pseudo-fill($z: -1);
&:after {
left:-($padding - 2);
right:-($padding - 1);
}
&:before {
position: relative;
font-family: FontAwesome;
content: "\f04b";
width: $field-height;
text-align: left;
display: inline-block;
transform-origin: 2rem 3rem;
font-size: 7rem;
width: 8rem;
height: 8rem;
line-height: 6rem;
margin-right: 8rem;
top: -2rem;
transform: rotate(90deg);
transition: top .1s, transform .1s;
}
}
&.folded {
--alpha-fill: 0.10;
margin-bottom: 0;
.category-header:before {
transform: rotate(0deg);
top: 0;
}
osc-inspector-field {
display: none;
}
}
.category-header + osc-inspector-field {
margin-top: 8rem;
}
osc-inspector-field:last-child {
margin-bottom: 8rem;
}
}
osc-inspector-checkbox {
line-height: $field-height;
height: $field-height;
width: $field-height;
cursor: pointer;
background: var(--color-foreground);
text-align: center;
display: flex;
align-items: center;
justify-content: center;
margin-left: 4rem;
i {
color: transparent;
margin-top: -1rem;
margin-left: 1rem;
}
&.on {
position: relative;
z-index: 1;
@include pseudo-fill($z: -1);
i {
color: inherit;
}
}
}
osc-inspector-select {
position: relative;
font-family: mono;
line-height: inherit;
padding: 0;
overflow: hidden;
height: $field-height;
width: $field-height;
background: var(--color-foreground);
margin-left: 4rem;
select {
background: var(--color-foreground);
// width: 100%;
line-height: $field-height - 8rem;
padding: 4rem 6rem;
-webkit-appearance:none;
-moz-appearance:none;
appearance:none;
position: absolute;
left:0;
opacity: 0;
optgroup {
background: var(--color-foreground);
font-weight: bold;
option {
background: var(--color-background);
color: var(--color-text);
margin-left: -4rem;
font-weight: normal;
text-indent: -10px;
margin: 0;
}
}
}
&:after{
content:"\f0d7";
font-family: FontAwesome;
position: absolute;
line-height: $field-height;
height: $field-height;
width: $field-height;
text-align: center;
right:0;
top:1rem;
font-size: 16rem;
pointer-events: none;
}
}
.osc-inspector-color {
appearance: none;
padding: 0;
border: 0;
box-shadow: 0;
outline: 0;
position: relative;
font-family: mono;
line-height: inherit;
padding: 0;
overflow: hidden;
height: $field-height;
width: $field-height;
background: var(--color-foreground);
margin-left: 4rem;
-webkit-appearance:none;
-moz-appearance:none;
appearance:none;
}

78
src/scss/ui/modal.scss Normal file
View file

@ -0,0 +1,78 @@
.popup {
position: fixed;
top:0;
left:0;
right:0;
bottom:0;
padding:10%;
align-items:center;
justify-content: center;
z-index: 99999999;
transform: translate3d(0,0,0);
display: none;
// backdrop-filter: blur(1rem); // perf hit
&.show {
display: flex;
}
&:before {
content: "";
position: absolute;
top:0rem;
left:0;
right:0;
bottom:0;
background: black;
opacity: .1;
}
.popup-title {
position: relative;
height: var(--nav-height);
display: flex;
padding:0 15rem;
align-items: center;
background: var(--color-background);
.title {
flex:1;
overflow: hidden;
}
i {
margin-right: 5rem;
}
&.closable {
padding-right: 0;
}
.popup-label {
flex:1;
overflow: hidden;
}
.closer {
height: var(--nav-height);
width: var(--nav-height);
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
i {
pointer-events: none;
}
}
}
.popup-wrapper {
background: var(--color-foreground);
display: flex;
flex-direction: column;
align-items: stretch;
width:auto;
max-width:600rem;
max-height: 100%;
position: relative;
overflow: hidden;
.popup-content {
flex:1;
width: auto;
}
}
}

View file

@ -0,0 +1,44 @@
::-webkit-scrollbar {
width: var(--scrollbar-size);
height:var(--scrollbar-size);
}
::-webkit-scrollbar-track-piece {
background: var(--color-foreground);
&:vertical {
border-left: 1rem solid var(--color-foreground);
}
&:horizontal {
border-top: 1rem solid var(--color-foreground);
}
}
::-webkit-scrollbar-thumb {
background: var(--color-scrollbar);
&:active {
background: var(--color-scrollbar-on);
}
&:vertical {
border-left: 1rem solid var(--color-foreground);
}
&:horizontal {
border-top: 1rem solid var(--color-foreground);
}
}
::-webkit-scrollbar-button:decrement:start, ::-webkit-scrollbar-button:increment:end {
height: 0;
width: 0;
}
::-webkit-scrollbar-corner {
height: 0rem;
width: 0rem;
background: var(--color-foreground);
}
* {
scrollbar-color: var(--color-scrollbar) var(--color-background);
scrollbar-width: thin;
}

View file

@ -0,0 +1,19 @@
.select-area {
position:fixed;
z-index:999999;
border: 1rem solid var(--color-accent);
pointer-events: none;
&:after {
content:"";
position: absolute;
top:0;left:0;
right:0;bottom:0;
background: var(--color-accent);
opacity: 0.2;
}
&.hidden {
display: none;
}
}

115
src/scss/ui/tree.scss Normal file
View file

@ -0,0 +1,115 @@
#osc-tree {
--alpha-fill: 0.5;
--widget-padding: -1rem;
$padding: 16rem;
$line-height: 22rem;
padding: 0 $padding;
text-transform: none;
line-height: $line-height;
ol {
list-style: none;
position: relative;
padding-left: 16rem;
ol:before {
content: "";
position: absolute;
top: 0;
bottom: $line-height / 2 - 1;
left: -12rem;
border-left: 1rem solid var(--color-stroke);
opacity: 0.25;
pointer-events: none;
}
}
li {
position: relative;user-select: none;
> ol {
display: none;
}
&.expanded > ol {
display: block;
}
li:before {
content: "";
position: absolute;
top: $line-height / 2;
left: -27rem;
width: 16rem;
border-bottom: 1rem solid var(--color-stroke);
opacity: 0.25;
pointer-events: none;
}
.container:before {
width: 8rem;
}
&.invisible {
opacity: 0.5;
font-style: italic;
// &:after {
// content: "\f070";
// font-family: FontAwesome;
// width: 12rem;
// display: block;
// position: absolute;
// right: -12rem;
// }
}
}
.toggle {
&:before {
content: "\f054";
font-family: FontAwesome;
width: 20rem;
display: block;
position: absolute;
left: -21rem;
font-style: normal;
text-align: center;
}
cursor: pointer;
}
.container.expanded > .toggle:before {
content: "\f078";
}
.editing {
z-index: 1;
@include pseudo-fill($z: -1);
&:after {
left: calc(-1 * var(--depth) * 16rem - #{$padding});
right: -($padding - 1);
bottom: auto;
height: $line-height;
top: 0;
}
}
.contains-editing:not(.expanded):not(.editing) {
z-index: 1;
@include pseudo-fill($z: -1);
&:after {
left: calc(-1 * var(--depth) * 16rem - #{$padding});
right: -($padding - 1);
bottom: auto;
height: $line-height;
opacity: 0.1;
}
}
}

221
src/scss/ui/workspaces.scss Normal file
View file

@ -0,0 +1,221 @@
osc-workspace {
background: var(--color-background);
--color-fill: var(--color-widget);
--color-stroke: var(--color-widget);
position: static;
width: 100%;
height: 100%;
display: flex;
flex-direction: row;
overflow: hidden;
}
osc-panel-container {
position: relative;
display:flex;
&.center {
flex: 1;
z-index: 1;
min-width: 100rem;
}
&.left, &.right {
z-index: 2;
min-width: 0;
width: 0;
&:after {
// hover trap to display toggle-button when closed
content: "";
position: absolute;
top: 0;
bottom: 0;
width: 1rem;
z-index: 1;
}
::-webkit-scrollbar-thumb, ::-webkit-scrollbar-track-piece {
border-color: var(--color-background)!important;
}
}
&.left:after {
right: -1rem;
}
&.right:after {
left: -1rem;
}
.resize-handle {
position: absolute;
top: 0;
bottom: 0;
width: 4rem;
cursor: ew-resize;
z-index: 4;
&.right {
left: 0;
}
&.left {
right: 0;
}
}
.toggle-button {
position: absolute;
top: 50%;
height: 50rem;
width: 25rem;
margin-top: -25rem;
cursor: pointer;
background: var(--color-background);
font-size: 14rem;
z-index: 2;
transition: transform 0.2s ease-out 0.1s;
will-change: transform;
&:after {
font-family: FontAwesome;
line-height: 50rem;
width: 25rem;
text-align: center;
display: block;
opacity: 0;
transition: opacity 0.2s ease-out 0s;
}
&.left {
border-top-right-radius: 25rem;
border-bottom-right-radius: 25rem;
right: -25rem;
transform: translateX(-25rem);
&:after {
content:"\f104";
margin-left: -4rem;
}
}
&.right {
border-top-left-radius: 25rem;
border-bottom-left-radius: 25rem;
left: -25rem;
transform: translateX(25rem);
&:after {
content:"\f105";
margin-left: 4rem;
}
}
}
&:hover .toggle-button, .toggle-button:hover {
transition: transform 0.2s ease-out 0s;
transform: translateX(0);
&:after {
transition: opacity 0.1s ease-in 0.1s;
opacity: 1;
}
}
&.minimized .toggle-button {
&.left:after {
content:"\f105";
}
&.right:after {
content:"\f104";
}
}
&.disabled .toggle-button {
display: none;
}
}
osc-modal-container {
position: absolute;
top: 0;
left: 0;
right: 0;
}
osc-panel-inner {
display: flex;
flex-direction: column;
flex: 1;
overflow: hidden;
z-index: 3;
min-width: 0;
}
// @keyframes test{
// 0% {
// transform: scaleX(0);
// opacity: 0;
// }
// 100% {
// tranform: scaleX(1);
// opacity: var(--alpha-fill);
// }
// }
//
// osc-panel-container:not(.disabled) osc-panel-header:before {
// animation: test 0.1s forwards;
//
// }
osc-panel-header {
--alpha-fill: 0.25;
display: flex;
height: var(--nav-height);
align-items: center;
align-items: center;
justify-content: center;
position:relative;
letter-spacing: 1rem;
font-size: 109%;
text-overflow: ellipsis;
padding: 0 8rem;
&:before {
content: "";
position: absolute;
left: 1rem;
right: 1rem;
bottom: 2rem;
opacity: var(--alpha-fill);
height: 4rem;
background: var(--color-fill);
z-index: 101;
}
}
osc-panel-content {
flex: 1;
overflow-y: auto;
&.left, &.right {
border-right: 1rem solid var(--color-background);
}
}

107
src/scss/widgets.old.scss Normal file
View file

@ -0,0 +1,107 @@
.widget {
height:auto;
overflow: hidden;
position:relative;
vertical-align:top;
box-shadow: 1rem 0 0 0 var(--color-border),
0 1rem 0 0 var(--color-border),
1rem 1rem 0 0 var(--color-border),
0 0 0 1rem var(--color-light) inset;
border-left:1rem solid var(--color-border);
border-top:1rem solid var(--color-border);
-webkit-tap-highlight-color:transparent;
display: inline-flex;
flex-direction: column;
--default-bg: var(--color-fg);
background: var(--default-bg);
max-width: 100%;
max-height: 100%;
text-transform: uppercase;
contain: style size layout;
color: var(--color-text);
--color-glass-1: var(--color-custom);
--color-glass-2: var(--color-track);
&.absolute-position {
position: absolute;
z-index: 10;
}
&.nolabel {
> .label {
display:none;
}
}
> .label ~ div {
border-top-left-radius:0;
border-top-right-radius:0;
border-bottom-right-radius:inherit;
border-bottom-left-radius:inherit;
min-height: 0;
}
&.nolabel > .label ~ div {
border-radius: inherit;
}
.label {
text-overflow:ellipsis;
overflow:hidden;
text-align:center;
height:30rem;
max-height:30rem;
padding:0 6rem;
width: 100%;
flex-shrink: 0;
display: flex;
justify-content: center;
white-space: pre;
// justify-content: space-around;
align-items: center;
&.accent {
color:var(--color-accent);
}
}
}
.glass-effect {
position: relative;
&:after {
content:"";
position: absolute;
pointer-events: none;
top:0;
left:0;
right:0;
bottom:0;
background: radial-gradient(ellipse farthest-side at center top, var(--color-glass-1), var(--color-glass-2));
background-size: 150% 150%;
background-repeat: no-repeat;
background-position: center top;
opacity: var(--glass-opacity);
z-index: 3;
}
}
@import 'widgets/fader';
@import 'widgets/knob';
@import 'widgets/matrices';
@import 'widgets/patchbay';
@import 'widgets/pads';
@import 'widgets/plots';
@import 'widgets/toggle';
@import 'widgets/push';
@import 'widgets/switch';
@import 'widgets/menu';
@import 'widgets/panel';
@import 'widgets/inputs';
@import 'widgets/maths';

View file

@ -0,0 +1,238 @@
.input-container {
width: 100rem;
height: 60rem;
padding:1rem;
.vertical {
position: relative;
input {
transform: rotate(-90deg);
vertical-align: middle;
max-width: initial!important;
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%) rotate(-90deg);
margin-top: -1px
}
}
.not-editable {
@extend .glass-effect;
}
}
.widget {
.input {
display: flex;
flex: 1 1 100%;
background:transparent;
color:var(--color-text);
overflow: hidden;
text-align:center;
padding:1rem;
border: 1rem solid var(--color-bg);
background: var(--color-track);
&.right {
text-align: right;
}
&.left {
text-align: left;
}
input {
display: block;
flex:1;
max-width: 100%;
font: inherit;
border:0;
padding:0;
background: transparent;
color:var(--color-accent);
border-radius: inherit;
-webkit-appearance:none;
appearance: none;
text-align:inherit;
line-height: 50rem;
vertical-align: top;
letter-spacing: 1rem;
-webkit-user-select: text;
user-select: text;
&:focus {
color:var(--color-text-fade);
}
&:focus::selection {
color:var(--color-custom);
background: transparent;
}
}
canvas {
flex:1;
max-width: 100%;
}
input + canvas {
display: none;
width: 0;
}
}
}
.panel:not(.tab) > .input-container {
padding: 0rem;
> .input {
box-shadow: 0 0 0 1rem var(--color-light),
0 0 0 1rem var(--color-fg);
margin:1rem;
border: 1rem solid var(--color-bg);
}
}
.keys-container {
width: 100rem;
height:60rem;
flex-shrink: 0;
padding:1rem;
--opacity: .75;
.keys {
flex: 1 1 100%;
height:35rem;
padding: 10rem;
justify-content: center;
display: flex;
align-items: center;
background: var(--color-track);
color:var(--color-custom);
border: 1rem solid var(--color-bg);
@extend .glass-effect;
i {
opacity: var(--opacity);
}
span {
font-family: monospace;
letter-spacing: 0;
margin-left: 4rem;
}
}
}
.panel:not(.tab) > .keys-container {
--color-border:transparent;
padding: 0rem;
.keys {
margin: 1rem;
box-shadow: 0 0 0 1rem var(--color-light),
0 0 0 1rem var(--color-fg);
border: 1rem solid var(--color-bg);
}
}
.script-container {
width: 100rem;
height:60rem;
flex-shrink: 0;
padding:1rem;
--opacity: .75;
.script {
flex: 1 1 100%;
height:35rem;
padding: 10rem;
justify-content: center;
display: flex;
align-items: center;
background: var(--color-track);
color:var(--color-custom);
border: 1rem solid var(--color-bg);
@extend .glass-effect;
i {
opacity: var(--opacity);
}
span {
font-family: monospace;
letter-spacing: 0;
margin-left: 4rem;
}
}
}
.panel:not(.tab) > .script-container {
--color-border:transparent;
padding: 0rem;
.script {
margin: 1rem;
box-shadow: 0 0 0 1rem var(--color-light),
0 0 0 1rem var(--color-fg);
border: 1rem solid var(--color-bg);
}
}
.gyroscope-container {
width: 100rem;
height:60rem;
flex-shrink: 0;
padding:1rem;
--opacity: .75;
.gyroscope {
flex: 1 1 100%;
height:35rem;
padding: 10rem;
justify-content: center;
display: flex;
align-items: center;
background: var(--color-track);
color:var(--color-custom);
border: 1rem solid var(--color-bg);
@extend .glass-effect;
i {
opacity: var(--opacity);
}
span {
font-family: monospace;
letter-spacing: 0;
margin-left: 4rem;
}
}
}
.panel:not(.tab) > .gyroscope-container {
--color-border:transparent;
padding: 0rem;
.gyroscope {
margin: 1rem;
box-shadow: 0 0 0 1rem var(--color-light),
0 0 0 1rem var(--color-fg);
border: 1rem solid var(--color-bg);
}
}
.file-container {
width: 100rem;
height:60rem;
padding:1rem;
&.nolabel {
--color-border:var(--color-bg);
padding: 0;
.file {
border: 0;
}
}
.file {
border: 1rem solid var(--color-bg);
flex: 1 1 100%;
display: flex;
align-items: center;
justify-content: center;
padding: 0 10rem;
text-transform: none;
i {
margin: 0 5rem;
pointer-events: none;
}
span {
pointer-events: none;
text-overflow: ellipsis;
overflow: hidden;
}
}
}

View file

@ -0,0 +1,206 @@
.xy-container, .rgb-container, .multixy-container {
width:200rem;
height:230rem;
padding:2rem;
--background: var(--color-track);
--pips-opacity: 0.2;
--point-opacity: 0.3;
.label {
flex-shrink: 0;
z-index: 1;
}
> .pad > .wrapper:after {
content:"";
position: absolute;
pointer-events: none;
top:var(--pointSize);
left:var(--pointSize);
height:calc(100% - 2 * var(--pointSize));
width:calc(100% - 2 * var(--pointSize));
background: var(--background);
box-shadow: 0 0 0 1rem var(--color-light),
0 0 0 1rem var(--color-bg) inset;
}
.pad {
height:100%;
width: 100%;
overflow: hidden;
display: flex;
flex-direction: column;
> .input {
margin-top: 2rem;
height: 25rem;
flex:initial!important;
flex-shrink: 0!important;
background: transparent!important;
border: 0!important;
}
> .wrapper {
position: relative;
flex:1;
touch-action: none;
> canvas {
width:100%;
height:100%;
position: absolute;
pointer-events: none;
z-index: 1;
}
> .fader {
pointer-events: none;
position: absolute;
width:100%;
height:100%;
z-index: 0;
--color-knob:transparent;
--color-gauge:transparent;
box-shadow: none;
border: 0;
* {
background: transparent!important;
}
.wrapper {
border:none;
}
.input {
display: none;
}
}
}
}
}
.rgb-container {
--point-opacity: .7;
> .pad {
> .wrapper {
display: flex;
flex-direction: column;
image-rendering:pixelated;
> .pad {
--color-custom:var(--color-white);
position: absolute;
.wrapper {
border:0;
background: transparent;
}
canvas {
border:0;
left:0;
background: transparent;
}
.input {
display: none;
}
}
> canvas {
top:var(--pointSize);
left:var(--pointSize);
flex:0;
height:calc(100% - 2 * var(--pointSize));
width:calc(100% - 2 * var(--pointSize));
background-color: red;
background-clip: content-box;
background-image: linear-gradient(to bottom, rgba(0,0,0,0) 0%,rgba(0,0,0,1) 100%), linear-gradient(to right, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%);
border: 1rem solid var(--color-bg);
}
background: transparent;
border: none;
box-shadow: none;
}
.alpha-wrapper, .hue-wrapper {
flex-shrink: 0;
padding: calc(var(--pointSize) / 2) var(--pointSize);
.fader {
box-shadow: 0 0 0 1rem var(--color-light);
height: calc(2 * var(--pointSize));
}
}
.hue-wrapper {
--color-gauge:transparent;
--color-knob:var(--color-white);
.wrapper {
&:after {
content:"";
display: block;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(to left, #F00, #FF0080, #F0F, #8000FF, #00F, #0080FF, #0FF, #00FF80, #0F0, #80FF00, #FF0, #FF8000, #F00) repeat scroll 0% 0%;
box-shadow: 0 0 0 4rem var(--color-track);
// z-index: 1;
opacity: 0.7;
}
canvas {
background: transparent;
-webkit-background-blend-mode: color-burn;
}
}
}
}
}
.multixy-container {
> .pad {
text-align: center;
font-size: 109%;
> .wrapper {
> canvas {
top:0;
left:0;
z-index: 2;
}
> .pad {
pointer-events: none;
position: absolute;
.wrapper {
border:0;
background: transparent;
}
canvas {
border:0;
left:0;
}
.input {
display: none;
}
}
}
}
}
.canvas-container {
width:200rem;
height:230rem;
.canvas {
flex: 1;
}
canvas {
width:100%;
height: 100%;
}
}

View file

@ -0,0 +1,265 @@
.led-container, .rgbled-container {
width:100rem;
height:100rem;
padding:1rem;
.led {
--opacity: 0;
--color-led: var(--color-custom);
display: flex;
flex-direction: row;
flex: 1 1 100%;
background: var(--color-track);
border:1rem solid var(--color-bg);
&:before {
content:"";
width:100%;
height: 100%;
background: var(--color-led);
border-radius: inherit;
opacity: var(--opacity);
box-shadow: inset 0 0 10rem var(--color-track);
}
@extend .glass-effect;
}
}
.rgbled-container .led {
--opacity: 1;
}
.plot-container, .visualizer-container, .eq-container {
height: 200rem;
width: 200rem;
padding:1rem;
.plot {
display: flex;
flex-direction: row;
flex: 1 1 100%;
background: var(--color-track);
border:1rem solid var(--color-bg);
@extend .glass-effect;
}
canvas {
flex:1;
image-rendering:pixelated;
width: 100%;
}
}
.meter-container {
@extend .fader-container;
--color-knob: transparent;
.wrapper {
pointer-events: none;
@extend .glass-effect;
}
}
.text-container {
width: 100rem;
height:60rem;
flex-shrink: 0;
padding:1rem;
.text {
flex: 1 1 100%;
height:35rem;
padding: 0 10rem;
justify-content: center;
display: flex;
align-items: center;
white-space: pre;
background: var(--color-track);
color:var(--color-custom);
border: 1rem solid var(--color-bg);
line-height: 100%;
overflow: hidden;
text-align: center;
&.right {
text-align: right;
justify-content: flex-end;
}
&.left {
text-align: left;
justify-content: flex-start;
}
&.wrap {
white-space: pre-wrap;
}
&.vertical {
transform: rotate(180deg);
text-overflow: ellipsis;
-webkit-writing-mode:vertical-rl;
writing-mode:vertical-rl;
padding: 10rem 0;
&:after {
transform: rotate(-180deg);
}
}
@extend .glass-effect;
}
}
.image-container {
width:100rem;
height:100rem;
padding:1rem;
.image {
display: flex;
flex-direction: row;
flex: 1 1 100%;
background-size:cover;
border:1rem solid var(--color-bg);
background-repeat: no-repeat;
}
&.noborder {
--color-border:transparent;
--color-light:transparent;
--color-light:transparent;
background: transparent;
padding: 0!important;
.image {
outline:transparent!important;
border:0!important;
box-shadow:none!important;
margin: 0!important;
}
}
}
.svg-container {
width:100rem;
height:100rem;
padding:1rem;
.svg {
display: flex;
flex-direction: row;
flex: 1 1 100%;
background: var(--color-track);
border:1rem solid var(--color-bg);
svg {
flex: 1 1 100%;
}
}
&.noborder {
--color-border:transparent;
--color-light:transparent;
--color-light:transparent;
background: transparent;
padding: 0!important;
.svg {
background: transparent;
outline:transparent!important;
border:0!important;
box-shadow:none!important;
margin: 0!important;
}
}
&:not(.noborder) .svg {
@extend .glass-effect;
}
}
.html-container {
width:100rem;
height:100rem;
padding:1rem;
.html {
display: flex;
flex-direction: row;
flex: 1 1 100%;
background: var(--color-track);
border:1rem solid var(--color-bg);
}
&.noborder {
--color-border:transparent;
--color-light:transparent;
--color-light:transparent;
background: transparent;
padding: 0!important;
.html {
background: transparent;
outline:transparent!important;
border:0!important;
box-shadow:none!important;
margin: 0!important;
}
}
&:not(.noborder) .html {
@extend .glass-effect;
}
}
.frame-container {
width:100rem;
height:100rem;
padding:1rem;
.frame {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
flex: 1 1 100%;
background-size:cover;
border:1rem solid var(--color-bg);
background-repeat: no-repeat;
iframe {
flex: 1 1 100%;
height: 100%;
width: 100%;
border: 0;
display: block;
}
iframe[src=""] {
pointer-events: none;
}
&.error {
iframe {
display: none;
}
}
}
&.noborder {
--color-border:transparent;
--color-light:transparent;
--color-light:transparent;
background: transparent;
padding: 0!important;
.frame {
outline:transparent!important;
border:0!important;
box-shadow:none!important;
margin: 0!important;
}
}
}
.editor-enabled .frame-container.nolabel iframe {
pointer-events: none;
}
.panel:not(.tab) > .led-container,
.panel:not(.tab) > .rgbled-container,
.panel:not(.tab) > .text-container,
.panel:not(.tab) > .visualizer-container,
.panel:not(.tab) > .eq-container,
.panel:not(.tab) > .plot-container,
.panel:not(.tab) > .image-container,
.panel:not(.tab) > .frame-container,
.panel:not(.tab) > .svg-container,
.panel:not(.tab) > .html-container {
--color-border:transparent;
padding: 0rem;
.plot, .text, .led, .image, .svg, .html, .frame {
margin: 1rem;
box-shadow: 0 0 0 1rem var(--color-light),
0 0 0 1rem var(--color-fg);
border: 1rem solid var(--color-bg);
}
}
.panel:not(.tab) > .image-container {
.image {
background-clip: content-box;
}
}

View file

@ -1,27 +1,32 @@
.widget {
height:auto;
overflow: hidden;
position:relative;
vertical-align:top;
box-shadow: 1rem 0 0 0 var(--color-border),
0 1rem 0 0 var(--color-border),
1rem 1rem 0 0 var(--color-border),
0 0 0 1rem var(--color-light) inset;
border-left:1rem solid var(--color-border);
border-top:1rem solid var(--color-border);
-webkit-tap-highlight-color:transparent;
display: inline-flex;
flex-direction: column;
--default-bg: var(--color-fg);
background: var(--default-bg);
max-width: 100%;
max-height: 100%;
text-transform: uppercase;
width: 100rem;
height: 100rem;
contain: style size layout;
-webkit-tap-highlight-color:transparent;
--widget-padding: 1rem;
--color-stroke:var(--color-widget);
--color-fill:var(--color-widget);
--alpha-stroke: 0.5;
--alpha-fill-off: 0.0;
--alpha-fill-on: 0.25;
--alpha-fill: var(--alpha-fill-off);
color: var(--color-text);
--color-glass-1: var(--color-custom);
--color-glass-2: var(--color-track);
&.absolute-position {
position: absolute;
@ -29,23 +34,12 @@
}
&.nolabel {
> .label {
> label {
display:none;
}
}
> .label ~ div {
border-top-left-radius:0;
border-top-right-radius:0;
border-bottom-right-radius:inherit;
border-bottom-left-radius:inherit;
min-height: 0;
}
&.nolabel > .label ~ div {
border-radius: inherit;
}
.label {
label {
text-overflow:ellipsis;
overflow:hidden;
text-align:center;
@ -57,51 +51,28 @@
display: flex;
justify-content: center;
white-space: pre;
// justify-content: space-around;
align-items: center;
&.accent {
color:var(--color-accent);
}
order: -1;
}
}
.glass-effect {
position: relative;
&:after {
content:"";
position: absolute;
pointer-events: none;
top:0;
left:0;
right:0;
bottom:0;
background: radial-gradient(ellipse farthest-side at center top, var(--color-glass-1), var(--color-glass-2));
background-size: 150% 150%;
background-repeat: no-repeat;
background-position: center top;
opacity: var(--glass-opacity);
z-index: 3;
canvas {
flex: 1;
min-height: 0;
}
> inner {
overflow: hidden;
position: relative;
flex: 1;
}
}
@import 'widgets/fader';
@import 'widgets/knob';
@import 'widgets/matrices';
@import 'widgets/patchbay';
@import 'widgets/pads';
@import 'widgets/plots';
@import 'widgets/toggle';
@import 'widgets/push';
@import 'widgets/switch';
@import 'widgets/menu';
@import 'widgets/panel';
@import 'widgets/containers';
@import 'widgets/sliders';
@import 'widgets/inputs';
@import 'widgets/maths';
@import 'widgets/buttons';
@import 'widgets/pads';
@import 'widgets/plots';
@import 'widgets/indicators';

Some files were not shown because too many files have changed in this diff Show more