Compare commits
2
Commits
89989c04e9
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9889ce1025 | ||
|
|
e223dc61c8 |
No files matched your search
@@ -4,6 +4,10 @@ A productivity toolkit that enhances PowerPoint with specialized formatting and
|
||||
|
||||

|
||||
|
||||
The add-in opens as a task pane with a header, collapsible tool sections, and a
|
||||
status bar docked at the bottom for progress and results. All sections start
|
||||
collapsed; click a section title to expand it.
|
||||
|
||||
## Features
|
||||
|
||||
### Content Tools
|
||||
@@ -29,8 +33,9 @@ A productivity toolkit that enhances PowerPoint with specialized formatting and
|
||||
|
||||
- **Custom Grid**: Create a grid on the current slide with adjustable spacing, opacity, and color.
|
||||
- **Guidelines**: Add horizontal or vertical guidelines at specific positions with customizable colors.
|
||||
- **Raster**: Add a wireframe cell grid (12 × 8, 24 × 16, or custom) to the current slide, this slide's layout, or the slide master for placing objects, then remove it.
|
||||
|
||||
> Grids and guidelines are ordinary slide shapes. They are included in slideshow, print, and export output. Remove them before presenting.
|
||||
> Grids, guidelines, and raster cells are ordinary shapes. They are included in slideshow, print, and export output. Remove them before presenting.
|
||||
|
||||
### Settings
|
||||
|
||||
@@ -192,14 +197,28 @@ manifest.xml # Add-in manifest
|
||||
|
||||
1. Navigate to the slide where the grid should appear.
|
||||
2. Set spacing (minimum 4 pt), opacity (0–100), and color.
|
||||
3. Click **Add** to create the grid. Click **Remove** to delete it.
|
||||
3. Click **Add grid** to create the grid. Click **Remove grid** to delete it.
|
||||
4. The grid is a set of shapes on the current slide and appears in slideshow/export output.
|
||||
|
||||
#### Guidelines
|
||||
|
||||
1. Set the position, orientation, and color.
|
||||
2. Click **Add** to create a guideline.
|
||||
3. Click **Remove** to delete all guidelines on the current slide.
|
||||
2. Click **Add guide** to create a guideline.
|
||||
3. Click **Remove guides** to delete all guidelines on the current slide.
|
||||
|
||||
#### Raster
|
||||
|
||||
1. Select the slide where objects should be placed.
|
||||
2. Choose **Place on**:
|
||||
- **Current slide** - sits on top of the slide content.
|
||||
- **This slide's layout (background)** - sits behind content on every slide using that layout.
|
||||
- **Slide master (all slides)** - sits behind content on every slide in the presentation.
|
||||
3. Choose the **12 × 8** or **24 × 16** preset, or select **Custom** and enter columns, rows, gutter, and opacity.
|
||||
4. Pick a color. Gray at 100 % matches the template wireframes; lower opacity keeps existing content visible.
|
||||
5. Click **Add raster**. Any existing raster in the presentation is replaced, so only one raster is active at a time.
|
||||
6. Click **Remove raster** before presenting. This removes it from the current slide, all layouts, and the slide master.
|
||||
|
||||
The hint below the controls shows the resulting cell size in millimetres and the number of cells (maximum 600). Layout/master rasters are background graphics and do not appear on slides that use **Hide Background Graphics**. Because a layout/master raster is inherited by every slide that uses it, prefer **12 × 8** on large presentations.
|
||||
|
||||
## Tips
|
||||
|
||||
@@ -208,6 +227,12 @@ manifest.xml # Add-in manifest
|
||||
- **Long operations**: A progress counter and **Stop** button appear for large presentations.
|
||||
- **Destructive actions**: Removals and Insert Titles ask for confirmation.
|
||||
|
||||
## Documentation
|
||||
|
||||
- [User Guide](docs/USER_GUIDE.md)
|
||||
- [Developer Guide](docs/DEVELOPERS.md)
|
||||
- [UI Guidelines](docs/UI_GUIDELINES.md)
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||
|
||||
+32
-7
@@ -44,9 +44,11 @@ The diagrams under `docs/` predate the context/service refactoring and should be
|
||||
│ │ ├── MatchProperties.tsx
|
||||
│ │ ├── MatchSizes.tsx
|
||||
│ │ ├── ProgressBarButtons.tsx
|
||||
│ │ ├── RasterManager.tsx
|
||||
│ │ ├── RoundImage.tsx
|
||||
│ │ ├── SwapPositions.tsx
|
||||
│ │ └── commonStyles.tsx
|
||||
│ │ ├── commonStyles.tsx
|
||||
│ │ └── ColorSwatches.tsx
|
||||
│ ├── context/
|
||||
│ │ ├── SettingsContext.tsx # Slide size preset (persisted)
|
||||
│ │ └── StatusContext.tsx # Status, processing, progress
|
||||
@@ -54,6 +56,7 @@ The diagrams under `docs/` predate the context/service refactoring and should be
|
||||
│ │ ├── cancellation.ts # Cooperative cancellation flag
|
||||
│ │ ├── markers.ts # Confidential/draft markers
|
||||
│ │ ├── progressBar.ts # Progress bar add/remove
|
||||
│ │ ├── raster.ts # Raster geometry + slide/layout/master targets
|
||||
│ │ └── titles.ts # Title collection + ranking
|
||||
│ ├── types/
|
||||
│ │ ├── office-types.ts # Office.js helpers
|
||||
@@ -194,6 +197,7 @@ For raw Fluent buttons that need a confirmation dialog:
|
||||
onConfirm={remove}
|
||||
confirmTitle="Remove the grid?"
|
||||
confirmMessage="This removes the grid from the current slide."
|
||||
confirmLabel="Remove"
|
||||
>
|
||||
Remove
|
||||
</ConfirmButton>
|
||||
@@ -201,12 +205,15 @@ For raw Fluent buttons that need a confirmation dialog:
|
||||
|
||||
### Section
|
||||
|
||||
Collapsible grouping with consistent styling:
|
||||
A single disclosure item. `Section` renders an `AccordionItem`, so it must be
|
||||
placed inside the shared `Accordion` in `App.tsx`:
|
||||
|
||||
```tsx
|
||||
<Section title="My Feature">
|
||||
<MyFeatureComponent />
|
||||
</Section>
|
||||
<Accordion multiple collapsible defaultOpenItems={["content"]}>
|
||||
<Section title="My Feature">
|
||||
<MyFeatureComponent />
|
||||
</Section>
|
||||
</Accordion>
|
||||
```
|
||||
|
||||
## Creating a New Tool
|
||||
@@ -350,6 +357,21 @@ Test pure functions and helpers directly. Office.js interactions should be kept
|
||||
|
||||
Continuous integration runs lint, typecheck, tests, build, and manifest validation on every push and pull request.
|
||||
|
||||
## UI Guidelines
|
||||
|
||||
The pane follows Fluent 2 and Microsoft's Office Add-in UX guidance. The full
|
||||
rules and review checklist live in [`docs/UI_GUIDELINES.md`](UI_GUIDELINES.md).
|
||||
|
||||
Key points:
|
||||
|
||||
- Use Fluent tokens for colour, spacing, type, radius, and motion. No literal
|
||||
hex values in UI styles (slide colours are the exception).
|
||||
- Keep one scroll container. Sections must not set `maxHeight` or `overflow`.
|
||||
- All action buttons use the blue primary style; destructive actions are
|
||||
confirmed by a dialog.
|
||||
- Labels are verb + object, with a short hint when a selection is required.
|
||||
- Keep the single always-mounted `role="status"` region for feedback.
|
||||
|
||||
## Performance Guidelines
|
||||
|
||||
- **Batch `context.sync()` calls.** Load all needed properties, then sync once.
|
||||
@@ -366,12 +388,15 @@ Continuous integration runs lint, typecheck, tests, build, and manifest validati
|
||||
4. Add confirmations for destructive operations.
|
||||
5. Make repeated add operations idempotent.
|
||||
6. Use Fluent `Field`/`Input`/`Dropdown` controls so labels and keyboard navigation work.
|
||||
7. Announce results through the status region (`role="status"`).
|
||||
8. Update docs when behavior changes.
|
||||
7. Use design tokens and follow `docs/UI_GUIDELINES.md` for any new UI.
|
||||
8. Announce results through the status region (`role="status"`).
|
||||
9. Update docs when behavior changes.
|
||||
|
||||
## Resources
|
||||
|
||||
- [Office Add-ins documentation](https://learn.microsoft.com/office/dev/add-ins/)
|
||||
- [Office Add-in UX design guidelines](https://learn.microsoft.com/office/dev/add-ins/design/add-in-design)
|
||||
- [Office.js API reference](https://learn.microsoft.com/javascript/api/overview/office)
|
||||
- [Fluent UI React v9](https://react.fluentui.dev/)
|
||||
- [Fluent 2 design system](https://fluent2.microsoft.design/)
|
||||
- [Vitest](https://vitest.dev/)
|
||||
@@ -0,0 +1,127 @@
|
||||
# Edison UI Guidelines
|
||||
|
||||
The task pane follows **Fluent 2** (`@fluentui/react-components` v9) and Microsoft's
|
||||
[Office Add-in UX guidelines](https://learn.microsoft.com/office/dev/add-ins/design/add-in-design),
|
||||
including WCAG 2.1 AA expectations. This document records the rules the codebase
|
||||
follows so new tools stay consistent.
|
||||
|
||||
## Structure
|
||||
|
||||
The pane has three fixed regions (`src/taskpane/components/App.tsx`):
|
||||
|
||||
1. **Header** — Edison icon, name, and a short descriptor. Gives the pane identity
|
||||
when several add-ins are open.
|
||||
2. **Scroll area** — one vertical scroll owner containing a single `Accordion`
|
||||
with one `Section` per tool group.
|
||||
3. **Status dock** — always-mounted `role="status"` live region at the bottom.
|
||||
It shows progress with a Stop button while processing, then the result.
|
||||
|
||||
Rules:
|
||||
|
||||
- Never add a second scroll container. Do not put `overflow: auto` or a fixed
|
||||
`maxHeight` inside a section; the pane scrolls as a whole.
|
||||
- `Section` renders an `AccordionItem`, so it must be a child of an `Accordion`.
|
||||
- All sections start collapsed. Use `multiple` on the `Accordion` so several
|
||||
groups can stay open.
|
||||
|
||||
## Design tokens
|
||||
|
||||
Use Fluent tokens for every colour, spacing, radius, shadow, and font value.
|
||||
|
||||
| Concern | Use |
|
||||
|---|---|
|
||||
| Colours | `tokens.colorNeutral*`, `tokens.colorBrand*`, `tokens.colorPalette*` |
|
||||
| Spacing | `tokens.spacingHorizontal*`, `tokens.spacingVertical*` |
|
||||
| Type | `tokens.fontFamilyBase`, `tokens.fontSizeBase200/300/400`, `tokens.fontWeightSemibold` |
|
||||
| Radius | `tokens.borderRadiusMedium` |
|
||||
| Elevation | `tokens.shadow2`, `tokens.shadow4` |
|
||||
| Motion | `tokens.durationNormal`, `tokens.curveEasyEase` |
|
||||
|
||||
- No literal hex colours in UI styles. The only exceptions are the colours that
|
||||
are written **into the slide** (grid, guideline, marking, watermark).
|
||||
- Do not hand-roll shadows or theme-dependent colours; that is what broke dark
|
||||
mode before v1.2.0.
|
||||
- Placeholder/loading chrome in `taskpane.html` uses CSS variables with a
|
||||
`prefers-color-scheme: dark` override.
|
||||
|
||||
## Typography and spacing
|
||||
|
||||
- Body text: `fontSizeBase300` (14 px). Metadata and hints: `fontSizeBase200`.
|
||||
- Section headings: `fontSizeBase400` + `fontWeightSemibold`, neutral foreground.
|
||||
- Pane padding: `spacingHorizontalL` (16 px). Gaps between related controls:
|
||||
`spacingVerticalS`/`spacingHorizontalS` (8 px); between tool groups:
|
||||
`spacingVerticalM` (12 px) via `Section`'s stack.
|
||||
- Prefer `gap` on flex containers over spacer `<div>` elements.
|
||||
- Do not use `Text size={100}` (10 px); it is below the readable minimum.
|
||||
|
||||
## Action hierarchy
|
||||
|
||||
The pane uses one button style: **all action buttons are blue** (`appearance="primary"`),
|
||||
including secondary actions, Remove, Cancel, and Stop. This keeps the controls
|
||||
visually consistent across sections.
|
||||
|
||||
| Action | Appearance |
|
||||
|---|---|
|
||||
| Every action button (run, add, remove, cancel, stop) | `primary` |
|
||||
| Colour swatches | keep the swatch colour (never brand blue) |
|
||||
| Horizontal/vertical direction toggles | `outline`, stateful |
|
||||
|
||||
- Keep destructive actions visually confirmed by a dialog even though the
|
||||
trigger is blue.
|
||||
- Dialog copy states exactly what will be removed or replaced. Cancel keeps
|
||||
initial focus.
|
||||
- Colour swatches are the one exception: they must show the colour that will be
|
||||
written to the slide.
|
||||
|
||||
## Labels and copy
|
||||
|
||||
- Buttons use **verb + object**: "Add progress bar", "Remove guides",
|
||||
"Match properties" — not "Add" / "Remove" on their own.
|
||||
- Section titles are nouns ("Grid & Guidelines"), matching the User Guide.
|
||||
- Add a one-line hint (`useCommonStyles().hint`, `Text size={200}`) above a tool
|
||||
when the selection requirement is not obvious ("Select exactly two shapes").
|
||||
- Avoid duplicating a section title in every button tooltip.
|
||||
|
||||
## Forms and groups
|
||||
|
||||
- One control → `Field label`. `Input` and `Dropdown` are field-aware, so the
|
||||
label is associated automatically.
|
||||
- A set of related controls (colour swatches, direction toggle) → visible `Text`
|
||||
label plus a `role="group"` container with `aria-labelledby`.
|
||||
- `Field`/`Dropdown` fill the pane width (`width: 100%`); numeric inputs may be
|
||||
capped (`maxWidth: 180px`).
|
||||
- Colour swatches are at least 32×32 px, show a check icon for the selected
|
||||
value (not colour alone — WCAG 1.4.1), and expose `aria-pressed`.
|
||||
|
||||
## Feedback and accessibility
|
||||
|
||||
- Keep exactly one `role="status"` region mounted for the lifetime of the pane.
|
||||
It announces progress and results without moving focus.
|
||||
- Success messages auto-clear after 5 seconds; warnings and errors stay until
|
||||
the next action.
|
||||
- Icon-only controls need an accessible name (`aria-label` or a Fluent `Tooltip`
|
||||
with `relationship="label"`).
|
||||
- Do not rely on `title` alone for the accessible name.
|
||||
- Every interactive control must be reachable and operable by keyboard.
|
||||
- Target size: at least 32×32 px for icon-only controls; primary buttons are
|
||||
full width of their container.
|
||||
- Status text must not be the only indication of an error; the icon and colour
|
||||
are paired with a message.
|
||||
|
||||
## Responsive behaviour
|
||||
|
||||
- Design for the minimum task-pane width (320 px). The pane can be narrower when
|
||||
docked; the two-column button grids collapse to one column below 360 px
|
||||
(`@media (max-width: 360px)`).
|
||||
- Prefer wrapping toolbars and full-width controls over horizontal scrolling.
|
||||
- Test at 320 px and ~480 px, in light and dark mode, with a collapsed section.
|
||||
|
||||
## Review checklist
|
||||
|
||||
- [ ] Only tokens for colours, spacing, type, radius, and motion
|
||||
- [ ] All action buttons use the blue primary style; destructive actions confirmed
|
||||
- [ ] Labels are verb + object; hints explain selection requirements
|
||||
- [ ] One scroll container; no nested `maxHeight`/`overflow`
|
||||
- [ ] Single always-mounted live region
|
||||
- [ ] Icon-only controls have accessible names
|
||||
- [ ] Works at 320 px, light and dark, keyboard only
|
||||
+54
-3
@@ -14,15 +14,22 @@ This guide will help you use the Edison PowerPoint Add-in to create professional
|
||||
|
||||
### Interface Overview
|
||||
|
||||
The Edison task pane is organized into collapsible sections:
|
||||
The Edison task pane has three areas:
|
||||
|
||||
- **Header** - The Edison logo and the add-in name, so you can tell which add-in pane is open.
|
||||
- **Sections** - A scrollable list of collapsible tool groups. All sections start collapsed; click a section title to expand or collapse it.
|
||||
- **Status bar** - Docked at the bottom of the pane. It shows progress and a **Stop** button during long operations, then the result.
|
||||
|
||||
The sections are:
|
||||
|
||||
- **Content** - Tools for manipulating content and shapes
|
||||
- **Progress Bar** - Add/remove presentation progress indicators
|
||||
- **Confidential Marking** - Add/remove confidential labels
|
||||
- **Draft Watermark** - Add/remove draft watermarks
|
||||
- **Alignment** - Tools for aligning shapes and objects
|
||||
- **Layout** - Grids and guidelines for the current slide
|
||||
- **Settings** - Slide size and other per-presentation preferences
|
||||
- **Grid & Guidelines** - Grids and guidelines for the current slide
|
||||
- **Raster** - Wireframe cell grids for placing objects
|
||||
- **Settings** - Slide size and version information
|
||||
|
||||
## Content Tools
|
||||
|
||||
@@ -127,6 +134,10 @@ Adds or removes a "DRAFT" watermark on slide masters to mark in-progress present
|
||||
|
||||
These tools align selected objects to the slide edges or center.
|
||||
|
||||
The alignment controls are icon buttons in a single row: the first three align
|
||||
horizontally (left, center, right), the last three align vertically (top,
|
||||
middle, bottom). Hover an icon to see its name.
|
||||
|
||||
### Horizontal Alignment
|
||||
|
||||
- **Left** - Aligns all shapes to the left edge of the slide
|
||||
@@ -171,6 +182,46 @@ Adds horizontal or vertical guidelines at specific positions.
|
||||
|
||||
**Tip:** Use different colors for different types of guidelines (for example blue for margins and red for key alignment points). Guidelines are also ordinary shapes and appear in output.
|
||||
|
||||
## Raster
|
||||
|
||||
Creates a wireframe cell grid on the current slide, its layout, or the slide
|
||||
master. Use it to place objects on a consistent column and row structure, then
|
||||
remove it before presenting.
|
||||
|
||||
**Presets (16:9):**
|
||||
- **12 × 8** - Coarse wireframe; cells are 26.39 × 22.06 mm.
|
||||
- **24 × 16** - Fine wireframe; cells are about 12.20 × 10.03 mm.
|
||||
- **Custom** - Enter your own columns, rows, gutter, and opacity.
|
||||
|
||||
**Place on:**
|
||||
- **Current slide** - Sits on top of the current slide's content.
|
||||
- **This slide's layout (background)** - Sits behind content on every slide using
|
||||
the current slide's layout. This is usually the best choice for a content grid.
|
||||
- **Slide master (all slides)** - Sits behind content on every slide in the
|
||||
presentation.
|
||||
|
||||
**How to use:**
|
||||
1. Navigate to a slide that uses the layout or master you want to target.
|
||||
2. Choose **Place on**, then choose a preset or set **Columns**, **Rows**,
|
||||
**Gutter (mm)**, and **Opacity (%)**.
|
||||
3. Pick a **Color**. Gray at 100 % matches the template wireframes.
|
||||
4. Click "Add raster". Any existing raster in the presentation is replaced, so
|
||||
only one raster is active at a time.
|
||||
5. Click "Remove raster" when you are finished. This removes the raster from the
|
||||
current slide, all layouts, and the slide master.
|
||||
|
||||
The hint below the controls shows the resulting cell size in millimetres and the
|
||||
number of cells. A raster is limited to 600 cells.
|
||||
|
||||
**Warning:** Raster shapes are **included in slideshow, print, and export
|
||||
output**. Remove the raster before presenting. Layout and master rasters are
|
||||
background graphics and are not shown on slides that use **Hide Background
|
||||
Graphics**; a full-slide picture on the slide can also cover them.
|
||||
|
||||
**Performance:** a layout/master raster is inherited by every slide that uses
|
||||
it. On long presentations, prefer the **12 × 8** preset; a 24 × 16 raster adds
|
||||
384 shapes to every inherited slide.
|
||||
|
||||
## Settings
|
||||
|
||||
### Slide Size
|
||||
|
||||
@@ -54,7 +54,7 @@ const Root: React.FC = () => {
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<FluentProvider theme={theme}>
|
||||
<FluentProvider theme={theme} style={{ height: "100%" }}>
|
||||
<ErrorBoundary>
|
||||
<SettingsProvider>
|
||||
<App />
|
||||
|
||||
@@ -6,11 +6,16 @@
|
||||
*/
|
||||
|
||||
import * as React from "react";
|
||||
import {
|
||||
Button,
|
||||
makeStyles
|
||||
import {
|
||||
makeStyles,
|
||||
Text,
|
||||
tokens,
|
||||
Toolbar,
|
||||
ToolbarButton,
|
||||
ToolbarDivider,
|
||||
Tooltip
|
||||
} from "@fluentui/react-components";
|
||||
import {
|
||||
import {
|
||||
TextAlignLeftRegular,
|
||||
TextAlignCenterRegular,
|
||||
TextAlignRightRegular,
|
||||
@@ -39,42 +44,57 @@ type VerticalAlignmentType = 'top' | 'middle' | 'bottom';
|
||||
* Component-specific styles
|
||||
*/
|
||||
const useStyles = makeStyles({
|
||||
alignmentGrid: {
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(3, 1fr)",
|
||||
gap: "8px",
|
||||
width: "100%"
|
||||
},
|
||||
alignButton: {
|
||||
toolbar: {
|
||||
width: "100%",
|
||||
minWidth: 0,
|
||||
padding: "8px 4px",
|
||||
"& span": {
|
||||
justifyContent: "center"
|
||||
}
|
||||
flexWrap: "wrap",
|
||||
gap: tokens.spacingHorizontalXS,
|
||||
padding: 0,
|
||||
backgroundColor: "transparent"
|
||||
}
|
||||
});
|
||||
|
||||
interface AlignButtonProps {
|
||||
label: string;
|
||||
icon: React.ReactElement;
|
||||
disabled: boolean;
|
||||
onClick: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Icon-only alignment button with a tooltip that doubles as its accessible name.
|
||||
*/
|
||||
const AlignButton: React.FC<AlignButtonProps> = ({ label, icon, disabled, onClick }) => (
|
||||
<Tooltip content={label} relationship="description">
|
||||
<ToolbarButton
|
||||
appearance="primary"
|
||||
aria-label={label}
|
||||
icon={icon}
|
||||
disabled={disabled}
|
||||
onClick={onClick}
|
||||
/>
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
/**
|
||||
* AlignmentButtons component provides UI and functionality to align
|
||||
* selected shapes in PowerPoint presentations.
|
||||
*
|
||||
*
|
||||
* @returns React component
|
||||
*/
|
||||
export const AlignmentButtons: React.FC = () => {
|
||||
const styles = useStyles();
|
||||
const commonStyles = useCommonStyles();
|
||||
const { slideSize } = useSettings();
|
||||
const {
|
||||
const {
|
||||
setStatusMessage,
|
||||
setStatusType,
|
||||
isProcessing,
|
||||
isProcessing,
|
||||
setIsProcessing
|
||||
} = useStatusContext();
|
||||
|
||||
/**
|
||||
* Handles errors and updates the status message
|
||||
*
|
||||
*
|
||||
* @param error - The error object
|
||||
* @param operation - The operation being performed (for logging)
|
||||
*/
|
||||
@@ -86,7 +106,7 @@ export const AlignmentButtons: React.FC = () => {
|
||||
|
||||
/**
|
||||
* Generic function to handle horizontal alignment of shapes
|
||||
*
|
||||
*
|
||||
* @param alignmentType - The type of horizontal alignment to apply
|
||||
*/
|
||||
const handleHorizontalAlignment = async (alignmentType: HorizontalAlignmentType): Promise<void> => {
|
||||
@@ -142,7 +162,7 @@ export const AlignmentButtons: React.FC = () => {
|
||||
|
||||
/**
|
||||
* Generic function to handle vertical alignment of shapes
|
||||
*
|
||||
*
|
||||
* @param alignmentType - The type of vertical alignment to apply
|
||||
*/
|
||||
const handleVerticalAlignment = async (alignmentType: VerticalAlignmentType): Promise<void> => {
|
||||
@@ -240,68 +260,48 @@ export const AlignmentButtons: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className={commonStyles.container}>
|
||||
<div className={styles.alignmentGrid}>
|
||||
<Button
|
||||
appearance="primary"
|
||||
className={styles.alignButton}
|
||||
onClick={alignTop}
|
||||
icon={<TextboxAlignTopRegular />}
|
||||
disabled={isProcessing}
|
||||
title="Align Top"
|
||||
>
|
||||
Top
|
||||
</Button>
|
||||
<Button
|
||||
appearance="primary"
|
||||
className={styles.alignButton}
|
||||
onClick={alignMiddle}
|
||||
icon={<TextboxAlignMiddleRegular />}
|
||||
disabled={isProcessing}
|
||||
title="Align Middle"
|
||||
>
|
||||
Middle
|
||||
</Button>
|
||||
<Button
|
||||
appearance="primary"
|
||||
className={styles.alignButton}
|
||||
onClick={alignBottom}
|
||||
icon={<TextboxAlignBottomRegular />}
|
||||
disabled={isProcessing}
|
||||
title="Align Bottom"
|
||||
>
|
||||
Bottom
|
||||
</Button>
|
||||
<Button
|
||||
appearance="primary"
|
||||
className={styles.alignButton}
|
||||
onClick={alignLeft}
|
||||
<Text size={200} className={commonStyles.hint}>
|
||||
Select objects on the slide, then align them to the slide edges or center.
|
||||
</Text>
|
||||
<Toolbar aria-label="Align selected objects" className={styles.toolbar}>
|
||||
<AlignButton
|
||||
label="Align left"
|
||||
icon={<TextAlignLeftRegular />}
|
||||
disabled={isProcessing}
|
||||
title="Align Left"
|
||||
>
|
||||
Left
|
||||
</Button>
|
||||
<Button
|
||||
appearance="primary"
|
||||
className={styles.alignButton}
|
||||
onClick={alignCenter}
|
||||
onClick={alignLeft}
|
||||
/>
|
||||
<AlignButton
|
||||
label="Align center"
|
||||
icon={<TextAlignCenterRegular />}
|
||||
disabled={isProcessing}
|
||||
title="Align Center"
|
||||
>
|
||||
Center
|
||||
</Button>
|
||||
<Button
|
||||
appearance="primary"
|
||||
className={styles.alignButton}
|
||||
onClick={alignRight}
|
||||
onClick={alignCenter}
|
||||
/>
|
||||
<AlignButton
|
||||
label="Align right"
|
||||
icon={<TextAlignRightRegular />}
|
||||
disabled={isProcessing}
|
||||
title="Align Right"
|
||||
>
|
||||
Right
|
||||
</Button>
|
||||
</div>
|
||||
onClick={alignRight}
|
||||
/>
|
||||
<ToolbarDivider />
|
||||
<AlignButton
|
||||
label="Align top"
|
||||
icon={<TextboxAlignTopRegular />}
|
||||
disabled={isProcessing}
|
||||
onClick={alignTop}
|
||||
/>
|
||||
<AlignButton
|
||||
label="Align middle"
|
||||
icon={<TextboxAlignMiddleRegular />}
|
||||
disabled={isProcessing}
|
||||
onClick={alignMiddle}
|
||||
/>
|
||||
<AlignButton
|
||||
label="Align bottom"
|
||||
icon={<TextboxAlignBottomRegular />}
|
||||
disabled={isProcessing}
|
||||
onClick={alignBottom}
|
||||
/>
|
||||
</Toolbar>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
+172
-114
@@ -17,11 +17,14 @@ import DraftButtons from "./DraftButtons";
|
||||
import ProgressBarButtons from "./ProgressBarButtons";
|
||||
import AlignmentButtons from "./AlignmentButtons";
|
||||
import GridGuidelineManager from "./GridGuidelineManager";
|
||||
import RasterManager from "./RasterManager";
|
||||
import Section from "./Section";
|
||||
import {
|
||||
Accordion,
|
||||
Button,
|
||||
Dropdown,
|
||||
Field,
|
||||
Image,
|
||||
makeStyles,
|
||||
Option,
|
||||
ProgressBar as FluentProgressBar,
|
||||
@@ -48,23 +51,58 @@ const useStyles = makeStyles({
|
||||
root: {
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
padding: "16px",
|
||||
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",
|
||||
backgroundColor: tokens.colorNeutralBackground1,
|
||||
overflow: "auto",
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0
|
||||
height: "100%",
|
||||
overflow: "hidden",
|
||||
fontFamily: tokens.fontFamilyBase,
|
||||
backgroundColor: tokens.colorNeutralBackground1
|
||||
},
|
||||
header: {
|
||||
display: "flex",
|
||||
flexShrink: 0,
|
||||
alignItems: "center",
|
||||
gap: tokens.spacingHorizontalS,
|
||||
padding: `${tokens.spacingVerticalM} ${tokens.spacingHorizontalL}`,
|
||||
borderBottomWidth: "1px",
|
||||
borderBottomStyle: "solid",
|
||||
borderBottomColor: tokens.colorNeutralStroke2
|
||||
},
|
||||
headerText: {
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
minWidth: 0
|
||||
},
|
||||
muted: {
|
||||
color: tokens.colorNeutralForeground3
|
||||
},
|
||||
scrollArea: {
|
||||
flex: 1,
|
||||
overflowY: "auto",
|
||||
overflowX: "hidden",
|
||||
padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalL} ${tokens.spacingVerticalL}`
|
||||
},
|
||||
accordion: {
|
||||
width: "100%"
|
||||
},
|
||||
dropdown: {
|
||||
width: "100%"
|
||||
},
|
||||
about: {
|
||||
paddingTop: tokens.spacingVerticalS
|
||||
},
|
||||
statusDock: {
|
||||
flexShrink: 0
|
||||
},
|
||||
statusDockActive: {
|
||||
padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalL}`,
|
||||
borderTopWidth: "1px",
|
||||
borderTopStyle: "solid",
|
||||
borderTopColor: tokens.colorNeutralStroke2,
|
||||
backgroundColor: tokens.colorNeutralBackground2
|
||||
},
|
||||
statusContainer: {
|
||||
marginTop: "4px",
|
||||
padding: "8px 12px",
|
||||
fontSize: "13px",
|
||||
borderRadius: "6px",
|
||||
backgroundColor: tokens.colorNeutralBackground3,
|
||||
transition: "all 0.3s ease"
|
||||
padding: `${tokens.spacingVerticalXS} ${tokens.spacingHorizontalS}`,
|
||||
borderRadius: tokens.borderRadiusMedium,
|
||||
backgroundColor: tokens.colorNeutralBackground3
|
||||
},
|
||||
infoStatus: {
|
||||
backgroundColor: tokens.colorBrandBackground2,
|
||||
@@ -82,22 +120,18 @@ const useStyles = makeStyles({
|
||||
backgroundColor: tokens.colorPaletteRedBackground1,
|
||||
color: tokens.colorPaletteRedForeground1
|
||||
},
|
||||
statusIcon: {
|
||||
marginRight: "8px"
|
||||
},
|
||||
statusText: {
|
||||
display: "flex",
|
||||
alignItems: "center"
|
||||
alignItems: "center",
|
||||
gap: tokens.spacingHorizontalS
|
||||
},
|
||||
progressBar: {
|
||||
marginTop: "8px"
|
||||
marginTop: tokens.spacingVerticalS
|
||||
},
|
||||
footer: {
|
||||
fontSize: "12px",
|
||||
color: tokens.colorNeutralForeground3,
|
||||
textAlign: "center",
|
||||
marginTop: "auto",
|
||||
padding: "8px 0"
|
||||
stopRow: {
|
||||
display: "flex",
|
||||
justifyContent: "flex-end",
|
||||
marginTop: tokens.spacingVerticalXS
|
||||
}
|
||||
});
|
||||
|
||||
@@ -132,16 +166,18 @@ const App: React.FC = () => {
|
||||
const getStatusIcon = () => {
|
||||
switch (statusType) {
|
||||
case "success":
|
||||
return <CheckmarkCircleRegular className={styles.statusIcon} />;
|
||||
return <CheckmarkCircleRegular />;
|
||||
case "warning":
|
||||
return <WarningRegular className={styles.statusIcon} />;
|
||||
return <WarningRegular />;
|
||||
case "error":
|
||||
return <ErrorCircleRegular className={styles.statusIcon} />;
|
||||
return <ErrorCircleRegular />;
|
||||
default:
|
||||
return <InfoRegular className={styles.statusIcon} />;
|
||||
return <InfoRegular />;
|
||||
}
|
||||
};
|
||||
|
||||
const hasStatus = isProcessing || Boolean(statusMessage);
|
||||
|
||||
return (
|
||||
<StatusContext.Provider value={{
|
||||
statusMessage,
|
||||
@@ -154,94 +190,116 @@ const App: React.FC = () => {
|
||||
setProgress
|
||||
}}>
|
||||
<div className={styles.root}>
|
||||
<Section title="Content">
|
||||
<MatchProperties />
|
||||
<div style={{ marginTop: "8px" }}></div>
|
||||
<MatchSizes />
|
||||
<div style={{ marginTop: "8px" }}></div>
|
||||
<SwapPositions />
|
||||
<div style={{ marginTop: "8px" }}></div>
|
||||
<InsertTitles />
|
||||
<div style={{ marginTop: "8px" }}></div>
|
||||
<RoundImage />
|
||||
</Section>
|
||||
|
||||
<Section title="Progress Bar">
|
||||
<ProgressBarButtons />
|
||||
</Section>
|
||||
|
||||
<Section title="Confidential Marking">
|
||||
<ConfidentialButtons />
|
||||
</Section>
|
||||
|
||||
<Section title="Draft Watermark">
|
||||
<DraftButtons />
|
||||
</Section>
|
||||
|
||||
<Section title="Alignment">
|
||||
<AlignmentButtons />
|
||||
</Section>
|
||||
|
||||
<Section title="Layout">
|
||||
<GridGuidelineManager />
|
||||
</Section>
|
||||
|
||||
<Section title="Settings">
|
||||
<Field label="Slide size">
|
||||
<Dropdown
|
||||
value={SLIDE_SIZE_LABELS[slideSizePreset]}
|
||||
selectedOptions={[slideSizePreset]}
|
||||
onOptionSelect={(_, data) => {
|
||||
if (data.optionValue === "widescreen" || data.optionValue === "standard") {
|
||||
setSlideSizePreset(data.optionValue);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Option value="widescreen">{SLIDE_SIZE_LABELS.widescreen}</Option>
|
||||
<Option value="standard">{SLIDE_SIZE_LABELS.standard}</Option>
|
||||
</Dropdown>
|
||||
</Field>
|
||||
</Section>
|
||||
|
||||
{/* Status message area at the bottom */}
|
||||
{isProcessing && (
|
||||
<div className={styles.statusContainer} role="status" aria-live="polite">
|
||||
<div className={styles.statusText}>
|
||||
<Spinner size="tiny" style={{ marginRight: "8px" }} />
|
||||
{progress ? `Processing ${progress.current} / ${progress.total}...` : "Processing..."}
|
||||
</div>
|
||||
{progress && progress.total > 0 && (
|
||||
<FluentProgressBar
|
||||
className={styles.progressBar}
|
||||
value={progress.current / progress.total}
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
size="small"
|
||||
appearance="subtle"
|
||||
style={{ marginTop: "4px" }}
|
||||
onClick={requestCancellation}
|
||||
>
|
||||
Stop
|
||||
</Button>
|
||||
<header className={styles.header}>
|
||||
<Image src="assets/edison-32.png" alt="" width={32} height={32} />
|
||||
<div className={styles.headerText}>
|
||||
<Text size={400} weight="semibold">Edison</Text>
|
||||
<Text size={200} className={styles.muted}>PowerPoint toolbox</Text>
|
||||
</div>
|
||||
)}
|
||||
</header>
|
||||
|
||||
{!isProcessing && statusMessage && (
|
||||
<div
|
||||
className={`${styles.statusContainer} ${styles[`${statusType}Status`]}`}
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
<div className={styles.scrollArea}>
|
||||
<Accordion
|
||||
multiple
|
||||
collapsible
|
||||
className={styles.accordion}
|
||||
>
|
||||
<div className={styles.statusText}>
|
||||
{getStatusIcon()}
|
||||
{statusMessage}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<Section title="Content" value="content">
|
||||
<MatchProperties />
|
||||
<MatchSizes />
|
||||
<SwapPositions />
|
||||
<InsertTitles />
|
||||
<RoundImage />
|
||||
</Section>
|
||||
|
||||
<div className={styles.footer}>
|
||||
<Text size={100}>Edison • v{__APP_VERSION__}</Text>
|
||||
<Section title="Progress Bar" value="progress-bar">
|
||||
<ProgressBarButtons />
|
||||
</Section>
|
||||
|
||||
<Section title="Confidential Marking" value="confidential">
|
||||
<ConfidentialButtons />
|
||||
</Section>
|
||||
|
||||
<Section title="Draft Watermark" value="draft">
|
||||
<DraftButtons />
|
||||
</Section>
|
||||
|
||||
<Section title="Alignment" value="alignment">
|
||||
<AlignmentButtons />
|
||||
</Section>
|
||||
|
||||
<Section title="Grid & Guidelines" value="grid-guidelines">
|
||||
<GridGuidelineManager />
|
||||
</Section>
|
||||
|
||||
<Section title="Raster" value="raster">
|
||||
<RasterManager />
|
||||
</Section>
|
||||
|
||||
<Section title="Settings" value="settings">
|
||||
<Field
|
||||
label="Slide size"
|
||||
hint="Used by alignment, grid, progress bar, title, and marking tools."
|
||||
>
|
||||
<Dropdown
|
||||
className={styles.dropdown}
|
||||
value={SLIDE_SIZE_LABELS[slideSizePreset]}
|
||||
selectedOptions={[slideSizePreset]}
|
||||
onOptionSelect={(_, data) => {
|
||||
if (data.optionValue === "widescreen" || data.optionValue === "standard") {
|
||||
setSlideSizePreset(data.optionValue);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Option value="widescreen">{SLIDE_SIZE_LABELS.widescreen}</Option>
|
||||
<Option value="standard">{SLIDE_SIZE_LABELS.standard}</Option>
|
||||
</Dropdown>
|
||||
</Field>
|
||||
<div className={styles.about}>
|
||||
<Text size={200} className={styles.muted}>Version {__APP_VERSION__}</Text>
|
||||
</div>
|
||||
</Section>
|
||||
</Accordion>
|
||||
</div>
|
||||
|
||||
{/* Always-mounted live region docked at the bottom of the pane */}
|
||||
<div
|
||||
className={`${styles.statusDock} ${hasStatus ? styles.statusDockActive : ""}`}
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
aria-atomic="true"
|
||||
>
|
||||
{isProcessing ? (
|
||||
<div>
|
||||
<div className={styles.statusText}>
|
||||
<Spinner size="tiny" />
|
||||
<Text size={300}>Processing</Text>
|
||||
{progress && (
|
||||
<Text size={300} aria-live="off">
|
||||
{progress.current} of {progress.total}…
|
||||
</Text>
|
||||
)}
|
||||
</div>
|
||||
{progress && progress.total > 0 && (
|
||||
<FluentProgressBar
|
||||
className={styles.progressBar}
|
||||
value={progress.current / progress.total}
|
||||
/>
|
||||
)}
|
||||
<div className={styles.stopRow}>
|
||||
<Button size="small" appearance="primary" onClick={requestCancellation}>
|
||||
Stop
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : statusMessage ? (
|
||||
<div className={`${styles.statusContainer} ${styles[`${statusType}Status`]}`}>
|
||||
<div className={styles.statusText}>
|
||||
{getStatusIcon()}
|
||||
<Text size={300}>{statusMessage}</Text>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</StatusContext.Provider>
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* @file ColorSwatches.tsx
|
||||
* @description Shared colour picker for grids, guidelines, and rasters.
|
||||
*/
|
||||
|
||||
import * as React from "react";
|
||||
import { Button, makeStyles, Text, tokens } from "@fluentui/react-components";
|
||||
import { CheckmarkRegular } from "@fluentui/react-icons";
|
||||
|
||||
export type SwatchColor = "blue" | "red" | "yellow" | "green" | "gray";
|
||||
|
||||
/** Colours written to the slide. */
|
||||
export const SWATCH_VALUES: Record<SwatchColor, string> = {
|
||||
blue: "#4472C4",
|
||||
red: "#C00000",
|
||||
yellow: "#FFC000",
|
||||
green: "#70AD47",
|
||||
gray: "#D9D9D9",
|
||||
};
|
||||
|
||||
const SWATCH_LABELS: Record<SwatchColor, string> = {
|
||||
blue: "Blue",
|
||||
red: "Red",
|
||||
yellow: "Yellow",
|
||||
green: "Green",
|
||||
gray: "Gray",
|
||||
};
|
||||
|
||||
const SWATCH_ORDER: readonly SwatchColor[] = ["blue", "red", "yellow", "green", "gray"];
|
||||
|
||||
/** Choose a check colour that stays readable on every swatch. */
|
||||
const getSwatchForeground = (color: SwatchColor): string =>
|
||||
color === "yellow" || color === "green" || color === "gray" ? "#000000" : "#ffffff";
|
||||
|
||||
const useStyles = makeStyles({
|
||||
row: {
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: tokens.spacingHorizontalS,
|
||||
},
|
||||
label: {
|
||||
minWidth: "48px",
|
||||
color: tokens.colorNeutralForeground2,
|
||||
},
|
||||
group: {
|
||||
display: "flex",
|
||||
gap: tokens.spacingHorizontalXS,
|
||||
},
|
||||
button: {
|
||||
width: "32px",
|
||||
height: "32px",
|
||||
minWidth: "32px",
|
||||
padding: 0,
|
||||
border: `1px solid ${tokens.colorNeutralStroke1}`,
|
||||
borderRadius: tokens.borderRadiusMedium,
|
||||
},
|
||||
selected: {
|
||||
border: `2px solid ${tokens.colorBrandForeground1}`,
|
||||
},
|
||||
});
|
||||
|
||||
export interface ColorSwatchesProps {
|
||||
/** Visible group label, e.g. "Color" */
|
||||
label: string;
|
||||
value: SwatchColor;
|
||||
onChange: (color: SwatchColor) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* A labelled group of colour swatches with a check mark on the selected value.
|
||||
*/
|
||||
export const ColorSwatches: React.FC<ColorSwatchesProps> = ({ label, value, onChange }) => {
|
||||
const styles = useStyles();
|
||||
const labelId = React.useId();
|
||||
|
||||
return (
|
||||
<div className={styles.row}>
|
||||
<Text id={labelId} size={200} className={styles.label}>
|
||||
{label}
|
||||
</Text>
|
||||
<div className={styles.group} role="group" aria-labelledby={labelId}>
|
||||
{SWATCH_ORDER.map((color) => {
|
||||
const selected = color === value;
|
||||
return (
|
||||
<Button
|
||||
key={color}
|
||||
appearance="subtle"
|
||||
className={`${styles.button} ${selected ? styles.selected : ""}`}
|
||||
style={{
|
||||
backgroundColor: SWATCH_VALUES[color],
|
||||
color: getSwatchForeground(color),
|
||||
width: "32px",
|
||||
minWidth: "32px",
|
||||
height: "32px",
|
||||
padding: 0,
|
||||
}}
|
||||
onClick={() => onChange(color)}
|
||||
title={`${SWATCH_LABELS[color]} color`}
|
||||
aria-label={`${SWATCH_LABELS[color]} color`}
|
||||
aria-pressed={selected}
|
||||
icon={selected ? <CheckmarkRegular /> : undefined}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ColorSwatches;
|
||||
@@ -5,10 +5,7 @@
|
||||
*/
|
||||
|
||||
import * as React from "react";
|
||||
import {
|
||||
Button,
|
||||
makeStyles
|
||||
} from "@fluentui/react-components";
|
||||
import { Button, Text } from "@fluentui/react-components";
|
||||
import {
|
||||
ShieldLockRegular,
|
||||
DismissRegular
|
||||
@@ -41,26 +38,6 @@ const CONFIDENTIAL_CONFIG = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Component-specific styles
|
||||
*/
|
||||
const useStyles = makeStyles({
|
||||
buttonGrid: {
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(2, 1fr)",
|
||||
gap: "8px",
|
||||
width: "100%"
|
||||
},
|
||||
confidentialButton: {
|
||||
width: "100%",
|
||||
minWidth: 0,
|
||||
padding: "8px 4px",
|
||||
"& span": {
|
||||
justifyContent: "center"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Interface for slide processing results
|
||||
*/
|
||||
@@ -77,7 +54,6 @@ interface ProcessingResult {
|
||||
* @returns React component
|
||||
*/
|
||||
export const ConfidentialButtons: React.FC = () => {
|
||||
const styles = useStyles();
|
||||
const commonStyles = useCommonStyles();
|
||||
const { slideSize } = useSettings();
|
||||
const {
|
||||
@@ -265,20 +241,21 @@ export const ConfidentialButtons: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className={commonStyles.container}>
|
||||
<div className={styles.buttonGrid}>
|
||||
<Text size={200} className={commonStyles.hint}>
|
||||
Adds a centered label near the bottom of every slide.
|
||||
</Text>
|
||||
<div className={commonStyles.buttonGroup}>
|
||||
<Button
|
||||
appearance="primary"
|
||||
className={styles.confidentialButton}
|
||||
onClick={addConfidentialMarking}
|
||||
icon={<ShieldLockRegular />}
|
||||
disabled={isProcessing}
|
||||
title="Add Confidential"
|
||||
>
|
||||
Add
|
||||
Add confidential marking
|
||||
</Button>
|
||||
<ConfirmButton
|
||||
appearance="primary"
|
||||
className={styles.confidentialButton}
|
||||
onConfirm={removeConfidentialMarking}
|
||||
icon={<DismissRegular />}
|
||||
disabled={isProcessing}
|
||||
@@ -287,7 +264,7 @@ export const ConfidentialButtons: React.FC = () => {
|
||||
confirmMessage="This removes the confidential marking from every slide in the presentation."
|
||||
confirmLabel="Remove"
|
||||
>
|
||||
Remove
|
||||
Remove confidential markings
|
||||
</ConfirmButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
DialogBody,
|
||||
DialogContent,
|
||||
DialogSurface,
|
||||
DialogTitle,
|
||||
DialogTitle
|
||||
} from "@fluentui/react-components";
|
||||
|
||||
export interface ConfirmButtonProps {
|
||||
@@ -74,7 +74,7 @@ export const ConfirmButton: React.FC<ConfirmButtonProps> = ({
|
||||
<DialogTitle>{confirmTitle}</DialogTitle>
|
||||
<DialogContent>{confirmMessage}</DialogContent>
|
||||
<DialogActions>
|
||||
<Button appearance="secondary" onClick={() => setIsOpen(false)}>
|
||||
<Button appearance="primary" onClick={() => setIsOpen(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button appearance="primary" onClick={handleConfirm}>
|
||||
|
||||
@@ -6,12 +6,9 @@
|
||||
*/
|
||||
|
||||
import * as React from "react";
|
||||
import { Button, Text } from "@fluentui/react-components";
|
||||
import {
|
||||
Button,
|
||||
makeStyles
|
||||
} from "@fluentui/react-components";
|
||||
import {
|
||||
Edit24Regular,
|
||||
Edit20Regular,
|
||||
DismissRegular
|
||||
} from "@fluentui/react-icons";
|
||||
import { useStatusContext } from "../context/StatusContext";
|
||||
@@ -53,26 +50,6 @@ const DRAFT_CONFIG = {
|
||||
].join("\n")
|
||||
};
|
||||
|
||||
/**
|
||||
* Component-specific styles
|
||||
*/
|
||||
const useStyles = makeStyles({
|
||||
buttonGrid: {
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(2, 1fr)",
|
||||
gap: "8px",
|
||||
width: "100%"
|
||||
},
|
||||
draftButton: {
|
||||
width: "100%",
|
||||
minWidth: 0,
|
||||
padding: "8px 4px",
|
||||
"& span": {
|
||||
justifyContent: "center"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Interface for master slide processing results
|
||||
*/
|
||||
@@ -89,7 +66,6 @@ interface ProcessingResult {
|
||||
* @returns React component
|
||||
*/
|
||||
export const DraftButtons: React.FC = () => {
|
||||
const styles = useStyles();
|
||||
const commonStyles = useCommonStyles();
|
||||
const {
|
||||
setStatusMessage,
|
||||
@@ -277,20 +253,21 @@ export const DraftButtons: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className={commonStyles.container}>
|
||||
<div className={styles.buttonGrid}>
|
||||
<Text size={200} className={commonStyles.hint}>
|
||||
Applies a DRAFT watermark to every slide master.
|
||||
</Text>
|
||||
<div className={commonStyles.buttonGroup}>
|
||||
<Button
|
||||
appearance="primary"
|
||||
className={styles.draftButton}
|
||||
onClick={addDraftWatermark}
|
||||
icon={<Edit24Regular />}
|
||||
icon={<Edit20Regular />}
|
||||
disabled={isProcessing}
|
||||
title="Add Draft"
|
||||
>
|
||||
Add
|
||||
Add draft watermark
|
||||
</Button>
|
||||
<ConfirmButton
|
||||
appearance="primary"
|
||||
className={styles.draftButton}
|
||||
onConfirm={removeDraftWatermark}
|
||||
icon={<DismissRegular />}
|
||||
disabled={isProcessing}
|
||||
@@ -299,7 +276,7 @@ export const DraftButtons: React.FC = () => {
|
||||
confirmMessage="This removes the DRAFT watermark from every slide master."
|
||||
confirmLabel="Remove"
|
||||
>
|
||||
Remove
|
||||
Remove draft watermarks
|
||||
</ConfirmButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import * as React from "react";
|
||||
import { Button, makeStyles, Text, tokens } from "@fluentui/react-components";
|
||||
import { getErrorMessage } from "../types/office-types";
|
||||
|
||||
interface ErrorBoundaryProps {
|
||||
@@ -15,6 +16,37 @@ interface ErrorBoundaryState {
|
||||
message: string;
|
||||
}
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "flex-start",
|
||||
gap: tokens.spacingVerticalM,
|
||||
padding: tokens.spacingVerticalL,
|
||||
backgroundColor: tokens.colorNeutralBackground1
|
||||
},
|
||||
message: {
|
||||
color: tokens.colorNeutralForeground2,
|
||||
whiteSpace: "pre-wrap"
|
||||
}
|
||||
});
|
||||
|
||||
const ErrorFallback: React.FC<{ message: string }> = ({ message }) => {
|
||||
const styles = useStyles();
|
||||
|
||||
return (
|
||||
<div role="alert" className={styles.root}>
|
||||
<Text size={400} weight="semibold">Edison could not load</Text>
|
||||
<Text size={300} className={styles.message}>
|
||||
{message || "An unexpected error occurred."}
|
||||
</Text>
|
||||
<Button appearance="primary" onClick={() => window.location.reload()}>
|
||||
Reload task pane
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
||||
state: ErrorBoundaryState = { hasError: false, message: "" };
|
||||
|
||||
@@ -28,15 +60,7 @@ export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoun
|
||||
|
||||
render(): React.ReactNode {
|
||||
if (this.state.hasError) {
|
||||
return (
|
||||
<div role="alert" style={{ padding: "16px", fontFamily: "inherit" }}>
|
||||
<h2 style={{ marginTop: 0, fontSize: "16px" }}>Edison could not load</h2>
|
||||
<p style={{ fontSize: "13px" }}>{this.state.message || "An unexpected error occurred."}</p>
|
||||
<button type="button" onClick={() => window.location.reload()}>
|
||||
Reload task pane
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
return <ErrorFallback message={this.state.message} />;
|
||||
}
|
||||
|
||||
return this.props.children;
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
/**
|
||||
* GridGuidelineManager Component
|
||||
*
|
||||
*
|
||||
* This component provides functionality to create and manage grids and guidelines
|
||||
* on PowerPoint slides. It allows users to add customizable grids with adjustable
|
||||
* spacing, opacity, and color, as well as add individual guidelines with custom
|
||||
* positioning and color.
|
||||
*
|
||||
*
|
||||
* @module GridGuidelineManager
|
||||
*/
|
||||
|
||||
import * as React from "react";
|
||||
import {
|
||||
import {
|
||||
Button,
|
||||
Field,
|
||||
Input,
|
||||
makeStyles,
|
||||
Label,
|
||||
Text,
|
||||
ToggleButton,
|
||||
tokens
|
||||
tokens,
|
||||
} from "@fluentui/react-components";
|
||||
import {
|
||||
import {
|
||||
DismissRegular,
|
||||
AddRegular,
|
||||
LineHorizontal3Regular,
|
||||
SplitVerticalRegular,
|
||||
GridDotsRegular
|
||||
GridDotsRegular,
|
||||
} from "@fluentui/react-icons";
|
||||
import { useStatusContext } from "../context/StatusContext";
|
||||
import { useSettings } from "../context/SettingsContext";
|
||||
import { useCommonStyles } from "./commonStyles";
|
||||
import { deleteShapesByPrefix, getErrorMessage } from "../types/office-types";
|
||||
import { SHAPE_NAME_PREFIXES } from "../constants";
|
||||
import { isCancellationRequested, resetCancellation } from "../services/cancellation";
|
||||
import ConfirmButton from "./ConfirmButton";
|
||||
import { ColorSwatches, SwatchColor, SWATCH_VALUES } from "./ColorSwatches";
|
||||
|
||||
/**
|
||||
* Safety limits for user-provided grid and guideline values.
|
||||
@@ -52,127 +52,70 @@ const GUIDE_PREFIX = SHAPE_NAME_PREFIXES.guide;
|
||||
const clamp = (value: number, min: number, max: number): number =>
|
||||
Math.min(max, Math.max(min, value));
|
||||
|
||||
/**
|
||||
* Available colors for grids and guidelines
|
||||
*/
|
||||
type GridColor = "blue" | "red" | "yellow" | "green";
|
||||
|
||||
/**
|
||||
* Direction options for guidelines
|
||||
*/
|
||||
type GuideDirection = "horizontal" | "vertical";
|
||||
|
||||
/**
|
||||
* Color values mapping for the available grid and guideline colors
|
||||
*/
|
||||
const colorValues = {
|
||||
blue: "#4472C4",
|
||||
red: "#C00000",
|
||||
yellow: "#FFC000",
|
||||
green: "#70AD47"
|
||||
};
|
||||
|
||||
/**
|
||||
* Props for the ColorButton component
|
||||
*/
|
||||
interface ColorButtonProps {
|
||||
/** The color this button represents */
|
||||
color: GridColor;
|
||||
/** The currently selected color */
|
||||
selectedColor: GridColor;
|
||||
/** Callback function when the color is clicked */
|
||||
onClick: (color: GridColor) => void;
|
||||
}
|
||||
|
||||
const useStyles = makeStyles({
|
||||
buttonGrid: {
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(2, 1fr)",
|
||||
gap: "8px",
|
||||
width: "100%",
|
||||
marginBottom: "8px"
|
||||
root: {
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: tokens.spacingVerticalM,
|
||||
},
|
||||
gridButton: {
|
||||
width: "100%",
|
||||
minWidth: 0,
|
||||
padding: "8px 4px",
|
||||
"& span": {
|
||||
justifyContent: "center"
|
||||
}
|
||||
hint: {
|
||||
color: tokens.colorNeutralForeground3,
|
||||
},
|
||||
field: {
|
||||
maxWidth: "180px",
|
||||
},
|
||||
controlRow: {
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "8px",
|
||||
marginBottom: "8px"
|
||||
gap: tokens.spacingHorizontalS,
|
||||
},
|
||||
controlLabel: {
|
||||
minWidth: "80px",
|
||||
marginBottom: "0"
|
||||
minWidth: "48px",
|
||||
color: tokens.colorNeutralForeground2,
|
||||
},
|
||||
controlInput: {
|
||||
flex: 1,
|
||||
"& input[type=number]::-webkit-inner-spin-button, & input[type=number]::-webkit-outer-spin-button": {
|
||||
"-webkit-appearance": "none",
|
||||
margin: 0
|
||||
inlineGroup: {
|
||||
display: "flex",
|
||||
gap: tokens.spacingHorizontalXS,
|
||||
},
|
||||
buttonGrid: {
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(2, minmax(0, 1fr))",
|
||||
gap: tokens.spacingHorizontalS,
|
||||
width: "100%",
|
||||
"@media (max-width: 360px)": {
|
||||
gridTemplateColumns: "1fr",
|
||||
},
|
||||
"& input[type=number]": {
|
||||
"-moz-appearance": "textfield"
|
||||
}
|
||||
},
|
||||
gridButton: {
|
||||
width: "100%",
|
||||
minWidth: 0,
|
||||
},
|
||||
guidesContainer: {
|
||||
marginTop: "16px"
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: tokens.spacingVerticalM,
|
||||
paddingTop: tokens.spacingVerticalM,
|
||||
borderTopWidth: "1px",
|
||||
borderTopStyle: "solid",
|
||||
borderTopColor: tokens.colorNeutralStroke3,
|
||||
},
|
||||
guideButtonGrid: {
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(2, 1fr)",
|
||||
gap: "8px",
|
||||
width: "100%",
|
||||
marginTop: "8px"
|
||||
},
|
||||
colorButton: {
|
||||
width: "24px",
|
||||
height: "24px",
|
||||
minWidth: "24px",
|
||||
padding: "0",
|
||||
border: "1px solid " + tokens.colorNeutralStroke1,
|
||||
marginLeft: "8px"
|
||||
},
|
||||
colorButtonSelected: {
|
||||
border: "2px solid " + tokens.colorBrandForeground1
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* ColorButton component - Renders a color selection button
|
||||
*
|
||||
* @param props - Component props
|
||||
* @returns React component
|
||||
*/
|
||||
const ColorButton: React.FC<ColorButtonProps> = ({ color, selectedColor, onClick }) => {
|
||||
const styles = useStyles();
|
||||
return (
|
||||
<Button
|
||||
className={`${styles.colorButton} ${color === selectedColor ? styles.colorButtonSelected : ''}`}
|
||||
style={{ backgroundColor: colorValues[color] }}
|
||||
onClick={() => onClick(color)}
|
||||
title={color.charAt(0).toUpperCase() + color.slice(1)}
|
||||
aria-label={`${color.charAt(0).toUpperCase() + color.slice(1)} color`}
|
||||
aria-pressed={color === selectedColor}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Custom hook for handling numeric input fields
|
||||
*
|
||||
*
|
||||
* @param initialValue - The initial value for the input
|
||||
* @returns A tuple containing the current value and a change handler function
|
||||
*/
|
||||
type NumericInputHandler = [
|
||||
number,
|
||||
(e: React.ChangeEvent<HTMLInputElement>) => void,
|
||||
(value: number) => void
|
||||
(value: number) => void,
|
||||
];
|
||||
|
||||
const useNumericInputHandler = (initialValue: number): NumericInputHandler => {
|
||||
@@ -195,34 +138,28 @@ const useNumericInputHandler = (initialValue: number): NumericInputHandler => {
|
||||
/**
|
||||
* GridGuidelineManager component - Provides UI and functionality for creating
|
||||
* and managing grids and guidelines on PowerPoint slides
|
||||
*
|
||||
*
|
||||
* @returns React component
|
||||
*/
|
||||
export const GridGuidelineManager: React.FC = () => {
|
||||
const styles = useStyles();
|
||||
const commonStyles = useCommonStyles();
|
||||
const { slideSize } = useSettings();
|
||||
const {
|
||||
setStatusMessage,
|
||||
setStatusType,
|
||||
isProcessing,
|
||||
setIsProcessing,
|
||||
setProgress
|
||||
} = useStatusContext();
|
||||
const { setStatusMessage, setStatusType, isProcessing, setIsProcessing, setProgress } =
|
||||
useStatusContext();
|
||||
|
||||
// Grid state
|
||||
const [gridSpacing, handleGridSpacingChange, setGridSpacing] = useNumericInputHandler(50);
|
||||
const [gridColor, setGridColor] = React.useState<GridColor>("blue");
|
||||
const [gridColor, setGridColor] = React.useState<SwatchColor>("blue");
|
||||
const [gridOpacity, handleGridOpacityChange, setGridOpacity] = useNumericInputHandler(30);
|
||||
|
||||
|
||||
// Guidelines state
|
||||
const [guidePosition, handleGuidePositionChange, setGuidePosition] = useNumericInputHandler(240);
|
||||
const [guideDirection, setGuideDirection] = React.useState<GuideDirection>("horizontal");
|
||||
const [guideColor, setGuideColor] = React.useState<GridColor>("red");
|
||||
const [guideColor, setGuideColor] = React.useState<SwatchColor>("red");
|
||||
|
||||
/**
|
||||
* Creates a line shape on the slide using a thin rectangle
|
||||
*
|
||||
*
|
||||
* @param slide - The PowerPoint slide to add the shape to
|
||||
* @param startX - Starting X coordinate
|
||||
* @param startY - Starting Y coordinate
|
||||
@@ -230,32 +167,29 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
* @param endY - Ending Y coordinate
|
||||
* @returns The created shape object
|
||||
*/
|
||||
const createLineShape = React.useCallback((
|
||||
slide: PowerPoint.Slide,
|
||||
startX: number,
|
||||
startY: number,
|
||||
endX: number,
|
||||
endY: number
|
||||
) => {
|
||||
// Create a line using alternative approach with a rectangle shape
|
||||
const line = slide.shapes.addGeometricShape("Rectangle");
|
||||
|
||||
if (startX === endX) {
|
||||
// Vertical line
|
||||
line.left = startX;
|
||||
line.top = startY;
|
||||
line.height = endY - startY;
|
||||
line.width = 1; // Make it 1pt wide
|
||||
} else {
|
||||
// Horizontal line
|
||||
line.left = startX;
|
||||
line.top = startY;
|
||||
line.width = endX - startX;
|
||||
line.height = 1; // Make it 1pt tall
|
||||
}
|
||||
|
||||
return line;
|
||||
}, []);
|
||||
const createLineShape = React.useCallback(
|
||||
(slide: PowerPoint.Slide, startX: number, startY: number, endX: number, endY: number) => {
|
||||
// Create a line using alternative approach with a rectangle shape
|
||||
const line = slide.shapes.addGeometricShape("Rectangle");
|
||||
|
||||
if (startX === endX) {
|
||||
// Vertical line
|
||||
line.left = startX;
|
||||
line.top = startY;
|
||||
line.height = endY - startY;
|
||||
line.width = 1; // Make it 1pt wide
|
||||
} else {
|
||||
// Horizontal line
|
||||
line.left = startX;
|
||||
line.top = startY;
|
||||
line.width = endX - startX;
|
||||
line.height = 1; // Make it 1pt tall
|
||||
}
|
||||
|
||||
return line;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates a grid on the current slide based on the configured settings
|
||||
@@ -302,11 +236,11 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
const selectedSlides = context.presentation.getSelectedSlides();
|
||||
selectedSlides.load("items");
|
||||
await context.sync();
|
||||
|
||||
|
||||
if (selectedSlides.items.length === 0) {
|
||||
throw new Error("No slide selected");
|
||||
}
|
||||
|
||||
|
||||
const currentSlide = selectedSlides.items[0];
|
||||
|
||||
// Remove any existing grid on this slide inside the same request context
|
||||
@@ -328,50 +262,50 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
|
||||
const totalLines = numHorizontalLines + numVerticalLines;
|
||||
let queuedLines = 0;
|
||||
|
||||
|
||||
// Create horizontal grid lines
|
||||
for (let i = 1; i <= numHorizontalLines; i++) {
|
||||
if (isCancellationRequested()) break;
|
||||
|
||||
const yPosition = i * spacing;
|
||||
|
||||
|
||||
// Skip if we're at the edge of the slide
|
||||
if (yPosition >= slideSize.height) continue;
|
||||
|
||||
|
||||
// Create horizontal line
|
||||
const line = createLineShape(currentSlide, 0, yPosition, slideSize.width, yPosition);
|
||||
line.name = `${GRID_PREFIX}h_${i}`;
|
||||
|
||||
|
||||
// Set line properties
|
||||
line.fill.setSolidColor(colorValues[gridColor]);
|
||||
line.fill.setSolidColor(SWATCH_VALUES[gridColor]);
|
||||
line.lineFormat.weight = 0.75; // Thin line
|
||||
line.lineFormat.visible = false; // No outline, just fill
|
||||
|
||||
|
||||
// Set transparency (opacity is inverse of transparency)
|
||||
line.fill.transparency = (100 - opacity) / 100;
|
||||
|
||||
queuedLines++;
|
||||
setProgress({ current: queuedLines, total: totalLines });
|
||||
}
|
||||
|
||||
|
||||
// Create vertical grid lines
|
||||
for (let i = 1; i <= numVerticalLines; i++) {
|
||||
if (isCancellationRequested()) break;
|
||||
|
||||
const xPosition = i * spacing;
|
||||
|
||||
|
||||
// Skip if we're at the edge of the slide
|
||||
if (xPosition >= slideSize.width) continue;
|
||||
|
||||
|
||||
// Create vertical line
|
||||
const line = createLineShape(currentSlide, xPosition, 0, xPosition, slideSize.height);
|
||||
line.name = `${GRID_PREFIX}v_${i}`;
|
||||
|
||||
|
||||
// Set line properties
|
||||
line.fill.setSolidColor(colorValues[gridColor]);
|
||||
line.fill.setSolidColor(SWATCH_VALUES[gridColor]);
|
||||
line.lineFormat.weight = 0.75; // Thin line
|
||||
line.lineFormat.visible = false; // No outline, just fill
|
||||
|
||||
|
||||
// Set transparency (opacity is inverse of transparency)
|
||||
line.fill.transparency = (100 - opacity) / 100;
|
||||
|
||||
@@ -395,8 +329,20 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
setIsProcessing(false);
|
||||
setProgress(null);
|
||||
}
|
||||
}, [createLineShape, gridColor, gridOpacity, gridSpacing, setGridOpacity, setGridSpacing, setIsProcessing, setProgress, setStatusMessage, setStatusType, slideSize]);
|
||||
|
||||
}, [
|
||||
createLineShape,
|
||||
gridColor,
|
||||
gridOpacity,
|
||||
gridSpacing,
|
||||
setGridOpacity,
|
||||
setGridSpacing,
|
||||
setIsProcessing,
|
||||
setProgress,
|
||||
setStatusMessage,
|
||||
setStatusType,
|
||||
slideSize,
|
||||
]);
|
||||
|
||||
/**
|
||||
* Removes the grid from the current slide
|
||||
*/
|
||||
@@ -404,34 +350,34 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
resetCancellation();
|
||||
setProgress(null);
|
||||
setIsProcessing(true);
|
||||
|
||||
|
||||
try {
|
||||
await PowerPoint.run(async (context) => {
|
||||
// Get the current slide using the selected slides collection
|
||||
const selectedSlides = context.presentation.getSelectedSlides();
|
||||
selectedSlides.load("items");
|
||||
await context.sync();
|
||||
|
||||
|
||||
if (selectedSlides.items.length === 0) {
|
||||
throw new Error("No slide selected");
|
||||
}
|
||||
|
||||
|
||||
const currentSlide = selectedSlides.items[0];
|
||||
|
||||
|
||||
// Load all shapes on this slide
|
||||
currentSlide.shapes.load("items");
|
||||
await context.sync();
|
||||
|
||||
|
||||
// Load all shape names at once
|
||||
for (const shape of currentSlide.shapes.items) {
|
||||
shape.load("name");
|
||||
}
|
||||
await context.sync();
|
||||
|
||||
|
||||
// Delete all grid shapes and commit the changes
|
||||
const removedCount = deleteShapesByPrefix(currentSlide.shapes.items, GRID_PREFIX);
|
||||
await context.sync();
|
||||
|
||||
|
||||
if (removedCount > 0) {
|
||||
setStatusMessage(`Removed grid from slide`);
|
||||
setStatusType("success");
|
||||
@@ -475,18 +421,17 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
const selectedSlides = context.presentation.getSelectedSlides();
|
||||
selectedSlides.load("items");
|
||||
await context.sync();
|
||||
|
||||
|
||||
if (selectedSlides.items.length === 0) {
|
||||
throw new Error("No slide selected");
|
||||
}
|
||||
|
||||
|
||||
const currentSlide = selectedSlides.items[0];
|
||||
|
||||
|
||||
|
||||
// Create a unique identifier for this guide
|
||||
const timestamp = new Date().getTime();
|
||||
const guideId = `${GUIDE_PREFIX}${guideDirection}_${timestamp}`;
|
||||
|
||||
|
||||
// Add the guide line
|
||||
let line: PowerPoint.Shape;
|
||||
if (guideDirection === "horizontal") {
|
||||
@@ -496,16 +441,16 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
// Create vertical guideline
|
||||
line = createLineShape(currentSlide, position, 0, position, slideSize.height);
|
||||
}
|
||||
|
||||
|
||||
line.name = guideId;
|
||||
|
||||
|
||||
// Set line properties
|
||||
line.fill.setSolidColor(colorValues[guideColor]);
|
||||
line.fill.setSolidColor(SWATCH_VALUES[guideColor]);
|
||||
line.lineFormat.visible = false; // No outline, just fill
|
||||
|
||||
|
||||
// We want solid lines for guidelines
|
||||
line.fill.transparency = 0;
|
||||
|
||||
|
||||
setStatusMessage(`Added ${guideDirection} guideline`);
|
||||
setStatusType("success");
|
||||
});
|
||||
@@ -517,8 +462,19 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
setIsProcessing(false);
|
||||
setProgress(null);
|
||||
}
|
||||
}, [createLineShape, guideColor, guideDirection, guidePosition, setGuidePosition, setIsProcessing, setProgress, setStatusMessage, setStatusType, slideSize]);
|
||||
|
||||
}, [
|
||||
createLineShape,
|
||||
guideColor,
|
||||
guideDirection,
|
||||
guidePosition,
|
||||
setGuidePosition,
|
||||
setIsProcessing,
|
||||
setProgress,
|
||||
setStatusMessage,
|
||||
setStatusType,
|
||||
slideSize,
|
||||
]);
|
||||
|
||||
/**
|
||||
* Removes all guidelines from the current slide
|
||||
*/
|
||||
@@ -532,27 +488,27 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
const selectedSlides = context.presentation.getSelectedSlides();
|
||||
selectedSlides.load("items");
|
||||
await context.sync();
|
||||
|
||||
|
||||
if (selectedSlides.items.length === 0) {
|
||||
throw new Error("No slide selected");
|
||||
}
|
||||
|
||||
|
||||
const currentSlide = selectedSlides.items[0];
|
||||
|
||||
|
||||
// Load all shapes on this slide
|
||||
currentSlide.shapes.load("items");
|
||||
await context.sync();
|
||||
|
||||
|
||||
// Load all shape names at once
|
||||
for (const shape of currentSlide.shapes.items) {
|
||||
shape.load("name");
|
||||
}
|
||||
await context.sync();
|
||||
|
||||
|
||||
// Delete all guideline shapes and commit the changes
|
||||
const removedCount = deleteShapesByPrefix(currentSlide.shapes.items, GUIDE_PREFIX);
|
||||
await context.sync();
|
||||
|
||||
|
||||
if (removedCount > 0) {
|
||||
setStatusMessage(`Removed ${removedCount} guidelines`);
|
||||
setStatusType("success");
|
||||
@@ -572,17 +528,15 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
}, [setIsProcessing, setProgress, setStatusMessage, setStatusType]);
|
||||
|
||||
return (
|
||||
<div className={commonStyles.container} style={{ maxHeight: "400px", overflowY: "auto" }}>
|
||||
{/* Grid Controls */}
|
||||
<Label style={{
|
||||
fontWeight: "600",
|
||||
marginBottom: "12px",
|
||||
fontSize: "16px"
|
||||
}}>
|
||||
<div className={styles.root}>
|
||||
<Text size={400} weight="semibold">
|
||||
Grid
|
||||
</Label>
|
||||
|
||||
<Field label="Spacing" style={{ marginBottom: "8px" }}>
|
||||
</Text>
|
||||
<Text size={200} className={styles.hint}>
|
||||
Grid lines are slide shapes and appear in slideshows and exports.
|
||||
</Text>
|
||||
|
||||
<Field label="Spacing (pt)" className={styles.field}>
|
||||
<Input
|
||||
type="number"
|
||||
value={String(gridSpacing)}
|
||||
@@ -590,11 +544,10 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
min={GRID_SPACING_MIN}
|
||||
max={Math.min(slideSize.width, slideSize.height)}
|
||||
title="Grid spacing in points"
|
||||
style={{ width: "100px" }}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="Opacity" style={{ marginBottom: "8px" }}>
|
||||
|
||||
<Field label="Opacity (%)" className={styles.field}>
|
||||
<Input
|
||||
type="number"
|
||||
value={String(gridOpacity)}
|
||||
@@ -602,30 +555,21 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
min={GRID_OPACITY_MIN}
|
||||
max={GRID_OPACITY_MAX}
|
||||
title="Grid opacity percentage"
|
||||
style={{ width: "100px" }}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<div className={styles.controlRow}>
|
||||
<Label className={styles.controlLabel}>Color</Label>
|
||||
<div style={{ display: "flex" }}>
|
||||
<ColorButton color="blue" selectedColor={gridColor} onClick={setGridColor} />
|
||||
<ColorButton color="red" selectedColor={gridColor} onClick={setGridColor} />
|
||||
<ColorButton color="yellow" selectedColor={gridColor} onClick={setGridColor} />
|
||||
<ColorButton color="green" selectedColor={gridColor} onClick={setGridColor} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<ColorSwatches label="Color" value={gridColor} onChange={setGridColor} />
|
||||
|
||||
<div className={styles.buttonGrid}>
|
||||
<Button
|
||||
appearance="primary"
|
||||
<Button
|
||||
appearance="primary"
|
||||
className={styles.gridButton}
|
||||
onClick={createGrid}
|
||||
onClick={createGrid}
|
||||
icon={<GridDotsRegular />}
|
||||
disabled={isProcessing}
|
||||
title="Create Grid"
|
||||
title="Add grid"
|
||||
>
|
||||
Add
|
||||
Add grid
|
||||
</Button>
|
||||
<ConfirmButton
|
||||
appearance="primary"
|
||||
@@ -633,47 +577,43 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
onConfirm={removeGrid}
|
||||
icon={<DismissRegular />}
|
||||
disabled={isProcessing}
|
||||
title="Remove Grid"
|
||||
title="Remove grid"
|
||||
confirmTitle="Remove the grid?"
|
||||
confirmMessage="This removes the grid from the current slide."
|
||||
confirmLabel="Remove"
|
||||
>
|
||||
Remove
|
||||
Remove grid
|
||||
</ConfirmButton>
|
||||
</div>
|
||||
|
||||
|
||||
{/* Guidelines Section */}
|
||||
<div className={styles.guidesContainer}>
|
||||
<Label style={{
|
||||
fontWeight: "600",
|
||||
marginBottom: "12px",
|
||||
fontSize: "16px"
|
||||
}}>
|
||||
<Text size={400} weight="semibold">
|
||||
Guidelines
|
||||
</Label>
|
||||
|
||||
<Field label="Position" style={{ marginBottom: "8px" }}>
|
||||
<Input
|
||||
type="number"
|
||||
value={String(guidePosition)}
|
||||
onChange={handleGuidePositionChange}
|
||||
min={0}
|
||||
max={guideDirection === "horizontal" ? slideSize.height : slideSize.width}
|
||||
title="Guideline position in points"
|
||||
style={{ width: "100px" }}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
</Text>
|
||||
|
||||
<Field label="Position (pt)" className={styles.field}>
|
||||
<Input
|
||||
type="number"
|
||||
value={String(guidePosition)}
|
||||
onChange={handleGuidePositionChange}
|
||||
min={0}
|
||||
max={guideDirection === "horizontal" ? slideSize.height : slideSize.width}
|
||||
title="Guideline position in points"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<div className={styles.controlRow}>
|
||||
<Label className={styles.controlLabel}>Type</Label>
|
||||
<div style={{ display: "flex", gap: "8px" }}>
|
||||
<Text id="guide-direction-label" size={200} className={styles.controlLabel}>
|
||||
Type
|
||||
</Text>
|
||||
<div className={styles.inlineGroup} role="group" aria-labelledby="guide-direction-label">
|
||||
<ToggleButton
|
||||
size="small"
|
||||
appearance="outline"
|
||||
checked={guideDirection === "horizontal"}
|
||||
onClick={() => setGuideDirection("horizontal")}
|
||||
icon={<LineHorizontal3Regular />}
|
||||
style={{ minWidth: "40px", padding: "2px 8px" }}
|
||||
>
|
||||
Horizontal
|
||||
</ToggleButton>
|
||||
@@ -683,33 +623,24 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
checked={guideDirection === "vertical"}
|
||||
onClick={() => setGuideDirection("vertical")}
|
||||
icon={<SplitVerticalRegular />}
|
||||
style={{ minWidth: "40px", padding: "2px 8px" }}
|
||||
>
|
||||
Vertical
|
||||
</ToggleButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={styles.controlRow}>
|
||||
<Label className={styles.controlLabel}>Color</Label>
|
||||
<div style={{ display: "flex" }}>
|
||||
<ColorButton color="blue" selectedColor={guideColor} onClick={setGuideColor} />
|
||||
<ColorButton color="red" selectedColor={guideColor} onClick={setGuideColor} />
|
||||
<ColorButton color="yellow" selectedColor={guideColor} onClick={setGuideColor} />
|
||||
<ColorButton color="green" selectedColor={guideColor} onClick={setGuideColor} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={styles.guideButtonGrid}>
|
||||
<Button
|
||||
appearance="primary"
|
||||
|
||||
<ColorSwatches label="Color" value={guideColor} onChange={setGuideColor} />
|
||||
|
||||
<div className={styles.buttonGrid}>
|
||||
<Button
|
||||
appearance="primary"
|
||||
className={styles.gridButton}
|
||||
onClick={addGuideline}
|
||||
onClick={addGuideline}
|
||||
icon={<AddRegular />}
|
||||
disabled={isProcessing}
|
||||
title="Add Guideline"
|
||||
title="Add guideline"
|
||||
>
|
||||
Add
|
||||
Add guide
|
||||
</Button>
|
||||
<ConfirmButton
|
||||
appearance="primary"
|
||||
@@ -717,12 +648,12 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
onConfirm={removeGuidelines}
|
||||
icon={<DismissRegular />}
|
||||
disabled={isProcessing}
|
||||
title="Remove All Guidelines"
|
||||
title="Remove all guidelines"
|
||||
confirmTitle="Remove all guidelines?"
|
||||
confirmMessage="This removes every guideline from the current slide."
|
||||
confirmLabel="Remove"
|
||||
>
|
||||
Remove
|
||||
Remove guides
|
||||
</ConfirmButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { Image, tokens, makeStyles } from "@fluentui/react-components";
|
||||
|
||||
export interface HeaderProps {
|
||||
title: string;
|
||||
logo: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
const useStyles = makeStyles({
|
||||
welcome__header: {
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
paddingBottom: "30px",
|
||||
paddingTop: "100px",
|
||||
backgroundColor: tokens.colorNeutralBackground3,
|
||||
},
|
||||
message: {
|
||||
fontSize: tokens.fontSizeHero900,
|
||||
fontWeight: tokens.fontWeightRegular,
|
||||
fontColor: tokens.colorNeutralBackgroundStatic,
|
||||
},
|
||||
});
|
||||
|
||||
const Header: React.FC<HeaderProps> = (props: HeaderProps) => {
|
||||
const { title, logo, message } = props;
|
||||
const styles = useStyles();
|
||||
|
||||
return (
|
||||
<section className={styles.welcome__header}>
|
||||
<Image width="90" height="90" src={logo} alt={title} />
|
||||
<h1 className={styles.message}>{message}</h1>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
export default Header;
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import * as React from "react";
|
||||
import { Dropdown, Field, Option } from "@fluentui/react-components";
|
||||
import { Dropdown, Field, makeStyles, Option, Text } from "@fluentui/react-components";
|
||||
import { TextBulletListRegular } from "@fluentui/react-icons";
|
||||
import { useStatusContext } from "../context/StatusContext";
|
||||
import { useSettings } from "../context/SettingsContext";
|
||||
@@ -22,8 +22,15 @@ const DETECTION_LABELS: Record<TitleDetectionMethod, string> = {
|
||||
first: "First text on slide"
|
||||
};
|
||||
|
||||
const useStyles = makeStyles({
|
||||
dropdown: {
|
||||
width: "100%"
|
||||
}
|
||||
});
|
||||
|
||||
export const InsertTitles: React.FC = () => {
|
||||
const styles = useCommonStyles();
|
||||
const localStyles = useStyles();
|
||||
const { slideSize } = useSettings();
|
||||
const { setStatusMessage, setStatusType, setIsProcessing, setProgress } = useStatusContext();
|
||||
const [titleDetectionMethod, setTitleDetectionMethod] =
|
||||
@@ -109,6 +116,9 @@ export const InsertTitles: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<Text size={200} className={styles.hint}>
|
||||
Select the text box that should receive the collected titles.
|
||||
</Text>
|
||||
<div className={styles.buttonGroup}>
|
||||
<ActionButton
|
||||
title="Insert Titles"
|
||||
@@ -122,6 +132,7 @@ export const InsertTitles: React.FC = () => {
|
||||
|
||||
<Field label="Title detection">
|
||||
<Dropdown
|
||||
className={localStyles.dropdown}
|
||||
value={DETECTION_LABELS[titleDetectionMethod]}
|
||||
selectedOptions={[titleDetectionMethod]}
|
||||
onOptionSelect={(_, data) => {
|
||||
@@ -140,6 +151,7 @@ export const InsertTitles: React.FC = () => {
|
||||
|
||||
<Field label="Slide numbers">
|
||||
<Dropdown
|
||||
className={localStyles.dropdown}
|
||||
value={includeSlideNumbers ? "Include slide numbers" : "Exclude slide numbers"}
|
||||
selectedOptions={[includeSlideNumbers ? "yes" : "no"]}
|
||||
onOptionSelect={(_, data) => {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
import * as React from "react";
|
||||
import { Text } from "@fluentui/react-components";
|
||||
import { ColorRegular } from "@fluentui/react-icons";
|
||||
import { useStatusContext } from "../context/StatusContext";
|
||||
import { useCommonStyles } from "./commonStyles";
|
||||
@@ -321,6 +322,9 @@ export const MatchProperties: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<Text size={200} className={styles.hint}>
|
||||
Select two or more shapes; the first shape is the source.
|
||||
</Text>
|
||||
<div className={styles.buttonGroup}>
|
||||
<ActionButton
|
||||
title="Match Properties"
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
import * as React from "react";
|
||||
import { Text } from "@fluentui/react-components";
|
||||
import { ArrowFitInRegular } from "@fluentui/react-icons";
|
||||
import { useStatusContext } from "../context/StatusContext";
|
||||
import { useCommonStyles } from "./commonStyles";
|
||||
@@ -178,6 +179,9 @@ export const MatchSizes: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<Text size={200} className={styles.hint}>
|
||||
Select two or more shapes; the first shape sets the size.
|
||||
</Text>
|
||||
<div className={styles.buttonGroup}>
|
||||
<ActionButton
|
||||
title="Match Sizes"
|
||||
|
||||
@@ -6,10 +6,7 @@
|
||||
*/
|
||||
|
||||
import * as React from "react";
|
||||
import {
|
||||
Button,
|
||||
makeStyles
|
||||
} from "@fluentui/react-components";
|
||||
import { Button, Text } from "@fluentui/react-components";
|
||||
import {
|
||||
GaugeRegular,
|
||||
DismissRegular
|
||||
@@ -25,25 +22,7 @@ import {
|
||||
} from "../services/progressBar";
|
||||
import ConfirmButton from "./ConfirmButton";
|
||||
|
||||
const useStyles = makeStyles({
|
||||
buttonGrid: {
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(2, 1fr)",
|
||||
gap: "8px",
|
||||
width: "100%"
|
||||
},
|
||||
progressButton: {
|
||||
width: "100%",
|
||||
minWidth: 0,
|
||||
padding: "8px 4px",
|
||||
"& span": {
|
||||
justifyContent: "center"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export const ProgressBarButtons: React.FC = () => {
|
||||
const styles = useStyles();
|
||||
const commonStyles = useCommonStyles();
|
||||
const { slideSize } = useSettings();
|
||||
const {
|
||||
@@ -135,20 +114,21 @@ export const ProgressBarButtons: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className={commonStyles.container}>
|
||||
<div className={styles.buttonGrid}>
|
||||
<Text size={200} className={commonStyles.hint}>
|
||||
Adds a progress bar to every slide. Each slide gets two shapes.
|
||||
</Text>
|
||||
<div className={commonStyles.buttonGroup}>
|
||||
<Button
|
||||
appearance="primary"
|
||||
className={styles.progressButton}
|
||||
onClick={addProgressBar}
|
||||
icon={<GaugeRegular />}
|
||||
disabled={isProcessing}
|
||||
title="Add Progress Bar"
|
||||
>
|
||||
Add
|
||||
Add progress bar
|
||||
</Button>
|
||||
<ConfirmButton
|
||||
appearance="primary"
|
||||
className={styles.progressButton}
|
||||
onConfirm={removeProgressBar}
|
||||
icon={<DismissRegular />}
|
||||
disabled={isProcessing}
|
||||
@@ -157,7 +137,7 @@ export const ProgressBarButtons: React.FC = () => {
|
||||
confirmMessage="This removes the progress bar from every slide in the presentation."
|
||||
confirmLabel="Remove"
|
||||
>
|
||||
Remove
|
||||
Remove progress bars
|
||||
</ConfirmButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,361 @@
|
||||
/**
|
||||
* @file RasterManager.tsx
|
||||
* @description Adds and removes a wireframe cell raster on the current slide.
|
||||
*/
|
||||
|
||||
import * as React from "react";
|
||||
import {
|
||||
Button,
|
||||
Dropdown,
|
||||
Field,
|
||||
Input,
|
||||
makeStyles,
|
||||
Option,
|
||||
Text,
|
||||
tokens,
|
||||
} from "@fluentui/react-components";
|
||||
import { DismissRegular, GridDotsRegular } from "@fluentui/react-icons";
|
||||
import { useStatusContext } from "../context/StatusContext";
|
||||
import { useSettings } from "../context/SettingsContext";
|
||||
import { useCommonStyles } from "./commonStyles";
|
||||
import { getErrorMessage } from "../types/office-types";
|
||||
import {
|
||||
RASTER_DEFAULT_GUTTER_MM,
|
||||
RASTER_DEFAULT_OPACITY,
|
||||
RASTER_PRESETS,
|
||||
RASTER_SCOPE_LABELS,
|
||||
RasterPresetId,
|
||||
RasterScope,
|
||||
} from "../constants";
|
||||
import {
|
||||
addRasterCells,
|
||||
computeRasterLayout,
|
||||
formatMillimeters,
|
||||
getRasterTarget,
|
||||
removeAllRasters,
|
||||
} from "../services/raster";
|
||||
import { isCancellationRequested, resetCancellation } from "../services/cancellation";
|
||||
import { ColorSwatches, SwatchColor, SWATCH_VALUES } from "./ColorSwatches";
|
||||
import ConfirmButton from "./ConfirmButton";
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: tokens.spacingVerticalM,
|
||||
},
|
||||
control: {
|
||||
width: "100%",
|
||||
},
|
||||
twoColumn: {
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(2, minmax(0, 1fr))",
|
||||
gap: tokens.spacingHorizontalS,
|
||||
"@media (max-width: 360px)": {
|
||||
gridTemplateColumns: "1fr",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const parseInteger = (value: string): number => Number.parseInt(value, 10);
|
||||
const parseDecimal = (value: string): number => Number.parseFloat(value);
|
||||
|
||||
/** PowerPoint shape coordinates use points. */
|
||||
const MILLIMETERS_TO_POINTS = 72 / 25.4;
|
||||
|
||||
export const RasterManager: React.FC = () => {
|
||||
const styles = useStyles();
|
||||
const commonStyles = useCommonStyles();
|
||||
const { slideSize } = useSettings();
|
||||
const { setStatusMessage, setStatusType, isProcessing, setIsProcessing, setProgress } =
|
||||
useStatusContext();
|
||||
|
||||
const [preset, setPreset] = React.useState<RasterPresetId>("coarse");
|
||||
const [scope, setScope] = React.useState<RasterScope>("slide");
|
||||
const [columnsInput, setColumnsInput] = React.useState("12");
|
||||
const [rowsInput, setRowsInput] = React.useState("8");
|
||||
const [gutterInput, setGutterInput] = React.useState(String(RASTER_DEFAULT_GUTTER_MM));
|
||||
const [opacityInput, setOpacityInput] = React.useState(String(RASTER_DEFAULT_OPACITY));
|
||||
const [color, setColor] = React.useState<SwatchColor>("gray");
|
||||
|
||||
const layoutResult = React.useMemo(
|
||||
() =>
|
||||
computeRasterLayout({
|
||||
columns: parseInteger(columnsInput),
|
||||
rows: parseInteger(rowsInput),
|
||||
gutter: parseDecimal(gutterInput) * MILLIMETERS_TO_POINTS,
|
||||
slideWidth: slideSize.width,
|
||||
slideHeight: slideSize.height,
|
||||
}),
|
||||
[columnsInput, rowsInput, gutterInput, slideSize.height, slideSize.width]
|
||||
);
|
||||
|
||||
const opacity = parseDecimal(opacityInput);
|
||||
const opacityValid = Number.isFinite(opacity) && opacity >= 0 && opacity <= 100;
|
||||
const layout = layoutResult.ok ? layoutResult.layout : null;
|
||||
const canAdd = layout !== null && opacityValid;
|
||||
|
||||
const presetLabel =
|
||||
preset === "custom"
|
||||
? "Custom"
|
||||
: (RASTER_PRESETS.find((item) => item.id === preset)?.label ?? "Custom");
|
||||
|
||||
const scopeHint =
|
||||
scope === "slide"
|
||||
? "Sits on top of the current slide's content."
|
||||
: scope === "layout"
|
||||
? "Background: appears on every slide using this layout."
|
||||
: "Background: appears on every slide in the presentation.";
|
||||
|
||||
const scopeTarget =
|
||||
scope === "slide"
|
||||
? "the current slide"
|
||||
: scope === "layout"
|
||||
? "this slide's layout"
|
||||
: "the slide master";
|
||||
|
||||
const hint = !layoutResult.ok
|
||||
? layoutResult.error
|
||||
: !opacityValid
|
||||
? "Opacity must be between 0 and 100."
|
||||
: `Cell size: ${formatMillimeters(layoutResult.layout.cellWidth)} × ${formatMillimeters(layoutResult.layout.cellHeight)} mm · ${layoutResult.layout.total} cells`;
|
||||
|
||||
const handlePreset = (nextPreset: RasterPresetId): void => {
|
||||
setPreset(nextPreset);
|
||||
if (nextPreset === "custom") return;
|
||||
|
||||
const selected = RASTER_PRESETS.find((item) => item.id === nextPreset);
|
||||
if (!selected) return;
|
||||
|
||||
setColumnsInput(String(selected.columns));
|
||||
setRowsInput(String(selected.rows));
|
||||
setGutterInput(String(RASTER_DEFAULT_GUTTER_MM));
|
||||
};
|
||||
|
||||
const updateGeometryNumber =
|
||||
(setter: React.Dispatch<React.SetStateAction<string>>) =>
|
||||
(event: React.ChangeEvent<HTMLInputElement>): void => {
|
||||
setter(event.target.value);
|
||||
setPreset("custom");
|
||||
};
|
||||
|
||||
const updateOpacity = (event: React.ChangeEvent<HTMLInputElement>): void => {
|
||||
setOpacityInput(event.target.value);
|
||||
};
|
||||
|
||||
const addRasterToSlide = async (): Promise<void> => {
|
||||
if (!layoutResult.ok) {
|
||||
setStatusMessage(layoutResult.error);
|
||||
setStatusType("warning");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!opacityValid) {
|
||||
setStatusMessage("Opacity must be between 0 and 100.");
|
||||
setStatusType("warning");
|
||||
return;
|
||||
}
|
||||
|
||||
resetCancellation();
|
||||
setProgress(null);
|
||||
setIsProcessing(true);
|
||||
|
||||
try {
|
||||
await PowerPoint.run(async (context) => {
|
||||
const selectedSlides = context.presentation.getSelectedSlides();
|
||||
selectedSlides.load("items");
|
||||
await context.sync();
|
||||
|
||||
if (selectedSlides.items.length === 0) {
|
||||
setStatusMessage("No slide selected.");
|
||||
setStatusType("warning");
|
||||
return;
|
||||
}
|
||||
|
||||
const slide = selectedSlides.items[0];
|
||||
const target = await getRasterTarget(context, slide, scope);
|
||||
|
||||
// Keep one raster in the presentation: clear the current slide, all
|
||||
// layouts, and the slide master before adding the new one.
|
||||
await removeAllRasters(context);
|
||||
|
||||
const result = await addRasterCells(
|
||||
context,
|
||||
target,
|
||||
layoutResult.layout,
|
||||
SWATCH_VALUES[color],
|
||||
opacity,
|
||||
(current, total) => setProgress({ current, total })
|
||||
);
|
||||
|
||||
if (isCancellationRequested() || result.cancelled) {
|
||||
setStatusMessage("Operation cancelled.");
|
||||
setStatusType("warning");
|
||||
return;
|
||||
}
|
||||
|
||||
setStatusMessage(
|
||||
`Added ${layoutResult.layout.columns} × ${layoutResult.layout.rows} raster (${result.created} cells) to ${scopeTarget}.`
|
||||
);
|
||||
setStatusType("success");
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
setStatusMessage(`Error: ${getErrorMessage(error)}`);
|
||||
setStatusType("error");
|
||||
console.error("Add raster error:", error);
|
||||
} finally {
|
||||
setIsProcessing(false);
|
||||
setProgress(null);
|
||||
}
|
||||
};
|
||||
|
||||
const removeRasterFromSlide = async (): Promise<void> => {
|
||||
resetCancellation();
|
||||
setProgress(null);
|
||||
setIsProcessing(true);
|
||||
|
||||
try {
|
||||
await PowerPoint.run(async (context) => {
|
||||
const result = await removeAllRasters(context);
|
||||
|
||||
if (result.removed > 0) {
|
||||
setStatusMessage(`Removed ${result.removed} raster cells from the presentation.`);
|
||||
setStatusType("success");
|
||||
} else {
|
||||
setStatusMessage("No raster found in the presentation.");
|
||||
setStatusType("warning");
|
||||
}
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
setStatusMessage(`Error: ${getErrorMessage(error)}`);
|
||||
setStatusType("error");
|
||||
console.error("Remove raster error:", error);
|
||||
} finally {
|
||||
setIsProcessing(false);
|
||||
setProgress(null);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.root}>
|
||||
<Text size={200} className={commonStyles.hint}>
|
||||
Adds a wireframe cell raster for object placement. Remove it before presenting.
|
||||
</Text>
|
||||
|
||||
<Field label="Place on" hint={scopeHint}>
|
||||
<Dropdown
|
||||
className={styles.control}
|
||||
value={RASTER_SCOPE_LABELS[scope]}
|
||||
selectedOptions={[scope]}
|
||||
onOptionSelect={(_, data) => {
|
||||
if (data.optionValue) {
|
||||
setScope(data.optionValue as RasterScope);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Option value="slide">{RASTER_SCOPE_LABELS.slide}</Option>
|
||||
<Option value="layout">{RASTER_SCOPE_LABELS.layout}</Option>
|
||||
<Option value="master">{RASTER_SCOPE_LABELS.master}</Option>
|
||||
</Dropdown>
|
||||
</Field>
|
||||
|
||||
<Field label="Preset">
|
||||
<Dropdown
|
||||
className={styles.control}
|
||||
value={presetLabel}
|
||||
selectedOptions={[preset]}
|
||||
onOptionSelect={(_, data) => {
|
||||
if (data.optionValue) {
|
||||
handlePreset(data.optionValue as RasterPresetId);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{RASTER_PRESETS.map((item) => (
|
||||
<Option key={item.id} value={item.id}>
|
||||
{item.label}
|
||||
</Option>
|
||||
))}
|
||||
<Option value="custom">Custom</Option>
|
||||
</Dropdown>
|
||||
</Field>
|
||||
|
||||
<div className={styles.twoColumn}>
|
||||
<Field label="Columns">
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
max={48}
|
||||
value={columnsInput}
|
||||
onChange={updateGeometryNumber(setColumnsInput)}
|
||||
title="Number of raster columns"
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Rows">
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
max={32}
|
||||
value={rowsInput}
|
||||
onChange={updateGeometryNumber(setRowsInput)}
|
||||
title="Number of raster rows"
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
|
||||
<div className={styles.twoColumn}>
|
||||
<Field label="Gutter (mm)">
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
step="0.1"
|
||||
value={gutterInput}
|
||||
onChange={updateGeometryNumber(setGutterInput)}
|
||||
title="Space between raster cells in millimetres"
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Opacity (%)">
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
max={100}
|
||||
value={opacityInput}
|
||||
onChange={updateOpacity}
|
||||
title="Raster cell opacity percentage"
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
|
||||
<ColorSwatches label="Color" value={color} onChange={setColor} />
|
||||
|
||||
<Text size={200} className={commonStyles.hint}>
|
||||
{hint}
|
||||
</Text>
|
||||
|
||||
<div className={commonStyles.buttonGroup}>
|
||||
<Button
|
||||
appearance="primary"
|
||||
icon={<GridDotsRegular />}
|
||||
onClick={addRasterToSlide}
|
||||
disabled={isProcessing || !canAdd}
|
||||
title="Add raster"
|
||||
>
|
||||
Add raster
|
||||
</Button>
|
||||
<ConfirmButton
|
||||
appearance="primary"
|
||||
icon={<DismissRegular />}
|
||||
onConfirm={removeRasterFromSlide}
|
||||
disabled={isProcessing}
|
||||
title="Remove raster"
|
||||
confirmTitle="Remove raster?"
|
||||
confirmMessage="This removes the raster from every slide, layout, and slide master in the presentation."
|
||||
confirmLabel="Remove"
|
||||
>
|
||||
Remove raster
|
||||
</ConfirmButton>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RasterManager;
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
import * as React from "react";
|
||||
import { Text } from "@fluentui/react-components";
|
||||
import { CircleRegular } from "@fluentui/react-icons";
|
||||
import { useStatusContext } from "../context/StatusContext";
|
||||
import { useCommonStyles } from "./commonStyles";
|
||||
@@ -160,6 +161,9 @@ export const RoundImage: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<Text size={200} className={styles.hint}>
|
||||
Select one image to create the mask, then intersect it in PowerPoint.
|
||||
</Text>
|
||||
<div className={styles.buttonGroup}>
|
||||
<ActionButton
|
||||
title="Round Image"
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import * as React from "react";
|
||||
import {
|
||||
Accordion,
|
||||
AccordionHeader,
|
||||
AccordionItem,
|
||||
AccordionPanel,
|
||||
@@ -10,46 +9,46 @@ import {
|
||||
|
||||
interface SectionProps {
|
||||
title: string;
|
||||
/** Stable accordion value; defaults to the title. */
|
||||
value?: string;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const useStyles = makeStyles({
|
||||
section: {
|
||||
marginBottom: "6px",
|
||||
padding: "12px",
|
||||
borderRadius: "8px",
|
||||
backgroundColor: tokens.colorNeutralBackground2,
|
||||
boxShadow: "0 1px 2px rgba(0, 0, 0, 0.06)",
|
||||
transition: "all 0.2s ease",
|
||||
":hover": {
|
||||
boxShadow: "0 2px 4px rgba(0, 0, 0, 0.1)"
|
||||
}
|
||||
item: {
|
||||
borderBottomWidth: "1px",
|
||||
borderBottomStyle: "solid",
|
||||
borderBottomColor: tokens.colorNeutralStroke3
|
||||
},
|
||||
accordion: {
|
||||
width: "100%"
|
||||
header: {
|
||||
color: tokens.colorNeutralForeground1,
|
||||
fontSize: tokens.fontSizeBase400,
|
||||
fontWeight: tokens.fontWeightSemibold
|
||||
},
|
||||
sectionTitle: {
|
||||
fontWeight: tokens.fontWeightSemibold,
|
||||
color: tokens.colorBrandForeground1,
|
||||
fontSize: tokens.fontSizeBase400
|
||||
stack: {
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: tokens.spacingVerticalM,
|
||||
paddingBottom: tokens.spacingVerticalM
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Collapsible section used to group related tools.
|
||||
* A single disclosure section inside the task pane's shared `Accordion`.
|
||||
*
|
||||
* `Section` must be rendered inside an `Accordion` so the disclosure widgets
|
||||
* share keyboard navigation and expansion state.
|
||||
*/
|
||||
export const Section: React.FC<SectionProps> = ({ title, children }) => {
|
||||
export const Section: React.FC<SectionProps> = ({ title, value, children }) => {
|
||||
const styles = useStyles();
|
||||
|
||||
return (
|
||||
<div className={styles.section}>
|
||||
<Accordion collapsible defaultOpenItems={[title]} className={styles.accordion}>
|
||||
<AccordionItem value={title}>
|
||||
<AccordionHeader className={styles.sectionTitle}>{title}</AccordionHeader>
|
||||
<AccordionPanel>{children}</AccordionPanel>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
<AccordionItem value={value ?? title} className={styles.item}>
|
||||
<AccordionHeader className={styles.header}>{title}</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.stack}>{children}</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
import * as React from "react";
|
||||
import { Text } from "@fluentui/react-components";
|
||||
import { ArrowSwapRegular } from "@fluentui/react-icons";
|
||||
import { useStatusContext } from "../context/StatusContext";
|
||||
import { useCommonStyles } from "./commonStyles";
|
||||
@@ -142,6 +143,9 @@ export const SwapPositions: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<Text size={200} className={styles.hint}>
|
||||
Select exactly two shapes to exchange their positions.
|
||||
</Text>
|
||||
<div className={styles.buttonGroup}>
|
||||
<ActionButton
|
||||
title="Swap Positions"
|
||||
|
||||
@@ -1,49 +1,30 @@
|
||||
import { makeStyles } from "@fluentui/react-components";
|
||||
import { makeStyles, tokens } from "@fluentui/react-components";
|
||||
|
||||
// Common styles used across multiple components
|
||||
/**
|
||||
* Shared layout styles for the task pane.
|
||||
*
|
||||
* Only layout primitives live here. Status colours, spacing and typography come
|
||||
* from Fluent tokens so the pane follows the active (light or dark) theme.
|
||||
*/
|
||||
export const useCommonStyles = makeStyles({
|
||||
container: {
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
width: "100%",
|
||||
gap: tokens.spacingVerticalS
|
||||
},
|
||||
buttonGroup: {
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: "8px",
|
||||
marginBottom: "2px",
|
||||
gap: tokens.spacingVerticalS
|
||||
},
|
||||
actionButton: {
|
||||
justifyContent: "flex-start",
|
||||
transitionProperty: "all",
|
||||
transitionDuration: "200ms",
|
||||
transitionTimingFunction: "cubic-bezier(0.33, 0, 0.67, 1)",
|
||||
transitionProperty: "background-color, border-color, color",
|
||||
transitionDuration: tokens.durationNormal,
|
||||
transitionTimingFunction: tokens.curveEasyEase
|
||||
},
|
||||
statusContainer: {
|
||||
marginTop: "4px",
|
||||
padding: "8px 12px",
|
||||
fontSize: "13px",
|
||||
borderRadius: "6px",
|
||||
backgroundColor: "#f3f2f1", // Light gray background
|
||||
transition: "all 0.3s ease",
|
||||
},
|
||||
successStatus: {
|
||||
backgroundColor: "#DFF6DD", // Light green background
|
||||
color: "#107C10", // Green text
|
||||
},
|
||||
warningStatus: {
|
||||
backgroundColor: "#FFF4CE", // Light yellow background
|
||||
color: "#797673", // Dark gray text
|
||||
},
|
||||
errorStatus: {
|
||||
backgroundColor: "#FDE7E9", // Light red background
|
||||
color: "#A80000", // Red text
|
||||
},
|
||||
statusIcon: {
|
||||
marginRight: "8px",
|
||||
},
|
||||
statusText: {
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
},
|
||||
});
|
||||
hint: {
|
||||
color: tokens.colorNeutralForeground3
|
||||
}
|
||||
});
|
||||
@@ -31,4 +31,37 @@ export const SHAPE_NAME_PREFIXES = {
|
||||
progressBar: "progress_bar_",
|
||||
grid: "edison_grid_",
|
||||
guide: "edison_guide_",
|
||||
raster: "edison_raster_",
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Raster (wireframe cell grid) defaults.
|
||||
*
|
||||
* A 2 mm gutter reproduces the 12 × 8 and 24 × 16 wireframes from the
|
||||
* design template at 16:9.
|
||||
*/
|
||||
export const RASTER_DEFAULT_GUTTER_MM = 2;
|
||||
export const RASTER_DEFAULT_OPACITY = 30;
|
||||
export const RASTER_MAX_CELLS = 600;
|
||||
|
||||
export type RasterPresetId = "coarse" | "fine" | "custom";
|
||||
|
||||
export type RasterScope = "slide" | "layout" | "master";
|
||||
|
||||
export const RASTER_SCOPE_LABELS: Record<RasterScope, string> = {
|
||||
slide: "Current slide",
|
||||
layout: "This layout (background)",
|
||||
master: "Slide master (all slides)",
|
||||
};
|
||||
|
||||
export interface RasterPreset {
|
||||
id: Exclude<RasterPresetId, "custom">;
|
||||
label: string;
|
||||
columns: number;
|
||||
rows: number;
|
||||
}
|
||||
|
||||
export const RASTER_PRESETS: readonly RasterPreset[] = [
|
||||
{ id: "coarse", label: "12 × 8", columns: 12, rows: 8 },
|
||||
{ id: "fine", label: "24 × 16", columns: 24, rows: 16 },
|
||||
];
|
||||
@@ -7,9 +7,18 @@ import Root from "./Root";
|
||||
const rootElement: HTMLElement | null = document.getElementById("container");
|
||||
const root = rootElement ? createRoot(rootElement) : undefined;
|
||||
|
||||
const hideLoadingIndicator = (): void => {
|
||||
const loading = document.getElementById("loading");
|
||||
if (!loading) return;
|
||||
|
||||
loading.style.opacity = "0";
|
||||
window.setTimeout(() => loading.remove(), 200);
|
||||
};
|
||||
|
||||
/* Render application after Office initializes */
|
||||
Office.onReady(() => {
|
||||
root?.render(<Root />);
|
||||
window.requestAnimationFrame(hideLoadingIndicator);
|
||||
});
|
||||
|
||||
// Define proper module hot interface for webpack hot module replacement
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { computeRasterLayout, formatMillimeters, type RasterLayout } from "./raster";
|
||||
import { RASTER_DEFAULT_GUTTER_MM, RASTER_MAX_CELLS } from "../constants";
|
||||
|
||||
const GUTTER = (RASTER_DEFAULT_GUTTER_MM * 72) / 25.4;
|
||||
|
||||
const mm = (points: number): number => (points * 25.4) / 72;
|
||||
|
||||
/** Narrow the result or fail the test with the returned error. */
|
||||
const layoutOf = (result: ReturnType<typeof computeRasterLayout>): RasterLayout => {
|
||||
if (!result.ok) {
|
||||
throw new Error(result.error);
|
||||
}
|
||||
return result.layout;
|
||||
};
|
||||
|
||||
describe("computeRasterLayout", () => {
|
||||
it("reproduces the 12 × 8 wireframe", () => {
|
||||
const layout = layoutOf(
|
||||
computeRasterLayout({
|
||||
columns: 12,
|
||||
rows: 8,
|
||||
gutter: GUTTER,
|
||||
slideWidth: 960,
|
||||
slideHeight: 540,
|
||||
})
|
||||
);
|
||||
|
||||
expect(layout.total).toBe(96);
|
||||
expect(mm(layout.cellWidth)).toBeCloseTo(26.39, 2);
|
||||
expect(mm(layout.cellHeight)).toBeCloseTo(22.06, 2);
|
||||
|
||||
const last = layout.cells[layout.cells.length - 1];
|
||||
expect(last.left + last.width).toBeCloseTo(960, 6);
|
||||
expect(last.top + last.height).toBeCloseTo(540, 6);
|
||||
});
|
||||
|
||||
it("reproduces the 24 × 16 wireframe", () => {
|
||||
const layout = layoutOf(
|
||||
computeRasterLayout({
|
||||
columns: 24,
|
||||
rows: 16,
|
||||
gutter: GUTTER,
|
||||
slideWidth: 960,
|
||||
slideHeight: 540,
|
||||
})
|
||||
);
|
||||
|
||||
expect(layout.total).toBe(384);
|
||||
// A round 2 mm gutter lands within 0.01 mm of the template's 12.20 mm.
|
||||
expect(Math.abs(mm(layout.cellWidth) - 12.2)).toBeLessThan(0.01);
|
||||
expect(mm(layout.cellHeight)).toBeCloseTo(10.03, 2);
|
||||
|
||||
const last = layout.cells[layout.cells.length - 1];
|
||||
expect(last.left + last.width).toBeCloseTo(960, 6);
|
||||
expect(last.top + last.height).toBeCloseTo(540, 6);
|
||||
});
|
||||
|
||||
it("fills a 4:3 slide", () => {
|
||||
const layout = layoutOf(
|
||||
computeRasterLayout({
|
||||
columns: 12,
|
||||
rows: 8,
|
||||
gutter: GUTTER,
|
||||
slideWidth: 720,
|
||||
slideHeight: 540,
|
||||
})
|
||||
);
|
||||
|
||||
const last = layout.cells[layout.cells.length - 1];
|
||||
expect(last.left + last.width).toBeCloseTo(720, 6);
|
||||
expect(last.top + last.height).toBeCloseTo(540, 6);
|
||||
});
|
||||
|
||||
it("handles a single cell without a gutter", () => {
|
||||
const layout = layoutOf(
|
||||
computeRasterLayout({
|
||||
columns: 1,
|
||||
rows: 1,
|
||||
gutter: 0,
|
||||
slideWidth: 960,
|
||||
slideHeight: 540,
|
||||
})
|
||||
);
|
||||
|
||||
expect(layout.cellWidth).toBe(960);
|
||||
expect(layout.cellHeight).toBe(540);
|
||||
expect(layout.cells).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("rejects invalid columns, rows, and gutters", () => {
|
||||
const base = { columns: 12, rows: 8, gutter: GUTTER, slideWidth: 960, slideHeight: 540 };
|
||||
|
||||
expect(computeRasterLayout({ ...base, columns: 0 }).ok).toBe(false);
|
||||
expect(computeRasterLayout({ ...base, rows: -1 }).ok).toBe(false);
|
||||
expect(computeRasterLayout({ ...base, gutter: -1 }).ok).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects rasters over the cell limit", () => {
|
||||
const result = computeRasterLayout({
|
||||
columns: 30,
|
||||
rows: 21,
|
||||
gutter: 2,
|
||||
slideWidth: 960,
|
||||
slideHeight: 540,
|
||||
});
|
||||
|
||||
expect(30 * 21).toBeGreaterThan(RASTER_MAX_CELLS);
|
||||
expect(result.ok).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects a gutter that leaves no room for cells", () => {
|
||||
const result = computeRasterLayout({
|
||||
columns: 12,
|
||||
rows: 8,
|
||||
gutter: 100,
|
||||
slideWidth: 960,
|
||||
slideHeight: 540,
|
||||
});
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatMillimeters", () => {
|
||||
it("converts points to millimetres", () => {
|
||||
expect(formatMillimeters(72)).toBe("25.40");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,275 @@
|
||||
/* global PowerPoint */
|
||||
|
||||
/**
|
||||
* @file raster.ts
|
||||
* @description Wireframe cell-grid ("raster") geometry and PowerPoint operations.
|
||||
*
|
||||
* A raster is a columns × rows grid of rectangles that fills the current slide.
|
||||
* It is used as a temporary placement aid, similar to grids and guidelines.
|
||||
*/
|
||||
|
||||
import { RASTER_MAX_CELLS, SHAPE_NAME_PREFIXES, RasterScope } from "../constants";
|
||||
import { deleteShapesByPrefix } from "../types/office-types";
|
||||
import { isCancellationRequested } from "./cancellation";
|
||||
|
||||
export const RASTER_PREFIX = SHAPE_NAME_PREFIXES.raster;
|
||||
|
||||
/** Smallest allowed cell edge, in points. */
|
||||
const MIN_CELL_SIZE = 1;
|
||||
|
||||
export interface RasterLayoutOptions {
|
||||
columns: number;
|
||||
rows: number;
|
||||
/** Space between cells, in points. */
|
||||
gutter: number;
|
||||
/** Slide width in points. */
|
||||
slideWidth: number;
|
||||
/** Slide height in points. */
|
||||
slideHeight: number;
|
||||
}
|
||||
|
||||
export interface RasterCell {
|
||||
column: number;
|
||||
row: number;
|
||||
left: number;
|
||||
top: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export interface RasterLayout {
|
||||
columns: number;
|
||||
rows: number;
|
||||
cellWidth: number;
|
||||
cellHeight: number;
|
||||
total: number;
|
||||
cells: RasterCell[];
|
||||
}
|
||||
|
||||
export type RasterLayoutResult = { ok: true; layout: RasterLayout } | { ok: false; error: string };
|
||||
|
||||
/**
|
||||
* Converts points to millimetres for display.
|
||||
*/
|
||||
export const formatMillimeters = (points: number): string => ((points * 25.4) / 72).toFixed(2);
|
||||
|
||||
/**
|
||||
* Computes the rectangles for a raster that fills the slide.
|
||||
*
|
||||
* Cells are evenly sized; the leftover space is distributed into the gutters.
|
||||
*/
|
||||
export function computeRasterLayout(options: RasterLayoutOptions): RasterLayoutResult {
|
||||
const { columns, rows, gutter, slideWidth, slideHeight } = options;
|
||||
|
||||
if (!Number.isInteger(columns) || columns < 1) {
|
||||
return { ok: false, error: "Columns must be at least 1." };
|
||||
}
|
||||
|
||||
if (!Number.isInteger(rows) || rows < 1) {
|
||||
return { ok: false, error: "Rows must be at least 1." };
|
||||
}
|
||||
|
||||
if (!Number.isFinite(gutter) || gutter < 0) {
|
||||
return { ok: false, error: "Gutter must be 0 or greater." };
|
||||
}
|
||||
|
||||
if (
|
||||
!Number.isFinite(slideWidth) ||
|
||||
!Number.isFinite(slideHeight) ||
|
||||
slideWidth <= 0 ||
|
||||
slideHeight <= 0
|
||||
) {
|
||||
return { ok: false, error: "Slide size is not available." };
|
||||
}
|
||||
|
||||
const total = columns * rows;
|
||||
if (total > RASTER_MAX_CELLS) {
|
||||
return {
|
||||
ok: false,
|
||||
error: `A ${columns} × ${rows} raster creates ${total} cells. The maximum is ${RASTER_MAX_CELLS}; reduce columns or rows.`,
|
||||
};
|
||||
}
|
||||
|
||||
const cellWidth = (slideWidth - (columns - 1) * gutter) / columns;
|
||||
const cellHeight = (slideHeight - (rows - 1) * gutter) / rows;
|
||||
|
||||
if (cellWidth < MIN_CELL_SIZE || cellHeight < MIN_CELL_SIZE) {
|
||||
return {
|
||||
ok: false,
|
||||
error: "The gutter is too large for this number of columns or rows.",
|
||||
};
|
||||
}
|
||||
|
||||
const cells: RasterCell[] = [];
|
||||
for (let row = 0; row < rows; row++) {
|
||||
for (let column = 0; column < columns; column++) {
|
||||
cells.push({
|
||||
column,
|
||||
row,
|
||||
left: column * (cellWidth + gutter),
|
||||
top: row * (cellHeight + gutter),
|
||||
width: cellWidth,
|
||||
height: cellHeight,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
layout: { columns, rows, cellWidth, cellHeight, total, cells },
|
||||
};
|
||||
}
|
||||
|
||||
export interface AddRasterResult {
|
||||
created: number;
|
||||
cancelled: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the raster cells to any shape collection (slide, layout, or master).
|
||||
* Existing raster shapes should be removed by the caller before this runs.
|
||||
*/
|
||||
export async function addRasterCells(
|
||||
context: PowerPoint.RequestContext,
|
||||
shapes: PowerPoint.ShapeCollection,
|
||||
layout: RasterLayout,
|
||||
color: string,
|
||||
opacity: number,
|
||||
onProgress: (current: number, total: number) => void
|
||||
): Promise<AddRasterResult> {
|
||||
const clampedOpacity = Math.min(100, Math.max(0, opacity));
|
||||
const transparency = (100 - clampedOpacity) / 100;
|
||||
const created: PowerPoint.Shape[] = [];
|
||||
let cancelled = false;
|
||||
|
||||
try {
|
||||
for (const cell of layout.cells) {
|
||||
if (isCancellationRequested()) {
|
||||
cancelled = true;
|
||||
break;
|
||||
}
|
||||
|
||||
const shape = shapes.addGeometricShape("Rectangle", {
|
||||
left: cell.left,
|
||||
top: cell.top,
|
||||
width: cell.width,
|
||||
height: cell.height,
|
||||
});
|
||||
|
||||
shape.name = `${RASTER_PREFIX}c${cell.column}_r${cell.row}`;
|
||||
shape.fill.setSolidColor(color);
|
||||
shape.fill.transparency = transparency;
|
||||
shape.lineFormat.visible = false;
|
||||
|
||||
created.push(shape);
|
||||
onProgress(created.length, layout.total);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
// Do not leave a partial raster behind if the host rejects a shape.
|
||||
for (const shape of created) {
|
||||
shape.delete();
|
||||
}
|
||||
await context.sync();
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (cancelled) {
|
||||
// Leave no partial raster behind.
|
||||
for (const shape of created) {
|
||||
shape.delete();
|
||||
}
|
||||
await context.sync();
|
||||
return { created: 0, cancelled: true };
|
||||
}
|
||||
|
||||
await context.sync();
|
||||
return { created: created.length, cancelled: false };
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the shape collection for the requested raster scope.
|
||||
*/
|
||||
export async function getRasterTarget(
|
||||
context: PowerPoint.RequestContext,
|
||||
slide: PowerPoint.Slide,
|
||||
scope: RasterScope
|
||||
): Promise<PowerPoint.ShapeCollection> {
|
||||
if (scope === "layout") {
|
||||
slide.load("layout");
|
||||
await context.sync();
|
||||
return slide.layout.shapes;
|
||||
}
|
||||
|
||||
if (scope === "master") {
|
||||
slide.load("slideMaster");
|
||||
await context.sync();
|
||||
return slide.slideMaster.shapes;
|
||||
}
|
||||
|
||||
return slide.shapes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads every shape collection that can contain a raster: all slides, all
|
||||
* layouts, and all slide masters. Names are loaded so callers can filter.
|
||||
*/
|
||||
async function loadRasterCollections(
|
||||
context: PowerPoint.RequestContext
|
||||
): Promise<PowerPoint.ShapeCollection[]> {
|
||||
const slides = context.presentation.slides;
|
||||
const masters = context.presentation.slideMasters;
|
||||
slides.load("items");
|
||||
masters.load("items");
|
||||
await context.sync();
|
||||
|
||||
const collections: PowerPoint.ShapeCollection[] = [];
|
||||
for (const slide of slides.items) {
|
||||
collections.push(slide.shapes);
|
||||
}
|
||||
|
||||
for (const master of masters.items) {
|
||||
master.layouts.load("items");
|
||||
collections.push(master.shapes);
|
||||
}
|
||||
await context.sync();
|
||||
|
||||
for (const master of masters.items) {
|
||||
for (const layout of master.layouts.items) {
|
||||
collections.push(layout.shapes);
|
||||
}
|
||||
}
|
||||
|
||||
for (const collection of collections) {
|
||||
collection.load("items");
|
||||
}
|
||||
await context.sync();
|
||||
|
||||
for (const collection of collections) {
|
||||
for (const shape of collection.items) {
|
||||
shape.load("name");
|
||||
}
|
||||
}
|
||||
await context.sync();
|
||||
|
||||
return collections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes raster cells from every slide, layout, and slide master.
|
||||
*
|
||||
* The raster tool keeps one raster in the presentation, so cleanup is global
|
||||
* regardless of the selected scope.
|
||||
*/
|
||||
export async function removeAllRasters(
|
||||
context: PowerPoint.RequestContext
|
||||
): Promise<{ removed: number }> {
|
||||
const collections = await loadRasterCollections(context);
|
||||
|
||||
let removed = 0;
|
||||
for (const collection of collections) {
|
||||
removed += deleteShapesByPrefix(collection.items, RASTER_PREFIX);
|
||||
}
|
||||
await context.sync();
|
||||
|
||||
return { removed };
|
||||
}
|
||||
+43
-35
@@ -15,23 +15,46 @@
|
||||
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
--system-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
||||
--background: #faf9f8;
|
||||
--foreground: #242424;
|
||||
--accent: #0f6cbd;
|
||||
--accent-soft: rgba(15, 108, 189, 0.25);
|
||||
--error-background: #fde7e9;
|
||||
--error-foreground: #a80000;
|
||||
}
|
||||
|
||||
body {
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--background: #1f1f1f;
|
||||
--foreground: #ffffff;
|
||||
--accent: #479ef5;
|
||||
--accent-soft: rgba(71, 158, 245, 0.3);
|
||||
--error-background: #3b1a1c;
|
||||
--error-foreground: #ff99a4;
|
||||
}
|
||||
}
|
||||
|
||||
html,
|
||||
body,
|
||||
#container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: var(--system-font);
|
||||
background-color: var(--background);
|
||||
color: var(--foreground);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Custom scrollbar for macOS style */
|
||||
@@ -69,28 +92,31 @@
|
||||
padding: 16px;
|
||||
margin: 20px;
|
||||
border-radius: 8px;
|
||||
background-color: #FEF0F1;
|
||||
color: #D13438;
|
||||
background-color: var(--error-background);
|
||||
color: var(--error-foreground);
|
||||
font-family: var(--system-font);
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
/* Loading animation */
|
||||
.loading-container {
|
||||
#loading {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 10;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
justify-content: center;
|
||||
background-color: var(--background);
|
||||
transition: opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 3px solid rgba(0, 120, 212, 0.2);
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: 3px solid var(--accent-soft);
|
||||
border-radius: 50%;
|
||||
border-top-color: #0078D4;
|
||||
animation: spin 1s ease-in-out infinite;
|
||||
border-top-color: var(--accent);
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
@@ -101,7 +127,7 @@
|
||||
|
||||
<body>
|
||||
<!-- Loading spinner shown until React loads -->
|
||||
<div id="loading" class="loading-container">
|
||||
<div id="loading">
|
||||
<div class="spinner"></div>
|
||||
</div>
|
||||
|
||||
@@ -126,24 +152,6 @@
|
||||
document.getElementById("container").style.display = "none";
|
||||
document.getElementById("loading").style.display = "none";
|
||||
}
|
||||
|
||||
// Hide loading spinner when the app is loaded
|
||||
window.addEventListener('DOMContentLoaded', function() {
|
||||
// The React app will remove the loading element when it's ready
|
||||
setTimeout(function() {
|
||||
var loadingEl = document.getElementById("loading");
|
||||
if (loadingEl) {
|
||||
loadingEl.style.opacity = "0";
|
||||
loadingEl.style.transition = "opacity 0.3s ease";
|
||||
setTimeout(function() {
|
||||
if (loadingEl.parentNode) {
|
||||
loadingEl.parentNode.removeChild(loadingEl);
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
}, 500);
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
Reference in new issue
Block a user