@youtyan/code-viewer 0.2.1 → 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 +14 -11
- package/web/app.js +5 -0
- package/web/vendor/README.md +9 -2
- package/web/vendor/THIRD_PARTY_NOTICES.txt +7684 -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@youtyan/code-viewer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Local browser-based code and git diff viewer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "bun run build:web && bun run build:server",
|
|
31
|
-
"build:web": "bun build --target=browser --format=iife --outfile=web/app.js web-src/app.ts && bun build --target=browser --format=esm --outfile=web/mermaid.js web-src/mermaid-entry.ts && bun build --target=browser --format=esm --outfile=web/shiki.js web-src/shiki-entry.ts",
|
|
31
|
+
"build:web": "bun build --target=browser --format=iife --outfile=web/app.js web-src/app.ts && bun build --target=browser --format=esm --outfile=web/mermaid.js web-src/mermaid-entry.ts && bun build --target=browser --format=esm --outfile=web/shiki.js web-src/shiki-entry.ts && node scripts/generate-third-party-notices.mjs",
|
|
32
32
|
"build:server": "bun build --target=node --format=esm --outfile=dist/code-viewer.js web-src/server/cli.ts",
|
|
33
33
|
"check": "bun run typecheck",
|
|
34
34
|
"typecheck": "tsc --noEmit",
|
|
35
|
-
"check:bundle": "
|
|
35
|
+
"check:bundle": "node scripts/check-bundle.mjs",
|
|
36
36
|
"check:format": "biome format .",
|
|
37
37
|
"dev": "bun run web-src/server/dev.ts",
|
|
38
38
|
"preview": "bun run web-src/server/dev.ts",
|
|
@@ -55,14 +55,17 @@
|
|
|
55
55
|
"license": "MIT",
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@biomejs/biome": "2.4.14",
|
|
58
|
-
"@types/bun": "
|
|
59
|
-
"@types/markdown-it": "
|
|
60
|
-
"markdown-it": "
|
|
61
|
-
"markdown-it-anchor": "
|
|
62
|
-
"markdown-it-footnote": "
|
|
63
|
-
"mermaid": "
|
|
64
|
-
"shiki": "
|
|
65
|
-
"typescript": "
|
|
58
|
+
"@types/bun": "1.3.13",
|
|
59
|
+
"@types/markdown-it": "14.1.2",
|
|
60
|
+
"markdown-it": "14.1.1",
|
|
61
|
+
"markdown-it-anchor": "9.2.0",
|
|
62
|
+
"markdown-it-footnote": "4.0.0",
|
|
63
|
+
"mermaid": "11.14.0",
|
|
64
|
+
"shiki": "4.0.2",
|
|
65
|
+
"typescript": "5.9.3"
|
|
66
|
+
},
|
|
67
|
+
"optionalDependencies": {
|
|
68
|
+
"better-sqlite3": "12.9.0"
|
|
66
69
|
},
|
|
67
70
|
"engines": {
|
|
68
71
|
"node": ">=20.0.0"
|
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";
|
package/web/vendor/README.md
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
# Vendored Browser Assets
|
|
2
2
|
|
|
3
|
-
These
|
|
4
|
-
CDN assets from the browser.
|
|
3
|
+
These browser assets are served locally so git-diff-preview works offline and
|
|
4
|
+
does not load CDN assets from the browser. Some assets are committed here, and
|
|
5
|
+
the generated bundles next to this directory are produced at build / pack time.
|
|
5
6
|
|
|
6
7
|
| Package | Version | Files | License |
|
|
7
8
|
| --- | --- | --- | --- |
|
|
8
9
|
| diff2html | 3.4.56 | `diff2html/diff2html.min.css`, `diff2html/diff2html-ui.min.js` | MIT, https://github.com/rtfpessoa/diff2html |
|
|
9
10
|
| highlight.js | 11.9.0 | `highlight.js/highlight.min.js`, `highlight.js/styles/github*.min.css` | BSD-3-Clause, https://github.com/highlightjs/highlight.js |
|
|
11
|
+
| Browser bundle dependencies | fixed by `bun.lock` | generated `../app.js`, `../mermaid.js`, `../shiki.js` | see `THIRD_PARTY_NOTICES.txt` |
|
|
10
12
|
|
|
11
13
|
`diff2html-ui.min.js` is the UI bundle from the npm package. `highlight.min.js`
|
|
12
14
|
is the standard browser build for highlight.js 11.9.0.
|
|
15
|
+
|
|
16
|
+
`../app.js`, `../mermaid.js`, and `../shiki.js` are generated by
|
|
17
|
+
`bun run build:web` and are included in npm tarballs, but are not tracked in git.
|
|
18
|
+
`THIRD_PARTY_NOTICES.txt` is generated from the installed npm packages during
|
|
19
|
+
the same build.
|