Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/salty-squids-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@hirokisakabe/pom": patch
---

fix: ESM 環境での import 拡張子問題を修正

- TypeScript の `moduleResolution: NodeNext` と `rewriteRelativeImportExtensions` を使用して、ビルド時に相対 import に `.js` 拡張子を自動追加
- これにより `@hirokisakabe/pom/schema` を ESM 環境でインポートした際に発生していた `ERR_MODULE_NOT_FOUND` エラーを解消
10 changes: 5 additions & 5 deletions src/buildPptx.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { calcYogaLayout } from "./calcYogaLayout/calcYogaLayout";
import { calcYogaLayout } from "./calcYogaLayout/calcYogaLayout.ts";
import {
setTextMeasurementMode,
TextMeasurementMode,
} from "./calcYogaLayout/measureText";
import { renderPptx } from "./renderPptx/renderPptx";
import { toPositioned } from "./toPositioned/toPositioned";
import { POMNode, PositionedNode, SlideMasterOptions } from "./types";
} from "./calcYogaLayout/measureText.ts";
import { renderPptx } from "./renderPptx/renderPptx.ts";
import { toPositioned } from "./toPositioned/toPositioned.ts";
import { POMNode, PositionedNode, SlideMasterOptions } from "./types.ts";

export type { TextMeasurementMode };

Expand Down
10 changes: 5 additions & 5 deletions src/calcYogaLayout/calcYogaLayout.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { POMNode, VStackNode, HStackNode } from "../types";
import type { POMNode, VStackNode, HStackNode } from "../types.ts";
import { Node as YogaNode } from "yoga-layout";
import { loadYoga } from "yoga-layout/load";
import { measureText } from "./measureText";
import { measureImage, prefetchImageSize } from "./measureImage";
import { calcTableIntrinsicSize } from "../table/utils";
import { measureText } from "./measureText.ts";
import { measureImage, prefetchImageSize } from "./measureImage.ts";
import { calcTableIntrinsicSize } from "../table/utils.ts";
import {
measureProcessArrow,
measureTimeline,
measureMatrix,
measureTree,
measureFlow,
} from "./measureCompositeNodes";
} from "./measureCompositeNodes.ts";

/**
* POMNode ツリーを Yoga でレイアウト計算する
Expand Down
4 changes: 2 additions & 2 deletions src/calcYogaLayout/fontLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

import opentype, { Font } from "opentype.js";
import { NOTO_SANS_JP_REGULAR_BASE64 } from "./fonts/notoSansJPRegular.js";
import { NOTO_SANS_JP_BOLD_BASE64 } from "./fonts/notoSansJPBold.js";
import { NOTO_SANS_JP_REGULAR_BASE64 } from "./fonts/notoSansJPRegular.ts";
import { NOTO_SANS_JP_BOLD_BASE64 } from "./fonts/notoSansJPBold.ts";

// フォントキャッシュ
const fontCache = new Map<string, Font>();
Expand Down
2 changes: 1 addition & 1 deletion src/calcYogaLayout/measureCompositeNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
TreeNode,
FlowNode,
TreeDataItem,
} from "../types";
} from "../types.ts";

/**
* ProcessArrow ノードの intrinsic size を計算する
Expand Down
11 changes: 10 additions & 1 deletion src/calcYogaLayout/measureImage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import imageSize from "image-size";
import { createRequire } from "module";
import * as fs from "fs";

const require = createRequire(import.meta.url);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const imageSizeModule = require("image-size");
// CommonJS モジュールは .default または直接エクスポートされる場合がある
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
const imageSize: typeof import("image-size").default =
imageSizeModule.default ?? imageSizeModule;
/* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */

/**
* 画像サイズのキャッシュ(事前取得した画像サイズを保持)
*/
Expand Down
2 changes: 1 addition & 1 deletion src/calcYogaLayout/measureText.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { measureTextWidth as measureTextWidthOpentype } from "./fontLoader.js";
import { measureTextWidth as measureTextWidthOpentype } from "./fontLoader.ts";

type MeasureOptions = {
fontFamily: string;
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./types";
export * from "./inputSchema";
export { buildPptx } from "./buildPptx";
export type { TextMeasurementMode } from "./buildPptx";
export * from "./types.ts";
export * from "./inputSchema.ts";
export { buildPptx } from "./buildPptx.ts";
export type { TextMeasurementMode } from "./buildPptx.ts";
2 changes: 1 addition & 1 deletion src/inputSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {
type AlignItems,
type JustifyContent,
type TreeDataItem,
} from "./types";
} from "./types.ts";

// ===== Base Node Schema =====
export const inputBaseNodeSchema = z.object({
Expand Down
6 changes: 3 additions & 3 deletions src/renderPptx/nodes/chart.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PositionedNode } from "../../types";
import type { RenderContext } from "../types";
import { pxToIn } from "../units";
import type { PositionedNode } from "../../types.ts";
import type { RenderContext } from "../types.ts";
import { pxToIn } from "../units.ts";

type ChartPositionedNode = Extract<PositionedNode, { type: "chart" }>;

Expand Down
6 changes: 3 additions & 3 deletions src/renderPptx/nodes/flow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PositionedNode } from "../../types";
import type { RenderContext } from "../types";
import { pxToIn, pxToPt } from "../units";
import type { PositionedNode } from "../../types.ts";
import type { RenderContext } from "../types.ts";
import { pxToIn, pxToPt } from "../units.ts";

type FlowPositionedNode = Extract<PositionedNode, { type: "flow" }>;

Expand Down
6 changes: 3 additions & 3 deletions src/renderPptx/nodes/image.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PositionedNode } from "../../types";
import type { RenderContext } from "../types";
import { pxToIn } from "../units";
import type { PositionedNode } from "../../types.ts";
import type { RenderContext } from "../types.ts";
import { pxToIn } from "../units.ts";

type ImagePositionedNode = Extract<PositionedNode, { type: "image" }>;

Expand Down
22 changes: 11 additions & 11 deletions src/renderPptx/nodes/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export { renderTextNode } from "./text";
export { renderImageNode } from "./image";
export { renderTableNode } from "./table";
export { renderShapeNode } from "./shape";
export { renderChartNode } from "./chart";
export { renderTimelineNode } from "./timeline";
export { renderMatrixNode } from "./matrix";
export { renderTreeNode } from "./tree";
export { renderFlowNode } from "./flow";
export { renderProcessArrowNode } from "./processArrow";
export { renderLineNode } from "./line";
export { renderTextNode } from "./text.ts";
export { renderImageNode } from "./image.ts";
export { renderTableNode } from "./table.ts";
export { renderShapeNode } from "./shape.ts";
export { renderChartNode } from "./chart.ts";
export { renderTimelineNode } from "./timeline.ts";
export { renderMatrixNode } from "./matrix.ts";
export { renderTreeNode } from "./tree.ts";
export { renderFlowNode } from "./flow.ts";
export { renderProcessArrowNode } from "./processArrow.ts";
export { renderLineNode } from "./line.ts";
6 changes: 3 additions & 3 deletions src/renderPptx/nodes/line.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PositionedNode, LineArrow } from "../../types";
import type { RenderContext } from "../types";
import { pxToIn, pxToPt } from "../units";
import type { PositionedNode, LineArrow } from "../../types.ts";
import type { RenderContext } from "../types.ts";
import { pxToIn, pxToPt } from "../units.ts";

type LinePositionedNode = Extract<PositionedNode, { type: "line" }>;

Expand Down
6 changes: 3 additions & 3 deletions src/renderPptx/nodes/matrix.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PositionedNode } from "../../types";
import type { RenderContext } from "../types";
import { pxToIn, pxToPt } from "../units";
import type { PositionedNode } from "../../types.ts";
import type { RenderContext } from "../types.ts";
import { pxToIn, pxToPt } from "../units.ts";

type MatrixPositionedNode = Extract<PositionedNode, { type: "matrix" }>;

Expand Down
6 changes: 3 additions & 3 deletions src/renderPptx/nodes/processArrow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PositionedNode } from "../../types";
import type { RenderContext } from "../types";
import { pxToIn, pxToPt } from "../units";
import type { PositionedNode } from "../../types.ts";
import type { RenderContext } from "../types.ts";
import { pxToIn, pxToPt } from "../units.ts";

type ProcessArrowPositionedNode = Extract<
PositionedNode,
Expand Down
6 changes: 3 additions & 3 deletions src/renderPptx/nodes/shape.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PositionedNode } from "../../types";
import type { RenderContext } from "../types";
import { pxToIn, pxToPt } from "../units";
import type { PositionedNode } from "../../types.ts";
import type { RenderContext } from "../types.ts";
import { pxToIn, pxToPt } from "../units.ts";

type ShapePositionedNode = Extract<PositionedNode, { type: "shape" }>;

Expand Down
8 changes: 4 additions & 4 deletions src/renderPptx/nodes/table.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PositionedNode } from "../../types";
import type { RenderContext } from "../types";
import { resolveColumnWidths, resolveRowHeights } from "../../table/utils";
import { pxToIn, pxToPt } from "../units";
import type { PositionedNode } from "../../types.ts";
import type { RenderContext } from "../types.ts";
import { resolveColumnWidths, resolveRowHeights } from "../../table/utils.ts";
import { pxToIn, pxToPt } from "../units.ts";

type TablePositionedNode = Extract<PositionedNode, { type: "table" }>;

Expand Down
6 changes: 3 additions & 3 deletions src/renderPptx/nodes/text.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PositionedNode } from "../../types";
import type { RenderContext } from "../types";
import { createTextOptions } from "../textOptions";
import type { PositionedNode } from "../../types.ts";
import type { RenderContext } from "../types.ts";
import { createTextOptions } from "../textOptions.ts";

type TextPositionedNode = Extract<PositionedNode, { type: "text" }>;

Expand Down
6 changes: 3 additions & 3 deletions src/renderPptx/nodes/timeline.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PositionedNode } from "../../types";
import type { RenderContext } from "../types";
import { pxToIn, pxToPt } from "../units";
import type { PositionedNode } from "../../types.ts";
import type { RenderContext } from "../types.ts";
import { pxToIn, pxToPt } from "../units.ts";

type TimelinePositionedNode = Extract<PositionedNode, { type: "timeline" }>;

Expand Down
6 changes: 3 additions & 3 deletions src/renderPptx/nodes/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type {
TreeDataItem,
TreeNodeShape,
TreeConnectorStyle,
} from "../../types";
import type { RenderContext } from "../types";
import { pxToIn, pxToPt } from "../units";
} from "../../types.ts";
import type { RenderContext } from "../types.ts";
import { pxToIn, pxToPt } from "../units.ts";

type TreePositionedNode = Extract<PositionedNode, { type: "tree" }>;

Expand Down
2 changes: 1 addition & 1 deletion src/renderPptx/renderPptx.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect } from "vitest";
import { PX_PER_IN, pxToIn, pxToPt } from "./renderPptx";
import { PX_PER_IN, pxToIn, pxToPt } from "./renderPptx.ts";

describe("PX_PER_IN", () => {
it("96である", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/renderPptx/renderPptx.textOptions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { createTextOptions } from "./textOptions";
import { pxToIn, pxToPt } from "./units";
import { createTextOptions } from "./textOptions.ts";
import { pxToIn, pxToPt } from "./units.ts";

describe("createTextOptions", () => {
it("指定した色と配置をオプションに反映する", () => {
Expand Down
45 changes: 30 additions & 15 deletions src/renderPptx/renderPptx.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import { createRequire } from "module";

// pptxgenjs の型定義(NodeNext 互換)
type PptxGenJSInstance = import("pptxgenjs").default;

const require = createRequire(import.meta.url);
import type PptxGenJSType from "pptxgenjs";
const PptxGenJS = require("pptxgenjs") as typeof PptxGenJSType;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const pptxModule = require("pptxgenjs");
// CommonJS モジュールは .default または直接エクスポートされる場合がある
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
const PptxGenJS: new () => PptxGenJSInstance = pptxModule.default ?? pptxModule;
/* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
type SlideMasterProps = Parameters<PptxGenJSInstance["defineSlideMaster"]>[0];
type ImageProps = {
x: number;
y: number;
w: number;
h: number;
path?: string;
data?: string;
};
import type {
PositionedNode,
SlideMasterOptions,
MasterObject,
} from "../types";
import type { RenderContext } from "./types";
import { pxToIn, pxToPt } from "./units";
import { renderBackgroundAndBorder } from "./utils/backgroundBorder";
} from "../types.ts";
import type { RenderContext } from "./types.ts";
import { pxToIn, pxToPt } from "./units.ts";
import { renderBackgroundAndBorder } from "./utils/backgroundBorder.ts";
import {
renderTextNode,
renderImageNode,
Expand All @@ -22,11 +39,11 @@ import {
renderFlowNode,
renderProcessArrowNode,
renderLineNode,
} from "./nodes";
} from "./nodes/index.ts";

type SlidePx = { w: number; h: number };
export { createTextOptions } from "./textOptions";
export { PX_PER_IN, pxToIn, pxToPt } from "./units";
export { createTextOptions } from "./textOptions.ts";
export { PX_PER_IN, pxToIn, pxToPt } from "./units.ts";

const DEFAULT_MASTER_NAME = "POM_MASTER";

Expand All @@ -35,9 +52,7 @@ const DEFAULT_MASTER_NAME = "POM_MASTER";
*/
function convertMasterObject(
obj: MasterObject,
): PptxGenJSType.SlideMasterProps["objects"] extends (infer T)[] | undefined
? T
: never {
): SlideMasterProps["objects"] extends (infer T)[] | undefined ? T : never {
switch (obj.type) {
case "text":
return {
Expand All @@ -57,7 +72,7 @@ function convertMasterObject(
},
};
case "image": {
const imageProps: PptxGenJSType.ImageProps = {
const imageProps: ImageProps = {
x: pxToIn(obj.x),
y: pxToIn(obj.y),
w: pxToIn(obj.w),
Expand Down Expand Up @@ -113,12 +128,12 @@ function convertMasterObject(
* SlideMasterOptions から pptxgenjs の defineSlideMaster を呼び出す
*/
function defineSlideMasterFromOptions(
pptx: PptxGenJSType,
pptx: PptxGenJSInstance,
master: SlideMasterOptions,
): string {
const masterName = master.title || DEFAULT_MASTER_NAME;

const masterProps: PptxGenJSType.SlideMasterProps = {
const masterProps: SlideMasterProps = {
title: masterName,
};

Expand Down
4 changes: 2 additions & 2 deletions src/renderPptx/textOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PositionedNode, BulletOptions } from "../types";
import { pxToIn, pxToPt } from "./units";
import type { PositionedNode, BulletOptions } from "../types.ts";
import { pxToIn, pxToPt } from "./units.ts";

type TextNode = Extract<PositionedNode, { type: "text" }>;

Expand Down
10 changes: 4 additions & 6 deletions src/renderPptx/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type PptxGenJSType from "pptxgenjs";
import type { PositionedNode } from "../types";
import type { PositionedNode } from "../types.ts";

export type SlideInstance = ReturnType<
InstanceType<typeof PptxGenJSType>["addSlide"]
>;
export type PptxInstance = InstanceType<typeof PptxGenJSType>;
type PptxGenJSClass = import("pptxgenjs").default;
export type SlideInstance = ReturnType<PptxGenJSClass["addSlide"]>;
export type PptxInstance = PptxGenJSClass;

export type RenderContext = {
slide: SlideInstance;
Expand Down
6 changes: 3 additions & 3 deletions src/renderPptx/utils/backgroundBorder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PositionedNode } from "../../types";
import type { RenderContext } from "../types";
import { pxToIn, pxToPt } from "../units";
import type { PositionedNode } from "../../types.ts";
import type { RenderContext } from "../types.ts";
import { pxToIn, pxToPt } from "../units.ts";

/**
* ノードの背景色とボーダーを描画する
Expand Down
10 changes: 5 additions & 5 deletions src/renderPptx/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { renderBackgroundAndBorder } from "./backgroundBorder";
export { drawCircle, drawLine } from "./shapeDrawing";
export type { CircleOptions, LineOptions } from "./shapeDrawing";
export { drawSimpleText } from "./textDrawing";
export type { SimpleTextOptions } from "./textDrawing";
export { renderBackgroundAndBorder } from "./backgroundBorder.ts";
export { drawCircle, drawLine } from "./shapeDrawing.ts";
export type { CircleOptions, LineOptions } from "./shapeDrawing.ts";
export { drawSimpleText } from "./textDrawing.ts";
export type { SimpleTextOptions } from "./textDrawing.ts";
Loading