@putkoff/abstract-utilities 0.1.241 → 0.1.243

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/esm/index.js CHANGED
@@ -1,5 +1,9 @@
1
1
  export { useCallback, useEffect, useRef, useState } from 'react';
2
- import path from 'path';
2
+ import path$2 from 'path';
3
+ import * as path$1 from 'path-browserify';
4
+ import * as fs from 'node:fs';
5
+ import * as fsp from 'node:fs/promises';
6
+ import * as path from 'node:path';
3
7
  import { jsx, jsxs } from 'react/jsx-runtime';
4
8
 
5
9
  function getSafeDocument() {
@@ -600,7 +604,7 @@ function get_full_path(partial_path, parent_dir = null) {
600
604
  if (typeof partial_path !== 'string') {
601
605
  throw new Error('partial_path must be a string');
602
606
  }
603
- if (path.isAbsolute(partial_path)) {
607
+ if (path$2.isAbsolute(partial_path)) {
604
608
  return partial_path;
605
609
  }
606
610
  return urlJoin(parent_dir, partial_path);
@@ -615,7 +619,7 @@ function path_to_url(filePath, all_paths) {
615
619
  }
616
620
  for (const key in all_paths) {
617
621
  const mapping = all_paths[key];
618
- const normalizedBase = path.normalize(mapping.path);
622
+ const normalizedBase = path$2.normalize(mapping.path);
619
623
  if (filePath.startsWith(normalizedBase)) {
620
624
  const relativePath = filePath.substring(normalizedBase.length);
621
625
  return urlJoin(mapping.url, relativePath.replace(/\\/g, '/'));
@@ -641,508 +645,6 @@ function url_to_path(urlStr, all_paths) {
641
645
  return null;
642
646
  }
643
647
 
644
- function assertPath(path) {
645
- if (typeof path !== 'string') {
646
- throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
647
- }
648
- }
649
-
650
- // Resolves . and .. elements in a path with directory names
651
- function normalizeStringPosix(path, allowAboveRoot) {
652
- var res = '';
653
- var lastSegmentLength = 0;
654
- var lastSlash = -1;
655
- var dots = 0;
656
- var code;
657
- for (var i = 0; i <= path.length; ++i) {
658
- if (i < path.length)
659
- code = path.charCodeAt(i);
660
- else if (code === 47 /*/*/)
661
- break;
662
- else
663
- code = 47 /*/*/;
664
- if (code === 47 /*/*/) {
665
- if (lastSlash === i - 1 || dots === 1) ; else if (lastSlash !== i - 1 && dots === 2) {
666
- if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
667
- if (res.length > 2) {
668
- var lastSlashIndex = res.lastIndexOf('/');
669
- if (lastSlashIndex !== res.length - 1) {
670
- if (lastSlashIndex === -1) {
671
- res = '';
672
- lastSegmentLength = 0;
673
- } else {
674
- res = res.slice(0, lastSlashIndex);
675
- lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
676
- }
677
- lastSlash = i;
678
- dots = 0;
679
- continue;
680
- }
681
- } else if (res.length === 2 || res.length === 1) {
682
- res = '';
683
- lastSegmentLength = 0;
684
- lastSlash = i;
685
- dots = 0;
686
- continue;
687
- }
688
- }
689
- if (allowAboveRoot) {
690
- if (res.length > 0)
691
- res += '/..';
692
- else
693
- res = '..';
694
- lastSegmentLength = 2;
695
- }
696
- } else {
697
- if (res.length > 0)
698
- res += '/' + path.slice(lastSlash + 1, i);
699
- else
700
- res = path.slice(lastSlash + 1, i);
701
- lastSegmentLength = i - lastSlash - 1;
702
- }
703
- lastSlash = i;
704
- dots = 0;
705
- } else if (code === 46 /*.*/ && dots !== -1) {
706
- ++dots;
707
- } else {
708
- dots = -1;
709
- }
710
- }
711
- return res;
712
- }
713
-
714
- function _format(sep, pathObject) {
715
- var dir = pathObject.dir || pathObject.root;
716
- var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
717
- if (!dir) {
718
- return base;
719
- }
720
- if (dir === pathObject.root) {
721
- return dir + base;
722
- }
723
- return dir + sep + base;
724
- }
725
-
726
- var posix = {
727
- // path.resolve([from ...], to)
728
- resolve: function resolve() {
729
- var resolvedPath = '';
730
- var resolvedAbsolute = false;
731
- var cwd;
732
-
733
- for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
734
- var path;
735
- if (i >= 0)
736
- path = arguments[i];
737
- else {
738
- if (cwd === undefined)
739
- cwd = process.cwd();
740
- path = cwd;
741
- }
742
-
743
- assertPath(path);
744
-
745
- // Skip empty entries
746
- if (path.length === 0) {
747
- continue;
748
- }
749
-
750
- resolvedPath = path + '/' + resolvedPath;
751
- resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
752
- }
753
-
754
- // At this point the path should be resolved to a full absolute path, but
755
- // handle relative paths to be safe (might happen when process.cwd() fails)
756
-
757
- // Normalize the path
758
- resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
759
-
760
- if (resolvedAbsolute) {
761
- if (resolvedPath.length > 0)
762
- return '/' + resolvedPath;
763
- else
764
- return '/';
765
- } else if (resolvedPath.length > 0) {
766
- return resolvedPath;
767
- } else {
768
- return '.';
769
- }
770
- },
771
-
772
- normalize: function normalize(path) {
773
- assertPath(path);
774
-
775
- if (path.length === 0) return '.';
776
-
777
- var isAbsolute = path.charCodeAt(0) === 47 /*/*/;
778
- var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/;
779
-
780
- // Normalize the path
781
- path = normalizeStringPosix(path, !isAbsolute);
782
-
783
- if (path.length === 0 && !isAbsolute) path = '.';
784
- if (path.length > 0 && trailingSeparator) path += '/';
785
-
786
- if (isAbsolute) return '/' + path;
787
- return path;
788
- },
789
-
790
- isAbsolute: function isAbsolute(path) {
791
- assertPath(path);
792
- return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
793
- },
794
-
795
- join: function join() {
796
- if (arguments.length === 0)
797
- return '.';
798
- var joined;
799
- for (var i = 0; i < arguments.length; ++i) {
800
- var arg = arguments[i];
801
- assertPath(arg);
802
- if (arg.length > 0) {
803
- if (joined === undefined)
804
- joined = arg;
805
- else
806
- joined += '/' + arg;
807
- }
808
- }
809
- if (joined === undefined)
810
- return '.';
811
- return posix.normalize(joined);
812
- },
813
-
814
- relative: function relative(from, to) {
815
- assertPath(from);
816
- assertPath(to);
817
-
818
- if (from === to) return '';
819
-
820
- from = posix.resolve(from);
821
- to = posix.resolve(to);
822
-
823
- if (from === to) return '';
824
-
825
- // Trim any leading backslashes
826
- var fromStart = 1;
827
- for (; fromStart < from.length; ++fromStart) {
828
- if (from.charCodeAt(fromStart) !== 47 /*/*/)
829
- break;
830
- }
831
- var fromEnd = from.length;
832
- var fromLen = fromEnd - fromStart;
833
-
834
- // Trim any leading backslashes
835
- var toStart = 1;
836
- for (; toStart < to.length; ++toStart) {
837
- if (to.charCodeAt(toStart) !== 47 /*/*/)
838
- break;
839
- }
840
- var toEnd = to.length;
841
- var toLen = toEnd - toStart;
842
-
843
- // Compare paths to find the longest common path from root
844
- var length = fromLen < toLen ? fromLen : toLen;
845
- var lastCommonSep = -1;
846
- var i = 0;
847
- for (; i <= length; ++i) {
848
- if (i === length) {
849
- if (toLen > length) {
850
- if (to.charCodeAt(toStart + i) === 47 /*/*/) {
851
- // We get here if `from` is the exact base path for `to`.
852
- // For example: from='/foo/bar'; to='/foo/bar/baz'
853
- return to.slice(toStart + i + 1);
854
- } else if (i === 0) {
855
- // We get here if `from` is the root
856
- // For example: from='/'; to='/foo'
857
- return to.slice(toStart + i);
858
- }
859
- } else if (fromLen > length) {
860
- if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
861
- // We get here if `to` is the exact base path for `from`.
862
- // For example: from='/foo/bar/baz'; to='/foo/bar'
863
- lastCommonSep = i;
864
- } else if (i === 0) {
865
- // We get here if `to` is the root.
866
- // For example: from='/foo'; to='/'
867
- lastCommonSep = 0;
868
- }
869
- }
870
- break;
871
- }
872
- var fromCode = from.charCodeAt(fromStart + i);
873
- var toCode = to.charCodeAt(toStart + i);
874
- if (fromCode !== toCode)
875
- break;
876
- else if (fromCode === 47 /*/*/)
877
- lastCommonSep = i;
878
- }
879
-
880
- var out = '';
881
- // Generate the relative path based on the path difference between `to`
882
- // and `from`
883
- for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
884
- if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) {
885
- if (out.length === 0)
886
- out += '..';
887
- else
888
- out += '/..';
889
- }
890
- }
891
-
892
- // Lastly, append the rest of the destination (`to`) path that comes after
893
- // the common path parts
894
- if (out.length > 0)
895
- return out + to.slice(toStart + lastCommonSep);
896
- else {
897
- toStart += lastCommonSep;
898
- if (to.charCodeAt(toStart) === 47 /*/*/)
899
- ++toStart;
900
- return to.slice(toStart);
901
- }
902
- },
903
-
904
- _makeLong: function _makeLong(path) {
905
- return path;
906
- },
907
-
908
- dirname: function dirname(path) {
909
- assertPath(path);
910
- if (path.length === 0) return '.';
911
- var code = path.charCodeAt(0);
912
- var hasRoot = code === 47 /*/*/;
913
- var end = -1;
914
- var matchedSlash = true;
915
- for (var i = path.length - 1; i >= 1; --i) {
916
- code = path.charCodeAt(i);
917
- if (code === 47 /*/*/) {
918
- if (!matchedSlash) {
919
- end = i;
920
- break;
921
- }
922
- } else {
923
- // We saw the first non-path separator
924
- matchedSlash = false;
925
- }
926
- }
927
-
928
- if (end === -1) return hasRoot ? '/' : '.';
929
- if (hasRoot && end === 1) return '//';
930
- return path.slice(0, end);
931
- },
932
-
933
- basename: function basename(path, ext) {
934
- if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string');
935
- assertPath(path);
936
-
937
- var start = 0;
938
- var end = -1;
939
- var matchedSlash = true;
940
- var i;
941
-
942
- if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
943
- if (ext.length === path.length && ext === path) return '';
944
- var extIdx = ext.length - 1;
945
- var firstNonSlashEnd = -1;
946
- for (i = path.length - 1; i >= 0; --i) {
947
- var code = path.charCodeAt(i);
948
- if (code === 47 /*/*/) {
949
- // If we reached a path separator that was not part of a set of path
950
- // separators at the end of the string, stop now
951
- if (!matchedSlash) {
952
- start = i + 1;
953
- break;
954
- }
955
- } else {
956
- if (firstNonSlashEnd === -1) {
957
- // We saw the first non-path separator, remember this index in case
958
- // we need it if the extension ends up not matching
959
- matchedSlash = false;
960
- firstNonSlashEnd = i + 1;
961
- }
962
- if (extIdx >= 0) {
963
- // Try to match the explicit extension
964
- if (code === ext.charCodeAt(extIdx)) {
965
- if (--extIdx === -1) {
966
- // We matched the extension, so mark this as the end of our path
967
- // component
968
- end = i;
969
- }
970
- } else {
971
- // Extension does not match, so our result is the entire path
972
- // component
973
- extIdx = -1;
974
- end = firstNonSlashEnd;
975
- }
976
- }
977
- }
978
- }
979
-
980
- if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;
981
- return path.slice(start, end);
982
- } else {
983
- for (i = path.length - 1; i >= 0; --i) {
984
- if (path.charCodeAt(i) === 47 /*/*/) {
985
- // If we reached a path separator that was not part of a set of path
986
- // separators at the end of the string, stop now
987
- if (!matchedSlash) {
988
- start = i + 1;
989
- break;
990
- }
991
- } else if (end === -1) {
992
- // We saw the first non-path separator, mark this as the end of our
993
- // path component
994
- matchedSlash = false;
995
- end = i + 1;
996
- }
997
- }
998
-
999
- if (end === -1) return '';
1000
- return path.slice(start, end);
1001
- }
1002
- },
1003
-
1004
- extname: function extname(path) {
1005
- assertPath(path);
1006
- var startDot = -1;
1007
- var startPart = 0;
1008
- var end = -1;
1009
- var matchedSlash = true;
1010
- // Track the state of characters (if any) we see before our first dot and
1011
- // after any path separator we find
1012
- var preDotState = 0;
1013
- for (var i = path.length - 1; i >= 0; --i) {
1014
- var code = path.charCodeAt(i);
1015
- if (code === 47 /*/*/) {
1016
- // If we reached a path separator that was not part of a set of path
1017
- // separators at the end of the string, stop now
1018
- if (!matchedSlash) {
1019
- startPart = i + 1;
1020
- break;
1021
- }
1022
- continue;
1023
- }
1024
- if (end === -1) {
1025
- // We saw the first non-path separator, mark this as the end of our
1026
- // extension
1027
- matchedSlash = false;
1028
- end = i + 1;
1029
- }
1030
- if (code === 46 /*.*/) {
1031
- // If this is our first dot, mark it as the start of our extension
1032
- if (startDot === -1)
1033
- startDot = i;
1034
- else if (preDotState !== 1)
1035
- preDotState = 1;
1036
- } else if (startDot !== -1) {
1037
- // We saw a non-dot and non-path separator before our dot, so we should
1038
- // have a good chance at having a non-empty extension
1039
- preDotState = -1;
1040
- }
1041
- }
1042
-
1043
- if (startDot === -1 || end === -1 ||
1044
- // We saw a non-dot character immediately before the dot
1045
- preDotState === 0 ||
1046
- // The (right-most) trimmed path component is exactly '..'
1047
- preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
1048
- return '';
1049
- }
1050
- return path.slice(startDot, end);
1051
- },
1052
-
1053
- format: function format(pathObject) {
1054
- if (pathObject === null || typeof pathObject !== 'object') {
1055
- throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
1056
- }
1057
- return _format('/', pathObject);
1058
- },
1059
-
1060
- parse: function parse(path) {
1061
- assertPath(path);
1062
-
1063
- var ret = { root: '', dir: '', base: '', ext: '', name: '' };
1064
- if (path.length === 0) return ret;
1065
- var code = path.charCodeAt(0);
1066
- var isAbsolute = code === 47 /*/*/;
1067
- var start;
1068
- if (isAbsolute) {
1069
- ret.root = '/';
1070
- start = 1;
1071
- } else {
1072
- start = 0;
1073
- }
1074
- var startDot = -1;
1075
- var startPart = 0;
1076
- var end = -1;
1077
- var matchedSlash = true;
1078
- var i = path.length - 1;
1079
-
1080
- // Track the state of characters (if any) we see before our first dot and
1081
- // after any path separator we find
1082
- var preDotState = 0;
1083
-
1084
- // Get non-dir info
1085
- for (; i >= start; --i) {
1086
- code = path.charCodeAt(i);
1087
- if (code === 47 /*/*/) {
1088
- // If we reached a path separator that was not part of a set of path
1089
- // separators at the end of the string, stop now
1090
- if (!matchedSlash) {
1091
- startPart = i + 1;
1092
- break;
1093
- }
1094
- continue;
1095
- }
1096
- if (end === -1) {
1097
- // We saw the first non-path separator, mark this as the end of our
1098
- // extension
1099
- matchedSlash = false;
1100
- end = i + 1;
1101
- }
1102
- if (code === 46 /*.*/) {
1103
- // If this is our first dot, mark it as the start of our extension
1104
- if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;
1105
- } else if (startDot !== -1) {
1106
- // We saw a non-dot and non-path separator before our dot, so we should
1107
- // have a good chance at having a non-empty extension
1108
- preDotState = -1;
1109
- }
1110
- }
1111
-
1112
- if (startDot === -1 || end === -1 ||
1113
- // We saw a non-dot character immediately before the dot
1114
- preDotState === 0 ||
1115
- // The (right-most) trimmed path component is exactly '..'
1116
- preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
1117
- if (end !== -1) {
1118
- if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);
1119
- }
1120
- } else {
1121
- if (startPart === 0 && isAbsolute) {
1122
- ret.name = path.slice(1, startDot);
1123
- ret.base = path.slice(1, end);
1124
- } else {
1125
- ret.name = path.slice(startPart, startDot);
1126
- ret.base = path.slice(startPart, end);
1127
- }
1128
- ret.ext = path.slice(startDot, end);
1129
- }
1130
-
1131
- if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = '/';
1132
-
1133
- return ret;
1134
- },
1135
-
1136
- sep: '/',
1137
- delimiter: ':',
1138
- win32: null,
1139
- posix: null
1140
- };
1141
-
1142
- posix.posix = posix;
1143
-
1144
- var pathBrowserify = posix;
1145
-
1146
648
  function ensure_list(obj) {
1147
649
  const objArray = Array.isArray(obj) ? obj : [obj];
1148
650
  return objArray;
@@ -1276,6 +778,313 @@ function getAlphas() {
1276
778
  return 'abcdefghijklmnopqrstuvwxyz';
1277
779
  }
1278
780
 
781
+ /** ---- Data: large but explicit, mirrors your Python mapping ---- */
782
+ const MIME_TYPES = {
783
+ image: {
784
+ ".jpg": "image/jpeg",
785
+ ".jpeg": "image/jpeg",
786
+ ".png": "image/png",
787
+ ".gif": "image/gif",
788
+ ".bmp": "image/bmp",
789
+ ".tiff": "image/tiff",
790
+ ".webp": "image/webp",
791
+ ".svg": "image/svg+xml",
792
+ ".ico": "image/vnd.microsoft.icon",
793
+ ".heic": "image/heic",
794
+ ".psd": "image/vnd.adobe.photoshop",
795
+ ".raw": "image/x-raw",
796
+ },
797
+ video: {
798
+ ".mp4": "video/mp4",
799
+ ".webm": "video/webm",
800
+ ".ogg": "video/ogg",
801
+ ".mov": "video/quicktime",
802
+ ".avi": "video/x-msvideo",
803
+ ".mkv": "video/x-matroska",
804
+ ".flv": "video/x-flv",
805
+ ".wmv": "video/x-ms-wmv",
806
+ ".3gp": "video/3gpp",
807
+ ".ts": "video/mp2t",
808
+ ".mpeg": "video/mpeg",
809
+ ".mpg": "video/mpg",
810
+ },
811
+ audio: {
812
+ ".mp3": "audio/mpeg",
813
+ ".wav": "audio/wav",
814
+ ".flac": "audio/flac",
815
+ ".aac": "audio/aac",
816
+ ".ogg": "audio/ogg",
817
+ ".m4a": "audio/mp4",
818
+ ".opus": "audio/opus",
819
+ },
820
+ document: {
821
+ ".pdf": "application/pdf",
822
+ ".doc": "application/msword",
823
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
824
+ ".odt": "application/vnd.oasis.opendocument.text",
825
+ ".txt": "text/plain",
826
+ ".rtf": "application/rtf",
827
+ ".md": "text/markdown",
828
+ ".markdown": "text/markdown",
829
+ ".tex": "application/x-tex",
830
+ ".log": "text/plain",
831
+ ".json": "application/json",
832
+ ".xml": "application/xml",
833
+ ".yaml": "application/x-yaml",
834
+ ".yml": "application/x-yaml",
835
+ ".ini": "text/plain",
836
+ ".cfg": "text/plain",
837
+ ".toml": "application/toml",
838
+ ".csv": "text/csv",
839
+ ".tsv": "text/tab-separated-values",
840
+ },
841
+ presentation: {
842
+ ".ppt": "application/vnd.ms-powerpoint",
843
+ ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
844
+ ".odp": "application/vnd.oasis.opendocument.presentation",
845
+ },
846
+ spreadsheet: {
847
+ ".xls": "application/vnd.ms-excel",
848
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
849
+ ".ods": "application/vnd.oasis.opendocument.spreadsheet",
850
+ ".csv": "text/csv",
851
+ ".tsv": "text/tab-separated-values",
852
+ },
853
+ code: {
854
+ ".py": "text/x-python",
855
+ ".java": "text/x-java-source",
856
+ ".c": "text/x-c",
857
+ ".cpp": "text/x-c++",
858
+ ".h": "text/x-c",
859
+ ".hpp": "text/x-c++",
860
+ ".js": "application/javascript",
861
+ ".cjs": "application/javascript",
862
+ ".mjs": "application/javascript",
863
+ ".jsx": "application/javascript",
864
+ ".ts": "application/typescript",
865
+ ".tsx": "application/typescript",
866
+ ".rb": "text/x-ruby",
867
+ ".php": "application/x-php",
868
+ ".go": "text/x-go",
869
+ ".rs": "text/rust",
870
+ ".swift": "text/x-swift",
871
+ ".kt": "text/x-kotlin",
872
+ ".sh": "application/x-shellscript",
873
+ ".bash": "application/x-shellscript",
874
+ ".ps1": "application/x-powershell",
875
+ ".sql": "application/sql",
876
+ ".yml": "application/x-yaml",
877
+ ".coffee": "text/coffeescript",
878
+ ".lua": "text/x-lua",
879
+ },
880
+ archive: {
881
+ ".zip": "application/zip",
882
+ ".tar": "application/x-tar",
883
+ ".gz": "application/gzip",
884
+ ".tgz": "application/gzip",
885
+ ".bz2": "application/x-bzip2",
886
+ ".xz": "application/x-xz",
887
+ ".rar": "application/vnd.rar",
888
+ ".7z": "application/x-7z-compressed",
889
+ ".iso": "application/x-iso9660-image",
890
+ ".dmg": "application/x-apple-diskimage",
891
+ ".jar": "application/java-archive",
892
+ ".war": "application/java-archive",
893
+ ".whl": "application/python-wheel",
894
+ ".egg": "application/python-egg",
895
+ },
896
+ font: {
897
+ ".ttf": "font/ttf",
898
+ ".otf": "font/otf",
899
+ ".woff": "font/woff",
900
+ ".woff2": "font/woff2",
901
+ ".eot": "application/vnd.ms-fontobject",
902
+ },
903
+ executable: {
904
+ ".exe": "application/vnd.microsoft.portable-executable",
905
+ ".dll": "application/vnd.microsoft.portable-executable",
906
+ ".bin": "application/octet-stream",
907
+ ".deb": "application/vnd.debian.binary-package",
908
+ ".rpm": "application/x-rpm",
909
+ },
910
+ };
911
+ /** Mirror of MEDIA_TYPES in Python: category -> Set of extensions */
912
+ const MEDIA_TYPES = Object.fromEntries(Object.entries(MIME_TYPES).map(([cat, mapping]) => [
913
+ cat,
914
+ new Set(Object.keys(mapping)),
915
+ ]));
916
+ /** ---- Helpers ---- */
917
+ function toCategorySet(categories) {
918
+ const allCats = new Set(Object.keys(MIME_TYPES));
919
+ if (!categories) {
920
+ // all categories
921
+ return new Set(allCats);
922
+ }
923
+ const out = new Set();
924
+ for (const c of categories) {
925
+ const key = String(c);
926
+ if (allCats.has(key))
927
+ out.add(key);
928
+ }
929
+ return out.size ? out : new Set(allCats);
930
+ }
931
+ function normalizeCategories(categories, opts) {
932
+ var _a;
933
+ const selected = (_a = categories !== null && categories !== void 0 ? categories : opts === null || opts === void 0 ? void 0 : opts.media_types) !== null && _a !== void 0 ? _a : null;
934
+ return toCategorySet(selected);
935
+ }
936
+ function extOf(input) {
937
+ // Behaves like pathlib.Path(...).suffix.lower(): last extension only; lowercased.
938
+ let ext = path.extname(input || "");
939
+ if (!ext && input && input.startsWith(".")) {
940
+ // user passed ".jpg" directly
941
+ ext = input;
942
+ }
943
+ return (ext || "").toLowerCase();
944
+ }
945
+ function unionExts(categories) {
946
+ const out = new Set();
947
+ for (const c of categories) {
948
+ const set = MEDIA_TYPES[c];
949
+ for (const e of set)
950
+ out.add(e);
951
+ }
952
+ return out;
953
+ }
954
+ /** ---- API (Python parity) ---- */
955
+ /**
956
+ * Return a sub-map of MEDIA_TYPES for the given categories.
957
+ * If categories is falsy, returns all categories.
958
+ */
959
+ function getMediaMap(categories, opts) {
960
+ const cats = normalizeCategories(categories, opts);
961
+ const result = {};
962
+ for (const c of cats)
963
+ result[c] = new Set(MEDIA_TYPES[c]);
964
+ return result;
965
+ }
966
+ /**
967
+ * Return a flat, sorted list of all extensions for the given categories.
968
+ */
969
+ function getMediaExts(categories, opts) {
970
+ const cats = normalizeCategories(categories, opts);
971
+ return Array.from(unionExts(cats)).sort();
972
+ }
973
+ /**
974
+ * Given a file path or extension, return its media category (e.g. "image") or null.
975
+ * Mirrors Python's confirm_type.
976
+ */
977
+ function confirmType(pathOrExt, categories, opts) {
978
+ const cats = normalizeCategories(categories, opts);
979
+ const ext = extOf(pathOrExt);
980
+ // Preserve object insertion order like Python dict iteration
981
+ for (const [category, exts] of Object.entries(MEDIA_TYPES)) {
982
+ if (!cats.has(category))
983
+ continue;
984
+ if (ext && exts.has(ext))
985
+ return category;
986
+ }
987
+ return null;
988
+ }
989
+ /**
990
+ * True if the given file path or extension belongs to one of the categories.
991
+ */
992
+ function isMediaType(pathOrExt, categories, opts) {
993
+ return confirmType(pathOrExt, categories, opts) !== null;
994
+ }
995
+ /**
996
+ * Look up the MIME type by extension; fall back to 'application/octet-stream'.
997
+ */
998
+ function getMimeType(pathOrExt) {
999
+ const ext = extOf(pathOrExt);
1000
+ for (const mapping of Object.values(MIME_TYPES)) {
1001
+ if (ext && mapping[ext]) {
1002
+ return mapping[ext];
1003
+ }
1004
+ }
1005
+ return "application/octet-stream";
1006
+ }
1007
+ /**
1008
+ * Recursively collect files under `directory` whose extension is in `categories`.
1009
+ * Synchronous version.
1010
+ */
1011
+ function getAllFileTypesSync(directory, categories, opts) {
1012
+ const base = directory;
1013
+ let stat;
1014
+ try {
1015
+ stat = fs.statSync(base);
1016
+ }
1017
+ catch (_a) {
1018
+ return [];
1019
+ }
1020
+ if (!stat.isDirectory())
1021
+ return [];
1022
+ const cats = normalizeCategories(categories, opts);
1023
+ const wanted = unionExts(cats);
1024
+ const results = [];
1025
+ function walkSync(dir) {
1026
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
1027
+ for (const ent of entries) {
1028
+ const full = path.join(dir, ent.name);
1029
+ if (ent.isDirectory()) {
1030
+ walkSync(full);
1031
+ }
1032
+ else if (ent.isFile()) {
1033
+ const ext = path.extname(ent.name).toLowerCase();
1034
+ if (wanted.has(ext))
1035
+ results.push(full);
1036
+ }
1037
+ }
1038
+ }
1039
+ walkSync(base);
1040
+ return results;
1041
+ }
1042
+ /**
1043
+ * Recursively collect files under `directory` whose extension is in `categories`.
1044
+ * Async/Promise version.
1045
+ */
1046
+ function getAllFileTypes(directory, categories, opts) {
1047
+ return __awaiter(this, void 0, void 0, function* () {
1048
+ let stat;
1049
+ try {
1050
+ stat = yield fsp.stat(directory);
1051
+ }
1052
+ catch (_a) {
1053
+ return [];
1054
+ }
1055
+ if (!stat.isDirectory())
1056
+ return [];
1057
+ const cats = normalizeCategories(categories, opts);
1058
+ const wanted = unionExts(cats);
1059
+ const results = [];
1060
+ function walkAsync(dir) {
1061
+ return __awaiter(this, void 0, void 0, function* () {
1062
+ const entries = yield fsp.readdir(dir, { withFileTypes: true });
1063
+ for (const ent of entries) {
1064
+ const full = path.join(dir, ent.name);
1065
+ if (ent.isDirectory()) {
1066
+ yield walkAsync(full);
1067
+ }
1068
+ else if (ent.isFile()) {
1069
+ const ext = path.extname(ent.name).toLowerCase();
1070
+ if (wanted.has(ext))
1071
+ results.push(full);
1072
+ }
1073
+ }
1074
+ });
1075
+ }
1076
+ yield walkAsync(directory);
1077
+ return results;
1078
+ });
1079
+ }
1080
+ /** Optional convenience re-exports that mirror your Python names */
1081
+ const get_all_file_types = getAllFileTypes;
1082
+ const get_media_map = getMediaMap;
1083
+ const get_media_exts = getMediaExts;
1084
+ const confirm_type = confirmType;
1085
+ const is_media_type = isMediaType;
1086
+ const get_mime_type = getMimeType;
1087
+
1279
1088
  function getSubstring(obj, maxLength = null, minLength = null) {
1280
1089
  const objLength = obj.length;
1281
1090
  const effectiveMaxLength = maxLength !== null && maxLength !== void 0 ? maxLength : objLength; // Use nullish coalescing for clarity
@@ -1458,28 +1267,28 @@ function getAbsolutePath() {
1458
1267
  function get_dirname(filePath) {
1459
1268
  if (!filePath)
1460
1269
  return '';
1461
- return pathBrowserify.dirname(filePath);
1270
+ return path$1.dirname(filePath);
1462
1271
  }
1463
1272
  function get_basename(filePath) {
1464
1273
  if (!filePath)
1465
1274
  return '';
1466
- return pathBrowserify.basename(filePath);
1275
+ return path$1.basename(filePath);
1467
1276
  }
1468
1277
  function get_filename(file_path) {
1469
- const ext = pathBrowserify.extname(file_path);
1470
- return pathBrowserify.basename(file_path, ext);
1278
+ const ext = path$1.extname(file_path);
1279
+ return path$1.basename(file_path, ext);
1471
1280
  }
1472
1281
  function get_extname(filePath) {
1473
1282
  if (!filePath)
1474
1283
  return '';
1475
- return pathBrowserify.extname(filePath);
1284
+ return path$1.extname(filePath);
1476
1285
  }
1477
1286
  function get_splitext(filePath) {
1478
1287
  if (!filePath)
1479
1288
  return { filename: '', extname: '' };
1480
- const ext = pathBrowserify.extname(filePath);
1289
+ const ext = path$1.extname(filePath);
1481
1290
  // Get the basename without the extension
1482
- const filename = pathBrowserify.basename(filePath, ext);
1291
+ const filename = path$1.basename(filePath, ext);
1483
1292
  return { filename, ext };
1484
1293
  }
1485
1294
  /**
@@ -1537,11 +1346,11 @@ function sanitizeFilename(filename) {
1537
1346
  .replace(/^-|-$/, ''); // Remove leading/trailing hyphens
1538
1347
  }
1539
1348
  function get_relative_path(directory, fullPath) {
1540
- return pathBrowserify.relative(directory, fullPath);
1349
+ return path$1.relative(directory, fullPath);
1541
1350
  }
1542
1351
  // Safer resolver that strips .. at the front only, but prefer server-side checks.
1543
1352
  function get_safe_path(p) {
1544
- return pathBrowserify.normalize(p).replace(/^(\.\.[/\\])+/, '');
1353
+ return path$1.normalize(p).replace(/^(\.\.[/\\])+/, '');
1545
1354
  }
1546
1355
  function make_sanitized_path(...paths) {
1547
1356
  let real_path = '';
@@ -1845,5 +1654,5 @@ const encodeTextForUrl = (text) => encode(text);
1845
1654
  /** Quick helper: decode long blobs coming from share-intents/UTMs */
1846
1655
  const decodeShareBlob = (blob) => decodeMaybeDouble(blob).replace(/\r\n/g, "\n");
1847
1656
 
1848
- export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertIt, alertit, assureArray, assureList, assureNumber, assureString, assure_array, assure_list, assure_number, assure_string, buildUrl, callStorage, callWindowMethod, capitalize, capitalize_str, checkResponse, cleanArray, cleanText, create_list_string, currentUsername, currentUsernames, decodeFormComponent, decodeJwt, decodeMaybeDouble, decodeSafe, decodeShareBlob, eatAll, eatEnd, eatInner, eatOuter, encode, encodeTextForUrl, ensureArray, ensureList, ensureNumber, ensureString, ensure_array, ensure_list, ensure_number, ensure_string, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, formatNumber, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, get, getAbsDir, getAbsPath, getAlphaNum, getAlphas, getAuthorizationHeader, getBaseDir, getBody, getChar, getCleanArray, getComponentsUtilsDirectory, getConfigContent, getConfigJson, getConfigVar, getDbConfigsPath, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMethod, getNums, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, getWindowHost, getWindowProp, get_basename, get_dirname, get_extname, get_filename, get_full_path, get_full_url, get_key_value, get_keyword_string, get_relative_path, get_result, get_safe_path, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, isLoggedIn, isNum, isStrInString, isTokenExpired, isType, makePath, make_path, make_sanitized_path, normalizeUrl, parseQuery, parseResult, path_to_url, processKeywords, readJsonFile, removeToken, requireToken, roundPercentage, safeDivide, safeGlobalProp, safeMultiply, safeNums, safeStorage, sanitizeFilename, stripPrefixes, truncateString, tryParse, urlJoin, url_to_path };
1657
+ export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, MEDIA_TYPES, MIME_TYPES, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertIt, alertit, assureArray, assureList, assureNumber, assureString, assure_array, assure_list, assure_number, assure_string, buildUrl, callStorage, callWindowMethod, capitalize, capitalize_str, checkResponse, cleanArray, cleanText, confirmType, confirm_type, create_list_string, currentUsername, currentUsernames, decodeFormComponent, decodeJwt, decodeMaybeDouble, decodeSafe, decodeShareBlob, eatAll, eatEnd, eatInner, eatOuter, encode, encodeTextForUrl, ensureArray, ensureList, ensureNumber, ensureString, ensure_array, ensure_list, ensure_number, ensure_string, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, formatNumber, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, get, getAbsDir, getAbsPath, getAllFileTypes, getAllFileTypesSync, getAlphaNum, getAlphas, getAuthorizationHeader, getBaseDir, getBody, getChar, getCleanArray, getComponentsUtilsDirectory, getConfigContent, getConfigJson, getConfigVar, getDbConfigsPath, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMediaExts, getMediaMap, getMethod, getMimeType, getNums, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, getWindowHost, getWindowProp, get_all_file_types, get_basename, get_dirname, get_extname, get_filename, get_full_path, get_full_url, get_key_value, get_keyword_string, get_media_exts, get_media_map, get_mime_type, get_relative_path, get_result, get_safe_path, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, isLoggedIn, isMediaType, isNum, isStrInString, isTokenExpired, isType, is_media_type, makePath, make_path, make_sanitized_path, normalizeUrl, parseQuery, parseResult, path_to_url, processKeywords, readJsonFile, removeToken, requireToken, roundPercentage, safeDivide, safeGlobalProp, safeMultiply, safeNums, safeStorage, sanitizeFilename, stripPrefixes, truncateString, tryParse, urlJoin, url_to_path };
1849
1658
  //# sourceMappingURL=index.js.map