Website Structure

This commit is contained in:
supalerk-ar66 2026-01-13 10:46:40 +07:00
parent 62812f2090
commit 71f0676a62
22365 changed files with 4265753 additions and 791 deletions

View file

@ -0,0 +1,169 @@
'use strict';
const node_url = require('node:url');
const node_util = require('node:util');
const ufo = require('ufo');
const enhancedResolve = require('enhanced-resolve');
const mlly = require('mlly');
const pathe = require('pathe');
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
const enhancedResolve__default = /*#__PURE__*/_interopDefaultCompat(enhancedResolve);
const ProtocolRegex = /^(?<proto>.{2,}):.+$/;
function getProtocol(id) {
const proto = id.match(ProtocolRegex);
return proto ? proto.groups.proto : null;
}
function matches(input, matchers, context) {
return matchers.some((matcher) => {
if (matcher instanceof RegExp) {
return matcher.test(input);
}
if (typeof matcher === "function") {
return matcher(input, context);
}
return false;
});
}
function toMatcher(pattern) {
if (typeof pattern !== "string") {
return pattern;
}
pattern = pattern.replace(/\//g, "[\\\\/+]");
return new RegExp(`([\\/]|^)${pattern}(@[^\\/]*)?([\\/](?!node_modules)|$)`);
}
function getType(id, fallback = "commonjs") {
if (id.endsWith(".cjs")) {
return "commonjs";
}
if (id.endsWith(".mjs")) {
return "module";
}
return fallback;
}
const DefaultResolveOptions = {
extensions: [".ts", ".mjs", ".cjs", ".js", ".json"],
type: "commonjs"
};
async function resolveId(id, base = ".", options = {}) {
options = { ...DefaultResolveOptions, ...options };
if (!options.conditionNames) {
options.conditionNames = [options.type === "commonjs" ? "require" : "import"];
}
if (mlly.isNodeBuiltin(id)) {
return {
id: id.replace(/^node:/, ""),
path: id,
type: options.type,
external: true
};
}
if (id.startsWith("file:/")) {
id = node_url.fileURLToPath(id);
}
if (ufo.hasProtocol(id)) {
const url = new URL(id);
return {
id: url.href,
path: url.pathname,
type: getType(id, options.type),
external: true
};
}
if (base.includes("\0")) {
base = options.roots?.[0] || ".";
}
const _resolve = node_util.promisify(enhancedResolve__default.create(options));
const resolvedModule = await _resolve(base, id);
return {
id,
path: resolvedModule || id,
type: getType(resolvedModule || id, "unknown")
};
}
const ExternalsDefaults = {
inline: [
// Rollup
// eslint-disable-next-line no-control-regex
/\u0000/,
// Webpack
/^!/,
/^-!/,
// Common
/^#/,
/\?/
],
external: [],
externalProtocols: ["node", "file", "data"],
externalExtensions: [".js", ".mjs", ".cjs", ".node"],
resolve: {},
detectInvalidNodeImports: true
};
async function isExternal(id, importer, options = {}) {
options = { ...ExternalsDefaults, ...options };
const inlineMatchers = options.inline.map((p) => toMatcher(p));
const externalMatchers = options.external.map((p) => toMatcher(p));
const context = { opts: options, id, resolved: null };
if (!id || matches(id, inlineMatchers, context)) {
return null;
}
const proto = getProtocol(id);
if (proto && !options.externalProtocols.includes(proto)) {
return null;
}
if (proto === "data") {
return { id, external: true };
}
const r = context.resolved = await resolveId(id, importer, options.resolve).catch(() => {
return { id, path: id, external: null };
});
const idExtension = pathe.extname(r.path);
if (idExtension && !options.externalExtensions.includes(idExtension)) {
return null;
}
if (matches(r.id, inlineMatchers, context) || matches(r.path, inlineMatchers, context)) {
return null;
}
if (r.external || matches(id, externalMatchers, context) || matches(r.id, externalMatchers, context) || matches(r.path, externalMatchers, context)) {
if (options.detectInvalidNodeImports && !await mlly.isValidNodeImport(r.path)) {
return null;
}
return { id: r.id, external: true };
}
return null;
}
function rollupExternals(options) {
return {
name: "node-externals",
resolveId(id, importer) {
return isExternal(id, importer, options);
}
};
}
function webpackExternals(options) {
const _isExternal = async ({ request }, callback) => {
try {
const res = await isExternal(request, ".", options);
callback(void 0, res && res.id);
} catch (error) {
callback(error, null);
}
};
return _isExternal;
}
exports.ExternalsDefaults = ExternalsDefaults;
exports.getProtocol = getProtocol;
exports.getType = getType;
exports.isExternal = isExternal;
exports.matches = matches;
exports.resolveId = resolveId;
exports.rollupExternals = rollupExternals;
exports.toMatcher = toMatcher;
exports.webpackExternals = webpackExternals;

View file

@ -0,0 +1,70 @@
import { ResolveOptions as ResolveOptions$1 } from 'enhanced-resolve';
import { Plugin } from 'rollup';
type ModuleType = "commonjs" | "module" | "unknown";
interface ResolveOptions extends Partial<ResolveOptions$1> {
/**
* Whether to resolve esm or cjs by default
* @default 'commonjs'
*/
type?: ModuleType;
}
interface ResolvedId {
id: string;
path: string;
type?: ModuleType;
external?: boolean;
}
declare function resolveId(id: string, base?: string, options?: ResolveOptions): Promise<ResolvedId>;
type Matcher<T = any> = RegExp | ((input: string, context?: T) => boolean);
declare function getProtocol(id: string): string | null;
declare function matches<T = any>(input: string, matchers: Matcher<T>[], context?: T): boolean;
declare function toMatcher(pattern: string): RegExp;
declare function toMatcher<T>(pattern: Matcher<T>): Matcher<T>;
declare function getType(id: string, fallback?: ModuleType): ModuleType;
interface ExternalsOptions {
/**
* Patterns that always will be excluded from externals
*/
inline?: Array<string | Matcher>;
/**
* Patterns that match if an id/module is external
*/
external?: Array<string | Matcher>;
/**
* Protocols that are allowed to be externalized.
* Any other matched protocol will be inlined.
*
* Default: ['node', 'file', 'data']
*/
externalProtocols?: Array<string>;
/**
* Extensions that are allowed to be externalized.
* Any other matched extension will be inlined.
*
* Default: ['.js', '.mjs', '.cjs', '.node']
*/
externalExtensions?: Array<string>;
/**
* Resolve options (passed directly to [`enhanced-resolve`](https://github.com/webpack/enhanced-resolve))
*/
resolve?: Partial<ResolveOptions>;
/**
* Try to automatically detect and inline invalid node imports
* matching file name (at first) and then loading code.
*/
detectInvalidNodeImports?: boolean;
}
declare const ExternalsDefaults: ExternalsOptions;
declare function isExternal(id: string, importer: string, options?: ExternalsOptions): Promise<null | {
id: string;
external: true;
}>;
declare function rollupExternals(options: ExternalsOptions): Plugin;
declare function webpackExternals(options: ExternalsOptions): any;
export { ExternalsDefaults, ExternalsOptions, Matcher, ModuleType, ResolveOptions, ResolvedId, getProtocol, getType, isExternal, matches, resolveId, rollupExternals, toMatcher, webpackExternals };

View file

@ -0,0 +1,155 @@
import { fileURLToPath } from 'node:url';
import { promisify } from 'node:util';
import { hasProtocol } from 'ufo';
import enhancedResolve from 'enhanced-resolve';
import { isNodeBuiltin, isValidNodeImport } from 'mlly';
import { extname } from 'pathe';
const ProtocolRegex = /^(?<proto>.{2,}):.+$/;
function getProtocol(id) {
const proto = id.match(ProtocolRegex);
return proto ? proto.groups.proto : null;
}
function matches(input, matchers, context) {
return matchers.some((matcher) => {
if (matcher instanceof RegExp) {
return matcher.test(input);
}
if (typeof matcher === "function") {
return matcher(input, context);
}
return false;
});
}
function toMatcher(pattern) {
if (typeof pattern !== "string") {
return pattern;
}
pattern = pattern.replace(/\//g, "[\\\\/+]");
return new RegExp(`([\\/]|^)${pattern}(@[^\\/]*)?([\\/](?!node_modules)|$)`);
}
function getType(id, fallback = "commonjs") {
if (id.endsWith(".cjs")) {
return "commonjs";
}
if (id.endsWith(".mjs")) {
return "module";
}
return fallback;
}
const DefaultResolveOptions = {
extensions: [".ts", ".mjs", ".cjs", ".js", ".json"],
type: "commonjs"
};
async function resolveId(id, base = ".", options = {}) {
options = { ...DefaultResolveOptions, ...options };
if (!options.conditionNames) {
options.conditionNames = [options.type === "commonjs" ? "require" : "import"];
}
if (isNodeBuiltin(id)) {
return {
id: id.replace(/^node:/, ""),
path: id,
type: options.type,
external: true
};
}
if (id.startsWith("file:/")) {
id = fileURLToPath(id);
}
if (hasProtocol(id)) {
const url = new URL(id);
return {
id: url.href,
path: url.pathname,
type: getType(id, options.type),
external: true
};
}
if (base.includes("\0")) {
base = options.roots?.[0] || ".";
}
const _resolve = promisify(enhancedResolve.create(options));
const resolvedModule = await _resolve(base, id);
return {
id,
path: resolvedModule || id,
type: getType(resolvedModule || id, "unknown")
};
}
const ExternalsDefaults = {
inline: [
// Rollup
// eslint-disable-next-line no-control-regex
/\u0000/,
// Webpack
/^!/,
/^-!/,
// Common
/^#/,
/\?/
],
external: [],
externalProtocols: ["node", "file", "data"],
externalExtensions: [".js", ".mjs", ".cjs", ".node"],
resolve: {},
detectInvalidNodeImports: true
};
async function isExternal(id, importer, options = {}) {
options = { ...ExternalsDefaults, ...options };
const inlineMatchers = options.inline.map((p) => toMatcher(p));
const externalMatchers = options.external.map((p) => toMatcher(p));
const context = { opts: options, id, resolved: null };
if (!id || matches(id, inlineMatchers, context)) {
return null;
}
const proto = getProtocol(id);
if (proto && !options.externalProtocols.includes(proto)) {
return null;
}
if (proto === "data") {
return { id, external: true };
}
const r = context.resolved = await resolveId(id, importer, options.resolve).catch(() => {
return { id, path: id, external: null };
});
const idExtension = extname(r.path);
if (idExtension && !options.externalExtensions.includes(idExtension)) {
return null;
}
if (matches(r.id, inlineMatchers, context) || matches(r.path, inlineMatchers, context)) {
return null;
}
if (r.external || matches(id, externalMatchers, context) || matches(r.id, externalMatchers, context) || matches(r.path, externalMatchers, context)) {
if (options.detectInvalidNodeImports && !await isValidNodeImport(r.path)) {
return null;
}
return { id: r.id, external: true };
}
return null;
}
function rollupExternals(options) {
return {
name: "node-externals",
resolveId(id, importer) {
return isExternal(id, importer, options);
}
};
}
function webpackExternals(options) {
const _isExternal = async ({ request }, callback) => {
try {
const res = await isExternal(request, ".", options);
callback(void 0, res && res.id);
} catch (error) {
callback(error, null);
}
};
return _isExternal;
}
export { ExternalsDefaults, getProtocol, getType, isExternal, matches, resolveId, rollupExternals, toMatcher, webpackExternals };