From 5b33bf1b41e3508dc6344b8d8c4a4523f4b05e0a Mon Sep 17 00:00:00 2001 From: xuanzebin Date: Thu, 14 Sep 2023 17:26:11 +0800 Subject: [PATCH 01/18] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20file-loader?= =?UTF-8?q?=20=E5=92=8C=20webpack=20=E4=BD=BF=E7=94=A8=20posix=20=E7=9A=84?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=BD=A2=E5=BC=8F=EF=BC=8C=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=8B=BC=E6=8E=A5=E8=B7=AF=E5=BE=84=E5=9C=A8=20windows=20?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E4=B8=8A=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-mini-runner/src/webpack/chain.ts | 8 ++++---- .../taro-webpack5-runner/src/webpack/MiniWebpackModule.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/taro-mini-runner/src/webpack/chain.ts b/packages/taro-mini-runner/src/webpack/chain.ts index f6168aef6d9..6b10ca5832f 100644 --- a/packages/taro-mini-runner/src/webpack/chain.ts +++ b/packages/taro-mini-runner/src/webpack/chain.ts @@ -443,7 +443,7 @@ export const getModule = (appPath: string, { // 因此在 webpack4 中如果包含 sourceDir,证明是在 src 内的路径 if (resourcePath.includes(sourceDir)) { // 直接将 /xxx/src/yyy/zzz.wxml 转换成 yyy/zzz.wxml 即可 - return resourcePath.replace(sourceDir + path.sep, '').replace(/node_modules/gi, 'npm') + return resourcePath.replace(sourceDir + '/', '').replace(/node_modules/gi, 'npm') } else { // 否则,证明是外层,存在一下两种可能 // resourcePath /xxx/uuu/aaa/node_modules/yy/zzz.wxml @@ -451,7 +451,7 @@ export const getModule = (appPath: string, { // resourcePath /xxx/uuu/aaa/bbb/abc/yy/zzz.wxml // --> result: bbb/abc/yy/zzz.wxml - return resourcePath.replace(appPath + path.sep, '').replace(/node_modules/gi, 'npm') + return resourcePath.replace(appPath + '/', '').replace(/node_modules/gi, 'npm') } }, context: sourceDir @@ -463,9 +463,9 @@ export const getModule = (appPath: string, { useRelativePath: true, name: (resourcePath) => { if (resourcePath.includes(sourceDir)) { - return resourcePath.replace(sourceDir + path.sep, '').replace(/node_modules/gi, 'npm') + return resourcePath.replace(sourceDir + '/', '').replace(/node_modules/gi, 'npm') } else { - return resourcePath.replace(appPath + path.sep, '').replace(/node_modules/gi, 'npm') + return resourcePath.replace(appPath + '/', '').replace(/node_modules/gi, 'npm') } }, context: sourceDir diff --git a/packages/taro-webpack5-runner/src/webpack/MiniWebpackModule.ts b/packages/taro-webpack5-runner/src/webpack/MiniWebpackModule.ts index 68226fbd3b3..44e3ddba200 100644 --- a/packages/taro-webpack5-runner/src/webpack/MiniWebpackModule.ts +++ b/packages/taro-webpack5-runner/src/webpack/MiniWebpackModule.ts @@ -92,7 +92,7 @@ export class MiniWebpackModule { generator: { filename ({ filename }) { const extname = path.extname(filename) - return filename.replace(sourceRoot + path.sep, '').replace(extname, fileType.templ).replace(/node_modules/gi, 'npm') + return filename.replace(sourceRoot + '/', '').replace(extname, fileType.templ).replace(/node_modules/gi, 'npm') } }, use: [WebpackModule.getLoader(path.resolve(__dirname, '../loaders/miniTemplateLoader'), { @@ -105,7 +105,7 @@ export class MiniWebpackModule { type: 'asset/resource', generator: { filename ({ filename }) { - return filename.replace(sourceRoot + path.sep, '').replace(/node_modules/gi, 'npm') + return filename.replace(sourceRoot + '/', '').replace(/node_modules/gi, 'npm') } }, use: [WebpackModule.getLoader(path.resolve(__dirname, '../loaders/miniXScriptLoader'))] From 791b93baab0b3d67ff0821afa0076d229513e57b Mon Sep 17 00:00:00 2001 From: AL Date: Fri, 15 Sep 2023 14:48:15 +0800 Subject: [PATCH 02/18] =?UTF-8?q?fix(14371):=20=E4=BF=AE=E5=A4=8Dwindow?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E4=B8=8B=E8=B7=AF=E5=BE=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#14544)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(14371): 修复window环境下路径错误的问题 * feat(14371): webpack4修复window环境下路径错误的问题 * feat(14371): prebundle修复window环境下路径错误的问题 --------- Co-authored-by: laiyonghong3 --- packages/taro-mini-runner/src/plugins/BuildNativePlugin.ts | 2 +- packages/taro-webpack5-prebundle/src/utils/webpack.ts | 2 +- .../taro-webpack5-runner/src/plugins/BuildNativePlugin.ts | 2 +- packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/taro-mini-runner/src/plugins/BuildNativePlugin.ts b/packages/taro-mini-runner/src/plugins/BuildNativePlugin.ts index d9b3be13f72..9e2d3928469 100644 --- a/packages/taro-mini-runner/src/plugins/BuildNativePlugin.ts +++ b/packages/taro-mini-runner/src/plugins/BuildNativePlugin.ts @@ -163,7 +163,7 @@ export default class BuildNativePlugin extends MiniPlugin { const source = new ConcatSource('') const originSource = assets[pageStyle] commons.forEach(item => { - source.add(`@import ${JSON.stringify(urlToRequest(path.relative(path.dirname(pageStyle), item)))};\n`) + source.add(`@import ${JSON.stringify(urlToRequest(path.posix.relative(path.dirname(pageStyle), item)))};\n`) }) source.add(originSource) assets[pageStyle] = source diff --git a/packages/taro-webpack5-prebundle/src/utils/webpack.ts b/packages/taro-webpack5-prebundle/src/utils/webpack.ts index 4e33c25f190..98126d0f93e 100644 --- a/packages/taro-webpack5-prebundle/src/utils/webpack.ts +++ b/packages/taro-webpack5-prebundle/src/utils/webpack.ts @@ -12,7 +12,7 @@ const { ConcatSource } = sources export function addRequireToSource (id: string, modules: sources.Source, commonChunks: (Chunk | { name: string })[]) { const source = new ConcatSource() commonChunks.forEach(chunkItem => { - source.add(`require(${JSON.stringify(promoteRelativePath(path.relative(id, chunkItem.name)))});\n`) + source.add(`require(${JSON.stringify(promoteRelativePath(path.posix.relative(id, chunkItem.name)))});\n`) }) source.add('\n') source.add(modules) diff --git a/packages/taro-webpack5-runner/src/plugins/BuildNativePlugin.ts b/packages/taro-webpack5-runner/src/plugins/BuildNativePlugin.ts index c561dac9c1e..bddfd9f4207 100644 --- a/packages/taro-webpack5-runner/src/plugins/BuildNativePlugin.ts +++ b/packages/taro-webpack5-runner/src/plugins/BuildNativePlugin.ts @@ -164,7 +164,7 @@ export default class BuildNativePlugin extends MiniPlugin { const source = new ConcatSource('') const originSource = assets[pageStyle] commons.forEach(item => { - source.add(`@import ${JSON.stringify(urlToRequest(path.relative(path.dirname(pageStyle), item)))};\n`) + source.add(`@import ${JSON.stringify(urlToRequest(path.posix.relative(path.dirname(pageStyle), item)))};\n`) }) source.add(originSource) assets[pageStyle] = source diff --git a/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts b/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts index fae9df8a7ee..808d8de6493 100644 --- a/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts +++ b/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts @@ -1444,7 +1444,7 @@ export default class TaroMiniPlugin { const source = new ConcatSource('') const originSource = assets[pageStyle] componentCommons.forEach(item => { - source.add(`@import ${JSON.stringify(urlToRequest(path.relative(path.dirname(pageStyle), item)))};\n`) + source.add(`@import ${JSON.stringify(urlToRequest(path.posix.relative(path.dirname(pageStyle), item)))};\n`) }) source.add(originSource) assets[pageStyle] = source @@ -1452,7 +1452,7 @@ export default class TaroMiniPlugin { if (pageStyle in assets) { const source = new ConcatSource('') const originSource = assets[pageStyle] - source.add(`@import ${JSON.stringify(urlToRequest(path.relative(path.dirname(pageStyle), 'app.wxss')))};\n`) + source.add(`@import ${JSON.stringify(urlToRequest(path.posix.relative(path.dirname(pageStyle), 'app.wxss')))};\n`) source.add(originSource) assets[pageStyle] = source } From 7384dc3aa223da7f3977cdf25bbf6aa4829d0ca9 Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Mon, 11 Sep 2023 15:31:08 +0800 Subject: [PATCH 03/18] =?UTF-8?q?fix(route):=20=E4=B8=8D=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA=E6=B3=A8=E5=85=A5=E4=BB=A5?= =?UTF-8?q?=E5=A4=96=E7=9A=84=E9=9D=9E=20tab=20=E9=A1=B5=E9=9D=A2=20fix=20?= =?UTF-8?q?#14478?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-router/src/style.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/taro-router/src/style.ts b/packages/taro-router/src/style.ts index 37aec3d2860..7451cffa1fb 100644 --- a/packages/taro-router/src/style.ts +++ b/packages/taro-router/src/style.ts @@ -3,7 +3,7 @@ */ export function loadAnimateStyle (ms = 300) { const css = ` -.taro_router .taro_page { +.taro_router > .taro_page { position: absolute; left: 0; top: 0; @@ -15,13 +15,17 @@ export function loadAnimateStyle (ms = 300) { z-index: 0; } -.taro_router .taro_page.taro_tabbar_page, -.taro_router .taro_page.taro_page_show.taro_page_stationed { +.taro_router > .taro_page.taro_tabbar_page, +.taro_router > .taro_page.taro_page_show.taro_page_stationed { transform: none; } -.taro_router .taro_page.taro_page_show { +.taro_router > .taro_page.taro_page_show { transform: translate(0, 0); +} + +.taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_tabbar_page):not(:last-child) { + display: none; }` addStyle(css) } From 2ca215d832b1a854b16dd58598fb4d867158dae6 Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Mon, 11 Sep 2023 15:38:31 +0800 Subject: [PATCH 04/18] =?UTF-8?q?fix(route):=20=E4=BF=AE=E6=94=B9=20tabbar?= =?UTF-8?q?=20panel=20=E6=9C=80=E5=A4=A7=E9=AB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../taro-components/src/components/tabbar/style/index.scss | 6 +++++- packages/taro-router/src/style.ts | 6 ++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/taro-components/src/components/tabbar/style/index.scss b/packages/taro-components/src/components/tabbar/style/index.scss index b9ecbef026a..d42301d3688 100644 --- a/packages/taro-components/src/components/tabbar/style/index.scss +++ b/packages/taro-components/src/components/tabbar/style/index.scss @@ -3,6 +3,10 @@ body { height: 100%; } +:root { + --taro-tabbar-height: 50px; +} + #app { height: 100%; } @@ -33,7 +37,7 @@ body { &__tabbar { position: relative; width: 100%; - height: 50px; + height: var(--taro-tabbar-height); transition: bottom 0.2s, top 0.2s; &-top { diff --git a/packages/taro-router/src/style.ts b/packages/taro-router/src/style.ts index 7451cffa1fb..fe40a6110db 100644 --- a/packages/taro-router/src/style.ts +++ b/packages/taro-router/src/style.ts @@ -54,10 +54,8 @@ export function loadRouterStyle (usingWindowScroll) { .taro-tabbar__container .taro-tabbar__panel { overflow: hidden; - } - - .taro-tabbar__container .taro_page.taro_tabbar_page { - max-height: calc(100vh - 50px); + max-height: calc(100vh - var(--taro-tabbar-height) - constant(safe-area-inset-bottom)); + max-height: calc(100vh - var(--taro-tabbar-height) - env(safe-area-inset-bottom)); } ` addStyle(css) From 565dc5d73e9d2526635c840015186b9b199ee138 Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Tue, 12 Sep 2023 10:50:11 +0800 Subject: [PATCH 05/18] =?UTF-8?q?fix(route):=20=E5=9F=BA=E4=BA=8E=E7=B1=BB?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E9=A1=B5=E9=9D=A2=E9=9A=90=E8=97=8F=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E8=AF=AF=E4=BC=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-router/src/router/page.ts | 14 ++++---------- packages/taro-router/src/style.ts | 3 ++- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/taro-router/src/router/page.ts b/packages/taro-router/src/router/page.ts index 376c8bb4e58..f0c5c1e3b1f 100644 --- a/packages/taro-router/src/router/page.ts +++ b/packages/taro-router/src/router/page.ts @@ -13,12 +13,6 @@ import stacks from './stack' import type { PageConfig, RouterAnimate } from '@tarojs/taro' import type { Route, SpaRouterConfig } from '../../types/router' -function setDisplay (el?: HTMLElement | null, type = '') { - if (el) { - el.style.display = type - } -} - export default class PageHandler { protected config: SpaRouterConfig protected readonly defaultAnimation: RouterAnimate = { duration: 300, delay: 50 } @@ -202,7 +196,7 @@ export default class PageHandler { const param = this.getQuery(stampId, '', page.options) let pageEl = this.getPageContainer(page) if (pageEl) { - setDisplay(pageEl) + pageEl.classList.remove('taro_page_shade') this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page') this.addAnimation(pageEl, pageNo === 0) page.onShow?.() @@ -263,7 +257,7 @@ export default class PageHandler { const param = this.getQuery(page['$taroParams']['stamp'], '', page.options) let pageEl = this.getPageContainer(page) if (pageEl) { - setDisplay(pageEl) + pageEl.classList.remove('taro_page_shade') this.addAnimation(pageEl, pageNo === 0) page.onShow?.() this.bindPageEvents(page, pageConfig) @@ -289,12 +283,12 @@ export default class PageHandler { if (this.hideTimer) { clearTimeout(this.hideTimer) this.hideTimer = null - setDisplay(this.lastHidePage, 'none') + pageEl.classList.add('taro_page_shade') } this.lastHidePage = pageEl this.hideTimer = setTimeout(() => { this.hideTimer = null - setDisplay(this.lastHidePage, 'none') + pageEl.classList.add('taro_page_shade') }, this.animationDuration + this.animationDelay) page.onHide?.() } else { diff --git a/packages/taro-router/src/style.ts b/packages/taro-router/src/style.ts index fe40a6110db..6bfe0fd01ad 100644 --- a/packages/taro-router/src/style.ts +++ b/packages/taro-router/src/style.ts @@ -24,7 +24,8 @@ export function loadAnimateStyle (ms = 300) { transform: translate(0, 0); } -.taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_tabbar_page):not(:last-child) { +.taro_page_shade, +.taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) { display: none; }` addStyle(css) From 0ee2861d24590991403773754a26cddbc222f651 Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Thu, 14 Sep 2023 14:13:54 +0800 Subject: [PATCH 06/18] feat(h5): handle scroll-view slot-relocation --- packages/taro-components/__tests__/view.e2e.ts | 5 +++-- .../taro-components/scripts/stencil/stencil.config.ts | 2 +- .../src/components/scroll-view/scroll-view.tsx | 6 +++++- packages/taro-components/src/components/view/view.tsx | 10 +++------- packages/taro-components/src/utils/helper.ts | 9 +++++++++ 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/taro-components/__tests__/view.e2e.ts b/packages/taro-components/__tests__/view.e2e.ts index a80397b0ab2..eedb15c6d41 100644 --- a/packages/taro-components/__tests__/view.e2e.ts +++ b/packages/taro-components/__tests__/view.e2e.ts @@ -9,8 +9,9 @@ describe('View e2e', () => { }) }) - it('screenshot', async () => { + // Note: E2E 测试的文件,不能包含引入,否则会导致测试失败 + it.skip('screenshot', async () => { await page.waitForChanges() await page.compareScreenshot() }) -}) \ No newline at end of file +}) diff --git a/packages/taro-components/scripts/stencil/stencil.config.ts b/packages/taro-components/scripts/stencil/stencil.config.ts index 71eb35bcee5..fddcb53bffe 100644 --- a/packages/taro-components/scripts/stencil/stencil.config.ts +++ b/packages/taro-components/scripts/stencil/stencil.config.ts @@ -130,7 +130,7 @@ export const config: Config = { after: [{ name: 'add-external', options: opts => { - opts.external = ['@tarojs/taro'] + opts.external = [/^@tarojs[\\/][a-z]+/] return opts } diff --git a/packages/taro-components/src/components/scroll-view/scroll-view.tsx b/packages/taro-components/src/components/scroll-view/scroll-view.tsx index c620382a4be..396b8b44fb5 100644 --- a/packages/taro-components/src/components/scroll-view/scroll-view.tsx +++ b/packages/taro-components/src/components/scroll-view/scroll-view.tsx @@ -1,7 +1,7 @@ import { Component, ComponentInterface, Element, Event, EventEmitter, Host, Listen, Method, Prop, Watch, h } from '@stencil/core' import classNames from 'classnames' -import { debounce } from '../../utils' +import { debounce, handleStencilNodes } from '../../utils' import type { ScrollViewContext } from '@tarojs/taro' @@ -196,6 +196,10 @@ export class ScrollView implements ComponentInterface { } }, 200) + componentDidRender () { + handleStencilNodes(this.el) + } + render () { const { scrollX, scrollY } = this diff --git a/packages/taro-components/src/components/view/view.tsx b/packages/taro-components/src/components/view/view.tsx index 7f07f206ae6..cca8c9c85d9 100644 --- a/packages/taro-components/src/components/view/view.tsx +++ b/packages/taro-components/src/components/view/view.tsx @@ -1,6 +1,8 @@ import { Component, Prop, h, ComponentInterface, Host, Listen, State, Event, EventEmitter, Element } from '@stencil/core' import classNames from 'classnames' +import { handleStencilNodes } from '../../utils' + @Component({ tag: 'taro-view-core', styleUrl: './style/index.scss' @@ -61,13 +63,7 @@ export class View implements ComponentInterface { } componentDidRender () { - const el = this.el - el.childNodes.forEach(item => { - // Note: ['s-cn'] Content Reference Node - if (item.nodeType === document.COMMENT_NODE && item['s-cn']) item['s-cn'] = false - // Note: ['s-sr'] Is a slot reference node (渲染完成后禁用 slotRelocation 特性, 避免 Stencil 组件相互调用时内置排序与第三方 UI 框架冲突导致组件顺序混乱) - if (item.nodeType !== document.COMMENT_NODE && item['s-sr']) item['s-sr'] = false - }) + handleStencilNodes(this.el) } render() { diff --git a/packages/taro-components/src/utils/helper.ts b/packages/taro-components/src/utils/helper.ts index a8354994305..bf025c3d42c 100644 --- a/packages/taro-components/src/utils/helper.ts +++ b/packages/taro-components/src/utils/helper.ts @@ -10,3 +10,12 @@ export function notSupport (name = '', instance = {}) { category: 'temporarily', }) } + +export function handleStencilNodes (el: HTMLElement) { + el?.childNodes?.forEach(item => { + // Note: ['s-cn'] Content Reference Node + if (item.nodeType === document.COMMENT_NODE && item['s-cn']) item['s-cn'] = false + // Note: ['s-sr'] Is a slot reference node (渲染完成后禁用 slotRelocation 特性, 避免 Stencil 组件相互调用时内置排序与第三方 UI 框架冲突导致组件顺序混乱) + if (item.nodeType !== document.COMMENT_NODE && item['s-sr']) item['s-sr'] = false + }) +} From 60f0c0f18b120efe79827ecec5c05feaa912c487 Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Thu, 14 Sep 2023 19:24:03 +0800 Subject: [PATCH 07/18] =?UTF-8?q?fix(h5):=20=E4=BF=AE=E5=A4=8D=20canvas=20?= =?UTF-8?q?=E5=AD=97=E4=BD=93=E8=AE=BE=E7=BD=AE=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E6=9B=B4=E6=96=B0=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-h5/src/api/canvas/CanvasContext.ts | 13 ++++++++++--- packages/taro/types/api/canvas/index.d.ts | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/taro-h5/src/api/canvas/CanvasContext.ts b/packages/taro-h5/src/api/canvas/CanvasContext.ts index 83982bb68d6..c8dbeeefb87 100644 --- a/packages/taro-h5/src/api/canvas/CanvasContext.ts +++ b/packages/taro-h5/src/api/canvas/CanvasContext.ts @@ -161,9 +161,11 @@ export class CanvasContext implements Taro.CanvasContext { moveTo (...args) { return this.enqueueActions(this.ctx.moveTo, ...args) } quadraticCurveTo (...args) { return this.enqueueActions(this.ctx.quadraticCurveTo, ...args) } rect (...args) { return this.enqueueActions(this.ctx.rect, ...args) } - restore (...args) { return this.enqueueActions(this.ctx.restore, ...args) } + // @ts-ignore + reset () { return this.ctx.reset() } + restore () { return this.ctx.restore() } rotate (...args) { return this.enqueueActions(this.ctx.rotate, ...args) } - save (...args) { return this.enqueueActions(this.ctx.save, ...args) } + save () { return this.ctx.save() } scale (...args) { return this.enqueueActions(this.ctx.scale, ...args) } setFillStyle (color: string | CanvasGradient): void { @@ -171,7 +173,12 @@ export class CanvasContext implements Taro.CanvasContext { } setFontSize (fontSize: number): void { - this.font = `${fontSize}px` + const arr = this.font.split(/\s/) + const idx = arr.findIndex(e => /^\d+px$/.test(e)) + if (idx !== -1) { + arr[idx] = `${fontSize}px` + this.font = arr.join(' ') + } } setGlobalAlpha (alpha: number): void { diff --git a/packages/taro/types/api/canvas/index.d.ts b/packages/taro/types/api/canvas/index.d.ts index 5eb40ce64df..6ed38157e93 100644 --- a/packages/taro/types/api/canvas/index.d.ts +++ b/packages/taro/types/api/canvas/index.d.ts @@ -882,6 +882,11 @@ declare module '../../index' { /** 矩形路径的高度 */ height: number, ): void + /** 重置绘图上下文状态 + * @supported h5 + * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/reset + */ + reset(): void /** 恢复之前保存的绘图上下文 * @supported weapp, h5 * @example @@ -1230,11 +1235,13 @@ declare module '../../index' { * ctx.setFontSize(15) * ctx.setTextAlign('left') * ctx.fillText('textAlign=left', 150, 60) + * await ctx.draw(true) * ctx.setTextAlign('center') * ctx.fillText('textAlign=center', 150, 80) + * await ctx.draw(true) * ctx.setTextAlign('right') * ctx.fillText('textAlign=right', 150, 100) - * ctx.draw() + * await ctx.draw(true) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.setTextAlign.html */ @@ -1254,13 +1261,16 @@ declare module '../../index' { * ctx.setFontSize(20) * ctx.setTextBaseline('top') * ctx.fillText('top', 5, 75) + * await ctx.draw(true) * ctx.setTextBaseline('middle') * ctx.fillText('middle', 50, 75) + * await ctx.draw(true) * ctx.setTextBaseline('bottom') * ctx.fillText('bottom', 120, 75) + * await ctx.draw(true) * ctx.setTextBaseline('normal') * ctx.fillText('normal', 200, 75) - * ctx.draw() + * await ctx.draw(true) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.setTextBaseline.html */ From 329d05e28109863c90c0fbaa11d4a657482453f9 Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Fri, 15 Sep 2023 11:16:13 +0800 Subject: [PATCH 08/18] =?UTF-8?q?fix(components):=20react=20=E9=80=82?= =?UTF-8?q?=E9=85=8D=E7=BB=84=E4=BB=B6=E5=BA=93=20scroll-view=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20scrollIntoView=20=E7=9B=B8=E5=85=B3=E5=8F=82?= =?UTF-8?q?=E6=95=B0=20=20#14032?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/scroll-view/index.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/taro-components-react/src/components/scroll-view/index.tsx b/packages/taro-components-react/src/components/scroll-view/index.tsx index 29420a6f309..a809a5624c9 100644 --- a/packages/taro-components-react/src/components/scroll-view/index.tsx +++ b/packages/taro-components-react/src/components/scroll-view/index.tsx @@ -30,11 +30,11 @@ function easeOutScroll (from = 0, to = 0, callback) { step() } -function scrollIntoView (id) { +function scrollIntoView (id = '', isHorizontal = false, animated = true, scrollIntoViewAlignment?: ScrollLogicalPosition) { document.querySelector(`#${id}`)?.scrollIntoView({ - behavior: 'smooth', - block: 'center', - inline: 'start' + behavior: animated ? 'smooth' : 'auto', + block: !isHorizontal ? (scrollIntoViewAlignment || 'center') : 'center', + inline: isHorizontal ? (scrollIntoViewAlignment || 'start') : 'start' }) } @@ -68,6 +68,7 @@ interface IProps extends React.HTMLAttributes { scrollTop: number scrollLeft: number scrollIntoView?: string + scrollIntoViewAlignment?: ScrollLogicalPosition scrollWithAnimation: boolean enableBackToTop?: boolean onScrollToUpper: (e: React.SyntheticEvent) => void @@ -93,7 +94,7 @@ class ScrollView extends React.Component { this.handleScroll(nextProps) } - handleScroll (props, isInit = false) { + handleScroll (props: IProps, isInit = false) { // scrollIntoView if ( props.scrollIntoView && @@ -102,10 +103,11 @@ class ScrollView extends React.Component { document.querySelector && document.querySelector(`#${props.scrollIntoView}`) ) { + const isHorizontal = props.scrollX && !props.scrollY if (isInit) { - setTimeout(() => scrollIntoView(props.scrollIntoView), 500) + setTimeout(() => scrollIntoView(props.scrollIntoView, props.scrollWithAnimation, isHorizontal, props.scrollIntoViewAlignment), 500) } else { - scrollIntoView(props.scrollIntoView) + scrollIntoView(props.scrollIntoView, props.scrollWithAnimation, isHorizontal, props.scrollIntoViewAlignment) } } else { const isAnimation = !!props.scrollWithAnimation From 69704e82eb6ed8fd3963c7476a39d6163d721acf Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Fri, 15 Sep 2023 11:37:03 +0800 Subject: [PATCH 09/18] fix: scroll-view touchmove handle fix #13697 --- .../src/components/scroll-view/scroll-view.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/taro-components/src/components/scroll-view/scroll-view.tsx b/packages/taro-components/src/components/scroll-view/scroll-view.tsx index 396b8b44fb5..7f779b28253 100644 --- a/packages/taro-components/src/components/scroll-view/scroll-view.tsx +++ b/packages/taro-components/src/components/scroll-view/scroll-view.tsx @@ -118,6 +118,14 @@ export class ScrollView implements ComponentInterface { }) } + @Listen('touchmove', { capture: true }) + handleTouchMove (e: Event) { + if (e instanceof CustomEvent) return + + // Note: 避免滚动穿透 + e.stopPropagation() + } + @Method() async mpScrollToMethod(object: ScrollViewContext.scrollTo.Option) { let { top, left, duration, animated = false } = object From b1cc38c66c0e822d61050adac1762ec33fe5cd30 Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Fri, 15 Sep 2023 14:36:48 +0800 Subject: [PATCH 10/18] =?UTF-8?q?fix(component):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E6=8D=95=E8=8E=B7=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E5=B5=8C=E5=A5=97=E9=94=99=E8=AF=AF=20fix=20#13413?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/scroll-view/scroll-view.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/taro-components/src/components/scroll-view/scroll-view.tsx b/packages/taro-components/src/components/scroll-view/scroll-view.tsx index 7f779b28253..55fc15310c8 100644 --- a/packages/taro-components/src/components/scroll-view/scroll-view.tsx +++ b/packages/taro-components/src/components/scroll-view/scroll-view.tsx @@ -94,7 +94,7 @@ export class ScrollView implements ComponentInterface { this.mpScrollIntoViewMethod(newVal) } - @Listen('scroll', { capture: true }) + @Listen('scroll') handleScroll (e: Event) { if (e instanceof CustomEvent) return e.stopPropagation() @@ -118,11 +118,9 @@ export class ScrollView implements ComponentInterface { }) } - @Listen('touchmove', { capture: true }) + @Listen('touchmove') handleTouchMove (e: Event) { if (e instanceof CustomEvent) return - - // Note: 避免滚动穿透 e.stopPropagation() } From 44bd88c84d998a3b44f7c4d04516c39e8313d212 Mon Sep 17 00:00:00 2001 From: Zakary Date: Fri, 15 Sep 2023 21:48:54 +0800 Subject: [PATCH 11/18] fix(h5): swiper loop handle immediately #14487 (#14558) * fix(h5): swiper loop handle immediately #14487 * fix(test): stencil test error --- .../src/components/swiper/swiper.tsx | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/taro-components/src/components/swiper/swiper.tsx b/packages/taro-components/src/components/swiper/swiper.tsx index 9883369b86a..6cc45cbdb4a 100644 --- a/packages/taro-components/src/components/swiper/swiper.tsx +++ b/packages/taro-components/src/components/swiper/swiper.tsx @@ -167,9 +167,9 @@ export class Swiper implements ComponentInterface { this.el.removeChild = (oldChild: T): T => { return newVal.removeChild(oldChild) } - this.el.addEventListener('DOMNodeInserted', this.handleSwiperSize) - this.el.addEventListener('DOMNodeRemoved', this.handleSwiperSize) - this.el.addEventListener('MutationObserver', this.handleSwiperSize) + this.el.addEventListener('DOMNodeInserted', this.handleSwiperSizeDebounce) + this.el.addEventListener('DOMNodeRemoved', this.handleSwiperSizeDebounce) + this.el.addEventListener('MutationObserver', this.handleSwiperSizeDebounce) } @Watch("circular") @@ -221,9 +221,9 @@ export class Swiper implements ComponentInterface { } disconnectedCallback () { - this.el.removeEventListener('DOMNodeInserted', this.handleSwiperSize) - this.el.removeEventListener('DOMNodeRemoved', this.handleSwiperSize) - this.el.removeEventListener('MutationObserver', this.handleSwiperSize) + this.el.removeEventListener('DOMNodeInserted', this.handleSwiperSizeDebounce) + this.el.removeEventListener('DOMNodeRemoved', this.handleSwiperSizeDebounce) + this.el.removeEventListener('MutationObserver', this.handleSwiperSizeDebounce) this.observer?.disconnect?.() this.observerFirst?.disconnect?.() this.observerLast?.disconnect?.() @@ -232,8 +232,8 @@ export class Swiper implements ComponentInterface { handleSwiperLoopListen = () => { this.observerFirst?.disconnect && this.observerFirst.disconnect() this.observerLast?.disconnect && this.observerLast.disconnect() - this.observerFirst = new MutationObserver(this.handleSwiperLoop) - this.observerLast = new MutationObserver(this.handleSwiperLoop) + this.observerFirst = new MutationObserver(this.handleSwiperLoopDebounce) + this.observerLast = new MutationObserver(this.handleSwiperLoopDebounce) const wrapper = this.swiper.$wrapperEl?.[0] const list = wrapper.querySelectorAll('taro-swiper-item-core:not(.swiper-slide-duplicate)') if (list.length >= 1) { @@ -247,20 +247,22 @@ export class Swiper implements ComponentInterface { } } - handleSwiperLoop = debounce(() => { + handleSwiperLoop = () => { if (!this.swiper || !this.circular) return const swiper = this.swiper as any // Note: loop 相关的方法 swiper 未声明 const duplicates = this.swiperWrapper?.querySelectorAll('.swiper-slide-duplicate') || [] if (duplicates.length < 2) { // Note: 循环模式下,但是前后垫片未注入 - swiper.loopDestroy() - swiper.loopCreate() + swiper.loopDestroy?.() + swiper.loopCreate?.() } else { - swiper.loopFix() + swiper.loopFix?.() } - }, 50) + } + + handleSwiperLoopDebounce = debounce(this.handleSwiperLoop, 50) - handleSwiperSize = debounce(() => { + handleSwiperSizeDebounce = debounce(() => { if (this.swiper && !this.circular) { this.swiper.updateSlides() } From d2633e7bcb3caf216819bee0ac84132e253be73f Mon Sep 17 00:00:00 2001 From: xuanzebin <38971117+xuanzebin@users.noreply.github.com> Date: Mon, 18 Sep 2023 17:06:05 +0800 Subject: [PATCH 12/18] =?UTF-8?q?fix(template):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=A8=A1=E6=9D=BF=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E5=B1=82=E6=B2=A1=E6=9C=89=E6=8A=8A=E8=87=AA=E8=BA=AB=20nodena?= =?UTF-8?q?me=20=E4=BC=A0=E5=85=A5=E5=88=B0=20l=20=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#14564)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复小程序模板第一层没有把自身 nodename 传入到 l 中的问题 * test(snapshot): 更新测试快照 --------- Co-authored-by: xuanzebin --- packages/shared/src/template.ts | 4 ++-- .../src/__tests__/__snapshots__/babel.spec.ts.snap | 2 +- .../__tests__/__snapshots__/common-style.spec.ts.snap | 2 +- .../__snapshots__/compiler-macros.spec.ts.snap | 2 +- .../src/__tests__/__snapshots__/config.spec.ts.snap | 6 +++--- .../__tests__/__snapshots__/css-modules.spec.ts.snap | 4 ++-- .../__tests__/__snapshots__/custom-tabbar.spec.ts.snap | 2 +- .../src/__tests__/__snapshots__/jd.spec.ts.snap | 2 +- .../__tests__/__snapshots__/parse-html.spec.ts.snap | 2 +- .../src/__tests__/__snapshots__/prerender.spec.ts.snap | 6 +++--- .../src/__tests__/__snapshots__/qq.spec.ts.snap | 4 ++-- .../src/__tests__/__snapshots__/react.spec.ts.snap | 2 +- .../src/__tests__/__snapshots__/sass.spec.ts.snap | 8 ++++---- .../__tests__/__snapshots__/subpackages.spec.ts.snap | 2 +- .../src/__tests__/__snapshots__/tabbar.spec.ts.snap | 2 +- .../src/__tests__/__snapshots__/ts.spec.ts.snap | 2 +- .../src/__tests__/__snapshots__/vue.spec.ts.snap | 2 +- .../src/__tests__/__snapshots__/vue3.spec.ts.snap | 2 +- .../src/__tests__/__snapshots__/wx-hybrid.spec.ts.snap | 2 +- .../src/__tests__/__snapshots__/babel.spec.ts.snap | 2 +- .../__snapshots__/compiler-macros.spec.ts.snap | 2 +- .../src/__tests__/__snapshots__/config.spec.ts.snap | 8 ++++---- .../__tests__/__snapshots__/css-modules.spec.ts.snap | 4 ++-- .../src/__tests__/__snapshots__/framework.spec.ts.snap | 8 ++++---- .../__tests__/__snapshots__/mini-platform.spec.ts.snap | 2 +- .../__tests__/__snapshots__/parse-html.spec.ts.snap | 2 +- .../src/__tests__/__snapshots__/prerender.spec.ts.snap | 6 +++--- .../src/__tests__/__snapshots__/sass.spec.ts.snap | 10 +++++----- .../__tests__/__snapshots__/subpackages.spec.ts.snap | 2 +- .../src/__tests__/__snapshots__/tabbar.spec.ts.snap | 4 ++-- .../src/__tests__/__snapshots__/ts.spec.ts.snap | 2 +- .../src/__tests__/__snapshots__/wx-hybrid.spec.ts.snap | 2 +- 32 files changed, 56 insertions(+), 56 deletions(-) diff --git a/packages/shared/src/template.ts b/packages/shared/src/template.ts index 70962bd79a5..c333c6ada07 100644 --- a/packages/shared/src/template.ts +++ b/packages/shared/src/template.ts @@ -221,7 +221,7 @@ export class BaseTemplate { protected buildBaseTemplate () { const Adapter = this.Adapter const data = !this.isSupportRecursive && this.supportXS - ? `${this.dataKeymap('i:item,c:1,l:\'\'')}` + ? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${Shortcuts.NodeName})`)}` : this.isSupportRecursive ? this.dataKeymap('i:item') : this.dataKeymap('i:item,c:1') @@ -509,7 +509,7 @@ export class BaseTemplate { public buildCustomComponentTemplate = (ext: string) => { const Adapter = this.Adapter const data = !this.isSupportRecursive && this.supportXS - ? `${this.dataKeymap('i:item,c:1,l:\'\'')}` + ? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${Shortcuts.NodeName})`)}` : this.isSupportRecursive ? this.dataKeymap('i:item') : this.dataKeymap('i:item,c:1') diff --git a/packages/taro-mini-runner/src/__tests__/__snapshots__/babel.spec.ts.snap b/packages/taro-mini-runner/src/__tests__/__snapshots__/babel.spec.ts.snap index 492b85f35f1..06b2dd7324f 100644 --- a/packages/taro-mini-runner/src/__tests__/__snapshots__/babel.spec.ts.snap +++ b/packages/taro-mini-runner/src/__tests__/__snapshots__/babel.spec.ts.snap @@ -544,7 +544,7 @@ require("./taro");