@seanyeh77/ui 0.50.0 → 0.51.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.
@@ -103,7 +103,7 @@ function ConsoleLayout({ title, tags, status, kpis, clock, fullscreen = true, ma
103
103
  ref,
104
104
  className: cx("ui-console", stacked && "is-stacked", className),
105
105
  children: /* @__PURE__ */ jsxs("div", {
106
- className: "ui-console-frame",
106
+ className: cx("ui-console-frame", bottom == null && "no-bottom"),
107
107
  style: frameStyle,
108
108
  children: [
109
109
  top,
@@ -1 +1 @@
1
- {"version":3,"file":"ConsoleLayout.js","names":["phCornersIn","phCornersOut"],"sources":["../../../src/components/ConsoleLayout/ConsoleLayout.tsx"],"sourcesContent":["import * as React from 'react';\nimport { IconButton } from '../IconButton/IconButton';\nimport { devWarn } from '../../internal/dev';\nimport { cx } from '../../internal/util';\nimport { tr } from '../../i18n';\nimport { includeIcons } from '../../icons/store';\nimport phCornersIn from '../../icons/ph/corners-in';\nimport phCornersOut from '../../icons/ph/corners-out';\n\nincludeIcons(phCornersIn, phCornersOut);\n\n/** A card that shows only when the screen is tall enough. */\nexport interface ConsoleExtra {\n /** Stable key for the card. */\n id: string;\n /** Optional: also needs the layout's logical height (the screen height divided by the zoom) to be at least this\n * many px. Without it, the card shows whenever it fits under the side cards at its own height. */\n minHeight?: number;\n /** The card: usually a Card. */\n node: React.ReactNode;\n}\n\nexport interface ConsoleLayoutProps {\n /** The product or screen name, the page's only heading: 「設施監控」. */\n title: string;\n /** Right after the title: a Tag 「示範資料」 with the info icon. Same size and color as the text around it. */\n tags?: React.ReactNode;\n /** Right side, before the KPIs: one short state in plain words, 「AI 最佳化中」. Shown in body size and ink color;\n * pass plain text, not a Badge. */\n status?: React.ReactNode;\n /** Right side: `<KpiCard size=\"compact\" />` side by side. In the top bar they lose their card look and sit between\n * 1 px lines. */\n kpis?: React.ReactNode;\n /** Right side, after the KPIs: the time and whether it is live, 「16:24 即時」. */\n clock?: React.ReactNode;\n /** A 「全螢幕」 button at the right end (Fullscreen API). Default true; hidden where the browser has no full screen. */\n fullscreen?: boolean;\n /** The main view, left of the side panel; it fills its cell (pass one Card, e.g. with a ZoneMap). */\n main: React.ReactNode;\n /** The side panel, 400 px (360 px under 1280 px): cards from top to bottom (TimeControl, EventTimeline). When they\n * do not fit, the side panel scrolls on its own; the page never does. */\n side?: React.ReactNode;\n /** The bottom row under the main view, as tall as its content: e.g. a LineChart in a Card. The main view takes the\n * height that is left. */\n bottom?: React.ReactNode;\n /** Cards added at the end of the side panel when they fit there at their own height, in order (the first that does\n * not fit and every one after it stay out): `[{ id, node }]`. Stacked, all of them show. */\n extras?: ConsoleExtra[];\n /** Below this width of the layout (px) everything is one scrolling column (stacked). Default 1100: narrower, the main\n * view beside the side panel would be under 700 px wide. */\n stackedBelow?: number;\n /** 'auto' (default): stacked below `stackedBelow`. 'console': never stacked. 'stacked': always stacked. */\n mode?: 'auto' | 'console' | 'stacked';\n /** Extra class on the root element. */\n className?: string;\n}\n\n/** Design size: at this size and up the layout zooms in. */\nconst BASE_W = 1440;\nconst BASE_H = 900;\nconst MAX_ZOOM = 1.5;\nconst STACKED_BELOW = 1100;\nconst PHONE = 600;\n\nconst noSubscribe = () => () => {};\nconst fullscreenEnabled = () => typeof document !== 'undefined' && document.fullscreenEnabled === true;\nconst serverFalse = () => false;\n\n/** Zoom for a screen of w × h px: 1 up to 1440 × 900, then grows with the screen, at most 1.5. */\nexport function consoleZoom(w: number, h: number): number {\n return Math.max(1, Math.min(MAX_ZOOM, Math.min(w / BASE_W, h / BASE_H)));\n}\n\n/** A full-screen monitoring layout: a top bar (title, tags, then status, KPIs, clock and full screen on the right),\n * the main view with a side panel beside it and a bottom row under it, filling the screen without scrolling. From\n * 1440 × 900 up everything zooms with the screen (at most 1.5×). Phones (under 600 px) get one scrolling column. */\nexport function ConsoleLayout({\n title,\n tags,\n status,\n kpis,\n clock,\n fullscreen = true,\n main,\n side,\n bottom,\n extras,\n stackedBelow = STACKED_BELOW,\n mode = 'auto',\n className,\n}: ConsoleLayoutProps) {\n const ref = React.useRef<HTMLDivElement>(null);\n const sideRef = React.useRef<HTMLElement>(null);\n const [size, setSize] = React.useState<{ w: number; h: number } | null>(null);\n const [full, setFull] = React.useState(false);\n // false on the server and the first browser render, so the markup matches; then whether full screen is allowed.\n const canFull = React.useSyncExternalStore(noSubscribe, fullscreenEnabled, serverFalse);\n\n React.useLayoutEffect(() => {\n const el = ref.current;\n if (!el) return;\n const measure = () => setSize({ w: el.clientWidth, h: el.clientHeight });\n measure();\n if (typeof ResizeObserver === 'undefined') return;\n const ro = new ResizeObserver(measure);\n ro.observe(el);\n return () => ro.disconnect();\n }, []);\n\n React.useEffect(() => {\n const f = () => setFull(document.fullscreenElement != null && document.fullscreenElement === ref.current);\n document.addEventListener('fullscreenchange', f);\n return () => document.removeEventListener('fullscreenchange', f);\n }, []);\n\n const toggleFull = () => {\n const el = ref.current;\n if (!el) return;\n if (document.fullscreenElement) void document.exitFullscreen().catch(() => undefined);\n else void el.requestFullscreen().catch(() => undefined);\n };\n\n const stacked = mode === 'stacked' || (mode === 'auto' && size != null && size.w < stackedBelow);\n const phone = size != null && size.w < PHONE;\n // Stacked, the column scrolls and never zooms.\n // The zoom takes at most the window's height: a layout an app lets grow with its content would otherwise zoom in on\n // its own height.\n const zoomH = size ? Math.min(size.h, (typeof window !== 'undefined' && window.innerHeight) || size.h) : 0;\n const zoom = size && !stacked ? consoleZoom(size.w, zoomH) : 1;\n const logicalH = size ? size.h / zoom : 0;\n const allowed = (extras ?? []).filter((x) => stacked || x.minHeight == null || logicalH >= x.minHeight);\n const fit = useExtrasFit(sideRef, stacked ? -1 : allowed.length, `${allowed.map((x) => x.id).join('|')}|${size?.w}|${size?.h}|${zoom}`);\n const frameStyle: React.CSSProperties | undefined =\n size && !stacked && zoom !== 1 ? ({ zoom, width: size.w / zoom, height: size.h / zoom } as React.CSSProperties) : undefined;\n\n const top = (\n <header className=\"ui-console-top\">\n <div className=\"ui-console-start\">\n <h1 className=\"ui-console-title\">{title}</h1>\n {tags}\n </div>\n <div className=\"ui-console-end\">\n {status != null ? <span className=\"ui-console-status\">{status}</span> : null}\n {kpis != null ? <div className=\"ui-console-kpis\">{kpis}</div> : null}\n {clock != null ? <span className=\"ui-console-clock\">{clock}</span> : null}\n {fullscreen && canFull && !phone ? (\n <IconButton label={full ? tr('離開全螢幕') : tr('全螢幕')} icon={full ? 'corners-in' : 'corners-out'} onClick={toggleFull} />\n ) : null}\n </div>\n </header>\n );\n\n return (\n <div ref={ref} className={cx('ui-console', stacked && 'is-stacked', className)}>\n <div className=\"ui-console-frame\" style={frameStyle}>\n {top}\n {/* The main landmark draws no box (display: contents): the main view and the bottom row stay grid cells, and\n stacked, the whole column after the top bar is in it. */}\n <main className=\"ui-console-content\">\n <div className=\"ui-console-main\">{main}</div>\n {stacked ? (\n <>\n {side != null ? <div className=\"ui-console-cards\">{side}</div> : null}\n {bottom}\n {allowed.length ? (\n <div className=\"ui-console-cards\">\n {allowed.map((x) => (\n <React.Fragment key={x.id}>{x.node}</React.Fragment>\n ))}\n </div>\n ) : null}\n </>\n ) : bottom != null ? (\n <div className=\"ui-console-bottom\">{bottom}</div>\n ) : null}\n </main>\n {stacked ? null : (\n <aside ref={sideRef} className=\"ui-console-side\" aria-label={tr('側欄')}>\n {side}\n {/* Each extra in a wrapper that is measured; one that does not fit is laid out out of sight, at no height,\n so it is measured again when the panel grows. */}\n {allowed.map((x, i) => {\n const out = i >= fit;\n return (\n <div key={x.id} className={cx('ui-console-extra', out && 'is-out')} data-extra=\"\" aria-hidden={out || undefined} inert={out || undefined}>\n {x.node}\n </div>\n );\n })}\n </aside>\n )}\n </div>\n </div>\n );\n}\n\n/** How many extras fit in the side panel under its other cards, each at its own height, in order. n is how many there\n * are (-1: none are measured, stacked). Measured again when the panel or any card changes size. */\nfunction useExtrasFit(sideRef: React.RefObject<HTMLElement | null>, n: number, key: string): number {\n const [fit, setFit] = React.useState(0);\n React.useLayoutEffect(() => {\n const side = sideRef.current;\n if (!side || n <= 0) return setFit(0);\n const measure = () => {\n const cs = getComputedStyle(side);\n const gap = parseFloat(cs.rowGap) || 0;\n const room = side.clientHeight - (parseFloat(cs.paddingTop) || 0) - (parseFloat(cs.paddingBottom) || 0);\n const kids = [...side.children] as HTMLElement[];\n const cards = kids.filter((k) => !k.hasAttribute('data-extra'));\n const extraEls = kids.filter((k) => k.hasAttribute('data-extra'));\n devWarn(\n cards.some((k) => k.scrollHeight > k.clientHeight + 1 && !/auto|scroll/.test(getComputedStyle(k).overflowY)),\n 'ConsoleLayout',\n 'a side card is shorter than its content, so the content is cut. Keep side cards at their own height: do not give them flex: 1 or min-height: 0; the side panel scrolls when they do not fit.',\n );\n let used = cards.reduce((t, k, i) => t + k.offsetHeight + (i ? gap : 0), 0);\n let count = 0;\n for (const ex of extraEls) {\n // An extra out of sight has no height of its own: its card's height counts.\n const h = ex.classList.contains('is-out') ? ((ex.firstElementChild as HTMLElement | null)?.offsetHeight ?? 0) : ex.offsetHeight;\n const need = h + (used > 0 ? gap : 0);\n if (used + need > room + 0.5) break;\n used += need;\n count++;\n }\n setFit((f) => (f === count ? f : count));\n };\n measure();\n if (typeof ResizeObserver !== 'function') return;\n const ro = new ResizeObserver(measure);\n ro.observe(side);\n for (const k of side.children) {\n ro.observe(k);\n if (k.firstElementChild) ro.observe(k.firstElementChild);\n }\n return () => ro.disconnect();\n }, [sideRef, n, key]);\n return n < 0 ? 0 : fit;\n}\n"],"mappings":";;;;;;;;;;;AASA,aAAaA,oBAAaC,mBAAY;;AAiDtC,MAAM,SAAS;AACf,MAAM,SAAS;AACf,MAAM,WAAW;AACjB,MAAM,gBAAgB;AACtB,MAAM,QAAQ;AAEd,MAAM,0BAA0B,CAAC;AACjC,MAAM,0BAA0B,OAAO,aAAa,eAAe,SAAS,sBAAsB;AAClG,MAAM,oBAAoB;;AAG1B,SAAgB,YAAY,GAAW,GAAmB;CACxD,OAAO,KAAK,IAAI,GA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AM,KAAK;GACrC,MAAM,OAAO,KAAK,gBAAgB,WAAW,GAAG,UAAU,KAAK,MAAM,WAAW,GAAG,aAAa,KAAK;GACrG,MAAM,OAAO,CAAC,GAAG,KAAK,QAAQ;GAC9B,MAAM,QAAQ,KAAK,QAAQ,MAAM,CAAC,EAAE,aAAa,YAAY,CAAC;GAC9D,MAAM,WAAW,KAAK,QAAQ,MAAM,EAAE,aAAa,YAAY,CAAC;GAChE,QACE,MAAM,MAAM,MAAM,EAAE,eAAe,EAAE,eAAe,KAAK,CAAC,cAAc,KAAK,iBAAiB,CAAC,CAAC,CAAC,SAAS,CAAC,GAC3G,iBACA,8LACF;GACA,IAAI,OAAO,MAAM,QAAQ,GAAG,GAAG,MAAM,IAAI,EAAE,gBAAgB,IAAI,MAAM,IAAI,CAAC;GAC1E,IAAI,QAAQ;GACZ,KAAK,MAAM,MAAM,UAAU;IAGzB,MAAM,QADI,GAAG,UAAU,SAAS,QAAQ,IAAM,GAAG,mBAA0C,gBAAgB,IAAK,GAAG,iBACjG,OAAO,IAAI,MAAM;IACnC,IAAI,OAAO,OAAO,OAAO,IAAK;IAC9B,QAAQ;IACR;GACF;GACA,QAAQ,MAAO,MAAM,QAAQ,IAAI,KAAM;EACzC;EACA,QAAQ;EACR,IAAI,OAAO,mBAAmB,YAAY;EAC1C,MAAM,KAAK,IAAI,eAAe,OAAO;EACrC,GAAG,QAAQ,IAAI;EACf,KAAK,MAAM,KAAK,KAAK,UAAU;GAC7B,GAAG,QAAQ,CAAC;GACZ,IAAI,EAAE,mBAAmB,GAAG,QAAQ,EAAE,iBAAiB;EACzD;EACA,aAAa,GAAG,WAAW;CAC7B,GAAG;EAAC;EAAS;EAAG;CAAG,CAAC;CACpB,OAAO,IAAI,IAAI,IAAI;AACrB"}
1
+ {"version":3,"file":"ConsoleLayout.js","names":["phCornersIn","phCornersOut"],"sources":["../../../src/components/ConsoleLayout/ConsoleLayout.tsx"],"sourcesContent":["import * as React from 'react';\nimport { IconButton } from '../IconButton/IconButton';\nimport { devWarn } from '../../internal/dev';\nimport { cx } from '../../internal/util';\nimport { tr } from '../../i18n';\nimport { includeIcons } from '../../icons/store';\nimport phCornersIn from '../../icons/ph/corners-in';\nimport phCornersOut from '../../icons/ph/corners-out';\n\nincludeIcons(phCornersIn, phCornersOut);\n\n/** A card that shows only when the screen is tall enough. */\nexport interface ConsoleExtra {\n /** Stable key for the card. */\n id: string;\n /** Optional: also needs the layout's logical height (the screen height divided by the zoom) to be at least this\n * many px. Without it, the card shows whenever it fits under the side cards at its own height. */\n minHeight?: number;\n /** The card: usually a Card. */\n node: React.ReactNode;\n}\n\nexport interface ConsoleLayoutProps {\n /** The product or screen name, the page's only heading: 「設施監控」. */\n title: string;\n /** Right after the title: a Tag 「示範資料」 with the info icon. Same size and color as the text around it. */\n tags?: React.ReactNode;\n /** Right side, before the KPIs: one short state in plain words, 「AI 最佳化中」. Shown in body size and ink color;\n * pass plain text, not a Badge. */\n status?: React.ReactNode;\n /** Right side: `<KpiCard size=\"compact\" />` side by side. In the top bar they lose their card look and sit between\n * 1 px lines. */\n kpis?: React.ReactNode;\n /** Right side, after the KPIs: the time and whether it is live, 「16:24 即時」. */\n clock?: React.ReactNode;\n /** A 「全螢幕」 button at the right end (Fullscreen API). Default true; hidden where the browser has no full screen. */\n fullscreen?: boolean;\n /** The main view, left of the side panel; it fills its cell (pass one Card, e.g. with a ZoneMap). */\n main: React.ReactNode;\n /** The side panel, 400 px (360 px under 1280 px): cards from top to bottom (TimeControl, EventTimeline). When they\n * do not fit, the side panel scrolls on its own; the page never does. */\n side?: React.ReactNode;\n /** The bottom row under the main view, as tall as its content: e.g. a LineChart in a Card. The main view takes the\n * height that is left. */\n bottom?: React.ReactNode;\n /** Cards added at the end of the side panel when they fit there at their own height, in order (the first that does\n * not fit and every one after it stay out): `[{ id, node }]`. Stacked, all of them show. */\n extras?: ConsoleExtra[];\n /** Below this width of the layout (px) everything is one scrolling column (stacked). Default 1100: narrower, the main\n * view beside the side panel would be under 700 px wide. */\n stackedBelow?: number;\n /** 'auto' (default): stacked below `stackedBelow`. 'console': never stacked. 'stacked': always stacked. */\n mode?: 'auto' | 'console' | 'stacked';\n /** Extra class on the root element. */\n className?: string;\n}\n\n/** Design size: at this size and up the layout zooms in. */\nconst BASE_W = 1440;\nconst BASE_H = 900;\nconst MAX_ZOOM = 1.5;\nconst STACKED_BELOW = 1100;\nconst PHONE = 600;\n\nconst noSubscribe = () => () => {};\nconst fullscreenEnabled = () => typeof document !== 'undefined' && document.fullscreenEnabled === true;\nconst serverFalse = () => false;\n\n/** Zoom for a screen of w × h px: 1 up to 1440 × 900, then grows with the screen, at most 1.5. */\nexport function consoleZoom(w: number, h: number): number {\n return Math.max(1, Math.min(MAX_ZOOM, Math.min(w / BASE_W, h / BASE_H)));\n}\n\n/** A full-screen monitoring layout: a top bar (title, tags, then status, KPIs, clock and full screen on the right),\n * the main view with a side panel beside it and a bottom row under it, filling the screen without scrolling. From\n * 1440 × 900 up everything zooms with the screen (at most 1.5×). Phones (under 600 px) get one scrolling column. */\nexport function ConsoleLayout({\n title,\n tags,\n status,\n kpis,\n clock,\n fullscreen = true,\n main,\n side,\n bottom,\n extras,\n stackedBelow = STACKED_BELOW,\n mode = 'auto',\n className,\n}: ConsoleLayoutProps) {\n const ref = React.useRef<HTMLDivElement>(null);\n const sideRef = React.useRef<HTMLElement>(null);\n const [size, setSize] = React.useState<{ w: number; h: number } | null>(null);\n const [full, setFull] = React.useState(false);\n // false on the server and the first browser render, so the markup matches; then whether full screen is allowed.\n const canFull = React.useSyncExternalStore(noSubscribe, fullscreenEnabled, serverFalse);\n\n React.useLayoutEffect(() => {\n const el = ref.current;\n if (!el) return;\n const measure = () => setSize({ w: el.clientWidth, h: el.clientHeight });\n measure();\n if (typeof ResizeObserver === 'undefined') return;\n const ro = new ResizeObserver(measure);\n ro.observe(el);\n return () => ro.disconnect();\n }, []);\n\n React.useEffect(() => {\n const f = () => setFull(document.fullscreenElement != null && document.fullscreenElement === ref.current);\n document.addEventListener('fullscreenchange', f);\n return () => document.removeEventListener('fullscreenchange', f);\n }, []);\n\n const toggleFull = () => {\n const el = ref.current;\n if (!el) return;\n if (document.fullscreenElement) void document.exitFullscreen().catch(() => undefined);\n else void el.requestFullscreen().catch(() => undefined);\n };\n\n const stacked = mode === 'stacked' || (mode === 'auto' && size != null && size.w < stackedBelow);\n const phone = size != null && size.w < PHONE;\n // Stacked, the column scrolls and never zooms.\n // The zoom takes at most the window's height: a layout an app lets grow with its content would otherwise zoom in on\n // its own height.\n const zoomH = size ? Math.min(size.h, (typeof window !== 'undefined' && window.innerHeight) || size.h) : 0;\n const zoom = size && !stacked ? consoleZoom(size.w, zoomH) : 1;\n const logicalH = size ? size.h / zoom : 0;\n const allowed = (extras ?? []).filter((x) => stacked || x.minHeight == null || logicalH >= x.minHeight);\n const fit = useExtrasFit(sideRef, stacked ? -1 : allowed.length, `${allowed.map((x) => x.id).join('|')}|${size?.w}|${size?.h}|${zoom}`);\n const frameStyle: React.CSSProperties | undefined =\n size && !stacked && zoom !== 1 ? ({ zoom, width: size.w / zoom, height: size.h / zoom } as React.CSSProperties) : undefined;\n\n const top = (\n <header className=\"ui-console-top\">\n <div className=\"ui-console-start\">\n <h1 className=\"ui-console-title\">{title}</h1>\n {tags}\n </div>\n <div className=\"ui-console-end\">\n {status != null ? <span className=\"ui-console-status\">{status}</span> : null}\n {kpis != null ? <div className=\"ui-console-kpis\">{kpis}</div> : null}\n {clock != null ? <span className=\"ui-console-clock\">{clock}</span> : null}\n {fullscreen && canFull && !phone ? (\n <IconButton label={full ? tr('離開全螢幕') : tr('全螢幕')} icon={full ? 'corners-in' : 'corners-out'} onClick={toggleFull} />\n ) : null}\n </div>\n </header>\n );\n\n return (\n <div ref={ref} className={cx('ui-console', stacked && 'is-stacked', className)}>\n <div className={cx('ui-console-frame', bottom == null && 'no-bottom')} style={frameStyle}>\n {top}\n {/* The main landmark draws no box (display: contents): the main view and the bottom row stay grid cells, and\n stacked, the whole column after the top bar is in it. */}\n <main className=\"ui-console-content\">\n <div className=\"ui-console-main\">{main}</div>\n {stacked ? (\n <>\n {side != null ? <div className=\"ui-console-cards\">{side}</div> : null}\n {bottom}\n {allowed.length ? (\n <div className=\"ui-console-cards\">\n {allowed.map((x) => (\n <React.Fragment key={x.id}>{x.node}</React.Fragment>\n ))}\n </div>\n ) : null}\n </>\n ) : bottom != null ? (\n <div className=\"ui-console-bottom\">{bottom}</div>\n ) : null}\n </main>\n {stacked ? null : (\n <aside ref={sideRef} className=\"ui-console-side\" aria-label={tr('側欄')}>\n {side}\n {/* Each extra in a wrapper that is measured; one that does not fit is laid out out of sight, at no height,\n so it is measured again when the panel grows. */}\n {allowed.map((x, i) => {\n const out = i >= fit;\n return (\n <div key={x.id} className={cx('ui-console-extra', out && 'is-out')} data-extra=\"\" aria-hidden={out || undefined} inert={out || undefined}>\n {x.node}\n </div>\n );\n })}\n </aside>\n )}\n </div>\n </div>\n );\n}\n\n/** How many extras fit in the side panel under its other cards, each at its own height, in order. n is how many there\n * are (-1: none are measured, stacked). Measured again when the panel or any card changes size. */\nfunction useExtrasFit(sideRef: React.RefObject<HTMLElement | null>, n: number, key: string): number {\n const [fit, setFit] = React.useState(0);\n React.useLayoutEffect(() => {\n const side = sideRef.current;\n if (!side || n <= 0) return setFit(0);\n const measure = () => {\n const cs = getComputedStyle(side);\n const gap = parseFloat(cs.rowGap) || 0;\n const room = side.clientHeight - (parseFloat(cs.paddingTop) || 0) - (parseFloat(cs.paddingBottom) || 0);\n const kids = [...side.children] as HTMLElement[];\n const cards = kids.filter((k) => !k.hasAttribute('data-extra'));\n const extraEls = kids.filter((k) => k.hasAttribute('data-extra'));\n devWarn(\n cards.some((k) => k.scrollHeight > k.clientHeight + 1 && !/auto|scroll/.test(getComputedStyle(k).overflowY)),\n 'ConsoleLayout',\n 'a side card is shorter than its content, so the content is cut. Keep side cards at their own height: do not give them flex: 1 or min-height: 0; the side panel scrolls when they do not fit.',\n );\n let used = cards.reduce((t, k, i) => t + k.offsetHeight + (i ? gap : 0), 0);\n let count = 0;\n for (const ex of extraEls) {\n // An extra out of sight has no height of its own: its card's height counts.\n const h = ex.classList.contains('is-out') ? ((ex.firstElementChild as HTMLElement | null)?.offsetHeight ?? 0) : ex.offsetHeight;\n const need = h + (used > 0 ? gap : 0);\n if (used + need > room + 0.5) break;\n used += need;\n count++;\n }\n setFit((f) => (f === count ? f : count));\n };\n measure();\n if (typeof ResizeObserver !== 'function') return;\n const ro = new ResizeObserver(measure);\n ro.observe(side);\n for (const k of side.children) {\n ro.observe(k);\n if (k.firstElementChild) ro.observe(k.firstElementChild);\n }\n return () => ro.disconnect();\n }, [sideRef, n, key]);\n return n < 0 ? 0 : fit;\n}\n"],"mappings":";;;;;;;;;;;AASA,aAAaA,oBAAaC,mBAAY;;AAiDtC,MAAM,SAAS;AACf,MAAM,SAAS;AACf,MAAM,WAAW;AACjB,MAAM,gBAAgB;AACtB,MAAM,QAAQ;AAEd,MAAM,0BAA0B,CAAC;AACjC,MAAM,0BAA0B,OAAO,aAAa,eAAe,SAAS,sBAAsB;AAClG,MAAM,oBAAoB;;AAG1B,SAAgB,YAAY,GAAW,GAAmB;CACxD,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,UAAU,KAAK,IAAI,IAAI,QAAQ,IAAI,MAAM,CAAC,CAAC;AACzE;;;;AAKA,SAAgB,cAAc,EAC5B,OACA,MACA,QACA,MACA,OACA,aAAa,MACb,MACA,MACA,QACA,QACA,eAAe,eACf,OAAO,QACP,aACqB;CACrB,MAAM,MAAM,MAAM,OAAuB,IAAI;CAC7C,MAAM,UAAU,MAAM,OAAoB,IAAI;CAC9C,MAAM,CAAC,MAAM,WAAW,MAAM,SAA0C,IAAI;CAC5E,MAAM,CAAC,MAAM,WAAW,MAAM,SAAS,KAAK;CAE5C,MAAM,UAAU,MAAM,qBAAqB,aAAa,mBAAmB,WAAW;CAEtF,MAAM,sBAAsB;EAC1B,MAAM,KAAK,IAAI;EACf,IAA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,GAAG,MAAM,IAAI,EAAE,gBAAgB,IAAI,MAAM,IAAI,CAAC;GAC1E,IAAI,QAAQ;GACZ,KAAK,MAAM,MAAM,UAAU;IAGzB,MAAM,QADI,GAAG,UAAU,SAAS,QAAQ,IAAM,GAAG,mBAA0C,gBAAgB,IAAK,GAAG,iBACjG,OAAO,IAAI,MAAM;IACnC,IAAI,OAAO,OAAO,OAAO,IAAK;IAC9B,QAAQ;IACR;GACF;GACA,QAAQ,MAAO,MAAM,QAAQ,IAAI,KAAM;EACzC;EACA,QAAQ;EACR,IAAI,OAAO,mBAAmB,YAAY;EAC1C,MAAM,KAAK,IAAI,eAAe,OAAO;EACrC,GAAG,QAAQ,IAAI;EACf,KAAK,MAAM,KAAK,KAAK,UAAU;GAC7B,GAAG,QAAQ,CAAC;GACZ,IAAI,EAAE,mBAAmB,GAAG,QAAQ,EAAE,iBAAiB;EACzD;EACA,aAAa,GAAG,WAAW;CAC7B,GAAG;EAAC;EAAS;EAAG;CAAG,CAAC;CACpB,OAAO,IAAI,IAAI,IAAI;AACrB"}
@@ -13,6 +13,20 @@ export interface FloorPlanZone extends Omit<Zone, 'area'> {
13
13
  emphasis?: 'primary' | 'muted';
14
14
  /** The id of the group it belongs to (`groups`). */
15
15
  group?: string;
16
+ /** Higher numbers get label room first (default 0); among equals, primary zones and then smaller ones first. The
17
+ * selected zone always gets room first. */
18
+ labelPriority?: number;
19
+ /** More lines in the tooltip after `detail`, e.g. 「濕度 48 %」; screen readers read them too. */
20
+ tooltip?: string[];
21
+ }
22
+ /** Where the plan is looked at: the centre in metres (y up) and the zoom (1 is the whole plan, at most 8). */
23
+ export interface FloorPlanView {
24
+ /** Centre, east–west, in metres. */
25
+ x: number;
26
+ /** Centre, south–north, in metres (y up). */
27
+ y: number;
28
+ /** 1: the whole plan; up to 8. */
29
+ zoom: number;
16
30
  }
17
31
  export interface FloorPlanGroup {
18
32
  /** Unique id, named by the zones' `group`. */
@@ -56,6 +70,12 @@ export interface FloorPlanProps {
56
70
  /** The plan grows to fill the height it is given (in ConsoleLayout's main view, or any flex column), never below
57
71
  * 240 px. Without it the plan keeps the outline's proportions, 240 to 640 px high. */
58
72
  fill?: boolean;
73
+ /** The view to start from (e.g. the one onViewChange last gave, when the plan is shown again). Default: the whole
74
+ * plan. */
75
+ defaultView?: FloorPlanView;
76
+ /** The view changed and settled (after a drag, a pinch, a wheel step, a key or a button): keep it to start from it
77
+ * next time. */
78
+ onViewChange?: (view: FloorPlanView) => void;
59
79
  /** Extra class on the root element. */
60
80
  className?: string;
61
81
  }
@@ -1,8 +1,7 @@
1
1
  "use client";
2
2
  import { devWarn } from "../../internal/dev.js";
3
3
  import { cssZoom, cx, reduced, resizeObserver, useMedia, useNarrow } from "../../internal/util.js";
4
- import { heatRange, noData, zoneText } from "../../internal/zone.js";
5
- import { format } from "../../format.js";
4
+ import { heatRange, noData, signedNumber, zoneText } from "../../internal/zone.js";
6
5
  import { tr } from "../../i18n.js";
7
6
  import corners_out_default from "../../icons/ph/corners-out.js";
8
7
  import minus_default from "../../icons/ph/minus.js";
@@ -86,6 +85,31 @@ function zoneOrder(zones) {
86
85
  const area = new Map(zones.map((z) => [z, polygonArea(z.outline)]));
87
86
  return [...zones].sort((a, b) => Number(a.emphasis === "muted") - Number(b.emphasis === "muted") || (area.get(a) ?? 0) - (area.get(b) ?? 0));
88
87
  }
88
+ /** The order labels get room in: the selected zone, then higher `labelPriority`, then primary before muted, then the
89
+ * smaller area first. */
90
+ function labelOrder(zones, selected) {
91
+ const area = new Map(zones.map((z) => [z, polygonArea(z.outline)]));
92
+ return [...zones].sort((a, b) => Number(b.id === selected) - Number(a.id === selected) || (b.labelPriority ?? 0) - (a.labelPriority ?? 0) || Number(a.emphasis === "muted") - Number(b.emphasis === "muted") || (area.get(a) ?? 0) - (area.get(b) ?? 0));
93
+ }
94
+ /** A view as a viewBox of the plan's box (base), and back. */
95
+ function viewBoxOf(v, base) {
96
+ const zoom = Math.min(8, Math.max(1, v.zoom));
97
+ const w = base.w / zoom;
98
+ const h = base.h / zoom;
99
+ return {
100
+ x: v.x - w / 2,
101
+ y: -v.y - h / 2,
102
+ w,
103
+ h
104
+ };
105
+ }
106
+ function viewOf(b, base) {
107
+ return {
108
+ x: b.x + b.w / 2,
109
+ y: -(b.y + b.h / 2),
110
+ zoom: base.w / b.w
111
+ };
112
+ }
89
113
  /** The screen transform for a viewBox shown in W × H px (preserveAspectRatio xMidYMid meet): px per metre, and the
90
114
  * screen point of a point in metres (y up). */
91
115
  function screenOf(view, W, H) {
@@ -159,6 +183,20 @@ function placeLabels(items, view, W, H, taken = []) {
159
183
  }
160
184
  return out;
161
185
  }
186
+ /** A view kept inside the plan: zoom 1 to MAX_ZOOM, the centre on the plan; the whole plan does not pan. */
187
+ function clampTo(v, base) {
188
+ if (v.w >= base.w * .999) return base;
189
+ const w = Math.max(base.w / MAX_ZOOM, v.w);
190
+ const h = w * base.h / base.w;
191
+ const cx = Math.min(base.x + base.w, Math.max(base.x, v.x + v.w / 2));
192
+ const cy = Math.min(base.y + base.h, Math.max(base.y, v.y + v.h / 2));
193
+ return {
194
+ x: cx - w / 2,
195
+ y: cy - h / 2,
196
+ w,
197
+ h
198
+ };
199
+ }
162
200
  /** A pointer position in CSS px from an element's top left corner (screen px divided by any CSS zoom). */
163
201
  function localPoint(el, e) {
164
202
  const r = el.getBoundingClientRect();
@@ -197,43 +235,41 @@ function FloorPlan({ zones, label, groups = [], shell, edges = [], legend = true
197
235
  }, []);
198
236
  const [W, H] = size;
199
237
  const baseKey = `${base.x},${base.y},${base.w},${base.h}`;
200
- const [viewState, setViewState] = React.useState({
238
+ const [viewState, setViewState] = React.useState(() => ({
201
239
  key: baseKey,
202
- view: base
203
- });
240
+ view: p.defaultView ? clampTo(viewBoxOf(p.defaultView, base), base) : base
241
+ }));
204
242
  const view = viewState.key === baseKey ? viewState.view : base;
205
243
  const setView = React.useCallback((v) => setViewState({
206
244
  key: baseKey,
207
245
  view: v
208
246
  }), [baseKey]);
209
- const clampView = React.useCallback((v) => {
210
- if (v.w >= base.w * .999) return base;
211
- const w = Math.max(base.w / MAX_ZOOM, v.w);
212
- const h = w * base.h / base.w;
213
- const cx = Math.min(base.x + base.w, Math.max(base.x, v.x + v.w / 2));
214
- const cy = Math.min(base.y + base.h, Math.max(base.y, v.y + v.h / 2));
215
- return {
216
- x: cx - w / 2,
217
- y: cy - h / 2,
218
- w,
219
- h
220
- };
221
- }, [base]);
247
+ const clampView = React.useCallback((v) => clampTo(v, base), [base]);
248
+ const onViewChange = p.onViewChange;
249
+ const settle = React.useCallback((b) => onViewChange?.(viewOf(b, base)), [onViewChange, base]);
222
250
  const viewRef = React.useRef(view);
223
251
  React.useLayoutEffect(() => {
224
252
  viewRef.current = view;
225
253
  });
226
254
  const anim = React.useRef(0);
227
- const goTo = React.useCallback((to, animate) => {
255
+ const goTo = React.useCallback((to, animate, notify = true) => {
228
256
  cancelAnimationFrame(anim.current);
229
257
  const target = clampView(to);
230
- if (!animate || reduced() || typeof requestAnimationFrame !== "function") return setView(target);
258
+ if (!animate || reduced() || typeof requestAnimationFrame !== "function") {
259
+ setView(target);
260
+ if (notify) settle(target);
261
+ return;
262
+ }
231
263
  const from = viewRef.current;
232
264
  const t0 = performance.now();
233
265
  const step = (now) => {
234
266
  const t = Math.min(1, (now - t0) / 200);
235
267
  const e = 1 - (1 - t) ** 3;
236
- if (t >= 1) return setView(target);
268
+ if (t >= 1) {
269
+ setView(target);
270
+ settle(target);
271
+ return;
272
+ }
237
273
  setView({
238
274
  x: from.x + (target.x - from.x) * e,
239
275
  y: from.y + (target.y - from.y) * e,
@@ -243,10 +279,14 @@ function FloorPlan({ zones, label, groups = [], shell, edges = [], legend = true
243
279
  anim.current = requestAnimationFrame(step);
244
280
  };
245
281
  anim.current = requestAnimationFrame(step);
246
- }, [clampView, setView]);
282
+ }, [
283
+ clampView,
284
+ setView,
285
+ settle
286
+ ]);
247
287
  React.useEffect(() => () => cancelAnimationFrame(anim.current), []);
248
288
  /** Zoom by factor around a screen point (px in the drawing); default its middle. */
249
- const zoomAt = React.useCallback((factor, px = W / 2, py = H / 2, animate = false) => {
289
+ const zoomAt = React.useCallback((factor, px = W / 2, py = H / 2, animate = false, notify = true) => {
250
290
  const v = viewRef.current;
251
291
  const { back } = screenOf(v, W, H);
252
292
  const [mx, my] = back(px, py);
@@ -258,7 +298,7 @@ function FloorPlan({ zones, label, groups = [], shell, edges = [], legend = true
258
298
  y: fy - (fy - v.y) / v.h * h,
259
299
  w,
260
300
  h
261
- }, animate);
301
+ }, animate, notify);
262
302
  }, [
263
303
  W,
264
304
  H,
@@ -312,16 +352,17 @@ function FloorPlan({ zones, label, groups = [], shell, edges = [], legend = true
312
352
  ...v,
313
353
  x: v.x - (now[0] - prev[0]) / s,
314
354
  y: v.y - (now[1] - prev[1]) / s
315
- }, false);
355
+ }, false, false);
316
356
  pointers.current.set(e.pointerId, now);
317
357
  if (pointers.current.size === 2) {
318
358
  const [a, b] = [...pointers.current.values()];
319
359
  const d = Math.hypot(a[0] - b[0], a[1] - b[1]);
320
- if (g.dist) zoomAt(d / g.dist, (a[0] + b[0]) / 2, (a[1] + b[1]) / 2);
360
+ if (g.dist) zoomAt(d / g.dist, (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, false, false);
321
361
  g.dist = d;
322
362
  }
323
363
  };
324
364
  const onPointerUp = (e) => {
365
+ if (pointers.current.has(e.pointerId) && pointers.current.size === 1 && gesture.current.moved) settle(viewRef.current);
325
366
  pointers.current.delete(e.pointerId);
326
367
  if (pointers.current.size < 2) gesture.current.dist = void 0;
327
368
  };
@@ -355,7 +396,7 @@ function FloorPlan({ zones, label, groups = [], shell, edges = [], legend = true
355
396
  const coarse = useMedia("(pointer: coarse)");
356
397
  const scr = screenOf(view, W, H);
357
398
  const s = scr.s;
358
- const texts = new Map(zones.map((z) => [z.id, zoneText(z, min, max, z.emphasis === "muted" ? [tr("次要")] : [])]));
399
+ const texts = new Map(zones.map((z) => [z.id, zoneText(z, min, max, z.emphasis === "muted" ? [tr("次要")] : [], z.tooltip)]));
359
400
  const textOf = (z) => texts.get(z.id) ?? zoneText(z, min, max);
360
401
  const groupBoxes = [];
361
402
  for (const g of groups) {
@@ -380,7 +421,7 @@ function FloorPlan({ zones, label, groups = [], shell, edges = [], legend = true
380
421
  }
381
422
  };
382
423
  });
383
- const spots = placeLabels(order.map((z) => {
424
+ const spots = placeLabels(labelOrder(zones, p.value).map((z) => {
384
425
  const t = textOf(z);
385
426
  const muted = z.emphasis === "muted" || noData(z);
386
427
  const warn = !!z.tone && z.tone !== "normal";
@@ -715,7 +756,8 @@ function FloorPlan({ zones, label, groups = [], shell, edges = [], legend = true
715
756
  tr(",") + tipText.state,
716
757
  tipZone.emphasis === "muted" ? tr(",") + tr("次要") : ""
717
758
  ] }),
718
- tipZone.detail ? /* @__PURE__ */ jsx("span", { children: tipZone.detail }) : null
759
+ tipZone.detail ? /* @__PURE__ */ jsx("span", { children: tipZone.detail }) : null,
760
+ (tipZone.tooltip ?? []).map((line, k) => /* @__PURE__ */ jsx("span", { children: line }, k))
719
761
  ]
720
762
  }) : null,
721
763
  /* @__PURE__ */ jsxs("div", {
@@ -753,7 +795,8 @@ function FloorPlan({ zones, label, groups = [], shell, edges = [], legend = true
753
795
  warn: p.warn,
754
796
  limit: p.limit,
755
797
  decimals: zones.find((z) => z.decimals != null)?.decimals ?? 1,
756
- muted: hasMuted
798
+ muted: hasMuted,
799
+ signed: zones.some((z) => z.value != null) && zones.every((z) => z.value == null || z.signed)
757
800
  }) : null
758
801
  ]
759
802
  });
@@ -769,9 +812,10 @@ function tipStyle(x, y, W, H) {
769
812
  bottom: below ? void 0 : Math.max(4, H - y + 10)
770
813
  };
771
814
  }
772
- function Legend({ min, max, unit, warn, limit, decimals, muted }) {
815
+ function Legend({ min, max, unit, warn, limit, decimals, muted, signed = false }) {
773
816
  const pct = (v) => `${Math.min(100, Math.max(0, (v - min) / (max - min) * 100))}%`;
774
- const num = (v) => format.number(v, decimals) + (unit ? " " + unit : "");
817
+ const fmt = (v) => signedNumber(v, decimals, signed);
818
+ const num = (v) => fmt(v) + (unit ? " " + unit : "");
775
819
  return /* @__PURE__ */ jsxs("div", {
776
820
  className: "ui-fp-legend",
777
821
  children: [
@@ -780,7 +824,7 @@ function Legend({ min, max, unit, warn, limit, decimals, muted }) {
780
824
  children: [
781
825
  /* @__PURE__ */ jsx("span", {
782
826
  className: "ui-fp-num",
783
- children: format.number(min, decimals)
827
+ children: fmt(min)
784
828
  }),
785
829
  /* @__PURE__ */ jsxs("span", {
786
830
  className: "ui-fp-bar",
@@ -806,7 +850,7 @@ function Legend({ min, max, unit, warn, limit, decimals, muted }) {
806
850
  }),
807
851
  /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("span", {
808
852
  className: "ui-fp-num",
809
- children: format.number(max, decimals)
853
+ children: fmt(max)
810
854
  }), unit ? "\xA0" + unit : ""] })
811
855
  ]
812
856
  }),
@@ -825,6 +869,6 @@ function Legend({ min, max, unit, warn, limit, decimals, muted }) {
825
869
  ]
826
870
  });
827
871
  }
828
- export { FloorPlan, insidePolygon, placeLabels, planBox, polygonArea, polygonPath, ringPath, screenOf, textWidth, zoneOrder };
872
+ export { FloorPlan, insidePolygon, labelOrder, placeLabels, planBox, polygonArea, polygonPath, ringPath, screenOf, textWidth, viewBoxOf, viewOf, zoneOrder };
829
873
 
830
874
  //# sourceMappingURL=FloorPlan.js.map