UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

71 lines (70 loc) • 3.13 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; 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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var chartNative_exports = {}; __export(chartNative_exports, { chartPointsNative: () => chartPointsNative, chartStyleNative: () => chartStyleNative }); module.exports = __toCommonJS(chartNative_exports); var import_react_native = require("react-native-web"); function nativeColor(name, color) { const processed = (0, import_react_native.processColor)(color); if (typeof processed !== "number") throw new Error(`Swift.Chart ${name} must be a color string or number`); return processed; } function chartPointsNative(name, points) { if (!Array.isArray(points)) throw new Error(`Swift.Chart ${name} must be an array`); return JSON.stringify(points.map((point, index) => { if (typeof point?.x !== "string" && (typeof point?.x !== "number" || !Number.isFinite(point.x))) throw new Error(`Swift.Chart ${name}[${index}].x must be a string or finite number`); if (typeof point.y !== "number" || !Number.isFinite(point.y)) throw new Error(`Swift.Chart ${name}[${index}].y must be a finite number`); return { x: point.x, y: point.y, ...point.color === void 0 ? {} : { color: nativeColor(`${name}[${index}].color`, point.color) } }; })); } const pointStyles = [ "circle", "square", "diamond" ]; function chartStyleNative(name, style, fields) { if (style === void 0) return "{}"; if (typeof style !== "object" || style === null) throw new Error(`Swift.Chart ${name} must be an object`); const native = {}; for (const [key, value] of Object.entries(style)) { if (value === void 0) continue; if (!fields.includes(key)) throw new Error(`Swift.Chart ${name} has unknown field ${key}`); if (key === "color") native.color = nativeColor(`${name}.color`, value); else if (key === "pointStyle") { if (!pointStyles.includes(value)) throw new Error(`Swift.Chart ${name}.pointStyle must be one of ${pointStyles.join(", ")}`); native.pointStyle = value; } else if (key === "dashArray") { if (!Array.isArray(value) || value.some((item) => typeof item !== "number" || !Number.isFinite(item) || item < 0)) throw new Error(`Swift.Chart ${name}.dashArray must be an array of non-negative numbers`); native.dashArray = value; } else { if (typeof value !== "number" || !Number.isFinite(value)) throw new Error(`Swift.Chart ${name}.${key} must be a finite number`); native[key] = value; } } return JSON.stringify(native); }