You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.0 KiB

  1. <script lang="ts">
  2. import { getSelectedContext } from "$lib/contexts/SelectContext.svelte";
  3. import { getStateContext } from "$lib/contexts/StateContext.svelte";
  4. import type Device from "$lib/models/device";
  5. import { KELVIN_PALETTE, RGB_PALETTE } from "$lib/models/palette";
  6. import ColorPalette from "./ColorPalette.svelte";
  7. const {deviceList} = getStateContext();
  8. const {selectedMap} = getSelectedContext();
  9. let selected: Device[];
  10. let unselected: Device[];
  11. $: selected = $deviceList.filter(d => !!$selectedMap[d.id]);
  12. $: unselected = $deviceList.filter(d => !$selectedMap[d.id]);
  13. let assignment: string;
  14. $: {
  15. assignment = "";
  16. if (selected.length > 0) {
  17. for (const alias of selected[0].aliases) {
  18. if (!selected.find(d => !d.aliases.includes(alias)) && !unselected.find(d => d.aliases.includes(alias))) {
  19. assignment = alias;
  20. break;
  21. }
  22. }
  23. if (assignment === "") {
  24. if (selected.length == 1) {
  25. assignment = selected[0].id;
  26. } else {
  27. let prefix = selected[0].id;
  28. for (const device of selected) {
  29. for (let i = 0; i < prefix.length; i++) {
  30. if (device.id.charAt(i) !== prefix.charAt(i)) {
  31. prefix = prefix.slice(0, i);
  32. break;
  33. }
  34. }
  35. }
  36. if (prefix.length > 0) {
  37. assignment = `${prefix}{${selected.map(d => d.id.slice(prefix.length)).join("|")}}`
  38. }
  39. }
  40. if (assignment === "") {
  41. assignment = `{${selected.map(d => d.id).join("|")}}`
  42. }
  43. }
  44. }
  45. }
  46. </script>
  47. <div class="toolbar">
  48. <ColorPalette palette={RGB_PALETTE} />
  49. </div>
  50. <style lang="sass">
  51. div.toolbar
  52. position: fixed
  53. bottom: 0
  54. width: 100%
  55. height: 2em
  56. padding: 0.35em 1ch
  57. box-sizing: border-box
  58. font-size: 1.5em
  59. background: #18181c
  60. color: #abc
  61. box-shadow: 1px 1px 1px #000
  62. display: flex
  63. flex-direction: row
  64. flex-wrap: wrap
  65. </style>