@githumbi/grabby 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 (66) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +22 -0
  3. package/README.md +262 -0
  4. package/builders.json +14 -0
  5. package/dist/angular/index.d.ts +279 -0
  6. package/dist/angular/index.js +5145 -0
  7. package/dist/angular/index.js.map +1 -0
  8. package/dist/babel-plugin/index.cjs +95 -0
  9. package/dist/babel-plugin/index.cjs.map +1 -0
  10. package/dist/babel-plugin/index.d.cts +28 -0
  11. package/dist/babel-plugin/index.d.ts +28 -0
  12. package/dist/babel-plugin/index.js +60 -0
  13. package/dist/babel-plugin/index.js.map +1 -0
  14. package/dist/builder/builders/application/index.js +141 -0
  15. package/dist/builder/builders/application/index.js.map +1 -0
  16. package/dist/builder/builders/application/schema.json +7 -0
  17. package/dist/builder/builders/dev-server/index.js +137 -0
  18. package/dist/builder/builders/dev-server/index.js.map +1 -0
  19. package/dist/builder/builders/dev-server/schema.json +26 -0
  20. package/dist/builder/index.js +2 -0
  21. package/dist/builder/index.js.map +1 -0
  22. package/dist/builder/package.json +1 -0
  23. package/dist/chunk-6CBIOKZV.cjs +45 -0
  24. package/dist/chunk-6CBIOKZV.cjs.map +1 -0
  25. package/dist/chunk-M3DOFJA7.js +45 -0
  26. package/dist/chunk-M3DOFJA7.js.map +1 -0
  27. package/dist/cli/index.js +406 -0
  28. package/dist/cli/index.js.map +1 -0
  29. package/dist/core/index.cjs +5081 -0
  30. package/dist/core/index.cjs.map +1 -0
  31. package/dist/core/index.d.cts +96 -0
  32. package/dist/core/index.d.ts +96 -0
  33. package/dist/core/index.js +5081 -0
  34. package/dist/core/index.js.map +1 -0
  35. package/dist/esbuild-plugin/index.cjs +134 -0
  36. package/dist/esbuild-plugin/index.cjs.map +1 -0
  37. package/dist/esbuild-plugin/index.d.cts +21 -0
  38. package/dist/esbuild-plugin/index.d.ts +21 -0
  39. package/dist/esbuild-plugin/index.js +96 -0
  40. package/dist/esbuild-plugin/index.js.map +1 -0
  41. package/dist/export/index.cjs +166 -0
  42. package/dist/export/index.cjs.map +1 -0
  43. package/dist/export/index.d.cts +86 -0
  44. package/dist/export/index.d.ts +86 -0
  45. package/dist/export/index.js +137 -0
  46. package/dist/export/index.js.map +1 -0
  47. package/dist/grabby.global.js +635 -0
  48. package/dist/live/index.cjs +30 -0
  49. package/dist/live/index.cjs.map +1 -0
  50. package/dist/live/index.d.cts +20 -0
  51. package/dist/live/index.d.ts +20 -0
  52. package/dist/live/index.js +30 -0
  53. package/dist/live/index.js.map +1 -0
  54. package/dist/loader.global.js +1 -0
  55. package/dist/plugin/index.cjs +229 -0
  56. package/dist/plugin/index.cjs.map +1 -0
  57. package/dist/plugin/index.d.cts +76 -0
  58. package/dist/plugin/index.d.ts +76 -0
  59. package/dist/plugin/index.js +186 -0
  60. package/dist/plugin/index.js.map +1 -0
  61. package/dist/react/index.d.ts +290 -0
  62. package/dist/react/index.js +5110 -0
  63. package/dist/react/index.js.map +1 -0
  64. package/dist/types-CMgpkvBz.d.cts +265 -0
  65. package/dist/types-CMgpkvBz.d.ts +265 -0
  66. package/package.json +191 -0
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/esbuild-plugin/index.ts
31
+ var esbuild_plugin_exports = {};
32
+ __export(esbuild_plugin_exports, {
33
+ grabbyEsbuildPlugin: () => grabbyEsbuildPlugin,
34
+ scanComponentSources: () => scanComponentSources
35
+ });
36
+ module.exports = __toCommonJS(esbuild_plugin_exports);
37
+
38
+ // src/esbuild-plugin/scan.ts
39
+ var import_typescript = __toESM(require("typescript"), 1);
40
+ var import_path = __toESM(require("path"), 1);
41
+ var import_fs = __toESM(require("fs"), 1);
42
+ function scanComponentSources(rootDir) {
43
+ const sourceMap = {};
44
+ const files = findTypeScriptFiles(rootDir);
45
+ for (const filePath of files) {
46
+ const content = import_fs.default.readFileSync(filePath, "utf8");
47
+ if (!content.includes("@Component")) continue;
48
+ const relativePath = import_path.default.relative(rootDir, filePath).replace(/\\/g, "/");
49
+ const components = extractComponents(content, filePath);
50
+ for (const comp of components) {
51
+ sourceMap[comp.name] = { file: relativePath, line: comp.line };
52
+ }
53
+ }
54
+ return sourceMap;
55
+ }
56
+ function extractComponents(code, filePath) {
57
+ const sourceFile = import_typescript.default.createSourceFile(
58
+ filePath,
59
+ code,
60
+ import_typescript.default.ScriptTarget.Latest,
61
+ true,
62
+ import_typescript.default.ScriptKind.TS
63
+ );
64
+ const results = [];
65
+ function visit(node) {
66
+ if (import_typescript.default.isClassDeclaration(node) && node.name) {
67
+ const decorators = import_typescript.default.getDecorators(node);
68
+ if (!decorators) return;
69
+ const hasComponent = decorators.some((d) => {
70
+ if (!import_typescript.default.isCallExpression(d.expression)) return false;
71
+ if (!import_typescript.default.isIdentifier(d.expression.expression)) return false;
72
+ return d.expression.expression.text === "Component";
73
+ });
74
+ if (hasComponent) {
75
+ const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
76
+ results.push({ name: node.name.text, line: line + 1 });
77
+ }
78
+ }
79
+ import_typescript.default.forEachChild(node, visit);
80
+ }
81
+ visit(sourceFile);
82
+ return results;
83
+ }
84
+ function findTypeScriptFiles(rootDir) {
85
+ const results = [];
86
+ const srcDir = import_path.default.join(rootDir, "src");
87
+ if (!import_fs.default.existsSync(srcDir)) return results;
88
+ walk(srcDir, results);
89
+ return results;
90
+ }
91
+ function walk(dir, results) {
92
+ let entries;
93
+ try {
94
+ entries = import_fs.default.readdirSync(dir, { withFileTypes: true });
95
+ } catch {
96
+ return;
97
+ }
98
+ for (const entry of entries) {
99
+ if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
100
+ const fullPath = import_path.default.join(dir, entry.name);
101
+ if (entry.isDirectory()) {
102
+ walk(fullPath, results);
103
+ } else if (entry.name.endsWith(".ts") && !entry.name.endsWith(".spec.ts") && !entry.name.endsWith(".d.ts")) {
104
+ results.push(fullPath);
105
+ }
106
+ }
107
+ }
108
+
109
+ // src/esbuild-plugin/plugin.ts
110
+ function grabbyEsbuildPlugin(options) {
111
+ return {
112
+ name: "grabby",
113
+ setup(build) {
114
+ if (options?.enabled === false) return;
115
+ const rootDir = options?.rootDir || process.cwd();
116
+ const sourceMap = scanComponentSources(rootDir);
117
+ if (Object.keys(sourceMap).length === 0) return;
118
+ const json = JSON.stringify(sourceMap);
119
+ const existingBanner = build.initialOptions.banner;
120
+ const bannerObj = typeof existingBanner === "object" ? existingBanner : {};
121
+ const existingJs = bannerObj.js || "";
122
+ build.initialOptions.banner = {
123
+ ...bannerObj,
124
+ js: `globalThis.__GRABBY_SOURCE_MAP__=${json};${existingJs}`
125
+ };
126
+ }
127
+ };
128
+ }
129
+ // Annotate the CommonJS export names for ESM import in node:
130
+ 0 && (module.exports = {
131
+ grabbyEsbuildPlugin,
132
+ scanComponentSources
133
+ });
134
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/esbuild-plugin/index.ts","../../src/esbuild-plugin/scan.ts","../../src/esbuild-plugin/plugin.ts"],"sourcesContent":["export { grabbyEsbuildPlugin } from './plugin';\nexport { scanComponentSources, type SourceMap, type ComponentSourceInfo } from './scan';\n","import ts from 'typescript';\nimport path from 'path';\nimport fs from 'fs';\n\nexport interface ComponentSourceInfo {\n file: string;\n line: number;\n}\n\nexport type SourceMap = Record<string, ComponentSourceInfo>;\n\n/**\n * Scans the project for `.component.ts` files and extracts component\n * class names with their source locations. Returns a map of\n * `{ ComponentName: { file, line } }`.\n */\nexport function scanComponentSources(rootDir: string): SourceMap {\n const sourceMap: SourceMap = {};\n const files = findTypeScriptFiles(rootDir);\n\n for (const filePath of files) {\n const content = fs.readFileSync(filePath, 'utf8');\n if (!content.includes('@Component')) continue;\n\n const relativePath = path.relative(rootDir, filePath).replace(/\\\\/g, '/');\n const components = extractComponents(content, filePath);\n\n for (const comp of components) {\n sourceMap[comp.name] = { file: relativePath, line: comp.line };\n }\n }\n\n return sourceMap;\n}\n\ninterface ComponentInfo {\n name: string;\n line: number;\n}\n\nfunction extractComponents(code: string, filePath: string): ComponentInfo[] {\n const sourceFile = ts.createSourceFile(\n filePath,\n code,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TS,\n );\n\n const results: ComponentInfo[] = [];\n\n function visit(node: ts.Node): void {\n if (ts.isClassDeclaration(node) && node.name) {\n const decorators = ts.getDecorators(node);\n if (!decorators) return;\n\n const hasComponent = decorators.some((d) => {\n if (!ts.isCallExpression(d.expression)) return false;\n if (!ts.isIdentifier(d.expression.expression)) return false;\n return d.expression.expression.text === 'Component';\n });\n\n if (hasComponent) {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n results.push({ name: node.name.text, line: line + 1 });\n }\n }\n\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return results;\n}\n\nfunction findTypeScriptFiles(rootDir: string): string[] {\n const results: string[] = [];\n const srcDir = path.join(rootDir, 'src');\n\n if (!fs.existsSync(srcDir)) return results;\n\n walk(srcDir, results);\n return results;\n}\n\nfunction walk(dir: string, results: string[]): void {\n let entries: fs.Dirent[];\n try {\n entries = fs.readdirSync(dir, { withFileTypes: true });\n } catch {\n return;\n }\n\n for (const entry of entries) {\n if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue;\n\n const fullPath = path.join(dir, entry.name);\n\n if (entry.isDirectory()) {\n walk(fullPath, results);\n } else if (entry.name.endsWith('.ts') && !entry.name.endsWith('.spec.ts') && !entry.name.endsWith('.d.ts')) {\n results.push(fullPath);\n }\n }\n}\n","import type { Plugin } from 'esbuild';\nimport { scanComponentSources } from './scan';\n\nexport function grabbyEsbuildPlugin(options?: {\n rootDir?: string;\n /** Set to false to disable the transform (e.g., in production). Default: true */\n enabled?: boolean;\n}): Plugin {\n return {\n name: 'grabby',\n setup(build) {\n if (options?.enabled === false) return;\n\n const rootDir = options?.rootDir || process.cwd();\n const sourceMap = scanComponentSources(rootDir);\n\n if (Object.keys(sourceMap).length === 0) return;\n\n // Inject the source map as a global variable via banner\n const json = JSON.stringify(sourceMap);\n const existingBanner = build.initialOptions.banner;\n const bannerObj = typeof existingBanner === 'object' ? existingBanner : {};\n const existingJs = bannerObj.js || '';\n build.initialOptions.banner = {\n ...bannerObj,\n js: `globalThis.__GRABBY_SOURCE_MAP__=${json};${existingJs}`,\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,wBAAe;AACf,kBAAiB;AACjB,gBAAe;AAcR,SAAS,qBAAqB,SAA4B;AAC/D,QAAM,YAAuB,C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,UAAU;AAAA,MAC5D;AAAA,IACF;AAAA,EACF;AACF;","names":["fs","path","ts"]}
@@ -0,0 +1,21 @@
1
+ import { Plugin } from 'esbuild';
2
+
3
+ declare function grabbyEsbuildPlugin(options?: {
4
+ rootDir?: string;
5
+ /** Set to false to disable the transform (e.g., in production). Default: true */
6
+ enabled?: boolean;
7
+ }): Plugin;
8
+
9
+ interface ComponentSourceInfo {
10
+ file: string;
11
+ line: number;
12
+ }
13
+ type SourceMap = Record<string, ComponentSourceInfo>;
14
+ /**
15
+ * Scans the project for `.component.ts` files and extracts component
16
+ * class names with their source locations. Returns a map of
17
+ * `{ ComponentName: { file, line } }`.
18
+ */
19
+ declare function scanComponentSources(rootDir: string): SourceMap;
20
+
21
+ export { type ComponentSourceInfo, type SourceMap, grabbyEsbuildPlugin, scanComponentSources };
@@ -0,0 +1,21 @@
1
+ import { Plugin } from 'esbuild';
2
+
3
+ declare function grabbyEsbuildPlugin(options?: {
4
+ rootDir?: string;
5
+ /** Set to false to disable the transform (e.g., in production). Default: true */
6
+ enabled?: boolean;
7
+ }): Plugin;
8
+
9
+ interface ComponentSourceInfo {
10
+ file: string;
11
+ line: number;
12
+ }
13
+ type SourceMap = Record<string, ComponentSourceInfo>;
14
+ /**
15
+ * Scans the project for `.component.ts` files and extracts component
16
+ * class names with their source locations. Returns a map of
17
+ * `{ ComponentName: { file, line } }`.
18
+ */
19
+ declare function scanComponentSources(rootDir: string): SourceMap;
20
+
21
+ export { type ComponentSourceInfo, type SourceMap, grabbyEsbuildPlugin, scanComponentSources };
@@ -0,0 +1,96 @@
1
+ // src/esbuild-plugin/scan.ts
2
+ import ts from "typescript";
3
+ import path from "path";
4
+ import fs from "fs";
5
+ function scanComponentSources(rootDir) {
6
+ const sourceMap = {};
7
+ const files = findTypeScriptFiles(rootDir);
8
+ for (const filePath of files) {
9
+ const content = fs.readFileSync(filePath, "utf8");
10
+ if (!content.includes("@Component")) continue;
11
+ const relativePath = path.relative(rootDir, filePath).replace(/\\/g, "/");
12
+ const components = extractComponents(content, filePath);
13
+ for (const comp of components) {
14
+ sourceMap[comp.name] = { file: relativePath, line: comp.line };
15
+ }
16
+ }
17
+ return sourceMap;
18
+ }
19
+ function extractComponents(code, filePath) {
20
+ const sourceFile = ts.createSourceFile(
21
+ filePath,
22
+ code,
23
+ ts.ScriptTarget.Latest,
24
+ true,
25
+ ts.ScriptKind.TS
26
+ );
27
+ const results = [];
28
+ function visit(node) {
29
+ if (ts.isClassDeclaration(node) && node.name) {
30
+ const decorators = ts.getDecorators(node);
31
+ if (!decorators) return;
32
+ const hasComponent = decorators.some((d) => {
33
+ if (!ts.isCallExpression(d.expression)) return false;
34
+ if (!ts.isIdentifier(d.expression.expression)) return false;
35
+ return d.expression.expression.text === "Component";
36
+ });
37
+ if (hasComponent) {
38
+ const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
39
+ results.push({ name: node.name.text, line: line + 1 });
40
+ }
41
+ }
42
+ ts.forEachChild(node, visit);
43
+ }
44
+ visit(sourceFile);
45
+ return results;
46
+ }
47
+ function findTypeScriptFiles(rootDir) {
48
+ const results = [];
49
+ const srcDir = path.join(rootDir, "src");
50
+ if (!fs.existsSync(srcDir)) return results;
51
+ walk(srcDir, results);
52
+ return results;
53
+ }
54
+ function walk(dir, results) {
55
+ let entries;
56
+ try {
57
+ entries = fs.readdirSync(dir, { withFileTypes: true });
58
+ } catch {
59
+ return;
60
+ }
61
+ for (const entry of entries) {
62
+ if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
63
+ const fullPath = path.join(dir, entry.name);
64
+ if (entry.isDirectory()) {
65
+ walk(fullPath, results);
66
+ } else if (entry.name.endsWith(".ts") && !entry.name.endsWith(".spec.ts") && !entry.name.endsWith(".d.ts")) {
67
+ results.push(fullPath);
68
+ }
69
+ }
70
+ }
71
+
72
+ // src/esbuild-plugin/plugin.ts
73
+ function grabbyEsbuildPlugin(options) {
74
+ return {
75
+ name: "grabby",
76
+ setup(build) {
77
+ if (options?.enabled === false) return;
78
+ const rootDir = options?.rootDir || process.cwd();
79
+ const sourceMap = scanComponentSources(rootDir);
80
+ if (Object.keys(sourceMap).length === 0) return;
81
+ const json = JSON.stringify(sourceMap);
82
+ const existingBanner = build.initialOptions.banner;
83
+ const bannerObj = typeof existingBanner === "object" ? existingBanner : {};
84
+ const existingJs = bannerObj.js || "";
85
+ build.initialOptions.banner = {
86
+ ...bannerObj,
87
+ js: `globalThis.__GRABBY_SOURCE_MAP__=${json};${existingJs}`
88
+ };
89
+ }
90
+ };
91
+ }
92
+ export {
93
+ grabbyEsbuildPlugin,
94
+ scanComponentSources
95
+ };
96
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/esbuild-plugin/scan.ts","../../src/esbuild-plugin/plugin.ts"],"sourcesContent":["import ts from 'typescript';\nimport path from 'path';\nimport fs from 'fs';\n\nexport interface ComponentSourceInfo {\n file: string;\n line: number;\n}\n\nexport type SourceMap = Record<string, ComponentSourceInfo>;\n\n/**\n * Scans the project for `.component.ts` files and extracts component\n * class names with their source locations. Returns a map of\n * `{ ComponentName: { file, line } }`.\n */\nexport function scanComponentSources(rootDir: string): SourceMap {\n const sourceMap: SourceMap = {};\n const files = findTypeScriptFiles(rootDir);\n\n for (const filePath of files) {\n const content = fs.readFileSync(filePath, 'utf8');\n if (!content.includes('@Component')) continue;\n\n const relativePath = path.relative(rootDir, filePath).replace(/\\\\/g, '/');\n const components = extractComponents(content, filePath);\n\n for (const comp of components) {\n sourceMap[comp.name] = { file: relativePath, line: comp.line };\n }\n }\n\n return sourceMap;\n}\n\ninterface ComponentInfo {\n name: string;\n line: number;\n}\n\nfunction extractComponents(code: string, filePath: string): ComponentInfo[] {\n const sourceFile = ts.createSourceFile(\n filePath,\n code,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TS,\n );\n\n const results: ComponentInfo[] = [];\n\n function visit(node: ts.Node): void {\n if (ts.isClassDeclaration(node) && node.name) {\n const decorators = ts.getDecorators(node);\n if (!decorators) return;\n\n const hasComponent = decorators.some((d) => {\n if (!ts.isCallExpression(d.expression)) return false;\n if (!ts.isIdentifier(d.expression.expression)) return false;\n return d.expression.expression.text === 'Component';\n });\n\n if (hasComponent) {\n const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n results.push({ name: node.name.text, line: line + 1 });\n }\n }\n\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return results;\n}\n\nfunction findTypeScriptFiles(rootDir: string): string[] {\n const results: string[] = [];\n const srcDir = path.join(rootDir, 'src');\n\n if (!fs.existsSync(srcDir)) return results;\n\n walk(srcDir, results);\n return results;\n}\n\nfunction walk(dir: string, results: string[]): void {\n let entries: fs.Dirent[];\n try {\n entries = fs.readdirSync(dir, { withFileTypes: true });\n } catch {\n return;\n }\n\n for (const entry of entries) {\n if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue;\n\n const fullPath = path.join(dir, entry.name);\n\n if (entry.isDirectory()) {\n walk(fullPath, results);\n } else if (entry.name.endsWith('.ts') && !entry.name.endsWith('.spec.ts') && !entry.name.endsWith('.d.ts')) {\n results.push(fullPath);\n }\n }\n}\n","import type { Plugin } from 'esbuild';\nimport { scanComponentSources } from './scan';\n\nexport function grabbyEsbuildPlugin(options?: {\n rootDir?: string;\n /** Set to false to disable the transform (e.g., in production). Default: true */\n enabled?: boolean;\n}): Plugin {\n return {\n name: 'grabby',\n setup(build) {\n if (options?.enabled === false) return;\n\n const rootDir = options?.rootDir || process.cwd();\n const sourceMap = scanComponentSources(rootDir);\n\n if (Object.keys(sourceMap).length === 0) return;\n\n // Inject the source map as a global variable via banner\n const json = JSON.stringify(sourceMap);\n const existingBanner = build.initialOptions.banner;\n const bannerObj = typeof existingBanner === 'object' ? existingBanner : {};\n const existingJs = bannerObj.js || '';\n build.initialOptions.banner = {\n ...bannerObj,\n js: `globalThis.__GRABBY_SOURCE_MAP__=${json};${existingJs}`,\n };\n },\n };\n}\n"],"mappings":";AAAA,OA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AC5D;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/export.ts
21
+ var export_exports = {};
22
+ __export(export_exports, {
23
+ authorLabel: () => authorLabel,
24
+ estimateTokens: () => estimateTokens,
25
+ formatExport: () => formatExport
26
+ });
27
+ module.exports = __toCommonJS(export_exports);
28
+
29
+ // src/core/capture/export.ts
30
+ function estimateTokens(text) {
31
+ return Math.ceil(text.length / 4);
32
+ }
33
+ var STYLE_FACTS = /* @__PURE__ */ new Set(["styles", "layout", "computed"]);
34
+ var PREVIEW_FACTS = /* @__PURE__ */ new Set(["label", "type", "text", "href", "placeholder", "alt", "src", "title"]);
35
+ function inPreview(preview, value) {
36
+ return value.length > 0 && (preview.includes(`>${value}<`) || preview.includes(`"${value}"`) || preview.includes(`>${value}`));
37
+ }
38
+ function authorKey(a) {
39
+ return a.anonymous || !a.name ? `anon:${a.sessionId}` : `name:${a.name}`;
40
+ }
41
+ function authorLabel(a) {
42
+ if (!a.anonymous && a.name) return a.name;
43
+ return `Anonymous ${a.sessionId.replace(/-/g, "").slice(0, 4)}`;
44
+ }
45
+ function basename(path) {
46
+ return path.split(/[\\/]/).pop() ?? path;
47
+ }
48
+ function location(file, line, full) {
49
+ const name = full ? file : basename(file);
50
+ return line != null ? `${name}:${line}` : name;
51
+ }
52
+ function indent(text, pad) {
53
+ return text.split("\n").map((l, i) => i === 0 ? l : `${pad}${l}`).join("\n");
54
+ }
55
+ function uniq(values) {
56
+ return Array.from(new Set(values));
57
+ }
58
+ function header(comments, env, ctx) {
59
+ const n = comments.length;
60
+ const lines = [`# UI feedback \xB7 ${n} comment${n === 1 ? "" : "s"}`];
61
+ const meta = [];
62
+ if (env.origin) meta.push(env.origin);
63
+ const frameworks = uniq(comments.map((c) => c.framework).filter(Boolean));
64
+ if (frameworks.length) meta.push(frameworks.join(", "));
65
+ const routes = uniq(comments.map((c) => c.page.route));
66
+ if (!ctx.showRoutes && routes.length === 1) meta.push(`page ${routes[0]}`);
67
+ const vp = comments[0]?.page.viewport;
68
+ if (vp) meta.push(`${vp[0]}\xD7${vp[1]}`);
69
+ meta.push((env.now ?? /* @__PURE__ */ new Date()).toISOString().slice(0, 10));
70
+ lines.push(meta.join(" \xB7 "));
71
+ if (ctx.showAuthors) {
72
+ const people = uniq(comments.map((c) => authorLabel(c.author)));
73
+ lines.push(`From: ${people.join(", ")}`);
74
+ }
75
+ return lines;
76
+ }
77
+ function compactLine(c, i, ctx) {
78
+ const t = c.target;
79
+ const where = t.source ? location(t.source.file, t.source.line, true) : t.selector;
80
+ const parts = [where, t.component, `<${t.tag}>`].filter(Boolean).join(" ");
81
+ const who = ctx.showAuthors ? ` (${authorLabel(c.author)})` : "";
82
+ const route = ctx.showRoutes ? ` [${c.page.route}]` : "";
83
+ const id = ctx.showIds ? ` [id ${c.id}]` : "";
84
+ return `${i}. ${parts}${route} \u2014 ${indent(c.comment, " ")}${who}${id}`;
85
+ }
86
+ function detailBlock(c, i, ctx, groupHasSource, headedComponent) {
87
+ const t = c.target;
88
+ const full = ctx.level === "detailed";
89
+ const lines = [`${i}. ${indent(c.comment, " ")}`];
90
+ const b = (text) => lines.push(` - ${text}`);
91
+ const where = [`\`${t.preview}\``, `(${t.kind})`];
92
+ if (t.component && t.component !== headedComponent) {
93
+ where.push(t.source?.line != null && groupHasSource ? `${t.component} line ${t.source.line}` : t.component);
94
+ } else if (t.source?.line != null && groupHasSource) {
95
+ where.push(`line ${t.source.line}`);
96
+ }
97
+ b(where.join(" "));
98
+ if (!t.source || full) b(`selector: \`${t.selector}\``);
99
+ const plain = Object.entries(t.facts).filter(([k, v]) => !STYLE_FACTS.has(k) && !(PREVIEW_FACTS.has(k) && !full && inPreview(t.preview, v)));
100
+ if (plain.length) b(plain.map(([k, v]) => `${k}: ${v}`).join(" \xB7 "));
101
+ for (const [k, v] of Object.entries(t.facts)) if (STYLE_FACTS.has(k)) b(`${k}: ${v}`);
102
+ const parents = t.stack.filter((f, i2) => !(i2 === 0 && (t.source || f.name === t.component)));
103
+ if (parents.length) {
104
+ b(`inside: ${parents.map((f) => f.file ? `${f.name} (${location(f.file, f.line, full)})` : f.name).join(" \u203A ")}`);
105
+ }
106
+ if (full) {
107
+ for (const [k, v] of Object.entries(t.extra)) b(`${k}: ${v}`);
108
+ b(`viewport: ${c.page.viewport[0]}\xD7${c.page.viewport[1]}`);
109
+ }
110
+ if (c.screenshot?.url) b(`screenshot: ${c.screenshot.url}`);
111
+ const meta = [];
112
+ if (ctx.showAuthors) meta.push(`by ${authorLabel(c.author)}`);
113
+ if (ctx.showRoutes) meta.push(`on ${c.page.route}`);
114
+ if (meta.length) b(meta.join(" "));
115
+ if (ctx.showIds) b(`id: ${c.id}`);
116
+ return lines;
117
+ }
118
+ function formatExport(comments, level = "standard", env = {}) {
119
+ if (comments.length === 0) return "";
120
+ const ordered = [...comments].sort((a, b) => a.createdAt - b.createdAt);
121
+ const authors = uniq(ordered.map((c) => authorKey(c.author)));
122
+ const ctx = {
123
+ level,
124
+ showIds: env.showIds === true,
125
+ showAuthors: authors.length > 1 || ordered.some((c) => !c.author.anonymous && !!c.author.name),
126
+ showRoutes: uniq(ordered.map((c) => c.page.route)).length > 1
127
+ };
128
+ const out = header(ordered, env, ctx);
129
+ if (level === "compact") {
130
+ out.push("");
131
+ ordered.forEach((c, idx) => out.push(compactLine(c, idx + 1, ctx)));
132
+ return out.join("\n");
133
+ }
134
+ const groups = /* @__PURE__ */ new Map();
135
+ for (const c of ordered) {
136
+ const key = c.target.source?.file ?? "";
137
+ const list = groups.get(key);
138
+ if (list) list.push(c);
139
+ else groups.set(key, [c]);
140
+ }
141
+ let n = 0;
142
+ for (const [file, list] of groups) {
143
+ out.push("");
144
+ const components = uniq(list.map((c) => c.target.component));
145
+ const headed = file && components.length === 1 ? components[0] : null;
146
+ const lines = uniq(list.map((c) => c.target.source?.line ?? null));
147
+ if (file) {
148
+ const loc = lines.length === 1 ? location(file, lines[0], true) : file;
149
+ out.push(`## ${loc}${headed ? ` \xB7 ${headed}` : ""}`);
150
+ } else {
151
+ out.push("## Elements without source info");
152
+ }
153
+ for (const c of list) {
154
+ n += 1;
155
+ out.push(...detailBlock(c, n, ctx, !!file && lines.length > 1, headed));
156
+ }
157
+ }
158
+ return out.join("\n");
159
+ }
160
+ // Annotate the CommonJS export names for ESM import in node:
161
+ 0 && (module.exports = {
162
+ authorLabel,
163
+ estimateTokens,
164
+ formatExport
165
+ });
166
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/export.ts","../../src/core/capture/export.ts"],"sourcesContent":["/**\n * The comment formatter on its own, with no DOM code, for Node consumers\n * such as @githumbi/grabby-server.\n */\nexport { formatExport, estimateTokens, authorLabel, type ExportEnv } from './core/capture/export';\nexport type {\n GrabbyComment,\n GrabbyTarget,\n TargetKind,\n DetailLevel,\n CommentAuthor,\n PageInfo,\n ScreenshotRef,\n SourceLocation,\n StackFrame,\n} from './core/types';\n","import type { GrabbyComment, DetailLevel, CommentAuthor } from '../types';\n\nexport interface ExportEnv {\n /** Page origin shown in the header, e.g. \"localhost:4200\". */\n origin?: string;\n now?: Date;\n /** Print each comment's id, so an agent can act on it (e.g. resolve it). */\n showIds?: boolean;\n}\n\n/** Rough token count (≈4 characters per token), for the Copy dialog. */\nexport function estimateTokens(text: string): number {\n return Math.ceil(text.length / 4);\n}\n\nconst STYLE_FACTS = new Set(['styles', 'layout', 'computed']);\n/** Facts that are often already visible in the preview; skipped when they are. */\nconst PREVIEW_FACTS = new Set(['label', 'type', 'text', 'href', 'placeholder', 'alt', 'src', 'title']);\n\nfunction inPreview(preview: string, value: string): boolean {\n return value.length > 0 && (preview.includes(`>${value}<`) || preview.includes(`\"${value}\"`) || preview.includes(`>${value}`));\n}\n\nfunction authorKey(a: CommentAuthor): string {\n return a.anonymous || !a.name ? `anon:${a.sessionId}` : `name:${a.name}`;\n}\n\nexport function authorLabel(a: CommentAuthor): string {\n if (!a.anonymous && a.name) return a.name;\n return `Anonymous ${a.sessionId.replace(/-/g, '').slice(0, 4)}`;\n}\n\nfunction basename(path: string): string {\n return path.split(/[\\\\/]/).pop() ?? path;\n}\n\nfunction location(file: string, line: number | null, full: boolean): string {\n const name = full ? file : basename(file);\n return line != null ? `${name}:${line}` : name;\n}\n\nfunction indent(text: string, pad: string): string {\n return text.split('\\n').map((l, i) => (i === 0 ? l : `${pad}${l}`)).join('\\n');\n}\n\nfunction uniq<T>(values: T[]): T[] {\n return Array.from(new Set(values));\n}\n\ninterface Context {\n showAuthors: boolean;\n showRoutes: boolean;\n showIds: boolean;\n level: DetailLevel;\n}\n\nfunction header(comments: GrabbyComment[], env: ExportEnv, ctx: Context): string[] {\n const n = comments.length;\n const lines = [`# UI feedback · ${n} comment${n === 1 ? '' : 's'}`];\n const meta: string[] = [];\n if (env.origin) meta.push(env.origin);\n const frameworks = uniq(comments.map((c) => c.framework).filter(Boolean));\n if (frameworks.length) meta.push(frameworks.join(', '));\n const routes = uniq(comments.map((c) => c.page.route));\n if (!ctx.showRoutes && routes.length === 1) meta.push(`page ${routes[0]}`);\n const vp = comments[0]?.page.viewport;\n if (vp) meta.push(`${vp[0]}×${vp[1]}`);\n meta.push((env.now ?? new Date()).toISOString().slice(0, 10));\n lines.push(meta.join(' · '));\n if (ctx.showAuthors) {\n const people = uniq(comments.map((c) => authorLabel(c.author)));\n lines.push(`From: ${people.join(', ')}`);\n }\n return lines;\n}\n\nfunction compactLine(c: GrabbyComment, i: number, ctx: Context): string {\n const t = c.target;\n const where = t.source ? location(t.source.file, t.source.line, true) : t.selector;\n const parts = [where, t.component, `<${t.tag}>`].filter(Boolean).join(' ');\n const who = ctx.showAuthors ? ` (${authorLabel(c.author)})` : '';\n const route = ctx.showRoutes ? ` [${c.page.route}]` : '';\n const id = ctx.showIds ? ` [id ${c.id}]` : '';\n return `${i}. ${parts}${route} — ${indent(c.comment, ' ')}${who}${id}`;\n}\n\nfunction detailBlock(c: GrabbyComment, i: number, ctx: Context, groupHasSource: boolean, headedComponent: string | null): string[] {\n const t = c.target;\n const full = ctx.level === 'detailed';\n const lines = [`${i}. ${indent(c.comment, ' ')}`];\n const b = (text: string) => lines.push(` - ${text}`);\n\n const where: string[] = [`\\`${t.preview}\\``, `(${t.kind})`];\n if (t.component && t.component !== headedComponent) {\n where.push(t.source?.line != null && groupHasSource ? `${t.component} line ${t.source.line}` : t.component);\n } else if (t.source?.line != null && groupHasSource) {\n where.push(`line ${t.source.line}`);\n }\n b(where.join(' '));\n\n // A selector is only worth tokens when there's no file to point at.\n if (!t.source || full) b(`selector: \\`${t.selector}\\``);\n\n const plain = Object.entries(t.facts)\n .filter(([k, v]) => !STYLE_FACTS.has(k) && !(PREVIEW_FACTS.has(k) && !full && inPreview(t.preview, v)));\n if (plain.length) b(plain.map(([k, v]) => `${k}: ${v}`).join(' · '));\n for (const [k, v] of Object.entries(t.facts)) if (STYLE_FACTS.has(k)) b(`${k}: ${v}`);\n\n // The first frame is the element's own component; it's already named above.\n const parents = t.stack.filter((f, i) => !(i === 0 && (t.source || f.name === t.component)));\n if (parents.length) {\n b(`inside: ${parents.map((f) => (f.file ? `${f.name} (${location(f.file, f.line, full)})` : f.name)).join(' › ')}`);\n }\n\n if (full) {\n for (const [k, v] of Object.entries(t.extra)) b(`${k}: ${v}`);\n b(`viewport: ${c.page.viewport[0]}×${c.page.viewport[1]}`);\n }\n\n if (c.screenshot?.url) b(`screenshot: ${c.screenshot.url}`);\n\n const meta: string[] = [];\n if (ctx.showAuthors) meta.push(`by ${authorLabel(c.author)}`);\n if (ctx.showRoutes) meta.push(`on ${c.page.route}`);\n if (meta.length) b(meta.join(' '));\n if (ctx.showIds) b(`id: ${c.id}`);\n return lines;\n}\n\n/**\n * Turns comments into text for an AI agent. Page-level context is said once\n * in the header, comments are grouped by the file they point at, and only the\n * facts that matter for each element's kind are included.\n */\nexport function formatExport(comments: GrabbyComment[], level: DetailLevel = 'standard', env: ExportEnv = {}): string {\n if (comments.length === 0) return '';\n const ordered = [...comments].sort((a, b) => a.createdAt - b.createdAt);\n const authors = uniq(ordered.map((c) => authorKey(c.author)));\n const ctx: Context = {\n level,\n showIds: env.showIds === true,\n showAuthors: authors.length > 1 || ordered.some((c) => !c.author.anonymous && !!c.author.name),\n showRoutes: uniq(ordered.map((c) => c.page.route)).length > 1,\n };\n\n const out = header(ordered, env, ctx);\n\n if (level === 'compact') {\n out.push('');\n ordered.forEach((c, idx) => out.push(compactLine(c, idx + 1, ctx)));\n return out.join('\\n');\n }\n\n // Group by file so an agent handles each file once; keep first-seen order.\n const groups = new Map<string, GrabbyComment[]>();\n for (const c of ordered) {\n const key = c.target.source?.file ?? '';\n const list = groups.get(key);\n if (list) list.push(c);\n else groups.set(key, [c]);\n }\n\n let n = 0;\n for (const [file, list] of groups) {\n out.push('');\n const components = uniq(list.map((c) => c.target.component));\n const headed = file && components.length === 1 ? components[0] : null;\n const lines = uniq(list.map((c) => c.target.source?.line ?? null));\n if (file) {\n const loc = lines.length === 1 ? location(file, lines[0], true) : file;\n out.push(`## ${loc}${headed ? ` · ${headed}` : ''}`);\n } else {\n out.push('## Elements without source info');\n }\n for (const c of list) {\n n += 1;\n out.push(...detailBlock(c, n,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AAQ,QAAQ,IAAI,CAAC;AACjE,QAAI,MAAM;AACR,YAAM,MAAM,MAAM,WAAW,IAAI,SAAS,MAAM,MAAM,CAAC,GAAG,IAAI,IAAI;AAClE,UAAI,KAAK,MAAM,GAAG,GAAG,SAAS,SAAM,MAAM,KAAK,EAAE,EAAE;AAAA,IACrD,OAAO;AACL,UAAI,KAAK,iCAAiC;AAAA,IAC5C;AACA,eAAW,KAAK,MAAM;AACpB,WAAK;AACL,UAAI,KAAK,GAAG,YAAY,GAAG,GAAG,KAAK,CAAC,CAAC,QAAQ,MAAM,SAAS,GAAG,MAAM,CAAC;AAAA,IACxE;AAAA,EACF;AACA,SAAO,IAAI,KAAK,IAAI;AACtB;","names":["i"]}
@@ -0,0 +1,86 @@
1
+ /** What kind of UI the comment is about; decides which facts get captured. */
2
+ type TargetKind = 'action' | 'field' | 'text' | 'media' | 'container' | 'section';
3
+ /** How much context the export includes. */
4
+ type DetailLevel = 'compact' | 'standard' | 'detailed';
5
+ interface SourceLocation {
6
+ file: string;
7
+ line: number | null;
8
+ column: number | null;
9
+ }
10
+ interface StackFrame {
11
+ name: string;
12
+ file: string | null;
13
+ line: number | null;
14
+ }
15
+ /** The compact, serialisable description of the element a comment is about. */
16
+ interface GrabbyTarget {
17
+ kind: TargetKind;
18
+ tag: string;
19
+ component: string | null;
20
+ source: SourceLocation | null;
21
+ /** Up to 3 of the app's own component frames, innermost first. */
22
+ stack: StackFrame[];
23
+ /** Unique CSS selector. Exported only when there is no source location. */
24
+ selector: string;
25
+ /** Trimmed opening tag plus a text excerpt, at most ~300 characters. */
26
+ preview: string;
27
+ /** Kind-specific facts for the standard export, in display order. */
28
+ facts: Record<string, string>;
29
+ /** Extra facts only shown at the detailed level. */
30
+ extra: Record<string, string>;
31
+ }
32
+ interface CommentAuthor {
33
+ name: string | null;
34
+ anonymous: boolean;
35
+ /** Stable random id per browser, so anonymous commenters stay distinguishable. */
36
+ sessionId: string;
37
+ /** The host app's own user id, when it called `identify()`. */
38
+ userId?: string;
39
+ }
40
+ interface PageInfo {
41
+ /** Pathname only; query strings are dropped unless allowlisted. */
42
+ route: string;
43
+ title: string;
44
+ viewport: [number, number];
45
+ }
46
+ interface ScreenshotRef {
47
+ /** Key of the image in this browser's IndexedDB. */
48
+ localId?: string;
49
+ /** Where a server stored it, once uploaded. */
50
+ url?: string;
51
+ width: number;
52
+ height: number;
53
+ }
54
+ interface GrabbyComment {
55
+ id: string;
56
+ createdAt: number;
57
+ updatedAt: number;
58
+ status: 'open' | 'resolved';
59
+ comment: string;
60
+ author: CommentAuthor;
61
+ page: PageInfo;
62
+ target: GrabbyTarget;
63
+ screenshot: ScreenshotRef | null;
64
+ framework: string;
65
+ /** Delivery to a Grabby server, when one is configured. Browser-only. */
66
+ sync?: 'pending' | 'sent' | 'failed';
67
+ }
68
+
69
+ interface ExportEnv {
70
+ /** Page origin shown in the header, e.g. "localhost:4200". */
71
+ origin?: string;
72
+ now?: Date;
73
+ /** Print each comment's id, so an agent can act on it (e.g. resolve it). */
74
+ showIds?: boolean;
75
+ }
76
+ /** Rough token count (≈4 characters per token), for the Copy dialog. */
77
+ declare function estimateTokens(text: string): number;
78
+ declare function authorLabel(a: CommentAuthor): string;
79
+ /**
80
+ * Turns comments into text for an AI agent. Page-level context is said once
81
+ * in the header, comments are grouped by the file they point at, and only the
82
+ * facts that matter for each element's kind are included.
83
+ */
84
+ declare function formatExport(comments: GrabbyComment[], level?: DetailLevel, env?: ExportEnv): string;
85
+
86
+ export { type CommentAuthor, type DetailLevel, type ExportEnv, type GrabbyComment, type GrabbyTarget, type PageInfo, type ScreenshotRef, type SourceLocation, type StackFrame, type TargetKind, authorLabel, estimateTokens, formatExport };