Modernize platform, structure, and UX
CI / build (push) Canceled after 0s

Phase 3:
- Declare PowerPointApi 1.5 and replace template manifest values
- Remove the dead command pipeline and the tracked Babel/polyfill setup
- Extract constants, status/settings contexts, PowerPoint services, and an error boundary
- Build with ES2020 and strict TypeScript; hash production assets and drop prod source maps
- Add Vitest tests, CI, LICENSE, Node 20 pinning, and prune unused dependencies
- Correct the README, user guide, developer guide, and audit notes

Phase 4:
- Add a persisted 16:9/4:3 slide size setting used by all layout tools
- Add dark mode with Office/system theme detection
- Make sections collapsible and move to accessible Fluent controls
- Announce status through aria-live and add semantic status icons
- Add a progress counter with cooperative cancellation and a Stop button
- Update the tracked dependency tree for the pruned packages
This commit is contained in:
schihei committed 2026-11-25 12:01:40 +01:00
1 parent e57258afe9
commit 89989c04e9
6211 files changed
+7028 -274819

No files matched your search

+61 -91
View File
@@ -13,9 +13,13 @@ import {
ShieldLockRegular,
DismissRegular
} from "@fluentui/react-icons";
import { useStatusContext } from "./App";
import { useStatusContext } from "../context/StatusContext";
import { useSettings } from "../context/SettingsContext";
import { useCommonStyles } from "./commonStyles";
import { getErrorMessage } from "../types/office-types";
import { MARKER_NAMES } from "../constants";
import { addMarkerToCollections, removeMarkerFromCollections } from "../services/markers";
import { isCancellationRequested, resetCancellation } from "../services/cancellation";
import ConfirmButton from "./ConfirmButton";
/**
@@ -24,19 +28,12 @@ import ConfirmButton from "./ConfirmButton";
const CONFIDENTIAL_CONFIG = {
// Marking text that appears on slides
TEXT: "– Confidential –",
// Shape name used to identify confidential markings
SHAPE_NAME: "ConfidentialMarking",
// Font configuration
FONT: {
NAME: "Inter",
SIZE: 8,
COLOR: "#DA1335" // RGB(218, 19, 53)
},
// Default slide dimensions in points (if we can't get actual dimensions)
SLIDE: {
WIDTH: 960, // 10 inches * 72 points
HEIGHT: 540, // 7.5 inches * 72 points
},
// Text box configuration
TEXT_BOX: {
HEIGHT: 25,
@@ -82,11 +79,13 @@ interface ProcessingResult {
export const ConfidentialButtons: React.FC = () => {
const styles = useStyles();
const commonStyles = useCommonStyles();
const { slideSize } = useSettings();
const {
setStatusMessage,
setStatusType,
isProcessing,
setIsProcessing
setIsProcessing,
setProgress
} = useStatusContext();
/**
@@ -131,6 +130,8 @@ export const ConfidentialButtons: React.FC = () => {
* Adds confidential markings to all slides in the presentation
*/
const addConfidentialMarking = async (): Promise<void> => {
resetCancellation();
setProgress(null);
setIsProcessing(true);
try {
await PowerPoint.run(async (context) => {
@@ -146,12 +147,18 @@ export const ConfidentialButtons: React.FC = () => {
}
const result = await processAddMarkings(context, slides.items);
if (isCancellationRequested()) {
setStatusMessage("Operation cancelled.");
setStatusType("warning");
return;
}
updateStatusFromResult(result, true);
});
} catch (error) {
} catch (error: unknown) {
handleError(error, "Add confidential");
} finally {
setIsProcessing(false);
setProgress(null);
}
};
@@ -166,64 +173,42 @@ export const ConfidentialButtons: React.FC = () => {
context: PowerPoint.RequestContext,
slides: PowerPoint.Slide[]
): Promise<ProcessingResult> => {
const result: ProcessingResult = {
processedSlides: 0,
const positionFromTop = slideSize.height - CONFIDENTIAL_CONFIG.TEXT_BOX.POSITION_FROM_BOTTOM;
const result = await addMarkerToCollections(
context,
slides.map((slide) => slide.shapes),
{
name: MARKER_NAMES.confidential,
text: CONFIDENTIAL_CONFIG.TEXT,
font: {
name: CONFIDENTIAL_CONFIG.FONT.NAME,
size: CONFIDENTIAL_CONFIG.FONT.SIZE,
color: CONFIDENTIAL_CONFIG.FONT.COLOR
},
box: {
left: 0,
top: positionFromTop,
width: slideSize.width,
height: CONFIDENTIAL_CONFIG.TEXT_BOX.HEIGHT
},
horizontalAlignment: PowerPoint.ParagraphHorizontalAlignment.center
},
(current, total) => setProgress({ current, total })
);
return {
processedSlides: slides.length,
errorSlides: 0,
affectedCount: 0
affectedCount: result.affected
};
const { WIDTH, HEIGHT } = CONFIDENTIAL_CONFIG.SLIDE;
const positionFromTop = HEIGHT - CONFIDENTIAL_CONFIG.TEXT_BOX.POSITION_FROM_BOTTOM;
// Load the shapes and names for every slide in two batches instead of two syncs per slide
for (const slide of slides) {
slide.shapes.load("items");
}
await context.sync();
const shapesBySlide: PowerPoint.Shape[][] = [];
for (const slide of slides) {
shapesBySlide.push(slide.shapes.items);
for (const shape of slide.shapes.items) {
shape.load("name");
}
}
await context.sync();
// Replace any existing marking so repeated clicks do not duplicate it
for (const shapes of shapesBySlide) {
for (const shape of shapes) {
if (shape.name === CONFIDENTIAL_CONFIG.SHAPE_NAME) {
shape.delete();
}
}
}
// Create one marking per slide in a single batch
for (const slide of slides) {
const textBox = slide.shapes.addTextBox(CONFIDENTIAL_CONFIG.TEXT, {
left: 0,
top: positionFromTop,
width: WIDTH,
height: CONFIDENTIAL_CONFIG.TEXT_BOX.HEIGHT
});
textBox.name = CONFIDENTIAL_CONFIG.SHAPE_NAME;
textBox.textFrame.textRange.font.name = CONFIDENTIAL_CONFIG.FONT.NAME;
textBox.textFrame.textRange.font.size = CONFIDENTIAL_CONFIG.FONT.SIZE;
textBox.textFrame.textRange.font.color = CONFIDENTIAL_CONFIG.FONT.COLOR;
textBox.textFrame.textRange.paragraphFormat.horizontalAlignment = "Center";
result.processedSlides++;
}
await context.sync();
result.affectedCount = slides.length;
return result;
};
/**
* Removes confidential markings from all slides in the presentation
*/
const removeConfidentialMarking = async (): Promise<void> => {
resetCancellation();
setProgress(null);
setIsProcessing(true);
try {
await PowerPoint.run(async (context) => {
@@ -239,12 +224,18 @@ export const ConfidentialButtons: React.FC = () => {
}
const result = await processRemoveMarkings(context, slides.items);
if (isCancellationRequested()) {
setStatusMessage("Operation cancelled.");
setStatusType("warning");
return;
}
updateStatusFromResult(result, false);
});
} catch (error) {
} catch (error: unknown) {
handleError(error, "Remove confidential");
} finally {
setIsProcessing(false);
setProgress(null);
}
};
@@ -259,38 +250,17 @@ export const ConfidentialButtons: React.FC = () => {
context: PowerPoint.RequestContext,
slides: PowerPoint.Slide[]
): Promise<ProcessingResult> => {
const result: ProcessingResult = {
processedSlides: 0,
const result = await removeMarkerFromCollections(
context,
slides.map((slide) => slide.shapes),
MARKER_NAMES.confidential
);
return {
processedSlides: slides.length,
errorSlides: 0,
affectedCount: 0
affectedCount: result.affected
};
// Load the shapes and names for every slide in two batches
for (const slide of slides) {
slide.shapes.load("items");
}
await context.sync();
const allShapes: PowerPoint.Shape[] = [];
for (const slide of slides) {
for (const shape of slide.shapes.items) {
shape.load("name");
allShapes.push(shape);
}
}
await context.sync();
// Delete all matching shapes in one batch
for (const shape of allShapes) {
if (shape.name === CONFIDENTIAL_CONFIG.SHAPE_NAME) {
shape.delete();
result.affectedCount++;
}
}
await context.sync();
result.processedSlides = slides.length;
return result;
};
return (