@hirokisakabe/pom 0.1.12 → 0.2.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 +28 -582
- package/dist/calcYogaLayout/calcYogaLayout.js +12 -0
- package/dist/inputSchema.d.ts +268 -2
- package/dist/inputSchema.d.ts.map +1 -1
- package/dist/inputSchema.js +53 -1
- package/dist/renderPptx/renderPptx.d.ts.map +1 -1
- package/dist/renderPptx/renderPptx.js +784 -0
- package/dist/toPositioned/toPositioned.d.ts.map +1 -1
- package/dist/toPositioned/toPositioned.js +45 -0
- package/dist/types.d.ts +399 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +134 -0
- package/package.json +11 -2
- package/dist/parsePptx/convertChart.d.ts +0 -8
- package/dist/parsePptx/convertChart.d.ts.map +0 -1
- package/dist/parsePptx/convertChart.js +0 -78
- package/dist/parsePptx/convertImage.d.ts +0 -8
- package/dist/parsePptx/convertImage.d.ts.map +0 -1
- package/dist/parsePptx/convertImage.js +0 -13
- package/dist/parsePptx/convertShape.d.ts +0 -7
- package/dist/parsePptx/convertShape.d.ts.map +0 -1
- package/dist/parsePptx/convertShape.js +0 -137
- package/dist/parsePptx/convertTable.d.ts +0 -7
- package/dist/parsePptx/convertTable.d.ts.map +0 -1
- package/dist/parsePptx/convertTable.js +0 -46
- package/dist/parsePptx/convertText.d.ts +0 -7
- package/dist/parsePptx/convertText.d.ts.map +0 -1
- package/dist/parsePptx/convertText.js +0 -32
- package/dist/parsePptx/index.d.ts +0 -23
- package/dist/parsePptx/index.d.ts.map +0 -1
- package/dist/parsePptx/index.js +0 -114
- package/dist/parsePptx/parseHtml.d.ts +0 -22
- package/dist/parsePptx/parseHtml.d.ts.map +0 -1
- package/dist/parsePptx/parseHtml.js +0 -53
- package/dist/parsePptx/types.d.ts +0 -15
- package/dist/parsePptx/types.d.ts.map +0 -1
- package/dist/parsePptx/types.js +0 -1
- package/dist/parsePptx/units.d.ts +0 -13
- package/dist/parsePptx/units.d.ts.map +0 -1
- package/dist/parsePptx/units.js +0 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hirokisakabe/pom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "PowerPoint Object Model - A declarative TypeScript library for creating PowerPoint presentations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -59,9 +59,18 @@
|
|
|
59
59
|
"vrt:docker": "docker compose build vrt && docker compose run --rm vrt",
|
|
60
60
|
"vrt:docker:update": "docker compose build vrt-update && docker compose run --rm vrt-update",
|
|
61
61
|
"preview": "tsx preview/lib/previewPptx.ts",
|
|
62
|
-
"preview:docker": "docker compose build preview && docker compose run --rm preview"
|
|
62
|
+
"preview:docker": "docker compose build preview && docker compose run --rm preview",
|
|
63
|
+
"docs:images": "tsx docs/lib/generateNodeImages.ts",
|
|
64
|
+
"docs:images:docker": "docker compose run --rm docs-images",
|
|
65
|
+
"docs:images:docker:update": "docker compose build docs-images && docker compose run --rm docs-images",
|
|
66
|
+
"release": "changeset publish"
|
|
67
|
+
},
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"access": "public"
|
|
63
70
|
},
|
|
64
71
|
"devDependencies": {
|
|
72
|
+
"@changesets/changelog-github": "^0.5.2",
|
|
73
|
+
"@changesets/cli": "^2.29.8",
|
|
65
74
|
"@eslint/js": "^9.39.1",
|
|
66
75
|
"@types/image-size": "0.7.0",
|
|
67
76
|
"@types/pngjs": "6.0.5",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ChartNode } from "../types";
|
|
2
|
-
import type { Chart } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* pptxtojsonのChart要素をPOMのChartNodeに変換
|
|
5
|
-
* scatter/bubbleチャートはサポートされていないためnullを返す
|
|
6
|
-
*/
|
|
7
|
-
export declare function convertChart(element: Chart): ChartNode | null;
|
|
8
|
-
//# sourceMappingURL=convertChart.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convertChart.d.ts","sourceRoot":"","sources":["../../src/parsePptx/convertChart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAwB,MAAM,UAAU,CAAC;AAChE,OAAO,KAAK,EAAE,KAAK,EAA2C,MAAM,SAAS,CAAC;AA2C9E;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CA4C7D"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { ptToPx, normalizeColor } from "./units";
|
|
2
|
-
/**
|
|
3
|
-
* pptxtojsonのchartType から POMのChartType へのマッピング
|
|
4
|
-
* 3Dチャートは2D相当として扱う
|
|
5
|
-
*/
|
|
6
|
-
const CHART_TYPE_MAP = {
|
|
7
|
-
barChart: "bar",
|
|
8
|
-
bar3DChart: "bar",
|
|
9
|
-
lineChart: "line",
|
|
10
|
-
line3DChart: "line",
|
|
11
|
-
pieChart: "pie",
|
|
12
|
-
pie3DChart: "pie",
|
|
13
|
-
areaChart: "area",
|
|
14
|
-
area3DChart: "area",
|
|
15
|
-
doughnutChart: "doughnut",
|
|
16
|
-
radarChart: "radar",
|
|
17
|
-
// サポートされていないチャートタイプ
|
|
18
|
-
scatterChart: null,
|
|
19
|
-
bubbleChart: null,
|
|
20
|
-
surfaceChart: null,
|
|
21
|
-
surface3DChart: null,
|
|
22
|
-
stockChart: null,
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* pptxtojsonのchartTypeをPOMのChartTypeに変換
|
|
26
|
-
* サポートされていない場合はnullを返す
|
|
27
|
-
*/
|
|
28
|
-
function mapChartType(chartType) {
|
|
29
|
-
return CHART_TYPE_MAP[chartType];
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* CommonChartかどうかをチェック
|
|
33
|
-
*/
|
|
34
|
-
function isCommonChart(chart) {
|
|
35
|
-
return (chart.chartType !== "scatterChart" && chart.chartType !== "bubbleChart");
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* pptxtojsonのChart要素をPOMのChartNodeに変換
|
|
39
|
-
* scatter/bubbleチャートはサポートされていないためnullを返す
|
|
40
|
-
*/
|
|
41
|
-
export function convertChart(element) {
|
|
42
|
-
// scatter/bubbleチャートはサポートされていない
|
|
43
|
-
if (!isCommonChart(element)) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
const pomChartType = mapChartType(element.chartType);
|
|
47
|
-
if (pomChartType === null) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
// データの変換
|
|
51
|
-
// pptxtojson: { key: string, values: { x: string, y: number }[], xlabels: { [key]: string } }
|
|
52
|
-
// pom: { name?: string, labels: string[], values: number[] }
|
|
53
|
-
const data = element.data.map((item) => {
|
|
54
|
-
const labels = item.values.map((v) => v.x);
|
|
55
|
-
const values = item.values.map((v) => v.y);
|
|
56
|
-
return {
|
|
57
|
-
name: item.key || undefined,
|
|
58
|
-
labels,
|
|
59
|
-
values,
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
const result = {
|
|
63
|
-
type: "chart",
|
|
64
|
-
chartType: pomChartType,
|
|
65
|
-
data,
|
|
66
|
-
w: ptToPx(element.width),
|
|
67
|
-
h: ptToPx(element.height),
|
|
68
|
-
};
|
|
69
|
-
// チャートの色
|
|
70
|
-
if (element.colors && element.colors.length > 0) {
|
|
71
|
-
result.chartColors = element.colors.map(normalizeColor);
|
|
72
|
-
}
|
|
73
|
-
// radarチャートのスタイル
|
|
74
|
-
if (pomChartType === "radar") {
|
|
75
|
-
result.radarStyle = "standard";
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ImageNode } from "../types";
|
|
2
|
-
import type { Image } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* pptxtojsonのImage要素をPOMのImageNodeに変換
|
|
5
|
-
* pptxtojsonは画像をBase64形式で提供する
|
|
6
|
-
*/
|
|
7
|
-
export declare function convertImage(element: Image): ImageNode;
|
|
8
|
-
//# sourceMappingURL=convertImage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convertImage.d.ts","sourceRoot":"","sources":["../../src/parsePptx/convertImage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGrC;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,KAAK,GAAG,SAAS,CAOtD"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ptToPx } from "./units";
|
|
2
|
-
/**
|
|
3
|
-
* pptxtojsonのImage要素をPOMのImageNodeに変換
|
|
4
|
-
* pptxtojsonは画像をBase64形式で提供する
|
|
5
|
-
*/
|
|
6
|
-
export function convertImage(element) {
|
|
7
|
-
return {
|
|
8
|
-
type: "image",
|
|
9
|
-
src: element.src,
|
|
10
|
-
w: ptToPx(element.width),
|
|
11
|
-
h: ptToPx(element.height),
|
|
12
|
-
};
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convertShape.d.ts","sourceRoot":"","sources":["../../src/parsePptx/convertShape.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAa,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAsFrC;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,KAAK,GAAG,SAAS,CA2DtD"}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { ptToPx, normalizeColor } from "./units";
|
|
2
|
-
import { extractPlainText, extractStyles } from "./parseHtml";
|
|
3
|
-
/**
|
|
4
|
-
* pptxtojsonのshapType から POMのShapeType へのマッピング
|
|
5
|
-
* pptxtojsonのshapTypeはOpenXMLの図形名に近い形式
|
|
6
|
-
*/
|
|
7
|
-
const SHAPE_TYPE_MAP = {
|
|
8
|
-
rect: "rect",
|
|
9
|
-
rectangle: "rect",
|
|
10
|
-
roundRect: "roundRect",
|
|
11
|
-
roundRectangle: "roundRect",
|
|
12
|
-
ellipse: "ellipse",
|
|
13
|
-
oval: "ellipse",
|
|
14
|
-
triangle: "triangle",
|
|
15
|
-
rtTriangle: "rtTriangle",
|
|
16
|
-
parallelogram: "parallelogram",
|
|
17
|
-
trapezoid: "trapezoid",
|
|
18
|
-
diamond: "diamond",
|
|
19
|
-
pentagon: "pentagon",
|
|
20
|
-
hexagon: "hexagon",
|
|
21
|
-
heptagon: "heptagon",
|
|
22
|
-
octagon: "octagon",
|
|
23
|
-
decagon: "decagon",
|
|
24
|
-
dodecagon: "dodecagon",
|
|
25
|
-
star4: "star4",
|
|
26
|
-
star5: "star5",
|
|
27
|
-
star6: "star6",
|
|
28
|
-
star7: "star7",
|
|
29
|
-
star8: "star8",
|
|
30
|
-
star10: "star10",
|
|
31
|
-
star12: "star12",
|
|
32
|
-
star16: "star16",
|
|
33
|
-
star24: "star24",
|
|
34
|
-
star32: "star32",
|
|
35
|
-
plus: "plus",
|
|
36
|
-
cross: "plus",
|
|
37
|
-
arrow: "rightArrow",
|
|
38
|
-
rightArrow: "rightArrow",
|
|
39
|
-
leftArrow: "leftArrow",
|
|
40
|
-
upArrow: "upArrow",
|
|
41
|
-
downArrow: "downArrow",
|
|
42
|
-
leftRightArrow: "leftRightArrow",
|
|
43
|
-
upDownArrow: "upDownArrow",
|
|
44
|
-
cloud: "cloud",
|
|
45
|
-
cloudCallout: "cloudCallout",
|
|
46
|
-
heart: "heart",
|
|
47
|
-
lightningBolt: "lightningBolt",
|
|
48
|
-
sun: "sun",
|
|
49
|
-
moon: "moon",
|
|
50
|
-
arc: "arc",
|
|
51
|
-
donut: "donut",
|
|
52
|
-
line: "line",
|
|
53
|
-
chevron: "chevron",
|
|
54
|
-
homePlate: "homePlate",
|
|
55
|
-
can: "can",
|
|
56
|
-
cube: "cube",
|
|
57
|
-
bevel: "bevel",
|
|
58
|
-
funnel: "funnel",
|
|
59
|
-
wedgeRectCallout: "wedgeRectCallout",
|
|
60
|
-
wedgeRoundRectCallout: "wedgeRoundRectCallout",
|
|
61
|
-
wedgeEllipseCallout: "wedgeEllipseCallout",
|
|
62
|
-
frame: "frame",
|
|
63
|
-
plaque: "plaque",
|
|
64
|
-
bracePair: "bracePair",
|
|
65
|
-
bracketPair: "bracketPair",
|
|
66
|
-
leftBrace: "leftBrace",
|
|
67
|
-
rightBrace: "rightBrace",
|
|
68
|
-
leftBracket: "leftBracket",
|
|
69
|
-
rightBracket: "rightBracket",
|
|
70
|
-
flowChartProcess: "flowChartProcess",
|
|
71
|
-
flowChartDecision: "flowChartDecision",
|
|
72
|
-
flowChartTerminator: "flowChartTerminator",
|
|
73
|
-
flowChartDocument: "flowChartDocument",
|
|
74
|
-
flowChartConnector: "flowChartConnector",
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* pptxtojsonのshapTypeをPOMのShapeTypeに変換
|
|
78
|
-
* マッピングに存在しない場合はデフォルトで "rect" を返す
|
|
79
|
-
*/
|
|
80
|
-
function mapShapeType(shapType) {
|
|
81
|
-
return SHAPE_TYPE_MAP[shapType] || "rect";
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* pptxtojsonのShape要素をPOMのShapeNodeに変換
|
|
85
|
-
*/
|
|
86
|
-
export function convertShape(element) {
|
|
87
|
-
const result = {
|
|
88
|
-
type: "shape",
|
|
89
|
-
shapeType: mapShapeType(element.shapType),
|
|
90
|
-
w: ptToPx(element.width),
|
|
91
|
-
h: ptToPx(element.height),
|
|
92
|
-
};
|
|
93
|
-
// テキストがある場合
|
|
94
|
-
if (element.content) {
|
|
95
|
-
const text = extractPlainText(element.content);
|
|
96
|
-
if (text) {
|
|
97
|
-
result.text = text;
|
|
98
|
-
const styles = extractStyles(element.content);
|
|
99
|
-
if (styles.fontSize !== undefined) {
|
|
100
|
-
result.fontPx = ptToPx(styles.fontSize);
|
|
101
|
-
}
|
|
102
|
-
if (styles.color) {
|
|
103
|
-
result.color = normalizeColor(styles.color);
|
|
104
|
-
}
|
|
105
|
-
if (styles.bold) {
|
|
106
|
-
result.bold = true;
|
|
107
|
-
}
|
|
108
|
-
if (styles.textAlign) {
|
|
109
|
-
result.alignText = styles.textAlign;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
// 塗りつぶし
|
|
114
|
-
if (element.fill && element.fill.type === "color") {
|
|
115
|
-
result.fill = {
|
|
116
|
-
color: normalizeColor(element.fill.value),
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
// 枠線
|
|
120
|
-
if (element.borderColor && element.borderWidth) {
|
|
121
|
-
result.line = {
|
|
122
|
-
color: normalizeColor(element.borderColor),
|
|
123
|
-
width: ptToPx(element.borderWidth),
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
// 影
|
|
127
|
-
if (element.shadow) {
|
|
128
|
-
result.shadow = {
|
|
129
|
-
type: "outer",
|
|
130
|
-
blur: element.shadow.blur,
|
|
131
|
-
offset: Math.sqrt(element.shadow.h * element.shadow.h +
|
|
132
|
-
element.shadow.v * element.shadow.v),
|
|
133
|
-
color: normalizeColor(element.shadow.color),
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convertTable.d.ts","sourceRoot":"","sources":["../../src/parsePptx/convertTable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAoC,MAAM,UAAU,CAAC;AAC5E,OAAO,KAAK,EAAE,KAAK,EAA8B,MAAM,SAAS,CAAC;AA2BjE;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,KAAK,GAAG,SAAS,CA2BtD"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { ptToPx, normalizeColor } from "./units";
|
|
2
|
-
import { extractPlainText } from "./parseHtml";
|
|
3
|
-
/**
|
|
4
|
-
* pptxtojsonのTableCell要素をPOMのTableCellに変換
|
|
5
|
-
*/
|
|
6
|
-
function convertCell(cell) {
|
|
7
|
-
const result = {
|
|
8
|
-
text: extractPlainText(cell.text),
|
|
9
|
-
};
|
|
10
|
-
if (cell.fontColor) {
|
|
11
|
-
result.color = normalizeColor(cell.fontColor);
|
|
12
|
-
}
|
|
13
|
-
if (cell.fontBold) {
|
|
14
|
-
result.bold = true;
|
|
15
|
-
}
|
|
16
|
-
if (cell.fillColor) {
|
|
17
|
-
result.backgroundColor = normalizeColor(cell.fillColor);
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* pptxtojsonのTable要素をPOMのTableNodeに変換
|
|
23
|
-
*/
|
|
24
|
-
export function convertTable(element) {
|
|
25
|
-
// 列幅の変換
|
|
26
|
-
const columns = element.colWidths.map((width) => ({
|
|
27
|
-
width: ptToPx(width),
|
|
28
|
-
}));
|
|
29
|
-
// 行データの変換
|
|
30
|
-
const rows = element.data.map((rowCells, rowIndex) => {
|
|
31
|
-
const cells = rowCells.map((cell) => convertCell(cell));
|
|
32
|
-
const row = { cells };
|
|
33
|
-
// 行の高さ
|
|
34
|
-
if (element.rowHeights && element.rowHeights[rowIndex]) {
|
|
35
|
-
row.height = ptToPx(element.rowHeights[rowIndex]);
|
|
36
|
-
}
|
|
37
|
-
return row;
|
|
38
|
-
});
|
|
39
|
-
return {
|
|
40
|
-
type: "table",
|
|
41
|
-
columns,
|
|
42
|
-
rows,
|
|
43
|
-
w: ptToPx(element.width),
|
|
44
|
-
h: ptToPx(element.height),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convertText.d.ts","sourceRoot":"","sources":["../../src/parsePptx/convertText.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAIpC;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,IAAI,GAAG,QAAQ,CAiCnD"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ptToPx, normalizeColor } from "./units";
|
|
2
|
-
import { extractPlainText, extractStyles } from "./parseHtml";
|
|
3
|
-
/**
|
|
4
|
-
* pptxtojsonのText要素をPOMのTextNodeに変換
|
|
5
|
-
*/
|
|
6
|
-
export function convertText(element) {
|
|
7
|
-
const text = extractPlainText(element.content);
|
|
8
|
-
const styles = extractStyles(element.content);
|
|
9
|
-
const result = {
|
|
10
|
-
type: "text",
|
|
11
|
-
text,
|
|
12
|
-
w: ptToPx(element.width),
|
|
13
|
-
h: ptToPx(element.height),
|
|
14
|
-
};
|
|
15
|
-
// スタイル情報を設定
|
|
16
|
-
if (styles.fontSize !== undefined) {
|
|
17
|
-
result.fontPx = ptToPx(styles.fontSize);
|
|
18
|
-
}
|
|
19
|
-
if (styles.color) {
|
|
20
|
-
result.color = normalizeColor(styles.color);
|
|
21
|
-
}
|
|
22
|
-
if (styles.bold) {
|
|
23
|
-
result.bold = true;
|
|
24
|
-
}
|
|
25
|
-
if (styles.textAlign) {
|
|
26
|
-
result.alignText = styles.textAlign;
|
|
27
|
-
}
|
|
28
|
-
if (styles.fontFamily) {
|
|
29
|
-
result.fontFamily = styles.fontFamily;
|
|
30
|
-
}
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { ParsedPptx, ParsePptxOptions } from "./types";
|
|
2
|
-
export type { ParsedPptx, ParsePptxOptions };
|
|
3
|
-
/**
|
|
4
|
-
* PPTXファイルを解析してPOMNode[]に変換
|
|
5
|
-
*
|
|
6
|
-
* @param data - PPTXファイルのバイナリデータ
|
|
7
|
-
* @param options - 解析オプション
|
|
8
|
-
* @returns ParsedPptx - 解析結果
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { parsePptx } from "@hirokisakabe/pom";
|
|
13
|
-
* import fs from "fs";
|
|
14
|
-
*
|
|
15
|
-
* const data = new Uint8Array(fs.readFileSync("presentation.pptx"));
|
|
16
|
-
* const result = await parsePptx(data);
|
|
17
|
-
*
|
|
18
|
-
* console.log(`スライド数: ${result.slides.length}`);
|
|
19
|
-
* console.log(`サイズ: ${result.metadata.slideWidth}x${result.metadata.slideHeight}`);
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare function parsePptx(data: Uint8Array, options?: ParsePptxOptions): Promise<ParsedPptx>;
|
|
23
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parsePptx/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAkB,MAAM,SAAS,CAAC;AAQ5E,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC;AA4E7C;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,UAAU,EAChB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,UAAU,CAAC,CAmCrB"}
|
package/dist/parsePptx/index.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import * as pptxtojson from "pptxtojson";
|
|
2
|
-
import { ptToPx } from "./units";
|
|
3
|
-
import { convertText } from "./convertText";
|
|
4
|
-
import { convertImage } from "./convertImage";
|
|
5
|
-
import { convertShape } from "./convertShape";
|
|
6
|
-
import { convertTable } from "./convertTable";
|
|
7
|
-
import { convertChart } from "./convertChart";
|
|
8
|
-
/**
|
|
9
|
-
* サポートされる要素タイプ
|
|
10
|
-
*/
|
|
11
|
-
const SUPPORTED_ELEMENT_TYPES = ["text", "image", "shape", "table", "chart"];
|
|
12
|
-
/**
|
|
13
|
-
* 要素がサポートされているかチェック
|
|
14
|
-
*/
|
|
15
|
-
function isSupported(element) {
|
|
16
|
-
return SUPPORTED_ELEMENT_TYPES.includes(element.type);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* pptxtojsonの要素をPOMNodeに変換
|
|
20
|
-
*/
|
|
21
|
-
function convertElement(element) {
|
|
22
|
-
switch (element.type) {
|
|
23
|
-
case "text":
|
|
24
|
-
return convertText(element);
|
|
25
|
-
case "image":
|
|
26
|
-
return convertImage(element);
|
|
27
|
-
case "shape":
|
|
28
|
-
return convertShape(element);
|
|
29
|
-
case "table":
|
|
30
|
-
return convertTable(element);
|
|
31
|
-
case "chart":
|
|
32
|
-
return convertChart(element);
|
|
33
|
-
case "group":
|
|
34
|
-
// グループ内の要素をフラット化して返す(最初の要素のみ)
|
|
35
|
-
// 注: グループ全体を適切に処理するには追加の実装が必要
|
|
36
|
-
return null;
|
|
37
|
-
case "diagram":
|
|
38
|
-
// diagramはフラット化してshapeとして扱う可能性があるが、
|
|
39
|
-
// 現時点では未対応
|
|
40
|
-
return null;
|
|
41
|
-
default:
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* スライドをPOMNodeに変換
|
|
47
|
-
* 各スライドはVStackとして返す
|
|
48
|
-
*/
|
|
49
|
-
function convertSlide(slide, slideWidth, slideHeight) {
|
|
50
|
-
const children = [];
|
|
51
|
-
// 要素をorder順にソート
|
|
52
|
-
const sortedElements = [...slide.elements]
|
|
53
|
-
.filter(isSupported)
|
|
54
|
-
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
55
|
-
for (const element of sortedElements) {
|
|
56
|
-
const node = convertElement(element);
|
|
57
|
-
if (node) {
|
|
58
|
-
children.push(node);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// VStackでラップして返す
|
|
62
|
-
const result = {
|
|
63
|
-
type: "vstack",
|
|
64
|
-
w: slideWidth,
|
|
65
|
-
h: slideHeight,
|
|
66
|
-
children,
|
|
67
|
-
};
|
|
68
|
-
return result;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* PPTXファイルを解析してPOMNode[]に変換
|
|
72
|
-
*
|
|
73
|
-
* @param data - PPTXファイルのバイナリデータ
|
|
74
|
-
* @param options - 解析オプション
|
|
75
|
-
* @returns ParsedPptx - 解析結果
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```typescript
|
|
79
|
-
* import { parsePptx } from "@hirokisakabe/pom";
|
|
80
|
-
* import fs from "fs";
|
|
81
|
-
*
|
|
82
|
-
* const data = new Uint8Array(fs.readFileSync("presentation.pptx"));
|
|
83
|
-
* const result = await parsePptx(data);
|
|
84
|
-
*
|
|
85
|
-
* console.log(`スライド数: ${result.slides.length}`);
|
|
86
|
-
* console.log(`サイズ: ${result.metadata.slideWidth}x${result.metadata.slideHeight}`);
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
export async function parsePptx(data, options) {
|
|
90
|
-
// Uint8ArrayをArrayBufferに変換
|
|
91
|
-
const arrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
92
|
-
// pptxtojsonでパース
|
|
93
|
-
const result = await pptxtojson.parse(arrayBuffer, {
|
|
94
|
-
slideFactor: options?.slideFactor,
|
|
95
|
-
fontsizeFactor: options?.fontsizeFactor,
|
|
96
|
-
});
|
|
97
|
-
// スライドサイズをpxに変換
|
|
98
|
-
const slideWidth = ptToPx(result.size.width);
|
|
99
|
-
const slideHeight = ptToPx(result.size.height);
|
|
100
|
-
// 各スライドをPOMNodeに変換
|
|
101
|
-
const slides = result.slides.map((slide) => convertSlide(slide, slideWidth, slideHeight));
|
|
102
|
-
// 画像を収集
|
|
103
|
-
const images = new Map();
|
|
104
|
-
// 注: pptxtojsonは画像をBase64文字列として提供するため、
|
|
105
|
-
// 必要に応じてUint8Arrayに変換して保存する実装が必要
|
|
106
|
-
return {
|
|
107
|
-
slides,
|
|
108
|
-
images,
|
|
109
|
-
metadata: {
|
|
110
|
-
slideWidth,
|
|
111
|
-
slideHeight,
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pptxtojsonのテキスト要素はHTML形式でスタイル情報を含んでいる
|
|
3
|
-
* このモジュールはHTMLからテキストとスタイル情報を抽出する
|
|
4
|
-
*/
|
|
5
|
-
export interface ExtractedStyles {
|
|
6
|
-
fontSize?: number;
|
|
7
|
-
color?: string;
|
|
8
|
-
bold?: boolean;
|
|
9
|
-
textAlign?: "left" | "center" | "right";
|
|
10
|
-
fontFamily?: string;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* HTMLコンテンツからプレーンテキストを抽出
|
|
14
|
-
* <p>タグは改行、<br>は改行、それ以外のタグは除去
|
|
15
|
-
*/
|
|
16
|
-
export declare function extractPlainText(html: string): string;
|
|
17
|
-
/**
|
|
18
|
-
* HTMLのstyle属性からスタイル情報を抽出
|
|
19
|
-
* 最初に見つかったスタイルを使用(複数スタイルの場合は最初のもの)
|
|
20
|
-
*/
|
|
21
|
-
export declare function extractStyles(html: string): ExtractedStyles;
|
|
22
|
-
//# sourceMappingURL=parseHtml.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parseHtml.d.ts","sourceRoot":"","sources":["../../src/parsePptx/parseHtml.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAWrD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAkC3D"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pptxtojsonのテキスト要素はHTML形式でスタイル情報を含んでいる
|
|
3
|
-
* このモジュールはHTMLからテキストとスタイル情報を抽出する
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* HTMLコンテンツからプレーンテキストを抽出
|
|
7
|
-
* <p>タグは改行、<br>は改行、それ以外のタグは除去
|
|
8
|
-
*/
|
|
9
|
-
export function extractPlainText(html) {
|
|
10
|
-
return html
|
|
11
|
-
.replace(/<br\s*\/?>/gi, "\n")
|
|
12
|
-
.replace(/<\/p>/gi, "\n")
|
|
13
|
-
.replace(/<[^>]+>/g, "")
|
|
14
|
-
.replace(/ /gi, " ")
|
|
15
|
-
.replace(/</gi, "<")
|
|
16
|
-
.replace(/>/gi, ">")
|
|
17
|
-
.replace(/&/gi, "&")
|
|
18
|
-
.replace(/"/gi, '"')
|
|
19
|
-
.trim();
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* HTMLのstyle属性からスタイル情報を抽出
|
|
23
|
-
* 最初に見つかったスタイルを使用(複数スタイルの場合は最初のもの)
|
|
24
|
-
*/
|
|
25
|
-
export function extractStyles(html) {
|
|
26
|
-
const result = {};
|
|
27
|
-
// font-size: Npt
|
|
28
|
-
const fontSizeMatch = html.match(/font-size:\s*(\d+(?:\.\d+)?)pt/i);
|
|
29
|
-
if (fontSizeMatch) {
|
|
30
|
-
result.fontSize = parseFloat(fontSizeMatch[1]);
|
|
31
|
-
}
|
|
32
|
-
// color: #XXXXXX or rgb(...)
|
|
33
|
-
const colorMatch = html.match(/(?:^|[^-])color:\s*(#[0-9A-Fa-f]{6})/i);
|
|
34
|
-
if (colorMatch) {
|
|
35
|
-
result.color = colorMatch[1];
|
|
36
|
-
}
|
|
37
|
-
// font-weight: bold
|
|
38
|
-
const boldMatch = html.match(/font-weight:\s*bold/i);
|
|
39
|
-
if (boldMatch) {
|
|
40
|
-
result.bold = true;
|
|
41
|
-
}
|
|
42
|
-
// text-align: left|center|right
|
|
43
|
-
const textAlignMatch = html.match(/text-align:\s*(left|center|right)/i);
|
|
44
|
-
if (textAlignMatch) {
|
|
45
|
-
result.textAlign = textAlignMatch[1];
|
|
46
|
-
}
|
|
47
|
-
// font-family
|
|
48
|
-
const fontFamilyMatch = html.match(/font-family:\s*["']?([^;"']+)/i);
|
|
49
|
-
if (fontFamilyMatch) {
|
|
50
|
-
result.fontFamily = fontFamilyMatch[1].trim();
|
|
51
|
-
}
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { POMNode } from "../types";
|
|
2
|
-
export type { Slide, Element, BaseElement, Text, Image, Shape, Table, TableCell, Chart, CommonChart, ScatterChart, ChartItem, ChartValue, ChartType, Fill, ColorFill, ImageFill, GradientFill, PatternFill, Shadow, Border, Group, Diagram, Video, Audio, Math, } from "pptxtojson";
|
|
3
|
-
export type ParsedPptx = {
|
|
4
|
-
slides: POMNode[];
|
|
5
|
-
images: Map<string, Uint8Array>;
|
|
6
|
-
metadata: {
|
|
7
|
-
slideWidth: number;
|
|
8
|
-
slideHeight: number;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
export type ParsePptxOptions = {
|
|
12
|
-
slideFactor?: number;
|
|
13
|
-
fontsizeFactor?: number;
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/parsePptx/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,YAAY,EACV,KAAK,EACL,OAAO,EACP,WAAW,EACX,IAAI,EACJ,KAAK,EACL,KAAK,EACL,KAAK,EACL,SAAS,EACT,KAAK,EACL,WAAW,EACX,YAAY,EACZ,SAAS,EACT,UAAU,EACV,SAAS,EACT,IAAI,EACJ,SAAS,EACT,SAAS,EACT,YAAY,EACZ,WAAW,EACX,MAAM,EACN,MAAM,EACN,KAAK,EACL,OAAO,EACP,KAAK,EACL,KAAK,EACL,IAAI,GACL,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAChC,QAAQ,EAAE;QACR,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC"}
|
package/dist/parsePptx/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ポイント(pt)からピクセル(px)への変換
|
|
3
|
-
* pptxtojsonはpt単位で出力する
|
|
4
|
-
* 変換式: pt × 4/3 = px (96 DPI基準)
|
|
5
|
-
*/
|
|
6
|
-
export declare function ptToPx(pt: number): number;
|
|
7
|
-
/**
|
|
8
|
-
* カラーコードの正規化
|
|
9
|
-
* "#FF0000" → "FF0000"
|
|
10
|
-
* pomでは#なしの16進数カラーコードを使用する
|
|
11
|
-
*/
|
|
12
|
-
export declare function normalizeColor(color: string): string;
|
|
13
|
-
//# sourceMappingURL=units.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src/parsePptx/units.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKpD"}
|