leafer-game 2.2.9 → 2.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/web.js CHANGED
@@ -4327,37 +4327,39 @@ var LeaferUI = function(exports) {
4327
4327
  if (oldValue === 0 || value === 0) doBoundsType(leaf);
4328
4328
  }
4329
4329
  }
4330
+ function sortParentChange(parent) {
4331
+ parent.__layout.childrenSortChange();
4332
+ if (parent.__.flow) parent.__layout.boxChange();
4333
+ }
4330
4334
  function sortType(defaultValue) {
4331
4335
  return decorateLeafAttr(defaultValue, key => attr({
4332
4336
  set(value) {
4333
4337
  if (this.__setAttr(key, value)) {
4334
- this.waitParent(() => {
4335
- const {parent: parent} = this;
4336
- parent.__layout.childrenSortChange();
4337
- if (parent.__.flow) parent.__layout.boxChange();
4338
- });
4338
+ this.waitParentChange(sortParentChange);
4339
4339
  }
4340
4340
  }
4341
4341
  }));
4342
4342
  }
4343
+ function maskParentChange(parent) {
4344
+ parent.__updateMask();
4345
+ }
4343
4346
  function maskType(defaultValue, updateSelf) {
4344
4347
  return decorateLeafAttr(defaultValue, key => attr({
4345
4348
  set(value) {
4346
4349
  if (this.__setAttr(key, value)) {
4347
4350
  this.__layout.boxChanged || this.__layout.boxChange();
4348
- updateSelf ? this.__updateMask() : this.waitParent(() => {
4349
- this.parent.__updateMask(value);
4350
- });
4351
+ updateSelf ? this.__updateMask() : this.waitParentChange(maskParentChange);
4351
4352
  }
4352
4353
  }
4353
4354
  }));
4354
4355
  }
4356
+ function eraserParentChange(parent) {
4357
+ parent.__updateEraser();
4358
+ }
4355
4359
  function eraserType(defaultValue) {
4356
4360
  return decorateLeafAttr(defaultValue, key => attr({
4357
4361
  set(value) {
4358
- this.__setAttr(key, value) && this.waitParent(() => {
4359
- this.parent.__updateEraser(value);
4360
- });
4362
+ this.__setAttr(key, value) && this.waitParentChange(eraserParentChange);
4361
4363
  }
4362
4364
  }));
4363
4365
  }
@@ -6063,6 +6065,11 @@ var LeaferUI = function(exports) {
6063
6065
  this.__hasMask = this.__hasEraser = null;
6064
6066
  this.forceUpdate();
6065
6067
  }
6068
+ waitParentChange(item) {
6069
+ this.__parentChange || (this.__parentChange = []);
6070
+ if (!this.__parentChange.includes(item)) this.__parentChange.push(item);
6071
+ if (this.parent) item(this.parent, this);
6072
+ }
6066
6073
  waitParent(item, bind) {
6067
6074
  if (bind) item = item.bind(bind);
6068
6075
  this.parent ? item() : this.on(ChildEvent.ADD, item, "once");
@@ -6150,8 +6157,8 @@ var LeaferUI = function(exports) {
6150
6157
  __extraUpdate() {
6151
6158
  if (this.leaferIsReady) this.leafer.layouter.addExtra(this);
6152
6159
  }
6153
- __updateEraser(value) {
6154
- this.__hasEraser = value ? true : this.children.some(item => item.__.eraser);
6160
+ __updateEraser() {
6161
+ this.__hasEraser = this.children.some(item => item.__.eraser);
6155
6162
  }
6156
6163
  __renderEraser(canvas, options) {
6157
6164
  canvas.save();
@@ -6160,7 +6167,7 @@ var LeaferUI = function(exports) {
6160
6167
  canvas.clearRect(r.x, r.y, r.width, r.height);
6161
6168
  canvas.restore();
6162
6169
  }
6163
- __updateMask(_value) {
6170
+ __updateMask() {
6164
6171
  const hasMask = this.children.some(item => item.__.mask && item.__.visible && item.__.opacity);
6165
6172
  this.__hasMask = this.__.maskskip ? hasMask && 0 : hasMask;
6166
6173
  }
@@ -6408,6 +6415,7 @@ var LeaferUI = function(exports) {
6408
6415
  const childLayout = child.__layout;
6409
6416
  childLayout.boxChanged || childLayout.boxChange();
6410
6417
  childLayout.matrixChanged || childLayout.matrixChange();
6418
+ if (child.__parentChange) child.__parentChange.forEach(item => item(this, child));
6411
6419
  if (child.__bubbleMap) child.__emitLifeEvent(ChildEvent.ADD);
6412
6420
  if (this.isFrame) child.__bindFrame(this);
6413
6421
  if (this.leafer) {
@@ -6626,7 +6634,7 @@ var LeaferUI = function(exports) {
6626
6634
  this.levelMap = null;
6627
6635
  }
6628
6636
  }
6629
- const version = "2.2.9";
6637
+ const version = "2.2.11";
6630
6638
  const debug$5 = Debug.get("LeaferCanvas");
6631
6639
  class LeaferCanvas extends LeaferCanvasBase {
6632
6640
  set zIndex(zIndex) {
@@ -8285,7 +8293,7 @@ var LeaferUI = function(exports) {
8285
8293
  getPath(curve, pathForRender) {
8286
8294
  this.__layout.update();
8287
8295
  let path = pathForRender ? this.__.__pathForRender : this.__.path;
8288
- if (!path) pen.set(path = []), this.__drawPathByBox(pen, !pathForRender);
8296
+ if (!path) pen.set(path = []), this.__drawPathByBox(pen, "box", !pathForRender);
8289
8297
  return curve ? PathConvert.toCanvasData(path, true) : path;
8290
8298
  }
8291
8299
  getPathString(curve, pathForRender, floatLength) {
@@ -8323,10 +8331,10 @@ var LeaferUI = function(exports) {
8323
8331
  data.__usePointsMode ? PathDrawer.drawPathByPoints(canvas, data.points, data.closed) : this.__drawPathByData(canvas, data.path, true);
8324
8332
  }
8325
8333
  __drawPathByData(drawer, data, ignoreCornerRadius) {
8326
- data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer, ignoreCornerRadius);
8334
+ data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer, "box", ignoreCornerRadius);
8327
8335
  }
8328
- __drawPathByBox(drawer, ignoreCornerRadius) {
8329
- const {x: x, y: y, width: width, height: height} = this.__layout.boxBounds;
8336
+ __drawPathByBox(drawer, boundsType = "box", ignoreCornerRadius) {
8337
+ const {x: x, y: y, width: width, height: height} = this.__layout[boundsType + "Bounds"];
8330
8338
  if (this.__.cornerRadius && !ignoreCornerRadius) {
8331
8339
  const {cornerRadius: cornerRadius} = this.__;
8332
8340
  drawer.roundRect(x, y, width, height, isNumber(cornerRadius) ? [ cornerRadius ] : cornerRadius);
@@ -9246,14 +9254,15 @@ var LeaferUI = function(exports) {
9246
9254
  }
9247
9255
  __updateTextDrawData() {
9248
9256
  const data = this.__;
9249
- const {lineHeight: lineHeight, letterSpacing: letterSpacing, fontFamily: fontFamily, fontSize: fontSize, fontWeight: fontWeight, italic: italic, textCase: textCase, textOverflow: textOverflow, padding: padding, width: width, height: height} = data;
9257
+ const {lineHeight: lineHeight, letterSpacing: letterSpacing, wordSpacing: wordSpacing, fontFamily: fontFamily, fontSize: fontSize, fontWeight: fontWeight, italic: italic, textCase: textCase, textOverflow: textOverflow, padding: padding, width: width, height: height} = data;
9250
9258
  data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
9251
9259
  data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
9260
+ data.__wordSpacing = UnitConvert.number(wordSpacing, fontSize);
9252
9261
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * .7) / 2;
9253
9262
  data.__font = `${italic ? "italic " : ""}${textCase === "small-caps" ? "small-caps " : ""}${fontWeight !== "normal" ? fontWeight + " " : ""}${fontSize || 12}px ${fontFamily || "caption"}`;
9254
9263
  stintSet$1(data, "__padding", padding && MathHelper.fourNumber(padding));
9255
9264
  stintSet$1(data, "__clipText", textOverflow !== "show" && !data.__autoSize);
9256
- stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || data.motionText || textCase !== "none");
9265
+ stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || data.__wordSpacing || data.motionText || textCase !== "none");
9257
9266
  data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === "") ? data.placeholder : data.text, this.__);
9258
9267
  }
9259
9268
  __updateBoxBounds() {
@@ -9333,6 +9342,7 @@ var LeaferUI = function(exports) {
9333
9342
  __decorate([ boundsType("none") ], exports.Text.prototype, "textCase", void 0);
9334
9343
  __decorate([ boundsType("none") ], exports.Text.prototype, "textDecoration", void 0);
9335
9344
  __decorate([ boundsType(0) ], exports.Text.prototype, "letterSpacing", void 0);
9345
+ __decorate([ boundsType(0) ], exports.Text.prototype, "wordSpacing", void 0);
9336
9346
  __decorate([ boundsType({
9337
9347
  type: "percent",
9338
9348
  value: 1.5
@@ -11143,7 +11153,7 @@ var LeaferUI = function(exports) {
11143
11153
  if (scaleX !== 1) canvas.scale(scaleX, scaleY);
11144
11154
  }
11145
11155
  if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode;
11146
- fillPathOrText(ui, canvas, renderOptions);
11156
+ fillPathOrText(ui, canvas, renderOptions, true);
11147
11157
  canvas.restore();
11148
11158
  } else {
11149
11159
  if (originPaint.blendMode) {
@@ -11154,24 +11164,45 @@ var LeaferUI = function(exports) {
11154
11164
  }
11155
11165
  }
11156
11166
  }
11157
- function fillPathOrText(ui, canvas, renderOptions) {
11158
- ui.__.__font ? Paint.fillText(ui, canvas, renderOptions) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
11167
+ function fillPathOrText(ui, canvas, renderOptions, complexPaint) {
11168
+ ui.__.__font ? Paint.fillText(ui, canvas, renderOptions, complexPaint) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
11159
11169
  }
11160
- function fillText(ui, canvas, renderOptions) {
11161
- if (ui.motionText) return Paint.fillMotionText(ui, canvas, renderOptions);
11162
- const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
11170
+ function fillText(ui, canvas, renderOptions, complexPaint) {
11171
+ const data = ui.__;
11163
11172
  if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
11164
- let row;
11165
- for (let i = 0, len = rows.length; i < len; i++) {
11166
- row = rows[i];
11167
- if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
11168
- canvas.fillText(charData.char, charData.x, row.y);
11169
- });
11173
+ let originCanvas;
11174
+ if (complexPaint) {
11175
+ originCanvas = canvas;
11176
+ canvas = canvas.getSameCanvas(true, true);
11177
+ canvas.font = ui.__.__font;
11178
+ canvas.fillStyle = "#000";
11179
+ }
11180
+ if (ui.motionText) {
11181
+ Paint.fillMotionText(ui, canvas, renderOptions);
11182
+ } else {
11183
+ let row;
11184
+ const {rows: rows, decorationY: decorationY} = data.__textDrawData;
11185
+ for (let i = 0, len = rows.length; i < len; i++) {
11186
+ row = rows[i];
11187
+ if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
11188
+ canvas.fillText(charData.char, charData.x, row.y);
11189
+ });
11190
+ }
11191
+ if (decorationY) {
11192
+ const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
11193
+ if (decorationColor) canvas.fillStyle = decorationColor;
11194
+ rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
11195
+ }
11170
11196
  }
11171
- if (decorationY) {
11172
- const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
11173
- if (decorationColor) canvas.fillStyle = decorationColor;
11174
- rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
11197
+ if (complexPaint) {
11198
+ canvas.beginPath();
11199
+ ui.__drawPathByBox(canvas, "render");
11200
+ canvas.fillStyle = originCanvas.fillStyle;
11201
+ canvas.setTransform(originCanvas.getTransform());
11202
+ canvas.blendMode = "source-in";
11203
+ canvas.fill();
11204
+ originCanvas.copyWorldByReset(canvas, ui.__nowWorld);
11205
+ canvas.recycle(ui.__nowWorld);
11175
11206
  }
11176
11207
  }
11177
11208
  function stroke(stroke, ui, canvas, renderOptions) {
@@ -12189,8 +12220,8 @@ var LeaferUI = function(exports) {
12189
12220
  const afterChar = ">)]}%!?,.:;'\"" + langAfter;
12190
12221
  const symbolChar = afterChar + "_#~&*+\\=|" + langSymbol;
12191
12222
  const breakChar = "- " + langBreak$1;
12192
- const cjkRangeList = [ [ 19968, 40959 ], [ 13312, 19903 ], [ 131072, 173791 ], [ 173824, 177983 ], [ 177984, 178207 ], [ 178208, 183983 ], [ 183984, 191471 ], [ 196608, 201551 ], [ 201552, 205743 ], [ 11904, 12031 ], [ 12032, 12255 ], [ 12272, 12287 ], [ 12288, 12351 ], [ 12736, 12783 ], [ 12800, 13055 ], [ 13056, 13311 ], [ 63744, 64255 ], [ 65072, 65103 ], [ 127488, 127743 ], [ 194560, 195103 ] ];
12193
- const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join("|"));
12223
+ const cjkRangeList = [ [ 19968, 40959 ], [ 13312, 19903 ], [ 131072, 173791 ], [ 173824, 177983 ], [ 177984, 178207 ], [ 178208, 183983 ], [ 183984, 191471 ], [ 196608, 201551 ], [ 201552, 205743 ], [ 11904, 12031 ], [ 12032, 12255 ], [ 12272, 12287 ], [ 12288, 12351 ], [ 4352, 4607 ], [ 12352, 12447 ], [ 12448, 12543 ], [ 12544, 12591 ], [ 12592, 12687 ], [ 12688, 12703 ], [ 12704, 12735 ], [ 12784, 12799 ], [ 12736, 12783 ], [ 12800, 13055 ], [ 13056, 13311 ], [ 63744, 64255 ], [ 65072, 65103 ], [ 127488, 127743 ], [ 194560, 195103 ] ];
12224
+ const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u{${start.toString(16)}}-\\u{${end.toString(16)}}]`).join("|"), "u");
12194
12225
  function mapChar(str) {
12195
12226
  const map = {};
12196
12227
  str.split("").forEach(char => map[char] = true);
@@ -12269,11 +12300,13 @@ var LeaferUI = function(exports) {
12269
12300
  rows = drawData.rows;
12270
12301
  bounds = drawData.bounds;
12271
12302
  findMaxWidth = !bounds.width && !style.autoSizeAlign;
12272
- const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
12303
+ const {paraIndent: paraIndent, textCase: textCase} = style;
12273
12304
  const {canvas: canvas} = Platform, {width: width} = bounds;
12274
12305
  if (style.__isCharMode) {
12275
12306
  const wrap = style.textWrap !== "none";
12276
12307
  const breakAll = style.textWrap === "break";
12308
+ const letterSpacing = style.__letterSpacing;
12309
+ const wordSpacing = style.__wordSpacing;
12277
12310
  paraStart = true;
12278
12311
  lastCharType = null;
12279
12312
  startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
@@ -12294,9 +12327,9 @@ var LeaferUI = function(exports) {
12294
12327
  charType = getCharType(char);
12295
12328
  if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
12296
12329
  charWidth = canvas.measureText(char).width;
12297
- if (__letterSpacing) {
12298
- if (__letterSpacing < 0) charSize = charWidth;
12299
- charWidth += __letterSpacing;
12330
+ if (letterSpacing) {
12331
+ if (letterSpacing < 0) charSize = charWidth;
12332
+ charWidth += letterSpacing;
12300
12333
  }
12301
12334
  langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
12302
12335
  afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
@@ -12317,11 +12350,11 @@ var LeaferUI = function(exports) {
12317
12350
  }
12318
12351
  if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
12319
12352
  if (charType === Break) {
12320
- if (char === " " && wordWidth) addWord();
12353
+ if (char === " " && wordWidth) addWord(wordSpacing);
12321
12354
  addChar(char, charWidth);
12322
12355
  addWord();
12323
12356
  } else if (langBreak || afterBreak) {
12324
- if (wordWidth) addWord();
12357
+ if (wordWidth) addWord(wordSpacing);
12325
12358
  addChar(char, charWidth);
12326
12359
  } else {
12327
12360
  addChar(char, charWidth);
@@ -12355,7 +12388,11 @@ var LeaferUI = function(exports) {
12355
12388
  });
12356
12389
  wordWidth += width;
12357
12390
  }
12358
- function addWord() {
12391
+ function addWord(wordSpacing) {
12392
+ if (wordSpacing) {
12393
+ rowWidth += wordSpacing;
12394
+ word.addWidth = wordSpacing;
12395
+ }
12359
12396
  rowWidth += wordWidth;
12360
12397
  word.width = wordWidth;
12361
12398
  row.words.push(word);
@@ -12393,6 +12430,7 @@ var LeaferUI = function(exports) {
12393
12430
  const {rows: rows} = drawData;
12394
12431
  const {textAlign: textAlign, paraIndent: paraIndent} = style;
12395
12432
  const useLetter = style.__letterSpacing || style.motionText;
12433
+ const wordSpacing = style.__wordSpacing;
12396
12434
  const justifyLast = width && textAlign.includes("both");
12397
12435
  const justify = justifyLast || width && textAlign.includes("justify");
12398
12436
  const justifyLetter = justify && textAlign.includes("letter");
@@ -12405,7 +12443,7 @@ var LeaferUI = function(exports) {
12405
12443
  remainingWidth = width - row.width - indentWidth;
12406
12444
  if (justifyLetter) addLetterWidth = remainingWidth / (row.words.reduce((total, item) => total + item.data.length, 0) - 1); else addWordWidth = wordsLength > 1 ? remainingWidth / (wordsLength - 1) : 0;
12407
12445
  }
12408
- mode = useLetter || row.isOverflow || justifyLetter ? CharMode : addWordWidth ? WordMode : TextMode;
12446
+ mode = useLetter || row.isOverflow || justifyLetter ? CharMode : addWordWidth || wordSpacing ? WordMode : TextMode;
12409
12447
  if (row.isOverflow && !useLetter) row.textMode = true;
12410
12448
  if (mode === TextMode) {
12411
12449
  row.x += indentWidth;
@@ -12425,6 +12463,7 @@ var LeaferUI = function(exports) {
12425
12463
  } else {
12426
12464
  charX = toChar(word.data, charX, row.data, row.isOverflow, canJustify && addLetterWidth);
12427
12465
  }
12466
+ if (word.addWidth) charX += word.addWidth;
12428
12467
  if (canJustify) {
12429
12468
  isLastWord = index === wordsLength - 1;
12430
12469
  if (addWordWidth) {
@@ -12679,9 +12718,15 @@ var LeaferUI = function(exports) {
12679
12718
  });
12680
12719
  useCanvas();
12681
12720
  class RobotData extends UIData {
12721
+ get __isCanvas() {
12722
+ return true;
12723
+ }
12682
12724
  get __drawAfterFill() {
12683
12725
  return true;
12684
12726
  }
12727
+ get __boxStroke() {
12728
+ return !this.__pathInputed;
12729
+ }
12685
12730
  setRobot(value) {
12686
12731
  this._robot = value;
12687
12732
  this.__leaf.__updateRobot();