@hirokisakabe/pom 0.2.0 → 0.3.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 +3 -2
- package/dist/calcYogaLayout/calcYogaLayout.d.ts.map +1 -1
- package/dist/calcYogaLayout/calcYogaLayout.js +49 -84
- package/dist/calcYogaLayout/fontLoader.d.ts +20 -0
- package/dist/calcYogaLayout/fontLoader.d.ts.map +1 -0
- package/dist/calcYogaLayout/fontLoader.js +59 -0
- package/dist/calcYogaLayout/fonts/notoSansJPBold.d.ts +7 -0
- package/dist/calcYogaLayout/fonts/notoSansJPBold.d.ts.map +1 -0
- package/dist/calcYogaLayout/fonts/notoSansJPBold.js +6 -0
- package/dist/calcYogaLayout/fonts/notoSansJPRegular.d.ts +7 -0
- package/dist/calcYogaLayout/fonts/notoSansJPRegular.d.ts.map +1 -0
- package/dist/calcYogaLayout/fonts/notoSansJPRegular.js +6 -0
- package/dist/calcYogaLayout/measureText.d.ts +1 -1
- package/dist/calcYogaLayout/measureText.d.ts.map +1 -1
- package/dist/calcYogaLayout/measureText.js +65 -114
- package/dist/renderPptx/nodes/box.d.ts +1 -0
- package/dist/renderPptx/nodes/box.d.ts.map +1 -0
- package/dist/renderPptx/nodes/box.js +2 -0
- package/dist/renderPptx/nodes/chart.d.ts +8 -0
- package/dist/renderPptx/nodes/chart.d.ts.map +1 -0
- package/dist/renderPptx/nodes/chart.js +23 -0
- package/dist/renderPptx/nodes/flow.d.ts +8 -0
- package/dist/renderPptx/nodes/flow.d.ts.map +1 -0
- package/dist/renderPptx/nodes/flow.js +208 -0
- package/dist/renderPptx/nodes/image.d.ts +8 -0
- package/dist/renderPptx/nodes/image.d.ts.map +1 -0
- package/dist/renderPptx/nodes/image.js +17 -0
- package/dist/renderPptx/nodes/index.d.ts +11 -0
- package/dist/renderPptx/nodes/index.d.ts.map +1 -0
- package/dist/renderPptx/nodes/index.js +10 -0
- package/dist/renderPptx/nodes/matrix.d.ts +8 -0
- package/dist/renderPptx/nodes/matrix.d.ts.map +1 -0
- package/dist/renderPptx/nodes/matrix.js +150 -0
- package/dist/renderPptx/nodes/processArrow.d.ts +8 -0
- package/dist/renderPptx/nodes/processArrow.d.ts.map +1 -0
- package/dist/renderPptx/nodes/processArrow.js +75 -0
- package/dist/renderPptx/nodes/shape.d.ts +8 -0
- package/dist/renderPptx/nodes/shape.d.ts.map +1 -0
- package/dist/renderPptx/nodes/shape.js +49 -0
- package/dist/renderPptx/nodes/table.d.ts +8 -0
- package/dist/renderPptx/nodes/table.d.ts.map +1 -0
- package/dist/renderPptx/nodes/table.js +29 -0
- package/dist/renderPptx/nodes/text.d.ts +8 -0
- package/dist/renderPptx/nodes/text.d.ts.map +1 -0
- package/dist/renderPptx/nodes/text.js +5 -0
- package/dist/renderPptx/nodes/timeline.d.ts +8 -0
- package/dist/renderPptx/nodes/timeline.d.ts.map +1 -0
- package/dist/renderPptx/nodes/timeline.js +157 -0
- package/dist/renderPptx/nodes/tree.d.ts +8 -0
- package/dist/renderPptx/nodes/tree.d.ts.map +1 -0
- package/dist/renderPptx/nodes/tree.js +223 -0
- package/dist/renderPptx/renderPptx.d.ts.map +1 -1
- package/dist/renderPptx/renderPptx.js +27 -945
- package/dist/renderPptx/types.d.ts +10 -0
- package/dist/renderPptx/types.d.ts.map +1 -0
- package/dist/renderPptx/types.js +1 -0
- package/dist/renderPptx/utils/backgroundBorder.d.ts +8 -0
- package/dist/renderPptx/utils/backgroundBorder.d.ts.map +1 -0
- package/dist/renderPptx/utils/backgroundBorder.js +44 -0
- package/dist/renderPptx/utils/index.d.ts +6 -0
- package/dist/renderPptx/utils/index.d.ts.map +1 -0
- package/dist/renderPptx/utils/index.js +3 -0
- package/dist/renderPptx/utils/shapeDrawing.d.ts +27 -0
- package/dist/renderPptx/utils/shapeDrawing.d.ts.map +1 -0
- package/dist/renderPptx/utils/shapeDrawing.js +36 -0
- package/dist/renderPptx/utils/textDrawing.d.ts +20 -0
- package/dist/renderPptx/utils/textDrawing.d.ts.map +1 -0
- package/dist/renderPptx/utils/textDrawing.js +20 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
## Requirements
|
|
6
6
|
|
|
7
|
-
- Node.js 18 or higher
|
|
7
|
+
- Node.js 18 or higher (for Node.js environments)
|
|
8
|
+
- Modern browser with ES2020+ support (for browser environments)
|
|
8
9
|
|
|
9
10
|
> [!NOTE]
|
|
10
|
-
>
|
|
11
|
+
> pom works in both Node.js and browser environments. Text measurement uses opentype.js with bundled Noto Sans JP fonts, ensuring consistent layout across all environments.
|
|
11
12
|
|
|
12
13
|
## Installation
|
|
13
14
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calcYogaLayout.d.ts","sourceRoot":"","sources":["../../src/calcYogaLayout/calcYogaLayout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"calcYogaLayout.d.ts","sourceRoot":"","sources":["../../src/calcYogaLayout/calcYogaLayout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAA0B,MAAM,UAAU,CAAC;AAOhE;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,OAAO,EACb,SAAS,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,iBAiBpC"}
|
|
@@ -172,94 +172,12 @@ async function applyStyleToYogaNode(node, yn) {
|
|
|
172
172
|
break;
|
|
173
173
|
case "vstack": {
|
|
174
174
|
yn.setFlexDirection(yoga.FLEX_DIRECTION_COLUMN);
|
|
175
|
-
|
|
176
|
-
yn.setGap(yoga.GUTTER_ROW, node.gap);
|
|
177
|
-
yn.setGap(yoga.GUTTER_COLUMN, node.gap);
|
|
178
|
-
}
|
|
179
|
-
if (node.alignItems !== undefined) {
|
|
180
|
-
switch (node.alignItems) {
|
|
181
|
-
case "start":
|
|
182
|
-
yn.setAlignItems(yoga.ALIGN_FLEX_START);
|
|
183
|
-
break;
|
|
184
|
-
case "center":
|
|
185
|
-
yn.setAlignItems(yoga.ALIGN_CENTER);
|
|
186
|
-
break;
|
|
187
|
-
case "end":
|
|
188
|
-
yn.setAlignItems(yoga.ALIGN_FLEX_END);
|
|
189
|
-
break;
|
|
190
|
-
case "stretch":
|
|
191
|
-
yn.setAlignItems(yoga.ALIGN_STRETCH);
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (node.justifyContent !== undefined) {
|
|
196
|
-
switch (node.justifyContent) {
|
|
197
|
-
case "start":
|
|
198
|
-
yn.setJustifyContent(yoga.JUSTIFY_FLEX_START);
|
|
199
|
-
break;
|
|
200
|
-
case "center":
|
|
201
|
-
yn.setJustifyContent(yoga.JUSTIFY_CENTER);
|
|
202
|
-
break;
|
|
203
|
-
case "end":
|
|
204
|
-
yn.setJustifyContent(yoga.JUSTIFY_FLEX_END);
|
|
205
|
-
break;
|
|
206
|
-
case "spaceBetween":
|
|
207
|
-
yn.setJustifyContent(yoga.JUSTIFY_SPACE_BETWEEN);
|
|
208
|
-
break;
|
|
209
|
-
case "spaceAround":
|
|
210
|
-
yn.setJustifyContent(yoga.JUSTIFY_SPACE_AROUND);
|
|
211
|
-
break;
|
|
212
|
-
case "spaceEvenly":
|
|
213
|
-
yn.setJustifyContent(yoga.JUSTIFY_SPACE_EVENLY);
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
175
|
+
applyFlexProperties(node, yn, yoga);
|
|
217
176
|
break;
|
|
218
177
|
}
|
|
219
178
|
case "hstack": {
|
|
220
179
|
yn.setFlexDirection(yoga.FLEX_DIRECTION_ROW);
|
|
221
|
-
|
|
222
|
-
yn.setGap(yoga.GUTTER_ROW, node.gap);
|
|
223
|
-
yn.setGap(yoga.GUTTER_COLUMN, node.gap);
|
|
224
|
-
}
|
|
225
|
-
if (node.alignItems !== undefined) {
|
|
226
|
-
switch (node.alignItems) {
|
|
227
|
-
case "start":
|
|
228
|
-
yn.setAlignItems(yoga.ALIGN_FLEX_START);
|
|
229
|
-
break;
|
|
230
|
-
case "center":
|
|
231
|
-
yn.setAlignItems(yoga.ALIGN_CENTER);
|
|
232
|
-
break;
|
|
233
|
-
case "end":
|
|
234
|
-
yn.setAlignItems(yoga.ALIGN_FLEX_END);
|
|
235
|
-
break;
|
|
236
|
-
case "stretch":
|
|
237
|
-
yn.setAlignItems(yoga.ALIGN_STRETCH);
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (node.justifyContent !== undefined) {
|
|
242
|
-
switch (node.justifyContent) {
|
|
243
|
-
case "start":
|
|
244
|
-
yn.setJustifyContent(yoga.JUSTIFY_FLEX_START);
|
|
245
|
-
break;
|
|
246
|
-
case "center":
|
|
247
|
-
yn.setJustifyContent(yoga.JUSTIFY_CENTER);
|
|
248
|
-
break;
|
|
249
|
-
case "end":
|
|
250
|
-
yn.setJustifyContent(yoga.JUSTIFY_FLEX_END);
|
|
251
|
-
break;
|
|
252
|
-
case "spaceBetween":
|
|
253
|
-
yn.setJustifyContent(yoga.JUSTIFY_SPACE_BETWEEN);
|
|
254
|
-
break;
|
|
255
|
-
case "spaceAround":
|
|
256
|
-
yn.setJustifyContent(yoga.JUSTIFY_SPACE_AROUND);
|
|
257
|
-
break;
|
|
258
|
-
case "spaceEvenly":
|
|
259
|
-
yn.setJustifyContent(yoga.JUSTIFY_SPACE_EVENLY);
|
|
260
|
-
break;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
180
|
+
applyFlexProperties(node, yn, yoga);
|
|
263
181
|
break;
|
|
264
182
|
}
|
|
265
183
|
case "text":
|
|
@@ -359,3 +277,50 @@ async function applyStyleToYogaNode(node, yn) {
|
|
|
359
277
|
break;
|
|
360
278
|
}
|
|
361
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* vstack/hstack 共通の Flex プロパティを適用する
|
|
282
|
+
*/
|
|
283
|
+
function applyFlexProperties(node, yn, yoga) {
|
|
284
|
+
if (node.gap !== undefined) {
|
|
285
|
+
yn.setGap(yoga.GUTTER_ROW, node.gap);
|
|
286
|
+
yn.setGap(yoga.GUTTER_COLUMN, node.gap);
|
|
287
|
+
}
|
|
288
|
+
if (node.alignItems !== undefined) {
|
|
289
|
+
switch (node.alignItems) {
|
|
290
|
+
case "start":
|
|
291
|
+
yn.setAlignItems(yoga.ALIGN_FLEX_START);
|
|
292
|
+
break;
|
|
293
|
+
case "center":
|
|
294
|
+
yn.setAlignItems(yoga.ALIGN_CENTER);
|
|
295
|
+
break;
|
|
296
|
+
case "end":
|
|
297
|
+
yn.setAlignItems(yoga.ALIGN_FLEX_END);
|
|
298
|
+
break;
|
|
299
|
+
case "stretch":
|
|
300
|
+
yn.setAlignItems(yoga.ALIGN_STRETCH);
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (node.justifyContent !== undefined) {
|
|
305
|
+
switch (node.justifyContent) {
|
|
306
|
+
case "start":
|
|
307
|
+
yn.setJustifyContent(yoga.JUSTIFY_FLEX_START);
|
|
308
|
+
break;
|
|
309
|
+
case "center":
|
|
310
|
+
yn.setJustifyContent(yoga.JUSTIFY_CENTER);
|
|
311
|
+
break;
|
|
312
|
+
case "end":
|
|
313
|
+
yn.setJustifyContent(yoga.JUSTIFY_FLEX_END);
|
|
314
|
+
break;
|
|
315
|
+
case "spaceBetween":
|
|
316
|
+
yn.setJustifyContent(yoga.JUSTIFY_SPACE_BETWEEN);
|
|
317
|
+
break;
|
|
318
|
+
case "spaceAround":
|
|
319
|
+
yn.setJustifyContent(yoga.JUSTIFY_SPACE_AROUND);
|
|
320
|
+
break;
|
|
321
|
+
case "spaceEvenly":
|
|
322
|
+
yn.setJustifyContent(yoga.JUSTIFY_SPACE_EVENLY);
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* opentype.js を使用したフォント読み込みモジュール
|
|
3
|
+
* Node.js とブラウザ両方で動作する
|
|
4
|
+
*/
|
|
5
|
+
import { Font } from "opentype.js";
|
|
6
|
+
/**
|
|
7
|
+
* フォントを取得する(キャッシュ付き)
|
|
8
|
+
* @param weight フォントウェイト ("normal" or "bold")
|
|
9
|
+
* @returns opentype.js の Font オブジェクト
|
|
10
|
+
*/
|
|
11
|
+
export declare function getFont(weight: "normal" | "bold"): Font;
|
|
12
|
+
/**
|
|
13
|
+
* 指定したテキストの幅を計測する
|
|
14
|
+
* @param text 計測するテキスト
|
|
15
|
+
* @param fontSizePx フォントサイズ(ピクセル)
|
|
16
|
+
* @param weight フォントウェイト
|
|
17
|
+
* @returns テキスト幅(ピクセル)
|
|
18
|
+
*/
|
|
19
|
+
export declare function measureTextWidth(text: string, fontSizePx: number, weight: "normal" | "bold"): number;
|
|
20
|
+
//# sourceMappingURL=fontLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fontLoader.d.ts","sourceRoot":"","sources":["../../src/calcYogaLayout/fontLoader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAiB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AA6B7C;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAqBvD;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,QAAQ,GAAG,MAAM,GACxB,MAAM,CAGR"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* opentype.js を使用したフォント読み込みモジュール
|
|
3
|
+
* Node.js とブラウザ両方で動作する
|
|
4
|
+
*/
|
|
5
|
+
import opentype from "opentype.js";
|
|
6
|
+
import { NOTO_SANS_JP_REGULAR_BASE64 } from "./fonts/notoSansJPRegular.js";
|
|
7
|
+
import { NOTO_SANS_JP_BOLD_BASE64 } from "./fonts/notoSansJPBold.js";
|
|
8
|
+
// フォントキャッシュ
|
|
9
|
+
const fontCache = new Map();
|
|
10
|
+
/**
|
|
11
|
+
* Base64 文字列を ArrayBuffer に変換する
|
|
12
|
+
* Node.js とブラウザ両方で動作する
|
|
13
|
+
*/
|
|
14
|
+
function base64ToArrayBuffer(base64) {
|
|
15
|
+
// Node.js 環境
|
|
16
|
+
if (typeof Buffer !== "undefined") {
|
|
17
|
+
const buffer = Buffer.from(base64, "base64");
|
|
18
|
+
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
19
|
+
}
|
|
20
|
+
// ブラウザ環境
|
|
21
|
+
const binaryString = atob(base64);
|
|
22
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
23
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
24
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
25
|
+
}
|
|
26
|
+
return bytes.buffer;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* フォントを取得する(キャッシュ付き)
|
|
30
|
+
* @param weight フォントウェイト ("normal" or "bold")
|
|
31
|
+
* @returns opentype.js の Font オブジェクト
|
|
32
|
+
*/
|
|
33
|
+
export function getFont(weight) {
|
|
34
|
+
const cacheKey = weight;
|
|
35
|
+
// キャッシュがあればそれを返す
|
|
36
|
+
const cached = fontCache.get(cacheKey);
|
|
37
|
+
if (cached) {
|
|
38
|
+
return cached;
|
|
39
|
+
}
|
|
40
|
+
// Base64 データを選択
|
|
41
|
+
const base64 = weight === "bold" ? NOTO_SANS_JP_BOLD_BASE64 : NOTO_SANS_JP_REGULAR_BASE64;
|
|
42
|
+
// ArrayBuffer に変換してパース
|
|
43
|
+
const buffer = base64ToArrayBuffer(base64);
|
|
44
|
+
const font = opentype.parse(buffer);
|
|
45
|
+
// キャッシュに保存
|
|
46
|
+
fontCache.set(cacheKey, font);
|
|
47
|
+
return font;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 指定したテキストの幅を計測する
|
|
51
|
+
* @param text 計測するテキスト
|
|
52
|
+
* @param fontSizePx フォントサイズ(ピクセル)
|
|
53
|
+
* @param weight フォントウェイト
|
|
54
|
+
* @returns テキスト幅(ピクセル)
|
|
55
|
+
*/
|
|
56
|
+
export function measureTextWidth(text, fontSizePx, weight) {
|
|
57
|
+
const font = getFont(weight);
|
|
58
|
+
return font.getAdvanceWidth(text, fontSizePx, { kerning: true });
|
|
59
|
+
}
|