Skip to content

Commit 792b611

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

19 files changed

+298
-0
lines changed

packages/core/dist/core.cjs

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

packages/core/dist/core.d.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 {};

packages/core/dist/core.js

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
var C = Object.defineProperty;
2+
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);
4+
const T = {
5+
stringify: (t) => t,
6+
parse: (t) => t
7+
}, V = {
8+
stringify: (t) => `${t}`,
9+
parse: (t) => parseFloat(t)
10+
}, N = {
11+
stringify: (t) => t ? "true" : "false",
12+
parse: (t) => /^[ty1-9]/i.test(t)
13+
}, P = {
14+
stringify: (t) => t.name,
15+
parse: (t, e, s) => {
16+
const o = (() => {
17+
if (typeof window < "u" && t in window)
18+
return window[t];
19+
if (typeof global < "u" && t in global)
20+
return global[t];
21+
})();
22+
return typeof o == "function" ? o.bind(s) : void 0;
23+
}
24+
}, $ = {
25+
stringify: (t) => JSON.stringify(t),
26+
parse: (t) => JSON.parse(t)
27+
}, A = {
28+
string: T,
29+
number: V,
30+
boolean: N,
31+
function: P,
32+
json: $
33+
};
34+
function J(t) {
35+
return t.replace(
36+
/([a-z0-9])([A-Z])/g,
37+
(e, s, o) => `${s}-${o.toLowerCase()}`
38+
);
39+
}
40+
const d = Symbol.for("r2wc.render"), g = Symbol.for("r2wc.connected"), f = Symbol.for("r2wc.context"), p = Symbol.for("r2wc.props");
41+
function M(t, e, s) {
42+
var k, O, j;
43+
e.props || (e.props = t.propTypes ? Object.keys(t.propTypes) : []);
44+
const o = Array.isArray(e.props) ? e.props.slice() : Object.keys(e.props), h = {}, m = {}, w = {};
45+
for (const r of o) {
46+
h[r] = Array.isArray(e.props) ? "string" : e.props[r];
47+
const u = J(r);
48+
m[r] = u, w[u] = r;
49+
}
50+
class S extends HTMLElement {
51+
constructor() {
52+
super();
53+
b(this, k, !0);
54+
b(this, O);
55+
b(this, j, {});
56+
b(this, "container");
57+
e.shadow ? this.container = this.attachShadow({
58+
mode: e.shadow
59+
}) : this.container = this, this[p].container = this.container;
60+
for (const i of o) {
61+
const l = m[i], n = this.getAttribute(l), c = h[i], a = c ? A[c] : null;
62+
a != null && a.parse && n && (this[p][i] = a.parse(n, l, this));
63+
}
64+
}
65+
static get observedAttributes() {
66+
return Object.keys(w);
67+
}
68+
connectedCallback() {
69+
this[g] = !0, this[d]();
70+
}
71+
disconnectedCallback() {
72+
this[g] = !1, this[f] && s.unmount(this[f]), delete this[f];
73+
}
74+
attributeChangedCallback(i, l, n) {
75+
const c = w[i], a = h[c], y = a ? A[a] : null;
76+
c in h && (y != null && y.parse) && n && (this[p][c] = y.parse(n, i, this), this[d]());
77+
}
78+
[(k = g, O = f, j = p, d)]() {
79+
this[g] && (this[f] ? s.update(this[f], this[p]) : this[f] = s.mount(
80+
this.container,
81+
t,
82+
this[p]
83+
));
84+
}
85+
}
86+
for (const r of o) {
87+
const u = m[r], i = h[r];
88+
Object.defineProperty(S.prototype, r, {
89+
enumerable: !0,
90+
configurable: !0,
91+
get() {
92+
return this[p][r];
93+
},
94+
set(l) {
95+
this[p][r] = l;
96+
const n = i ? A[i] : null;
97+
if (n != null && n.stringify) {
98+
const c = n.stringify(l, u, this);
99+
this.getAttribute(u) !== c && this.setAttribute(u, c);
100+
} else
101+
this[d]();
102+
}
103+
});
104+
}
105+
return S;
106+
}
107+
function _(t, e) {
108+
const s = "host" in t ? t.host : t;
109+
for (const o in e)
110+
s[o] = e[o];
111+
}
112+
export {
113+
M as default,
114+
_ as useImperativeMethods
115+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { Transform } from "./index";
2+
declare const boolean: Transform<boolean>;
3+
export default boolean;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { Transform } from "./index";
2+
declare const function_: Transform<(...args: unknown[]) => unknown>;
3+
export default function_;
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export interface Transform<Type> {
2+
stringify?: (value: Type, attribute: string, element: HTMLElement) => string;
3+
parse: (value: string, attribute: string, element: HTMLElement) => Type;
4+
}
5+
declare const transforms: {
6+
string: Transform<string>;
7+
number: Transform<number>;
8+
boolean: Transform<boolean>;
9+
function: Transform<(...args: unknown[]) => unknown>;
10+
json: Transform<string>;
11+
};
12+
export type R2WCType = keyof typeof transforms;
13+
export default transforms;
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { Transform } from "./index";
2+
declare const json: Transform<string>;
3+
export default json;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { Transform } from "./index";
2+
declare const number: Transform<number>;
3+
export default number;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { Transform } from "./index";
2+
declare const string: Transform<string>;
3+
export default string;

packages/core/dist/utils.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export declare function toDashedCase(camelCase: string): string;
2+
export declare function toCamelCase(dashedCase: string): string;

packages/emotion/dist/emotion.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),n=require("@emotion/cache"),u=require("@emotion/react"),s=require("react");function h(t,o="rtwc"){return({container:e,...c})=>{const i=s.useMemo(()=>n({key:o,container:e}),[e]);return r.jsx(u.CacheProvider,{value:i,children:r.jsx(t,{...c,container:e})})}}exports.withCacheProvider=h;

packages/emotion/dist/emotion.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import type { R2WCBaseProps } from "@r2wc/core";
2+
export declare function withCacheProvider<Props>(Component: React.ComponentType<Props>, key?: string): React.FC<Props & R2WCBaseProps>;

packages/emotion/dist/emotion.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { jsx as e } from "react/jsx-runtime";
2+
import c from "@emotion/cache";
3+
import { CacheProvider as h } from "@emotion/react";
4+
import { useMemo as n } from "react";
5+
function C(o, t = "rtwc") {
6+
return ({
7+
container: r,
8+
...i
9+
}) => {
10+
const m = n(() => c({ key: t, container: r }), [r]);
11+
return /* @__PURE__ */ e(h, { value: m, children: /* @__PURE__ */ e(
12+
o,
13+
{
14+
...i,
15+
container: r
16+
}
17+
) });
18+
};
19+
}
20+
export {
21+
C as withCacheProvider
22+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"use strict";const p=require("@r2wc/core");function l(d,i,e,m={}){function f(r,n,u){const o=i.createElement(n,u);if("createRoot"in e){const t=e.createRoot(r);return t.render(o),{container:r,root:t,ReactComponent:n}}if("render"in e)return e.render(o,r),{container:r,ReactComponent:n};throw new Error("Invalid ReactDOM instance provided.")}function s({container:r,root:n,ReactComponent:u},o){const t=i.createElement(u,o);if(n){n.render(t);return}if("render"in e){e.render(t,r);return}}function c({container:r,root:n}){if(n){n.unmount();return}if("unmountComponentAtNode"in e){e.unmountComponentAtNode(r);return}}return p(d,m,{mount:f,unmount:c,update:s})}module.exports=l;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import c from "@r2wc/core";
2+
function w(m, i, e, d = {}) {
3+
function f(r, n, u) {
4+
const o = i.createElement(n, u);
5+
if ("createRoot" in e) {
6+
const t = e.createRoot(r);
7+
return t.render(o), {
8+
container: r,
9+
root: t,
10+
ReactComponent: n
11+
};
12+
}
13+
if ("render" in e)
14+
return e.render(o, r), {
15+
container: r,
16+
ReactComponent: n
17+
};
18+
throw new Error("Invalid ReactDOM instance provided.");
19+
}
20+
function p({ container: r, root: n, ReactComponent: u }, o) {
21+
const t = i.createElement(u, o);
22+
if (n) {
23+
n.render(t);
24+
return;
25+
}
26+
if ("render" in e) {
27+
e.render(t, r);
28+
return;
29+
}
30+
}
31+
function l({ container: r, root: n }) {
32+
if (n) {
33+
n.unmount();
34+
return;
35+
}
36+
if ("unmountComponentAtNode" in e) {
37+
e.unmountComponentAtNode(r);
38+
return;
39+
}
40+
}
41+
return c(m, d, { mount: f, unmount: l, update: p });
42+
}
43+
export {
44+
w as default
45+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("react"),i=require("react-dom/client"),o=require("@r2wc/core");function s(e,t,n){const r=i.createRoot(e),c=u.createElement(t,n);return r.render(c),{root:r,ReactComponent:t}}function l({root:e,ReactComponent:t},n){const r=u.createElement(t,n);e.render(r)}function a({root:e}){e.unmount()}function d(e,t={}){return o(e,t,{mount:s,update:l,unmount:a})}Object.defineProperty(exports,"useImperativeMethods",{enumerable:!0,get:()=>o.useImperativeMethods});exports.default=d;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
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;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import n from "react";
2+
import { createRoot as u } from "react-dom/client";
3+
import c from "@r2wc/core";
4+
import { useImperativeMethods as E } from "@r2wc/core";
5+
function f(e, t, o) {
6+
const r = u(e), m = n.createElement(t, o);
7+
return r.render(m), {
8+
root: r,
9+
ReactComponent: t
10+
};
11+
}
12+
function i({ root: e, ReactComponent: t }, o) {
13+
const r = n.createElement(t, o);
14+
e.render(r);
15+
}
16+
function a({ root: e }) {
17+
e.unmount();
18+
}
19+
function l(e, t = {}) {
20+
return c(e, t, { mount: f, update: i, unmount: a });
21+
}
22+
export {
23+
l as default,
24+
E as useImperativeMethods
25+
};

0 commit comments

Comments
 (0)