diff --git a/packages/core/dist/core.cjs b/packages/core/dist/core.cjs index aa9bd72..4cf5b34 100644 --- a/packages/core/dist/core.cjs +++ b/packages/core/dist/core.cjs @@ -1 +1 @@ -"use strict";var C=Object.defineProperty;var M=(t,e,s)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var b=(t,e,s)=>(M(t,typeof e!="symbol"?e+"":e,s),s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const T={stringify:t=>t,parse:t=>t},P={stringify:t=>`${t}`,parse:t=>parseFloat(t)},V={stringify:t=>t?"true":"false",parse:t=>/^[ty1-9]/i.test(t)},_={stringify:t=>t.name,parse:(t,e,s)=>{const o=(()=>{if(typeof window<"u"&&t in window)return window[t];if(typeof global<"u"&&t in global)return global[t]})();return typeof o=="function"?o.bind(s):void 0}},x={stringify:t=>JSON.stringify(t),parse:t=>JSON.parse(t)},A={string:T,number:P,boolean:V,function:_,json:x};function N(t){return t.replace(/([a-z0-9])([A-Z])/g,(e,s,o)=>`${s}-${o.toLowerCase()}`)}const d=Symbol.for("r2wc.render"),g=Symbol.for("r2wc.connected"),l=Symbol.for("r2wc.context"),p=Symbol.for("r2wc.props");function $(t,e,s){var O,j,k;e.props||(e.props=t.propTypes?Object.keys(t.propTypes):[]);const o=Array.isArray(e.props)?e.props.slice():Object.keys(e.props),h={},m={},w={};for(const r of o){h[r]=Array.isArray(e.props)?"string":e.props[r];const u=N(r);m[r]=u,w[u]=r}class S extends HTMLElement{constructor(){super();b(this,O,!0);b(this,j);b(this,k,{});b(this,"container");e.shadow?this.container=this.attachShadow({mode:e.shadow}):this.container=this,this[p].container=this.container;for(const i of o){const f=m[i],n=this.getAttribute(f),c=h[i],a=c?A[c]:null;a!=null&&a.parse&&n&&(this[p][i]=a.parse(n,f,this))}}static get observedAttributes(){return Object.keys(w)}connectedCallback(){this[g]=!0,this[d]()}disconnectedCallback(){this[g]=!1,this[l]&&s.unmount(this[l]),delete this[l]}attributeChangedCallback(i,f,n){const c=w[i],a=h[c],y=a?A[a]:null;c in h&&(y!=null&&y.parse)&&n&&(this[p][c]=y.parse(n,i,this),this[d]())}[(O=g,j=l,k=p,d)](){this[g]&&(this[l]?s.update(this[l],this[p]):this[l]=s.mount(this.container,t,this[p]))}}for(const r of o){const u=m[r],i=h[r];Object.defineProperty(S.prototype,r,{enumerable:!0,configurable:!0,get(){return this[p][r]},set(f){this[p][r]=f;const n=i?A[i]:null;if(n!=null&&n.stringify){const c=n.stringify(f,u,this);this.getAttribute(u)!==c&&this.setAttribute(u,c)}else this[d]()}})}return S}function v(t,e){const s="host"in t?t.host:t;for(const o in e)s[o]=e[o]}exports.default=$;exports.useImperativeMethods=v; +"use strict";var C=Object.defineProperty;var M=(t,e,s)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var b=(t,e,s)=>M(t,typeof e!="symbol"?e+"":e,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const T={stringify:t=>t?"true":"false",parse:t=>/^[ty1-9]/i.test(t)},P={stringify:t=>t.name,parse:(t,e,s)=>{const o=(()=>{if(typeof window<"u"&&t in window)return window[t];if(typeof global<"u"&&t in global)return global[t]})();return typeof o=="function"?o.bind(s):void 0}},V={stringify:t=>JSON.stringify(t),parse:t=>JSON.parse(t)},_={stringify:t=>`${t}`,parse:t=>parseFloat(t)},x={stringify:t=>t,parse:t=>t},A={string:x,number:_,boolean:T,function:P,json:V};function N(t){return t.replace(/([a-z0-9])([A-Z])/g,(e,s,o)=>`${s}-${o.toLowerCase()}`)}const d=Symbol.for("r2wc.render"),g=Symbol.for("r2wc.connected"),l=Symbol.for("r2wc.context"),p=Symbol.for("r2wc.props");function $(t,e,s){var O,j,k;e.props||(e.props=t.propTypes?Object.keys(t.propTypes):[]);const o=Array.isArray(e.props)?e.props.slice():Object.keys(e.props),h={},m={},w={};for(const r of o){h[r]=Array.isArray(e.props)?"string":e.props[r];const u=N(r);m[r]=u,w[u]=r}class S extends HTMLElement{constructor(){super();b(this,k,!0);b(this,j);b(this,O,{});b(this,"container");e.shadow?this.container=this.attachShadow({mode:e.shadow}):this.container=this,this[p].container=this.container;for(const i of o){const f=m[i],n=this.getAttribute(f),c=h[i],a=c?A[c]:null;a!=null&&a.parse&&n&&(this[p][i]=a.parse(n,f,this))}}static get observedAttributes(){return Object.keys(w)}connectedCallback(){this[g]=!0,this[d]()}disconnectedCallback(){this[g]=!1,this[l]&&s.unmount(this[l]),delete this[l]}attributeChangedCallback(i,f,n){const c=w[i],a=h[c],y=a?A[a]:null;c in h&&(y!=null&&y.parse)&&n&&(this[p][c]=y.parse(n,i,this),this[d]())}[(k=g,j=l,O=p,d)](){this[g]&&(this[l]?s.update(this[l],this[p]):this[l]=s.mount(this.container,t,this[p]))}}for(const r of o){const u=m[r],i=h[r];Object.defineProperty(S.prototype,r,{enumerable:!0,configurable:!0,get(){return this[p][r]},set(f){this[p][r]=f;const n=i?A[i]:null;if(n!=null&&n.stringify){const c=n.stringify(f,u,this);this.getAttribute(u)!==c&&this.setAttribute(u,c)}else this[d]()}})}return S}function v(t,e){const s="host"in t?t.host:t;for(const o in e)s[o]=e[o]}exports.default=$;exports.useImperativeMethods=v; diff --git a/packages/core/dist/core.d.ts b/packages/core/dist/core.d.ts index 6fbec20..a39f471 100644 --- a/packages/core/dist/core.d.ts +++ b/packages/core/dist/core.d.ts @@ -1,25 +1,47 @@ -import type { R2WCType } from "./transforms"; -type PropName = Exclude, "container">; -type PropNames = Array>; -export interface R2WCOptions { - shadow?: "open" | "closed"; - props?: PropNames | Partial, R2WCType>>; -} -export interface R2WCRenderer { - mount: (container: HTMLElement, ReactComponent: React.ComponentType, props: Props) => Context; - update: (context: Context, props: Props) => void; - unmount: (context: Context) => void; -} -export interface R2WCBaseProps { - container: HTMLElement; -} -/** - * Converts a React component into a Web Component. - * @param {ReactComponent} - * @param {Object} options - Optional parameters - * @param {String?} options.shadow - Shadow DOM mode as either open or closed. - * @param {Object|Array?} options.props - Array of camelCasedProps to watch as Strings or { [camelCasedProp]: "string" | "number" | "boolean" | "function" | "json" } - */ -export default function r2wc(ReactComponent: React.ComponentType, options: R2WCOptions, renderer: R2WCRenderer): CustomElementConstructor; -export declare function useImperativeMethods(container: HTMLElement | ShadowRoot, methods: Record unknown>): void; -export {}; +declare type PropName = Exclude, "container">; + +declare type PropNames = Array>; + +/** + * Converts a React component into a Web Component. + * @param {ReactComponent} + * @param {Object} options - Optional parameters + * @param {String?} options.shadow - Shadow DOM mode as either open or closed. + * @param {Object|Array?} options.props - Array of camelCasedProps to watch as Strings or { [camelCasedProp]: "string" | "number" | "boolean" | "function" | "json" } + */ +declare function r2wc(ReactComponent: React.ComponentType, options: R2WCOptions, renderer: R2WCRenderer): CustomElementConstructor; +export default r2wc; + +export declare interface R2WCBaseProps { + container: HTMLElement; +} + +export declare interface R2WCOptions { + shadow?: "open" | "closed"; + props?: PropNames | Partial, R2WCType>>; +} + +export declare interface R2WCRenderer { + mount: (container: HTMLElement, ReactComponent: React.ComponentType, props: Props) => Context; + update: (context: Context, props: Props) => void; + unmount: (context: Context) => void; +} + +declare type R2WCType = keyof typeof transforms; + +declare interface Transform { + stringify?: (value: Type, attribute: string, element: HTMLElement) => string; + parse: (value: string, attribute: string, element: HTMLElement) => Type; +} + +declare const transforms: { + string: Transform; + number: Transform; + boolean: Transform; + function: Transform<(...args: unknown[]) => unknown>; + json: Transform; +}; + +export declare function useImperativeMethods(container: HTMLElement | ShadowRoot, methods: Record unknown>): void; + +export { } diff --git a/packages/core/dist/core.js b/packages/core/dist/core.js index 96b74c6..92d043b 100644 --- a/packages/core/dist/core.js +++ b/packages/core/dist/core.js @@ -1,16 +1,10 @@ var C = Object.defineProperty; var x = (t, e, s) => e in t ? C(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s; -var b = (t, e, s) => (x(t, typeof e != "symbol" ? e + "" : e, s), s); +var b = (t, e, s) => x(t, typeof e != "symbol" ? e + "" : e, s); const T = { - stringify: (t) => t, - parse: (t) => t -}, V = { - stringify: (t) => `${t}`, - parse: (t) => parseFloat(t) -}, N = { stringify: (t) => t ? "true" : "false", parse: (t) => /^[ty1-9]/i.test(t) -}, P = { +}, V = { stringify: (t) => t.name, parse: (t, e, s) => { const o = (() => { @@ -21,15 +15,21 @@ const T = { })(); return typeof o == "function" ? o.bind(s) : void 0; } -}, $ = { +}, N = { stringify: (t) => JSON.stringify(t), parse: (t) => JSON.parse(t) +}, P = { + stringify: (t) => `${t}`, + parse: (t) => parseFloat(t) +}, $ = { + stringify: (t) => t, + parse: (t) => t }, A = { - string: T, - number: V, - boolean: N, - function: P, - json: $ + string: $, + number: P, + boolean: T, + function: V, + json: N }; function J(t) { return t.replace( @@ -50,9 +50,9 @@ function M(t, e, s) { class S extends HTMLElement { constructor() { super(); - b(this, k, !0); + b(this, j, !0); b(this, O); - b(this, j, {}); + b(this, k, {}); b(this, "container"); e.shadow ? this.container = this.attachShadow({ mode: e.shadow @@ -75,7 +75,7 @@ function M(t, e, s) { const c = w[i], a = h[c], y = a ? A[a] : null; c in h && (y != null && y.parse) && n && (this[p][c] = y.parse(n, i, this), this[d]()); } - [(k = g, O = f, j = p, d)]() { + [(j = g, O = f, k = p, d)]() { this[g] && (this[f] ? s.update(this[f], this[p]) : this[f] = s.mount( this.container, t, diff --git a/packages/core/dist/transforms/boolean.d.ts b/packages/core/dist/transforms/boolean.d.ts deleted file mode 100644 index 4975864..0000000 --- a/packages/core/dist/transforms/boolean.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { Transform } from "./index"; -declare const boolean: Transform; -export default boolean; diff --git a/packages/core/dist/transforms/function.d.ts b/packages/core/dist/transforms/function.d.ts deleted file mode 100644 index 5cca9b5..0000000 --- a/packages/core/dist/transforms/function.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { Transform } from "./index"; -declare const function_: Transform<(...args: unknown[]) => unknown>; -export default function_; diff --git a/packages/core/dist/transforms/index.d.ts b/packages/core/dist/transforms/index.d.ts deleted file mode 100644 index d4b87af..0000000 --- a/packages/core/dist/transforms/index.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface Transform { - stringify?: (value: Type, attribute: string, element: HTMLElement) => string; - parse: (value: string, attribute: string, element: HTMLElement) => Type; -} -declare const transforms: { - string: Transform; - number: Transform; - boolean: Transform; - function: Transform<(...args: unknown[]) => unknown>; - json: Transform; -}; -export type R2WCType = keyof typeof transforms; -export default transforms; diff --git a/packages/core/dist/transforms/json.d.ts b/packages/core/dist/transforms/json.d.ts deleted file mode 100644 index 9a995f5..0000000 --- a/packages/core/dist/transforms/json.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { Transform } from "./index"; -declare const json: Transform; -export default json; diff --git a/packages/core/dist/transforms/number.d.ts b/packages/core/dist/transforms/number.d.ts deleted file mode 100644 index ff1a7b7..0000000 --- a/packages/core/dist/transforms/number.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { Transform } from "./index"; -declare const number: Transform; -export default number; diff --git a/packages/core/dist/transforms/string.d.ts b/packages/core/dist/transforms/string.d.ts deleted file mode 100644 index f77133c..0000000 --- a/packages/core/dist/transforms/string.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { Transform } from "./index"; -declare const string: Transform; -export default string; diff --git a/packages/core/dist/utils.d.ts b/packages/core/dist/utils.d.ts deleted file mode 100644 index aea722c..0000000 --- a/packages/core/dist/utils.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export declare function toDashedCase(camelCase: string): string; -export declare function toCamelCase(dashedCase: string): string; diff --git a/packages/emotion/dist/emotion.d.ts b/packages/emotion/dist/emotion.d.ts index 7e60ec2..e714ed1 100644 --- a/packages/emotion/dist/emotion.d.ts +++ b/packages/emotion/dist/emotion.d.ts @@ -1,2 +1,5 @@ -import type { R2WCBaseProps } from "@r2wc/core"; -export declare function withCacheProvider(Component: React.ComponentType, key?: string): React.FC; +import { R2WCBaseProps } from '@r2wc/core'; + +export declare function withCacheProvider(Component: React.ComponentType, key?: string): React.FC; + +export { } diff --git a/packages/legacy/dist/react-to-webcomponent.d.ts b/packages/legacy/dist/react-to-webcomponent.d.ts index 87abe60..a4191e8 100644 --- a/packages/legacy/dist/react-to-webcomponent.d.ts +++ b/packages/legacy/dist/react-to-webcomponent.d.ts @@ -1,26 +1,33 @@ -import type { R2WCOptions } from "@r2wc/core"; -interface ReactType { - createElement: (type: any, data: any, children?: any) => React.ReactElement; -} -interface ReactDOMRootRootType { - render: (element: React.ReactElement | null) => void; - unmount: () => void; -} -interface ReactDOMRootType { - createRoot: (container: Element | DocumentFragment, options?: any) => ReactDOMRootRootType; -} -interface ReactDOMRenderType { - unmountComponentAtNode: (container: Element | DocumentFragment) => boolean; - render: (element: React.ReactElement, container: ReactDOM.Container | null) => unknown; -} -/** - * Converts a React component into a webcomponent by mounting it into an HTMLElement container. - * @param {ReactComponent} - * @param {React} - * @param {ReactDOM} - * @param {Object} options - Optional parameters - * @param {String?} options.shadow - Shadow DOM mode as either open or closed. - * @param {Object|Array?} options.props - Array of camelCasedProps to watch as Strings or { [camelCasedProp]: String | Number | Boolean | Function | Object | Array } - */ -export default function r2wc(ReactComponent: React.ComponentType, React: ReactType, ReactDOM: ReactDOMRootType | ReactDOMRenderType, options?: R2WCOptions): CustomElementConstructor; -export {}; +import { R2WCOptions } from '@r2wc/core'; + +/** + * Converts a React component into a webcomponent by mounting it into an HTMLElement container. + * @param {ReactComponent} + * @param {React} + * @param {ReactDOM} + * @param {Object} options - Optional parameters + * @param {String?} options.shadow - Shadow DOM mode as either open or closed. + * @param {Object|Array?} options.props - Array of camelCasedProps to watch as Strings or { [camelCasedProp]: String | Number | Boolean | Function | Object | Array } + */ +declare function r2wc(ReactComponent: React.ComponentType, React: ReactType, ReactDOM: ReactDOMRootType | ReactDOMRenderType, options?: R2WCOptions): CustomElementConstructor; +export default r2wc; + +declare interface ReactDOMRenderType { + unmountComponentAtNode: (container: Element | DocumentFragment) => boolean; + render: (element: React.ReactElement, container: ReactDOM.Container | null) => unknown; +} + +declare interface ReactDOMRootRootType { + render: (element: React.ReactElement | null) => void; + unmount: () => void; +} + +declare interface ReactDOMRootType { + createRoot: (container: Element | DocumentFragment, options?: any) => ReactDOMRootRootType; +} + +declare interface ReactType { + createElement: (type: any, data: any, children?: any) => React.ReactElement; +} + +export { } diff --git a/packages/react-to-web-component/dist/react-to-web-component.d.ts b/packages/react-to-web-component/dist/react-to-web-component.d.ts index 9c22254..4fae64d 100644 --- a/packages/react-to-web-component/dist/react-to-web-component.d.ts +++ b/packages/react-to-web-component/dist/react-to-web-component.d.ts @@ -1,4 +1,10 @@ -import type { R2WCOptions } from "@r2wc/core"; -import React from "react"; -export { useImperativeMethods } from "@r2wc/core"; -export default function r2wc(ReactComponent: React.ComponentType, options?: R2WCOptions): CustomElementConstructor; +import { default as default_2 } from 'react'; +import { R2WCOptions } from '@r2wc/core'; +import { useImperativeMethods } from '@r2wc/core'; + +declare function r2wc(ReactComponent: default_2.ComponentType, options?: R2WCOptions): CustomElementConstructor; +export default r2wc; + +export { useImperativeMethods } + +export { }