-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
508 additions
and
584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod import; | ||
pub mod memo; | ||
pub mod minify; | ||
pub mod path; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
///! 验证模块是否为文件,是就添加 .js 否就添加 /index.js | ||
///! 识别模块是否为相对路径,如何是 ts 需要处理 | ||
use swc_core::ecma::visit::{noop_visit_mut_type, VisitMut}; | ||
use swc_ecma_ast::{CallExpr, Callee, ExprOrSpread, ImportDecl, Lit, Str}; | ||
|
||
fn resolve_path(origin: &str) -> Str { | ||
return format!("{}.js", origin).into(); | ||
} | ||
|
||
#[derive(Default)] | ||
struct TransformVisitor {} | ||
|
||
impl VisitMut for TransformVisitor { | ||
noop_visit_mut_type!(); | ||
|
||
fn visit_mut_import_decl(&mut self, node: &mut ImportDecl) { | ||
node.src = resolve_path(node.src.value.as_str()).into(); | ||
} | ||
|
||
// 只处理 string 的动态导入 | ||
fn visit_mut_call_expr(&mut self, node: &mut CallExpr) { | ||
if let Callee::Import(_) = node.callee { | ||
if let Some(Some(Lit::Str(source))) = node.args.get(0).map(|e| e.expr.as_lit()) { | ||
node.args = vec![ExprOrSpread { | ||
spread: None, | ||
expr: resolve_path(source.value.as_str()).into(), | ||
}] | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn path_transform() -> impl VisitMut { | ||
TransformVisitor::default() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// @ts-nocheck | ||
import '@mantou/gem'; | ||
import '@mantou/gem/helper/react-shim'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// @ts-nocheck | ||
import '@mantou/gem/index.js'; | ||
import '@mantou/gem/helper/react-shim.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { rgbToHexColor, parseHexColor } from 'duoyun-ui/lib/color'; | ||
import { Range, Color } from 'vscode-languageserver/node'; | ||
import type { ColorInformation, ColorPresentation } from 'vscode-languageserver/node'; | ||
import type { HexColor } from 'duoyun-ui/lib/color'; | ||
import type { TextDocument } from 'vscode-languageserver-textdocument'; | ||
|
||
import { COLOR_REG } from './constants'; | ||
|
||
export class ColorProvider { | ||
provideDocumentColors(document: TextDocument) { | ||
COLOR_REG.exec('null'); | ||
|
||
const documentText = document.getText(); | ||
const colors: ColorInformation[] = []; | ||
|
||
let match: RegExpExecArray | null; | ||
while ((match = COLOR_REG.exec(documentText)) !== null) { | ||
const hex = match.groups!.content as HexColor; | ||
const [red, green, blue, alpha] = parseHexColor(hex); | ||
const offset = match.index + (match.groups!.start?.length || 0); | ||
const range = Range.create(document.positionAt(offset), document.positionAt(offset + hex.length)); | ||
const color = Color.create(red / 255, green / 255, blue / 255, alpha); | ||
colors.push({ range, color }); | ||
} | ||
return colors; | ||
} | ||
|
||
provideColorPresentations({ red, green, blue, alpha }: Color): ColorPresentation[] { | ||
return [{ label: rgbToHexColor([red * 255, green * 255, blue * 255, alpha]) }]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const COLOR_REG = /(?<start>'|")?(?<content>#([0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3,4}))($1|\s*;|\s*\))/g; | ||
|
||
// 直接通过正则匹配 css 片段,通过条件的结束 ` 号匹配 | ||
export const CSS_REG = /(?<start>\/\*\s*css\s*\*\/\s*`|(?<!`)(?:css|less|scss)\s*`)(?<content>.*?)(`(?=;|,?\s*\)))/gs; | ||
// 直接通过正则匹配 style 片段,通过条件的结束 ` 号匹配 | ||
// 语言服务和高亮都只支持 styled 写法 | ||
export const STYLE_REG = /(?<start>\/\*\s*style\s*\*\/\s*`|(?<!`)styled?\s*`)(?<content>.*?)(`(?=,|\s*}\s*\)))/gs; | ||
|
||
// 处理后进行正则匹配,所以不需要验证后面的 ` 号 | ||
export const HTML_REG = /(?<start>\/\*\s*html\s*\*\/\s*`|(?<!`)(?:html|raw)\s*`)(?<content>[^`]*)(`)/g; | ||
|
||
// 展位字符串模版中的插槽 | ||
export const SLOT_TOKEN = '_'; |
Oops, something went wrong.