@plitzi/sdk-shared 0.33.2 → 0.34.0
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.
- package/CHANGELOG.md +58 -0
- package/dist/actions/cron.d.ts +34 -0
- package/dist/actions/cron.mjs +72 -0
- package/dist/actions/index.d.ts +6 -0
- package/dist/actions/index.mjs +5 -0
- package/dist/actions/triggerParams.d.ts +41 -0
- package/dist/actions/triggerParams.mjs +40 -0
- package/dist/actions/triggers.d.ts +29 -0
- package/dist/actions/triggers.mjs +4 -0
- package/dist/actions/validateDocument.d.ts +23 -0
- package/dist/actions/validateDocument.mjs +267 -0
- package/dist/auth/failureChannel.d.ts +9 -4
- package/dist/auth/failureChannel.mjs +3 -2
- package/dist/authoring/builder.d.ts +51 -0
- package/dist/authoring/builder.mjs +29 -0
- package/dist/authoring/declare.d.ts +64 -0
- package/dist/authoring/declare.mjs +4 -0
- package/dist/authoring/elementCallbacks.d.ts +13 -0
- package/dist/authoring/elementCallbacks.mjs +71 -0
- package/dist/authoring/index.d.ts +21 -0
- package/dist/authoring/index.mjs +6 -0
- package/dist/authoring/paramSpec.d.ts +51 -0
- package/dist/authoring/paramSpec.mjs +40 -0
- package/dist/authoring/spaceCallbacks.d.ts +10 -0
- package/dist/authoring/spaceCallbacks.mjs +51 -0
- package/dist/builder/contexts/BuilderContext.d.ts +2 -4
- package/dist/dataSource/getBindingsDetails.mjs +1 -1
- package/dist/dataSource/helpers/getSourceName.d.ts +1 -3
- package/dist/dataSource/helpers/getSourceName.mjs +1 -1
- package/dist/dataSource/index.d.ts +2 -0
- package/dist/dataSource/index.mjs +6 -5
- package/dist/dataSource/resolveVariables.d.ts +22 -0
- package/dist/dataSource/resolveVariables.mjs +16 -0
- package/dist/dataSource/utility/index.mjs +15 -13
- package/dist/dataSource/utility/not.d.ts +11 -0
- package/dist/dataSource/utility/not.mjs +15 -0
- package/dist/devTools/debugCookie.d.ts +16 -0
- package/dist/devTools/debugCookie.mjs +7 -0
- package/dist/devTools/index.d.ts +6 -2
- package/dist/devTools/index.mjs +4 -2
- package/dist/devTools/interactionLog.d.ts +14 -0
- package/dist/devTools/interactionLog.mjs +4 -0
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.mjs +11 -9
- package/dist/helpers/reducerOrigin.d.ts +15 -0
- package/dist/helpers/reducerOrigin.mjs +4 -0
- package/dist/helpers/ruleEvaluator.d.ts +14 -0
- package/dist/helpers/ruleEvaluator.mjs +5 -0
- package/dist/helpers/twigWrapper/AST.d.ts +12 -1
- package/dist/helpers/twigWrapper/AST.mjs +0 -0
- package/dist/helpers/twigWrapper/Evaluator/Evaluator.mjs +7 -0
- package/dist/helpers/twigWrapper/Parser/Cursor.d.ts +7 -0
- package/dist/helpers/twigWrapper/Parser/Cursor.mjs +5 -0
- package/dist/helpers/twigWrapper/Parser/ExpressionParser.mjs +46 -8
- package/dist/helpers/twigWrapper/Parser/types.mjs +0 -0
- package/dist/helpers/twigWrapper/charClass.d.ts +7 -0
- package/dist/helpers/twigWrapper/charClass.mjs +16 -12
- package/dist/helpers/twigWrapper/tokens/tokenPatterns.mjs +2 -2
- package/dist/helpers/utils.d.ts +0 -2
- package/dist/helpers/utils.mjs +16 -19
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.mjs +4 -3
- package/dist/hooks/useFontHead.d.ts +3 -0
- package/dist/hooks/useFontHead.mjs +23 -0
- package/dist/hooks/usePlitziServiceContext.d.ts +3 -2
- package/dist/index.mjs +61 -45
- package/dist/navigation/index.d.ts +1 -1
- package/dist/navigation/index.mjs +2 -2
- package/dist/navigation/routes.d.ts +8 -0
- package/dist/navigation/routes.mjs +39 -39
- package/dist/network/graphql/builder/Mutations/Segment/SegmentAddMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Segment/SegmentAddTemplateMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Segment/SegmentUpdateMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentAddElementMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentCloneElementMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentMoveElementMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentRemoveElementMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentRenameElementMutation.d.ts +3 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentRenameElementMutation.mjs +9 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentUpdateElementMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentUpdateElementsMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Space/SpaceAddElementMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Space/SpaceAddTemplateMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Space/SpaceCloneElementMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Space/SpaceMoveElementMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Space/SpaceRemoveElementMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Space/SpaceRenameElementMutation.d.ts +5 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceRenameElementMutation.mjs +9 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateElementMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateElementsMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateSchemaMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Space/actions/SpaceAddActionMutation.d.ts +8 -0
- package/dist/network/graphql/builder/Mutations/Space/actions/SpaceAddActionMutation.mjs +16 -0
- package/dist/network/graphql/builder/Mutations/Space/actions/SpaceRemoveActionMutation.d.ts +4 -0
- package/dist/network/graphql/builder/Mutations/Space/actions/SpaceRemoveActionMutation.mjs +16 -0
- package/dist/network/graphql/builder/Mutations/Space/actions/SpaceRunActionMutation.d.ts +4 -0
- package/dist/network/graphql/builder/Mutations/Space/actions/SpaceRunActionMutation.mjs +14 -0
- package/dist/network/graphql/builder/Mutations/Space/actions/SpaceUpdateActionMutation.d.ts +4 -0
- package/dist/network/graphql/builder/Mutations/Space/actions/SpaceUpdateActionMutation.mjs +16 -0
- package/dist/network/graphql/builder/Mutations/Space/pages/SpaceAddPageMutation.mjs +2 -3
- package/dist/network/graphql/builder/Mutations/Space/pages/SpaceUpdatePageMutation.mjs +0 -1
- package/dist/network/graphql/builder/Mutations/Style/fonts/StyleAddFontMutation.d.ts +2 -0
- package/dist/network/graphql/builder/Mutations/Style/fonts/StyleAddFontMutation.mjs +11 -0
- package/dist/network/graphql/builder/Mutations/Style/fonts/StyleRemoveFontMutation.d.ts +2 -0
- package/dist/network/graphql/builder/Mutations/Style/fonts/StyleRemoveFontMutation.mjs +11 -0
- package/dist/network/graphql/builder/Mutations/Style/fonts/StyleUpdateFontMutation.d.ts +2 -0
- package/dist/network/graphql/builder/Mutations/Style/fonts/StyleUpdateFontMutation.mjs +11 -0
- package/dist/network/graphql/builder/Mutations/index.d.ts +24 -0
- package/dist/network/graphql/builder/Mutations/index.mjs +150 -132
- package/dist/network/graphql/builder/Queries/InitQuery.mjs +1 -2
- package/dist/network/graphql/builder/Queries/Segment/SegmentQuery.mjs +0 -1
- package/dist/network/graphql/builder/Queries/Segment/SegmentsQuery.mjs +0 -1
- package/dist/network/graphql/builder/Queries/Space/SpaceActionEventsQuery.d.ts +9 -0
- package/dist/network/graphql/builder/Queries/Space/SpaceActionEventsQuery.mjs +30 -0
- package/dist/network/graphql/builder/Queries/Space/SpaceActionTasksQuery.d.ts +6 -0
- package/dist/network/graphql/builder/Queries/Space/SpaceActionTasksQuery.mjs +16 -0
- package/dist/network/graphql/builder/Queries/Space/SpaceActionsQuery.d.ts +9 -0
- package/dist/network/graphql/builder/Queries/Space/SpaceActionsQuery.mjs +25 -0
- package/dist/network/graphql/builder/Queries/Space/SpaceCheckActionQuery.d.ts +6 -0
- package/dist/network/graphql/builder/Queries/Space/SpaceCheckActionQuery.mjs +17 -0
- package/dist/network/graphql/builder/Queries/Space/SpaceQuotaQuery.d.ts +30 -0
- package/dist/network/graphql/builder/Queries/Space/SpaceQuotaQuery.mjs +40 -0
- package/dist/network/graphql/builder/Queries/index.d.ts +16 -0
- package/dist/network/graphql/builder/Queries/index.mjs +24 -14
- package/dist/network/graphql/sdk/Queries/InitQuery.d.ts +4 -0
- package/dist/network/graphql/sdk/Queries/InitQuery.mjs +5 -2
- package/dist/network/graphql/sdk/Queries/Segment/SegmentQuery.mjs +0 -1
- package/dist/network/graphql/sdk/Queries/Segment/SegmentsQuery.mjs +0 -1
- package/dist/network/spaceEvents.d.ts +20 -1
- package/dist/network/spaceEvents.mjs +89 -74
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.mjs +2 -1
- package/dist/schema/serverElements.d.ts +16 -0
- package/dist/schema/serverElements.mjs +18 -0
- package/dist/server/actions/useActionsSync.d.ts +10 -0
- package/dist/server/actions/useActionsSync.mjs +7 -0
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.mjs +5 -4
- package/dist/server/rsc/refreshRsc.d.ts +11 -1
- package/dist/server/rsc/refreshRsc.mjs +30 -12
- package/dist/server/rsc/useRscSync.mjs +20 -13
- package/dist/state/runtimeStatePersist.mjs +4 -3
- package/dist/store/actionRuns/actionRunsRecorder.d.ts +36 -0
- package/dist/store/actionRuns/actionRunsRecorder.mjs +39 -0
- package/dist/store/actionRuns/actionRunsStore.d.ts +16 -0
- package/dist/store/actionRuns/actionRunsStore.mjs +5 -0
- package/dist/store/actionRuns/index.d.ts +6 -0
- package/dist/store/actionRuns/index.mjs +4 -0
- package/dist/store/actionRuns/useActionRuns.d.ts +13 -0
- package/dist/store/actionRuns/useActionRuns.mjs +10 -0
- package/dist/store/index.d.ts +46 -45
- package/dist/store/index.mjs +6 -3
- package/dist/store/renderSettings.d.ts +3 -0
- package/dist/store/renderSettings.mjs +17 -5
- package/dist/store/tracing/tracingCollector.d.ts +1 -1
- package/dist/store/tracing/tracingCollector.mjs +37 -35
- package/dist/store/tracing/tracingStore.d.ts +13 -0
- package/dist/store/tracing/tracingStore.mjs +3 -3
- package/dist/style/fontAssets.d.ts +12 -0
- package/dist/style/fontAssets.mjs +18 -0
- package/dist/style/fontValidation.d.ts +8 -0
- package/dist/style/fontValidation.mjs +107 -0
- package/dist/style/fonts.d.ts +74 -0
- package/dist/style/fonts.mjs +198 -0
- package/dist/style/fontsFromCss.d.ts +27 -0
- package/dist/style/fontsFromCss.mjs +43 -0
- package/dist/style/index.d.ts +4 -0
- package/dist/style/index.mjs +5 -1
- package/dist/style/styleConstants.d.ts +2 -2
- package/dist/style/styleConstants.mjs +1 -0
- package/dist/theme/ThemeProvider.d.ts +36 -6
- package/dist/theme/ThemeProvider.mjs +49 -35
- package/dist/theme/ThemeScope.d.ts +16 -0
- package/dist/theme/ThemeScope.mjs +6 -0
- package/dist/theme/index.d.ts +7 -1
- package/dist/theme/index.mjs +6 -2
- package/dist/theme/themeCookie.d.ts +30 -0
- package/dist/theme/themeCookie.mjs +24 -0
- package/dist/theme/themeStore.d.ts +40 -0
- package/dist/theme/themeStore.mjs +17 -0
- package/dist/theme/useTheme.d.ts +29 -0
- package/dist/theme/useTheme.mjs +20 -0
- package/dist/types/ActionTypes.d.ts +396 -0
- package/dist/types/ActionTypes.mjs +0 -0
- package/dist/types/AuthTypes.d.ts +23 -2
- package/dist/types/BuilderTypes.d.ts +0 -12
- package/dist/types/CommonTypes.d.ts +13 -0
- package/dist/types/DevToolsTypes.d.ts +57 -14
- package/dist/types/EventBridgeTypes.d.ts +1 -1
- package/dist/types/InteractionTypes.d.ts +23 -3
- package/dist/types/PluginTypes.d.ts +0 -3
- package/dist/types/SchemaTypes.d.ts +29 -4
- package/dist/types/ServerTypes.d.ts +390 -46
- package/dist/types/SpaceTypes.d.ts +16 -0
- package/dist/types/StoreTypes.d.ts +181 -3
- package/dist/types/StyleTypes.d.ts +83 -4
- package/dist/types/TemplateTypes.d.ts +20 -0
- package/dist/types/TemplateTypes.mjs +0 -0
- package/dist/types/ThemeTypes.d.ts +28 -1
- package/dist/types/index.d.ts +2 -0
- package/eslint.config.mjs +2 -0
- package/package.json +244 -29
- package/vite.config.ts +27 -7
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FontStyle, SpaceFont } from '../types/StyleTypes';
|
|
2
|
+
/**
|
|
3
|
+
* What a deployment knows about a family it did not declare — the Google catalog, usually.
|
|
4
|
+
*
|
|
5
|
+
* Optional everywhere it is taken: without it every unknown family is declared as a system stack, which renders
|
|
6
|
+
* exactly as it would have anyway and shows up in the Fonts panel for somebody to convert on purpose.
|
|
7
|
+
*/
|
|
8
|
+
export type FontCatalogLookup = (family: string) => {
|
|
9
|
+
weights: number[];
|
|
10
|
+
styles: FontStyle[];
|
|
11
|
+
category?: string;
|
|
12
|
+
} | undefined;
|
|
13
|
+
/** A guess from the name, for a family nothing can identify: a licensed face, a foundry kit, a typo. */
|
|
14
|
+
export declare const fallbackForFamily: (family: string, category?: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* The manifest a stylesheet implies.
|
|
17
|
+
*
|
|
18
|
+
* Used wherever CSS arrives from outside and has to become a space: an import from HTML, Tailwind or Webflow, and
|
|
19
|
+
* the one-shot migration that gave the first manifests to spaces written before there were any. Both face the same
|
|
20
|
+
* problem — a `font-family` names a family and says nothing about where it comes from — and the answer is the same
|
|
21
|
+
* guess, so it lives once.
|
|
22
|
+
*
|
|
23
|
+
* A family the catalog knows is declared as a Google font at the weights the CSS actually uses. Anything else is
|
|
24
|
+
* declared as a system stack: it renders exactly as it does now, and it is visible in the panel rather than being
|
|
25
|
+
* a name in a stylesheet that nobody can see is unloadable.
|
|
26
|
+
*/
|
|
27
|
+
export declare const fontsFromCss: (css: string, lookup?: FontCatalogLookup) => SpaceFont[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { SYSTEM_FONTS as e, familiesInCss as t } from "./fonts.mjs";
|
|
2
|
+
//#region src/style/fontsFromCss.ts
|
|
3
|
+
var n = {
|
|
4
|
+
serif: "Georgia, serif",
|
|
5
|
+
"sans-serif": "system-ui, sans-serif",
|
|
6
|
+
display: "system-ui, sans-serif",
|
|
7
|
+
handwriting: "cursive",
|
|
8
|
+
monospace: "ui-monospace, monospace"
|
|
9
|
+
}, r = (e) => {
|
|
10
|
+
let t = /* @__PURE__ */ new Set();
|
|
11
|
+
for (let n of e.matchAll(/font-weight\s*:\s*(\d{3})/g)) t.add(Number(n[1]));
|
|
12
|
+
return [...t].sort((e, t) => e - t);
|
|
13
|
+
}, i = (e, t) => {
|
|
14
|
+
if (t && n[t]) return n[t];
|
|
15
|
+
let r = e.toLowerCase();
|
|
16
|
+
return r.includes("mono") || r.includes("code") || r.includes("courier") ? "ui-monospace, monospace" : r.includes("serif") && !r.includes("sans") ? "Georgia, serif" : "system-ui, sans-serif";
|
|
17
|
+
}, a = (n, a) => {
|
|
18
|
+
let o = new Set(e.map((e) => e.family.toLowerCase())), s = r(n);
|
|
19
|
+
return t(n).filter((e) => !o.has(e.toLowerCase())).map((e) => {
|
|
20
|
+
let t = a?.(e);
|
|
21
|
+
if (!t) return {
|
|
22
|
+
source: "system",
|
|
23
|
+
family: e,
|
|
24
|
+
fallback: i(e),
|
|
25
|
+
weights: [400, 700],
|
|
26
|
+
styles: ["normal", "italic"]
|
|
27
|
+
};
|
|
28
|
+
let n = t.weights.filter((e) => s.includes(e));
|
|
29
|
+
return {
|
|
30
|
+
source: "google",
|
|
31
|
+
family: e,
|
|
32
|
+
fallback: i(e, t.category),
|
|
33
|
+
weights: n.length > 0 ? n : t.weights.filter((e) => e === 400 || e === 700),
|
|
34
|
+
styles: t.styles,
|
|
35
|
+
display: "swap"
|
|
36
|
+
};
|
|
37
|
+
}).map((e) => e.weights.length > 0 ? e : {
|
|
38
|
+
...e,
|
|
39
|
+
weights: [400]
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
export { i as fallbackForFamily, a as fontsFromCss };
|
package/dist/style/index.d.ts
CHANGED
package/dist/style/index.mjs
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import e, { EMPTY_STYLE_SCHEMA as t, StyleBindingsAllowed as n, baseDefaultValue as r, inheritableAttributesBase as i } from "./styleConstants.mjs";
|
|
2
|
-
|
|
2
|
+
import { fontLinkAssets as a } from "./fontAssets.mjs";
|
|
3
|
+
import { SYSTEM_FONTS as o, availableFonts as s, familiesInCss as c, fontFamilyStack as l, fontUrlResolver as u, fontsToHead as d, googleCss2Url as f, googleTextSubsetUrl as p, isSafeFontUrl as m, primaryFamily as h } from "./fonts.mjs";
|
|
4
|
+
import { FontValidationError as g, parseSpaceFont as _ } from "./fontValidation.mjs";
|
|
5
|
+
import { fallbackForFamily as v, fontsFromCss as y } from "./fontsFromCss.mjs";
|
|
6
|
+
export { t as EMPTY_STYLE_SCHEMA, g as FontValidationError, o as SYSTEM_FONTS, n as StyleBindingsAllowed, s as availableFonts, r as baseDefaultValue, v as fallbackForFamily, c as familiesInCss, l as fontFamilyStack, a as fontLinkAssets, u as fontUrlResolver, y as fontsFromCss, d as fontsToHead, f as googleCss2Url, p as googleTextSubsetUrl, i as inheritableAttributesBase, m as isSafeFontUrl, _ as parseSpaceFont, h as primaryFamily, e as styleConstants };
|
|
@@ -169,8 +169,8 @@ declare const styleConstants: {
|
|
|
169
169
|
};
|
|
170
170
|
export declare const inheritableAttributesBase: StyleCategory[];
|
|
171
171
|
export declare const StyleBindingsAllowed: {
|
|
172
|
-
path: "display" | "flex-wrap" | "flex-direction" | "align-items" | "justify-items" | "justify-content" | "align-content" | "row-gap" | "column-gap" | "grid-row-gap" | "grid-column-gap" | "grid-template-areas" | "grid-template-columns" | "grid-template-rows" | "grid-auto-flow" | "grid-auto-rows" | "grid-auto-columns" | "grid-row-start" | "grid-column-start" | "grid-row-end" | "grid-column-end" | "align-self" | "justify-self" | "order" | "flex-grow" | "flex-shrink" | "flex-basis" | "list-style" | "list-style-type" | "list-style-position" | "list-style-image" | "background-color" | "background-image" | "background-position" | "background-size" | "background-repeat" | "background-origin" | "background-clip" | "background-attachment" | "background-blend-mode" | "mask-image" | "border-top-style" | "border-top-width" | "border-top-color" | "border-bottom-style" | "border-bottom-width" | "border-bottom-color" | "border-left-style" | "border-left-width" | "border-left-color" | "border-right-style" | "border-right-width" | "border-right-color" | "border-top-left-radius" | "border-top-right-radius" | "border-bottom-left-radius" | "border-bottom-right-radius" | "border-collapse" | "border-spacing" | "table-layout" | "opacity" | "visibility" | "cursor" | "transition" | "transition-property" | "transition-duration" | "transition-timing-function" | "transition-delay" | "animation" | "animation-name" | "animation-duration" | "animation-timing-function" | "animation-delay" | "animation-iteration-count" | "animation-direction" | "animation-fill-mode" | "animation-play-state" | "box-shadow" | "
|
|
173
|
-
label: "display" | "flex-wrap" | "flex-direction" | "align-items" | "justify-items" | "justify-content" | "align-content" | "row-gap" | "column-gap" | "grid-row-gap" | "grid-column-gap" | "grid-template-areas" | "grid-template-columns" | "grid-template-rows" | "grid-auto-flow" | "grid-auto-rows" | "grid-auto-columns" | "grid-row-start" | "grid-column-start" | "grid-row-end" | "grid-column-end" | "align-self" | "justify-self" | "order" | "flex-grow" | "flex-shrink" | "flex-basis" | "list-style" | "list-style-type" | "list-style-position" | "list-style-image" | "background-color" | "background-image" | "background-position" | "background-size" | "background-repeat" | "background-origin" | "background-clip" | "background-attachment" | "background-blend-mode" | "mask-image" | "border-top-style" | "border-top-width" | "border-top-color" | "border-bottom-style" | "border-bottom-width" | "border-bottom-color" | "border-left-style" | "border-left-width" | "border-left-color" | "border-right-style" | "border-right-width" | "border-right-color" | "border-top-left-radius" | "border-top-right-radius" | "border-bottom-left-radius" | "border-bottom-right-radius" | "border-collapse" | "border-spacing" | "table-layout" | "opacity" | "visibility" | "cursor" | "transition" | "transition-property" | "transition-duration" | "transition-timing-function" | "transition-delay" | "animation" | "animation-name" | "animation-duration" | "animation-timing-function" | "animation-delay" | "animation-iteration-count" | "animation-direction" | "animation-fill-mode" | "animation-play-state" | "box-shadow" | "
|
|
172
|
+
path: "filter" | "fill" | "display" | "flex-wrap" | "flex-direction" | "align-items" | "justify-items" | "justify-content" | "align-content" | "row-gap" | "column-gap" | "grid-row-gap" | "grid-column-gap" | "grid-template-areas" | "grid-template-columns" | "grid-template-rows" | "grid-auto-flow" | "grid-auto-rows" | "grid-auto-columns" | "grid-row-start" | "grid-column-start" | "grid-row-end" | "grid-column-end" | "align-self" | "justify-self" | "order" | "flex-grow" | "flex-shrink" | "flex-basis" | "list-style" | "list-style-type" | "list-style-position" | "list-style-image" | "background-color" | "background-image" | "background-position" | "background-size" | "background-repeat" | "background-origin" | "background-clip" | "background-attachment" | "background-blend-mode" | "mask-image" | "border-top-style" | "border-top-width" | "border-top-color" | "border-bottom-style" | "border-bottom-width" | "border-bottom-color" | "border-left-style" | "border-left-width" | "border-left-color" | "border-right-style" | "border-right-width" | "border-right-color" | "border-top-left-radius" | "border-top-right-radius" | "border-bottom-left-radius" | "border-bottom-right-radius" | "border-collapse" | "border-spacing" | "table-layout" | "opacity" | "visibility" | "cursor" | "transition" | "transition-property" | "transition-duration" | "transition-timing-function" | "transition-delay" | "animation" | "animation-name" | "animation-duration" | "animation-timing-function" | "animation-delay" | "animation-iteration-count" | "animation-direction" | "animation-fill-mode" | "animation-play-state" | "box-shadow" | "backdrop-filter" | "mix-blend-mode" | "isolation" | "clip-path" | "transform" | "transform-origin" | "perspective" | "will-change" | "outline-width" | "outline-style" | "outline-color" | "outline-offset" | "pointer-events" | "user-select" | "touch-action" | "resize" | "appearance" | "scroll-behavior" | "overscroll-behavior" | "accent-color" | "caret-color" | "color-scheme" | "position" | "float" | "clear" | "z-index" | "top" | "bottom" | "left" | "right" | "box-sizing" | "aspect-ratio" | "width" | "height" | "min-width" | "min-height" | "max-width" | "max-height" | "overflow" | "overflow-x" | "overflow-y" | "object-fit" | "object-position" | "column-width" | "column-count" | "margin-top" | "margin-bottom" | "margin-left" | "margin-right" | "padding-top" | "padding-bottom" | "padding-left" | "padding-right" | "font-family" | "font-weight" | "font-size" | "line-height" | "color" | "text-align" | "font-style" | "font-variant" | "text-decoration" | "text-decoration-line" | "text-decoration-color" | "text-decoration-style" | "text-decoration-thickness" | "text-underline-offset" | "letter-spacing" | "word-spacing" | "text-indent" | "text-transform" | "direction" | "white-space" | "text-wrap" | "word-break" | "overflow-wrap" | "hyphens" | "vertical-align" | "text-overflow" | "text-shadow" | "line-clamp" | "-webkit-line-clamp" | "-webkit-box-orient" | "stroke" | "stroke-width";
|
|
173
|
+
label: "filter" | "fill" | "display" | "flex-wrap" | "flex-direction" | "align-items" | "justify-items" | "justify-content" | "align-content" | "row-gap" | "column-gap" | "grid-row-gap" | "grid-column-gap" | "grid-template-areas" | "grid-template-columns" | "grid-template-rows" | "grid-auto-flow" | "grid-auto-rows" | "grid-auto-columns" | "grid-row-start" | "grid-column-start" | "grid-row-end" | "grid-column-end" | "align-self" | "justify-self" | "order" | "flex-grow" | "flex-shrink" | "flex-basis" | "list-style" | "list-style-type" | "list-style-position" | "list-style-image" | "background-color" | "background-image" | "background-position" | "background-size" | "background-repeat" | "background-origin" | "background-clip" | "background-attachment" | "background-blend-mode" | "mask-image" | "border-top-style" | "border-top-width" | "border-top-color" | "border-bottom-style" | "border-bottom-width" | "border-bottom-color" | "border-left-style" | "border-left-width" | "border-left-color" | "border-right-style" | "border-right-width" | "border-right-color" | "border-top-left-radius" | "border-top-right-radius" | "border-bottom-left-radius" | "border-bottom-right-radius" | "border-collapse" | "border-spacing" | "table-layout" | "opacity" | "visibility" | "cursor" | "transition" | "transition-property" | "transition-duration" | "transition-timing-function" | "transition-delay" | "animation" | "animation-name" | "animation-duration" | "animation-timing-function" | "animation-delay" | "animation-iteration-count" | "animation-direction" | "animation-fill-mode" | "animation-play-state" | "box-shadow" | "backdrop-filter" | "mix-blend-mode" | "isolation" | "clip-path" | "transform" | "transform-origin" | "perspective" | "will-change" | "outline-width" | "outline-style" | "outline-color" | "outline-offset" | "pointer-events" | "user-select" | "touch-action" | "resize" | "appearance" | "scroll-behavior" | "overscroll-behavior" | "accent-color" | "caret-color" | "color-scheme" | "position" | "float" | "clear" | "z-index" | "top" | "bottom" | "left" | "right" | "box-sizing" | "aspect-ratio" | "width" | "height" | "min-width" | "min-height" | "max-width" | "max-height" | "overflow" | "overflow-x" | "overflow-y" | "object-fit" | "object-position" | "column-width" | "column-count" | "margin-top" | "margin-bottom" | "margin-left" | "margin-right" | "padding-top" | "padding-bottom" | "padding-left" | "padding-right" | "font-family" | "font-weight" | "font-size" | "line-height" | "color" | "text-align" | "font-style" | "font-variant" | "text-decoration" | "text-decoration-line" | "text-decoration-color" | "text-decoration-style" | "text-decoration-thickness" | "text-underline-offset" | "letter-spacing" | "word-spacing" | "text-indent" | "text-transform" | "direction" | "white-space" | "text-wrap" | "word-break" | "overflow-wrap" | "hyphens" | "vertical-align" | "text-overflow" | "text-shadow" | "line-clamp" | "-webkit-line-clamp" | "-webkit-box-orient" | "stroke" | "stroke-width";
|
|
174
174
|
}[];
|
|
175
175
|
export declare const baseDefaultValue: Record<StyleCategory, StyleValue>;
|
|
176
176
|
export default styleConstants;
|
|
@@ -1,12 +1,42 @@
|
|
|
1
|
-
import { Theme
|
|
1
|
+
import { Theme } from '../types';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Whose theme this provider is running.
|
|
5
|
+
*
|
|
6
|
+
* `document` — the default — is a surface that IS the page: it stamps the class on `<html>`, and everything in the
|
|
7
|
+
* document follows it. `container` is the SDK EMBEDDED in an application that has a theme of its own: it touches
|
|
8
|
+
* nothing outside itself, gets a theme store of its own, and hands the class back through `useTheme` for the app's
|
|
9
|
+
* own root element to wear.
|
|
10
|
+
*
|
|
11
|
+
* The desktop window is why this exists. It renders its chrome in Tailwind's `dark:` variants off the document
|
|
12
|
+
* class and mounts the SDK twice inside it — once for the rail, once for the space the visitor opened — so a
|
|
13
|
+
* visitor toggling the theme of THEIR space was repainting the application around it.
|
|
14
|
+
*/
|
|
15
|
+
export type ThemeScope = 'document' | 'container';
|
|
4
16
|
export type ThemeProviderProps = {
|
|
5
17
|
defaultTheme?: Theme;
|
|
6
|
-
|
|
7
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The theme the host already knows.
|
|
20
|
+
*
|
|
21
|
+
* The server-rendered case: the choice is in the cookie, the server read it, rendered the class and passes the
|
|
22
|
+
* value here — so the document arrives correct and the provider agrees with it from its first render. Left out,
|
|
23
|
+
* the cookie is read here instead, which is what a surface no server rendered does.
|
|
24
|
+
*/
|
|
25
|
+
theme?: Theme;
|
|
26
|
+
scope?: ThemeScope;
|
|
27
|
+
/** The cookie the choice lives in. Named per surface where two share an origin — the builder and a space do. */
|
|
28
|
+
cookieName?: string;
|
|
8
29
|
children?: ReactNode;
|
|
9
30
|
};
|
|
10
|
-
|
|
11
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Drives the theme store: what was chosen, what the machine is asking for, and what the document says.
|
|
33
|
+
*
|
|
34
|
+
* It provides no VALUE. The theme lives in a store and every consumer reads it with `useTheme`, so a panel in a
|
|
35
|
+
* shadow root or an editor in a portal gets the same answer as a component under this element. What is left here is
|
|
36
|
+
* the three things only a mounted component can do — read the cookie once, subscribe to `matchMedia`, and stamp the
|
|
37
|
+
* root — and doing them in ONE place is the point: a component running its own `matchMedia` gets a value that stops
|
|
38
|
+
* updating the moment the visitor changes their system setting, which is how a panel ends up dark inside a page
|
|
39
|
+
* that is still light.
|
|
40
|
+
*/
|
|
41
|
+
declare const ThemeProvider: ({ defaultTheme, theme, scope, cookieName, children }: ThemeProviderProps) => import("react").JSX.Element;
|
|
12
42
|
export default ThemeProvider;
|
|
@@ -1,40 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { THEME_COOKIE_NAME as e, applyThemeClass as t, readThemeCookie as n, writeThemeCookie as r } from "./themeCookie.mjs";
|
|
2
|
+
import i, { createThemeStore as a, resolveScheme as o, setMachineScheme as s, setThemeMode as c } from "./themeStore.mjs";
|
|
3
|
+
import l from "./ThemeScope.mjs";
|
|
4
|
+
import { useCommonStoreSync as u } from "../store/index.mjs";
|
|
5
|
+
import { use as d, useEffect as f, useId as p, useState as m, useSyncExternalStore as h } from "react";
|
|
6
|
+
import { StoreContext as g, useIsomorphicLayoutEffect as _ } from "@plitzi/nexus/react";
|
|
7
|
+
import { Fragment as v, jsx as y, jsxs as b } from "react/jsx-runtime";
|
|
4
8
|
//#region src/theme/ThemeProvider.tsx
|
|
5
|
-
var
|
|
6
|
-
theme
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
var x = "(prefers-color-scheme: dark)", S = () => window.matchMedia(x).matches ? "dark" : "light", C = ({ state: e }) => (u([
|
|
10
|
+
"theme.mode",
|
|
11
|
+
"theme.resolved",
|
|
12
|
+
"theme.areas"
|
|
13
|
+
], [
|
|
14
|
+
e.mode,
|
|
15
|
+
o(e.mode, e.scheme),
|
|
16
|
+
e.areas
|
|
17
|
+
]), null), w = ({ defaultTheme: o = "system", theme: u, scope: w = "document", cookieName: T = e, children: E }) => {
|
|
18
|
+
let D = w === "container", O = p(), [k] = m(() => D ? a(`theme${O}`) : void 0), A = k ?? i;
|
|
19
|
+
_(() => {
|
|
20
|
+
let e = D ? void 0 : n(T);
|
|
21
|
+
A.batch(() => {
|
|
22
|
+
s(S(), A), c(u ?? e ?? o, A);
|
|
18
23
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
}, [
|
|
25
|
+
o,
|
|
26
|
+
u,
|
|
27
|
+
T,
|
|
28
|
+
D,
|
|
29
|
+
A
|
|
30
|
+
]);
|
|
31
|
+
let j = h(A.subscribe, A.getState, A.getState), M = d(g) !== void 0;
|
|
32
|
+
f(() => {
|
|
33
|
+
let e = window.matchMedia(x), t = () => s(e.matches ? "dark" : "light", A);
|
|
34
|
+
return e.addEventListener("change", t), t(), () => e.removeEventListener("change", t);
|
|
35
|
+
}, [A]), f(() => {
|
|
36
|
+
if (D) return;
|
|
37
|
+
let e = () => {
|
|
38
|
+
let { mode: e } = A.getState();
|
|
39
|
+
r(e, T), t(e, document.documentElement);
|
|
22
40
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}), [
|
|
34
|
-
return /* @__PURE__ */ i(o, {
|
|
35
|
-
value: p,
|
|
36
|
-
children: l
|
|
37
|
-
});
|
|
41
|
+
return e(), A.subscribe(e);
|
|
42
|
+
}, [
|
|
43
|
+
T,
|
|
44
|
+
D,
|
|
45
|
+
A
|
|
46
|
+
]);
|
|
47
|
+
let N = M ? /* @__PURE__ */ y(C, { state: j }) : null;
|
|
48
|
+
return D ? /* @__PURE__ */ b(l, {
|
|
49
|
+
value: k,
|
|
50
|
+
children: [N, E]
|
|
51
|
+
}) : /* @__PURE__ */ b(v, { children: [N, E] });
|
|
38
52
|
};
|
|
39
53
|
//#endregion
|
|
40
|
-
export {
|
|
54
|
+
export { w as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ThemeStoreInstance } from './themeStore';
|
|
2
|
+
/**
|
|
3
|
+
* Which theme store the tree under here reads.
|
|
4
|
+
*
|
|
5
|
+
* Absent — the ordinary case — means the surface's own, the module-level singleton. It is only ever provided by a
|
|
6
|
+
* `ThemeProvider` running in `container` scope: an SDK embedded in an application that has a theme of its own, where
|
|
7
|
+
* "the surface" is the application and not the space inside it. Two SDK instances in one document (the desktop
|
|
8
|
+
* window renders its shell as a space AND the space the visitor opened) is exactly the case the singleton cannot
|
|
9
|
+
* serve on its own — whichever mounted last would be answering for both.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately NOT the way ordinary consumers reach the theme: a panel in a shadow root and an editor in a portal
|
|
12
|
+
* are under no provider at all, and they still have to get an answer. That is what the fall-through is for.
|
|
13
|
+
*/
|
|
14
|
+
declare const ThemeScopeContext: import('react').Context<import('@plitzi/nexus').StoreApi<import('..').ThemeState> | undefined>;
|
|
15
|
+
export declare const useThemeStore: () => ThemeStoreInstance;
|
|
16
|
+
export default ThemeScopeContext;
|
package/dist/theme/index.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { default as ThemeProvider } from './ThemeProvider';
|
|
2
|
+
import { default as useTheme } from './useTheme';
|
|
2
3
|
export * from './ThemeProvider';
|
|
3
|
-
export
|
|
4
|
+
export * from './ThemeScope';
|
|
5
|
+
export * from './themeCookie';
|
|
6
|
+
export * from './themeStore';
|
|
7
|
+
export * from './useTheme';
|
|
8
|
+
export { default as themeStore } from './themeStore';
|
|
9
|
+
export { ThemeProvider, useTheme };
|
package/dist/theme/index.mjs
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import e,
|
|
2
|
-
|
|
1
|
+
import { THEME_CLASSES as e, THEME_COOKIE_NAME as t, applyThemeClass as n, isTheme as r, readThemeCookie as i, themeFromCookies as a, writeThemeCookie as o } from "./themeCookie.mjs";
|
|
2
|
+
import s, { createThemeState as c, createThemeStore as l, resolveScheme as u, setAreaTheme as d, setMachineScheme as f, setThemeMode as p, themeFor as m } from "./themeStore.mjs";
|
|
3
|
+
import { useThemeStore as h } from "./ThemeScope.mjs";
|
|
4
|
+
import g from "./ThemeProvider.mjs";
|
|
5
|
+
import _, { SPACE_THEME_AREA as v } from "./useTheme.mjs";
|
|
6
|
+
export { v as SPACE_THEME_AREA, e as THEME_CLASSES, t as THEME_COOKIE_NAME, g as ThemeProvider, n as applyThemeClass, c as createThemeState, l as createThemeStore, r as isTheme, i as readThemeCookie, u as resolveScheme, d as setAreaTheme, f as setMachineScheme, p as setThemeMode, m as themeFor, a as themeFromCookies, s as themeStore, _ as useTheme, h as useThemeStore, o as writeThemeCookie };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Theme } from '../types';
|
|
2
|
+
/** The name the choice is kept under, and the one a server reads it back with. */
|
|
3
|
+
export declare const THEME_COOKIE_NAME = "theme";
|
|
4
|
+
/** The two a document may WEAR. `system` writes nothing — the absence is what lets the media queries answer. */
|
|
5
|
+
export declare const THEME_CLASSES: Theme[];
|
|
6
|
+
export declare const isTheme: (value: unknown) => value is Theme;
|
|
7
|
+
/**
|
|
8
|
+
* Applies a theme to an element — the chosen class on, the other off, so a change is never additive.
|
|
9
|
+
*
|
|
10
|
+
* Removing a class cannot express "I want light on a machine set to dark", which is why `light` is written as
|
|
11
|
+
* explicitly as `dark` is, and why only `system` leaves the element bare.
|
|
12
|
+
*/
|
|
13
|
+
export declare const applyThemeClass: (mode: Theme, root: HTMLElement) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Reads the theme out of a `Cookie` header, or out of `document.cookie`.
|
|
16
|
+
*
|
|
17
|
+
* A cookie and not web storage, and that is the whole design: it is the only place a browser keeps a preference
|
|
18
|
+
* that the SERVER can also read. So the document arrives with the class already on `<html>` — no blocking script
|
|
19
|
+
* in the head to beat the first paint, no four hundred milliseconds of the other theme for the SDK to correct,
|
|
20
|
+
* and no second copy of these rules written in another language for a template to get subtly wrong.
|
|
21
|
+
*
|
|
22
|
+
* One function for both sides for the same reason: the server parsing the header with its own regex is that copy.
|
|
23
|
+
*/
|
|
24
|
+
export declare const themeFromCookies: (cookies: string | undefined, name?: string) => Theme | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Every accessor is guarded: a sandboxed iframe and a browser set to block site data both answer by throwing
|
|
27
|
+
* rather than by returning nothing. The theme still works there; it just stops being remembered.
|
|
28
|
+
*/
|
|
29
|
+
export declare const readThemeCookie: (name?: string) => Theme | undefined;
|
|
30
|
+
export declare const writeThemeCookie: (mode: Theme, name?: string) => void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/theme/themeCookie.ts
|
|
2
|
+
var e = "theme", t = ["dark", "light"], n = [...t, "system"], r = 31536e3, i = (e) => n.includes(e), a = (e, n) => {
|
|
3
|
+
for (let r of t) n.classList.toggle(r, e === r);
|
|
4
|
+
}, o = (t, n = e) => {
|
|
5
|
+
if (t) for (let e of t.split(";")) {
|
|
6
|
+
let t = e.indexOf("=");
|
|
7
|
+
if (t > -1 && e.slice(0, t).trim() === n) {
|
|
8
|
+
let n = decodeURIComponent(e.slice(t + 1).trim());
|
|
9
|
+
return i(n) ? n : void 0;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}, s = (t = e) => {
|
|
13
|
+
try {
|
|
14
|
+
return o(document.cookie, t);
|
|
15
|
+
} catch {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
}, c = (t, n = e) => {
|
|
19
|
+
try {
|
|
20
|
+
document.cookie = `${n}=${encodeURIComponent(t)};path=/;max-age=${r};SameSite=Lax`;
|
|
21
|
+
} catch {}
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { t as THEME_CLASSES, e as THEME_COOKIE_NAME, a as applyThemeClass, i as isTheme, s as readThemeCookie, o as themeFromCookies, c as writeThemeCookie };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ColorScheme, Theme, ThemeState } from '../types';
|
|
2
|
+
export declare const createThemeState: () => ThemeState;
|
|
3
|
+
/**
|
|
4
|
+
* The theme, as a store rather than a context.
|
|
5
|
+
*
|
|
6
|
+
* It is read by things that render outside the app's provider tree — the dev-tools panel in its shadow root, an
|
|
7
|
+
* editor mounted into a portal — and by the odd module that has no component around it at all. A context could
|
|
8
|
+
* serve neither, and every consumer that wanted the answer had to be under the one provider that held it.
|
|
9
|
+
*
|
|
10
|
+
* What varies WITHIN a surface is `areas`, which is a map rather than a second store for the same reason — two
|
|
11
|
+
* stores would need somebody to keep them in step, and "keeping them in step" is the whole of what an area's rule
|
|
12
|
+
* is.
|
|
13
|
+
*/
|
|
14
|
+
export declare const createThemeStore: (id?: string) => import('@plitzi/nexus').StoreApi<ThemeState>;
|
|
15
|
+
export type ThemeStoreInstance = ReturnType<typeof createThemeStore>;
|
|
16
|
+
/**
|
|
17
|
+
* The surface's theme.
|
|
18
|
+
*
|
|
19
|
+
* A browser tab usually paints one surface, and this is it — what the dev-tools panel and anything else outside a
|
|
20
|
+
* provider tree reads. It stops being the only one when a page EMBEDS the SDK in an application that has a theme of
|
|
21
|
+
* its own (the desktop window, a space mounted in a host): there the embedded surface gets a store of its own from
|
|
22
|
+
* {@link createThemeStore} and this one keeps belonging to the application around it. See `ThemeProvider`'s `scope`.
|
|
23
|
+
*/
|
|
24
|
+
declare const themeStore: import('@plitzi/nexus').StoreApi<ThemeState>;
|
|
25
|
+
export declare const resolveScheme: (mode: Theme, scheme: ColorScheme) => ColorScheme;
|
|
26
|
+
/** The theme of one area, or of the surface when the area has made no choice of its own. */
|
|
27
|
+
export declare const themeFor: (state: ThemeState, area?: string) => Theme;
|
|
28
|
+
/**
|
|
29
|
+
* The surface's own choice — and, with it, every area's.
|
|
30
|
+
*
|
|
31
|
+
* Clearing `areas` IS the sync rule: an area's theme is an override of what the surface is currently showing, so
|
|
32
|
+
* the moment the surface changes its mind there is nothing left to override. Without this an author who darkened
|
|
33
|
+
* the preview pane once would find it stuck there for good, deaf to the editor's toggle, which is the complaint
|
|
34
|
+
* that a separate per-area setting always produces.
|
|
35
|
+
*/
|
|
36
|
+
export declare const setThemeMode: (mode: Theme, store?: ThemeStoreInstance) => void;
|
|
37
|
+
export declare const setAreaTheme: (area: string, mode: Theme, store?: ThemeStoreInstance) => void;
|
|
38
|
+
/** What the machine is asking for. Written only by `ThemeProvider`, which is the one subscriber to it. */
|
|
39
|
+
export declare const setMachineScheme: (scheme: ColorScheme, store?: ThemeStoreInstance) => void;
|
|
40
|
+
export default themeStore;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createStore as e } from "@plitzi/nexus";
|
|
2
|
+
//#region src/theme/themeStore.ts
|
|
3
|
+
var t = () => ({
|
|
4
|
+
mode: "system",
|
|
5
|
+
scheme: "light",
|
|
6
|
+
areas: {}
|
|
7
|
+
}), n = (n = "theme") => e(t(), { id: n }), r = n(), i = (e, t) => e === "system" ? t : e, a = (e, t) => (t ? e.areas[t] : void 0) ?? e.mode, o = (e, t = r) => {
|
|
8
|
+
t.batch(() => {
|
|
9
|
+
t.setState("mode", e), t.setState("areas", {});
|
|
10
|
+
});
|
|
11
|
+
}, s = (e, t, n = r) => {
|
|
12
|
+
n.setState(`areas.${e}`, t);
|
|
13
|
+
}, c = (e, t = r) => {
|
|
14
|
+
t.setState("scheme", e);
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { t as createThemeState, n as createThemeStore, r as default, i as resolveScheme, s as setAreaTheme, c as setMachineScheme, o as setThemeMode, a as themeFor };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ThemeValue } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* The area every surface that paints the SPACE uses — the builder's canvas, and every `BuilderAreaPreview`: the
|
|
4
|
+
* page thumbnails, a template preview, what the agent renders in the chat.
|
|
5
|
+
*
|
|
6
|
+
* ONE area and not one per surface, on purpose. They are all showing the same thing, and a preview of a page that
|
|
7
|
+
* paints in a different scheme from the canvas beside it is not a preview of anything. What the split is actually
|
|
8
|
+
* for is the EDITOR versus the space it is editing: the panels, menus and dialogs follow the surface theme, and
|
|
9
|
+
* this follows whichever scheme the author wants to look at their page in.
|
|
10
|
+
*
|
|
11
|
+
* Named rather than typed at each call site so there is one string to change and nowhere for a typo to hide — a
|
|
12
|
+
* misspelled area does not fail, it silently makes a second one that follows the surface.
|
|
13
|
+
*/
|
|
14
|
+
export declare const SPACE_THEME_AREA = "canvas";
|
|
15
|
+
/**
|
|
16
|
+
* The theme, for whoever is asking.
|
|
17
|
+
*
|
|
18
|
+
* Called bare it answers the surface's; called with an `area` it answers that area's, falling back to the surface
|
|
19
|
+
* while the area has made no choice of its own. `setTheme` writes wherever it read, so a control never has to know
|
|
20
|
+
* which of the two it is wired to — the builder's header toggle and the canvas's own are the same component with a
|
|
21
|
+
* different argument.
|
|
22
|
+
*
|
|
23
|
+
* `resolvedTheme` is always a colour: `system` is resolved against the machine's live answer, which `ThemeProvider`
|
|
24
|
+
* keeps in the store. Anything that PAINTS wants that one — a code editor, a chart, a canvas — because `system`
|
|
25
|
+
* cannot be compared against a colour, and resolving it to `light` (the usual shortcut) makes a dark-set machine
|
|
26
|
+
* render the light thing.
|
|
27
|
+
*/
|
|
28
|
+
declare const useTheme: (area?: string) => ThemeValue;
|
|
29
|
+
export default useTheme;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { resolveScheme as e, setAreaTheme as t, setThemeMode as n, themeFor as r } from "./themeStore.mjs";
|
|
2
|
+
import { useThemeStore as i } from "./ThemeScope.mjs";
|
|
3
|
+
import { useCallback as a, useMemo as o, useSyncExternalStore as s } from "react";
|
|
4
|
+
//#region src/theme/useTheme.ts
|
|
5
|
+
var c = "canvas", l = (c) => {
|
|
6
|
+
let l = i(), u = s(l.subscribe, l.getState, l.getState), d = r(u, c), f = e(d, u.scheme), p = a((e) => c ? t(c, e, l) : n(e, l), [c, l]), m = a(() => p(f === "dark" ? "light" : "dark"), [f, p]);
|
|
7
|
+
return o(() => ({
|
|
8
|
+
theme: d,
|
|
9
|
+
resolvedTheme: f,
|
|
10
|
+
setTheme: p,
|
|
11
|
+
toggleTheme: m
|
|
12
|
+
}), [
|
|
13
|
+
d,
|
|
14
|
+
f,
|
|
15
|
+
p,
|
|
16
|
+
m
|
|
17
|
+
]);
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { c as SPACE_THEME_AREA, l as default };
|