@mobilenext/mobile-mcp 1.0.1 → 1.0.3

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.
@@ -1,155 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isScalingAvailable = exports.isImageMagickInstalled = exports.isSipsInstalled = exports.Image = exports.ImageTransformer = void 0;
7
- const child_process_1 = require("child_process");
8
- const node_os_1 = __importDefault(require("node:os"));
9
- const node_fs_1 = __importDefault(require("node:fs"));
10
- const node_path_1 = __importDefault(require("node:path"));
11
- const logger_1 = require("./logger");
12
- const DEFAULT_JPEG_QUALITY = 75;
13
- class ImageTransformer {
14
- buffer;
15
- newWidth = 0;
16
- newFormat = "png";
17
- jpegOptions = { quality: DEFAULT_JPEG_QUALITY };
18
- constructor(buffer) {
19
- this.buffer = buffer;
20
- }
21
- resize(width) {
22
- this.newWidth = width;
23
- return this;
24
- }
25
- jpeg(options) {
26
- this.newFormat = "jpg";
27
- this.jpegOptions = options;
28
- return this;
29
- }
30
- png() {
31
- this.newFormat = "png";
32
- return this;
33
- }
34
- toBuffer() {
35
- if ((0, exports.isSipsInstalled)()) {
36
- try {
37
- return this.toBufferWithSips();
38
- }
39
- catch (error) {
40
- (0, logger_1.trace)(`Sips failed, falling back to ImageMagick: ${error}`);
41
- }
42
- }
43
- try {
44
- return this.toBufferWithImageMagick();
45
- }
46
- catch (error) {
47
- (0, logger_1.trace)(`ImageMagick failed: ${error}`);
48
- throw new Error("Image scaling unavailable (requires Sips or ImageMagick).");
49
- }
50
- }
51
- qualityToSips(q) {
52
- if (q >= 90) {
53
- return "best";
54
- }
55
- if (q >= 75) {
56
- return "high";
57
- }
58
- if (q >= 50) {
59
- return "normal";
60
- }
61
- return "low";
62
- }
63
- toBufferWithSips() {
64
- const tempDir = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "image-"));
65
- const inputFile = node_path_1.default.join(tempDir, "input");
66
- const outputFile = node_path_1.default.join(tempDir, `output.${this.newFormat === "jpg" ? "jpg" : "png"}`);
67
- try {
68
- node_fs_1.default.writeFileSync(inputFile, this.buffer);
69
- const args = ["-s", "format", this.newFormat === "jpg" ? "jpeg" : "png"];
70
- if (this.newFormat === "jpg") {
71
- args.push("-s", "formatOptions", this.qualityToSips(this.jpegOptions.quality));
72
- }
73
- args.push("-Z", `${this.newWidth}`);
74
- args.push("--out", outputFile);
75
- args.push(inputFile);
76
- (0, logger_1.trace)(`Running sips command: /usr/bin/sips ${args.join(" ")}`);
77
- const proc = (0, child_process_1.spawnSync)("/usr/bin/sips", args, {
78
- maxBuffer: 8 * 1024 * 1024
79
- });
80
- if (proc.status !== 0) {
81
- throw new Error(`Sips failed with status ${proc.status}`);
82
- }
83
- const outputBuffer = node_fs_1.default.readFileSync(outputFile);
84
- (0, logger_1.trace)("Sips returned buffer of size: " + outputBuffer.length);
85
- return outputBuffer;
86
- }
87
- finally {
88
- try {
89
- node_fs_1.default.rmSync(tempDir, { recursive: true, force: true });
90
- }
91
- catch (error) {
92
- // Ignore cleanup errors
93
- }
94
- }
95
- }
96
- toBufferWithImageMagick() {
97
- const magickArgs = ["-", "-resize", `${this.newWidth}x`, "-quality", `${this.jpegOptions.quality}`, `${this.newFormat}:-`];
98
- (0, logger_1.trace)(`Running magick command: magick ${magickArgs.join(" ")}`);
99
- const proc = (0, child_process_1.spawnSync)("magick", magickArgs, {
100
- maxBuffer: 8 * 1024 * 1024,
101
- input: this.buffer
102
- });
103
- return proc.stdout;
104
- }
105
- }
106
- exports.ImageTransformer = ImageTransformer;
107
- class Image {
108
- buffer;
109
- constructor(buffer) {
110
- this.buffer = buffer;
111
- }
112
- static fromBuffer(buffer) {
113
- return new Image(buffer);
114
- }
115
- resize(width) {
116
- return new ImageTransformer(this.buffer).resize(width);
117
- }
118
- jpeg(options) {
119
- return new ImageTransformer(this.buffer).jpeg(options);
120
- }
121
- }
122
- exports.Image = Image;
123
- const isDarwin = () => {
124
- return node_os_1.default.platform() === "darwin";
125
- };
126
- const isSipsInstalled = () => {
127
- if (!isDarwin()) {
128
- return false;
129
- }
130
- try {
131
- (0, child_process_1.execFileSync)("/usr/bin/sips", ["--version"]);
132
- return true;
133
- }
134
- catch (error) {
135
- return false;
136
- }
137
- };
138
- exports.isSipsInstalled = isSipsInstalled;
139
- const isImageMagickInstalled = () => {
140
- try {
141
- return (0, child_process_1.execFileSync)("magick", ["--version"])
142
- .toString()
143
- .split("\n")
144
- .filter(line => line.includes("Version: ImageMagick"))
145
- .length > 0;
146
- }
147
- catch (error) {
148
- return false;
149
- }
150
- };
151
- exports.isImageMagickInstalled = isImageMagickInstalled;
152
- const isScalingAvailable = () => {
153
- return (0, exports.isImageMagickInstalled)() || (0, exports.isSipsInstalled)();
154
- };
155
- exports.isScalingAvailable = isScalingAvailable;