@arcgis/map-components
Version:
ArcGIS Map Components
165 lines (164 loc) • 9.41 kB
JavaScript
import { c as u } from "../../chunks/runtime.js";
import { html as o } from "lit-html";
import { ref as p } from "lit-html/directives/ref.js";
import { usePropertyChange as m } from "@arcgis/components-controllers";
import { focusElement as b } from "@arcgis/components-utils";
import { watch as g } from "@arcgis/core/core/reactiveUtils.js";
import _ from "@arcgis/core/widgets/DirectionalPad/DirectionalPadViewModel.js";
import { LitElement as v, createEvent as f, noShadowRoot as $, safeClassMap as n, nothing as l, safeStyleMap as w } from "@arcgis/lumina";
import { u as R } from "../../chunks/useT9n.js";
import { m as C } from "../../chunks/useViewModel.js";
import { g as d } from "../../chunks/globalCss.js";
import { css as x } from "@lit/reactive-element/css-tag.js";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
v4.32.13 */
const h = [-45, 0, 45, -90, 90, -135, 180, 135], y = {
0: { label: "north", iconName: "chevron-up" },
45: { label: "northEast", iconName: "chevron-up-right" },
90: { label: "east", iconName: "chevron-right" },
135: { label: "southEast", iconName: "chevron-down-right" },
180: { label: "south", iconName: "chevron-down" },
"-135": { label: "southWest", iconName: "chevron-down-left" },
"-90": { label: "west", iconName: "chevron-left" },
"-45": { label: "northWest", iconName: "chevron-up-left" }
}, a = "arcgis-directional-pad", s = {
base: a,
buttonsContainer: `${a}__buttons-container`,
button: `${a}__button`,
compassButton: `${a}__compass`,
rotationContainer: `${a}__rotation-container`,
rotationSliderContainer: `${a}__rotation-slider-container`,
rotationReset: `${a}__rotation-reset-button`,
error: `${a}__error`
}, M = x` {.arcgis-directional-pad{display:flex;flex-direction:column;gap:var(--calcite-spacing-sm);outline:none;box-shadow:none!important;background-color:transparent!important;user-select:none;calcite-action-pad{display:contents}calcite-action-group{touch-action:none}calcite-action{aspect-ratio:1}}.arcgis-directional-pad__buttons-container{--calcite-color-background: transparent;--calcite-action-group-gap: 0;--calcite-action-group-padding: 0;calcite-action{--calcite-color-focus: var(--calcite-color-foreground-3)}calcite-action:not([active]){--calcite-action-background-color-press: var(--calcite-color-foreground-1)}calcite-action[active]{--calcite-action-background-color: var(--calcite-color-foreground-3)}calcite-icon{transform:var(--rotation, unset)} (hover: none){calcite-action{--calcite-action-background-color-hover: var(--calcite-color-foreground-1);--calcite-action-text-color-press: var(--calcite-color-text-3)}}}.arcgis-directional-pad__rotation-container{display:block;width:100%;calcite-action{flex:.3}}.arcgis-directional-pad__rotation-slider-container{display:flex;flex:1;align-items:center;calcite-slider{flex:1;padding-inline:var(--calcite-spacing-xxs)}}}`;
function S(c) {
const { x: t, y: e, width: i, height: r } = c.getBoundingClientRect();
return { x: t + i / 2, y: e + r / 2 };
}
function B(c) {
return c?.spatialReference?.isWebMercator || c?.spatialReference?.isGeographic || !1;
}
const E = C(_);
class D extends v {
constructor() {
super(...arguments), this.messages = R({}), this._onContextMenu = (t) => t.preventDefault(), this._buttons = {}, this.viewModel = E(this), this.angle = this.viewModel.angle, this.rotation = this.viewModel.rotation, this.autoDestroyDisabled = !1, this.disabled = this.viewModel.disabled, this.hideDirectionalButtons = !1, this.icon = "move", this.position = "bottom-left", this.showRotationResetButton = !1, this.showRotationSlider = !1, this.state = this.viewModel.state, this.visualScale = "s", this.arcgisPropertyChange = m()("state"), this.arcgisReady = f();
}
static {
this.properties = { _rotationEnabled: 16, angle: 16, rotation: 16, autoDestroyDisabled: 5, disabled: 5, hideDirectionalButtons: 5, icon: 3, label: 1, messageOverrides: 0, position: 3, referenceElement: 1, showRotationResetButton: 5, showRotationSlider: 5, state: 3, visualScale: 1 };
}
static {
this.shadowRootOptions = $;
}
static {
this.styles = M;
}
// #endregion
// #region State Properties
/**
* When `false`, sets rotation-related controls to a disabled state so the
* user cannot interact with them.
*/
get _rotationEnabled() {
return this.view?.ready ? this.view.constraints.rotationEnabled ?? !1 : !0;
}
// #endregion
// #region Public Methods
/** Permanently destroy the component */
async destroy() {
await this.manager.destroy();
}
// #endregion
// #region Lifecycle
loaded() {
this.manager.onLifecycle(() => [
// Move focus when movement angle changed by touch/mouse (not keyboard!)
g(() => this.viewModel.angle, () => {
this._buttonsContainer?.contains(document.activeElement) && (this.viewModel.angle == null ? this.el.childElem?.focus() : b(this._buttons[this.viewModel.angle]));
})
]);
}
// #endregion
// #region Private Methods
_rotateIcon(t) {
return {
"--rotation": `rotate(${t}deg)`
};
}
_setButtonContainerRef(t) {
t !== void 0 ? (this._buttonsContainer = t, queueMicrotask(() => {
this._buttons = Object.fromEntries(Array.from(t.children, (e) => [
Number.parseInt(e.getAttribute("data-angle") ?? ""),
e
]));
})) : (this._buttonsContainer = void 0, this._buttons = {});
}
/**
* Find component center and start movement
*/
_onButtonPointerDown(t) {
if (this._buttonsContainer === void 0)
return;
t.composedPath().find((r) => r.hasPointerCapture?.(t.pointerId))?.releasePointerCapture(t.pointerId);
const i = S(this._buttonsContainer);
this.viewModel.beginFollowingPointer(t, i);
}
_onSliderInput({ currentTarget: t }) {
typeof t.value == "number" && (this.viewModel.rotation = t.value);
}
/**
* Reset angle of rotation
*/
_onRotationReset() {
this.viewModel.rotation = 0;
}
/**
* Handle directional pad clicks only when using the keyboard
*/
_onClick(t) {
this.viewModel.moveOnce(t);
}
// #endregion
// #region Rendering
render() {
const { label: t, disabled: e } = this, i = this.view == null || this.view.type === "2d";
return o`<div .ariaLabel=${t ?? void 0} class=${n({ [s.base]: !0, [d.widget]: !0, [d.disabled]: e })} tabindex=-1>${i ? this._renderContent() : this._renderUnsupportedMessage()}</div>`;
}
_renderUnsupportedMessage() {
return o`<section class=${n(s.error)}><p>${this.messages.unsupported}</p></section>`;
}
_renderContent() {
return [
this.hideDirectionalButtons ? void 0 : this._renderDirectionalButtons(),
this.showRotationSlider ? this._renderRotation() : void 0
];
}
_renderDirectionalButtons() {
return o`<calcite-action-pad expand-disabled layout=grid><calcite-action-group class=${n(s.buttonsContainer)} dir=ltr =${{
handleEvent: this._onContextMenu,
capture: !0
}} ${p(this._setButtonContainerRef)}>${h.slice(0, 4).map(this._renderButton, this)}${this._renderCompass()}${h.slice(4).map(this._renderButton, this)}</calcite-action-group></calcite-action-pad>`;
}
_renderButton(t) {
const { label: e, iconName: i } = y[t], r = this.messages[e];
return o`<calcite-action .active=${this.angle === t} alignment=center class=${n(s.button)} data-angle=${t ?? l} .disabled=${this.disabled} =${this._onClick.bind(this, t)} =${this._onButtonPointerDown} .scale=${this.visualScale} .text=${r ?? ""} title=${r ?? l}><calcite-icon .icon=${i} .scale=${this.visualScale}></calcite-icon></calcite-action>`;
}
_renderCompass() {
const t = this.disabled || B(this.view) ? "compass-needle" : "arrow-up", e = this.rotation === 0, i = this.messages.resetHeading;
return o`<calcite-action alignment=center class=${n(s.compassButton)} .disabled=${this.disabled || !this._rotationEnabled || e} =${this._onRotationReset} .scale=${this.visualScale} style=${w(this._rotateIcon(this.rotation))} .text=${i ?? ""} title=${i ?? l}>${!e && o`<calcite-icon .icon=${t} .scale=${this.visualScale}></calcite-icon>` || ""}</calcite-action>`;
}
_renderRotation() {
return o`<calcite-action-pad expand-disabled layout=horizontal><calcite-action-group class=${n(s.rotationContainer)}>${this.showRotationResetButton ? this._renderRotationResetButton() : null}${this._renderRotationSlider()}</calcite-action-group></calcite-action-pad>`;
}
_renderRotationResetButton() {
const t = this.messages.resetHeading;
return o`<calcite-action alignment=center class=${n(s.rotationReset)} .disabled=${this.disabled || !this._rotationEnabled} =${this._onRotationReset} .scale=${this.visualScale} .text=${t ?? ""} title=${t ?? l}><calcite-icon flip-rtl icon=rotate .scale=${this.visualScale}></calcite-icon></calcite-action>`;
}
_renderRotationSlider() {
return o`<div class=${n(s.rotationSliderContainer)}><calcite-slider .ariaLabel=${this.messages.heading} .disabled=${this.disabled || !this._rotationEnabled} label-handles max=360 min=0 required .scale=${this.visualScale} .value=${Math.round(this.rotation)} =${this._onSliderInput}></calcite-slider></div>`;
}
}
u("arcgis-directional-pad", D);
export {
D as ArcgisDirectionalPad
};