Files
bare-operating-system/kernel/lib/bare/bundles/bareSdl.js
T
2026-04-04 01:20:57 -04:00

709 lines
23 KiB
JavaScript

var __bare_os_bundle_exports__ = (() => {
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined") return require.apply(this, arguments);
throw Error('Dynamic require of "' + x + '" is not supported');
});
var __commonJS = (cb, mod) => function __require2() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// ../../node_modules/bare-sdl/binding.js
var require_binding = __commonJS({
"../../node_modules/bare-sdl/binding.js"(exports, module) {
module.exports = __require.addon();
}
});
// ../../node_modules/bare-sdl/lib/constants.js
var require_constants = __commonJS({
"../../node_modules/bare-sdl/lib/constants.js"(exports, module) {
var binding = require_binding();
module.exports = binding.constants;
}
});
// ../../node_modules/bare-sdl/lib/audio-device.js
var require_audio_device = __commonJS({
"../../node_modules/bare-sdl/lib/audio-device.js"(exports, module) {
var binding = require_binding();
var constants = binding.constants;
var SDLAudioSpec = class {
constructor(format) {
this._format = format;
}
get format() {
return binding.getAudioDeviceFormatFormat(this._format._handle);
}
get channels() {
return binding.getAudioDeviceFormatChannels(this._format._handle);
}
get freq() {
return binding.getAudioDeviceFormatFreq(this._format._handle);
}
toJSON() {
return {
format: this.format,
channels: this.channels,
freq: this.freq
};
}
};
var SDLAudioDeviceFormat = class {
constructor(deviceId) {
this._handle = binding.getAudioDeviceFormat(deviceId);
}
get valid() {
return binding.getAudioDeviceFormatValid(this._handle);
}
get sampleFrames() {
return binding.getAudioDeviceFormatSampleFrames(this._handle);
}
get spec() {
return new SDLAudioSpec(this);
}
toJSON() {
return {
valid: this.valid,
sampleFrames: this.sampleFrames,
spec: this.spec.toJSON()
};
}
};
var SDLAudioDevice = class _SDLAudioDevice {
static AudioSpec = SDLAudioSpec;
static AudioDeviceFormat = SDLAudioDeviceFormat;
static playbackDeviceFormats() {
const list = binding.getAudioPlaybackDevices();
return list.map((deviceId) => {
return new SDLAudioDeviceFormat(deviceId);
});
}
static getRecordingDevice({ name } = {}) {
if (!name) {
return _SDLAudioDevice.defaultRecordingDevice();
}
const device = _SDLAudioDevice.recordingDevices().find((device2) => {
return name === device2.name;
});
if (!device) {
return null;
}
return new _SDLAudioDevice(device);
}
static recordingDeviceFormats() {
const list = binding.getAudioRecordingDevices();
return list.map((deviceId) => {
return new SDLAudioDeviceFormat(deviceId);
});
}
static recordingDevices() {
const devices = binding.getAudioRecordingDevices();
return devices.map((id, index) => {
const name = _SDLAudioDevice.getAudioDeviceName(id);
return {
id,
name,
index
};
});
}
static getPlaybackDevice({ name } = {}) {
if (!name) {
return _SDLAudioDevice.defaultPlaybackDevice();
}
const device = _SDLAudioDevice.playbackDevices().find((device2) => {
return name === device2.name;
});
if (!device) {
return null;
}
return new _SDLAudioDevice(device);
}
static playbackDevices() {
const devices = binding.getAudioPlaybackDevices();
return devices.map((id, index) => {
const name = _SDLAudioDevice.getAudioDeviceName(id);
return {
id,
name,
index
};
});
}
static defaultRecordingDevice(spec) {
return new _SDLAudioDevice(
constants.SDL_AUDIO_DEVICE_DEFAULT_RECORDING,
spec
);
}
static defaultPlaybackDevice(spec) {
return new _SDLAudioDevice(constants.SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, spec);
}
static getAudioDeviceName(id) {
return binding.getAudioDeviceName(id);
}
constructor(deviceId, spec) {
this._requestedDeviceId = deviceId;
this.spec = spec;
const format = this.spec?.format;
const channels = this.spec?.channels;
const freq = this.spec?.freq;
this.id = binding.openAudioDevice(
this._requestedDeviceId,
format,
channels,
freq
);
if (!this.spec) {
this.spec = this.format.spec;
}
}
close() {
if (!this.id) return;
binding.closeAudioDevice(this.id);
this.id = null;
}
destroy() {
this.close();
}
[Symbol.dispose]() {
this.destroy();
}
get name() {
return binding.getAudioDeviceName(this.id);
}
get format() {
return new SDLAudioDeviceFormat(this.id);
}
get isPlaybackDevice() {
return binding.isAudioDevicePlayback(this.id);
}
get isPhysicalDevice() {
return binding.isAudioDevicePhysical(this.id);
}
get isPaused() {
return binding.isAudioDevicePaused(this.id);
}
get gain() {
return binding.getAudioDeviceGain(this.id);
}
set gain(volume) {
binding.setAudioDeviceGain(this.id, volume);
}
pause() {
if (!this.id) return false;
return binding.pauseAudioDevice(this.id);
}
resume() {
if (!this.id) return false;
return binding.resumeAudioDevice(this.id);
}
bindStream(stream) {
if (!this.id) {
throw new Error("Audio device not open");
}
if (!stream._handle) {
throw new Error("Audio stream not created");
}
const success = binding.bindAudioStream(this.id, stream._handle);
if (typeof stream._onBound === "function") {
stream._onBound();
}
this.resume();
return success;
}
unbindStream(stream) {
if (!this.id) return;
if (!stream._handle) {
throw new Error("Audio stream not created");
}
binding.unbindAudioStream(stream._handle);
if (typeof stream._bound !== "undefined") {
stream._bound = false;
}
return;
}
toJSON() {
return {
id: this.id,
name: this.name,
format: this.format.toJSON(),
isPlaybackDevice: this.isPlaybackDevice,
isPhysicalDevice: this.isPhysicalDevice,
isPaused: this.isPaused,
gain: this.gain
};
}
};
module.exports = SDLAudioDevice;
}
});
// ../../node_modules/bare-sdl/lib/camera.js
var require_camera = __commonJS({
"../../node_modules/bare-sdl/lib/camera.js"(exports, module) {
var binding = require_binding();
var SDLCameraSpec = class {
constructor(spec) {
this._spec = spec;
}
get format() {
return binding.getCameraSpecFormat(this._spec);
}
get colorspace() {
return binding.getCameraSpecColorspace(this._spec);
}
get width() {
return binding.getCameraSpecWidth(this._spec);
}
get height() {
return binding.getCameraSpecHeight(this._spec);
}
get framerateNumerator() {
return binding.getCameraSpecFramerateNumerator(this._spec);
}
get framerateDenominator() {
return binding.getCameraSpecFramerateDenominator(this._spec);
}
get fps() {
if (!this.framerateNumerator || !this.framerateDenominator) {
return 0;
}
return this.framerateNumerator / this.framerateDenominator;
}
toJSON() {
return {
format: this.format,
colorspace: this.colorspace,
width: this.width,
height: this.height,
framerateNumerator: this.framerateNumerator,
framerateDenominator: this.framerateDenominator,
fps: this.fps
};
}
};
var SDLCameraFrame = class {
constructor(camera) {
this._camera = camera;
this._handle = binding.acquireCameraFrame(camera._handle);
}
get valid() {
return binding.getCameraFrameValid(this._handle);
}
get timestamp() {
return binding.getCameraFrameTimestamp(this._handle);
}
get width() {
return binding.getCameraFrameWidth(this._handle);
}
get height() {
return binding.getCameraFrameHeight(this._handle);
}
get pitch() {
return binding.getCameraFramePitch(this._handle);
}
get format() {
return binding.getCameraFrameFormat(this._handle);
}
get pixels() {
return binding.getCameraFramePixels(this._handle);
}
release() {
if (this._handle && this._camera._handle) {
binding.releaseCameraFrame(this._camera._handle, this._handle);
this._handle = null;
}
}
[Symbol.dispose]() {
this.release();
}
toJSON() {
return {
valid: this.valid,
timestamp: this.timestamp,
width: this.width,
height: this.height,
pitch: this.pitch,
format: this.format
};
}
};
var SDLCamera = class _SDLCamera {
static CameraSpec = SDLCameraSpec;
static CameraFrame = SDLCameraFrame;
static defaultCamera(spec) {
const devices = binding.getCameras();
if (!spec) {
const formats = _SDLCamera.getSupportedFormats(devices[0]);
spec = formats[0];
}
return new _SDLCamera(devices[0], spec);
}
static getCameras() {
const cameras = binding.getCameras();
return cameras.map((id, index) => {
const name = _SDLCamera.getCameraName(id);
return {
id,
name,
index
};
});
}
static getCameraName(deviceId) {
return binding.getCameraName(deviceId);
}
static getCameraPosition(deviceId) {
return binding.getCameraPosition(deviceId);
}
static getSupportedFormats(deviceId) {
const formatHandles = binding.getCameraSupportedFormats(deviceId);
return formatHandles.map((handle) => {
const spec = new SDLCameraSpec(handle);
return spec.toJSON();
});
}
constructor(deviceId, spec) {
if (typeof deviceId !== "number" && deviceId.id) {
deviceId = deviceId.id;
}
this._deviceId = deviceId;
this._spec = spec;
const format = spec?.format;
const colorspace = spec?.colorspace;
const width = spec?.width;
const height = spec?.height;
const framerateNumerator = spec?.framerateNumerator;
const framerateDenominator = spec?.framerateDenominator;
this._handle = binding.openCamera(
deviceId,
format,
colorspace,
width,
height,
framerateNumerator,
framerateDenominator
);
}
get id() {
return binding.getCameraId(this._handle);
}
get name() {
return binding.getCameraName(this._deviceId);
}
get properties() {
return binding.getCameraProperties(this._handle);
}
get permissionState() {
return binding.getCameraPermissionState(this._handle);
}
get isApproved() {
return this.permissionState === 1;
}
get isDenied() {
return this.permissionState === -1;
}
get isPending() {
return this.permissionState === 0;
}
get spec() {
const spec = binding.getCameraFormat(this._handle);
return new SDLCameraSpec(spec);
}
acquireFrame() {
return new SDLCameraFrame(this);
}
destroy() {
if (this._handle) {
binding.closeCamera(this._handle);
this._handle = null;
}
}
[Symbol.dispose]() {
this.destroy();
}
toJSON() {
return {
id: this.id,
deviceId: this._deviceId,
permissionState: this.permissionState,
isApproved: this.isApproved,
isDenied: this.isDenied,
isPending: this.isPending,
spec: this.spec.toJSON()
};
}
};
module.exports = SDLCamera;
}
});
// ../../node_modules/bare-sdl/lib/audio-stream.js
var require_audio_stream = __commonJS({
"../../node_modules/bare-sdl/lib/audio-stream.js"(exports, module) {
var binding = require_binding();
module.exports = class SDLAudioStream {
constructor(source, target, options = {}) {
this.source = source;
this.target = target;
this._handle = null;
this._destroyed = false;
this._handle = binding.createAudioStream(
source.format,
source.channels,
source.freq,
target.format,
target.channels,
target.freq,
this._makeSafeCallback(options?.get),
this._makeSafeCallback(options?.put)
);
}
put(buffer, offset = 0, length) {
if (this._destroyed || !this._handle) return false;
const result = this._handleBufferParams(buffer, offset, length);
return binding.putAudioStreamData(
this._handle,
result.arrayBuffer,
result.byteOffset,
result.length
);
}
get(buffer, offset = 0, length) {
if (this._destroyed || !this._handle) return 0;
const result = this._handleBufferParams(buffer, offset, length);
return binding.getAudioStreamData(
this._handle,
result.arrayBuffer,
result.byteOffset,
result.length
);
}
_handleBufferParams(buffer, offset, length) {
let arrayBuffer = buffer;
let byteOffset = offset;
if (Buffer.isBuffer(buffer)) {
arrayBuffer = buffer.buffer;
byteOffset = buffer.byteOffset + offset;
length = length ?? buffer.length - offset;
} else {
length = length ?? buffer.byteLength - offset;
}
return {
arrayBuffer,
byteOffset,
length
};
}
get available() {
if (this._destroyed || !this._handle) return 0;
return binding.getAudioStreamAvailable(this._handle);
}
get device() {
if (this._destroyed || !this._handle) return 0;
return binding.getAudioStreamDevice(this._handle);
}
flush() {
if (this._destroyed || !this._handle) return false;
return binding.flushAudioStream(this._handle);
}
clear() {
if (this._destroyed || !this._handle) return false;
return binding.clearAudioStream(this._handle);
}
resume() {
if (this._destroyed || !this._handle) return false;
return binding.resumeAudioStreamDevice(this._handle);
}
destroy() {
if (this._destroyed) return;
this._destroyed = true;
if (this._handle) {
binding.destroyAudioStream(this._handle);
this._handle = null;
}
this._get = null;
this._put = null;
}
_makeSafeCallback(cb) {
if (!cb) {
return;
}
return (needed, total) => {
if (!this._destroyed) {
cb(needed, total);
}
};
}
};
}
});
// ../../node_modules/bare-sdl/lib/event.js
var require_event = __commonJS({
"../../node_modules/bare-sdl/lib/event.js"(exports, module) {
var binding = require_binding();
var SDLEvent = class {
constructor() {
this._handle = binding.createEvent();
}
get type() {
return binding.getEventType(this._handle);
}
get key() {
return new SDLKeyboardEvent(this);
}
};
var SDLKeyboardEvent = class {
constructor(event = new SDLEvent()) {
this._handle = binding.getEventKey(event._handle);
}
get scancode() {
return binding.getEventKeyScancode(this._handle);
}
};
module.exports = SDLEvent;
module.exports.Keyboard = SDLKeyboardEvent;
}
});
// ../../node_modules/bare-sdl/lib/poller.js
var require_poller = __commonJS({
"../../node_modules/bare-sdl/lib/poller.js"(exports, module) {
var binding = require_binding();
module.exports = class SDLPoller {
poll(event) {
return binding.poll(event._handle);
}
};
}
});
// ../../node_modules/bare-sdl/lib/renderer.js
var require_renderer = __commonJS({
"../../node_modules/bare-sdl/lib/renderer.js"(exports, module) {
var binding = require_binding();
module.exports = class SDLRenderer {
constructor(window) {
this._handle = binding.createRenderer(window._handle);
}
destroy() {
binding.destroyRenderer(this._handle);
this._handle = null;
}
clear() {
return binding.clearRender(this._handle);
}
texture(texture) {
return binding.textureRender(this._handle, texture._handle);
}
present() {
return binding.presentRender(this._handle);
}
};
}
});
// ../../node_modules/bare-sdl/lib/texture.js
var require_texture = __commonJS({
"../../node_modules/bare-sdl/lib/texture.js"(exports, module) {
var binding = require_binding();
var constants = require_constants();
module.exports = class SDLTexture {
constructor(renderer, width, height, pixelFormat = constants.SDL_PIXELFORMAT_RGB24, textureAccess = constants.SDL_TEXTUREACCESS_STREAMING) {
this._handle = binding.createTexture(
renderer._handle,
pixelFormat,
textureAccess,
width,
height
);
}
destroy() {
binding.destroyTexture(this._handle);
this._handle = null;
}
update(buffer, pitch) {
return binding.updateTexture(
this._handle,
buffer.buffer,
buffer.byteOffset,
pitch
);
}
};
}
});
// ../../node_modules/bare-sdl/lib/window.js
var require_window = __commonJS({
"../../node_modules/bare-sdl/lib/window.js"(exports, module) {
var binding = require_binding();
module.exports = class SDLWindow {
constructor(title, width, height, flags = 0) {
this._handle = binding.createWindow(title, width, height, flags);
}
destroy() {
binding.destroyWindow(this._handle);
this._handle = null;
}
};
}
});
// ../../node_modules/bare-sdl/index.js
var require_bare_sdl = __commonJS({
"../../node_modules/bare-sdl/index.js"(exports) {
exports.constants = require_constants();
exports.AudioDevice = require_audio_device();
exports.Camera = require_camera();
exports.AudioStream = require_audio_stream();
exports.Event = require_event();
exports.Poller = require_poller();
exports.Renderer = require_renderer();
exports.Texture = require_texture();
exports.Window = require_window();
}
});
// ../../bare-lib-entry-bareSdl.js
var bare_lib_entry_bareSdl_exports = {};
__export(bare_lib_entry_bareSdl_exports, {
default: () => bare_lib_entry_bareSdl_default
});
var import_bare_sdl = __toESM(require_bare_sdl());
var bare_lib_entry_bareSdl_default = import_bare_sdl.default;
return __toCommonJS(bare_lib_entry_bareSdl_exports);
})();
;(function(){var g=globalThis;var s="__bare_os_stdlib__";g[s]=g[s]||{};var e=typeof __bare_os_bundle_exports__!=="undefined"?__bare_os_bundle_exports__:void 0;var v=e!=null&&typeof e==="object"&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;g[s]["bareSdl"]=v;})();