poseui 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +8 -4
- package/dist/index.js +5 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { GenerateOptions } from "@unocss/core";
|
|
2
|
+
|
|
1
3
|
//#region src/index.d.ts
|
|
2
4
|
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
3
5
|
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
@@ -39,13 +41,13 @@ declare class PoseValidationError extends Error {
|
|
|
39
41
|
constructor(issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
40
42
|
}
|
|
41
43
|
type Dyn<TProps, T> = T | ((props: TProps) => T);
|
|
42
|
-
type ChildValue = string | number | PoseElement<any, any> | Array<string | number | PoseElement<any, any
|
|
44
|
+
type ChildValue = string | number | undefined | null | PoseElement<any, any> | Array<string | number | PoseElement<any, any> | undefined | null>;
|
|
43
45
|
type Child<TProps> = ChildValue | ((props: TProps) => ChildValue);
|
|
44
46
|
type RenderReturn<TSchema extends StandardSchemaV1 | undefined> = TSchema extends StandardSchemaV1 ? ReturnType<TSchema["~standard"]["validate"]> extends Promise<any> ? Promise<string> : string : string;
|
|
45
|
-
type CallArgs<TProps extends Record<string, unknown
|
|
47
|
+
type CallArgs<TProps extends Record<string, unknown>, TSchema> = TSchema extends StandardSchemaV1 ? [TProps?] : [keyof TProps] extends [never] ? [TProps?] : [TProps];
|
|
46
48
|
type ClassEntry<TProps> = string | ((props: TProps) => string);
|
|
47
49
|
interface PoseElement<TProps extends Record<string, unknown>, TSchema extends StandardSchemaV1 | undefined = undefined> {
|
|
48
|
-
(...args: CallArgs<TProps>): RenderReturn<TSchema>;
|
|
50
|
+
(...args: CallArgs<TProps, TSchema>): RenderReturn<TSchema>;
|
|
49
51
|
readonly classes: ReadonlyArray<ClassEntry<TProps>>;
|
|
50
52
|
/**
|
|
51
53
|
* Bind a Standard Schema (Zod, Valibot, ArkType, …).
|
|
@@ -810,7 +812,9 @@ interface PoseElement<TProps extends Record<string, unknown>, TSchema extends St
|
|
|
810
812
|
* @example
|
|
811
813
|
* const { html, css } = await card.render({ name: 'Ada' })
|
|
812
814
|
*/
|
|
813
|
-
render(
|
|
815
|
+
render(props?: CallArgs<TProps, TSchema>[0], opts?: {
|
|
816
|
+
generatorOptions?: Partial<GenerateOptions<false>>;
|
|
817
|
+
}): Promise<{
|
|
814
818
|
html: string;
|
|
815
819
|
css: string;
|
|
816
820
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ function resolveClasses(classes, props) {
|
|
|
31
31
|
}
|
|
32
32
|
function renderChild(child, props) {
|
|
33
33
|
if (typeof child === "function") return renderChild(child(props), props);
|
|
34
|
-
if (Array.isArray(child)) return child.map((c) => renderChild(c, props)).join("");
|
|
34
|
+
if (Array.isArray(child)) return child.filter((c) => c != null).map((c) => renderChild(c, props)).join("");
|
|
35
35
|
if (child != null && typeof child === "object" && "__pose" in child) return child(props);
|
|
36
36
|
return child == null ? "" : String(child);
|
|
37
37
|
}
|
|
@@ -481,10 +481,10 @@ function createBuilder(state) {
|
|
|
481
481
|
}
|
|
482
482
|
};
|
|
483
483
|
el.cls = (value) => typeof value === "function" ? derive([value]) : derive([value]);
|
|
484
|
-
el.render = async (
|
|
485
|
-
const html = render(
|
|
484
|
+
el.render = async (props, opts) => {
|
|
485
|
+
const html = render(props);
|
|
486
486
|
const resolvedHtml = html instanceof Promise ? await html : html;
|
|
487
|
-
const { css } = await (await getGenerator()).generate(resolvedHtml,
|
|
487
|
+
const { css } = await (await getGenerator()).generate(resolvedHtml, opts?.generatorOptions);
|
|
488
488
|
return {
|
|
489
489
|
html: resolvedHtml,
|
|
490
490
|
css
|
|
@@ -497,7 +497,7 @@ function createBuilder(state) {
|
|
|
497
497
|
});
|
|
498
498
|
return el;
|
|
499
499
|
}
|
|
500
|
-
let _generator =
|
|
500
|
+
let _generator = void 0;
|
|
501
501
|
async function getGenerator() {
|
|
502
502
|
if (_generator) return _generator;
|
|
503
503
|
const { createGenerator } = await import("@unocss/core");
|