@osbjs/osbjs
Version:
a minimalist osu! storyboarding framework
45 lines (44 loc) • 2.07 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getImageDimensions = exports.parseOsuTimestamp = exports.rgbToHex = void 0;
const image_size_1 = __importDefault(require("image-size"));
__exportStar(require("./OsbColor"), exports);
__exportStar(require("./OsbVector2"), exports);
__exportStar(require("./SubtitleCollection"), exports);
function rgbToHex(r, g, b) {
if (typeof r !== 'number' || typeof g !== 'number' || typeof b !== 'number' || r > 255 || g > 255 || b > 255) {
throw new TypeError('Expected three numbers below 256');
}
return '#' + (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1);
}
exports.rgbToHex = rgbToHex;
function parseOsuTimestamp(timestamp) {
const match = timestamp.match(/^(\d{2,}):(\d{2}):(\d{3})$/);
if (!match) {
throw new Error('Invalid osu timestamp format: "' + timestamp + '"');
}
const minutes = match[1] ? parseInt(match[1], 10) * 60000 : 0;
const seconds = parseInt(match[2], 10) * 1000;
const milliseconds = parseInt(match[3], 10);
return minutes + seconds + milliseconds;
}
exports.parseOsuTimestamp = parseOsuTimestamp;
/** alias for imageSize */
function getImageDimensions(path) {
const { width, height } = (0, image_size_1.default)(path);
return { width, height };
}
exports.getImageDimensions = getImageDimensions;