@arcgis/lumina 4.31.0-next.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,819 @@
1
+ import {
2
+ defaultEventBubbles,
3
+ defaultEventCancelable,
4
+ defaultEventComposed,
5
+ lazyMetaGroupJoiner,
6
+ lazyMetaItemJoiner,
7
+ lazyMetaSubItemJoiner
8
+ } from "./chunk-CH52Q2MB.js";
9
+
10
+ // src/createEvent.ts
11
+ import { retrieveComponent, trackPropertyKey } from "@arcgis/components-controllers";
12
+ var createEventFactory = (eventName = "", options = {}, component = retrieveComponent()) => {
13
+ const emitter = {
14
+ emit: (payload) => {
15
+ if (process.env.NODE_ENV !== "production") {
16
+ if (eventName === "") {
17
+ throw new Error("Unable to resolve event name from property name");
18
+ }
19
+ if (!component.el.isConnected) {
20
+ console.warn(
21
+ `Trying to emit an ${eventName} event on a disconnected element ${component.el.tagName.toLowerCase()}`
22
+ );
23
+ }
24
+ }
25
+ const event = new CustomEvent(eventName, {
26
+ detail: payload,
27
+ cancelable: defaultEventCancelable,
28
+ bubbles: defaultEventBubbles,
29
+ composed: defaultEventComposed,
30
+ ...options
31
+ });
32
+ component.el.dispatchEvent(event);
33
+ return event;
34
+ }
35
+ };
36
+ if (eventName === "") {
37
+ trackPropertyKey(
38
+ component,
39
+ (key) => {
40
+ if (process.env.NODE_ENV !== "production" && key === void 0) {
41
+ throw new Error(`createEvent must be called in property default value only`);
42
+ }
43
+ eventName = key;
44
+ },
45
+ emitter
46
+ );
47
+ }
48
+ return emitter;
49
+ };
50
+ var createEvent = createEventFactory.bind(null, "");
51
+
52
+ // src/decorators.ts
53
+ import { state } from "@lit/reactive-element/decorators/state.js";
54
+ import { property as litProperty } from "@lit/reactive-element/decorators/property.js";
55
+ var property = litProperty;
56
+ var method = void 0;
57
+
58
+ // src/lazyLoad.ts
59
+ import { Deferred, camelToKebab } from "@arcgis/components-utils";
60
+
61
+ // src/devOnlyDetectIncorrectLazyUsages.ts
62
+ function devOnlyDetectIncorrectLazyUsages(LitClass) {
63
+ const genericPrototype = LitClass.prototype;
64
+ const allowList = /* @__PURE__ */ new Set([
65
+ // We shouldn't be overwriting this property
66
+ "constructor",
67
+ // Called by Lit - we proxy it to this.el in ProxyComponent
68
+ "setAttribute"
69
+ ]);
70
+ const customErrorMessages = {
71
+ addEventListener: "use this.listen() or this.el.addEventListener()"
72
+ };
73
+ Object.entries({
74
+ ...Object.getOwnPropertyDescriptors(HTMLElement.prototype),
75
+ ...Object.getOwnPropertyDescriptors(Element.prototype),
76
+ ...Object.getOwnPropertyDescriptors(Node.prototype),
77
+ ...Object.getOwnPropertyDescriptors(EventTarget.prototype)
78
+ }).filter(([key, { value }]) => typeof value === "function" && !allowList.has(key)).forEach(([key]) => {
79
+ genericPrototype[key] = () => {
80
+ throw new Error(
81
+ `You should not be calling this.${key}() directly as it won't work correctly in lazy-builds. Instead, ${customErrorMessages[key] ?? `use this.el.${key}()`}`
82
+ );
83
+ };
84
+ });
85
+ }
86
+
87
+ // src/lifecycleSupport.ts
88
+ function attachToAncestor(child, el) {
89
+ let ancestor = el;
90
+ while (ancestor = ancestor.parentNode ?? ancestor.host) {
91
+ if (ancestor?.constructor?.lumina) {
92
+ const litParent = ancestor;
93
+ if (!litParent.manager?.loadedCalled) {
94
+ litParent._offspring.push(child);
95
+ }
96
+ return litParent._postLoad?.promise;
97
+ }
98
+ }
99
+ return false;
100
+ }
101
+
102
+ // src/utils.ts
103
+ var noShadowRoot = {};
104
+
105
+ // src/lazyLoad.ts
106
+ var makeDefineCustomElements = (runtime, structure) => function defineCustomElements(windowOrOptions, options) {
107
+ if (!globalThis.customElements) {
108
+ return;
109
+ }
110
+ const resolvedOptions = options ?? windowOrOptions ?? {};
111
+ const resourcesUrl = resolvedOptions.resourcesUrl;
112
+ if (resourcesUrl) {
113
+ runtime.setAssetPath(resourcesUrl);
114
+ }
115
+ const hideUntilHydrated = new CSSStyleSheet();
116
+ hideUntilHydrated.replaceSync(
117
+ `:is(${Object.keys(structure).join(",")}):not([${runtime.hydratedAttribute}]){visibility:hidden}[${runtime.hydratedAttribute}]{visibility:inherit}`
118
+ );
119
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, hideUntilHydrated];
120
+ Object.entries(structure).forEach(createLazyElement);
121
+ };
122
+ function createLazyElement([tagName, [load, compactMeta = ""]]) {
123
+ var _a;
124
+ if (customElements.get(tagName)) {
125
+ return;
126
+ }
127
+ const [compactObservedProps, compactAsyncMethods, compactSyncMethods] = compactMeta.split(lazyMetaGroupJoiner);
128
+ const observedProps = compactObservedProps ? compactObservedProps?.split(lazyMetaItemJoiner).map(parseCondensedProp) : void 0;
129
+ const observedProperties = observedProps?.map(([property2]) => property2);
130
+ const ProxyClass = (_a = class extends ProxyComponent {
131
+ constructor() {
132
+ const isFirstInstanceOfType = !ProxyClass._loadPromise;
133
+ if (isFirstInstanceOfType) {
134
+ ProxyClass._loadPromise = load();
135
+ ProxyClass._initializePrototype();
136
+ }
137
+ super();
138
+ }
139
+ }, _a.observedAttributes = observedProps?.map(([, attribute]) => attribute).filter((attribute) => attribute !== ""), _a._properties = observedProperties, _a._asyncMethods = compactAsyncMethods ? compactAsyncMethods?.split(lazyMetaItemJoiner) : void 0, _a._syncMethods = compactSyncMethods?.split(lazyMetaItemJoiner), _a._name = tagName, _a);
140
+ customElements.define(tagName, ProxyClass);
141
+ }
142
+ function parseCondensedProp(propAndAttribute) {
143
+ const name = propAndAttribute.split(lazyMetaSubItemJoiner);
144
+ return name.length === 1 ? [name[0], camelToKebab(name[0])] : name;
145
+ }
146
+ var HtmlElement = globalThis.HTMLElement ?? parseCondensedProp;
147
+ var ProxyComponent = class extends HtmlElement {
148
+ constructor() {
149
+ super();
150
+ /**
151
+ * On HMR, preserve the values of all properties that at least once were set
152
+ * by someone other than component itself.
153
+ *
154
+ * @internal
155
+ */
156
+ this._hmrSetProps = /* @__PURE__ */ new Set();
157
+ /** @internal */
158
+ this._hmrSetAttributes = /* @__PURE__ */ new Set();
159
+ /** @internal */
160
+ this._store = {};
161
+ /**
162
+ * If attributeChangedCallback() is called before the LitElement is loaded,
163
+ * store the attributes here, and replay later
164
+ */
165
+ this._pendingAttributes = [];
166
+ /**
167
+ * Resolved once LitElement's load() is complete.
168
+ * Not read inside of this class, but needed for LitElement to determine if
169
+ * it's closest ancestor finished load()
170
+ */
171
+ this._postLoad = new Deferred();
172
+ /**
173
+ * Resolved once LitElement's loaded() is complete
174
+ */
175
+ this._postLoaded = new Deferred();
176
+ /**
177
+ * Direct offspring that should be awaited before loaded() is emitted
178
+ */
179
+ this._offspring = [];
180
+ this._saveInstanceProperties();
181
+ const ProxyClass = this.constructor;
182
+ if (ProxyClass._LitConstructor) {
183
+ this._initializeComponent({ a: ProxyClass._LitConstructor });
184
+ } else {
185
+ void ProxyClass._loadPromise.then(this._initializeComponent.bind(this)).catch(this._postLoaded.reject);
186
+ }
187
+ if (process.env.NODE_ENV !== "production") {
188
+ ProxyClass._hmrInstances ?? (ProxyClass._hmrInstances = []);
189
+ ProxyClass._hmrInstances.push(new WeakRef(this));
190
+ }
191
+ }
192
+ /** @internal */
193
+ static _initializePrototype() {
194
+ this._properties?.forEach(this._bindProp, this);
195
+ this._asyncMethods?.forEach(this._bindAsync, this);
196
+ this._syncMethods?.forEach(this._bindSync, this);
197
+ }
198
+ static _bindProp(propName) {
199
+ Object.defineProperty(this.prototype, propName, {
200
+ configurable: true,
201
+ enumerable: true,
202
+ get() {
203
+ return this._store[propName];
204
+ },
205
+ set(value) {
206
+ this._store[propName] = value;
207
+ if (process.env.NODE_ENV !== "production") {
208
+ this._hmrSetProps.add(propName);
209
+ }
210
+ }
211
+ });
212
+ }
213
+ static _bindAsync(methodName) {
214
+ Object.defineProperty(this.prototype, methodName, {
215
+ async value(...args) {
216
+ if (!this._litElement) {
217
+ await this._postLoaded.promise;
218
+ }
219
+ const genericLitElement = this._litElement;
220
+ return await genericLitElement[methodName](...args);
221
+ },
222
+ configurable: true,
223
+ writable: true,
224
+ enumerable: true
225
+ });
226
+ }
227
+ static _bindSync(methodName) {
228
+ Object.defineProperty(this.prototype, methodName, {
229
+ value(...args) {
230
+ if (process.env.NODE_ENV === "development" && !this._litElement) {
231
+ const ProxyClass = this.constructor;
232
+ throw new Error(
233
+ `Tried to call method ${methodName}() on <${ProxyClass._name}> component before it's fully loaded. Please do 'await component.componentOnReady();' before calling this method.`
234
+ );
235
+ }
236
+ const genericLitElement = this._litElement;
237
+ return genericLitElement[methodName](...args);
238
+ },
239
+ configurable: true,
240
+ enumerable: true
241
+ });
242
+ }
243
+ get manager() {
244
+ return this._litElement?.manager;
245
+ }
246
+ /**
247
+ * Until the custom element is registered on the page, an instance of that
248
+ * element can be constructed and some properties on that instance set.
249
+ *
250
+ * These properties are set before the element prototype is set to this proxy
251
+ * class and thus none of our getters/setters are yet registered - such
252
+ * properties will be set by JavaScript on the instance directly.
253
+ *
254
+ * Once element is registered, the properties set in the meanwhile will shadow
255
+ * the getter/setters, and thus break reactivity. The fix is to delete these
256
+ * properties from the instance, and re-apply them once accessors are set.
257
+ *
258
+ * @example
259
+ * ```ts
260
+ * import { defineCustomElements } from '@arcgis/map-components';
261
+ * const map = document.createElement('arcgis-map');
262
+ * // This will shadow the getter/setters
263
+ * map.itemId = '...';
264
+ * // This finally defines the custom elements and sets the property accessors
265
+ * defineCustomElements();
266
+ * ```
267
+ *
268
+ * @remarks
269
+ * This is an equivalent of the __saveInstanceProperties method in Lit's
270
+ * ReactiveElement. Lit takes care of this on LitElement, but we have to take
271
+ * care of this on the lazy proxy
272
+ */
273
+ _saveInstanceProperties() {
274
+ const ProxyClass = this.constructor;
275
+ const genericThis = this;
276
+ ProxyClass._properties?.forEach((propName) => {
277
+ if (Object.hasOwn(this, propName)) {
278
+ this._store[propName] = genericThis[propName];
279
+ delete genericThis[propName];
280
+ }
281
+ });
282
+ }
283
+ /*
284
+ * This method must be statically present rather than added later, or else,
285
+ * browsers won't call it. Same for connected and disconnected callbacks.
286
+ */
287
+ attributeChangedCallback(name, oldValue, newValue) {
288
+ this._litElement?.attributeChangedCallback(name, oldValue, newValue);
289
+ if (!this._litElement) {
290
+ this._pendingAttributes.push(name);
291
+ }
292
+ if (process.env.NODE_ENV !== "production") {
293
+ this._hmrSetAttributes.add(name);
294
+ }
295
+ }
296
+ connectedCallback() {
297
+ if (this._litElement) {
298
+ this._litElement?.connectedCallback();
299
+ } else {
300
+ queueMicrotask(() => {
301
+ this._ancestorLoad ?? (this._ancestorLoad = attachToAncestor(this, this));
302
+ });
303
+ }
304
+ }
305
+ disconnectedCallback() {
306
+ this._litElement?.disconnectedCallback();
307
+ }
308
+ /**
309
+ * Create a promise that resolves once component is fully loaded
310
+ */
311
+ async componentOnReady() {
312
+ await this._postLoaded.promise;
313
+ return this._litElement;
314
+ }
315
+ /** @internal */
316
+ _initializeComponent(module) {
317
+ const ProxyClass = this.constructor;
318
+ const tagName = ProxyClass._name;
319
+ if (process.env.NODE_ENV !== "production") {
320
+ Object.entries(module).forEach(([name, LitConstructor2]) => {
321
+ if (name !== "exportsForTests" && typeof LitConstructor2 !== "function" || typeof LitConstructor2.tagName !== "string") {
322
+ console.warn(
323
+ `Found non-component export "${name}" in the file for the "${tagName}" component. This will interfere with hot module replacement. Please move "${name}" into a separate file.`
324
+ );
325
+ }
326
+ });
327
+ }
328
+ const LitConstructor = Object.values(module).find(
329
+ (LitConstructor2) => LitConstructor2.tagName === tagName
330
+ );
331
+ if (process.env.NODE_ENV !== "production" && !LitConstructor) {
332
+ throw new Error(
333
+ `Unable to find the LitElement class for the "${tagName}" custom element in the lazy-loaded module`
334
+ );
335
+ }
336
+ const lazyTagName = process.env.NODE_ENV === "production" ? `${tagName}--lazy` : (ProxyClass._hmrIndex ?? 0) === 0 ? `${tagName}--lazy` : `${tagName}--lazy-${ProxyClass._hmrIndex}`;
337
+ const isFirstInitialization = !ProxyClass._LitConstructor;
338
+ if (isFirstInitialization) {
339
+ ProxyClass._LitConstructor = LitConstructor;
340
+ LitConstructor.prototype.removeAttribute = removeAttribute;
341
+ LitConstructor.prototype.setAttribute = setAttribute;
342
+ if (process.env.NODE_ENV !== "production" && LitConstructor.shadowRootOptions !== noShadowRoot) {
343
+ devOnlyDetectIncorrectLazyUsages(Object.getPrototypeOf(LitConstructor));
344
+ }
345
+ customElements.define(lazyTagName, LitConstructor);
346
+ }
347
+ LitConstructor.lazy = this;
348
+ const litElement = document.createElement(lazyTagName);
349
+ LitConstructor.lazy = void 0;
350
+ this._litElement = litElement;
351
+ this._pendingAttributes.forEach((name) => {
352
+ const value = this.getAttribute(name);
353
+ litElement.attributeChangedCallback(
354
+ name,
355
+ // Lit doesn't look at this value, thus even if attribute already exists, that's ok
356
+ null,
357
+ value
358
+ );
359
+ });
360
+ Object.entries(this._store).forEach(syncLitElement, litElement);
361
+ this._store = litElement;
362
+ if (process.env.NODE_ENV !== "production") {
363
+ const litObserved = LitConstructor.observedAttributes ?? [];
364
+ const lazyObserved = ProxyClass.observedAttributes ?? [];
365
+ const missingFromLazy = litObserved.filter((attribute) => !lazyObserved.includes(attribute));
366
+ const missingFromLit = lazyObserved.filter((attribute) => !litObserved.includes(attribute));
367
+ if (missingFromLazy.length > 0) {
368
+ console.warn(
369
+ `The following attributes on <${ProxyClass._name}> are present on the Lit element, but are missing from the lazy proxy component: ${missingFromLazy.join(", ")}. This either indicates a bug in Lumina, or you are creating the attribute dynamically in a way that compiler can not infer statically. For these attributes, lazy-loading version of your component won't work correctly, thus this must be resolved`
370
+ );
371
+ }
372
+ if (missingFromLit.length > 0) {
373
+ console.warn(
374
+ `The following attributes on <${ProxyClass._name}> are defined on the lazy proxy component, but not on the actual Lit element: ${missingFromLit.join(", ")}. This either indicates a bug in Lumina, or you are creating the attribute dynamically in a way that compiler can not infer statically. This is a non-critical issue, but does indicate that something is going wrong and should be fixed`
375
+ );
376
+ }
377
+ }
378
+ if (this.isConnected) {
379
+ litElement.connectedCallback();
380
+ }
381
+ }
382
+ };
383
+ ProxyComponent.lumina = true;
384
+ function removeAttribute(qualifiedName) {
385
+ HTMLElement.prototype.removeAttribute.call(this.el, qualifiedName);
386
+ }
387
+ function setAttribute(qualifiedName, value) {
388
+ HTMLElement.prototype.setAttribute.call(this.el, qualifiedName, value);
389
+ }
390
+ function syncLitElement([key, value]) {
391
+ this[key] = value;
392
+ }
393
+
394
+ // src/hmrSupport.ts
395
+ import { camelToKebab as camelToKebab2 } from "@arcgis/components-utils";
396
+ function handleHmrUpdate(newModules) {
397
+ newModules.forEach((newModule) => {
398
+ if (newModule === void 0) {
399
+ return;
400
+ }
401
+ Object.values(newModule).forEach((exported) => {
402
+ if (typeof exported !== "function" || typeof exported.tagName !== "string") {
403
+ return;
404
+ }
405
+ const LitConstructor = exported;
406
+ const ProxyClass = customElements.get(LitConstructor.tagName);
407
+ if (ProxyClass === void 0) {
408
+ throw new Error(`Failed to find custom element proxy for tag name: ${LitConstructor.tagName}`);
409
+ }
410
+ ProxyClass._LitConstructor = void 0;
411
+ ProxyClass._loadPromise = void 0;
412
+ ProxyClass._hmrIndex ?? (ProxyClass._hmrIndex = 0);
413
+ ProxyClass._hmrIndex += 1;
414
+ ProxyClass._initializePrototype();
415
+ ProxyClass._hmrInstances?.forEach((instanceWeakRef) => {
416
+ const instance = instanceWeakRef.deref();
417
+ if (instance === void 0) {
418
+ return;
419
+ }
420
+ if (instance._litElement === void 0) {
421
+ void ProxyClass._loadPromise.then(() => reInitialize(instance, newModule));
422
+ } else {
423
+ reInitialize(instance, newModule);
424
+ }
425
+ });
426
+ return;
427
+ });
428
+ });
429
+ }
430
+ function reInitialize(instance, newModule) {
431
+ const PreviousLitConstructor = instance._litElement.constructor;
432
+ const properties = PreviousLitConstructor.elementProperties;
433
+ const preservedProperties = Array.from(properties.entries()).filter(
434
+ ([propertyName, descriptor]) => typeof propertyName === "string" && (instance._hmrSetProps.has(propertyName) || typeof descriptor.attribute === "string" && instance._hmrSetAttributes.has(descriptor.attribute))
435
+ ).map(([key]) => [key, instance[key]]);
436
+ instance._store = Object.fromEntries(preservedProperties);
437
+ const isConnected = instance.isConnected;
438
+ if (isConnected) {
439
+ instance._litElement.disconnectedCallback();
440
+ }
441
+ instance._initializeComponent(newModule);
442
+ }
443
+ function handleComponentMetaUpdate(meta) {
444
+ var _a, _b, _c;
445
+ const ProxyClass = customElements.get(meta.tagName);
446
+ if (ProxyClass === void 0) {
447
+ return;
448
+ }
449
+ const attributes = meta.properties.map(([property2, attribute]) => attribute ?? camelToKebab2(property2)).filter(Boolean);
450
+ observedAttributes[_a = meta.tagName] ?? (observedAttributes[_a] = {});
451
+ (_b = observedAttributes[meta.tagName]).original ?? (_b.original = new Set(ProxyClass.observedAttributes));
452
+ const originallyObserved = observedAttributes[meta.tagName].original;
453
+ (_c = observedAttributes[meta.tagName]).manuallyObserved ?? (_c.manuallyObserved = new Set(
454
+ /**
455
+ * Never manually observe attributes that were in the original
456
+ * observedAttributes as those would be observed by the browser
457
+ */
458
+ attributes.filter((attribute) => !originallyObserved.has(attribute))
459
+ ));
460
+ ProxyClass._asyncMethods = meta.asyncMethods;
461
+ ProxyClass._syncMethods = meta.syncMethods;
462
+ ProxyClass._properties = meta.properties.map(([name]) => name);
463
+ ProxyClass.observedAttributes = attributes;
464
+ }
465
+ var observedAttributesSymbol = Symbol.for("@arcgis/lumina:observedAttributes");
466
+ var globalThisWithObservedAttributes = globalThis;
467
+ var alreadyHadObservers = observedAttributesSymbol in globalThisWithObservedAttributes;
468
+ globalThisWithObservedAttributes[observedAttributesSymbol] ?? (globalThisWithObservedAttributes[observedAttributesSymbol] = {});
469
+ var observedAttributes = globalThisWithObservedAttributes[observedAttributesSymbol];
470
+ if (!alreadyHadObservers) {
471
+ const makeObserver = (original) => function observeAttributes(qualifiedName, ...rest) {
472
+ const observed = observedAttributes[this.tagName.toLowerCase()]?.manuallyObserved;
473
+ if (observed?.has(qualifiedName)) {
474
+ const oldValue = this.getAttribute(qualifiedName);
475
+ const returns = original.call(this, qualifiedName, ...rest);
476
+ const newValue = this.getAttribute(qualifiedName);
477
+ this.attributeChangedCallback(qualifiedName, oldValue, newValue);
478
+ return returns;
479
+ } else {
480
+ return original.call(this, qualifiedName, ...rest);
481
+ }
482
+ };
483
+ ProxyComponent.prototype.setAttribute = makeObserver(ProxyComponent.prototype.setAttribute);
484
+ ProxyComponent.prototype.toggleAttribute = makeObserver(ProxyComponent.prototype.toggleAttribute);
485
+ ProxyComponent.prototype.removeAttribute = makeObserver(ProxyComponent.prototype.removeAttribute);
486
+ }
487
+
488
+ // src/LitElement.ts
489
+ import { Deferred as Deferred2, camelToKebab as camelToKebab3 } from "@arcgis/components-utils";
490
+ import { LitElement as OriginalLitElement } from "lit";
491
+ import { useControllerManager } from "@arcgis/components-controllers";
492
+ var emptyFunction = () => void 0;
493
+ var _LitElement = class _LitElement extends OriginalLitElement {
494
+ constructor() {
495
+ super();
496
+ /**
497
+ * In lazy build, the actual DOM element differs from the class instance:
498
+ * - "this.el" is a proxy custom element - it's physically present in the DOM
499
+ * even before the Lit component is loaded.
500
+ * - "this" is the actual Lit component - in case of Lazy builds, it's
501
+ * never directly attached to the DOM. Instead, all interactions with the
502
+ * proxy are forwarded to the actual Lit component. And, when Lit wants to
503
+ * render, it renders into the shadow root of the proxy.
504
+ *
505
+ * "this.el" should be used instead of "this" for all things involving the
506
+ * DOM (addEventListener, querySelector, children, setAttribute,
507
+ * MutationObserver, etc...)
508
+ *
509
+ * @example
510
+ * ```ts
511
+ * // Generally, you shouldn't have to write logic specific to lazy or non-lazy
512
+ * // build, but if you have to, you can detect if you are in a lazy build like so:
513
+ * const isLazy = this.el !== this;
514
+ * ```
515
+ *
516
+ * @remarks
517
+ * Since we can't pass arguments to web component constructor, we are using
518
+ * a temporary static property instead
519
+ */
520
+ this.el = this.constructor.lazy ?? this;
521
+ /**
522
+ * Controller Manager orchestrates all components used by this component,
523
+ * connecting their lifecycle hooks and providing context information.
524
+ */
525
+ this.manager = useControllerManager(this);
526
+ /** @internal */
527
+ this._postLoad = this.constructor.lazy?._postLoad ?? new Deferred2();
528
+ /**
529
+ * Direct offspring that should be awaited before loaded() is emitted.
530
+ *
531
+ * `attachToAncestor()` will add elements to this array
532
+ *
533
+ * @internal
534
+ */
535
+ this._offspring = this.constructor.lazy?._offspring ?? [];
536
+ /**
537
+ * Promise that resolves once parent's load() completed. False if there is no
538
+ * parent
539
+ *
540
+ * @internal
541
+ */
542
+ this._ancestorLoad = this.constructor.lazy?._ancestorLoad;
543
+ this._postLoaded = this.constructor.lazy?._postLoaded ?? new Deferred2();
544
+ this._enableUpdating = this.enableUpdating;
545
+ this.enableUpdating = emptyFunction;
546
+ const ourShouldUpdate = _LitElement.prototype.shouldUpdate;
547
+ if (this.shouldUpdate !== ourShouldUpdate) {
548
+ this._originalShouldUpdate = this.shouldUpdate;
549
+ this.shouldUpdate = ourShouldUpdate;
550
+ }
551
+ if (process.env.NODE_ENV !== "production") {
552
+ globalThis.devOnly$luminaComponentRefCallback?.(this);
553
+ }
554
+ }
555
+ static finalizeStyles(styles) {
556
+ if (process.env.NODE_ENV === "test" && Array.isArray(styles)) {
557
+ styles = styles.filter(Boolean);
558
+ }
559
+ const finalizedStyles = super.finalizeStyles(styles);
560
+ const Class = this.constructor;
561
+ const options = Class.shadowRootOptions;
562
+ const useLightDom = options === noShadowRoot;
563
+ return this.runtime === void 0 || useLightDom ? finalizedStyles : [...this.runtime.commonStyles, ...finalizedStyles];
564
+ }
565
+ static createProperty(name, options) {
566
+ const flags = typeof options === "number" ? options : Array.isArray(options) ? options[0] : 0;
567
+ const rest = Array.isArray(options) ? options[1] : void 0;
568
+ super.createProperty(name, {
569
+ /**
570
+ * By default to infer attribute name from property name, Lit just
571
+ * converts property name to lowercase. That is consistent with
572
+ * native DOM attributes.
573
+ *
574
+ * However, that is not consistent with Stencil and would be a
575
+ * breaking change for us. Also, kebab-case is more common among the
576
+ * web components. But the most important reason is that we have
577
+ * some pretty long attribute names, which would be utterly
578
+ * unreadable in lowercase.
579
+ *
580
+ * Also, if browsers add new attributes, that may cause a conflict
581
+ * with our attributes.
582
+ *
583
+ * Thus, overwriting Lit's default behavior to use kebab-case:
584
+ */
585
+ attribute: !!(flags & 1 /* ATTRIBUTE */) && typeof name === "string" ? camelToKebab3(name) : false,
586
+ reflect: !!(flags & 2 /* REFLECT */),
587
+ type: flags & 4 /* BOOLEAN */ ? Boolean : flags & 8 /* NUMBER */ ? Number : void 0,
588
+ /**
589
+ * At the moment in Lit, state:true just means attribute:false, so this
590
+ * line is technically redundant, but let's keep it here just in case Lit
591
+ * will add more meaning to state:true in the future.
592
+ */
593
+ state: !!(flags & 16 /* STATE */),
594
+ // Controllers add this option to Lit
595
+ readOnly: !!(flags & 32 /* READ_ONLY */),
596
+ noAccessor: !!(flags & 64 /* NO_ACCESSOR */),
597
+ ...rest
598
+ });
599
+ }
600
+ connectedCallback() {
601
+ const isFirstCall = !this.manager.connectedCalled;
602
+ super.connectedCallback();
603
+ if (isFirstCall) {
604
+ queueMicrotask(() => void this._load().catch(this._postLoaded.reject));
605
+ }
606
+ }
607
+ /** Do asynchronous component load */
608
+ async _load() {
609
+ const parentLoadPromise = this._ancestorLoad ?? attachToAncestor(this, this);
610
+ if (parentLoadPromise) {
611
+ await parentLoadPromise;
612
+ }
613
+ await this.manager._load();
614
+ this._enableUpdating(true);
615
+ this.performUpdate();
616
+ this._postLoad.resolve();
617
+ const pendingChildren = this._offspring.filter((loaded) => !loaded.manager?.loadedCalled);
618
+ if (pendingChildren.length) {
619
+ await Promise.allSettled(pendingChildren.map(async (child) => await child.componentOnReady()));
620
+ }
621
+ this._offspring.length = 0;
622
+ const Class = this.constructor;
623
+ this.el.setAttribute(Class.runtime.hydratedAttribute, "");
624
+ this.manager._loaded();
625
+ this._postLoaded.resolve();
626
+ }
627
+ /**
628
+ * Overwrite Lit's default behavior of attaching shadow root to the lit
629
+ * element, and instead use this.el to support lazy builds.
630
+ *
631
+ * Also, support the case when component asked to not use shadow root
632
+ */
633
+ createRenderRoot() {
634
+ if (process.env.NODE_ENV !== "production" && this.el.shadowRoot !== null) {
635
+ return this.el.shadowRoot;
636
+ }
637
+ const Class = this.constructor;
638
+ const options = Class.shadowRootOptions;
639
+ const useLightDom = options === noShadowRoot;
640
+ const renderRoot = useLightDom ? this.el : this.el.attachShadow(options);
641
+ Object.defineProperty(this, "shadowRoot", {
642
+ // Create shadow root on the proxy instance, to make Lit render content there
643
+ value: renderRoot
644
+ });
645
+ const domRoot = renderRoot.getRootNode();
646
+ domRoot.adoptedStyleSheets = [
647
+ ...domRoot.adoptedStyleSheets,
648
+ ...Class.elementStyles.map((stylesheet) => "styleSheet" in stylesheet ? stylesheet.styleSheet : stylesheet)
649
+ ];
650
+ return renderRoot;
651
+ }
652
+ /**
653
+ * Overwriting default shouldUpdate simply to get access to
654
+ * "changedProperties" so that we can later provide it to ControllerManager
655
+ */
656
+ shouldUpdate(_changedProperties) {
657
+ this.$changes = _changedProperties;
658
+ return this._originalShouldUpdate?.(_changedProperties) ?? true;
659
+ }
660
+ listen(name, listener, options) {
661
+ const boundListener = listener?.bind(this) ?? listener;
662
+ this.manager.onLifecycle(() => {
663
+ this.el.addEventListener(name, boundListener, options);
664
+ return () => this.el.removeEventListener(name, boundListener, options);
665
+ });
666
+ }
667
+ listenOn(target, name, listener, options) {
668
+ const boundListener = listener?.bind(this) ?? listener;
669
+ this.manager.onLifecycle(() => {
670
+ target.addEventListener(name, boundListener, options);
671
+ return () => target.removeEventListener(name, boundListener, options);
672
+ });
673
+ }
674
+ /**
675
+ * Create a promise that resolves once component is fully loaded.
676
+ *
677
+ * @example
678
+ * const map = document.createElement('arcgis-map');
679
+ * document.body.append(map);
680
+ * map.componentOnReady().then(() => {
681
+ * console.log('Map is ready to go!');
682
+ * });
683
+ */
684
+ async componentOnReady() {
685
+ await this._postLoaded.promise;
686
+ return this;
687
+ }
688
+ };
689
+ _LitElement.lumina = true;
690
+ var LitElement = _LitElement;
691
+ LitElement.createEvent = createEventFactory;
692
+ if (process.env.NODE_ENV !== "production") {
693
+ const globalWithLit = globalThis;
694
+ globalWithLit.litIssuedWarnings ?? (globalWithLit.litIssuedWarnings = /* @__PURE__ */ new Set());
695
+ globalWithLit.litIssuedWarnings.add(
696
+ "Overriding ReactiveElement.createProperty() is deprecated. The override will not be called with standard decorators See https://lit.dev/msg/no-override-create-property for more information."
697
+ );
698
+ }
699
+
700
+ // src/PublicLitElement.ts
701
+ var PublicLitElement = class extends HTMLElement {
702
+ /**
703
+ * Create a promise that resolves once component is fully loaded.
704
+ *
705
+ * @example
706
+ * const map = document.createElement("arcgis-map");
707
+ * document.body.append(map);
708
+ * map.componentOnReady().then(() => {
709
+ * console.log("Map is ready to go!");
710
+ * });
711
+ */
712
+ async componentOnReady() {
713
+ await Promise.resolve();
714
+ return this;
715
+ }
716
+ };
717
+
718
+ // src/runtime.ts
719
+ import { unsafeCSS } from "lit";
720
+ function makeRuntime({
721
+ defaultAssetsUrl,
722
+ hydratedAttribute = "hydrated",
723
+ commonStyles,
724
+ globalStyles
725
+ }) {
726
+ const href = globalThis.location?.href;
727
+ let assetPath;
728
+ setAssetPath(defaultAssetsUrl);
729
+ function setAssetPath(path) {
730
+ assetPath = new URL(path, href).href;
731
+ }
732
+ function getAssetPath(suffix) {
733
+ const assetUrl = new URL(suffix, assetPath);
734
+ return assetUrl.origin !== globalThis.location?.origin ? assetUrl.href : assetUrl.pathname;
735
+ }
736
+ const hideUntilHydrated = unsafeCSS(`:host(:not([${hydratedAttribute}])){visibility:hidden}`);
737
+ if (globalStyles) {
738
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, globalStyles.styleSheet];
739
+ }
740
+ const runtime = {
741
+ defaultAssetsUrl,
742
+ getAssetPath,
743
+ setAssetPath,
744
+ hydratedAttribute,
745
+ commonStyles: [...commonStyles ? [commonStyles] : [], hideUntilHydrated],
746
+ globalStyles,
747
+ customElement(tagName, component) {
748
+ component.runtime = runtime;
749
+ component.tagName = tagName;
750
+ if (!customElements.get(tagName)) {
751
+ customElements.define(tagName, component);
752
+ }
753
+ }
754
+ };
755
+ if (process.env.NODE_ENV !== "production") {
756
+ globalThis.devOnly$luminaRuntime = runtime;
757
+ }
758
+ return runtime;
759
+ }
760
+
761
+ // src/jsx/jsx.ts
762
+ import { directive as litDirective } from "lit-html/directive.js";
763
+ import { noChange as litNoChange, nothing as litNothing } from "lit-html";
764
+ var bindAttribute = void 0;
765
+ var bindBooleanAttribute = void 0;
766
+ var bindProperty = void 0;
767
+ var bindEvent = void 0;
768
+ var nothing = litNothing;
769
+ var noChange = litNoChange;
770
+ var directive = litDirective;
771
+
772
+ // src/jsx/directives.ts
773
+ import { classMap } from "lit-html/directives/class-map.js";
774
+ import { styleMap } from "lit/directives/style-map.js";
775
+ var safeClassMap = (parameters) => typeof parameters === "object" && parameters != null ? classMap(parameters) : parameters;
776
+ var safeStyleMap = (parameters) => typeof parameters === "object" && parameters != null ? styleMap(parameters) : parameters;
777
+
778
+ // src/wrappersUtils.ts
779
+ function createPrototypeProxy(tagName) {
780
+ const customElement = {
781
+ name: tagName,
782
+ get prototype() {
783
+ const customElementPrototype = customElements.get(tagName)?.prototype;
784
+ if (!customElementPrototype) {
785
+ if (process.env.NODE_ENV === "production") {
786
+ throw new Error(`Custom element "${tagName}" not found`);
787
+ } else {
788
+ return Object.create(HTMLElement.prototype);
789
+ }
790
+ }
791
+ Object.defineProperty(customElement, "prototype", customElementPrototype);
792
+ return customElementPrototype;
793
+ }
794
+ };
795
+ return customElement;
796
+ }
797
+ export {
798
+ LitElement,
799
+ PublicLitElement,
800
+ bindAttribute,
801
+ bindBooleanAttribute,
802
+ bindEvent,
803
+ bindProperty,
804
+ createEvent,
805
+ createPrototypeProxy,
806
+ directive,
807
+ handleComponentMetaUpdate,
808
+ handleHmrUpdate,
809
+ makeDefineCustomElements,
810
+ makeRuntime,
811
+ method,
812
+ noChange,
813
+ noShadowRoot,
814
+ nothing,
815
+ property,
816
+ safeClassMap,
817
+ safeStyleMap,
818
+ state
819
+ };