@next2d/text 1.15.0 → 1.16.0
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/TextField.d.ts +2 -0
- package/dist/TextField.js +94 -72
- package/package.json +8 -8
package/dist/TextField.d.ts
CHANGED
package/dist/TextField.js
CHANGED
|
@@ -3,8 +3,8 @@ import { InteractiveObject, Sprite } from "@next2d/display";
|
|
|
3
3
|
import { FocusEvent, Event as Next2DEvent, MouseEvent as Next2DMouseEvent } from "@next2d/events";
|
|
4
4
|
import { Tween } from "@next2d/ui";
|
|
5
5
|
import { Rectangle } from "@next2d/geom";
|
|
6
|
-
import { $currentPlayer, $DIV, $isSafari, $MOUSE_DOWN, $MOUSE_UP, $MOUSE_WHEEL, $P_TAG, $PREFIX, $rendererWorker, $SCROLL, $textContext, $TOUCH_END, $TOUCH_START, $
|
|
7
|
-
import { $doUpdated, $clamp, $getArray, $intToRGBA, $isNaN, $Math, $requestAnimationFrame, $toColorInt, $getMap, $poolFloat32Array6, $boundsMatrix, $multiplicationMatrix, $poolBoundsObject, $multiplicationColor, $Infinity, $Number, $poolArray, $poolFloat32Array8, $generateFontStyle, $getBoundsObject } from "@next2d/share";
|
|
6
|
+
import { $currentPlayer, $DIV, $isSafari, $MOUSE_DOWN, $MOUSE_UP, $MOUSE_WHEEL, $P_TAG, $PREFIX, $rendererWorker, $SCROLL, $textContext, $TOUCH_END, $TOUCH_START, $document, $RegExp } from "@next2d/util";
|
|
7
|
+
import { $cacheStore, $doUpdated, $clamp, $getArray, $intToRGBA, $isNaN, $Math, $requestAnimationFrame, $toColorInt, $getMap, $poolFloat32Array6, $boundsMatrix, $multiplicationMatrix, $poolBoundsObject, $multiplicationColor, $Infinity, $Number, $poolArray, $poolFloat32Array8, $generateFontStyle, $devicePixelRatio, $getBoundsObject } from "@next2d/share";
|
|
8
8
|
/**
|
|
9
9
|
* TextField クラスは、テキストの表示と入力用の表示オブジェクトを作成するために使用されます。
|
|
10
10
|
* プロパティインスペクターを使用して、テキストフィールドにインスタンス名を付けることができます。
|
|
@@ -287,6 +287,16 @@ export class TextField extends InteractiveObject {
|
|
|
287
287
|
* @private
|
|
288
288
|
*/
|
|
289
289
|
this._$heightCache = $getMap();
|
|
290
|
+
/**
|
|
291
|
+
* @type {array}
|
|
292
|
+
* @private
|
|
293
|
+
*/
|
|
294
|
+
this._$cacheKeys = $getArray();
|
|
295
|
+
/**
|
|
296
|
+
* @type {array}
|
|
297
|
+
* @private
|
|
298
|
+
*/
|
|
299
|
+
this._$cacheParams = $getArray(0, 0, 0);
|
|
290
300
|
}
|
|
291
301
|
/**
|
|
292
302
|
* @description 指定されたクラスのストリングを返します。
|
|
@@ -1711,8 +1721,7 @@ export class TextField extends InteractiveObject {
|
|
|
1711
1721
|
this._$doChanged();
|
|
1712
1722
|
$doUpdated();
|
|
1713
1723
|
// cache clear
|
|
1714
|
-
|
|
1715
|
-
player.cacheStore.removeCache(this._$instanceId);
|
|
1724
|
+
$cacheStore.removeCache(this._$instanceId);
|
|
1716
1725
|
}
|
|
1717
1726
|
/**
|
|
1718
1727
|
* @return {void}
|
|
@@ -2027,17 +2036,6 @@ export class TextField extends InteractiveObject {
|
|
|
2027
2036
|
default:
|
|
2028
2037
|
break;
|
|
2029
2038
|
}
|
|
2030
|
-
if (0 > xMin + width || 0 > yMin + height) {
|
|
2031
|
-
return;
|
|
2032
|
-
}
|
|
2033
|
-
// cache current buffer
|
|
2034
|
-
const manager = context.frameBuffer;
|
|
2035
|
-
const currentAttachment = manager.currentAttachment;
|
|
2036
|
-
if (!currentAttachment
|
|
2037
|
-
|| xMin > currentAttachment.width
|
|
2038
|
-
|| yMin > currentAttachment.height) {
|
|
2039
|
-
return;
|
|
2040
|
-
}
|
|
2041
2039
|
let xScale = +$Math.sqrt(multiMatrix[0] * multiMatrix[0]
|
|
2042
2040
|
+ multiMatrix[1] * multiMatrix[1]);
|
|
2043
2041
|
if (!$Number.isInteger(xScale)) {
|
|
@@ -2059,47 +2057,58 @@ export class TextField extends InteractiveObject {
|
|
|
2059
2057
|
yScale = +yScale.toFixed(4);
|
|
2060
2058
|
}
|
|
2061
2059
|
const filters = this._$filters || this.filters;
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|| 0 > filterBounds.yMin + filterBounds.yMax) {
|
|
2071
|
-
$poolBoundsObject(filterBounds);
|
|
2072
|
-
return;
|
|
2073
|
-
}
|
|
2074
|
-
$poolBoundsObject(filterBounds);
|
|
2075
|
-
}
|
|
2076
|
-
else {
|
|
2077
|
-
return;
|
|
2060
|
+
const canApply = filters !== null
|
|
2061
|
+
&& filters.length > 0
|
|
2062
|
+
&& this._$canApply(filters);
|
|
2063
|
+
let filterBounds = $getBoundsObject(0, width, 0, height);
|
|
2064
|
+
if (canApply && filters) {
|
|
2065
|
+
for (let idx = 0; idx < filters.length; ++idx) {
|
|
2066
|
+
filterBounds = filters[idx]
|
|
2067
|
+
._$generateFilterRect(filterBounds, xScale, yScale);
|
|
2078
2068
|
}
|
|
2079
2069
|
}
|
|
2080
|
-
|
|
2081
|
-
const
|
|
2082
|
-
const
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2070
|
+
// cache current buffer
|
|
2071
|
+
const manager = context.frameBuffer;
|
|
2072
|
+
const currentAttachment = manager.currentAttachment;
|
|
2073
|
+
if (!currentAttachment
|
|
2074
|
+
|| xMin - filterBounds.xMin > currentAttachment.width
|
|
2075
|
+
|| yMin - filterBounds.yMin > currentAttachment.height) {
|
|
2076
|
+
$poolBoundsObject(filterBounds);
|
|
2077
|
+
return;
|
|
2078
|
+
}
|
|
2079
|
+
if (0 > xMin + filterBounds.xMax || 0 > yMin + filterBounds.yMax) {
|
|
2080
|
+
$poolBoundsObject(filterBounds);
|
|
2081
|
+
return;
|
|
2082
|
+
}
|
|
2083
|
+
$poolBoundsObject(filterBounds);
|
|
2087
2084
|
// texture is small or renew
|
|
2088
2085
|
if (this._$isUpdated()) {
|
|
2089
|
-
cacheStore.removeCache(instanceId);
|
|
2090
|
-
|
|
2086
|
+
$cacheStore.removeCache(this._$instanceId);
|
|
2087
|
+
context.cachePosition = null;
|
|
2088
|
+
this._$cacheKeys.length = 0;
|
|
2089
|
+
}
|
|
2090
|
+
if (!this._$cacheKeys.length
|
|
2091
|
+
|| this._$cacheParams[0] !== xScale
|
|
2092
|
+
|| this._$cacheParams[1] !== yScale
|
|
2093
|
+
|| this._$cacheParams[2] !== color_transform[7]) {
|
|
2094
|
+
const keys = $getArray(xScale, yScale);
|
|
2095
|
+
this._$cacheKeys = $cacheStore.generateKeys(this._$instanceId, keys);
|
|
2096
|
+
$poolArray(keys);
|
|
2097
|
+
this._$cacheParams[0] = xScale;
|
|
2098
|
+
this._$cacheParams[1] = yScale;
|
|
2099
|
+
this._$cacheParams[2] = color_transform[7];
|
|
2091
2100
|
}
|
|
2092
|
-
|
|
2101
|
+
const blendMode = this._$blendMode || this.blendMode;
|
|
2102
|
+
context.cachePosition = $cacheStore.get(this._$cacheKeys);
|
|
2103
|
+
if (!context.cachePosition) {
|
|
2093
2104
|
// resize
|
|
2094
2105
|
const lineWidth = $Math.min(1, $Math.max(xScale, yScale));
|
|
2095
|
-
const
|
|
2096
|
-
const
|
|
2097
|
-
// alpha reset
|
|
2098
|
-
multiColor[3] = 1;
|
|
2106
|
+
const width = $Math.ceil($Math.abs(baseBounds.xMax - baseBounds.xMin) * xScale);
|
|
2107
|
+
const height = $Math.ceil($Math.abs(baseBounds.yMax - baseBounds.yMin) * yScale);
|
|
2099
2108
|
// new canvas
|
|
2100
|
-
const canvas = cacheStore.getCanvas();
|
|
2101
|
-
canvas.width =
|
|
2102
|
-
canvas.height =
|
|
2109
|
+
const canvas = $cacheStore.getCanvas();
|
|
2110
|
+
canvas.width = width + lineWidth * 2;
|
|
2111
|
+
canvas.height = height + lineWidth * 2;
|
|
2103
2112
|
const ctx = canvas.getContext("2d");
|
|
2104
2113
|
if (!ctx) {
|
|
2105
2114
|
throw new Error("the context is null.");
|
|
@@ -2108,19 +2117,19 @@ export class TextField extends InteractiveObject {
|
|
|
2108
2117
|
if (this._$background || this._$border) {
|
|
2109
2118
|
ctx.beginPath();
|
|
2110
2119
|
ctx.moveTo(0, 0);
|
|
2111
|
-
ctx.lineTo(
|
|
2112
|
-
ctx.lineTo(
|
|
2113
|
-
ctx.lineTo(0,
|
|
2120
|
+
ctx.lineTo(width, 0);
|
|
2121
|
+
ctx.lineTo(width, height);
|
|
2122
|
+
ctx.lineTo(0, height);
|
|
2114
2123
|
ctx.lineTo(0, 0);
|
|
2115
2124
|
if (this._$background) {
|
|
2116
2125
|
const rgb = $intToRGBA(this._$backgroundColor);
|
|
2117
|
-
const alpha = $Math.max(0, $Math.min(rgb.A * 255
|
|
2126
|
+
const alpha = $Math.max(0, $Math.min(rgb.A * 255 + multiColor[7], 255)) / 255;
|
|
2118
2127
|
ctx.fillStyle = `rgba(${rgb.R},${rgb.G},${rgb.B},${alpha})`;
|
|
2119
2128
|
ctx.fill();
|
|
2120
2129
|
}
|
|
2121
2130
|
if (this._$border) {
|
|
2122
2131
|
const rgb = $intToRGBA(this._$borderColor);
|
|
2123
|
-
const alpha = $Math.max(0, $Math.min(rgb.A * 255
|
|
2132
|
+
const alpha = $Math.max(0, $Math.min(rgb.A * 255 + multiColor[7], 255)) / 255;
|
|
2124
2133
|
ctx.lineWidth = lineWidth;
|
|
2125
2134
|
ctx.strokeStyle = `rgba(${rgb.R},${rgb.G},${rgb.B},${alpha})`;
|
|
2126
2135
|
ctx.stroke();
|
|
@@ -2130,20 +2139,25 @@ export class TextField extends InteractiveObject {
|
|
|
2130
2139
|
ctx.save();
|
|
2131
2140
|
ctx.beginPath();
|
|
2132
2141
|
ctx.moveTo(2, 2);
|
|
2133
|
-
ctx.lineTo(
|
|
2134
|
-
ctx.lineTo(
|
|
2135
|
-
ctx.lineTo(2,
|
|
2142
|
+
ctx.lineTo(width - 2, 2);
|
|
2143
|
+
ctx.lineTo(width - 2, height - 2);
|
|
2144
|
+
ctx.lineTo(2, height - 2);
|
|
2136
2145
|
ctx.lineTo(2, 2);
|
|
2137
2146
|
ctx.clip();
|
|
2138
2147
|
ctx.beginPath();
|
|
2139
2148
|
ctx.setTransform(xScale, 0, 0, yScale, 0, 0);
|
|
2140
|
-
this._$doDraw(ctx, matrix, multiColor,
|
|
2149
|
+
this._$doDraw(ctx, matrix, multiColor, width / xScale);
|
|
2141
2150
|
ctx.restore();
|
|
2142
|
-
|
|
2151
|
+
const position = manager
|
|
2152
|
+
.createCachePosition(width, height);
|
|
2153
|
+
const texture = manager
|
|
2154
|
+
.createTextureFromCanvas(ctx.canvas);
|
|
2155
|
+
context.drawTextureFromRect(texture, position);
|
|
2143
2156
|
// set cache
|
|
2144
|
-
|
|
2157
|
+
context.cachePosition = position;
|
|
2158
|
+
$cacheStore.set(this._$cacheKeys, position);
|
|
2145
2159
|
// destroy cache
|
|
2146
|
-
cacheStore.destroy(ctx);
|
|
2160
|
+
$cacheStore.destroy(ctx);
|
|
2147
2161
|
}
|
|
2148
2162
|
let drawFilter = false;
|
|
2149
2163
|
let offsetX = 0;
|
|
@@ -2151,9 +2165,15 @@ export class TextField extends InteractiveObject {
|
|
|
2151
2165
|
if (filters && filters.length
|
|
2152
2166
|
&& this._$canApply(filters)) {
|
|
2153
2167
|
drawFilter = true;
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2168
|
+
const position = this._$drawFilter(context, multiMatrix, filters, width, height);
|
|
2169
|
+
if (position.offsetX) {
|
|
2170
|
+
offsetX = position.offsetX;
|
|
2171
|
+
}
|
|
2172
|
+
if (position.offsetY) {
|
|
2173
|
+
offsetY = position.offsetY;
|
|
2174
|
+
}
|
|
2175
|
+
// update
|
|
2176
|
+
context.cachePosition = position;
|
|
2157
2177
|
}
|
|
2158
2178
|
const radianX = $Math.atan2(multiMatrix[1], multiMatrix[0]);
|
|
2159
2179
|
const radianY = $Math.atan2(-multiMatrix[2], multiMatrix[3]);
|
|
@@ -2170,13 +2190,15 @@ export class TextField extends InteractiveObject {
|
|
|
2170
2190
|
context.setTransform(1, 0, 0, 1, xMin - offsetX, yMin - offsetY);
|
|
2171
2191
|
}
|
|
2172
2192
|
// draw
|
|
2173
|
-
context.
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2193
|
+
if (context.cachePosition) {
|
|
2194
|
+
context.globalAlpha = alpha;
|
|
2195
|
+
context.imageSmoothingEnabled = true;
|
|
2196
|
+
context.globalCompositeOperation = blendMode;
|
|
2197
|
+
context.drawInstance(xMin - offsetX, yMin - offsetY, xMax, yMax, color_transform);
|
|
2198
|
+
// cache position clear
|
|
2199
|
+
context.cachePosition = null;
|
|
2200
|
+
}
|
|
2178
2201
|
// get cache
|
|
2179
|
-
$poolArray(cacheKeys);
|
|
2180
2202
|
$poolBoundsObject(baseBounds);
|
|
2181
2203
|
// pool
|
|
2182
2204
|
if (multiMatrix !== matrix) {
|
|
@@ -2230,11 +2252,11 @@ export class TextField extends InteractiveObject {
|
|
|
2230
2252
|
const tf = obj.textFormat;
|
|
2231
2253
|
// color
|
|
2232
2254
|
const rgb = $intToRGBA(tf.color || 0);
|
|
2233
|
-
const alpha = $Math.max(0, $Math.min(rgb.A * 255
|
|
2255
|
+
const alpha = $Math.max(0, $Math.min(rgb.A * 255 + color_transform[7], 255)) / 255;
|
|
2234
2256
|
context.fillStyle = `rgba(${rgb.R},${rgb.G},${rgb.B},${alpha})`;
|
|
2235
2257
|
if (this._$thickness) {
|
|
2236
2258
|
const rgb = $intToRGBA(this._$thicknessColor);
|
|
2237
|
-
const alpha = $Math.max(0, $Math.min(rgb.A * 255
|
|
2259
|
+
const alpha = $Math.max(0, $Math.min(rgb.A * 255 + color_transform[7], 255)) / 255;
|
|
2238
2260
|
context.lineWidth = this._$thickness;
|
|
2239
2261
|
context.strokeStyle = `rgba(${rgb.R},${rgb.G},${rgb.B},${alpha})`;
|
|
2240
2262
|
}
|
|
@@ -2251,7 +2273,7 @@ export class TextField extends InteractiveObject {
|
|
|
2251
2273
|
if (tf.underline) {
|
|
2252
2274
|
const offset = tf.size ? tf.size / 12 : 0;
|
|
2253
2275
|
const rgb = $intToRGBA(tf.color || 0);
|
|
2254
|
-
const alpha = $Math.max(0, $Math.min(rgb.A * 255
|
|
2276
|
+
const alpha = $Math.max(0, $Math.min(rgb.A * 255 + color_transform[7], 255)) / 255;
|
|
2255
2277
|
context.lineWidth = $Math.max(1, 1 / $Math.min(matrix[0], matrix[3]));
|
|
2256
2278
|
context.strokeStyle = `rgba(${rgb.R},${rgb.G},${rgb.B},${alpha})`;
|
|
2257
2279
|
context.beginPath();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next2d/text",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"description": "Next2D Text Packages",
|
|
5
5
|
"author": "Toshiyuki Ienaga<ienaga@tvon.jp> (https://github.com/ienaga/)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"url": "git+https://github.com/Next2D/Player.git"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@next2d/display": "1.
|
|
36
|
-
"@next2d/events": "1.
|
|
37
|
-
"@next2d/ui": "1.
|
|
38
|
-
"@next2d/geom": "1.
|
|
39
|
-
"@next2d/interface": "1.
|
|
40
|
-
"@next2d/core": "1.
|
|
41
|
-
"@next2d/webgl": "1.
|
|
35
|
+
"@next2d/display": "1.16.0",
|
|
36
|
+
"@next2d/events": "1.16.0",
|
|
37
|
+
"@next2d/ui": "1.16.0",
|
|
38
|
+
"@next2d/geom": "1.16.0",
|
|
39
|
+
"@next2d/interface": "1.16.0",
|
|
40
|
+
"@next2d/core": "1.16.0",
|
|
41
|
+
"@next2d/webgl": "1.16.0"
|
|
42
42
|
}
|
|
43
43
|
}
|