fix output

This commit is contained in:
2026-01-27 16:47:33 +03:30
parent c122b00647
commit a99c6aa051
4582 changed files with 389930 additions and 2514 deletions
+288
View File
@@ -0,0 +1,288 @@
'use strict';
var core = require('@capacitor/core');
exports.CameraSource = void 0;
(function (CameraSource) {
/**
* Prompts the user to select either the photo album or take a photo.
*/
CameraSource["Prompt"] = "PROMPT";
/**
* Take a new photo using the camera.
*/
CameraSource["Camera"] = "CAMERA";
/**
* Pick an existing photo from the gallery or photo album.
*/
CameraSource["Photos"] = "PHOTOS";
})(exports.CameraSource || (exports.CameraSource = {}));
exports.CameraDirection = void 0;
(function (CameraDirection) {
CameraDirection["Rear"] = "REAR";
CameraDirection["Front"] = "FRONT";
})(exports.CameraDirection || (exports.CameraDirection = {}));
exports.CameraResultType = void 0;
(function (CameraResultType) {
CameraResultType["Uri"] = "uri";
CameraResultType["Base64"] = "base64";
CameraResultType["DataUrl"] = "dataUrl";
})(exports.CameraResultType || (exports.CameraResultType = {}));
class CameraWeb extends core.WebPlugin {
async getPhoto(options) {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
if (options.webUseInput || options.source === exports.CameraSource.Photos) {
this.fileInputExperience(options, resolve, reject);
}
else if (options.source === exports.CameraSource.Prompt) {
let actionSheet = document.querySelector('pwa-action-sheet');
if (!actionSheet) {
actionSheet = document.createElement('pwa-action-sheet');
document.body.appendChild(actionSheet);
}
actionSheet.header = options.promptLabelHeader || 'Photo';
actionSheet.cancelable = false;
actionSheet.options = [
{ title: options.promptLabelPhoto || 'From Photos' },
{ title: options.promptLabelPicture || 'Take Picture' },
];
actionSheet.addEventListener('onSelection', async (e) => {
const selection = e.detail;
if (selection === 0) {
this.fileInputExperience(options, resolve, reject);
}
else {
this.cameraExperience(options, resolve, reject);
}
});
}
else {
this.cameraExperience(options, resolve, reject);
}
});
}
async pickImages(_options) {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
this.multipleFileInputExperience(resolve, reject);
});
}
async cameraExperience(options, resolve, reject) {
if (customElements.get('pwa-camera-modal')) {
const cameraModal = document.createElement('pwa-camera-modal');
cameraModal.facingMode =
options.direction === exports.CameraDirection.Front ? 'user' : 'environment';
document.body.appendChild(cameraModal);
try {
await cameraModal.componentOnReady();
cameraModal.addEventListener('onPhoto', async (e) => {
const photo = e.detail;
if (photo === null) {
reject(new core.CapacitorException('User cancelled photos app'));
}
else if (photo instanceof Error) {
reject(photo);
}
else {
resolve(await this._getCameraPhoto(photo, options));
}
cameraModal.dismiss();
document.body.removeChild(cameraModal);
});
cameraModal.present();
}
catch (e) {
this.fileInputExperience(options, resolve, reject);
}
}
else {
console.error(`Unable to load PWA Element 'pwa-camera-modal'. See the docs: https://capacitorjs.com/docs/web/pwa-elements.`);
this.fileInputExperience(options, resolve, reject);
}
}
fileInputExperience(options, resolve, reject) {
let input = document.querySelector('#_capacitor-camera-input');
const cleanup = () => {
var _a;
(_a = input.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(input);
};
if (!input) {
input = document.createElement('input');
input.id = '_capacitor-camera-input';
input.type = 'file';
input.hidden = true;
document.body.appendChild(input);
input.addEventListener('change', (_e) => {
const file = input.files[0];
let format = 'jpeg';
if (file.type === 'image/png') {
format = 'png';
}
else if (file.type === 'image/gif') {
format = 'gif';
}
if (options.resultType === 'dataUrl' ||
options.resultType === 'base64') {
const reader = new FileReader();
reader.addEventListener('load', () => {
if (options.resultType === 'dataUrl') {
resolve({
dataUrl: reader.result,
format,
});
}
else if (options.resultType === 'base64') {
const b64 = reader.result.split(',')[1];
resolve({
base64String: b64,
format,
});
}
cleanup();
});
reader.readAsDataURL(file);
}
else {
resolve({
webPath: URL.createObjectURL(file),
format: format,
});
cleanup();
}
});
input.addEventListener('cancel', (_e) => {
reject(new core.CapacitorException('User cancelled photos app'));
cleanup();
});
}
input.accept = 'image/*';
input.capture = true;
if (options.source === exports.CameraSource.Photos ||
options.source === exports.CameraSource.Prompt) {
input.removeAttribute('capture');
}
else if (options.direction === exports.CameraDirection.Front) {
input.capture = 'user';
}
else if (options.direction === exports.CameraDirection.Rear) {
input.capture = 'environment';
}
input.click();
}
multipleFileInputExperience(resolve, reject) {
let input = document.querySelector('#_capacitor-camera-input-multiple');
const cleanup = () => {
var _a;
(_a = input.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(input);
};
if (!input) {
input = document.createElement('input');
input.id = '_capacitor-camera-input-multiple';
input.type = 'file';
input.hidden = true;
input.multiple = true;
document.body.appendChild(input);
input.addEventListener('change', (_e) => {
const photos = [];
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < input.files.length; i++) {
const file = input.files[i];
let format = 'jpeg';
if (file.type === 'image/png') {
format = 'png';
}
else if (file.type === 'image/gif') {
format = 'gif';
}
photos.push({
webPath: URL.createObjectURL(file),
format: format,
});
}
resolve({ photos });
cleanup();
});
input.addEventListener('cancel', (_e) => {
reject(new core.CapacitorException('User cancelled photos app'));
cleanup();
});
}
input.accept = 'image/*';
input.click();
}
_getCameraPhoto(photo, options) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
const format = photo.type.split('/')[1];
if (options.resultType === 'uri') {
resolve({
webPath: URL.createObjectURL(photo),
format: format,
saved: false,
});
}
else {
reader.readAsDataURL(photo);
reader.onloadend = () => {
const r = reader.result;
if (options.resultType === 'dataUrl') {
resolve({
dataUrl: r,
format: format,
saved: false,
});
}
else {
resolve({
base64String: r.split(',')[1],
format: format,
saved: false,
});
}
};
reader.onerror = e => {
reject(e);
};
}
});
}
async checkPermissions() {
if (typeof navigator === 'undefined' || !navigator.permissions) {
throw this.unavailable('Permissions API not available in this browser');
}
try {
// https://developer.mozilla.org/en-US/docs/Web/API/Permissions/query
// the specific permissions that are supported varies among browsers that implement the
// permissions API, so we need a try/catch in case 'camera' is invalid
const permission = await window.navigator.permissions.query({
name: 'camera',
});
return {
camera: permission.state,
photos: 'granted',
};
}
catch (_a) {
throw this.unavailable('Camera permissions are not available in this browser');
}
}
async requestPermissions() {
throw this.unimplemented('Not implemented on web.');
}
async pickLimitedLibraryPhotos() {
throw this.unavailable('Not implemented on web.');
}
async getLimitedLibraryPhotos() {
throw this.unavailable('Not implemented on web.');
}
}
new CameraWeb();
const Camera = core.registerPlugin('Camera', {
web: () => new CameraWeb(),
});
exports.Camera = Camera;
//# sourceMappingURL=plugin.cjs.js.map
+85
View File
@@ -0,0 +1,85 @@
{
"name": "@capacitor/camera",
"version": "7.0.2",
"description": "The Camera API provides the ability to take a photo with the camera or choose an existing one from the photo album.",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"unpkg": "dist/plugin.js",
"files": [
"android/src/main/",
"android/build.gradle",
"dist/",
"ios/Sources",
"ios/Tests",
"Package.swift",
"CapacitorCamera.podspec"
],
"author": "Ionic <hi@ionicframework.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/ionic-team/capacitor-plugins.git"
},
"bugs": {
"url": "https://github.com/ionic-team/capacitor-plugins/issues"
},
"keywords": [
"capacitor",
"plugin",
"native"
],
"scripts": {
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
"verify:ios": "xcodebuild build -scheme CapacitorCamera -destination generic/platform=iOS",
"verify:android": "cd android && ./gradlew clean build test && cd ..",
"verify:web": "npm run build",
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
"eslint": "eslint . --ext ts",
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
"swiftlint": "node-swiftlint",
"docgen": "docgen --api CameraPlugin --output-readme README.md --output-json dist/docs.json",
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
"clean": "rimraf ./dist",
"watch": "tsc --watch",
"prepublishOnly": "npm run build",
"publish:cocoapod": "pod trunk push ./CapacitorCamera.podspec --allow-warnings"
},
"devDependencies": {
"@capacitor/android": "^7.0.0",
"@capacitor/core": "^7.0.0",
"@capacitor/docgen": "0.2.2",
"@capacitor/ios": "^7.0.0",
"@ionic/eslint-config": "^0.4.0",
"@ionic/prettier-config": "~1.0.1",
"@ionic/swiftlint-config": "^1.1.2",
"eslint": "^8.57.0",
"prettier": "~2.3.0",
"prettier-plugin-java": "~1.0.2",
"rimraf": "^6.0.1",
"rollup": "^4.26.0",
"swiftlint": "^1.0.1",
"typescript": "~4.1.5"
},
"peerDependencies": {
"@capacitor/core": ">=7.0.0"
},
"prettier": "@ionic/prettier-config",
"swiftlint": "@ionic/swiftlint-config",
"eslintConfig": {
"extends": "@ionic/eslint-config/recommended"
},
"capacitor": {
"ios": {
"src": "ios"
},
"android": {
"src": "android"
}
},
"publishConfig": {
"access": "public"
},
"gitHead": "7c53a4c249abe958983f1ac9df04dec7ab89c10e"
}