From ac40c98eb2708ce1ebd5301999a5c7da46e555f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C5=BD=C3=A1ra?= Date: Wed, 24 Jun 2020 14:22:29 +0200 Subject: [PATCH] filtering --- app/css/cyp.less | 1 + app/css/elements/filter.less | 8 ++ app/css/elements/search.less | 2 +- app/css/mixins.less | 1 - app/cyp.css | 2 +- app/cyp.js | 167 ++++++++++++++++++++++------------- app/icons/filter-variant.svg | 1 + app/js/elements/filter.js | 33 +++++++ app/js/elements/library.js | 15 +++- app/js/elements/search.js | 2 +- app/js/icons.js | 118 ++++++++++++------------- app/js/item.js | 4 + 12 files changed, 228 insertions(+), 126 deletions(-) create mode 100644 app/css/elements/filter.less create mode 100644 app/icons/filter-variant.svg create mode 100644 app/js/elements/filter.js diff --git a/app/css/cyp.less b/app/css/cyp.less index 01277fa..00999ff 100644 --- a/app/css/cyp.less +++ b/app/css/cyp.less @@ -84,6 +84,7 @@ select { @import "elements/range.less"; @import "elements/playlist.less"; @import "elements/search.less"; +@import "elements/filter.less"; @import "elements/library.less"; @import "elements/tag.less"; @import "elements/back.less"; diff --git a/app/css/elements/filter.less b/app/css/elements/filter.less new file mode 100644 index 0000000..bdccf12 --- /dev/null +++ b/app/css/elements/filter.less @@ -0,0 +1,8 @@ +cyp-filter { + .item; + + .icon { + width: 32px; + margin-left: var(--icon-spacing); + } +} diff --git a/app/css/elements/search.less b/app/css/elements/search.less index e9425fb..44b1ea4 100644 --- a/app/css/elements/search.less +++ b/app/css/elements/search.less @@ -3,7 +3,7 @@ cyp-search { .item; align-items: stretch; - button:first-of-type { + button:first-of-type { // pseudo-class to override margin-left: var(--icon-spacing); } } diff --git a/app/css/mixins.less b/app/css/mixins.less index 00c0c44..90a0143 100644 --- a/app/css/mixins.less +++ b/app/css/mixins.less @@ -50,7 +50,6 @@ padding: 8px; - > .icon { margin-right: var(--icon-spacing); } diff --git a/app/cyp.css b/app/cyp.css index d41649f..f1e11a5 100644 --- a/app/cyp.css +++ b/app/cyp.css @@ -1 +1 @@ -*,*::before,*::after{box-sizing:inherit}html{background-color:var(--fg)}body{margin:0}main{flex:auto;overflow:auto}header,footer{flex:none;z-index:1;box-shadow:var(--box-shadow)}footer{position:relative;overflow:hidden;height:56px}@media (max-width:480px){footer{height:40px}}input,select{font:inherit}select{color:inherit}option{color:initial}button{color:inherit;font:inherit;-webkit-appearance:none;-moz-appearance:none;appearance:none;flex-direction:row;align-items:center;flex:none;background-color:transparent;padding:0;border:none;line-height:1;cursor:pointer}button:not([hidden]){display:flex}select{background-color:transparent;border:1px solid var(--fg);border-radius:4px;padding:2px 4px}@font-face{font-family:"Lato";src:url("font/LatoLatin-Regular.woff2") format("woff2");font-style:normal;font-weight:normal}@font-face{font-family:"Lato";src:url("font/LatoLatin-Bold.woff2") format("woff2");font-style:normal;font-weight:bold}.icon{width:var(--icon-size);flex:none}.icon path:not([fill]),.icon polygon:not([fill]),.icon circle:not([fill]){fill:currentColor}.flex-row{flex-direction:row;align-items:center}.flex-row:not([hidden]){display:flex}.flex-column{flex-direction:column}.flex-column:not([hidden]){display:flex}.ellipsis{overflow:hidden;text-overflow:ellipsis}.font-large{font-size:18px;line-height:24px}.selectable{cursor:pointer;position:relative}.selectable.selected{color:var(--primary);background-color:var(--primary-tint)}.selectable.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}.item{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px}.item:not([hidden]){display:flex}.item:nth-child(odd){background-color:var(--bg-alt)}.item.selected{color:var(--primary);background-color:var(--primary-tint)}.item.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}.item>.icon{margin-right:var(--icon-spacing)}.item .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}.item button:first-of-type{margin-left:auto}.item button .icon{width:32px}.art .icon,.art img{display:block;width:100%}cyp-app{--icon-size:24px;--icon-spacing:4px;--primary:rgb(var(--primary-raw));--primary-tint:rgba(var(--primary-raw), .1);--box-shadow:0 0 3px #000;--border-width:4px}cyp-app[theme=light]{--fg:#333;--bg:#f0f0f0;--bg-alt:#e0e0e0;--text-shadow:none}cyp-app[theme=dark]{--fg:#f0f0f0;--bg:#333;--bg-alt:#444;--text-shadow:0 1px 1px rgba(0,0,0,0.8)}@media (prefers-color-scheme:dark){cyp-app[theme=auto]{--fg:#f0f0f0;--bg:#333;--bg-alt:#444;--text-shadow:0 1px 1px rgba(0,0,0,0.8)}}@media (prefers-color-scheme:light){cyp-app[theme=auto]{--fg:#333;--bg:#f0f0f0;--bg-alt:#e0e0e0;--text-shadow:none}}@media (max-width:640px),(max-height:640px){cyp-app[theme]{--text-shadow:none}}cyp-app[color=dodgerblue]{--primary-raw:30, 144, 255}cyp-app[color=darkorange]{--primary-raw:255, 140, 0}cyp-app[color=limegreen]{--primary-raw:50, 205, 50}cyp-app{flex-direction:column;box-sizing:border-box;margin:0 auto;max-width:800px;height:calc(100px * var(--vh));font-family:lato,sans-serif;font-size:16px;line-height:1.25;background-color:var(--bg);color:var(--fg);white-space:nowrap}cyp-app:not([hidden]){display:flex}cyp-menu,cyp-commands{flex-direction:row;align-items:center;height:100%}cyp-menu:not([hidden]),cyp-commands:not([hidden]){display:flex}cyp-menu button,cyp-commands button{height:100%;flex-direction:column;align-items:center;justify-content:center}cyp-menu button:not([hidden]),cyp-commands button:not([hidden]){display:flex}@media (max-width:480px){cyp-menu button,cyp-commands button{flex-direction:row}cyp-menu button span:not([id]),cyp-commands button span:not([id]){display:none}}cyp-menu button .icon+*,cyp-commands button .icon+*{margin-top:2px}cyp-menu button{flex:1 0 0;border-top:var(--border-width) solid transparent;border-bottom:var(--border-width) solid transparent}cyp-menu button .icon{margin-right:var(--icon-spacing)}cyp-menu button.active{border-top-color:var(--primary);color:var(--primary);background-color:var(--primary-tint)}cyp-commands{position:absolute;left:0;top:0;width:100%;transition:top 300ms;background-color:var(--bg)}cyp-commands[hidden]{display:flex;top:100%}cyp-commands button{flex:0 1 80px}cyp-commands button.last{order:1;margin-left:auto}cyp-song{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px}cyp-song:not([hidden]){display:flex}cyp-song:nth-child(odd){background-color:var(--bg-alt)}cyp-song.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-song.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-song>.icon{margin-right:var(--icon-spacing)}cyp-song .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-song button:first-of-type{margin-left:auto}cyp-song button .icon{width:32px}cyp-song .multiline{flex-direction:column;min-width:0}cyp-song .multiline:not([hidden]){display:flex}cyp-song .multiline .subtitle{overflow:hidden;text-overflow:ellipsis}cyp-queue cyp-song>.icon{width:32px;margin-right:8px}cyp-queue cyp-song .track{display:none}cyp-queue cyp-song:not(.playing)>.icon-play,cyp-queue cyp-song.playing>.icon-music{display:none}cyp-queue cyp-song.playing>.icon{color:var(--primary)}cyp-queue cyp-song.playing::after{content:"";position:absolute;left:0;bottom:0;background-color:var(--primary);width:calc(100% * var(--progress, 0));height:var(--border-width)}cyp-library cyp-song{padding-left:0;padding-top:0;padding-bottom:0}cyp-library cyp-song>.icon{width:64px}cyp-library cyp-song>.icon-play{display:none}cyp-player{flex-direction:row;align-items:center;align-items:stretch}cyp-player:not([hidden]){display:flex}cyp-player:not([data-state=play]) .pause{display:none}cyp-player[data-state=play] .play{display:none}cyp-player:not([data-flags~=random]) .random,cyp-player:not([data-flags~=repeat]) .repeat{opacity:.5}cyp-player[data-flags~=mute] .mute .icon-volume-high{display:none}cyp-player:not([data-flags~=mute]) .mute .icon-volume-off{display:none}cyp-player x-range{flex:auto;--elapsed-color:var(--primary)}cyp-player .art{flex:none;width:96px;height:96px}cyp-player .info{flex:auto;min-width:0;flex-direction:column;justify-content:space-between;padding:0 var(--icon-spacing)}cyp-player .info:not([hidden]){display:flex}cyp-player .info .title{margin-top:8px;font-size:18px;line-height:24px;font-weight:bold}cyp-player .info .title,cyp-player .info .subtitle{overflow:hidden;text-overflow:ellipsis}cyp-player .timeline{flex:none;height:var(--icon-size);margin-bottom:4px;flex-direction:row;align-items:center}cyp-player .timeline:not([hidden]){display:flex}cyp-player .timeline .duration,cyp-player .timeline .elapsed{flex:none;width:5ch;text-align:center}cyp-player .controls{width:220px;min-width:0;flex-direction:column}cyp-player .controls:not([hidden]){display:flex}cyp-player .controls .playback{flex:auto;flex-direction:row;align-items:center;justify-content:space-around}cyp-player .controls .playback:not([hidden]){display:flex}cyp-player .controls .playback .icon{width:40px}cyp-player .controls .playback .icon-play,cyp-player .controls .playback .icon-pause{width:64px}cyp-player .controls .volume{flex:none;margin-bottom:4px;flex-direction:row;align-items:center}cyp-player .controls .volume:not([hidden]){display:flex}cyp-player .controls .volume .mute{margin-right:var(--icon-spacing)}cyp-player .misc{flex:none;flex-direction:column;justify-content:space-around}cyp-player .misc:not([hidden]){display:flex}cyp-player .misc .icon{width:32px}@media (max-width:519px){cyp-player{flex-wrap:wrap;justify-content:space-between}cyp-player .info{order:1;flex-basis:100%;height:96px}}cyp-queue .current>.icon{color:var(--primary)}cyp-settings{--spacing:8px;font-size:18px;line-height:24px}cyp-settings dl{margin:var(--spacing);display:grid;grid-template-columns:max-content 1fr;align-items:center;grid-gap:var(--spacing)}cyp-settings dt{font-weight:bold}cyp-settings dd{margin:0;flex-direction:column;align-items:start}cyp-settings dd:not([hidden]){display:flex}cyp-settings label{flex-direction:row;align-items:center}cyp-settings label:not([hidden]){display:flex}cyp-settings label [type=radio],cyp-settings label [type=checkbox]{margin:0 4px 0 0}cyp-yt pre{margin:.5em .5ch;flex-grow:1;overflow:auto;white-space:pre-wrap}x-range{--thumb-size:8px;--thumb-color:#ddd;--thumb-shadow:#000;--thumb-hover-color:#fff;--track-size:4px;--track-color:#888;--track-shadow:#000;--elapsed-color:#ddd;--remaining-color:transparent;--radius:calc(var(--track-size)/2);display:inline-block;position:relative;width:192px;height:16px}x-range .-track,x-range .-elapsed,x-range .-remaining{position:absolute;top:calc(50% - var(--track-size)/2);height:var(--track-size);border-radius:var(--radius)}x-range .-track{width:100%;left:0;background-color:var(--track-color);box-shadow:0 0 1px var(--thumb-shadow)}x-range .-elapsed{left:0;background-color:var(--elapsed-color)}x-range .-remaining{right:0;background-color:var(--remaining-color)}x-range .-inner{position:absolute;left:var(--thumb-size);right:var(--thumb-size);top:0;bottom:0}x-range .-thumb{all:unset;position:absolute;top:50%;transform:translate(-50%, -50%);border-radius:50%;width:calc(2*var(--thumb-size));height:calc(2*var(--thumb-size));background-color:var(--thumb-color);box-shadow:0 0 2px var(--thumb-shadow)}x-range[disabled]{opacity:.5}x-range:not([disabled]) .-thumb:hover{background-color:var(--thumb-hover-color)}cyp-playlist{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px}cyp-playlist:not([hidden]){display:flex}cyp-playlist:nth-child(odd){background-color:var(--bg-alt)}cyp-playlist.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-playlist.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-playlist>.icon{margin-right:var(--icon-spacing)}cyp-playlist .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-playlist button:first-of-type{margin-left:auto}cyp-playlist button .icon{width:32px}cyp-search form{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px;align-items:stretch}cyp-search form:not([hidden]){display:flex}cyp-search form:nth-child(odd){background-color:var(--bg-alt)}cyp-search form.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-search form.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-search form>.icon{margin-right:var(--icon-spacing)}cyp-search form .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-search form button:first-of-type{margin-left:auto}cyp-search form button .icon{width:32px}cyp-search form button:first-of-type{margin-left:var(--icon-spacing)}cyp-search.pending form{background-image:linear-gradient(var(--primary), var(--primary));background-repeat:no-repeat;background-size:25% var(--border-width);animation:bar ease-in-out 3s alternate infinite}@keyframes bar{0%{background-position:0 100%}100%{background-position:100% 100%}}cyp-library nav{flex-direction:column;align-items:center}cyp-library nav:not([hidden]){display:flex}cyp-library nav button{font-size:18px;line-height:24px;width:200px;margin-top:2em;text-decoration:underline}cyp-library nav button .icon{width:32px;margin-right:var(--icon-spacing)}cyp-tag{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px;padding-left:0;padding-top:0;padding-bottom:0}cyp-tag:not([hidden]){display:flex}cyp-tag:nth-child(odd){background-color:var(--bg-alt)}cyp-tag.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-tag.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-tag>.icon{margin-right:var(--icon-spacing)}cyp-tag .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-tag button:first-of-type{margin-left:auto}cyp-tag button .icon{width:32px}cyp-tag .art{margin-right:var(--icon-spacing);width:64px;height:64px}cyp-back{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px}cyp-back:not([hidden]){display:flex}cyp-back:nth-child(odd){background-color:var(--bg-alt)}cyp-back.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-back.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-back>.icon{margin-right:var(--icon-spacing)}cyp-back .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-back button:first-of-type{margin-left:auto}cyp-back button .icon{width:32px}cyp-path{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px}cyp-path:not([hidden]){display:flex}cyp-path:nth-child(odd){background-color:var(--bg-alt)}cyp-path.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-path.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-path>.icon{margin-right:var(--icon-spacing)}cyp-path .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-path button:first-of-type{margin-left:auto}cyp-path button .icon{width:32px}cyp-yt-result{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px;cursor:default}cyp-yt-result:not([hidden]){display:flex}cyp-yt-result:nth-child(odd){background-color:var(--bg-alt)}cyp-yt-result.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-yt-result.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-yt-result>.icon{margin-right:var(--icon-spacing)}cyp-yt-result .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-yt-result button:first-of-type{margin-left:auto}cyp-yt-result button .icon{width:32px}cyp-yt-result button .icon{width:var(--icon-size)} \ No newline at end of file +*,*::before,*::after{box-sizing:inherit}html{background-color:var(--fg)}body{margin:0}main{flex:auto;overflow:auto}header,footer{flex:none;z-index:1;box-shadow:var(--box-shadow)}footer{position:relative;overflow:hidden;height:56px}@media (max-width:480px){footer{height:40px}}input,select{font:inherit}select{color:inherit}option{color:initial}button{color:inherit;font:inherit;-webkit-appearance:none;-moz-appearance:none;appearance:none;flex-direction:row;align-items:center;flex:none;background-color:transparent;padding:0;border:none;line-height:1;cursor:pointer}button:not([hidden]){display:flex}select{background-color:transparent;border:1px solid var(--fg);border-radius:4px;padding:2px 4px}@font-face{font-family:"Lato";src:url("font/LatoLatin-Regular.woff2") format("woff2");font-style:normal;font-weight:normal}@font-face{font-family:"Lato";src:url("font/LatoLatin-Bold.woff2") format("woff2");font-style:normal;font-weight:bold}.icon{width:var(--icon-size);flex:none}.icon path:not([fill]),.icon polygon:not([fill]),.icon circle:not([fill]){fill:currentColor}.flex-row{flex-direction:row;align-items:center}.flex-row:not([hidden]){display:flex}.flex-column{flex-direction:column}.flex-column:not([hidden]){display:flex}.ellipsis{overflow:hidden;text-overflow:ellipsis}.font-large{font-size:18px;line-height:24px}.selectable{cursor:pointer;position:relative}.selectable.selected{color:var(--primary);background-color:var(--primary-tint)}.selectable.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}.item{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px}.item:not([hidden]){display:flex}.item:nth-child(odd){background-color:var(--bg-alt)}.item.selected{color:var(--primary);background-color:var(--primary-tint)}.item.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}.item>.icon{margin-right:var(--icon-spacing)}.item .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}.item button:first-of-type{margin-left:auto}.item button .icon{width:32px}.art .icon,.art img{display:block;width:100%}cyp-app{--icon-size:24px;--icon-spacing:4px;--primary:rgb(var(--primary-raw));--primary-tint:rgba(var(--primary-raw), .1);--box-shadow:0 0 3px #000;--border-width:4px}cyp-app[theme=light]{--fg:#333;--bg:#f0f0f0;--bg-alt:#e0e0e0;--text-shadow:none}cyp-app[theme=dark]{--fg:#f0f0f0;--bg:#333;--bg-alt:#444;--text-shadow:0 1px 1px rgba(0,0,0,0.8)}@media (prefers-color-scheme:dark){cyp-app[theme=auto]{--fg:#f0f0f0;--bg:#333;--bg-alt:#444;--text-shadow:0 1px 1px rgba(0,0,0,0.8)}}@media (prefers-color-scheme:light){cyp-app[theme=auto]{--fg:#333;--bg:#f0f0f0;--bg-alt:#e0e0e0;--text-shadow:none}}@media (max-width:640px),(max-height:640px){cyp-app[theme]{--text-shadow:none}}cyp-app[color=dodgerblue]{--primary-raw:30, 144, 255}cyp-app[color=darkorange]{--primary-raw:255, 140, 0}cyp-app[color=limegreen]{--primary-raw:50, 205, 50}cyp-app{flex-direction:column;box-sizing:border-box;margin:0 auto;max-width:800px;height:calc(100px * var(--vh));font-family:lato,sans-serif;font-size:16px;line-height:1.25;background-color:var(--bg);color:var(--fg);white-space:nowrap}cyp-app:not([hidden]){display:flex}cyp-menu,cyp-commands{flex-direction:row;align-items:center;height:100%}cyp-menu:not([hidden]),cyp-commands:not([hidden]){display:flex}cyp-menu button,cyp-commands button{height:100%;flex-direction:column;align-items:center;justify-content:center}cyp-menu button:not([hidden]),cyp-commands button:not([hidden]){display:flex}@media (max-width:480px){cyp-menu button,cyp-commands button{flex-direction:row}cyp-menu button span:not([id]),cyp-commands button span:not([id]){display:none}}cyp-menu button .icon+*,cyp-commands button .icon+*{margin-top:2px}cyp-menu button{flex:1 0 0;border-top:var(--border-width) solid transparent;border-bottom:var(--border-width) solid transparent}cyp-menu button .icon{margin-right:var(--icon-spacing)}cyp-menu button.active{border-top-color:var(--primary);color:var(--primary);background-color:var(--primary-tint)}cyp-commands{position:absolute;left:0;top:0;width:100%;transition:top 300ms;background-color:var(--bg)}cyp-commands[hidden]{display:flex;top:100%}cyp-commands button{flex:0 1 80px}cyp-commands button.last{order:1;margin-left:auto}cyp-song{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px}cyp-song:not([hidden]){display:flex}cyp-song:nth-child(odd){background-color:var(--bg-alt)}cyp-song.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-song.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-song>.icon{margin-right:var(--icon-spacing)}cyp-song .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-song button:first-of-type{margin-left:auto}cyp-song button .icon{width:32px}cyp-song .multiline{flex-direction:column;min-width:0}cyp-song .multiline:not([hidden]){display:flex}cyp-song .multiline .subtitle{overflow:hidden;text-overflow:ellipsis}cyp-queue cyp-song>.icon{width:32px;margin-right:8px}cyp-queue cyp-song .track{display:none}cyp-queue cyp-song:not(.playing)>.icon-play,cyp-queue cyp-song.playing>.icon-music{display:none}cyp-queue cyp-song.playing>.icon{color:var(--primary)}cyp-queue cyp-song.playing::after{content:"";position:absolute;left:0;bottom:0;background-color:var(--primary);width:calc(100% * var(--progress, 0));height:var(--border-width)}cyp-library cyp-song{padding-left:0;padding-top:0;padding-bottom:0}cyp-library cyp-song>.icon{width:64px}cyp-library cyp-song>.icon-play{display:none}cyp-player{flex-direction:row;align-items:center;align-items:stretch}cyp-player:not([hidden]){display:flex}cyp-player:not([data-state=play]) .pause{display:none}cyp-player[data-state=play] .play{display:none}cyp-player:not([data-flags~=random]) .random,cyp-player:not([data-flags~=repeat]) .repeat{opacity:.5}cyp-player[data-flags~=mute] .mute .icon-volume-high{display:none}cyp-player:not([data-flags~=mute]) .mute .icon-volume-off{display:none}cyp-player x-range{flex:auto;--elapsed-color:var(--primary)}cyp-player .art{flex:none;width:96px;height:96px}cyp-player .info{flex:auto;min-width:0;flex-direction:column;justify-content:space-between;padding:0 var(--icon-spacing)}cyp-player .info:not([hidden]){display:flex}cyp-player .info .title{margin-top:8px;font-size:18px;line-height:24px;font-weight:bold}cyp-player .info .title,cyp-player .info .subtitle{overflow:hidden;text-overflow:ellipsis}cyp-player .timeline{flex:none;height:var(--icon-size);margin-bottom:4px;flex-direction:row;align-items:center}cyp-player .timeline:not([hidden]){display:flex}cyp-player .timeline .duration,cyp-player .timeline .elapsed{flex:none;width:5ch;text-align:center}cyp-player .controls{width:220px;min-width:0;flex-direction:column}cyp-player .controls:not([hidden]){display:flex}cyp-player .controls .playback{flex:auto;flex-direction:row;align-items:center;justify-content:space-around}cyp-player .controls .playback:not([hidden]){display:flex}cyp-player .controls .playback .icon{width:40px}cyp-player .controls .playback .icon-play,cyp-player .controls .playback .icon-pause{width:64px}cyp-player .controls .volume{flex:none;margin-bottom:4px;flex-direction:row;align-items:center}cyp-player .controls .volume:not([hidden]){display:flex}cyp-player .controls .volume .mute{margin-right:var(--icon-spacing)}cyp-player .misc{flex:none;flex-direction:column;justify-content:space-around}cyp-player .misc:not([hidden]){display:flex}cyp-player .misc .icon{width:32px}@media (max-width:519px){cyp-player{flex-wrap:wrap;justify-content:space-between}cyp-player .info{order:1;flex-basis:100%;height:96px}}cyp-queue .current>.icon{color:var(--primary)}cyp-settings{--spacing:8px;font-size:18px;line-height:24px}cyp-settings dl{margin:var(--spacing);display:grid;grid-template-columns:max-content 1fr;align-items:center;grid-gap:var(--spacing)}cyp-settings dt{font-weight:bold}cyp-settings dd{margin:0;flex-direction:column;align-items:start}cyp-settings dd:not([hidden]){display:flex}cyp-settings label{flex-direction:row;align-items:center}cyp-settings label:not([hidden]){display:flex}cyp-settings label [type=radio],cyp-settings label [type=checkbox]{margin:0 4px 0 0}cyp-yt pre{margin:.5em .5ch;flex-grow:1;overflow:auto;white-space:pre-wrap}x-range{--thumb-size:8px;--thumb-color:#ddd;--thumb-shadow:#000;--thumb-hover-color:#fff;--track-size:4px;--track-color:#888;--track-shadow:#000;--elapsed-color:#ddd;--remaining-color:transparent;--radius:calc(var(--track-size)/2);display:inline-block;position:relative;width:192px;height:16px}x-range .-track,x-range .-elapsed,x-range .-remaining{position:absolute;top:calc(50% - var(--track-size)/2);height:var(--track-size);border-radius:var(--radius)}x-range .-track{width:100%;left:0;background-color:var(--track-color);box-shadow:0 0 1px var(--thumb-shadow)}x-range .-elapsed{left:0;background-color:var(--elapsed-color)}x-range .-remaining{right:0;background-color:var(--remaining-color)}x-range .-inner{position:absolute;left:var(--thumb-size);right:var(--thumb-size);top:0;bottom:0}x-range .-thumb{all:unset;position:absolute;top:50%;transform:translate(-50%, -50%);border-radius:50%;width:calc(2*var(--thumb-size));height:calc(2*var(--thumb-size));background-color:var(--thumb-color);box-shadow:0 0 2px var(--thumb-shadow)}x-range[disabled]{opacity:.5}x-range:not([disabled]) .-thumb:hover{background-color:var(--thumb-hover-color)}cyp-playlist{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px}cyp-playlist:not([hidden]){display:flex}cyp-playlist:nth-child(odd){background-color:var(--bg-alt)}cyp-playlist.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-playlist.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-playlist>.icon{margin-right:var(--icon-spacing)}cyp-playlist .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-playlist button:first-of-type{margin-left:auto}cyp-playlist button .icon{width:32px}cyp-search form{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px;align-items:stretch}cyp-search form:not([hidden]){display:flex}cyp-search form:nth-child(odd){background-color:var(--bg-alt)}cyp-search form.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-search form.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-search form>.icon{margin-right:var(--icon-spacing)}cyp-search form .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-search form button:first-of-type{margin-left:auto}cyp-search form button .icon{width:32px}cyp-search form button:first-of-type{margin-left:var(--icon-spacing)}cyp-search.pending form{background-image:linear-gradient(var(--primary), var(--primary));background-repeat:no-repeat;background-size:25% var(--border-width);animation:bar ease-in-out 3s alternate infinite}@keyframes bar{0%{background-position:0 100%}100%{background-position:100% 100%}}cyp-filter{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px}cyp-filter:not([hidden]){display:flex}cyp-filter:nth-child(odd){background-color:var(--bg-alt)}cyp-filter.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-filter.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-filter>.icon{margin-right:var(--icon-spacing)}cyp-filter .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-filter button:first-of-type{margin-left:auto}cyp-filter button .icon{width:32px}cyp-filter .icon{width:32px;margin-left:var(--icon-spacing)}cyp-library nav{flex-direction:column;align-items:center}cyp-library nav:not([hidden]){display:flex}cyp-library nav button{font-size:18px;line-height:24px;width:200px;margin-top:2em;text-decoration:underline}cyp-library nav button .icon{width:32px;margin-right:var(--icon-spacing)}cyp-tag{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px;padding-left:0;padding-top:0;padding-bottom:0}cyp-tag:not([hidden]){display:flex}cyp-tag:nth-child(odd){background-color:var(--bg-alt)}cyp-tag.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-tag.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-tag>.icon{margin-right:var(--icon-spacing)}cyp-tag .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-tag button:first-of-type{margin-left:auto}cyp-tag button .icon{width:32px}cyp-tag .art{margin-right:var(--icon-spacing);width:64px;height:64px}cyp-back{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px}cyp-back:not([hidden]){display:flex}cyp-back:nth-child(odd){background-color:var(--bg-alt)}cyp-back.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-back.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-back>.icon{margin-right:var(--icon-spacing)}cyp-back .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-back button:first-of-type{margin-left:auto}cyp-back button .icon{width:32px}cyp-path{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px}cyp-path:not([hidden]){display:flex}cyp-path:nth-child(odd){background-color:var(--bg-alt)}cyp-path.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-path.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-path>.icon{margin-right:var(--icon-spacing)}cyp-path .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-path button:first-of-type{margin-left:auto}cyp-path button .icon{width:32px}cyp-yt-result{flex-direction:row;align-items:center;cursor:pointer;position:relative;padding:8px;cursor:default}cyp-yt-result:not([hidden]){display:flex}cyp-yt-result:nth-child(odd){background-color:var(--bg-alt)}cyp-yt-result.selected{color:var(--primary);background-color:var(--primary-tint)}cyp-yt-result.selected::before{content:"";position:absolute;left:0;top:0;bottom:0;width:var(--border-width);background-color:var(--primary)}cyp-yt-result>.icon{margin-right:var(--icon-spacing)}cyp-yt-result .title{font-size:18px;line-height:24px;overflow:hidden;text-overflow:ellipsis;font-weight:bold;min-width:0}cyp-yt-result button:first-of-type{margin-left:auto}cyp-yt-result button .icon{width:32px}cyp-yt-result button .icon{width:var(--icon-size)} \ No newline at end of file diff --git a/app/cyp.js b/app/cyp.js index 362b27b..ac5df7d 100644 --- a/app/cyp.js +++ b/app/cyp.js @@ -424,17 +424,35 @@ function createURL(ticket) { } let ICONS={}; -ICONS["library-music"] = ` - -`; -ICONS["plus"] = ` - +ICONS["playlist-music"] = ` + `; ICONS["folder"] = ` `; -ICONS["playlist-music"] = ` - +ICONS["shuffle"] = ` + +`; +ICONS["artist"] = ` + +`; +ICONS["download"] = ` + +`; +ICONS["checkbox-marked-outline"] = ` + +`; +ICONS["magnify"] = ` + +`; +ICONS["delete"] = ` + +`; +ICONS["rewind"] = ` + +`; +ICONS["cancel"] = ` + `; ICONS["settings"] = ` @@ -442,74 +460,56 @@ ICONS["settings"] = ` ICONS["pause"] = ` `; -ICONS["artist"] = ` - +ICONS["arrow-down-bold"] = ` + +`; +ICONS["filter-variant"] = ` + `; ICONS["volume-off"] = ` `; -ICONS["keyboard-backspace"] = ` - -`; -ICONS["cancel"] = ` - -`; -ICONS["fast-forward"] = ` - -`; -ICONS["delete"] = ` - -`; -ICONS["volume-high"] = ` - -`; -ICONS["minus"] = ` - -`; -ICONS["play"] = ` - -`; -ICONS["magnify"] = ` - -`; -ICONS["arrow-down-bold"] = ` - +ICONS["close"] = ` + `; ICONS["music"] = ` `; -ICONS["rewind"] = ` - -`; -ICONS["album"] = ` - -`; -ICONS["download"] = ` - -`; -ICONS["account-multiple"] = ` - -`; -ICONS["close"] = ` - -`; -ICONS["content-save"] = ` - +ICONS["repeat"] = ` + `; ICONS["arrow-up-bold"] = ` `; +ICONS["keyboard-backspace"] = ` + +`; +ICONS["play"] = ` + +`; +ICONS["plus"] = ` + +`; +ICONS["content-save"] = ` + +`; +ICONS["library-music"] = ` + +`; +ICONS["fast-forward"] = ` + +`; +ICONS["volume-high"] = ` + +`; ICONS["chevron-double-right"] = ` `; -ICONS["shuffle"] = ` - +ICONS["album"] = ` + `; -ICONS["checkbox-marked-outline"] = ` - -`; -ICONS["repeat"] = ` - +ICONS["minus_unused"] = ` + `; function node(name, attrs, content, parent) { @@ -1056,6 +1056,10 @@ class Item extends HTMLElement { _buildTitle(title) { return node("span", {className:"title"}, title, this); } + + matchPrefix(prefix) { + return this.textContent.match(/\w+/g).some(word => word.toLowerCase().startsWith(prefix)); + } } class Song extends Item { @@ -1589,6 +1593,37 @@ class Back extends Item { customElements.define("cyp-back", Back); +const SELECTOR = ["cyp-tag", "cyp-path", "cyp-song"].join(", "); + +class Filter extends HTMLElement { + constructor() { + super(); + this._built = false; + } + + get value() { return this._input.value.trim(); } + set value(value) { this._input.value = value; } + get _input() { return this.querySelector("input"); } + + connectedCallback() { + if (this._built) { return; } + + node("input", {type:"text"}, "", this); + icon("filter-variant", this); + + this._input.addEventListener("input", e => this._apply()); + this._built = true; + } + + _apply() { + let value = this.value.toLowerCase(); + let all = [...this.parentNode.querySelectorAll(SELECTOR)]; + all.forEach(item => item.hidden = !item.matchPrefix(value)); + } +} + +customElements.define("cyp-filter", Filter); + const TAGS$1 = { "Album": "Albums", "AlbumArtist": "Artists" @@ -1622,6 +1657,8 @@ class Library extends Component { if (query.length < 3) { return; } this._doSearch(query); }; + + this._filter = new Filter(); } _popState() { @@ -1680,11 +1717,12 @@ class Library extends Component { } async _listTags(tag, filter = {}) { - const values = await this._mpd.listTags(tag, filter); + const values = (await this._mpd.listTags(tag, filter)).filter(nonempty); clear(this); if ("AlbumArtist" in filter) { this._buildBack(); } - values.filter(nonempty).forEach(value => this._buildTag(tag, value, filter)); + (values.length > 0) && this._addFilter(); + values.forEach(value => this._buildTag(tag, value, filter)); } async _listPath(path) { @@ -1692,6 +1730,7 @@ class Library extends Component { clear(this); path && this._buildBack(); + (paths["directory"].length + paths["file"].length > 0) && this._addFilter(); paths["directory"].forEach(path => this._buildPath(path)); paths["file"].forEach(path => this._buildPath(path)); } @@ -1700,6 +1739,7 @@ class Library extends Component { const songs = await this._mpd.listSongs(filter); clear(this); this._buildBack(); + (songs.length > 0 && this._addFilter()); songs.forEach(song => this.appendChild(new Song(song))); } @@ -1793,6 +1833,11 @@ class Library extends Component { } } + _addFilter() { + this.appendChild(this._filter); + this._filter.value = ""; + } + _initCommands() { const sel = this.selection; diff --git a/app/icons/filter-variant.svg b/app/icons/filter-variant.svg new file mode 100644 index 0000000..9011cfa --- /dev/null +++ b/app/icons/filter-variant.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/js/elements/filter.js b/app/js/elements/filter.js new file mode 100644 index 0000000..888cbeb --- /dev/null +++ b/app/js/elements/filter.js @@ -0,0 +1,33 @@ +import * as html from "../html.js"; + + +const SELECTOR = ["cyp-tag", "cyp-path", "cyp-song"].join(", "); + +export default class Filter extends HTMLElement { + constructor() { + super(); + this._built = false; + } + + get value() { return this._input.value.trim(); } + set value(value) { this._input.value = value; } + get _input() { return this.querySelector("input"); } + + connectedCallback() { + if (this._built) { return; } + + html.node("input", {type:"text"}, "", this); + html.icon("filter-variant", this); + + this._input.addEventListener("input", e => this._apply()); + this._built = true; + } + + _apply() { + let value = this.value.toLowerCase(); + let all = [...this.parentNode.querySelectorAll(SELECTOR)]; + all.forEach(item => item.hidden = !item.matchPrefix(value)); + } +} + +customElements.define("cyp-filter", Filter); diff --git a/app/js/elements/library.js b/app/js/elements/library.js index 48ab7d3..b347863 100644 --- a/app/js/elements/library.js +++ b/app/js/elements/library.js @@ -5,6 +5,7 @@ import Path from "./path.js"; import Back from "./back.js"; import Song from "./song.js"; import Search from "./search.js"; +import Filter from "./filter.js"; import { escape, serializeFilter } from "../mpd.js"; @@ -42,6 +43,8 @@ class Library extends Component { if (query.length < 3) { return; } this._doSearch(query); } + + this._filter = new Filter(); } _popState() { @@ -100,11 +103,12 @@ class Library extends Component { } async _listTags(tag, filter = {}) { - const values = await this._mpd.listTags(tag, filter); + const values = (await this._mpd.listTags(tag, filter)).filter(nonempty); html.clear(this); if ("AlbumArtist" in filter) { this._buildBack(); } - values.filter(nonempty).forEach(value => this._buildTag(tag, value, filter)); + (values.length > 0) && this._addFilter(); + values.forEach(value => this._buildTag(tag, value, filter)); } async _listPath(path) { @@ -112,6 +116,7 @@ class Library extends Component { html.clear(this); path && this._buildBack(); + (paths["directory"].length + paths["file"].length > 0) && this._addFilter(); paths["directory"].forEach(path => this._buildPath(path)); paths["file"].forEach(path => this._buildPath(path)); } @@ -120,6 +125,7 @@ class Library extends Component { const songs = await this._mpd.listSongs(filter); html.clear(this); this._buildBack(); + (songs.length > 0 && this._addFilter()); songs.forEach(song => this.appendChild(new Song(song))); } @@ -213,6 +219,11 @@ class Library extends Component { } } + _addFilter() { + this.appendChild(this._filter); + this._filter.value = ""; + } + _initCommands() { const sel = this.selection; diff --git a/app/js/elements/search.js b/app/js/elements/search.js index e2f0a92..838f6af 100644 --- a/app/js/elements/search.js +++ b/app/js/elements/search.js @@ -30,4 +30,4 @@ export default class Search extends HTMLElement { } } -customElements.define("cyp-search", Search); \ No newline at end of file +customElements.define("cyp-search", Search); diff --git a/app/js/icons.js b/app/js/icons.js index 0cbdbbb..9353a64 100644 --- a/app/js/icons.js +++ b/app/js/icons.js @@ -1,15 +1,33 @@ let ICONS={}; -ICONS["library-music"] = ` - -`; -ICONS["plus"] = ` - +ICONS["playlist-music"] = ` + `; ICONS["folder"] = ` `; -ICONS["playlist-music"] = ` - +ICONS["shuffle"] = ` + +`; +ICONS["artist"] = ` + +`; +ICONS["download"] = ` + +`; +ICONS["checkbox-marked-outline"] = ` + +`; +ICONS["magnify"] = ` + +`; +ICONS["delete"] = ` + +`; +ICONS["rewind"] = ` + +`; +ICONS["cancel"] = ` + `; ICONS["settings"] = ` @@ -17,73 +35,55 @@ ICONS["settings"] = ` ICONS["pause"] = ` `; -ICONS["artist"] = ` - +ICONS["arrow-down-bold"] = ` + +`; +ICONS["filter-variant"] = ` + `; ICONS["volume-off"] = ` `; -ICONS["keyboard-backspace"] = ` - -`; -ICONS["cancel"] = ` - -`; -ICONS["fast-forward"] = ` - -`; -ICONS["delete"] = ` - -`; -ICONS["volume-high"] = ` - -`; -ICONS["minus"] = ` - -`; -ICONS["play"] = ` - -`; -ICONS["magnify"] = ` - -`; -ICONS["arrow-down-bold"] = ` - +ICONS["close"] = ` + `; ICONS["music"] = ` `; -ICONS["rewind"] = ` - -`; -ICONS["album"] = ` - -`; -ICONS["download"] = ` - -`; -ICONS["account-multiple"] = ` - -`; -ICONS["close"] = ` - -`; -ICONS["content-save"] = ` - +ICONS["repeat"] = ` + `; ICONS["arrow-up-bold"] = ` `; +ICONS["keyboard-backspace"] = ` + +`; +ICONS["play"] = ` + +`; +ICONS["plus"] = ` + +`; +ICONS["content-save"] = ` + +`; +ICONS["library-music"] = ` + +`; +ICONS["fast-forward"] = ` + +`; +ICONS["volume-high"] = ` + +`; ICONS["chevron-double-right"] = ` `; -ICONS["shuffle"] = ` - +ICONS["album"] = ` + `; -ICONS["checkbox-marked-outline"] = ` - -`; -ICONS["repeat"] = ` - +ICONS["minus_unused"] = ` + `; export default ICONS; diff --git a/app/js/item.js b/app/js/item.js index 59b1768..f9f11e3 100644 --- a/app/js/item.js +++ b/app/js/item.js @@ -19,4 +19,8 @@ export default class Item extends HTMLElement { _buildTitle(title) { return html.node("span", {className:"title"}, title, this); } + + matchPrefix(prefix) { + return this.textContent.match(/\w+/g).some(word => word.toLowerCase().startsWith(prefix)); + } }