Skip to content

Commit ae655cb

Browse files
author
Christopher J Baker
committed
add build
1 parent 792b611 commit ae655cb

File tree

13 files changed

+113
-105
lines changed

13 files changed

+113
-105
lines changed

packages/core/dist/core.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +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;
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);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;

packages/core/dist/core.d.ts

+47-25
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,47 @@
1-
import type { R2WCType } from "./transforms";
2-
type PropName<Props> = Exclude<Extract<keyof Props, string>, "container">;
3-
type PropNames<Props> = Array<PropName<Props>>;
4-
export interface R2WCOptions<Props> {
5-
shadow?: "open" | "closed";
6-
props?: PropNames<Props> | Partial<Record<PropName<Props>, R2WCType>>;
7-
}
8-
export interface R2WCRenderer<Props extends R2WCBaseProps, Context> {
9-
mount: (container: HTMLElement, ReactComponent: React.ComponentType<Props>, props: Props) => Context;
10-
update: (context: Context, props: Props) => void;
11-
unmount: (context: Context) => void;
12-
}
13-
export interface R2WCBaseProps {
14-
container: HTMLElement;
15-
}
16-
/**
17-
* Converts a React component into a Web Component.
18-
* @param {ReactComponent}
19-
* @param {Object} options - Optional parameters
20-
* @param {String?} options.shadow - Shadow DOM mode as either open or closed.
21-
* @param {Object|Array?} options.props - Array of camelCasedProps to watch as Strings or { [camelCasedProp]: "string" | "number" | "boolean" | "function" | "json" }
22-
*/
23-
export default function r2wc<Props extends R2WCBaseProps, Context>(ReactComponent: React.ComponentType<Props>, options: R2WCOptions<Props>, renderer: R2WCRenderer<Props, Context>): CustomElementConstructor;
24-
export declare function useImperativeMethods<Methods extends string>(container: HTMLElement | ShadowRoot, methods: Record<Methods, () => unknown>): void;
25-
export {};
1+
declare type PropName<Props> = Exclude<Extract<keyof Props, string>, "container">;
2+
3+
declare type PropNames<Props> = Array<PropName<Props>>;
4+
5+
/**
6+
* Converts a React component into a Web Component.
7+
* @param {ReactComponent}
8+
* @param {Object} options - Optional parameters
9+
* @param {String?} options.shadow - Shadow DOM mode as either open or closed.
10+
* @param {Object|Array?} options.props - Array of camelCasedProps to watch as Strings or { [camelCasedProp]: "string" | "number" | "boolean" | "function" | "json" }
11+
*/
12+
declare function r2wc<Props extends R2WCBaseProps, Context>(ReactComponent: React.ComponentType<Props>, options: R2WCOptions<Props>, renderer: R2WCRenderer<Props, Context>): CustomElementConstructor;
13+
export default r2wc;
14+
15+
export declare interface R2WCBaseProps {
16+
container: HTMLElement;
17+
}
18+
19+
export declare interface R2WCOptions<Props> {
20+
shadow?: "open" | "closed";
21+
props?: PropNames<Props> | Partial<Record<PropName<Props>, R2WCType>>;
22+
}
23+
24+
export declare interface R2WCRenderer<Props extends R2WCBaseProps, Context> {
25+
mount: (container: HTMLElement, ReactComponent: React.ComponentType<Props>, props: Props) => Context;
26+
update: (context: Context, props: Props) => void;
27+
unmount: (context: Context) => void;
28+
}
29+
30+
declare type R2WCType = keyof typeof transforms;
31+
32+
declare interface Transform<Type> {
33+
stringify?: (value: Type, attribute: string, element: HTMLElement) => string;
34+
parse: (value: string, attribute: string, element: HTMLElement) => Type;
35+
}
36+
37+
declare const transforms: {
38+
string: Transform<string>;
39+
number: Transform<number>;
40+
boolean: Transform<boolean>;
41+
function: Transform<(...args: unknown[]) => unknown>;
42+
json: Transform<string>;
43+
};
44+
45+
export declare function useImperativeMethods<Methods extends string>(container: HTMLElement | ShadowRoot, methods: Record<Methods, () => unknown>): void;
46+
47+
export { }

packages/core/dist/core.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
var C = Object.defineProperty;
22
var x = (t, e, s) => e in t ? C(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
3-
var b = (t, e, s) => (x(t, typeof e != "symbol" ? e + "" : e, s), s);
3+
var b = (t, e, s) => x(t, typeof e != "symbol" ? e + "" : e, s);
44
const T = {
5-
stringify: (t) => t,
6-
parse: (t) => t
7-
}, V = {
8-
stringify: (t) => `${t}`,
9-
parse: (t) => parseFloat(t)
10-
}, N = {
115
stringify: (t) => t ? "true" : "false",
126
parse: (t) => /^[ty1-9]/i.test(t)
13-
}, P = {
7+
}, V = {
148
stringify: (t) => t.name,
159
parse: (t, e, s) => {
1610
const o = (() => {
@@ -21,15 +15,21 @@ const T = {
2115
})();
2216
return typeof o == "function" ? o.bind(s) : void 0;
2317
}
24-
}, $ = {
18+
}, N = {
2519
stringify: (t) => JSON.stringify(t),
2620
parse: (t) => JSON.parse(t)
21+
}, P = {
22+
stringify: (t) => `${t}`,
23+
parse: (t) => parseFloat(t)
24+
}, $ = {
25+
stringify: (t) => t,
26+
parse: (t) => t
2727
}, A = {
28-
string: T,
29-
number: V,
30-
boolean: N,
31-
function: P,
32-
json: $
28+
string: $,
29+
number: P,
30+
boolean: T,
31+
function: V,
32+
json: N
3333
};
3434
function J(t) {
3535
return t.replace(
@@ -50,9 +50,9 @@ function M(t, e, s) {
5050
class S extends HTMLElement {
5151
constructor() {
5252
super();
53-
b(this, k, !0);
53+
b(this, j, !0);
5454
b(this, O);
55-
b(this, j, {});
55+
b(this, k, {});
5656
b(this, "container");
5757
e.shadow ? this.container = this.attachShadow({
5858
mode: e.shadow
@@ -75,7 +75,7 @@ function M(t, e, s) {
7575
const c = w[i], a = h[c], y = a ? A[a] : null;
7676
c in h && (y != null && y.parse) && n && (this[p][c] = y.parse(n, i, this), this[d]());
7777
}
78-
[(k = g, O = f, j = p, d)]() {
78+
[(j = g, O = f, k = p, d)]() {
7979
this[g] && (this[f] ? s.update(this[f], this[p]) : this[f] = s.mount(
8080
this.container,
8181
t,

packages/core/dist/transforms/boolean.d.ts

-3
This file was deleted.

packages/core/dist/transforms/function.d.ts

-3
This file was deleted.

packages/core/dist/transforms/index.d.ts

-13
This file was deleted.

packages/core/dist/transforms/json.d.ts

-3
This file was deleted.

packages/core/dist/transforms/number.d.ts

-3
This file was deleted.

packages/core/dist/transforms/string.d.ts

-3
This file was deleted.

packages/core/dist/utils.d.ts

-2
This file was deleted.

packages/emotion/dist/emotion.d.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
import type { R2WCBaseProps } from "@r2wc/core";
2-
export declare function withCacheProvider<Props>(Component: React.ComponentType<Props>, key?: string): React.FC<Props & R2WCBaseProps>;
1+
import { R2WCBaseProps } from '@r2wc/core';
2+
3+
export declare function withCacheProvider<Props>(Component: React.ComponentType<Props>, key?: string): React.FC<Props & R2WCBaseProps>;
4+
5+
export { }
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1-
import type { R2WCOptions } from "@r2wc/core";
2-
interface ReactType {
3-
createElement: (type: any, data: any, children?: any) => React.ReactElement;
4-
}
5-
interface ReactDOMRootRootType {
6-
render: (element: React.ReactElement | null) => void;
7-
unmount: () => void;
8-
}
9-
interface ReactDOMRootType {
10-
createRoot: (container: Element | DocumentFragment, options?: any) => ReactDOMRootRootType;
11-
}
12-
interface ReactDOMRenderType {
13-
unmountComponentAtNode: (container: Element | DocumentFragment) => boolean;
14-
render: (element: React.ReactElement, container: ReactDOM.Container | null) => unknown;
15-
}
16-
/**
17-
* Converts a React component into a webcomponent by mounting it into an HTMLElement container.
18-
* @param {ReactComponent}
19-
* @param {React}
20-
* @param {ReactDOM}
21-
* @param {Object} options - Optional parameters
22-
* @param {String?} options.shadow - Shadow DOM mode as either open or closed.
23-
* @param {Object|Array?} options.props - Array of camelCasedProps to watch as Strings or { [camelCasedProp]: String | Number | Boolean | Function | Object | Array }
24-
*/
25-
export default function r2wc<Props extends object>(ReactComponent: React.ComponentType<Props>, React: ReactType, ReactDOM: ReactDOMRootType | ReactDOMRenderType, options?: R2WCOptions<Props>): CustomElementConstructor;
26-
export {};
1+
import { R2WCOptions } from '@r2wc/core';
2+
3+
/**
4+
* Converts a React component into a webcomponent by mounting it into an HTMLElement container.
5+
* @param {ReactComponent}
6+
* @param {React}
7+
* @param {ReactDOM}
8+
* @param {Object} options - Optional parameters
9+
* @param {String?} options.shadow - Shadow DOM mode as either open or closed.
10+
* @param {Object|Array?} options.props - Array of camelCasedProps to watch as Strings or { [camelCasedProp]: String | Number | Boolean | Function | Object | Array }
11+
*/
12+
declare function r2wc<Props extends object>(ReactComponent: React.ComponentType<Props>, React: ReactType, ReactDOM: ReactDOMRootType | ReactDOMRenderType, options?: R2WCOptions<Props>): CustomElementConstructor;
13+
export default r2wc;
14+
15+
declare interface ReactDOMRenderType {
16+
unmountComponentAtNode: (container: Element | DocumentFragment) => boolean;
17+
render: (element: React.ReactElement, container: ReactDOM.Container | null) => unknown;
18+
}
19+
20+
declare interface ReactDOMRootRootType {
21+
render: (element: React.ReactElement | null) => void;
22+
unmount: () => void;
23+
}
24+
25+
declare interface ReactDOMRootType {
26+
createRoot: (container: Element | DocumentFragment, options?: any) => ReactDOMRootRootType;
27+
}
28+
29+
declare interface ReactType {
30+
createElement: (type: any, data: any, children?: any) => React.ReactElement;
31+
}
32+
33+
export { }
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import type { R2WCOptions } from "@r2wc/core";
2-
import React from "react";
3-
export { useImperativeMethods } from "@r2wc/core";
4-
export default function r2wc<Props extends object>(ReactComponent: React.ComponentType<Props>, options?: R2WCOptions<Props>): CustomElementConstructor;
1+
import { default as default_2 } from 'react';
2+
import { R2WCOptions } from '@r2wc/core';
3+
import { useImperativeMethods } from '@r2wc/core';
4+
5+
declare function r2wc<Props extends object>(ReactComponent: default_2.ComponentType<Props>, options?: R2WCOptions<Props>): CustomElementConstructor;
6+
export default r2wc;
7+
8+
export { useImperativeMethods }
9+
10+
export { }

0 commit comments

Comments
 (0)