@wix/origami-runtime 0.0.0-stage → 0.19.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/README.md CHANGED
@@ -1,3 +1,34 @@
1
- # Temporary Holding Version
1
+ # Origami runtime
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Before local builds or tests, run `pnpm -r run build` from the repository root to build workspace dependencies in order.
4
+
5
+ The root entry exports binding, provider, and component authoring helpers.
6
+
7
+ `svg(url, uri)` creates a deferred SVG source without calling hooks or fetching content:
8
+
9
+ ```jsx
10
+ import { svg } from '@wix/origami-runtime'
11
+
12
+ <SvgImage svgId={svg(url, uri)} />
13
+ ```
14
+
15
+ The existing `withOrigami` wrapper resolves these sources before rendering the original component,
16
+ including sources nested in objects, arrays, and `elementProps`. Sources can be created inside
17
+ repeater render callbacks. The wrapper uses a fixed set of hooks even when the number of sources changes.
18
+ React elements and render callbacks are left intact; their own wrapped components resolve their sources.
19
+
20
+ Resolution returns only `{svgContent}`. The root SVG markup contains the calculated `viewBox`;
21
+ nested SVG viewports remain unchanged. The viewport follows Thunderbolt: non-UGC artwork prefers
22
+ `data-bbox`; UGC preserves the raw viewport or falls back to width and height. The UGC fallback
23
+ accepts unitless and pixel dimensions; other units leave the viewport unspecified.
24
+
25
+ Sources receive plain URL and URI strings and have no dependency on the media SDK.
26
+ DM reconstructs the Core vector from the expression without fetching or executing it.
27
+ The wrapper supplies empty SVG content while loading or after a fetch failure, reuses loaded URLs
28
+ within its mounted instance, and cancels pending requests when its source URLs change or it unmounts.
29
+ The existing `useSvgProps(url, uri)` hook uses the same resolution implementation for direct hook consumers;
30
+ it must be called at the top level of a React component or hook.
31
+
32
+ Layout components and the shared DOM/CSS contract belong to
33
+ [`@wix/origami-system-components`](../origami-system-components/README.md).
34
+ This package has no layout subpaths or system-components dependency.
@@ -0,0 +1,44 @@
1
+ declare const D: unique symbol;
2
+ export type ContextHook<T> = () => T;
3
+ type CtxData = {
4
+ [D]: 'ctx';
5
+ from: ContextHook<unknown>;
6
+ path: string;
7
+ placeholder?: unknown;
8
+ };
9
+ type RecordCall = (...args: unknown[]) => CallD;
10
+ type CtxD = RecordCall & CtxData;
11
+ type CallD = {
12
+ [D]: 'call';
13
+ target: CtxData;
14
+ args: unknown[];
15
+ };
16
+ type FnD = {
17
+ [D]: 'fn';
18
+ ref: (...a: unknown[]) => unknown;
19
+ args: unknown[];
20
+ };
21
+ type IsD = {
22
+ [D]: 'is';
23
+ binding: unknown;
24
+ value: unknown;
25
+ };
26
+ type AllD = {
27
+ [D]: 'all';
28
+ entries: unknown[];
29
+ };
30
+ export type Binding = CtxD | CallD | FnD | IsD | AllD;
31
+ export declare const isBinding: (v: unknown) => v is Binding;
32
+ type PathValue<M, P extends string> = M extends object ? P extends `${infer K}.${infer Rest}` ? K extends keyof M ? PathValue<M[K], Rest> : unknown : P extends keyof M ? M[P] : unknown : unknown;
33
+ export declare const ctx: <M, P extends string>(path: P, opts: {
34
+ from: ContextHook<M>;
35
+ placeholder?: PathValue<NonNullable<M>, P>;
36
+ }) => PathValue<NonNullable<M>, P>;
37
+ export declare const fn: <T>(ref: (...a: never[]) => T, ...args: unknown[]) => T;
38
+ export declare const is: <T>(binding: T, value: T) => boolean;
39
+ export declare const all: (first: boolean, second: boolean, ...rest: boolean[]) => boolean;
40
+ export declare const raw: <T>(value: T) => T;
41
+ type Hooks = Map<ContextHook<unknown>, unknown>;
42
+ export declare const resolve: (v: unknown, hooks?: Hooks, seen?: WeakSet<object>) => unknown;
43
+ export declare const holds: (v: unknown, hooks?: Hooks, seen?: WeakSet<object>) => boolean;
44
+ export {};
@@ -0,0 +1,90 @@
1
+ import { isValidElement } from 'react';
2
+ const D = Symbol('origami.binding');
3
+ const RAW = Symbol('origami.raw');
4
+ export const isBinding = (v) => (typeof v === 'object' || typeof v === 'function') && v !== null && D in v;
5
+ const isRaw = (v) => typeof v === 'object' && v !== null && RAW in v;
6
+ const unwrap = (v) => v !== null && typeof v === 'object' && typeof v.get === 'function'
7
+ ? v.get()
8
+ : v;
9
+ const pick = (o, path) => path
10
+ .split('.')
11
+ .reduce((v, k) => (v == null ? undefined : unwrap(unwrap(v)[k])), o);
12
+ // document/bindings — each call returns a branded descriptor at authoring time, resolved lazily at
13
+ // render time by resolve(). ctx()'s return type is derived from what the `from` hook returns (via
14
+ // PathValue; NonNullable, since a hook used outside its provider may return undefined), so a call
15
+ // site gets the real manifest-declared type back, not the descriptor's runtime shape: a binding is
16
+ // a promise that the slot it's assigned to will eventually hold that value, exactly like a literal
17
+ // of that type would. The descriptor is also a function, so `ctx(path, { from })(args)` works when
18
+ // the path names a method: calling it runs nothing, it records the call for resolve().
19
+ export const ctx = (path, opts) => {
20
+ // 1. What the binding holds: the hook to read and the path to walk.
21
+ const data = { [D]: 'ctx', from: opts.from, path, placeholder: opts.placeholder };
22
+ // 2. What calling it does: record the args, next to the data. Nothing runs until resolve().
23
+ const recordCall = (...args) => ({ [D]: 'call', target: data, args });
24
+ // 3. One value that is both: the function, with the data attached.
25
+ const binding = Object.assign(recordCall, data);
26
+ // 4. Typed as the value it will resolve to, so call sites type-check against the real value.
27
+ return binding;
28
+ };
29
+ export const fn = (ref, ...args) => ({ [D]: 'fn', ref: ref, args });
30
+ // `value`'s type is tied to `binding`'s (T), not a fixed union — a binding derived from a boolean
31
+ // field must be compared to a boolean, one derived from an enum field to a member of that enum,
32
+ // with nothing hardcoded here to any one of those shapes.
33
+ export const is = (binding, value) => ({ [D]: 'is', binding, value });
34
+ // AND of two or more conditions: every entry must hold (see holds()).
35
+ export const all = (first, second, ...rest) => ({ [D]: 'all', entries: [first, second, ...rest] });
36
+ export const raw = (value) => ({ [RAW]: value });
37
+ const isPlain = (v) => typeof v === 'object' && v !== null && Object.getPrototypeOf(v) === Object.prototype;
38
+ // Each hook runs once per resolve(), on first use.
39
+ const read = (hook, hooks) => {
40
+ if (!hooks.has(hook))
41
+ hooks.set(hook, hook());
42
+ return hooks.get(hook);
43
+ };
44
+ // Calls the hooks that ctx() bindings name, so it must run during render. Bindings are authored
45
+ // statically per call site, so the same hooks run in the same order every render. A failing
46
+ // binding resolves to undefined rather than throwing.
47
+ export const resolve = (v, hooks = new Map(), seen = new WeakSet()) => {
48
+ if (isRaw(v))
49
+ return v[RAW];
50
+ if (isBinding(v)) {
51
+ try {
52
+ if (v[D] === 'ctx') {
53
+ const out = v.path ? pick(read(v.from, hooks), v.path) : unwrap(read(v.from, hooks));
54
+ return out === undefined ? v.placeholder : out;
55
+ }
56
+ // The method is read like any ctx() value, then called without a `this`.
57
+ if (v[D] === 'call') {
58
+ const method = resolve(v.target, hooks, seen);
59
+ const args = v.args.map(arg => resolve(arg, hooks, seen));
60
+ return method(...args);
61
+ }
62
+ if (v[D] === 'fn')
63
+ return v.ref(...v.args.map(a => resolve(a, hooks, seen)));
64
+ // Every entry is read, not just up to the first false one, so the hooks they name run in
65
+ // the same order every render.
66
+ if (v[D] === 'all')
67
+ return v.entries.map(e => holds(e, hooks, seen)).every(Boolean);
68
+ return resolve(v.binding, hooks, seen) === v.value;
69
+ }
70
+ catch (e) {
71
+ console.error('binding failed, left unresolved', e);
72
+ return undefined;
73
+ }
74
+ }
75
+ if (Array.isArray(v))
76
+ return v.map(x => resolve(x, hooks, seen));
77
+ if (isValidElement(v))
78
+ return v;
79
+ if (isPlain(v)) {
80
+ if (seen.has(v))
81
+ return v;
82
+ seen.add(v);
83
+ return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, resolve(x, hooks, seen)]));
84
+ }
85
+ return v;
86
+ };
87
+ // A condition holds only when it resolves to a strict `true`, as thunderbolt reads it. False,
88
+ // undefined, a merely truthy value, a failed binding and a raw() entry (opaque, never a match) don't.
89
+ export const holds = (v, hooks, seen) => !isRaw(v) && resolve(v, hooks, seen) === true;
90
+ //# sourceMappingURL=bindings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindings.js","sourceRoot":"","sources":["../src/bindings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,CAAC,CAAC;QAAE,OAAO,CAAC,CAAA;IAC/B,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACb,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAA;QACzB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QACX,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9F,CAAC;IACD,OAAO,CAAC,CAAA;AACZ,CAAC,CAAA;AAED,8FAA8F;AAC9F,sGAAsG;AACtG,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,CAAU,EAAE,KAAa,EAAE,IAAsB,EAAW,EAAE,CAChF,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,CAAA"}
@@ -0,0 +1,4 @@
1
+ export type Cond = unknown;
2
+ export type ClassNames = string | Record<string, Cond | readonly Cond[]> | readonly ClassNames[] | undefined;
3
+ export declare const cx: (block: string, value: ClassNames) => string;
4
+ export declare const rootClass: (id: string, value: ClassNames) => string;
@@ -0,0 +1,23 @@
1
+ const on = (c) => Array.isArray(c) ? c.length > 0 && c.every(x => x === true) : c === true;
2
+ const term = (block, name) => (name.startsWith('wix-visibility-') ? name : `${block}--${name}`);
3
+ export const cx = (block, value) => {
4
+ const out = [];
5
+ const walk = (v) => {
6
+ if (v === undefined)
7
+ return;
8
+ if (typeof v === 'string')
9
+ return void v
10
+ .split(/\s+/)
11
+ .filter(Boolean)
12
+ .forEach(n => out.push(term(block, n)));
13
+ if (Array.isArray(v))
14
+ return void v.forEach(walk);
15
+ for (const [k, c] of Object.entries(v))
16
+ if (on(c))
17
+ out.push(term(block, k));
18
+ };
19
+ walk(value);
20
+ return out.join(' ');
21
+ };
22
+ export const rootClass = (id, value) => [id, cx(id, value)].filter(Boolean).join(' ');
23
+ //# sourceMappingURL=classNames.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classNames.js","sourceRoot":"","sources":["../src/classNames.ts"],"names":[],"mappings":"AAMA,MAAM,EAAE,GAAG,CAAC,CAAyB,EAAW,EAAE,CAC9C,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;AAE5E,MAAM,IAAI,GAAG,CAAC,KAAa,EAAE,IAAY,EAAU,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,KAAK,IAAI,EAAE,CAAC,CAAA;AAEvH,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAa,EAAE,KAAiB,EAAU,EAAE;IAC3D,MAAM,GAAG,GAAa,EAAE,CAAA;IACxB,MAAM,IAAI,GAAG,CAAC,CAAa,EAAQ,EAAE;QACjC,IAAI,CAAC,KAAK,SAAS;YAAE,OAAM;QAC3B,IAAI,OAAO,CAAC,KAAK,QAAQ;YACrB,OAAO,KAAK,CAAC;iBACR,KAAK,CAAC,KAAK,CAAC;iBACZ,MAAM,CAAC,OAAO,CAAC;iBACf,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;QAC/C,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACjD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAyB,CAAC;YAAE,IAAI,EAAE,CAAC,CAAC,CAAC;gBAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;IACvG,CAAC,CAAA;IACD,IAAI,CAAC,KAAK,CAAC,CAAA;IACX,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACxB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAU,EAAE,KAAiB,EAAU,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA"}
@@ -0,0 +1,9 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ export declare const Show: ({ when, children }: {
3
+ when: boolean;
4
+ children: ReactNode;
5
+ }) => ReactElement | null;
6
+ export declare const Remove: ({ when, children }: {
7
+ when: boolean;
8
+ children: ReactElement;
9
+ }) => ReactElement | null;
@@ -0,0 +1,10 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { holds, resolve } from './bindings';
3
+ // Removing a component is the one visibility mode that changes the tree rather than the node.
4
+ // Only a strict `false` removes — hence `when: boolean`, matching what
5
+ // is()/ctx()-to-a-boolean-field/a literal all actually produce.
6
+ export const Show = ({ when, children }) => resolve(when) === false ? null : _jsx(_Fragment, { children: children });
7
+ // DM JSX 0.61's removed component: the outermost wrapper around exactly one component, no DOM node.
8
+ // `when` is one condition or all(...); the child is removed only when it holds, else kept.
9
+ export const Remove = ({ when, children }) => holds(when) ? null : children;
10
+ //# sourceMappingURL=components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.js","sourceRoot":"","sources":["../src/components.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3C,8FAA8F;AAC9F,uEAAuE;AACvE,gEAAgE;AAChE,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,EAA0C,EAAuB,EAAE,CACpG,OAAO,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,4BAAG,QAAQ,GAAI,CAAA;AAEpD,oGAAoG;AACpG,2FAA2F;AAC3F,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,EAA6C,EAAuB,EAAE,CACzG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAA"}
@@ -0,0 +1,92 @@
1
+ export interface WixProps {
2
+ wixPath?: string;
3
+ presetsWrapperProps?: {
4
+ className?: string;
5
+ };
6
+ }
7
+ export interface WixElementProps {
8
+ wix?: WixProps;
9
+ }
10
+ export interface PropBuilder<T> {
11
+ readonly _type: T;
12
+ readonly kind: string;
13
+ readonly meta: Record<string, unknown>;
14
+ }
15
+ /** `Image` from `@wix/editor-react-types`: the value of a manifest `image` prop. Wrappers name it wherever an image sits. */
16
+ export type Image = {
17
+ uri?: string;
18
+ url: string;
19
+ name?: string;
20
+ height?: number;
21
+ width?: number;
22
+ animated?: boolean;
23
+ crop?: {
24
+ x: number;
25
+ y: number;
26
+ width: number;
27
+ height: number;
28
+ };
29
+ quality?: number;
30
+ alt?: string;
31
+ };
32
+ /** `Video` from `@wix/editor-react-types`: the value of a manifest `video` prop. */
33
+ export type Video = {
34
+ uri: string;
35
+ name?: string;
36
+ sources: Array<{
37
+ quality: '1080p' | '720p' | '480p' | '360p';
38
+ width: number;
39
+ height: number;
40
+ types: Array<{
41
+ format: 'mp4' | 'mp4-luminance';
42
+ uri: string;
43
+ url: string;
44
+ }>;
45
+ }>;
46
+ adaptiveSources: Array<{
47
+ format: 'hls' | 'dash';
48
+ uri: string;
49
+ url: string;
50
+ }>;
51
+ hasAudio: boolean;
52
+ fps: number;
53
+ poster?: Image;
54
+ };
55
+ export declare const prop: {
56
+ text: (opts?: {
57
+ maxLength?: number;
58
+ }) => PropBuilder<string>;
59
+ richText: () => PropBuilder<string>;
60
+ boolean: () => PropBuilder<boolean>;
61
+ number: (opts?: {
62
+ min?: number;
63
+ max?: number;
64
+ }) => PropBuilder<number>;
65
+ event: <T = Event>(domEvent: string) => PropBuilder<(value: T) => void>;
66
+ enum: <T extends string>(...options: T[]) => PropBuilder<T>;
67
+ link: () => PropBuilder<{
68
+ href: string;
69
+ target?: string;
70
+ }>;
71
+ direction: () => PropBuilder<"ltr" | "rtl">;
72
+ vectorArt: () => PropBuilder<string>;
73
+ element: <T>() => PropBuilder<T>;
74
+ object: <T>() => PropBuilder<T>;
75
+ image: <T>() => PropBuilder<T>;
76
+ video: <T>() => PropBuilder<T>;
77
+ };
78
+ export interface ComponentDefinition<TProps extends Record<string, PropBuilder<any>>, TElements extends Record<string, PropBuilder<any>> = Record<string, never>> {
79
+ componentId: string;
80
+ compName: string;
81
+ props: TProps;
82
+ elements?: TElements;
83
+ presets?: string[];
84
+ }
85
+ export declare const defineComponent: <TProps extends Record<string, PropBuilder<any>>, TElements extends Record<string, PropBuilder<any>> = Record<string, never>>(def: ComponentDefinition<TProps, TElements>) => ComponentDefinition<TProps, TElements>;
86
+ export type InferProps<D extends ComponentDefinition<any, any>> = {
87
+ [K in keyof D['props']]?: D['props'][K]['_type'];
88
+ } & (keyof D['elements'] extends never ? unknown : {
89
+ elementProps?: {
90
+ [K in keyof D['elements']]?: D['elements'][K]['_type'];
91
+ };
92
+ });
package/dist/define.js ADDED
@@ -0,0 +1,22 @@
1
+ const makeProp = (kind, meta = {}) => ({ _type: undefined, kind, meta });
2
+ export const prop = {
3
+ text: (opts) => makeProp('text', opts ?? {}),
4
+ richText: () => makeProp('richText'),
5
+ boolean: () => makeProp('boolean'),
6
+ number: (opts) => makeProp('number', opts ?? {}),
7
+ event: (domEvent) => makeProp('function', { domEvent }),
8
+ enum: (...options) => makeProp('textEnum', { options }),
9
+ link: () => makeProp('link'),
10
+ direction: () => makeProp('direction'),
11
+ vectorArt: () => makeProp('vectorArt'),
12
+ // A refElement slot — T is the child component's own generated Props type, imported by the generator.
13
+ element: () => makeProp('element'),
14
+ // Any other value — an object, an array, or one with no known shape (T = unknown); T comes from the generator.
15
+ object: () => makeProp('object'),
16
+ // An image or a video (the manifest's `image` and `video` types): typed like `object`, but marked so tools
17
+ // can find image and video props.
18
+ image: () => makeProp('image'),
19
+ video: () => makeProp('video'),
20
+ };
21
+ export const defineComponent = (def) => def;
22
+ //# sourceMappingURL=define.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AA4CA,MAAM,QAAQ,GAAG,CAAI,IAAY,EAAE,OAAgC,EAAE,EAAkB,EAAE,CACrF,CAAC,EAAE,KAAK,EAAE,SAAyB,EAAE,IAAI,EAAE,IAAI,EAAE,CAAmB,CAAA;AAExE,MAAM,CAAC,MAAM,IAAI,GAAG;IAChB,IAAI,EAAE,CAAC,IAA6B,EAAE,EAAE,CAAC,QAAQ,CAAS,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;IAC7E,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAS,UAAU,CAAC;IAC5C,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAU,SAAS,CAAC;IAC3C,MAAM,EAAE,CAAC,IAAqC,EAAE,EAAE,CAAC,QAAQ,CAAS,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC;IACzF,KAAK,EAAE,CAAY,QAAgB,EAAE,EAAE,CAAC,QAAQ,CAAqB,UAAU,EAAE,EAAE,QAAQ,EAAE,CAAC;IAC9F,IAAI,EAAE,CAAmB,GAAG,OAAY,EAAE,EAAE,CAAC,QAAQ,CAAI,UAAU,EAAE,EAAE,OAAO,EAAE,CAAC;IACjF,IAAI,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAoC,MAAM,CAAC;IAC/D,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAgB,WAAW,CAAC;IACrD,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAS,WAAW,CAAC;IAC9C,sGAAsG;IACtG,OAAO,EAAE,GAAM,EAAE,CAAC,QAAQ,CAAI,SAAS,CAAC;IACxC,+GAA+G;IAC/G,MAAM,EAAE,GAAM,EAAE,CAAC,QAAQ,CAAI,QAAQ,CAAC;IACtC,2GAA2G;IAC3G,kCAAkC;IAClC,KAAK,EAAE,GAAM,EAAE,CAAC,QAAQ,CAAI,OAAO,CAAC;IACpC,KAAK,EAAE,GAAM,EAAE,CAAC,QAAQ,CAAI,OAAO,CAAC;CACvC,CAAA;AAkBD,MAAM,CAAC,MAAM,eAAe,GAAG,CAM3B,GAA2C,EACL,EAAE,CAAC,GAAG,CAAA"}
@@ -0,0 +1,12 @@
1
+ export { all, ctx, fn, is, raw, resolve, isBinding } from './bindings';
2
+ export type { Binding, ContextHook } from './bindings';
3
+ export { Remove, Show } from './components';
4
+ export { withOrigami } from './withOrigami';
5
+ export { withInteractions } from './withInteractions';
6
+ export { useSvgProps } from './useSvgProps';
7
+ export type { SvgProps } from './svgContent';
8
+ export { svg } from './svg';
9
+ export { cx, rootClass } from './classNames';
10
+ export type { ClassNames, Cond } from './classNames';
11
+ export { prop, defineComponent } from './define';
12
+ export type { WixProps, WixElementProps, PropBuilder, ComponentDefinition, InferProps, Image, Video } from './define';
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export { all, ctx, fn, is, raw, resolve, isBinding } from './bindings';
2
+ export { Remove, Show } from './components';
3
+ export { withOrigami } from './withOrigami';
4
+ export { withInteractions } from './withInteractions';
5
+ export { useSvgProps } from './useSvgProps';
6
+ export { svg } from './svg';
7
+ export { cx, rootClass } from './classNames';
8
+ export { prop, defineComponent } from './define';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAC3B,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE5C,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA"}
package/dist/svg.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { type SvgProps } from "./svgContent";
2
+ export declare const svg: (url: string, uri: string) => SvgProps;
3
+ export declare function useSvgSources<T>(props: T): T;
package/dist/svg.js ADDED
@@ -0,0 +1,99 @@
1
+ import { isValidElement, useEffect, useRef, useState } from "react";
2
+ import { resolveSvgProps } from "./svgContent";
3
+ const SVG_SOURCE = Symbol.for("@wix/origami-runtime.svgSource");
4
+ // Share both in-flight work and parsed results across mounted wrappers.
5
+ const svgRequests = new Map();
6
+ const loadSvg = (url) => {
7
+ const cached = svgRequests.get(url);
8
+ if (cached)
9
+ return cached;
10
+ const request = (async () => {
11
+ const response = await fetch(url);
12
+ if (!response.ok) {
13
+ throw new Error(`SVG fetch failed: ${response.status}`);
14
+ }
15
+ const content = await response.text();
16
+ return resolveSvgProps(content);
17
+ })().catch((error) => {
18
+ svgRequests.delete(url);
19
+ throw error;
20
+ });
21
+ svgRequests.set(url, request);
22
+ return request;
23
+ };
24
+ class SvgSource {
25
+ url;
26
+ uri;
27
+ [SVG_SOURCE] = true;
28
+ constructor(url, uri) {
29
+ this.url = url;
30
+ this.uri = uri;
31
+ }
32
+ }
33
+ export const svg = (url, uri) => new SvgSource(url, uri);
34
+ const isSvgSource = (value) => value !== null &&
35
+ typeof value === "object" &&
36
+ SVG_SOURCE in value &&
37
+ value[SVG_SOURCE] === true;
38
+ const mapSources = (value, resolve, seen = new WeakMap()) => {
39
+ if (isSvgSource(value))
40
+ return resolve(value);
41
+ if (value === null || typeof value !== "object" || isValidElement(value))
42
+ return value;
43
+ if (seen.has(value))
44
+ return seen.get(value);
45
+ if (Array.isArray(value)) {
46
+ const mapped = new Array(value.length);
47
+ seen.set(value, mapped);
48
+ value.forEach((entry, index) => {
49
+ mapped[index] = mapSources(entry, resolve, seen);
50
+ });
51
+ return mapped;
52
+ }
53
+ if (Object.getPrototypeOf(value) === Object.prototype) {
54
+ const mapped = {};
55
+ seen.set(value, mapped);
56
+ for (const [key, entry] of Object.entries(value)) {
57
+ Object.defineProperty(mapped, key, {
58
+ value: mapSources(entry, resolve, seen),
59
+ enumerable: true,
60
+ configurable: true,
61
+ writable: true,
62
+ });
63
+ }
64
+ return mapped;
65
+ }
66
+ return value;
67
+ };
68
+ export function useSvgSources(props) {
69
+ const cache = useRef(new Map());
70
+ const [, setVersion] = useState(0);
71
+ const urls = new Set();
72
+ mapSources(props, (source) => urls.add(source.url));
73
+ const urlsKey = JSON.stringify([...urls].sort());
74
+ useEffect(() => {
75
+ let active = true;
76
+ const load = async (url) => {
77
+ try {
78
+ const resolved = await loadSvg(url);
79
+ if (active) {
80
+ cache.current.set(url, resolved);
81
+ setVersion((version) => version + 1);
82
+ }
83
+ }
84
+ catch (error) {
85
+ if (active)
86
+ console.error("Could not load SVG:", error);
87
+ }
88
+ };
89
+ for (const url of JSON.parse(urlsKey)) {
90
+ if (!cache.current.has(url))
91
+ void load(url);
92
+ }
93
+ return () => {
94
+ active = false;
95
+ };
96
+ }, [urlsKey]);
97
+ return mapSources(props, (source) => cache.current.get(source.url) ?? { svgContent: "" });
98
+ }
99
+ //# sourceMappingURL=svg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svg.js","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,eAAe,EAAiB,MAAM,cAAc,CAAC;AAE9D,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;AAChE,wEAAwE;AACxE,MAAM,WAAW,GAAG,IAAI,GAAG,EAA6B,CAAC;AAEzD,MAAM,OAAO,GAAG,CAAC,GAAW,EAAqB,EAAE;IACjD,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpC,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,MAAM,OAAO,GAAG,CAAC,KAAK,IAAI,EAAE;QAC1B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;QAC1D,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtC,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACnB,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxB,MAAM,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;IACH,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC9B,OAAO,OAAO,CAAC;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CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;gBACpC,IAAI,MAAM,EAAE,CAAC;oBACX,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;oBACjC,UAAU,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;gBACvC,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,MAAM;oBAAE,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;YAC1D,CAAC;QACH,CAAC,CAAC;QACF,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAa,EAAE,CAAC;YAClD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,GAAG,EAAE;YACV,MAAM,GAAG,KAAK,CAAC;QACjB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO,UAAU,CACf,KAAK,EACL,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,CAC3D,CAAC;AACT,CAAC"}
@@ -0,0 +1,4 @@
1
+ export interface SvgProps {
2
+ svgContent: string;
3
+ }
4
+ export declare function resolveSvgProps(svgContent: string): SvgProps;
@@ -0,0 +1,38 @@
1
+ // Other units need a layout or unit conversion context; do not guess their viewport size.
2
+ function viewportDimension(value) {
3
+ const match = value
4
+ ?.trim()
5
+ .match(/^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(?:px)?$/i);
6
+ if (!match)
7
+ return undefined;
8
+ const dimension = Number(match[1]);
9
+ return Number.isFinite(dimension) && dimension >= 0 ? dimension : undefined;
10
+ }
11
+ export function resolveSvgProps(svgContent) {
12
+ const props = { svgContent };
13
+ if (!svgContent)
14
+ return props;
15
+ const document = new DOMParser().parseFromString(svgContent, "image/svg+xml");
16
+ const svg = document.documentElement;
17
+ if (svg.localName !== "svg" || document.querySelector("parsererror"))
18
+ return { svgContent: "" };
19
+ const contentType = svg.getAttribute("data-type") || "shape";
20
+ const contentBox = svg.getAttribute("data-bbox") || "";
21
+ const rawViewBox = svg.getAttribute("viewBox") || "";
22
+ const width = viewportDimension(svg.getAttribute("width"));
23
+ const height = viewportDimension(svg.getAttribute("height"));
24
+ const fallback = contentType === "ugc" && width !== undefined && height !== undefined
25
+ ? `0 0 ${width} ${height}`
26
+ : "";
27
+ const viewBox = !rawViewBox && fallback
28
+ ? fallback
29
+ : contentType !== "ugc" && contentBox
30
+ ? contentBox
31
+ : rawViewBox;
32
+ if (viewBox && viewBox !== rawViewBox) {
33
+ svg.setAttribute("viewBox", viewBox);
34
+ props.svgContent = new XMLSerializer().serializeToString(svg);
35
+ }
36
+ return props;
37
+ }
38
+ //# sourceMappingURL=svgContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svgContent.js","sourceRoot":"","sources":["../src/svgContent.ts"],"names":[],"mappings":"AAIA,0FAA0F;AAC1F,SAAS,iBAAiB,CAAC,KAAoB;IAC7C,MAAM,KAAK,GAAG,KAAK;QACjB,EAAE,IAAI,EAAE;SACP,KAAK,CAAC,oDAAoD,CAAC,CAAC;IAC/D,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,OAAO,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU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AAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACrC,KAAK,CAAC,UAAU,GAAG,IAAI,aAAa,EAAE,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;IAChE,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { SvgProps } from './svgContent';
2
+ export declare function useSvgProps(url: string, uri: string): SvgProps;
@@ -0,0 +1,5 @@
1
+ import { svg, useSvgSources } from './svg';
2
+ export function useSvgProps(url, uri) {
3
+ return useSvgSources(svg(url, uri));
4
+ }
5
+ //# sourceMappingURL=useSvgProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSvgProps.js","sourceRoot":"","sources":["../src/useSvgProps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAG1C,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,GAAW;IAChD,OAAO,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;AACvC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const withInteractions: (Component: any) => (props: any) => React.JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { InteractionsDefinition } from '@wix/site-service-interactions/definition';
3
+ import { useService } from '@wix/services-manager-react';
4
+ // Copied from wix-next's @wix/builder-interactions, not imported from it: a component with
5
+ // interactions renders inside an <interact-element> keyed by its comp path, else its id.
6
+ export const withInteractions = Component => props => {
7
+ const { hasInteractions } = useService(InteractionsDefinition);
8
+ const key = props.wix?.compPath ?? props.id;
9
+ if (hasInteractions(key)) {
10
+ return (_jsx("interact-element", { "data-interact-key": key, children: _jsx(Component, { ...props }) }));
11
+ }
12
+ return _jsx(Component, { ...props });
13
+ };
14
+ //# sourceMappingURL=withInteractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withInteractions.js","sourceRoot":"","sources":["../src/withInteractions.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAA;AAClF,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAExD,2FAA2F;AAC3F,yFAAyF;AACzF,MAAM,CAAC,MAAM,gBAAgB,GAAG,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE;IACjD,MAAM,EAAE,eAAe,EAAE,GAAG,UAAU,CAAC,sBAAsB,CAAC,CAAA;IAE9D,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,EAAE,QAAQ,IAAI,KAAK,CAAC,EAAE,CAAA;IAE3C,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,CACH,gDAAqC,GAAG,YACpC,KAAC,SAAS,OAAK,KAAK,GAAI,GACT,CACtB,CAAA;IACL,CAAC;IACD,OAAO,KAAC,SAAS,OAAK,KAAK,GAAI,CAAA;AACnC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ import type { ComponentType, FunctionComponent } from 'react';
2
+ export declare const withOrigami: <P extends object>(Component: ComponentType<P>) => FunctionComponent<P>;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { isBinding, resolve } from './bindings';
3
+ import { useSvgSources } from './svg';
4
+ // Resolve the authored props (reading the hooks they bind to), render the real component.
5
+ export const withOrigami = (Component) => {
6
+ const W = (props) => {
7
+ for (const [k, v] of Object.entries(props)) {
8
+ if (/^on[A-Z]/.test(k) && isBinding(v)) {
9
+ throw new Error(`${k}: a callback has no spelling (ADR-0015); fn() would run at render`);
10
+ }
11
+ }
12
+ const resolved = useSvgSources(resolve(props));
13
+ return _jsx(Component, { ...resolved });
14
+ };
15
+ W.displayName = `Origami(${Component.displayName ?? Component.name})`;
16
+ return W;
17
+ };
18
+ //# sourceMappingURL=withOrigami.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withOrigami.js","sourceRoot":"","sources":["../src/withOrigami.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAErC,0FAA0F;AAC1F,MAAM,CAAC,MAAM,WAAW,GAAG,CAAmB,SAA2B,EAAwB,EAAE;IAC/F,MAAM,CAAC,GAAyB,CAAC,KAAQ,EAAE,EAAE;QACzC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC,EAAE,CAAC;YACpE,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;gBACrC,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAA;YAC5F,CAAC;QACL,CAAC;QACD,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,KAAK,CAAM,CAAC,CAAA;QACnD,OAAO,KAAC,SAAS,OAAK,QAAQ,GAAI,CAAA;IACtC,CAAC,CAAA;IACD,CAAC,CAAC,WAAW,GAAG,WAAW,SAAS,CAAC,WAAW,IAAI,SAAS,CAAC,IAAI,GAAG,CAAA;IACrE,OAAO,CAAC,CAAA;AACZ,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@wix/origami-runtime",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.19.2",
4
+ "description": "React runtime for Origami-generated component wrappers: context bindings, providers, and className resolution",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "!**/*.tsbuildinfo"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc -b .",
13
+ "lint": "oxlint .",
14
+ "test-type-check": "tsc --project tsconfig.test.json",
15
+ "test": "pnpm run test-type-check && vitest --run",
16
+ "clean": "rm -rf dist tsconfig.tsbuildinfo"
17
+ },
18
+ "devDependencies": {
19
+ "@testing-library/react": "^16.3.0",
20
+ "@types/react": "^18.3.1",
21
+ "@wix/services-manager": "^1.0.7",
22
+ "@wix/services-manager-react": "^1.0.8",
23
+ "@wix/site-service-interactions": "^1.0.28",
24
+ "jsdom": "^23.0.1",
25
+ "react": "^18.3.1",
26
+ "typescript": "^6.0.3",
27
+ "vitest": "^4.1.11"
28
+ },
29
+ "peerDependencies": {
30
+ "@wix/services-manager": "^1.0.7",
31
+ "@wix/services-manager-react": "^1.0.8",
32
+ "@wix/site-service-interactions": "^1.0.28",
33
+ "react": "^18.3.1"
34
+ },
35
+ "publishUnscoped": false,
36
+ "publishConfig": {
37
+ "registry": "https://registry.npmjs.org/",
38
+ "access": "public"
39
+ },
40
+ "wix": {
41
+ "artifact": {
42
+ "groupId": "com.wixpress.npm",
43
+ "artifactId": "origami-runtime",
44
+ "targets": {
45
+ "docker": false
46
+ }
47
+ },
48
+ "validations": {
49
+ "source": [
50
+ "lint"
51
+ ],
52
+ "postBuild": [
53
+ "test"
54
+ ]
55
+ }
56
+ },
57
+ "exports": {
58
+ ".": {
59
+ "types": "./dist/index.d.ts",
60
+ "default": "./dist/index.js"
61
+ }
62
+ },
63
+ "type": "module",
64
+ "falconPackageHash": "ff4fcb08d2eb21bdfd748f51b326dd359dc90e3015702d9eecbd8660"
6
65
  }