@rpascene/shared 0.30.8

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 (177) hide show
  1. package/README.md +9 -0
  2. package/dist/es/baseDB.mjs +109 -0
  3. package/dist/es/build/copy-static.mjs +29 -0
  4. package/dist/es/common.mjs +37 -0
  5. package/dist/es/constants/example-code.mjs +202 -0
  6. package/dist/es/constants/index.mjs +74 -0
  7. package/dist/es/env/basic.mjs +6 -0
  8. package/dist/es/env/constants.mjs +97 -0
  9. package/dist/es/env/decide-model-config.mjs +172 -0
  10. package/dist/es/env/global-config-manager.mjs +82 -0
  11. package/dist/es/env/helper.mjs +45 -0
  12. package/dist/es/env/index.mjs +5 -0
  13. package/dist/es/env/init-debug.mjs +18 -0
  14. package/dist/es/env/model-config-manager.mjs +99 -0
  15. package/dist/es/env/parse.mjs +69 -0
  16. package/dist/es/env/types.mjs +265 -0
  17. package/dist/es/env/utils.mjs +18 -0
  18. package/dist/es/extractor/constants.mjs +2 -0
  19. package/dist/es/extractor/cs_postmessage.mjs +61 -0
  20. package/dist/es/extractor/customLocator.mjs +646 -0
  21. package/dist/es/extractor/debug.mjs +6 -0
  22. package/dist/es/extractor/dom-util.mjs +92 -0
  23. package/dist/es/extractor/index.mjs +7 -0
  24. package/dist/es/extractor/locator.mjs +95 -0
  25. package/dist/es/extractor/tree.mjs +81 -0
  26. package/dist/es/extractor/util.mjs +244 -0
  27. package/dist/es/extractor/web-extractor.mjs +361 -0
  28. package/dist/es/img/box-select.mjs +184 -0
  29. package/dist/es/img/draw-box.mjs +42 -0
  30. package/dist/es/img/get-jimp.mjs +10 -0
  31. package/dist/es/img/get-photon.mjs +19 -0
  32. package/dist/es/img/get-sharp.mjs +11 -0
  33. package/dist/es/img/index.mjs +5 -0
  34. package/dist/es/img/info.mjs +32 -0
  35. package/dist/es/img/transform.mjs +192 -0
  36. package/dist/es/index.mjs +3 -0
  37. package/dist/es/logger.mjs +61 -0
  38. package/dist/es/node/fs.mjs +44 -0
  39. package/dist/es/node/index.mjs +1 -0
  40. package/dist/es/polyfills/async-hooks.mjs +2 -0
  41. package/dist/es/polyfills/index.mjs +1 -0
  42. package/dist/es/types/index.mjs +3 -0
  43. package/dist/es/us-keyboard-layout.mjs +1414 -0
  44. package/dist/es/us-keyboard-layout.mjs.LICENSE.txt +5 -0
  45. package/dist/es/utils.mjs +66 -0
  46. package/dist/lib/baseDB.js +149 -0
  47. package/dist/lib/build/copy-static.js +77 -0
  48. package/dist/lib/common.js +93 -0
  49. package/dist/lib/constants/example-code.js +239 -0
  50. package/dist/lib/constants/index.js +153 -0
  51. package/dist/lib/env/basic.js +40 -0
  52. package/dist/lib/env/constants.js +143 -0
  53. package/dist/lib/env/decide-model-config.js +212 -0
  54. package/dist/lib/env/global-config-manager.js +116 -0
  55. package/dist/lib/env/helper.js +85 -0
  56. package/dist/lib/env/index.js +94 -0
  57. package/dist/lib/env/init-debug.js +52 -0
  58. package/dist/lib/env/model-config-manager.js +133 -0
  59. package/dist/lib/env/parse.js +106 -0
  60. package/dist/lib/env/types.js +650 -0
  61. package/dist/lib/env/utils.js +61 -0
  62. package/dist/lib/extractor/constants.js +42 -0
  63. package/dist/lib/extractor/cs_postmessage.js +98 -0
  64. package/dist/lib/extractor/customLocator.js +698 -0
  65. package/dist/lib/extractor/debug.js +12 -0
  66. package/dist/lib/extractor/dom-util.js +150 -0
  67. package/dist/lib/extractor/index.js +153 -0
  68. package/dist/lib/extractor/locator.js +141 -0
  69. package/dist/lib/extractor/tree.js +127 -0
  70. package/dist/lib/extractor/util.js +335 -0
  71. package/dist/lib/extractor/web-extractor.js +407 -0
  72. package/dist/lib/img/box-select.js +232 -0
  73. package/dist/lib/img/draw-box.js +89 -0
  74. package/dist/lib/img/get-jimp.js +72 -0
  75. package/dist/lib/img/get-photon.js +76 -0
  76. package/dist/lib/img/get-sharp.js +63 -0
  77. package/dist/lib/img/index.js +102 -0
  78. package/dist/lib/img/info.js +86 -0
  79. package/dist/lib/img/transform.js +279 -0
  80. package/dist/lib/index.js +43 -0
  81. package/dist/lib/logger.js +114 -0
  82. package/dist/lib/node/fs.js +97 -0
  83. package/dist/lib/node/index.js +60 -0
  84. package/dist/lib/polyfills/async-hooks.js +36 -0
  85. package/dist/lib/polyfills/index.js +60 -0
  86. package/dist/lib/types/index.js +37 -0
  87. package/dist/lib/us-keyboard-layout.js +1457 -0
  88. package/dist/lib/us-keyboard-layout.js.LICENSE.txt +5 -0
  89. package/dist/lib/utils.js +136 -0
  90. package/dist/types/baseDB.d.ts +25 -0
  91. package/dist/types/build/copy-static.d.ts +31 -0
  92. package/dist/types/common.d.ts +12 -0
  93. package/dist/types/constants/example-code.d.ts +2 -0
  94. package/dist/types/constants/index.d.ts +23 -0
  95. package/dist/types/env/basic.d.ts +6 -0
  96. package/dist/types/env/constants.d.ts +40 -0
  97. package/dist/types/env/decide-model-config.d.ts +14 -0
  98. package/dist/types/env/global-config-manager.d.ts +32 -0
  99. package/dist/types/env/helper.d.ts +6 -0
  100. package/dist/types/env/index.d.ts +4 -0
  101. package/dist/types/env/init-debug.d.ts +1 -0
  102. package/dist/types/env/model-config-manager.d.ts +24 -0
  103. package/dist/types/env/parse.d.ts +12 -0
  104. package/dist/types/env/types.d.ts +295 -0
  105. package/dist/types/env/utils.d.ts +7 -0
  106. package/dist/types/extractor/constants.d.ts +1 -0
  107. package/dist/types/extractor/cs_postmessage.d.ts +2 -0
  108. package/dist/types/extractor/customLocator.d.ts +69 -0
  109. package/dist/types/extractor/debug.d.ts +1 -0
  110. package/dist/types/extractor/dom-util.d.ts +26 -0
  111. package/dist/types/extractor/index.d.ts +36 -0
  112. package/dist/types/extractor/locator.d.ts +7 -0
  113. package/dist/types/extractor/tree.d.ts +9 -0
  114. package/dist/types/extractor/util.d.ts +43 -0
  115. package/dist/types/extractor/web-extractor.d.ts +19 -0
  116. package/dist/types/img/box-select.d.ts +25 -0
  117. package/dist/types/img/draw-box.d.ts +15 -0
  118. package/dist/types/img/get-jimp.d.ts +2 -0
  119. package/dist/types/img/get-photon.d.ts +8 -0
  120. package/dist/types/img/get-sharp.d.ts +3 -0
  121. package/dist/types/img/index.d.ts +4 -0
  122. package/dist/types/img/info.d.ts +29 -0
  123. package/dist/types/img/transform.d.ts +88 -0
  124. package/dist/types/index.d.ts +3 -0
  125. package/dist/types/logger.d.ts +4 -0
  126. package/dist/types/node/fs.d.ts +15 -0
  127. package/dist/types/node/index.d.ts +1 -0
  128. package/dist/types/polyfills/async-hooks.d.ts +6 -0
  129. package/dist/types/polyfills/index.d.ts +4 -0
  130. package/dist/types/types/index.d.ts +37 -0
  131. package/dist/types/us-keyboard-layout.d.ts +32 -0
  132. package/dist/types/utils.d.ts +22 -0
  133. package/package.json +102 -0
  134. package/src/baseDB.ts +158 -0
  135. package/src/build/copy-static.ts +62 -0
  136. package/src/common.ts +67 -0
  137. package/src/constants/example-code.ts +202 -0
  138. package/src/constants/index.ts +81 -0
  139. package/src/env/basic.ts +12 -0
  140. package/src/env/constants.ts +291 -0
  141. package/src/env/decide-model-config.ts +319 -0
  142. package/src/env/global-config-manager.ts +174 -0
  143. package/src/env/helper.ts +80 -0
  144. package/src/env/index.ts +4 -0
  145. package/src/env/init-debug.ts +29 -0
  146. package/src/env/model-config-manager.ts +145 -0
  147. package/src/env/parse.ts +131 -0
  148. package/src/env/types.ts +573 -0
  149. package/src/env/utils.ts +39 -0
  150. package/src/extractor/constants.ts +5 -0
  151. package/src/extractor/cs_postmessage.ts +101 -0
  152. package/src/extractor/customLocator.ts +1138 -0
  153. package/src/extractor/debug.ts +10 -0
  154. package/src/extractor/dom-util.ts +141 -0
  155. package/src/extractor/index.ts +54 -0
  156. package/src/extractor/locator.ts +179 -0
  157. package/src/extractor/tree.ts +179 -0
  158. package/src/extractor/util.ts +468 -0
  159. package/src/extractor/web-extractor.ts +559 -0
  160. package/src/img/box-select.ts +346 -0
  161. package/src/img/draw-box.ts +60 -0
  162. package/src/img/get-jimp.ts +12 -0
  163. package/src/img/get-photon.ts +48 -0
  164. package/src/img/get-sharp.ts +18 -0
  165. package/src/img/index.ts +24 -0
  166. package/src/img/info.ts +79 -0
  167. package/src/img/jimp.d.ts +4 -0
  168. package/src/img/transform.ts +396 -0
  169. package/src/index.ts +6 -0
  170. package/src/logger.ts +93 -0
  171. package/src/node/fs.ts +84 -0
  172. package/src/node/index.ts +1 -0
  173. package/src/polyfills/async-hooks.ts +6 -0
  174. package/src/polyfills/index.ts +4 -0
  175. package/src/types/index.ts +53 -0
  176. package/src/us-keyboard-layout.ts +723 -0
  177. package/src/utils.ts +127 -0
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2017 Google Inc.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
@@ -0,0 +1,66 @@
1
+ import { sha256 } from "js-sha256";
2
+ import { v4 } from "uuid";
3
+ var _process_versions;
4
+ const ifInBrowser = 'undefined' != typeof window;
5
+ const ifInWorker = 'undefined' != typeof WorkerGlobalScope;
6
+ const ifInNode = 'undefined' != typeof process && (null == (_process_versions = process.versions) ? void 0 : _process_versions.node);
7
+ function uuid() {
8
+ return v4();
9
+ }
10
+ const hashMap = {};
11
+ function generateHashId(rect, content = '') {
12
+ const combined = JSON.stringify({
13
+ content,
14
+ rect
15
+ });
16
+ let sliceLength = 5;
17
+ let slicedHash = '';
18
+ const hashHex = sha256.create().update(combined).hex();
19
+ const toLetters = (hex)=>hex.split('').map((char)=>{
20
+ const code = Number.parseInt(char, 16);
21
+ return String.fromCharCode(97 + code % 26);
22
+ }).join('');
23
+ const hashLetters = toLetters(hashHex);
24
+ while(sliceLength < hashLetters.length - 1){
25
+ slicedHash = hashLetters.slice(0, sliceLength);
26
+ if (hashMap[slicedHash] && hashMap[slicedHash] !== combined) {
27
+ sliceLength++;
28
+ continue;
29
+ }
30
+ hashMap[slicedHash] = combined;
31
+ break;
32
+ }
33
+ return slicedHash;
34
+ }
35
+ function assert(condition, message) {
36
+ if (!condition) throw new Error(message || 'Assertion failed');
37
+ }
38
+ function getGlobalScope() {
39
+ if ('undefined' != typeof window) return window;
40
+ if ('undefined' != typeof globalThis) return globalThis;
41
+ if ('undefined' != typeof self) return self;
42
+ }
43
+ let isMcp = false;
44
+ function setIsMcp(value) {
45
+ isMcp = value;
46
+ }
47
+ function logMsg(...message) {
48
+ if (!isMcp) console.log(...message);
49
+ }
50
+ async function repeat(times, fn) {
51
+ for(let i = 0; i < times; i++)await fn(i);
52
+ }
53
+ const utils_REGEXP_LT = /</g;
54
+ const utils_REGEXP_GT = />/g;
55
+ const REGEXP_LT_ESCAPE = '__rpascene_lt__';
56
+ const REGEXP_GT_ESCAPE = '__rpascene_gt__';
57
+ const escapeScriptTag = (html)=>html.replace(utils_REGEXP_LT, REGEXP_LT_ESCAPE).replace(utils_REGEXP_GT, REGEXP_GT_ESCAPE);
58
+ const antiEscapeScriptTag = (html)=>{
59
+ const REGEXP_LT = new RegExp(REGEXP_LT_ESCAPE, 'g');
60
+ const REGEXP_GT = new RegExp(REGEXP_GT_ESCAPE, 'g');
61
+ return html.replace(REGEXP_LT, '<').replace(REGEXP_GT, '>');
62
+ };
63
+ function replaceIllegalPathCharsAndSpace(str) {
64
+ return str.replace(/[:*?"<>| ]/g, '-');
65
+ }
66
+ export { antiEscapeScriptTag, assert, escapeScriptTag, generateHashId, getGlobalScope, ifInBrowser, ifInNode, ifInWorker, logMsg, repeat, replaceIllegalPathCharsAndSpace, setIsMcp, uuid };
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ IndexedDBManager: ()=>IndexedDBManager,
28
+ createCleanupFunction: ()=>createCleanupFunction,
29
+ withErrorHandling: ()=>withErrorHandling
30
+ });
31
+ function _define_property(obj, key, value) {
32
+ if (key in obj) Object.defineProperty(obj, key, {
33
+ value: value,
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true
37
+ });
38
+ else obj[key] = value;
39
+ return obj;
40
+ }
41
+ class IndexedDBManager {
42
+ initDB() {
43
+ return new Promise((resolve, reject)=>{
44
+ const request = indexedDB.open(this.dbName, this.version);
45
+ request.onerror = ()=>reject(request.error);
46
+ request.onsuccess = ()=>resolve(request.result);
47
+ request.onupgradeneeded = (event)=>{
48
+ const db = event.target.result;
49
+ this.storeConfigs.forEach(({ name, keyPath })=>{
50
+ if (!db.objectStoreNames.contains(name)) {
51
+ const store = db.createObjectStore(name, {
52
+ keyPath
53
+ });
54
+ store.createIndex('timestamp', 'timestamp', {
55
+ unique: false
56
+ });
57
+ }
58
+ });
59
+ };
60
+ });
61
+ }
62
+ async withTransaction(storeNames, mode, operation) {
63
+ const db = await this.dbPromise;
64
+ const transaction = db.transaction(storeNames, mode);
65
+ const stores = Array.isArray(storeNames) ? storeNames.map((name)=>transaction.objectStore(name)) : transaction.objectStore(storeNames);
66
+ return operation(stores);
67
+ }
68
+ promisifyRequest(request) {
69
+ return new Promise((resolve, reject)=>{
70
+ request.onsuccess = ()=>resolve(request.result);
71
+ request.onerror = ()=>reject(request.error);
72
+ });
73
+ }
74
+ async put(storeName, data) {
75
+ await this.withTransaction(storeName, 'readwrite', async (store)=>{
76
+ await this.promisifyRequest(store.put(data));
77
+ });
78
+ }
79
+ async get(storeName, key) {
80
+ return this.withTransaction(storeName, 'readonly', async (store)=>this.promisifyRequest(store.get(key)));
81
+ }
82
+ async getAll(storeName, sortByTimestamp = true) {
83
+ return this.withTransaction(storeName, 'readonly', async (store)=>{
84
+ const objectStore = store;
85
+ const results = sortByTimestamp ? await this.promisifyRequest(objectStore.index('timestamp').getAll()) : await this.promisifyRequest(objectStore.getAll());
86
+ return sortByTimestamp ? results.sort((a, b)=>a.timestamp - b.timestamp) : results;
87
+ });
88
+ }
89
+ async clear(storeName) {
90
+ await this.withTransaction(storeName, 'readwrite', async (store)=>{
91
+ await this.promisifyRequest(store.clear());
92
+ });
93
+ }
94
+ async delete(storeName, key) {
95
+ await this.withTransaction(storeName, 'readwrite', async (store)=>{
96
+ await this.promisifyRequest(store.delete(key));
97
+ });
98
+ }
99
+ async count(storeName) {
100
+ return this.withTransaction(storeName, 'readonly', async (store)=>this.promisifyRequest(store.count()));
101
+ }
102
+ getDBPromise() {
103
+ return this.dbPromise;
104
+ }
105
+ constructor(dbName, version, storeConfigs){
106
+ _define_property(this, "dbPromise", void 0);
107
+ _define_property(this, "dbName", void 0);
108
+ _define_property(this, "version", void 0);
109
+ _define_property(this, "storeConfigs", void 0);
110
+ this.dbName = dbName;
111
+ this.version = version;
112
+ this.storeConfigs = storeConfigs;
113
+ this.dbPromise = this.initDB();
114
+ }
115
+ }
116
+ const withErrorHandling = async (operation, errorMessage, defaultValue, onQuotaExceeded)=>{
117
+ try {
118
+ return await operation();
119
+ } catch (e) {
120
+ console.error(errorMessage, e);
121
+ if (e instanceof Error && 'QuotaExceededError' === e.name && onQuotaExceeded) {
122
+ console.log('Storage quota exceeded, running cleanup...');
123
+ await onQuotaExceeded();
124
+ }
125
+ return defaultValue;
126
+ }
127
+ };
128
+ const createCleanupFunction = (dbManager, storeName, maxItems)=>async ()=>{
129
+ try {
130
+ const results = await dbManager.getAll(storeName);
131
+ if (results.length > maxItems) {
132
+ const toDelete = results.sort((a, b)=>a.timestamp - b.timestamp).slice(0, results.length - maxItems);
133
+ await Promise.all(toDelete.map((item)=>dbManager.delete(storeName, item.id)));
134
+ }
135
+ } catch (e) {
136
+ console.error(`Failed to cleanup ${storeName}:`, e);
137
+ }
138
+ };
139
+ exports.IndexedDBManager = __webpack_exports__.IndexedDBManager;
140
+ exports.createCleanupFunction = __webpack_exports__.createCleanupFunction;
141
+ exports.withErrorHandling = __webpack_exports__.withErrorHandling;
142
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
143
+ "IndexedDBManager",
144
+ "createCleanupFunction",
145
+ "withErrorHandling"
146
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
147
+ Object.defineProperty(exports, '__esModule', {
148
+ value: true
149
+ });
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ createPlaygroundCopyPlugin: ()=>createPlaygroundCopyPlugin,
37
+ createCopyStaticPlugin: ()=>createCopyStaticPlugin
38
+ });
39
+ const external_node_fs_namespaceObject = require("node:fs");
40
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
41
+ const external_node_path_namespaceObject = require("node:path");
42
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
43
+ const createCopyStaticPlugin = (options)=>({
44
+ name: options.pluginName || 'copy-static',
45
+ setup (api) {
46
+ api.onAfterBuild(async ()=>{
47
+ const { srcDir, destDir, faviconPath } = options;
48
+ await external_node_fs_default().promises.mkdir(destDir, {
49
+ recursive: true
50
+ });
51
+ await external_node_fs_default().promises.cp(srcDir, destDir, {
52
+ recursive: true
53
+ });
54
+ console.log(`Copied build artifacts from ${srcDir} to ${destDir}`);
55
+ if (faviconPath) {
56
+ const faviconDest = external_node_path_default().join(destDir, 'favicon.ico');
57
+ await external_node_fs_default().promises.copyFile(faviconPath, faviconDest);
58
+ console.log(`Copied favicon from ${faviconPath} to ${faviconDest}`);
59
+ }
60
+ });
61
+ }
62
+ });
63
+ const createPlaygroundCopyPlugin = (srcDir, destDir, pluginName, faviconSrc)=>createCopyStaticPlugin({
64
+ srcDir,
65
+ destDir,
66
+ faviconPath: faviconSrc,
67
+ pluginName
68
+ });
69
+ exports.createCopyStaticPlugin = __webpack_exports__.createCopyStaticPlugin;
70
+ exports.createPlaygroundCopyPlugin = __webpack_exports__.createPlaygroundCopyPlugin;
71
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
72
+ "createCopyStaticPlugin",
73
+ "createPlaygroundCopyPlugin"
74
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
75
+ Object.defineProperty(exports, '__esModule', {
76
+ value: true
77
+ });
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ defaultRunDirName: ()=>defaultRunDirName,
37
+ ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED: ()=>ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED,
38
+ getRpasceneRunSubDir: ()=>getRpasceneRunSubDir,
39
+ getRpasceneRunDir: ()=>getRpasceneRunDir,
40
+ getRpasceneRunBaseDir: ()=>getRpasceneRunBaseDir
41
+ });
42
+ const external_node_fs_namespaceObject = require("node:fs");
43
+ const external_node_os_namespaceObject = require("node:os");
44
+ const external_node_path_namespaceObject = require("node:path");
45
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
46
+ const basic_js_namespaceObject = require("./env/basic.js");
47
+ const types_js_namespaceObject = require("./env/types.js");
48
+ const external_utils_js_namespaceObject = require("./utils.js");
49
+ const defaultRunDirName = 'rpascene_run';
50
+ const getRpasceneRunDir = ()=>{
51
+ if (!external_utils_js_namespaceObject.ifInNode) return '';
52
+ return (0, basic_js_namespaceObject.getBasicEnvValue)(types_js_namespaceObject.RPASCENE_RUN_DIR) || defaultRunDirName;
53
+ };
54
+ const getRpasceneRunBaseDir = ()=>{
55
+ if (!external_utils_js_namespaceObject.ifInNode) return '';
56
+ let basePath = external_node_path_default().resolve(process.cwd(), getRpasceneRunDir());
57
+ if (!(0, external_node_fs_namespaceObject.existsSync)(basePath)) try {
58
+ (0, external_node_fs_namespaceObject.mkdirSync)(basePath, {
59
+ recursive: true
60
+ });
61
+ } catch (error) {
62
+ basePath = external_node_path_default().join((0, external_node_os_namespaceObject.tmpdir)(), defaultRunDirName);
63
+ (0, external_node_fs_namespaceObject.mkdirSync)(basePath, {
64
+ recursive: true
65
+ });
66
+ }
67
+ return basePath;
68
+ };
69
+ const getRpasceneRunSubDir = (subdir)=>{
70
+ if (!external_utils_js_namespaceObject.ifInNode) return '';
71
+ const basePath = getRpasceneRunBaseDir();
72
+ const logPath = external_node_path_default().join(basePath, subdir);
73
+ if (!(0, external_node_fs_namespaceObject.existsSync)(logPath)) (0, external_node_fs_namespaceObject.mkdirSync)(logPath, {
74
+ recursive: true
75
+ });
76
+ return logPath;
77
+ };
78
+ const ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED = 'NOT_IMPLEMENTED_AS_DESIGNED';
79
+ exports.ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED = __webpack_exports__.ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED;
80
+ exports.defaultRunDirName = __webpack_exports__.defaultRunDirName;
81
+ exports.getRpasceneRunBaseDir = __webpack_exports__.getRpasceneRunBaseDir;
82
+ exports.getRpasceneRunDir = __webpack_exports__.getRpasceneRunDir;
83
+ exports.getRpasceneRunSubDir = __webpack_exports__.getRpasceneRunSubDir;
84
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
85
+ "ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED",
86
+ "defaultRunDirName",
87
+ "getRpasceneRunBaseDir",
88
+ "getRpasceneRunDir",
89
+ "getRpasceneRunSubDir"
90
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
91
+ Object.defineProperty(exports, '__esModule', {
92
+ value: true
93
+ });
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ PLAYWRIGHT_EXAMPLE_CODE: ()=>PLAYWRIGHT_EXAMPLE_CODE,
28
+ YAML_EXAMPLE_CODE: ()=>YAML_EXAMPLE_CODE
29
+ });
30
+ const PLAYWRIGHT_EXAMPLE_CODE = `
31
+ // Reference the following code to generate Rpascene test cases
32
+ // The following is test code for Rpascene AI, for reference
33
+ // The following is Playwright syntax, you can use Playwright to assist in test generation
34
+ IMPORTANT: Follow these exact type signatures for AI functions:
35
+
36
+ // Type signatures for AI functions:
37
+ aiInput(value: string, locator: string): Promise<void>
38
+ aiTap(locator: string): Promise<void>
39
+ aiDoubleClick(locator: string): Promise<void>
40
+ aiScroll(scrollParam: {
41
+ direction: 'up' | 'down' | 'left' | 'right',
42
+ scrollType: 'once' | 'untilBottom' | 'untilTop' | 'untilRight' | 'untilLeft',
43
+ distance: number - scroll distance, px is the unit
44
+ }): Promise<void>
45
+ aiAssert(assertion: string): Promise<void>
46
+ aiQuery<T>(queryObject: Record<string, string>): Promise<T> // Extracts data from page based on descriptions
47
+
48
+ // examples:
49
+ // Reference the following code to generate Rpascene test cases
50
+ // The following is test code for Rpascene AI, for reference
51
+ // The following is Playwright syntax, you can use Playwright to assist in test generation
52
+ import { test as base } from '@playwright/test';
53
+ import type { PlayWrightAiFixtureType } from '@rpascene/web/playwright';
54
+ import { PlaywrightAiFixture } from '@rpascene/web/playwright';
55
+
56
+ const test = base.extend<PlayWrightAiFixtureType>(PlaywrightAiFixture({
57
+ waitForNetworkIdleTimeout: 2000, // optional, the timeout for waiting for network idle between each action, default is 2000ms
58
+ }));
59
+
60
+
61
+ test.beforeEach(async ({ page }) => {
62
+ await page.goto('https://www.xxx.com/');
63
+ await page.setViewportSize({ width: 1920, height: 1080 });
64
+ });
65
+
66
+ test('ai shop', async ({
67
+ aiInput,
68
+ aiAssert,
69
+ aiQuery,
70
+ aiKeyboardPress,
71
+ aiHover,
72
+ aiTap,
73
+ agentForPage,
74
+ page,
75
+ }) => {
76
+ // login
77
+ await aiAssert('The page shows the login interface');
78
+ await aiInput('user_name', 'in user name input');
79
+ await aiInput('password', 'in password input');
80
+ await aiKeyboardPress('Enter', 'Login Button');
81
+
82
+ // check the login success
83
+ await aiWaitFor('The page shows that the loading is complete');
84
+ await aiAssert('The current page shows the product detail page');
85
+
86
+ // check the product info
87
+ const dataA = await aiQuery({
88
+ userInfo: 'User information in the format {name: string}',
89
+ theFirstProductInfo: 'The first product info in the format {name: string, price: number}',
90
+ });
91
+ expect(dataA.theFirstProductInfo.name).toBe('xxx');
92
+ expect(dataA.theFirstProductInfo.price).toBe(100);
93
+
94
+
95
+ // add to cart
96
+ await aiTap('click add to cart button');
97
+
98
+ await aiTap('click right top cart icon');
99
+ await aiAssert('The cart icon shows the number 1');
100
+ });
101
+ `;
102
+ const YAML_EXAMPLE_CODE = `
103
+ 1. Format:
104
+
105
+ web:
106
+ url: "starting_url"
107
+ viewportWidth: 1280
108
+ viewportHeight: 960
109
+
110
+ tasks:
111
+ - name: "descriptive task name"
112
+ flow:
113
+ - aiTap: "element description"
114
+ - aiInput: 'text value'
115
+ locate: 'input field description'
116
+ - aiScroll:
117
+ direction: down/up
118
+ scrollType: untilBottom/untilTop/page
119
+ - aiAssert: "expected state"
120
+ - sleep: milliseconds
121
+
122
+ 2. Action Types:
123
+ - aiTap: for clicks (natural language targeting)
124
+ - aiInput: for text input with 'locate' field
125
+ - aiScroll: with direction and scrollType
126
+ - aiAssert: for validations
127
+ - sleep: for delays (milliseconds)
128
+
129
+ 3. Best Practices:
130
+ - Group related actions into logical tasks
131
+ - Use natural language descriptions
132
+ - Add deepThink: true for complex interactions
133
+ - Keep task names concise but descriptive
134
+
135
+
136
+
137
+ YAML type
138
+ tasks:
139
+ - name: <name>
140
+ continueOnError: <boolean> # Optional, whether to continue to the next task on error, defaults to false.
141
+ flow:
142
+ # Auto Planning (.ai)
143
+ # ----------------
144
+
145
+ # Perform an interaction. \`ai\` is a shorthand for \`aiAction\`.
146
+ - ai: <prompt>
147
+ cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
148
+
149
+ # This usage is the same as \`ai\`.
150
+ - aiAction: <prompt>
151
+ cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
152
+
153
+ # Instant Action (.aiTap, .aiDoubleClick, .aiHover, .aiInput, .aiKeyboardPress, .aiScroll)
154
+ # ----------------
155
+
156
+ # Tap an element described by a prompt.
157
+ - aiTap: <prompt>
158
+ deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
159
+ xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided, Rpascene will prioritize this xpath to find the element before using the cache and the AI model. Defaults to empty.
160
+ cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
161
+
162
+ # Double click an element described by a prompt.
163
+ - aiDoubleClick: <prompt>
164
+ deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
165
+ xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided, Rpascene will prioritize this xpath to find the element before using the cache and the AI model. Defaults to empty.
166
+ cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
167
+
168
+ # Hover over an element described by a prompt.
169
+ - aiHover: <prompt>
170
+ deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
171
+ xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided, Rpascene will prioritize this xpath to find the element before using the cache and the AI model. Defaults to empty.
172
+ cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
173
+
174
+ # Input text into an element described by a prompt.
175
+ - aiInput: <final text content of the input>
176
+ locate: <prompt>
177
+ deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
178
+ xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided, Rpascene will prioritize this xpath to find the element before using the cache and the AI model. Defaults to empty.
179
+ cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
180
+
181
+ # Press a key (e.g., Enter, Tab, Escape) on an element described by a prompt.
182
+ - aiKeyboardPress: <key>
183
+ locate: <prompt>
184
+ deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
185
+ xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided, Rpascene will prioritize this xpath to find the element before using the cache and the AI model. Defaults to empty.
186
+ cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
187
+
188
+ # Scroll globally or on an element described by a prompt.
189
+ - aiScroll:
190
+ direction: 'up' # or 'down' | 'left' | 'right'
191
+ scrollType: 'once' # or 'untilTop' | 'untilBottom' | 'untilLeft' | 'untilRight'
192
+ distance: <number> # Optional, the scroll distance in pixels.
193
+ locate: <prompt> # Optional, the element to scroll on.
194
+ deepThink: <boolean> # Optional, whether to use deepThink to precisely locate the element. Defaults to False.
195
+ xpath: <xpath> # Optional, the xpath of the target element for the operation. If provided, Rpascene will prioritize this xpath to find the element before using the cache and the AI model. Defaults to empty.
196
+ cacheable: <boolean> # Optional, whether to cache the result of this API call when the [caching feature](./caching.mdx) is enabled. Defaults to True.
197
+
198
+ # Log the current screenshot with a description in the report file.
199
+ - logScreenshot: <title> # Optional, the title of the screenshot. If not provided, the title will be 'untitled'.
200
+ content: <content> # Optional, the description of the screenshot.
201
+
202
+ # Data Extraction
203
+ # ----------------
204
+
205
+ # Perform a query that returns a JSON object.
206
+ - aiQuery: <prompt> # Remember to describe the format of the result in the prompt.
207
+ name: <name> # The key for the query result in the JSON output.
208
+
209
+ # More APIs
210
+ # ----------------
211
+
212
+ # Wait for a condition to be met, with a timeout (in ms, optional, defaults to 30000).
213
+ - aiWaitFor: <prompt>
214
+ timeout: <ms>
215
+
216
+ # Perform an assertion.
217
+ - aiAssert: <prompt>
218
+ errorMessage: <error-message> # Optional, the error message to print if the assertion fails.
219
+
220
+ # Wait for a specified amount of time.
221
+ - sleep: <ms>
222
+
223
+ # Execute a piece of JavaScript code in the web page context.
224
+ - javascript: <javascript>
225
+ name: <name> # Optional, assign a name to the return value, which will be used as a key in the JSON output.
226
+
227
+ - name: <name>
228
+ flow:
229
+ # ...
230
+ `;
231
+ exports.PLAYWRIGHT_EXAMPLE_CODE = __webpack_exports__.PLAYWRIGHT_EXAMPLE_CODE;
232
+ exports.YAML_EXAMPLE_CODE = __webpack_exports__.YAML_EXAMPLE_CODE;
233
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
234
+ "PLAYWRIGHT_EXAMPLE_CODE",
235
+ "YAML_EXAMPLE_CODE"
236
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
237
+ Object.defineProperty(exports, '__esModule', {
238
+ value: true
239
+ });