mirror of
https://github.com/appium/appium.git
synced 2026-10-27 03:25:54 +08:00
BREAKING CHANGE: @appium/universal-xml-plugin is now an ESM-only package. It can no longer be loaded via CommonJS require(); consumers must use import or dynamic import(). Appium's own extension loader already loads plugins via dynamic import(), so appium plugin install/use universal-xml is unaffected. Deep imports into the package's internals are no longer possible — only the public entry point is exposed via exports.
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import {ATTR_PREFIX} from './source.js';
|
|
import type {TransformMetadata} from './types.js';
|
|
|
|
/**
|
|
* No-op transformer for iOS source XML.
|
|
* @param nodeObj Node object to transform.
|
|
*/
|
|
export function ios(nodeObj: any): void {
|
|
void nodeObj;
|
|
// iOS transformer does nothing
|
|
}
|
|
|
|
/**
|
|
* Normalizes Android-specific attributes in source XML.
|
|
* @param nodeObj Node object to transform.
|
|
* @param metadata Transformation metadata.
|
|
*/
|
|
export function android(nodeObj: any, metadata: TransformMetadata): void {
|
|
// strip android:id from front of id
|
|
const resId = nodeObj[`${ATTR_PREFIX}resource-id`];
|
|
if (resId && metadata.appPackage) {
|
|
nodeObj[`${ATTR_PREFIX}resource-id`] = resId.replace(`${metadata.appPackage}:id/`, '');
|
|
}
|
|
|
|
// turn bounds attr into rect-based attrs
|
|
if (nodeObj[`${ATTR_PREFIX}bounds`]) {
|
|
const boundsArray = nodeObj[`${ATTR_PREFIX}bounds`].split(/\[|\]|,/).filter((str: string) => str !== '');
|
|
const [x, y, x2, y2] = boundsArray;
|
|
const width = parseInt(x2, 10) - parseInt(x, 10);
|
|
const height = parseInt(y2, 10) - parseInt(y, 10);
|
|
nodeObj[`${ATTR_PREFIX}x`] = x;
|
|
nodeObj[`${ATTR_PREFIX}y`] = y;
|
|
nodeObj[`${ATTR_PREFIX}width`] = width.toString();
|
|
nodeObj[`${ATTR_PREFIX}height`] = height.toString();
|
|
}
|
|
}
|