frame.simulator 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/batch.js CHANGED
@@ -1,33 +1,7 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Batch = void 0;
27
- const fs = __importStar(require("fs"));
28
- const path = __importStar(require("path"));
29
- const command_1 = require("./command");
30
- class Batch {
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { Command } from './command';
4
+ export class Batch {
31
5
  constructor(filename, port = 3010) {
32
6
  const batchFilePath = path.join(process.cwd(), filename);
33
7
  this.filename = batchFilePath;
@@ -172,7 +146,7 @@ class Batch {
172
146
  if (attempt >= 1) {
173
147
  console.log(`Attempt ${attempt}/${retries} to click button: ${testId}`);
174
148
  }
175
- const status = await this.sendRequest(command_1.Command.SimulateClick, {
149
+ const status = await this.sendRequest(Command.SimulateClick, {
176
150
  testId,
177
151
  });
178
152
  if (status !== 'ok') {
@@ -187,7 +161,7 @@ class Batch {
187
161
  }
188
162
  }
189
163
  async selectInput(testId, value) {
190
- const status = await this.sendRequest(command_1.Command.SimulateInput, {
164
+ const status = await this.sendRequest(Command.SimulateInput, {
191
165
  testId,
192
166
  value,
193
167
  });
@@ -197,7 +171,7 @@ class Batch {
197
171
  }
198
172
  async sampleClickCanvasDrawAt(testId, x, y) {
199
173
  console.log(`sampleClickCanvasDrawAt(${x}, ${y})`);
200
- await this.sendRequest(command_1.Command.SimulateClickOnCanvas, {
174
+ await this.sendRequest(Command.SimulateClickOnCanvas, {
201
175
  testId,
202
176
  x,
203
177
  y,
@@ -206,4 +180,3 @@ class Batch {
206
180
  await new Promise((resolve) => setTimeout(resolve, 300));
207
181
  }
208
182
  }
209
- exports.Batch = Batch;
package/dist/command.js CHANGED
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Command = void 0;
4
- var Command;
1
+ export var Command;
5
2
  (function (Command) {
6
3
  Command["SimulateClick"] = "SimulateClick";
7
4
  Command["SimulateClickOnCanvas"] = "SimulateClickOnCanvas";
8
5
  Command["SimulateInput"] = "SimulateInput";
9
6
  Command["SimulateCheck"] = "SimulateCheck";
10
- })(Command || (exports.Command = Command = {}));
7
+ })(Command || (Command = {}));
@@ -1,19 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useCommandHandler = useCommandHandler;
4
- const command_1 = require("./command");
5
- const simulator_1 = require("./simulator");
6
- function useCommandHandler() {
1
+ import { Command } from './command';
2
+ import { Simulator } from './simulator';
3
+ export function useCommandHandler() {
7
4
  const handleCommand = async (command, data) => {
8
- const simulator = new simulator_1.Simulator();
5
+ const simulator = new Simulator();
9
6
  switch (command) {
10
- case command_1.Command.SimulateClick:
7
+ case Command.SimulateClick:
11
8
  return simulator.simulateClick(data);
12
- case command_1.Command.SimulateClickOnCanvas:
9
+ case Command.SimulateClickOnCanvas:
13
10
  return simulator.simulateClickOnCanvas(data);
14
- case command_1.Command.SimulateInput:
11
+ case Command.SimulateInput:
15
12
  return simulator.simulateInput(data);
16
- case command_1.Command.SimulateCheck:
13
+ case Command.SimulateCheck:
17
14
  return simulator.simulateCheck(data);
18
15
  default:
19
16
  console.warn('Unknown command:', command);
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("frame.constants");class o{constructor(){console.log("Simulator initialized")}findHTMLElement(n,i,t){t&&console.log(`${c.green}Simulating ${t} on element with testId: ${n}${c.reset}`);const e=document.querySelector(`[data-testid="${n}"]`);return e?e instanceof i||console.error(`Element found but not a ${i.name} for ${t} simulation: ${n}`):console.error(`Element not found for ${t} simulation: ${n}`),e}simulateClickOnCanvas(n){const{x:i,y:t}=n,e=this.findHTMLElement("canvas.draw",HTMLCanvasElement,"click");if(e){const s=e.getBoundingClientRect(),l=new MouseEvent("click",{clientX:s.left+s.width/2+i,clientY:s.top+s.height/2-t,bubbles:!0});l.isBatch=!0,l.batchX=i,l.batchY=t,e.dispatchEvent(l)}}simulateClick(n){const{testId:i}=n,t=this.findHTMLElement(i,HTMLButtonElement,"click");if(t){const e=new MouseEvent("click",{bubbles:!0});e.isBatch=!0,t.click()}}simulateCheck(n){const{testId:i}=n,t=this.findHTMLElement(i,HTMLInputElement,"check");if(t){const e=new MouseEvent("click",{bubbles:!0});e.isBatch=!0,t.dispatchEvent(e)}}simulateInput(n){const{testId:i,value:t}=n,e=this.findHTMLElement(i,HTMLDivElement,"input");if(e){if(e instanceof HTMLInputElement)return e.value=t.toString(),e.dispatchEvent(new Event("input",{bubbles:!0})),{status:"ok"};if(e instanceof HTMLDivElement){const s=e.firstChild;s instanceof HTMLInputElement&&(s.value=t||"",s.dispatchEvent(new Event("input",{bubbles:!0})))}}}}exports.Simulator=o;
@@ -0,0 +1,60 @@
1
+ import { green as c, reset as o } from "frame.constants";
2
+ class r {
3
+ constructor() {
4
+ console.log("Simulator initialized");
5
+ }
6
+ findHTMLElement(n, i, t) {
7
+ t && console.log(
8
+ `${c}Simulating ${t} on element with testId: ${n}${o}`
9
+ );
10
+ const e = document.querySelector(`[data-testid="${n}"]`);
11
+ return e ? e instanceof i || console.error(
12
+ `Element found but not a ${i.name} for ${t} simulation: ${n}`
13
+ ) : console.error(`Element not found for ${t} simulation: ${n}`), e;
14
+ }
15
+ simulateClickOnCanvas(n) {
16
+ const { x: i, y: t } = n, e = this.findHTMLElement(
17
+ "canvas.draw",
18
+ HTMLCanvasElement,
19
+ "click"
20
+ );
21
+ if (e) {
22
+ const s = e.getBoundingClientRect(), l = new MouseEvent("click", {
23
+ clientX: s.left + s.width / 2 + i,
24
+ // Convert canvas-relative to screen coordinates
25
+ clientY: s.top + s.height / 2 - t,
26
+ // Convert canvas-relative to screen coordinates (flip Y)
27
+ bubbles: !0
28
+ });
29
+ l.isBatch = !0, l.batchX = i, l.batchY = t, e.dispatchEvent(l);
30
+ }
31
+ }
32
+ simulateClick(n) {
33
+ const { testId: i } = n, t = this.findHTMLElement(i, HTMLButtonElement, "click");
34
+ if (t) {
35
+ const e = new MouseEvent("click", { bubbles: !0 });
36
+ e.isBatch = !0, t.click();
37
+ }
38
+ }
39
+ simulateCheck(n) {
40
+ const { testId: i } = n, t = this.findHTMLElement(i, HTMLInputElement, "check");
41
+ if (t) {
42
+ const e = new MouseEvent("click", { bubbles: !0 });
43
+ e.isBatch = !0, t.dispatchEvent(e);
44
+ }
45
+ }
46
+ simulateInput(n) {
47
+ const { testId: i, value: t } = n, e = this.findHTMLElement(i, HTMLDivElement, "input");
48
+ if (e) {
49
+ if (e instanceof HTMLInputElement)
50
+ return e.value = t.toString(), e.dispatchEvent(new Event("input", { bubbles: !0 })), { status: "ok" };
51
+ if (e instanceof HTMLDivElement) {
52
+ const s = e.firstChild;
53
+ s instanceof HTMLInputElement && (s.value = t || "", s.dispatchEvent(new Event("input", { bubbles: !0 })));
54
+ }
55
+ }
56
+ }
57
+ }
58
+ export {
59
+ r as Simulator
60
+ };
package/dist/index.js CHANGED
@@ -1,11 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Batch = exports.useCommandHandler = exports.Command = exports.Simulator = void 0;
4
- var simulator_1 = require("./simulator");
5
- Object.defineProperty(exports, "Simulator", { enumerable: true, get: function () { return simulator_1.Simulator; } });
6
- var command_1 = require("./command");
7
- Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return command_1.Command; } });
8
- var commandHandler_1 = require("./commandHandler");
9
- Object.defineProperty(exports, "useCommandHandler", { enumerable: true, get: function () { return commandHandler_1.useCommandHandler; } });
10
- var batch_1 = require("./batch");
11
- Object.defineProperty(exports, "Batch", { enumerable: true, get: function () { return batch_1.Batch; } });
1
+ export { Simulator } from './simulator';
2
+ export { Command } from './command';
3
+ export { useCommandHandler } from './commandHandler';
4
+ export { Batch } from './batch';
package/dist/main.js CHANGED
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const batch_1 = require("./batch");
1
+ import { Batch } from './batch';
4
2
  async function handleDrawFrame(batch, item, index) {
5
3
  const coordinates = item.payload.coordinates;
6
4
  console.log(` Command[${index}]: MainDrawFrame`);
@@ -55,7 +53,7 @@ async function handleCommand(batch, item, index) {
55
53
  }
56
54
  async function main(batchFile) {
57
55
  try {
58
- const batch = new batch_1.Batch(batchFile);
56
+ const batch = new Batch(batchFile);
59
57
  await batch.run(handleCommand);
60
58
  }
61
59
  catch (error) {
package/dist/simulator.js CHANGED
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Simulator = void 0;
4
- const frame_constants_1 = require("frame.constants");
5
- class Simulator {
1
+ import { green, reset } from 'frame.constants';
2
+ export class Simulator {
6
3
  constructor() {
7
4
  console.log('Simulator initialized');
8
5
  }
9
6
  findHTMLElement(testId, elementType, type) {
10
7
  if (type) {
11
- console.log(`${frame_constants_1.green}Simulating ${type} on element with testId: ${testId}${frame_constants_1.reset}`);
8
+ console.log(`${green}Simulating ${type} on element with testId: ${testId}${reset}`);
12
9
  }
13
10
  const element = document.querySelector(`[data-testid="${testId}"]`);
14
11
  if (element) {
@@ -82,4 +79,3 @@ class Simulator {
82
79
  }
83
80
  }
84
81
  }
85
- exports.Simulator = Simulator;
@@ -1 +1 @@
1
- {"root":["../batch.ts","../command-server.ts","../command.ts","../commandhandler.ts","../index.ts","../main.ts","../simulator.ts","../types.ts"],"version":"5.6.3"}
1
+ {"root":["../batch.ts","../command-server.ts","../command.ts","../commandhandler.ts","../index.ts","../main.ts","../simulator.ts","../types.ts","../vite.config.ts"],"version":"5.6.3"}
package/dist/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;
@@ -0,0 +1,21 @@
1
+ import { defineConfig } from 'vite';
2
+ import tsconfigPaths from 'vite-tsconfig-paths';
3
+ export default defineConfig({
4
+ plugins: [tsconfigPaths()],
5
+ build: {
6
+ lib: {
7
+ entry: './simulator.ts',
8
+ name: 'FrameSimulator',
9
+ fileName: 'frame-simulator',
10
+ formats: ['es', 'cjs'],
11
+ },
12
+ rollupOptions: {
13
+ external: ['frame.constants'],
14
+ output: {
15
+ globals: {
16
+ 'frame.constants': 'frameConstants',
17
+ },
18
+ },
19
+ },
20
+ },
21
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frame.simulator",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "A simulator for testing form interactions in a controlled environment.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -27,6 +27,8 @@
27
27
  "cors": "^2.8.5",
28
28
  "express": "^5.2.1",
29
29
  "frame.constants": "^1.0.5",
30
- "tsx": "^4.21.0"
30
+ "tsx": "^4.21.0",
31
+ "vite": "^7.3.1",
32
+ "vite-tsconfig-paths": "^6.1.1"
31
33
  }
32
34
  }
package/simulator.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { green, red, reset } from 'frame.constants';
1
+ import { green, reset } from 'frame.constants';
2
2
  import { TClick, TClickOnCanvas, TInput } from './types';
3
3
 
4
4
  export class Simulator {
package/tsconfig.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2020",
4
- "module": "commonjs",
4
+ "module": "ESNext",
5
+ "moduleResolution": "node",
5
6
  "declaration": true,
6
7
  "outDir": "dist",
7
8
  "strict": true,
package/vite.config.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { defineConfig } from 'vite';
2
+ import tsconfigPaths from 'vite-tsconfig-paths';
3
+
4
+ export default defineConfig({
5
+ plugins: [tsconfigPaths()],
6
+ build: {
7
+ lib: {
8
+ entry: './simulator.ts',
9
+ name: 'FrameSimulator',
10
+ fileName: 'frame-simulator',
11
+ formats: ['es', 'cjs'],
12
+ },
13
+ rollupOptions: {
14
+ external: ['frame.constants'],
15
+ output: {
16
+ globals: {
17
+ 'frame.constants': 'frameConstants',
18
+ },
19
+ },
20
+ },
21
+ },
22
+ });