first commit

This commit is contained in:
2026-06-24 09:48:54 +02:00
commit 41e62ddcad
33739 changed files with 4266226 additions and 0 deletions
@@ -0,0 +1,20 @@
/** Style constants for the layer dropdown UI */
export declare const DROPDOWN_CONTAINER_STYLES: Record<string, string>;
export declare const DROPDOWN_ITEM_BASE_STYLES: Record<string, string>;
export declare const DROPDOWN_ITEM_ACTIVE_COLOR = "#526cff";
export declare const DROPDOWN_ITEM_ACTIVE_BG = "#DBEAFE";
export declare const DROPDOWN_ITEM_ACTIVE_FONT_WEIGHT = "600";
export declare const DROPDOWN_ITEM_HOVER_BG = "#f1f5f9";
export declare const DEPTH_INDENT_PX = 10;
/** SVG chevron shown when dropdown is collapsed (click to expand) */
export declare const CHEVRON_COLLAPSED = "<svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" style=\"vertical-align:middle;margin-left:4px\"><path d=\"M6 9l6 6 6-6\" stroke=\"currentColor\" stroke-width=\"2\" fill=\"none\"/></svg>";
/** SVG chevron shown when dropdown is expanded (click to collapse) */
export declare const CHEVRON_EXPANDED = "<svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" style=\"vertical-align:middle;margin-left:4px\"><path d=\"M18 15l-6-6-6 6\" stroke=\"currentColor\" stroke-width=\"2\" fill=\"none\"/></svg>";
export declare const CHEVRON_ATTR = "data-chevron";
export declare const BASE_PADDING_PX = 12;
export declare const LAYER_DROPDOWN_ATTR = "data-layer-dropdown";
/** Max instrumented ancestors to show above the selected element */
export declare const MAX_PARENT_DEPTH = 2;
/** Max instrumented depth levels to show below the selected element */
export declare const MAX_CHILD_DEPTH = 2;
//# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/injections/layer-dropdown/consts.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAEhD,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAa5D,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAQ5D,CAAC;AAEF,eAAO,MAAM,0BAA0B,YAAY,CAAC;AACpD,eAAO,MAAM,uBAAuB,YAAY,CAAC;AACjD,eAAO,MAAM,gCAAgC,QAAQ,CAAC;AAEtD,eAAO,MAAM,sBAAsB,YAAY,CAAC;AAEhD,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,qEAAqE;AACrE,eAAO,MAAM,iBAAiB,oMAAoL,CAAC;AACnN,sEAAsE;AACtE,eAAO,MAAM,gBAAgB,uMAAuL,CAAC;AAErN,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAE3C,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAEzD,oEAAoE;AACpE,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,uEAAuE;AACvE,eAAO,MAAM,eAAe,IAAI,CAAC"}
@@ -0,0 +1,41 @@
/** Style constants for the layer dropdown UI */
export const DROPDOWN_CONTAINER_STYLES = {
position: "absolute",
backgroundColor: "#ffffff",
border: "1px solid #e2e8f0",
borderRadius: "6px",
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
fontSize: "12px",
minWidth: "120px",
maxHeight: "200px",
overflowY: "auto",
zIndex: "10001",
padding: "4px 0",
pointerEvents: "auto",
};
export const DROPDOWN_ITEM_BASE_STYLES = {
padding: "4px 12px",
cursor: "pointer",
color: "#334155",
backgroundColor: "transparent",
whiteSpace: "nowrap",
lineHeight: "1.5",
fontWeight: "400",
};
export const DROPDOWN_ITEM_ACTIVE_COLOR = "#526cff";
export const DROPDOWN_ITEM_ACTIVE_BG = "#DBEAFE";
export const DROPDOWN_ITEM_ACTIVE_FONT_WEIGHT = "600";
export const DROPDOWN_ITEM_HOVER_BG = "#f1f5f9";
export const DEPTH_INDENT_PX = 10;
/** SVG chevron shown when dropdown is collapsed (click to expand) */
export const CHEVRON_COLLAPSED = `<svg width="12" height="12" viewBox="0 0 24 24" style="vertical-align:middle;margin-left:4px"><path d="M6 9l6 6 6-6" stroke="currentColor" stroke-width="2" fill="none"/></svg>`;
/** SVG chevron shown when dropdown is expanded (click to collapse) */
export const CHEVRON_EXPANDED = `<svg width="12" height="12" viewBox="0 0 24 24" style="vertical-align:middle;margin-left:4px"><path d="M18 15l-6-6-6 6" stroke="currentColor" stroke-width="2" fill="none"/></svg>`;
export const CHEVRON_ATTR = "data-chevron";
export const BASE_PADDING_PX = 12;
export const LAYER_DROPDOWN_ATTR = "data-layer-dropdown";
/** Max instrumented ancestors to show above the selected element */
export const MAX_PARENT_DEPTH = 2;
/** Max instrumented depth levels to show below the selected element */
export const MAX_CHILD_DEPTH = 2;
//# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../../src/injections/layer-dropdown/consts.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAEhD,MAAM,CAAC,MAAM,yBAAyB,GAA2B;IAC/D,QAAQ,EAAE,UAAU;IACpB,eAAe,EAAE,SAAS;IAC1B,MAAM,EAAE,mBAAmB;IAC3B,YAAY,EAAE,KAAK;IACnB,SAAS,EAAE,gCAAgC;IAC3C,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,OAAO;IACjB,SAAS,EAAE,OAAO;IAClB,SAAS,EAAE,MAAM;IACjB,MAAM,EAAE,OAAO;IACf,OAAO,EAAE,OAAO;IAChB,aAAa,EAAE,MAAM;CACtB,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAA2B;IAC/D,OAAO,EAAE,UAAU;IACnB,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,SAAS;IAChB,eAAe,EAAE,aAAa;IAC9B,UAAU,EAAE,QAAQ;IACpB,UAAU,EAAE,KAAK;IACjB,UAAU,EAAE,KAAK;CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,SAAS,CAAC;AACpD,MAAM,CAAC,MAAM,uBAAuB,GAAG,SAAS,CAAC;AACjD,MAAM,CAAC,MAAM,gCAAgC,GAAG,KAAK,CAAC;AAEtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,SAAS,CAAC;AAEhD,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAElC,qEAAqE;AACrE,MAAM,CAAC,MAAM,iBAAiB,GAAG,iLAAiL,CAAC;AACnN,sEAAsE;AACtE,MAAM,CAAC,MAAM,gBAAgB,GAAG,oLAAoL,CAAC;AAErN,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC;AAE3C,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAElC,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAEzD,oEAAoE;AACpE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,uEAAuE;AACvE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC"}
@@ -0,0 +1,4 @@
/** Controller that encapsulates layer-dropdown integration logic */
import type { LayerControllerConfig, LayerController } from "./types.js";
export declare function createLayerController(config: LayerControllerConfig): LayerController;
//# sourceMappingURL=controller.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/injections/layer-dropdown/controller.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAUpE,OAAO,KAAK,EAAa,qBAAqB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,eAAe,CAgGpF"}
@@ -0,0 +1,88 @@
/** Controller that encapsulates layer-dropdown integration logic */
import { getElementSelectorId } from "../utils.js";
import { buildLayerChain } from "./utils.js";
import { enhanceLabelWithChevron, showDropdown, closeDropdown, isDropdownOpen, } from "./dropdown-ui.js";
export function createLayerController(config) {
let layerPreviewOverlay = null;
let escapeHandler = null;
let dropdownSourceLayer = null;
const clearLayerPreview = () => {
if (layerPreviewOverlay && layerPreviewOverlay.parentNode) {
layerPreviewOverlay.remove();
}
layerPreviewOverlay = null;
};
const showLayerPreview = (layer) => {
clearLayerPreview();
if (getElementSelectorId(layer.element) === config.getSelectedElementId())
return;
layerPreviewOverlay = config.createPreviewOverlay(layer.element);
};
const selectLayer = (layer) => {
clearLayerPreview();
closeDropdown();
if (escapeHandler) {
document.removeEventListener("keydown", escapeHandler, true);
escapeHandler = null;
}
dropdownSourceLayer = null;
const firstOverlay = config.selectElement(layer.element);
attachToOverlay(firstOverlay, layer.element);
};
const restoreSelection = () => {
if (escapeHandler) {
document.removeEventListener("keydown", escapeHandler, true);
escapeHandler = null;
}
if (dropdownSourceLayer) {
selectLayer(dropdownSourceLayer);
dropdownSourceLayer = null;
}
};
const handleLabelClick = (e, label, element, layers, currentId) => {
e.stopPropagation();
e.preventDefault();
if (isDropdownOpen()) {
closeDropdown();
restoreSelection();
}
else {
dropdownSourceLayer = {
element,
tagName: element.tagName.toLowerCase(),
selectorId: currentId,
};
config.onDeselect();
escapeHandler = (ev) => {
if (ev.key === "Escape") {
ev.stopPropagation();
closeDropdown();
restoreSelection();
}
};
document.addEventListener("keydown", escapeHandler, true);
showDropdown(label, layers, element, { onSelect: selectLayer, onHover: showLayerPreview, onHoverEnd: clearLayerPreview });
}
};
const attachToOverlay = (overlay, element) => {
if (!overlay)
return;
const label = overlay.querySelector("div");
if (!label)
return;
const layers = buildLayerChain(element);
if (layers.length <= 1)
return;
const currentId = getElementSelectorId(element);
enhanceLabelWithChevron(label);
label.addEventListener("click", (e) => {
handleLabelClick(e, label, element, layers, currentId);
});
};
const cleanup = () => {
clearLayerPreview();
closeDropdown();
};
return { attachToOverlay, cleanup };
}
//# sourceMappingURL=controller.js.map
@@ -0,0 +1 @@
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../src/injections/layer-dropdown/controller.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAEpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE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AAmC,EACnC,OAAgB,EAChB,EAAE;QACF,IAAI,CAAC,OAAO;YAAE,OAAO;QAErB,MAAM,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC,KAAK,CAA0B,CAAC;QACpE,IAAI,CAAC,KAAK;YAAE,OAAO;QAEnB,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC;YAAE,OAAO;QAE/B,MAAM,SAAS,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAChD,uBAAuB,CAAC,KAAK,CAAC,CAAC;QAE/B,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAa,EAAE,EAAE;YAChD,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,iBAAiB,EAAE,CAAC;QACpB,aAAa,EAAE,CAAC;IAClB,CAAC,CAAC;IAEF,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC;AACtC,CAAC"}
@@ -0,0 +1,13 @@
/** Dropdown UI component for layer navigation */
import type { LayerInfo, DropdownCallbacks } from "./types.js";
/** Create the dropdown DOM element with layer items */
export declare function createDropdownElement(layers: LayerInfo[], currentElement: Element | null, callbacks: DropdownCallbacks): HTMLDivElement;
/** Add chevron indicator and pointer-events to the label */
export declare function enhanceLabelWithChevron(label: HTMLDivElement): void;
/** Show the dropdown below the label element */
export declare function showDropdown(label: HTMLDivElement, layers: LayerInfo[], currentElement: Element | null, callbacks: DropdownCallbacks): void;
/** Close the active dropdown and clean up listeners */
export declare function closeDropdown(): void;
/** Check if a dropdown is currently visible */
export declare function isDropdownOpen(): boolean;
//# sourceMappingURL=dropdown-ui.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"dropdown-ui.d.ts","sourceRoot":"","sources":["../../../src/injections/layer-dropdown/dropdown-ui.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAiBjD,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAgD/D,uDAAuD;AACvD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,SAAS,EAAE,EACnB,cAAc,EAAE,OAAO,GAAG,IAAI,EAC9B,SAAS,EAAE,iBAAiB,GAC3B,cAAc,CAYhB;AAED,4DAA4D;AAC5D,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAiBnE;AAkED,gDAAgD;AAChD,wBAAgB,YAAY,CAC1B,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,SAAS,EAAE,EACnB,cAAc,EAAE,OAAO,GAAG,IAAI,EAC9B,SAAS,EAAE,iBAAiB,GAC3B,IAAI,CAiCN;AAED,uDAAuD;AACvD,wBAAgB,aAAa,IAAI,IAAI,CA0BpC;AAED,+CAA+C;AAC/C,wBAAgB,cAAc,IAAI,OAAO,CAExC"}
@@ -0,0 +1,186 @@
/** Dropdown UI component for layer navigation */
import { DROPDOWN_CONTAINER_STYLES, DROPDOWN_ITEM_BASE_STYLES, DROPDOWN_ITEM_ACTIVE_COLOR, DROPDOWN_ITEM_ACTIVE_BG, DROPDOWN_ITEM_ACTIVE_FONT_WEIGHT, DROPDOWN_ITEM_HOVER_BG, DEPTH_INDENT_PX, BASE_PADDING_PX, CHEVRON_COLLAPSED, CHEVRON_EXPANDED, CHEVRON_ATTR, LAYER_DROPDOWN_ATTR, } from "./consts.js";
import { applyStyles, getLayerDisplayName } from "./utils.js";
import { PLUGIN_ELEMENT_ATTR } from "../utils.js";
let activeDropdown = null;
let activeLabel = null;
let outsideMousedownHandler = null;
let activeOnHoverEnd = null;
let activeKeydownHandler = null;
function createDropdownItem(layer, isActive, { onSelect, onHover, onHoverEnd }) {
const item = document.createElement("div");
item.textContent = getLayerDisplayName(layer);
applyStyles(item, DROPDOWN_ITEM_BASE_STYLES);
const depth = layer.depth ?? 0;
if (depth > 0) {
item.style.paddingLeft = `${BASE_PADDING_PX + depth * DEPTH_INDENT_PX}px`;
}
if (isActive) {
item.style.color = DROPDOWN_ITEM_ACTIVE_COLOR;
item.style.backgroundColor = DROPDOWN_ITEM_ACTIVE_BG;
item.style.fontWeight = DROPDOWN_ITEM_ACTIVE_FONT_WEIGHT;
}
item.addEventListener("mouseenter", () => {
if (!isActive)
item.style.backgroundColor = DROPDOWN_ITEM_HOVER_BG;
if (onHover)
onHover(layer);
});
item.addEventListener("mouseleave", () => {
if (!isActive)
item.style.backgroundColor = "transparent";
if (onHoverEnd)
onHoverEnd();
});
item.addEventListener("click", (e) => {
e.stopPropagation();
e.preventDefault();
onSelect(layer);
});
return item;
}
/** Create the dropdown DOM element with layer items */
export function createDropdownElement(layers, currentElement, callbacks) {
const container = document.createElement("div");
container.setAttribute(LAYER_DROPDOWN_ATTR, "true");
container.setAttribute(PLUGIN_ELEMENT_ATTR, "true");
applyStyles(container, DROPDOWN_CONTAINER_STYLES);
layers.forEach((layer) => {
const isActive = layer.element === currentElement;
container.appendChild(createDropdownItem(layer, isActive, callbacks));
});
return container;
}
/** Add chevron indicator and pointer-events to the label */
export function enhanceLabelWithChevron(label) {
if (label.querySelector(`[${CHEVRON_ATTR}]`))
return;
const chevron = document.createElement("span");
chevron.setAttribute(CHEVRON_ATTR, "true");
chevron.style.display = "inline-flex";
chevron.innerHTML = CHEVRON_COLLAPSED;
label.appendChild(chevron);
label.style.display = "inline-flex";
label.style.alignItems = "center";
label.style.cursor = "pointer";
label.style.userSelect = "none";
label.style.whiteSpace = "nowrap";
label.style.pointerEvents = "auto";
label.setAttribute(LAYER_DROPDOWN_ATTR, "true");
label.setAttribute(PLUGIN_ELEMENT_ATTR, "true");
}
function setupKeyboardNavigation(dropdown, layers, currentElement, { onSelect, onHover, onHoverEnd }) {
const items = Array.from(dropdown.children);
let focusedIndex = layers.findIndex((l) => l.element === currentElement);
const setFocusedItem = (index) => {
if (focusedIndex >= 0 && focusedIndex < items.length) {
const prev = items[focusedIndex];
if (prev.style.color !== DROPDOWN_ITEM_ACTIVE_COLOR) {
prev.style.backgroundColor = "transparent";
}
}
focusedIndex = index;
if (focusedIndex >= 0 && focusedIndex < items.length) {
const cur = items[focusedIndex];
if (cur.style.color !== DROPDOWN_ITEM_ACTIVE_COLOR) {
cur.style.backgroundColor = DROPDOWN_ITEM_HOVER_BG;
}
cur.scrollIntoView({ block: "nearest" });
if (onHover && focusedIndex >= 0 && focusedIndex < layers.length) {
onHover(layers[focusedIndex]);
}
}
};
activeKeydownHandler = (e) => {
if (e.key === "ArrowDown") {
e.preventDefault();
e.stopPropagation();
setFocusedItem(focusedIndex < items.length - 1 ? focusedIndex + 1 : 0);
}
else if (e.key === "ArrowUp") {
e.preventDefault();
e.stopPropagation();
setFocusedItem(focusedIndex > 0 ? focusedIndex - 1 : items.length - 1);
}
else if (e.key === "Enter" && focusedIndex >= 0 && focusedIndex < layers.length) {
e.preventDefault();
e.stopPropagation();
if (onHoverEnd)
onHoverEnd();
onSelect(layers[focusedIndex]);
closeDropdown();
}
};
document.addEventListener("keydown", activeKeydownHandler, true);
}
function setupOutsideClickHandler(dropdown, label) {
let skipFirst = true;
outsideMousedownHandler = (e) => {
if (skipFirst) {
skipFirst = false;
return;
}
const target = e.target;
if (!dropdown.contains(target) && target !== label) {
closeDropdown();
}
};
document.addEventListener("mousedown", outsideMousedownHandler, true);
}
/** Show the dropdown below the label element */
export function showDropdown(label, layers, currentElement, callbacks) {
closeDropdown();
const dropdown = createDropdownElement(layers, currentElement, {
...callbacks,
onSelect: (layer) => {
if (callbacks.onHoverEnd)
callbacks.onHoverEnd();
callbacks.onSelect(layer);
closeDropdown();
},
});
const overlay = label.parentElement;
if (!overlay)
return;
dropdown.style.top = `${label.offsetTop + label.offsetHeight + 2}px`;
dropdown.style.left = `${label.offsetLeft}px`;
overlay.appendChild(dropdown);
activeDropdown = dropdown;
activeLabel = label;
const chevronEl = label.querySelector(`[${CHEVRON_ATTR}]`);
if (chevronEl) {
chevronEl.innerHTML = CHEVRON_EXPANDED;
}
activeOnHoverEnd = callbacks.onHoverEnd ?? null;
setupKeyboardNavigation(dropdown, layers, currentElement, callbacks);
setupOutsideClickHandler(dropdown, label);
}
/** Close the active dropdown and clean up listeners */
export function closeDropdown() {
const chevronEl = activeLabel?.querySelector(`[${CHEVRON_ATTR}]`);
if (chevronEl) {
chevronEl.innerHTML = CHEVRON_COLLAPSED;
}
activeLabel = null;
if (activeOnHoverEnd) {
activeOnHoverEnd();
activeOnHoverEnd = null;
}
if (activeDropdown && activeDropdown.parentNode) {
activeDropdown.remove();
}
activeDropdown = null;
if (outsideMousedownHandler) {
document.removeEventListener("mousedown", outsideMousedownHandler, true);
outsideMousedownHandler = null;
}
if (activeKeydownHandler) {
document.removeEventListener("keydown", activeKeydownHandler, true);
activeKeydownHandler = null;
}
}
/** Check if a dropdown is currently visible */
export function isDropdownOpen() {
return activeDropdown !== null;
}
//# sourceMappingURL=dropdown-ui.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,26 @@
/** Shared types for the layer-dropdown module */
export interface LayerInfo {
element: Element;
tagName: string;
selectorId: string | null;
depth?: number;
}
export type OnLayerSelect = (layer: LayerInfo) => void;
export type OnLayerHover = (layer: LayerInfo) => void;
export type OnLayerHoverEnd = () => void;
export interface DropdownCallbacks {
onSelect: OnLayerSelect;
onHover?: OnLayerHover;
onHoverEnd?: OnLayerHoverEnd;
}
export interface LayerControllerConfig {
createPreviewOverlay: (element: Element) => HTMLDivElement;
getSelectedElementId: () => string | null;
selectElement: (element: Element) => HTMLDivElement | undefined;
onDeselect: () => void;
}
export interface LayerController {
attachToOverlay: (overlay: HTMLDivElement | undefined, element: Element) => void;
cleanup: () => void;
}
//# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/injections/layer-dropdown/types.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;AACvD,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;AACtD,MAAM,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC;AAEzC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,UAAU,CAAC,EAAE,eAAe,CAAC;CAC9B;AAED,MAAM,WAAW,qBAAqB;IACpC,oBAAoB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,cAAc,CAAC;IAC3D,oBAAoB,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC1C,aAAa,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,cAAc,GAAG,SAAS,CAAC;IAChE,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACjF,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB"}
@@ -0,0 +1,3 @@
/** Shared types for the layer-dropdown module */
export {};
//# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/injections/layer-dropdown/types.ts"],"names":[],"mappings":"AAAA,iDAAiD"}
@@ -0,0 +1,25 @@
/** DOM utilities for the layer-dropdown module */
import type { LayerInfo } from "./types.js";
/** Apply a style map to an element */
export declare function applyStyles(element: HTMLElement, styles: Record<string, string>): void;
/** Display name for a layer — just the real tag name */
export declare function getLayerDisplayName(layer: LayerInfo): string;
/**
* Collect instrumented descendants up to `maxDepth` instrumented nesting levels.
* Non-instrumented wrappers are walked through without counting toward depth.
* Results are in DOM order.
* When `startDepth` is provided, assigns `depth` to each item during collection.
*/
export declare function getInstrumentedDescendants(parent: Element, maxDepth: number, startDepth?: number): LayerInfo[];
/**
* Build the layer chain for the dropdown:
*
* Parents – up to MAX_PARENT_DEPTH instrumented ancestors, outer → inner.
* Siblings – instrumented children of the immediate parent, at the same depth.
* Current – the selected element (highlighted), with children expanded.
* Children – instrumented descendants within MAX_CHILD_DEPTH levels, DOM order.
*
* Each item carries a `depth` for visual indentation.
*/
export declare function buildLayerChain(selectedElement: Element): LayerInfo[];
//# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/injections/layer-dropdown/utils.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAKlD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,sCAAsC;AACtC,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAOtF;AAED,wDAAwD;AACxD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAE5D;AAYD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,GAClB,SAAS,EAAE,CA0Bb;AAkFD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,eAAe,EAAE,OAAO,GAAG,SAAS,EAAE,CAcrE"}
@@ -0,0 +1,143 @@
/** DOM utilities for the layer-dropdown module */
import { isInstrumentedElement, getElementSelectorId } from "../utils.js";
import { MAX_PARENT_DEPTH, MAX_CHILD_DEPTH } from "./consts.js";
/** Apply a style map to an element */
export function applyStyles(element, styles) {
for (const key of Object.keys(styles)) {
element.style.setProperty(key.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`), styles[key]);
}
}
/** Display name for a layer — just the real tag name */
export function getLayerDisplayName(layer) {
return layer.tagName;
}
function toLayerInfo(element, depth) {
const info = {
element,
tagName: element.tagName.toLowerCase(),
selectorId: getElementSelectorId(element),
};
if (depth !== undefined)
info.depth = depth;
return info;
}
/**
* Collect instrumented descendants up to `maxDepth` instrumented nesting levels.
* Non-instrumented wrappers are walked through without counting toward depth.
* Results are in DOM order.
* When `startDepth` is provided, assigns `depth` to each item during collection.
*/
export function getInstrumentedDescendants(parent, maxDepth, startDepth) {
const result = [];
function walk(el, instrDepth) {
if (instrDepth > maxDepth)
return;
for (let i = 0; i < el.children.length; i++) {
const child = el.children[i];
if (isInstrumentedElement(child)) {
const info = {
element: child,
tagName: child.tagName.toLowerCase(),
selectorId: getElementSelectorId(child),
};
if (startDepth !== undefined) {
info.depth = startDepth + instrDepth - 1;
}
result.push(info);
walk(child, instrDepth + 1);
}
else {
walk(child, instrDepth);
}
}
}
walk(parent, 1);
return result;
}
/** Collect instrumented ancestors from selected element up to MAX_PARENT_DEPTH (outermost first). */
function collectInstrumentedParents(selectedElement) {
const parents = [];
let current = selectedElement.parentElement;
while (current &&
current !== document.documentElement &&
current !== document.body &&
parents.length < MAX_PARENT_DEPTH) {
if (isInstrumentedElement(current)) {
parents.push(toLayerInfo(current));
}
current = current.parentElement;
}
parents.reverse();
return parents;
}
/** Add parents to chain with depth 0, 1, …; returns depth of selected (parents.length). */
function addParentsToChain(chain, parents) {
parents.forEach((p, i) => {
chain.push({ ...p, depth: i });
});
return parents.length;
}
/** Add selected element and its descendants at the given depth. */
function addSelfAndDescendantsToChain(chain, selectedElement, selfDepth) {
chain.push(toLayerInfo(selectedElement, selfDepth));
const descendants = getInstrumentedDescendants(selectedElement, MAX_CHILD_DEPTH, selfDepth + 1);
chain.push(...descendants);
}
/** Get the innermost instrumented parent's DOM element, or null if none. */
function getImmediateInstrParent(parents) {
return parents.at(-1)?.element ?? null;
}
/** Collect instrumented siblings of the selected element from its parent (DOM order). */
function collectSiblings(parent, selectedElement) {
const siblings = getInstrumentedDescendants(parent, 1);
if (!siblings.some((s) => s.element === selectedElement)) {
siblings.push(toLayerInfo(selectedElement));
}
return siblings;
}
/** Add siblings at selfDepth, expanding children only for the selected element. */
function appendSiblingsWithSelected(chain, siblings, selectedElement, selfDepth) {
const selectedSelectorId = getElementSelectorId(selectedElement);
const seen = new Set();
for (const sibling of siblings) {
if (sibling.element === selectedElement) {
addSelfAndDescendantsToChain(chain, selectedElement, selfDepth);
if (selectedSelectorId)
seen.add(selectedSelectorId);
}
else {
const id = sibling.selectorId;
if (id != null) {
if (id === selectedSelectorId || seen.has(id))
continue;
seen.add(id);
}
chain.push({ ...sibling, depth: selfDepth });
}
}
}
/**
* Build the layer chain for the dropdown:
*
* Parents – up to MAX_PARENT_DEPTH instrumented ancestors, outer → inner.
* Siblings – instrumented children of the immediate parent, at the same depth.
* Current – the selected element (highlighted), with children expanded.
* Children – instrumented descendants within MAX_CHILD_DEPTH levels, DOM order.
*
* Each item carries a `depth` for visual indentation.
*/
export function buildLayerChain(selectedElement) {
const parents = collectInstrumentedParents(selectedElement);
const chain = [];
const selfDepth = addParentsToChain(chain, parents);
const instrParent = getImmediateInstrParent(parents);
if (instrParent) {
const siblings = collectSiblings(instrParent, selectedElement);
appendSiblingsWithSelected(chain, siblings, selectedElement, selfDepth);
}
else {
addSelfAndDescendantsToChain(chain, selectedElement, selfDepth);
}
return chain;
}
//# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/injections/layer-dropdown/utils.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAElD,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM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