@plasmicapp/react-web 0.2.397 → 0.2.399

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.
@@ -5,9 +5,9 @@ export { PlasmicDataSourceContextProvider, useCurrentUser } from '@plasmicapp/da
5
5
  import * as plasmicQuery from '@plasmicapp/query';
6
6
  import * as React from 'react';
7
7
  import React__default, { useLayoutEffect, useEffect } from 'react';
8
+ import { usePlasmicLinkMaybe, PlasmicTranslatorContext as PlasmicTranslatorContext$1, usePlasmicTranslator as usePlasmicTranslator$1, DataProvider, PlasmicLinkProvider, usePlasmicCanvasContext } from '@plasmicapp/host';
8
9
  import get from 'dlv';
9
10
  export { default as get } from 'dlv';
10
- import { usePlasmicLinkMaybe, PlasmicTranslatorContext as PlasmicTranslatorContext$1, usePlasmicTranslator as usePlasmicTranslator$1, DataProvider, PlasmicLinkProvider, usePlasmicCanvasContext } from '@plasmicapp/host';
11
11
  import * as ReactDOM from 'react-dom';
12
12
  import ReactDOM__default from 'react-dom';
13
13
  import { SSRProvider, useIsSSR as useIsSSR$1 } from '@react-aria/ssr';
@@ -442,6 +442,88 @@ function mapValues(obj, mapper) {
442
442
  return result;
443
443
  }
444
444
 
445
+ var PlasmicHeadContext = React.createContext(undefined);
446
+ function PlasmicHead(props) {
447
+ var Head = React.useContext(PlasmicHeadContext);
448
+ var headMetadata =
449
+ // Check if `HeadMetadataContext` is exported for backward compatibility
450
+ "HeadMetadataContext" in plasmicQuery
451
+ ? React.useContext(plasmicQuery.HeadMetadataContext)
452
+ : undefined;
453
+ if (headMetadata) {
454
+ // If we have the Head metadata object specified, mutate it so to ensure it
455
+ // stores the data that should go in the <head>.
456
+ if (props.image) {
457
+ headMetadata.image = props.image;
458
+ }
459
+ if (props.title) {
460
+ headMetadata.title = props.title;
461
+ }
462
+ if (props.description) {
463
+ headMetadata.description = props.description;
464
+ }
465
+ if (props.canonical) {
466
+ headMetadata.canonical = props.canonical;
467
+ }
468
+ }
469
+ if (!Head) {
470
+ console.warn("Plasmic: Head meta tags are being ignored. To make them work, pass a Head component into PlasmicRootProvider.");
471
+ // TODO: Link to doc about Head.
472
+ return null;
473
+ }
474
+ // Helmet does not support React.Fragments, so we need to use `[<meta />,
475
+ // <meta />]` instead of `<><meta /><meta /></>`.
476
+ return (React.createElement(Head, null,
477
+ props.image ? ([
478
+ React.createElement("meta", { key: "twitter:card", name: "twitter:card", content: "summary_large_image" }),
479
+ React.createElement("meta", { key: "og:image", property: "og:image", content: props.image }),
480
+ React.createElement("meta", { key: "twitter:image", name: "twitter:image", content: props.image }),
481
+ ]) : (React.createElement("meta", { key: "twitter:card", name: "twitter:card", content: "summary" })),
482
+ props.title && [
483
+ React.createElement("title", { key: "title" }, props.title),
484
+ React.createElement("meta", { key: "og:title", property: "og:title", content: props.title }),
485
+ React.createElement("meta", { key: "twitter:title", property: "twitter:title", content: props.title }),
486
+ ],
487
+ props.description && [
488
+ React.createElement("meta", { key: "description", name: "description", content: props.description }),
489
+ React.createElement("meta", { key: "og:description", property: "og:description", content: props.description }),
490
+ React.createElement("meta", { key: "twitter:description", name: "twitter:description", content: props.description }),
491
+ ],
492
+ props.canonical && (React.createElement("link", { key: "canonical", rel: "canonical", href: props.canonical }))));
493
+ }
494
+ var plasmicHeadMeta = {
495
+ name: "hostless-plasmic-head",
496
+ displayName: "Page Metadata Override",
497
+ description: "Set page metadata (HTML <head />) to dynamic values.",
498
+ importName: "PlasmicHead",
499
+ importPath: "@plasmicapp/react-web",
500
+ isRepeatable: false,
501
+ styleSections: false,
502
+ props: {
503
+ title: {
504
+ type: "string",
505
+ displayName: "Title",
506
+ },
507
+ description: {
508
+ type: "string",
509
+ displayName: "Description",
510
+ },
511
+ image: {
512
+ type: "imageUrl",
513
+ displayName: "Image",
514
+ },
515
+ canonical: {
516
+ type: "string",
517
+ displayName: "Canonical URL",
518
+ },
519
+ },
520
+ };
521
+
522
+ function PlasmicIcon(props) {
523
+ var PlasmicIconType = props.PlasmicIconType, rest = __rest(props, ["PlasmicIconType"]);
524
+ return React.createElement(PlasmicIconType, __assign({}, rest));
525
+ }
526
+
445
527
  var isBrowser = typeof window !== "undefined";
446
528
  var NONE = Symbol("NONE");
447
529
  var useIsomorphicLayoutEffect$1 = isBrowser
@@ -637,989 +719,958 @@ function getElementTypeName(element) {
637
719
  }
638
720
  }
639
721
 
640
- function renderStack(as, props, hasGap, ref) {
641
- var children = props.children, rest = __rest(props, ["children"]);
642
- var wrappedChildren = wrapFlexContainerChildren(children, hasGap !== null && hasGap !== void 0 ? hasGap : false);
643
- return createElementWithChildren(as, __assign({ ref: ref }, rest), wrappedChildren);
644
- }
645
- function FlexStack_(props, outerRef) {
646
- var as = props.as, hasGap = props.hasGap, rest = __rest(props, ["as", "hasGap"]);
647
- return renderStack(as !== null && as !== void 0 ? as : "div", rest, hasGap, outerRef);
648
- }
649
- var FlexStack = React.forwardRef(FlexStack_);
650
- var makeStackImpl = function (as) {
651
- return React.forwardRef(function (props, ref) {
652
- var hasGap = props.hasGap, rest = __rest(props, ["hasGap"]);
653
- return renderStack(as, rest, hasGap, ref);
722
+ /**
723
+ * Responsive `<img/>` replacement, based on `next/image`
724
+ */
725
+ var IMG_OPTIMIZER_HOST = "https://img.plasmic.app";
726
+ // Default image sizes to snap to
727
+ // TODO: make this configurable?
728
+ var IMG_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];
729
+ var DEVICE_SIZES = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
730
+ var ALL_SIZES = __spreadArray(__spreadArray([], __read(IMG_SIZES), false), __read(DEVICE_SIZES), false);
731
+ var PlasmicImg = React__default.forwardRef(function PlasmicImg(props, outerRef) {
732
+ var src = props.src, className = props.className, displayWidth = props.displayWidth, displayHeight = props.displayHeight, displayMinWidth = props.displayMinWidth, displayMinHeight = props.displayMinHeight, displayMaxWidth = props.displayMaxWidth, displayMaxHeight = props.displayMaxHeight, quality = props.quality, loader = props.loader, imgRef = props.imgRef, style = props.style, loading = props.loading, rest = __rest(props, ["src", "className", "displayWidth", "displayHeight", "displayMinWidth", "displayMinHeight", "displayMaxWidth", "displayMaxHeight", "quality", "loader", "imgRef", "style", "loading"]);
733
+ var imgProps = Object.assign({}, rest, {
734
+ // Default loading to "lazy" if not specified (which is different from the
735
+ // html img, which defaults to eager!)
736
+ loading: loading !== null && loading !== void 0 ? loading : "lazy",
654
737
  });
655
- };
656
- var Stack = Object.assign(FlexStack, {
657
- div: makeStackImpl("div"),
658
- a: makeStackImpl("a"),
659
- button: makeStackImpl("button"),
660
- h1: makeStackImpl("h1"),
661
- h2: makeStackImpl("h2"),
662
- h3: makeStackImpl("h3"),
663
- h4: makeStackImpl("h4"),
664
- h5: makeStackImpl("h5"),
665
- h6: makeStackImpl("h6"),
666
- label: makeStackImpl("label"),
667
- form: makeStackImpl("form"),
668
- section: makeStackImpl("section"),
669
- head: makeStackImpl("head"),
670
- main: makeStackImpl("main"),
671
- nav: makeStackImpl("nav"),
672
- });
673
-
674
- function hasVariant(variants, groupName, variant) {
675
- if (variants == null) {
676
- return false;
677
- }
678
- var groupVariants = variants[groupName];
679
- if (groupVariants == null) {
680
- return false;
738
+ var _a = !src
739
+ ? { fullWidth: undefined, fullHeight: undefined, aspectRatio: undefined }
740
+ : typeof src === "string"
741
+ ? getImageSizeData(getPixelLength(props.width), getPixelLength(props.height))
742
+ : src, fullWidth = _a.fullWidth, fullHeight = _a.fullHeight, aspectRatio = _a.aspectRatio;
743
+ var srcStr = src
744
+ ? typeof src === "string"
745
+ ? src
746
+ : typeof src.src === "string"
747
+ ? src.src
748
+ : src.src.src
749
+ : "";
750
+ // Assume external image if either dimension is null and use usual <img>
751
+ if (fullHeight == null || fullWidth == null) {
752
+ return (React__default.createElement("img", __assign({ src: srcStr, className: className, style: style }, imgProps, { loading: loading, ref: mergeRefs(imgRef, outerRef) })));
681
753
  }
682
- else if (groupVariants === true) {
683
- return variant === groupName;
754
+ if (isSvg(srcStr) &&
755
+ (displayHeight == null || displayHeight === "auto") &&
756
+ (displayWidth == null || displayWidth === "auto")) {
757
+ displayWidth = "100%";
684
758
  }
685
- else if (groupVariants === false) {
686
- return false;
759
+ var computedDisplayWidth = displayWidth;
760
+ if (fullWidth &&
761
+ fullHeight &&
762
+ (!displayWidth || displayWidth === "auto") &&
763
+ !!getPixelLength(displayHeight)) {
764
+ // If there's a pixel length specified for displayHeight but not displayWidth,
765
+ // then we can derive the pixel length for displayWidth. Having an explicit
766
+ // displayWidth makes this a fixed-size image, which makes it possible for us to
767
+ // generate better markup!
768
+ if (!isSvg(srcStr)) {
769
+ // We shouldn't do it for SVGs though, because `fullWidth` and
770
+ // `fullHeight` might have rounded values so the final
771
+ // `displayWidth` could differ by 1px or so.
772
+ computedDisplayWidth =
773
+ (getPixelLength(displayHeight) * fullWidth) / fullHeight;
774
+ }
687
775
  }
688
- else if (Array.isArray(groupVariants)) {
689
- return groupVariants.includes(variant);
776
+ var spacerWidth = fullWidth;
777
+ var spacerHeight = fullHeight;
778
+ if (aspectRatio && isFinite(aspectRatio) && isSvg(srcStr)) {
779
+ // For SVGs, fullWidth and fullHeight can be rounded values, which would
780
+ // cause some discrepancy between the actual aspect ratio and the aspect
781
+ // ratio from those values. So, for those cases, we set large width / height
782
+ // values to get a more precise ratio from the spacer.
783
+ spacerWidth = DEFAULT_SVG_WIDTH;
784
+ spacerHeight = Math.round(spacerWidth / aspectRatio);
690
785
  }
691
- else if (typeof groupVariants === "string") {
692
- return groupVariants === variant;
786
+ var _b = getWidths(computedDisplayWidth, fullWidth, {
787
+ minWidth: displayMinWidth,
788
+ }), sizes = _b.sizes, widthDescs = _b.widthDescs;
789
+ var imageLoader = getImageLoader(loader);
790
+ var spacerSvg = "<svg width=\"".concat(spacerWidth, "\" height=\"").concat(spacerHeight, "\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"/>");
791
+ var spacerSvgBase64 =
792
+ // if btoa exists, use btoa, as it works in browser and in
793
+ // cloudflare edge workers. For node, use Buffer.from().
794
+ typeof globalThis.btoa === "function"
795
+ ? globalThis.btoa(spacerSvg)
796
+ : Buffer.from(spacerSvg).toString("base64");
797
+ var wrapperStyle = __assign({}, (style || {}));
798
+ var spacerStyle = __assign({}, pick(style || {}, "objectFit", "objectPosition"));
799
+ if (displayWidth != null && displayWidth !== "auto") {
800
+ // If width is set, set it on the wrapper along with min/max width
801
+ // and just use `width: 100%` on the spacer
802
+ spacerStyle.width = "100%";
803
+ // Rely on the styles set by `classname` on the wrapper:
804
+ // wrapperStyle.width = displayWidth;
805
+ // wrapperStyle.minWidth = displayMinWidth;
806
+ // wrapperStyle.maxWidth = displayMaxWidth;
693
807
  }
694
808
  else {
695
- return (groupVariants[variant] !== undefined && groupVariants[variant] !== false);
696
- }
697
- }
698
- function wrapFlexContainerChildren(children, hasGap) {
699
- // We need to always wrap the children, even if there are no gaps, because
700
- // otherwise if we toggle between with and without gap, React reconciliation
701
- // will blow away the children tree and all state if we switch from having
702
- // a wrapper and not.
703
- var className = hasGap ? "__wab_flex-container ρfc" : "__wab_passthrough";
704
- if (!children) {
705
- return null;
809
+ // Otherwise, we want auto sizing from the spacer, so set width there.
810
+ //
811
+ // But if we have min/max width, it should be set in the wrapper and it
812
+ // can be percentage values (and we add corresponding min/max width to
813
+ // 100% in the spacer). In general it ends up with the correct effect,
814
+ // but some edge cases might make `min-width: 100%` shrink the image more
815
+ // than it should.
816
+ spacerStyle.width = displayWidth;
817
+ wrapperStyle.width = "auto";
818
+ if (displayMinWidth) {
819
+ spacerStyle.minWidth = "100%";
820
+ // Rely on min-width set by `classname` on the wrapper:
821
+ // wrapperStyle.minWidth = displayMinWidth;
822
+ }
823
+ if (displayMaxWidth != null && displayMaxWidth !== "none") {
824
+ spacerStyle.maxWidth = "100%";
825
+ // Rely on max-width set by `classname` on the wrapper:
826
+ // wrapperStyle.maxWidth = displayMaxWidth;
827
+ }
706
828
  }
707
- else if (Array.isArray(children)) {
708
- return React.createElement.apply(React, __spreadArray(["div", { className: className }], __read(children), false));
829
+ if (displayHeight != null && displayHeight !== "auto") {
830
+ spacerStyle.height = "100%";
831
+ // wrapperStyle.height = displayHeight;
832
+ // wrapperStyle.minHeight = displayMinHeight;
833
+ // wrapperStyle.maxHeight = displayMaxHeight;
709
834
  }
710
835
  else {
711
- return React.createElement("div", { className: className }, children);
712
- }
713
- }
714
- function createPlasmicElement(override, defaultRoot, defaultProps, wrapChildrenInFlex) {
715
- if (!override ||
716
- (typeof override === "object" && Object.keys(override).length === 0)) {
717
- return createElementWithChildren(defaultRoot, defaultProps, defaultProps.children);
718
- }
719
- var override2 = deriveOverride(override);
720
- var props = mergeOverrideProps(defaultProps, override2.props);
721
- if (override2.type === "render") {
722
- return override2.render(props, defaultRoot);
723
- }
724
- var root = defaultRoot;
725
- if (override2.type === "as" && override2.as) {
726
- if (defaultRoot === Stack) {
727
- // If there was an "as" override specified, but the default type is
728
- // a Stack, then we don't want to switch to using "as" as the root,
729
- // because then we'd lose the flex wrapper that Stack provides.
730
- // Instead, we specify the "as" as the "as" prop to Stack.
731
- props.as = override2.as;
836
+ spacerStyle.height = displayHeight;
837
+ wrapperStyle.height = "auto";
838
+ if (displayMinHeight) {
839
+ spacerStyle.minHeight = "100%";
840
+ // wrapperStyle.minHeight = displayMinHeight;
732
841
  }
733
- else {
734
- root = override2.as;
842
+ if (displayMaxHeight != null && displayMaxHeight !== "none") {
843
+ spacerStyle.maxHeight = "100%";
844
+ // wrapperStyle.maxHeight = displayMaxHeight;
735
845
  }
736
846
  }
737
- var children = props.children;
738
- if (override2.wrapChildren) {
739
- children = override2.wrapChildren(ensureNotArray(children));
740
- }
741
- if (wrapChildrenInFlex) {
742
- // For legacy, we still support data-plasmic-wrap-flex-children
743
- children = wrapFlexContainerChildren(children, true);
744
- }
745
- var result = createElementWithChildren(root, props, children);
746
- if (override2.wrap) {
747
- result = override2.wrap(result);
748
- }
749
- return result;
847
+ return (React__default.createElement("div", { className: classNames$1(className, "__wab_img-wrapper"), ref: outerRef, style: wrapperStyle },
848
+ React__default.createElement("img", { alt: "", "aria-hidden": true, className: "__wab_img-spacer-svg", src: "data:image/svg+xml;base64,".concat(spacerSvgBase64), style: spacerStyle }),
849
+ makePicture({
850
+ imageLoader: imageLoader,
851
+ widthDescs: widthDescs,
852
+ sizes: sizes,
853
+ src: srcStr,
854
+ quality: quality,
855
+ ref: imgRef,
856
+ style: style ? pick(style, "objectFit", "objectPosition") : undefined,
857
+ imgProps: imgProps,
858
+ className: "__wab_img",
859
+ })));
860
+ });
861
+ function makePicture(opts) {
862
+ // If imageLoader is undefined, then this renders to just a normal
863
+ // <img />. Else it will render to a <picture> with a <source> for
864
+ // webp, and srcSet/sizes set according to width requirements.
865
+ var imageLoader = opts.imageLoader, widthDescs = opts.widthDescs, src = opts.src, quality = opts.quality, style = opts.style, className = opts.className, sizes = opts.sizes, imgProps = opts.imgProps, ref = opts.ref;
866
+ return (React__default.createElement("picture", { className: "__wab_picture" },
867
+ imageLoader && imageLoader.supportsUrl(src) && (React__default.createElement("source", { type: "image/webp", srcSet: widthDescs
868
+ .map(function (wd) {
869
+ return "".concat(imageLoader.transformUrl({
870
+ src: src,
871
+ quality: quality,
872
+ width: wd.width,
873
+ format: "webp",
874
+ }), " ").concat(wd.desc);
875
+ })
876
+ .join(", ") })),
877
+ React__default.createElement("img", __assign({}, imgProps, { ref: ref, className: className, decoding: "async", src: imageLoader && imageLoader.supportsUrl(src)
878
+ ? imageLoader.transformUrl({
879
+ src: src,
880
+ quality: quality,
881
+ width: widthDescs[widthDescs.length - 1].width,
882
+ })
883
+ : src, srcSet: imageLoader && imageLoader.supportsUrl(src)
884
+ ? widthDescs
885
+ .map(function (wd) {
886
+ return "".concat(imageLoader.transformUrl({
887
+ src: src,
888
+ quality: quality,
889
+ width: wd.width,
890
+ }), " ").concat(wd.desc);
891
+ })
892
+ .join(", ")
893
+ : undefined, sizes: imageLoader && imageLoader.supportsUrl(src) ? sizes : undefined, style: __assign(__assign({}, (style ? pick(style, "objectFit", "objectPosition") : {})), { width: 0, height: 0 }) }))));
750
894
  }
751
- // We use data-plasmic-XXX attributes for custom properties since Typescript doesn't
752
- // support type check on jsx pragma. See https://github.com/microsoft/TypeScript/issues/21699
753
- // for more info.
754
- var seenElements = new Map();
755
- function createPlasmicElementProxy(defaultElement, props) {
756
- // We use seenElements to keep track of elements that has been rendered by
757
- // createPlasmicElementProxy(). When a JSX tree is evaluated, the JSX factory
758
- // is invoked from the leaf to the root as the last call. So we can store
759
- // all the elements we've created until we encounter the leaf, at which point
760
- // we will clear this map. We are guaranteed that this map will only contain
761
- // elements from one Plasmic* component at a time, because we're just creating
762
- // elements and not "rendering" at this point; even if this JSX tree references
763
- // other Plasmic* elements, we'll just create an element referencing that component,
764
- // rather than following into the content of that component.
765
- //
766
- // TODO: is this ConcurrentMode friendly?
895
+ var DEFAULT_SVG_WIDTH = 10000;
896
+ function isSvg(src) {
897
+ return src.endsWith(".svg") || src.startsWith("data:image/svg");
898
+ }
899
+ function getClosestPresetSize(width, fullWidth) {
767
900
  var _a;
768
- var children = [];
769
- for (var _i = 2; _i < arguments.length; _i++) {
770
- children[_i - 2] = arguments[_i];
901
+ var nextBiggerIndex = (_a = ALL_SIZES.findIndex(function (w) { return w >= width; })) !== null && _a !== void 0 ? _a : ALL_SIZES.length - 1;
902
+ var nextBigger = ALL_SIZES[nextBiggerIndex];
903
+ if (nextBigger >= fullWidth) {
904
+ // If the requested width is larger than the fullWidth,
905
+ // we just use the original width instead. It's impossible
906
+ // to make an image bigger than fullWidth!
907
+ return undefined;
771
908
  }
772
- if (props == null) {
773
- props = {};
909
+ else if (nextBiggerIndex + 1 < ALL_SIZES.length &&
910
+ fullWidth <= ALL_SIZES[nextBiggerIndex + 1]) {
911
+ // If the fullWidth is just between nextBigger and the one after that,
912
+ // then also might as well just use the original size (so, width is 30,
913
+ // nextBigger is 32, then we just use the original as long as fullWidth is
914
+ // less than 48)
915
+ return undefined;
774
916
  }
775
- var name = props["data-plasmic-name"];
776
- var isRoot = props["data-plasmic-root"];
777
- var forNodeName = props["data-plasmic-for-node"];
778
- delete props["data-plasmic-name"];
779
- delete props["data-plasmic-root"];
780
- delete props["data-plasmic-for-node"];
781
- var element = createPlasmicElementFromJsx.apply(void 0, __spreadArray([defaultElement,
782
- props], __read(children), false));
783
- if (name) {
784
- seenElements.set(name, element);
917
+ return nextBigger;
918
+ }
919
+ /**
920
+ * Computes the appropriate srcSet and sizes to use
921
+ */
922
+ function getWidths(width, fullWidth, extra) {
923
+ var minWidth = extra === null || extra === void 0 ? void 0 : extra.minWidth;
924
+ var pixelWidth = getPixelLength(width);
925
+ var pixelMinWidth = getPixelLength(minWidth);
926
+ if (pixelWidth != null && (!minWidth || pixelMinWidth != null)) {
927
+ // If there's an exact width, then we just need to display it at 1x and 2x density
928
+ return {
929
+ widthDescs: [
930
+ {
931
+ width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth !== null && pixelMinWidth !== void 0 ? pixelMinWidth : 0), fullWidth),
932
+ desc: "1x",
933
+ },
934
+ {
935
+ width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth !== null && pixelMinWidth !== void 0 ? pixelMinWidth : 0) * 2, fullWidth),
936
+ desc: "2x",
937
+ },
938
+ ],
939
+ sizes: undefined,
940
+ };
785
941
  }
786
- if (isRoot) {
787
- // If this is the root, and we requested a specific node by specifying data-plasmic-for-node,
788
- // then return that node instead
789
- var forNode = forNodeName
790
- ? (_a = seenElements.get(forNodeName)) !== null && _a !== void 0 ? _a : null
791
- : element;
792
- // Clear out the seenElements map, as we're done rendering this Plasmic* component.
793
- seenElements.clear();
794
- return forNode;
942
+ // Otherwise we don't know what sizes we'll end up, so we just cap it at
943
+ // device width. TODO: do better!
944
+ var usefulSizes = DEVICE_SIZES.filter(function (size) { return !fullWidth || size < fullWidth; });
945
+ if (!!fullWidth && usefulSizes.length === 0) {
946
+ // image fullWidth is smaller than all device sizes. So all we can do
947
+ // is offer 1x
948
+ return {
949
+ widthDescs: [
950
+ {
951
+ width: getClosestPresetSize(fullWidth, fullWidth),
952
+ desc: "1x",
953
+ },
954
+ ],
955
+ sizes: undefined,
956
+ };
795
957
  }
796
- return element;
958
+ return {
959
+ widthDescs: usefulSizes.map(function (size) { return ({
960
+ width: getClosestPresetSize(size, fullWidth),
961
+ // If this is the last (buggest) useful width, but it is
962
+ // still within the bounds set by DEVICE_SIZES, then just
963
+ // use the original, unresized image. This means if we match
964
+ // the largest size, we use unresized and best quality image.
965
+ // We only do this, though, if fullWidth is "reasonable" --
966
+ // smaller than the largest size we would consider.
967
+ // i === usefulSizes.length - 1 &&
968
+ // fullWidth < DEVICE_SIZES[DEVICE_SIZES.length - 1]
969
+ // ? undefined
970
+ // : size,
971
+ desc: "".concat(size, "w"),
972
+ }); }),
973
+ sizes: "100vw",
974
+ };
797
975
  }
798
- function createPlasmicElementFromJsx(defaultElement, props) {
799
- var _a;
800
- var children = [];
801
- for (var _i = 2; _i < arguments.length; _i++) {
802
- children[_i - 2] = arguments[_i];
976
+ function getPixelLength(length) {
977
+ if (length == null || length == "") {
978
+ return undefined;
803
979
  }
804
- var override = props["data-plasmic-override"];
805
- var wrapFlexChild = props["data-plasmic-wrap-flex-child"];
806
- var triggerProps = ((_a = props["data-plasmic-trigger-props"]) !== null && _a !== void 0 ? _a : []);
807
- delete props["data-plasmic-override"];
808
- delete props["data-plasmic-wrap-flex-child"];
809
- delete props["data-plasmic-trigger-props"];
810
- return createPlasmicElement(override, defaultElement, mergeProps.apply(void 0, __spreadArray([props,
811
- children.length === 0
812
- ? {}
813
- : { children: children.length === 1 ? children[0] : children }], __read(triggerProps), false)), wrapFlexChild);
980
+ if (typeof length === "number") {
981
+ return length;
982
+ }
983
+ var parsed = parseNumeric(length);
984
+ if (parsed && (!parsed.units || parsed.units === "px")) {
985
+ return parsed.num;
986
+ }
987
+ return undefined;
814
988
  }
815
- function makeFragment() {
816
- var children = [];
817
- for (var _i = 0; _i < arguments.length; _i++) {
818
- children[_i] = arguments[_i];
989
+ function parseNumeric(val) {
990
+ // Parse strings like "30", "30px", "30%", "30px /* blah blah */"
991
+ var res = val.match(/^\s*(-?(?:\d+\.\d*|\d*\.\d+|\d+))\s*([a-z]*|%)\s*(?:\/\*.*)?$/i);
992
+ if (res == null) {
993
+ return undefined;
819
994
  }
820
- return React.createElement.apply(React, __spreadArray([React.Fragment, {}], __read(children), false));
995
+ var num = res[1];
996
+ var units = res[2];
997
+ return { num: +num, units: units };
821
998
  }
822
- var UNSET = Symbol("UNSET");
823
- function mergeOverrideProps(defaults, overrides) {
824
- var e_1, _a;
825
- if (!overrides) {
826
- return defaults;
999
+ function getImageSizeData(width, height) {
1000
+ var aspectRatio = width && height ? width / height : undefined;
1001
+ return {
1002
+ fullWidth: width,
1003
+ fullHeight: height,
1004
+ aspectRatio: aspectRatio && isFinite(aspectRatio) ? aspectRatio : undefined,
1005
+ };
1006
+ }
1007
+ function getImageLoader(loader) {
1008
+ if (loader == null) {
1009
+ return undefined;
827
1010
  }
828
- var result = __assign({}, defaults);
829
- try {
830
- for (var _b = __values(Object.keys(overrides)), _c = _b.next(); !_c.done; _c = _b.next()) {
831
- var key = _c.value;
832
- var defaultVal = defaults[key];
833
- var overrideVal = overrides[key];
834
- if (overrideVal === UNSET) {
835
- delete result[key];
836
- }
837
- else {
838
- // We use the NONE sentinel if the overrideVal is nil, and is not one of the
839
- // props that we merge by default -- which are className, style, and
840
- // event handlers. This means for all other "normal" props -- like children,
841
- // title, etc -- a nil value will unset the default.
842
- if (overrideVal == null &&
843
- key !== "className" &&
844
- key !== "style" &&
845
- !(key.startsWith("on") && typeof defaultVal === "function")) {
846
- overrideVal = NONE;
847
- }
848
- result[key] = mergePropVals(key, defaultVal, overrideVal);
849
- }
850
- }
1011
+ else if (loader === "plasmic") {
1012
+ return PLASMIC_IMAGE_LOADER;
851
1013
  }
852
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
853
- finally {
854
- try {
855
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
856
- }
857
- finally { if (e_1) throw e_1.error; }
1014
+ else {
1015
+ return loader;
858
1016
  }
859
- return result;
860
1017
  }
861
- function wrapWithClassName(element, className) {
862
- var key = React.isValidElement(element)
863
- ? element.key || undefined
864
- : undefined;
865
- return React.createElement("div", {
866
- key: key,
867
- className: className,
868
- style: {
869
- display: "grid",
870
- },
871
- }, element);
1018
+ function isInternalKey(src) {
1019
+ return /^([a-f0-9]{32})\..{1,16}$/i.test(src);
872
1020
  }
873
- function deriveOverride(x) {
874
- if (!x) {
875
- // undefined Binding is an empty Binding
876
- return {
877
- type: "default",
878
- props: {},
879
- };
1021
+ var PLASMIC_IMAGE_LOADER = {
1022
+ supportsUrl: function (src) {
1023
+ return (src.startsWith("http") || isInternalKey(src)) && !isSvg(src);
1024
+ },
1025
+ transformUrl: function (opts) {
1026
+ var _a;
1027
+ var params = [
1028
+ "src=".concat(encodeURIComponent(opts.src)),
1029
+ opts.width ? "w=".concat(opts.width) : undefined,
1030
+ "q=".concat((_a = opts.quality) !== null && _a !== void 0 ? _a : 75),
1031
+ opts.format ? "f=".concat(opts.format) : undefined,
1032
+ ].filter(function (x) { return !!x; });
1033
+ return "".concat(IMG_OPTIMIZER_HOST, "/img-optimizer/v1/img?").concat(params.join("&"));
1034
+ },
1035
+ };
1036
+
1037
+ var PlasmicLink = React__default.forwardRef(function PlasmicLink(props, ref) {
1038
+ var _a;
1039
+ // The usePlasmicLinkMaybe function may be undefined, if host is not up-to-date
1040
+ var Link = (_a = usePlasmicLinkMaybe === null || usePlasmicLinkMaybe === void 0 ? void 0 : usePlasmicLinkMaybe()) !== null && _a !== void 0 ? _a : PlasmicLinkInternal;
1041
+ if (Link === PlasmicLink || Link === PlasmicLinkInternal) {
1042
+ // Just in case, break the cycle
1043
+ return React__default.createElement(PlasmicLinkInternal, __assign({}, props, { ref: ref }));
880
1044
  }
881
- else if (isReactNode(x)) {
882
- // If ReactNode, then assume this is the children
883
- return {
884
- type: "default",
885
- props: {
886
- children: x,
887
- },
888
- };
1045
+ else {
1046
+ // Don't pass component/platform props to non-PlasmicLinkInternal
1047
+ return React__default.createElement(Link, __assign({}, omit(props, "component", "platform"), { ref: ref }));
889
1048
  }
890
- else if (typeof x === "object") {
891
- // If any of the overrideKeys is a key of this object, then assume
892
- // this is a full Override
893
- if ("as" in x) {
894
- return __assign(__assign({}, x), { props: x.props || {}, type: "as" });
1049
+ });
1050
+ var PlasmicLinkInternal = React__default.forwardRef(function PlasmicLinkInternal(props, ref) {
1051
+ var _a;
1052
+ // props.href is required for nextjs; if no props.href,
1053
+ // then we just render the default anchor element
1054
+ if (props.platform === "nextjs" && props.href) {
1055
+ var nextjsProps = [
1056
+ "href",
1057
+ "replace",
1058
+ "scroll",
1059
+ "shallow",
1060
+ "passHref",
1061
+ "prefetch",
1062
+ "locale",
1063
+ ];
1064
+ // If this is a fragment identifier link, then we set
1065
+ // scroll={false} so that smooth scrolling works
1066
+ var isFragment = (_a = props.href) === null || _a === void 0 ? void 0 : _a.startsWith("#");
1067
+ return React__default.createElement(props.component, __assign(__assign({ scroll: !isFragment }, pick.apply(void 0, __spreadArray([props], __read(nextjsProps), false))), { legacyBehavior: true }), React__default.createElement("a", __assign({}, omit.apply(void 0, __spreadArray([props, "component", "platform"], __read(nextjsProps), false)), { ref: ref })));
1068
+ }
1069
+ if (props.platform === "gatsby" && isInternalHref(props.href)) {
1070
+ return React__default.createElement(props.component, __assign(__assign({}, omit(props, "component", "platform", "href")), { to: props.href, ref: ref }));
1071
+ }
1072
+ if (props.platform === "tanstack" && isInternalHref(props.href)) {
1073
+ return React__default.createElement(props.component, __assign(__assign({}, omit(props, "component", "platform", "href")), { to: props.href, ref: ref }));
1074
+ }
1075
+ return React__default.createElement("a", __assign({}, omit(props, "component", "platform"), { ref: ref }));
1076
+ });
1077
+ function isInternalHref(href) {
1078
+ return /^\/(?!\/)/.test(href);
1079
+ }
1080
+
1081
+ // Make the refactor to host backwards compatible for loader
1082
+ var PlasmicTranslatorContext = PlasmicTranslatorContext$1 !== null && PlasmicTranslatorContext$1 !== void 0 ? PlasmicTranslatorContext$1 : React__default.createContext(undefined);
1083
+ var usePlasmicTranslator = usePlasmicTranslator$1 !== null && usePlasmicTranslator$1 !== void 0 ? usePlasmicTranslator$1 : (function () {
1084
+ var _t = React__default.useContext(PlasmicTranslatorContext);
1085
+ var translator = _t
1086
+ ? typeof _t === "function"
1087
+ ? _t
1088
+ : _t.translator
1089
+ : undefined;
1090
+ return translator;
1091
+ });
1092
+ function genTranslatableString(elt, opts) {
1093
+ var components = {};
1094
+ var componentsCount = 0;
1095
+ var getText = function (node) {
1096
+ var _a;
1097
+ if (!node) {
1098
+ return "";
895
1099
  }
896
- else if ("render" in x) {
897
- return __assign(__assign({}, x), { type: "render" });
1100
+ if (typeof node === "number" ||
1101
+ typeof node === "boolean" ||
1102
+ typeof node === "string") {
1103
+ return node.toString();
898
1104
  }
899
- else if ("props" in x) {
900
- return __assign(__assign({}, x), { props: x.props || {}, type: "default" });
1105
+ if (typeof node !== "object") {
1106
+ return "";
901
1107
  }
902
- else if (isSubset(Object.keys(x), ["wrap", "wrapChildren"])) {
903
- // Only twiddling functions present, so assume no props overrides
904
- // (otherwise we'd assume these were props).
905
- return __assign(__assign({}, x), { props: {}, type: "default" });
1108
+ if (Array.isArray(node) || isIterable(node)) {
1109
+ return Array.from(node)
1110
+ .map(function (child) { return getText(child); })
1111
+ .filter(function (child) { return !!child; })
1112
+ .join("");
906
1113
  }
907
- // Else, assume this is just a props object.
908
- return {
909
- type: "default",
910
- props: x,
911
- };
912
- }
913
- else if (typeof x === "function") {
914
- return {
915
- type: "render",
916
- render: x,
917
- };
1114
+ var nodeChildren = (hasKey(node, "props") &&
1115
+ hasKey(node.props, "children") &&
1116
+ node.props.children) ||
1117
+ (hasKey(node, "children") && node.children) ||
1118
+ [];
1119
+ var contents = "".concat(React__default.Children.toArray(nodeChildren)
1120
+ .map(function (child) { return getText(child); })
1121
+ .filter(function (child) { return !!child; })
1122
+ .join(""));
1123
+ if (React__default.isValidElement(node) && node.type === React__default.Fragment) {
1124
+ return contents;
1125
+ }
1126
+ var prefix = (_a = opts === null || opts === void 0 ? void 0 : opts.tagPrefix) !== null && _a !== void 0 ? _a : "";
1127
+ var componentId = "".concat(prefix).concat(componentsCount + 1);
1128
+ componentsCount++;
1129
+ components[componentId] = React__default.isValidElement(node)
1130
+ ? React__default.cloneElement(node, {
1131
+ key: componentId,
1132
+ children: undefined,
1133
+ })
1134
+ : node;
1135
+ return "<".concat(componentId, ">").concat(contents, "</").concat(componentId, ">");
1136
+ };
1137
+ var str = getText(elt);
1138
+ return {
1139
+ str: str,
1140
+ components: components,
1141
+ componentsCount: componentsCount,
1142
+ };
1143
+ }
1144
+ function Trans(_a) {
1145
+ var transKey = _a.transKey, children = _a.children;
1146
+ var _t = React__default.useContext(PlasmicTranslatorContext);
1147
+ var translator = _t
1148
+ ? typeof _t === "function"
1149
+ ? _t
1150
+ : _t.translator
1151
+ : undefined;
1152
+ if (!translator) {
1153
+ warnNoTranslationFunctionAtMostOnce();
1154
+ return children;
918
1155
  }
919
- throw new Error("Unexpected override: ".concat(x));
1156
+ var _b = genTranslatableString(children, {
1157
+ tagPrefix: typeof _t === "object" ? _t.tagPrefix : undefined,
1158
+ }), str = _b.str, components = _b.components, componentsCount = _b.componentsCount;
1159
+ return translator(transKey !== null && transKey !== void 0 ? transKey : str, componentsCount > 0 ? { components: components } : undefined);
920
1160
  }
921
- function mergeVariants(v1, v2) {
922
- if (!v1 || !v2) {
923
- return v1 || v2 || {};
1161
+ var hasWarned = false;
1162
+ function warnNoTranslationFunctionAtMostOnce() {
1163
+ if (!hasWarned) {
1164
+ console.warn("Using Plasmic Translation but no translation function has been provided");
1165
+ hasWarned = true;
924
1166
  }
925
- return __assign(__assign({}, v1), v2);
926
1167
  }
927
- function mergeVariantsWithStates(variants, $state, linkedStates) {
928
- return __assign(__assign({}, variants), Object.fromEntries(linkedStates.map(function (_a) {
929
- var variantGroup = _a.variantGroup, statePath = _a.statePath;
930
- return [
931
- variantGroup,
932
- get($state, statePath),
933
- ];
934
- })));
1168
+ function hasKey(v, key) {
1169
+ return typeof v === "object" && v !== null && key in v;
935
1170
  }
936
- function mergeArgs(a1, a2) {
937
- if (!a1 || !a2) {
938
- return a1 || a2 || {};
939
- }
940
- return __assign(__assign({}, a1), a2);
1171
+ function isIterable(val) {
1172
+ return val != null && typeof val[Symbol.iterator] === "function";
941
1173
  }
942
- function mergeFlexOverrides(o1, o2) {
943
- var e_2, _a;
944
- if (!o2) {
945
- return o1;
946
- }
947
- var keys = Array.from(new Set(__spreadArray(__spreadArray([], __read(Object.keys(o1)), false), __read(Object.keys(o2)), false)));
948
- var merged = {};
949
- try {
950
- for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
951
- var key = keys_1_1.value;
952
- merged[key] = mergeFlexOverride(o1[key], o2[key]);
953
- }
1174
+
1175
+ function PlasmicSlot(props) {
1176
+ return renderPlasmicSlot(props);
1177
+ }
1178
+ function renderPlasmicSlot(opts) {
1179
+ var as = opts.as, defaultContents = opts.defaultContents, value = opts.value, rest = __rest(opts, ["as", "defaultContents", "value"]);
1180
+ var content = value === undefined ? defaultContents : value;
1181
+ if (typeof content !== "number" &&
1182
+ (!content || (Array.isArray(content) && content.length === 0))) {
1183
+ return null;
954
1184
  }
955
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
956
- finally {
957
- try {
958
- if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
959
- }
960
- finally { if (e_2) throw e_2.error; }
1185
+ // If the content is a raw string, then we need to wrap the raw string
1186
+ // into an element, in case the slot is inside a flex-gap
1187
+ // container (you cannot apply margin to just a text node).
1188
+ var maybeString = maybeAsString(content);
1189
+ if (maybeString) {
1190
+ content = (React.createElement("span", { className: "__wab_slot-string-wrapper \u03C1sw" }, maybeString));
961
1191
  }
962
- return merged;
1192
+ var nonEmptyProps = Object.keys(rest).filter(function (p) { return !!rest[p]; });
1193
+ if (nonEmptyProps.length === 0) {
1194
+ // No attrs to apply to the slot (which means the slot is unstyled), then
1195
+ // just render the content directly; no need for style wrapper.
1196
+ return content;
1197
+ }
1198
+ return React.createElement(as || "span", mergeProps({ className: "__wab_slot ρs" }, rest), content);
963
1199
  }
964
- function mergeFlexOverride(fo1, fo2) {
965
- var _a, _b;
966
- if (!fo1) {
967
- return fo2;
1200
+ function maybeAsString(node) {
1201
+ // Unwrap fragments
1202
+ if (React.isValidElement(node)) {
1203
+ // Fragment doesn't render DOM elements
1204
+ if (node.type === React.Fragment) {
1205
+ return maybeAsString(node.props.children);
1206
+ }
1207
+ else if (node.type === Trans) {
1208
+ // Trans also doesn't render DOM elements. But we don't want to just render
1209
+ // its content string, because we want to keep the <Trans/> for the localization.
1210
+ // So we render the same node, to be wrapped into __wab_slot-string-wrapper.
1211
+ return node;
1212
+ }
968
1213
  }
969
- if (!fo2) {
970
- return fo1;
1214
+ if (typeof node === "string") {
1215
+ return node;
971
1216
  }
972
- var o1 = deriveOverride(fo1);
973
- var o2 = deriveOverride(fo2);
974
- var wrap = chainSingleArgFuncs.apply(void 0, __spreadArray([], __read([o1.wrap, o2.wrap].filter(notNil)), false));
975
- var wrapChildren = chainSingleArgFuncs.apply(void 0, __spreadArray([], __read([o1.wrapChildren, o2.wrapChildren].filter(notNil)), false));
976
- // "render" type always takes precedence, but we still merge the props
977
- var props = mergeOverrideProps((_a = o1.props) !== null && _a !== void 0 ? _a : {}, o2.props);
978
- if (o2.type === "render") {
979
- return {
980
- render: o2.render,
981
- props: props,
982
- wrap: wrap,
983
- wrapChildren: wrapChildren,
984
- };
1217
+ if (typeof node === "number") {
1218
+ return "".concat(node);
985
1219
  }
986
- if (o1.type === "render") {
987
- return {
988
- render: o1.render,
989
- props: props,
990
- wrap: wrap,
991
- wrapChildren: wrapChildren,
992
- };
1220
+ if (Array.isArray(node) && node.length === 1 && typeof node[0] === "string") {
1221
+ return node[0];
993
1222
  }
994
- // "as" will take precedence
995
- var as = (_b = (o2.type === "as" ? o2.as : undefined)) !== null && _b !== void 0 ? _b : (o1.type === "as" ? o1.as : undefined);
996
- return __assign({ props: props, wrap: wrap, wrapChildren: wrapChildren }, (as ? { as: as } : {}));
1223
+ return undefined;
997
1224
  }
998
- function deriveRenderOpts(props, config) {
999
- var _a;
1000
- var name = config.name, descendantNames = config.descendantNames, internalVariantPropNames = config.internalVariantPropNames, internalArgPropNames = config.internalArgPropNames;
1001
- var reservedPropNames = ["variants", "args", "overrides"];
1002
- var variants = mergeVariants(omit.apply(void 0, __spreadArray([pick.apply(void 0, __spreadArray([props], __read(internalVariantPropNames), false))], __read(reservedPropNames), false)), props.variants);
1003
- var args = mergeArgs(omit.apply(void 0, __spreadArray([pick.apply(void 0, __spreadArray([props], __read(internalArgPropNames), false))], __read(reservedPropNames), false)), props.args);
1004
- var overrides = mergeFlexOverrides(omit.apply(void 0, __spreadArray(__spreadArray(__spreadArray([pick.apply(void 0, __spreadArray([props], __read(descendantNames), false))], __read(internalArgPropNames), false), __read(internalVariantPropNames), false), __read(reservedPropNames), false)), props.overrides);
1005
- var leftoverProps = omit.apply(void 0, __spreadArray(__spreadArray(__spreadArray([props,
1006
- "variants",
1007
- "args",
1008
- "overrides"], __read(descendantNames), false), __read(internalVariantPropNames), false), __read(internalArgPropNames), false));
1009
- if (Object.keys(leftoverProps).length > 0) {
1010
- overrides = mergeFlexOverrides(overrides, (_a = {},
1011
- _a[name] = {
1012
- props: leftoverProps,
1013
- },
1014
- _a));
1225
+
1226
+ function hasVariant(variants, groupName, variant) {
1227
+ if (variants == null) {
1228
+ return false;
1229
+ }
1230
+ var groupVariants = variants[groupName];
1231
+ if (groupVariants == null) {
1232
+ return false;
1233
+ }
1234
+ else if (groupVariants === true) {
1235
+ return variant === groupName;
1236
+ }
1237
+ else if (groupVariants === false) {
1238
+ return false;
1239
+ }
1240
+ else if (Array.isArray(groupVariants)) {
1241
+ return groupVariants.includes(variant);
1242
+ }
1243
+ else if (typeof groupVariants === "string") {
1244
+ return groupVariants === variant;
1245
+ }
1246
+ else {
1247
+ return (groupVariants[variant] !== undefined && groupVariants[variant] !== false);
1015
1248
  }
1016
- return { variants: variants, args: args, overrides: overrides };
1017
1249
  }
1018
-
1019
- var isDefaultValue = function (val) { return val === "PLEASE_RENDER_INSIDE_PROVIDER"; };
1020
- var seenDefaultVariants = {};
1021
- function ensureGlobalVariants(globalVariantValues) {
1022
- Object.entries(globalVariantValues)
1023
- .filter(function (_a) {
1024
- var _b = __read(_a, 2); _b[0]; var value = _b[1];
1025
- return isDefaultValue(value);
1026
- })
1027
- .forEach(function (_a) {
1028
- var _b = __read(_a, 2), key = _b[0]; _b[1];
1029
- globalVariantValues[key] = undefined;
1030
- if (!seenDefaultVariants[key] && process.env.NODE_ENV === "development") {
1031
- seenDefaultVariants[key] = true;
1032
- var providerName = "".concat(key[0].toUpperCase()).concat(key.substring(1), "Context.Provider");
1033
- console.warn("Plasmic context value for global variant \"".concat(key, "\" was not provided; please use ").concat(providerName, " at the root of your React app. Learn More: https://www.plasmic.app/learn/other-assets/#global-variants"));
1034
- }
1035
- });
1036
- return globalVariantValues;
1250
+ function wrapFlexContainerChildren(children, hasGap) {
1251
+ // We need to always wrap the children, even if there are no gaps, because
1252
+ // otherwise if we toggle between with and without gap, React reconciliation
1253
+ // will blow away the children tree and all state if we switch from having
1254
+ // a wrapper and not.
1255
+ var className = hasGap ? "__wab_flex-container ρfc" : "__wab_passthrough";
1256
+ if (!children) {
1257
+ return null;
1258
+ }
1259
+ else if (Array.isArray(children)) {
1260
+ return React.createElement.apply(React, __spreadArray(["div", { className: className }], __read(children), false));
1261
+ }
1262
+ else {
1263
+ return React.createElement("div", { className: className }, children);
1264
+ }
1037
1265
  }
1038
-
1039
- var PlasmicHeadContext = React.createContext(undefined);
1040
- function PlasmicHead(props) {
1041
- var Head = React.useContext(PlasmicHeadContext);
1042
- var headMetadata =
1043
- // Check if `HeadMetadataContext` is exported for backward compatibility
1044
- "HeadMetadataContext" in plasmicQuery
1045
- ? React.useContext(plasmicQuery.HeadMetadataContext)
1046
- : undefined;
1047
- if (headMetadata) {
1048
- // If we have the Head metadata object specified, mutate it so to ensure it
1049
- // stores the data that should go in the <head>.
1050
- if (props.image) {
1051
- headMetadata.image = props.image;
1052
- }
1053
- if (props.title) {
1054
- headMetadata.title = props.title;
1055
- }
1056
- if (props.description) {
1057
- headMetadata.description = props.description;
1266
+ function createPlasmicElement(override, defaultRoot, defaultProps, wrapChildrenInFlex) {
1267
+ if (!override ||
1268
+ (typeof override === "object" && Object.keys(override).length === 0)) {
1269
+ return createElementWithChildren(defaultRoot, defaultProps, defaultProps.children);
1270
+ }
1271
+ var override2 = deriveOverride(override);
1272
+ var props = mergeOverrideProps(defaultProps, override2.props);
1273
+ if (override2.type === "render") {
1274
+ return override2.render(props, defaultRoot);
1275
+ }
1276
+ var root = defaultRoot;
1277
+ if (override2.type === "as" && override2.as) {
1278
+ if (defaultRoot === Stack) {
1279
+ // If there was an "as" override specified, but the default type is
1280
+ // a Stack, then we don't want to switch to using "as" as the root,
1281
+ // because then we'd lose the flex wrapper that Stack provides.
1282
+ // Instead, we specify the "as" as the "as" prop to Stack.
1283
+ props.as = override2.as;
1058
1284
  }
1059
- if (props.canonical) {
1060
- headMetadata.canonical = props.canonical;
1285
+ else {
1286
+ root = override2.as;
1061
1287
  }
1062
1288
  }
1063
- if (!Head) {
1064
- console.warn("Plasmic: Head meta tags are being ignored. To make them work, pass a Head component into PlasmicRootProvider.");
1065
- // TODO: Link to doc about Head.
1066
- return null;
1289
+ var children = props.children;
1290
+ if (override2.wrapChildren) {
1291
+ children = override2.wrapChildren(ensureNotArray(children));
1067
1292
  }
1068
- // Helmet does not support React.Fragments, so we need to use `[<meta />,
1069
- // <meta />]` instead of `<><meta /><meta /></>`.
1070
- return (React.createElement(Head, null,
1071
- props.image ? ([
1072
- React.createElement("meta", { key: "twitter:card", name: "twitter:card", content: "summary_large_image" }),
1073
- React.createElement("meta", { key: "og:image", property: "og:image", content: props.image }),
1074
- React.createElement("meta", { key: "twitter:image", name: "twitter:image", content: props.image }),
1075
- ]) : (React.createElement("meta", { key: "twitter:card", name: "twitter:card", content: "summary" })),
1076
- props.title && [
1077
- React.createElement("title", { key: "title" }, props.title),
1078
- React.createElement("meta", { key: "og:title", property: "og:title", content: props.title }),
1079
- React.createElement("meta", { key: "twitter:title", property: "twitter:title", content: props.title }),
1080
- ],
1081
- props.description && [
1082
- React.createElement("meta", { key: "description", name: "description", content: props.description }),
1083
- React.createElement("meta", { key: "og:description", property: "og:description", content: props.description }),
1084
- React.createElement("meta", { key: "twitter:description", name: "twitter:description", content: props.description }),
1085
- ],
1086
- props.canonical && (React.createElement("link", { key: "canonical", rel: "canonical", href: props.canonical }))));
1293
+ if (wrapChildrenInFlex) {
1294
+ // For legacy, we still support data-plasmic-wrap-flex-children
1295
+ children = wrapFlexContainerChildren(children, true);
1296
+ }
1297
+ var result = createElementWithChildren(root, props, children);
1298
+ if (override2.wrap) {
1299
+ result = override2.wrap(result);
1300
+ }
1301
+ return result;
1087
1302
  }
1088
- var plasmicHeadMeta = {
1089
- name: "hostless-plasmic-head",
1090
- displayName: "Page Metadata Override",
1091
- description: "Set page metadata (HTML <head />) to dynamic values.",
1092
- importName: "PlasmicHead",
1093
- importPath: "@plasmicapp/react-web",
1094
- isRepeatable: false,
1095
- styleSections: false,
1096
- props: {
1097
- title: {
1098
- type: "string",
1099
- displayName: "Title",
1100
- },
1101
- description: {
1102
- type: "string",
1103
- displayName: "Description",
1104
- },
1105
- image: {
1106
- type: "imageUrl",
1107
- displayName: "Image",
1108
- },
1109
- canonical: {
1110
- type: "string",
1111
- displayName: "Canonical URL",
1112
- },
1113
- },
1114
- };
1115
-
1116
- function PlasmicIcon(props) {
1117
- var PlasmicIconType = props.PlasmicIconType, rest = __rest(props, ["PlasmicIconType"]);
1118
- return React.createElement(PlasmicIconType, __assign({}, rest));
1119
- }
1120
-
1121
- /**
1122
- * Responsive `<img/>` replacement, based on `next/image`
1123
- */
1124
- var IMG_OPTIMIZER_HOST = "https://img.plasmic.app";
1125
- // Default image sizes to snap to
1126
- // TODO: make this configurable?
1127
- var IMG_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];
1128
- var DEVICE_SIZES = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
1129
- var ALL_SIZES = __spreadArray(__spreadArray([], __read(IMG_SIZES), false), __read(DEVICE_SIZES), false);
1130
- var PlasmicImg = React__default.forwardRef(function PlasmicImg(props, outerRef) {
1131
- var src = props.src, className = props.className, displayWidth = props.displayWidth, displayHeight = props.displayHeight, displayMinWidth = props.displayMinWidth, displayMinHeight = props.displayMinHeight, displayMaxWidth = props.displayMaxWidth, displayMaxHeight = props.displayMaxHeight, quality = props.quality, loader = props.loader, imgRef = props.imgRef, style = props.style, loading = props.loading, rest = __rest(props, ["src", "className", "displayWidth", "displayHeight", "displayMinWidth", "displayMinHeight", "displayMaxWidth", "displayMaxHeight", "quality", "loader", "imgRef", "style", "loading"]);
1132
- var imgProps = Object.assign({}, rest, {
1133
- // Default loading to "lazy" if not specified (which is different from the
1134
- // html img, which defaults to eager!)
1135
- loading: loading !== null && loading !== void 0 ? loading : "lazy",
1136
- });
1137
- var _a = !src
1138
- ? { fullWidth: undefined, fullHeight: undefined, aspectRatio: undefined }
1139
- : typeof src === "string"
1140
- ? getImageSizeData(getPixelLength(props.width), getPixelLength(props.height))
1141
- : src, fullWidth = _a.fullWidth, fullHeight = _a.fullHeight, aspectRatio = _a.aspectRatio;
1142
- var srcStr = src
1143
- ? typeof src === "string"
1144
- ? src
1145
- : typeof src.src === "string"
1146
- ? src.src
1147
- : src.src.src
1148
- : "";
1149
- // Assume external image if either dimension is null and use usual <img>
1150
- if (fullHeight == null || fullWidth == null) {
1151
- return (React__default.createElement("img", __assign({ src: srcStr, className: className, style: style }, imgProps, { loading: loading, ref: mergeRefs(imgRef, outerRef) })));
1152
- }
1153
- if (isSvg(srcStr) &&
1154
- (displayHeight == null || displayHeight === "auto") &&
1155
- (displayWidth == null || displayWidth === "auto")) {
1156
- displayWidth = "100%";
1157
- }
1158
- var computedDisplayWidth = displayWidth;
1159
- if (fullWidth &&
1160
- fullHeight &&
1161
- (!displayWidth || displayWidth === "auto") &&
1162
- !!getPixelLength(displayHeight)) {
1163
- // If there's a pixel length specified for displayHeight but not displayWidth,
1164
- // then we can derive the pixel length for displayWidth. Having an explicit
1165
- // displayWidth makes this a fixed-size image, which makes it possible for us to
1166
- // generate better markup!
1167
- if (!isSvg(srcStr)) {
1168
- // We shouldn't do it for SVGs though, because `fullWidth` and
1169
- // `fullHeight` might have rounded values so the final
1170
- // `displayWidth` could differ by 1px or so.
1171
- computedDisplayWidth =
1172
- (getPixelLength(displayHeight) * fullWidth) / fullHeight;
1173
- }
1174
- }
1175
- var spacerWidth = fullWidth;
1176
- var spacerHeight = fullHeight;
1177
- if (aspectRatio && isFinite(aspectRatio) && isSvg(srcStr)) {
1178
- // For SVGs, fullWidth and fullHeight can be rounded values, which would
1179
- // cause some discrepancy between the actual aspect ratio and the aspect
1180
- // ratio from those values. So, for those cases, we set large width / height
1181
- // values to get a more precise ratio from the spacer.
1182
- spacerWidth = DEFAULT_SVG_WIDTH;
1183
- spacerHeight = Math.round(spacerWidth / aspectRatio);
1184
- }
1185
- var _b = getWidths(computedDisplayWidth, fullWidth, {
1186
- minWidth: displayMinWidth,
1187
- }), sizes = _b.sizes, widthDescs = _b.widthDescs;
1188
- var imageLoader = getImageLoader(loader);
1189
- var spacerSvg = "<svg width=\"".concat(spacerWidth, "\" height=\"").concat(spacerHeight, "\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"/>");
1190
- var spacerSvgBase64 =
1191
- // if btoa exists, use btoa, as it works in browser and in
1192
- // cloudflare edge workers. For node, use Buffer.from().
1193
- typeof globalThis.btoa === "function"
1194
- ? globalThis.btoa(spacerSvg)
1195
- : Buffer.from(spacerSvg).toString("base64");
1196
- var wrapperStyle = __assign({}, (style || {}));
1197
- var spacerStyle = __assign({}, pick(style || {}, "objectFit", "objectPosition"));
1198
- if (displayWidth != null && displayWidth !== "auto") {
1199
- // If width is set, set it on the wrapper along with min/max width
1200
- // and just use `width: 100%` on the spacer
1201
- spacerStyle.width = "100%";
1202
- // Rely on the styles set by `classname` on the wrapper:
1203
- // wrapperStyle.width = displayWidth;
1204
- // wrapperStyle.minWidth = displayMinWidth;
1205
- // wrapperStyle.maxWidth = displayMaxWidth;
1206
- }
1207
- else {
1208
- // Otherwise, we want auto sizing from the spacer, so set width there.
1209
- //
1210
- // But if we have min/max width, it should be set in the wrapper and it
1211
- // can be percentage values (and we add corresponding min/max width to
1212
- // 100% in the spacer). In general it ends up with the correct effect,
1213
- // but some edge cases might make `min-width: 100%` shrink the image more
1214
- // than it should.
1215
- spacerStyle.width = displayWidth;
1216
- wrapperStyle.width = "auto";
1217
- if (displayMinWidth) {
1218
- spacerStyle.minWidth = "100%";
1219
- // Rely on min-width set by `classname` on the wrapper:
1220
- // wrapperStyle.minWidth = displayMinWidth;
1221
- }
1222
- if (displayMaxWidth != null && displayMaxWidth !== "none") {
1223
- spacerStyle.maxWidth = "100%";
1224
- // Rely on max-width set by `classname` on the wrapper:
1225
- // wrapperStyle.maxWidth = displayMaxWidth;
1226
- }
1227
- }
1228
- if (displayHeight != null && displayHeight !== "auto") {
1229
- spacerStyle.height = "100%";
1230
- // wrapperStyle.height = displayHeight;
1231
- // wrapperStyle.minHeight = displayMinHeight;
1232
- // wrapperStyle.maxHeight = displayMaxHeight;
1233
- }
1234
- else {
1235
- spacerStyle.height = displayHeight;
1236
- wrapperStyle.height = "auto";
1237
- if (displayMinHeight) {
1238
- spacerStyle.minHeight = "100%";
1239
- // wrapperStyle.minHeight = displayMinHeight;
1240
- }
1241
- if (displayMaxHeight != null && displayMaxHeight !== "none") {
1242
- spacerStyle.maxHeight = "100%";
1243
- // wrapperStyle.maxHeight = displayMaxHeight;
1244
- }
1245
- }
1246
- return (React__default.createElement("div", { className: classNames$1(className, "__wab_img-wrapper"), ref: outerRef, style: wrapperStyle },
1247
- React__default.createElement("img", { alt: "", "aria-hidden": true, className: "__wab_img-spacer-svg", src: "data:image/svg+xml;base64,".concat(spacerSvgBase64), style: spacerStyle }),
1248
- makePicture({
1249
- imageLoader: imageLoader,
1250
- widthDescs: widthDescs,
1251
- sizes: sizes,
1252
- src: srcStr,
1253
- quality: quality,
1254
- ref: imgRef,
1255
- style: style ? pick(style, "objectFit", "objectPosition") : undefined,
1256
- imgProps: imgProps,
1257
- className: "__wab_img",
1258
- })));
1259
- });
1260
- function makePicture(opts) {
1261
- // If imageLoader is undefined, then this renders to just a normal
1262
- // <img />. Else it will render to a <picture> with a <source> for
1263
- // webp, and srcSet/sizes set according to width requirements.
1264
- var imageLoader = opts.imageLoader, widthDescs = opts.widthDescs, src = opts.src, quality = opts.quality, style = opts.style, className = opts.className, sizes = opts.sizes, imgProps = opts.imgProps, ref = opts.ref;
1265
- return (React__default.createElement("picture", { className: "__wab_picture" },
1266
- imageLoader && imageLoader.supportsUrl(src) && (React__default.createElement("source", { type: "image/webp", srcSet: widthDescs
1267
- .map(function (wd) {
1268
- return "".concat(imageLoader.transformUrl({
1269
- src: src,
1270
- quality: quality,
1271
- width: wd.width,
1272
- format: "webp",
1273
- }), " ").concat(wd.desc);
1274
- })
1275
- .join(", ") })),
1276
- React__default.createElement("img", __assign({}, imgProps, { ref: ref, className: className, decoding: "async", src: imageLoader && imageLoader.supportsUrl(src)
1277
- ? imageLoader.transformUrl({
1278
- src: src,
1279
- quality: quality,
1280
- width: widthDescs[widthDescs.length - 1].width,
1281
- })
1282
- : src, srcSet: imageLoader && imageLoader.supportsUrl(src)
1283
- ? widthDescs
1284
- .map(function (wd) {
1285
- return "".concat(imageLoader.transformUrl({
1286
- src: src,
1287
- quality: quality,
1288
- width: wd.width,
1289
- }), " ").concat(wd.desc);
1290
- })
1291
- .join(", ")
1292
- : undefined, sizes: imageLoader && imageLoader.supportsUrl(src) ? sizes : undefined, style: __assign(__assign({}, (style ? pick(style, "objectFit", "objectPosition") : {})), { width: 0, height: 0 }) }))));
1293
- }
1294
- var DEFAULT_SVG_WIDTH = 10000;
1295
- function isSvg(src) {
1296
- return src.endsWith(".svg") || src.startsWith("data:image/svg");
1297
- }
1298
- function getClosestPresetSize(width, fullWidth) {
1303
+ // We use data-plasmic-XXX attributes for custom properties since Typescript doesn't
1304
+ // support type check on jsx pragma. See https://github.com/microsoft/TypeScript/issues/21699
1305
+ // for more info.
1306
+ var seenElements = new Map();
1307
+ function createPlasmicElementProxy(defaultElement, props) {
1308
+ // We use seenElements to keep track of elements that has been rendered by
1309
+ // createPlasmicElementProxy(). When a JSX tree is evaluated, the JSX factory
1310
+ // is invoked from the leaf to the root as the last call. So we can store
1311
+ // all the elements we've created until we encounter the leaf, at which point
1312
+ // we will clear this map. We are guaranteed that this map will only contain
1313
+ // elements from one Plasmic* component at a time, because we're just creating
1314
+ // elements and not "rendering" at this point; even if this JSX tree references
1315
+ // other Plasmic* elements, we'll just create an element referencing that component,
1316
+ // rather than following into the content of that component.
1317
+ //
1318
+ // TODO: is this ConcurrentMode friendly?
1299
1319
  var _a;
1300
- var nextBiggerIndex = (_a = ALL_SIZES.findIndex(function (w) { return w >= width; })) !== null && _a !== void 0 ? _a : ALL_SIZES.length - 1;
1301
- var nextBigger = ALL_SIZES[nextBiggerIndex];
1302
- if (nextBigger >= fullWidth) {
1303
- // If the requested width is larger than the fullWidth,
1304
- // we just use the original width instead. It's impossible
1305
- // to make an image bigger than fullWidth!
1306
- return undefined;
1307
- }
1308
- else if (nextBiggerIndex + 1 < ALL_SIZES.length &&
1309
- fullWidth <= ALL_SIZES[nextBiggerIndex + 1]) {
1310
- // If the fullWidth is just between nextBigger and the one after that,
1311
- // then also might as well just use the original size (so, width is 30,
1312
- // nextBigger is 32, then we just use the original as long as fullWidth is
1313
- // less than 48)
1314
- return undefined;
1315
- }
1316
- return nextBigger;
1317
- }
1318
- /**
1319
- * Computes the appropriate srcSet and sizes to use
1320
- */
1321
- function getWidths(width, fullWidth, extra) {
1322
- var minWidth = extra === null || extra === void 0 ? void 0 : extra.minWidth;
1323
- var pixelWidth = getPixelLength(width);
1324
- var pixelMinWidth = getPixelLength(minWidth);
1325
- if (pixelWidth != null && (!minWidth || pixelMinWidth != null)) {
1326
- // If there's an exact width, then we just need to display it at 1x and 2x density
1327
- return {
1328
- widthDescs: [
1329
- {
1330
- width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth !== null && pixelMinWidth !== void 0 ? pixelMinWidth : 0), fullWidth),
1331
- desc: "1x",
1332
- },
1333
- {
1334
- width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth !== null && pixelMinWidth !== void 0 ? pixelMinWidth : 0) * 2, fullWidth),
1335
- desc: "2x",
1336
- },
1337
- ],
1338
- sizes: undefined,
1339
- };
1340
- }
1341
- // Otherwise we don't know what sizes we'll end up, so we just cap it at
1342
- // device width. TODO: do better!
1343
- var usefulSizes = DEVICE_SIZES.filter(function (size) { return !fullWidth || size < fullWidth; });
1344
- if (!!fullWidth && usefulSizes.length === 0) {
1345
- // image fullWidth is smaller than all device sizes. So all we can do
1346
- // is offer 1x
1347
- return {
1348
- widthDescs: [
1349
- {
1350
- width: getClosestPresetSize(fullWidth, fullWidth),
1351
- desc: "1x",
1352
- },
1353
- ],
1354
- sizes: undefined,
1355
- };
1356
- }
1357
- return {
1358
- widthDescs: usefulSizes.map(function (size) { return ({
1359
- width: getClosestPresetSize(size, fullWidth),
1360
- // If this is the last (buggest) useful width, but it is
1361
- // still within the bounds set by DEVICE_SIZES, then just
1362
- // use the original, unresized image. This means if we match
1363
- // the largest size, we use unresized and best quality image.
1364
- // We only do this, though, if fullWidth is "reasonable" --
1365
- // smaller than the largest size we would consider.
1366
- // i === usefulSizes.length - 1 &&
1367
- // fullWidth < DEVICE_SIZES[DEVICE_SIZES.length - 1]
1368
- // ? undefined
1369
- // : size,
1370
- desc: "".concat(size, "w"),
1371
- }); }),
1372
- sizes: "100vw",
1373
- };
1374
- }
1375
- function getPixelLength(length) {
1376
- if (length == null || length == "") {
1377
- return undefined;
1378
- }
1379
- if (typeof length === "number") {
1380
- return length;
1381
- }
1382
- var parsed = parseNumeric(length);
1383
- if (parsed && (!parsed.units || parsed.units === "px")) {
1384
- return parsed.num;
1385
- }
1386
- return undefined;
1387
- }
1388
- function parseNumeric(val) {
1389
- // Parse strings like "30", "30px", "30%", "30px /* blah blah */"
1390
- var res = val.match(/^\s*(-?(?:\d+\.\d*|\d*\.\d+|\d+))\s*([a-z]*|%)\s*(?:\/\*.*)?$/i);
1391
- if (res == null) {
1392
- return undefined;
1320
+ var children = [];
1321
+ for (var _i = 2; _i < arguments.length; _i++) {
1322
+ children[_i - 2] = arguments[_i];
1393
1323
  }
1394
- var num = res[1];
1395
- var units = res[2];
1396
- return { num: +num, units: units };
1397
- }
1398
- function getImageSizeData(width, height) {
1399
- var aspectRatio = width && height ? width / height : undefined;
1400
- return {
1401
- fullWidth: width,
1402
- fullHeight: height,
1403
- aspectRatio: aspectRatio && isFinite(aspectRatio) ? aspectRatio : undefined,
1404
- };
1405
- }
1406
- function getImageLoader(loader) {
1407
- if (loader == null) {
1408
- return undefined;
1324
+ if (props == null) {
1325
+ props = {};
1409
1326
  }
1410
- else if (loader === "plasmic") {
1411
- return PLASMIC_IMAGE_LOADER;
1327
+ var name = props["data-plasmic-name"];
1328
+ var isRoot = props["data-plasmic-root"];
1329
+ var forNodeName = props["data-plasmic-for-node"];
1330
+ delete props["data-plasmic-name"];
1331
+ delete props["data-plasmic-root"];
1332
+ delete props["data-plasmic-for-node"];
1333
+ var element = createPlasmicElementFromJsx.apply(void 0, __spreadArray([defaultElement,
1334
+ props], __read(children), false));
1335
+ if (name) {
1336
+ seenElements.set(name, element);
1412
1337
  }
1413
- else {
1414
- return loader;
1338
+ if (isRoot) {
1339
+ // If this is the root, and we requested a specific node by specifying data-plasmic-for-node,
1340
+ // then return that node instead
1341
+ var forNode = forNodeName
1342
+ ? (_a = seenElements.get(forNodeName)) !== null && _a !== void 0 ? _a : null
1343
+ : element;
1344
+ // Clear out the seenElements map, as we're done rendering this Plasmic* component.
1345
+ seenElements.clear();
1346
+ return forNode;
1415
1347
  }
1348
+ return element;
1416
1349
  }
1417
- function isInternalKey(src) {
1418
- return /^([a-f0-9]{32})\..{1,16}$/i.test(src);
1419
- }
1420
- var PLASMIC_IMAGE_LOADER = {
1421
- supportsUrl: function (src) {
1422
- return (src.startsWith("http") || isInternalKey(src)) && !isSvg(src);
1423
- },
1424
- transformUrl: function (opts) {
1425
- var _a;
1426
- var params = [
1427
- "src=".concat(encodeURIComponent(opts.src)),
1428
- opts.width ? "w=".concat(opts.width) : undefined,
1429
- "q=".concat((_a = opts.quality) !== null && _a !== void 0 ? _a : 75),
1430
- opts.format ? "f=".concat(opts.format) : undefined,
1431
- ].filter(function (x) { return !!x; });
1432
- return "".concat(IMG_OPTIMIZER_HOST, "/img-optimizer/v1/img?").concat(params.join("&"));
1433
- },
1434
- };
1435
-
1436
- var PlasmicLink = React__default.forwardRef(function PlasmicLink(props, ref) {
1350
+ function createPlasmicElementFromJsx(defaultElement, props) {
1437
1351
  var _a;
1438
- // The usePlasmicLinkMaybe function may be undefined, if host is not up-to-date
1439
- var Link = (_a = usePlasmicLinkMaybe === null || usePlasmicLinkMaybe === void 0 ? void 0 : usePlasmicLinkMaybe()) !== null && _a !== void 0 ? _a : PlasmicLinkInternal;
1440
- if (Link === PlasmicLink || Link === PlasmicLinkInternal) {
1441
- // Just in case, break the cycle
1442
- return React__default.createElement(PlasmicLinkInternal, __assign({}, props, { ref: ref }));
1352
+ var children = [];
1353
+ for (var _i = 2; _i < arguments.length; _i++) {
1354
+ children[_i - 2] = arguments[_i];
1443
1355
  }
1444
- else {
1445
- // Don't pass component/platform props to non-PlasmicLinkInternal
1446
- return React__default.createElement(Link, __assign({}, omit(props, "component", "platform"), { ref: ref }));
1356
+ var override = props["data-plasmic-override"];
1357
+ var wrapFlexChild = props["data-plasmic-wrap-flex-child"];
1358
+ var triggerProps = ((_a = props["data-plasmic-trigger-props"]) !== null && _a !== void 0 ? _a : []);
1359
+ delete props["data-plasmic-override"];
1360
+ delete props["data-plasmic-wrap-flex-child"];
1361
+ delete props["data-plasmic-trigger-props"];
1362
+ return createPlasmicElement(override, defaultElement, mergeProps.apply(void 0, __spreadArray([props,
1363
+ children.length === 0
1364
+ ? {}
1365
+ : { children: children.length === 1 ? children[0] : children }], __read(triggerProps), false)), wrapFlexChild);
1366
+ }
1367
+ function makeFragment() {
1368
+ var children = [];
1369
+ for (var _i = 0; _i < arguments.length; _i++) {
1370
+ children[_i] = arguments[_i];
1447
1371
  }
1448
- });
1449
- var PlasmicLinkInternal = React__default.forwardRef(function PlasmicLinkInternal(props, ref) {
1450
- var _a;
1451
- // props.href is required for nextjs; if no props.href,
1452
- // then we just render the default anchor element
1453
- if (props.platform === "nextjs" && props.href) {
1454
- var nextjsProps = [
1455
- "href",
1456
- "replace",
1457
- "scroll",
1458
- "shallow",
1459
- "passHref",
1460
- "prefetch",
1461
- "locale",
1462
- ];
1463
- // If this is a fragment identifier link, then we set
1464
- // scroll={false} so that smooth scrolling works
1465
- var isFragment = (_a = props.href) === null || _a === void 0 ? void 0 : _a.startsWith("#");
1466
- return React__default.createElement(props.component, __assign(__assign({ scroll: !isFragment }, pick.apply(void 0, __spreadArray([props], __read(nextjsProps), false))), { legacyBehavior: true }), React__default.createElement("a", __assign({}, omit.apply(void 0, __spreadArray([props, "component", "platform"], __read(nextjsProps), false)), { ref: ref })));
1372
+ return React.createElement.apply(React, __spreadArray([React.Fragment, {}], __read(children), false));
1373
+ }
1374
+ var UNSET = Symbol("UNSET");
1375
+ function mergeOverrideProps(defaults, overrides) {
1376
+ var e_1, _a;
1377
+ if (!overrides) {
1378
+ return defaults;
1467
1379
  }
1468
- if (props.platform === "gatsby" && isInternalHref(props.href)) {
1469
- return React__default.createElement(props.component, __assign(__assign({}, omit(props, "component", "platform", "href")), { to: props.href, ref: ref }));
1380
+ var result = __assign({}, defaults);
1381
+ try {
1382
+ for (var _b = __values(Object.keys(overrides)), _c = _b.next(); !_c.done; _c = _b.next()) {
1383
+ var key = _c.value;
1384
+ var defaultVal = defaults[key];
1385
+ var overrideVal = overrides[key];
1386
+ if (overrideVal === UNSET) {
1387
+ delete result[key];
1388
+ }
1389
+ else {
1390
+ // We use the NONE sentinel if the overrideVal is nil, and is not one of the
1391
+ // props that we merge by default -- which are className, style, and
1392
+ // event handlers. This means for all other "normal" props -- like children,
1393
+ // title, etc -- a nil value will unset the default.
1394
+ if (overrideVal == null &&
1395
+ key !== "className" &&
1396
+ key !== "style" &&
1397
+ !(key.startsWith("on") && typeof defaultVal === "function")) {
1398
+ overrideVal = NONE;
1399
+ }
1400
+ result[key] = mergePropVals(key, defaultVal, overrideVal);
1401
+ }
1402
+ }
1470
1403
  }
1471
- if (props.platform === "tanstack" && isInternalHref(props.href)) {
1472
- return React__default.createElement(props.component, __assign(__assign({}, omit(props, "component", "platform", "href")), { to: props.href, ref: ref }));
1404
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1405
+ finally {
1406
+ try {
1407
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1408
+ }
1409
+ finally { if (e_1) throw e_1.error; }
1473
1410
  }
1474
- return React__default.createElement("a", __assign({}, omit(props, "component", "platform"), { ref: ref }));
1475
- });
1476
- function isInternalHref(href) {
1477
- return /^\/(?!\/)/.test(href);
1411
+ return result;
1478
1412
  }
1479
-
1480
- // Make the refactor to host backwards compatible for loader
1481
- var PlasmicTranslatorContext = PlasmicTranslatorContext$1 !== null && PlasmicTranslatorContext$1 !== void 0 ? PlasmicTranslatorContext$1 : React__default.createContext(undefined);
1482
- var usePlasmicTranslator = usePlasmicTranslator$1 !== null && usePlasmicTranslator$1 !== void 0 ? usePlasmicTranslator$1 : (function () {
1483
- var _t = React__default.useContext(PlasmicTranslatorContext);
1484
- var translator = _t
1485
- ? typeof _t === "function"
1486
- ? _t
1487
- : _t.translator
1413
+ function wrapWithClassName(element, className) {
1414
+ var key = React.isValidElement(element)
1415
+ ? element.key || undefined
1488
1416
  : undefined;
1489
- return translator;
1490
- });
1491
- function genTranslatableString(elt, opts) {
1492
- var components = {};
1493
- var componentsCount = 0;
1494
- var getText = function (node) {
1495
- var _a;
1496
- if (!node) {
1497
- return "";
1498
- }
1499
- if (typeof node === "number" ||
1500
- typeof node === "boolean" ||
1501
- typeof node === "string") {
1502
- return node.toString();
1503
- }
1504
- if (typeof node !== "object") {
1505
- return "";
1506
- }
1507
- if (Array.isArray(node) || isIterable(node)) {
1508
- return Array.from(node)
1509
- .map(function (child) { return getText(child); })
1510
- .filter(function (child) { return !!child; })
1511
- .join("");
1512
- }
1513
- var nodeChildren = (hasKey(node, "props") &&
1514
- hasKey(node.props, "children") &&
1515
- node.props.children) ||
1516
- (hasKey(node, "children") && node.children) ||
1517
- [];
1518
- var contents = "".concat(React__default.Children.toArray(nodeChildren)
1519
- .map(function (child) { return getText(child); })
1520
- .filter(function (child) { return !!child; })
1521
- .join(""));
1522
- if (React__default.isValidElement(node) && node.type === React__default.Fragment) {
1523
- return contents;
1524
- }
1525
- var prefix = (_a = opts === null || opts === void 0 ? void 0 : opts.tagPrefix) !== null && _a !== void 0 ? _a : "";
1526
- var componentId = "".concat(prefix).concat(componentsCount + 1);
1527
- componentsCount++;
1528
- components[componentId] = React__default.isValidElement(node)
1529
- ? React__default.cloneElement(node, {
1530
- key: componentId,
1531
- children: undefined,
1532
- })
1533
- : node;
1534
- return "<".concat(componentId, ">").concat(contents, "</").concat(componentId, ">");
1535
- };
1536
- var str = getText(elt);
1537
- return {
1538
- str: str,
1539
- components: components,
1540
- componentsCount: componentsCount,
1541
- };
1417
+ return React.createElement("div", {
1418
+ key: key,
1419
+ className: className,
1420
+ style: {
1421
+ display: "grid",
1422
+ },
1423
+ }, element);
1542
1424
  }
1543
- function Trans(_a) {
1544
- var transKey = _a.transKey, children = _a.children;
1545
- var _t = React__default.useContext(PlasmicTranslatorContext);
1546
- var translator = _t
1547
- ? typeof _t === "function"
1548
- ? _t
1549
- : _t.translator
1550
- : undefined;
1551
- if (!translator) {
1552
- warnNoTranslationFunctionAtMostOnce();
1553
- return children;
1425
+ function deriveOverride(x) {
1426
+ if (!x) {
1427
+ // undefined Binding is an empty Binding
1428
+ return {
1429
+ type: "default",
1430
+ props: {},
1431
+ };
1432
+ }
1433
+ else if (isReactNode(x)) {
1434
+ // If ReactNode, then assume this is the children
1435
+ return {
1436
+ type: "default",
1437
+ props: {
1438
+ children: x,
1439
+ },
1440
+ };
1441
+ }
1442
+ else if (typeof x === "object") {
1443
+ // If any of the overrideKeys is a key of this object, then assume
1444
+ // this is a full Override
1445
+ if ("as" in x) {
1446
+ return __assign(__assign({}, x), { props: x.props || {}, type: "as" });
1447
+ }
1448
+ else if ("render" in x) {
1449
+ return __assign(__assign({}, x), { type: "render" });
1450
+ }
1451
+ else if ("props" in x) {
1452
+ return __assign(__assign({}, x), { props: x.props || {}, type: "default" });
1453
+ }
1454
+ else if (isSubset(Object.keys(x), ["wrap", "wrapChildren"])) {
1455
+ // Only twiddling functions present, so assume no props overrides
1456
+ // (otherwise we'd assume these were props).
1457
+ return __assign(__assign({}, x), { props: {}, type: "default" });
1458
+ }
1459
+ // Else, assume this is just a props object.
1460
+ return {
1461
+ type: "default",
1462
+ props: x,
1463
+ };
1554
1464
  }
1555
- var _b = genTranslatableString(children, {
1556
- tagPrefix: typeof _t === "object" ? _t.tagPrefix : undefined,
1557
- }), str = _b.str, components = _b.components, componentsCount = _b.componentsCount;
1558
- return translator(transKey !== null && transKey !== void 0 ? transKey : str, componentsCount > 0 ? { components: components } : undefined);
1559
- }
1560
- var hasWarned = false;
1561
- function warnNoTranslationFunctionAtMostOnce() {
1562
- if (!hasWarned) {
1563
- console.warn("Using Plasmic Translation but no translation function has been provided");
1564
- hasWarned = true;
1465
+ else if (typeof x === "function") {
1466
+ return {
1467
+ type: "render",
1468
+ render: x,
1469
+ };
1565
1470
  }
1471
+ throw new Error("Unexpected override: ".concat(x));
1566
1472
  }
1567
- function hasKey(v, key) {
1568
- return typeof v === "object" && v !== null && key in v;
1473
+ function mergeVariants(v1, v2) {
1474
+ if (!v1 || !v2) {
1475
+ return v1 || v2 || {};
1476
+ }
1477
+ return __assign(__assign({}, v1), v2);
1569
1478
  }
1570
- function isIterable(val) {
1571
- return val != null && typeof val[Symbol.iterator] === "function";
1479
+ function mergeVariantsWithStates(variants, $state, linkedStates) {
1480
+ return __assign(__assign({}, variants), Object.fromEntries(linkedStates.map(function (_a) {
1481
+ var variantGroup = _a.variantGroup, statePath = _a.statePath;
1482
+ return [
1483
+ variantGroup,
1484
+ get($state, statePath),
1485
+ ];
1486
+ })));
1572
1487
  }
1573
-
1574
- function PlasmicSlot(props) {
1575
- return renderPlasmicSlot(props);
1488
+ function mergeArgs(a1, a2) {
1489
+ if (!a1 || !a2) {
1490
+ return a1 || a2 || {};
1491
+ }
1492
+ return __assign(__assign({}, a1), a2);
1576
1493
  }
1577
- function renderPlasmicSlot(opts) {
1578
- var as = opts.as, defaultContents = opts.defaultContents, value = opts.value, rest = __rest(opts, ["as", "defaultContents", "value"]);
1579
- var content = value === undefined ? defaultContents : value;
1580
- if (typeof content !== "number" &&
1581
- (!content || (Array.isArray(content) && content.length === 0))) {
1582
- return null;
1494
+ function mergeFlexOverrides(o1, o2) {
1495
+ var e_2, _a;
1496
+ if (!o2) {
1497
+ return o1;
1583
1498
  }
1584
- // If the content is a raw string, then we need to wrap the raw string
1585
- // into an element, in case the slot is inside a flex-gap
1586
- // container (you cannot apply margin to just a text node).
1587
- var maybeString = maybeAsString(content);
1588
- if (maybeString) {
1589
- content = (React.createElement("span", { className: "__wab_slot-string-wrapper \u03C1sw" }, maybeString));
1499
+ var keys = Array.from(new Set(__spreadArray(__spreadArray([], __read(Object.keys(o1)), false), __read(Object.keys(o2)), false)));
1500
+ var merged = {};
1501
+ try {
1502
+ for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
1503
+ var key = keys_1_1.value;
1504
+ merged[key] = mergeFlexOverride(o1[key], o2[key]);
1505
+ }
1590
1506
  }
1591
- var nonEmptyProps = Object.keys(rest).filter(function (p) { return !!rest[p]; });
1592
- if (nonEmptyProps.length === 0) {
1593
- // No attrs to apply to the slot (which means the slot is unstyled), then
1594
- // just render the content directly; no need for style wrapper.
1595
- return content;
1507
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1508
+ finally {
1509
+ try {
1510
+ if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
1511
+ }
1512
+ finally { if (e_2) throw e_2.error; }
1596
1513
  }
1597
- return React.createElement(as || "span", mergeProps({ className: "__wab_slot ρs" }, rest), content);
1514
+ return merged;
1598
1515
  }
1599
- function maybeAsString(node) {
1600
- // Unwrap fragments
1601
- if (React.isValidElement(node)) {
1602
- // Fragment doesn't render DOM elements
1603
- if (node.type === React.Fragment) {
1604
- return maybeAsString(node.props.children);
1605
- }
1606
- else if (node.type === Trans) {
1607
- // Trans also doesn't render DOM elements. But we don't want to just render
1608
- // its content string, because we want to keep the <Trans/> for the localization.
1609
- // So we render the same node, to be wrapped into __wab_slot-string-wrapper.
1610
- return node;
1611
- }
1516
+ function mergeFlexOverride(fo1, fo2) {
1517
+ var _a, _b;
1518
+ if (!fo1) {
1519
+ return fo2;
1612
1520
  }
1613
- if (typeof node === "string") {
1614
- return node;
1521
+ if (!fo2) {
1522
+ return fo1;
1615
1523
  }
1616
- if (typeof node === "number") {
1617
- return "".concat(node);
1524
+ var o1 = deriveOverride(fo1);
1525
+ var o2 = deriveOverride(fo2);
1526
+ var wrap = chainSingleArgFuncs.apply(void 0, __spreadArray([], __read([o1.wrap, o2.wrap].filter(notNil)), false));
1527
+ var wrapChildren = chainSingleArgFuncs.apply(void 0, __spreadArray([], __read([o1.wrapChildren, o2.wrapChildren].filter(notNil)), false));
1528
+ // "render" type always takes precedence, but we still merge the props
1529
+ var props = mergeOverrideProps((_a = o1.props) !== null && _a !== void 0 ? _a : {}, o2.props);
1530
+ if (o2.type === "render") {
1531
+ return {
1532
+ render: o2.render,
1533
+ props: props,
1534
+ wrap: wrap,
1535
+ wrapChildren: wrapChildren,
1536
+ };
1618
1537
  }
1619
- if (Array.isArray(node) && node.length === 1 && typeof node[0] === "string") {
1620
- return node[0];
1538
+ if (o1.type === "render") {
1539
+ return {
1540
+ render: o1.render,
1541
+ props: props,
1542
+ wrap: wrap,
1543
+ wrapChildren: wrapChildren,
1544
+ };
1621
1545
  }
1622
- return undefined;
1546
+ // "as" will take precedence
1547
+ var as = (_b = (o2.type === "as" ? o2.as : undefined)) !== null && _b !== void 0 ? _b : (o1.type === "as" ? o1.as : undefined);
1548
+ return __assign({ props: props, wrap: wrap, wrapChildren: wrapChildren }, (as ? { as: as } : {}));
1549
+ }
1550
+ function deriveRenderOpts(props, config) {
1551
+ var _a;
1552
+ var name = config.name, descendantNames = config.descendantNames, internalVariantPropNames = config.internalVariantPropNames, internalArgPropNames = config.internalArgPropNames;
1553
+ var reservedPropNames = ["variants", "args", "overrides"];
1554
+ var variants = mergeVariants(omit.apply(void 0, __spreadArray([pick.apply(void 0, __spreadArray([props], __read(internalVariantPropNames), false))], __read(reservedPropNames), false)), props.variants);
1555
+ var args = mergeArgs(omit.apply(void 0, __spreadArray([pick.apply(void 0, __spreadArray([props], __read(internalArgPropNames), false))], __read(reservedPropNames), false)), props.args);
1556
+ var overrides = mergeFlexOverrides(omit.apply(void 0, __spreadArray(__spreadArray(__spreadArray([pick.apply(void 0, __spreadArray([props], __read(descendantNames), false))], __read(internalArgPropNames), false), __read(internalVariantPropNames), false), __read(reservedPropNames), false)), props.overrides);
1557
+ var leftoverProps = omit.apply(void 0, __spreadArray(__spreadArray(__spreadArray([props,
1558
+ "variants",
1559
+ "args",
1560
+ "overrides"], __read(descendantNames), false), __read(internalVariantPropNames), false), __read(internalArgPropNames), false));
1561
+ if (Object.keys(leftoverProps).length > 0) {
1562
+ overrides = mergeFlexOverrides(overrides, (_a = {},
1563
+ _a[name] = {
1564
+ props: leftoverProps,
1565
+ },
1566
+ _a));
1567
+ }
1568
+ return { variants: variants, args: args, overrides: overrides };
1569
+ }
1570
+
1571
+ function renderStack(as, props, hasGap, ref) {
1572
+ var children = props.children, rest = __rest(props, ["children"]);
1573
+ var wrappedChildren = wrapFlexContainerChildren(children, hasGap !== null && hasGap !== void 0 ? hasGap : false);
1574
+ return createElementWithChildren(as, __assign({ ref: ref }, rest), wrappedChildren);
1575
+ }
1576
+ function FlexStack_(props, outerRef) {
1577
+ var as = props.as, hasGap = props.hasGap, rest = __rest(props, ["as", "hasGap"]);
1578
+ return renderStack(as !== null && as !== void 0 ? as : "div", rest, hasGap, outerRef);
1579
+ }
1580
+ var FlexStack = React.forwardRef(FlexStack_);
1581
+ var makeStackImpl = function (as) {
1582
+ return React.forwardRef(function (props, ref) {
1583
+ var hasGap = props.hasGap, rest = __rest(props, ["hasGap"]);
1584
+ return renderStack(as, rest, hasGap, ref);
1585
+ });
1586
+ };
1587
+ var Stack = Object.assign(FlexStack, {
1588
+ div: makeStackImpl("div"),
1589
+ a: makeStackImpl("a"),
1590
+ button: makeStackImpl("button"),
1591
+ h1: makeStackImpl("h1"),
1592
+ h2: makeStackImpl("h2"),
1593
+ h3: makeStackImpl("h3"),
1594
+ h4: makeStackImpl("h4"),
1595
+ h5: makeStackImpl("h5"),
1596
+ h6: makeStackImpl("h6"),
1597
+ label: makeStackImpl("label"),
1598
+ form: makeStackImpl("form"),
1599
+ section: makeStackImpl("section"),
1600
+ head: makeStackImpl("head"),
1601
+ main: makeStackImpl("main"),
1602
+ nav: makeStackImpl("nav"),
1603
+ });
1604
+
1605
+ var isDefaultValue = function (val) {
1606
+ return val === "PLEASE_RENDER_INSIDE_PROVIDER";
1607
+ };
1608
+ var seenDefaultVariants = {};
1609
+ /**
1610
+ * Usage:
1611
+ * ```
1612
+ * // plasmic.ts
1613
+ * import { usePlatform } from "./PlasmicGlobalVariant__Platform";
1614
+ * import { useTheme } from "./PlasmicGlobalVariant__Theme";
1615
+ *
1616
+ * export const useGlobalVariants = createUseGlobalVariants({
1617
+ * platform: usePlatform,
1618
+ * theme: useTheme,
1619
+ * });
1620
+ *
1621
+ * // PlasmicComponent.tsx
1622
+ * import { useGlobalVariants } from "./plasmic_project";
1623
+ *
1624
+ * export function PlasmicComponent() {
1625
+ * // ...
1626
+ * const globalVariants = useGlobalVariants();
1627
+ * // ...
1628
+ * }
1629
+ * ```
1630
+ */
1631
+ function createUseGlobalVariants(globalVariantHooks) {
1632
+ return function () {
1633
+ return ensureGlobalVariants(Object.fromEntries(Object.entries(globalVariantHooks).map(function (_a) {
1634
+ var _b = __read(_a, 2), globalVariant = _b[0], useHook = _b[1];
1635
+ return [globalVariant, useHook()];
1636
+ })));
1637
+ };
1638
+ }
1639
+ /**
1640
+ * @deprecated - new generated code should use `useGlobalVariants` instead
1641
+ *
1642
+ * Usage:
1643
+ * ```
1644
+ * // PlasmicComponent.tsx
1645
+ * import { useTheme } from "./PlasmicGlobalVariant__Theme";
1646
+ * import { usePlatform } from "./PlasmicGlobalVariant__Platform";
1647
+ *
1648
+ * export function PlasmicComponent() {
1649
+ * // ...
1650
+ * const globalVariants = ensureGlobalVariants({
1651
+ * platform: usePlatform(),
1652
+ * theme: useTheme(),
1653
+ * });
1654
+ * // ...
1655
+ * }
1656
+ * ```
1657
+ */
1658
+ function ensureGlobalVariants(globalVariants) {
1659
+ Object.entries(globalVariants)
1660
+ .filter(function (_a) {
1661
+ var _b = __read(_a, 2); _b[0]; var value = _b[1];
1662
+ return isDefaultValue(value);
1663
+ })
1664
+ .forEach(function (_a) {
1665
+ var _b = __read(_a, 2), key = _b[0]; _b[1];
1666
+ globalVariants[key] = undefined;
1667
+ if (!seenDefaultVariants[key] && process.env.NODE_ENV === "development") {
1668
+ seenDefaultVariants[key] = true;
1669
+ var providerName = "".concat(key[0].toUpperCase()).concat(key.substring(1), "Context.Provider");
1670
+ console.warn("Plasmic context value for global variant \"".concat(key, "\" was not provided; please use ").concat(providerName, " at the root of your React app. Learn More: https://www.plasmic.app/learn/other-assets/#global-variants"));
1671
+ }
1672
+ });
1673
+ return globalVariants;
1623
1674
  }
1624
1675
 
1625
1676
  var listeners = [];
@@ -1765,6 +1816,115 @@ function MaybeWrap(props) {
1765
1816
  return props.cond ? props.wrapper(props.children) : props.children;
1766
1817
  }
1767
1818
 
1819
+ /**
1820
+ * Context that enables a project's style tokens to be propagated across projects.
1821
+ *
1822
+ * The value is an array of class names, including the class name for the base
1823
+ * variant and active global variants. The class names should be applied to all
1824
+ * Plasmic content.
1825
+ */
1826
+ var StyleTokensContext = React__default.createContext(undefined);
1827
+ /**
1828
+ * Returns style tokens. If the context is not available, falls back to the
1829
+ * current project's styles.
1830
+ *
1831
+ * Usage:
1832
+ * ```
1833
+ * // PlasmicStyleTokensProvider.ts
1834
+ * export const useStyleTokens = createUseStyleTokens(
1835
+ * projectStyleTokenData,
1836
+ * useGlobalVariants,
1837
+ * );
1838
+ *
1839
+ * // PlasmicPage.tsx
1840
+ * import { useStyleTokens } from "./plasmic_project";
1841
+ *
1842
+ * export function PlasmicPage() {
1843
+ * const styleTokensClassNames = useStyleTokens();
1844
+ * return (
1845
+ * <div className={classNames(
1846
+ * projectcss.all,
1847
+ * projectcss.root_reset,
1848
+ * projectcss.plasmic_default_styles,
1849
+ * projectcss.plasmic_mixins,
1850
+ * styleTokensClassNames,
1851
+ * )}>
1852
+ * <h1 className={projectcss.all}>
1853
+ * Hello, world!
1854
+ * </h1>
1855
+ * </div>
1856
+ * );
1857
+ * }
1858
+ * ```
1859
+ */
1860
+ function createUseStyleTokens(tokenData, useGlobalVariants) {
1861
+ return function () {
1862
+ var overrides = React__default.useContext(StyleTokensContext);
1863
+ var globalVariants = useGlobalVariants();
1864
+ return React__default.useMemo(function () {
1865
+ if (overrides && overrides.length > 0) {
1866
+ return overrides;
1867
+ }
1868
+ else {
1869
+ return activeTokensClassNames(tokenData, globalVariants);
1870
+ }
1871
+ }, [overrides, globalVariants, tokenData]);
1872
+ };
1873
+ }
1874
+ /**
1875
+ * Creates a StyleTokens context provider for a given project, which includes
1876
+ * its tokens, overrides, and all tokens from its dependencies.
1877
+ *
1878
+ * Usage:
1879
+ * ```
1880
+ * // PlasmicStyleTokensProvider.ts
1881
+ * export const StyleTokensProvider = createStyleTokensProvider(
1882
+ * projectStyleTokenData,
1883
+ * useGlobalVariants,
1884
+ * );
1885
+ *
1886
+ * // Page.tsx
1887
+ * import { StyleTokensProvider } from "./plasmic_project";
1888
+ *
1889
+ * export default function Page() {
1890
+ * return (
1891
+ * <PlatformContext.Provider value="osx">
1892
+ * <ThemeContext.Provider value="dark">
1893
+ * <StyleTokensProvider>
1894
+ * <PlasmicPage />
1895
+ * </StyleTokensProvider>
1896
+ * </ThemeContext.Provider>
1897
+ * </PlatformContext.Provider>
1898
+ * );
1899
+ * }
1900
+ * ```
1901
+ */
1902
+ function createStyleTokensProvider(tokenData, useGlobalVariants) {
1903
+ return function (props) {
1904
+ var globalVariants = useGlobalVariants();
1905
+ var tokens = React__default.useMemo(function () {
1906
+ return activeTokensClassNames(tokenData, globalVariants);
1907
+ }, [globalVariants, tokenData]);
1908
+ return (React__default.createElement(StyleTokensContext.Provider, { value: tokens }, props.children));
1909
+ };
1910
+ }
1911
+ /**
1912
+ * Gets the class names for the base tokens and the varianted tokens for active
1913
+ * global variants.
1914
+ */
1915
+ function activeTokensClassNames(tokenData, globalVariants) {
1916
+ var varianted = tokenData.varianted
1917
+ .filter(function (_a) {
1918
+ var groupName = _a.groupName, variant = _a.variant;
1919
+ return hasVariant(globalVariants, groupName, variant);
1920
+ })
1921
+ .map(function (_a) {
1922
+ var className = _a.className;
1923
+ return className;
1924
+ });
1925
+ return __spreadArray([tokenData.base], __read(varianted), false);
1926
+ }
1927
+
1768
1928
  function useFocused(opts) {
1769
1929
  var _a = useFocusRing({
1770
1930
  within: false,
@@ -4077,5 +4237,5 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissabl
4077
4237
  };
4078
4238
  }
4079
4239
 
4080
- export { DropdownMenu, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicPageGuard, PlasmicRootProvider, PlasmicSlot, SelectContext, Stack, Trans, TriggeredOverlayContext, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateOnMutateForSpec, generateStateOnChangeProp, generateStateOnChangePropForCodeComponents, generateStateValueProp, getCurrentInitialValue, getDataProps, getStateCellsInPlasmicProxy, getStateSpecInPlasmicProxy, hasVariant, initializeCodeComponentStates, initializePlasmicStates, is$StateProxy, isPlasmicStateProxy, makeFragment, mergeVariantsWithStates, omit, pick, plasmicHeadMeta, renderPlasmicSlot, resetToInitialValue, set, setPlumeStrictMode, useButton, useCheckbox, useDollarState, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, usePlasmicTranslator, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, withPlasmicPageGuard, wrapWithClassName };
4240
+ export { DropdownMenu, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicPageGuard, PlasmicRootProvider, PlasmicSlot, SelectContext, Stack, Trans, TriggeredOverlayContext, classNames, createPlasmicElementProxy, createStyleTokensProvider, createUseGlobalVariants, createUseScreenVariants, createUseStyleTokens, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateOnMutateForSpec, generateStateOnChangeProp, generateStateOnChangePropForCodeComponents, generateStateValueProp, getCurrentInitialValue, getDataProps, getStateCellsInPlasmicProxy, getStateSpecInPlasmicProxy, hasVariant, initializeCodeComponentStates, initializePlasmicStates, is$StateProxy, isPlasmicStateProxy, makeFragment, mergeVariantsWithStates, omit, pick, plasmicHeadMeta, renderPlasmicSlot, resetToInitialValue, set, setPlumeStrictMode, useButton, useCheckbox, useDollarState, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, usePlasmicTranslator, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, withPlasmicPageGuard, wrapWithClassName };
4081
4241
  //# sourceMappingURL=react-web.esm.js.map