sculpted 0.0.0 → 0.1.0

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.
Files changed (31) hide show
  1. package/LICENSE +105 -0
  2. package/README.md +233 -0
  3. package/dist/index.d.mts +129 -0
  4. package/dist/index.mjs +3 -0
  5. package/dist/patcher-BAw2kF1Q.mjs +2594 -0
  6. package/dist/protocol-BJm-xGHP.mjs +54 -0
  7. package/dist/runtime-DwE3PVhB.d.mts +64 -0
  8. package/dist/runtime.d.mts +2 -0
  9. package/dist/runtime.mjs +613 -0
  10. package/dist/sourceSyntax-DanNzS7Y.d.mts +103 -0
  11. package/dist/types-CdByW0ji.d.mts +381 -0
  12. package/dist/ui.d.mts +54 -0
  13. package/dist/ui.mjs +11125 -0
  14. package/dist/vite.d.mts +85 -0
  15. package/dist/vite.mjs +2325 -0
  16. package/examples/manual-vite-preact-pandacss/README.md +75 -0
  17. package/examples/manual-vite-preact-pandacss/index.html +12 -0
  18. package/examples/manual-vite-preact-pandacss/package.json +23 -0
  19. package/examples/manual-vite-preact-pandacss/panda.config.ts +43 -0
  20. package/examples/manual-vite-preact-pandacss/pnpm-lock.yaml +3359 -0
  21. package/examples/manual-vite-preact-pandacss/pnpm-workspace.yaml +2 -0
  22. package/examples/manual-vite-preact-pandacss/postcss.config.cjs +5 -0
  23. package/examples/manual-vite-preact-pandacss/src/TsrxManualPanel.tsrx +47 -0
  24. package/examples/manual-vite-preact-pandacss/src/index.css +8 -0
  25. package/examples/manual-vite-preact-pandacss/src/main.style.ts +33 -0
  26. package/examples/manual-vite-preact-pandacss/src/main.tsx +484 -0
  27. package/examples/manual-vite-preact-pandacss/src/tsrx.d.ts +5 -0
  28. package/examples/manual-vite-preact-pandacss/tsconfig.json +21 -0
  29. package/examples/manual-vite-preact-pandacss/vite.config.ts +20 -0
  30. package/package.json +66 -8
  31. package/readme.md +0 -1
@@ -0,0 +1,613 @@
1
+ import { _ as markerClassForEditId, g as editIdsFromMarkerClassList, r as DEFAULT_EDIT_ID_ATTRIBUTE } from "./protocol-BJm-xGHP.mjs";
2
+ //#region src/runtime.ts
3
+ const DEFAULT_GLOBAL_NAME = "__PANDA_INSPECTOR__";
4
+ const PREVIEW_STYLE_ID = "panda-inspector-preview-styles";
5
+ const HIGHLIGHT_ID = "panda-inspector-highlight";
6
+ var PandaRuntimeInspector = class {
7
+ version = 1;
8
+ manifestEndpoint;
9
+ editorMetadataEndpoint;
10
+ writebackEndpoint;
11
+ tokenWritebackEndpoint;
12
+ openSourceEndpoint;
13
+ styleModuleEndpoint;
14
+ #attributes;
15
+ #environment;
16
+ #manifest;
17
+ #editorMetadata;
18
+ #entries = /* @__PURE__ */ new Map();
19
+ #stopInspecting;
20
+ #forcedStateElement;
21
+ constructor(options = {}, environment = browserEnvironment()) {
22
+ this.manifestEndpoint = options.manifestEndpoint ?? "/@panda-inspector/manifest";
23
+ this.editorMetadataEndpoint = options.editorMetadataEndpoint ?? "/@panda-inspector/editor-metadata";
24
+ this.writebackEndpoint = options.writebackEndpoint ?? "/@panda-inspector/writeback";
25
+ this.tokenWritebackEndpoint = options.tokenWritebackEndpoint ?? "/@panda-inspector/token-writeback";
26
+ this.openSourceEndpoint = options.openSourceEndpoint ?? "/@panda-inspector/open-source";
27
+ this.styleModuleEndpoint = options.styleModuleEndpoint ?? "/@panda-inspector/style-module";
28
+ this.#attributes = {
29
+ editId: options.attributes?.editId ?? "data-panda-edit-id",
30
+ source: options.attributes?.source ?? "data-panda-source",
31
+ jsxSource: options.attributes?.jsxSource ?? "data-panda-jsx-source",
32
+ component: options.attributes?.component ?? "data-preact-component",
33
+ forcedState: options.attributes?.forcedState ?? "data-panda-forced-state"
34
+ };
35
+ this.#environment = environment;
36
+ }
37
+ async loadManifest() {
38
+ const response = await this.#environment.fetch(this.manifestEndpoint, { cache: "no-store" });
39
+ if (!response.ok) throw new Error(`Failed to load Panda inspector manifest: ${response.status}`);
40
+ const manifest = await response.json();
41
+ this.#manifest = manifest;
42
+ this.#entries = new Map(manifest.entries.map((entry) => [entry.id, entry]));
43
+ return manifest;
44
+ }
45
+ async getManifest() {
46
+ return this.#manifest ?? this.loadManifest();
47
+ }
48
+ async loadEditorMetadata() {
49
+ const response = await this.#environment.fetch(this.editorMetadataEndpoint, { cache: "no-store" });
50
+ if (!response.ok) throw new Error(`Failed to load Panda editor metadata: ${response.status}`);
51
+ const metadata = await response.json();
52
+ this.#editorMetadata = metadata;
53
+ return metadata;
54
+ }
55
+ async getEditorMetadata() {
56
+ return this.#editorMetadata ?? this.loadEditorMetadata();
57
+ }
58
+ getEntry(id) {
59
+ return this.#entries.get(id);
60
+ }
61
+ async requestStyleEdit(request, write) {
62
+ const result = await (await this.#environment.fetch(this.writebackEndpoint, {
63
+ method: "POST",
64
+ cache: "no-store",
65
+ headers: { "content-type": "application/json" },
66
+ body: JSON.stringify({
67
+ ...request,
68
+ options: {
69
+ ...request.options,
70
+ write
71
+ }
72
+ })
73
+ })).json();
74
+ if (result.ok && result.manifestUpdate) await this.loadManifest();
75
+ return result;
76
+ }
77
+ async requestStyleEditBatch(requests, write) {
78
+ const batch = {
79
+ kind: "panda-css-batch",
80
+ requests,
81
+ options: { write }
82
+ };
83
+ const result = await (await this.#environment.fetch(this.writebackEndpoint, {
84
+ method: "POST",
85
+ cache: "no-store",
86
+ headers: { "content-type": "application/json" },
87
+ body: JSON.stringify(batch)
88
+ })).json();
89
+ if (result.ok && result.manifestUpdate) await this.loadManifest();
90
+ return result.responses;
91
+ }
92
+ async requestInlineCssSource(request, write) {
93
+ const result = await (await this.#environment.fetch(this.writebackEndpoint, {
94
+ method: "POST",
95
+ cache: "no-store",
96
+ headers: { "content-type": "application/json" },
97
+ body: JSON.stringify({
98
+ ...request,
99
+ options: {
100
+ ...request.options,
101
+ write
102
+ }
103
+ })
104
+ })).json();
105
+ if (result.ok && result.manifestUpdate) await this.loadManifest();
106
+ return result;
107
+ }
108
+ async getComponentStyleModule(componentSource) {
109
+ return await (await this.#environment.fetch(this.styleModuleEndpoint, {
110
+ method: "POST",
111
+ cache: "no-store",
112
+ headers: { "content-type": "application/json" },
113
+ body: JSON.stringify({ componentSource })
114
+ })).json();
115
+ }
116
+ async requestStyleModuleEdit(request, write) {
117
+ const result = await (await this.#environment.fetch(this.writebackEndpoint, {
118
+ method: "POST",
119
+ cache: "no-store",
120
+ headers: { "content-type": "application/json" },
121
+ body: JSON.stringify({
122
+ ...request,
123
+ options: {
124
+ ...request.options,
125
+ write
126
+ }
127
+ })
128
+ })).json();
129
+ if (result.ok && result.manifestUpdate) await this.loadManifest();
130
+ return result;
131
+ }
132
+ async requestTokenConfigEdit(request, write) {
133
+ const result = await (await this.#environment.fetch(this.tokenWritebackEndpoint, {
134
+ method: "POST",
135
+ cache: "no-store",
136
+ headers: { "content-type": "application/json" },
137
+ body: JSON.stringify({
138
+ ...request,
139
+ options: {
140
+ ...request.options,
141
+ write
142
+ }
143
+ })
144
+ })).json();
145
+ if (result.ok && result.metadataUpdate) await this.loadEditorMetadata();
146
+ return result;
147
+ }
148
+ async openSourceLocation(request) {
149
+ const result = await (await this.#environment.fetch(this.openSourceEndpoint, {
150
+ method: "POST",
151
+ cache: "no-store",
152
+ headers: { "content-type": "application/json" },
153
+ body: JSON.stringify(request)
154
+ })).json();
155
+ if (!result.ok) return result;
156
+ try {
157
+ const editorResponse = await this.#environment.fetch(result.openEditorUrl, { cache: "no-store" });
158
+ if (editorResponse.ok) return result;
159
+ return {
160
+ ok: false,
161
+ error: {
162
+ code: "open-failed",
163
+ message: `Vite editor opener returned ${editorResponse.status}.`,
164
+ details: { file: result.file }
165
+ }
166
+ };
167
+ } catch (error) {
168
+ return {
169
+ ok: false,
170
+ error: {
171
+ code: "open-failed",
172
+ message: error instanceof Error ? error.message : String(error),
173
+ details: { file: result.file }
174
+ }
175
+ };
176
+ }
177
+ }
178
+ async selectElement(element) {
179
+ await this.getManifest();
180
+ const markerEditIds = editIdsFromMarkerClassList(element.getAttribute("class") ?? "");
181
+ const attributeEditIds = (element.getAttribute(this.#attributes.editId) ?? "").split(/\s+/).filter(Boolean);
182
+ const jsxSource = element.getAttribute(this.#attributes.jsxSource)?.trim() || void 0;
183
+ const jsxSourceEditIds = markerEditIds.length === 0 && attributeEditIds.length === 0 && jsxSource ? this.#entriesForJsxSource(jsxSource).map((entry) => entry.id) : [];
184
+ const targetIds = markerEditIds.length > 0 ? markerEditIds : attributeEditIds.length > 0 ? attributeEditIds : jsxSourceEditIds;
185
+ const editId = targetIds.join(" ") || void 0;
186
+ const source = element.getAttribute(this.#attributes.source) ?? void 0;
187
+ const component = element.getAttribute(this.#attributes.component) ?? void 0;
188
+ const evidence = this.#elementEvidence(element);
189
+ if (!editId) return {
190
+ state: "no-panda-metadata",
191
+ source,
192
+ component,
193
+ targets: [],
194
+ editableTargets: [],
195
+ readonlyTargets: [],
196
+ missingTargetIds: [],
197
+ evidence,
198
+ message: "Selected element does not include Panda inspector metadata."
199
+ };
200
+ const targets = [];
201
+ const missingTargetIds = [];
202
+ for (const targetId of targetIds) {
203
+ const target = this.#entries.get(targetId);
204
+ if (target) targets.push(target);
205
+ else missingTargetIds.push(targetId);
206
+ }
207
+ const editableTargets = targets.filter(isEditableTarget);
208
+ const readonlyTargets = targets.filter((target) => !isEditableTarget(target));
209
+ const targetGroups = {
210
+ editableTargets,
211
+ readonlyTargets,
212
+ missingTargetIds
213
+ };
214
+ if (editableTargets.length > 0 && (readonlyTargets.length > 0 || missingTargetIds.length > 0)) return {
215
+ state: "mixed-targets",
216
+ editId,
217
+ source,
218
+ component,
219
+ targets,
220
+ ...targetGroups,
221
+ evidence,
222
+ message: "Selected element includes editable and read-only Panda source targets."
223
+ };
224
+ if (editableTargets.length > 1) return {
225
+ state: "multiple-supported-targets",
226
+ editId,
227
+ source,
228
+ component,
229
+ targets,
230
+ ...targetGroups,
231
+ evidence,
232
+ message: "Selected element maps to multiple editable Panda css() objects."
233
+ };
234
+ if (editableTargets[0]) return {
235
+ state: "single-supported-target",
236
+ editId,
237
+ source,
238
+ component,
239
+ targets,
240
+ ...targetGroups,
241
+ evidence
242
+ };
243
+ if (missingTargetIds.length > 0) return {
244
+ state: "stale-target",
245
+ editId,
246
+ source,
247
+ component,
248
+ targets,
249
+ ...targetGroups,
250
+ evidence,
251
+ message: "Selected element metadata no longer exists in the current manifest."
252
+ };
253
+ const target = readonlyTargets[0];
254
+ return {
255
+ state: targetIds.length > 1 ? "multiple-targets" : "unsupported-target",
256
+ editId,
257
+ source,
258
+ component,
259
+ targets,
260
+ ...targetGroups,
261
+ evidence,
262
+ message: target?.reason ?? "Selected Panda source target is not editable."
263
+ };
264
+ }
265
+ startInspecting(onSelect, onStop) {
266
+ this.stopInspecting();
267
+ const { window } = this.#environment;
268
+ const onPointerMove = (event) => {
269
+ const element = this.inspectableElementFromPoint(event.clientX, event.clientY);
270
+ if (!element) {
271
+ this.#clearHighlight();
272
+ return;
273
+ }
274
+ this.highlightElement(element);
275
+ };
276
+ const onClick = (event) => {
277
+ const element = this.inspectableElementFromPoint(event.clientX, event.clientY);
278
+ if (!element) return;
279
+ event.preventDefault();
280
+ event.stopPropagation();
281
+ this.stopInspecting();
282
+ this.selectElement(element).then((info) => {
283
+ onSelect?.(info, element);
284
+ });
285
+ };
286
+ const onKeyDown = (event) => {
287
+ if (event.key === "Escape") {
288
+ event.preventDefault();
289
+ event.stopPropagation();
290
+ this.stopInspecting();
291
+ }
292
+ };
293
+ window.addEventListener("pointermove", onPointerMove, true);
294
+ window.addEventListener("click", onClick, true);
295
+ window.addEventListener("keydown", onKeyDown, true);
296
+ this.#stopInspecting = () => {
297
+ window.removeEventListener("pointermove", onPointerMove, true);
298
+ window.removeEventListener("click", onClick, true);
299
+ window.removeEventListener("keydown", onKeyDown, true);
300
+ this.#clearHighlight();
301
+ this.#stopInspecting = void 0;
302
+ onStop?.();
303
+ };
304
+ return this.#stopInspecting;
305
+ }
306
+ stopInspecting() {
307
+ this.#stopInspecting?.();
308
+ }
309
+ highlightElement(element) {
310
+ this.highlightElements([element]);
311
+ }
312
+ highlightElements(elements) {
313
+ this.#highlightElements(elements);
314
+ }
315
+ highlightSourceTarget(editId) {
316
+ this.highlightElements(this.sourceTargetElements(editId));
317
+ }
318
+ sourceTargetElements(editId) {
319
+ const markerClass = markerClassForEditId(editId);
320
+ const entry = this.#entries.get(editId);
321
+ const selector = [
322
+ `.${markerClass}`,
323
+ `[${this.#attributes.editId}~=${cssStringLiteral(editId)}]`,
324
+ entry?.jsxSource ? `[${this.#attributes.jsxSource}=${cssStringLiteral(entry.jsxSource)}]` : void 0,
325
+ ...(entry?.jsxSourceAliases ?? []).map((source) => `[${this.#attributes.jsxSource}=${cssStringLiteral(source)}]`)
326
+ ].filter((item) => item !== void 0).join(", ");
327
+ return Array.from(this.#environment.document.querySelectorAll(selector)).filter((element) => !isInspectorOwnedElement(element));
328
+ }
329
+ clearHighlight() {
330
+ this.#clearHighlight();
331
+ }
332
+ applyForcedStates(element, states) {
333
+ this.clearForcedStates();
334
+ if (!element || states.length === 0) return;
335
+ element.setAttribute(this.#attributes.forcedState, states.join(" "));
336
+ this.#forcedStateElement = element;
337
+ }
338
+ clearForcedStates() {
339
+ this.#forcedStateElement?.removeAttribute(this.#attributes.forcedState);
340
+ this.#forcedStateElement = void 0;
341
+ }
342
+ metadataBackedElementFromPoint(x, y) {
343
+ const element = this.#environment.document.elementFromPoint(x, y);
344
+ if (!element || isInspectorOwnedElement(element)) return void 0;
345
+ return metadataBackedElement(element, this.#attributes);
346
+ }
347
+ inspectableElementFromPoint(x, y) {
348
+ const element = this.#environment.document.elementFromPoint(x, y);
349
+ return element && !isInspectorOwnedElement(element) ? element : void 0;
350
+ }
351
+ applyPreview(preview) {
352
+ const style = this.#previewStyleElement();
353
+ style.textContent = preview.rules.flatMap((rule) => {
354
+ const markerClass = markerClassForEditId(rule.editId);
355
+ const entry = this.#entries.get(rule.editId);
356
+ const blocks = [];
357
+ const declarationsByCondition = /* @__PURE__ */ new Map();
358
+ for (const declaration of rule.declarations) declarationsByCondition.set(declaration.condition, [...declarationsByCondition.get(declaration.condition) ?? [], declaration]);
359
+ for (const [condition, declarationsForCondition] of declarationsByCondition) {
360
+ const declarations = declarationsForCondition.map((declaration) => ` ${declaration.property}: ${declaration.value} !important;`).join("\n");
361
+ const selectors = [
362
+ `.${escapeCssClass(markerClass)}`,
363
+ `[${DEFAULT_EDIT_ID_ATTRIBUTE}~="${escapeCssAttribute(rule.editId)}"]`,
364
+ entry?.jsxSource ? `[${this.#attributes.jsxSource}="${escapeCssAttribute(entry.jsxSource)}"]` : void 0,
365
+ ...(entry?.jsxSourceAliases ?? []).map((source) => `[${this.#attributes.jsxSource}="${escapeCssAttribute(source)}"]`)
366
+ ].filter((selector) => selector !== void 0).flatMap((selector) => condition ? previewConditionSelectors(selector, condition, this.#attributes) : selector).join(", ");
367
+ blocks.push(`${selectors} {\n${declarations}\n}`);
368
+ }
369
+ return blocks;
370
+ }).join("\n\n");
371
+ this.#environment.document.head.append(style);
372
+ }
373
+ clearPreview() {
374
+ this.#environment.document.getElementById(PREVIEW_STYLE_ID)?.remove();
375
+ }
376
+ #elementEvidence(element) {
377
+ return {
378
+ computedStyles: computedStyleSnapshot(this.#environment.window, this.#environment.document, element),
379
+ propertyContext: propertyContextSnapshot(this.#environment.window, element),
380
+ attributes: attributeSnapshot(element),
381
+ bounds: boundsSnapshot(element),
382
+ ancestors: ancestorSnapshot(element),
383
+ componentLayers: componentLayerSnapshot(element, this.#attributes)
384
+ };
385
+ }
386
+ #previewStyleElement() {
387
+ const { document } = this.#environment;
388
+ const existing = document.getElementById(PREVIEW_STYLE_ID);
389
+ if (existing?.tagName === "STYLE") return existing;
390
+ const style = document.createElement("style");
391
+ style.id = PREVIEW_STYLE_ID;
392
+ style.setAttribute("data-panda-inspector-owned", "true");
393
+ document.head.append(style);
394
+ return style;
395
+ }
396
+ #entriesForJsxSource(jsxSource) {
397
+ return Array.from(this.#entries.values()).filter((entry) => entry.jsxSource === jsxSource || (entry.jsxSourceAliases ?? []).includes(jsxSource));
398
+ }
399
+ #highlightElements(elements) {
400
+ const { document } = this.#environment;
401
+ if (elements.length === 0) {
402
+ this.#clearHighlight();
403
+ return;
404
+ }
405
+ const existing = document.getElementById(HIGHLIGHT_ID);
406
+ const highlight = existing ?? document.createElement("div");
407
+ highlight.id = HIGHLIGHT_ID;
408
+ highlight.setAttribute("data-panda-inspector-owned", "true");
409
+ highlight.setAttribute("style", [
410
+ "position: fixed",
411
+ "pointer-events: none",
412
+ "z-index: 2147483647",
413
+ "inset: 0"
414
+ ].join("; "));
415
+ highlight.textContent = "";
416
+ for (const element of elements) {
417
+ const bounds = element.getBoundingClientRect();
418
+ const outline = document.createElement("div");
419
+ outline.setAttribute("style", [
420
+ "position: fixed",
421
+ "pointer-events: none",
422
+ "border: 2px solid #1683d8",
423
+ "box-sizing: border-box",
424
+ `left: ${bounds.left}px`,
425
+ `top: ${bounds.top}px`,
426
+ `width: ${bounds.width}px`,
427
+ `height: ${bounds.height}px`
428
+ ].join("; "));
429
+ highlight.append(outline);
430
+ }
431
+ if (!existing) document.body.append(highlight);
432
+ }
433
+ #clearHighlight() {
434
+ this.#environment.document.getElementById(HIGHLIGHT_ID)?.remove();
435
+ }
436
+ };
437
+ function installPandaInspectorRuntime(options = {}) {
438
+ const environment = browserEnvironment();
439
+ const runtime = new PandaRuntimeInspector(options, environment);
440
+ const globalName = options.globalName ?? DEFAULT_GLOBAL_NAME;
441
+ environment.window[globalName] = runtime;
442
+ return runtime;
443
+ }
444
+ function browserEnvironment() {
445
+ if (typeof window === "undefined" || typeof document === "undefined") throw new Error("Panda inspector runtime requires a browser environment.");
446
+ return {
447
+ window,
448
+ document,
449
+ fetch: window.fetch.bind(window)
450
+ };
451
+ }
452
+ function computedStyleSnapshot(window, document, element) {
453
+ const style = window.getComputedStyle(element);
454
+ const defaultElement = document.createElement(element.tagName.toLowerCase());
455
+ defaultElement.setAttribute("data-panda-inspector-owned", "true");
456
+ document.body.append(defaultElement);
457
+ const defaultStyle = window.getComputedStyle(defaultElement);
458
+ const declarations = [];
459
+ try {
460
+ for (const property of style) {
461
+ const value = style.getPropertyValue(property);
462
+ if (value === defaultStyle.getPropertyValue(property)) continue;
463
+ declarations.push({
464
+ property,
465
+ value
466
+ });
467
+ }
468
+ } finally {
469
+ defaultElement.remove();
470
+ }
471
+ return declarations;
472
+ }
473
+ function propertyContextSnapshot(window, element) {
474
+ const style = window.getComputedStyle(element);
475
+ const parentStyle = element.parentElement ? window.getComputedStyle(element.parentElement) : void 0;
476
+ return {
477
+ tagName: element.tagName.toLowerCase(),
478
+ display: style.getPropertyValue("display") || "inline",
479
+ parentDisplay: parentStyle?.getPropertyValue("display") || void 0,
480
+ position: style.getPropertyValue("position") || "static",
481
+ overflow: style.getPropertyValue("overflow") || "visible",
482
+ overflowX: style.getPropertyValue("overflow-x") || "visible",
483
+ overflowY: style.getPropertyValue("overflow-y") || "visible",
484
+ whiteSpace: style.getPropertyValue("white-space") || "normal"
485
+ };
486
+ }
487
+ function attributeSnapshot(element) {
488
+ return Array.from(element.attributes, (attribute) => ({
489
+ name: attribute.name,
490
+ value: attribute.value
491
+ }));
492
+ }
493
+ function boundsSnapshot(element) {
494
+ const bounds = element.getBoundingClientRect();
495
+ return {
496
+ x: bounds.x,
497
+ y: bounds.y,
498
+ width: bounds.width,
499
+ height: bounds.height
500
+ };
501
+ }
502
+ function ancestorSnapshot(element) {
503
+ const ancestors = [];
504
+ let current = element.parentElement;
505
+ while (current) {
506
+ ancestors.push(current.tagName.toLowerCase());
507
+ current = current.parentElement;
508
+ }
509
+ return ancestors;
510
+ }
511
+ function componentLayerSnapshot(element, attributes) {
512
+ const layers = [];
513
+ const pendingElements = [];
514
+ let current = element;
515
+ let activeComponent;
516
+ let depth = 0;
517
+ while (current && depth < 24) {
518
+ const ownComponent = current.getAttribute(attributes.component)?.trim() || void 0;
519
+ const snapshot = componentLayerElementSnapshot(current, element, attributes);
520
+ if (!ownComponent && !activeComponent) {
521
+ pendingElements.push(snapshot);
522
+ current = current.parentElement;
523
+ depth += 1;
524
+ continue;
525
+ }
526
+ const component = ownComponent || activeComponent;
527
+ if (component !== activeComponent) {
528
+ layers.push({
529
+ component,
530
+ elements: []
531
+ });
532
+ activeComponent = component;
533
+ layers[layers.length - 1]?.elements.push(...pendingElements);
534
+ pendingElements.length = 0;
535
+ }
536
+ layers[layers.length - 1]?.elements.push(snapshot);
537
+ current = current.parentElement;
538
+ depth += 1;
539
+ }
540
+ if (pendingElements.length > 0) layers.push({
541
+ component: "DOM",
542
+ elements: pendingElements
543
+ });
544
+ return layers.filter((layer) => layer.elements.length > 0);
545
+ }
546
+ function componentLayerElementSnapshot(current, inspectedElement, attributes) {
547
+ const tagName = current.tagName.toLowerCase();
548
+ return {
549
+ tagName,
550
+ source: current.getAttribute(attributes.jsxSource)?.trim() || void 0,
551
+ element: tagName === "html" || tagName === "body" ? void 0 : current,
552
+ inspected: current === inspectedElement
553
+ };
554
+ }
555
+ function metadataBackedElement(element, attributes) {
556
+ let current = element;
557
+ while (current) {
558
+ if (isInspectorOwnedElement(current)) return void 0;
559
+ if (hasPandaMetadata(current, attributes)) return current;
560
+ current = current.parentElement;
561
+ }
562
+ }
563
+ function hasPandaMetadata(element, attributes) {
564
+ if (editIdsFromMarkerClassList(element.getAttribute("class") ?? "").length > 0) return true;
565
+ return (element.getAttribute(attributes.editId) ?? "").split(/\s+/).filter(Boolean).length > 0;
566
+ }
567
+ function cssStringLiteral(value) {
568
+ return `"${value.replace(/["\\\n\r\f]/g, (character) => {
569
+ if (character === "\n") return "\\a ";
570
+ if (character === "\r") return "\\d ";
571
+ if (character === "\f") return "\\c ";
572
+ return `\\${character}`;
573
+ })}"`;
574
+ }
575
+ function isInspectorOwnedElement(element) {
576
+ let current = element;
577
+ while (current) {
578
+ if (current.getAttribute("data-panda-inspector-owned") === "true" || current.getAttribute("data-panda-inspector-panel") === "true") return true;
579
+ if (current.parentElement) {
580
+ current = current.parentElement;
581
+ continue;
582
+ }
583
+ if (typeof current.getRootNode !== "function") return false;
584
+ const root = current.getRootNode();
585
+ current = isShadowRoot(root) ? root.host : null;
586
+ }
587
+ return false;
588
+ }
589
+ function isShadowRoot(root) {
590
+ return typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot;
591
+ }
592
+ function isEditableTarget(target) {
593
+ return target.kind === "panda-css";
594
+ }
595
+ function escapeCssAttribute(value) {
596
+ return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
597
+ }
598
+ function escapeCssClass(value) {
599
+ return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
600
+ }
601
+ function previewConditionSelectors(selector, condition, attributes) {
602
+ const forcedSelector = `${selector}[${attributes.forcedState}~="${escapeCssAttribute(condition)}"]`;
603
+ const pseudoSelector = previewConditionPseudoSelector(condition);
604
+ return pseudoSelector ? [`${selector}${pseudoSelector}`, forcedSelector] : [forcedSelector];
605
+ }
606
+ function previewConditionPseudoSelector(condition) {
607
+ if (condition === "hover") return ":hover";
608
+ if (condition === "focus") return ":focus";
609
+ if (condition === "focus-visible") return ":focus-visible";
610
+ if (condition === "active") return ":active";
611
+ }
612
+ //#endregion
613
+ export { PandaRuntimeInspector, installPandaInspectorRuntime };