@youtyan/code-viewer 0.2.2 → 0.2.3
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/code-viewer.js +302 -1
- package/package.json +1 -1
- package/web/app.js +5 -0
package/dist/code-viewer.js
CHANGED
|
@@ -2853,6 +2853,306 @@ var init_routes = __esm(() => {
|
|
|
2853
2853
|
APP_ENTRY_PATHS = ["/", "/index.html"];
|
|
2854
2854
|
});
|
|
2855
2855
|
|
|
2856
|
+
// web-src/views/media-embed.ts
|
|
2857
|
+
function isImage(p) {
|
|
2858
|
+
return IMAGE_RE.test(p);
|
|
2859
|
+
}
|
|
2860
|
+
function isVideo(p) {
|
|
2861
|
+
return VIDEO_RE.test(p);
|
|
2862
|
+
}
|
|
2863
|
+
function isAudio(p) {
|
|
2864
|
+
return AUDIO_RE.test(p);
|
|
2865
|
+
}
|
|
2866
|
+
var IMAGE_RE, VIDEO_RE, AUDIO_RE;
|
|
2867
|
+
var init_media_embed = __esm(() => {
|
|
2868
|
+
IMAGE_RE = /\.(png|jpe?g|gif|webp|svg|avif|bmp|ico)(\?.*)?$/i;
|
|
2869
|
+
VIDEO_RE = /\.(mp4|webm|mov)$/i;
|
|
2870
|
+
AUDIO_RE = /\.(mp3|wav|ogg|flac|m4a|aac|opus)$/i;
|
|
2871
|
+
});
|
|
2872
|
+
|
|
2873
|
+
// web-src/core/source-meta.ts
|
|
2874
|
+
function sourceFileName(path) {
|
|
2875
|
+
return (path.split("/").pop() || path).toLowerCase();
|
|
2876
|
+
}
|
|
2877
|
+
function sourceFileExtension(name) {
|
|
2878
|
+
const index = name.lastIndexOf(".");
|
|
2879
|
+
return index >= 0 ? name.slice(index + 1) : "";
|
|
2880
|
+
}
|
|
2881
|
+
function isDockerfileName(name) {
|
|
2882
|
+
return /^dockerfile(?:[.-].+)?$/i.test(name);
|
|
2883
|
+
}
|
|
2884
|
+
function isMakefileName(name) {
|
|
2885
|
+
return /^makefile(?:[.-].+)?$/i.test(name);
|
|
2886
|
+
}
|
|
2887
|
+
function isDotenvName(name) {
|
|
2888
|
+
return /^(?:\.?env|.*\.env)(?:[.-].+)?$/i.test(name);
|
|
2889
|
+
}
|
|
2890
|
+
function sourceDisplayKind(path) {
|
|
2891
|
+
if (isVideo(path))
|
|
2892
|
+
return "video";
|
|
2893
|
+
if (isAudio(path))
|
|
2894
|
+
return "audio";
|
|
2895
|
+
if (isImage(path))
|
|
2896
|
+
return "image";
|
|
2897
|
+
if (/\.pdf$/i.test(path))
|
|
2898
|
+
return "pdf";
|
|
2899
|
+
const name = sourceFileName(path);
|
|
2900
|
+
const ext = sourceFileExtension(name);
|
|
2901
|
+
if (TEXT_SOURCE_EXTENSIONS.has(ext))
|
|
2902
|
+
return "text";
|
|
2903
|
+
if (TEXT_SOURCE_FILENAMES.has(name))
|
|
2904
|
+
return "text";
|
|
2905
|
+
if (isDotenvName(name))
|
|
2906
|
+
return "text";
|
|
2907
|
+
if (isDockerfileName(name) || isMakefileName(name))
|
|
2908
|
+
return "text";
|
|
2909
|
+
return "unsupported";
|
|
2910
|
+
}
|
|
2911
|
+
var EXT_TO_LANG, TEXT_SOURCE_EXTENSIONS, TEXT_SOURCE_FILENAMES;
|
|
2912
|
+
var init_source_meta = __esm(() => {
|
|
2913
|
+
init_media_embed();
|
|
2914
|
+
EXT_TO_LANG = {
|
|
2915
|
+
js: "javascript",
|
|
2916
|
+
mjs: "javascript",
|
|
2917
|
+
cjs: "javascript",
|
|
2918
|
+
ts: "typescript",
|
|
2919
|
+
tsx: "typescript",
|
|
2920
|
+
jsx: "javascript",
|
|
2921
|
+
py: "python",
|
|
2922
|
+
rb: "ruby",
|
|
2923
|
+
go: "go",
|
|
2924
|
+
rs: "rust",
|
|
2925
|
+
java: "java",
|
|
2926
|
+
kt: "kotlin",
|
|
2927
|
+
swift: "swift",
|
|
2928
|
+
c: "c",
|
|
2929
|
+
h: "c",
|
|
2930
|
+
cc: "cpp",
|
|
2931
|
+
cpp: "cpp",
|
|
2932
|
+
hpp: "cpp",
|
|
2933
|
+
cs: "csharp",
|
|
2934
|
+
php: "php",
|
|
2935
|
+
lua: "lua",
|
|
2936
|
+
sh: "bash",
|
|
2937
|
+
bash: "bash",
|
|
2938
|
+
zsh: "bash",
|
|
2939
|
+
fish: "bash",
|
|
2940
|
+
sql: "sql",
|
|
2941
|
+
json: "json",
|
|
2942
|
+
yaml: "yaml",
|
|
2943
|
+
yml: "yaml",
|
|
2944
|
+
toml: "toml",
|
|
2945
|
+
tf: "terraform",
|
|
2946
|
+
tfvars: "terraform",
|
|
2947
|
+
hcl: "terraform",
|
|
2948
|
+
xml: "xml",
|
|
2949
|
+
html: "xml",
|
|
2950
|
+
vue: "xml",
|
|
2951
|
+
css: "css",
|
|
2952
|
+
scss: "scss",
|
|
2953
|
+
md: "markdown",
|
|
2954
|
+
dockerfile: "dockerfile",
|
|
2955
|
+
proto: "protobuf",
|
|
2956
|
+
gradle: "gradle",
|
|
2957
|
+
properties: "properties",
|
|
2958
|
+
patch: "diff",
|
|
2959
|
+
diff: "diff",
|
|
2960
|
+
nix: "nix",
|
|
2961
|
+
cue: "cue",
|
|
2962
|
+
rego: "rego",
|
|
2963
|
+
bicep: "bicep",
|
|
2964
|
+
bazel: "starlark",
|
|
2965
|
+
bzl: "starlark",
|
|
2966
|
+
cmake: "cmake",
|
|
2967
|
+
groovy: "groovy",
|
|
2968
|
+
dart: "dart",
|
|
2969
|
+
scala: "scala",
|
|
2970
|
+
clj: "clojure",
|
|
2971
|
+
cljs: "clojure",
|
|
2972
|
+
cljc: "clojure",
|
|
2973
|
+
edn: "clojure",
|
|
2974
|
+
ex: "elixir",
|
|
2975
|
+
exs: "elixir",
|
|
2976
|
+
erl: "erlang",
|
|
2977
|
+
hrl: "erlang",
|
|
2978
|
+
hs: "haskell",
|
|
2979
|
+
lhs: "haskell",
|
|
2980
|
+
ml: "ocaml",
|
|
2981
|
+
mli: "ocaml",
|
|
2982
|
+
jl: "julia",
|
|
2983
|
+
r: "r",
|
|
2984
|
+
rmd: "r",
|
|
2985
|
+
pl: "perl",
|
|
2986
|
+
pm: "perl",
|
|
2987
|
+
tcl: "tcl",
|
|
2988
|
+
vim: "vim",
|
|
2989
|
+
f: "fortran",
|
|
2990
|
+
f90: "fortran",
|
|
2991
|
+
m: "objective-c",
|
|
2992
|
+
mm: "objective-cpp",
|
|
2993
|
+
tex: "tex",
|
|
2994
|
+
bib: "bibtex",
|
|
2995
|
+
rst: "rst"
|
|
2996
|
+
};
|
|
2997
|
+
TEXT_SOURCE_EXTENSIONS = new Set([
|
|
2998
|
+
...Object.keys(EXT_TO_LANG),
|
|
2999
|
+
"txt",
|
|
3000
|
+
"md",
|
|
3001
|
+
"markdown",
|
|
3002
|
+
"mdown",
|
|
3003
|
+
"mkdn",
|
|
3004
|
+
"mdx",
|
|
3005
|
+
"json",
|
|
3006
|
+
"jsonc",
|
|
3007
|
+
"csv",
|
|
3008
|
+
"tsv",
|
|
3009
|
+
"yaml",
|
|
3010
|
+
"yml",
|
|
3011
|
+
"toml",
|
|
3012
|
+
"hcl",
|
|
3013
|
+
"tf",
|
|
3014
|
+
"tfvars",
|
|
3015
|
+
"tfstate",
|
|
3016
|
+
"xml",
|
|
3017
|
+
"html",
|
|
3018
|
+
"htm",
|
|
3019
|
+
"css",
|
|
3020
|
+
"scss",
|
|
3021
|
+
"sass",
|
|
3022
|
+
"less",
|
|
3023
|
+
"js",
|
|
3024
|
+
"jsx",
|
|
3025
|
+
"mjs",
|
|
3026
|
+
"cjs",
|
|
3027
|
+
"ts",
|
|
3028
|
+
"tsx",
|
|
3029
|
+
"mts",
|
|
3030
|
+
"cts",
|
|
3031
|
+
"vue",
|
|
3032
|
+
"svelte",
|
|
3033
|
+
"astro",
|
|
3034
|
+
"rs",
|
|
3035
|
+
"go",
|
|
3036
|
+
"py",
|
|
3037
|
+
"rb",
|
|
3038
|
+
"php",
|
|
3039
|
+
"java",
|
|
3040
|
+
"kt",
|
|
3041
|
+
"kts",
|
|
3042
|
+
"c",
|
|
3043
|
+
"cc",
|
|
3044
|
+
"cpp",
|
|
3045
|
+
"cxx",
|
|
3046
|
+
"h",
|
|
3047
|
+
"hpp",
|
|
3048
|
+
"cs",
|
|
3049
|
+
"swift",
|
|
3050
|
+
"sh",
|
|
3051
|
+
"bash",
|
|
3052
|
+
"zsh",
|
|
3053
|
+
"fish",
|
|
3054
|
+
"ps1",
|
|
3055
|
+
"sql",
|
|
3056
|
+
"graphql",
|
|
3057
|
+
"graphqls",
|
|
3058
|
+
"gql",
|
|
3059
|
+
"ini",
|
|
3060
|
+
"conf",
|
|
3061
|
+
"env",
|
|
3062
|
+
"properties",
|
|
3063
|
+
"gitignore",
|
|
3064
|
+
"dockerignore",
|
|
3065
|
+
"editorconfig",
|
|
3066
|
+
"lock",
|
|
3067
|
+
"log",
|
|
3068
|
+
"patch",
|
|
3069
|
+
"diff",
|
|
3070
|
+
"sum",
|
|
3071
|
+
"mk",
|
|
3072
|
+
"proto",
|
|
3073
|
+
"thrift",
|
|
3074
|
+
"prisma",
|
|
3075
|
+
"gradle",
|
|
3076
|
+
"cmake",
|
|
3077
|
+
"nix",
|
|
3078
|
+
"cue",
|
|
3079
|
+
"rego",
|
|
3080
|
+
"bicep",
|
|
3081
|
+
"bazel",
|
|
3082
|
+
"bzl",
|
|
3083
|
+
"dart",
|
|
3084
|
+
"scala",
|
|
3085
|
+
"clj",
|
|
3086
|
+
"cljs",
|
|
3087
|
+
"cljc",
|
|
3088
|
+
"edn",
|
|
3089
|
+
"ex",
|
|
3090
|
+
"exs",
|
|
3091
|
+
"erl",
|
|
3092
|
+
"hrl",
|
|
3093
|
+
"hs",
|
|
3094
|
+
"lhs",
|
|
3095
|
+
"ml",
|
|
3096
|
+
"mli",
|
|
3097
|
+
"jl",
|
|
3098
|
+
"r",
|
|
3099
|
+
"rmd",
|
|
3100
|
+
"pl",
|
|
3101
|
+
"pm",
|
|
3102
|
+
"tcl",
|
|
3103
|
+
"vim",
|
|
3104
|
+
"groovy",
|
|
3105
|
+
"f",
|
|
3106
|
+
"f90",
|
|
3107
|
+
"m",
|
|
3108
|
+
"mm",
|
|
3109
|
+
"pas",
|
|
3110
|
+
"tex",
|
|
3111
|
+
"bib",
|
|
3112
|
+
"rst",
|
|
3113
|
+
"adoc",
|
|
3114
|
+
"org",
|
|
3115
|
+
"ipynb",
|
|
3116
|
+
"ejs",
|
|
3117
|
+
"hbs",
|
|
3118
|
+
"mustache",
|
|
3119
|
+
"liquid",
|
|
3120
|
+
"pug"
|
|
3121
|
+
]);
|
|
3122
|
+
TEXT_SOURCE_FILENAMES = new Set([
|
|
3123
|
+
"readme",
|
|
3124
|
+
"license",
|
|
3125
|
+
"copying",
|
|
3126
|
+
"authors",
|
|
3127
|
+
"contributors",
|
|
3128
|
+
"notice",
|
|
3129
|
+
"changelog",
|
|
3130
|
+
"todo",
|
|
3131
|
+
"manifest",
|
|
3132
|
+
"version",
|
|
3133
|
+
"codeowners",
|
|
3134
|
+
"go.mod",
|
|
3135
|
+
"build.bazel",
|
|
3136
|
+
"workspace.bazel",
|
|
3137
|
+
"module.bazel",
|
|
3138
|
+
"gemfile",
|
|
3139
|
+
"rakefile",
|
|
3140
|
+
"procfile",
|
|
3141
|
+
"brewfile",
|
|
3142
|
+
"gnumakefile",
|
|
3143
|
+
"bsdmakefile",
|
|
3144
|
+
".gitattributes",
|
|
3145
|
+
".gitmodules",
|
|
3146
|
+
".npmrc",
|
|
3147
|
+
".nvmrc",
|
|
3148
|
+
".yarnrc",
|
|
3149
|
+
".prettierrc",
|
|
3150
|
+
".eslintrc",
|
|
3151
|
+
".babelrc",
|
|
3152
|
+
".stylelintrc"
|
|
3153
|
+
]);
|
|
3154
|
+
});
|
|
3155
|
+
|
|
2856
3156
|
// web-src/server/cache.ts
|
|
2857
3157
|
import { lstatSync as lstatSync2 } from "node:fs";
|
|
2858
3158
|
import { join as join6 } from "node:path";
|
|
@@ -9572,7 +9872,7 @@ function rawFileHeaders(path, size = null, range, metadata = {}) {
|
|
|
9572
9872
|
".opus": "audio/ogg"
|
|
9573
9873
|
};
|
|
9574
9874
|
const headers = {
|
|
9575
|
-
"Content-Type": mime[extname(path).toLowerCase()] || "application/octet-stream",
|
|
9875
|
+
"Content-Type": mime[extname(path).toLowerCase()] || (sourceDisplayKind(path) === "text" ? "text/plain; charset=utf-8" : "application/octet-stream"),
|
|
9576
9876
|
"Cache-Control": "no-store",
|
|
9577
9877
|
"X-Content-Type-Options": "nosniff",
|
|
9578
9878
|
"Content-Security-Policy": "sandbox",
|
|
@@ -10219,6 +10519,7 @@ async function shutdown(exitCode = 0) {
|
|
|
10219
10519
|
var WEB_ROOT, VERSION, DEFAULT_ARGS, PREVIEW_HUNKS_DEFAULT = 3, PREVIEW_LINES_DEFAULT = 1200, WATCHED_ASSET_FILES, SIZE_SMALL = 2000, SIZE_MEDIUM = 8000, SIZE_LARGE = 20000, LINE_INDEX_MIN_START = 1e4, LINE_INDEX_MAX_FILE_BYTES, BLOB_LINE_CACHE_MAX_BYTES, MAX_UPLOAD_FILE_BYTES, MAX_UPLOAD_TOTAL_BYTES, MAX_UPLOAD_BODY_BYTES, MAX_UPLOAD_FILES = 50, SAFE_UPLOAD_EXTENSIONS, generation = 1, cwd, cliArgs, listenPort = 0, openAfterStart = false, scopeOmitDirNames, scopeOmitDirCliOverride = null, scopeExcludeNames, uploadDisabledByConfig = false, rgAvailableCache = null, enc, sseClients, sseKeepalives, fileCache, metaCache, fileListCache, lineIndexCache, blobLineIndexCache, blobBytesCache, blobLineCacheBytes = 0, server, worktreeWatch = null, shuttingDown = false;
|
|
10220
10520
|
var init_preview = __esm(async () => {
|
|
10221
10521
|
init_routes();
|
|
10522
|
+
init_source_meta();
|
|
10222
10523
|
init_annotations();
|
|
10223
10524
|
init_cache();
|
|
10224
10525
|
init_dev_assets();
|
package/package.json
CHANGED
package/web/app.js
CHANGED
|
@@ -8481,6 +8481,9 @@ ${frontmatter.yaml}
|
|
|
8481
8481
|
function isMakefileName(name) {
|
|
8482
8482
|
return /^makefile(?:[.-].+)?$/i.test(name);
|
|
8483
8483
|
}
|
|
8484
|
+
function isDotenvName(name) {
|
|
8485
|
+
return /^(?:\.?env|.*\.env)(?:[.-].+)?$/i.test(name);
|
|
8486
|
+
}
|
|
8484
8487
|
function sourceDisplayKind(path) {
|
|
8485
8488
|
if (isVideo(path))
|
|
8486
8489
|
return "video";
|
|
@@ -8496,6 +8499,8 @@ ${frontmatter.yaml}
|
|
|
8496
8499
|
return "text";
|
|
8497
8500
|
if (TEXT_SOURCE_FILENAMES.has(name))
|
|
8498
8501
|
return "text";
|
|
8502
|
+
if (isDotenvName(name))
|
|
8503
|
+
return "text";
|
|
8499
8504
|
if (isDockerfileName(name) || isMakefileName(name))
|
|
8500
8505
|
return "text";
|
|
8501
8506
|
return "unsupported";
|