@tarojs/plugin-platform-harmony-ets 4.0.0-beta.2 → 4.0.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/apis/base/system.ts +53 -20
  2. package/dist/apis/framework/index.ts +1 -5
  3. package/dist/apis/index.ts +3 -1
  4. package/dist/apis/network/request.ts +5 -5
  5. package/dist/apis/route/index.ts +15 -0
  6. package/dist/apis/storage/index.ts +124 -60
  7. package/dist/apis/wxml/IntersectionObserver.ts +5 -3
  8. package/dist/apis/wxml/index.ts +2 -0
  9. package/dist/components-harmony-ets/button.ets +41 -78
  10. package/dist/components-harmony-ets/checkbox.ets +19 -209
  11. package/dist/components-harmony-ets/form.ets +38 -160
  12. package/dist/components-harmony-ets/icon.ets +31 -83
  13. package/dist/components-harmony-ets/image.ets +22 -78
  14. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  15. package/dist/components-harmony-ets/input.ets +10 -67
  16. package/dist/components-harmony-ets/label.ets +52 -173
  17. package/dist/components-harmony-ets/movableArea.ets +89 -0
  18. package/dist/components-harmony-ets/movableView.ets +67 -0
  19. package/dist/components-harmony-ets/picker.ets +32 -147
  20. package/dist/components-harmony-ets/progress.ets +47 -0
  21. package/dist/components-harmony-ets/pseudo.ets +80 -0
  22. package/dist/components-harmony-ets/radio.ets +19 -210
  23. package/dist/components-harmony-ets/richText.ets +22 -102
  24. package/dist/components-harmony-ets/scrollView.ets +66 -169
  25. package/dist/components-harmony-ets/slider.ets +10 -72
  26. package/dist/components-harmony-ets/style.ets +244 -0
  27. package/dist/components-harmony-ets/swiper.ets +30 -87
  28. package/dist/components-harmony-ets/switch.ets +9 -71
  29. package/dist/components-harmony-ets/text.ets +38 -89
  30. package/dist/components-harmony-ets/textArea.ets +10 -67
  31. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  32. package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
  33. package/dist/components-harmony-ets/utils/flexManager.ets +8 -7
  34. package/dist/components-harmony-ets/utils/helper.ets +5 -4
  35. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  36. package/dist/components-harmony-ets/utils/index.ts +55 -2
  37. package/dist/components-harmony-ets/utils/styles.ets +45 -85
  38. package/dist/components-harmony-ets/video.ets +33 -88
  39. package/dist/components-harmony-ets/view.ets +47 -160
  40. package/dist/components-harmony-ets/webView.ets +44 -99
  41. package/dist/index.d.ts +151 -0
  42. package/dist/index.js +58 -29
  43. package/dist/index.js.map +1 -1
  44. package/dist/runtime-ets/bom/window.ts +4 -2
  45. package/dist/runtime-ets/current.ts +2 -0
  46. package/dist/runtime-ets/dom/bind.ts +0 -1
  47. package/dist/runtime-ets/dom/cssNesting.ts +311 -0
  48. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +15 -40
  49. package/dist/runtime-ets/dom/document.ts +21 -8
  50. package/dist/runtime-ets/dom/element/element.ts +53 -9
  51. package/dist/runtime-ets/dom/element/form.ts +11 -4
  52. package/dist/runtime-ets/dom/element/index.ts +12 -1
  53. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  54. package/dist/runtime-ets/dom/element/movableView.ts +193 -0
  55. package/dist/runtime-ets/dom/element/normal.ts +8 -3
  56. package/dist/runtime-ets/dom/element/progress.ts +13 -0
  57. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  58. package/dist/runtime-ets/dom/element/text.ts +1 -0
  59. package/dist/runtime-ets/dom/element/video.ts +1 -0
  60. package/dist/runtime-ets/dom/element/webView.ts +8 -0
  61. package/dist/runtime-ets/dom/event.ts +0 -1
  62. package/dist/runtime-ets/dom/eventTarget.ts +0 -3
  63. package/dist/runtime-ets/dom/node.ts +18 -17
  64. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +184 -207
  65. package/dist/runtime-ets/dom/stylesheet/index.ts +28 -308
  66. package/dist/runtime-ets/dom/stylesheet/type.ts +18 -6
  67. package/dist/runtime-ets/dom/stylesheet/util.ts +19 -15
  68. package/dist/runtime-ets/index.ts +2 -2
  69. package/dist/runtime-ets/interface/event.ts +1 -1
  70. package/dist/runtime-ets/utils/index.ts +24 -9
  71. package/dist/runtime-framework/react/app.ts +5 -1
  72. package/dist/runtime-framework/react/hooks.ts +3 -3
  73. package/dist/runtime-framework/react/native-page.ts +14 -9
  74. package/dist/runtime-framework/react/page.ts +1 -0
  75. package/dist/runtime-framework/solid/hooks.ts +3 -3
  76. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  77. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  78. package/dist/runtime-utils.d.ts +825 -0
  79. package/dist/runtime-utils.js +185 -91
  80. package/dist/runtime-utils.js.map +1 -1
  81. package/dist/runtime.d.ts +1 -0
  82. package/dist/runtime.js +185 -91
  83. package/dist/runtime.js.map +1 -1
  84. package/index.js +3 -1
  85. package/package.json +10 -10
  86. package/types/index.d.ts +4 -0
  87. package/dist/runtime-ets/utils/bind.ts +0 -24
package/dist/index.js CHANGED
@@ -5,9 +5,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var helper = require('@tarojs/helper');
6
6
  var path = require('node:path');
7
7
  var runnerUtils = require('@tarojs/runner-utils');
8
- var shared = require('@tarojs/shared');
9
8
  var service = require('@tarojs/service');
10
9
  var _package = require('@tarojs/service/dist/utils/package');
10
+ var shared = require('@tarojs/shared');
11
11
  var webpackSources = require('webpack-sources');
12
12
  var template = require('@tarojs/shared/dist/template');
13
13
 
@@ -244,10 +244,11 @@ class TaroPlatformHarmony extends service.TaroPlatform {
244
244
  FRAMEWORK: JSON.stringify(this.config.framework),
245
245
  TARO_ENV: JSON.stringify(this.platform),
246
246
  TARO_PLATFORM: JSON.stringify(this.platformType),
247
- TARO_VERSION: JSON.stringify(_package.getPkgVersion())
247
+ TARO_VERSION: JSON.stringify(_package.getPkgVersion()),
248
+ SUPPORT_TARO_POLYFILL: 'disabled',
248
249
  },
249
250
  });
250
- return Object.assign(Object.assign(Object.assign({}, config), { buildAdapter: config.platform, fileType: this.fileType, platformType: this.platformType, useETS: this.useETS, useJSON5: this.useJSON5 }), extraOptions);
251
+ return Object.assign(Object.assign(Object.assign({}, config), { buildAdapter: config.platform, fileType: this.fileType, platformType: this.platformType, useETS: this.useETS, useNesting: config.useNesting, useJSON5: this.useJSON5 }), extraOptions);
251
252
  }
252
253
  /**
253
254
  * 调用 runner 开始编译
@@ -316,14 +317,16 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
316
317
  ['react', /^react$|react[\\/]cjs/],
317
318
  ['react/jsx-runtime', /^react[\\/]jsx-runtime$/], // Note: React 环境下自动注入,避免重复
318
319
  ];
320
+ this.harmonyScope = [...HARMONY_SCOPES];
321
+ const that = this;
319
322
  this.setupTransaction.addWrapper({
320
323
  close() {
321
- this.modifyViteConfig();
324
+ that.modifyViteConfig();
322
325
  },
323
326
  });
324
327
  ctx.onBuildFinish(() => {
325
328
  const outDir = path__namespace.resolve(process.cwd(), config.outputRoot);
326
- this.handleResourceEmit(outDir);
329
+ that.handleResourceEmit(outDir);
327
330
  });
328
331
  }
329
332
  get framework() {
@@ -335,6 +338,11 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
335
338
  get apiLibrary() {
336
339
  return path__namespace.resolve(__dirname, './apis');
337
340
  }
341
+ get apiEntry() {
342
+ return [
343
+ /(@tarojs[\\/]plugin-platform-harmony-ets|taro-platform-harmony)[\\/]dist[\\/]apis[\\/]index\.ts/,
344
+ ];
345
+ }
338
346
  get componentLibrary() {
339
347
  return path__namespace.resolve(__dirname, './components-harmony-ets');
340
348
  }
@@ -371,8 +379,8 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
371
379
  return;
372
380
  if (this.excludeLibraries.some(e => typeof e === 'string' ? e === lib : e.test(lib)))
373
381
  return;
382
+ const { outputRoot, chorePackagePrefix } = this.ctx.runOpts.config;
374
383
  if (sync) {
375
- const { outputRoot } = this.ctx.runOpts.config;
376
384
  const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES);
377
385
  // FIXME 不支持 alias 配置
378
386
  const libName = lib;
@@ -423,6 +431,7 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
423
431
  if ((/(?:import\s|from\s|require\()['"]([\\/.][^'"\s]+)['"]\)?/g.test(code)
424
432
  || /\/{3}\s<reference\spath=['"][^'"\s]+['"]\s\/>/g.test(code))
425
433
  && `${libName}${path__namespace.extname(libDir)}` !== libDir) {
434
+ // Note: 文件包含包内引用的依赖
426
435
  const pkgPath = path__namespace.relative(libName, libDir);
427
436
  if (new RegExp(`^index(${this.extensions.map(e => e.replace('.', '\\.')).join('|')})$`).test(pkgPath)) {
428
437
  // Note: 入口为 index 场景
@@ -473,16 +482,16 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
473
482
  }
474
483
  else if (stat.isFile()) {
475
484
  let code = helper.fs.readFileSync(lib, { encoding: 'utf8' });
476
- // TODO: 后续这部分代码应该根据使用的框架抽离到对应的平台插件处
477
- if ([/taro-platform-harmony[\\/]dist[\\/]apis[\\/]index\.ts/].some(e => e.test(lib))) {
485
+ if (this.apiEntry.some(e => e.test(lib))) {
478
486
  code = apiLoader(code);
479
487
  }
480
488
  if (this.extensions.includes(path__namespace.extname(lib))) {
481
- code = code.replace(/(?:import\s|from\s|require\()['"]([^.][^'"\s]+)['"]\)?/g, (src, p1) => {
489
+ // Note: 查询 externals 内的依赖,并将它们添加到 externalDeps
490
+ code = code.replace(/(?:import\s|from\s|require\()['"]([^\\/.][^'"\s]+)['"]\)?/g, (src, p1) => {
482
491
  const { outputRoot } = this.ctx.runOpts.config;
483
492
  const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES, p1);
484
493
  const relativePath = parseRelativePath(path__namespace.dirname(target), targetPath);
485
- if (HARMONY_SCOPES.every(e => !e.test(p1))) {
494
+ if (this.harmonyScope.every(e => !e.test(p1))) {
486
495
  if (this.indexOfLibraries(p1) === -1 && !/\.(d\.ts|flow\.js)$/.test(lib)) {
487
496
  this.externalDeps.push([p1, new RegExp(`^${p1.replace(/([-\\/$])/g, '\\$1')}$`)]);
488
497
  this.moveLibraries(p1, targetPath, path__namespace.dirname(lib), true);
@@ -500,9 +509,16 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
500
509
  if (['.ts'].includes(ext)) {
501
510
  code = '// @ts-nocheck\n' + code;
502
511
  }
512
+ // 处理嵌套样式的编译,需要针对ReactElement进行props操作,dev模式下会Object.freeze,所以需要在开发模式下注入Object.freeze来覆盖解锁
513
+ // 处理的方法再taro-platform-harmony/src/runtime-ets/dom/cssNesting: ele.props.style = declaration
514
+ if (/react\/jsx-runtime/.test(lib) && process.env.NODE_ENV === 'development') {
515
+ code = 'Object.freeze = (obj) => obj \n' + code;
516
+ }
503
517
  }
504
- if (/tarojs[\\/]taro[\\/]types[\\/]index.d.ts/.test(target)) {
505
- code = `/// <reference path="global.d.ts" />
518
+ // Note: 传入 chorePackagePrefix 时,不生成核心依赖库
519
+ if (!chorePackagePrefix) {
520
+ if (/tarojs[\\/]taro[\\/]types[\\/]index.d.ts/.test(target)) {
521
+ code = `/// <reference path="global.d.ts" />
506
522
 
507
523
  /// <reference path="taro.api.d.ts" />
508
524
  /// <reference path="taro.component.d.ts" />
@@ -522,14 +538,15 @@ declare global {
522
538
  const defineAppConfig: (config: Taro.Config) => Taro.Config
523
539
  const definePageConfig: (config: Taro.Config) => Taro.Config
524
540
  }`;
525
- }
526
- try {
527
- const targetPath = target.replace(new RegExp(`\\b${helper.NODE_MODULES}\\b`), 'npm');
528
- helper.fs.ensureDirSync(path__namespace.dirname(targetPath));
529
- helper.fs.writeFileSync(targetPath, code);
530
- }
531
- catch (e) {
532
- console.error(`[taro-arkts] inject ${lib} to ${target} failed`, e);
541
+ }
542
+ try {
543
+ const targetPath = target.replace(new RegExp(`\\b${helper.NODE_MODULES}\\b`), 'npm');
544
+ helper.fs.ensureDirSync(path__namespace.dirname(targetPath));
545
+ helper.fs.writeFileSync(targetPath, code);
546
+ }
547
+ catch (e) {
548
+ console.error(`[taro-arkts] inject ${lib} to ${target} failed`, e);
549
+ }
533
550
  }
534
551
  }
535
552
  else if (stat.isSymbolicLink()) {
@@ -551,7 +568,7 @@ declare global {
551
568
  const that = this;
552
569
  const { appPath } = that.ctx.paths;
553
570
  const { config } = that.ctx.runOpts;
554
- const { outputRoot } = config;
571
+ const { outputRoot, ohPackage = {}, chorePackagePrefix } = config;
555
572
  if (!that.framework.includes('vue')) {
556
573
  that.excludeLibraries.push(/\bvue\b/);
557
574
  }
@@ -567,11 +584,21 @@ declare global {
567
584
  /^solid-js\/universal$/,
568
585
  ]);
569
586
  }
570
- function modifyResolveId({ source = '', importer = '', options = {}, name = 'modifyResolveId', resolve }) {
571
- if (shared.isFunction(resolve)) {
572
- if (source === that.runtimePath || that.runtimePath.includes(source)) {
573
- return resolve('@tarojs/runtime', importer, options);
574
- }
587
+ const externals = Object.keys(ohPackage.dependencies || []).concat(Object.keys(ohPackage.devDependencies || []));
588
+ function modifyResolveId({ source = '', name = 'modifyResolveId' }) {
589
+ if (externals.includes(source)) {
590
+ return {
591
+ external: true,
592
+ id: source,
593
+ resolvedBy: name,
594
+ };
595
+ }
596
+ if (chorePackagePrefix && that.indexOfLibraries(source) > -1) {
597
+ return {
598
+ external: true,
599
+ id: path__namespace.join(chorePackagePrefix, source),
600
+ resolvedBy: name,
601
+ };
575
602
  }
576
603
  // Note: 映射 Taro 相关依赖到注入 taro 目录
577
604
  if (that.indexOfLibraries(source) > -1) {
@@ -1150,7 +1177,7 @@ class Harmony extends service.TaroPlatformBase {
1150
1177
  const outDir = path.join(compsOutDir, name);
1151
1178
  helper.fs.copy(src, outDir);
1152
1179
  });
1153
- this.modifyHostPackageDep(outDir);
1180
+ this.modifyHostPackage(config.harmony);
1154
1181
  });
1155
1182
  }
1156
1183
  modifyWebpackConfig() {
@@ -1213,13 +1240,13 @@ class Harmony extends service.TaroPlatformBase {
1213
1240
  console.warn(helper.chalk.red('设置鸿蒙 Hap 配置失败:', err));
1214
1241
  });
1215
1242
  }
1216
- modifyHostPackageDep(dest) {
1243
+ modifyHostPackage({ projectPath, hapName = 'entry' }) {
1217
1244
  return __awaiter(this, void 0, void 0, function* () {
1245
+ const packageJsonFile = path.join(projectPath, hapName, 'package.json');
1218
1246
  const hmsDeps = {
1219
1247
  '@hmscore/hms-js-base': '^6.1.0-300',
1220
1248
  '@hmscore/hms-jsb-account': '^1.0.300'
1221
1249
  };
1222
- const packageJsonFile = path.resolve(dest, '../../../../../package.json');
1223
1250
  const isExists = yield helper.fs.pathExists(packageJsonFile);
1224
1251
  if (!isExists)
1225
1252
  return;
@@ -1236,6 +1263,7 @@ class Harmony extends service.TaroPlatformBase {
1236
1263
  }
1237
1264
  packageJson = JSON.stringify(packageJson);
1238
1265
  yield helper.fs.writeFile(packageJsonFile, packageJson);
1266
+ return packageJson;
1239
1267
  });
1240
1268
  }
1241
1269
  getChunkEntryModule(compilation, chunk, compiler = 'webpack4') {
@@ -1304,6 +1332,7 @@ function assertHarmonyConfig(ctx, config) {
1304
1332
  }
1305
1333
  }
1306
1334
 
1335
+ exports.HarmonyOS_ArkTS = Harmony$1;
1307
1336
  exports.HarmonyOS_JSUI = Harmony;
1308
1337
  exports.default = index;
1309
1338
  //# sourceMappingURL=index.js.map