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

21
Frontend-Learner/node_modules/magic-string-ast/LICENSE generated vendored Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright © 2023-PRESENT Kevin Deng (https://github.com/sxzz)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,68 @@
# magic-string-ast
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![JSR][jsr-badge-src]][jsr-badge-href]
[![Unit Test][unit-test-src]][unit-test-href]
[magic-string](https://github.com/rich-harris/magic-string) with AST shortcut.
## Install
```bash
# npm
npm i magic-string-ast
# jsr
npx jsr add -D @sxzz/magic-string-ast
```
## Usage
```ts
import { MagicStringAST } from 'magic-string-ast'
const offset = 0
const node = {
// AST node with `start` and `end` properties
start: 6,
end: 7,
// ...
}
const s = new MagicStringAST('const a = 1')
s.sliceNode(node, { offset }) // 'a'
s.removeNode(node)
s.moveNode(node, 0)
s.overwriteNode(node, 'foo')
// support source-map, inspired by muggle-string.
s.replaceRange(5, 5, '(', expression, ')') // appendLeft
s.replaceRange(5, 8, '(', expression, ')') // overwrite
s.replaceRange(5, 8) // remove
```
For more APIs, see [docs](https://jsr.io/@sxzz/magic-string-ast/doc) and [magic-string](https://github.com/rich-harris/magic-string#usage).
## Sponsors
<p align="center">
<a href="https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg">
<img src='https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg'/>
</a>
</p>
## License
[MIT](./LICENSE) License © 2023-PRESENT [Kevin Deng](https://github.com/sxzz)
<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/magic-string-ast.svg
[npm-version-href]: https://npmjs.com/package/magic-string-ast
[npm-downloads-src]: https://img.shields.io/npm/dm/magic-string-ast
[npm-downloads-href]: https://www.npmcharts.com/compare/magic-string-ast?interval=30
[jsr-badge-src]: https://jsr.io/badges/@sxzz/magic-string-ast
[jsr-badge-href]: https://jsr.io/@sxzz/magic-string-ast
[unit-test-src]: https://github.com/sxzz/magic-string-ast/actions/workflows/unit-test.yml/badge.svg
[unit-test-href]: https://github.com/sxzz/magic-string-ast/actions/workflows/unit-test.yml

View file

@ -0,0 +1,67 @@
import MagicString, { MagicStringOptions, OverwriteOptions } from "magic-string";
export * from "magic-string";
//#region src/index.d.ts
interface Node {
start?: number | null;
end?: number | null;
}
interface MagicStringAST extends MagicString {}
/**
* MagicString with AST manipulation
*/
declare class MagicStringAST implements MagicString {
private prototype;
s: MagicString;
constructor(str: string | MagicString, options?: MagicStringOptions, prototype?: typeof MagicString);
private getNodePos;
removeNode(node: Node | Node[], {
offset
}?: {
offset?: number;
}): this;
moveNode(node: Node | Node[], index: number, {
offset
}?: {
offset?: number;
}): this;
sliceNode(node: Node | Node[], {
offset
}?: {
offset?: number;
}): string;
overwriteNode(node: Node | Node[], content: string | Node | Node[], {
offset,
...options
}?: OverwriteOptions & {
offset?: number;
}): this;
snipNode(node: Node | Node[], {
offset
}?: {
offset?: number;
}): MagicStringAST;
clone(): this;
toString(): string;
private replaceRangeState;
/**
* Replace a range of text with new nodes.
* @param start The start index of the range to replace.
* @param end The end index of the range to replace.
* @param nodes The nodes or strings to insert into the range.
*/
replaceRange(start: number, end: number, ...nodes: (string | Node)[]): this;
}
/**
* The result of code transformation.
*/
interface CodeTransform {
code: string;
map: any;
}
/**
* Generate an object of code and source map from MagicString.
*/
declare function generateTransform(s: MagicString | undefined, id: string): CodeTransform | undefined;
//#endregion
export { CodeTransform, MagicString, MagicStringAST, generateTransform };

View file

@ -0,0 +1,118 @@
import MagicString from "magic-string";
export * from "magic-string"
//#region src/index.ts
/**
* MagicString with AST manipulation
*/
var MagicStringAST = class MagicStringAST {
s;
constructor(str, options, prototype = typeof str === "string" ? MagicString : str.constructor) {
this.prototype = prototype;
this.s = typeof str === "string" ? new prototype(str, options) : str;
return new Proxy(this.s, { get: (target, p, receiver) => {
if (Reflect.has(this, p)) return Reflect.get(this, p, receiver);
let parent = Reflect.get(target, p, receiver);
if (typeof parent === "function") parent = parent.bind(target);
return parent;
} });
}
getNodePos(nodes, offset = 0) {
if (Array.isArray(nodes)) return [offset + nodes[0].start, offset + nodes.at(-1).end];
else return [offset + nodes.start, offset + nodes.end];
}
removeNode(node, { offset } = {}) {
if (isEmptyNodes(node)) return this;
this.s.remove(...this.getNodePos(node, offset));
return this;
}
moveNode(node, index, { offset } = {}) {
if (isEmptyNodes(node)) return this;
this.s.move(...this.getNodePos(node, offset), index);
return this;
}
sliceNode(node, { offset } = {}) {
if (isEmptyNodes(node)) return "";
return this.s.slice(...this.getNodePos(node, offset));
}
overwriteNode(node, content, { offset,...options } = {}) {
if (isEmptyNodes(node)) return this;
const _content = typeof content === "string" ? content : this.sliceNode(content);
this.s.overwrite(...this.getNodePos(node, offset), _content, options);
return this;
}
snipNode(node, { offset } = {}) {
let newS;
if (isEmptyNodes(node)) newS = this.s.snip(0, 0);
else newS = this.s.snip(...this.getNodePos(node, offset));
return new MagicStringAST(newS, void 0, this.prototype);
}
clone() {
return new MagicStringAST(this.s.clone(), void 0, this.prototype);
}
toString() {
return this.s.toString();
}
replaceRangeState = {};
/**
* Replace a range of text with new nodes.
* @param start The start index of the range to replace.
* @param end The end index of the range to replace.
* @param nodes The nodes or strings to insert into the range.
*/
replaceRange(start, end, ...nodes) {
const state = this.replaceRangeState[this.offset] || (this.replaceRangeState[this.offset] = {
nodes: [],
indexes: {}
});
if (nodes.length) {
let index = state.indexes[start] || 0;
let intro = "";
let prevNode;
for (const node of nodes) if (typeof node === "string") node && (intro += node);
else {
this.move(node.start, node.end, start);
index = node.start;
prevNode = node;
if (intro) {
this.appendRight(index, intro);
intro = "";
}
state.nodes.push(node);
}
if (intro) this.appendLeft(prevNode?.end || start, intro);
state.indexes[start] = index;
}
if (end > start) {
let index = start;
state.nodes.filter((node) => node.start >= start && node.end <= end).sort((a, b) => a.start - b.start).forEach((node) => {
if (node.start > index) this.remove(index, node.start);
index = node.end;
});
this.remove(index, end);
}
return this;
}
};
function isEmptyNodes(nodes) {
return Array.isArray(nodes) && nodes.length === 0;
}
/**
* Generate an object of code and source map from MagicString.
*/
function generateTransform(s, id) {
if (s?.hasChanged()) return {
code: s.toString(),
get map() {
return s.generateMap({
source: id,
includeContent: true,
hires: "boundary"
});
}
};
}
//#endregion
export { MagicString, MagicStringAST, generateTransform };

View file

@ -0,0 +1,64 @@
{
"name": "magic-string-ast",
"version": "1.0.3",
"description": "magic-string with AST shortcut.",
"type": "module",
"license": "MIT",
"homepage": "https://github.com/sxzz/magic-string-ast#readme",
"bugs": {
"url": "https://github.com/sxzz/magic-string-ast/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sxzz/magic-string-ast.git"
},
"author": "Kevin Deng <sxzz@sxzz.moe>",
"funding": "https://github.com/sponsors/sxzz",
"files": [
"dist"
],
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js",
"./package.json": "./package.json"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"magic-string": "^0.30.19"
},
"devDependencies": {
"@sxzz/eslint-config": "^7.2.7",
"@sxzz/prettier-config": "^2.2.4",
"@types/node": "^24.7.0",
"bumpp": "^10.3.1",
"eslint": "^9.37.0",
"fast-glob": "^3.3.3",
"magic-string-stack": "^1.1.0",
"prettier": "^3.6.2",
"tsdown": "^0.15.6",
"tsx": "^4.20.6",
"typescript": "^5.9.3",
"vitest": "^3.2.4"
},
"engines": {
"node": ">=20.19.0"
},
"prettier": "@sxzz/prettier-config",
"tsdown": {
"exports": true,
"inlineOnly": []
},
"scripts": {
"lint": "eslint .",
"lint:fix": "pnpm run lint --fix",
"build": "tsdown",
"test": "vitest",
"typecheck": "tsc --noEmit",
"format": "prettier --cache --write .",
"release": "bumpp"
}
}