@midscene/shared 0.13.1 → 0.13.2-beta-20250401015137.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.
- package/dist/es/extractor-debug.js +0 -1
- package/dist/es/extractor.js +0 -1
- package/dist/es/fs.js +0 -1
- package/dist/es/logger.d.ts +6 -0
- package/dist/es/logger.js +72 -0
- package/dist/es/utils.d.ts +3 -6
- package/dist/es/utils.js +2 -12
- package/dist/lib/extractor-debug.js +0 -23
- package/dist/lib/extractor.js +0 -11
- package/dist/lib/fs.js +0 -1
- package/dist/lib/logger.d.ts +6 -0
- package/dist/lib/logger.js +109 -0
- package/dist/lib/utils.d.ts +3 -6
- package/dist/lib/utils.js +2 -24
- package/dist/script/htmlElement.js +0 -467
- package/dist/script/htmlElementDebug.js +0 -467
- package/dist/types/logger.d.ts +6 -0
- package/dist/types/utils.d.ts +3 -6
- package/package.json +7 -2
- package/src/common.ts +34 -0
- package/src/logger.ts +65 -0
- package/src/utils.ts +8 -17
|
@@ -570,472 +570,6 @@ var midscene_element_inspector = (() => {
|
|
|
570
570
|
}
|
|
571
571
|
});
|
|
572
572
|
|
|
573
|
-
// ../../node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js
|
|
574
|
-
var require_ms = __commonJS({
|
|
575
|
-
"../../node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js"(exports, module) {
|
|
576
|
-
"use strict";
|
|
577
|
-
var s = 1e3;
|
|
578
|
-
var m = s * 60;
|
|
579
|
-
var h = m * 60;
|
|
580
|
-
var d = h * 24;
|
|
581
|
-
var w = d * 7;
|
|
582
|
-
var y = d * 365.25;
|
|
583
|
-
module.exports = function(val, options) {
|
|
584
|
-
options = options || {};
|
|
585
|
-
var type = typeof val;
|
|
586
|
-
if (type === "string" && val.length > 0) {
|
|
587
|
-
return parse(val);
|
|
588
|
-
} else if (type === "number" && isFinite(val)) {
|
|
589
|
-
return options.long ? fmtLong(val) : fmtShort(val);
|
|
590
|
-
}
|
|
591
|
-
throw new Error(
|
|
592
|
-
"val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
|
|
593
|
-
);
|
|
594
|
-
};
|
|
595
|
-
function parse(str) {
|
|
596
|
-
str = String(str);
|
|
597
|
-
if (str.length > 100) {
|
|
598
|
-
return;
|
|
599
|
-
}
|
|
600
|
-
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
601
|
-
str
|
|
602
|
-
);
|
|
603
|
-
if (!match) {
|
|
604
|
-
return;
|
|
605
|
-
}
|
|
606
|
-
var n = parseFloat(match[1]);
|
|
607
|
-
var type = (match[2] || "ms").toLowerCase();
|
|
608
|
-
switch (type) {
|
|
609
|
-
case "years":
|
|
610
|
-
case "year":
|
|
611
|
-
case "yrs":
|
|
612
|
-
case "yr":
|
|
613
|
-
case "y":
|
|
614
|
-
return n * y;
|
|
615
|
-
case "weeks":
|
|
616
|
-
case "week":
|
|
617
|
-
case "w":
|
|
618
|
-
return n * w;
|
|
619
|
-
case "days":
|
|
620
|
-
case "day":
|
|
621
|
-
case "d":
|
|
622
|
-
return n * d;
|
|
623
|
-
case "hours":
|
|
624
|
-
case "hour":
|
|
625
|
-
case "hrs":
|
|
626
|
-
case "hr":
|
|
627
|
-
case "h":
|
|
628
|
-
return n * h;
|
|
629
|
-
case "minutes":
|
|
630
|
-
case "minute":
|
|
631
|
-
case "mins":
|
|
632
|
-
case "min":
|
|
633
|
-
case "m":
|
|
634
|
-
return n * m;
|
|
635
|
-
case "seconds":
|
|
636
|
-
case "second":
|
|
637
|
-
case "secs":
|
|
638
|
-
case "sec":
|
|
639
|
-
case "s":
|
|
640
|
-
return n * s;
|
|
641
|
-
case "milliseconds":
|
|
642
|
-
case "millisecond":
|
|
643
|
-
case "msecs":
|
|
644
|
-
case "msec":
|
|
645
|
-
case "ms":
|
|
646
|
-
return n;
|
|
647
|
-
default:
|
|
648
|
-
return void 0;
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
function fmtShort(ms) {
|
|
652
|
-
var msAbs = Math.abs(ms);
|
|
653
|
-
if (msAbs >= d) {
|
|
654
|
-
return Math.round(ms / d) + "d";
|
|
655
|
-
}
|
|
656
|
-
if (msAbs >= h) {
|
|
657
|
-
return Math.round(ms / h) + "h";
|
|
658
|
-
}
|
|
659
|
-
if (msAbs >= m) {
|
|
660
|
-
return Math.round(ms / m) + "m";
|
|
661
|
-
}
|
|
662
|
-
if (msAbs >= s) {
|
|
663
|
-
return Math.round(ms / s) + "s";
|
|
664
|
-
}
|
|
665
|
-
return ms + "ms";
|
|
666
|
-
}
|
|
667
|
-
function fmtLong(ms) {
|
|
668
|
-
var msAbs = Math.abs(ms);
|
|
669
|
-
if (msAbs >= d) {
|
|
670
|
-
return plural(ms, msAbs, d, "day");
|
|
671
|
-
}
|
|
672
|
-
if (msAbs >= h) {
|
|
673
|
-
return plural(ms, msAbs, h, "hour");
|
|
674
|
-
}
|
|
675
|
-
if (msAbs >= m) {
|
|
676
|
-
return plural(ms, msAbs, m, "minute");
|
|
677
|
-
}
|
|
678
|
-
if (msAbs >= s) {
|
|
679
|
-
return plural(ms, msAbs, s, "second");
|
|
680
|
-
}
|
|
681
|
-
return ms + " ms";
|
|
682
|
-
}
|
|
683
|
-
function plural(ms, msAbs, n, name) {
|
|
684
|
-
var isPlural = msAbs >= n * 1.5;
|
|
685
|
-
return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
});
|
|
689
|
-
|
|
690
|
-
// ../../node_modules/.pnpm/debug@4.4.0_supports-color@5.5.0/node_modules/debug/src/common.js
|
|
691
|
-
var require_common = __commonJS({
|
|
692
|
-
"../../node_modules/.pnpm/debug@4.4.0_supports-color@5.5.0/node_modules/debug/src/common.js"(exports, module) {
|
|
693
|
-
"use strict";
|
|
694
|
-
function setup(env) {
|
|
695
|
-
createDebug.debug = createDebug;
|
|
696
|
-
createDebug.default = createDebug;
|
|
697
|
-
createDebug.coerce = coerce;
|
|
698
|
-
createDebug.disable = disable;
|
|
699
|
-
createDebug.enable = enable;
|
|
700
|
-
createDebug.enabled = enabled;
|
|
701
|
-
createDebug.humanize = require_ms();
|
|
702
|
-
createDebug.destroy = destroy;
|
|
703
|
-
Object.keys(env).forEach((key) => {
|
|
704
|
-
createDebug[key] = env[key];
|
|
705
|
-
});
|
|
706
|
-
createDebug.names = [];
|
|
707
|
-
createDebug.skips = [];
|
|
708
|
-
createDebug.formatters = {};
|
|
709
|
-
function selectColor(namespace) {
|
|
710
|
-
let hash = 0;
|
|
711
|
-
for (let i = 0; i < namespace.length; i++) {
|
|
712
|
-
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
713
|
-
hash |= 0;
|
|
714
|
-
}
|
|
715
|
-
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
716
|
-
}
|
|
717
|
-
createDebug.selectColor = selectColor;
|
|
718
|
-
function createDebug(namespace) {
|
|
719
|
-
let prevTime;
|
|
720
|
-
let enableOverride = null;
|
|
721
|
-
let namespacesCache;
|
|
722
|
-
let enabledCache;
|
|
723
|
-
function debug2(...args) {
|
|
724
|
-
if (!debug2.enabled) {
|
|
725
|
-
return;
|
|
726
|
-
}
|
|
727
|
-
const self2 = debug2;
|
|
728
|
-
const curr = Number(/* @__PURE__ */ new Date());
|
|
729
|
-
const ms = curr - (prevTime || curr);
|
|
730
|
-
self2.diff = ms;
|
|
731
|
-
self2.prev = prevTime;
|
|
732
|
-
self2.curr = curr;
|
|
733
|
-
prevTime = curr;
|
|
734
|
-
args[0] = createDebug.coerce(args[0]);
|
|
735
|
-
if (typeof args[0] !== "string") {
|
|
736
|
-
args.unshift("%O");
|
|
737
|
-
}
|
|
738
|
-
let index = 0;
|
|
739
|
-
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
740
|
-
if (match === "%%") {
|
|
741
|
-
return "%";
|
|
742
|
-
}
|
|
743
|
-
index++;
|
|
744
|
-
const formatter = createDebug.formatters[format];
|
|
745
|
-
if (typeof formatter === "function") {
|
|
746
|
-
const val = args[index];
|
|
747
|
-
match = formatter.call(self2, val);
|
|
748
|
-
args.splice(index, 1);
|
|
749
|
-
index--;
|
|
750
|
-
}
|
|
751
|
-
return match;
|
|
752
|
-
});
|
|
753
|
-
createDebug.formatArgs.call(self2, args);
|
|
754
|
-
const logFn = self2.log || createDebug.log;
|
|
755
|
-
logFn.apply(self2, args);
|
|
756
|
-
}
|
|
757
|
-
debug2.namespace = namespace;
|
|
758
|
-
debug2.useColors = createDebug.useColors();
|
|
759
|
-
debug2.color = createDebug.selectColor(namespace);
|
|
760
|
-
debug2.extend = extend;
|
|
761
|
-
debug2.destroy = createDebug.destroy;
|
|
762
|
-
Object.defineProperty(debug2, "enabled", {
|
|
763
|
-
enumerable: true,
|
|
764
|
-
configurable: false,
|
|
765
|
-
get: () => {
|
|
766
|
-
if (enableOverride !== null) {
|
|
767
|
-
return enableOverride;
|
|
768
|
-
}
|
|
769
|
-
if (namespacesCache !== createDebug.namespaces) {
|
|
770
|
-
namespacesCache = createDebug.namespaces;
|
|
771
|
-
enabledCache = createDebug.enabled(namespace);
|
|
772
|
-
}
|
|
773
|
-
return enabledCache;
|
|
774
|
-
},
|
|
775
|
-
set: (v) => {
|
|
776
|
-
enableOverride = v;
|
|
777
|
-
}
|
|
778
|
-
});
|
|
779
|
-
if (typeof createDebug.init === "function") {
|
|
780
|
-
createDebug.init(debug2);
|
|
781
|
-
}
|
|
782
|
-
return debug2;
|
|
783
|
-
}
|
|
784
|
-
function extend(namespace, delimiter) {
|
|
785
|
-
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
|
|
786
|
-
newDebug.log = this.log;
|
|
787
|
-
return newDebug;
|
|
788
|
-
}
|
|
789
|
-
function enable(namespaces) {
|
|
790
|
-
createDebug.save(namespaces);
|
|
791
|
-
createDebug.namespaces = namespaces;
|
|
792
|
-
createDebug.names = [];
|
|
793
|
-
createDebug.skips = [];
|
|
794
|
-
const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(" ", ",").split(",").filter(Boolean);
|
|
795
|
-
for (const ns of split) {
|
|
796
|
-
if (ns[0] === "-") {
|
|
797
|
-
createDebug.skips.push(ns.slice(1));
|
|
798
|
-
} else {
|
|
799
|
-
createDebug.names.push(ns);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
function matchesTemplate(search, template) {
|
|
804
|
-
let searchIndex = 0;
|
|
805
|
-
let templateIndex = 0;
|
|
806
|
-
let starIndex = -1;
|
|
807
|
-
let matchIndex = 0;
|
|
808
|
-
while (searchIndex < search.length) {
|
|
809
|
-
if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
|
|
810
|
-
if (template[templateIndex] === "*") {
|
|
811
|
-
starIndex = templateIndex;
|
|
812
|
-
matchIndex = searchIndex;
|
|
813
|
-
templateIndex++;
|
|
814
|
-
} else {
|
|
815
|
-
searchIndex++;
|
|
816
|
-
templateIndex++;
|
|
817
|
-
}
|
|
818
|
-
} else if (starIndex !== -1) {
|
|
819
|
-
templateIndex = starIndex + 1;
|
|
820
|
-
matchIndex++;
|
|
821
|
-
searchIndex = matchIndex;
|
|
822
|
-
} else {
|
|
823
|
-
return false;
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
while (templateIndex < template.length && template[templateIndex] === "*") {
|
|
827
|
-
templateIndex++;
|
|
828
|
-
}
|
|
829
|
-
return templateIndex === template.length;
|
|
830
|
-
}
|
|
831
|
-
function disable() {
|
|
832
|
-
const namespaces = [
|
|
833
|
-
...createDebug.names,
|
|
834
|
-
...createDebug.skips.map((namespace) => "-" + namespace)
|
|
835
|
-
].join(",");
|
|
836
|
-
createDebug.enable("");
|
|
837
|
-
return namespaces;
|
|
838
|
-
}
|
|
839
|
-
function enabled(name) {
|
|
840
|
-
for (const skip of createDebug.skips) {
|
|
841
|
-
if (matchesTemplate(name, skip)) {
|
|
842
|
-
return false;
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
for (const ns of createDebug.names) {
|
|
846
|
-
if (matchesTemplate(name, ns)) {
|
|
847
|
-
return true;
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
return false;
|
|
851
|
-
}
|
|
852
|
-
function coerce(val) {
|
|
853
|
-
if (val instanceof Error) {
|
|
854
|
-
return val.stack || val.message;
|
|
855
|
-
}
|
|
856
|
-
return val;
|
|
857
|
-
}
|
|
858
|
-
function destroy() {
|
|
859
|
-
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
860
|
-
}
|
|
861
|
-
createDebug.enable(createDebug.load());
|
|
862
|
-
return createDebug;
|
|
863
|
-
}
|
|
864
|
-
module.exports = setup;
|
|
865
|
-
}
|
|
866
|
-
});
|
|
867
|
-
|
|
868
|
-
// ../../node_modules/.pnpm/debug@4.4.0_supports-color@5.5.0/node_modules/debug/src/browser.js
|
|
869
|
-
var require_browser = __commonJS({
|
|
870
|
-
"../../node_modules/.pnpm/debug@4.4.0_supports-color@5.5.0/node_modules/debug/src/browser.js"(exports, module) {
|
|
871
|
-
"use strict";
|
|
872
|
-
exports.formatArgs = formatArgs;
|
|
873
|
-
exports.save = save;
|
|
874
|
-
exports.load = load;
|
|
875
|
-
exports.useColors = useColors;
|
|
876
|
-
exports.storage = localstorage();
|
|
877
|
-
exports.destroy = (() => {
|
|
878
|
-
let warned = false;
|
|
879
|
-
return () => {
|
|
880
|
-
if (!warned) {
|
|
881
|
-
warned = true;
|
|
882
|
-
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
883
|
-
}
|
|
884
|
-
};
|
|
885
|
-
})();
|
|
886
|
-
exports.colors = [
|
|
887
|
-
"#0000CC",
|
|
888
|
-
"#0000FF",
|
|
889
|
-
"#0033CC",
|
|
890
|
-
"#0033FF",
|
|
891
|
-
"#0066CC",
|
|
892
|
-
"#0066FF",
|
|
893
|
-
"#0099CC",
|
|
894
|
-
"#0099FF",
|
|
895
|
-
"#00CC00",
|
|
896
|
-
"#00CC33",
|
|
897
|
-
"#00CC66",
|
|
898
|
-
"#00CC99",
|
|
899
|
-
"#00CCCC",
|
|
900
|
-
"#00CCFF",
|
|
901
|
-
"#3300CC",
|
|
902
|
-
"#3300FF",
|
|
903
|
-
"#3333CC",
|
|
904
|
-
"#3333FF",
|
|
905
|
-
"#3366CC",
|
|
906
|
-
"#3366FF",
|
|
907
|
-
"#3399CC",
|
|
908
|
-
"#3399FF",
|
|
909
|
-
"#33CC00",
|
|
910
|
-
"#33CC33",
|
|
911
|
-
"#33CC66",
|
|
912
|
-
"#33CC99",
|
|
913
|
-
"#33CCCC",
|
|
914
|
-
"#33CCFF",
|
|
915
|
-
"#6600CC",
|
|
916
|
-
"#6600FF",
|
|
917
|
-
"#6633CC",
|
|
918
|
-
"#6633FF",
|
|
919
|
-
"#66CC00",
|
|
920
|
-
"#66CC33",
|
|
921
|
-
"#9900CC",
|
|
922
|
-
"#9900FF",
|
|
923
|
-
"#9933CC",
|
|
924
|
-
"#9933FF",
|
|
925
|
-
"#99CC00",
|
|
926
|
-
"#99CC33",
|
|
927
|
-
"#CC0000",
|
|
928
|
-
"#CC0033",
|
|
929
|
-
"#CC0066",
|
|
930
|
-
"#CC0099",
|
|
931
|
-
"#CC00CC",
|
|
932
|
-
"#CC00FF",
|
|
933
|
-
"#CC3300",
|
|
934
|
-
"#CC3333",
|
|
935
|
-
"#CC3366",
|
|
936
|
-
"#CC3399",
|
|
937
|
-
"#CC33CC",
|
|
938
|
-
"#CC33FF",
|
|
939
|
-
"#CC6600",
|
|
940
|
-
"#CC6633",
|
|
941
|
-
"#CC9900",
|
|
942
|
-
"#CC9933",
|
|
943
|
-
"#CCCC00",
|
|
944
|
-
"#CCCC33",
|
|
945
|
-
"#FF0000",
|
|
946
|
-
"#FF0033",
|
|
947
|
-
"#FF0066",
|
|
948
|
-
"#FF0099",
|
|
949
|
-
"#FF00CC",
|
|
950
|
-
"#FF00FF",
|
|
951
|
-
"#FF3300",
|
|
952
|
-
"#FF3333",
|
|
953
|
-
"#FF3366",
|
|
954
|
-
"#FF3399",
|
|
955
|
-
"#FF33CC",
|
|
956
|
-
"#FF33FF",
|
|
957
|
-
"#FF6600",
|
|
958
|
-
"#FF6633",
|
|
959
|
-
"#FF9900",
|
|
960
|
-
"#FF9933",
|
|
961
|
-
"#FFCC00",
|
|
962
|
-
"#FFCC33"
|
|
963
|
-
];
|
|
964
|
-
function useColors() {
|
|
965
|
-
if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
|
|
966
|
-
return true;
|
|
967
|
-
}
|
|
968
|
-
if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
969
|
-
return false;
|
|
970
|
-
}
|
|
971
|
-
let m;
|
|
972
|
-
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
|
|
973
|
-
typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
|
|
974
|
-
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
975
|
-
typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
|
|
976
|
-
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
977
|
-
}
|
|
978
|
-
function formatArgs(args) {
|
|
979
|
-
args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
|
|
980
|
-
if (!this.useColors) {
|
|
981
|
-
return;
|
|
982
|
-
}
|
|
983
|
-
const c = "color: " + this.color;
|
|
984
|
-
args.splice(1, 0, c, "color: inherit");
|
|
985
|
-
let index = 0;
|
|
986
|
-
let lastC = 0;
|
|
987
|
-
args[0].replace(/%[a-zA-Z%]/g, (match) => {
|
|
988
|
-
if (match === "%%") {
|
|
989
|
-
return;
|
|
990
|
-
}
|
|
991
|
-
index++;
|
|
992
|
-
if (match === "%c") {
|
|
993
|
-
lastC = index;
|
|
994
|
-
}
|
|
995
|
-
});
|
|
996
|
-
args.splice(lastC, 0, c);
|
|
997
|
-
}
|
|
998
|
-
exports.log = console.debug || console.log || (() => {
|
|
999
|
-
});
|
|
1000
|
-
function save(namespaces) {
|
|
1001
|
-
try {
|
|
1002
|
-
if (namespaces) {
|
|
1003
|
-
exports.storage.setItem("debug", namespaces);
|
|
1004
|
-
} else {
|
|
1005
|
-
exports.storage.removeItem("debug");
|
|
1006
|
-
}
|
|
1007
|
-
} catch (error) {
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
function load() {
|
|
1011
|
-
let r;
|
|
1012
|
-
try {
|
|
1013
|
-
r = exports.storage.getItem("debug");
|
|
1014
|
-
} catch (error) {
|
|
1015
|
-
}
|
|
1016
|
-
if (!r && typeof process !== "undefined" && "env" in process) {
|
|
1017
|
-
r = process.env.DEBUG;
|
|
1018
|
-
}
|
|
1019
|
-
return r;
|
|
1020
|
-
}
|
|
1021
|
-
function localstorage() {
|
|
1022
|
-
try {
|
|
1023
|
-
return localStorage;
|
|
1024
|
-
} catch (error) {
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
module.exports = require_common()(exports);
|
|
1028
|
-
var { formatters } = module.exports;
|
|
1029
|
-
formatters.j = function(v) {
|
|
1030
|
-
try {
|
|
1031
|
-
return JSON.stringify(v);
|
|
1032
|
-
} catch (error) {
|
|
1033
|
-
return "[UnexpectedJSONParseError]: " + error.message;
|
|
1034
|
-
}
|
|
1035
|
-
};
|
|
1036
|
-
}
|
|
1037
|
-
});
|
|
1038
|
-
|
|
1039
573
|
// src/constants/index.ts
|
|
1040
574
|
var CONTAINER_MINI_HEIGHT = 3;
|
|
1041
575
|
var CONTAINER_MINI_WIDTH = 3;
|
|
@@ -1110,7 +644,6 @@ var midscene_element_inspector = (() => {
|
|
|
1110
644
|
|
|
1111
645
|
// src/utils.ts
|
|
1112
646
|
var import_js_sha256 = __toESM(require_sha256());
|
|
1113
|
-
var import_debug = __toESM(require_browser());
|
|
1114
647
|
var hashMap = {};
|
|
1115
648
|
function generateHashId(rect, content = "") {
|
|
1116
649
|
const combined = JSON.stringify({
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type DebugFunction = (...args: unknown[]) => void;
|
|
2
|
+
declare function getDebug(topic: string): DebugFunction;
|
|
3
|
+
declare function enableDebug(topic: string): void;
|
|
4
|
+
declare function cleanupLogStreams(): void;
|
|
5
|
+
|
|
6
|
+
export { type DebugFunction, cleanupLogStreams, enableDebug, getDebug };
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import debug from 'debug';
|
|
2
|
-
|
|
3
1
|
declare const ifInBrowser: boolean;
|
|
4
2
|
declare function uuid(): string;
|
|
5
|
-
declare function getDebug(topic: string): debug.Debugger;
|
|
6
|
-
declare function enableDebug(topic: string): void;
|
|
7
3
|
declare function generateHashId(rect: any, content?: string): string;
|
|
8
4
|
/**
|
|
9
5
|
* A utility function that asserts a condition and throws an error with a message if the condition is false.
|
|
@@ -13,6 +9,7 @@ declare function generateHashId(rect: any, content?: string): string;
|
|
|
13
9
|
* @throws Error with the provided message if the condition is false
|
|
14
10
|
*/
|
|
15
11
|
declare function assert(condition: any, message?: string): asserts condition;
|
|
16
|
-
|
|
12
|
+
type GlobalScope = typeof window | typeof globalThis | typeof self | undefined;
|
|
13
|
+
declare function getGlobalScope(): GlobalScope;
|
|
17
14
|
|
|
18
|
-
export { assert,
|
|
15
|
+
export { assert, generateHashId, getGlobalScope, ifInBrowser, uuid };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/shared",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2-beta-20250401015137.0",
|
|
4
4
|
"repository": "https://github.com/web-infra-dev/midscene",
|
|
5
5
|
"homepage": "https://midscenejs.com/",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"./utils": "./dist/lib/utils.js",
|
|
15
15
|
"./extractor": "./dist/lib/extractor.js",
|
|
16
16
|
"./extractor-debug": "./dist/lib/extractor-debug.js",
|
|
17
|
-
"./keyboard-layout": "./dist/lib/us-keyboard-layout.js"
|
|
17
|
+
"./keyboard-layout": "./dist/lib/us-keyboard-layout.js",
|
|
18
|
+
"./logger": "./dist/lib/logger.js"
|
|
18
19
|
},
|
|
19
20
|
"typesVersions": {
|
|
20
21
|
"*": {
|
|
@@ -41,6 +42,9 @@
|
|
|
41
42
|
],
|
|
42
43
|
"keyboard-layout": [
|
|
43
44
|
"./dist/types/us-keyboard-layout.d.ts"
|
|
45
|
+
],
|
|
46
|
+
"logger": [
|
|
47
|
+
"./dist/types/logger.d.ts"
|
|
44
48
|
]
|
|
45
49
|
}
|
|
46
50
|
},
|
|
@@ -58,6 +62,7 @@
|
|
|
58
62
|
"@modern-js/module-tools": "2.60.6",
|
|
59
63
|
"@types/debug": "4.1.12",
|
|
60
64
|
"@types/node": "^18.0.0",
|
|
65
|
+
"dotenv": "16.4.5",
|
|
61
66
|
"rimraf": "~3.0.2",
|
|
62
67
|
"typescript": "^5.8.2",
|
|
63
68
|
"vitest": "3.0.5"
|
package/src/common.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
// Define locally for now to avoid import issues
|
|
5
|
+
export const isNodeEnv =
|
|
6
|
+
typeof process !== 'undefined' &&
|
|
7
|
+
process.versions != null &&
|
|
8
|
+
process.versions.node != null;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get the path to the midscene_run directory or a subdirectory within it.
|
|
12
|
+
* Creates the directory if it doesn't exist.
|
|
13
|
+
*
|
|
14
|
+
* @param subdir - Optional subdirectory name (e.g., 'log', 'report')
|
|
15
|
+
* @returns The absolute path to the requested directory
|
|
16
|
+
*/
|
|
17
|
+
export const getMidsceneRunLogPath = (): string => {
|
|
18
|
+
const basePath = path.join(process.cwd(), 'midscene_run');
|
|
19
|
+
|
|
20
|
+
// Create a base directory
|
|
21
|
+
if (!fs.existsSync(basePath)) {
|
|
22
|
+
fs.mkdirSync(basePath, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Create a log directory
|
|
26
|
+
const logPath = path.join(basePath, 'log');
|
|
27
|
+
if (!fs.existsSync(logPath)) {
|
|
28
|
+
fs.mkdirSync(logPath, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return logPath;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const logDir = isNodeEnv ? getMidsceneRunLogPath() : '';
|
package/src/logger.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import debug from 'debug';
|
|
4
|
+
import { isNodeEnv, logDir } from './common';
|
|
5
|
+
|
|
6
|
+
const topicPrefix = 'midscene';
|
|
7
|
+
// Map to store file streams
|
|
8
|
+
const logStreams = new Map<string, fs.WriteStream>();
|
|
9
|
+
|
|
10
|
+
// Function to get or create a log stream
|
|
11
|
+
function getLogStream(topic: string): fs.WriteStream {
|
|
12
|
+
if (!logStreams.has(topic)) {
|
|
13
|
+
const logFile = path.join(logDir, `${topic}.log`);
|
|
14
|
+
const stream = fs.createWriteStream(logFile, { flags: 'a' });
|
|
15
|
+
logStreams.set(topic, stream);
|
|
16
|
+
}
|
|
17
|
+
return logStreams.get(topic)!;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Function to write log to file
|
|
21
|
+
function writeLogToFile(topic: string, message: string): void {
|
|
22
|
+
if (!isNodeEnv) return;
|
|
23
|
+
|
|
24
|
+
const stream = getLogStream(topic);
|
|
25
|
+
const timestamp = new Date().toISOString();
|
|
26
|
+
stream.write(`[${timestamp}] ${message}\n`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type DebugFunction = (...args: unknown[]) => void;
|
|
30
|
+
|
|
31
|
+
export function getDebug(topic: string): DebugFunction {
|
|
32
|
+
// Create a wrapper function that handles both file logging and debug output
|
|
33
|
+
return (...args: unknown[]): void => {
|
|
34
|
+
const message = args
|
|
35
|
+
.map((arg) =>
|
|
36
|
+
typeof arg === 'object' ? JSON.stringify(arg) : String(arg),
|
|
37
|
+
)
|
|
38
|
+
.join(' ');
|
|
39
|
+
|
|
40
|
+
if (isNodeEnv) {
|
|
41
|
+
writeLogToFile(topic, message);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const debugFn = debug(`${topicPrefix}:${topic}`) as DebugFunction;
|
|
45
|
+
debugFn(...args);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function enableDebug(topic: string): void {
|
|
50
|
+
if (isNodeEnv) {
|
|
51
|
+
// In Node.js, we don't need to enable debug as we're using file logging
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
debug.enable(`${topicPrefix}:${topic}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Cleanup function to close all log streams
|
|
58
|
+
export function cleanupLogStreams(): void {
|
|
59
|
+
if (!isNodeEnv) return;
|
|
60
|
+
|
|
61
|
+
for (const stream of logStreams.values()) {
|
|
62
|
+
stream.end();
|
|
63
|
+
}
|
|
64
|
+
logStreams.clear();
|
|
65
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -1,25 +1,14 @@
|
|
|
1
1
|
import { sha256 } from 'js-sha256';
|
|
2
2
|
|
|
3
|
-
import debug from 'debug';
|
|
4
|
-
|
|
5
3
|
export const ifInBrowser = typeof window !== 'undefined';
|
|
6
4
|
|
|
7
|
-
export function uuid() {
|
|
5
|
+
export function uuid(): string {
|
|
8
6
|
return Math.random().toString(36).substring(2, 15);
|
|
9
7
|
}
|
|
10
8
|
|
|
11
9
|
const hashMap: Record<string, string> = {}; // id - combined
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
export function getDebug(topic: string) {
|
|
15
|
-
return debug(`${topicPrefix}:${topic}`);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function enableDebug(topic: string) {
|
|
19
|
-
debug.enable(`${topicPrefix}:${topic}`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function generateHashId(rect: any, content = '') {
|
|
11
|
+
export function generateHashId(rect: any, content = ''): string {
|
|
23
12
|
// Combine the input into a string
|
|
24
13
|
const combined = JSON.stringify({
|
|
25
14
|
content,
|
|
@@ -32,7 +21,7 @@ export function generateHashId(rect: any, content = '') {
|
|
|
32
21
|
const hashHex = sha256.create().update(combined).hex();
|
|
33
22
|
|
|
34
23
|
// Convert hex to a-z by mapping each hex char to a letter
|
|
35
|
-
const toLetters = (hex: string) => {
|
|
24
|
+
const toLetters = (hex: string): string => {
|
|
36
25
|
return hex
|
|
37
26
|
.split('')
|
|
38
27
|
.map((char) => {
|
|
@@ -69,13 +58,15 @@ export function assert(condition: any, message?: string): asserts condition {
|
|
|
69
58
|
}
|
|
70
59
|
}
|
|
71
60
|
|
|
72
|
-
|
|
61
|
+
type GlobalScope = typeof window | typeof globalThis | typeof self | undefined;
|
|
62
|
+
|
|
63
|
+
export function getGlobalScope(): GlobalScope {
|
|
73
64
|
if (typeof window !== 'undefined') {
|
|
74
65
|
return window;
|
|
75
66
|
}
|
|
76
67
|
|
|
77
|
-
if (typeof
|
|
78
|
-
return
|
|
68
|
+
if (typeof globalThis !== 'undefined') {
|
|
69
|
+
return globalThis;
|
|
79
70
|
}
|
|
80
71
|
|
|
81
72
|
if (typeof self !== 'undefined') {
|