Skip to content

Build your personal knowledge base with Trilium Notes

16.4 KB
Raw Blame
.geo-view {
  overflow: hidden;
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;

  > .collection-properties {
    position: relative;
  }
}

.geo-map-container.maplibregl-map {
  font: inherit;

  .maplibregl-ctrl-attrib {
    font-size: 0.8em;
  }
}

.geo-map-container {
  /* How far everything standing over the map is held off its edges: the zoom controls (see
     MapToolbar.css), the editing bar, the detail pane (see DetailPane.css) and MapLibre's own scale
     and attribution below. The very room the image viewer keeps its controls at, taken from the
     shared name rather than restated (see the overlay buttons in theme-next/base.css), so the two
     cannot drift apart.

     Then the same room named once per edge, which is what everything over the map is actually placed
     from: in fullscreen the edges of the map are the edges of the screen, and part of a screen may
     not be the screen's to draw on (see below). Every placement goes through these rather than
     through the room above, so that saying it once there is enough. */
  --geo-map-inset: var(--overlay-button-inset, 10px);
  --geo-map-inset-top: var(--geo-map-inset);
  --geo-map-inset-bottom: var(--geo-map-inset);
  --geo-map-inset-left: var(--geo-map-inset);
  --geo-map-inset-right: var(--geo-map-inset);

  /* The two sides again, in the reading direction, for the app's own furniture — which is placed
     that way round, the trailing corner being the corner the reader ends a line at. MapLibre's
     corners are named left and right whatever the direction, so its controls keep the pair above. */
  --geo-map-inset-start: var(--geo-map-inset-left);
  --geo-map-inset-end: var(--geo-map-inset-right);

  /* How tall the controls in the corner stand, which is what anything else opened over that corner
     has to end above (see DetailPane.css). The image viewer's zoom controls are the same height,
     being the same group (see the overlay buttons in theme-next/forms.css); the fallback is that
     height where no theme names one. */
  --geo-map-toolbar-height: var(--overlay-button-height, 28px);

  /* Where the head of the leading column stands: the search bar (see SearchBox.css) and the result
     navigator placed from it (see ResultNavigator.css). Overridden for mobile below. */
  --geo-map-search-top: var(--geo-map-inset-top);

  /* Where the foot of the map stops anything reaching down towards it: the room kept from the
     bottom, the height of the bars standing there (MapToolbar, EditToolbar), and as much air again.
     Read by the detail pane and by the place panel on mobile. */
  --geo-map-foot: calc(var(--geo-map-inset-bottom) + var(--geo-map-toolbar-height) + var(--geo-map-inset));

  /*
   * What everything standing over the map is dressed in — our own control groups and MapLibre's
   * scale and attribution alike, so that they read as one set rather than as ours beside theirs.
   * The app's menu surface, which is what every panel floating over content in Trilium is drawn on;
   * the map's furniture asks for it by these names, and the groups have them handed over below,
   * under the names their own surface reads.
   *
   * Thinner than a menu's, though, and that is the whole of the difference: a menu is opened over a
   * page that is mostly one flat colour, where 85% of that colour over the rest of it is glass
   * enough. These stand over a picture. At the same fill the frosting behind them (see below) has
   * nothing left to show — on a dark map especially, where what little comes through is dark to
   * begin with — and a panel meant to look like glass reads as a chip of plastic laid on the map.
   * Two thirds of the fill leaves the streets under it as shapes rather than as detail, which is
   * what a frosted pane does, and still carries text at the size these are set in.
   */
  --geo-map-panel-fill: 66%;
  --geo-map-panel-background: color-mix(in srgb, var(--menu-background-color) var(--geo-map-panel-fill), transparent);
  --geo-map-panel-text-color: var(--menu-text-color);
  --geo-map-panel-border-color: var(--dropdown-border-color);
  --geo-map-panel-hover-background: var(--icon-button-hover-background);
  --geo-map-panel-hover-text-color: var(--hover-item-text-color);
  --geo-map-panel-active-background: var(--active-item-background-color);
  --geo-map-panel-active-text-color: var(--active-item-text-color);

  height: 100%;
  position: relative;
  overflow: hidden;

  .maplibregl-canvas-container {
    position: relative;
  }

  /* MapLibre spaces its controls off the edge by margins of its own; restated in the shared
     inset's terms, so they stand where everything else over the map stands and follow it if it
     ever moves. The foot carries the scale and, on desktop, the attribution; on mobile the
     attribution stands at the head instead (see map.tsx). */
  .maplibregl-ctrl-bottom-left .maplibregl-ctrl,
  .maplibregl-ctrl-bottom-right .maplibregl-ctrl {
    margin-bottom: var(--geo-map-inset-bottom);
    margin-left: var(--geo-map-inset-left);
    margin-right: var(--geo-map-inset-right);
  }

  .maplibregl-ctrl-top-left .maplibregl-ctrl {
    margin-top: var(--geo-map-inset-top);
    margin-left: var(--geo-map-inset-left);
    margin-right: var(--geo-map-inset-right);
  }
}

/* On mobile the attribution takes the top leading corner (see map.tsx), so the column starts below
   it: the room kept from the top, the attribution's own height, and as much air again. */
body.mobile .geo-map-container {
  --geo-map-search-top: calc(var(--geo-map-inset-top) * 2 + var(--geo-map-toolbar-height));
}

/* Read the other way round, the trailing corner is the left one. Only which side is which changes;
   what each side is worth is settled above and in fullscreen below, and is read through from here. */
body[dir=rtl] .geo-map-container {
  --geo-map-inset-start: var(--geo-map-inset-right);
  --geo-map-inset-end: var(--geo-map-inset-left);
}

/*
 * On a screen of its own, the map keeps clear of whatever the screen keeps for itself — the notch
 * and the home bar of a phone, and the rounded corners and the camera housing of a laptop that has
 * one, which is why this is not asked only of mobile. Nothing outside the map can do it for it:
 * fullscreen takes the container out of the layout that pads for these (see `#root-widget` and the
 * panes in style.css) and lays it over the whole screen instead, so its own edges are the ones that
 * have to give way. The mind map reckons its own fullscreen the same way (see MindMap.css).
 *
 * The map itself still fills the screen corner to corner — only what stands over it is held off,
 * which is the point of insetting rather than padding.
 */
.geo-map-container:fullscreen {
  --geo-map-inset-top: calc(var(--geo-map-inset) + var(--safe-area-inset-top, env(safe-area-inset-top)));
  --geo-map-inset-bottom: calc(var(--geo-map-inset) + var(--safe-area-inset-bottom, env(safe-area-inset-bottom)));
  --geo-map-inset-left: calc(var(--geo-map-inset) + var(--safe-area-inset-left, env(safe-area-inset-left)));
  --geo-map-inset-right: calc(var(--geo-map-inset) + var(--safe-area-inset-right, env(safe-area-inset-right)));
}

/*
 * On a dark map everything standing over it goes dark too, whatever the app itself is wearing — a
 * built-in dark style or one a note has said is dark (`#map:darkStyle`, see `useLayerData`). A pale
 * panel over a dark map is a lamp standing in the corner of it: the eye goes to the panel rather
 * than to what the panel is for.
 *
 * The colours are ones the app already keeps dark in both of its themes — what a tooltip is drawn in
 * — so this follows the theme rather than setting up a second one beside it. The hairline and the
 * hover are the dark surface's own, the theme's being settled against a background these panels no
 * longer have: its light-theme border would ring a dark panel in white, and its hover would put dark
 * text on a dark fill.
 *
 * Only what we dress is dressed: a marker's preview is the app's own note tooltip, and it belongs to
 * the app rather than to the map, so it is left in the theme the reader chose.
 */
.geo-map-container.dark {
  --geo-map-panel-background: color-mix(in srgb, var(--tooltip-background-color) var(--geo-map-panel-fill), transparent);
  --geo-map-panel-text-color: var(--tooltip-foreground-color);
  --geo-map-panel-border-color: rgb(255 255 255 / 15%);
  --geo-map-panel-hover-background: rgb(255 255 255 / 12%);
  --geo-map-panel-hover-text-color: var(--tooltip-foreground-color);
  --geo-map-panel-active-background: rgb(255 255 255 / 22%);
  --geo-map-panel-active-text-color: var(--tooltip-foreground-color);
}

/*
 * Everything the control groups standing over the map have in common — the camera in the foot
 * corner (MapToolbar), the editing actions at the middle of the foot (EditToolbar), the drawing
 * tools at the head or down the leading edge (DrawToolbar) — said here once for all of them: the
 * room they keep from the map's edges, the layer they stand on, and the set the map's furniture is
 * dressed in, all under the names the shared group reads (see the overlay buttons in
 * theme-next/forms.css). What is left for each of them to say is where it stands.
 *
 * Set on the groups rather than on the map, so that nothing else standing over the map is dressed
 * for a theme the reader did not choose — a marker's preview is the app's own note tooltip, and it
 * belongs to the app.
 */
.geo-map-container .tn-overlay-control-group {
  /* The room the map keeps at each of its edges, handed to whichever corner a group names (see
     `placement` on OverlayControlGroup): in fullscreen the edges of the map are the edges of the
     screen, and part of a screen may not be the screen's to draw on. Told per edge, so that a group
     at the foot stands clear of a home bar and still on the line the scale opposite it keeps. */
  --overlay-group-inset-top: var(--geo-map-inset-top);
  --overlay-group-inset-bottom: var(--geo-map-inset-bottom);
  --overlay-group-inset-start: var(--geo-map-inset-start);
  --overlay-group-inset-end: var(--geo-map-inset-end);

  /* Above the canvas whatever order the two end up in: MapLibre builds its part of the container
     itself, so what Preact renders alongside is not reliably the later sibling. The number clears
     MapLibre's own control corners, which sit at 2. */
  z-index: 3;

  /* The hover pair has no overlay-button name of its own, so the group's is asked for directly; the
     last pair marks a choice in force, which is the editing group's + while the map waits to be told
     a place. */
  --overlay-button-background: var(--geo-map-panel-background);
  --overlay-button-color: var(--geo-map-panel-text-color);
  --overlay-button-backdrop-filter: var(--dropdown-backdrop-filter, blur(10px));
  --opaque-icon-button-hover-background-color: var(--geo-map-panel-hover-background);
  --opaque-icon-button-hover-color: var(--geo-map-panel-hover-text-color);
  --active-item-background-color: var(--geo-map-panel-active-background);
  --active-item-text-color: var(--geo-map-panel-active-text-color);
}

/*
 * MapLibre's own furniture, dressed as the bar opposite it is.
 *
 * It ships them as white boxes with hairlines of their own and nothing to switch: there is no dark
 * mode in maplibre-gl.css, only literal colours (the scale a white fill with a `#333` rule around
 * it, the attribution a flat white pill), so the only way for them to belong to the map they stand
 * on is to be dressed here. Selectors carry both of the control's own classes, which is what it
 * takes to outweigh MapLibre's `.maplibregl-ctrl-attrib.maplibregl-compact` without `!important`.
 */
.geo-map-container .maplibregl-ctrl.maplibregl-ctrl-scale,
.geo-map-container .maplibregl-ctrl.maplibregl-ctrl-attrib {
  background: var(--geo-map-panel-background);
  color: var(--geo-map-panel-text-color);
  border: 1px solid var(--geo-map-panel-border-color);
  border-radius: 8px;
  box-shadow: 0 2px 8px #0003;
  /* The frosting the groups opposite wear, which is a menu's. */
  backdrop-filter: var(--dropdown-backdrop-filter, blur(10px));
}

/* The scale is a ruler as much as a label: its width says what the distance is worth, so it keeps
   the room MapLibre gives its text rather than being squeezed into a chip. */
.geo-map-container .maplibregl-ctrl.maplibregl-ctrl-scale {
  padding: 1px 6px;
}

/* Folded into a corner, and unfolded there, the attribution is rounded further by MapLibre than our
   panels are (12px against 8px) — by rules as specific as the one above, so its corners are asked
   for once more with a class to spare. */
.geo-map-container .maplibregl-ctrl.maplibregl-ctrl-attrib.maplibregl-compact,
.geo-map-container .maplibregl-ctrl.maplibregl-ctrl-attrib.maplibregl-compact-show {
  border-radius: 8px;
}

/* The links are the attribution — every word of it but the separators — so they are the text rather
   than something coloured apart from it, and say they can be followed when pointed at. */
.geo-map-container .maplibregl-ctrl-attrib a {
  color: inherit;
}

.geo-map-container .maplibregl-ctrl-attrib a:hover {
  color: inherit;
  text-decoration: underline;
}

/*
 * The mark on the button that folds the attribution away, drawn as the mask of a shape filled with
 * the panel's own colour rather than as the picture MapLibre paints there.
 *
 * That picture is a black glyph baked into a data URI, so on a dark panel it is a black mark on a
 * dark ground with no way to recolour it — and inverting it would be a guess at which panels are
 * dark. Worn as a mask it takes whatever colour the panel is wearing, in either theme and on either
 * kind of map. The shape is MapLibre's own (BSD-3-Clause, © MapLibre contributors), the very one it
 * would have drawn.
 *
 * Named by four of its classes, which is what it takes to outweigh the faint black MapLibre washes
 * the button with while the attribution is unfolded — three classes of its own, and enough to leave
 * the mark filled with a colour that cannot be seen against anything.
 */
.geo-map-container .maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-button {
  background-color: currentColor;
  background-image: none;
  -webkit-mask-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' fill-rule='evenodd' viewBox='0 0 20 20'%3E%3Cpath d='M4 10a6 6 0 1 0 12 0 6 6 0 1 0-12 0m5-3a1 1 0 1 0 2 0 1 1 0 1 0-2 0m0 3a1 1 0 1 1 2 0v3a1 1 0 1 1-2 0'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' fill-rule='evenodd' viewBox='0 0 20 20'%3E%3Cpath d='M4 10a6 6 0 1 0 12 0 6 6 0 1 0-12 0m5-3a1 1 0 1 0 2 0 1 1 0 1 0-2 0m0 3a1 1 0 1 1 2 0v3a1 1 0 1 1-2 0'/%3E%3C/svg%3E");
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

/*
 * The map is waiting to be told a place, and says so under the pointer.
 *
 * Set on MapLibre's own canvas container rather than on the map around it: MapLibre dresses that
 * container itself (`.maplibregl-canvas-container.maplibregl-interactive { cursor: grab }`), so a
 * cursor stated anywhere above it is never inherited through — which is why the rule stopped showing
 * when the map moved off Leaflet. Named by four classes, which is what it takes to outweigh that.
 *
 * Left off while the pointer is down, so that panning the map to reach the place still says grabbing
 * as it does at every other time — MapLibre's `:active` rule is a class fewer, and would lose.
 */
.geo-view.placing-note .geo-map-container .maplibregl-canvas-container:not(:active) {
  cursor: crosshair;
}

/* The marker preview is the app's own note tooltip (see Tooltips), so the popup around it is taken
   back to nothing — otherwise the tooltip, chrome and all, would sit inside a second box of
   MapLibre's own, white on every theme and with its own padding, corners and shadow. */
.marker-tooltip .maplibregl-popup-content {
  padding: 0;
  background: none;
  border-radius: 0;
  box-shadow: none;
}

/* Drawn in a hard white by MapLibre, and the tooltip it would point at hides its own arrow anyway. */
.marker-tooltip .maplibregl-popup-tip {
  display: none;
}

/* Bootstrap positions a tooltip absolutely, which here would take the preview out of the popup's
   flow and collapse the box the popup is sized and placed by — MapLibre already places it. Still
   positioned, though, so that the quick-edit button, which is pinned to the corner of the tooltip,
   still has that tooltip to be pinned to. */
.marker-tooltip .tooltip {
  position: relative;
}