Skip to content

Commit

Permalink
chore: upgrade to @weapp-core/escape@4
Browse files Browse the repository at this point in the history
  • Loading branch information
sonofmagic committed Feb 1, 2025
1 parent fe799f9 commit c8311de
Show file tree
Hide file tree
Showing 30 changed files with 519 additions and 620 deletions.
2 changes: 1 addition & 1 deletion packages/postcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"dependencies": {
"@csstools/postcss-cascade-layers": "^5.0.1",
"@csstools/postcss-is-pseudo-class": "^5.0.1",
"@weapp-core/escape": "~3.0.2",
"@weapp-core/escape": "~4.0.0",
"@weapp-tailwindcss/shared": "workspace:*",
"postcss": "~8.5.1",
"postcss-rem-to-responsive-pixel": "~6.0.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/postcss/src/shared.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { InternalCssSelectorReplacerOptions } from './types'
import { escape, SimpleMappingChars2String } from '@weapp-core/escape'
import { escape, MappingChars2String } from '@weapp-core/escape'
// css 中,要多加一个 '\' 来转义
// for raw css selector
// export function cssSelectorReplacer(selector: string, escapeEntries = MappingChars2StringEntries) {
Expand All @@ -9,7 +9,7 @@ import { escape, SimpleMappingChars2String } from '@weapp-core/escape'
export function internalCssSelectorReplacer(
selectors: string,
options: InternalCssSelectorReplacerOptions = {
escapeMap: SimpleMappingChars2String,
escapeMap: MappingChars2String,
},
) {
const { mangleContext, escapeMap } = options
Expand Down
2 changes: 1 addition & 1 deletion packages/weapp-tailwindcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"@babel/parser": "~7.26.7",
"@babel/traverse": "~7.26.7",
"@babel/types": "~7.26.7",
"@weapp-core/escape": "~3.0.2",
"@weapp-core/escape": "~4.0.0",
"@weapp-core/regex": "~1.0.1",
"@weapp-tailwindcss/init": "workspace:*",
"@weapp-tailwindcss/logger": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/weapp-tailwindcss/src/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { UserDefinedOptions } from './types'
import { SimpleMappingChars2String } from '@weapp-core/escape'
import { MappingChars2String } from '@weapp-core/escape'
import { isPackageExists } from 'local-pkg'
import { noop } from './utils'

Expand Down Expand Up @@ -86,7 +86,7 @@ export function getDefaultOptions(): UserDefinedOptions {
onUpdate: noop,

customAttributes: {},
customReplaceDictionary: SimpleMappingChars2String,
customReplaceDictionary: MappingChars2String,
appType: undefined,
arbitraryValues: {
allowDoubleQuotes: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/weapp-tailwindcss/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const customAttributes = {
- 默认模式: 把小程序中不允许的字符串,转义为**相等长度**的代替字符串,这种情况不追求转化目标字符串的一比一绝对等价,即无法从生成结果,反推原先的`class`
当然,你也可以自定义,传一个 `Record<string, string>` 类型,只需保证转化后 css 中的 `class` 选择器,不会和自己定义的 `class` 产生冲突即可,示例见[dic.ts](https://github.com/sonofmagic/weapp-core/blob/main/packages/escape/src/dic.ts)
* @default SimpleMappingChars2String
* @default MappingChars2String
*/
customReplaceDictionary?: Record<string, string>

Expand Down
4 changes: 2 additions & 2 deletions packages/weapp-tailwindcss/src/wxml/shared.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { ITemplateHandlerOptions } from '../types'
import { escape, SimpleMappingChars2String } from '@weapp-core/escape'
import { escape, MappingChars2String } from '@weapp-core/escape'

export function replaceWxml(
original: string,
options: ITemplateHandlerOptions = {
keepEOL: false,
escapeMap: SimpleMappingChars2String,
escapeMap: MappingChars2String,
},
) {
const { keepEOL, escapeMap, mangleContext, ignoreHead } = options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`all arbitrary values usages > ArbitraryVariants > Selectors 1`] = `"_ncnth-child_3__cunderline"`;
exports[`all arbitrary values usages > ArbitraryVariants > Selectors 1`] = `"_ncnth-childy3y_cunderline"`;

exports[`all arbitrary values usages > ArbitraryVariants > Selectors 2`] = `"lgc_ncnth-child_3__chovercunderline"`;
exports[`all arbitrary values usages > ArbitraryVariants > Selectors 2`] = `"lgc_ncnth-childy3y_chovercunderline"`;

exports[`all arbitrary values usages > ArbitraryVariants > Selectors 3`] = `"_n_p_cmt-4"`;

exports[`all arbitrary values usages > ArbitraryVariants > Selectors 4`] = `"_jsupports_displaycgrid__cgrid"`;
exports[`all arbitrary values usages > ArbitraryVariants > Selectors 4`] = `"_jsupportsydisplaycgridy_cgrid"`;

exports[`all arbitrary values usages > ArbitraryVariants > Selectors 5`] = `"_jmedia_any-hoverchover__nchover__copacity-100"`;
exports[`all arbitrary values usages > ArbitraryVariants > Selectors 5`] = `"_jmediayany-hoverchoveryznchoverz_copacity-100"`;

exports[`all arbitrary values usages > Backgrounds > Background Color 1`] = `"bg-_h50d71e_"`;

exports[`all arbitrary values usages > Backgrounds > Background Image 1`] = `"bg-_url_qsimgshero-patterndsvgq__"`;
exports[`all arbitrary values usages > Backgrounds > Background Image 1`] = `"bg-_urlyqsimgshero-patterndsvgqy_"`;

exports[`all arbitrary values usages > Backgrounds > Background Position 1`] = `"bg-_center_top_1rem_"`;

Expand Down Expand Up @@ -46,7 +46,7 @@ exports[`all arbitrary values usages > Borders > Ring Width 1`] = `"ring-_10px_"

exports[`all arbitrary values usages > Effects > Box Shadow 1`] = `"shadow-_inset_0_0_0_0_h50d71e_"`;

exports[`all arbitrary values usages > Effects > Box Shadow 2`] = `"shadow-_0_35px_60px_-15px_rgba_0b0b0b0d3__"`;
exports[`all arbitrary values usages > Effects > Box Shadow 2`] = `"shadow-_0_35px_60px_-15px_rgbay0b0b0b0d3y_"`;

exports[`all arbitrary values usages > Effects > Box Shadow Color 1`] = `"shadow-_h50d71e_"`;

Expand Down Expand Up @@ -116,7 +116,7 @@ exports[`all arbitrary values usages > Filters > Contrast 3`] = `"contrast-_d25_

exports[`all arbitrary values usages > Filters > Drop Shadow 1`] = `"drop-shadow-_0_0_0_0_h50d71e_"`;

exports[`all arbitrary values usages > Filters > Drop Shadow 2`] = `"drop-shadow-_0_35px_35px_rgba_0b0b0b0d25__"`;
exports[`all arbitrary values usages > Filters > Drop Shadow 2`] = `"drop-shadow-_0_35px_35px_rgbay0b0b0b0d25y_"`;

exports[`all arbitrary values usages > Filters > Grayscale 1`] = `"grayscale-_50p_"`;

Expand Down Expand Up @@ -156,17 +156,17 @@ exports[`all arbitrary values usages > Flexbox & Grid > Flex Shrink 1`] = `"shri

exports[`all arbitrary values usages > Flexbox & Grid > Gap 1`] = `"gap-_2d75rem_"`;

exports[`all arbitrary values usages > Flexbox & Grid > Grid Auto Columns 1`] = `"auto-cols-_minmax_0b_2fr__"`;
exports[`all arbitrary values usages > Flexbox & Grid > Grid Auto Columns 1`] = `"auto-cols-_minmaxy0b_2fry_"`;

exports[`all arbitrary values usages > Flexbox & Grid > Grid Auto Rows 1`] = `"auto-rows-_minmax_0b_2fr__"`;
exports[`all arbitrary values usages > Flexbox & Grid > Grid Auto Rows 1`] = `"auto-rows-_minmaxy0b_2fry_"`;

exports[`all arbitrary values usages > Flexbox & Grid > Grid Column Start / End 1`] = `"col-_16_s_span_16_"`;

exports[`all arbitrary values usages > Flexbox & Grid > Grid Row Start / End 1`] = `"row-_span_16_s_span_16_"`;

exports[`all arbitrary values usages > Flexbox & Grid > Grid Template Columns 1`] = `"grid-cols-_200px_minmax_900pxb_1fr__100px_"`;
exports[`all arbitrary values usages > Flexbox & Grid > Grid Template Columns 1`] = `"grid-cols-_200px_minmaxy900pxb_1fry_100px_"`;

exports[`all arbitrary values usages > Flexbox & Grid > Grid Template Rows 1`] = `"grid-rows-_200px_minmax_900pxb_1fr__100px_"`;
exports[`all arbitrary values usages > Flexbox & Grid > Grid Template Rows 1`] = `"grid-rows-_200px_minmaxy900pxb_1fry_100px_"`;

exports[`all arbitrary values usages > Flexbox & Grid > Order 1`] = `"order-_13_"`;

Expand Down Expand Up @@ -194,7 +194,7 @@ exports[`all arbitrary values usages > Interactivity > Caret Size 9`] = `"caret-

exports[`all arbitrary values usages > Interactivity > Caret Size 10`] = `"caret-_100px_"`;

exports[`all arbitrary values usages > Interactivity > Cursor 1`] = `"cursor-_url_handdcur_b_pointer_"`;
exports[`all arbitrary values usages > Interactivity > Cursor 1`] = `"cursor-_urlyhanddcuryb_pointer_"`;

exports[`all arbitrary values usages > Interactivity > Cursor 2`] = `"cursor-_pointer_"`;

Expand Down Expand Up @@ -392,7 +392,7 @@ exports[`all arbitrary values usages > Transitions & Animation > Transition Prop

exports[`all arbitrary values usages > Transitions & Animation > Transition Property 3`] = `"transition-_height_"`;

exports[`all arbitrary values usages > Transitions & Animation > Transition Timing Function 1`] = `"ease-_cubic-bezier_0d95b0d05b0d795b0d035__"`;
exports[`all arbitrary values usages > Transitions & Animation > Transition Timing Function 1`] = `"ease-_cubic-beziery0d95b0d05b0d795b0d035y_"`;

exports[`all arbitrary values usages > Typography > Content 1`] = `"beforeccontent-_qHello_Worldq_"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`customReplaceDictionary > styleHandler complex mode 1`] = `".w-_0d5px_{--tw-border-opacity: 1;}"`;

exports[`customReplaceDictionary > styleHandler custom map 1`] = `".w--0d5px-{--tw-border-opacity: 1;}"`;

exports[`customReplaceDictionary > styleHandler default(complex) mode 1`] = `".w-_0d5px_{--tw-border-opacity: 1;}"`;

exports[`customReplaceDictionary > templateHandler complex mode 1`] = `"<van-image class="w-_0d5px_" custom-class="w-[0.5px]" image-class="w-[0.5px]" other-attr="w-_0d5px_"></van-image>"`;

exports[`customReplaceDictionary > templateHandler custom map 1`] = `"<van-image class="w--0d5px-" custom-class="w-[0.5px]" image-class="w-[0.5px]" other-attr="w--0d5px-"></van-image>"`;

exports[`customReplaceDictionary > templateHandler default(complex) mode 1`] = `"<van-image class="w-_0d5px_" custom-class="w-[0.5px]" image-class="w-[0.5px]" other-attr="w-_0d5px_"></van-image>"`;
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ view,text,::before,::after {
--tw-bg-opacity: 1;
background-color: rgb(255 255 255 / var(--tw-bg-opacity, 1))
}
.bg-_url_qhttpscssxxxdcomsxxdwebpq__ {
.bg-_urlyqhttpscssxxxdcomsxxdwebpqy_ {
background-image: url('https://xxx.com/xx.webp')
}
.bg-_url_httpscsspic1dzhimgdcomsv2-3ee20468f54bbfefcd0027283b21aaa8_720wdjpg__ {
.bg-_urlyhttpscsspic1dzhimgdcomsv2-3ee20468f54bbfefcd0027283b21aaa8_720wdjpgy_ {
background-image: url(https://pic1.zhimg.com/v2-3ee20468f54bbfefcd0027283b21aaa8_720w.jpg)
}
.bg-_lengthc100p_100p_ {
Expand Down Expand Up @@ -214,7 +214,7 @@ Page({
motto: 'Hello World',
userInfo: {},
contentStyle: 'mt-_24px_',
classNames: "bg-_url_qhttpscssxxxdcomsxxdwebpq__ text-_h123456_ text-_50px_ bg-_hfff_"
classNames: "bg-_urlyqhttpscssxxxdcomsxxdwebpqy_ text-_h123456_ text-_50px_ bg-_hfff_"
},
onLoad: function () {},
copyText: function (e) {
Expand Down Expand Up @@ -242,7 +242,7 @@ exports[`gulp > common build > wxml 1`] = `
"<!-- index.wxml -->
<view class="h-full text-center">
<view class="m-_20px_">
<view class="bg-_url_httpscsspic1dzhimgdcomsv2-3ee20468f54bbfefcd0027283b21aaa8_720wdjpg__ bg-_lengthc100p_100p_ bg-no-repeat w-screen h-_41d54vw_"></view>
<view class="bg-_urlyhttpscsspic1dzhimgdcomsv2-3ee20468f54bbfefcd0027283b21aaa8_720wdjpgy_ bg-_lengthc100p_100p_ bg-no-repeat w-screen h-_41d54vw_"></view>
<view class="space-y-4">
<view class="text-_14px_">基于Gulp 的微信小程序前端开发工作流</view>
<view class="text-_14px_ text-_h5ba4e5_" bindtap="copyText" data-text="https://github.com/sonofmagic/weapp-tailwindcss">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ exports[`jsHandler > "after:content-["对酒当歌,人生几何"]" 1`] = `"con

exports[`jsHandler > 'common' "after:content-['对酒当歌,人生几何']" 1`] = `"const a = "afterccontent-_qu5bf9u9152u5f53u6b4cuff0cu4ebau751fu51e0u4f55q_""`;

exports[`jsHandler > 'common' TemplateElement case 0 1`] = `"const p = 'text-_12px_';const n = \`bg-_urlyqu5929u6c14u597dqy_\${p}text-_199px_ \\n\\n flex \\n\\n bg-_red_ '\`"`;

exports[`jsHandler > 'common' img url case 1`] = `
"data: {
classNames: "bg-_url_qhttpscssylnavdcomsassetssimagessvusdivider-graydwebpq__"
classNames: "bg-_urlyqhttpscssylnavdcomsassetssimagessvusdivider-graydwebpqy_"
}"
`;

Expand All @@ -16,6 +18,8 @@ exports[`jsHandler > 'common' mpx jit classNames 1`] = `
}"
`;

exports[`jsHandler > astGrep TemplateElement case 0 1`] = `"const p = 'text-_12px_ leading-_24px_';const n = \`bg-_urlyqu5929u6c14u597dqy_\${p}text-_199px_ \\n\\n flex \\n\\n bg-_red_ '\`"`;

exports[`jsHandler > empty case 0 1`] = `
{
"code": "const a = ''",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ exports[`get options > default options 1`] = `
"%": "p",
"&": "n",
"'": "q",
"(": "_",
")": "_",
"(": "y",
")": "y",
"*": "m",
"+": "a",
",": "b",
Expand All @@ -85,9 +85,9 @@ exports[`get options > default options 1`] = `
"]": "_",
"^": "k",
"\`": "v",
"{": "_",
"{": "z",
"|": "u",
"}": "_",
"}": "z",
"~": "t",
},
"customRuleCallback": [Function],
Expand All @@ -101,8 +101,8 @@ exports[`get options > default options 1`] = `
"%": "p",
"&": "n",
"'": "q",
"(": "_",
")": "_",
"(": "y",
")": "y",
"*": "m",
"+": "a",
",": "b",
Expand All @@ -120,9 +120,9 @@ exports[`get options > default options 1`] = `
"]": "_",
"^": "k",
"\`": "v",
"{": "_",
"{": "z",
"|": "u",
"}": "_",
"}": "z",
"~": "t",
},
"htmlMatcher": [Function],
Expand Down
Loading

0 comments on commit c8311de

Please sign in to comment.