@antone-io/render-picker 0.0.0-stage → 0.3.2

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.
@@ -0,0 +1,105 @@
1
+ "use client";
2
+ import {
3
+ NPM_MARKER_ATTR,
4
+ initClickToSource,
5
+ initComponentAnnotator,
6
+ initSettingsRefresh,
7
+ initTplAnnotator,
8
+ startCapture
9
+ } from "./chunk-2N6FOIM5.js";
10
+
11
+ // src/core/dev/console-hush.ts
12
+ var DEFAULT_HUSH_RULES = [
13
+ /Download the React DevTools/,
14
+ /^\[HMR\] connected$/,
15
+ /^\[Fast Refresh\]/
16
+ ];
17
+ var METHODS = ["log", "info", "debug"];
18
+ function hushConsoleNoise(rules = DEFAULT_HUSH_RULES) {
19
+ const originals = /* @__PURE__ */ new Map();
20
+ for (const name of METHODS) {
21
+ const original = console[name];
22
+ originals.set(name, original);
23
+ console[name] = (...args) => {
24
+ const first = args[0];
25
+ if (typeof first === "string" && rules.some((r) => r.test(first))) {
26
+ return;
27
+ }
28
+ original.apply(console, args);
29
+ };
30
+ }
31
+ return () => {
32
+ for (const [name, original] of originals) {
33
+ console[name] = original;
34
+ }
35
+ };
36
+ }
37
+
38
+ // src/client.ts
39
+ var DEFAULT_ANNOTATE_DELAY_MS = 2e3;
40
+ function defaultEnabled() {
41
+ try {
42
+ return process.env.NODE_ENV !== "production";
43
+ } catch {
44
+ return false;
45
+ }
46
+ }
47
+ function defaultProjectRoot() {
48
+ try {
49
+ if (process.env.NEXT_PUBLIC_PROJECT_ROOT) return process.env.NEXT_PUBLIC_PROJECT_ROOT;
50
+ } catch {
51
+ }
52
+ if (typeof document !== "undefined") {
53
+ const meta = document.querySelector('meta[name="render-picker-root"]');
54
+ return meta?.getAttribute("content") ?? void 0;
55
+ }
56
+ return void 0;
57
+ }
58
+ function initRenderPicker(options = {}) {
59
+ const {
60
+ enabled = defaultEnabled(),
61
+ projectRoot = defaultProjectRoot(),
62
+ source = "react",
63
+ clickToSource = true,
64
+ annotate: annotate2 = true,
65
+ hushConsole = true
66
+ } = options;
67
+ if (!enabled || typeof window === "undefined") return () => {
68
+ };
69
+ const cleanups = [];
70
+ document.documentElement.setAttribute(NPM_MARKER_ATTR, "npm");
71
+ cleanups.push(() => document.documentElement.removeAttribute(NPM_MARKER_ATTR));
72
+ cleanups.push(startCapture());
73
+ cleanups.push(initSettingsRefresh());
74
+ if (hushConsole) {
75
+ cleanups.push(
76
+ hushConsoleNoise(hushConsole === true ? DEFAULT_HUSH_RULES : hushConsole)
77
+ );
78
+ }
79
+ if (clickToSource) cleanups.push(initClickToSource(projectRoot));
80
+ if (annotate2) {
81
+ if (source === "prestashop") {
82
+ cleanups.push(initTplAnnotator());
83
+ } else {
84
+ const delayMs = typeof annotate2 === "object" && annotate2.delayMs !== void 0 ? annotate2.delayMs : DEFAULT_ANNOTATE_DELAY_MS;
85
+ let stopAnnotator = null;
86
+ const timer = setTimeout(() => {
87
+ stopAnnotator = initComponentAnnotator();
88
+ }, delayMs);
89
+ cleanups.push(() => {
90
+ clearTimeout(timer);
91
+ stopAnnotator?.();
92
+ });
93
+ }
94
+ }
95
+ return () => {
96
+ for (const cleanup of cleanups.reverse()) cleanup();
97
+ };
98
+ }
99
+
100
+ export {
101
+ DEFAULT_HUSH_RULES,
102
+ hushConsoleNoise,
103
+ initRenderPicker
104
+ };
105
+ //# sourceMappingURL=chunk-WUA7VWEU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/dev/console-hush.ts","../src/client.ts"],"sourcesContent":["/**\n * Masque les logs \"Download the React DevTools\" / \"[HMR] connected\" /\n * \"[Fast Refresh]\" en dev. Simple filtre de console.\n */\n\nexport const DEFAULT_HUSH_RULES: readonly RegExp[] = [\n /Download the React DevTools/,\n /^\\[HMR\\] connected$/,\n /^\\[Fast Refresh\\]/,\n];\n\ntype ConsoleMethod = \"log\" | \"info\" | \"debug\";\nconst METHODS: ConsoleMethod[] = [\"log\", \"info\", \"debug\"];\n\n/** Patch console.log/info/debug. Retourne une fonction qui restaure l'original. */\nexport function hushConsoleNoise(\n rules: readonly RegExp[] = DEFAULT_HUSH_RULES,\n): () => void {\n const originals = new Map<ConsoleMethod, (...args: unknown[]) => void>();\n for (const name of METHODS) {\n // eslint-disable-next-line no-console\n const original = console[name] as (...args: unknown[]) => void;\n originals.set(name, original);\n // eslint-disable-next-line no-console\n console[name] = (...args: unknown[]) => {\n const first = args[0];\n if (typeof first === \"string\" && rules.some((r) => r.test(first))) {\n return;\n }\n original.apply(console, args);\n };\n }\n return () => {\n for (const [name, original] of originals) {\n // eslint-disable-next-line no-console\n console[name] = original;\n }\n };\n}\n","import { startCapture } from \"./core/devpanel/capture\";\nimport { NPM_MARKER_ATTR } from \"./core/inspector/constants/behavior\";\nimport { initClickToSource } from \"./core/dev/click-to-source\";\nimport { initComponentAnnotator } from \"./core/source/component-annotate\";\nimport { initTplAnnotator } from \"./core/source/tpl-annotate\";\nimport { DEFAULT_HUSH_RULES, hushConsoleNoise } from \"./core/dev/console-hush\";\nimport { initSettingsRefresh } from \"./core/settings\";\n\nexport interface RenderPickerOptions {\n /** Active l'outillage. Défaut : `process.env.NODE_ENV !== \"production\"`. */\n enabled?: boolean;\n /**\n * Racine absolue du projet. Défaut : `process.env.NEXT_PUBLIC_PROJECT_ROOT`,\n * sinon le contenu de `<meta name=\"render-picker-root\">` (pages sans bundler,\n * ex. PrestaShop).\n */\n projectRoot?: string | null;\n /**\n * Source de la résolution `data-source` :\n * - `\"react\"` (défaut) : fibers React (`initComponentAnnotator`, sourcemaps) ;\n * - `\"prestashop\"` : commentaires Smarty `rp@file:line` (`initTplAnnotator`,\n * sans attente d'hydratation).\n */\n source?: \"react\" | \"prestashop\";\n /** Alt+clic → VS Code. Défaut : true. */\n clickToSource?: boolean;\n /**\n * Annotation `data-component` / `data-source`. Défaut : true, après 2000 ms —\n * injecter des attributs avant la fin de l'hydratation provoque\n * \"tree hydrated but some attributes didn't match\". Ignoré si `source: \"prestashop\"`\n * (annotation immédiate, pas d'hydratation React).\n */\n annotate?: boolean | { delayMs?: number };\n /** Filtre console dev. `true` = règles par défaut, ou liste de RegExp. Défaut : true. */\n hushConsole?: boolean | readonly RegExp[];\n}\n\nconst DEFAULT_ANNOTATE_DELAY_MS = 2000;\n\n// Accès littéraux : Next/webpack/Turbopack remplacent `process.env.X` à la build,\n// y compris dans node_modules. Le try couvre les runtimes sans `process`.\nfunction defaultEnabled(): boolean {\n try {\n return process.env.NODE_ENV !== \"production\";\n } catch {\n return false;\n }\n}\n\nfunction defaultProjectRoot(): string | undefined {\n try {\n if (process.env.NEXT_PUBLIC_PROJECT_ROOT) return process.env.NEXT_PUBLIC_PROJECT_ROOT;\n } catch {\n // pas de `process` (navigateur sans bundler) → repli sur le <meta>\n }\n if (typeof document !== \"undefined\") {\n const meta = document.querySelector('meta[name=\"render-picker-root\"]');\n return meta?.getAttribute(\"content\") ?? undefined;\n }\n return undefined;\n}\n\n/**\n * Point d'entrée à appeler dans `instrumentation-client.ts`.\n * Retourne une fonction qui démonte tout (listeners, observer, console).\n */\nexport function initRenderPicker(options: RenderPickerOptions = {}): () => void {\n const {\n enabled = defaultEnabled(),\n projectRoot = defaultProjectRoot(),\n source = \"react\",\n clickToSource = true,\n annotate = true,\n hushConsole = true,\n } = options;\n\n if (!enabled || typeof window === \"undefined\") return () => {};\n\n const cleanups: (() => void)[] = [];\n\n // Marqueur lu par l'extension Chrome pour se désactiver (évite le double picker).\n document.documentElement.setAttribute(NPM_MARKER_ATTR, \"npm\");\n cleanups.push(() => document.documentElement.removeAttribute(NPM_MARKER_ATTR));\n\n // Capture console + network pour le panneau d'inspection.\n cleanups.push(startCapture());\n\n // Config.json relu sur le disque (route dev) au focus — remap à chaud.\n cleanups.push(initSettingsRefresh());\n\n if (hushConsole) {\n cleanups.push(\n hushConsoleNoise(hushConsole === true ? DEFAULT_HUSH_RULES : hushConsole),\n );\n }\n\n // Enregistré immédiatement (avant tout effet React) pour être premier en\n // capture. Lit data-source au moment du clic → pas besoin d'attendre l'annotation.\n if (clickToSource) cleanups.push(initClickToSource(projectRoot));\n\n if (annotate) {\n if (source === \"prestashop\") {\n // Commentaires Smarty déjà dans le HTML serveur → annotation immédiate,\n // pas d'hydratation React à attendre.\n cleanups.push(initTplAnnotator());\n } else {\n const delayMs =\n typeof annotate === \"object\" && annotate.delayMs !== undefined\n ? annotate.delayMs\n : DEFAULT_ANNOTATE_DELAY_MS;\n let stopAnnotator: (() => void) | null = null;\n const timer = setTimeout(() => {\n stopAnnotator = initComponentAnnotator();\n }, delayMs);\n cleanups.push(() => {\n clearTimeout(timer);\n stopAnnotator?.();\n });\n }\n }\n\n return () => {\n for (const cleanup of cleanups.reverse()) cleanup();\n };\n}\n\nexport { buildVscodeUri, initClickToSource } from \"./core/dev/click-to-source\";\nexport { buildEditorUri, EDITORS, type EditorId, type EditorInfo } from \"./core/dev/editors\";\nexport {\n pickResultFromElement,\n searchElements,\n toSelector,\n} from \"./core/search/element-search\";\nexport {\n annotate,\n annotateTree,\n componentInfo,\n initComponentAnnotator,\n type AnnotateResult,\n} from \"./core/source/component-annotate\";\nexport {\n annotateFromComments,\n initTplAnnotator,\n parseTplMarker,\n} from \"./core/source/tpl-annotate\";\nexport { DEFAULT_HUSH_RULES, hushConsoleNoise } from \"./core/dev/console-hush\";\nexport { enrichResult, findPickedElement } from \"./core/source/enrich\";\nexport { createInspector } from \"./core/inspector/inspector\";\nexport { ACCENT } from \"./core/inspector/constants/picker\";\nexport {\n PANEL_BORDER,\n SOLID_BG,\n TOOLTIP_SHADOW,\n} from \"./core/inspector/constants/theme\";\nexport { getCssSelector } from \"./core/inspector/css-selector\";\nexport { getXPath } from \"./core/inspector/xpath\";\nexport {\n normalizeSourcePath,\n resolvePosition,\n} from \"./core/source/source-map-resolver\";\nexport {\n DEFAULT_SETTINGS,\n fetchSettings,\n initSettingsRefresh,\n loadSettings,\n refreshSettings,\n saveSettings,\n settingsDelta,\n type RenderPickerSettings,\n} from \"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