Skip to content

Commit 56d2eae

Browse files
committed
feat: 修复 BitMapText textAlign = 'right' 不生效问题,修改 ScrollBar 的默认样式
1 parent 787254e commit 56d2eae

File tree

12 files changed

+97
-61
lines changed

12 files changed

+97
-61
lines changed

demos/noengine/engine.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ var StyleOpType;
200200
})(StyleOpType || (StyleOpType = {}));
201201
var Element = /** @class */ (function () {
202202
function Element(_a) {
203-
var _this = this;
204203
var _b = _a.style, style = _b === void 0 ? {} : _b, _c = _a.idName, idName = _c === void 0 ? '' : _c, _d = _a.className, className = _d === void 0 ? '' : _d, _e = _a.id, id = _e === void 0 ? uuid += 1 : _e, _f = _a.dataset, dataset = _f === void 0 ? {} : _f;
204+
var _this = this;
205205
/**
206206
* 子节点列表
207207
*/
@@ -2461,12 +2461,12 @@ var defaultOptions = {
24612461
textNodeName: '#text',
24622462
ignoreAttributes: true,
24632463
ignoreNameSpace: false,
2464-
allowBooleanAttributes: false,
2464+
allowBooleanAttributes: false, //a tag can have attributes without any value
24652465
//ignoreRootElement : false,
24662466
parseNodeValue: true,
24672467
parseAttributeValue: false,
24682468
arrayMode: false,
2469-
trimValues: true,
2469+
trimValues: true, //Trim string values of tag and attributes
24702470
cdataTagName: false,
24712471
cdataPositionChar: '\\c',
24722472
localeRange: '',
@@ -2713,7 +2713,7 @@ module.exports = function (tagname, parent, val) {
27132713

27142714
var util = __webpack_require__(13);
27152715
var defaultOptions = {
2716-
allowBooleanAttributes: false,
2716+
allowBooleanAttributes: false, //A tag can have attributes without any value
27172717
localeRange: 'a-zA-Z',
27182718
};
27192719
var props = ['allowBooleanAttributes', 'localeRange'];
@@ -3798,8 +3798,8 @@ function parseText(style, value) {
37983798
var Text = /** @class */ (function (_super) {
37993799
__extends(Text, _super);
38003800
function Text(_a) {
3801-
var _this = this;
38023801
var _b = _a.style, style = _b === void 0 ? {} : _b, _c = _a.idName, idName = _c === void 0 ? '' : _c, _d = _a.className, className = _d === void 0 ? '' : _d, _e = _a.value, value = _e === void 0 ? '' : _e, dataset = _a.dataset;
3802+
var _this = this;
38033803
var originStyleWidth = style.width;
38043804
// 没有设置宽度的时候通过canvas计算出文字宽度
38053805
if (originStyleWidth === undefined) {
@@ -5473,8 +5473,8 @@ function checkNeedHideScrollBar(direction, dimensions) {
54735473
var ScrollBar = /** @class */ (function (_super) {
54745474
__extends(ScrollBar, _super);
54755475
function ScrollBar(_a) {
5476+
var direction = _a.direction, dimensions = _a.dimensions, _b = _a.backgroundColor, backgroundColor = _b === void 0 ? 'rgba(162, 162, 162, 0.7)' : _b, _c = _a.width, width = _c === void 0 ? 10 : _c;
54765477
var _this = this;
5477-
var direction = _a.direction, dimensions = _a.dimensions, _b = _a.backgroundColor, backgroundColor = _b === void 0 ? 'rgba(162, 162, 162, 1)' : _b, _c = _a.width, width = _c === void 0 ? 16 : _c;
54785478
var style = Object.assign({
54795479
backgroundColor: backgroundColor,
54805480
position: 'absolute',
@@ -5490,7 +5490,7 @@ var ScrollBar = /** @class */ (function (_super) {
54905490
_this.autoHideTime = 2000;
54915491
_this.autoHideDelayTime = 1500;
54925492
_this.autoHideRemainingTime = 0;
5493-
_this.innerWidth = 16;
5493+
_this.innerWidth = 10;
54945494
_this.isHide = false;
54955495
_this.currLeft = 0;
54965496
_this.currTop = 0;
@@ -5722,11 +5722,16 @@ var BitMapText = /** @class */ (function (_super) {
57225722
var style = this.style;
57235723
var _a = style.letterSpacing, letterSpacing = _a === void 0 ? 0 : _a;
57245724
var width = 0;
5725+
// 记录上一个字符,方便处理 kerning
5726+
var prevCharCode = null;
57255727
for (var i = 0, len = this.value.length; i < len; i++) {
57265728
var char = this.value[i];
57275729
var cfg = this.font.chars[char];
57285730
if (cfg) {
5729-
width += cfg.w;
5731+
if (prevCharCode && cfg.kerning[prevCharCode]) {
5732+
width += cfg.kerning[prevCharCode];
5733+
}
5734+
width += cfg.xadvance;
57305735
if (i < len - 1) {
57315736
width += letterSpacing;
57325737
}
@@ -5763,7 +5768,7 @@ var BitMapText = /** @class */ (function (_super) {
57635768
drawX += (width - realWidth) / 2;
57645769
}
57655770
else if (textAlign === 'right') {
5766-
drawY += (width - realWidth);
5771+
drawX += (width - realWidth);
57675772
}
57685773
}
57695774
// 记录上一个字符,方便处理 kerning
@@ -6140,7 +6145,7 @@ var Layout = /** @class */ (function (_super) {
61406145
/**
61416146
* 当前 Layout 版本,一般跟小游戏插件版本对齐
61426147
*/
6143-
_this.version = '1.0.11';
6148+
_this.version = '1.0.12';
61446149
_this.env = _env__WEBPACK_IMPORTED_MODULE_0__["default"];
61456150
/**
61466151
* Layout 渲染的目标画布对应的 2d context
@@ -6297,7 +6302,7 @@ var Layout = /** @class */ (function (_super) {
62976302
debugInfo.start('init');
62986303
var parseConfig = {
62996304
attributeNamePrefix: '',
6300-
attrNodeName: 'attr',
6305+
attrNodeName: 'attr', // default is 'false'
63016306
textNodeName: '#text',
63026307
ignoreAttributes: false,
63036308
ignoreNameSpace: true,

demos/noengine/sub/engine.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ var StyleOpType;
200200
})(StyleOpType || (StyleOpType = {}));
201201
var Element = /** @class */ (function () {
202202
function Element(_a) {
203-
var _this = this;
204203
var _b = _a.style, style = _b === void 0 ? {} : _b, _c = _a.idName, idName = _c === void 0 ? '' : _c, _d = _a.className, className = _d === void 0 ? '' : _d, _e = _a.id, id = _e === void 0 ? uuid += 1 : _e, _f = _a.dataset, dataset = _f === void 0 ? {} : _f;
204+
var _this = this;
205205
/**
206206
* 子节点列表
207207
*/
@@ -2461,12 +2461,12 @@ var defaultOptions = {
24612461
textNodeName: '#text',
24622462
ignoreAttributes: true,
24632463
ignoreNameSpace: false,
2464-
allowBooleanAttributes: false,
2464+
allowBooleanAttributes: false, //a tag can have attributes without any value
24652465
//ignoreRootElement : false,
24662466
parseNodeValue: true,
24672467
parseAttributeValue: false,
24682468
arrayMode: false,
2469-
trimValues: true,
2469+
trimValues: true, //Trim string values of tag and attributes
24702470
cdataTagName: false,
24712471
cdataPositionChar: '\\c',
24722472
localeRange: '',
@@ -2713,7 +2713,7 @@ module.exports = function (tagname, parent, val) {
27132713

27142714
var util = __webpack_require__(13);
27152715
var defaultOptions = {
2716-
allowBooleanAttributes: false,
2716+
allowBooleanAttributes: false, //A tag can have attributes without any value
27172717
localeRange: 'a-zA-Z',
27182718
};
27192719
var props = ['allowBooleanAttributes', 'localeRange'];
@@ -3798,8 +3798,8 @@ function parseText(style, value) {
37983798
var Text = /** @class */ (function (_super) {
37993799
__extends(Text, _super);
38003800
function Text(_a) {
3801-
var _this = this;
38023801
var _b = _a.style, style = _b === void 0 ? {} : _b, _c = _a.idName, idName = _c === void 0 ? '' : _c, _d = _a.className, className = _d === void 0 ? '' : _d, _e = _a.value, value = _e === void 0 ? '' : _e, dataset = _a.dataset;
3802+
var _this = this;
38033803
var originStyleWidth = style.width;
38043804
// 没有设置宽度的时候通过canvas计算出文字宽度
38053805
if (originStyleWidth === undefined) {
@@ -5473,8 +5473,8 @@ function checkNeedHideScrollBar(direction, dimensions) {
54735473
var ScrollBar = /** @class */ (function (_super) {
54745474
__extends(ScrollBar, _super);
54755475
function ScrollBar(_a) {
5476+
var direction = _a.direction, dimensions = _a.dimensions, _b = _a.backgroundColor, backgroundColor = _b === void 0 ? 'rgba(162, 162, 162, 0.7)' : _b, _c = _a.width, width = _c === void 0 ? 10 : _c;
54765477
var _this = this;
5477-
var direction = _a.direction, dimensions = _a.dimensions, _b = _a.backgroundColor, backgroundColor = _b === void 0 ? 'rgba(162, 162, 162, 1)' : _b, _c = _a.width, width = _c === void 0 ? 16 : _c;
54785478
var style = Object.assign({
54795479
backgroundColor: backgroundColor,
54805480
position: 'absolute',
@@ -5490,7 +5490,7 @@ var ScrollBar = /** @class */ (function (_super) {
54905490
_this.autoHideTime = 2000;
54915491
_this.autoHideDelayTime = 1500;
54925492
_this.autoHideRemainingTime = 0;
5493-
_this.innerWidth = 16;
5493+
_this.innerWidth = 10;
54945494
_this.isHide = false;
54955495
_this.currLeft = 0;
54965496
_this.currTop = 0;
@@ -5722,11 +5722,16 @@ var BitMapText = /** @class */ (function (_super) {
57225722
var style = this.style;
57235723
var _a = style.letterSpacing, letterSpacing = _a === void 0 ? 0 : _a;
57245724
var width = 0;
5725+
// 记录上一个字符,方便处理 kerning
5726+
var prevCharCode = null;
57255727
for (var i = 0, len = this.value.length; i < len; i++) {
57265728
var char = this.value[i];
57275729
var cfg = this.font.chars[char];
57285730
if (cfg) {
5729-
width += cfg.w;
5731+
if (prevCharCode && cfg.kerning[prevCharCode]) {
5732+
width += cfg.kerning[prevCharCode];
5733+
}
5734+
width += cfg.xadvance;
57305735
if (i < len - 1) {
57315736
width += letterSpacing;
57325737
}
@@ -5763,7 +5768,7 @@ var BitMapText = /** @class */ (function (_super) {
57635768
drawX += (width - realWidth) / 2;
57645769
}
57655770
else if (textAlign === 'right') {
5766-
drawY += (width - realWidth);
5771+
drawX += (width - realWidth);
57675772
}
57685773
}
57695774
// 记录上一个字符,方便处理 kerning
@@ -6140,7 +6145,7 @@ var Layout = /** @class */ (function (_super) {
61406145
/**
61416146
* 当前 Layout 版本,一般跟小游戏插件版本对齐
61426147
*/
6143-
_this.version = '1.0.11';
6148+
_this.version = '1.0.12';
61446149
_this.env = _env__WEBPACK_IMPORTED_MODULE_0__["default"];
61456150
/**
61466151
* Layout 渲染的目标画布对应的 2d context
@@ -6297,7 +6302,7 @@ var Layout = /** @class */ (function (_super) {
62976302
debugInfo.start('init');
62986303
var parseConfig = {
62996304
attributeNamePrefix: '',
6300-
attrNodeName: 'attr',
6305+
attrNodeName: 'attr', // default is 'false'
63016306
textNodeName: '#text',
63026307
ignoreAttributes: false,
63036308
ignoreNameSpace: true,

dist/index.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ var StyleOpType;
200200
})(StyleOpType || (StyleOpType = {}));
201201
var Element = /** @class */ (function () {
202202
function Element(_a) {
203-
var _this = this;
204203
var _b = _a.style, style = _b === void 0 ? {} : _b, _c = _a.idName, idName = _c === void 0 ? '' : _c, _d = _a.className, className = _d === void 0 ? '' : _d, _e = _a.id, id = _e === void 0 ? uuid += 1 : _e, _f = _a.dataset, dataset = _f === void 0 ? {} : _f;
204+
var _this = this;
205205
/**
206206
* 子节点列表
207207
*/
@@ -2461,12 +2461,12 @@ var defaultOptions = {
24612461
textNodeName: '#text',
24622462
ignoreAttributes: true,
24632463
ignoreNameSpace: false,
2464-
allowBooleanAttributes: false,
2464+
allowBooleanAttributes: false, //a tag can have attributes without any value
24652465
//ignoreRootElement : false,
24662466
parseNodeValue: true,
24672467
parseAttributeValue: false,
24682468
arrayMode: false,
2469-
trimValues: true,
2469+
trimValues: true, //Trim string values of tag and attributes
24702470
cdataTagName: false,
24712471
cdataPositionChar: '\\c',
24722472
localeRange: '',
@@ -2713,7 +2713,7 @@ module.exports = function (tagname, parent, val) {
27132713

27142714
var util = __webpack_require__(13);
27152715
var defaultOptions = {
2716-
allowBooleanAttributes: false,
2716+
allowBooleanAttributes: false, //A tag can have attributes without any value
27172717
localeRange: 'a-zA-Z',
27182718
};
27192719
var props = ['allowBooleanAttributes', 'localeRange'];
@@ -3798,8 +3798,8 @@ function parseText(style, value) {
37983798
var Text = /** @class */ (function (_super) {
37993799
__extends(Text, _super);
38003800
function Text(_a) {
3801-
var _this = this;
38023801
var _b = _a.style, style = _b === void 0 ? {} : _b, _c = _a.idName, idName = _c === void 0 ? '' : _c, _d = _a.className, className = _d === void 0 ? '' : _d, _e = _a.value, value = _e === void 0 ? '' : _e, dataset = _a.dataset;
3802+
var _this = this;
38033803
var originStyleWidth = style.width;
38043804
// 没有设置宽度的时候通过canvas计算出文字宽度
38053805
if (originStyleWidth === undefined) {
@@ -5473,8 +5473,8 @@ function checkNeedHideScrollBar(direction, dimensions) {
54735473
var ScrollBar = /** @class */ (function (_super) {
54745474
__extends(ScrollBar, _super);
54755475
function ScrollBar(_a) {
5476+
var direction = _a.direction, dimensions = _a.dimensions, _b = _a.backgroundColor, backgroundColor = _b === void 0 ? 'rgba(162, 162, 162, 0.7)' : _b, _c = _a.width, width = _c === void 0 ? 10 : _c;
54765477
var _this = this;
5477-
var direction = _a.direction, dimensions = _a.dimensions, _b = _a.backgroundColor, backgroundColor = _b === void 0 ? 'rgba(162, 162, 162, 1)' : _b, _c = _a.width, width = _c === void 0 ? 16 : _c;
54785478
var style = Object.assign({
54795479
backgroundColor: backgroundColor,
54805480
position: 'absolute',
@@ -5490,7 +5490,7 @@ var ScrollBar = /** @class */ (function (_super) {
54905490
_this.autoHideTime = 2000;
54915491
_this.autoHideDelayTime = 1500;
54925492
_this.autoHideRemainingTime = 0;
5493-
_this.innerWidth = 16;
5493+
_this.innerWidth = 10;
54945494
_this.isHide = false;
54955495
_this.currLeft = 0;
54965496
_this.currTop = 0;
@@ -5722,11 +5722,16 @@ var BitMapText = /** @class */ (function (_super) {
57225722
var style = this.style;
57235723
var _a = style.letterSpacing, letterSpacing = _a === void 0 ? 0 : _a;
57245724
var width = 0;
5725+
// 记录上一个字符,方便处理 kerning
5726+
var prevCharCode = null;
57255727
for (var i = 0, len = this.value.length; i < len; i++) {
57265728
var char = this.value[i];
57275729
var cfg = this.font.chars[char];
57285730
if (cfg) {
5729-
width += cfg.w;
5731+
if (prevCharCode && cfg.kerning[prevCharCode]) {
5732+
width += cfg.kerning[prevCharCode];
5733+
}
5734+
width += cfg.xadvance;
57305735
if (i < len - 1) {
57315736
width += letterSpacing;
57325737
}
@@ -5763,7 +5768,7 @@ var BitMapText = /** @class */ (function (_super) {
57635768
drawX += (width - realWidth) / 2;
57645769
}
57655770
else if (textAlign === 'right') {
5766-
drawY += (width - realWidth);
5771+
drawX += (width - realWidth);
57675772
}
57685773
}
57695774
// 记录上一个字符,方便处理 kerning
@@ -6140,7 +6145,7 @@ var Layout = /** @class */ (function (_super) {
61406145
/**
61416146
* 当前 Layout 版本,一般跟小游戏插件版本对齐
61426147
*/
6143-
_this.version = '1.0.11';
6148+
_this.version = '1.0.12';
61446149
_this.env = _env__WEBPACK_IMPORTED_MODULE_0__["default"];
61456150
/**
61466151
* Layout 渲染的目标画布对应的 2d context
@@ -6297,7 +6302,7 @@ var Layout = /** @class */ (function (_super) {
62976302
debugInfo.start('init');
62986303
var parseConfig = {
62996304
attributeNamePrefix: '',
6300-
attrNodeName: 'attr',
6305+
attrNodeName: 'attr', // default is 'false'
63016306
textNodeName: '#text',
63026307
ignoreAttributes: false,
63036308
ignoreNameSpace: true,

docs/.vitepress/config.mts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ export default defineConfig({
7373
link: "/index",
7474
items: [
7575
{ text: '简介', link: '/index'},
76-
{ text: '常见问题', link: '/qa'}
76+
{ text: '常见问题', link: '/qa'},
77+
{
78+
text: '更新日志',
79+
link: '/CHANGELOG',
80+
}
7781
]
7882
},
7983

@@ -133,10 +137,6 @@ export default defineConfig({
133137
{ text: '概览', link: '/plugin/guide', },
134138
{ text: '富文本插件', link: '/plugin/richtext'}
135139
],
136-
},
137-
{
138-
text: '更新日志',
139-
link: '/CHANGELOG',
140140
}
141141
],
142142

docs/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
#### 2024.11.1
2+
1. `F` 修复 BitMapText textAlign = 'right' 不生效问题;
3+
2. `U` 修改 ScrollBar 的默认样式;
4+
3. `U` 小游戏插件发布1.0.12版本;
5+
16
#### 2024.4.11
2-
1. `U` 修复样式伪类功能在touchend没有触发的bug;
7+
1. `F` 修复样式伪类功能在touchend没有触发的bug;
38
2. `U` 小游戏插件发布1.0.11版本;
49

510
#### 2024.3.25

docs/components/scrollbar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ScrollBar 本身只是个普通的 View 组件,只不过默认带了一些样
6161

6262
| 属性 | 类型 | 描述|
6363
| --------- | ------ | -------------------------------------------------------------------------- |
64-
| backgroundColor | string | 默认值'rgba(162, 162, 162, 1)',建议采用 rgba 的格式设置颜色 |
64+
| backgroundColor | string | 默认值'rgba(162, 162, 162, 0.7)',建议采用 rgba 的格式设置颜色 |
6565
| position | string | 'absolute',`不建议修改` |
6666
| opacity | number | 透明度,开启了autoHide会动态修改透明度,`不建议修改` |
6767
| borderRadius | number | 值为 width / 2,`不建议修改` |

0 commit comments

Comments
 (0)