//#region src/utils/read-non-empty-trimmed-string.ts
function readNonEmptyTrimmedString(value) {
	if (typeof value !== "string") return void 0;
	const trimmed = value.trim();
	return trimmed.length > 0 ? trimmed : void 0;
}
//#endregion
//#region src/widgets/authoring.ts
const SOURCE_WIDGET_MARKER = "__fluidSourceWidget";
const SOURCE_WIDGET_PACKAGE_MARKER = "__fluidSourceWidgetPackage";
const WIDGET_PACKAGE_DESCRIPTOR_MANIFEST_VERSION = 1;
const DEFAULT_WIDGET_PACKAGE_VERSION = "0.0.0-dev";
const DEFAULT_WIDGET_PACKAGE_TYPE = "company";
const DEFAULT_WIDGET_ICON = "box";
const DEFAULT_WIDGET_CATEGORY = "components";
const DEFAULT_WIDGET_CONTAINER = "block";
const DEFAULT_MIN_SDK_VERSION = "0.0.0";
const CLI_MANAGED_PACKAGE_STABLE_ID = "__fluid_cli_managed__";
function defineWidget(options) {
	return {
		...options,
		[SOURCE_WIDGET_MARKER]: true,
		defaultProps: options.defaultProps ?? {}
	};
}
function defineWidgetPackage(options) {
	const packageStableId = options.packageStableId ?? options.stableId;
	const packageType = options.packageType ?? DEFAULT_WIDGET_PACKAGE_TYPE;
	if (!packageStableId && packageType !== "droplet") throw new Error("defineWidgetPackage requires packageStableId for non-droplet widget packages.");
	const resolvedPackageStableId = packageStableId ?? CLI_MANAGED_PACKAGE_STABLE_ID;
	const packageId = `${options.scope}.${resolvedPackageStableId}`;
	return {
		[SOURCE_WIDGET_PACKAGE_MARKER]: true,
		manifestVersion: WIDGET_PACKAGE_DESCRIPTOR_MANIFEST_VERSION,
		scope: options.scope,
		packageStableId: resolvedPackageStableId,
		packageId,
		packageType,
		version: options.version ?? DEFAULT_WIDGET_PACKAGE_VERSION,
		widgets: options.widgets,
		cssUrls: options.cssUrls ?? [],
		remoteEntryUrl: options.remoteEntryUrl
	};
}
function isSourceWidget(value) {
	return isRecord(value) && value[SOURCE_WIDGET_MARKER] === true;
}
function isSourceWidgetPackage(value) {
	return isRecord(value) && value[SOURCE_WIDGET_PACKAGE_MARKER] === true;
}
function sourceWidgetPackageToDescriptor(sourcePackage, options = {}) {
	const remoteEntry = resolveRemoteEntryUrl(sourcePackage, options);
	if (!remoteEntry) return void 0;
	return {
		manifestVersion: WIDGET_PACKAGE_DESCRIPTOR_MANIFEST_VERSION,
		packageId: sourcePackage.packageId,
		packageType: sourcePackage.packageType,
		version: sourcePackage.version,
		remoteEntryUrl: remoteEntry.url,
		cssUrls: resolveCssUrls(sourcePackage, options, remoteEntry.usesFallback),
		widgets: sourcePackage.widgets.map((widget) => sourceWidgetToDescriptor(sourcePackage, widget))
	};
}
function sourceWidgetPackagesToDescriptors(sourcePackages, options = {}) {
	const descriptors = [];
	for (const sourcePackage of sourcePackages) {
		const descriptor = sourceWidgetPackageToDescriptor(sourcePackage, options);
		if (descriptor) descriptors.push(descriptor);
	}
	return descriptors;
}
function sourceWidgetPackageToManifests(sourcePackage) {
	return sourcePackage.widgets.map((widget) => sourceWidgetToManifest(sourcePackage, widget));
}
function sourceWidgetPackagesToManifests(sourcePackages) {
	return sourcePackages.flatMap(sourceWidgetPackageToManifests);
}
function sourceWidgetToDescriptor(sourcePackage, widget) {
	const type = getSourceWidgetType(sourcePackage, widget);
	const displayName = widget.displayName ?? widget.name;
	return {
		type,
		name: widget.name,
		displayName,
		description: widget.description ?? `Custom widget ${displayName}`,
		icon: widget.icon ?? DEFAULT_WIDGET_ICON,
		category: widget.category ?? DEFAULT_WIDGET_CATEGORY,
		propertySchema: {
			...widget.propertySchema,
			widgetType: type
		},
		defaultProps: widget.defaultProps,
		container: widget.container ?? DEFAULT_WIDGET_CONTAINER,
		minSdkVersion: widget.minSdkVersion ?? DEFAULT_MIN_SDK_VERSION,
		resizable: normalizeSourceResizable(widget.resizable)
	};
}
function sourceWidgetToManifest(sourcePackage, widget) {
	const descriptor = sourceWidgetToDescriptor(sourcePackage, widget);
	return {
		manifestVersion: WIDGET_PACKAGE_DESCRIPTOR_MANIFEST_VERSION,
		type: descriptor.type,
		component: widget.component,
		displayName: descriptor.displayName,
		description: descriptor.description,
		icon: descriptor.icon,
		category: descriptor.category,
		propertySchema: normalizeLegacyPropertySchema(descriptor.propertySchema, descriptor.type, descriptor.displayName),
		defaultProps: { ...descriptor.defaultProps },
		minSdkVersion: descriptor.minSdkVersion,
		resizable: sourceWidgetToLegacyResizable(widget.resizable, descriptor.resizable)
	};
}
function normalizeLegacyPropertySchema(propertySchema, widgetType, displayName) {
	return {
		...propertySchema,
		widgetType,
		displayName: typeof propertySchema.displayName === "string" ? propertySchema.displayName : displayName,
		fields: Array.isArray(propertySchema.fields) ? propertySchema.fields : []
	};
}
function getSourceWidgetType(sourcePackage, widget) {
	return `${sourcePackage.scope}.${sourcePackage.packageStableId}.${widget.name}`;
}
function resolveRemoteEntryUrl(sourcePackage, options) {
	const packageRemoteEntryUrl = readNonEmptyTrimmedString(sourcePackage.remoteEntryUrl);
	if (packageRemoteEntryUrl) return {
		url: packageRemoteEntryUrl,
		usesFallback: false
	};
	const fallbackRemoteEntryUrl = readNonEmptyTrimmedString(typeof options.remoteEntryUrl === "function" ? options.remoteEntryUrl(sourcePackage) : options.remoteEntryUrl);
	return fallbackRemoteEntryUrl ? {
		url: fallbackRemoteEntryUrl,
		usesFallback: true
	} : void 0;
}
function sourceWidgetToLegacyResizable(sourceResizable, descriptorResizable) {
	const legacyResizable = descriptorToLegacyResizable(descriptorResizable);
	if (!isRecord(sourceResizable)) return legacyResizable;
	return {
		...legacyResizable,
		...typeof sourceResizable.minWidth === "number" ? { minWidth: sourceResizable.minWidth } : {},
		...typeof sourceResizable.minHeight === "number" ? { minHeight: sourceResizable.minHeight } : {}
	};
}
function resolveCssUrls(sourcePackage, options, usesFallbackRemoteEntryUrl) {
	if (sourcePackage.cssUrls.length > 0) return sourcePackage.cssUrls;
	return usesFallbackRemoteEntryUrl ? options.cssUrls ?? [] : [];
}
function descriptorToLegacyResizable(resizable) {
	if (resizable === false) return void 0;
	if (resizable === true || resizable === "both") return {
		horizontal: true,
		vertical: true
	};
	if (resizable === "horizontal") return { horizontal: true };
	if (resizable === "vertical") return { vertical: true };
}
function normalizeSourceResizable(resizable) {
	if (resizable === void 0) return false;
	if (typeof resizable === "boolean") return resizable;
	if (resizable === "horizontal" || resizable === "vertical" || resizable === "both") return resizable;
	const horizontal = resizable.horizontal === true;
	const vertical = resizable.vertical === true;
	if (horizontal && vertical) return "both";
	if (horizontal) return "horizontal";
	if (vertical) return "vertical";
	return false;
}
function isRecord(value) {
	return typeof value === "object" && value !== null && !Array.isArray(value);
}
//#endregion
export { sourceWidgetPackageToDescriptor as a, sourceWidgetPackagesToManifests as c, isSourceWidgetPackage as i, readNonEmptyTrimmedString as l, defineWidgetPackage as n, sourceWidgetPackageToManifests as o, isSourceWidget as r, sourceWidgetPackagesToDescriptors as s, defineWidget as t };

//# sourceMappingURL=authoring-BLhdAWs4.mjs.map