Skip to content

Commit f207c2d

Browse files
authored
Merge pull request #41 from wechat-miniprogram/feat/insertElement
Feat/insertElement
2 parents 56d2eae + 4e9067f commit f207c2d

File tree

21 files changed

+1369
-225
lines changed

21 files changed

+1369
-225
lines changed

CHANGELOG.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
#### 2024.11.11
2+
1. `A` 新增insertElement;
3+
2. `U` 优化ts声明协议;
4+
3. `U` 小游戏插件发布1.0.13版本;
5+
6+
#### 2024.11.1
7+
1. `F` 修复 BitMapText textAlign = 'right' 不生效问题;
8+
2. `U` 修改 ScrollBar 的默认样式;
9+
3. `U` 小游戏插件发布1.0.12版本;
110

211
#### 2024.4.11
3-
1. `U` 修复样式伪类功能在touchend没有触发的bug;
12+
1. `F` 修复样式伪类功能在touchend没有触发的bug;
413
2. `U` 小游戏插件发布1.0.11版本;
514

615
#### 2024.3.25
@@ -24,17 +33,18 @@
2433
#### 2023.12.26
2534
1. `U` 小游戏插件发布1.0.6版本;
2635
2. `F` 修复圆角矩形在有borderRadius的时候绘制不够圆润问题;
27-
3. `U` 文字样式支持fontFamily属性
36+
3. `U` 文字样式支持 fontFamily 属性
2837
4. `F` 修复 ScrollView 的滚动条在页面布局变化时会位置异常问题;
2938
5. `U` Layout 支持多例模式;
3039

3140
#### 2023.7.25
32-
1. `U` 支持部分 transform 属性;
33-
2. `U` 小游戏插件发布1.0.5版本
41+
1. `U` transform 部分属性支持,使用可见[教程](./tutorial/loading);
42+
2. `U` 小游戏插件发布 1.0.5 版本
3443

3544
#### 2023.7.12
36-
1. `U` ScrollView 支持滚动条特性;
37-
2. `U` 小游戏插件发布1.0.4版本;
45+
1. `U` ScrollView 支持 [滚动条](./components/scrollbar.md)特性;
46+
2. `U` 支持 opacity 样式属性;
47+
3. `U` 小游戏插件发布 1.0.4 版本;
3848

3949
#### 2023.6.20
4050
1. `F` 兼容在字节小游戏下运行失败问题;

build/dts.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
compilationOptions: {
3+
preferredConfigPath: '../tsconfig.json',
4+
},
5+
entries: [
6+
{
7+
filePath: '../dist/index.d.ts',
8+
outFile: '../dist/layout.d.ts',
9+
libraries: {
10+
inlinedLibraries: ['tiny-emitter'],
11+
},
12+
output: {
13+
inlineDeclareGlobals: true,
14+
exportReferencedTypes: false,
15+
umdModuleName: 'Layout',
16+
},
17+
},
18+
],
19+
};

demos/noengine/engine.js

Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function setDirty(ele, reason) {
177177
}
178178
}
179179
// 全局事件管道
180-
var EE = new (tiny_emitter__WEBPACK_IMPORTED_MODULE_3___default())();
180+
var EE = new (tiny_emitter__WEBPACK_IMPORTED_MODULE_3___default().TinyEmitter)();
181181
var uuid = 0;
182182
var toEventName = function (event, id) {
183183
var elementEvent = [
@@ -3029,8 +3029,10 @@ __webpack_require__.r(__webpack_exports__);
30293029
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
30303030
/* harmony export */ });
30313031
/* harmony import */ var _imageManager__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
3032+
/* harmony import */ var tiny_emitter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8);
3033+
/* harmony import */ var tiny_emitter__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(tiny_emitter__WEBPACK_IMPORTED_MODULE_1__);
3034+
30323035

3033-
var Emitter = __webpack_require__(8);
30343036
/**
30353037
* http://www.angelcode.com/products/bmfont/doc/file_format.html
30363038
*/
@@ -3041,7 +3043,7 @@ var BitMapFont = /** @class */ (function () {
30413043
this.ready = false;
30423044
this.config = config;
30433045
this.chars = this.parseConfig(config);
3044-
this.event = new Emitter();
3046+
this.event = new (tiny_emitter__WEBPACK_IMPORTED_MODULE_1___default().TinyEmitter)();
30453047
this.texture = _imageManager__WEBPACK_IMPORTED_MODULE_0__["default"].loadImage(src, function (texture, fromCache) {
30463048
if (fromCache) {
30473049
_this.texture = texture;
@@ -3398,7 +3400,7 @@ function create(node, style, parent) {
33983400
if (typeof thisStyle.opacity === 'undefined') {
33993401
thisStyle.opacity = 1;
34003402
}
3401-
if (parentStyle.opacity !== 1 && typeof parentStyle.opacity === 'number') {
3403+
if (parentStyle && parentStyle.opacity !== 1 && typeof parentStyle.opacity === 'number') {
34023404
thisStyle.opacity = parentStyle.opacity * thisStyle.opacity;
34033405
}
34043406
}
@@ -6060,8 +6062,16 @@ var __webpack_exports__ = {};
60606062
"use strict";
60616063
__webpack_require__.r(__webpack_exports__);
60626064
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
6065+
/* harmony export */ BitMapText: () => (/* reexport safe */ _components__WEBPACK_IMPORTED_MODULE_13__.BitMapText),
6066+
/* harmony export */ Button: () => (/* reexport safe */ _components__WEBPACK_IMPORTED_MODULE_13__.Button),
6067+
/* harmony export */ Canvas: () => (/* reexport safe */ _components__WEBPACK_IMPORTED_MODULE_13__.Canvas),
60636068
/* harmony export */ EE: () => (/* binding */ EE),
6069+
/* harmony export */ Element: () => (/* reexport safe */ _components_elements__WEBPACK_IMPORTED_MODULE_1__["default"]),
6070+
/* harmony export */ Image: () => (/* reexport safe */ _components__WEBPACK_IMPORTED_MODULE_13__.Image),
60646071
/* harmony export */ Layout: () => (/* binding */ Layout),
6072+
/* harmony export */ ScrollView: () => (/* reexport safe */ _components__WEBPACK_IMPORTED_MODULE_13__.ScrollView),
6073+
/* harmony export */ Text: () => (/* reexport safe */ _components__WEBPACK_IMPORTED_MODULE_13__.Text),
6074+
/* harmony export */ View: () => (/* reexport safe */ _components__WEBPACK_IMPORTED_MODULE_13__.View),
60656075
/* harmony export */ "default": () => (/* binding */ layout),
60666076
/* harmony export */ env: () => (/* reexport safe */ _env__WEBPACK_IMPORTED_MODULE_0__["default"])
60676077
/* harmony export */ });
@@ -6120,7 +6130,7 @@ var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from
61206130

61216131

61226132
// 全局事件管道
6123-
var EE = new (tiny_emitter__WEBPACK_IMPORTED_MODULE_3___default())();
6133+
var EE = new (tiny_emitter__WEBPACK_IMPORTED_MODULE_3___default().TinyEmitter)();
61246134
var imgPool = new _common_pool__WEBPACK_IMPORTED_MODULE_2__["default"]('imgPool');
61256135
var bitMapPool = new _common_pool__WEBPACK_IMPORTED_MODULE_2__["default"]('bitMapPool');
61266136
var debugInfo = new _common_debugInfo__WEBPACK_IMPORTED_MODULE_8__["default"]();
@@ -6145,7 +6155,7 @@ var Layout = /** @class */ (function (_super) {
61456155
/**
61466156
* 当前 Layout 版本,一般跟小游戏插件版本对齐
61476157
*/
6148-
_this.version = '1.0.12';
6158+
_this.version = '1.0.13';
61496159
_this.env = _env__WEBPACK_IMPORTED_MODULE_0__["default"];
61506160
/**
61516161
* Layout 渲染的目标画布对应的 2d context
@@ -6300,34 +6310,8 @@ var Layout = /** @class */ (function (_super) {
63006310
};
63016311
Layout.prototype.init = function (template, style, attrValueProcessor) {
63026312
debugInfo.start('init');
6303-
var parseConfig = {
6304-
attributeNamePrefix: '',
6305-
attrNodeName: 'attr', // default is 'false'
6306-
textNodeName: '#text',
6307-
ignoreAttributes: false,
6308-
ignoreNameSpace: true,
6309-
allowBooleanAttributes: true,
6310-
parseNodeValue: false,
6311-
parseAttributeValue: false,
6312-
trimValues: true,
6313-
parseTrueNumberOnly: false,
6314-
alwaysCreateTextNode: true,
6315-
};
6316-
if (attrValueProcessor && typeof attrValueProcessor === 'function') {
6317-
// @ts-ignore
6318-
parseConfig.attrValueProcessor = attrValueProcessor;
6319-
}
6320-
debugInfo.start('init_xmlParse');
6321-
// 将xml字符串解析成xml节点树
6322-
var jsonObj = _libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6__.parse(template, parseConfig, true);
6323-
// console.log(jsonObj)
6324-
debugInfo.end('init_xmlParse');
6325-
var xmlTree = jsonObj.children[0];
6326-
// XML树生成渲染树
6327-
debugInfo.start('init_xml2Layout');
6328-
var layoutTree = _common_vd__WEBPACK_IMPORTED_MODULE_10__.create.call(this, xmlTree, style);
6329-
debugInfo.end('init_xml2Layout');
6330-
this.add(layoutTree);
6313+
var elementArray = this.insertElementArray(template, style, attrValueProcessor, true);
6314+
this.add(elementArray[0]);
63316315
this.state = _common_util__WEBPACK_IMPORTED_MODULE_5__.STATE.INITED;
63326316
this.ticker.add(this.tickerFunc, true);
63336317
this.ticker.start();
@@ -6560,6 +6544,19 @@ var Layout = /** @class */ (function (_super) {
65606544
bitMapPool.set(name, font);
65616545
}
65626546
};
6547+
/**
6548+
* 创建节点,创建之后会返回Element列表,可以传入parent立刻插入节点,也可以稍后主动appendChild到需要的节点下
6549+
*/
6550+
Layout.prototype.insertElement = function (template, style, parent) {
6551+
var elementArray = this.insertElementArray(template, style);
6552+
elementArray.forEach(function (it) {
6553+
(0,_common_vd__WEBPACK_IMPORTED_MODULE_10__.iterateTree)(it, function (element) { return element.observeStyleAndEvent(); });
6554+
if (parent) {
6555+
parent.appendChild(it);
6556+
}
6557+
});
6558+
return elementArray;
6559+
};
65636560
/**
65646561
* 克隆节点,克隆后的节点可以添加到 Layout 的某个节点中
65656562
* 该方法可以在数据有变化的时候避免重新执行 Layout.init 流程。
@@ -6603,6 +6600,46 @@ var Layout = /** @class */ (function (_super) {
66036600
// console.log(`[Layout] 插件 ${plugin.name || ''} 已卸载`)
66046601
Layout.installedPlugins.splice(pluginIndex, 1);
66056602
};
6603+
/**
6604+
* 创建节点,创建之后会返回Element列表
6605+
*/
6606+
Layout.prototype.insertElementArray = function (template, style, attrValueProcessor, onlyFirst) {
6607+
var _this = this;
6608+
var parseConfig = {
6609+
attributeNamePrefix: '',
6610+
attrNodeName: 'attr', // default is 'false'
6611+
textNodeName: '#text',
6612+
ignoreAttributes: false,
6613+
ignoreNameSpace: true,
6614+
allowBooleanAttributes: true,
6615+
parseNodeValue: false,
6616+
parseAttributeValue: false,
6617+
trimValues: true,
6618+
parseTrueNumberOnly: false,
6619+
alwaysCreateTextNode: true,
6620+
};
6621+
if (attrValueProcessor && typeof attrValueProcessor === 'function') {
6622+
// @ts-ignore
6623+
parseConfig.attrValueProcessor = attrValueProcessor;
6624+
}
6625+
debugInfo.start('insert_xmlParse');
6626+
// 将xml字符串解析成xml节点树
6627+
var jsonObj = _libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6__.parse(template, parseConfig, true);
6628+
// console.log(jsonObj)
6629+
debugInfo.end('insert_xmlParse');
6630+
var getElements = [];
6631+
jsonObj.children.forEach(function (xmlTree, index) {
6632+
if (onlyFirst && index > 0) {
6633+
return;
6634+
}
6635+
// XML树生成渲染树
6636+
debugInfo.start('insert_xml2Layout');
6637+
var layoutTree = _common_vd__WEBPACK_IMPORTED_MODULE_10__.create.call(_this, xmlTree, style);
6638+
debugInfo.end('insert_xml2Layout');
6639+
getElements.push(layoutTree);
6640+
});
6641+
return getElements;
6642+
};
66066643
Layout.installedPlugins = [];
66076644
return Layout;
66086645
}(_components_elements__WEBPACK_IMPORTED_MODULE_1__["default"]));

0 commit comments

Comments
 (0)