@rootnative/web 0.0.0-alpha.1 → 0.0.0-alpha.3

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.
@@ -1,8 +1,13 @@
1
- import { t as hasDOM } from "./env-BQE0B2yw.js";
2
- import { createContext, useContext } from "react";
1
+ import { t as hasDOM } from "./env-DK5Mt9yX.js";
3
2
  // src/style/registry.ts
3
+ const RESET_STYLE_ID = "rootnative-style-reset";
4
4
  const SHORTHAND_STYLE_ID = "rootnative-style-shorthand";
5
5
  const LONGHAND_STYLE_ID = "rootnative-style-longhand";
6
+ const SHEET_ORDER = [
7
+ RESET_STYLE_ID,
8
+ SHORTHAND_STYLE_ID,
9
+ LONGHAND_STYLE_ID
10
+ ];
6
11
  const shorthandProperties = /* @__PURE__ */ new Set([
7
12
  "border",
8
13
  "borderBlock",
@@ -27,6 +32,7 @@ const shorthandProperties = /* @__PURE__ */ new Set([
27
32
  "paddingInline",
28
33
  "textDecoration"
29
34
  ]);
35
+ const isShorthandProperty = (name) => shorthandProperties.has(name);
30
36
  const toKebab = (name) => name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
31
37
  const hash = (input) => {
32
38
  let h = 2166136261;
@@ -38,14 +44,17 @@ const hash = (input) => {
38
44
  };
39
45
  var StyleRegistry = class {
40
46
  constructor(sheets = {
47
+ reset: null,
41
48
  shorthand: null,
42
49
  longhand: null
43
50
  }) {
44
51
  this.classNames = /* @__PURE__ */ new Map();
45
52
  this.adopted = /* @__PURE__ */ new Set();
53
+ this.resetRules = [];
46
54
  this.shorthandRules = [];
47
55
  this.longhandRules = [];
48
56
  this.sheets = sheets;
57
+ this.adopt(sheets.reset);
49
58
  this.adopt(sheets.shorthand);
50
59
  this.adopt(sheets.longhand);
51
60
  }
@@ -55,7 +64,7 @@ var StyleRegistry = class {
55
64
  if (known !== void 0) return known;
56
65
  const className = `rn-${hash(key)}`;
57
66
  this.classNames.set(key, className);
58
- const shorthand = shorthandProperties.has(property);
67
+ const shorthand = isShorthandProperty(property);
59
68
  const rule = `.${className}{${toKebab(property)}:${value}}`;
60
69
  (shorthand ? this.shorthandRules : this.longhandRules).push(rule);
61
70
  if (!this.adopted.has(className)) {
@@ -81,14 +90,26 @@ var StyleRegistry = class {
81
90
  }
82
91
  return className;
83
92
  }
93
+ resetClass(className, declarations) {
94
+ if (this.classNames.has(className)) return className;
95
+ this.classNames.set(className, className);
96
+ const rule = `.${className}{${Object.entries(declarations).map(([property, value]) => `${toKebab(property)}:${value}`).join(";")}}`;
97
+ this.resetRules.push(rule);
98
+ if (!this.adopted.has(className)) {
99
+ const sheet = this.sheets.reset;
100
+ sheet?.insertRule(rule, sheet.cssRules.length);
101
+ }
102
+ return className;
103
+ }
84
104
  cssText() {
85
105
  return {
106
+ reset: this.resetRules.join("\n"),
86
107
  shorthand: this.shorthandRules.join("\n"),
87
108
  longhand: this.longhandRules.join("\n")
88
109
  };
89
110
  }
90
111
  get ruleCount() {
91
- return this.shorthandRules.length + this.longhandRules.length;
112
+ return this.resetRules.length + this.shorthandRules.length + this.longhandRules.length;
92
113
  }
93
114
  adopt(sheet) {
94
115
  if (sheet === null) return;
@@ -99,9 +120,11 @@ let defaultRegistry = null;
99
120
  const getStyleRegistry = () => {
100
121
  if (defaultRegistry !== null) return defaultRegistry;
101
122
  defaultRegistry = new StyleRegistry(hasDOM() ? {
123
+ reset: domSheet(RESET_STYLE_ID),
102
124
  shorthand: domSheet(SHORTHAND_STYLE_ID),
103
125
  longhand: domSheet(LONGHAND_STYLE_ID)
104
126
  } : {
127
+ reset: null,
105
128
  shorthand: null,
106
129
  longhand: null
107
130
  });
@@ -112,13 +135,12 @@ const domSheet = (id) => {
112
135
  if (element === null) {
113
136
  element = document.createElement("style");
114
137
  element.id = id;
115
- document.head.appendChild(element);
138
+ const later = SHEET_ORDER.slice(SHEET_ORDER.indexOf(id) + 1).map((name) => document.getElementById(name)).find((found) => found !== null);
139
+ if (later === void 0 || later === null) document.head.appendChild(element);
140
+ else later.before(element);
116
141
  }
117
142
  return element.sheet;
118
143
  };
119
- // src/style/StyleRegistryContext.ts
120
- const StyleRegistryContext = createContext(null);
121
- const useStyleRegistry = () => useContext(StyleRegistryContext) ?? getStyleRegistry();
122
- export { StyleRegistry as a, SHORTHAND_STYLE_ID as i, useStyleRegistry as n, getStyleRegistry as o, LONGHAND_STYLE_ID as r, StyleRegistryContext as t };
144
+ export { getStyleRegistry as a, StyleRegistry as i, RESET_STYLE_ID as n, isShorthandProperty as o, SHORTHAND_STYLE_ID as r, LONGHAND_STYLE_ID as t };
123
145
 
124
- //# sourceMappingURL=StyleRegistryContext-D6yDrZk0.js.map
146
+ //# sourceMappingURL=registry-Aa_Od5m0.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry-Aa_Od5m0.js","names":[],"sources":["../src/style/registry.ts"],"sourcesContent":["import { hasDOM } from '../utils/env'\nimport type { CSSDeclarations } from './types'\n\n// Three style elements, and with equal specificity the later sheet wins:\n// - the reset rules of the components, which stand for the defaults of native layout,\n// - the shorthand rules of the app's styles,\n// - the longhand rules of the app's styles.\n// So any style of the app beats a default, and a longhand always beats a shorthand, as on native.\nexport const RESET_STYLE_ID = 'rootnative-style-reset'\nexport const SHORTHAND_STYLE_ID = 'rootnative-style-shorthand'\nexport const LONGHAND_STYLE_ID = 'rootnative-style-longhand'\n\nconst SHEET_ORDER = [RESET_STYLE_ID, SHORTHAND_STYLE_ID, LONGHAND_STYLE_ID] as const\n\nconst shorthandProperties: ReadonlySet<string> = new Set([\n 'border',\n 'borderBlock',\n 'borderColor',\n 'borderInline',\n 'borderRadius',\n 'borderStyle',\n 'borderWidth',\n 'flex',\n 'flexFlow',\n 'gap',\n 'inset',\n 'insetBlock',\n 'insetInline',\n 'margin',\n 'marginBlock',\n 'marginInline',\n 'outline',\n 'overflow',\n 'padding',\n 'paddingBlock',\n 'paddingInline',\n 'textDecoration',\n])\n\nexport const isShorthandProperty = (name: string): boolean => shorthandProperties.has(name)\n\nconst toKebab = (name: string): string => name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)\n\nconst hash = (input: string): string => {\n let h = 0x811c9dc5\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i)\n h = Math.imul(h, 0x01000193)\n }\n return (h >>> 0).toString(36)\n}\n\nexport type StyleSheets = {\n reset: CSSStyleSheet | null\n shorthand: CSSStyleSheet | null\n longhand: CSSStyleSheet | null\n}\n\nexport class StyleRegistry {\n private readonly classNames = new Map<string, string>()\n private readonly adopted = new Set<string>()\n private readonly resetRules: string[] = []\n private readonly shorthandRules: string[] = []\n private readonly longhandRules: string[] = []\n private readonly sheets: StyleSheets\n\n constructor(sheets: StyleSheets = { reset: null, shorthand: null, longhand: null }) {\n this.sheets = sheets\n this.adopt(sheets.reset)\n this.adopt(sheets.shorthand)\n this.adopt(sheets.longhand)\n }\n\n classFor(property: string, value: string): string {\n const key = `${property}:${value}`\n const known = this.classNames.get(key)\n if (known !== undefined) return known\n\n const className = `rn-${hash(key)}`\n this.classNames.set(key, className)\n\n const shorthand = isShorthandProperty(property)\n const rule = `.${className}{${toKebab(property)}:${value}}`\n const rules = shorthand ? this.shorthandRules : this.longhandRules\n rules.push(rule)\n\n if (!this.adopted.has(className)) {\n const sheet = shorthand ? this.sheets.shorthand : this.sheets.longhand\n sheet?.insertRule(rule, sheet.cssRules.length)\n }\n return className\n }\n\n classesFor(declarations: CSSDeclarations): string {\n const names: string[] = []\n for (const property in declarations) {\n names.push(this.classFor(property, declarations[property] as string))\n }\n return names.join(' ')\n }\n\n // Inserts a fixed set of rules under one class name, once. For rules an atomic\n // declaration cannot express, for example a child selector.\n staticClass(className: string, rules: ReadonlyArray<string>): string {\n if (this.classNames.has(className)) return className\n this.classNames.set(className, className)\n for (const rule of rules) {\n this.longhandRules.push(rule)\n if (!this.adopted.has(className)) {\n const sheet = this.sheets.longhand\n sheet?.insertRule(rule, sheet.cssRules.length)\n }\n }\n return className\n }\n\n // Inserts the default style of a component as one rule in the reset sheet, once. Its class\n // name is its own, never an atomic one, so a style of the app with the same declaration\n // still gets an atomic class that beats the default.\n resetClass(className: string, declarations: CSSDeclarations): string {\n if (this.classNames.has(className)) return className\n this.classNames.set(className, className)\n const body = Object.entries(declarations)\n .map(([property, value]) => `${toKebab(property)}:${value}`)\n .join(';')\n const rule = `.${className}{${body}}`\n this.resetRules.push(rule)\n if (!this.adopted.has(className)) {\n const sheet = this.sheets.reset\n sheet?.insertRule(rule, sheet.cssRules.length)\n }\n return className\n }\n\n // The rules of each sheet, for server rendering.\n cssText(): { reset: string; shorthand: string; longhand: string } {\n return {\n reset: this.resetRules.join('\\n'),\n shorthand: this.shorthandRules.join('\\n'),\n longhand: this.longhandRules.join('\\n'),\n }\n }\n\n get ruleCount(): number {\n return this.resetRules.length + this.shorthandRules.length + this.longhandRules.length\n }\n\n // Remembers the class names the server already rendered, so the client does not insert them again.\n private adopt(sheet: CSSStyleSheet | null): void {\n if (sheet === null) return\n for (const rule of Array.from(sheet.cssRules)) {\n if (rule instanceof CSSStyleRule) this.adopted.add(rule.selectorText.slice(1))\n }\n }\n}\n\nlet defaultRegistry: StyleRegistry | null = null\n\nexport const getStyleRegistry = (): StyleRegistry => {\n if (defaultRegistry !== null) return defaultRegistry\n defaultRegistry = new StyleRegistry(\n hasDOM()\n ? {\n reset: domSheet(RESET_STYLE_ID),\n shorthand: domSheet(SHORTHAND_STYLE_ID),\n longhand: domSheet(LONGHAND_STYLE_ID),\n }\n : { reset: null, shorthand: null, longhand: null },\n )\n return defaultRegistry\n}\n\n// For tests, so each file starts with an empty registry.\nexport const resetStyleRegistry = (): void => {\n defaultRegistry = null\n if (!hasDOM()) return\n for (const id of SHEET_ORDER) document.getElementById(id)?.remove()\n}\n\n// A new style element goes before the sheets that must come after it. A page from an older\n// server can have the other two sheets already.\nconst domSheet = (id: (typeof SHEET_ORDER)[number]): CSSStyleSheet => {\n let element = document.getElementById(id) as HTMLStyleElement | null\n if (element === null) {\n element = document.createElement('style')\n element.id = id\n const later = SHEET_ORDER.slice(SHEET_ORDER.indexOf(id) + 1)\n .map((name) => document.getElementById(name))\n .find((found) => found !== null)\n if (later === undefined || later === null) document.head.appendChild(element)\n else later.before(element)\n }\n return element.sheet as CSSStyleSheet\n}\n"],"mappings":";;AAQA,MAAa,iBAAiB;AAC9B,MAAa,qBAAqB;AAClC,MAAa,oBAAoB;AAEjC,MAAM,cAAc;CAAC;CAAgB;CAAoB;AAAiB;AAE1E,MAAM,sCAA2C,IAAI,IAAI;CACvD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,uBAAuB,SAA0B,oBAAoB,IAAI,IAAI;AAE1F,MAAM,WAAW,SAAyB,KAAK,QAAQ,WAAW,MAAM,IAAI,EAAE,YAAY,GAAG;AAE7F,MAAM,QAAQ,UAA0B;CACtC,IAAI,IAAI;CACR,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,KAAK,MAAM,WAAW,CAAC;EACvB,IAAI,KAAK,KAAK,GAAG,QAAU;CAC7B;CACA,QAAQ,MAAM,EAAA,CAAG,SAAS,EAAE;AAC9B;AAQA,IAAa,gBAAb,MAA2B;CAQzB,YAAY,SAAsB;EAAE,OAAO;EAAM,WAAW;EAAM,UAAU;CAAK,GAAG;EAPpF,KAAiB,6BAAa,IAAI,IAAoB;EACtD,KAAiB,0BAAU,IAAI,IAAY;EAC3C,KAAiB,aAAuB,CAAC;EACzC,KAAiB,iBAA2B,CAAC;EAC7C,KAAiB,gBAA0B,CAAC;EAI1C,KAAK,SAAS;EACd,KAAK,MAAM,OAAO,KAAK;EACvB,KAAK,MAAM,OAAO,SAAS;EAC3B,KAAK,MAAM,OAAO,QAAQ;CAC5B;CAEA,SAAS,UAAkB,OAAuB;EAChD,MAAM,MAAM,GAAG,SAAS,GAAG;EAC3B,MAAM,QAAQ,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;CACA,OAAO,QAAQ;AACjB"}
@@ -1,12 +1,14 @@
1
1
  import { t as CSSDeclarations } from "../types-BxTWbdj9.js";
2
2
  import { ReactElement, ReactNode } from "react";
3
3
  type StyleSheets = {
4
+ reset: CSSStyleSheet | null;
4
5
  shorthand: CSSStyleSheet | null;
5
6
  longhand: CSSStyleSheet | null;
6
7
  };
7
8
  export declare class StyleRegistry {
8
9
  private readonly classNames;
9
10
  private readonly adopted;
11
+ private readonly resetRules;
10
12
  private readonly shorthandRules;
11
13
  private readonly longhandRules;
12
14
  private readonly sheets;
@@ -14,7 +16,9 @@ export declare class StyleRegistry {
14
16
  classFor(property: string, value: string): string;
15
17
  classesFor(declarations: CSSDeclarations): string;
16
18
  staticClass(className: string, rules: ReadonlyArray<string>): string;
19
+ resetClass(className: string, declarations: CSSDeclarations): string;
17
20
  cssText(): {
21
+ reset: string;
18
22
  shorthand: string;
19
23
  longhand: string;
20
24
  };
@@ -1,4 +1,5 @@
1
- import { a as StyleRegistry, i as SHORTHAND_STYLE_ID, r as LONGHAND_STYLE_ID, t as StyleRegistryContext } from "../StyleRegistryContext-D6yDrZk0.js";
1
+ import { i as StyleRegistry, n as RESET_STYLE_ID, r as SHORTHAND_STYLE_ID, t as LONGHAND_STYLE_ID } from "../registry-Aa_Od5m0.js";
2
+ import { t as StyleRegistryContext } from "../StyleRegistryContext-ROsMlY4O.js";
2
3
  import { Fragment, createElement } from "react";
3
4
  // src/server/index.ts
4
5
  const createStyleRegistry = () => new StyleRegistry();
@@ -7,8 +8,11 @@ function StyleRegistryProvider(props) {
7
8
  }
8
9
  const escapeCSS = (css) => css.replace(/<\//g, "<\\/");
9
10
  const renderStyleTags = (registry) => {
10
- const { shorthand, longhand } = registry.cssText();
11
+ const { reset, shorthand, longhand } = registry.cssText();
11
12
  return createElement(Fragment, null, createElement("style", {
13
+ id: RESET_STYLE_ID,
14
+ dangerouslySetInnerHTML: { __html: escapeCSS(reset) }
15
+ }), createElement("style", {
12
16
  id: SHORTHAND_STYLE_ID,
13
17
  dangerouslySetInnerHTML: { __html: escapeCSS(shorthand) }
14
18
  }), createElement("style", {
@@ -17,8 +21,8 @@ const renderStyleTags = (registry) => {
17
21
  }));
18
22
  };
19
23
  const styleTagsHTML = (registry) => {
20
- const { shorthand, longhand } = registry.cssText();
21
- return `<style id="${SHORTHAND_STYLE_ID}">${escapeCSS(shorthand)}</style><style id="${LONGHAND_STYLE_ID}">${escapeCSS(longhand)}</style>`;
24
+ const { reset, shorthand, longhand } = registry.cssText();
25
+ return `<style id="${RESET_STYLE_ID}">${escapeCSS(reset)}</style><style id="${SHORTHAND_STYLE_ID}">${escapeCSS(shorthand)}</style><style id="${LONGHAND_STYLE_ID}">${escapeCSS(longhand)}</style>`;
22
26
  };
23
27
  export { StyleRegistry, StyleRegistryProvider, createStyleRegistry, renderStyleTags, styleTagsHTML };
24
28
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/server/index.ts"],"sourcesContent":["import { createElement, Fragment, type ReactElement, type ReactNode } from 'react'\n\nimport { LONGHAND_STYLE_ID, SHORTHAND_STYLE_ID, StyleRegistry } from '../style/registry'\nimport { StyleRegistryContext } from '../style/StyleRegistryContext'\n\nexport { StyleRegistry } from '../style/registry'\n\n// One registry per request, so concurrent renders never share CSS.\nexport const createStyleRegistry = (): StyleRegistry => new StyleRegistry()\n\nexport function StyleRegistryProvider(props: {\n registry: StyleRegistry\n children?: ReactNode\n}): ReactElement {\n return createElement(StyleRegistryContext.Provider, { value: props.registry }, props.children)\n}\n\n// A closing tag inside CSS text would end the style element early.\nconst escapeCSS = (css: string): string => css.replace(/<\\//g, '<\\\\/')\n\n// The two style elements the client adopts on hydration. Render them in <head>.\nexport const renderStyleTags = (registry: StyleRegistry): ReactElement => {\n const { shorthand, longhand } = registry.cssText()\n return createElement(\n Fragment,\n null,\n createElement('style', {\n id: SHORTHAND_STYLE_ID,\n dangerouslySetInnerHTML: { __html: escapeCSS(shorthand) },\n }),\n createElement('style', {\n id: LONGHAND_STYLE_ID,\n dangerouslySetInnerHTML: { __html: escapeCSS(longhand) },\n }),\n )\n}\n\n// The same two elements as an HTML string, for a template.\nexport const styleTagsHTML = (registry: StyleRegistry): string => {\n const { shorthand, longhand } = registry.cssText()\n return (\n `<style id=\"${SHORTHAND_STYLE_ID}\">${escapeCSS(shorthand)}</style>` +\n `<style id=\"${LONGHAND_STYLE_ID}\">${escapeCSS(longhand)}</style>`\n )\n}\n"],"mappings":";;;AAQA,MAAa,4BAA2C,IAAI,cAAc;AAE1E,SAAgB,sBAAsB,OAGrB;CACf,OAAO,cAAc,qBAAqB,UAAU,EAAE,OAAO,MAAM,SAAS,GAAG,MAAM,QAAQ;AAC/F;AAGA,MAAM,aAAa,QAAwB,IAAI,QAAQ,QAAQ,MAAM;AAGrE,MAAa,mBAAmB,aAA0C;CACxE,MAAM,EAAE,WAAW,aAAa,SAAS,QAAQ;CACjD,OAAO,cACL,UACA,MACA,cAAc,SAAS;EACrB,IAAI;EACJ,yBAAyB,EAAE,QAAQ,UAAU,SAAS,EAAE;CAC1D,CAAC,GACD,cAAc,SAAS;EACrB,IAAI;EACJ,yBAAyB,EAAE,QAAQ,UAAU,QAAQ,EAAE;CACzD,CAAC,CACH;AACF;AAGA,MAAa,iBAAiB,aAAoC;CAChE,MAAM,EAAE,WAAW,aAAa,SAAS,QAAQ;CACjD,OACE,cAAc,mBAAmB,IAAI,UAAU,SAAS,EAAE,qBAC5C,kBAAkB,IAAI,UAAU,QAAQ,EAAE;AAE5D"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/server/index.ts"],"sourcesContent":["import { createElement, Fragment, type ReactElement, type ReactNode } from 'react'\n\nimport {\n LONGHAND_STYLE_ID,\n RESET_STYLE_ID,\n SHORTHAND_STYLE_ID,\n StyleRegistry,\n} from '../style/registry'\nimport { StyleRegistryContext } from '../style/StyleRegistryContext'\n\nexport { StyleRegistry } from '../style/registry'\n\n// One registry per request, so concurrent renders never share CSS.\nexport const createStyleRegistry = (): StyleRegistry => new StyleRegistry()\n\nexport function StyleRegistryProvider(props: {\n registry: StyleRegistry\n children?: ReactNode\n}): ReactElement {\n return createElement(StyleRegistryContext.Provider, { value: props.registry }, props.children)\n}\n\n// A closing tag inside CSS text would end the style element early.\nconst escapeCSS = (css: string): string => css.replace(/<\\//g, '<\\\\/')\n\n// The three style elements the client adopts on hydration. Render them in <head>, in this order.\nexport const renderStyleTags = (registry: StyleRegistry): ReactElement => {\n const { reset, shorthand, longhand } = registry.cssText()\n return createElement(\n Fragment,\n null,\n createElement('style', {\n id: RESET_STYLE_ID,\n dangerouslySetInnerHTML: { __html: escapeCSS(reset) },\n }),\n createElement('style', {\n id: SHORTHAND_STYLE_ID,\n dangerouslySetInnerHTML: { __html: escapeCSS(shorthand) },\n }),\n createElement('style', {\n id: LONGHAND_STYLE_ID,\n dangerouslySetInnerHTML: { __html: escapeCSS(longhand) },\n }),\n )\n}\n\n// The same three elements as an HTML string, for a template.\nexport const styleTagsHTML = (registry: StyleRegistry): string => {\n const { reset, shorthand, longhand } = registry.cssText()\n return (\n `<style id=\"${RESET_STYLE_ID}\">${escapeCSS(reset)}</style>` +\n `<style id=\"${SHORTHAND_STYLE_ID}\">${escapeCSS(shorthand)}</style>` +\n `<style id=\"${LONGHAND_STYLE_ID}\">${escapeCSS(longhand)}</style>`\n )\n}\n"],"mappings":";;;;AAaA,MAAa,4BAA2C,IAAI,cAAc;AAE1E,SAAgB,sBAAsB,OAGrB;CACf,OAAO,cAAc,qBAAqB,UAAU,EAAE,OAAO,MAAM,SAAS,GAAG,MAAM,QAAQ;AAC/F;AAGA,MAAM,aAAa,QAAwB,IAAI,QAAQ,QAAQ,MAAM;AAGrE,MAAa,mBAAmB,aAA0C;CACxE,MAAM,EAAE,OAAO,WAAW,aAAa,SAAS,QAAQ;CACxD,OAAO,cACL,UACA,MACA,cAAc,SAAS;EACrB,IAAI;EACJ,yBAAyB,EAAE,QAAQ,UAAU,KAAK,EAAE;CACtD,CAAC,GACD,cAAc,SAAS;EACrB,IAAI;EACJ,yBAAyB,EAAE,QAAQ,UAAU,SAAS,EAAE;CAC1D,CAAC,GACD,cAAc,SAAS;EACrB,IAAI;EACJ,yBAAyB,EAAE,QAAQ,UAAU,QAAQ,EAAE;CACzD,CAAC,CACH;AACF;AAGA,MAAa,iBAAiB,aAAoC;CAChE,MAAM,EAAE,OAAO,WAAW,aAAa,SAAS,QAAQ;CACxD,OACE,cAAc,eAAe,IAAI,UAAU,KAAK,EAAE,qBACpC,mBAAmB,IAAI,UAAU,SAAS,EAAE,qBAC5C,kBAAkB,IAAI,UAAU,QAAQ,EAAE;AAE5D"}
@@ -0,0 +1,25 @@
1
+ import { n as FlatStyle, r as StyleProp, t as CSSDeclarations } from "../types-BxTWbdj9.js";
2
+ /**
3
+ * Compat export. Compiles a React Native style to inline DOM style values, keyed by the
4
+ * camel-case names of `CSSStyleDeclaration`, with the same rules as the class names of `View`.
5
+ * Libraries such as Reanimated write the result into `element.style` on each frame.
6
+ *
7
+ * Shorthands come first, so a longhand written after them wins, as it does in the class names.
8
+ */
9
+ export declare const createReactDOMStyle: (style: StyleProp<FlatStyle>) => CSSDeclarations;
10
+ /**
11
+ * Compat export. Turns a React Native `transform` array into a CSS `transform` value. An empty
12
+ * string for a value that has no valid transform.
13
+ */
14
+ export declare const createTransformValue: (transform: unknown) => string;
15
+ /**
16
+ * Compat export. Turns the three React Native text shadow props into a CSS `text-shadow` value.
17
+ * `undefined` for a color that it can't parse.
18
+ */
19
+ export declare const createTextShadowValue: (style: {
20
+ readonly textShadowColor?: unknown;
21
+ readonly textShadowOffset?: unknown;
22
+ readonly textShadowRadius?: unknown;
23
+ }) => string | undefined;
24
+ export { type CSSDeclarations, createReactDOMStyle as default };
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,35 @@
1
+ import { c as toCSSTransform, l as toCSSTextShadow, o as resolveStyle, r as flattenStyle } from "../compile-CVUjQrR9.js";
2
+ import { o as isShorthandProperty } from "../registry-Aa_Od5m0.js";
3
+ // src/style/index.ts
4
+ /**
5
+ * Compat export. Compiles a React Native style to inline DOM style values, keyed by the
6
+ * camel-case names of `CSSStyleDeclaration`, with the same rules as the class names of `View`.
7
+ * Libraries such as Reanimated write the result into `element.style` on each frame.
8
+ *
9
+ * Shorthands come first, so a longhand written after them wins, as it does in the class names.
10
+ */
11
+ const createReactDOMStyle = (style) => {
12
+ const flat = flattenStyle(style);
13
+ if (flat === void 0) return {};
14
+ const resolved = resolveStyle(flat);
15
+ const shorthands = {};
16
+ const longhands = {};
17
+ for (const name in resolved) {
18
+ const target = isShorthandProperty(name) ? shorthands : longhands;
19
+ target[name] = resolved[name];
20
+ }
21
+ return Object.assign(shorthands, longhands);
22
+ };
23
+ /**
24
+ * Compat export. Turns a React Native `transform` array into a CSS `transform` value. An empty
25
+ * string for a value that has no valid transform.
26
+ */
27
+ const createTransformValue = (transform) => toCSSTransform(transform) ?? "";
28
+ /**
29
+ * Compat export. Turns the three React Native text shadow props into a CSS `text-shadow` value.
30
+ * `undefined` for a color that it can't parse.
31
+ */
32
+ const createTextShadowValue = (style) => toCSSTextShadow(style);
33
+ export { createReactDOMStyle, createReactDOMStyle as default, createTextShadowValue, createTransformValue };
34
+
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/style/index.ts"],"sourcesContent":["import { flattenStyle } from './compile'\nimport { isShorthandProperty } from './registry'\nimport { resolveStyle } from './resolveStyle'\nimport { toCSSTextShadow } from './shadow'\nimport { toCSSTransform } from './transform'\nimport type { CSSDeclarations, FlatStyle, StyleProp } from './types'\n\nexport type { CSSDeclarations } from './types'\n\n/**\n * Compat export. Compiles a React Native style to inline DOM style values, keyed by the\n * camel-case names of `CSSStyleDeclaration`, with the same rules as the class names of `View`.\n * Libraries such as Reanimated write the result into `element.style` on each frame.\n *\n * Shorthands come first, so a longhand written after them wins, as it does in the class names.\n */\nexport const createReactDOMStyle = (style: StyleProp<FlatStyle>): CSSDeclarations => {\n const flat = flattenStyle(style)\n if (flat === undefined) return {}\n\n const resolved = resolveStyle(flat)\n const shorthands: CSSDeclarations = {}\n const longhands: CSSDeclarations = {}\n for (const name in resolved) {\n const target = isShorthandProperty(name) ? shorthands : longhands\n target[name] = resolved[name] as string\n }\n return Object.assign(shorthands, longhands)\n}\n\n/**\n * Compat export. Turns a React Native `transform` array into a CSS `transform` value. An empty\n * string for a value that has no valid transform.\n */\nexport const createTransformValue = (transform: unknown): string => toCSSTransform(transform) ?? ''\n\n/**\n * Compat export. Turns the three React Native text shadow props into a CSS `text-shadow` value.\n * `undefined` for a color that it can't parse.\n */\nexport const createTextShadowValue = (style: {\n readonly textShadowColor?: unknown\n readonly textShadowOffset?: unknown\n readonly textShadowRadius?: unknown\n}): string | undefined => toCSSTextShadow(style)\n\n// react-native-web's `createReactDOMStyle` module has the function as its default export. The\n// Vite plugin points that module name here, so the same shape must be here too.\nexport default createReactDOMStyle\n"],"mappings":";;;;;;;;;;AAgBA,MAAa,uBAAuB,UAAiD;CACnF,MAAM,OAAO,aAAa,KAAK;CAC/B,IAAI,SAAS,KAAA,GAAW,OAAO,CAAC;CAEhC,MAAM,WAAW,aAAa,IAAI;CAClC,MAAM,aAA8B,CAAC;CACrC,MAAM,YAA6B,CAAC;CACpC,KAAK,MAAM,QAAQ,UAAU;EAC3B,MAAM,SAAS,oBAAoB,IAAI,IAAI,aAAa;EACxD,OAAO,QAAQ,SAAS;CAC1B;CACA,OAAO,OAAO,OAAO,YAAY,SAAS;AAC5C;;;;;AAMA,MAAa,wBAAwB,cAA+B,eAAe,SAAS,KAAK;;;;;AAMjG,MAAa,yBAAyB,UAIZ,gBAAgB,KAAK"}
@@ -1,7 +1,15 @@
1
1
  import { Plugin } from "vite";
2
+ export type RootnativeOptions = {
3
+ /**
4
+ * Runs the Babel plugin of `react-native-worklets` on your code and on the libraries that
5
+ * have worklets. Reanimated needs it, and so does a library built on Reanimated. The app
6
+ * must have `react-native-worklets` and `@babel/core`. Default: `false`.
7
+ */
8
+ worklets?: boolean | undefined;
9
+ };
2
10
  /**
3
11
  * The Vite plugin. It points `react-native` at `@rootnative/web`, resolves `.web.*` files
4
12
  * first, defines `__DEV__`, and replaces `Platform.OS` with `'web'`.
5
13
  */
6
- export declare const rootnative: () => Plugin;
14
+ export declare const rootnative: (options?: RootnativeOptions) => Plugin;
7
15
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import { n as isProductionEnv } from "../env-BQE0B2yw.js";
1
+ import { n as isProductionEnv } from "../env-DK5Mt9yX.js";
2
2
  // src/bundler/inlinePlatformOS.ts
3
3
  const SOURCES = /* @__PURE__ */ new Set(["react-native", "@rootnative/web"]);
4
4
  const REPLACEMENT = "\"web\"";
@@ -117,14 +117,81 @@ const inlinePlatformOS = (code, program) => {
117
117
  for (const { start, end } of edits) output = output.slice(0, start) + REPLACEMENT.padEnd(end - start) + output.slice(end);
118
118
  return output;
119
119
  };
120
+ // src/bundler/worklets.ts
121
+ /**
122
+ * The source of a file that can hold a worklet: a `'worklet'` directive, an import of
123
+ * Reanimated or Worklets, or a call that the Worklets Babel plugin turns into a worklet.
124
+ */
125
+ const WORKLET_CODE = /worklet|reanimated|useAnimated|useDerivedValue|useFrameCallback|runOnUI|scheduleOnUI|with(?:Timing|Spring|Decay|Repeat)\b/;
126
+ const SCRIPT_FILE = /\.[cm]?[jt]sx?$/;
127
+ const missing = (name) => /* @__PURE__ */ new Error(`[@rootnative/web] The \`worklets\` option needs \`${name}\`, and the app doesn't have it. Install it, or remove the option.`);
128
+ const loadTools = async (root) => {
129
+ const { createRequire } = await import("node:module");
130
+ const { resolve } = await import("node:path");
131
+ const fromRoot = createRequire(resolve(root, "package.json"));
132
+ let plugin;
133
+ let workletsManifest;
134
+ try {
135
+ plugin = fromRoot.resolve("react-native-worklets/plugin");
136
+ workletsManifest = fromRoot.resolve("react-native-worklets/package.json");
137
+ } catch {
138
+ throw missing("react-native-worklets");
139
+ }
140
+ for (const load of [fromRoot, createRequire(workletsManifest)]) try {
141
+ return {
142
+ babel: load("@babel/core"),
143
+ plugin
144
+ };
145
+ } catch {}
146
+ throw missing("@babel/core");
147
+ };
148
+ /**
149
+ * Makes the transform that runs the Worklets Babel plugin on one file, as the Babel preset of a
150
+ * React Native app does. It finds the plugin and Babel from the root of the app, on the first
151
+ * file that needs them.
152
+ */
153
+ const createWorkletTransform = (root) => {
154
+ let tools;
155
+ return async (code, id) => {
156
+ const file = id.split("?")[0];
157
+ if (file.startsWith("\0") || !SCRIPT_FILE.test(file) || !WORKLET_CODE.test(code)) return null;
158
+ tools ??= loadTools(root);
159
+ const { babel, plugin } = await tools;
160
+ const syntax = [];
161
+ if (/\.[cm]?tsx?$/.test(file)) syntax.push("typescript");
162
+ if (/\.[jt]sx$/.test(file)) syntax.push("jsx");
163
+ const result = await babel.transformAsync(code, {
164
+ filename: file,
165
+ babelrc: false,
166
+ configFile: false,
167
+ sourceMaps: true,
168
+ parserOpts: { plugins: syntax },
169
+ plugins: [plugin]
170
+ });
171
+ if (result?.code == null) return null;
172
+ return {
173
+ code: result.code,
174
+ map: result.map == null ? null : JSON.stringify(result.map)
175
+ };
176
+ };
177
+ };
120
178
  // src/bundler/index.ts
121
179
  /** Module names that resolve to this package. Each one matches the exact name only. */
122
- const ALIASES = { "react-native": "@rootnative/web" };
180
+ const ALIASES = {
181
+ "react-native": "@rootnative/web",
182
+ "@react-native/assets-registry/registry": "@rootnative/web/assets-registry",
183
+ "react-native-web/dist/cjs/exports/StyleSheet/compiler/createReactDOMStyle.js": "@rootnative/web/style",
184
+ "react-native-web/dist/cjs/exports/StyleSheet/preprocess.js": "@rootnative/web/style"
185
+ };
123
186
  /**
124
187
  * The globals that React Native code expects from its bundler, each as the code that replaces
125
188
  * the name. `__DEV__` is `true` in a development build and `false` in a production build.
189
+ * `global` is React Native's name for the global object, which a browser doesn't have.
126
190
  */
127
- const globalDefines = (production) => ({ __DEV__: JSON.stringify(!production) });
191
+ const globalDefines = (production) => ({
192
+ __DEV__: JSON.stringify(!production),
193
+ global: "globalThis"
194
+ });
128
195
  /**
129
196
  * Puts a `.web` variant of each extension first, as Metro does for the web platform. An
130
197
  * import of `./Button` then finds `Button.web.tsx` before `Button.tsx`.
@@ -155,52 +222,80 @@ const aliasArray = (alias) => {
155
222
  }));
156
223
  };
157
224
  const defineCode = (value) => typeof value === "string" ? value : JSON.stringify(value);
225
+ const PLATFORM_CODE = /\bPlatform\b/;
158
226
  /**
159
227
  * The Vite plugin. It points `react-native` at `@rootnative/web`, resolves `.web.*` files
160
228
  * first, defines `__DEV__`, and replaces `Platform.OS` with `'web'`.
161
229
  */
162
- const rootnative = () => ({
163
- name: "@rootnative/web",
164
- config(config) {
165
- config.resolve ??= {};
166
- config.resolve.alias = [...aliasArray(config.resolve.alias), ...Object.entries(ALIASES).map(([name, replacement]) => ({
167
- find: new RegExp(`^${escapeRegExp(name)}$`),
168
- replacement
169
- }))];
170
- config.resolve.extensions = webExtensions(config.resolve.extensions ?? VITE_DEFAULT_EXTENSIONS);
171
- const defines = Object.fromEntries(Object.entries(globalDefines(isProductionEnv())).map(([name, code]) => [name, config.define?.[name] === void 0 ? code : defineCode(config.define[name])]));
172
- config.define = {
173
- ...config.define,
174
- ...defines
175
- };
176
- config.optimizeDeps ??= {};
177
- config.optimizeDeps.rolldownOptions ??= {};
178
- config.optimizeDeps.rolldownOptions.transform ??= {};
179
- config.optimizeDeps.rolldownOptions.transform.define = {
180
- ...defines,
181
- ...config.optimizeDeps.rolldownOptions.transform.define
182
- };
183
- },
184
- transform: {
185
- filter: {
186
- id: SCRIPT_ID,
187
- code: /\bPlatform\b/
188
- },
189
- handler(code) {
190
- let program;
191
- try {
192
- program = this.parse(code);
193
- } catch {
194
- return null;
230
+ const rootnative = (options = {}) => {
231
+ let workletize;
232
+ return {
233
+ name: "@rootnative/web",
234
+ config(config) {
235
+ if (options.worklets === true) {
236
+ const transform = createWorkletTransform(config.root ?? process.cwd());
237
+ workletize = transform;
238
+ config.optimizeDeps ??= {};
239
+ config.optimizeDeps.rolldownOptions ??= {};
240
+ const rolldownOptions = config.optimizeDeps.rolldownOptions;
241
+ rolldownOptions.plugins = [rolldownOptions.plugins, {
242
+ name: "@rootnative/web:worklets",
243
+ transform: {
244
+ filter: {
245
+ id: SCRIPT_ID,
246
+ code: WORKLET_CODE
247
+ },
248
+ handler: transform
249
+ }
250
+ }];
195
251
  }
196
- const inlined = inlinePlatformOS(code, program);
197
- return inlined === null ? null : {
198
- code: inlined,
199
- map: null
252
+ config.resolve ??= {};
253
+ config.resolve.alias = [...aliasArray(config.resolve.alias), ...Object.entries(ALIASES).map(([name, replacement]) => ({
254
+ find: new RegExp(`^${escapeRegExp(name)}$`),
255
+ replacement
256
+ }))];
257
+ const extensions = webExtensions(config.resolve.extensions ?? VITE_DEFAULT_EXTENSIONS);
258
+ config.resolve.extensions = extensions;
259
+ const defines = Object.fromEntries(Object.entries(globalDefines(isProductionEnv())).map(([name, code]) => [name, config.define?.[name] === void 0 ? code : defineCode(config.define[name])]));
260
+ config.define = {
261
+ ...config.define,
262
+ ...defines
200
263
  };
264
+ config.optimizeDeps ??= {};
265
+ config.optimizeDeps.rolldownOptions ??= {};
266
+ config.optimizeDeps.rolldownOptions.transform ??= {};
267
+ config.optimizeDeps.rolldownOptions.transform.define = {
268
+ ...defines,
269
+ ...config.optimizeDeps.rolldownOptions.transform.define
270
+ };
271
+ config.optimizeDeps.rolldownOptions.resolve ??= {};
272
+ config.optimizeDeps.rolldownOptions.resolve.extensions ??= extensions;
273
+ },
274
+ transform: {
275
+ filter: {
276
+ id: SCRIPT_ID,
277
+ code: options.worklets === true ? [PLATFORM_CODE, WORKLET_CODE] : PLATFORM_CODE
278
+ },
279
+ async handler(code, id) {
280
+ const worklets = workletize === void 0 ? null : await workletize(code, id);
281
+ const current = worklets?.code ?? code;
282
+ if (!PLATFORM_CODE.test(current)) return worklets;
283
+ let program;
284
+ try {
285
+ program = this.parse(current);
286
+ } catch {
287
+ return worklets;
288
+ }
289
+ const inlined = inlinePlatformOS(current, program);
290
+ if (inlined === null) return worklets;
291
+ return {
292
+ code: inlined,
293
+ map: worklets?.map ?? null
294
+ };
295
+ }
201
296
  }
202
- }
203
- });
297
+ };
298
+ };
204
299
  export { rootnative };
205
300
 
206
301
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/bundler/inlinePlatformOS.ts","../../src/bundler/index.ts","../../src/vite/index.ts"],"sourcesContent":["interface AstNode {\n type: string\n start: number\n end: number\n [key: string]: unknown\n}\n\ninterface PlatformRead {\n start: number\n end: number\n name: string\n namespace: boolean\n}\n\nconst SOURCES = new Set(['react-native', '@rootnative/web'])\nconst REPLACEMENT = '\"web\"'\nconst LINE_BREAK = /[\\n\\r\\u2028\\u2029]/\n\nconst isNode = (value: unknown): value is AstNode =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { type?: unknown }).type === 'string'\n\nconst identifierName = (node: unknown): string | undefined =>\n isNode(node) && node.type === 'Identifier' && typeof node.name === 'string'\n ? node.name\n : undefined\n\nconst nodes = (value: unknown): AstNode[] =>\n Array.isArray(value) ? value.filter(isNode) : isNode(value) ? [value] : []\n\nconst collectBindings = (pattern: unknown, names: Set<string>): void => {\n if (!isNode(pattern)) return\n switch (pattern.type) {\n case 'Identifier': {\n const name = identifierName(pattern)\n if (name !== undefined) names.add(name)\n return\n }\n case 'ObjectPattern':\n for (const property of nodes(pattern.properties)) {\n collectBindings(property.type === 'RestElement' ? property.argument : property.value, names)\n }\n return\n case 'ArrayPattern':\n for (const element of nodes(pattern.elements)) collectBindings(element, names)\n return\n case 'RestElement':\n collectBindings(pattern.argument, names)\n return\n case 'AssignmentPattern':\n collectBindings(pattern.left, names)\n }\n}\n\nconst isWriteTarget = (parent: AstNode, key: string, grandparent: AstNode | undefined): boolean => {\n switch (parent.type) {\n case 'AssignmentExpression':\n case 'AssignmentPattern':\n case 'ForInStatement':\n case 'ForOfStatement':\n return key === 'left'\n case 'UpdateExpression':\n case 'ArrayPattern':\n case 'RestElement':\n return true\n case 'UnaryExpression':\n return parent.operator === 'delete'\n case 'Property':\n return key === 'value' && grandparent?.type === 'ObjectPattern'\n default:\n return false\n }\n}\n\nconst platformRead = (node: AstNode): Omit<PlatformRead, 'start' | 'end'> | undefined => {\n if (node.computed === true || identifierName(node.property) !== 'OS') return undefined\n const name = identifierName(node.object)\n if (name !== undefined) return { name, namespace: false }\n const object = node.object\n if (\n isNode(object) &&\n object.type === 'MemberExpression' &&\n object.computed !== true &&\n identifierName(object.property) === 'Platform'\n ) {\n const namespace = identifierName(object.object)\n if (namespace !== undefined) return { name: namespace, namespace: true }\n }\n return undefined\n}\n\n/**\n * Replaces each read of `Platform.OS` with `\"web\"`, so a minifier can drop the branches of the\n * other platforms. Only a `Platform` imported from `react-native` or `@rootnative/web` counts.\n * Takes the ESTree program of `code`, with `start` and `end` offsets. Returns `null` when\n * nothing changes.\n */\nexport const inlinePlatformOS = (code: string, program: object): string | null => {\n if (!isNode(program)) return null\n\n const named = new Set<string>()\n const namespaces = new Set<string>()\n const declared = new Set<string>()\n const reads: PlatformRead[] = []\n\n const visit = (\n node: AstNode,\n parent: AstNode | undefined,\n key: string,\n grandparent: AstNode | undefined,\n ): void => {\n switch (node.type) {\n case 'ImportDeclaration': {\n const source = isNode(node.source) ? node.source.value : undefined\n if (typeof source !== 'string' || !SOURCES.has(source)) break\n for (const specifier of nodes(node.specifiers)) {\n const local = identifierName(specifier.local)\n if (local === undefined) continue\n if (specifier.type === 'ImportNamespaceSpecifier') namespaces.add(local)\n const imported = isNode(specifier.imported)\n ? (identifierName(specifier.imported) ?? specifier.imported.value)\n : undefined\n if (specifier.type === 'ImportSpecifier' && imported === 'Platform') named.add(local)\n }\n break\n }\n case 'VariableDeclarator':\n collectBindings(node.id, declared)\n break\n case 'FunctionDeclaration':\n case 'FunctionExpression':\n case 'ArrowFunctionExpression':\n collectBindings(node.id, declared)\n for (const param of nodes(node.params)) collectBindings(param, declared)\n break\n case 'ClassDeclaration':\n case 'ClassExpression':\n collectBindings(node.id, declared)\n break\n case 'CatchClause':\n collectBindings(node.param, declared)\n break\n case 'MemberExpression': {\n const read = platformRead(node)\n if (\n read !== undefined &&\n (parent === undefined || !isWriteTarget(parent, key, grandparent))\n ) {\n reads.push({ ...read, start: node.start, end: node.end })\n }\n break\n }\n }\n for (const childKey of Object.keys(node)) {\n for (const child of nodes(node[childKey])) visit(child, node, childKey, parent)\n }\n }\n visit(program, undefined, '', undefined)\n\n // A local binding with the same name may shadow the import in some scope. Without scope\n // analysis, skip that name in the whole module.\n const edits = reads.filter(\n (read) =>\n (read.namespace ? namespaces : named).has(read.name) &&\n !declared.has(read.name) &&\n // The replacement keeps the length and the lines of the original, so every later column\n // stays put and the source map stays exact. A shorter or a multi-line read keeps its code.\n read.end - read.start >= REPLACEMENT.length &&\n !LINE_BREAK.test(code.slice(read.start, read.end)),\n )\n if (edits.length === 0) return null\n\n // Each edit keeps its length, so the offsets of the others stay valid in any order.\n let output = code\n for (const { start, end } of edits) {\n output = output.slice(0, start) + REPLACEMENT.padEnd(end - start) + output.slice(end)\n }\n return output\n}\n","export { inlinePlatformOS } from './inlinePlatformOS'\n\n/** Module names that resolve to this package. Each one matches the exact name only. */\nexport const ALIASES: Readonly<Record<string, string>> = {\n 'react-native': '@rootnative/web',\n}\n\n/**\n * The globals that React Native code expects from its bundler, each as the code that replaces\n * the name. `__DEV__` is `true` in a development build and `false` in a production build.\n */\nexport const globalDefines = (production: boolean): Record<string, string> => ({\n __DEV__: JSON.stringify(!production),\n})\n\n/**\n * Puts a `.web` variant of each extension first, as Metro does for the web platform. An\n * import of `./Button` then finds `Button.web.tsx` before `Button.tsx`.\n */\nexport const webExtensions = (extensions: readonly string[]): string[] => {\n const web = extensions.map((extension) =>\n extension.startsWith('.web.') ? extension : `.web${extension}`,\n )\n return [...new Set([...web, ...extensions])]\n}\n","import type { Alias, AliasOptions, Plugin } from 'vite'\n\nimport { ALIASES, globalDefines, inlinePlatformOS, webExtensions } from '../bundler'\nimport { isProductionEnv } from '../utils/env'\n\n// Vite's default `resolve.extensions`. A config that sets the option replaces this list, so the\n// plugin starts from the same one.\nconst VITE_DEFAULT_EXTENSIONS = ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']\n\nconst SCRIPT_ID = /\\.[cm]?[jt]sx?(?:$|\\?)/\n\nconst escapeRegExp = (value: string): string => value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n\nconst isAliasArray = (alias: AliasOptions): alias is readonly Alias[] => Array.isArray(alias)\n\nconst aliasArray = (alias: AliasOptions | undefined): Alias[] => {\n if (alias === undefined) return []\n if (isAliasArray(alias)) return [...alias]\n return Object.entries(alias).map(([find, replacement]) => ({ find, replacement }))\n}\n\nconst defineCode = (value: unknown): string =>\n typeof value === 'string' ? value : JSON.stringify(value)\n\n/**\n * The Vite plugin. It points `react-native` at `@rootnative/web`, resolves `.web.*` files\n * first, defines `__DEV__`, and replaces `Platform.OS` with `'web'`.\n */\nexport const rootnative = (): Plugin => ({\n name: '@rootnative/web',\n\n // Edits the config in place, so the app's own values win. A returned partial config would\n // append the lists after the app's entries and override its defines.\n config(config) {\n config.resolve ??= {}\n // Last, so an alias in the app's config wins. The first matching alias resolves an import.\n config.resolve.alias = [\n ...aliasArray(config.resolve.alias),\n ...Object.entries(ALIASES).map(([name, replacement]) => ({\n find: new RegExp(`^${escapeRegExp(name)}$`),\n replacement,\n })),\n ]\n config.resolve.extensions = webExtensions(config.resolve.extensions ?? VITE_DEFAULT_EXTENSIONS)\n\n // Vite has set NODE_ENV before this hook runs, so `__DEV__` follows React's development mode.\n const defines = Object.fromEntries(\n Object.entries(globalDefines(isProductionEnv())).map(([name, code]) => [\n name,\n config.define?.[name] === undefined ? code : defineCode(config.define[name]),\n ]),\n )\n config.define = { ...config.define, ...defines }\n // The dep optimizer applies only its own defines, so a pre-bundled library gets them here.\n config.optimizeDeps ??= {}\n config.optimizeDeps.rolldownOptions ??= {}\n config.optimizeDeps.rolldownOptions.transform ??= {}\n config.optimizeDeps.rolldownOptions.transform.define = {\n ...defines,\n ...config.optimizeDeps.rolldownOptions.transform.define,\n }\n },\n\n transform: {\n filter: { id: SCRIPT_ID, code: /\\bPlatform\\b/ },\n handler(code) {\n let program: object\n try {\n program = this.parse(code)\n } catch {\n // Not plain JavaScript yet. The module keeps its code, and a later step reports a real\n // syntax error.\n return null\n }\n const inlined = inlinePlatformOS(code, program)\n return inlined === null ? null : { code: inlined, map: null }\n },\n },\n})\n"],"mappings":";;AAcA,MAAM,0BAAU,IAAI,IAAI,CAAC,gBAAgB,iBAAiB,CAAC;AAC3D,MAAM,cAAc;AACpB,MAAM,aAAa;AAEnB,MAAM,UAAU,UACd,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA6B,SAAS;AAEhD,MAAM,kBAAkB,SACtB,OAAO,IAAI,KAAK,KAAK,SAAS,gBAAgB,OAAO,KAAK,SAAS,WAC/D,KAAK,OACL,KAAA;AAEN,MAAM,SAAS,UACb,MAAM,QAAQ,KAAK,IAAI,MAAM,OAAO,MAAM,IAAI,OAAO,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC;AAE3E,MAAM,mBAAmB,SAAkB,UAA6B;CACtE,IAAI,CAAC,OAAO,OAAO,GAAG;CACtB,QAAQ,QAAQ,MAAhB;EACE,KAAK,cAAc;GACjB,MAAM,OAAO,eAAe,OAAO;GACnC,IAAI,SAAS,KAAA,GAAW,MAAM,IAAI,IAAI;GACtC;EACF;EACA,KAAK;GACH,KAAK,MAAM,YAAY,MAAM,QAAQ,UAAU,GAC7C,gBAAgB,SAAS,SAAS,gBAAgB,SAAS,WAAW,SAAS,OAAO,KAAK;GAE7F;EACF,KAAK;GACH,KAAK,MAAM,WAAW,MAAM,QAAQ,QAAQ,GAAG,gBAAgB,SAAS,KAAK;GAC7E;EACF,KAAK;GACH,gBAAgB,QAAQ,UAAU,KAAK;GACvC;E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,IAAI,aAAa,IAAI,EAAE,EAAE;GAC1C;EACF,EAAE,CACJ;EACA,OAAO,QAAQ,aAAa,cAAc,OAAO,QAAQ,cAAc,uBAAuB;EAG9F,MAAM,UAAU,OAAO,YACrB,OAAO,QAAQ,cAAc,gBAAgB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,UAAU,CACrE,MACA,OAAO,SAAS,UAAU,KAAA,IAAY,OAAO,WAAW,OAAO,OAAO,KAAK,CAC7E,CAAC,CACH;EACA,OAAO,SAAS;GAAE,GAAG,OAAO;GAAQ,GAAG;EAAQ;EAE/C,OAAO,iBAAiB,CAAC;EACzB,OAAO,aAAa,oBAAoB,CAAC;EACzC,OAAO,aAAa,gBAAgB,cAAc,CAAC;EACnD,OAAO,aAAa,gBAAgB,UAAU,SAAS;GACrD,GAAG;GACH,GAAG,OAAO,aAAa,gBAAgB,UAAU;EACnD;CACF;CAEA,WAAW;EACT,QAAQ;GAAE,IAAI;GAAW,MAAM;EAAe;EAC9C,QAAQ,MAAM;GACZ,IAAI;GACJ,IAAI;IACF,UAAU,KAAK,MAAM,IAAI;GAC3B,QAAQ;IAGN,OAAO;GACT;GACA,MAAM,UAAU,iBAAiB,MAAM,OAAO;GAC9C,OAAO,YAAY,OAAO,OAAO;IAAE,MAAM;IAAS,KAAK;GAAK;EAC9D;CACF;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/bundler/inlinePlatformOS.ts","../../src/bundler/worklets.ts","../../src/bundler/index.ts","../../src/vite/index.ts"],"sourcesContent":["interface AstNode {\n type: string\n start: number\n end: number\n [key: string]: unknown\n}\n\ninterface PlatformRead {\n start: number\n end: number\n name: string\n namespace: boolean\n}\n\nconst SOURCES = new Set(['react-native', '@rootnative/web'])\nconst REPLACEMENT = '\"web\"'\nconst LINE_BREAK = /[\\n\\r\\u2028\\u2029]/\n\nconst isNode = (value: unknown): value is AstNode =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { type?: unknown }).type === 'string'\n\nconst identifierName = (node: unknown): string | undefined =>\n isNode(node) && node.type === 'Identifier' && typeof node.name === 'string'\n ? node.name\n : undefined\n\nconst nodes = (value: unknown): AstNode[] =>\n Array.isArray(value) ? value.filter(isNode) : isNode(value) ? [value] : []\n\nconst collectBindings = (pattern: unknown, names: Set<string>): void => {\n if (!isNode(pattern)) return\n switch (pattern.type) {\n case 'Identifier': {\n const name = identifierName(pattern)\n if (name !== undefined) names.add(name)\n return\n }\n case 'ObjectPattern':\n for (const property of nodes(pattern.properties)) {\n collectBindings(property.type === 'RestElement' ? property.argument : property.value, names)\n }\n return\n case 'ArrayPattern':\n for (const element of nodes(pattern.elements)) collectBindings(element, names)\n return\n case 'RestElement':\n collectBindings(pattern.argument, names)\n return\n case 'AssignmentPattern':\n collectBindings(pattern.left, names)\n }\n}\n\nconst isWriteTarget = (parent: AstNode, key: string, grandparent: AstNode | undefined): boolean => {\n switch (parent.type) {\n case 'AssignmentExpression':\n case 'AssignmentPattern':\n case 'ForInStatement':\n case 'ForOfStatement':\n return key === 'left'\n case 'UpdateExpression':\n case 'ArrayPattern':\n case 'RestElement':\n return true\n case 'UnaryExpression':\n return parent.operator === 'delete'\n case 'Property':\n return key === 'value' && grandparent?.type === 'ObjectPattern'\n default:\n return false\n }\n}\n\nconst platformRead = (node: AstNode): Omit<PlatformRead, 'start' | 'end'> | undefined => {\n if (node.computed === true || identifierName(node.property) !== 'OS') return undefined\n const name = identifierName(node.object)\n if (name !== undefined) return { name, namespace: false }\n const object = node.object\n if (\n isNode(object) &&\n object.type === 'MemberExpression' &&\n object.computed !== true &&\n identifierName(object.property) === 'Platform'\n ) {\n const namespace = identifierName(object.object)\n if (namespace !== undefined) return { name: namespace, namespace: true }\n }\n return undefined\n}\n\n/**\n * Replaces each read of `Platform.OS` with `\"web\"`, so a minifier can drop the branches of the\n * other platforms. Only a `Platform` imported from `react-native` or `@rootnative/web` counts.\n * Takes the ESTree program of `code`, with `start` and `end` offsets. Returns `null` when\n * nothing changes.\n */\nexport const inlinePlatformOS = (code: string, program: object): string | null => {\n if (!isNode(program)) return null\n\n const named = new Set<string>()\n const namespaces = new Set<string>()\n const declared = new Set<string>()\n const reads: PlatformRead[] = []\n\n const visit = (\n node: AstNode,\n parent: AstNode | undefined,\n key: string,\n grandparent: AstNode | undefined,\n ): void => {\n switch (node.type) {\n case 'ImportDeclaration': {\n const source = isNode(node.source) ? node.source.value : undefined\n if (typeof source !== 'string' || !SOURCES.has(source)) break\n for (const specifier of nodes(node.specifiers)) {\n const local = identifierName(specifier.local)\n if (local === undefined) continue\n if (specifier.type === 'ImportNamespaceSpecifier') namespaces.add(local)\n const imported = isNode(specifier.imported)\n ? (identifierName(specifier.imported) ?? specifier.imported.value)\n : undefined\n if (specifier.type === 'ImportSpecifier' && imported === 'Platform') named.add(local)\n }\n break\n }\n case 'VariableDeclarator':\n collectBindings(node.id, declared)\n break\n case 'FunctionDeclaration':\n case 'FunctionExpression':\n case 'ArrowFunctionExpression':\n collectBindings(node.id, declared)\n for (const param of nodes(node.params)) collectBindings(param, declared)\n break\n case 'ClassDeclaration':\n case 'ClassExpression':\n collectBindings(node.id, declared)\n break\n case 'CatchClause':\n collectBindings(node.param, declared)\n break\n case 'MemberExpression': {\n const read = platformRead(node)\n if (\n read !== undefined &&\n (parent === undefined || !isWriteTarget(parent, key, grandparent))\n ) {\n reads.push({ ...read, start: node.start, end: node.end })\n }\n break\n }\n }\n for (const childKey of Object.keys(node)) {\n for (const child of nodes(node[childKey])) visit(child, node, childKey, parent)\n }\n }\n visit(program, undefined, '', undefined)\n\n // A local binding with the same name may shadow the import in some scope. Without scope\n // analysis, skip that name in the whole module.\n const edits = reads.filter(\n (read) =>\n (read.namespace ? namespaces : named).has(read.name) &&\n !declared.has(read.name) &&\n // The replacement keeps the length and the lines of the original, so every later column\n // stays put and the source map stays exact. A shorter or a multi-line read keeps its code.\n read.end - read.start >= REPLACEMENT.length &&\n !LINE_BREAK.test(code.slice(read.start, read.end)),\n )\n if (edits.length === 0) return null\n\n // Each edit keeps its length, so the offsets of the others stay valid in any order.\n let output = code\n for (const { start, end } of edits) {\n output = output.slice(0, start) + REPLACEMENT.padEnd(end - start) + output.slice(end)\n }\n return output\n}\n","/**\n * The source of a file that can hold a worklet: a `'worklet'` directive, an import of\n * Reanimated or Worklets, or a call that the Worklets Babel plugin turns into a worklet.\n */\nexport const WORKLET_CODE: RegExp =\n /worklet|reanimated|useAnimated|useDerivedValue|useFrameCallback|runOnUI|scheduleOnUI|with(?:Timing|Spring|Decay|Repeat)\\b/\n\nconst SCRIPT_FILE = /\\.[cm]?[jt]sx?$/\n\n// The map is JSON text, which every bundler takes.\nexport type WorkletTransformResult = { code: string; map: string | null }\n\nexport type WorkletTransform = (code: string, id: string) => Promise<WorkletTransformResult | null>\n\ntype BabelCore = {\n transformAsync: (\n code: string,\n options: Record<string, unknown>,\n ) => Promise<{ code?: string | null; map?: object | null } | null>\n}\n\ntype Require = ((id: string) => unknown) & { resolve: (id: string) => string }\n\ntype Tools = { babel: BabelCore; plugin: string }\n\nconst missing = (name: string): Error =>\n new Error(\n `[@rootnative/web] The \\`worklets\\` option needs \\`${name}\\`, and the app doesn't have it. ` +\n `Install it, or remove the option.`,\n )\n\nconst loadTools = async (root: string): Promise<Tools> => {\n // Only Node runs this file. A dynamic import keeps the browser entries free of it.\n const { createRequire } = await import('node:module')\n const { resolve } = await import('node:path')\n const fromRoot = createRequire(resolve(root, 'package.json')) as Require\n\n let plugin: string\n let workletsManifest: string\n try {\n plugin = fromRoot.resolve('react-native-worklets/plugin')\n workletsManifest = fromRoot.resolve('react-native-worklets/package.json')\n } catch {\n throw missing('react-native-worklets')\n }\n\n // Babel is a peer of Worklets. A strict package layout links it beside Worklets, not in the app.\n for (const load of [fromRoot, createRequire(workletsManifest) as Require]) {\n try {\n return { babel: load('@babel/core') as BabelCore, plugin }\n } catch {\n // Try the next place.\n }\n }\n throw missing('@babel/core')\n}\n\n/**\n * Makes the transform that runs the Worklets Babel plugin on one file, as the Babel preset of a\n * React Native app does. It finds the plugin and Babel from the root of the app, on the first\n * file that needs them.\n */\nexport const createWorkletTransform = (root: string): WorkletTransform => {\n let tools: Promise<Tools> | undefined\n\n return async (code, id) => {\n const file = id.split('?')[0] as string\n if (file.startsWith('\\0') || !SCRIPT_FILE.test(file) || !WORKLET_CODE.test(code)) return null\n\n tools ??= loadTools(root)\n const { babel, plugin } = await tools\n\n // A library can ship TypeScript or JSX source. Babel reads the syntax and keeps it.\n const syntax: string[] = []\n if (/\\.[cm]?tsx?$/.test(file)) syntax.push('typescript')\n if (/\\.[jt]sx$/.test(file)) syntax.push('jsx')\n\n const result = await babel.transformAsync(code, {\n filename: file,\n babelrc: false,\n configFile: false,\n sourceMaps: true,\n parserOpts: { plugins: syntax },\n plugins: [plugin],\n })\n if (result?.code == null) return null\n return { code: result.code, map: result.map == null ? null : JSON.stringify(result.map) }\n }\n}\n","export { inlinePlatformOS } from './inlinePlatformOS'\nexport {\n createWorkletTransform,\n WORKLET_CODE,\n type WorkletTransform,\n type WorkletTransformResult,\n} from './worklets'\n\n/** Module names that resolve to this package. Each one matches the exact name only. */\nexport const ALIASES: Readonly<Record<string, string>> = {\n 'react-native': '@rootnative/web',\n // Libraries import it on the web, and the real module is Flow source that no web bundler reads.\n '@react-native/assets-registry/registry': '@rootnative/web/assets-registry',\n // Reanimated 4 reads its web style helpers from these react-native-web internal files.\n 'react-native-web/dist/cjs/exports/StyleSheet/compiler/createReactDOMStyle.js':\n '@rootnative/web/style',\n 'react-native-web/dist/cjs/exports/StyleSheet/preprocess.js': '@rootnative/web/style',\n}\n\n/**\n * The globals that React Native code expects from its bundler, each as the code that replaces\n * the name. `__DEV__` is `true` in a development build and `false` in a production build.\n * `global` is React Native's name for the global object, which a browser doesn't have.\n */\nexport const globalDefines = (production: boolean): Record<string, string> => ({\n __DEV__: JSON.stringify(!production),\n global: 'globalThis',\n})\n\n/**\n * Puts a `.web` variant of each extension first, as Metro does for the web platform. An\n * import of `./Button` then finds `Button.web.tsx` before `Button.tsx`.\n */\nexport const webExtensions = (extensions: readonly string[]): string[] => {\n const web = extensions.map((extension) =>\n extension.startsWith('.web.') ? extension : `.web${extension}`,\n )\n return [...new Set([...web, ...extensions])]\n}\n","import type { Alias, AliasOptions, Plugin } from 'vite'\n\nimport {\n ALIASES,\n createWorkletTransform,\n globalDefines,\n inlinePlatformOS,\n WORKLET_CODE,\n webExtensions,\n type WorkletTransform,\n} from '../bundler'\nimport { isProductionEnv } from '../utils/env'\n\n// Vite's default `resolve.extensions`. A config that sets the option replaces this list, so the\n// plugin starts from the same one.\nconst VITE_DEFAULT_EXTENSIONS = ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']\n\nconst SCRIPT_ID = /\\.[cm]?[jt]sx?(?:$|\\?)/\n\nconst escapeRegExp = (value: string): string => value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n\nconst isAliasArray = (alias: AliasOptions): alias is readonly Alias[] => Array.isArray(alias)\n\nconst aliasArray = (alias: AliasOptions | undefined): Alias[] => {\n if (alias === undefined) return []\n if (isAliasArray(alias)) return [...alias]\n return Object.entries(alias).map(([find, replacement]) => ({ find, replacement }))\n}\n\nconst defineCode = (value: unknown): string =>\n typeof value === 'string' ? value : JSON.stringify(value)\n\nconst PLATFORM_CODE = /\\bPlatform\\b/\n\nexport type RootnativeOptions = {\n /**\n * Runs the Babel plugin of `react-native-worklets` on your code and on the libraries that\n * have worklets. Reanimated needs it, and so does a library built on Reanimated. The app\n * must have `react-native-worklets` and `@babel/core`. Default: `false`.\n */\n worklets?: boolean | undefined\n}\n\n/**\n * The Vite plugin. It points `react-native` at `@rootnative/web`, resolves `.web.*` files\n * first, defines `__DEV__`, and replaces `Platform.OS` with `'web'`.\n */\nexport const rootnative = (options: RootnativeOptions = {}): Plugin => {\n let workletize: WorkletTransform | undefined\n\n return {\n name: '@rootnative/web',\n\n // Edits the config in place, so the app's own values win. A returned partial config would\n // append the lists after the app's entries and override its defines.\n config(config) {\n if (options.worklets === true) {\n const transform = createWorkletTransform(config.root ?? process.cwd())\n workletize = transform\n // The dev server pre-bundles the libraries, and a `transform` hook of a Vite plugin\n // never sees their files. The optimizer takes its own plugin.\n config.optimizeDeps ??= {}\n config.optimizeDeps.rolldownOptions ??= {}\n const rolldownOptions = config.optimizeDeps.rolldownOptions\n rolldownOptions.plugins = [\n rolldownOptions.plugins,\n {\n name: '@rootnative/web:worklets',\n transform: { filter: { id: SCRIPT_ID, code: WORKLET_CODE }, handler: transform },\n },\n ] as typeof rolldownOptions.plugins\n }\n\n config.resolve ??= {}\n // Last, so an alias in the app's config wins. The first matching alias resolves an import.\n config.resolve.alias = [\n ...aliasArray(config.resolve.alias),\n ...Object.entries(ALIASES).map(([name, replacement]) => ({\n find: new RegExp(`^${escapeRegExp(name)}$`),\n replacement,\n })),\n ]\n const extensions = webExtensions(config.resolve.extensions ?? VITE_DEFAULT_EXTENSIONS)\n config.resolve.extensions = extensions\n\n // Vite has set NODE_ENV before this hook runs, so `__DEV__` follows React's development mode.\n const defines = Object.fromEntries(\n Object.entries(globalDefines(isProductionEnv())).map(([name, code]) => [\n name,\n config.define?.[name] === undefined ? code : defineCode(config.define[name]),\n ]),\n )\n config.define = { ...config.define, ...defines }\n // The dep optimizer applies only its own defines, so a pre-bundled library gets them here.\n config.optimizeDeps ??= {}\n config.optimizeDeps.rolldownOptions ??= {}\n config.optimizeDeps.rolldownOptions.transform ??= {}\n config.optimizeDeps.rolldownOptions.transform.define = {\n ...defines,\n ...config.optimizeDeps.rolldownOptions.transform.define,\n }\n // The dep optimizer resolves a relative import inside a library with its own list. Without\n // the `.web` variants there, a library loads its native file, not its `.web.js` file.\n config.optimizeDeps.rolldownOptions.resolve ??= {}\n config.optimizeDeps.rolldownOptions.resolve.extensions ??= extensions\n },\n\n transform: {\n filter: {\n id: SCRIPT_ID,\n code: options.worklets === true ? [PLATFORM_CODE, WORKLET_CODE] : PLATFORM_CODE,\n },\n async handler(code, id) {\n // The Worklets step comes first, as the last plugin of the Babel preset does on native:\n // it reads the functions that the other transforms made.\n const worklets = workletize === undefined ? null : await workletize(code, id)\n const current = worklets?.code ?? code\n if (!PLATFORM_CODE.test(current)) return worklets\n\n let program: object\n try {\n program = this.parse(current)\n } catch {\n // Not plain JavaScript yet. The module keeps its code, and a later step reports a real\n // syntax error.\n return worklets\n }\n const inlined = inlinePlatformOS(current, program)\n if (inlined === null) return worklets\n // The replaced reads change only columns on their own lines, so the map of the\n // Worklets step stays close.\n return { code: inlined, map: worklets?.map ?? null }\n },\n },\n }\n}\n"],"mappings":";;AAcA,MAAM,0BAAU,IAAI,IAAI,CAAC,gBAAgB,iBAAiB,CAAC;AAC3D,MAAM,cAAc;AACpB,MAAM,aAAa;AAEnB,MAAM,UAAU,UACd,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA6B,SAAS;AAEhD,MAAM,kBAAkB,SACtB,OAAO,IAAI,KAAK,KAAK,SAAS,gBAAgB,OAAO,KAAK,SAAS,WAC/D,KAAK,OACL,KAAA;AAEN,MAAM,SAAS,UACb,MAAM,QAAQ,KAAK,IAAI,MAAM,OAAO,MAAM,IAAI,OAAO,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC;AAE3E,MAAM,mBAAmB,SAAkB,UAA6B;CACtE,IAAI,CAAC,OAAO,OAAO,GAAG;CACtB,QAAQ,QAAQ,MAAhB;EACE,KAAK,cAAc;GACjB,MAAM,OAAO,eAAe,OAAO;GACnC,IAAI,SAAS,KAAA,GAAW,MAAM,IAAI,IAAI;GACtC;EACF;EACA,KAAK;GACH,KAAK,MAAM,YAAY,MAAM,QAAQ,UAAU,GAC7C,gBAAgB,SAAS,SAAS,gBAAgB,SAAS,WAAW,SAAS,OAAO,KAAK;GAE7F;EACF,KAAK;GACH,KAAK,MAAM,WAAW,MAAM,QAAQ,QAAQ,GAAG,gBAAgB,SAAS,KAAK;GAC7E;EACF,KAAK;GACH,gBAAgB,QAAQ,UAAU,KAAK;GACvC;EACF,KAA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