@kubohiroya/turbowarp-svg-text 0.3.0 → 0.4.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/README.md +52 -106
- package/dist/composition.js +89 -583
- package/dist/extension-manifest.json +0 -65
- package/dist/svg-text.js +81 -561
- package/dist/types/composition.d.ts +5 -2
- package/dist/types/config.d.ts +1 -1
- package/dist/types/extension.d.ts +9 -33
- package/package.json +23 -26
package/README.md
CHANGED
|
@@ -1,138 +1,84 @@
|
|
|
1
1
|
# TurboWarp SVG Text
|
|
2
2
|
|
|
3
|
-
TurboWarp SVG Text provides responsive
|
|
3
|
+
TurboWarp SVG Text provides responsive named styles and SVG text actors. It is a text provider for host extensions such as `turbowarp-bubble`; Bubble shape, placement, portraits, and animation belong to the host.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Responsibilities
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- Define reusable text styles for font, size, color, background, and alignment.
|
|
8
|
+
- Create, replace, measure, and release SVG text skins.
|
|
9
|
+
- Keep text actors proportional to the stage.
|
|
10
|
+
- Restyle visible text actors when a named style changes.
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
- Choose one of sixteen bubble directions, including the eight intermediate 22.5-degree positions.
|
|
11
|
-
- Display say and think bubbles with a named style.
|
|
12
|
-
- Replace the current sprite's skin with multiline SVG text using `set this sprite text`.
|
|
13
|
-
- Apply the redefinable `default` style to standard say, think, and ask bubbles.
|
|
14
|
-
- Convert literal `\n`, `\r\n`, and `\r` sequences in displayed strings into line breaks.
|
|
15
|
-
- Immediately update visible bubbles and SVG text when a style is redefined or the stage size changes.
|
|
16
|
-
- Keep legacy size-based say/think opcodes hidden but executable for saved-project compatibility.
|
|
17
|
-
|
|
18
|
-
Animation is not included in this release.
|
|
12
|
+
This package does not provide `say` or `think` bubbles, bubble tails, actor-relative placement, portrait images, or bubble animation. Those responsibilities belong to the host package and its capabilities.
|
|
19
13
|
|
|
20
14
|
## Blocks
|
|
21
15
|
|
|
22
|
-
### `define text style [STYLE] background [BACKGROUND] text [TEXT_COLOR] font [FONT] size [SIZE] align [ALIGN]
|
|
23
|
-
|
|
24
|
-
Defines or replaces a named style. `ALIGN` accepts `left`, `center`, or `right`. `DIRECTION` accepts the following sixteen canonical values and their compass aliases; direction applies only to bubbles.
|
|
25
|
-
|
|
26
|
-
| Canonical value | Compass alias |
|
|
27
|
-
| ------------------ | ----------------- |
|
|
28
|
-
| `up` | `north` |
|
|
29
|
-
| `up-up-right` | `north-northeast` |
|
|
30
|
-
| `up-right` | `northeast` |
|
|
31
|
-
| `right-up-right` | `east-northeast` |
|
|
32
|
-
| `right` | `east` |
|
|
33
|
-
| `right-down-right` | `east-southeast` |
|
|
34
|
-
| `down-right` | `southeast` |
|
|
35
|
-
| `down-down-right` | `south-southeast` |
|
|
36
|
-
| `down` | `south` |
|
|
37
|
-
| `down-down-left` | `south-southwest` |
|
|
38
|
-
| `down-left` | `southwest` |
|
|
39
|
-
| `left-down-left` | `west-southwest` |
|
|
40
|
-
| `left` | `west` |
|
|
41
|
-
| `left-up-left` | `west-northwest` |
|
|
42
|
-
| `up-left` | `northwest` |
|
|
43
|
-
| `up-up-left` | `north-northwest` |
|
|
44
|
-
|
|
45
|
-
Direction input is trimmed and case-insensitive. Direction is measured from the actor center to the bubble body center. Changing the bubble width or height does not change the requested angle, although stage-edge clamping can move the bubble when necessary.
|
|
16
|
+
### `define text style [STYLE] background [BACKGROUND] text [TEXT_COLOR] font [FONT] size [SIZE] align [ALIGN]`
|
|
46
17
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
Redefining a name immediately redraws visible bubbles and SVG text actors that use it. Styles are runtime state, so projects should normally define them immediately after the green flag. A blank or unknown style name falls back to `default`.
|
|
18
|
+
Defines or replaces a named text style. Alignment accepts `left`, `center`, or `right`. The background is the rectangle behind an SVG text actor; a host Bubble can define a transparent background and render its own outer shape.
|
|
50
19
|
|
|
51
20
|
### `set this sprite text [TEXT] with style [STYLE]`
|
|
52
21
|
|
|
53
|
-
Creates an SVG skin and applies it to the current sprite's drawable
|
|
54
|
-
|
|
55
|
-
### `say [MESSAGE] with style [STYLE]`
|
|
56
|
-
|
|
57
|
-
Displays a say bubble using the selected named style.
|
|
58
|
-
|
|
59
|
-
### `think [MESSAGE] with style [STYLE]`
|
|
22
|
+
Creates an SVG skin and applies it to the current sprite's drawable. Newline characters render as separate lines. Reusing the same style name after redefinition redraws existing text actors.
|
|
60
23
|
|
|
61
|
-
|
|
24
|
+
## Composition API
|
|
62
25
|
|
|
63
|
-
|
|
26
|
+
The composition API does not register the standalone extension. The host supplies a TurboWarp runtime and explicit targets.
|
|
64
27
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
```text
|
|
68
|
-
stageScale = min(stageWidth / 480, stageHeight / 360)
|
|
69
|
-
fontSize = 14 × stageScale × styleSize / 100
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
| Stage | Style size | Font size |
|
|
73
|
-
| ------- | ---------: | --------: |
|
|
74
|
-
| 480×360 | 100 | 14px |
|
|
75
|
-
| 960×720 | 100 | 28px |
|
|
76
|
-
| 960×720 | 150 | 42px |
|
|
28
|
+
```ts
|
|
29
|
+
import { createSvgTextComposition } from "@kubohiroya/turbowarp-svg-text/composition";
|
|
77
30
|
|
|
78
|
-
|
|
31
|
+
const svgText = createSvgTextComposition({ runtime: Scratch.vm.runtime });
|
|
79
32
|
|
|
80
|
-
|
|
33
|
+
svgText.defineStyle({
|
|
34
|
+
name: "dialogue-text",
|
|
35
|
+
alignment: "left",
|
|
36
|
+
backgroundColor: "transparent",
|
|
37
|
+
font: "Noto Sans JP",
|
|
38
|
+
fontPercent: 100,
|
|
39
|
+
textColor: "#332200",
|
|
40
|
+
});
|
|
81
41
|
|
|
82
|
-
|
|
42
|
+
svgText.setText({
|
|
43
|
+
styleName: "dialogue-text",
|
|
44
|
+
target,
|
|
45
|
+
text: "The End",
|
|
46
|
+
});
|
|
83
47
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
48
|
+
const width = svgText.measureText({
|
|
49
|
+
styleName: "dialogue-text",
|
|
50
|
+
text: "The End",
|
|
51
|
+
});
|
|
87
52
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
say [Once upon a time...\nIn a village by the sea...] with style [narration]
|
|
91
|
-
set this sprite text [Act One\nUrashima Taro] with style [narration]
|
|
53
|
+
svgText.releaseTarget(target);
|
|
54
|
+
svgText.releaseAll();
|
|
92
55
|
```
|
|
93
56
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
Composite runtimes can import `@kubohiroya/turbowarp-svg-text/composition` without registering the
|
|
97
|
-
Standalone extension or adding blocks. The caller supplies one TurboWarp runtime and explicit
|
|
98
|
-
targets.
|
|
57
|
+
`setText` creates or replaces the SVG skin owned by the composition. `measureText` returns the maximum measured line width in stage-relative pixels. `releaseTarget` and `releaseAll` destroy skins owned by the composition.
|
|
99
58
|
|
|
100
|
-
|
|
101
|
-
import { createSvgTextComposition } from "@kubohiroya/turbowarp-svg-text/composition";
|
|
59
|
+
`SvgTextComposition` is intentionally suitable for a host Capability adapter:
|
|
102
60
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
svgText.setText({ target, text: "The End", styleName: "title" });
|
|
61
|
+
```ts
|
|
62
|
+
interface TextCapability {
|
|
63
|
+
setText(input: {
|
|
64
|
+
styleName: string;
|
|
65
|
+
target: { drawableID: number };
|
|
66
|
+
text: string;
|
|
67
|
+
}): void;
|
|
68
|
+
measureText(input: { styleName: string; text: string }): number;
|
|
69
|
+
releaseTarget(target: { drawableID: number }): void;
|
|
70
|
+
}
|
|
114
71
|
```
|
|
115
72
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
73
|
+
## Integration with TurboWarp Bubble
|
|
74
|
+
|
|
75
|
+
`@kubohiroya/turbowarp-bubble` owns the Bubble outer shape, placement, portrait layers, and animation. It can use this package as its `BubbleTextCapability`, but the Bubble core does not depend on SVG Text itself.
|
|
119
76
|
|
|
120
77
|
## Development
|
|
121
78
|
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
pnpm install --frozen-lockfile
|
|
79
|
+
```sh
|
|
80
|
+
pnpm install
|
|
125
81
|
pnpm check
|
|
126
82
|
```
|
|
127
83
|
|
|
128
|
-
The
|
|
129
|
-
|
|
130
|
-
## Compatibility and limitations
|
|
131
|
-
|
|
132
|
-
The extension runs unsandboxed because it uses the TurboWarp VM and renderer. Bubble support feature-detects the `SAY` and `STAGE_SIZE_CHANGED` events, the `Scratch.looks` custom state, drawable positioning, and scratch-render's `TextBubbleSkin.setStyle()`. SVG text actors use `createSVGSkin`, `updateDrawableSkinId`, and `destroySkin`.
|
|
133
|
-
|
|
134
|
-
If compatible private drawing hooks are unavailable, center/right bubble alignment falls back to left alignment. If drawable positioning is unavailable, TurboWarp's standard bubble placement is retained. `setText` reports an explicit error when SVG skin APIs are unavailable. Standard Scratch Looks continues to handle bubble stopping, replacement, target tracking, the 330-character limit, and number formatting.
|
|
135
|
-
|
|
136
|
-
## License
|
|
137
|
-
|
|
138
|
-
MPL-2.0
|
|
84
|
+
The package is distributed under MPL-2.0. See `LICENSE` for the source code terms.
|