jmgraph 3.2.20 → 3.2.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.
- package/README.md +137 -4
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +976 -827
- package/dist/jmgraph.min.js +1 -1
- package/index.js +13 -26
- package/package.json +1 -1
- package/src/core/jmControl.js +199 -30
- package/src/core/jmFilter.js +150 -0
- package/src/core/jmGraph.js +16 -265
- package/src/core/jmUtils.js +46 -37
- package/src/lib/webgl/base.js +10 -36
- package/src/lib/webgl/gradient.js +16 -3
- package/src/lib/webgl/index.js +5 -4
- package/src/lib/webgl/path.js +156 -33
- package/src/shapes/jmLabel.js +1 -62
- package/src/shapes/jmRect.js +107 -29
package/dist/jmgraph.js
CHANGED
|
@@ -120,22 +120,22 @@ Object.defineProperty(exports, "jmGradient", {
|
|
|
120
120
|
return _jmGraph.jmGradient;
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
|
-
Object.defineProperty(exports, "
|
|
123
|
+
Object.defineProperty(exports, "jmFilter", {
|
|
124
124
|
enumerable: true,
|
|
125
125
|
get: function get() {
|
|
126
|
-
return _jmGraph.
|
|
126
|
+
return _jmGraph.jmFilter;
|
|
127
127
|
}
|
|
128
128
|
});
|
|
129
|
-
Object.defineProperty(exports, "
|
|
129
|
+
Object.defineProperty(exports, "jmControl", {
|
|
130
130
|
enumerable: true,
|
|
131
131
|
get: function get() {
|
|
132
|
-
return _jmGraph.
|
|
132
|
+
return _jmGraph.jmControl;
|
|
133
133
|
}
|
|
134
134
|
});
|
|
135
|
-
Object.defineProperty(exports, "
|
|
135
|
+
Object.defineProperty(exports, "jmPath", {
|
|
136
136
|
enumerable: true,
|
|
137
137
|
get: function get() {
|
|
138
|
-
return _jmGraph.
|
|
138
|
+
return _jmGraph.jmPath;
|
|
139
139
|
}
|
|
140
140
|
});
|
|
141
141
|
exports.create = exports.jmGraph = exports["default"] = void 0;
|
|
@@ -176,10 +176,6 @@ function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _c
|
|
|
176
176
|
|
|
177
177
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
178
178
|
|
|
179
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
180
|
-
|
|
181
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
182
|
-
|
|
183
179
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
184
180
|
|
|
185
181
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
@@ -213,27 +209,17 @@ var shapes = {
|
|
|
213
209
|
"star": _jmStar.jmStar
|
|
214
210
|
};
|
|
215
211
|
|
|
216
|
-
var
|
|
217
|
-
_inherits(
|
|
218
|
-
|
|
219
|
-
var _super = _createSuper(jmGraph);
|
|
220
|
-
|
|
221
|
-
function jmGraph(canvas, option, callback) {
|
|
222
|
-
var _this;
|
|
212
|
+
var jmGraphImpl = /*#__PURE__*/function (_jmGraphCore) {
|
|
213
|
+
_inherits(jmGraphImpl, _jmGraphCore);
|
|
223
214
|
|
|
224
|
-
|
|
215
|
+
var _super = _createSuper(jmGraphImpl);
|
|
225
216
|
|
|
226
|
-
|
|
217
|
+
function jmGraphImpl(canvas, option, callback) {
|
|
218
|
+
_classCallCheck(this, jmGraphImpl);
|
|
227
219
|
|
|
220
|
+
// 合并shapes
|
|
228
221
|
option = Object.assign({}, option);
|
|
229
|
-
option.shapes = Object.assign(shapes, option.shapes || {});
|
|
230
|
-
|
|
231
|
-
if (!targetType || !(targetType.prototype instanceof _jmGraph.jmGraph)) {
|
|
232
|
-
return _possibleConstructorReturn(_this, new Promise(function (resolve, reject) {
|
|
233
|
-
var g = new jmGraph(canvas, option, callback);
|
|
234
|
-
if (resolve) resolve(g);
|
|
235
|
-
}));
|
|
236
|
-
}
|
|
222
|
+
option.shapes = Object.assign(shapes, option.shapes || {});
|
|
237
223
|
|
|
238
224
|
if (typeof option == 'function') {
|
|
239
225
|
callback = option;
|
|
@@ -243,30 +229,25 @@ var jmGraph = /*#__PURE__*/function (_jmGraphCore) {
|
|
|
243
229
|
return _super.call(this, canvas, option, callback);
|
|
244
230
|
}
|
|
245
231
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
value: function create() {
|
|
249
|
-
return createJmGraph.apply(void 0, arguments);
|
|
250
|
-
}
|
|
251
|
-
}]);
|
|
252
|
-
|
|
253
|
-
return jmGraph;
|
|
254
|
-
}(_jmGraph.jmGraph); //创建实例
|
|
232
|
+
return jmGraphImpl;
|
|
233
|
+
}(_jmGraph.jmGraph); //创建实例,支持不加 new 直接调用
|
|
255
234
|
|
|
256
235
|
|
|
257
|
-
exports.jmGraph =
|
|
236
|
+
exports.jmGraph = jmGraphImpl;
|
|
258
237
|
|
|
259
238
|
var createJmGraph = function createJmGraph() {
|
|
260
239
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
261
240
|
args[_key] = arguments[_key];
|
|
262
241
|
}
|
|
263
242
|
|
|
264
|
-
return _construct(
|
|
243
|
+
return _construct(jmGraphImpl, args);
|
|
265
244
|
};
|
|
266
245
|
|
|
267
246
|
exports.create = createJmGraph;
|
|
247
|
+
var _default = jmGraphImpl;
|
|
248
|
+
exports["default"] = _default;
|
|
268
249
|
|
|
269
|
-
},{"./src/core/jmGraph.js":
|
|
250
|
+
},{"./src/core/jmGraph.js":6,"./src/shapes/jmArc.js":23,"./src/shapes/jmArrow.js":24,"./src/shapes/jmArrowLine.js":25,"./src/shapes/jmBezier.js":26,"./src/shapes/jmCircle.js":27,"./src/shapes/jmEllipse.js":28,"./src/shapes/jmHArc.js":29,"./src/shapes/jmImage.js":30,"./src/shapes/jmLabel.js":31,"./src/shapes/jmLine.js":32,"./src/shapes/jmPolygon.js":33,"./src/shapes/jmPrismatic.js":34,"./src/shapes/jmRect.js":35,"./src/shapes/jmResize.js":36,"./src/shapes/jmStar.js":37}],2:[function(require,module,exports){
|
|
270
251
|
"use strict";
|
|
271
252
|
|
|
272
253
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -282,20 +263,14 @@ var _jmGradient = require("./jmGradient.js");
|
|
|
282
263
|
|
|
283
264
|
var _jmShadow = require("./jmShadow.js");
|
|
284
265
|
|
|
266
|
+
var _jmFilter = require("./jmFilter.js");
|
|
267
|
+
|
|
285
268
|
var _jmProperty2 = require("./jmProperty.js");
|
|
286
269
|
|
|
287
270
|
var _path = _interopRequireDefault(require("../lib/webgl/path.js"));
|
|
288
271
|
|
|
289
272
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
290
273
|
|
|
291
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
292
|
-
|
|
293
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
294
|
-
|
|
295
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
296
|
-
|
|
297
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
298
|
-
|
|
299
274
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
300
275
|
|
|
301
276
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
@@ -351,7 +326,9 @@ var jmStyleMap = {
|
|
|
351
326
|
'shadowOffsetY': 'shadowOffsetY',
|
|
352
327
|
'shadowColor': 'shadowColor',
|
|
353
328
|
'lineJoin': 'lineJoin',
|
|
354
|
-
'lineCap': 'lineCap'
|
|
329
|
+
'lineCap': 'lineCap',
|
|
330
|
+
'lineDashOffset': 'lineDashOffset',
|
|
331
|
+
'globalCompositeOperation': 'globalCompositeOperation'
|
|
355
332
|
};
|
|
356
333
|
|
|
357
334
|
var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
@@ -593,7 +570,10 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
593
570
|
value: function setStyle(style) {
|
|
594
571
|
var _this3 = this;
|
|
595
572
|
|
|
596
|
-
|
|
573
|
+
if (!style) {
|
|
574
|
+
style = this.style;
|
|
575
|
+
}
|
|
576
|
+
|
|
597
577
|
if (!style) return;
|
|
598
578
|
|
|
599
579
|
var __setStyle = function __setStyle(style, name, mpkey) {
|
|
@@ -681,6 +661,153 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
681
661
|
case 'cursor':
|
|
682
662
|
{
|
|
683
663
|
_this3.cursor = styleValue;
|
|
664
|
+
break;
|
|
665
|
+
}
|
|
666
|
+
// ===== 新增样式特性 =====
|
|
667
|
+
// 虚线样式:支持自定义lineDash模式 (如 [5, 3, 2] 或 "5,3,2")
|
|
668
|
+
|
|
669
|
+
case 'lineDash':
|
|
670
|
+
{
|
|
671
|
+
if (!_this3.context.setLineDash) break;
|
|
672
|
+
var dash;
|
|
673
|
+
|
|
674
|
+
if (typeof styleValue === 'string') {
|
|
675
|
+
dash = styleValue.split(',').map(function (v) {
|
|
676
|
+
return parseFloat(v.trim());
|
|
677
|
+
}).filter(function (v) {
|
|
678
|
+
return !isNaN(v);
|
|
679
|
+
});
|
|
680
|
+
} else if (Array.isArray(styleValue)) {
|
|
681
|
+
dash = styleValue.map(function (v) {
|
|
682
|
+
return parseFloat(v);
|
|
683
|
+
}).filter(function (v) {
|
|
684
|
+
return !isNaN(v);
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
if (dash && dash.length) {
|
|
689
|
+
_this3.context.setLineDash(dash);
|
|
690
|
+
} else {
|
|
691
|
+
_this3.context.setLineDash([]);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
break;
|
|
695
|
+
}
|
|
696
|
+
// 虚线偏移量
|
|
697
|
+
|
|
698
|
+
case 'lineDashOffset':
|
|
699
|
+
{
|
|
700
|
+
if (!_this3.context.setLineDash) break;
|
|
701
|
+
_this3.context.lineDashOffset = Number(styleValue) || 0;
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
// CSS滤镜效果 (blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity)
|
|
705
|
+
|
|
706
|
+
case 'filter':
|
|
707
|
+
{
|
|
708
|
+
if (_this3.context.filter === undefined) break;
|
|
709
|
+
|
|
710
|
+
if (styleValue instanceof _jmFilter.jmFilter) {
|
|
711
|
+
_this3.context.filter = styleValue.toCanvasFilter();
|
|
712
|
+
} else if (typeof styleValue === 'string') {
|
|
713
|
+
_this3.context.filter = styleValue || 'none';
|
|
714
|
+
} else if (_typeof(styleValue) === 'object') {
|
|
715
|
+
_this3.context.filter = new _jmFilter.jmFilter(styleValue).toCanvasFilter();
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
break;
|
|
719
|
+
}
|
|
720
|
+
// 混合模式 (source-over, multiply, screen, overlay, darken, lighten, etc.)
|
|
721
|
+
|
|
722
|
+
case 'globalCompositeOperation':
|
|
723
|
+
{
|
|
724
|
+
if (!_this3.context.globalCompositeOperation) break;
|
|
725
|
+
_this3.context.globalCompositeOperation = styleValue;
|
|
726
|
+
break;
|
|
727
|
+
}
|
|
728
|
+
// 裁剪路径:通过canvas clip实现
|
|
729
|
+
|
|
730
|
+
case 'clipPath':
|
|
731
|
+
{
|
|
732
|
+
if (!_this3.context.clip) break; // clipPath可以是一个图形控件实例
|
|
733
|
+
|
|
734
|
+
if (styleValue && styleValue.points && styleValue.points.length > 0) {
|
|
735
|
+
var bounds = _this3.parent && _this3.parent.absoluteBounds ? _this3.parent.absoluteBounds : _this3.absoluteBounds;
|
|
736
|
+
|
|
737
|
+
_this3.context.beginPath();
|
|
738
|
+
|
|
739
|
+
_this3.context.moveTo(styleValue.points[0].x + (bounds ? bounds.left : 0), styleValue.points[0].y + (bounds ? bounds.top : 0));
|
|
740
|
+
|
|
741
|
+
for (var i = 1; i < styleValue.points.length; i++) {
|
|
742
|
+
if (styleValue.points[i].m) {
|
|
743
|
+
_this3.context.moveTo(styleValue.points[i].x + (bounds ? bounds.left : 0), styleValue.points[i].y + (bounds ? bounds.top : 0));
|
|
744
|
+
} else {
|
|
745
|
+
_this3.context.lineTo(styleValue.points[i].x + (bounds ? bounds.left : 0), styleValue.points[i].y + (bounds ? bounds.top : 0));
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
if (styleValue.style && styleValue.style.close) {
|
|
750
|
+
_this3.context.closePath();
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
_this3.context.clip();
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
break;
|
|
757
|
+
}
|
|
758
|
+
// 遮罩效果:通过globalCompositeOperation + destination-in实现
|
|
759
|
+
|
|
760
|
+
case 'mask':
|
|
761
|
+
{
|
|
762
|
+
if (!_this3.context.globalCompositeOperation) break; // mask是一个图形控件实例,在绘制前需要先应用mask
|
|
763
|
+
// 这里只是标记,实际绘制在paint流程中处理
|
|
764
|
+
|
|
765
|
+
_this3.__mask = styleValue;
|
|
766
|
+
break;
|
|
767
|
+
}
|
|
768
|
+
// 图片阴影描边阴影(WebGL纹理canvas用)
|
|
769
|
+
|
|
770
|
+
case 'shadowColor':
|
|
771
|
+
{
|
|
772
|
+
if (_this3.webglControl) {
|
|
773
|
+
_this3.webglControl.setStyle('shadowColor', styleValue);
|
|
774
|
+
} else {
|
|
775
|
+
_this3.context.shadowColor = _jmUtils.jmUtils.toColor(styleValue);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
break;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
case 'shadowBlur':
|
|
782
|
+
{
|
|
783
|
+
if (_this3.webglControl) {
|
|
784
|
+
_this3.webglControl.setStyle('shadowBlur', styleValue);
|
|
785
|
+
} else {
|
|
786
|
+
_this3.context.shadowBlur = Number(styleValue) || 0;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
break;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
case 'shadowOffsetX':
|
|
793
|
+
{
|
|
794
|
+
if (_this3.webglControl) {
|
|
795
|
+
_this3.webglControl.setStyle('shadowOffsetX', styleValue);
|
|
796
|
+
} else {
|
|
797
|
+
_this3.context.shadowOffsetX = Number(styleValue) || 0;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
break;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
case 'shadowOffsetY':
|
|
804
|
+
{
|
|
805
|
+
if (_this3.webglControl) {
|
|
806
|
+
_this3.webglControl.setStyle('shadowOffsetY', styleValue);
|
|
807
|
+
} else {
|
|
808
|
+
_this3.context.shadowOffsetY = Number(styleValue) || 0;
|
|
809
|
+
}
|
|
810
|
+
|
|
684
811
|
break;
|
|
685
812
|
}
|
|
686
813
|
}
|
|
@@ -705,6 +832,8 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
705
832
|
style[k] = new _jmGradient.jmGradient(style[k]);
|
|
706
833
|
} else if (t == 'string' && k == 'shadow') {
|
|
707
834
|
style[k] = new _jmShadow.jmShadow(style[k]);
|
|
835
|
+
} else if (t == 'string' && k == 'filter') {
|
|
836
|
+
style[k] = new _jmFilter.jmFilter(style[k]);
|
|
708
837
|
}
|
|
709
838
|
|
|
710
839
|
__setStyle(style[k], k);
|
|
@@ -882,7 +1011,6 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
882
1011
|
}, {
|
|
883
1012
|
key: "getLocation",
|
|
884
1013
|
value: function getLocation() {
|
|
885
|
-
var clone = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
886
1014
|
//如果已经计算过则直接返回
|
|
887
1015
|
//在开画之前会清空此对象
|
|
888
1016
|
//if(reset !== true && this.location) return this.location;
|
|
@@ -891,32 +1019,34 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
891
1019
|
top: 0,
|
|
892
1020
|
width: 0,
|
|
893
1021
|
height: 0
|
|
894
|
-
};
|
|
895
|
-
|
|
896
|
-
|
|
1022
|
+
}; // 检查是否有百分比参数需要解析,没有则直接引用避免克隆开销
|
|
1023
|
+
|
|
1024
|
+
var needResolve = this.parent && (_jmUtils.jmUtils.checkPercent(this.width) || _jmUtils.jmUtils.checkPercent(this.height) || this.position && _jmUtils.jmUtils.checkPercent(this.position.x) || this.position && _jmUtils.jmUtils.checkPercent(this.position.y));
|
|
1025
|
+
|
|
1026
|
+
local.position = typeof this.position == 'function' ? this.position() : needResolve ? _jmUtils.jmUtils.clone(this.position) : this.position;
|
|
1027
|
+
local.center = this.center && typeof this.center === 'function' ? this.center() : needResolve ? _jmUtils.jmUtils.clone(this.center) : this.center; //中心
|
|
897
1028
|
|
|
898
|
-
local.start = this.start && typeof this.start === 'function' ? this.start() : _jmUtils.jmUtils.clone(this.start); //起点
|
|
1029
|
+
local.start = this.start && typeof this.start === 'function' ? this.start() : needResolve ? _jmUtils.jmUtils.clone(this.start) : this.start; //起点
|
|
899
1030
|
|
|
900
|
-
local.end = this.end && typeof this.end === 'function' ? this.end() : _jmUtils.jmUtils.clone(this.end); //起点
|
|
1031
|
+
local.end = this.end && typeof this.end === 'function' ? this.end() : needResolve ? _jmUtils.jmUtils.clone(this.end) : this.end; //起点
|
|
901
1032
|
|
|
902
1033
|
local.radius = this.radius; //半径
|
|
903
1034
|
|
|
904
1035
|
local.width = this.width;
|
|
905
1036
|
local.height = this.height;
|
|
906
|
-
|
|
907
|
-
var
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
margin.bottom = margin.bottom || 0; //如果没有指定位置,但指定了margin。则位置取margin偏移量
|
|
1037
|
+
var margin = this.style.margin;
|
|
1038
|
+
var marginObj = needResolve && margin ? _jmUtils.jmUtils.clone(margin, {}) : margin || {};
|
|
1039
|
+
marginObj.left = marginObj.left || 0;
|
|
1040
|
+
marginObj.top = marginObj.top || 0;
|
|
1041
|
+
marginObj.right = marginObj.right || 0;
|
|
1042
|
+
marginObj.bottom = marginObj.bottom || 0; //如果没有指定位置,但指定了margin。则位置取margin偏移量
|
|
913
1043
|
|
|
914
1044
|
if (local.position) {
|
|
915
1045
|
local.left = local.position.x;
|
|
916
1046
|
local.top = local.position.y;
|
|
917
1047
|
} else {
|
|
918
|
-
local.left =
|
|
919
|
-
local.top =
|
|
1048
|
+
local.left = marginObj.left;
|
|
1049
|
+
local.top = marginObj.top;
|
|
920
1050
|
}
|
|
921
1051
|
|
|
922
1052
|
if (this.parent) {
|
|
@@ -1210,25 +1340,36 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1210
1340
|
if (this.style.close) {
|
|
1211
1341
|
if (this.webglControl) this.webglControl.closePath();
|
|
1212
1342
|
this.context.closePath && this.context.closePath();
|
|
1213
|
-
}
|
|
1343
|
+
} // 根据渲染模式选择不同的绘制路径
|
|
1214
1344
|
|
|
1215
|
-
var fill = this.style['fill'] || this.style['fillStyle'];
|
|
1216
1345
|
|
|
1217
|
-
if (
|
|
1218
|
-
|
|
1346
|
+
if (this.webglControl) {
|
|
1347
|
+
// WebGL 模式:使用 WebGL 绘制
|
|
1348
|
+
var fill = this.style['fill'] || this.style['fillStyle'];
|
|
1349
|
+
|
|
1350
|
+
if (fill) {
|
|
1219
1351
|
var bounds = this.getBounds();
|
|
1220
1352
|
this.webglControl.fill(bounds);
|
|
1221
1353
|
}
|
|
1222
1354
|
|
|
1223
|
-
this.
|
|
1224
|
-
|
|
1355
|
+
if (this.style['stroke'] || !fill && !this.is('jmGraph')) {
|
|
1356
|
+
this.webglControl.stroke();
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
if (this.webglControl.endDraw) this.webglControl.endDraw();
|
|
1360
|
+
} else {
|
|
1361
|
+
// 2D 模式:使用 Canvas 2D API 绘制
|
|
1362
|
+
var _fill = this.style['fill'] || this.style['fillStyle'];
|
|
1363
|
+
|
|
1364
|
+
if (_fill) {
|
|
1365
|
+
this.context.fill && this.context.fill();
|
|
1366
|
+
}
|
|
1225
1367
|
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1368
|
+
if (this.style['stroke'] || !_fill && !this.is('jmGraph')) {
|
|
1369
|
+
this.context.stroke && this.context.stroke();
|
|
1370
|
+
}
|
|
1229
1371
|
}
|
|
1230
1372
|
|
|
1231
|
-
if (this.webglControl && this.webglControl.endDraw) this.webglControl.endDraw();
|
|
1232
1373
|
this.needUpdate = false;
|
|
1233
1374
|
}
|
|
1234
1375
|
/**
|
|
@@ -1247,7 +1388,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1247
1388
|
|
|
1248
1389
|
if (this.webglControl) {
|
|
1249
1390
|
this.webglControl.setParentBounds(bounds);
|
|
1250
|
-
this.webglControl.draw(
|
|
1391
|
+
this.webglControl.draw(this.points);
|
|
1251
1392
|
} else if (this.context && this.context.moveTo) {
|
|
1252
1393
|
this.context.moveTo(this.points[0].x + bounds.left, this.points[0].y + bounds.top);
|
|
1253
1394
|
var len = this.points.length;
|
|
@@ -1288,10 +1429,47 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1288
1429
|
this.context.save && this.context.save();
|
|
1289
1430
|
this.emit('beginDraw', this);
|
|
1290
1431
|
this.setStyle(); //设定样式
|
|
1432
|
+
// 应用mask遮罩效果:在mask区域内绘制当前控件
|
|
1433
|
+
// 使用 destination-in 合成模式,只保留mask区域内的内容
|
|
1434
|
+
|
|
1435
|
+
var maskStyle = this.style.mask || this.__mask;
|
|
1436
|
+
|
|
1437
|
+
if (maskStyle && maskStyle.points && this.context.globalCompositeOperation) {
|
|
1438
|
+
// 先绘制当前控件
|
|
1439
|
+
if (needDraw && this.beginDraw) this.beginDraw();
|
|
1440
|
+
if (needDraw && this.draw) this.draw();
|
|
1441
|
+
if (needDraw && this.endDraw) this.endDraw(); // 再应用mask裁剪
|
|
1442
|
+
|
|
1443
|
+
this.context.globalCompositeOperation = 'destination-in';
|
|
1444
|
+
if (maskStyle.initPoints) maskStyle.initPoints();
|
|
1445
|
+
var mBounds = maskStyle.parent && maskStyle.parent.absoluteBounds ? maskStyle.parent.absoluteBounds : this.absoluteBounds;
|
|
1446
|
+
this.context.beginPath();
|
|
1447
|
+
|
|
1448
|
+
if (maskStyle.points && maskStyle.points.length > 0) {
|
|
1449
|
+
this.context.moveTo(maskStyle.points[0].x + (mBounds ? mBounds.left : 0), maskStyle.points[0].y + (mBounds ? mBounds.top : 0));
|
|
1450
|
+
|
|
1451
|
+
for (var i = 1; i < maskStyle.points.length; i++) {
|
|
1452
|
+
if (maskStyle.points[i].m) {
|
|
1453
|
+
this.context.moveTo(maskStyle.points[i].x + (mBounds ? mBounds.left : 0), maskStyle.points[i].y + (mBounds ? mBounds.top : 0));
|
|
1454
|
+
} else {
|
|
1455
|
+
this.context.lineTo(maskStyle.points[i].x + (mBounds ? mBounds.left : 0), maskStyle.points[i].y + (mBounds ? mBounds.top : 0));
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
if (maskStyle.style && maskStyle.style.close) {
|
|
1460
|
+
this.context.closePath();
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1291
1463
|
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1464
|
+
this.context.fillStyle = '#ffffff';
|
|
1465
|
+
this.context.fill(); // 恢复合成模式
|
|
1466
|
+
|
|
1467
|
+
this.context.globalCompositeOperation = 'source-over';
|
|
1468
|
+
} else {
|
|
1469
|
+
if (needDraw && this.beginDraw) this.beginDraw();
|
|
1470
|
+
if (needDraw && this.draw) this.draw();
|
|
1471
|
+
if (needDraw && this.endDraw) this.endDraw();
|
|
1472
|
+
}
|
|
1295
1473
|
|
|
1296
1474
|
if (this.children) {
|
|
1297
1475
|
this.children.each(function (i, item) {
|
|
@@ -1928,7 +2106,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1928
2106
|
exports.jmControl = exports["default"] = jmControl;
|
|
1929
2107
|
;
|
|
1930
2108
|
|
|
1931
|
-
},{"../lib/webgl/path.js":22,"./
|
|
2109
|
+
},{"../lib/webgl/path.js":22,"./jmFilter.js":4,"./jmGradient.js":5,"./jmList.js":7,"./jmProperty.js":10,"./jmShadow.js":11,"./jmUtils.js":12}],3:[function(require,module,exports){
|
|
1932
2110
|
"use strict";
|
|
1933
2111
|
|
|
1934
2112
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -2205,6 +2383,209 @@ var jmKeyEvent = /*#__PURE__*/function () {
|
|
|
2205
2383
|
},{"./jmUtils.js":12}],4:[function(require,module,exports){
|
|
2206
2384
|
"use strict";
|
|
2207
2385
|
|
|
2386
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2387
|
+
value: true
|
|
2388
|
+
});
|
|
2389
|
+
exports.jmFilter = exports["default"] = void 0;
|
|
2390
|
+
|
|
2391
|
+
var _jmUtils = require("./jmUtils.js");
|
|
2392
|
+
|
|
2393
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
2394
|
+
|
|
2395
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2396
|
+
|
|
2397
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
2398
|
+
|
|
2399
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
2400
|
+
|
|
2401
|
+
/**
|
|
2402
|
+
* CSS滤镜效果类
|
|
2403
|
+
* 支持的滤镜: blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity
|
|
2404
|
+
*
|
|
2405
|
+
* @class jmFilter
|
|
2406
|
+
* @param {string|object} opt 滤镜参数
|
|
2407
|
+
* 字符串格式: "blur(2px) grayscale(50%) brightness(1.2)"
|
|
2408
|
+
* 对象格式: { blur: 2, grayscale: 0.5, brightness: 1.2 }
|
|
2409
|
+
*/
|
|
2410
|
+
var jmFilter = /*#__PURE__*/function () {
|
|
2411
|
+
function jmFilter(opt) {
|
|
2412
|
+
_classCallCheck(this, jmFilter);
|
|
2413
|
+
|
|
2414
|
+
this.filters = [];
|
|
2415
|
+
|
|
2416
|
+
if (typeof opt === 'string') {
|
|
2417
|
+
this.fromString(opt);
|
|
2418
|
+
} else if (opt && _typeof(opt) === 'object') {
|
|
2419
|
+
for (var k in opt) {
|
|
2420
|
+
if (k === 'constructor' || k === 'filters') continue;
|
|
2421
|
+
this.addFilter(k, opt[k]);
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
/**
|
|
2426
|
+
* 添加单个滤镜
|
|
2427
|
+
* @param {string} name 滤镜名称 (blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity)
|
|
2428
|
+
* @param {number|string} value 滤镜值
|
|
2429
|
+
*/
|
|
2430
|
+
|
|
2431
|
+
|
|
2432
|
+
_createClass(jmFilter, [{
|
|
2433
|
+
key: "addFilter",
|
|
2434
|
+
value: function addFilter(name, value) {
|
|
2435
|
+
name = name.toLowerCase().trim();
|
|
2436
|
+
|
|
2437
|
+
if (typeof value === 'string') {
|
|
2438
|
+
value = parseFloat(value);
|
|
2439
|
+
}
|
|
2440
|
+
|
|
2441
|
+
if (isNaN(value)) return; // 规范化滤镜名称
|
|
2442
|
+
|
|
2443
|
+
var normalized = {
|
|
2444
|
+
'blur': 'blur',
|
|
2445
|
+
'grayscale': 'grayscale',
|
|
2446
|
+
'greyscale': 'grayscale',
|
|
2447
|
+
'sepia': 'sepia',
|
|
2448
|
+
'brightness': 'brightness',
|
|
2449
|
+
'contrast': 'contrast',
|
|
2450
|
+
'saturate': 'saturate',
|
|
2451
|
+
'hue-rotate': 'hueRotate',
|
|
2452
|
+
'hueRotate': 'hueRotate',
|
|
2453
|
+
'invert': 'invert',
|
|
2454
|
+
'opacity': 'opacity'
|
|
2455
|
+
}[name];
|
|
2456
|
+
if (!normalized) return; // 检查是否已有同名滤镜,有则更新
|
|
2457
|
+
|
|
2458
|
+
var existing = this.filters.find(function (f) {
|
|
2459
|
+
return f.name === normalized;
|
|
2460
|
+
});
|
|
2461
|
+
|
|
2462
|
+
if (existing) {
|
|
2463
|
+
existing.value = value;
|
|
2464
|
+
} else {
|
|
2465
|
+
this.filters.push({
|
|
2466
|
+
name: normalized,
|
|
2467
|
+
value: value
|
|
2468
|
+
});
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
/**
|
|
2472
|
+
* 从字符串格式解析滤镜
|
|
2473
|
+
* 格式: "blur(2px) grayscale(50%) brightness(1.2)"
|
|
2474
|
+
* @param {string} s 滤镜字符串
|
|
2475
|
+
*/
|
|
2476
|
+
|
|
2477
|
+
}, {
|
|
2478
|
+
key: "fromString",
|
|
2479
|
+
value: function fromString(s) {
|
|
2480
|
+
if (!s || typeof s !== 'string') return; // 匹配 filterName(value) 模式
|
|
2481
|
+
|
|
2482
|
+
var regex = /([a-zA-Z-]+)\s*\(\s*([^)]+)\s*\)/g;
|
|
2483
|
+
var match;
|
|
2484
|
+
|
|
2485
|
+
while ((match = regex.exec(s)) !== null) {
|
|
2486
|
+
var name = match[1];
|
|
2487
|
+
var valueStr = match[2].replace(/[a-z%]+$/i, '').trim();
|
|
2488
|
+
var value = parseFloat(valueStr);
|
|
2489
|
+
|
|
2490
|
+
if (!isNaN(value)) {
|
|
2491
|
+
this.addFilter(name, value);
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
/**
|
|
2496
|
+
* 转换为CSS filter字符串格式
|
|
2497
|
+
* @returns {string}
|
|
2498
|
+
*/
|
|
2499
|
+
|
|
2500
|
+
}, {
|
|
2501
|
+
key: "toString",
|
|
2502
|
+
value: function toString() {
|
|
2503
|
+
return this.filters.map(function (f) {
|
|
2504
|
+
switch (f.name) {
|
|
2505
|
+
case 'blur':
|
|
2506
|
+
return "blur(".concat(f.value, "px)");
|
|
2507
|
+
|
|
2508
|
+
case 'hueRotate':
|
|
2509
|
+
return "hue-rotate(".concat(f.value, "deg)");
|
|
2510
|
+
|
|
2511
|
+
default:
|
|
2512
|
+
return "".concat(f.name, "(").concat(f.value, ")");
|
|
2513
|
+
}
|
|
2514
|
+
}).join(' ');
|
|
2515
|
+
}
|
|
2516
|
+
/**
|
|
2517
|
+
* 转换为Canvas context.filter可用的字符串
|
|
2518
|
+
* @returns {string}
|
|
2519
|
+
*/
|
|
2520
|
+
|
|
2521
|
+
}, {
|
|
2522
|
+
key: "toCanvasFilter",
|
|
2523
|
+
value: function toCanvasFilter() {
|
|
2524
|
+
if (this.filters.length === 0) return 'none';
|
|
2525
|
+
return this.toString();
|
|
2526
|
+
}
|
|
2527
|
+
/**
|
|
2528
|
+
* 检查是否有指定名称的滤镜
|
|
2529
|
+
* @param {string} name 滤镜名称
|
|
2530
|
+
* @returns {boolean}
|
|
2531
|
+
*/
|
|
2532
|
+
|
|
2533
|
+
}, {
|
|
2534
|
+
key: "has",
|
|
2535
|
+
value: function has(name) {
|
|
2536
|
+
return this.filters.some(function (f) {
|
|
2537
|
+
return f.name === name;
|
|
2538
|
+
});
|
|
2539
|
+
}
|
|
2540
|
+
/**
|
|
2541
|
+
* 获取指定滤镜的值
|
|
2542
|
+
* @param {string} name 滤镜名称
|
|
2543
|
+
* @returns {number|undefined}
|
|
2544
|
+
*/
|
|
2545
|
+
|
|
2546
|
+
}, {
|
|
2547
|
+
key: "get",
|
|
2548
|
+
value: function get(name) {
|
|
2549
|
+
var f = this.filters.find(function (f) {
|
|
2550
|
+
return f.name === name;
|
|
2551
|
+
});
|
|
2552
|
+
return f ? f.value : undefined;
|
|
2553
|
+
}
|
|
2554
|
+
/**
|
|
2555
|
+
* 移除指定滤镜
|
|
2556
|
+
* @param {string} name 滤镜名称
|
|
2557
|
+
*/
|
|
2558
|
+
|
|
2559
|
+
}, {
|
|
2560
|
+
key: "remove",
|
|
2561
|
+
value: function remove(name) {
|
|
2562
|
+
var index = this.filters.findIndex(function (f) {
|
|
2563
|
+
return f.name === name;
|
|
2564
|
+
});
|
|
2565
|
+
|
|
2566
|
+
if (index > -1) {
|
|
2567
|
+
this.filters.splice(index, 1);
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
/**
|
|
2571
|
+
* 清空所有滤镜
|
|
2572
|
+
*/
|
|
2573
|
+
|
|
2574
|
+
}, {
|
|
2575
|
+
key: "clear",
|
|
2576
|
+
value: function clear() {
|
|
2577
|
+
this.filters = [];
|
|
2578
|
+
}
|
|
2579
|
+
}]);
|
|
2580
|
+
|
|
2581
|
+
return jmFilter;
|
|
2582
|
+
}();
|
|
2583
|
+
|
|
2584
|
+
exports.jmFilter = exports["default"] = jmFilter;
|
|
2585
|
+
|
|
2586
|
+
},{"./jmUtils.js":12}],5:[function(require,module,exports){
|
|
2587
|
+
"use strict";
|
|
2588
|
+
|
|
2208
2589
|
Object.defineProperty(exports, "__esModule", {
|
|
2209
2590
|
value: true
|
|
2210
2591
|
});
|
|
@@ -2485,7 +2866,7 @@ var jmGradient = /*#__PURE__*/function () {
|
|
|
2485
2866
|
|
|
2486
2867
|
exports.jmGradient = exports["default"] = jmGradient;
|
|
2487
2868
|
|
|
2488
|
-
},{"./jmList.js":7,"./jmUtils.js":12}],
|
|
2869
|
+
},{"./jmList.js":7,"./jmUtils.js":12}],6:[function(require,module,exports){
|
|
2489
2870
|
"use strict";
|
|
2490
2871
|
|
|
2491
2872
|
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
@@ -2523,6 +2904,12 @@ Object.defineProperty(exports, "jmGradient", {
|
|
|
2523
2904
|
return _jmGradient.jmGradient;
|
|
2524
2905
|
}
|
|
2525
2906
|
});
|
|
2907
|
+
Object.defineProperty(exports, "jmFilter", {
|
|
2908
|
+
enumerable: true,
|
|
2909
|
+
get: function get() {
|
|
2910
|
+
return _jmFilter.jmFilter;
|
|
2911
|
+
}
|
|
2912
|
+
});
|
|
2526
2913
|
Object.defineProperty(exports, "jmEvents", {
|
|
2527
2914
|
enumerable: true,
|
|
2528
2915
|
get: function get() {
|
|
@@ -2541,12 +2928,6 @@ Object.defineProperty(exports, "jmPath", {
|
|
|
2541
2928
|
return _jmPath.jmPath;
|
|
2542
2929
|
}
|
|
2543
2930
|
});
|
|
2544
|
-
Object.defineProperty(exports, "jmLayer", {
|
|
2545
|
-
enumerable: true,
|
|
2546
|
-
get: function get() {
|
|
2547
|
-
return _jmLayer.jmLayer;
|
|
2548
|
-
}
|
|
2549
|
-
});
|
|
2550
2931
|
exports.jmGraph = exports["default"] = void 0;
|
|
2551
2932
|
|
|
2552
2933
|
var _jmUtils = require("./jmUtils.js");
|
|
@@ -2559,14 +2940,14 @@ var _jmShadow = require("./jmShadow.js");
|
|
|
2559
2940
|
|
|
2560
2941
|
var _jmGradient = require("./jmGradient.js");
|
|
2561
2942
|
|
|
2943
|
+
var _jmFilter = require("./jmFilter.js");
|
|
2944
|
+
|
|
2562
2945
|
var _jmEvents = require("./jmEvents.js");
|
|
2563
2946
|
|
|
2564
2947
|
var _jmControl2 = require("./jmControl.js");
|
|
2565
2948
|
|
|
2566
2949
|
var _jmPath = require("./jmPath.js");
|
|
2567
2950
|
|
|
2568
|
-
var _jmLayer = require("./jmLayer.js");
|
|
2569
|
-
|
|
2570
2951
|
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
2571
2952
|
|
|
2572
2953
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -2902,9 +3283,7 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
|
2902
3283
|
if (shape) {
|
|
2903
3284
|
if (!args) args = {};
|
|
2904
3285
|
args.graph = this;
|
|
2905
|
-
var obj = new shape(args);
|
|
2906
|
-
|
|
2907
|
-
this.addShapeToLayer(obj);
|
|
3286
|
+
var obj = new shape(args);
|
|
2908
3287
|
return obj;
|
|
2909
3288
|
}
|
|
2910
3289
|
}
|
|
@@ -3275,251 +3654,10 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
|
3275
3654
|
return this; // 支持链式调用
|
|
3276
3655
|
}
|
|
3277
3656
|
/**
|
|
3278
|
-
*
|
|
3279
|
-
* 创建图层管理的基础结构,包括默认图层
|
|
3657
|
+
* 保存为base64图形数据
|
|
3280
3658
|
*
|
|
3281
|
-
* @method
|
|
3282
|
-
* @
|
|
3283
|
-
*/
|
|
3284
|
-
|
|
3285
|
-
}, {
|
|
3286
|
-
key: "initLayers",
|
|
3287
|
-
value: function initLayers() {
|
|
3288
|
-
if (!this.layers) {
|
|
3289
|
-
this.layers = new _jmList.jmList(); // 创建默认图层
|
|
3290
|
-
|
|
3291
|
-
var defaultLayer = this.createLayer('Default Layer');
|
|
3292
|
-
this.activeLayer = defaultLayer;
|
|
3293
|
-
}
|
|
3294
|
-
}
|
|
3295
|
-
/**
|
|
3296
|
-
* 创建新图层
|
|
3297
|
-
* 图层用于组织和管理图形对象,支持可见性和锁定控制
|
|
3298
|
-
*
|
|
3299
|
-
* @method createLayer
|
|
3300
|
-
* @param {string} name 图层名称(必须唯一)
|
|
3301
|
-
* @param {object} [options] 图层选项
|
|
3302
|
-
* @param {boolean} [options.visible=true] 图层是否可见
|
|
3303
|
-
* @param {boolean} [options.locked=false] 图层是否锁定(锁定后不可交互)
|
|
3304
|
-
* @return {jmLayer} 新创建的图层
|
|
3305
|
-
*/
|
|
3306
|
-
|
|
3307
|
-
}, {
|
|
3308
|
-
key: "createLayer",
|
|
3309
|
-
value: function createLayer(name) {
|
|
3310
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3311
|
-
|
|
3312
|
-
// 参数验证
|
|
3313
|
-
if (!name || typeof name !== 'string') {
|
|
3314
|
-
console.warn('jmGraph: createLayer - 图层名称必须是非空字符串');
|
|
3315
|
-
name = "Layer_".concat(Date.now());
|
|
3316
|
-
}
|
|
3317
|
-
|
|
3318
|
-
this.initLayers(); // 检查图层名称是否已存在
|
|
3319
|
-
|
|
3320
|
-
var existingLayer = this.getLayer(name);
|
|
3321
|
-
|
|
3322
|
-
if (existingLayer) {
|
|
3323
|
-
console.warn("jmGraph: \u56FE\u5C42 \"".concat(name, "\" \u5DF2\u5B58\u5728\uFF0C\u5C06\u8FD4\u56DE\u73B0\u6709\u56FE\u5C42"));
|
|
3324
|
-
return existingLayer;
|
|
3325
|
-
}
|
|
3326
|
-
|
|
3327
|
-
var layer = new _jmLayer.jmLayer(_objectSpread({
|
|
3328
|
-
name: name,
|
|
3329
|
-
graph: this
|
|
3330
|
-
}, options));
|
|
3331
|
-
this.layers.add(layer);
|
|
3332
|
-
this.children.add(layer);
|
|
3333
|
-
this.needUpdate = true;
|
|
3334
|
-
return layer;
|
|
3335
|
-
}
|
|
3336
|
-
/**
|
|
3337
|
-
* 获取所有图层
|
|
3338
|
-
*
|
|
3339
|
-
* @method getLayers
|
|
3340
|
-
* @return {jmList} 图层列表
|
|
3341
|
-
*/
|
|
3342
|
-
|
|
3343
|
-
}, {
|
|
3344
|
-
key: "getLayers",
|
|
3345
|
-
value: function getLayers() {
|
|
3346
|
-
this.initLayers();
|
|
3347
|
-
return this.layers;
|
|
3348
|
-
}
|
|
3349
|
-
/**
|
|
3350
|
-
* 根据名称获取图层
|
|
3351
|
-
*
|
|
3352
|
-
* @method getLayer
|
|
3353
|
-
* @param {string} name 图层名称
|
|
3354
|
-
* @return {jmLayer|null} 图层对象,如果不存在则返回null
|
|
3355
|
-
*/
|
|
3356
|
-
|
|
3357
|
-
}, {
|
|
3358
|
-
key: "getLayer",
|
|
3359
|
-
value: function getLayer(name) {
|
|
3360
|
-
this.initLayers();
|
|
3361
|
-
if (!name) return null;
|
|
3362
|
-
var result = null;
|
|
3363
|
-
this.layers.each(function (i, layer) {
|
|
3364
|
-
if (layer.name === name) {
|
|
3365
|
-
result = layer;
|
|
3366
|
-
return false; // 找到后停止遍历
|
|
3367
|
-
}
|
|
3368
|
-
});
|
|
3369
|
-
return result;
|
|
3370
|
-
}
|
|
3371
|
-
/**
|
|
3372
|
-
* 设置活动图层
|
|
3373
|
-
* 新创建的图形将自动添加到活动图层
|
|
3374
|
-
*
|
|
3375
|
-
* @method setActiveLayer
|
|
3376
|
-
* @param {string|jmLayer} layer 图层名称或图层对象
|
|
3377
|
-
* @return {jmGraph} 返回当前实例,支持链式调用
|
|
3378
|
-
*/
|
|
3379
|
-
|
|
3380
|
-
}, {
|
|
3381
|
-
key: "setActiveLayer",
|
|
3382
|
-
value: function setActiveLayer(layer) {
|
|
3383
|
-
this.initLayers(); // 支持传入图层名称或图层对象
|
|
3384
|
-
|
|
3385
|
-
if (typeof layer === 'string') {
|
|
3386
|
-
layer = this.getLayer(layer);
|
|
3387
|
-
}
|
|
3388
|
-
|
|
3389
|
-
if (!layer || !(layer instanceof _jmLayer.jmLayer)) {
|
|
3390
|
-
console.warn('jmGraph: setActiveLayer - 无效的图层');
|
|
3391
|
-
return this;
|
|
3392
|
-
}
|
|
3393
|
-
|
|
3394
|
-
this.activeLayer = layer;
|
|
3395
|
-
return this;
|
|
3396
|
-
}
|
|
3397
|
-
/**
|
|
3398
|
-
* 获取当前活动图层
|
|
3399
|
-
* 活动图层是新创建图形的默认容器
|
|
3400
|
-
*
|
|
3401
|
-
* @method getActiveLayer
|
|
3402
|
-
* @return {jmLayer} 当前活动图层
|
|
3403
|
-
*/
|
|
3404
|
-
|
|
3405
|
-
}, {
|
|
3406
|
-
key: "getActiveLayer",
|
|
3407
|
-
value: function getActiveLayer() {
|
|
3408
|
-
this.initLayers();
|
|
3409
|
-
return this.activeLayer;
|
|
3410
|
-
}
|
|
3411
|
-
/**
|
|
3412
|
-
* 移除图层
|
|
3413
|
-
* 删除指定图层及其包含的所有图形
|
|
3414
|
-
* 注意:默认图层不可删除
|
|
3415
|
-
*
|
|
3416
|
-
* @method removeLayer
|
|
3417
|
-
* @param {string|jmLayer} layer 图层名称或图层对象
|
|
3418
|
-
* @return {boolean} 是否成功删除
|
|
3419
|
-
*/
|
|
3420
|
-
|
|
3421
|
-
}, {
|
|
3422
|
-
key: "removeLayer",
|
|
3423
|
-
value: function removeLayer(layer) {
|
|
3424
|
-
this.initLayers(); // 支持传入图层名称或图层对象
|
|
3425
|
-
|
|
3426
|
-
if (typeof layer === 'string') {
|
|
3427
|
-
layer = this.getLayer(layer);
|
|
3428
|
-
}
|
|
3429
|
-
|
|
3430
|
-
if (!layer) {
|
|
3431
|
-
console.warn('jmGraph: removeLayer - 图层不存在');
|
|
3432
|
-
return false;
|
|
3433
|
-
} // 禁止删除默认图层
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
if (layer.name === 'Default Layer') {
|
|
3437
|
-
console.warn('jmGraph: 不能删除默认图层');
|
|
3438
|
-
return false;
|
|
3439
|
-
} // 如果删除的是当前活动图层,切换到默认图层
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
if (this.activeLayer === layer) {
|
|
3443
|
-
this.activeLayer = this.getLayer('Default Layer');
|
|
3444
|
-
}
|
|
3445
|
-
|
|
3446
|
-
this.layers.remove(layer);
|
|
3447
|
-
this.children.remove(layer);
|
|
3448
|
-
this.needUpdate = true;
|
|
3449
|
-
return true;
|
|
3450
|
-
}
|
|
3451
|
-
/**
|
|
3452
|
-
* 将形状添加到指定图层
|
|
3453
|
-
* 如果未指定图层,则添加到当前活动图层
|
|
3454
|
-
*
|
|
3455
|
-
* @method addShapeToLayer
|
|
3456
|
-
* @param {jmControl} shape 要添加的形状对象
|
|
3457
|
-
* @param {string|jmLayer} [layer] 图层名称或图层对象,默认为当前活动图层
|
|
3458
|
-
* @return {jmGraph} 返回当前实例,支持链式调用
|
|
3459
|
-
*/
|
|
3460
|
-
|
|
3461
|
-
}, {
|
|
3462
|
-
key: "addShapeToLayer",
|
|
3463
|
-
value: function addShapeToLayer(shape, layer) {
|
|
3464
|
-
this.initLayers(); // 参数验证
|
|
3465
|
-
|
|
3466
|
-
if (!shape) {
|
|
3467
|
-
console.warn('jmGraph: addShapeToLayer - 无效的形状对象');
|
|
3468
|
-
return this;
|
|
3469
|
-
} // 确定目标图层
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
if (!layer) {
|
|
3473
|
-
layer = this.activeLayer;
|
|
3474
|
-
} else if (typeof layer === 'string') {
|
|
3475
|
-
layer = this.getLayer(layer);
|
|
3476
|
-
}
|
|
3477
|
-
|
|
3478
|
-
if (!layer) {
|
|
3479
|
-
console.warn('jmGraph: addShapeToLayer - 图层不存在');
|
|
3480
|
-
return this;
|
|
3481
|
-
}
|
|
3482
|
-
|
|
3483
|
-
layer.children.add(shape);
|
|
3484
|
-
this.needUpdate = true;
|
|
3485
|
-
return this;
|
|
3486
|
-
}
|
|
3487
|
-
/**
|
|
3488
|
-
* 从图层中移除形状
|
|
3489
|
-
*
|
|
3490
|
-
* @method removeShapeFromLayer
|
|
3491
|
-
* @param {jmControl} shape 要移除的形状对象
|
|
3492
|
-
* @return {jmGraph} 返回当前实例,支持链式调用
|
|
3493
|
-
*/
|
|
3494
|
-
|
|
3495
|
-
}, {
|
|
3496
|
-
key: "removeShapeFromLayer",
|
|
3497
|
-
value: function removeShapeFromLayer(shape) {
|
|
3498
|
-
var _this2 = this;
|
|
3499
|
-
|
|
3500
|
-
if (!shape) {
|
|
3501
|
-
console.warn('jmGraph: removeShapeFromLayer - 无效的形状对象');
|
|
3502
|
-
return this;
|
|
3503
|
-
} // 从所有图层中查找并移除
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
if (this.layers) {
|
|
3507
|
-
this.layers.each(function (i, layer) {
|
|
3508
|
-
if (layer.children.contains(shape)) {
|
|
3509
|
-
layer.children.remove(shape);
|
|
3510
|
-
_this2.needUpdate = true;
|
|
3511
|
-
return false; // 找到后停止遍历
|
|
3512
|
-
}
|
|
3513
|
-
});
|
|
3514
|
-
}
|
|
3515
|
-
|
|
3516
|
-
return this;
|
|
3517
|
-
}
|
|
3518
|
-
/**
|
|
3519
|
-
* 保存为base64图形数据
|
|
3520
|
-
*
|
|
3521
|
-
* @method toDataURL
|
|
3522
|
-
* @return {string} 当前画布图的base64字符串
|
|
3659
|
+
* @method toDataURL
|
|
3660
|
+
* @return {string} 当前画布图的base64字符串
|
|
3523
3661
|
*/
|
|
3524
3662
|
|
|
3525
3663
|
}, {
|
|
@@ -3599,9 +3737,8 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
|
3599
3737
|
}
|
|
3600
3738
|
}
|
|
3601
3739
|
/**
|
|
3602
|
-
*
|
|
3603
|
-
*
|
|
3604
|
-
*
|
|
3740
|
+
* 遍历所有形状,生成SVG标记
|
|
3741
|
+
*
|
|
3605
3742
|
* @method toSVG
|
|
3606
3743
|
* @return {string} SVG字符串
|
|
3607
3744
|
*/
|
|
@@ -3614,32 +3751,14 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
|
3614
3751
|
|
|
3615
3752
|
if (this.style && this.style.fill) {
|
|
3616
3753
|
svg += "<rect width=\"100%\" height=\"100%\" fill=\"".concat(this.style.fill, "\"/>");
|
|
3617
|
-
} //
|
|
3754
|
+
} // 遍历所有直接添加的形状
|
|
3618
3755
|
|
|
3619
3756
|
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
layer.children.each(function (j, shape) {
|
|
3627
|
-
if (shape.toSVG) {
|
|
3628
|
-
svg += shape.toSVG();
|
|
3629
|
-
}
|
|
3630
|
-
});
|
|
3631
|
-
svg += '</g>';
|
|
3632
|
-
}
|
|
3633
|
-
});
|
|
3634
|
-
} else {
|
|
3635
|
-
// 遍历直接添加的形状(兼容没有图层系统的情况)
|
|
3636
|
-
this.children.each(function (i, shape) {
|
|
3637
|
-
if (shape.toSVG) {
|
|
3638
|
-
svg += shape.toSVG();
|
|
3639
|
-
}
|
|
3640
|
-
});
|
|
3641
|
-
}
|
|
3642
|
-
|
|
3757
|
+
this.children.each(function (i, shape) {
|
|
3758
|
+
if (shape.toSVG) {
|
|
3759
|
+
svg += shape.toSVG();
|
|
3760
|
+
}
|
|
3761
|
+
});
|
|
3643
3762
|
svg += '</svg>';
|
|
3644
3763
|
return svg;
|
|
3645
3764
|
}
|
|
@@ -3722,215 +3841,7 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
|
3722
3841
|
|
|
3723
3842
|
exports.jmGraph = exports["default"] = jmGraph;
|
|
3724
3843
|
|
|
3725
|
-
},{"./jmControl.js":2,"./jmEvents.js":3,"./
|
|
3726
|
-
"use strict";
|
|
3727
|
-
|
|
3728
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
3729
|
-
|
|
3730
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3731
|
-
value: true
|
|
3732
|
-
});
|
|
3733
|
-
exports.jmLayer = exports["default"] = void 0;
|
|
3734
|
-
|
|
3735
|
-
var _jmControl2 = require("./jmControl.js");
|
|
3736
|
-
|
|
3737
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3738
|
-
|
|
3739
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
3740
|
-
|
|
3741
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
3742
|
-
|
|
3743
|
-
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
|
3744
|
-
|
|
3745
|
-
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
3746
|
-
|
|
3747
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
3748
|
-
|
|
3749
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
3750
|
-
|
|
3751
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
3752
|
-
|
|
3753
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
3754
|
-
|
|
3755
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
3756
|
-
|
|
3757
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
3758
|
-
|
|
3759
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
3760
|
-
|
|
3761
|
-
/**
|
|
3762
|
-
* 图层类
|
|
3763
|
-
* 用于组织和管理图形对象,支持可见性和锁定控制
|
|
3764
|
-
* 图层可以包含多个图形对象,并控制它们的显示和交互
|
|
3765
|
-
*
|
|
3766
|
-
* @class jmLayer
|
|
3767
|
-
* @extends jmControl
|
|
3768
|
-
* @param {object} params 图层参数
|
|
3769
|
-
* @param {string} [params.name] 图层名称,默认为 'Layer_${timestamp}'
|
|
3770
|
-
* @param {boolean} [params.visible=true] 图层是否可见
|
|
3771
|
-
* @param {boolean} [params.locked=false] 图层是否锁定(锁定后不可交互)
|
|
3772
|
-
* @param {jmGraph} [params.graph] 所属的画布对象
|
|
3773
|
-
*/
|
|
3774
|
-
var jmLayer = /*#__PURE__*/function (_jmControl) {
|
|
3775
|
-
_inherits(jmLayer, _jmControl);
|
|
3776
|
-
|
|
3777
|
-
var _super = _createSuper(jmLayer);
|
|
3778
|
-
|
|
3779
|
-
function jmLayer(params) {
|
|
3780
|
-
var _this;
|
|
3781
|
-
|
|
3782
|
-
var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'jmLayer';
|
|
3783
|
-
|
|
3784
|
-
_classCallCheck(this, jmLayer);
|
|
3785
|
-
|
|
3786
|
-
params = params || {};
|
|
3787
|
-
params.interactive = false; // 图层本身不响应交互事件
|
|
3788
|
-
|
|
3789
|
-
_this = _super.call(this, params, t);
|
|
3790
|
-
_this.name = params.name || "Layer_".concat(Date.now());
|
|
3791
|
-
_this.visible = params.visible !== false;
|
|
3792
|
-
_this.locked = params.locked || false;
|
|
3793
|
-
return _this;
|
|
3794
|
-
}
|
|
3795
|
-
/**
|
|
3796
|
-
* 图层名称
|
|
3797
|
-
* 图层的唯一标识符,用于查找和管理图层
|
|
3798
|
-
*
|
|
3799
|
-
* @property name
|
|
3800
|
-
* @type {string}
|
|
3801
|
-
*/
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
_createClass(jmLayer, [{
|
|
3805
|
-
key: "name",
|
|
3806
|
-
get: function get() {
|
|
3807
|
-
return this.property('name');
|
|
3808
|
-
},
|
|
3809
|
-
set: function set(v) {
|
|
3810
|
-
if (!v || typeof v !== 'string') {
|
|
3811
|
-
console.warn('jmLayer: name must be a non-empty string');
|
|
3812
|
-
return;
|
|
3813
|
-
}
|
|
3814
|
-
|
|
3815
|
-
return this.property('name', v);
|
|
3816
|
-
}
|
|
3817
|
-
/**
|
|
3818
|
-
* 图层是否可见
|
|
3819
|
-
* 不可见的图层不会被渲染,但仍然存在于图层列表中
|
|
3820
|
-
*
|
|
3821
|
-
* @property visible
|
|
3822
|
-
* @type {boolean}
|
|
3823
|
-
*/
|
|
3824
|
-
|
|
3825
|
-
}, {
|
|
3826
|
-
key: "visible",
|
|
3827
|
-
get: function get() {
|
|
3828
|
-
return this.property('visible');
|
|
3829
|
-
},
|
|
3830
|
-
set: function set(v) {
|
|
3831
|
-
this.needUpdate = true;
|
|
3832
|
-
return this.property('visible', v);
|
|
3833
|
-
}
|
|
3834
|
-
/**
|
|
3835
|
-
* 图层是否锁定
|
|
3836
|
-
* 锁定的图层中的图形不可被选中或移动,但仍然可见
|
|
3837
|
-
* 适用于背景图层或参考图层
|
|
3838
|
-
*
|
|
3839
|
-
* @property locked
|
|
3840
|
-
* @type {boolean}
|
|
3841
|
-
*/
|
|
3842
|
-
|
|
3843
|
-
}, {
|
|
3844
|
-
key: "locked",
|
|
3845
|
-
get: function get() {
|
|
3846
|
-
return this.property('locked');
|
|
3847
|
-
},
|
|
3848
|
-
set: function set(v) {
|
|
3849
|
-
return this.property('locked', v);
|
|
3850
|
-
}
|
|
3851
|
-
/**
|
|
3852
|
-
* 绘制图层
|
|
3853
|
-
* 只有可见的图层才会被绘制
|
|
3854
|
-
*
|
|
3855
|
-
* @method paint
|
|
3856
|
-
* @param {boolean} v 是否需要重绘
|
|
3857
|
-
*/
|
|
3858
|
-
|
|
3859
|
-
}, {
|
|
3860
|
-
key: "paint",
|
|
3861
|
-
value: function paint(v) {
|
|
3862
|
-
if (this.visible !== false) {
|
|
3863
|
-
_get(_getPrototypeOf(jmLayer.prototype), "paint", this).call(this, v);
|
|
3864
|
-
}
|
|
3865
|
-
}
|
|
3866
|
-
/**
|
|
3867
|
-
* 检查点是否在图层内
|
|
3868
|
-
* 锁定的图层不会响应鼠标事件
|
|
3869
|
-
*
|
|
3870
|
-
* @method checkPoint
|
|
3871
|
-
* @param {object} p 坐标点 {x, y}
|
|
3872
|
-
* @param {number} [pad] padding,额外的检测范围
|
|
3873
|
-
* @return {boolean} 是否在图层内
|
|
3874
|
-
*/
|
|
3875
|
-
|
|
3876
|
-
}, {
|
|
3877
|
-
key: "checkPoint",
|
|
3878
|
-
value: function checkPoint(p, pad) {
|
|
3879
|
-
// 锁定的图层不响应交互
|
|
3880
|
-
if (this.locked) return false;
|
|
3881
|
-
return _get(_getPrototypeOf(jmLayer.prototype), "checkPoint", this).call(this, p, pad);
|
|
3882
|
-
}
|
|
3883
|
-
/**
|
|
3884
|
-
* 清空图层
|
|
3885
|
-
* 移除图层中的所有图形对象
|
|
3886
|
-
*
|
|
3887
|
-
* @method clear
|
|
3888
|
-
*/
|
|
3889
|
-
|
|
3890
|
-
}, {
|
|
3891
|
-
key: "clear",
|
|
3892
|
-
value: function clear() {
|
|
3893
|
-
this.children.clear();
|
|
3894
|
-
this.needUpdate = true;
|
|
3895
|
-
}
|
|
3896
|
-
/**
|
|
3897
|
-
* 获取图层中的图形数量
|
|
3898
|
-
*
|
|
3899
|
-
* @method getShapeCount
|
|
3900
|
-
* @return {number} 图形数量
|
|
3901
|
-
*/
|
|
3902
|
-
|
|
3903
|
-
}, {
|
|
3904
|
-
key: "getShapeCount",
|
|
3905
|
-
value: function getShapeCount() {
|
|
3906
|
-
return this.children.length;
|
|
3907
|
-
}
|
|
3908
|
-
/**
|
|
3909
|
-
* 获取图层信息
|
|
3910
|
-
* 返回图层的基本信息,用于调试和日志
|
|
3911
|
-
*
|
|
3912
|
-
* @method getInfo
|
|
3913
|
-
* @return {object} 图层信息对象
|
|
3914
|
-
*/
|
|
3915
|
-
|
|
3916
|
-
}, {
|
|
3917
|
-
key: "getInfo",
|
|
3918
|
-
value: function getInfo() {
|
|
3919
|
-
return {
|
|
3920
|
-
name: this.name,
|
|
3921
|
-
visible: this.visible,
|
|
3922
|
-
locked: this.locked,
|
|
3923
|
-
shapeCount: this.getShapeCount()
|
|
3924
|
-
};
|
|
3925
|
-
}
|
|
3926
|
-
}]);
|
|
3927
|
-
|
|
3928
|
-
return jmLayer;
|
|
3929
|
-
}(_jmControl2.jmControl);
|
|
3930
|
-
|
|
3931
|
-
exports.jmLayer = exports["default"] = jmLayer;
|
|
3932
|
-
|
|
3933
|
-
},{"./jmControl.js":2}],7:[function(require,module,exports){
|
|
3844
|
+
},{"./jmControl.js":2,"./jmEvents.js":3,"./jmFilter.js":4,"./jmGradient.js":5,"./jmList.js":7,"./jmPath.js":9,"./jmProperty.js":10,"./jmShadow.js":11,"./jmUtils.js":12}],7:[function(require,module,exports){
|
|
3934
3845
|
"use strict";
|
|
3935
3846
|
|
|
3936
3847
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -4576,6 +4487,12 @@ exports.jmUtils = exports["default"] = void 0;
|
|
|
4576
4487
|
|
|
4577
4488
|
var _jmList = require("./jmList.js");
|
|
4578
4489
|
|
|
4490
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
4491
|
+
|
|
4492
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4493
|
+
|
|
4494
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
4495
|
+
|
|
4579
4496
|
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4580
4497
|
|
|
4581
4498
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -4759,68 +4676,89 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
4759
4676
|
var deep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
4760
4677
|
var copyHandler = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
4761
4678
|
var deepIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
4679
|
+
var cloned = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
|
|
4762
4680
|
|
|
4763
4681
|
// 如果有指定回调,则用回调处理,否则走后面的复制逻辑
|
|
4764
4682
|
if (typeof copyHandler === 'function') {
|
|
4765
4683
|
var obj = copyHandler(source, deep, deepIndex);
|
|
4766
4684
|
if (obj) return obj;
|
|
4767
|
-
}
|
|
4685
|
+
} // 首次调用时初始化克隆映射表(用于处理循环引用)
|
|
4686
|
+
|
|
4768
4687
|
|
|
4769
|
-
|
|
4688
|
+
if (!cloned) cloned = new WeakMap();
|
|
4770
4689
|
|
|
4771
4690
|
if (typeof target === 'boolean') {
|
|
4772
4691
|
deep = target;
|
|
4773
4692
|
target = undefined;
|
|
4774
|
-
} //
|
|
4693
|
+
} // 非对象直接返回
|
|
4775
4694
|
|
|
4776
4695
|
|
|
4777
|
-
if (
|
|
4778
|
-
return target;
|
|
4779
|
-
}
|
|
4696
|
+
if (!source || _typeof(source) !== 'object') {
|
|
4697
|
+
return typeof target !== 'undefined' ? target : source;
|
|
4698
|
+
} // 如果source已经被克隆过,直接返回之前的克隆对象,打破循环引用
|
|
4699
|
+
|
|
4780
4700
|
|
|
4781
|
-
if (source
|
|
4782
|
-
target = target || {}; //如果为当前泛型,则直接new
|
|
4701
|
+
if (cloned.has(source)) return cloned.get(source); // 数组处理
|
|
4783
4702
|
|
|
4703
|
+
if (Array.isArray(source)) {
|
|
4704
|
+
//如果为当前泛型,则直接new
|
|
4784
4705
|
if (this.isType(source, _jmList.jmList)) {
|
|
4785
4706
|
return new _jmList.jmList(source);
|
|
4786
|
-
}
|
|
4787
|
-
//如果是深度复,则拷贝每个对象
|
|
4788
|
-
if (deep) {
|
|
4789
|
-
var dest = [];
|
|
4707
|
+
}
|
|
4790
4708
|
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4709
|
+
if (deep) {
|
|
4710
|
+
var dest = [];
|
|
4711
|
+
cloned.set(source, dest);
|
|
4794
4712
|
|
|
4795
|
-
|
|
4713
|
+
for (var i = 0; i < source.length; i++) {
|
|
4714
|
+
dest.push(this.clone(source[i], undefined, deep, copyHandler, deepIndex + 1, cloned));
|
|
4796
4715
|
}
|
|
4797
4716
|
|
|
4798
|
-
return
|
|
4717
|
+
return dest;
|
|
4799
4718
|
}
|
|
4800
4719
|
|
|
4801
|
-
|
|
4720
|
+
return source.slice(0);
|
|
4721
|
+
} // 不复制页面元素和class对象(如jmControl实例等复杂对象保持引用)
|
|
4722
|
+
|
|
4723
|
+
|
|
4724
|
+
if (source.tagName || source.getContext || source.emit) {
|
|
4725
|
+
return source;
|
|
4726
|
+
} // 普通对象处理
|
|
4727
|
+
|
|
4728
|
+
|
|
4729
|
+
target = target || {};
|
|
4730
|
+
cloned.set(source, target); // 保持原型链一致
|
|
4731
|
+
|
|
4732
|
+
if (source.__proto__) target.__proto__ = source.__proto__; // 遍历自身可枚举属性(字符串键 + Symbol键),避免触发原型链上宿主对象的getter
|
|
4802
4733
|
|
|
4803
|
-
|
|
4734
|
+
var keys = Object.keys(source).concat(Object.getOwnPropertySymbols(source));
|
|
4735
|
+
|
|
4736
|
+
var _iterator = _createForOfIteratorHelper(keys),
|
|
4737
|
+
_step;
|
|
4738
|
+
|
|
4739
|
+
try {
|
|
4740
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
4741
|
+
var k = _step.value;
|
|
4804
4742
|
if (k === 'constructor') continue;
|
|
4805
4743
|
var v = source[k]; // 不复制页面元素和class对象
|
|
4806
4744
|
|
|
4807
|
-
if (v && (v.tagName || v.getContext)) {
|
|
4745
|
+
if (v && (v.tagName || v.getContext || v.emit)) {
|
|
4808
4746
|
target[k] = v;
|
|
4809
4747
|
continue;
|
|
4810
4748
|
} // 如果不是对象和空,则采用target的属性
|
|
4811
4749
|
|
|
4812
4750
|
|
|
4813
4751
|
if (_typeof(target[k]) === 'object' || typeof target[k] === 'undefined') {
|
|
4814
|
-
target[k] = this.clone(v, target[k], deep, copyHandler, deepIndex);
|
|
4752
|
+
target[k] = this.clone(v, target[k], deep, copyHandler, deepIndex + 1, cloned);
|
|
4815
4753
|
}
|
|
4816
4754
|
}
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
}
|
|
4820
|
-
|
|
4755
|
+
} catch (err) {
|
|
4756
|
+
_iterator.e(err);
|
|
4757
|
+
} finally {
|
|
4758
|
+
_iterator.f();
|
|
4821
4759
|
}
|
|
4822
4760
|
|
|
4823
|
-
return
|
|
4761
|
+
return target;
|
|
4824
4762
|
}
|
|
4825
4763
|
/**
|
|
4826
4764
|
* 绑定事件到html对象
|
|
@@ -6501,7 +6439,6 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
6501
6439
|
}, {
|
|
6502
6440
|
key: "createProgram",
|
|
6503
6441
|
value: function createProgram(vertexSrc, fragmentSrc) {
|
|
6504
|
-
this.context.lineWidth(1);
|
|
6505
6442
|
return (0, _program.createProgram)(this.context, vertexSrc, fragmentSrc);
|
|
6506
6443
|
} // 指定使用某个程序
|
|
6507
6444
|
|
|
@@ -6635,8 +6572,10 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
6635
6572
|
}, {
|
|
6636
6573
|
key: "earCutPointsToTriangles",
|
|
6637
6574
|
value: function earCutPointsToTriangles(points) {
|
|
6638
|
-
this.earCutCache = this.earCutCache || (this.earCutCache = {});
|
|
6639
|
-
|
|
6575
|
+
this.earCutCache = this.earCutCache || (this.earCutCache = {}); // 快速缓存 key:用长度和首尾点坐标
|
|
6576
|
+
|
|
6577
|
+
var len = points.length;
|
|
6578
|
+
var key = len + '_' + points[0].x + '_' + points[0].y + '_' + points[len - 1].x + '_' + points[len - 1].y;
|
|
6640
6579
|
if (this.earCutCache[key]) return this.earCutCache[key];
|
|
6641
6580
|
var ps = this.earCutPoints(points); // 切割得到3角色顶点索引,
|
|
6642
6581
|
|
|
@@ -6745,43 +6684,22 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
6745
6684
|
if (!canvas) {
|
|
6746
6685
|
return fillStyle;
|
|
6747
6686
|
}
|
|
6748
|
-
|
|
6749
|
-
canvas.width = bounds.width;
|
|
6750
|
-
canvas.height = bounds.height;
|
|
6751
|
-
|
|
6752
|
-
if (!canvas.width || !canvas.height) {
|
|
6753
|
-
return fillStyle;
|
|
6754
|
-
}
|
|
6755
|
-
|
|
6756
|
-
this.textureContext.clearRect(0, 0, canvas.width, canvas.height);
|
|
6757
|
-
this.textureContext.fillStyle = fillStyle;
|
|
6758
|
-
this.textureContext.beginPath();
|
|
6759
|
-
|
|
6760
|
-
if (!points || !points.length) {
|
|
6761
|
-
points = [];
|
|
6762
|
-
points.push({
|
|
6763
|
-
x: bounds.left,
|
|
6764
|
-
y: bounds.top
|
|
6765
|
-
});
|
|
6766
|
-
points.push({
|
|
6767
|
-
x: bounds.left + bounds.width,
|
|
6768
|
-
y: bounds.top
|
|
6769
|
-
});
|
|
6770
|
-
points.push({
|
|
6771
|
-
x: bounds.left + bounds.width,
|
|
6772
|
-
y: bounds.top + bounds.height
|
|
6773
|
-
});
|
|
6774
|
-
points.push({
|
|
6775
|
-
x: bounds.left,
|
|
6776
|
-
y: bounds.top + bounds.height
|
|
6777
|
-
});
|
|
6778
|
-
points.push({
|
|
6779
|
-
x: bounds.left,
|
|
6780
|
-
y: bounds.top
|
|
6781
|
-
});
|
|
6687
|
+
|
|
6688
|
+
canvas.width = bounds.width;
|
|
6689
|
+
canvas.height = bounds.height;
|
|
6690
|
+
|
|
6691
|
+
if (!canvas.width || !canvas.height) {
|
|
6692
|
+
return fillStyle;
|
|
6782
6693
|
}
|
|
6783
6694
|
|
|
6784
|
-
|
|
6695
|
+
this.textureContext.clearRect(0, 0, canvas.width, canvas.height);
|
|
6696
|
+
this.textureContext.fillStyle = fillStyle; // 规则图形用 fillRect,比 beginPath/lineTo/fill 快
|
|
6697
|
+
|
|
6698
|
+
if (!points || !points.length) {
|
|
6699
|
+
this.textureContext.fillRect(0, 0, bounds.width, bounds.height);
|
|
6700
|
+
} else {
|
|
6701
|
+
this.textureContext.beginPath();
|
|
6702
|
+
|
|
6785
6703
|
var _iterator = _createForOfIteratorHelper(points),
|
|
6786
6704
|
_step;
|
|
6787
6705
|
|
|
@@ -6801,16 +6719,11 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
6801
6719
|
} finally {
|
|
6802
6720
|
_iterator.f();
|
|
6803
6721
|
}
|
|
6804
|
-
|
|
6805
|
-
this.textureContext.
|
|
6806
|
-
this.textureContext.
|
|
6807
|
-
this.textureContext.lineTo(bounds.width, bounds.height);
|
|
6808
|
-
this.textureContext.lineTo(0, bounds.height);
|
|
6809
|
-
this.textureContext.lineTo(0, 0);
|
|
6722
|
+
|
|
6723
|
+
this.textureContext.closePath();
|
|
6724
|
+
this.textureContext.fill();
|
|
6810
6725
|
}
|
|
6811
6726
|
|
|
6812
|
-
this.textureContext.closePath();
|
|
6813
|
-
this.textureContext.fill();
|
|
6814
6727
|
var data = this.textureContext.getImageData(0, 0, canvas.width, canvas.height);
|
|
6815
6728
|
return {
|
|
6816
6729
|
data: data,
|
|
@@ -7263,9 +7176,13 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7263
7176
|
key: "toImageData",
|
|
7264
7177
|
value: function toImageData(control, bounds) {
|
|
7265
7178
|
var points = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
7179
|
+
// 缓存基于渐变参数(不含 bounds,因为同一个渐变只是位置不同时纹理相同)
|
|
7180
|
+
var gradientKey = this.toString();
|
|
7181
|
+
|
|
7182
|
+
if (this.__cachedData && this.__cacheKey === gradientKey && this.__cachedData.data && this.__cachedData.data.width === Math.ceil(bounds.width) && this.__cachedData.data.data && this.__cachedData.data.data.height === Math.ceil(bounds.height)) {
|
|
7183
|
+
return this.__cachedData;
|
|
7184
|
+
}
|
|
7266
7185
|
|
|
7267
|
-
//const key = this.key || this.toString();
|
|
7268
|
-
//if(WebglGradientTextureCache[key]) return WebglGradientTextureCache[key];
|
|
7269
7186
|
if (!control.textureContext) {
|
|
7270
7187
|
return null;
|
|
7271
7188
|
}
|
|
@@ -7282,9 +7199,17 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7282
7199
|
var c = control.graph.utils.toColor(s.color);
|
|
7283
7200
|
gradient && gradient.addColorStop(s.offset, c);
|
|
7284
7201
|
});
|
|
7285
|
-
var data = control.toFillTexture(gradient, bounds, points);
|
|
7286
|
-
|
|
7202
|
+
var data = control.toFillTexture(gradient, bounds, points);
|
|
7203
|
+
this.__cachedData = data;
|
|
7204
|
+
this.__cacheKey = gradientKey;
|
|
7287
7205
|
return data;
|
|
7206
|
+
} // 当渐变参数变化时使缓存失效
|
|
7207
|
+
|
|
7208
|
+
}, {
|
|
7209
|
+
key: "invalidateCache",
|
|
7210
|
+
value: function invalidateCache() {
|
|
7211
|
+
this.__cachedData = null;
|
|
7212
|
+
this.__cacheKey = null;
|
|
7288
7213
|
} // 根据绘制图形的坐标计算出对应点的颜色
|
|
7289
7214
|
|
|
7290
7215
|
/*
|
|
@@ -7408,7 +7333,15 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
|
|
|
7408
7333
|
|
|
7409
7334
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7410
7335
|
|
|
7411
|
-
function
|
|
7336
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
7337
|
+
|
|
7338
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7339
|
+
|
|
7340
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
7341
|
+
|
|
7342
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7343
|
+
|
|
7344
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
7412
7345
|
|
|
7413
7346
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
7414
7347
|
|
|
@@ -7454,12 +7387,66 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
7454
7387
|
_this.isRegular = option.isRegular || false;
|
|
7455
7388
|
_this.needCut = option.needCut || false;
|
|
7456
7389
|
_this.control = option.control;
|
|
7457
|
-
_this.points = [];
|
|
7390
|
+
_this.points = []; // 缓存 buffer 和纹理,避免每帧创建/销毁
|
|
7391
|
+
|
|
7392
|
+
_this.__cachedBuffers = [];
|
|
7393
|
+
_this.__cachedTexture = null;
|
|
7394
|
+
_this.__cachedTextureKey = null;
|
|
7458
7395
|
return _this;
|
|
7459
|
-
} //
|
|
7396
|
+
} // 释放缓存的 WebGL 资源
|
|
7460
7397
|
|
|
7461
7398
|
|
|
7462
7399
|
_createClass(WebglPath, [{
|
|
7400
|
+
key: "dispose",
|
|
7401
|
+
value: function dispose() {
|
|
7402
|
+
var _iterator = _createForOfIteratorHelper(this.__cachedBuffers),
|
|
7403
|
+
_step;
|
|
7404
|
+
|
|
7405
|
+
try {
|
|
7406
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
7407
|
+
var buf = _step.value;
|
|
7408
|
+
this.deleteBuffer(buf);
|
|
7409
|
+
}
|
|
7410
|
+
} catch (err) {
|
|
7411
|
+
_iterator.e(err);
|
|
7412
|
+
} finally {
|
|
7413
|
+
_iterator.f();
|
|
7414
|
+
}
|
|
7415
|
+
|
|
7416
|
+
this.__cachedBuffers = [];
|
|
7417
|
+
|
|
7418
|
+
if (this.__cachedTexture) {
|
|
7419
|
+
this.deleteTexture(this.__cachedTexture);
|
|
7420
|
+
this.__cachedTexture = null;
|
|
7421
|
+
this.__cachedTextureKey = null;
|
|
7422
|
+
}
|
|
7423
|
+
} // 获取或创建 buffer,优先复用缓存
|
|
7424
|
+
|
|
7425
|
+
}, {
|
|
7426
|
+
key: "getOrCreateBuffer",
|
|
7427
|
+
value: function getOrCreateBuffer(data, attr) {
|
|
7428
|
+
var buffer = this.__cachedBuffers.find(function (b) {
|
|
7429
|
+
return b.attr === attr;
|
|
7430
|
+
});
|
|
7431
|
+
|
|
7432
|
+
if (buffer) {
|
|
7433
|
+
var gl = this.context;
|
|
7434
|
+
var float32 = new Float32Array(data);
|
|
7435
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
|
|
7436
|
+
gl.bufferData(gl.ARRAY_BUFFER, float32, gl.DYNAMIC_DRAW);
|
|
7437
|
+
buffer.data = data;
|
|
7438
|
+
return buffer;
|
|
7439
|
+
}
|
|
7440
|
+
|
|
7441
|
+
buffer = this.createFloat32Buffer(data);
|
|
7442
|
+
buffer.attr = attr;
|
|
7443
|
+
|
|
7444
|
+
this.__cachedBuffers.push(buffer);
|
|
7445
|
+
|
|
7446
|
+
return buffer;
|
|
7447
|
+
} // 应用变换到点
|
|
7448
|
+
|
|
7449
|
+
}, {
|
|
7463
7450
|
key: "applyTransform",
|
|
7464
7451
|
value: function applyTransform(point) {
|
|
7465
7452
|
return _get(_getPrototypeOf(WebglPath.prototype), "applyTransform", this).call(this, point);
|
|
@@ -7485,20 +7472,20 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
7485
7472
|
|
|
7486
7473
|
var colorData = [];
|
|
7487
7474
|
|
|
7488
|
-
var
|
|
7489
|
-
|
|
7475
|
+
var _iterator2 = _createForOfIteratorHelper(color),
|
|
7476
|
+
_step2;
|
|
7490
7477
|
|
|
7491
7478
|
try {
|
|
7492
|
-
for (
|
|
7493
|
-
var c =
|
|
7479
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
7480
|
+
var c = _step2.value;
|
|
7494
7481
|
c = this.convertColor(c);
|
|
7495
7482
|
if (typeof c.a === 'undefined') c.a = 1;
|
|
7496
7483
|
colorData.push(c.r, c.g, c.b, c.a * this.style.globalAlpha);
|
|
7497
7484
|
}
|
|
7498
7485
|
} catch (err) {
|
|
7499
|
-
|
|
7486
|
+
_iterator2.e(err);
|
|
7500
7487
|
} finally {
|
|
7501
|
-
|
|
7488
|
+
_iterator2.f();
|
|
7502
7489
|
}
|
|
7503
7490
|
|
|
7504
7491
|
var colorBuffer = this.createFloat32Buffer(colorData);
|
|
@@ -7524,7 +7511,7 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
7524
7511
|
key: "endDraw",
|
|
7525
7512
|
value: function endDraw() {
|
|
7526
7513
|
if (this.points) delete this.points;
|
|
7527
|
-
if (this.pathPoints) delete this.pathPoints;
|
|
7514
|
+
if (this.pathPoints) delete this.pathPoints; // 缓存的纹理保留到下次绘制(渐变可能不变)
|
|
7528
7515
|
} // 图形封闭
|
|
7529
7516
|
|
|
7530
7517
|
}, {
|
|
@@ -7535,7 +7522,7 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
7535
7522
|
var end = this.points[this.points.length - 1];
|
|
7536
7523
|
if (start != end && !(start.x === end.x && start.y === end.y)) this.points.push(start);
|
|
7537
7524
|
}
|
|
7538
|
-
} //
|
|
7525
|
+
} // 绘制点数组(使用 DYNAMIC_DRAW 复用 buffer,避免每帧 create/delete)
|
|
7539
7526
|
|
|
7540
7527
|
}, {
|
|
7541
7528
|
key: "writePoints",
|
|
@@ -7543,25 +7530,64 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
7543
7530
|
var attr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.program.attrs.a_position;
|
|
7544
7531
|
var fixedPoints = [];
|
|
7545
7532
|
|
|
7546
|
-
var
|
|
7547
|
-
|
|
7533
|
+
var _this$transformMatrix = _slicedToArray(this.transformMatrix, 6),
|
|
7534
|
+
a = _this$transformMatrix[0],
|
|
7535
|
+
b = _this$transformMatrix[1],
|
|
7536
|
+
c = _this$transformMatrix[2],
|
|
7537
|
+
d = _this$transformMatrix[3],
|
|
7538
|
+
tx = _this$transformMatrix[4],
|
|
7539
|
+
ty = _this$transformMatrix[5];
|
|
7548
7540
|
|
|
7549
|
-
|
|
7550
|
-
|
|
7551
|
-
|
|
7552
|
-
|
|
7553
|
-
|
|
7554
|
-
|
|
7541
|
+
var isIdentity = a === 1 && b === 0 && c === 0 && d === 1 && tx === 0 && ty === 0;
|
|
7542
|
+
var offsetLeft = this.parentAbsoluteBounds.left;
|
|
7543
|
+
var offsetTop = this.parentAbsoluteBounds.top;
|
|
7544
|
+
|
|
7545
|
+
if (isIdentity) {
|
|
7546
|
+
// 单位矩阵时直接加偏移,避免逐点调用 applyTransform
|
|
7547
|
+
for (var i = 0; i < points.length; i++) {
|
|
7548
|
+
fixedPoints.push(points[i].x + offsetLeft, points[i].y + offsetTop);
|
|
7549
|
+
}
|
|
7550
|
+
} else {
|
|
7551
|
+
var _iterator3 = _createForOfIteratorHelper(points),
|
|
7552
|
+
_step3;
|
|
7553
|
+
|
|
7554
|
+
try {
|
|
7555
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
7556
|
+
var p = _step3.value;
|
|
7557
|
+
var transformedPoint = this.applyTransform(p);
|
|
7558
|
+
fixedPoints.push(transformedPoint.x + offsetLeft, transformedPoint.y + offsetTop);
|
|
7559
|
+
}
|
|
7560
|
+
} catch (err) {
|
|
7561
|
+
_iterator3.e(err);
|
|
7562
|
+
} finally {
|
|
7563
|
+
_iterator3.f();
|
|
7564
|
+
}
|
|
7565
|
+
}
|
|
7566
|
+
|
|
7567
|
+
var float32 = new Float32Array(fixedPoints);
|
|
7568
|
+
var gl = this.context; // 复用已有 buffer 或创建新的
|
|
7569
|
+
|
|
7570
|
+
if (this.__cachedBuffers.length > 0) {
|
|
7571
|
+
// 找一个同 attr 的 buffer 复用
|
|
7572
|
+
var buffer = this.__cachedBuffers.find(function (b) {
|
|
7573
|
+
return b.attr === attr;
|
|
7574
|
+
});
|
|
7575
|
+
|
|
7576
|
+
if (buffer) {
|
|
7577
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
|
|
7578
|
+
gl.bufferData(gl.ARRAY_BUFFER, float32, gl.DYNAMIC_DRAW);
|
|
7579
|
+
buffer.data = fixedPoints;
|
|
7580
|
+
this.writeVertexAttrib(buffer, attr, 2, 0, 0);
|
|
7581
|
+
return buffer;
|
|
7555
7582
|
}
|
|
7556
|
-
} catch (err) {
|
|
7557
|
-
_iterator2.e(err);
|
|
7558
|
-
} finally {
|
|
7559
|
-
_iterator2.f();
|
|
7560
7583
|
}
|
|
7561
7584
|
|
|
7562
|
-
var vertexBuffer = this.createFloat32Buffer(
|
|
7585
|
+
var vertexBuffer = this.createFloat32Buffer(float32, gl.ARRAY_BUFFER, gl.DYNAMIC_DRAW);
|
|
7563
7586
|
this.writeVertexAttrib(vertexBuffer, attr, 2, 0, 0);
|
|
7564
7587
|
vertexBuffer.attr = attr;
|
|
7588
|
+
|
|
7589
|
+
this.__cachedBuffers.push(vertexBuffer);
|
|
7590
|
+
|
|
7565
7591
|
return vertexBuffer;
|
|
7566
7592
|
} // 连接二个点
|
|
7567
7593
|
|
|
@@ -7874,27 +7900,29 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
7874
7900
|
}, {
|
|
7875
7901
|
key: "getTriangles",
|
|
7876
7902
|
value: function getTriangles(points) {
|
|
7877
|
-
this.trianglesCache = this.trianglesCache || (this.trianglesCache = {});
|
|
7878
|
-
|
|
7903
|
+
this.trianglesCache = this.trianglesCache || (this.trianglesCache = {}); // 快速缓存 key:用长度和首尾点坐标(比 JSON.stringify 快几个数量级)
|
|
7904
|
+
|
|
7905
|
+
var len = points.length;
|
|
7906
|
+
var key = len + '_' + points[0].x + '_' + points[0].y + '_' + points[len - 1].x + '_' + points[len - 1].y;
|
|
7879
7907
|
if (this.trianglesCache[key]) return this.trianglesCache[key];
|
|
7880
7908
|
var res = [];
|
|
7881
7909
|
var polygons = this.getPolygon(points);
|
|
7882
7910
|
|
|
7883
7911
|
if (polygons.length) {
|
|
7884
|
-
var
|
|
7885
|
-
|
|
7912
|
+
var _iterator4 = _createForOfIteratorHelper(polygons),
|
|
7913
|
+
_step4;
|
|
7886
7914
|
|
|
7887
7915
|
try {
|
|
7888
|
-
for (
|
|
7889
|
-
var polygon =
|
|
7916
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
7917
|
+
var polygon = _step4.value;
|
|
7890
7918
|
// 需要分割三角形,不然填充会有问题
|
|
7891
7919
|
var triangles = this.earCutPointsToTriangles(polygon);
|
|
7892
7920
|
res.push.apply(res, _toConsumableArray(triangles));
|
|
7893
7921
|
}
|
|
7894
7922
|
} catch (err) {
|
|
7895
|
-
|
|
7923
|
+
_iterator4.e(err);
|
|
7896
7924
|
} finally {
|
|
7897
|
-
|
|
7925
|
+
_iterator4.f();
|
|
7898
7926
|
}
|
|
7899
7927
|
}
|
|
7900
7928
|
|
|
@@ -7931,12 +7959,10 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
7931
7959
|
var regular = lineWidth <= 1.2;
|
|
7932
7960
|
points = regular ? points : this.pathToPoints(points);
|
|
7933
7961
|
var buffer = this.writePoints(points);
|
|
7934
|
-
this.context.drawArrays(regular ? this.context.LINE_LOOP : this.context.POINTS, 0, points.length);
|
|
7935
|
-
this.deleteBuffer(buffer);
|
|
7962
|
+
this.context.drawArrays(regular ? this.context.LINE_LOOP : this.context.POINTS, 0, points.length); // buffer 由 endDraw 统一清理
|
|
7936
7963
|
}
|
|
7937
7964
|
|
|
7938
|
-
colorBuffer && this.
|
|
7939
|
-
colorBuffer && this.disableVertexAttribArray(colorBuffer.attr);
|
|
7965
|
+
colorBuffer && this.disableVertexAttribArray(colorBuffer && colorBuffer.attr);
|
|
7940
7966
|
} // 填充图形
|
|
7941
7967
|
|
|
7942
7968
|
}, {
|
|
@@ -7976,8 +8002,7 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
7976
8002
|
this.context.uniform1i(this.program.uniforms.a_type.location, type);
|
|
7977
8003
|
var colorBuffer = this.setFragColor(color);
|
|
7978
8004
|
this.fillPolygons(points);
|
|
7979
|
-
colorBuffer && this.
|
|
7980
|
-
colorBuffer && this.disableVertexAttribArray(colorBuffer.attr);
|
|
8005
|
+
colorBuffer && this.disableVertexAttribArray(colorBuffer && colorBuffer.attr);
|
|
7981
8006
|
} // 区域填充图片
|
|
7982
8007
|
// points绘制的图形顶点
|
|
7983
8008
|
// 图片整体绘制区域
|
|
@@ -7985,16 +8010,39 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
7985
8010
|
}, {
|
|
7986
8011
|
key: "fillImage",
|
|
7987
8012
|
value: function fillImage(img, points, bounds) {
|
|
7988
|
-
if (!img) return; //
|
|
8013
|
+
if (!img) return; // 对于 ImageData,生成缓存 key(基于渐变参数或 bounds),复用纹理
|
|
8014
|
+
|
|
8015
|
+
var texture = null;
|
|
8016
|
+
|
|
8017
|
+
if (img instanceof ImageData) {
|
|
8018
|
+
var key = "".concat(img.width, "_").concat(img.height, "_").concat(bounds.width, "_").concat(bounds.height, "_").concat(bounds.left, "_").concat(bounds.top);
|
|
8019
|
+
|
|
8020
|
+
if (this.__cachedTexture && this.__cachedTextureKey === key) {
|
|
8021
|
+
texture = this.__cachedTexture;
|
|
8022
|
+
} else {
|
|
8023
|
+
texture = this.createDataTexture(img); // 释放旧纹理
|
|
8024
|
+
|
|
8025
|
+
if (this.__cachedTexture) {
|
|
8026
|
+
this.deleteTexture(this.__cachedTexture);
|
|
8027
|
+
}
|
|
8028
|
+
|
|
8029
|
+
this.__cachedTexture = texture;
|
|
8030
|
+
this.__cachedTextureKey = key;
|
|
8031
|
+
}
|
|
8032
|
+
} else {
|
|
8033
|
+
texture = this.createImgTexture(img);
|
|
8034
|
+
}
|
|
7989
8035
|
|
|
7990
|
-
var texture = img instanceof ImageData ? this.createDataTexture(img) : this.createImgTexture(img);
|
|
7991
8036
|
this.context.uniform1i(this.program.uniforms.u_sample.location, 0); // 纹理单元传递给着色器
|
|
7992
8037
|
// 指定纹理区域尺寸
|
|
7993
8038
|
|
|
7994
8039
|
this.context.uniform4f(this.program.uniforms.v_texture_bounds.location, bounds.left + this.parentAbsoluteBounds.left, bounds.top + this.parentAbsoluteBounds.top, bounds.width, bounds.height); // 纹理单元传递给着色器
|
|
7995
8040
|
|
|
7996
|
-
this.fillTexture(points);
|
|
7997
|
-
|
|
8041
|
+
this.fillTexture(points); // 仅对非缓存纹理(非 ImageData)立即删除
|
|
8042
|
+
|
|
8043
|
+
if (!(img instanceof ImageData)) {
|
|
8044
|
+
this.deleteTexture(texture);
|
|
8045
|
+
}
|
|
7998
8046
|
}
|
|
7999
8047
|
}, {
|
|
8000
8048
|
key: "fillTexture",
|
|
@@ -8013,34 +8061,104 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
8013
8061
|
}, {
|
|
8014
8062
|
key: "fillPolygons",
|
|
8015
8063
|
value: function fillPolygons(points) {
|
|
8064
|
+
var _this2 = this;
|
|
8065
|
+
|
|
8016
8066
|
var isTexture = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
8017
8067
|
|
|
8018
|
-
if (points.length
|
|
8019
|
-
|
|
8068
|
+
if (points.length <= 3) {
|
|
8069
|
+
// 3个点以下的三角形直接画
|
|
8070
|
+
var buffer = this.writePoints(points);
|
|
8071
|
+
var coordBuffer = isTexture ? this.writePoints(points, this.program.attrs.a_text_coord) : null;
|
|
8072
|
+
this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
|
|
8073
|
+
return;
|
|
8074
|
+
} // 规则图形(凸多边形,如圆):直接用 TRIANGLE_FAN 一次性绘制,无需 earcut
|
|
8075
|
+
|
|
8076
|
+
|
|
8077
|
+
if (this.isRegular) {
|
|
8078
|
+
var _buffer = this.writePoints(points);
|
|
8020
8079
|
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8080
|
+
var _coordBuffer = isTexture ? this.writePoints(points, this.program.attrs.a_text_coord) : null;
|
|
8081
|
+
|
|
8082
|
+
this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
|
|
8083
|
+
return;
|
|
8084
|
+
} // 不规则图形:需要 earcut 三角化后,合并为一个大的顶点缓冲区,单次 drawArrays
|
|
8085
|
+
|
|
8086
|
+
|
|
8087
|
+
var triangles = this.needCut ? this.earCutPointsToTriangles(points) : this.getTriangles(points);
|
|
8088
|
+
if (!triangles.length) return; // 合并所有三角形的顶点到一个数组
|
|
8089
|
+
|
|
8090
|
+
var allVertices = [];
|
|
8091
|
+
var allTexCoords = [];
|
|
8092
|
+
|
|
8093
|
+
var _iterator5 = _createForOfIteratorHelper(triangles),
|
|
8094
|
+
_step5;
|
|
8095
|
+
|
|
8096
|
+
try {
|
|
8097
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
8098
|
+
var triangle = _step5.value;
|
|
8099
|
+
|
|
8100
|
+
var _iterator6 = _createForOfIteratorHelper(triangle),
|
|
8101
|
+
_step6;
|
|
8024
8102
|
|
|
8025
8103
|
try {
|
|
8026
|
-
for (
|
|
8027
|
-
var
|
|
8028
|
-
|
|
8104
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
8105
|
+
var p = _step6.value;
|
|
8106
|
+
allVertices.push(p.x, p.y);
|
|
8107
|
+
if (isTexture) allTexCoords.push(p.x, p.y);
|
|
8029
8108
|
}
|
|
8030
8109
|
} catch (err) {
|
|
8031
|
-
|
|
8110
|
+
_iterator6.e(err);
|
|
8032
8111
|
} finally {
|
|
8033
|
-
|
|
8112
|
+
_iterator6.f();
|
|
8034
8113
|
}
|
|
8035
|
-
}
|
|
8114
|
+
} // 一次性上传所有数据并绘制
|
|
8115
|
+
|
|
8116
|
+
} catch (err) {
|
|
8117
|
+
_iterator5.e(err);
|
|
8118
|
+
} finally {
|
|
8119
|
+
_iterator5.f();
|
|
8120
|
+
}
|
|
8121
|
+
|
|
8122
|
+
var vertexData = new Float32Array(allVertices);
|
|
8123
|
+
var gl = this.context; // 复用或创建 position buffer
|
|
8124
|
+
|
|
8125
|
+
var posBuffer = this.__cachedBuffers.find(function (b) {
|
|
8126
|
+
return b.attr === _this2.program.attrs.a_position;
|
|
8127
|
+
});
|
|
8128
|
+
|
|
8129
|
+
if (!posBuffer) {
|
|
8130
|
+
posBuffer = this.createFloat32Buffer(vertexData, gl.ARRAY_BUFFER, gl.DYNAMIC_DRAW);
|
|
8131
|
+
posBuffer.attr = this.program.attrs.a_position;
|
|
8132
|
+
|
|
8133
|
+
this.__cachedBuffers.push(posBuffer);
|
|
8036
8134
|
} else {
|
|
8037
|
-
|
|
8135
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, posBuffer.buffer);
|
|
8136
|
+
gl.bufferData(gl.ARRAY_BUFFER, vertexData, gl.DYNAMIC_DRAW);
|
|
8137
|
+
}
|
|
8038
8138
|
|
|
8039
|
-
|
|
8040
|
-
|
|
8041
|
-
|
|
8042
|
-
|
|
8139
|
+
this.writeVertexAttrib(posBuffer, this.program.attrs.a_position, 2, 0, 0);
|
|
8140
|
+
|
|
8141
|
+
if (isTexture && allTexCoords.length) {
|
|
8142
|
+
var texData = new Float32Array(allTexCoords);
|
|
8143
|
+
|
|
8144
|
+
var texBuffer = this.__cachedBuffers.find(function (b) {
|
|
8145
|
+
return b.attr === _this2.program.attrs.a_text_coord;
|
|
8146
|
+
});
|
|
8147
|
+
|
|
8148
|
+
if (!texBuffer) {
|
|
8149
|
+
texBuffer = this.createFloat32Buffer(texData, gl.ARRAY_BUFFER, gl.DYNAMIC_DRAW);
|
|
8150
|
+
texBuffer.attr = this.program.attrs.a_text_coord;
|
|
8151
|
+
|
|
8152
|
+
this.__cachedBuffers.push(texBuffer);
|
|
8153
|
+
} else {
|
|
8154
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, texBuffer.buffer);
|
|
8155
|
+
gl.bufferData(gl.ARRAY_BUFFER, texData, gl.DYNAMIC_DRAW);
|
|
8156
|
+
}
|
|
8157
|
+
|
|
8158
|
+
this.writeVertexAttrib(texBuffer, this.program.attrs.a_text_coord, 2, 0, 0);
|
|
8043
8159
|
}
|
|
8160
|
+
|
|
8161
|
+
gl.drawArrays(gl.TRIANGLES, 0, allVertices.length / 2);
|
|
8044
8162
|
} // 填充图形
|
|
8045
8163
|
|
|
8046
8164
|
}, {
|
|
@@ -9561,12 +9679,6 @@ exports.jmLabel = exports["default"] = void 0;
|
|
|
9561
9679
|
|
|
9562
9680
|
var _jmControl2 = require("../core/jmControl.js");
|
|
9563
9681
|
|
|
9564
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
9565
|
-
|
|
9566
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
9567
|
-
|
|
9568
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9569
|
-
|
|
9570
9682
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
9571
9683
|
|
|
9572
9684
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -9626,7 +9738,7 @@ var jmLabel = /*#__PURE__*/function (_jmControl) {
|
|
|
9626
9738
|
_this.style.textAlign = _this.style.textAlign || 'left'; //文字垂直对齐
|
|
9627
9739
|
|
|
9628
9740
|
_this.style.textBaseline = _this.style.textBaseline || 'middle';
|
|
9629
|
-
_this.text = params.text || '';
|
|
9741
|
+
_this.text = params.text || params.value || '';
|
|
9630
9742
|
_this.center = params.center || null;
|
|
9631
9743
|
return _this;
|
|
9632
9744
|
}
|
|
@@ -9959,68 +10071,6 @@ var jmLabel = /*#__PURE__*/function (_jmControl) {
|
|
|
9959
10071
|
this.context.strokeText(txt, x, y);
|
|
9960
10072
|
}
|
|
9961
10073
|
}
|
|
9962
|
-
} //如果有指定边框,则画出边框
|
|
9963
|
-
|
|
9964
|
-
|
|
9965
|
-
if (this.style.border) {
|
|
9966
|
-
//如果指定了边框样式
|
|
9967
|
-
if (this.style.border.style) {
|
|
9968
|
-
this.context.save && this.context.save();
|
|
9969
|
-
this.setStyle(this.style.border.style);
|
|
9970
|
-
}
|
|
9971
|
-
|
|
9972
|
-
if (this.mode === '2d') {
|
|
9973
|
-
this.context.moveTo(this.points[0].x + bounds.left, this.points[0].y + bounds.top);
|
|
9974
|
-
|
|
9975
|
-
if (this.style.border.top) {
|
|
9976
|
-
this.context.lineTo(this.points[1].x + bounds.left, this.points[1].y + bounds.top);
|
|
9977
|
-
}
|
|
9978
|
-
|
|
9979
|
-
if (this.style.border.right) {
|
|
9980
|
-
this.context.moveTo(this.points[1].x + bounds.left, this.points[1].y + bounds.top);
|
|
9981
|
-
this.context.lineTo(this.points[2].x + bounds.left, this.points[2].y + bounds.top);
|
|
9982
|
-
}
|
|
9983
|
-
|
|
9984
|
-
if (this.style.border.bottom) {
|
|
9985
|
-
this.context.moveTo(this.points[2].x + bounds.left, this.points[2].y + bounds.top);
|
|
9986
|
-
this.context.lineTo(this.points[3].x + bounds.left, this.points[3].y + bounds.top);
|
|
9987
|
-
}
|
|
9988
|
-
|
|
9989
|
-
if (this.style.border.left) {
|
|
9990
|
-
this.context.moveTo(this.points[3].x + bounds.left, this.points[3].y + bounds.top);
|
|
9991
|
-
this.context.lineTo(this.points[0].x + bounds.left, this.points[0].y + bounds.top);
|
|
9992
|
-
}
|
|
9993
|
-
} else {
|
|
9994
|
-
var points = [];
|
|
9995
|
-
|
|
9996
|
-
if (this.style.border.top) {
|
|
9997
|
-
points.push(this.points[0]);
|
|
9998
|
-
points.push(this.points[1]);
|
|
9999
|
-
}
|
|
10000
|
-
|
|
10001
|
-
if (this.style.border.right) {
|
|
10002
|
-
points.push(_objectSpread(_objectSpread({}, this.points[1]), {}, {
|
|
10003
|
-
m: true
|
|
10004
|
-
}));
|
|
10005
|
-
points.push(this.points[2]);
|
|
10006
|
-
}
|
|
10007
|
-
|
|
10008
|
-
if (this.style.border.bottom) {
|
|
10009
|
-
points.push(_objectSpread(_objectSpread({}, this.points[2]), {}, {
|
|
10010
|
-
m: true
|
|
10011
|
-
}));
|
|
10012
|
-
points.push(this.points[3]);
|
|
10013
|
-
}
|
|
10014
|
-
|
|
10015
|
-
if (this.style.border.left) {
|
|
10016
|
-
points.push(_objectSpread(_objectSpread({}, this.points[3]), {}, {
|
|
10017
|
-
m: true
|
|
10018
|
-
}));
|
|
10019
|
-
points.push(this.points[0]);
|
|
10020
|
-
}
|
|
10021
|
-
|
|
10022
|
-
points.length && this.webglControl && this.webglControl.stroke(points);
|
|
10023
|
-
}
|
|
10024
10074
|
}
|
|
10025
10075
|
}
|
|
10026
10076
|
}, {
|
|
@@ -10511,8 +10561,6 @@ exports.jmPrismatic = exports["default"] = jmPrismatic;
|
|
|
10511
10561
|
},{"../core/jmPath.js":9}],35:[function(require,module,exports){
|
|
10512
10562
|
"use strict";
|
|
10513
10563
|
|
|
10514
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
10515
|
-
|
|
10516
10564
|
Object.defineProperty(exports, "__esModule", {
|
|
10517
10565
|
value: true
|
|
10518
10566
|
});
|
|
@@ -10524,6 +10572,8 @@ var _jmArc = require("./jmArc.js");
|
|
|
10524
10572
|
|
|
10525
10573
|
var _jmLine = require("./jmLine.js");
|
|
10526
10574
|
|
|
10575
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
10576
|
+
|
|
10527
10577
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10528
10578
|
|
|
10529
10579
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
@@ -10550,6 +10600,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
10550
10600
|
* @class jmRect
|
|
10551
10601
|
* @extends jmPath
|
|
10552
10602
|
* @param {object} params 参数 position=矩形左上角顶点坐标,width=宽,height=高,radius=边角弧度
|
|
10603
|
+
* radius支持数字(四角相同)或对象 { topLeft, topRight, bottomRight, bottomLeft }
|
|
10553
10604
|
*/
|
|
10554
10605
|
var jmRect = /*#__PURE__*/function (_jmPath) {
|
|
10555
10606
|
_inherits(jmRect, _jmPath);
|
|
@@ -10568,13 +10619,26 @@ var jmRect = /*#__PURE__*/function (_jmPath) {
|
|
|
10568
10619
|
|
|
10569
10620
|
_this = _super.call(this, params, t);
|
|
10570
10621
|
_this.style.close = true;
|
|
10571
|
-
|
|
10622
|
+
var r = params.radius || _this.style.radius || _this.style.borderRadius || 0;
|
|
10623
|
+
|
|
10624
|
+
if (_typeof(r) === 'object' && r !== null) {
|
|
10625
|
+
// 四角独立圆角
|
|
10626
|
+
_this.radius = {
|
|
10627
|
+
topLeft: Number(r.topLeft) || 0,
|
|
10628
|
+
topRight: Number(r.topRight) || 0,
|
|
10629
|
+
bottomRight: Number(r.bottomRight) || 0,
|
|
10630
|
+
bottomLeft: Number(r.bottomLeft) || 0
|
|
10631
|
+
};
|
|
10632
|
+
} else {
|
|
10633
|
+
_this.radius = r;
|
|
10634
|
+
}
|
|
10635
|
+
|
|
10572
10636
|
return _this;
|
|
10573
10637
|
}
|
|
10574
10638
|
/**
|
|
10575
|
-
*
|
|
10639
|
+
* 圆角半径,支持数字或四角独立对象
|
|
10576
10640
|
* @property radius
|
|
10577
|
-
* @type {number}
|
|
10641
|
+
* @type {number|object}
|
|
10578
10642
|
*/
|
|
10579
10643
|
|
|
10580
10644
|
|
|
@@ -10587,6 +10651,53 @@ var jmRect = /*#__PURE__*/function (_jmPath) {
|
|
|
10587
10651
|
this.needUpdate = true;
|
|
10588
10652
|
return this.property('radius', v);
|
|
10589
10653
|
}
|
|
10654
|
+
/**
|
|
10655
|
+
* 获取规范化的圆角值(四角独立)
|
|
10656
|
+
* @returns {object} { topLeft, topRight, bottomRight, bottomLeft }
|
|
10657
|
+
*/
|
|
10658
|
+
|
|
10659
|
+
}, {
|
|
10660
|
+
key: "getNormalizedRadius",
|
|
10661
|
+
value: function getNormalizedRadius() {
|
|
10662
|
+
var r = this.radius;
|
|
10663
|
+
|
|
10664
|
+
if (typeof r === 'number') {
|
|
10665
|
+
var v = Math.max(0, r);
|
|
10666
|
+
return {
|
|
10667
|
+
topLeft: v,
|
|
10668
|
+
topRight: v,
|
|
10669
|
+
bottomRight: v,
|
|
10670
|
+
bottomLeft: v
|
|
10671
|
+
};
|
|
10672
|
+
}
|
|
10673
|
+
|
|
10674
|
+
if (_typeof(r) === 'object' && r !== null) {
|
|
10675
|
+
return {
|
|
10676
|
+
topLeft: Math.max(0, Number(r.topLeft) || 0),
|
|
10677
|
+
topRight: Math.max(0, Number(r.topRight) || 0),
|
|
10678
|
+
bottomRight: Math.max(0, Number(r.bottomRight) || 0),
|
|
10679
|
+
bottomLeft: Math.max(0, Number(r.bottomLeft) || 0)
|
|
10680
|
+
};
|
|
10681
|
+
}
|
|
10682
|
+
|
|
10683
|
+
return {
|
|
10684
|
+
topLeft: 0,
|
|
10685
|
+
topRight: 0,
|
|
10686
|
+
bottomRight: 0,
|
|
10687
|
+
bottomLeft: 0
|
|
10688
|
+
};
|
|
10689
|
+
}
|
|
10690
|
+
/**
|
|
10691
|
+
* 检查是否有圆角
|
|
10692
|
+
* @returns {boolean}
|
|
10693
|
+
*/
|
|
10694
|
+
|
|
10695
|
+
}, {
|
|
10696
|
+
key: "hasRadius",
|
|
10697
|
+
value: function hasRadius() {
|
|
10698
|
+
var nr = this.getNormalizedRadius();
|
|
10699
|
+
return nr.topLeft > 0 || nr.topRight > 0 || nr.bottomRight > 0 || nr.bottomLeft > 0;
|
|
10700
|
+
}
|
|
10590
10701
|
/**
|
|
10591
10702
|
* 当前位置左上角
|
|
10592
10703
|
* @property position
|
|
@@ -10649,7 +10760,7 @@ var jmRect = /*#__PURE__*/function (_jmPath) {
|
|
|
10649
10760
|
|
|
10650
10761
|
/**
|
|
10651
10762
|
* 初始化图形点
|
|
10652
|
-
*
|
|
10763
|
+
* 支持四角独立圆角,借助圆弧对象计算描点
|
|
10653
10764
|
*
|
|
10654
10765
|
* @method initPoints
|
|
10655
10766
|
* @private
|
|
@@ -10680,55 +10791,93 @@ var jmRect = /*#__PURE__*/function (_jmPath) {
|
|
|
10680
10791
|
this.dottedLine = this.graph.createShape(_jmLine.jmLine, {
|
|
10681
10792
|
style: this.style
|
|
10682
10793
|
});
|
|
10683
|
-
}
|
|
10794
|
+
}
|
|
10684
10795
|
|
|
10796
|
+
var nr = this.getNormalizedRadius();
|
|
10797
|
+
var hasRadius = this.hasRadius(); // 如果有圆角(支持四角独立),借助圆弧对象计算描点
|
|
10798
|
+
|
|
10799
|
+
if (hasRadius) {
|
|
10800
|
+
var q = Math.PI / 2; // 限制圆角不超过短边的一半
|
|
10801
|
+
|
|
10802
|
+
var maxR = Math.min(location.width / 2, location.height / 2);
|
|
10803
|
+
var rtl = Math.min(nr.topLeft, maxR);
|
|
10804
|
+
var rtr = Math.min(nr.topRight, maxR);
|
|
10805
|
+
var rbr = Math.min(nr.bottomRight, maxR);
|
|
10806
|
+
var rbl = Math.min(nr.bottomLeft, maxR); // 左上角圆弧
|
|
10807
|
+
|
|
10808
|
+
if (rtl > 0) {
|
|
10809
|
+
var arc = this.graph.createShape(_jmArc.jmArc, {
|
|
10810
|
+
radius: rtl,
|
|
10811
|
+
anticlockwise: false
|
|
10812
|
+
});
|
|
10813
|
+
arc.center = {
|
|
10814
|
+
x: location.left + rtl,
|
|
10815
|
+
y: location.top + rtl
|
|
10816
|
+
};
|
|
10817
|
+
arc.startAngle = Math.PI;
|
|
10818
|
+
arc.endAngle = Math.PI + q;
|
|
10819
|
+
var ps1 = arc.initPoints();
|
|
10820
|
+
} else {
|
|
10821
|
+
var ps1 = [p1];
|
|
10822
|
+
} // 右上角圆弧
|
|
10823
|
+
|
|
10824
|
+
|
|
10825
|
+
if (rtr > 0) {
|
|
10826
|
+
var _arc = this.graph.createShape(_jmArc.jmArc, {
|
|
10827
|
+
radius: rtr,
|
|
10828
|
+
anticlockwise: false
|
|
10829
|
+
});
|
|
10830
|
+
|
|
10831
|
+
_arc.center = {
|
|
10832
|
+
x: p2.x - rtr,
|
|
10833
|
+
y: p2.y + rtr
|
|
10834
|
+
};
|
|
10835
|
+
_arc.startAngle = Math.PI + q;
|
|
10836
|
+
_arc.endAngle = Math.PI * 2;
|
|
10837
|
+
|
|
10838
|
+
var ps2 = _arc.initPoints();
|
|
10839
|
+
} else {
|
|
10840
|
+
var ps2 = [p2];
|
|
10841
|
+
} // 右下角圆弧
|
|
10842
|
+
|
|
10843
|
+
|
|
10844
|
+
if (rbr > 0) {
|
|
10845
|
+
var _arc2 = this.graph.createShape(_jmArc.jmArc, {
|
|
10846
|
+
radius: rbr,
|
|
10847
|
+
anticlockwise: false
|
|
10848
|
+
});
|
|
10849
|
+
|
|
10850
|
+
_arc2.center = {
|
|
10851
|
+
x: p3.x - rbr,
|
|
10852
|
+
y: p3.y - rbr
|
|
10853
|
+
};
|
|
10854
|
+
_arc2.startAngle = 0;
|
|
10855
|
+
_arc2.endAngle = q;
|
|
10856
|
+
|
|
10857
|
+
var ps3 = _arc2.initPoints();
|
|
10858
|
+
} else {
|
|
10859
|
+
var ps3 = [p3];
|
|
10860
|
+
} // 左下角圆弧
|
|
10861
|
+
|
|
10862
|
+
|
|
10863
|
+
if (rbl > 0) {
|
|
10864
|
+
var _arc3 = this.graph.createShape(_jmArc.jmArc, {
|
|
10865
|
+
radius: rbl,
|
|
10866
|
+
anticlockwise: false
|
|
10867
|
+
});
|
|
10868
|
+
|
|
10869
|
+
_arc3.center = {
|
|
10870
|
+
x: p4.x + rbl,
|
|
10871
|
+
y: p4.y - rbl
|
|
10872
|
+
};
|
|
10873
|
+
_arc3.startAngle = q;
|
|
10874
|
+
_arc3.endAngle = Math.PI;
|
|
10875
|
+
|
|
10876
|
+
var ps4 = _arc3.initPoints();
|
|
10877
|
+
} else {
|
|
10878
|
+
var ps4 = [p4];
|
|
10879
|
+
}
|
|
10685
10880
|
|
|
10686
|
-
if (location.radius && location.radius < location.width / 2 && location.radius < location.height / 2) {
|
|
10687
|
-
var q = Math.PI / 2;
|
|
10688
|
-
var arc = this.graph.createShape(_jmArc.jmArc, {
|
|
10689
|
-
radius: location.radius,
|
|
10690
|
-
anticlockwise: false
|
|
10691
|
-
});
|
|
10692
|
-
arc.center = {
|
|
10693
|
-
x: location.left + location.radius,
|
|
10694
|
-
y: location.top + location.radius
|
|
10695
|
-
};
|
|
10696
|
-
arc.startAngle = Math.PI;
|
|
10697
|
-
arc.endAngle = Math.PI + q;
|
|
10698
|
-
var ps1 = arc.initPoints();
|
|
10699
|
-
arc = this.graph.createShape(_jmArc.jmArc, {
|
|
10700
|
-
radius: location.radius,
|
|
10701
|
-
anticlockwise: false
|
|
10702
|
-
});
|
|
10703
|
-
arc.center = {
|
|
10704
|
-
x: p2.x - location.radius,
|
|
10705
|
-
y: p2.y + location.radius
|
|
10706
|
-
};
|
|
10707
|
-
arc.startAngle = Math.PI + q;
|
|
10708
|
-
arc.endAngle = Math.PI * 2;
|
|
10709
|
-
var ps2 = arc.initPoints();
|
|
10710
|
-
arc = this.graph.createShape(_jmArc.jmArc, {
|
|
10711
|
-
radius: location.radius,
|
|
10712
|
-
anticlockwise: false
|
|
10713
|
-
});
|
|
10714
|
-
arc.center = {
|
|
10715
|
-
x: p3.x - location.radius,
|
|
10716
|
-
y: p3.y - location.radius
|
|
10717
|
-
};
|
|
10718
|
-
arc.startAngle = 0;
|
|
10719
|
-
arc.endAngle = q;
|
|
10720
|
-
var ps3 = arc.initPoints();
|
|
10721
|
-
arc = this.graph.createShape(_jmArc.jmArc, {
|
|
10722
|
-
radius: location.radius,
|
|
10723
|
-
anticlockwise: false
|
|
10724
|
-
});
|
|
10725
|
-
arc.center = {
|
|
10726
|
-
x: p4.x + location.radius,
|
|
10727
|
-
y: p4.y - location.radius
|
|
10728
|
-
};
|
|
10729
|
-
arc.startAngle = q;
|
|
10730
|
-
arc.endAngle = Math.PI;
|
|
10731
|
-
var ps4 = arc.initPoints();
|
|
10732
10881
|
this.points = ps1.concat(ps2, ps3, ps4);
|
|
10733
10882
|
} else {
|
|
10734
10883
|
this.points = [];
|