@vvfx/sdk 0.2.2-alpha.0 → 0.2.2-alpha.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.
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: TODO
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 赤芍,何即,不择,意绮
6
- * Version: v0.2.2-alpha.0
6
+ * Version: v0.2.2-alpha.2
7
7
  */
8
8
 
9
9
  'use strict';
@@ -24032,9 +24032,21 @@ function getUniqueName(name, names) {
24032
24032
  };
24033
24033
  _create_class(TextItem, [
24034
24034
  {
24035
- key: "text",
24035
+ key: "pixelWidth",
24036
24036
  get: // ==================== 便捷访问器 ====================
24037
- /**
24037
+ function get() {
24038
+ return this.width;
24039
+ }
24040
+ },
24041
+ {
24042
+ key: "pixelHeight",
24043
+ get: function get() {
24044
+ return this.height;
24045
+ }
24046
+ },
24047
+ {
24048
+ key: "text",
24049
+ get: /**
24038
24050
  * @description 文本内容
24039
24051
  */ function get() {
24040
24052
  return this.property.text;
@@ -56591,6 +56603,10 @@ var cursorMap = {
56591
56603
  type: 'preset',
56592
56604
  content: 'crosshair'
56593
56605
  },
56606
+ 'box-select': {
56607
+ type: 'preset',
56608
+ content: 'crosshair'
56609
+ },
56594
56610
  'text-rotation': {
56595
56611
  type: 'svg',
56596
56612
  content: 'default',
@@ -60959,7 +60975,7 @@ var PageDataUtils = /*#__PURE__*/ function() {
60959
60975
  * @description 更新 PlayerItem 的 Property 属性
60960
60976
  */ _proto.updatePlayerItemPropertyAttribute = function updatePlayerItemPropertyAttribute(playerItem, targetItem, propertyName, propertyValue) {
60961
60977
  return _async_to_generator(function() {
60962
- var _this, _playerItem_getComponent, _playerItem_getComponent1, color, _array_, array, family, textComponent, textComponent1, lineCount, textHeight, _playerItem_getComponent2, textComponent2, textHeight1, textComponent3, outlineColor, textComponent4, textComponent5, textComponent6, originFontSize, lineCount1, textHeight2, textComponent7, textHeight3, viewSize, worldSizeX, originSize, originChildBoxes, originBox, worldScaleX, originScale, originWidth, currentWidth, ratio, originScale1, textComponent8, originChildBoxes1, originBox1, worldScaleY, originScale2, originHeight, currentHeight, ratio1, originScale3, viewSize1, worldSizeY, originSize1, textComponent9, textHeight4, _playerItem_getComponent3, _, _playerItem_getComponent4, _1, _propertyValue_compositions_find, _ref, subCompositionItem, compositionId, mainComposition, effectsSize, viewSize2, worldSize, compositionItem, component, videoComponent, videoComponent1, videoComponent2, pixelTranslation, viewTranslation, translation, rotation, currentScale, scaleRatio, frameComponent, _SDK_config_itemConfig_frameConfig, freeLayoutBackgroundColor, autoLayoutBackgroundColor, color1, childrenItem, time;
60978
+ var _this, _playerItem_getComponent, _playerItem_getComponent1, color, _array_, array, family, textComponent, textComponent1, lineCount, textHeight, _playerItem_getComponent2, textComponent2, textHeight1, textComponent3, outlineColor, textComponent4, textComponent5, textComponent6, originFontSize, lineCount1, textHeight2, textComponent7, textHeight3, viewSize, worldSizeX, originSize, originChildBoxes, originBox, worldScaleX, originScale, originWidth, currentWidth, ratio, originScale1, textComponent8, originChildBoxes1, originBox1, worldScaleY, originScale2, originHeight, currentHeight, ratio1, originScale3, viewSize1, worldSizeY, originSize1, textComponent9, textHeight4, _playerItem_getComponent3, _, _playerItem_getComponent4, _1, _propertyValue_compositions_find, _ref, subCompositionItem, compositionId, mainComposition, effectsSize, viewSize2, worldSize, compositionItem, component, videoPlayStates, videoComponent, videoComponent1, videoComponent2, pixelTranslation, viewTranslation, translation, rotation, currentScale, scaleRatio, frameComponent, _SDK_config_itemConfig_frameConfig, freeLayoutBackgroundColor, autoLayoutBackgroundColor, color1, childrenItem, time, videoPlayStates1;
60963
60979
  return _ts_generator(this, function(_state) {
60964
60980
  switch(_state.label){
60965
60981
  case 0:
@@ -61447,7 +61463,10 @@ var PageDataUtils = /*#__PURE__*/ function() {
61447
61463
  compositionItem.parentId = playerItem.getInstanceId();
61448
61464
  component = compositionItem.components[0];
61449
61465
  component == null ? void 0 : component.pause();
61466
+ // 刷新前快照视频播放态,刷新后恢复,避免更换特效导致全量视频被自动播放
61467
+ videoPlayStates = this.snapshotVideoPlayStates();
61450
61468
  this.sdk.player.gotoAndPlay(0);
61469
+ this.restoreVideoPlayStates(videoPlayStates);
61451
61470
  _state.label = 28;
61452
61471
  case 28:
61453
61472
  return [
@@ -61597,11 +61616,14 @@ var PageDataUtils = /*#__PURE__*/ function() {
61597
61616
  'size'
61598
61617
  ].includes(propertyName)) {
61599
61618
  time = this.sdk.pageData.time;
61619
+ // 刷新前快照视频播放态,刷新后恢复,避免设置属性导致全量视频被自动播放
61620
+ videoPlayStates1 = this.snapshotVideoPlayStates();
61600
61621
  if (SDK.config.mode === 'editor') {
61601
61622
  this.player.gotoAndPlay(time);
61602
61623
  } else {
61603
61624
  this.player.gotoAndStop(time);
61604
61625
  }
61626
+ this.restoreVideoPlayStates(videoPlayStates1);
61605
61627
  }
61606
61628
  return [
61607
61629
  2
@@ -64579,7 +64601,7 @@ var PageDataUtils = /*#__PURE__*/ function() {
64579
64601
  };
64580
64602
  addTextItemIntoNewScene = function addTextItemIntoNewScene(textCreateInfo, sceneSize, itemViewPosition) {
64581
64603
  var _scene_fonts;
64582
- var _textCreateInfo_id = textCreateInfo.id, id = _textCreateInfo_id === void 0 ? EFFECTS.generateGUID() : _textCreateInfo_id, _textCreateInfo_name = textCreateInfo.name, name = _textCreateInfo_name === void 0 ? '文本' : _textCreateInfo_name, _textCreateInfo_property = textCreateInfo.property, lineHeight = _textCreateInfo_property.lineHeight, textWidth = _textCreateInfo_property.width, tmp = _textCreateInfo_property.height, textHeight = tmp === void 0 ? lineHeight : tmp, fontFamily = _textCreateInfo_property.fontFamily, fontSize = _textCreateInfo_property.fontSize, _textCreateInfo_property_fontWeight = _textCreateInfo_property.fontWeight, fontWeight = _textCreateInfo_property_fontWeight === void 0 ? EFFECTS.spec.TextWeight.normal : _textCreateInfo_property_fontWeight, _textCreateInfo_property_fontStyle = _textCreateInfo_property.fontStyle, fontStyle = _textCreateInfo_property_fontStyle === void 0 ? EFFECTS.spec.FontStyle.normal : _textCreateInfo_property_fontStyle, _textCreateInfo_property_textAlign = _textCreateInfo_property.textAlign, textAlign = _textCreateInfo_property_textAlign === void 0 ? EFFECTS.spec.TextAlignment.left : _textCreateInfo_property_textAlign, text = _textCreateInfo_property.text, textColor = _textCreateInfo_property.color, tmp1 = _textCreateInfo_property.rotation, sourceRotation = tmp1 === void 0 ? 0 : tmp1, url = _textCreateInfo_property.fontUrl, outlineColor = _textCreateInfo_property.outlineColor, outlineWidth = _textCreateInfo_property.outlineWidth, outlineEnabled = _textCreateInfo_property.outlineEnabled;
64604
+ var _textCreateInfo_id = textCreateInfo.id, id = _textCreateInfo_id === void 0 ? EFFECTS.generateGUID() : _textCreateInfo_id, _textCreateInfo_name = textCreateInfo.name, name = _textCreateInfo_name === void 0 ? '文本' : _textCreateInfo_name, _textCreateInfo_property = textCreateInfo.property, lineHeight = _textCreateInfo_property.lineHeight, textWidth = _textCreateInfo_property.width, tmp = _textCreateInfo_property.height, textHeight = tmp === void 0 ? lineHeight : tmp, fontFamily = _textCreateInfo_property.fontFamily, fontSize = _textCreateInfo_property.fontSize, _textCreateInfo_property_fontWeight = _textCreateInfo_property.fontWeight, fontWeight = _textCreateInfo_property_fontWeight === void 0 ? EFFECTS.spec.TextWeight.normal : _textCreateInfo_property_fontWeight, _textCreateInfo_property_fontStyle = _textCreateInfo_property.fontStyle, fontStyle = _textCreateInfo_property_fontStyle === void 0 ? EFFECTS.spec.FontStyle.normal : _textCreateInfo_property_fontStyle, _textCreateInfo_property_textAlign = _textCreateInfo_property.textAlign, textAlign = _textCreateInfo_property_textAlign === void 0 ? EFFECTS.spec.TextAlignment.left : _textCreateInfo_property_textAlign, text = _textCreateInfo_property.text, textColor = _textCreateInfo_property.color, tmp1 = _textCreateInfo_property.rotation, sourceRotation = tmp1 === void 0 ? 0 : tmp1, url = _textCreateInfo_property.fontUrl, outlineColor = _textCreateInfo_property.outlineColor, outlineWidth = _textCreateInfo_property.outlineWidth, outlineEnabled = _textCreateInfo_property.outlineEnabled, letterSpacing = _textCreateInfo_property.letterSpacing;
64583
64605
  var rotation = Array.isArray(sourceRotation) ? [].concat(sourceRotation) : [
64584
64606
  0,
64585
64607
  0,
@@ -64609,7 +64631,7 @@ var PageDataUtils = /*#__PURE__*/ function() {
64609
64631
  fontSize: fontSize,
64610
64632
  textColor: resutlTextColor,
64611
64633
  fontWeight: fontWeight,
64612
- letterSpace: 0,
64634
+ letterSpace: letterSpacing,
64613
64635
  textAlign: textAlign,
64614
64636
  fontStyle: fontStyle,
64615
64637
  textWidth: textWidth,
@@ -65616,6 +65638,51 @@ var PageDataUtils = /*#__PURE__*/ function() {
65616
65638
  var result = box.clone().scale(scale, center).translate(translation);
65617
65639
  return result;
65618
65640
  };
65641
+ /**
65642
+ * @description 快照当前所有视频元素的播放状态(播放/暂停 + 当前播放进度),用于属性刷新后恢复,
65643
+ * 避免设置属性导致全量视频被自动播放或进度被重置回 0s
65644
+ */ _proto.snapshotVideoPlayStates = function snapshotVideoPlayStates() {
65645
+ var states = new Map();
65646
+ var composition = this.getCurrentComposition();
65647
+ for(var _iterator = _create_for_of_iterator_helper_loose(composition.items), _step; !(_step = _iterator()).done;){
65648
+ var item = _step.value;
65649
+ if (item.type === EFFECTS.spec.ItemType.video) {
65650
+ var videoComponent = item.getComponent(VideoComponent);
65651
+ if (!videoComponent) {
65652
+ continue;
65653
+ }
65654
+ //@ts-expect-error @赤芍 played 字段未在类型中声明,参见 rebuildCompositionItems 处用法
65655
+ var played = !!videoComponent.played;
65656
+ var time = videoComponent.getCurrentTime();
65657
+ states.set(item.getInstanceId(), {
65658
+ played: played,
65659
+ time: time
65660
+ });
65661
+ }
65662
+ }
65663
+ return states;
65664
+ };
65665
+ /**
65666
+ * @description 按快照恢复视频元素的播放状态(先 pause 再 seek,最后按原状态 play/pause,避免进度抖动)
65667
+ */ _proto.restoreVideoPlayStates = function restoreVideoPlayStates(states) {
65668
+ for(var _iterator = _create_for_of_iterator_helper_loose(states), _step; !(_step = _iterator()).done;){
65669
+ var _step_value = _step.value, id = _step_value[0], _step_value_ = _step_value[1], played = _step_value_.played, time = _step_value_.time;
65670
+ var playerItem = this.getPlayerItemById(id);
65671
+ if ((playerItem == null ? void 0 : playerItem.type) !== EFFECTS.spec.ItemType.video) {
65672
+ continue;
65673
+ }
65674
+ var videoComponent = playerItem.getComponent(VideoComponent);
65675
+ if (!videoComponent) {
65676
+ continue;
65677
+ }
65678
+ // 先暂停再 seek,避免播放状态下 seek 导致画面抖动
65679
+ videoComponent.pauseVideo();
65680
+ videoComponent.setCurrentTime(time);
65681
+ if (played) {
65682
+ videoComponent.playVideo();
65683
+ }
65684
+ }
65685
+ };
65619
65686
  _proto.playVideoItem = function playVideoItem(id) {
65620
65687
  var playerItem = this.getPlayerItemById(id);
65621
65688
  if ((playerItem == null ? void 0 : playerItem.type) !== EFFECTS.spec.ItemType.video) {
@@ -67181,7 +67248,7 @@ var PageDataUtils = /*#__PURE__*/ function() {
67181
67248
  };
67182
67249
  _proto.autoLayoutPage = function autoLayoutPage() {
67183
67250
  return _async_to_generator(function(param) {
67184
- var _this, pageData, _param_mode, mode, ids, _param_focus, focus, _param_gap, gap, isPartialLayout, targetItems, layoutElements, moveInfos, anchor, _iterator, _step, moveInfo, sdkItem;
67251
+ var _this, pageData, _param_mode, mode, ids, _param_focus, focus, _param_gap, gap, shift, isPartialLayout, targetItems, layoutElements, moveInfos, anchor, _iterator, _step, moveInfo, sdkItem;
67185
67252
  return _ts_generator(this, function(_state) {
67186
67253
  switch(_state.label){
67187
67254
  case 0:
@@ -67196,7 +67263,7 @@ var PageDataUtils = /*#__PURE__*/ function() {
67196
67263
  2
67197
67264
  ];
67198
67265
  }
67199
- _param_mode = param.mode, mode = _param_mode === void 0 ? SDK.config.pageConfig.autoLayoutDefaultMode : _param_mode, ids = param.ids, _param_focus = param.focus, focus = _param_focus === void 0 ? true : _param_focus, _param_gap = param.gap, gap = _param_gap === void 0 ? SDK.config.pageConfig.autoLayoutDefaultGap : _param_gap;
67266
+ _param_mode = param.mode, mode = _param_mode === void 0 ? SDK.config.pageConfig.autoLayoutDefaultMode : _param_mode, ids = param.ids, _param_focus = param.focus, focus = _param_focus === void 0 ? true : _param_focus, _param_gap = param.gap, gap = _param_gap === void 0 ? SDK.config.pageConfig.autoLayoutDefaultGap : _param_gap, shift = param.shift;
67200
67267
  isPartialLayout = !!(ids == null ? void 0 : ids.length);
67201
67268
  // 1. 确定参与排布的顶层元素(过滤子元素)
67202
67269
  targetItems = pageData.items.filter(function(item) {
@@ -67225,7 +67292,7 @@ var PageDataUtils = /*#__PURE__*/ function() {
67225
67292
  // 4. 计算锚点偏移
67226
67293
  // - 选中元素排布:以原始包围盒左上角为锚点
67227
67294
  // - 全量排布:以视口中心为锚点
67228
- anchor = isPartialLayout ? this.getPartialLayoutAnchor(layoutElements, moveInfos.boundingBox) : this.getGlobalLayoutAnchor(moveInfos.boundingBox);
67295
+ anchor = isPartialLayout ? this.getPartialLayoutAnchor(layoutElements, moveInfos.boundingBox) : this.getGlobalLayoutAnchor(moveInfos.boundingBox, shift);
67229
67296
  _iterator = _create_for_of_iterator_helper_loose(moveInfos.items);
67230
67297
  _state.label = 1;
67231
67298
  case 1:
@@ -67268,7 +67335,7 @@ var PageDataUtils = /*#__PURE__*/ function() {
67268
67335
  if (focus) {
67269
67336
  this.setPageZoom(1, undefined, true);
67270
67337
  this.setPageMove(new Vector2());
67271
- this.viewportFit(undefined, moveInfos.boundingBox.translate(anchor));
67338
+ this.viewportFit(shift, moveInfos.boundingBox.translate(anchor));
67272
67339
  }
67273
67340
  return [
67274
67341
  2
@@ -67292,8 +67359,9 @@ var PageDataUtils = /*#__PURE__*/ function() {
67292
67359
  /**
67293
67360
  * @description 计算全量排布的锚点偏移:以视口中心为锚点
67294
67361
  * @param layoutBoundingBox 排布算法输出的包围盒
67295
- */ _proto.getGlobalLayoutAnchor = function getGlobalLayoutAnchor(layoutBoundingBox) {
67296
- var viewCenter = new Vector2(this.sdk._container.offsetWidth / 2, this.sdk._container.offsetHeight / 2);
67362
+ */ _proto.getGlobalLayoutAnchor = function getGlobalLayoutAnchor(layoutBoundingBox, shift) {
67363
+ var _ref = shift != null ? shift : {}, _ref_top = _ref.top, top = _ref_top === void 0 ? 0 : _ref_top, _ref_bottom = _ref.bottom, bottom = _ref_bottom === void 0 ? 0 : _ref_bottom, _ref_left = _ref.left, left = _ref_left === void 0 ? 0 : _ref_left, _ref_right = _ref.right, right = _ref_right === void 0 ? 0 : _ref_right;
67364
+ var viewCenter = new Vector2(this.sdk._container.offsetWidth / 2 + left - right, this.sdk._container.offsetHeight / 2 + top - bottom);
67297
67365
  var boundCenter = layoutBoundingBox.getCenter();
67298
67366
  return new Vector2(viewCenter.x - boundCenter.x, viewCenter.y - boundCenter.y);
67299
67367
  };
@@ -68895,6 +68963,8 @@ var MaskGizmo = /*#__PURE__*/ function(Gizmo) {
68895
68963
  */ _this.maskSprite = null, _this._config = {}, _this.boxGraphics = new Graphics(), _this.type = 'mask', _this.mode = 'paint', /**
68896
68964
  * 蒙版工具独立的撤销重做实例
68897
68965
  */ _this._undoRedo = new GizmoUndoRedo(), /**
68966
+ * 框选擦除进行中标记(按下到松开之间),用于实时选框描边的显示控制
68967
+ */ _this._isBoxErasing = false, /**
68898
68968
  * 鼠标状态绘制结果
68899
68969
  */ _this.cursorResult = {
68900
68970
  type: 'normal',
@@ -68911,10 +68981,22 @@ var MaskGizmo = /*#__PURE__*/ function(Gizmo) {
68911
68981
  var _proto = MaskGizmo.prototype;
68912
68982
  /**
68913
68983
  * 设置模式
68914
- * @param mode 模式类型:'paint' 表示涂抹,'erase' 表示擦除
68984
+ * @param mode 模式类型:'paint' 笔刷涂抹、'erase' 笔刷逐笔擦除、'box-erase' 框选擦除、'box-paint' 框选涂抹
68915
68985
  */ _proto.setMode = function setMode(mode) {
68916
68986
  this.mode = mode;
68917
68987
  };
68988
+ /**
68989
+ * @description 判断点是否在包围盒内
68990
+ */ _proto._isPointInBox = function _isPointInBox(p, box) {
68991
+ return p.x >= box.min.x && p.x <= box.max.x && p.y >= box.min.y && p.y <= box.max.y;
68992
+ };
68993
+ /**
68994
+ * @description 将屏幕坐标转换为包围盒内的归一化坐标 [0,1](钳制在范围内)
68995
+ */ _proto._toNormalized = function _toNormalized(p, box) {
68996
+ var x = Math.max(0, Math.min(1, (p.x - box.min.x) / (box.max.x - box.min.x)));
68997
+ var y = Math.max(0, Math.min(1, (p.y - box.min.y) / (box.max.y - box.min.y)));
68998
+ return new Vector2(x, y);
68999
+ };
68918
69000
  _proto.initialize = function initialize() {};
68919
69001
  _proto.preparationAction = function preparationAction(event) {
68920
69002
  if (!this.interactive) {
@@ -68933,6 +69015,26 @@ var MaskGizmo = /*#__PURE__*/ function(Gizmo) {
68933
69015
  };
68934
69016
  // 更新鼠标位置
68935
69017
  this.result.point = new Vector2(event.offsetX, event.offsetY);
69018
+ // 框选模式(框选擦除 / 框选涂抹):仅在元素包围盒内按下才触发
69019
+ if (this.mode === 'box-erase' || this.mode === 'box-paint') {
69020
+ var box = this.result.box;
69021
+ if (!box || !this._isPointInBox(this.result.point, box)) {
69022
+ // 包围盒外按下:不触发框选,交由其它 gizmo
69023
+ return undefined;
69024
+ }
69025
+ var start = this._toNormalized(this.result.point, box);
69026
+ this.result.lines.push({
69027
+ type: this.mode === 'box-paint' ? 'paint' : 'erase',
69028
+ shape: 'rect',
69029
+ brushSize: 0,
69030
+ points: [
69031
+ start,
69032
+ start.clone()
69033
+ ]
69034
+ });
69035
+ this._isBoxErasing = true;
69036
+ return this.type;
69037
+ }
68936
69038
  // 开启新画笔
68937
69039
  this.result.lines.push({
68938
69040
  type: this.mode,
@@ -68942,32 +69044,61 @@ var MaskGizmo = /*#__PURE__*/ function(Gizmo) {
68942
69044
  return this.type;
68943
69045
  };
68944
69046
  _proto.action = function action(event) {
68945
- var // 记录鼠标划线位置
68946
- _this_result_lines_;
68947
69047
  if (!this.interactive || this.result.status === 'init') {
68948
69048
  return;
68949
69049
  }
68950
69050
  // 更新鼠标位置
68951
69051
  var box = this.result.box;
68952
- var point = new Vector2((event.offsetX - box.min.x) / (box.max.x - box.min.x), (event.offsetY - box.min.y) / (box.max.y - box.min.y));
68953
- (_this_result_lines_ = this.result.lines[this.result.lines.length - 1]) == null ? void 0 : _this_result_lines_.points.push(point);
69052
+ var point = new Vector2(event.offsetX, event.offsetY);
69053
+ this.result.point = point;
69054
+ var lastLine = this.result.lines[this.result.lines.length - 1];
69055
+ // 框选擦除:更新框选终点(钳制到包围盒内)
69056
+ if ((lastLine == null ? void 0 : lastLine.shape) === 'rect') {
69057
+ lastLine.points[1] = this._toNormalized(point, box);
69058
+ return;
69059
+ }
69060
+ // 记录鼠标划线位置(笔刷模式)
69061
+ var np = new Vector2((event.offsetX - box.min.x) / (box.max.x - box.min.x), (event.offsetY - box.min.y) / (box.max.y - box.min.y));
69062
+ lastLine == null ? void 0 : lastLine.points.push(np);
68954
69063
  };
68955
69064
  _proto.endAction = function endAction() {
68956
69065
  if (!this.interactive) {
68957
69066
  return undefined;
68958
69067
  }
68959
- // 记录操作到 undoRedo(仅当画线有实际点时才记录)
68960
69068
  var lastLine = this.result.lines[this.result.lines.length - 1];
69069
+ // 框选擦除:起点==终点视为空框选,移除;否则提交 undoRedo
69070
+ if ((lastLine == null ? void 0 : lastLine.shape) === 'rect') {
69071
+ this._isBoxErasing = false;
69072
+ var _lastLine_points = lastLine.points, a = _lastLine_points[0], b = _lastLine_points[1];
69073
+ var isEmpty = !!a && !!b && a.x === b.x && a.y === b.y;
69074
+ if (this._oldLines && !isEmpty) {
69075
+ var operation = {
69076
+ type: 'update',
69077
+ oldData: this._oldLines,
69078
+ newData: {
69079
+ lines: JSON.parse(JSON.stringify(this.result.lines))
69080
+ }
69081
+ };
69082
+ this._undoRedo.push(operation);
69083
+ this._eventEmitter.emit('maskGizmoUndoRedoChange', operation);
69084
+ } else {
69085
+ // 空框选移除
69086
+ this.result.lines.pop();
69087
+ }
69088
+ this._oldLines = undefined;
69089
+ return this.type;
69090
+ }
69091
+ // 记录操作到 undoRedo(仅当画线有实际点时才记录)
68961
69092
  if (this._oldLines && lastLine && lastLine.points.length > 0) {
68962
- var operation = {
69093
+ var operation1 = {
68963
69094
  type: 'update',
68964
69095
  oldData: this._oldLines,
68965
69096
  newData: {
68966
69097
  lines: JSON.parse(JSON.stringify(this.result.lines))
68967
69098
  }
68968
69099
  };
68969
- this._undoRedo.push(operation);
68970
- this._eventEmitter.emit('maskGizmoUndoRedoChange', operation);
69100
+ this._undoRedo.push(operation1);
69101
+ this._eventEmitter.emit('maskGizmoUndoRedoChange', operation1);
68971
69102
  } else if ((lastLine == null ? void 0 : lastLine.points.length) === 0) {
68972
69103
  // 如果没有实际绘制点,移除空的线条
68973
69104
  this.result.lines.pop();
@@ -69092,6 +69223,17 @@ var MaskGizmo = /*#__PURE__*/ function(Gizmo) {
69092
69223
  this.boxGraphics.lineStyle(boxLineWidth, boxLineColor, boxLineAlpha);
69093
69224
  this.boxGraphics.drawBox(box);
69094
69225
  this.boxGraphics.endFill();
69226
+ // 框选擦除进行中:叠加当前拖动矩形的可视描边
69227
+ var lastLine = this.result.lines[this.result.lines.length - 1];
69228
+ if (this._isBoxErasing && (lastLine == null ? void 0 : lastLine.shape) === 'rect' && lastLine.points.length >= 2) {
69229
+ var _lastLine_points = lastLine.points, a = _lastLine_points[0], b = _lastLine_points[1];
69230
+ if (a && b) {
69231
+ var selBox = new Box2(new Vector2(box.min.x + Math.min(a.x, b.x) * (box.max.x - box.min.x), box.min.y + Math.min(a.y, b.y) * (box.max.y - box.min.y)), new Vector2(box.min.x + Math.max(a.x, b.x) * (box.max.x - box.min.x), box.min.y + Math.max(a.y, b.y) * (box.max.y - box.min.y)));
69232
+ this.boxGraphics.lineStyle(boxLineWidth, boxLineColor, boxLineAlpha);
69233
+ this.boxGraphics.drawBox(selBox);
69234
+ this.boxGraphics.endFill();
69235
+ }
69236
+ }
69095
69237
  // 1. 画线形(只用于遮罩,不直接显示
69096
69238
  for(var _iterator = _create_for_of_iterator_helper_loose(this.result.lines), _step; !(_step = _iterator()).done;){
69097
69239
  var line = _step.value;
@@ -69099,6 +69241,32 @@ var MaskGizmo = /*#__PURE__*/ function(Gizmo) {
69099
69241
  continue;
69100
69242
  }
69101
69243
  var lineGraphics = new Graphics();
69244
+ // 矩形框选:填充矩形,paint 用 NORMAL 叠加,erase 用 DST_OUT 抠除
69245
+ if (line.shape === 'rect') {
69246
+ var a1 = line.points[0];
69247
+ var b1 = line.points[1];
69248
+ if (a1 && b1) {
69249
+ var w = box.max.x - box.min.x;
69250
+ var h = box.max.y - box.min.y;
69251
+ var x0 = Math.min(a1.x, b1.x) * w;
69252
+ var y0 = Math.min(a1.y, b1.y) * h;
69253
+ var x1 = Math.max(a1.x, b1.x) * w;
69254
+ var y1 = Math.max(a1.y, b1.y) * h;
69255
+ // 太小(纯点击)不渲染,避免 1px 擦除/涂抹点
69256
+ if (x1 - x0 > 0.5 || y1 - y0 > 0.5) {
69257
+ lineGraphics.beginFill(brushColor);
69258
+ lineGraphics.drawRect(x0, y0, x1 - x0, y1 - y0);
69259
+ lineGraphics.endFill();
69260
+ lineGraphics.blendMode = line.type === 'paint' ? BLEND_MODES.NORMAL : BLEND_MODES.DST_OUT;
69261
+ this._app.renderer.render(lineGraphics, {
69262
+ renderTexture: this.maskRenderTexture,
69263
+ clear: false
69264
+ });
69265
+ }
69266
+ }
69267
+ lineGraphics.destroy();
69268
+ continue;
69269
+ }
69102
69270
  lineGraphics.blendMode = line.type === 'paint' ? BLEND_MODES.NORMAL : BLEND_MODES.DST_OUT;
69103
69271
  lineGraphics.lineStyle({
69104
69272
  width: line.brushSize * viewportParam.scale,
@@ -69142,14 +69310,24 @@ var MaskGizmo = /*#__PURE__*/ function(Gizmo) {
69142
69310
  if (!point || !box) {
69143
69311
  return;
69144
69312
  }
69145
- if (point.x >= box.min.x && point.x <= box.max.x && point.y >= box.min.y && point.y <= box.max.y) {
69146
- var viewportParam = this._pageDataUtils.interactionUtils.viewportParam;
69313
+ var inside = point.x >= box.min.x && point.x <= box.max.x && point.y >= box.min.y && point.y <= box.max.y;
69314
+ if (!inside) {
69315
+ return;
69316
+ }
69317
+ // 框选模式(框选擦除 / 框选涂抹):crosshair
69318
+ if (this.mode === 'box-erase' || this.mode === 'box-paint') {
69147
69319
  this.cursorResult = {
69148
- type: 'circle',
69149
- angle: 0,
69150
- radius: this.config.brushSize * viewportParam.scale / 2
69320
+ type: 'box-select',
69321
+ angle: 0
69151
69322
  };
69323
+ return;
69152
69324
  }
69325
+ var viewportParam = this._pageDataUtils.interactionUtils.viewportParam;
69326
+ this.cursorResult = {
69327
+ type: 'circle',
69328
+ angle: 0,
69329
+ radius: this.config.brushSize * viewportParam.scale / 2
69330
+ };
69153
69331
  };
69154
69332
  _proto.close = function close() {
69155
69333
  this._config.maskImage = undefined;
@@ -69297,6 +69475,21 @@ var MaskGizmo = /*#__PURE__*/ function(Gizmo) {
69297
69475
  if (!line || line.points.length === 0) {
69298
69476
  continue;
69299
69477
  }
69478
+ // 矩形框选:填充矩形
69479
+ if (line.shape === 'rect') {
69480
+ var _line_points = line.points, a = _line_points[0], b1 = _line_points[1];
69481
+ if (!a || !b1) {
69482
+ continue;
69483
+ }
69484
+ var x0 = Math.min(a.x, b1.x) * width;
69485
+ var y0 = Math.min(a.y, b1.y) * height;
69486
+ var x1 = Math.max(a.x, b1.x) * width;
69487
+ var y1 = Math.max(a.y, b1.y) * height;
69488
+ ctx.globalCompositeOperation = 'source-over';
69489
+ ctx.fillStyle = line.type === 'paint' ? maskHexColor : maskBackgroundHexColor;
69490
+ ctx.fillRect(x0, y0, Math.max(1, x1 - x0), Math.max(1, y1 - y0));
69491
+ continue;
69492
+ }
69300
69493
  ctx.lineWidth = line.brushSize * scale;
69301
69494
  ctx.lineCap = 'round';
69302
69495
  ctx.lineJoin = 'round';
@@ -71302,7 +71495,8 @@ var GestureHandler = /*#__PURE__*/ function() {
71302
71495
  'active-hand',
71303
71496
  'pointer',
71304
71497
  'text-create',
71305
- 'frame-create'
71498
+ 'frame-create',
71499
+ 'box-select'
71306
71500
  ].includes(result.type)) {
71307
71501
  var cursor = cursorMap[result.type];
71308
71502
  if (cursor.type === 'svg') {
@@ -71474,6 +71668,7 @@ var GestureHandler = /*#__PURE__*/ function() {
71474
71668
  return;
71475
71669
  }
71476
71670
  this.maskGizmo.setMode(mode);
71671
+ this.render();
71477
71672
  };
71478
71673
  _proto.openLoadingGizmo = function openLoadingGizmo(id, options) {
71479
71674
  var _this__emitter;
@@ -94768,7 +94963,7 @@ var SDK = /*#__PURE__*/ function() {
94768
94963
  };
94769
94964
  /**
94770
94965
  * @description 设置蒙版工具模式
94771
- * @param mode 模式类型:'paint' 表示涂抹,'erase' 表示擦除
94966
+ * @param mode 模式类型:'paint' 笔刷涂抹、'erase' 笔刷逐笔擦除、'box-erase' 框选擦除、'box-paint' 框选涂抹
94772
94967
  */ _proto.setMaskGizmoMode = function setMaskGizmoMode(mode) {
94773
94968
  this._gestureHandler.setMaskGizmoMode(mode);
94774
94969
  };