@leafer/core 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/core.cjs CHANGED
@@ -1890,7 +1890,10 @@ const UICreator = {
1890
1890
  list$1[tag] = UI;
1891
1891
  },
1892
1892
  get(tag, data, x, y, width, height) {
1893
- if (!list$1[tag]) debug$9.error("not register " + tag);
1893
+ if (!list$1[tag]) {
1894
+ debug$9.warn("not register " + tag);
1895
+ return undefined;
1896
+ }
1894
1897
  const ui = new list$1[tag](data);
1895
1898
  if (!isUndefined(x)) {
1896
1899
  ui.x = x;
@@ -3747,10 +3750,10 @@ function canvasPatch(drawer) {
3747
3750
  const FileHelper = {
3748
3751
  alphaPixelTypes: [ "png", "webp", "svg" ],
3749
3752
  upperCaseTypeMap: {},
3750
- mineType(type) {
3751
- if (!type || type.startsWith("image")) return type;
3753
+ mimeType(type, base = "image") {
3754
+ if (!type || type.startsWith(base)) return type;
3752
3755
  if (type === "jpg") type = "jpeg";
3753
- return "image/" + type;
3756
+ return base + "/" + type;
3754
3757
  },
3755
3758
  fileType(filename) {
3756
3759
  const l = filename.split(".");
@@ -3783,6 +3786,8 @@ const FileHelper = {
3783
3786
 
3784
3787
  const F = FileHelper;
3785
3788
 
3789
+ F.mineType = F.mimeType;
3790
+
3786
3791
  F.alphaPixelTypes.forEach(type => F.upperCaseTypeMap[type] = type.toUpperCase());
3787
3792
 
3788
3793
  const debug$4 = Debug.get("TaskProcessor");
@@ -4027,6 +4032,9 @@ const debug$3 = Debug.get("Resource");
4027
4032
 
4028
4033
  const Resource = {
4029
4034
  tasker: new TaskProcessor,
4035
+ queue: new TaskProcessor({
4036
+ parallel: 1
4037
+ }),
4030
4038
  map: {},
4031
4039
  get isComplete() {
4032
4040
  return R.tasker.isComplete;
@@ -4063,6 +4071,12 @@ const Resource = {
4063
4071
  R.set(key, value);
4064
4072
  return value;
4065
4073
  },
4074
+ loadFilm(_key, _format) {
4075
+ return undefined;
4076
+ },
4077
+ loadVideo(_key, _format) {
4078
+ return undefined;
4079
+ },
4066
4080
  destroy() {
4067
4081
  R.map = {};
4068
4082
  }
@@ -4073,12 +4087,10 @@ const R = Resource;
4073
4087
  const ImageManager = {
4074
4088
  maxRecycled: 10,
4075
4089
  recycledList: [],
4076
- patternTasker: new TaskProcessor({
4077
- parallel: 1
4078
- }),
4079
- get(config) {
4090
+ patternTasker: Resource.queue,
4091
+ get(config, type) {
4080
4092
  let image = Resource.get(config.url);
4081
- if (!image) Resource.set(config.url, image = Creator.image(config));
4093
+ if (!image) Resource.set(config.url, image = type === "film" ? Creator.film(config) : Creator.image(config));
4082
4094
  image.use++;
4083
4095
  return image;
4084
4096
  },
@@ -4113,7 +4125,7 @@ const ImageManager = {
4113
4125
  if (config.format) return config.format === format;
4114
4126
  const {url: url} = config;
4115
4127
  if (url.startsWith("data:")) {
4116
- if (url.startsWith("data:" + FileHelper.mineType(format))) return true;
4128
+ if (url.startsWith("data:" + FileHelper.mimeType(format))) return true;
4117
4129
  } else {
4118
4130
  if (url.includes("." + format) || url.includes("." + FileHelper.upperCaseTypeMap[format])) return true; else if (format === "png" && !url.includes(".")) return true;
4119
4131
  }
@@ -4129,6 +4141,9 @@ const I = ImageManager;
4129
4141
  const {IMAGE: IMAGE, create: create$1} = IncrementId;
4130
4142
 
4131
4143
  class LeaferImage {
4144
+ get tag() {
4145
+ return "Image";
4146
+ }
4132
4147
  get url() {
4133
4148
  return this.config.url;
4134
4149
  }
@@ -4157,7 +4172,7 @@ class LeaferImage {
4157
4172
  if (!this.loading) {
4158
4173
  this.loading = true;
4159
4174
  Resource.tasker.add(() => __awaiter(this, void 0, void 0, function*() {
4160
- return yield Platform.origin.loadImage(this.getLoadUrl(thumbSize), this.crossOrigin, this).then(img => {
4175
+ return yield Platform.origin["load" + this.tag](this.getLoadUrl(thumbSize), this.crossOrigin, this).then(img => {
4161
4176
  if (thumbSize) this.setThumbView(img);
4162
4177
  this.setView(img);
4163
4178
  }).catch(e => {
@@ -4231,6 +4246,9 @@ class LeaferImage {
4231
4246
  Platform.image.setPatternTransform(pattern, transform, paint);
4232
4247
  return pattern;
4233
4248
  }
4249
+ render(canvas, x, y, width, height, _leaf, _paint, _imageScaleX, _imageScaleY) {
4250
+ canvas.drawImage(this.view, x, y, width, height);
4251
+ }
4234
4252
  getLoadUrl(_thumbSize) {
4235
4253
  return this.url;
4236
4254
  }
@@ -4257,6 +4275,18 @@ class LeaferImage {
4257
4275
  }
4258
4276
  }
4259
4277
 
4278
+ class LeaferFilm extends LeaferImage {
4279
+ get tag() {
4280
+ return "Film";
4281
+ }
4282
+ }
4283
+
4284
+ class LeaferVideo extends LeaferImage {
4285
+ get tag() {
4286
+ return "Video";
4287
+ }
4288
+ }
4289
+
4260
4290
  function defineKey(target, key, descriptor, noConfigurable) {
4261
4291
  if (!noConfigurable) descriptor.configurable = descriptor.enumerable = true;
4262
4292
  Object.defineProperty(target, key, descriptor);
@@ -6145,9 +6175,11 @@ const BranchRender = {
6145
6175
  if (this.__hasMask) {
6146
6176
  this.__renderMask(canvas, options);
6147
6177
  } else {
6178
+ let child;
6148
6179
  const {children: children} = this;
6149
6180
  for (let i = 0, len = children.length; i < len; i++) {
6150
- excludeRenderBounds(children[i], options) || children[i].__render(canvas, options);
6181
+ child = children[i];
6182
+ excludeRenderBounds(child, options) || (child.__.complex ? child.__renderComplex(canvas, options) : child.__render(canvas, options));
6151
6183
  }
6152
6184
  }
6153
6185
  },
@@ -6628,6 +6660,7 @@ exports.Leaf = class Leaf {
6628
6660
  __drawHitPath(_canvas) {}
6629
6661
  __updateHitCanvas() {}
6630
6662
  __render(_canvas, _options) {}
6663
+ __renderComplex(_canvas, _options) {}
6631
6664
  __drawFast(_canvas, _options) {}
6632
6665
  __draw(_canvas, _options, _originCanvas) {}
6633
6666
  __clip(_canvas, _options) {}
@@ -6747,6 +6780,7 @@ exports.Branch = class Branch extends exports.Leaf {
6747
6780
  this.add(item, index);
6748
6781
  noIndex || index++;
6749
6782
  }); else child = UICreator.get(child.tag, child);
6783
+ if (!child) return;
6750
6784
  }
6751
6785
  if (child.parent) child.parent.remove(child);
6752
6786
  child.parent = this;
@@ -6972,7 +7006,7 @@ class LeafLevelList {
6972
7006
  }
6973
7007
  }
6974
7008
 
6975
- const version = "2.0.1";
7009
+ const version = "2.0.2";
6976
7010
 
6977
7011
  exports.AlignHelper = AlignHelper;
6978
7012
 
@@ -7048,8 +7082,12 @@ exports.LeaferCanvasBase = LeaferCanvasBase;
7048
7082
 
7049
7083
  exports.LeaferEvent = LeaferEvent;
7050
7084
 
7085
+ exports.LeaferFilm = LeaferFilm;
7086
+
7051
7087
  exports.LeaferImage = LeaferImage;
7052
7088
 
7089
+ exports.LeaferVideo = LeaferVideo;
7090
+
7053
7091
  exports.MathHelper = MathHelper;
7054
7092
 
7055
7093
  exports.Matrix = Matrix;
package/lib/core.esm.js CHANGED
@@ -1888,7 +1888,10 @@ const UICreator = {
1888
1888
  list$1[tag] = UI;
1889
1889
  },
1890
1890
  get(tag, data, x, y, width, height) {
1891
- if (!list$1[tag]) debug$9.error("not register " + tag);
1891
+ if (!list$1[tag]) {
1892
+ debug$9.warn("not register " + tag);
1893
+ return undefined;
1894
+ }
1892
1895
  const ui = new list$1[tag](data);
1893
1896
  if (!isUndefined(x)) {
1894
1897
  ui.x = x;
@@ -3745,10 +3748,10 @@ function canvasPatch(drawer) {
3745
3748
  const FileHelper = {
3746
3749
  alphaPixelTypes: [ "png", "webp", "svg" ],
3747
3750
  upperCaseTypeMap: {},
3748
- mineType(type) {
3749
- if (!type || type.startsWith("image")) return type;
3751
+ mimeType(type, base = "image") {
3752
+ if (!type || type.startsWith(base)) return type;
3750
3753
  if (type === "jpg") type = "jpeg";
3751
- return "image/" + type;
3754
+ return base + "/" + type;
3752
3755
  },
3753
3756
  fileType(filename) {
3754
3757
  const l = filename.split(".");
@@ -3781,6 +3784,8 @@ const FileHelper = {
3781
3784
 
3782
3785
  const F = FileHelper;
3783
3786
 
3787
+ F.mineType = F.mimeType;
3788
+
3784
3789
  F.alphaPixelTypes.forEach(type => F.upperCaseTypeMap[type] = type.toUpperCase());
3785
3790
 
3786
3791
  const debug$4 = Debug.get("TaskProcessor");
@@ -4025,6 +4030,9 @@ const debug$3 = Debug.get("Resource");
4025
4030
 
4026
4031
  const Resource = {
4027
4032
  tasker: new TaskProcessor,
4033
+ queue: new TaskProcessor({
4034
+ parallel: 1
4035
+ }),
4028
4036
  map: {},
4029
4037
  get isComplete() {
4030
4038
  return R.tasker.isComplete;
@@ -4061,6 +4069,12 @@ const Resource = {
4061
4069
  R.set(key, value);
4062
4070
  return value;
4063
4071
  },
4072
+ loadFilm(_key, _format) {
4073
+ return undefined;
4074
+ },
4075
+ loadVideo(_key, _format) {
4076
+ return undefined;
4077
+ },
4064
4078
  destroy() {
4065
4079
  R.map = {};
4066
4080
  }
@@ -4071,12 +4085,10 @@ const R = Resource;
4071
4085
  const ImageManager = {
4072
4086
  maxRecycled: 10,
4073
4087
  recycledList: [],
4074
- patternTasker: new TaskProcessor({
4075
- parallel: 1
4076
- }),
4077
- get(config) {
4088
+ patternTasker: Resource.queue,
4089
+ get(config, type) {
4078
4090
  let image = Resource.get(config.url);
4079
- if (!image) Resource.set(config.url, image = Creator.image(config));
4091
+ if (!image) Resource.set(config.url, image = type === "film" ? Creator.film(config) : Creator.image(config));
4080
4092
  image.use++;
4081
4093
  return image;
4082
4094
  },
@@ -4111,7 +4123,7 @@ const ImageManager = {
4111
4123
  if (config.format) return config.format === format;
4112
4124
  const {url: url} = config;
4113
4125
  if (url.startsWith("data:")) {
4114
- if (url.startsWith("data:" + FileHelper.mineType(format))) return true;
4126
+ if (url.startsWith("data:" + FileHelper.mimeType(format))) return true;
4115
4127
  } else {
4116
4128
  if (url.includes("." + format) || url.includes("." + FileHelper.upperCaseTypeMap[format])) return true; else if (format === "png" && !url.includes(".")) return true;
4117
4129
  }
@@ -4127,6 +4139,9 @@ const I = ImageManager;
4127
4139
  const {IMAGE: IMAGE, create: create$1} = IncrementId;
4128
4140
 
4129
4141
  class LeaferImage {
4142
+ get tag() {
4143
+ return "Image";
4144
+ }
4130
4145
  get url() {
4131
4146
  return this.config.url;
4132
4147
  }
@@ -4155,7 +4170,7 @@ class LeaferImage {
4155
4170
  if (!this.loading) {
4156
4171
  this.loading = true;
4157
4172
  Resource.tasker.add(() => __awaiter(this, void 0, void 0, function*() {
4158
- return yield Platform.origin.loadImage(this.getLoadUrl(thumbSize), this.crossOrigin, this).then(img => {
4173
+ return yield Platform.origin["load" + this.tag](this.getLoadUrl(thumbSize), this.crossOrigin, this).then(img => {
4159
4174
  if (thumbSize) this.setThumbView(img);
4160
4175
  this.setView(img);
4161
4176
  }).catch(e => {
@@ -4229,6 +4244,9 @@ class LeaferImage {
4229
4244
  Platform.image.setPatternTransform(pattern, transform, paint);
4230
4245
  return pattern;
4231
4246
  }
4247
+ render(canvas, x, y, width, height, _leaf, _paint, _imageScaleX, _imageScaleY) {
4248
+ canvas.drawImage(this.view, x, y, width, height);
4249
+ }
4232
4250
  getLoadUrl(_thumbSize) {
4233
4251
  return this.url;
4234
4252
  }
@@ -4255,6 +4273,18 @@ class LeaferImage {
4255
4273
  }
4256
4274
  }
4257
4275
 
4276
+ class LeaferFilm extends LeaferImage {
4277
+ get tag() {
4278
+ return "Film";
4279
+ }
4280
+ }
4281
+
4282
+ class LeaferVideo extends LeaferImage {
4283
+ get tag() {
4284
+ return "Video";
4285
+ }
4286
+ }
4287
+
4258
4288
  function defineKey(target, key, descriptor, noConfigurable) {
4259
4289
  if (!noConfigurable) descriptor.configurable = descriptor.enumerable = true;
4260
4290
  Object.defineProperty(target, key, descriptor);
@@ -6143,9 +6173,11 @@ const BranchRender = {
6143
6173
  if (this.__hasMask) {
6144
6174
  this.__renderMask(canvas, options);
6145
6175
  } else {
6176
+ let child;
6146
6177
  const {children: children} = this;
6147
6178
  for (let i = 0, len = children.length; i < len; i++) {
6148
- excludeRenderBounds(children[i], options) || children[i].__render(canvas, options);
6179
+ child = children[i];
6180
+ excludeRenderBounds(child, options) || (child.__.complex ? child.__renderComplex(canvas, options) : child.__render(canvas, options));
6149
6181
  }
6150
6182
  }
6151
6183
  },
@@ -6626,6 +6658,7 @@ let Leaf = class Leaf {
6626
6658
  __drawHitPath(_canvas) {}
6627
6659
  __updateHitCanvas() {}
6628
6660
  __render(_canvas, _options) {}
6661
+ __renderComplex(_canvas, _options) {}
6629
6662
  __drawFast(_canvas, _options) {}
6630
6663
  __draw(_canvas, _options, _originCanvas) {}
6631
6664
  __clip(_canvas, _options) {}
@@ -6745,6 +6778,7 @@ let Branch = class Branch extends Leaf {
6745
6778
  this.add(item, index);
6746
6779
  noIndex || index++;
6747
6780
  }); else child = UICreator.get(child.tag, child);
6781
+ if (!child) return;
6748
6782
  }
6749
6783
  if (child.parent) child.parent.remove(child);
6750
6784
  child.parent = this;
@@ -6970,6 +7004,6 @@ class LeafLevelList {
6970
7004
  }
6971
7005
  }
6972
7006
 
6973
- const version = "2.0.1";
7007
+ const version = "2.0.2";
6974
7008
 
6975
- export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, Eventer, FileHelper, FourNumberHelper, ImageEvent, ImageManager, IncrementId, LayoutEvent, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, LeaferCanvasBase, LeaferEvent, LeaferImage, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, PathBounds, PathCommandDataHelper, PathCommandMap, PathCommandNodeHelper, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Platform, Plugin, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, Resource, Run, StringNumberMap, TaskItem, TaskProcessor, TwoPointBoundsHelper, UICreator, UnitConvertHelper, WaitHelper, WatchEvent, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, createDescriptor, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, dimType, doBoundsType, doStrokeType, emptyData, eraserType, extraPropertyEventMap, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isArray, isData, isEmptyData, isFinite, isNull, isNumber, isObject, isString, isUndefined, layoutProcessor, leaferTransformAttrMap, maskType, naturalBoundsType, opacityType, path, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, scrollType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, tryToNumber, useModule, version, visibleType };
7009
+ export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, Eventer, FileHelper, FourNumberHelper, ImageEvent, ImageManager, IncrementId, LayoutEvent, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, LeaferCanvasBase, LeaferEvent, LeaferFilm, LeaferImage, LeaferVideo, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, PathBounds, PathCommandDataHelper, PathCommandMap, PathCommandNodeHelper, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Platform, Plugin, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, Resource, Run, StringNumberMap, TaskItem, TaskProcessor, TwoPointBoundsHelper, UICreator, UnitConvertHelper, WaitHelper, WatchEvent, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, createDescriptor, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, dimType, doBoundsType, doStrokeType, emptyData, eraserType, extraPropertyEventMap, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isArray, isData, isEmptyData, isFinite, isNull, isNumber, isObject, isString, isUndefined, layoutProcessor, leaferTransformAttrMap, maskType, naturalBoundsType, opacityType, path, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, scrollType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, tryToNumber, useModule, version, visibleType };