@leafer/core 1.0.8 → 1.0.10
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 +35 -19
- package/lib/core.esm.js +35 -19
- package/lib/core.esm.min.js +1 -1
- package/lib/core.min.cjs +1 -1
- package/package.json +17 -17
- package/src/index.ts +1 -1
- package/types/index.d.ts +1 -1
package/lib/core.cjs
CHANGED
|
@@ -1413,14 +1413,13 @@ const UICreator = {
|
|
|
1413
1413
|
list: {},
|
|
1414
1414
|
register(UI) {
|
|
1415
1415
|
const { __tag: tag } = UI.prototype;
|
|
1416
|
-
if (list$1[tag])
|
|
1416
|
+
if (list$1[tag])
|
|
1417
1417
|
debug$7.repeat(tag);
|
|
1418
|
-
|
|
1419
|
-
else {
|
|
1420
|
-
list$1[tag] = UI;
|
|
1421
|
-
}
|
|
1418
|
+
list$1[tag] = UI;
|
|
1422
1419
|
},
|
|
1423
1420
|
get(tag, data, x, y, width, height) {
|
|
1421
|
+
if (!list$1[tag])
|
|
1422
|
+
debug$7.error('not register ' + tag);
|
|
1424
1423
|
const ui = new list$1[tag](data);
|
|
1425
1424
|
if (x !== undefined) {
|
|
1426
1425
|
ui.x = x;
|
|
@@ -1444,7 +1443,7 @@ const EventCreator = {
|
|
|
1444
1443
|
Object.keys(Event).forEach(key => {
|
|
1445
1444
|
name = Event[key];
|
|
1446
1445
|
if (typeof name === 'string')
|
|
1447
|
-
nameList[name]
|
|
1446
|
+
nameList[name] && debug$6.repeat(name), nameList[name] = Event;
|
|
1448
1447
|
});
|
|
1449
1448
|
},
|
|
1450
1449
|
changeName(oldName, newName) {
|
|
@@ -1646,7 +1645,7 @@ class LeafData {
|
|
|
1646
1645
|
const t = this;
|
|
1647
1646
|
if (t.blendMode === 'pass-through') {
|
|
1648
1647
|
const leaf = this.__leaf;
|
|
1649
|
-
if ((t.opacity < 1 && leaf.isBranch) || leaf.__hasEraser || t.eraser) {
|
|
1648
|
+
if ((t.opacity < 1 && (leaf.isBranch || t.__hasMultiPaint)) || leaf.__hasEraser || t.eraser) {
|
|
1650
1649
|
t.__single = true;
|
|
1651
1650
|
}
|
|
1652
1651
|
else if (t.__single) {
|
|
@@ -2044,8 +2043,9 @@ class LeaferCanvasBase extends Canvas {
|
|
|
2044
2043
|
takeCanvas = this.getSameCanvas();
|
|
2045
2044
|
takeCanvas.copyWorld(this);
|
|
2046
2045
|
}
|
|
2047
|
-
|
|
2048
|
-
|
|
2046
|
+
const s = this.size;
|
|
2047
|
+
DataHelper.copyAttrs(s, size, canvasSizeAttrs);
|
|
2048
|
+
canvasSizeAttrs.forEach(key => s[key] || (s[key] = 1));
|
|
2049
2049
|
this.bounds = new Bounds(0, 0, this.width, this.height);
|
|
2050
2050
|
if (this.context && !this.unreal) {
|
|
2051
2051
|
this.updateViewSize();
|
|
@@ -2159,6 +2159,17 @@ class LeaferCanvasBase extends Canvas {
|
|
|
2159
2159
|
if (!onlyResetTransform)
|
|
2160
2160
|
this.useWorldTransform();
|
|
2161
2161
|
}
|
|
2162
|
+
useGrayscaleAlpha(bounds) {
|
|
2163
|
+
this.setTempBounds(bounds, true, true);
|
|
2164
|
+
let alpha, pixel;
|
|
2165
|
+
const { context } = this, imageData = context.getImageData(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height), { data } = imageData;
|
|
2166
|
+
for (let i = 0, len = data.length; i < len; i += 4) {
|
|
2167
|
+
pixel = data[i] * 0.299 + data[i + 1] * 0.587 + data[i + 2] * 0.114;
|
|
2168
|
+
if (alpha = data[i + 3])
|
|
2169
|
+
data[i + 3] = alpha === 255 ? pixel : alpha * (pixel / 255);
|
|
2170
|
+
}
|
|
2171
|
+
context.putImageData(imageData, tempBounds.x, tempBounds.y);
|
|
2172
|
+
}
|
|
2162
2173
|
useMask(maskCanvas, fromBounds, toBounds) {
|
|
2163
2174
|
this.copyWorld(maskCanvas, fromBounds, toBounds, 'destination-in');
|
|
2164
2175
|
}
|
|
@@ -2169,7 +2180,7 @@ class LeaferCanvasBase extends Canvas {
|
|
|
2169
2180
|
if (blendMode)
|
|
2170
2181
|
this.blendMode = blendMode;
|
|
2171
2182
|
this.fillStyle = color;
|
|
2172
|
-
|
|
2183
|
+
this.setTempBounds(bounds);
|
|
2173
2184
|
this.fillRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
|
|
2174
2185
|
if (blendMode)
|
|
2175
2186
|
this.blendMode = 'source-over';
|
|
@@ -2178,22 +2189,18 @@ class LeaferCanvasBase extends Canvas {
|
|
|
2178
2189
|
if (blendMode)
|
|
2179
2190
|
this.blendMode = blendMode;
|
|
2180
2191
|
this.strokeStyle = color;
|
|
2181
|
-
|
|
2192
|
+
this.setTempBounds(bounds);
|
|
2182
2193
|
this.strokeRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
|
|
2183
2194
|
if (blendMode)
|
|
2184
2195
|
this.blendMode = 'source-over';
|
|
2185
2196
|
}
|
|
2186
2197
|
clearWorld(bounds, ceilPixel) {
|
|
2187
|
-
|
|
2188
|
-
if (ceilPixel)
|
|
2189
|
-
tempBounds.ceil();
|
|
2198
|
+
this.setTempBounds(bounds, ceilPixel);
|
|
2190
2199
|
this.clearRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
|
|
2191
2200
|
}
|
|
2192
2201
|
clipWorld(bounds, ceilPixel) {
|
|
2193
2202
|
this.beginPath();
|
|
2194
|
-
|
|
2195
|
-
if (ceilPixel)
|
|
2196
|
-
tempBounds.ceil();
|
|
2203
|
+
this.setTempBounds(bounds, ceilPixel);
|
|
2197
2204
|
this.rect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
|
|
2198
2205
|
this.clip();
|
|
2199
2206
|
}
|
|
@@ -2201,6 +2208,14 @@ class LeaferCanvasBase extends Canvas {
|
|
|
2201
2208
|
const { pixelRatio } = this;
|
|
2202
2209
|
this.clearRect(0, 0, this.width * pixelRatio + 2, this.height * pixelRatio + 2);
|
|
2203
2210
|
}
|
|
2211
|
+
setTempBounds(bounds, ceil, intersect) {
|
|
2212
|
+
tempBounds.set(bounds);
|
|
2213
|
+
if (intersect)
|
|
2214
|
+
tempBounds.intersect(this.bounds);
|
|
2215
|
+
tempBounds.scale(this.pixelRatio);
|
|
2216
|
+
if (ceil)
|
|
2217
|
+
tempBounds.ceil();
|
|
2218
|
+
}
|
|
2204
2219
|
isSameSize(size) {
|
|
2205
2220
|
return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
|
|
2206
2221
|
}
|
|
@@ -5214,13 +5229,14 @@ const BranchRender = {
|
|
|
5214
5229
|
this.__.__checkSingle();
|
|
5215
5230
|
},
|
|
5216
5231
|
__render(canvas, options) {
|
|
5232
|
+
this.__nowWorld = this.__getNowWorld(options);
|
|
5217
5233
|
if (this.__worldOpacity) {
|
|
5218
5234
|
if (this.__.__single) {
|
|
5219
5235
|
if (this.__.eraser === 'path')
|
|
5220
5236
|
return this.__renderEraser(canvas, options);
|
|
5221
5237
|
const tempCanvas = canvas.getSameCanvas(false, true);
|
|
5222
5238
|
this.__renderBranch(tempCanvas, options);
|
|
5223
|
-
const nowWorld = this.
|
|
5239
|
+
const nowWorld = this.__nowWorld;
|
|
5224
5240
|
canvas.opacity = this.__.opacity;
|
|
5225
5241
|
canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, this.__.__blendMode, true);
|
|
5226
5242
|
tempCanvas.recycle(nowWorld);
|
|
@@ -5961,7 +5977,7 @@ class LeafLevelList {
|
|
|
5961
5977
|
}
|
|
5962
5978
|
}
|
|
5963
5979
|
|
|
5964
|
-
const version = "1.0.
|
|
5980
|
+
const version = "1.0.10";
|
|
5965
5981
|
|
|
5966
5982
|
exports.AlignHelper = AlignHelper;
|
|
5967
5983
|
exports.AroundHelper = AroundHelper;
|
package/lib/core.esm.js
CHANGED
|
@@ -1411,14 +1411,13 @@ const UICreator = {
|
|
|
1411
1411
|
list: {},
|
|
1412
1412
|
register(UI) {
|
|
1413
1413
|
const { __tag: tag } = UI.prototype;
|
|
1414
|
-
if (list$1[tag])
|
|
1414
|
+
if (list$1[tag])
|
|
1415
1415
|
debug$7.repeat(tag);
|
|
1416
|
-
|
|
1417
|
-
else {
|
|
1418
|
-
list$1[tag] = UI;
|
|
1419
|
-
}
|
|
1416
|
+
list$1[tag] = UI;
|
|
1420
1417
|
},
|
|
1421
1418
|
get(tag, data, x, y, width, height) {
|
|
1419
|
+
if (!list$1[tag])
|
|
1420
|
+
debug$7.error('not register ' + tag);
|
|
1422
1421
|
const ui = new list$1[tag](data);
|
|
1423
1422
|
if (x !== undefined) {
|
|
1424
1423
|
ui.x = x;
|
|
@@ -1442,7 +1441,7 @@ const EventCreator = {
|
|
|
1442
1441
|
Object.keys(Event).forEach(key => {
|
|
1443
1442
|
name = Event[key];
|
|
1444
1443
|
if (typeof name === 'string')
|
|
1445
|
-
nameList[name]
|
|
1444
|
+
nameList[name] && debug$6.repeat(name), nameList[name] = Event;
|
|
1446
1445
|
});
|
|
1447
1446
|
},
|
|
1448
1447
|
changeName(oldName, newName) {
|
|
@@ -1644,7 +1643,7 @@ class LeafData {
|
|
|
1644
1643
|
const t = this;
|
|
1645
1644
|
if (t.blendMode === 'pass-through') {
|
|
1646
1645
|
const leaf = this.__leaf;
|
|
1647
|
-
if ((t.opacity < 1 && leaf.isBranch) || leaf.__hasEraser || t.eraser) {
|
|
1646
|
+
if ((t.opacity < 1 && (leaf.isBranch || t.__hasMultiPaint)) || leaf.__hasEraser || t.eraser) {
|
|
1648
1647
|
t.__single = true;
|
|
1649
1648
|
}
|
|
1650
1649
|
else if (t.__single) {
|
|
@@ -2042,8 +2041,9 @@ class LeaferCanvasBase extends Canvas {
|
|
|
2042
2041
|
takeCanvas = this.getSameCanvas();
|
|
2043
2042
|
takeCanvas.copyWorld(this);
|
|
2044
2043
|
}
|
|
2045
|
-
|
|
2046
|
-
|
|
2044
|
+
const s = this.size;
|
|
2045
|
+
DataHelper.copyAttrs(s, size, canvasSizeAttrs);
|
|
2046
|
+
canvasSizeAttrs.forEach(key => s[key] || (s[key] = 1));
|
|
2047
2047
|
this.bounds = new Bounds(0, 0, this.width, this.height);
|
|
2048
2048
|
if (this.context && !this.unreal) {
|
|
2049
2049
|
this.updateViewSize();
|
|
@@ -2157,6 +2157,17 @@ class LeaferCanvasBase extends Canvas {
|
|
|
2157
2157
|
if (!onlyResetTransform)
|
|
2158
2158
|
this.useWorldTransform();
|
|
2159
2159
|
}
|
|
2160
|
+
useGrayscaleAlpha(bounds) {
|
|
2161
|
+
this.setTempBounds(bounds, true, true);
|
|
2162
|
+
let alpha, pixel;
|
|
2163
|
+
const { context } = this, imageData = context.getImageData(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height), { data } = imageData;
|
|
2164
|
+
for (let i = 0, len = data.length; i < len; i += 4) {
|
|
2165
|
+
pixel = data[i] * 0.299 + data[i + 1] * 0.587 + data[i + 2] * 0.114;
|
|
2166
|
+
if (alpha = data[i + 3])
|
|
2167
|
+
data[i + 3] = alpha === 255 ? pixel : alpha * (pixel / 255);
|
|
2168
|
+
}
|
|
2169
|
+
context.putImageData(imageData, tempBounds.x, tempBounds.y);
|
|
2170
|
+
}
|
|
2160
2171
|
useMask(maskCanvas, fromBounds, toBounds) {
|
|
2161
2172
|
this.copyWorld(maskCanvas, fromBounds, toBounds, 'destination-in');
|
|
2162
2173
|
}
|
|
@@ -2167,7 +2178,7 @@ class LeaferCanvasBase extends Canvas {
|
|
|
2167
2178
|
if (blendMode)
|
|
2168
2179
|
this.blendMode = blendMode;
|
|
2169
2180
|
this.fillStyle = color;
|
|
2170
|
-
|
|
2181
|
+
this.setTempBounds(bounds);
|
|
2171
2182
|
this.fillRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
|
|
2172
2183
|
if (blendMode)
|
|
2173
2184
|
this.blendMode = 'source-over';
|
|
@@ -2176,22 +2187,18 @@ class LeaferCanvasBase extends Canvas {
|
|
|
2176
2187
|
if (blendMode)
|
|
2177
2188
|
this.blendMode = blendMode;
|
|
2178
2189
|
this.strokeStyle = color;
|
|
2179
|
-
|
|
2190
|
+
this.setTempBounds(bounds);
|
|
2180
2191
|
this.strokeRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
|
|
2181
2192
|
if (blendMode)
|
|
2182
2193
|
this.blendMode = 'source-over';
|
|
2183
2194
|
}
|
|
2184
2195
|
clearWorld(bounds, ceilPixel) {
|
|
2185
|
-
|
|
2186
|
-
if (ceilPixel)
|
|
2187
|
-
tempBounds.ceil();
|
|
2196
|
+
this.setTempBounds(bounds, ceilPixel);
|
|
2188
2197
|
this.clearRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
|
|
2189
2198
|
}
|
|
2190
2199
|
clipWorld(bounds, ceilPixel) {
|
|
2191
2200
|
this.beginPath();
|
|
2192
|
-
|
|
2193
|
-
if (ceilPixel)
|
|
2194
|
-
tempBounds.ceil();
|
|
2201
|
+
this.setTempBounds(bounds, ceilPixel);
|
|
2195
2202
|
this.rect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height);
|
|
2196
2203
|
this.clip();
|
|
2197
2204
|
}
|
|
@@ -2199,6 +2206,14 @@ class LeaferCanvasBase extends Canvas {
|
|
|
2199
2206
|
const { pixelRatio } = this;
|
|
2200
2207
|
this.clearRect(0, 0, this.width * pixelRatio + 2, this.height * pixelRatio + 2);
|
|
2201
2208
|
}
|
|
2209
|
+
setTempBounds(bounds, ceil, intersect) {
|
|
2210
|
+
tempBounds.set(bounds);
|
|
2211
|
+
if (intersect)
|
|
2212
|
+
tempBounds.intersect(this.bounds);
|
|
2213
|
+
tempBounds.scale(this.pixelRatio);
|
|
2214
|
+
if (ceil)
|
|
2215
|
+
tempBounds.ceil();
|
|
2216
|
+
}
|
|
2202
2217
|
isSameSize(size) {
|
|
2203
2218
|
return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
|
|
2204
2219
|
}
|
|
@@ -5212,13 +5227,14 @@ const BranchRender = {
|
|
|
5212
5227
|
this.__.__checkSingle();
|
|
5213
5228
|
},
|
|
5214
5229
|
__render(canvas, options) {
|
|
5230
|
+
this.__nowWorld = this.__getNowWorld(options);
|
|
5215
5231
|
if (this.__worldOpacity) {
|
|
5216
5232
|
if (this.__.__single) {
|
|
5217
5233
|
if (this.__.eraser === 'path')
|
|
5218
5234
|
return this.__renderEraser(canvas, options);
|
|
5219
5235
|
const tempCanvas = canvas.getSameCanvas(false, true);
|
|
5220
5236
|
this.__renderBranch(tempCanvas, options);
|
|
5221
|
-
const nowWorld = this.
|
|
5237
|
+
const nowWorld = this.__nowWorld;
|
|
5222
5238
|
canvas.opacity = this.__.opacity;
|
|
5223
5239
|
canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, this.__.__blendMode, true);
|
|
5224
5240
|
tempCanvas.recycle(nowWorld);
|
|
@@ -5959,6 +5975,6 @@ class LeafLevelList {
|
|
|
5959
5975
|
}
|
|
5960
5976
|
}
|
|
5961
5977
|
|
|
5962
|
-
const version = "1.0.
|
|
5978
|
+
const version = "1.0.10";
|
|
5963
5979
|
|
|
5964
5980
|
export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, Eventer, FileHelper, 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, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Platform, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, Run, StringNumberMap, TaskItem, TaskProcessor, TwoPointBoundsHelper, UICreator, WaitHelper, WatchEvent, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isNull, layoutProcessor, maskType, naturalBoundsType, needPlugin, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, useModule, version, visibleType };
|