@arcgis/map-components
Version:
ArcGIS Map Components
199 lines (198 loc) • 22.7 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { c as y } from "../../chunks/runtime.js";
import { css as $, html as a } from "lit";
import { ref as f } from "lit/directives/ref.js";
import { g as v } from "../../chunks/globalCss.js";
import S from "@arcgis/core/views/Theme.js";
import { u as C } from "../../chunks/useT9n.js";
import { generateGuid as k } from "@arcgis/toolkit/string";
import { classes as g } from "@arcgis/toolkit/dom";
import { usePropertyChange as I } from "@arcgis/lumina/controllers";
import { m as M } from "../../chunks/useViewModel.js";
import d from "@arcgis/core/Color.js";
import { LitElement as E, createEvent as T, safeClassMap as p, nothing as m } from "@arcgis/lumina";
import { substitute as P } from "@arcgis/core/intl.js";
import { watch as R } from "@arcgis/core/core/reactiveUtils.js";
import O from "@arcgis/core/widgets/support/GridControls/GridControlsViewModel.js";
function L(n) {
if (n == null || Number.isNaN(n))
return 0;
const e = n + 180;
return Math.trunc(w(e, 360));
}
function D(n) {
let e = n;
return e == null || (typeof e == "string" && (e = Number.parseInt(e, 10)), Number.isNaN(e)) ? 0 : w(Math.trunc(e), 360) - 180;
}
function w(n, e) {
return (n % e + e) % e;
}
const _ = {
fromAttribute: (n) => d.fromHex(n),
toAttribute: (n) => typeof n == "string" ? n : n?.toHex() ?? ""
}, z = $`.esri-widget__heading{color:var(--calcite-color-text-2);margin:0 0 .5rem;font-weight:var(--calcite-font-weight-semibold)}h1.esri-widget__heading{font-size:var(--calcite-font-size-xl)}h2.esri-widget__heading{font-size:var(--calcite-font-size-md)}h3.esri-widget__heading,h4.esri-widget__heading,h5.esri-widget__heading,h6.esri-widget__heading{font-size:var(--calcite-font-size)}.esri-widget{box-sizing:border-box;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);font-size:var(--calcite-font-size);line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget *,.esri-widget :before,.esri-widget :after{box-sizing:inherit}.esri-widget.esri-widget--disabled>*{opacity:.4;pointer-events:none}.esri-widget.esri-widget--compact{--esri-widget-padding-y: 0;--esri-widget-padding-x: 0}.esri-widget__anchor{color:var(--calcite-color-text-2)}.esri-widget__anchor:hover{color:var(--calcite-color-text-3)}.esri-widget__anchor:hover,.esri-widget__anchor:focus{text-decoration:underline}.esri-widget__anchor--disabled{opacity:.4;pointer-events:none}.esri-widget__header{background-color:var(--calcite-color-foreground-1);flex:1 0 100%;justify-content:space-between;align-items:center;width:100%;min-height:48px;padding:12px 0 12px 15px;display:flex}.esri-widget__heading{word-break:break-word}.esri-widget__header .esri-widget__heading{width:calc(100% - 48px);text-align:initial;color:var(--calcite-color-text-1);align-items:center;margin:0;padding:0;display:flex}.esri-widget__header-button{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);border:none;flex:0 0 48px;justify-content:center;align-self:stretch;align-items:center;width:48px;padding:0;display:flex}.esri-widget__footer{background-color:var(--calcite-color-foreground-1);justify-content:center;align-items:center;width:100%;min-height:48px;display:flex}.esri-widget__footer-pagination{color:var(--calcite-color-text-2);justify-content:space-between;align-items:center;display:flex}.esri-widget__footer-pagination-previous-button,.esri-widget__footer-pagination-next-button{cursor:pointer;background-color:var(--calcite-color-foreground-1);border:0;margin:0 7px;padding:12px 15px;transition:background-color .125s ease-in-out}.esri-widget__footer-pagination-previous-button:hover,.esri-widget__footer-pagination-previous-button:focus,.esri-widget__footer-pagination-next-button:hover,.esri-widget__footer-pagination-next-button:focus{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1)}.esri-menu{visibility:hidden;z-index:1;background-clip:padding;background-color:var(--calcite-color-foreground-1);background-clip:padding-box;width:100%;max-height:0;margin:2px 0 0;padding:0;font-size:var(--calcite-font-size);line-height:var(--calcite-spacing-xl);position:absolute;top:100%;left:0;overflow:hidden;box-shadow:0 1px 2px #0000004d}.esri-menu .esri-menu__header{color:var(--calcite-color-text-inverse);background-color:var(--calcite-color-inverse);padding:6px 12px}.esri-menu__list{margin:0;padding:0;list-style:none}.esri-menu__list-item{cursor:pointer;border-top:1px solid #adadad4d;border-left:3px solid #0000;padding:.8em 1em}.esri-menu__list-item [class^=esri-icon-],.esri-menu__list-item [class*=" esri-icon-"]{padding-right:2.8px}.esri-menu__list-item:first-child{border-top:none}.esri-menu__list-item--focus,.esri-menu__list-item:hover,.esri-menu__list-item:focus{background-color:var(--calcite-color-foreground-1)}.esri-menu__list-item:active{background-color:var(--calcite-color-foreground-current)}.esri-menu__list-item--active,.esri-menu__list-item--active:hover,.esri-menu__list-item--active:focus{background-color:var(--calcite-color-foreground-1);border-left-color:var(--calcite-color-brand)}.esri-widget__table{border-collapse:collapse;color:var(--calcite-color-text-1);border:none;width:100%;line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget__table tr:nth-child(odd){background-color:var(--calcite-color-transparent)}.esri-widget__table tr:nth-child(2n){background-color:var(--calcite-color-transparent-press)}.esri-widget__table tr a{color:var(--calcite-color-text-2)}.esri-widget__table tr a:hover,.esri-widget__table tr a:focus{color:var(--calcite-color-text-1)}.esri-widget__table tr td,.esri-widget__table tr th{vertical-align:top;word-break:break-word;padding:.5em .7em;font-size:var(--calcite-font-size-sm);font-weight:var(--calcite-font-weight-regular)}.esri-widget__table tr th{text-align:left;border-right:3px solid #0000000d;width:50%}.esri-widget__table tr td{width:50%}.esri-input{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1);border:1px solid #959595;font-size:var(--calcite-font-size)}.esri-input::-ms-clear{display:none}.esri-input::placeholder{opacity:1;color:var(--calcite-color-text-2)}.esri-input:placeholder-shown{text-overflow:ellipsis}.esri-input[type=text],.esri-input[type=password],.esri-input[type=number]{height:32px;padding:0 .5em}calcite-combobox.esri-input{border:none}.esri-widget__content--empty{text-align:center;color:var(--calcite-color-border-input);flex-flow:column wrap;align-items:center;padding:18px 22px;display:flex}.esri-widget__content--empty h1.esri-widget__heading,.esri-widget__content--empty h2.esri-widget__heading,.esri-widget__content--empty h3.esri-widget__heading,.esri-widget__content--empty h4.esri-widget__heading,.esri-widget__content--empty h5.esri-widget__heading{font-weight:var(--calcite-font-weight-regular)}.esri-widget__content-illustration--empty{width:128px;padding:1rem 0}.esri-widget__content-icon--empty{width:32px;padding:.5rem 0}.esri-select{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background:var(--calcite-color-foreground-1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-8 -8 32 32' width='32' height='32'%3E%3Cpath d='M8 11.207l-4-4V5.793l4 4 4-4v1.414z' fill='%23adadad' fillrule='nonzero'/%3E%3C/svg%3E") 100% no-repeat;border:1px solid #959595;border-radius:0;width:100%;height:32px;margin:0;padding:0 .5em;font-family:inherit;font-size:.85em;display:block}.esri-select[disabled]{cursor:auto}.esri-select::-ms-expand{display:none}.esri-disabled a,.esri-disabled [role=menu],.esri-disabled [role=checkbox],.esri-disabled [class^=esri-icon-],.esri-disabled [class*=" esri-icon-"]{color:var(--calcite-color-text-3)}.keynav-mode .esri-widget:focus,.keynav-mode .esri-widget :focus{z-index:1;outline-offset:2px;outline:2px solid #adadad}.esri-widget__loader-animation{border:.15em solid #adadad4d;border-top-color:var(--calcite-color-border-input);border-radius:100%;width:1em;height:1em;font-size:var(--calcite-font-size-md);animation:1.25s linear infinite esri-rotate;display:block;transform:translateZ(0)}:dir(rtl) .esri-widget__table th{text-align:right;border-left:3px solid #0000000d;border-right:none}:dir(rtl) .esri-select{background-position:0}:dir(rtl) .esri-menu__list-item{border-left:none;border-right:3px solid #0000}:dir(rtl) .esri-menu__list-item [class^=esri-icon-],:dir(rtl) .esri-menu__list-item [class*=" esri-icon-"]{padding-left:2px;padding-right:0}:dir(rtl) .esri-menu__list-item--active{border-right-color:var(--calcite-color-brand)}.esri-icon-font-fallback-text{clip:rect(0 0 0 0);width:1px;height:1px;position:absolute;overflow:hidden}.esri-rotating{animation:1.25s linear infinite esri-rotate;transform:translateZ(0)}.esri-clearfix:before,.esri-clearfix:after{content:" ";display:table}.esri-clearfix:after{clear:both}.esri-interactive{cursor:pointer}.esri-hidden{display:none!important}.esri-invisible{visibility:hidden!important}.esri-offscreen{position:absolute;top:-999em;left:-999em}.esri-match-height{flex-direction:column;flex:auto;display:flex;overflow:hidden}:host{display:flex}.root{user-select:none;display:flex;flex-flow:column wrap;padding:var(--arcgis-internal-padding);overflow-y:auto;width:100%;.container{display:flex;flex:1 1 auto;flex-direction:column;gap:var(--calcite-spacing-sm)}.numeric-inputs-container{display:grid;grid-auto-columns:1fr;grid-auto-flow:column;gap:var(--calcite-spacing-sm)}arcgis-labeled-switch{margin-block-end:var(--calcite-spacing-sm)}.switch--bordered{border-width:0 0 var(--calcite-spacing-px) 0;border-style:solid;border-color:var(--calcite-color-border-1);padding-block-end:var(--calcite-spacing-sm)}.tile-group{display:flex;column-gap:var(--calcite-spacing-md);align-items:start;margin-bottom:calc(0px - var(--calcite-spacing-sm))}.tile{position:relative;.content{display:flex;flex-direction:column;row-gap:var(--calcite-spacing-md);align-items:center;padding:var(--calcite-spacing-md);color:var(--calcite-color-text-2)}&.disabled{opacity:var(--calcite-opacity-disabled)}&:focus-within{outline:var(--calcite-spacing-base) solid var(--calcite-color-brand);outline-offset:var(--calcite-spacing-base)}input[type=radio]{appearance:none;position:absolute;inset:0;opacity:.001;border:var(--calcite-spacing-px) solid transparent;cursor:pointer;&:checked+.content{border:var(--calcite-spacing-px) solid var(--calcite-color-brand)}+.content{border:var(--calcite-spacing-px) solid transparent;calcite-label{margin-bottom:calc(0px - var(--calcite-label-margin-bottom, .75rem));font-weight:var(--calcite-font-weight-medium)}}}}.inline-icon{margin-left:var(--calcite-spacing-xs);vertical-align:top;color:var(--calcite-color-status-warning)}}`, h = {
componentIcon: "grid-unit",
gridTheme: { light: "circle", dark: "circle-area", custom: "palette" },
placementState: { interactive: "maximum-territory-distance", place: "move", rotate: "rotate" },
warning: "exclamation-mark-triangle"
}, u = d.fromArray([115, 115, 115]), b = d.fromArray([200, 200, 200]), B = ["interactive", "place", "rotate"], N = M(O);
class W extends E {
constructor() {
super(...arguments), this._labelUid = k(), this._messages = C({}), this._viewModel = N(this), this._placementModeButtonRefs = /* @__PURE__ */ new Map(), this.numericSpacingInputShouldBeVisible = this._viewModel.numericSpacingInputShouldBeVisible, this.view = this._viewModel.view, this.icon = h.componentIcon, this.snappingOptions = this._viewModel.snappingOptions, this.hideColorSelection = !1, this.hideDynamicScaleToggle = !1, this.hideGridEnabledToggle = !1, this.hideNumericInputs = !1, this.hideGridSnapEnabledToggle = !1, this.hideLineIntervalInput = !1, this.hideOutOfScaleWarning = !1, this.hidePlacementButtons = !1, this.hideRotateWithMapToggle = !1, this.rotation = this._viewModel.rotation, this.rotateWithMap = this._viewModel.rotateWithMap, this.spacing = this._viewModel.spacing, this.majorLineInterval = this._viewModel.majorLineInterval, this.gridColor = this._viewModel.gridColor, this.displayEnabled = this._viewModel.displayEnabled, this.gridOutOfScale = this._viewModel.gridOutOfScale, this.unit = this._viewModel.unit, this.dynamicScaling = this._viewModel.dynamicScaling, this.gridControlsEnabled = this._viewModel.gridControlsEnabled, this.interactivePlacementState = this._viewModel.interactivePlacementState, this.snappingEnabled = this._viewModel.snappingEnabled, this.effectiveSpacingAfterDynamicScaling = this._viewModel.effectiveSpacingAfterDynamicScaling, this.placementDisabled = this._viewModel.placementDisabled, this.autoDestroyDisabled = !1, this.arcgisPropertyChange = I()("customColor", "theme", "spacing", "rotation", "majorLineInterval", "rotateWithMap", "dynamicScaling", "snappingEnabled", "interactivePlacementState", "displayEnabled", "gridOutOfScale", "effectiveSpacingAfterDynamicScaling", "gridControlsEnabled", "gridColor"), this.arcgisReady = T();
}
static {
this.properties = { _placementModeButtonRefs: 16, _warningIconTooltipRef: 16, _themePopoverRef: 16, numericSpacingInputShouldBeVisible: 16, view: 0, referenceElement: 1, icon: 1, customColor: [3, { converter: _ }], snappingOptions: 0, theme: 1, hideColorSelection: 5, hideDynamicScaleToggle: 5, hideGridEnabledToggle: 5, hideNumericInputs: 5, hideGridSnapEnabledToggle: 5, hideLineIntervalInput: 5, hideOutOfScaleWarning: 5, hidePlacementButtons: 5, hideRotateWithMapToggle: 5, rotation: 11, rotateWithMap: 5, spacing: 11, majorLineInterval: 11, gridColor: [3, { converter: _ }], displayEnabled: 36, gridOutOfScale: 39, unit: 1, dynamicScaling: 5, gridControlsEnabled: 36, interactivePlacementState: 3, snappingEnabled: 5, effectiveSpacingAfterDynamicScaling: 43, placementDisabled: 5, autoDestroyDisabled: 5, messageOverrides: 0, label: 1 };
}
static {
this.styles = z;
}
get theme() {
const e = this.gridColor;
return !e || u.equals(e) ? "dark" : b.equals(e) ? "light" : "custom";
}
set theme(e) {
const i = this._viewModel.view;
switch (e) {
case "dark":
this.gridColor = u;
break;
case "custom":
this.customColor == null && (this.customColor = i?.theme?.accentColor ?? new S().accentColor), this.gridColor = this.customColor;
break;
default:
this.gridColor = b;
break;
}
}
async destroy() {
await this.manager.destroy();
}
trySetDisplayEnabled(e) {
this._viewModel.trySetDisplayEnabled(e);
}
loaded() {
this.manager.onLifecycle(() => [
// Move focus when movement angle changed by touch/mouse (not keyboard!)
R(() => this._viewModel.gridColor, (e) => {
const i = e instanceof d ? e : typeof e == "string" ? d.fromHex(e) : null;
i && !u.equals(e) && !b.equals(i) ? this.customColor = i : u.equals(i) ? this.theme = "dark" : b.equals(i) && (this.theme = "light");
})
]);
}
_togglePlacementState(e) {
this.interactivePlacementState = this.interactivePlacementState === e ? null : e;
}
_setWarningIconRef(e) {
this._warningIconTooltipRef = e;
}
_setPopoverRef(e) {
this._themePopoverRef = e;
}
_emptyFunction(e) {
}
_setPlacementButtonRef(e) {
if (e) {
const i = e.dataset.placementAction;
this._placementModeButtonRefs.set(i, e);
} else
this._placementModeButtonRefs.clear();
}
render() {
return a`<div class=${p(g("root", v.widget, v.panel))}><div class="container">${this._viewModel.destroyed ? null : this._renderContent()}</div></div>`;
}
_renderContent() {
const { hideGridEnabledToggle: e, hidePlacementButtons: i, hideNumericInputs: t, hideLineIntervalInput: r, hideGridSnapEnabledToggle: o, hideDynamicScaleToggle: l, hideRotateWithMapToggle: s, hideColorSelection: c } = this;
return [
e ? void 0 : this._renderEnabledToggle(),
i ? void 0 : this._renderGridPlacementButtons(),
t ? void 0 : this._renderNumericInputs(),
r ? void 0 : this._renderIntervalInput(),
!o && this.snappingOptions ? this._renderSnappingToggle() : void 0,
l ? void 0 : this._renderDynamicScaleToggle(),
s ? void 0 : this._renderRotateToggle(),
c ? void 0 : this._renderColorSelection()
];
}
_renderGridPlacementButtons() {
const { interactivePlacementState: e, placementDisabled: i, gridControlsEnabled: t } = this, r = i || !t;
return a`<calcite-label scale=s>${this._messages.placementOptions}<calcite-action-bar expand-disabled layout=horizontal>${B.map((o) => this._renderPlacementModeButton(o, r, e))}</calcite-action-bar></calcite-label>`;
}
_renderPlacementModeButton(e, i, t) {
const r = this._messages?.placementState?.[e], o = this._placementModeButtonRefs.get(e);
return a`<div><calcite-action .active=${t === e} alignment=center .disabled=${i} .icon=${h.placementState[e]} data-placement-action=${e ?? m} =${() => this._togglePlacementState(e)} .text=${r ?? ""} ${f(this._setPlacementButtonRef)}></calcite-action>${o ? a`<calcite-tooltip overlay-positioning=fixed placement=top .referenceElement=${o}>${r}</calcite-tooltip>` : void 0}</div>`;
}
_renderNumericInputs() {
const { rotation: e, spacing: i, effectiveSpacingAfterDynamicScaling: t, numericSpacingInputShouldBeVisible: r, gridControlsEnabled: o } = this, l = t != null && t !== i;
return a`<div class=${p(g("numeric-inputs-container"))}>${[
r ? a`<calcite-label scale=s><span>${this._messages?.inputLabel?.spacing}${l ? a`<calcite-icon class=${p(g("inline-icon"))} .icon=${h.warning} scale=s tabindex=0 ${f(this._setWarningIconRef)}></calcite-icon>` : void 0}</span><calcite-input-number .disabled=${!o} number-button-type=none .value=${i?.toFixed(2)} =${({ currentTarget: s }) => {
const c = Number.parseFloat(s.value);
this.spacing = c, c !== this.spacing && (s.value = `${this.spacing}`);
}}></calcite-input-number>${l && this._warningIconTooltipRef ? a`<calcite-tooltip overlay-positioning=fixed placement=leading .referenceElement=${this._warningIconTooltipRef}>${P(this._messages?.warnings?.dynamicSpacing ?? "", { actualSpacingIncludingUnit: t }, {
format: {
actualSpacingIncludingUnit: {
type: "number",
intlOptions: {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
unit: this.unit ?? "meters",
style: "decimal"
}
}
}
})}</calcite-tooltip>` : void 0}</calcite-label>` : void 0,
a`<calcite-label scale=s>${this._messages?.inputLabel?.angle}<calcite-input-number .disabled=${!o} integer number-button-type=none suffix-text=\u00B0 .value=${`${L(e)}`} =${({ currentTarget: s }) => this.rotation = D(s.value)}></calcite-input-number></calcite-label>`
]}</div>`;
}
_renderIntervalInput() {
const { majorLineInterval: e, gridControlsEnabled: i } = this;
return a`<div class=${p(g("numeric-inputs-container"))}><calcite-label scale=s>${this._messages?.inputLabel?.interval}<calcite-input-number .disabled=${!i} integer max=15 min=1 number-button-type=vertical .value=${`${e}`} =${({ currentTarget: t }) => {
const r = Number.parseInt(t.value, 10);
this.majorLineInterval = r, r !== this.majorLineInterval && (t.value = `${this.majorLineInterval}`);
}}></calcite-input-number></calcite-label></div>`;
}
_renderSnappingToggle() {
const { snappingOptions: e, gridControlsEnabled: i } = this, t = e?.gridEnabled ?? !1;
return a`<arcgis-labeled-switch .checked=${t} .disabled=${!(i && !!e)} .label=${this._messages?.switchLabel?.snap} =${(o) => {
o.stopPropagation(), this.snappingOptions?.set("gridEnabled", o.detail);
}}></arcgis-labeled-switch>`;
}
_renderDynamicScaleToggle() {
const { _messages: e, gridOutOfScale: i, dynamicScaling: t, gridControlsEnabled: r } = this, o = !this.hideOutOfScaleWarning && i;
return a`<arcgis-labeled-switch .checked=${t} .disabled=${!r} .hint=${o ? e?.warnings?.outOfScale : void 0} .hintIcon=${h.warning} hint-kind=warning .label=${e?.switchLabel?.scaling} =${(l) => {
l.stopPropagation(), this.dynamicScaling = l.detail;
}}></arcgis-labeled-switch>`;
}
_renderRotateToggle() {
const { gridControlsEnabled: e, rotateWithMap: i } = this;
return a`<arcgis-labeled-switch .checked=${i} .disabled=${!e} .label=${this._messages?.switchLabel?.rotateWithMap ?? ""} =${(t) => {
t.stopPropagation(), this.rotateWithMap = t.detail;
}}></arcgis-labeled-switch>`;
}
_renderEnabledToggle() {
return a`<div class="switch--bordered"><arcgis-labeled-switch .checked=${this.displayEnabled} .disabled=${!!this.interactivePlacementState} .label=${this._messages?.switchLabel?.display} =${(e) => {
e.stopPropagation(), this.trySetDisplayEnabled(e.detail);
}}></arcgis-labeled-switch></div>`;
}
_renderColorSelection() {
const { customColor: e } = this;
return a`<calcite-label scale=s>${this._messages?.inputLabel?.theme}<div class="tile-group">${[
this._renderThemeTile({ value: "dark" }),
this._renderThemeTile({ value: "light" }),
this._renderThemeTile({ value: "custom" }),
this._themePopoverRef ? a`<calcite-popover auto-close .label=${this._messages?.gridLineColorPopoverLabel ?? ""} overlay-positioning=fixed .referenceElement=${this._themePopoverRef}><calcite-color-picker alpha-channel saved-disabled .value=${e?.toHex({ digits: 8 }) ?? "#000000ff"} =${(i) => {
const t = d.fromHex(i.currentTarget.value);
t && (this.customColor = t, this.theme = "custom");
}}></calcite-color-picker></calcite-popover>` : void 0
]}</div></calcite-label>`;
}
_renderThemeTile(e) {
const { theme: i, gridControlsEnabled: t } = this, { value: r } = e, o = this._messages?.gridTheme?.[r], l = `${this._labelUid}--theme_tile_${r}`, s = `${l}__label`, c = h.gridTheme[r];
return a`<div class=${p(g({ tile: !0, disabled: !t }))} role=button ${f(r === "custom" ? this._setPopoverRef : this._emptyFunction)}><input aria-labelledby=${s ?? m} .checked=${i === r} .disabled=${!t} id=${l ?? m} .name=${`${this._labelUid}--theme`} =${(x) => {
this.theme = r, x.currentTarget.focus();
}} tabindex=0 type=radio><div class="content"><calcite-icon .icon=${c} scale=l></calcite-icon><calcite-label .for=${l} id=${s ?? m}>${o}</calcite-label></div></div>`;
}
}
y("arcgis-grid-controls", W);
export {
W as ArcgisGridControls
};