@cloudbase/lowcode-builder 1.8.44 → 1.8.45-beta.2

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.
@@ -387,9 +387,12 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
387
387
  subWxss: rootPath && !((_l = ctx.mainAppData) === null || _l === void 0 ? void 0 : _l.mpPkgUrl)
388
388
  ? `@import "${path_1.default.posix.relative(`/${rootPath}/pages/${page.id}`, '/lowcode')}/style.wxss";`
389
389
  : '',
390
- content: (0, weapps_core_1.toCssText)((0, cals_1.processCommonStyle2CSSProperties)(page.commonStyle, {
391
- defaultUnit: processCssUnit,
392
- }), 'page'),
390
+ content: [
391
+ (0, weapps_core_1.toCssText)((0, cals_1.processCommonStyle2CSSProperties)(page.commonStyle, {
392
+ defaultUnit: processCssUnit,
393
+ }), 'page'),
394
+ (0, util_2.generateScopedStyleText)(componentInstances),
395
+ ].join('\n'),
393
396
  pageWxss: importor.styles.length ? `@import "../../lowcode/${page.id}/style.wxss"` : '',
394
397
  },
395
398
  };
@@ -41,3 +41,4 @@ export declare function findComponentInfo(xComponent: {
41
41
  materialLibs: any;
42
42
  miniprogramPlugins: any;
43
43
  }): any;
44
+ export declare function generateScopedStyleText(widgets: Record<string, IWeAppComponentInstance>): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findComponentInfo = exports.processRepeaterSchema = exports.createDataBinds = exports.createTemplateEventFlows = exports.createTemplateQuery = exports.generateDataContainerListeners = exports.generateSyncListeners = exports.createEventHandlers = exports.createWidgetProps = exports.generatedDynamicData = void 0;
3
+ exports.generateScopedStyleText = exports.findComponentInfo = exports.processRepeaterSchema = exports.createDataBinds = exports.createTemplateEventFlows = exports.createTemplateQuery = exports.generateDataContainerListeners = exports.generateSyncListeners = exports.createEventHandlers = exports.createWidgetProps = exports.generatedDynamicData = void 0;
4
4
  const weapps_core_1 = require("@cloudbase/lowcode-generator/lib/weapps-core");
5
5
  const lowcode_generator_1 = require("@cloudbase/lowcode-generator");
6
6
  const weapp_1 = require("@cloudbase/lowcode-generator/lib/generator/util/weapp");
@@ -481,3 +481,36 @@ function findComponentInfo(xComponent, { materialLibs, miniprogramPlugins }) {
481
481
  return compProto;
482
482
  }
483
483
  exports.findComponentInfo = findComponentInfo;
484
+ function generateScopedStyleText(widgets) {
485
+ const cssTextList = [];
486
+ function traverse(target) {
487
+ var _a;
488
+ for (const [id, widget] of Object.entries(target)) {
489
+ const scopedStyle = (_a = widget.xProps) === null || _a === void 0 ? void 0 : _a.scopedStyle;
490
+ if (scopedStyle) {
491
+ let cssText = scopedStyle
492
+ // 移除 `/* ... */` 注释
493
+ .replace(/\/\*(?:[\s\S]*?)\*\//g, '')
494
+ // 移除换行及其前后的空白符
495
+ .replace(/\s*\n\s*/g, '')
496
+ // 添加 `#wd-page-root` 前缀以增加样式权重
497
+ .replace(/(:root.*?{)/g, '\n#wd-page-root $1')
498
+ // 替换 `:root`
499
+ .replace(/:root/g, `.wd-comp-id-${id}`)
500
+ // `: ` => `:`
501
+ .replace(/\s*:\s*/g, ':')
502
+ // ` {` => `{`
503
+ .replace(/\s*{\s*/g, '{')
504
+ // `;}` => `}`
505
+ .replace(/;\s*}/g, '}');
506
+ cssTextList.push(cssText.trim());
507
+ }
508
+ if (widget.properties) {
509
+ traverse(widget.properties);
510
+ }
511
+ }
512
+ }
513
+ traverse(widgets);
514
+ return cssTextList.join('\n');
515
+ }
516
+ exports.generateScopedStyleText = generateScopedStyleText;