@allyhub/sdk 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/node_modules/@allyhub/audio/dist/plan.d.ts +3 -0
- package/dist/node_modules/@allyhub/audio/dist/render.js +1 -1
- package/dist/node_modules/@allyhub/audio/package.json +1 -1
- package/dist/node_modules/@allyhub/chart/dist/chart-file.d.ts +2 -0
- package/dist/node_modules/@allyhub/chart/dist/chart-file.js +1 -1
- package/dist/node_modules/@allyhub/chart/dist/chart-xml.js +3 -2
- package/dist/node_modules/@allyhub/chart/dist/chart.d.ts +5 -12
- package/dist/node_modules/@allyhub/chart/dist/chart.js +2 -1
- package/dist/node_modules/@allyhub/chart/dist/color.d.ts +37 -0
- package/dist/node_modules/@allyhub/chart/dist/color.js +2 -0
- package/dist/node_modules/@allyhub/chart/dist/index.d.ts +1 -0
- package/dist/node_modules/@allyhub/chart/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/chart/dist/svg.js +1 -1
- package/dist/node_modules/@allyhub/chart/package.json +1 -1
- package/dist/node_modules/@allyhub/diagnostics/package.json +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/deck-code.d.ts +130 -0
- package/dist/node_modules/@allyhub/formats/dist/data/deck-code.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/gen.d.ts +3 -1
- package/dist/node_modules/@allyhub/formats/dist/data/gen.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/sheet.d.ts +512 -166
- package/dist/node_modules/@allyhub/formats/dist/data/sheet.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/slides.d.ts +2523 -136
- package/dist/node_modules/@allyhub/formats/dist/data/slides.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/schemas.d.ts +931 -87
- package/dist/node_modules/@allyhub/formats/dist/schemas.js +1 -1
- package/dist/node_modules/@allyhub/formats/package.json +1 -1
- package/dist/node_modules/@allyhub/image-draw/package.json +1 -1
- package/dist/node_modules/@allyhub/image-measure/package.json +1 -1
- package/dist/node_modules/@allyhub/image-sdk/package.json +1 -1
- package/dist/node_modules/@allyhub/measure/package.json +1 -1
- package/dist/node_modules/@allyhub/ooxml/dist/color.d.ts +11 -0
- package/dist/node_modules/@allyhub/ooxml/dist/color.js +1 -1
- package/dist/node_modules/@allyhub/ooxml/dist/ext.d.ts +43 -0
- package/dist/node_modules/@allyhub/ooxml/dist/ext.js +1 -1
- package/dist/node_modules/@allyhub/ooxml/dist/index.d.ts +2 -1
- package/dist/node_modules/@allyhub/ooxml/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/ooxml/dist/transform.d.ts +13 -0
- package/dist/node_modules/@allyhub/ooxml/dist/transform.js +2 -0
- package/dist/node_modules/@allyhub/ooxml/package.json +5 -1
- package/dist/node_modules/@allyhub/piece/dist/gen.d.ts +4 -4
- package/dist/node_modules/@allyhub/piece/dist/media.d.ts +2 -2
- package/dist/node_modules/@allyhub/piece/package.json +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/account.d.ts +49 -5
- package/dist/node_modules/@allyhub/protocol/dist/account.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/auth.d.ts +56 -0
- package/dist/node_modules/@allyhub/protocol/dist/auth.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/cloud.d.ts +72 -9
- package/dist/node_modules/@allyhub/protocol/dist/cloud.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/editor.d.ts +35 -20
- package/dist/node_modules/@allyhub/protocol/dist/editor.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/errors.d.ts +7 -0
- package/dist/node_modules/@allyhub/protocol/dist/errors.js +2 -0
- package/dist/node_modules/@allyhub/protocol/dist/events.d.ts +328 -0
- package/dist/node_modules/@allyhub/protocol/dist/events.js +2 -0
- package/dist/node_modules/@allyhub/protocol/dist/frame.d.ts +28 -2
- package/dist/node_modules/@allyhub/protocol/dist/frame.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/index.d.ts +2 -0
- package/dist/node_modules/@allyhub/protocol/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/jobs.d.ts +6 -6
- package/dist/node_modules/@allyhub/protocol/dist/mail.d.ts +2 -2
- package/dist/node_modules/@allyhub/protocol/dist/routes.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/snapshots.d.ts +69 -6
- package/dist/node_modules/@allyhub/protocol/dist/snapshots.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/tools.d.ts +9 -9
- package/dist/node_modules/@allyhub/protocol/package.json +1 -1
- package/dist/node_modules/@allyhub/runtimes/package.json +1 -1
- package/dist/node_modules/@allyhub/scenery/package.json +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/annotations.d.ts +14 -0
- package/dist/node_modules/@allyhub/sheet/dist/annotations.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/api/capabilities.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/index.d.ts +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/index.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/rules.d.ts +24 -0
- package/dist/node_modules/@allyhub/sheet/dist/api/rules.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/styles.d.ts +12 -0
- package/dist/node_modules/@allyhub/sheet/dist/api/styles.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/workbook.d.ts +3 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/workbook.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/arrange.d.ts +28 -1
- package/dist/node_modules/@allyhub/sheet/dist/arrange.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/data-tools.d.ts +42 -0
- package/dist/node_modules/@allyhub/sheet/dist/data-tools.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/edit.d.ts +43 -2
- package/dist/node_modules/@allyhub/sheet/dist/edit.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/fill.d.ts +10 -0
- package/dist/node_modules/@allyhub/sheet/dist/fill.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/filter.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/formula/rewrite.d.ts +14 -0
- package/dist/node_modules/@allyhub/sheet/dist/formula/rewrite.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/html.js +10 -10
- package/dist/node_modules/@allyhub/sheet/dist/index.d.ts +6 -1
- package/dist/node_modules/@allyhub/sheet/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/outline.d.ts +30 -0
- package/dist/node_modules/@allyhub/sheet/dist/outline.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/rich.d.ts +29 -0
- package/dist/node_modules/@allyhub/sheet/dist/rich.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/rules.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/table-style.d.ts +6 -0
- package/dist/node_modules/@allyhub/sheet/dist/table-style.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/table-styles.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/workbook.d.ts +5 -1
- package/dist/node_modules/@allyhub/sheet/dist/workbook.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/charts.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/import.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/read.d.ts +17 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/read.js +2 -2
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/runs.d.ts +56 -0
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/runs.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/styles.d.ts +6 -0
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/styles.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/write.js +1 -1
- package/dist/node_modules/@allyhub/sheet/package.json +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/animation.d.ts +117 -21
- package/dist/node_modules/@allyhub/slides-core/dist/animation.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/api.d.ts +181 -30
- package/dist/node_modules/@allyhub/slides-core/dist/api.js +3 -3
- package/dist/node_modules/@allyhub/slides-core/dist/capabilities.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/chart-api.d.ts +28 -2
- package/dist/node_modules/@allyhub/slides-core/dist/chart-api.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/check.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/enums.d.ts +222 -4
- package/dist/node_modules/@allyhub/slides-core/dist/enums.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/file.d.ts +6 -0
- package/dist/node_modules/@allyhub/slides-core/dist/file.js +3 -3
- package/dist/node_modules/@allyhub/slides-core/dist/generated/table-styles.d.ts +3 -0
- package/dist/node_modules/@allyhub/slides-core/dist/generated/table-styles.js +2 -0
- package/dist/node_modules/@allyhub/slides-core/dist/index.d.ts +3 -0
- package/dist/node_modules/@allyhub/slides-core/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/merge.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/model.d.ts +98 -10
- package/dist/node_modules/@allyhub/slides-core/dist/numbering.d.ts +6 -0
- package/dist/node_modules/@allyhub/slides-core/dist/numbering.js +2 -0
- package/dist/node_modules/@allyhub/slides-core/dist/office.d.ts +53 -0
- package/dist/node_modules/@allyhub/slides-core/dist/office.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/patterns.d.ts +8 -0
- package/dist/node_modules/@allyhub/slides-core/dist/patterns.js +2 -0
- package/dist/node_modules/@allyhub/slides-core/dist/resolve.d.ts +36 -6
- package/dist/node_modules/@allyhub/slides-core/dist/resolve.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/script.d.ts +11 -0
- package/dist/node_modules/@allyhub/slides-core/dist/script.js +2 -2
- package/dist/node_modules/@allyhub/slides-core/dist/sdk.d.ts +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/sdk.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/table-style.d.ts +48 -0
- package/dist/node_modules/@allyhub/slides-core/dist/table-style.js +2 -0
- package/dist/node_modules/@allyhub/slides-core/package.json +1 -1
- package/dist/node_modules/@allyhub/video-core/dist/mix-plan.js +1 -1
- package/dist/node_modules/@allyhub/video-core/dist/timeline.d.ts +4 -0
- package/dist/node_modules/@allyhub/video-core/package.json +1 -1
- package/dist/node_modules/@allyhub/video-sdk/package.json +1 -1
- package/docs/defaults.md +78 -4
- package/docs/image.md +1 -1
- package/docs/pictures.md +1 -1
- package/docs/project.md +1 -1
- package/docs/sheets.md +19 -9
- package/docs/slides.md +30 -16
- package/docs/speech.md +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { SheetRun } from "@allyhub/formats";
|
|
2
|
+
import { type Palette } from "./colors.js";
|
|
3
|
+
import type { XmlAttrs } from "./sax.js";
|
|
4
|
+
/** A run as the file says it: its text, and its font's elements by name. */
|
|
5
|
+
export interface RawRun {
|
|
6
|
+
text: string;
|
|
7
|
+
props: Record<string, XmlAttrs> | undefined;
|
|
8
|
+
}
|
|
9
|
+
/** A run's whole font, as the file gives it. */
|
|
10
|
+
export interface RunFont {
|
|
11
|
+
bold: boolean;
|
|
12
|
+
italic: boolean;
|
|
13
|
+
strike: boolean;
|
|
14
|
+
underline: NonNullable<SheetRun["underline"]>;
|
|
15
|
+
size: number | undefined;
|
|
16
|
+
color: string | undefined;
|
|
17
|
+
name: string | undefined;
|
|
18
|
+
script: SheetRun["script"];
|
|
19
|
+
}
|
|
20
|
+
/** A run read: its text, and its font when it has one. */
|
|
21
|
+
export interface ReadRun {
|
|
22
|
+
text: string;
|
|
23
|
+
font?: RunFont;
|
|
24
|
+
}
|
|
25
|
+
/** The runs of an `<si>` or an `<is>` as its elements stream in. */
|
|
26
|
+
export declare class RunsCollector {
|
|
27
|
+
readonly runs: RawRun[];
|
|
28
|
+
private inProps;
|
|
29
|
+
/** Whether the element was a run's: `<r>`, `<rPr>` or what is in it. */
|
|
30
|
+
open(name: string, attrs: XmlAttrs): boolean;
|
|
31
|
+
close(name: string): void;
|
|
32
|
+
/** A `<t>`'s text, the run's it is in. */
|
|
33
|
+
text(text: string): void;
|
|
34
|
+
}
|
|
35
|
+
/** The runs of a string read: their text, and each one's font. */
|
|
36
|
+
export declare function readRuns(raw: readonly RawRun[], p: Palette): ReadRun[];
|
|
37
|
+
/** What a cell's own font is, as a run's is set against it. */
|
|
38
|
+
export interface CellFont {
|
|
39
|
+
bold?: boolean | undefined;
|
|
40
|
+
italic?: boolean | undefined;
|
|
41
|
+
strike?: boolean | undefined;
|
|
42
|
+
underline?: SheetRun["underline"];
|
|
43
|
+
size?: number | undefined;
|
|
44
|
+
color?: string | undefined;
|
|
45
|
+
font?: string | undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* sheet.yaml's runs of a string: each says what its font has that the
|
|
49
|
+
* cell's does not. `base` is the workbook's body font, what a cell is in
|
|
50
|
+
* unless its look says.
|
|
51
|
+
*/
|
|
52
|
+
export declare function runsOver(runs: readonly ReadRun[], cell: CellFont, base: {
|
|
53
|
+
name?: string | undefined;
|
|
54
|
+
size?: number | undefined;
|
|
55
|
+
}): SheetRun[];
|
|
56
|
+
//# sourceMappingURL=runs.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
+
import{colorOf as g}from"./colors.js";import{readXstring as z}from"./xml.js";export class RunsCollector{runs=[];inProps=!1;open(i,r){if(i==="r")return this.runs.push({text:"",props:void 0}),!0;const e=this.runs[this.runs.length-1];return i==="rPr"&&e?(e.props={},this.inProps=!0,!0):this.inProps&&e?.props?(e.props[i]=r,!0):!1}close(i){i==="rPr"&&(this.inProps=!1)}text(i){const r=this.runs[this.runs.length-1];r&&(r.text+=i)}}const a=(u,i)=>{const r=u[i];if(r===void 0)return!1;const e=r.val;return e===void 0||e!=="0"&&e!=="false"},b=new Set(["double","singleAccounting","doubleAccounting"]);export function readRuns(u,i){return u.map(({text:r,props:e})=>{const n={text:z(r)};if(!e)return n;const t=e.u,s=t?.val,o=Number(e.sz?.val),l=e.vertAlign?.val;return n.font={bold:a(e,"b"),italic:a(e,"i"),strike:a(e,"strike"),underline:t===void 0||s==="none"?!1:s!==void 0&&b.has(s)?s:!0,size:Number.isFinite(o)&&o>0?o:void 0,color:g(e.color,i),name:e.rFont?.val,script:l==="superscript"||l==="subscript"?l:void 0},n})}export function runsOver(u,i,r){return u.map(({text:e,font:n})=>{const t={text:e};if(!n)return t;const s=(h,m)=>m===(i[h]===!0)?void 0:m,o=s("bold",n.bold);o!==void 0&&(t.bold=o);const l=s("italic",n.italic);l!==void 0&&(t.italic=l);const c=i.underline??!1;n.underline===c||n.underline===!0&&c==="single"||n.underline==="single"&&c===!0||(t.underline=n.underline);const p=s("strike",n.strike);p!==void 0&&(t.strike=p);const d=n.name??r.name;d!==void 0&&d!==(i.font??r.name)&&(t.font=d);const f=n.size??r.size;return f!==void 0&&f!==(i.size??r.size)&&(t.size=f),n.color!==void 0&&n.color.toUpperCase()!==(i.color??"#000000").toUpperCase()&&(t.color=n.color),n.script!==void 0&&(t.script=n.script),t})}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SheetRun } from "@allyhub/formats";
|
|
1
2
|
import type { CellLook } from "../workbook.js";
|
|
2
3
|
/** The body font of a workbook, whatever its cells say. */
|
|
3
4
|
export declare const DEFAULT_FONT: {
|
|
@@ -10,6 +11,11 @@ export declare const DEFAULT_FONT: {
|
|
|
10
11
|
* New Roman") is its first face.
|
|
11
12
|
*/
|
|
12
13
|
export declare function fontName(name: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* A rich string's run as `<r>`: its font whole, the cell's with the run's
|
|
16
|
+
* over it (`<rPr>`, whose font is `rFont`), or none when it says nothing.
|
|
17
|
+
*/
|
|
18
|
+
export declare function runXml(run: SheetRun, cell: CellLook): string;
|
|
13
19
|
export declare class Styles {
|
|
14
20
|
private readonly fonts;
|
|
15
21
|
private readonly fills;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{FIRST_CUSTOM as
|
|
2
|
+
import{RUN_FIELDS as x,runLook as y}from"../rich.js";import{FIRST_CUSTOM as v,builtinId as F}from"./numfmt.js";import{NS as I,el as e,xstring as S}from"./xml.js";export const DEFAULT_FONT={name:"Calibri",size:11};export function fontName(t){if(t.length<=31)return t;const n=t.split(/[;,]/u)[0]?.trim()??"";return(n===""?t:n).slice(0,31)}const f=t=>`FF${t.slice(1).toUpperCase()}`;class o{items=[];index=new Map;add(n){const r=this.index.get(n);if(r!==void 0)return r;const i=this.items.length;return this.items.push(n),this.index.set(n,i),i}}function h(t){const{underline:n}=t;return e("font",{},t.bold===!0?"<b/>":"",t.italic===!0?"<i/>":"",t.strike===!0?"<strike/>":"",n===!0||n==="single"?"<u/>":n?e("u",{val:n}):"",e("sz",{val:t.size??DEFAULT_FONT.size}),t.color===void 0?e("color",{theme:1}):e("color",{rgb:f(t.color)}),e("name",{val:fontName(t.font??DEFAULT_FONT.name)}),e("family",{val:2}),t.font===void 0?e("scheme",{val:"minor"}):"")}export function runXml(t,n){const r=`<t${/^\s|\s$|\n/u.test(t.text)?' xml:space="preserve"':""}>${S(t.text)}</t>`;if(x.every(s=>t[s]===void 0))return e("r",{},r);const i={...n,...y(t)},{underline:d}=i;return e("r",{},e("rPr",{},i.bold===!0?"<b/>":"",i.italic===!0?"<i/>":"",i.strike===!0?"<strike/>":"",d===!0||d==="single"?"<u/>":d?e("u",{val:d}):"",t.script===void 0?"":e("vertAlign",{val:t.script}),e("sz",{val:i.size??DEFAULT_FONT.size}),i.color===void 0?e("color",{theme:1}):e("color",{rgb:f(i.color)}),e("rFont",{val:fontName(i.font??DEFAULT_FONT.name)}),e("family",{val:2}),i.font===void 0?e("scheme",{val:"minor"}):""),r)}function w(t){const{pattern:n,color:r,background:i}=typeof t=="string"?{pattern:"solid",color:t,background:void 0}:t;return e("fill",{},e("patternFill",{patternType:n},r===void 0?"":e("fgColor",{rgb:f(r)}),i===void 0?n==="solid"?e("bgColor",{indexed:64}):"":e("bgColor",{rgb:f(i)})))}function u(t,n){return n?e(t,{style:n.style},n.color===void 0?e("color",{auto:1}):e("color",{rgb:f(n.color)})):e(t)}function b(t){return e("border",{},u("left",t.left),u("right",t.right),u("top",t.top),u("bottom",t.bottom),e("diagonal"))}function g(t,n="dxf",r){const{underline:i}=t,d=[t.bold===void 0?"":e("b",{val:t.bold}),t.italic===void 0?"":e("i",{val:t.italic}),t.strike===void 0?"":e("strike",{val:t.strike}),i===!0?"<u/>":"",t.color===void 0?"":e("color",{rgb:f(t.color)})].join(""),{fill:s,border:l}=t;return e(n,{},d===""?"":e("font",{},d),t.format===void 0||r===void 0?"":e("numFmt",{numFmtId:r,formatCode:t.format}),typeof s=="string"?e("fill",{},e("patternFill",{},e("bgColor",{rgb:f(s)}))):"",l?b(l):"")}const T=t=>t<0?90-t:t;function X(t){const n={horizontal:t.align,vertical:t.valign,textRotation:t.rotation===void 0?void 0:T(t.rotation),wrapText:t.wrap===!0?!0:void 0,indent:t.indent,shrinkToFit:t.shrink===!0?!0:void 0};return Object.values(n).every(r=>r===void 0)?"":e("alignment",n)}function z(t){const n={locked:t.locked===!1?!1:void 0,hidden:t.hide_formula===!0?!0:void 0};return n.locked===void 0&&n.hidden===void 0?"":e("protection",n)}export class Styles{fonts=new o;fills=new o;borders=new o;formats=new Map;xfs=new o;byLook=new Map;dxfs=new o;constructor(){this.fonts.add(h({})),this.fills.add(e("fill",{},e("patternFill",{patternType:"none"}))),this.fills.add(e("fill",{},e("patternFill",{patternType:"gray125"}))),this.borders.add(e("border",{},e("left"),e("right"),e("top"),e("bottom"),e("diagonal"))),this.xfs.add(e("xf",{numFmtId:0,fontId:0,fillId:0,borderId:0,xfId:0}))}format(n){if(n===void 0)return 0;const r=F(n);if(r!==void 0)return r;let i=this.formats.get(n);return i===void 0&&(i=v+this.formats.size,this.formats.set(n,i)),i}xf(n){const r=JSON.stringify(n),i=this.byLook.get(r);if(i!==void 0)return i;const d=this.format(n.format),s=this.fonts.add(h(n)),l=n.fill===void 0?0:this.fills.add(w(n.fill)),a=n.border===void 0?0:this.borders.add(b(n.border)),c=X(n),m=z(n),p=this.xfs.add(e("xf",{numFmtId:d,fontId:s,fillId:l,borderId:a,xfId:0,applyNumberFormat:d===0?void 0:!0,applyFont:s===0?void 0:!0,applyFill:l===0?void 0:!0,applyBorder:a===0?void 0:!0,applyAlignment:c===""?void 0:!0,applyProtection:m===""?void 0:!0},c,m));return this.byLook.set(r,p),p}dxf(n){return this.dxfs.add(g(n,"dxf",this.format(n.format)))}dxfXml(n,r){return g(n,r,this.format(n.format))}xml(){const n=(i,d)=>e(i,{count:d.length},d.join("")),r=[...this.formats].map(([i,d])=>e("numFmt",{numFmtId:d,formatCode:i}));return e("styleSheet",{xmlns:I.main},r.length>0?n("numFmts",r):"",n("fonts",this.fonts.items),n("fills",this.fills.items),n("borders",this.borders.items),n("cellStyleXfs",[e("xf",{numFmtId:0,fontId:0,fillId:0,borderId:0})]),n("cellXfs",this.xfs.items),n("cellStyles",[e("cellStyle",{name:"Normal",xfId:0,builtinId:0})]),this.dxfs.items.length===0?e("dxfs",{count:0}):n("dxfs",this.dxfs.items),e("tableStyles",{count:0,defaultTableStyle:"TableStyleMedium2",defaultPivotStyle:"PivotStyleLight16"}))}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{SHEET_MARGINS as we,SHEET_NOTE_AUTHOR as K,SHEET_PAPERS as xe}from"@allyhub/formats";import{MAX_COLUMNS as Q,MAX_ROWS as ee,cellName as R,columnIndex as $e,columnLetter as D,rangeName as M,readAddress as te,readArea as ye}from"../address.js";import{analyse as be}from"../calc/analyse.js";import{ITERATION_DEFAULTS as ne}from"../calc/engine.js";import{parseFormula as ve}from"../formula/parse.js";import{sheetPrefix as X}from"../formula/print.js";import{walk as se}from"../formula/walk.js";import{fileCells as Se,isPicture as ke,pictureHeight as Ae,pictureSize as oe}from"../files.js";import{scenariosByCell as Ee}from"../scenario.js";import{CellError as N,readTyped as Te}from"../values.js";import{FormulaCell as Ce}from"../workbook.js";import{chartPart as Me,drawingPart as _e}from"./charts.js";import{fileFormula as P,needsArray as B}from"./formula.js";import{GRID_END as W}from"./read.js";import{Styles as Re}from"./styles.js";import{THEME_XML as Le}from"./theme.js";import{HEAD as A,NS as E,el as o,xstring as x}from"./xml.js";import{ZipOut as je}from"./zip.js";const T={comments:"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",sheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",worksheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",styles:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",strings:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",theme:"application/vnd.openxmlformats-officedocument.theme+xml",table:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",metadata:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml",chart:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",core:"application/vnd.openxmlformats-package.core-properties+xml",app:"application/vnd.openxmlformats-officedocument.extended-properties+xml"},k=`${E.rel}/`,re="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",ie="http://schemas.microsoft.com/office/excel/2006/main",ae={conditional:"{78C0D931-6437-407d-A8EE-F0AAD7539E65}",validations:"{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"},Ie=191029;export const DEFAULT_TABLE_STYLE="TableStyleMedium2",LISTS_SHEET="AllyHub lists";const Oe=64,Fe=7,De=i=>Math.min(255,Math.floor(i/Fe*256)/256),Ne=i=>Math.min(409.5,i*3/4),q=32767,Pe=255,Ve=2e5,ze=o("metadata",{xmlns:E.main,"xmlns:xda":"http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray"},o("metadataTypes",{count:1},o("metadataType",{name:"XLDAPR",minSupportedVersion:12e4,copy:1,pasteAll:1,pasteValues:1,merge:1,splitFirst:1,rowColShift:1,clearFormats:1,clearComments:1,assign:1,coerce:1,cellMeta:1})),o("futureMetadata",{name:"XLDAPR",count:1},o("bk",{},o("extLst",{},o("ext",{uri:"{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}"},o("xda:dynamicArrayProperties",{fDynamic:1,fCollapsed:0}))))),o("cellMetadata",{count:1},o("bk",{},o("rc",{t:1,v:0}))));class Ue{index=new Map;count=0;of(t){this.count+=1;let n=this.index.get(t);return n===void 0&&(n=this.index.size,this.index.set(t,n)),n}write(t){t.write(`${A}<sst xmlns="${E.main}" count="${String(this.count)}" uniqueCount="${String(this.index.size)}">`);for(const n of this.index.keys()){const e=/^\s|\s$|\n/u.test(n);t.write(`<si><t${e?' xml:space="preserve"':""}>${x(n)}</t></si>`)}t.write("</sst>"),t.end()}}function He(i){let t=!1;return i&&se(i,n=>{(n.kind==="structured"||n.kind==="ref"&&n.sheet!==void 0)&&(t=!0)}),t}function Xe(i){for(const t in i)if(Object.hasOwn(i,t))return!1;return!0}const Be=i=>o("x",i).slice(2,-2),We="Base case";function qe(i){const t=new Map;for(const s of i.scenarios)for(const r of s.cells)t.set(R(r),r);const n=(s,r)=>o("inputCells",{r:R(s),val:r===null||r instanceof N?"":typeof r=="boolean"?r?"1":"0":String(r)}),e=(s,r)=>o("scenario",{name:s,locked:!0,count:r.length,user:"AllyHub"},r.join(""));return o("scenarios",{current:0,show:0,sqref:[...t.keys()].join(" ")},e(We,[...t.values()].map(s=>n(s,s.base))),...i.scenarios.map(s=>e(s.name,s.cells.map(r=>n(r,r.value)))))}function Ge(i,t,n,e){const s=[];let r=0;for(const{row:a,col:h,paths:l,column:c}of Se(i,t)){let d=0;const f=Ae(c);for(const u of l){const m=ke(u)?n?.(u):void 0,$=m&&oe(m);if(!m||!$){r+=1;continue}const S=Math.round($.width/$.height*f);s.push({row:a,col:h,x:d,width:S,height:f,name:u.split("/").pop()??u,path:u,file:`.${$.type==="jpeg"?"jpg":$.type}`,bytes:m}),d+=S+4}}for(const a of i.spec.pictures??[]){const h=te(a.at),l=n?.(a.file),c=l&&oe(l);if(!h||!l||!c)continue;const d=c.width/c.height,f=a.width??(a.height===void 0?c.width:a.height*d);s.push({row:h.row,col:h.col,x:a.x??0,y:a.y??0,width:Math.round(f),height:Math.round(a.height??f/d),name:a.file.split("/").pop()??a.file,path:a.file,file:`.${c.type==="jpeg"?"jpg":c.type}`,bytes:l})}return r>0&&e.push(`${i.name}: ${String(r)} file${r===1?"":"s"} in a cell, which stay${r===1?"s":""} a name`),s}class Ye{name;columns=[];known=new Map;constructor(t){let n=LISTS_SHEET;for(let e=2;t.sheet(n);e++)n=`${LISTS_SHEET} (${String(e)})`;this.name=n}place(t){const n=JSON.stringify(t);let e=this.known.get(n);e===void 0&&(e=this.columns.length,this.columns.push(t),this.known.set(n,e));const s=D(e);return`${X(this.name)}$${s}$1:$${s}$${String(Math.max(1,t.length))}`}xml(t){const n=[],e=Math.max(0,...this.columns.map(s=>s.length));for(let s=0;s<e;s++){let r=`<row r="${String(s+1)}">`;this.columns.forEach((a,h)=>{const l=a[s];l!==void 0&&(r+=`<c r="${R({row:s,col:h})}" t="s"><v>${String(t.of(l))}</v></c>`)}),n.push(`${r}</row>`)}return`${A}<worksheet xmlns="${E.main}" xmlns:r="${E.rel}"><dimension ref="${M({top:0,left:0,bottom:Math.max(0,e-1),right:Math.max(0,this.columns.length-1)})}"/><sheetViews><sheetView workbookViewId="0"/></sheetViews><sheetFormatPr defaultRowHeight="15"/><sheetData>${n.join("")}</sheetData><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/></worksheet>`}}class Ze{rows=new Int32Array(1024);cols=new Int32Array(1024);size=0;add(t,n){if(this.size===this.rows.length){const e=new Int32Array(this.size*2);e.set(this.rows),this.rows=e;const s=new Int32Array(this.size*2);s.set(this.cols),this.cols=s}this.rows[this.size]=t,this.cols[this.size]=n,this.size+=1}byRow(){const{size:t}=this;if(t===0)return{start:new Uint32Array(1),cols:new Int32Array(0),top:0,used:void 0};let n=1/0,e=-1,s=1/0,r=-1;for(let c=0;c<t;c++){const d=this.rows[c]??0,f=this.cols[c]??0;d<n&&(n=d),d>e&&(e=d),f<s&&(s=f),f>r&&(r=f)}const a=new Uint32Array(e-n+2);for(let c=0;c<t;c++){const d=(this.rows[c]??0)-n+1;a[d]=(a[d]??0)+1}for(let c=1;c<a.length;c++)a[c]=(a[c]??0)+(a[c-1]??0);const h=a.slice(0,-1),l=new Int32Array(t);for(let c=0;c<t;c++){const d=(this.rows[c]??0)-n,f=h[d]??0;l[f]=this.cols[c]??0,h[d]=f+1}return{start:a,cols:l,top:n,used:{top:n,bottom:e,left:s,right:r}}}}function Je(i,t){if(!i)return!1;let n=!1;const e=t.toLowerCase();return se(i,s=>{(s.kind==="ref"||s.kind==="name")&&s.sheet!==void 0&&s.sheet.toLowerCase()!==e&&(n=!0)}),n}const Ke=(i,t)=>`{00000000-0000-4000-8000-${(i*65536+t).toString(16).toUpperCase().padStart(12,"0")}}`;class Qe{arrays=!1;sheet;calc;styles;strings;wb;cached;left;lists;index;isTable;isRangeName;hiddenRows;tall;scenarios;drawn;newerRules=[];newerValidations=[];misgiven=new Set;shapes=new Map;groups=new Map;constructor(t,n,e,s,r,a,h,l,c=[],d){this.sheet=t,this.calc=n,this.wb=n.wb,this.styles=e,this.strings=s,this.cached=r,this.left=a,this.lists=h,this.index=l,this.isTable=u=>this.wb.table(u)!==void 0,this.isRangeName=u=>{const m=this.wb.name(u,t)?.formula?.node;return this.isTable(u)||m!==void 0&&B({kind:"unary",op:"-",arg:m})},this.hiddenRows=n.filtered(t),this.scenarios=d,this.drawn=t.charts.length>0||c.length>0;const f=new Map;for(const u of c)u.y===void 0&&f.set(u.row,Math.max(f.get(u.row)??0,u.height));this.tall=f}grid(){const{sheet:t}=this;if(t.lastRow>=ee)throw new Error(`${t.name} reaches row ${(t.lastRow+1).toLocaleString("en-US")}, and ${W}: an Excel file cannot hold it.`);if(t.columnsUsed>Q)throw new Error(`${t.name} reaches past column ${D(Q-1)}, and ${W}: an Excel file cannot hold it.`);for(const n of Object.keys(t.spec.rows??{}))if(Number(n)>ee)throw new Error(`${t.name} sets row ${n}, and ${W}: an Excel file cannot hold it.`)}gather(){const{sheet:t}=this,n=new Ze;for(let e=0;e<t.columnsUsed;e++){const[s,r]=t.span(e,0,Number.MAX_SAFE_INTEGER);for(let a=s;a<=r;a++)(t.at(a,e)!==void 0||t.spillAt(a,e))&&n.add(a,e)}for(const{area:e}of t.styledAreas()){const s=(e.bottom-e.top+1)*(e.right-e.left+1);if(s>Ve){this.left.push(`${t.name}!${M(e)}: its look on the cells that hold something, ${String(s)} cells being too many to write empty`);continue}for(let r=e.top;r<=e.bottom;r++)for(let a=e.left;a<=e.right;a++)n.add(r,a)}for(const e of t.keys.keys())n.add(Math.floor(e/16384),e%16384);return n.byRow()}styleOf(t,n){const e=this.sheet.lookAt(t,n);return Xe(e)?void 0:this.styles.xf(e)}held(t,n){return n.length<=q?n:(this.left.push(`${this.sheet.name}!${t} past Excel's ${String(q)} characters, of its ${String(n.length)}`),n.slice(0,q))}value(t,n,e){return e===null?`<c r="${t}"${v(n)}/>`:typeof e=="number"?`<c r="${t}"${v(n)}><v>${String(e)}</v></c>`:typeof e=="boolean"?`<c r="${t}"${v(n)} t="b"><v>${e?"1":"0"}</v></c>`:e instanceof N?fe(e)?`<c r="${t}"${v(n)} t="e"><v>${e.code}</v></c>`:`<c r="${t}"${v(n)} t="s"><v>${String(this.strings.of(e.code))}</v></c>`:`<c r="${t}"${v(n)} t="s"><v>${String(this.strings.of(this.held(t,e)))}</v></c>`}dataTable(t,n,e,s){const r=this.value(t,n,s),{shared:a}=e;if(e.row!==a.row||e.col!==a.col)return r;const h=a.node,l=p=>{if(p===void 0||p.kind==="missing")return null;if(!(p.kind!=="ref"||p.sheet!==void 0||!p.row||!p.col))return R({row:p.row.index,col:p.col.index})},c=h?.kind==="call"?h.args:[],d=l(c[0]),f=l(c[1]);if(d===void 0||f===void 0||d===null&&f===null)return this.left.push(`${this.sheet.name}!${t}: a data table whose inputs a file cannot hold, as its values`),r;const m=this.sheet.fills.find(p=>p.shared===a)?.area??{top:e.row,left:e.col,bottom:e.row,right:e.col},$=d!==null&&f!==null?{dt2D:!0,dtr:!0,r1:d,r2:f}:d!==null?{dtr:!0,r1:d}:{dtr:!1,r1:f??""},S=o("f",{t:"dataTable",ref:M(m),...$});return typeof s=="string"?`<c r="${t}"${v(n)} t="str">${S}<v>${x(s)}</v></c>`:r.includes("<v>")?r.replace("<v>",`${S}<v>`):r.replace("/>",`>${S}</c>`)}table(t){return this.sheet.tableAt(t.row,t.col)?.name}formula(t,n,e){const s=this.calc.value(e.sheet,e.row,e.col),{shared:r}=e,{node:a}=r;if(!a)return`<c r="${t}"${v(n)} t="e"><v>#NAME?</v></c>`;if(a.kind==="call"&&a.name==="TABLE"&&a.args.length<=2)return this.dataTable(t,n,e,s);const h=(r.analysis??=be(this.wb,r)).arguments[0];if(h!==void 0)return this.misgiven.has(r)||(this.misgiven.add(r),this.left.push(`${this.sheet.name}!${t}: a formula's value, not the formula, as ${h.name} is given ${String(h.given)} arguments`)),this.value(t,n,s);let l=this.shapes.get(r);l===void 0&&(l=B(a,this.isRangeName),this.shapes.set(r,l));const c=e.array!==void 0||e.blocked!==void 0||l;let d=c?void 0:this.groups.get(r);d?.written===!1&&(e.row!==d.ref.top||e.col!==d.ref.left)&&(d=void 0);let f,u="";if(d?.written===!0)f=`<f t="shared" si="${String(d.si)}"/>`;else{const m=P(e.moved,{table:this.table(e),isTable:this.isTable,array:c});f=d?`<f t="shared" ref="${M(d.ref)}" si="${String(d.si)}">${x(m)}</f>`:`<f>${x(m)}</f>`,d&&(d.written=!0),c&&(f=this.arrayFormula(e,m))}return c&&(this.arrays=!0,u=' cm="1"'),this.cached?s===null||typeof s=="number"?`<c r="${t}"${v(n)}${u}>${f}<v>${String(s??0)}</v></c>`:typeof s=="boolean"?`<c r="${t}"${v(n)} t="b"${u}>${f}<v>${s?"1":"0"}</v></c>`:s instanceof N?fe(s)?`<c r="${t}"${v(n)} t="e"${u}>${f}<v>${s.code}</v></c>`:s.code==="#CYCLE!"?`<c r="${t}"${v(n)}${u}>${f}<v>0</v></c>`:`<c r="${t}"${v(n)} t="e"${u}>${f}<v>#VALUE!</v></c>`:`<c r="${t}"${v(n)} t="str"${u}>${f}<v>${x(this.held(t,s))}</v></c>`:`<c r="${t}"${v(n)}${u}>${f}</c>`}arrayFormula(t,n){const e=t.spill??{top:t.row,left:t.col,bottom:t.row,right:t.col};return`<f t="array" ref="${M(e)}">${x(n)}</f>`}shareFormulas(){const t=new Map;for(const e of this.sheet.formulas){const s=t.get(e.shared);if(!s)t.set(e.shared,{area:{top:e.row,bottom:e.row,left:e.col,right:e.col},first:e,n:1});else{const{area:r}=s;e.row<r.top&&(r.top=e.row),e.row>r.bottom&&(r.bottom=e.row),e.col<r.left&&(r.left=e.col),e.col>r.right&&(r.right=e.col),(e.row<s.first.row||e.row===s.first.row&&e.col<s.first.col)&&(s.first=e),s.n+=1}}let n=0;for(const[e,{area:s,first:r,n:a}]of t)a>1&&r.row===s.top&&r.col===s.left&&!He(e.node)&&(this.groups.set(e,{si:n,ref:s,written:!1}),n+=1)}cell(t,n){const e=R({row:t,col:n}),s=this.styleOf(t,n),r=this.sheet.at(t,n);return r instanceof Ce?this.formula(e,s,r):r===void 0&&this.cached&&this.sheet.spillAt(t,n)?this.value(e,s,this.calc.value(this.sheet,t,n)):this.value(e,s,r??null)}columns(){const{sheet:t}=this,{spec:n}=t,e=new Map,s=new Map;for(const l of t.tables)for(const c of l.columns)c.spec?.width!==void 0&&s.set(l.at.col+c.index,c.spec.width);const r=new Set(s.keys()),a=new Map;for(const[l,c]of Object.entries(n.columns??{})){const d=$e(l);d!==void 0&&(a.set(d,c),r.add(d))}for(const l of r){const c=a.get(l),d=c?.width??s.get(l),f=he(c);e.set(l,o("col",{min:l+1,max:l+1,width:De(d??Oe),style:f===void 0?void 0:this.styles.xf(f),hidden:c?.hidden===!0?!0:void 0,customWidth:d===void 0?void 0:!0,outlineLevel:c?.level}))}const h=[...e.keys()].sort((l,c)=>l-c).map(l=>e.get(l)??"");return h.length===0?"":`<cols>${h.join("")}</cols>`}rowAttrs(t){const n=this.sheet.spec.rows?.[String(t+1)],e=he(n),s=n?.height??this.tall.get(t);return Be({r:t+1,s:e===void 0?void 0:this.styles.xf(e),customFormat:e===void 0?void 0:!0,ht:s===void 0?void 0:Ne(s),customHeight:s===void 0?void 0:!0,hidden:n?.hidden===!0||this.hiddenRows.has(t)?!0:void 0,outlineLevel:n?.level})}rows(t,n){const{sheet:e}=this,s=new Set(this.hiddenRows);for(const d of Object.keys(e.spec.rows??{}))s.add(Number(d)-1);const{start:r,cols:a,top:h}=n;let l=n.used?h:1/0,c=n.used?n.used.bottom:-1;for(const d of s)d<l&&(l=d),d>c&&(c=d);for(let d=Math.max(0,l);d<=c;d++){const f=d-h,u=f>=0&&f<r.length-1?r[f]??0:0,m=f>=0&&f<r.length-1?r[f+1]??0:0;if(u===m&&!s.has(d))continue;if(u===m){t.write(`<row${this.rowAttrs(d)}/>`);continue}const $=a.subarray(u,m).sort();let S=`<row${this.rowAttrs(d)}>`,p=-1;for(const b of $)b!==p&&(p=b,S+=this.cell(d,b));t.write(`${S}</row>`)}}view(t){const{freeze:n}=this.sheet;let e="";if(n&&(n.row>0||n.col>0)){const s=n.row>0&&n.col>0?"bottomRight":n.row>0?"bottomLeft":"topRight";e=o("pane",{xSplit:n.col>0?n.col:void 0,ySplit:n.row>0?n.row:void 0,topLeftCell:R(n),activePane:s,state:"frozen"})}return o("sheetViews",{},o("sheetView",{showGridLines:this.sheet.spec.gridlines===!1?!1:void 0,tabSelected:t?!0:void 0,workbookViewId:0},e))}write(t,n,e){const{sheet:s}=this;this.grid();const r=this.gather();this.shareFormulas();const a=s.tables.map((p,b)=>o("tablePart",{"r:id":`rId${String(b+1)}`})),{print:h}=s.spec,l=h?.fit,c=Object.keys(s.spec.notes??{}).length>0;t.write(`${A}<worksheet xmlns="${E.main}" xmlns:r="${E.rel}">`+(s.spec.tab===void 0&&l===void 0?"":o("sheetPr",{},s.spec.tab===void 0?"":o("tabColor",{rgb:`FF${s.spec.tab.slice(1).toUpperCase()}`}),l===void 0?"":o("pageSetUpPr",{fitToPage:!0})))+o("dimension",{ref:r.used?M(r.used):"A1"})+this.view(n)+o("sheetFormatPr",{defaultRowHeight:15,outlineLevelRow:le(s.spec.rows),outlineLevelCol:le(s.spec.columns)})+this.columns()+"<sheetData>"),this.rows(t,r);const d=a.length+1+(this.drawn?1:0)+(c?2:0);let f=0;const u=Object.entries(s.spec.links??{}).map(([p,b])=>b.startsWith("#")?o("hyperlink",{ref:p,location:b.slice(1)}):o("hyperlink",{ref:p,"r:id":`rId${String(d+f++)}`})),m=s.merges.map(p=>o("mergeCell",{ref:M(p)})),$=s.conditions.map((p,b)=>this.condition(p,b+1)).join(""),S=this.validations();return t.write("</sheetData>"+(s.spec.protect===!0?o("sheetProtection",{sheet:!0,objects:!0,scenarios:!0}):"")+(this.scenarios?qe(this.scenarios):"")+this.sheetFilter()+(m.length>0?o("mergeCells",{count:m.length},m.join("")):"")+$+S+(u.length>0?o("hyperlinks",{},u.join("")):"")+o("pageMargins",{...we,...h?.margins})+(h?.orientation!==void 0||h?.paper!==void 0||l!==void 0?o("pageSetup",{paperSize:h?.paper===void 0?void 0:xe[h.paper],fitToWidth:l?.width,fitToHeight:l?.height,orientation:h?.orientation}):"")+(h?.header||h?.footer?o("headerFooter",{},h.header?o("oddHeader",{},x(ce(h.header))):"",h.footer?o("oddFooter",{},x(ce(h.footer))):""):"")+(this.drawn?o("drawing",{"r:id":`rId${String(a.length+1)}`}):"")+(c?o("legacyDrawing",{"r:id":`rId${String(a.length+(this.drawn?2:1))}`}):"")+(a.length>0?o("tableParts",{count:a.length},a.join("")):"")+this.extensions()+"</worksheet>"),t.end(),s.tables.map((p,b)=>this.tableXml(p,e+b))}extensions(){const t=[];return this.newerRules.length>0&&t.push(o("ext",{uri:ae.conditional,"xmlns:x14":re},o("x14:conditionalFormattings",{},this.newerRules.join("")))),this.newerValidations.length>0&&t.push(o("ext",{uri:ae.validations,"xmlns:x14":re},o("x14:dataValidations",{count:this.newerValidations.length,"xmlns:xm":ie},this.newerValidations.join("")))),t.length===0?"":o("extLst",{},t.join(""))}bound(t){if(t===void 0)return"";if(typeof t=="number")return String(t);if(!t.startsWith("=")){const e=Te(t);return typeof e.value=="number"&&e.formula===void 0?String(e.value):`"${t.replaceAll('"','""')}"`}const n=ve(t);return n.ok?P(n.node,{isTable:this.isTable,array:!0}):t.slice(1)}cfvo(t,n){const e=t.value===void 0?void 0:typeof t.value=="number"?String(t.value):this.bound(t.value);return n?o("x14:cfvo",{type:t.at},e===void 0?"":o("xm:f",{},x(e))):o("cfvo",{type:t.at,val:e})}crosses(t){return t.some(n=>Je(n?.node,this.sheet.name))}condition(t,n){const{spec:e}=t,s=e.range,r=e.type!=="dataBar"&&this.crosses(t.formulas),a=(f,u,...m)=>{if(!r){const $=Object.keys(u).length===0?void 0:this.styles.dxf(u);return o("conditionalFormatting",{sqref:s},o("cfRule",{...f,dxfId:$,priority:n,stopIfTrue:e.stop===!0?!0:void 0},...m))}return this.newerRules.push(o("x14:conditionalFormatting",{"xmlns:xm":ie},o("x14:cfRule",{...f,priority:n,stopIfTrue:e.stop===!0?!0:void 0,id:Ke(this.index,n)},...m.map($=>$.replace(/^<formula>(.*)<\/formula>$/su,"<xm:f>$1</xm:f>")),Object.keys(u).length===0?"":this.styles.dxfXml(u,"x14:dxf")),o("xm:sqref",{},s))),""},h=st(e),l=t.areas[0],c=l?R({row:l.top,col:l.left}):"A1",d=f=>o("formula",{},x(f));switch(e.type){case"cellIs":return a({type:"cellIs",operator:e.operator},h,...e.formula.map(f=>d(this.bound(f))));case"containsText":{const f=e.operator??"contains",u=`"${e.text.replaceAll('"','""')}"`,m=f==="contains"?`NOT(ISERROR(SEARCH(${u},${c})))`:f==="notContains"?`ISERROR(SEARCH(${u},${c}))`:f==="beginsWith"?`LEFT(${c},LEN(${u}))=${u}`:`RIGHT(${c},LEN(${u}))=${u}`;return a({type:f==="contains"?"containsText":f==="notContains"?"notContainsText":f,operator:f==="contains"?"containsText":f,text:e.text},h,d(m))}case"duplicateValues":case"uniqueValues":return a({type:e.type},h);case"top10":return a({type:"top10",percent:e.percent===!0?!0:void 0,bottom:e.bottom===!0?!0:void 0,rank:e.rank},h);case"aboveAverage":return a({type:"aboveAverage",aboveAverage:e.below===!0?!1:void 0,equalAverage:e.equal===!0?!0:void 0},h);case"expression":return a({type:"expression"},h,d(this.bound(e.formula.startsWith("=")?e.formula:`=${e.formula}`)));case"dataBar":return a({type:"dataBar"},{},o("dataBar",{showValue:e.show===!1?!1:void 0},this.cfvo(e.min??{at:"min"},!1),this.cfvo(e.max??{at:"max"},!1),o("color",{rgb:de(e.color)})));case"colorScale":{const f=r?"x14:":"";return a({type:"colorScale"},{},o(`${f}colorScale`,{},...e.stops.map(u=>this.cfvo(u,r)),...e.stops.map(u=>o(`${f}color`,{rgb:de(u.color)}))))}case"iconSet":{const f=Number.parseInt(e.icons,10),u=e.stops??Array.from({length:f},(m,$)=>({at:"percent",value:Math.round($*100/f)}));return a({type:"iconSet"},{},o(r?"x14:iconSet":"iconSet",{iconSet:e.icons,showValue:e.show===!1?!1:void 0,reverse:e.reverse===!0?!0:void 0},...u.map(m=>this.cfvo(m,r))))}}}validation(t){const{spec:n}=t;let e="",s=this.crosses(t.formulas);if(n.values){const c=n.values.join(",");c.length>Pe||n.values.some(d=>d.includes(",")||d.includes('"'))?(e=this.lists.place(n.values),s=!0):e=`"${c}"`}else e=this.bound(n.formula?.[0]);const r=this.bound(n.formula?.[1]),{error:a,prompt:h}=n;n.multiple===!0&&this.left.push(`${this.sheet.name}!${n.range}: several choices in a cell: its text stays, and Excel's list offers one at a time`);const l={type:n.type,errorStyle:a?.style===void 0||a.style==="stop"?void 0:a.style,operator:n.operator===void 0||n.operator==="between"?void 0:n.operator,allowBlank:n.blank===!1?void 0:!0,showDropDown:n.dropdown===!1?!0:void 0,showInputMessage:h?.show===!1?void 0:!0,showErrorMessage:a?.show===!1||n.multiple===!0?void 0:!0,errorTitle:a?.title,error:a?.message,promptTitle:h?.title,prompt:h?.message};return s?(this.newerValidations.push(o("x14:dataValidation",l,e===""?"":o("x14:formula1",{},o("xm:f",{},x(e))),r===""?"":o("x14:formula2",{},o("xm:f",{},x(r))),o("xm:sqref",{},n.range))),""):o("dataValidation",{...l,sqref:n.range},e===""?"":o("formula1",{},x(e)),r===""?"":o("formula2",{},x(r)))}validations(){const t=this.sheet.validations.map(n=>this.validation(n)).filter(n=>n!=="");return t.length===0?"":o("dataValidations",{count:t.length},t.join(""))}filterColumns(t){return[...t.columns.entries()].sort(([n],[e])=>n-e).map(([n,e])=>ot(n-t.area.left,e))}sheetFilter(){const t=this.sheet.filters.find(n=>!n.table);return t?o("autoFilter",{ref:M(t.area)},...this.filterColumns(t)):""}columnFormula(t,n){if(!n?.node)return"";const e=B(n.node,this.isRangeName),s=P(n.node,{table:t.name,isTable:this.isTable,array:e});return o("calculatedColumnFormula",{array:e?!0:void 0},x(s))}tableXml(t,n){const e=t.area,s=M({...e,bottom:Math.max(e.bottom,e.top+1)}),r=t.spec.style??DEFAULT_TABLE_STYLE,a=this.sheet.filters.find(h=>h.table===t);return A+o("table",{xmlns:E.main,id:n,name:t.name,displayName:t.name,ref:s,totalsRowShown:0},a?o("autoFilter",{ref:s},...this.filterColumns(a)):"",o("tableColumns",{count:t.columns.length},t.columns.map((h,l)=>o("tableColumn",{id:l+1,name:h.name},this.columnFormula(t,h.formula))).join("")),r==="none"?o("tableStyleInfo",{showFirstColumn:0,showLastColumn:0,showRowStripes:1,showColumnStripes:0}):o("tableStyleInfo",{name:r,showFirstColumn:0,showLastColumn:0,showRowStripes:1,showColumnStripes:0}))}}const le=i=>{let t;for(const n of Object.values(i??{}))n.level!==void 0&&(t=Math.max(t??0,n.level));return t},ce=i=>[i.left===void 0?"":`&L${i.left}`,i.center===void 0?"":`&C${i.center}`,i.right===void 0?"":`&R${i.right}`].join(""),et=i=>typeof i=="string"?{text:i,author:K}:{text:i.text,author:i.author??K};function tt(i){const t=i.map(([e,s])=>({ref:e,...et(s)})),n=[...new Set(t.map(e=>e.author))];return A+o("comments",{xmlns:E.main},o("authors",{},n.map(e=>o("author",{},x(e))).join("")),o("commentList",{},t.map(e=>o("comment",{ref:e.ref,authorId:n.indexOf(e.author)},o("text",{},o("r",{},o("t",/^\s|\s$|\n/u.test(e.text)?{"xml:space":"preserve"}:{},x(e.text)))))).join("")))}function nt(i){return`<xml xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"><o:shapelayout v:ext="edit"><o:idmap v:ext="edit" data="1"/></o:shapelayout><v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe"><v:stroke joinstyle="miter"/><v:path gradientshapeok="t" o:connecttype="rect"/></v:shapetype>${i.flatMap(([n],e)=>{const s=te(n);return s?[`<v:shape id="_x0000_s${String(1025+e)}" type="#_x0000_t202" style="position:absolute;margin-left:80pt;margin-top:5pt;width:120pt;height:60pt;z-index:${String(e+1)};visibility:hidden" fillcolor="#ffffe1" o:insetmode="auto"><v:fill color2="#ffffe1"/><v:shadow on="t" color="black" obscured="t"/><v:path o:connecttype="none"/><v:textbox style="mso-direction-alt:auto"><div style="text-align:left"></div></v:textbox><x:ClientData ObjectType="Note"><x:MoveWithCells/><x:SizeWithCells/><x:Anchor>${String(s.col+1)}, 15, ${String(s.row)}, 2, ${String(s.col+3)}, 15, ${String(s.row+4)}, 4</x:Anchor><x:AutoFill>False</x:AutoFill><x:Row>${String(s.row)}</x:Row><x:Column>${String(s.col)}</x:Column></x:ClientData></v:shape>`]:[]}).join("")}</xml>`}const de=i=>`FF${i.slice(1).toUpperCase()}`;function st(i){if(i.type==="dataBar"||i.type==="colorScale"||i.type==="iconSet")return{};const t={};for(const n of["bold","italic","underline","strike","color","fill","border"])i[n]!==void 0&&(t[n]=i[n]);return t}function ot(i,t){return o("filterColumn",{colId:i},o("filters",{blank:t.blanks===!0?!0:void 0},(t.values??[]).map(n=>o("filter",{val:n})).join("")))}const v=i=>i===void 0?"":` s="${String(i)}"`,rt=new Set(["#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#GETTING_DATA"]),fe=i=>rt.has(i.code),it=new Set(["width","height","hidden"]);function he(i){if(!i)return;const t=Object.fromEntries(Object.entries(i).filter(([n])=>!it.has(n)));return Object.keys(t).length===0?void 0:t}const V=i=>A+o("Relationships",{xmlns:E.pkg},i.map(([t,n,e],s)=>o("Relationship",{Id:`rId${String(s+1)}`,Type:t,Target:n,TargetMode:e})).join(""));function at(i,t){const n=t.formula?.node;if(n)return P(n,{isTable:s=>i.table(s)!==void 0,array:!0});const{value:e}=t;return e==null?'""':typeof e=="string"?`"${e.replaceAll('"','""')}"`:typeof e=="boolean"?e?"TRUE":"FALSE":e instanceof N?e.code:String(e)}const lt=(i,t)=>i.length===t.length&&i.every((n,e)=>n===t[e]),ue=i=>`$${D(i.left)}$${String(i.top+1)}:$${D(i.right)}$${String(i.bottom+1)}`;function ct(i){const t=[],n=(e,s)=>o("definedName",{name:e.name,localSheetId:s,hidden:e.hidden===!0?!0:void 0},x(at(i,e)));for(const e of i.names.values())t.push(n(e));return i.sheets.forEach((e,s)=>{for(const d of e.names.values())t.push(n(d,s));const r=e.filters.find(d=>!d.table);r&&t.push(o("definedName",{name:"_xlnm._FilterDatabase",localSheetId:s,hidden:!0},x(`${X(e.name)}${ue(r.area)}`)));const a=X(e.name),h=e.spec.print,l=h?.area===void 0?void 0:ye(h.area);l&&t.push(o("definedName",{name:"_xlnm.Print_Area",localSheetId:s},x(`${a}${ue(l)}`)));const c=[h?.title_cols?.toUpperCase().replace(/([A-Z]+):([A-Z]+)/u,"$$$1:$$$2"),h?.title_rows?.replace(/(\d+):(\d+)/u,"$$$1:$$$2")].flatMap(d=>d===void 0?[]:[`${a}${d}`]);c.length>0&&t.push(o("definedName",{name:"_xlnm.Print_Titles",localSheetId:s},x(c.join(","))))}),t}function dt(i){if(i===void 0)return{};const t=i===!0?{}:i;return{iterate:!0,iterateCount:t.max_iterations??ne.max_iterations,iterateDelta:t.max_change??ne.max_change}}export function writeXlsx(i,t={}){const n=i.wb,e=[];n.checks.length>0&&e.push(`${String(n.checks.length)} check${n.checks.length===1?"":"s"}: a file has no such thing`);const s=Ee(i);e.push(...s.left);const r=new Re,a=new Ue,h=new Ye(n),l=new je,c=[["/xl/workbook.xml",T.sheet]],d=Math.max(0,n.sheets.findIndex(g=>g.spec.hidden!==!0));let f=1,u=!1;const m=new Map;let $=0,S=0,p=0;for(const[g,w]of n.sheets.entries()){const U=String(g+1),I=Ge(w,i,t.file,e),O=w.charts.filter(({spec:y})=>[y.categories,...y.series.flatMap(C=>[C.values,C.x])].some(C=>C?.endsWith("#"))).length;O>0&&e.push(`${w.name}: ${String(O)} chart${O===1?"":"s"} on a spill: ${O===1?"it reads":"they read"} the cells the spill covers now, and will not grow with it`);const Z=new Qe(w,i,r,a,t.cached!==!1,e,h,g,I,s.sheets.find(y=>y.sheet===w)),pe=Z.write(l.part(`xl/worksheets/sheet${U}.xml`),g===d,f);u||=Z.arrays,c.push([`/xl/worksheets/sheet${U}.xml`,T.worksheet]);const _=[];for(const y of pe){const C=`table${String(f)}.xml`;f+=1,l.add(`xl/tables/${C}`,y),c.push([`/xl/tables/${C}`,T.table]),_.push([`${k}table`,`../tables/${C}`])}if(w.charts.length>0||I.length>0){$+=1;const y=`drawing${String($)}.xml`;l.add(`xl/drawings/${y}`,_e(w.charts,I)),c.push([`/xl/drawings/${y}`,T.drawing]),_.push([`${k}drawing`,`../drawings/${y}`]);const C=w.charts.map(j=>{S+=1;const F=`chart${String(S)}.xml`;return l.add(`xl/charts/${F}`,Me(i,w,j)),c.push([`/xl/charts/${F}`,T.chart]),[`${k}chart`,`../charts/${F}`]});for(const j of I){const J=[...m].find(([,ge])=>lt(ge,j.bytes))?.[0]??`image${String(m.size+1)}${j.file}`;m.set(J,j.bytes),C.push([`${k}image`,`../media/${J}`])}l.add(`xl/drawings/_rels/${y}.rels`,V(C))}const H=Object.entries(w.spec.notes??{});if(H.length>0){p+=1;const y=String(p);l.add(`xl/comments${y}.xml`,tt(H)),c.push([`/xl/comments${y}.xml`,T.comments]),l.add(`xl/drawings/vmlDrawing${y}.vml`,nt(H)),_.push([`${k}vmlDrawing`,`../drawings/vmlDrawing${y}.vml`]),_.push([`${k}comments`,`../comments${y}.xml`])}for(const y of Object.values(w.spec.links??{}))y.startsWith("#")||_.push([`${k}hyperlink`,y,"External"]);_.length>0&&l.add(`xl/worksheets/_rels/sheet${U}.xml.rels`,V(_))}const b=n.sheets.length,z=h.columns.length>0;if(z){const g=`xl/worksheets/sheet${String(b+1)}.xml`;l.add(g,h.xml(a)),c.push([`/${g}`,T.worksheet])}const L=[...n.sheets,...z?[void 0]:[]].map((g,w)=>[`${k}worksheet`,`worksheets/sheet${String(w+1)}.xml`]);L.push([`${k}theme`,"theme/theme1.xml"]),L.push([`${k}styles`,"styles.xml"]),L.push([`${k}sharedStrings`,"sharedStrings.xml"]),u&&(L.push([`${k}sheetMetadata`,"metadata.xml"]),c.push(["/xl/metadata.xml",T.metadata]));const G=ct(n),Y=n.sheets.map((g,w)=>o("sheet",{name:g.name,sheetId:w+1,state:g.spec.hidden===!0?"hidden":void 0,"r:id":`rId${String(w+1)}`}));z&&Y.push(o("sheet",{name:h.name,sheetId:b+1,state:"veryHidden","r:id":`rId${String(b+1)}`})),l.add("xl/workbook.xml",A+o("workbook",{xmlns:E.main,"xmlns:r":E.rel},o("workbookPr",{}),o("bookViews",{},o("workbookView",{activeTab:d===0?void 0:d})),o("sheets",{},Y.join("")),G.length>0?o("definedNames",{},G.join("")):"",o("calcPr",{calcId:Ie,fullCalcOnLoad:!0,...dt(n.file.iteration)}))),l.add("xl/_rels/workbook.xml.rels",V(L)),l.add("xl/styles.xml",A+r.xml()),a.write(l.part("xl/sharedStrings.xml")),l.add("xl/theme/theme1.xml",A+Le),u&&l.add("xl/metadata.xml",A+ze),l.add("docProps/core.xml",A+o("cp:coreProperties",{"xmlns:cp":"http://schemas.openxmlformats.org/package/2006/metadata/core-properties","xmlns:dc":"http://purl.org/dc/elements/1.1/"},n.title===void 0?"":o("dc:title",{},x(n.title)))),l.add("docProps/app.xml",A+o("Properties",{xmlns:"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"},o("Application",{},"AllyHub"))),l.add("_rels/.rels",V([[`${k}officeDocument`,"xl/workbook.xml"],["http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties","docProps/core.xml"],[`${k}extended-properties`,"docProps/app.xml"]])),c.push(["/xl/styles.xml",T.styles],["/xl/sharedStrings.xml",T.strings],["/xl/theme/theme1.xml",T.theme],["/docProps/core.xml",T.core],["/docProps/app.xml",T.app]);const me=[...m].sort(([g],[w])=>g.localeCompare(w));for(const[g,w]of me)l.add(`xl/media/${g}`,w);return l.add("[Content_Types].xml",A+o("Types",{xmlns:E.types},o("Default",{Extension:"rels",ContentType:"application/vnd.openxmlformats-package.relationships+xml"}),o("Default",{Extension:"xml",ContentType:"application/xml"}),p>0?o("Default",{Extension:"vml",ContentType:"application/vnd.openxmlformats-officedocument.vmlDrawing"}):"",[...new Set([...m.keys()].map(g=>g.split(".").pop()??""))].sort().map(g=>o("Default",{Extension:g,ContentType:`image/${g==="jpg"?"jpeg":g}`})).join(""),c.map(([g,w])=>o("Override",{PartName:g,ContentType:w})).join(""))),{bytes:l.finish(),left:e}}
|
|
2
|
+
import{SHEET_MARGINS as xe,SHEET_NOTE_AUTHOR as ee,SHEET_PAPERS as $e}from"@allyhub/formats";import{MAX_COLUMNS as X,MAX_ROWS as W,cellName as j,columnIndex as te,columnLetter as I,rangeName as M,readAddress as se,readArea as ye}from"../address.js";import{analyse as be}from"../calc/analyse.js";import{ITERATION_DEFAULTS as ne}from"../calc/engine.js";import{parseFormula as ve}from"../formula/parse.js";import{sheetPrefix as q}from"../formula/print.js";import{walk as oe}from"../formula/walk.js";import{fileCells as Se,isPicture as ke,pictureHeight as Ae,pictureSize as re}from"../files.js";import{scenariosByCell as Ee}from"../scenario.js";import{CellError as P,readTyped as Te}from"../values.js";import{FormulaCell as Ce,runsText as _e}from"../workbook.js";import{chartPart as Re,drawingPart as Me}from"./charts.js";import{fileFormula as V,needsArray as G}from"./formula.js";import{GRID_END as Y}from"./read.js";import{Styles as Le,runXml as je}from"./styles.js";import{THEME_XML as Fe}from"./theme.js";import{HEAD as E,NS as T,el as r,xstring as w}from"./xml.js";import{ZipOut as Ie}from"./zip.js";const C={comments:"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",sheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",worksheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",styles:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",strings:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",theme:"application/vnd.openxmlformats-officedocument.theme+xml",table:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",metadata:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml",chart:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",core:"application/vnd.openxmlformats-package.core-properties+xml",app:"application/vnd.openxmlformats-officedocument.extended-properties+xml"},k=`${T.rel}/`,ie="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",ae="http://schemas.microsoft.com/office/excel/2006/main",le={conditional:"{78C0D931-6437-407d-A8EE-F0AAD7539E65}",validations:"{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"},Oe=191029;export const DEFAULT_TABLE_STYLE="TableStyleMedium2",LISTS_SHEET="AllyHub lists";const De=64,Ne=7,Pe=a=>Math.min(255,Math.floor(a/Ne*256)/256),Ve=a=>Math.min(409.5,a*3/4),z=32767,ze=255,Ue=2e5,Be=r("metadata",{xmlns:T.main,"xmlns:xda":"http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray"},r("metadataTypes",{count:1},r("metadataType",{name:"XLDAPR",minSupportedVersion:12e4,copy:1,pasteAll:1,pasteValues:1,merge:1,splitFirst:1,rowColShift:1,clearFormats:1,clearComments:1,assign:1,coerce:1,cellMeta:1})),r("futureMetadata",{name:"XLDAPR",count:1},r("bk",{},r("extLst",{},r("ext",{uri:"{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}"},r("xda:dynamicArrayProperties",{fDynamic:1,fCollapsed:0}))))),r("cellMetadata",{count:1},r("bk",{},r("rc",{t:1,v:0}))));class He{index=new Map;count=0;place(t){this.count+=1;let s=this.index.get(t);return s===void 0&&(s=this.index.size,this.index.set(t,s)),s}of(t){return this.place(`t${t}`)}rich(t){return this.place(`r${t}`)}write(t){t.write(`${E}<sst xmlns="${T.main}" count="${String(this.count)}" uniqueCount="${String(this.index.size)}">`);for(const s of this.index.keys()){if(s.startsWith("r")){t.write(`<si>${s.slice(1)}</si>`);continue}const e=s.slice(1),n=/^\s|\s$|\n/u.test(e);t.write(`<si><t${n?' xml:space="preserve"':""}>${w(e)}</t></si>`)}t.write("</sst>"),t.end()}}function Xe(a){let t=!1;return a&&oe(a,s=>{(s.kind==="structured"||s.kind==="ref"&&s.sheet!==void 0)&&(t=!0)}),t}function We(a){for(const t in a)if(Object.hasOwn(a,t))return!1;return!0}const qe=a=>r("x",a).slice(2,-2),Ge="Base case";function Ye(a){const t=new Map;for(const n of a.scenarios)for(const o of n.cells)t.set(j(o),o);const s=(n,o)=>r("inputCells",{r:j(n),val:o===null||o instanceof P?"":typeof o=="boolean"?o?"1":"0":String(o)}),e=(n,o)=>r("scenario",{name:n,locked:!0,count:o.length,user:"AllyHub"},o.join(""));return r("scenarios",{current:0,show:0,sqref:[...t.keys()].join(" ")},e(Ge,[...t.values()].map(n=>s(n,n.base))),...a.scenarios.map(n=>e(n.name,n.cells.map(o=>s(o,o.value)))))}function Ze(a,t,s,e){const n=[];let o=0;for(const{row:i,col:d,paths:l,column:c}of Se(a,t)){let f=0;const h=Ae(c);for(const u of l){const m=ke(u)?s?.(u):void 0,x=m&&re(m);if(!m||!x){o+=1;continue}const b=Math.round(x.width/x.height*h);n.push({row:i,col:d,x:f,width:b,height:h,name:u.split("/").pop()??u,path:u,file:`.${x.type==="jpeg"?"jpg":x.type}`,bytes:m}),f+=b+4}}for(const i of a.spec.pictures??[]){const d=se(i.at),l=s?.(i.file),c=l&&re(l);if(!d||!l||!c)continue;const f=c.width/c.height,h=i.width??(i.height===void 0?c.width:i.height*f);n.push({row:d.row,col:d.col,x:i.x??0,y:i.y??0,width:Math.round(h),height:Math.round(i.height??h/f),name:i.file.split("/").pop()??i.file,path:i.file,file:`.${c.type==="jpeg"?"jpg":c.type}`,bytes:l})}return o>0&&e.push(`${a.name}: ${String(o)} file${o===1?"":"s"} in a cell, which stay${o===1?"s":""} a name`),n}class Je{name;columns=[];known=new Map;constructor(t){let s=LISTS_SHEET;for(let e=2;t.sheet(s);e++)s=`${LISTS_SHEET} (${String(e)})`;this.name=s}place(t){const s=JSON.stringify(t);let e=this.known.get(s);e===void 0&&(e=this.columns.length,this.columns.push(t),this.known.set(s,e));const n=I(e);return`${q(this.name)}$${n}$1:$${n}$${String(Math.max(1,t.length))}`}xml(t){const s=[],e=Math.max(0,...this.columns.map(n=>n.length));for(let n=0;n<e;n++){let o=`<row r="${String(n+1)}">`;this.columns.forEach((i,d)=>{const l=i[n];l!==void 0&&(o+=`<c r="${j({row:n,col:d})}" t="s"><v>${String(t.of(l))}</v></c>`)}),s.push(`${o}</row>`)}return`${E}<worksheet xmlns="${T.main}" xmlns:r="${T.rel}"><dimension ref="${M({top:0,left:0,bottom:Math.max(0,e-1),right:Math.max(0,this.columns.length-1)})}"/><sheetViews><sheetView workbookViewId="0"/></sheetViews><sheetFormatPr defaultRowHeight="15"/><sheetData>${s.join("")}</sheetData><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/></worksheet>`}}class Ke{rows=new Int32Array(1024);cols=new Int32Array(1024);size=0;add(t,s){if(this.size===this.rows.length){const e=new Int32Array(this.size*2);e.set(this.rows),this.rows=e;const n=new Int32Array(this.size*2);n.set(this.cols),this.cols=n}this.rows[this.size]=t,this.cols[this.size]=s,this.size+=1}byRow(){const{size:t}=this;if(t===0)return{start:new Uint32Array(1),cols:new Int32Array(0),top:0,used:void 0};let s=1/0,e=-1,n=1/0,o=-1;for(let c=0;c<t;c++){const f=this.rows[c]??0,h=this.cols[c]??0;f<s&&(s=f),f>e&&(e=f),h<n&&(n=h),h>o&&(o=h)}const i=new Uint32Array(e-s+2);for(let c=0;c<t;c++){const f=(this.rows[c]??0)-s+1;i[f]=(i[f]??0)+1}for(let c=1;c<i.length;c++)i[c]=(i[c]??0)+(i[c-1]??0);const d=i.slice(0,-1),l=new Int32Array(t);for(let c=0;c<t;c++){const f=(this.rows[c]??0)-s,h=d[f]??0;l[h]=this.cols[c]??0,d[f]=h+1}return{start:i,cols:l,top:s,used:{top:s,bottom:e,left:n,right:o}}}}function Qe(a,t){if(!a)return!1;let s=!1;const e=t.toLowerCase();return oe(a,n=>{(n.kind==="ref"||n.kind==="name")&&n.sheet!==void 0&&n.sheet.toLowerCase()!==e&&(s=!0)}),s}const et=(a,t)=>`{00000000-0000-4000-8000-${(a*65536+t).toString(16).toUpperCase().padStart(12,"0")}}`;class tt{arrays=!1;sheet;calc;styles;strings;wb;cached;left;lists;index;isTable;isRangeName;hiddenRows;tall;scenarios;drawn;newerRules=[];newerValidations=[];misgiven=new Set;shapes=new Map;groups=new Map;constructor(t,s,e,n,o,i,d,l,c=[],f){this.sheet=t,this.calc=s,this.wb=s.wb,this.styles=e,this.strings=n,this.cached=o,this.left=i,this.lists=d,this.index=l,this.isTable=u=>this.wb.table(u)!==void 0,this.isRangeName=u=>{const m=this.wb.name(u,t)?.formula?.node;return this.isTable(u)||m!==void 0&&G({kind:"unary",op:"-",arg:m})},this.hiddenRows=s.filtered(t),this.scenarios=f,this.drawn=t.charts.length>0||c.length>0;const h=new Map;for(const u of c)u.y===void 0&&h.set(u.row,Math.max(h.get(u.row)??0,u.height));this.tall=h}grid(){const{sheet:t}=this;if(t.lastRow>=W)throw new Error(`${t.name} reaches row ${(t.lastRow+1).toLocaleString("en-US")}, and ${Y}: an Excel file cannot hold it.`);if(t.columnsUsed>X)throw new Error(`${t.name} reaches past column ${I(X-1)}, and ${Y}: an Excel file cannot hold it.`);for(const s of Object.keys(t.spec.rows??{}))if(Number(s)>W)throw new Error(`${t.name} sets row ${s}, and ${Y}: an Excel file cannot hold it.`)}gather(){const{sheet:t}=this,s=new Ke;for(let e=0;e<t.columnsUsed;e++){const[n,o]=t.span(e,0,Number.MAX_SAFE_INTEGER);for(let i=n;i<=o;i++)(t.at(i,e)!==void 0||t.spillAt(i,e))&&s.add(i,e)}for(const{area:e}of t.styledAreas()){const n=(e.bottom-e.top+1)*(e.right-e.left+1);if(n>Ue){this.left.push(`${t.name}!${M(e)}: its look on the cells that hold something, ${String(n)} cells being too many to write empty`);continue}for(let o=e.top;o<=e.bottom;o++)for(let i=e.left;i<=e.right;i++)s.add(o,i)}for(const e of t.keys.keys())s.add(Math.floor(e/16384),e%16384);return s.byRow()}styleOf(t,s){const e=this.sheet.lookAt(t,s);return We(e)?void 0:this.styles.xf(e)}held(t,s){return s.length<=z?s:(this.left.push(`${this.sheet.name}!${t} past Excel's ${String(z)} characters, of its ${String(s.length)}`),s.slice(0,z))}value(t,s,e){return e===null?`<c r="${t}"${v(s)}/>`:typeof e=="number"?`<c r="${t}"${v(s)}><v>${String(e)}</v></c>`:typeof e=="boolean"?`<c r="${t}"${v(s)} t="b"><v>${e?"1":"0"}</v></c>`:e instanceof P?he(e)?`<c r="${t}"${v(s)} t="e"><v>${e.code}</v></c>`:`<c r="${t}"${v(s)} t="s"><v>${String(this.strings.of(e.code))}</v></c>`:`<c r="${t}"${v(s)} t="s"><v>${String(this.strings.of(this.held(t,e)))}</v></c>`}dataTable(t,s,e,n){const o=this.value(t,s,n),{shared:i}=e;if(e.row!==i.row||e.col!==i.col)return o;const d=i.node,l=y=>{if(y===void 0||y.kind==="missing")return null;if(!(y.kind!=="ref"||y.sheet!==void 0||!y.row||!y.col))return j({row:y.row.index,col:y.col.index})},c=d?.kind==="call"?d.args:[],f=l(c[0]),h=l(c[1]);if(f===void 0||h===void 0||f===null&&h===null)return this.left.push(`${this.sheet.name}!${t}: a data table whose inputs a file cannot hold, as its values`),o;const m=this.sheet.fills.find(y=>y.shared===i)?.area??{top:e.row,left:e.col,bottom:e.row,right:e.col},x=f!==null&&h!==null?{dt2D:!0,dtr:!0,r1:f,r2:h}:f!==null?{dtr:!0,r1:f}:{dtr:!1,r1:h??""},b=r("f",{t:"dataTable",ref:M(m),...x});return typeof n=="string"?`<c r="${t}"${v(s)} t="str">${b}<v>${w(n)}</v></c>`:o.includes("<v>")?o.replace("<v>",`${b}<v>`):o.replace("/>",`>${b}</c>`)}table(t){return this.sheet.tableAt(t.row,t.col)?.name}formula(t,s,e){const n=this.calc.value(e.sheet,e.row,e.col),{shared:o}=e,{node:i}=o;if(!i)return`<c r="${t}"${v(s)} t="e"><v>#NAME?</v></c>`;if(i.kind==="call"&&i.name==="TABLE"&&i.args.length<=2)return this.dataTable(t,s,e,n);const d=(o.analysis??=be(this.wb,o)).arguments[0];if(d!==void 0)return this.misgiven.has(o)||(this.misgiven.add(o),this.left.push(`${this.sheet.name}!${t}: a formula's value, not the formula, as ${d.name} is given ${String(d.given)} arguments`)),this.value(t,s,n);let l=this.shapes.get(o);l===void 0&&(l=G(i,this.isRangeName),this.shapes.set(o,l));const c=e.array!==void 0||e.blocked!==void 0||l;let f=c?void 0:this.groups.get(o);f?.written===!1&&(e.row!==f.ref.top||e.col!==f.ref.left)&&(f=void 0);let h,u="";if(f?.written===!0)h=`<f t="shared" si="${String(f.si)}"/>`;else{const m=V(e.moved,{table:this.table(e),isTable:this.isTable,array:c});h=f?`<f t="shared" ref="${M(f.ref)}" si="${String(f.si)}">${w(m)}</f>`:`<f>${w(m)}</f>`,f&&(f.written=!0),c&&(h=this.arrayFormula(e,m))}return c&&(this.arrays=!0,u=' cm="1"'),this.cached?n===null||typeof n=="number"?`<c r="${t}"${v(s)}${u}>${h}<v>${String(n??0)}</v></c>`:typeof n=="boolean"?`<c r="${t}"${v(s)} t="b"${u}>${h}<v>${n?"1":"0"}</v></c>`:n instanceof P?he(n)?`<c r="${t}"${v(s)} t="e"${u}>${h}<v>${n.code}</v></c>`:n.code==="#CYCLE!"?`<c r="${t}"${v(s)}${u}>${h}<v>0</v></c>`:`<c r="${t}"${v(s)} t="e"${u}>${h}<v>#VALUE!</v></c>`:`<c r="${t}"${v(s)} t="str"${u}>${h}<v>${w(this.held(t,n))}</v></c>`:`<c r="${t}"${v(s)}${u}>${h}</c>`}arrayFormula(t,s){const e=t.spill??{top:t.row,left:t.col,bottom:t.row,right:t.col};return`<f t="array" ref="${M(e)}">${w(s)}</f>`}shareFormulas(){const t=new Map;for(const e of this.sheet.formulas){const n=t.get(e.shared);if(!n)t.set(e.shared,{area:{top:e.row,bottom:e.row,left:e.col,right:e.col},first:e,n:1});else{const{area:o}=n;e.row<o.top&&(o.top=e.row),e.row>o.bottom&&(o.bottom=e.row),e.col<o.left&&(o.left=e.col),e.col>o.right&&(o.right=e.col),(e.row<n.first.row||e.row===n.first.row&&e.col<n.first.col)&&(n.first=e),n.n+=1}}let s=0;for(const[e,{area:n,first:o,n:i}]of t)i>1&&o.row===n.top&&o.col===n.left&&!Xe(e.node)&&(this.groups.set(e,{si:s,ref:n,written:!1}),s+=1)}cell(t,s){const e=j({row:t,col:s}),n=this.styleOf(t,s),o=this.sheet.at(t,s);if(o instanceof Ce)return this.formula(e,n,o);const i=typeof o=="string"?this.sheet.runsAt(t,s):void 0;if(i&&_e(i).length<=z){const d=this.sheet.lookAt(t,s);return`<c r="${e}"${v(n)} t="s"><v>${String(this.strings.rich(i.map(l=>je(l,d)).join("")))}</v></c>`}return o===void 0&&this.cached&&this.sheet.spillAt(t,s)?this.value(e,n,this.calc.value(this.sheet,t,s)):this.value(e,n,o??null)}columns(){const{sheet:t}=this,{spec:s}=t,e=new Map,n=new Map;for(const l of t.tables)for(const c of l.columns)c.spec?.width!==void 0&&n.set(l.at.col+c.index,c.spec.width);const o=new Set(n.keys()),i=new Map;for(const[l,c]of Object.entries(s.columns??{})){const f=te(l);f!==void 0&&(i.set(f,c),o.add(f))}for(const l of[...i.keys()])for(const c of[-1,1])l+c>=0&&this.collapsedColumn(l+c)&&o.add(l+c);for(const l of o){const c=i.get(l),f=c?.width??n.get(l),h=ue(c);e.set(l,r("col",{min:l+1,max:l+1,width:Pe(f??De),style:h===void 0?void 0:this.styles.xf(h),hidden:c?.hidden===!0?!0:void 0,customWidth:f===void 0?void 0:!0,outlineLevel:c?.level,collapsed:this.collapsedColumn(l)?!0:void 0}))}const d=[...e.keys()].sort((l,c)=>l-c).map(l=>e.get(l)??"");return d.length===0?"":`<cols>${d.join("")}</cols>`}rowAttrs(t){const s=this.sheet.spec.rows?.[String(t+1)],e=ue(s),n=s?.height??this.tall.get(t);return qe({r:t+1,s:e===void 0?void 0:this.styles.xf(e),customFormat:e===void 0?void 0:!0,ht:n===void 0?void 0:Ve(n),customHeight:n===void 0?void 0:!0,hidden:s?.hidden===!0||this.hiddenRows.has(t)?!0:void 0,outlineLevel:s?.level,collapsed:this.collapsedRow(t)?!0:void 0})}collapsedRow(t){const s=this.sheet.spec.rows??{},e=d=>s[String(d+1)]?.level??0,n=d=>s[String(d+1)]?.hidden===!0||this.hiddenRows.has(d),o=this.sheet.spec.outline?.summary_below===!1?1:-1,i=t+o;return i>=0&&e(i)>e(t)&&n(i)}collapsedColumn(t){const s=this.sheet.spec.columns??{},e=i=>s[I(i)],n=this.sheet.spec.outline?.summary_right===!1?1:-1,o=t+n;return o>=0&&(e(o)?.level??0)>(e(t)?.level??0)&&e(o)?.hidden===!0}rows(t,s){const{sheet:e}=this,n=new Set(this.hiddenRows);for(const f of Object.keys(e.spec.rows??{})){const h=Number(f)-1;n.add(h);for(const u of[-1,1])h+u>=0&&this.collapsedRow(h+u)&&n.add(h+u)}const{start:o,cols:i,top:d}=s;let l=s.used?d:1/0,c=s.used?s.used.bottom:-1;for(const f of n)f<l&&(l=f),f>c&&(c=f);for(let f=Math.max(0,l);f<=c;f++){const h=f-d,u=h>=0&&h<o.length-1?o[h]??0:0,m=h>=0&&h<o.length-1?o[h+1]??0:0;if(u===m&&!n.has(f))continue;if(u===m){t.write(`<row${this.rowAttrs(f)}/>`);continue}const x=i.subarray(u,m).sort();let b=`<row${this.rowAttrs(f)}>`,y=-1;for(const R of x)R!==y&&(y=R,b+=this.cell(f,R));t.write(`${b}</row>`)}}view(t){const{freeze:s}=this.sheet;let e="";if(s&&(s.row>0||s.col>0)){const n=s.row>0&&s.col>0?"bottomRight":s.row>0?"bottomLeft":"topRight";e=r("pane",{xSplit:s.col>0?s.col:void 0,ySplit:s.row>0?s.row:void 0,topLeftCell:j(s),activePane:n,state:"frozen"})}return r("sheetViews",{},r("sheetView",{showGridLines:this.sheet.spec.gridlines===!1?!1:void 0,tabSelected:t?!0:void 0,workbookViewId:0},e))}write(t,s,e){const{sheet:n}=this;this.grid();const o=this.gather();this.shareFormulas();const i=n.tables.map((A,S)=>r("tablePart",{"r:id":`rId${String(S+1)}`})),{print:d}=n.spec,l=d?.fit,c=Object.keys(n.spec.notes??{}).length>0,f=n.spec.outline,h=f?.summary_below===!1||f?.summary_right===!1?r("outlinePr",{summaryBelow:f.summary_below===!1?!1:void 0,summaryRight:f.summary_right===!1?!1:void 0}):"";t.write(`${E}<worksheet xmlns="${T.main}" xmlns:r="${T.rel}">`+(n.spec.tab===void 0&&l===void 0&&h===""?"":r("sheetPr",{},n.spec.tab===void 0?"":r("tabColor",{rgb:`FF${n.spec.tab.slice(1).toUpperCase()}`}),h,l===void 0?"":r("pageSetUpPr",{fitToPage:!0})))+r("dimension",{ref:o.used?M(o.used):"A1"})+this.view(s)+r("sheetFormatPr",{defaultRowHeight:15,outlineLevelRow:ce(n.spec.rows),outlineLevelCol:ce(n.spec.columns)})+this.columns()+"<sheetData>"),this.rows(t,o);const u=i.length+1+(this.drawn?1:0)+(c?2:0);let m=0;const x=Object.entries(n.spec.links??{}).map(([A,S])=>S.startsWith("#")?r("hyperlink",{ref:A,location:S.slice(1)}):r("hyperlink",{ref:A,"r:id":`rId${String(u+m++)}`})),b=n.merges.map(A=>r("mergeCell",{ref:M(A)})),y=n.conditions.map((A,S)=>this.condition(A,S+1)).join(""),R=this.validations();return t.write("</sheetData>"+(n.spec.protect===!0?r("sheetProtection",{sheet:!0,objects:!0,scenarios:!0}):"")+(this.scenarios?Ye(this.scenarios):"")+this.sheetFilter()+(b.length>0?r("mergeCells",{count:b.length},b.join("")):"")+y+R+(x.length>0?r("hyperlinks",{},x.join("")):"")+r("pageMargins",{...xe,...d?.margins})+(d?.orientation!==void 0||d?.paper!==void 0||d?.scale!==void 0||l!==void 0?r("pageSetup",{paperSize:d?.paper===void 0?void 0:$e[d.paper],scale:d?.scale,fitToWidth:l?.width,fitToHeight:l?.height,orientation:d?.orientation}):"")+(d?.header||d?.footer?r("headerFooter",{},d.header?r("oddHeader",{},w(de(d.header))):"",d.footer?r("oddFooter",{},w(de(d.footer))):""):"")+ut(d?.breaks)+(this.drawn?r("drawing",{"r:id":`rId${String(i.length+1)}`}):"")+(c?r("legacyDrawing",{"r:id":`rId${String(i.length+(this.drawn?2:1))}`}):"")+(i.length>0?r("tableParts",{count:i.length},i.join("")):"")+this.extensions()+"</worksheet>"),t.end(),n.tables.map((A,S)=>this.tableXml(A,e+S))}extensions(){const t=[];return this.newerRules.length>0&&t.push(r("ext",{uri:le.conditional,"xmlns:x14":ie},r("x14:conditionalFormattings",{},this.newerRules.join("")))),this.newerValidations.length>0&&t.push(r("ext",{uri:le.validations,"xmlns:x14":ie},r("x14:dataValidations",{count:this.newerValidations.length,"xmlns:xm":ae},this.newerValidations.join("")))),t.length===0?"":r("extLst",{},t.join(""))}bound(t){if(t===void 0)return"";if(typeof t=="number")return String(t);if(!t.startsWith("=")){const e=Te(t);return typeof e.value=="number"&&e.formula===void 0?String(e.value):`"${t.replaceAll('"','""')}"`}const s=ve(t);return s.ok?V(s.node,{isTable:this.isTable,array:!0}):t.slice(1)}cfvo(t,s){const e=t.value===void 0?void 0:typeof t.value=="number"?String(t.value):this.bound(t.value);return s?r("x14:cfvo",{type:t.at},e===void 0?"":r("xm:f",{},w(e))):r("cfvo",{type:t.at,val:e})}crosses(t){return t.some(s=>Qe(s?.node,this.sheet.name))}condition(t,s){const{spec:e}=t,n=e.range,o=e.type!=="dataBar"&&this.crosses(t.formulas),i=(h,u,...m)=>{if(!o){const x=Object.keys(u).length===0?void 0:this.styles.dxf(u);return r("conditionalFormatting",{sqref:n},r("cfRule",{...h,dxfId:x,priority:s,stopIfTrue:e.stop===!0?!0:void 0},...m))}return this.newerRules.push(r("x14:conditionalFormatting",{"xmlns:xm":ae},r("x14:cfRule",{...h,priority:s,stopIfTrue:e.stop===!0?!0:void 0,id:et(this.index,s)},...m.map(x=>x.replace(/^<formula>(.*)<\/formula>$/su,"<xm:f>$1</xm:f>")),Object.keys(u).length===0?"":this.styles.dxfXml(u,"x14:dxf")),r("xm:sqref",{},n))),""},d=rt(e),l=t.areas[0],c=l?j({row:l.top,col:l.left}):"A1",f=h=>r("formula",{},w(h));switch(e.type){case"cellIs":return i({type:"cellIs",operator:e.operator},d,...e.formula.map(h=>f(this.bound(h))));case"containsText":{const h=e.operator??"contains",u=`"${e.text.replaceAll('"','""')}"`,m=h==="contains"?`NOT(ISERROR(SEARCH(${u},${c})))`:h==="notContains"?`ISERROR(SEARCH(${u},${c}))`:h==="beginsWith"?`LEFT(${c},LEN(${u}))=${u}`:`RIGHT(${c},LEN(${u}))=${u}`;return i({type:h==="contains"?"containsText":h==="notContains"?"notContainsText":h,operator:h==="contains"?"containsText":h,text:e.text},d,f(m))}case"duplicateValues":case"uniqueValues":return i({type:e.type},d);case"top10":return i({type:"top10",percent:e.percent===!0?!0:void 0,bottom:e.bottom===!0?!0:void 0,rank:e.rank},d);case"aboveAverage":return i({type:"aboveAverage",aboveAverage:e.below===!0?!1:void 0,equalAverage:e.equal===!0?!0:void 0},d);case"expression":return i({type:"expression"},d,f(this.bound(e.formula.startsWith("=")?e.formula:`=${e.formula}`)));case"dataBar":return i({type:"dataBar"},{},r("dataBar",{showValue:e.show===!1?!1:void 0},this.cfvo(e.min??{at:"min"},!1),this.cfvo(e.max??{at:"max"},!1),r("color",{rgb:fe(e.color)})));case"colorScale":{const h=o?"x14:":"";return i({type:"colorScale"},{},r(`${h}colorScale`,{},...e.stops.map(u=>this.cfvo(u,o)),...e.stops.map(u=>r(`${h}color`,{rgb:fe(u.color)}))))}case"iconSet":{const h=Number.parseInt(e.icons,10),u=e.stops??Array.from({length:h},(m,x)=>({at:"percent",value:Math.round(x*100/h)}));return i({type:"iconSet"},{},r(o?"x14:iconSet":"iconSet",{iconSet:e.icons,showValue:e.show===!1?!1:void 0,reverse:e.reverse===!0?!0:void 0},...u.map(m=>this.cfvo(m,o))))}}}validation(t){const{spec:s}=t;let e="",n=this.crosses(t.formulas);if(s.values){const c=s.values.join(",");c.length>ze||s.values.some(f=>f.includes(",")||f.includes('"'))?(e=this.lists.place(s.values),n=!0):e=`"${c}"`}else e=this.bound(s.formula?.[0]);const o=this.bound(s.formula?.[1]),{error:i,prompt:d}=s;s.multiple===!0&&this.left.push(`${this.sheet.name}!${s.range}: several choices in a cell: its text stays, and Excel's list offers one at a time`);const l={type:s.type,errorStyle:i?.style===void 0||i.style==="stop"?void 0:i.style,operator:s.operator===void 0||s.operator==="between"?void 0:s.operator,allowBlank:s.blank===!1?void 0:!0,showDropDown:s.dropdown===!1?!0:void 0,showInputMessage:d?.show===!1?void 0:!0,showErrorMessage:i?.show===!1||s.multiple===!0?void 0:!0,errorTitle:i?.title,error:i?.message,promptTitle:d?.title,prompt:d?.message};return n?(this.newerValidations.push(r("x14:dataValidation",l,e===""?"":r("x14:formula1",{},r("xm:f",{},w(e))),o===""?"":r("x14:formula2",{},r("xm:f",{},w(o))),r("xm:sqref",{},s.range))),""):r("dataValidation",{...l,sqref:s.range},e===""?"":r("formula1",{},w(e)),o===""?"":r("formula2",{},w(o)))}validations(){const t=this.sheet.validations.map(s=>this.validation(s)).filter(s=>s!=="");return t.length===0?"":r("dataValidations",{count:t.length},t.join(""))}filterColumns(t){return[...t.columns.entries()].sort(([s],[e])=>s-e).map(([s,e])=>it(s-t.area.left,e,n=>this.styles.dxf(n)))}sheetFilter(){const t=this.sheet.filters.find(s=>!s.table);return t?r("autoFilter",{ref:M(t.area)},...this.filterColumns(t)):""}columnFormula(t,s){if(!s?.node)return"";const e=G(s.node,this.isRangeName),n=V(s.node,{table:t.name,isTable:this.isTable,array:e});return r("calculatedColumnFormula",{array:e?!0:void 0},w(n))}tableXml(t,s){const e=t.area,n=M({...e,bottom:Math.max(e.bottom,e.top+1)}),o=t.spec.style??DEFAULT_TABLE_STYLE,i=this.sheet.filters.find(d=>d.table===t);return E+r("table",{xmlns:T.main,id:s,name:t.name,displayName:t.name,ref:n,totalsRowShown:0},i?r("autoFilter",{ref:n},...this.filterColumns(i)):"",r("tableColumns",{count:t.columns.length},t.columns.map((d,l)=>r("tableColumn",{id:l+1,name:d.name},this.columnFormula(t,d.formula))).join("")),r("tableStyleInfo",{name:o==="none"?void 0:o,showFirstColumn:t.spec.first_column===!0,showLastColumn:t.spec.last_column===!0,showRowStripes:t.spec.banded_rows!==!1,showColumnStripes:t.spec.banded_columns===!0}))}}const ce=a=>{let t;for(const s of Object.values(a??{}))s.level!==void 0&&(t=Math.max(t??0,s.level));return t},de=a=>[a.left===void 0?"":`&L${a.left}`,a.center===void 0?"":`&C${a.center}`,a.right===void 0?"":`&R${a.right}`].join(""),st=a=>typeof a=="string"?{text:a,author:ee}:{text:a.text,author:a.author??ee};function nt(a){const t=a.map(([e,n])=>({ref:e,...st(n)})),s=[...new Set(t.map(e=>e.author))];return E+r("comments",{xmlns:T.main},r("authors",{},s.map(e=>r("author",{},w(e))).join("")),r("commentList",{},t.map(e=>r("comment",{ref:e.ref,authorId:s.indexOf(e.author)},r("text",{},r("r",{},r("t",/^\s|\s$|\n/u.test(e.text)?{"xml:space":"preserve"}:{},w(e.text)))))).join("")))}function ot(a){return`<xml xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"><o:shapelayout v:ext="edit"><o:idmap v:ext="edit" data="1"/></o:shapelayout><v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe"><v:stroke joinstyle="miter"/><v:path gradientshapeok="t" o:connecttype="rect"/></v:shapetype>${a.flatMap(([s],e)=>{const n=se(s);return n?[`<v:shape id="_x0000_s${String(1025+e)}" type="#_x0000_t202" style="position:absolute;margin-left:80pt;margin-top:5pt;width:120pt;height:60pt;z-index:${String(e+1)};visibility:hidden" fillcolor="#ffffe1" o:insetmode="auto"><v:fill color2="#ffffe1"/><v:shadow on="t" color="black" obscured="t"/><v:path o:connecttype="none"/><v:textbox style="mso-direction-alt:auto"><div style="text-align:left"></div></v:textbox><x:ClientData ObjectType="Note"><x:MoveWithCells/><x:SizeWithCells/><x:Anchor>${String(n.col+1)}, 15, ${String(n.row)}, 2, ${String(n.col+3)}, 15, ${String(n.row+4)}, 4</x:Anchor><x:AutoFill>False</x:AutoFill><x:Row>${String(n.row)}</x:Row><x:Column>${String(n.col)}</x:Column></x:ClientData></v:shape>`]:[]}).join("")}</xml>`}const fe=a=>`FF${a.slice(1).toUpperCase()}`;function rt(a){if(a.type==="dataBar"||a.type==="colorScale"||a.type==="iconSet")return{};const t={};for(const s of["bold","italic","underline","strike","color","fill","border","format"])a[s]!==void 0&&(t[s]=a[s]);return t}function it(a,t,s){const e=t.values!==void 0||t.blanks!==void 0,{conditions:n,top:o,average:i,color:d}=t,l=e?r("filters",{blank:t.blanks===!0?!0:void 0},(t.values??[]).map(c=>r("filter",{val:c})).join("")):n?r("customFilters",{and:n.length===2&&t.or!==!0?!0:void 0},n.map(c=>r("customFilter",{operator:c.operator==="equal"?void 0:c.operator,val:String(c.value)})).join("")):o?r("top10",{top:o.bottom===!0?!1:void 0,percent:o.percent===!0?!0:void 0,val:o.count}):i?r("dynamicFilter",{type:i==="above"?"aboveAverage":"belowAverage"}):d?.fill!==void 0?r("colorFilter",{dxfId:s({fill:d.fill})}):d?.font!==void 0?r("colorFilter",{dxfId:s({color:d.font}),cellColor:!1}):"";return r("filterColumn",{colId:a},l)}const v=a=>a===void 0?"":` s="${String(a)}"`,at=new Set(["#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#GETTING_DATA"]),he=a=>at.has(a.code),lt=new Set(["width","height","hidden"]);function ue(a){if(!a)return;const t=Object.fromEntries(Object.entries(a).filter(([s])=>!lt.has(s)));return Object.keys(t).length===0?void 0:t}const U=a=>E+r("Relationships",{xmlns:T.pkg},a.map(([t,s,e],n)=>r("Relationship",{Id:`rId${String(n+1)}`,Type:t,Target:s,TargetMode:e})).join(""));function ct(a,t){const s=t.formula?.node;if(s)return V(s,{isTable:n=>a.table(n)!==void 0,array:!0});const{value:e}=t;return e==null?'""':typeof e=="string"?`"${e.replaceAll('"','""')}"`:typeof e=="boolean"?e?"TRUE":"FALSE":e instanceof P?e.code:String(e)}const dt=(a,t)=>a.length===t.length&&a.every((s,e)=>s===t[e]),me=a=>`$${I(a.left)}$${String(a.top+1)}:$${I(a.right)}$${String(a.bottom+1)}`;function ft(a){const t=[],s=(e,n)=>r("definedName",{name:e.name,localSheetId:n,hidden:e.hidden===!0?!0:void 0},w(ct(a,e)));for(const e of a.names.values())t.push(s(e));return a.sheets.forEach((e,n)=>{for(const f of e.names.values())t.push(s(f,n));const o=e.filters.find(f=>!f.table);o&&t.push(r("definedName",{name:"_xlnm._FilterDatabase",localSheetId:n,hidden:!0},w(`${q(e.name)}${me(o.area)}`)));const i=q(e.name),d=e.spec.print,l=d?.area===void 0?void 0:ye(d.area);l&&t.push(r("definedName",{name:"_xlnm.Print_Area",localSheetId:n},w(`${i}${me(l)}`)));const c=[d?.title_cols?.toUpperCase().replace(/([A-Z]+):([A-Z]+)/u,"$$$1:$$$2"),d?.title_rows?.replace(/(\d+):(\d+)/u,"$$$1:$$$2")].flatMap(f=>f===void 0?[]:[`${i}${f}`]);c.length>0&&t.push(r("definedName",{name:"_xlnm.Print_Titles",localSheetId:n},w(c.join(","))))}),t}function ht(a){if(a===void 0)return{};const t=a===!0?{}:a;return{iterate:!0,iterateCount:t.max_iterations??ne.max_iterations,iterateDelta:t.max_change??ne.max_change}}export function writeXlsx(a,t={}){const s=a.wb,e=[];s.checks.length>0&&e.push(`${String(s.checks.length)} check${s.checks.length===1?"":"s"}: a file has no such thing`);const n=Ee(a);e.push(...n.left);const o=new Le,i=new He,d=new Je(s),l=new Ie,c=[["/xl/workbook.xml",C.sheet]],f=Math.max(0,s.sheets.findIndex(p=>p.spec.hidden!==!0));let h=1,u=!1;const m=new Map;let x=0,b=0,y=0;for(const[p,g]of s.sheets.entries()){const B=String(p+1),O=Ze(g,a,t.file,e),D=g.charts.filter(({spec:$})=>[$.categories,...$.series.flatMap(_=>[_.values,_.x])].some(_=>_?.endsWith("#"))).length;D>0&&e.push(`${g.name}: ${String(D)} chart${D===1?"":"s"} on a spill: ${D===1?"it reads":"they read"} the cells the spill covers now, and will not grow with it`);const K=new tt(g,a,o,i,t.cached!==!1,e,d,p,O,n.sheets.find($=>$.sheet===g)),ge=K.write(l.part(`xl/worksheets/sheet${B}.xml`),p===f,h);u||=K.arrays,c.push([`/xl/worksheets/sheet${B}.xml`,C.worksheet]);const L=[];for(const $ of ge){const _=`table${String(h)}.xml`;h+=1,l.add(`xl/tables/${_}`,$),c.push([`/xl/tables/${_}`,C.table]),L.push([`${k}table`,`../tables/${_}`])}if(g.charts.length>0||O.length>0){x+=1;const $=`drawing${String(x)}.xml`;l.add(`xl/drawings/${$}`,Me(g.charts,O)),c.push([`/xl/drawings/${$}`,C.drawing]),L.push([`${k}drawing`,`../drawings/${$}`]);const _=g.charts.map(F=>{b+=1;const N=`chart${String(b)}.xml`;return l.add(`xl/charts/${N}`,Re(a,g,F)),c.push([`/xl/charts/${N}`,C.chart]),[`${k}chart`,`../charts/${N}`]});for(const F of O){const Q=[...m].find(([,we])=>dt(we,F.bytes))?.[0]??`image${String(m.size+1)}${F.file}`;m.set(Q,F.bytes),_.push([`${k}image`,`../media/${Q}`])}l.add(`xl/drawings/_rels/${$}.rels`,U(_))}const H=Object.entries(g.spec.notes??{});if(H.length>0){y+=1;const $=String(y);l.add(`xl/comments${$}.xml`,nt(H)),c.push([`/xl/comments${$}.xml`,C.comments]),l.add(`xl/drawings/vmlDrawing${$}.vml`,ot(H)),L.push([`${k}vmlDrawing`,`../drawings/vmlDrawing${$}.vml`]),L.push([`${k}comments`,`../comments${$}.xml`])}for(const $ of Object.values(g.spec.links??{}))$.startsWith("#")||L.push([`${k}hyperlink`,$,"External"]);L.length>0&&l.add(`xl/worksheets/_rels/sheet${B}.xml.rels`,U(L))}const R=s.sheets.length,A=d.columns.length>0;if(A){const p=`xl/worksheets/sheet${String(R+1)}.xml`;l.add(p,d.xml(i)),c.push([`/${p}`,C.worksheet])}const S=[...s.sheets,...A?[void 0]:[]].map((p,g)=>[`${k}worksheet`,`worksheets/sheet${String(g+1)}.xml`]);S.push([`${k}theme`,"theme/theme1.xml"]),S.push([`${k}styles`,"styles.xml"]),S.push([`${k}sharedStrings`,"sharedStrings.xml"]),u&&(S.push([`${k}sheetMetadata`,"metadata.xml"]),c.push(["/xl/metadata.xml",C.metadata]));const Z=ft(s),J=s.sheets.map((p,g)=>r("sheet",{name:p.name,sheetId:g+1,state:p.spec.hidden===!0?"hidden":void 0,"r:id":`rId${String(g+1)}`}));A&&J.push(r("sheet",{name:d.name,sheetId:R+1,state:"veryHidden","r:id":`rId${String(R+1)}`})),l.add("xl/workbook.xml",E+r("workbook",{xmlns:T.main,"xmlns:r":T.rel},r("workbookPr",{}),r("bookViews",{},r("workbookView",{activeTab:f===0?void 0:f})),r("sheets",{},J.join("")),Z.length>0?r("definedNames",{},Z.join("")):"",r("calcPr",{calcId:Oe,fullCalcOnLoad:!0,...ht(s.file.iteration)}))),l.add("xl/_rels/workbook.xml.rels",U(S)),l.add("xl/styles.xml",E+o.xml()),i.write(l.part("xl/sharedStrings.xml")),l.add("xl/theme/theme1.xml",E+Fe),u&&l.add("xl/metadata.xml",E+Be),l.add("docProps/core.xml",E+r("cp:coreProperties",{"xmlns:cp":"http://schemas.openxmlformats.org/package/2006/metadata/core-properties","xmlns:dc":"http://purl.org/dc/elements/1.1/"},s.title===void 0?"":r("dc:title",{},w(s.title)))),l.add("docProps/app.xml",E+r("Properties",{xmlns:"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"},r("Application",{},"AllyHub"))),l.add("_rels/.rels",U([[`${k}officeDocument`,"xl/workbook.xml"],["http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties","docProps/core.xml"],[`${k}extended-properties`,"docProps/app.xml"]])),c.push(["/xl/styles.xml",C.styles],["/xl/sharedStrings.xml",C.strings],["/xl/theme/theme1.xml",C.theme],["/docProps/core.xml",C.core],["/docProps/app.xml",C.app]);const pe=[...m].sort(([p],[g])=>p.localeCompare(g));for(const[p,g]of pe)l.add(`xl/media/${p}`,g);return l.add("[Content_Types].xml",E+r("Types",{xmlns:T.types},r("Default",{Extension:"rels",ContentType:"application/vnd.openxmlformats-package.relationships+xml"}),r("Default",{Extension:"xml",ContentType:"application/xml"}),y>0?r("Default",{Extension:"vml",ContentType:"application/vnd.openxmlformats-officedocument.vmlDrawing"}):"",[...new Set([...m.keys()].map(p=>p.split(".").pop()??""))].sort().map(p=>r("Default",{Extension:p,ContentType:`image/${p==="jpg"?"jpeg":p}`})).join(""),c.map(([p,g])=>r("Override",{PartName:p,ContentType:g})).join(""))),{bytes:l.finish(),left:e}}function ut(a){const t=(n,o,i)=>o.length===0?"":r(n,{count:o.length,manualBreakCount:o.length},o.map(d=>r("brk",{id:d,max:i,man:!0})).join("")),s=[...new Set(a?.rows??[])].sort((n,o)=>n-o).map(n=>n-1),e=[...new Set((a?.cols??[]).map(n=>te(n.toUpperCase())).filter(n=>n!==void 0&&n>0))].sort((n,o)=>n-o);return t("rowBreaks",s,X-1)+t("colBreaks",e,W-1)}
|
|
@@ -1,38 +1,79 @@
|
|
|
1
|
-
import type { AnimationDirection, AnimationEffect, AnimationFile, AnimationStart, SlideTransitionType, TransitionFile } from "@allyhub/formats";
|
|
1
|
+
import type { AnimateText, AnimationDirection, AnimationRepeat, AnimationEffect, AnimationFile, AnimationStart, SlideTransitionType, TransitionFile } from "@allyhub/formats";
|
|
2
2
|
import type { Frame, PathStep } from "./model.js";
|
|
3
3
|
/** PowerPoint's default length of each effect, seconds. */
|
|
4
4
|
export declare const ANIMATION_DURATIONS: Readonly<Record<AnimationEffect, number>>;
|
|
5
5
|
export declare const isExit: (e: AnimationEffect) => boolean;
|
|
6
6
|
export declare const isEntrance: (e: AnimationEffect) => boolean;
|
|
7
|
-
/** PowerPoint's default length of each transition, seconds. */
|
|
7
|
+
/** PowerPoint's default length of each transition, seconds (a cut has none). */
|
|
8
8
|
export declare const TRANSITION_DURATIONS: Readonly<Record<SlideTransitionType, number>>;
|
|
9
|
+
/**
|
|
10
|
+
* Each transition's Effect Options, as PowerPoint offers them: its ways,
|
|
11
|
+
* the first its default, and whether it can go through black.
|
|
12
|
+
*/
|
|
13
|
+
export declare const TRANSITION_OPTIONS: Readonly<Record<SlideTransitionType, {
|
|
14
|
+
directions: readonly AnimationDirection[];
|
|
15
|
+
throughBlack: boolean;
|
|
16
|
+
}>>;
|
|
17
|
+
/**
|
|
18
|
+
* Each effect's Effect Options, as PowerPoint offers them: its ways and
|
|
19
|
+
* its amounts, the first way its default, and its amount's default (a
|
|
20
|
+
* Grow/Shrink's size a share of its own, a spin's degrees, a
|
|
21
|
+
* Transparency's share that shows through).
|
|
22
|
+
*/
|
|
23
|
+
export declare const EFFECT_OPTIONS: Readonly<Record<AnimationEffect, {
|
|
24
|
+
directions: readonly AnimationDirection[];
|
|
25
|
+
amounts?: readonly number[];
|
|
26
|
+
amount?: number;
|
|
27
|
+
}>>;
|
|
28
|
+
/** Whether an effect takes a way: one it offers. */
|
|
29
|
+
export declare const effectTakes: (effect: AnimationEffect, d: AnimationDirection) => boolean;
|
|
9
30
|
/** A slide's transition with all it leaves to its defaults said. */
|
|
10
31
|
export interface ResolvedTransition {
|
|
11
32
|
type: SlideTransitionType;
|
|
33
|
+
/** One of its type's ways; a fade's, a cut's and a morph's is unused. */
|
|
12
34
|
direction: AnimationDirection;
|
|
35
|
+
throughBlack: boolean;
|
|
13
36
|
duration: number;
|
|
14
37
|
}
|
|
38
|
+
/** Whether a transition takes a way: one its type offers. */
|
|
39
|
+
export declare const transitionTakes: (type: SlideTransitionType, d: AnimationDirection) => boolean;
|
|
15
40
|
export declare const resolveTransition: (t: TransitionFile) => ResolvedTransition;
|
|
41
|
+
/** One of a transition's two slides, `p` of the way through it. */
|
|
42
|
+
export interface TransitionSlide {
|
|
43
|
+
opacity: number;
|
|
44
|
+
/** Moved by, in shares of the slide. */
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
/** Grown by, from its middle, and turned by, degrees clockwise. */
|
|
48
|
+
scale: number;
|
|
49
|
+
rotate: number;
|
|
50
|
+
/** What is cut from each side, a share of the slide. */
|
|
51
|
+
clip?: {
|
|
52
|
+
top: number;
|
|
53
|
+
right: number;
|
|
54
|
+
bottom: number;
|
|
55
|
+
left: number;
|
|
56
|
+
};
|
|
57
|
+
/** What shows of it, a polygon in shares of the slide (a split's two halves). */
|
|
58
|
+
polygon?: readonly (readonly [number, number])[];
|
|
59
|
+
}
|
|
16
60
|
/** How the two slides of a transition are drawn, `p` of the way through it. */
|
|
17
61
|
export interface TransitionState {
|
|
18
|
-
/** The slide coming on
|
|
19
|
-
incoming:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
bottom: number;
|
|
27
|
-
left: number;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
/** The slide going: moved by, in shares of the slide. */
|
|
31
|
-
outgoing: {
|
|
32
|
-
x: number;
|
|
33
|
-
y: number;
|
|
34
|
-
};
|
|
62
|
+
/** The slide coming on. */
|
|
63
|
+
incoming: TransitionSlide;
|
|
64
|
+
/** The slide going. */
|
|
65
|
+
outgoing: TransitionSlide;
|
|
66
|
+
/** The slide going is drawn over the one coming (an uncover, a reveal, a zoom out). */
|
|
67
|
+
outgoingOver: boolean;
|
|
68
|
+
/** What is under both is black: they fade to it and from it (Through Black). */
|
|
69
|
+
black: boolean;
|
|
35
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* What a split shows `shown` of the way open, in shares of what it splits:
|
|
73
|
+
* out from its middle line, or in from its two edges, along x for a
|
|
74
|
+
* vertical line, along y for a horizontal one.
|
|
75
|
+
*/
|
|
76
|
+
export declare function barn(d: AnimationDirection, shown: number): Pick<TransitionSlide, "clip" | "polygon">;
|
|
36
77
|
/** A transition's drawing `p` of the way through it. A morph's own is `morphFrame`'s. */
|
|
37
78
|
export declare function transitionAt(t: ResolvedTransition, p: number): TransitionState;
|
|
38
79
|
/** A shape's frame on its way from where it was to where it stands: the morph's ease in and out. */
|
|
@@ -47,15 +88,52 @@ export interface ResolvedAnimation {
|
|
|
47
88
|
start: AnimationStart;
|
|
48
89
|
duration: number;
|
|
49
90
|
delay: number;
|
|
91
|
+
/** Its amount, where it has one: a Grow/Shrink's size, a spin's degrees, a Transparency's share. */
|
|
92
|
+
amount?: number;
|
|
50
93
|
/** A motion path's steps, in EMU from where the shape stands. */
|
|
51
94
|
path?: PathStep[];
|
|
95
|
+
/** By word or letter: how far apart each starts (a share of its duration), and how many its text has. */
|
|
96
|
+
iterate?: {
|
|
97
|
+
by: AnimateText;
|
|
98
|
+
delay: number;
|
|
99
|
+
units: number;
|
|
100
|
+
};
|
|
101
|
+
/** How many times it plays (once where absent), or until the next click or the slide's end. */
|
|
102
|
+
repeat?: number | AnimationRepeat;
|
|
103
|
+
/** Back as it was before it once it has played. */
|
|
104
|
+
rewind?: true;
|
|
52
105
|
}
|
|
106
|
+
/** PowerPoint's delay between words or letters, a share of an effect's duration. */
|
|
107
|
+
export declare const TEXT_DELAY = 0.1;
|
|
108
|
+
/** A text's words (what stands between spaces) or its letters (each grapheme but spaces), as an effect by word or by letter takes them one at a time. */
|
|
109
|
+
export declare function textUnits(text: string, by: AnimateText): string[];
|
|
110
|
+
/** A part of a piece of text: the piece by its place in the list, from `start` to `end`. */
|
|
111
|
+
export interface TextPart {
|
|
112
|
+
piece: number;
|
|
113
|
+
start: number;
|
|
114
|
+
end: number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The units an effect by word or by letter takes one at a time, across a
|
|
118
|
+
* paragraph's pieces of text (its runs, or the text the stage draws them
|
|
119
|
+
* in): a word is what stands between spaces, whichever pieces it is in
|
|
120
|
+
* ("Ally**Hub**" is one), each unit the parts of the pieces it takes; a
|
|
121
|
+
* letter is each grapheme but spaces. The timing counts them and the stage
|
|
122
|
+
* draws them, so both count alike.
|
|
123
|
+
*/
|
|
124
|
+
export declare function unitsAcross(pieces: readonly string[], by: AnimateText): TextPart[][];
|
|
125
|
+
/** One round of an animation, seconds: by word or letter, from its first's start to its last's end. */
|
|
126
|
+
export declare const roundOf: (a: ResolvedAnimation) => number;
|
|
127
|
+
/** How long an animation plays on its slide's clock: its rounds, one where it repeats until something. */
|
|
128
|
+
export declare const spanOf: (a: ResolvedAnimation) => number;
|
|
53
129
|
/** An animation on its slide's clock. */
|
|
54
130
|
export interface TimedAnimation extends ResolvedAnimation {
|
|
55
131
|
/** The step it plays in: 0 before the first click. */
|
|
56
132
|
step: number;
|
|
57
133
|
from: number;
|
|
58
134
|
to: number;
|
|
135
|
+
/** Where it repeats until the next click or the slide's end: when it stops, its step's still or the slide's last. */
|
|
136
|
+
stop?: number;
|
|
59
137
|
}
|
|
60
138
|
export interface SlideClock {
|
|
61
139
|
timed: TimedAnimation[];
|
|
@@ -63,7 +141,9 @@ export interface SlideClock {
|
|
|
63
141
|
rests: number[];
|
|
64
142
|
}
|
|
65
143
|
/** An animation as the slides file has it, with its defaults; undefined for a path that does not read. */
|
|
66
|
-
export declare function resolveAnimation(a: AnimationFile
|
|
144
|
+
export declare function resolveAnimation(a: AnimationFile,
|
|
145
|
+
/** How many words or letters its text has, for one by word or letter. */
|
|
146
|
+
units?: number): ResolvedAnimation | undefined;
|
|
67
147
|
/**
|
|
68
148
|
* A slide's clock. `moving` is how long each shape that moves by its own
|
|
69
149
|
* code (a component) takes, by name: a step that brings one on rests no
|
|
@@ -99,12 +179,19 @@ export declare function clockOf(slide: {
|
|
|
99
179
|
component?: {
|
|
100
180
|
dur?: number;
|
|
101
181
|
};
|
|
182
|
+
media?: {
|
|
183
|
+
playback?: {
|
|
184
|
+
start?: "auto" | "on-click" | undefined;
|
|
185
|
+
} | undefined;
|
|
186
|
+
} | undefined;
|
|
102
187
|
}[];
|
|
103
188
|
transition?: ResolvedTransition;
|
|
104
189
|
}, first: boolean): SlideClock & {
|
|
105
190
|
lead: number;
|
|
106
191
|
comesOn: (shape: string) => number;
|
|
107
192
|
goesOff: (shape: string) => number | undefined;
|
|
193
|
+
/** When a movie or a sound starts playing: as it comes on, or a click of its own after the slide's animations (PowerPoint's In Click Sequence). */
|
|
194
|
+
playsAt: (shape: string) => number;
|
|
108
195
|
};
|
|
109
196
|
/** How a shape, or a paragraph of one, is drawn at a moment. */
|
|
110
197
|
export interface DrawnState {
|
|
@@ -114,6 +201,11 @@ export interface DrawnState {
|
|
|
114
201
|
x: number;
|
|
115
202
|
y: number;
|
|
116
203
|
scale: number;
|
|
204
|
+
/** Grown across and down besides, from its middle (a Grow/Shrink). */
|
|
205
|
+
sx: number;
|
|
206
|
+
sy: number;
|
|
207
|
+
/** Turned by, degrees clockwise (a spin). */
|
|
208
|
+
rotate: number;
|
|
117
209
|
/** What is cut from each side, a share of its size. */
|
|
118
210
|
clip?: {
|
|
119
211
|
top: number;
|
|
@@ -121,6 +213,8 @@ export interface DrawnState {
|
|
|
121
213
|
bottom: number;
|
|
122
214
|
left: number;
|
|
123
215
|
};
|
|
216
|
+
/** What shows of it, a polygon in shares of its size (a split in from both edges). */
|
|
217
|
+
polygon?: readonly (readonly [number, number])[];
|
|
124
218
|
}
|
|
125
219
|
/** Where a path has got to, a share `p` of its length along it. */
|
|
126
220
|
export declare function pathPoint(steps: readonly PathStep[], p: number): {
|
|
@@ -135,7 +229,9 @@ export declare function pathPoint(steps: readonly PathStep[], p: number): {
|
|
|
135
229
|
export declare function drawnAt(animations: readonly TimedAnimation[], t: number, f: Frame, slide: {
|
|
136
230
|
width: number;
|
|
137
231
|
height: number;
|
|
138
|
-
}
|
|
232
|
+
},
|
|
233
|
+
/** One word or letter of what these animate by word or letter, from 0: its own time. */
|
|
234
|
+
unit?: number): DrawnState;
|
|
139
235
|
/** Each thing a slide animates: a shape, or a paragraph of one, with its animations in order. */
|
|
140
236
|
export declare function animationTargets(timed: readonly TimedAnimation[]): {
|
|
141
237
|
shape: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{pathSteps as w}from"./path.js";import{EMU_PER_PT as u}from"./units.js";export const ANIMATION_DURATIONS={appear:0,fade:.5,wipe:.5,"fly-in":.5,zoom:.5,disappear:0,"fade-out":.5,"wipe-out":.5,"fly-out":.5,"zoom-out":.5,pulse:.5,path:2};const T=new Set(["disappear","fade-out","wipe-out","fly-out","zoom-out"]),E=new Set(["appear","fade","wipe","fly-in","zoom"]);export const isExit=t=>T.has(t),isEntrance=t=>E.has(t),TRANSITION_DURATIONS={fade:.7,push:1,wipe:1,morph:2},resolveTransition=t=>({type:t.type,direction:t.direction??"from-right",duration:t.duration??TRANSITION_DURATIONS[t.type]});const N={"from-left":{x:-1,y:0},"from-right":{x:1,y:0},"from-top":{x:0,y:-1},"from-bottom":{x:0,y:1}};export function transitionAt(t,o){const e={opacity:1,x:0,y:0};if(t.type==="fade")return{incoming:{...e,opacity:o},outgoing:{x:0,y:0}};if(t.type==="push"){const r=N[t.direction];return{incoming:{...e,x:r.x*(1-o),y:r.y*(1-o)},outgoing:{x:-r.x*o,y:-r.y*o}}}return t.type==="wipe"?{incoming:{...e,clip:S(t.direction,1-o)},outgoing:{x:0,y:0}}:{incoming:e,outgoing:{x:0,y:0}}}export function morphFrame(t,o,e){const r=e*e*(3-2*e),i=(p,f)=>p+(f-p)*r;return{left:i(t.left,o.left),top:i(t.top,o.top),width:i(t.width,o.width),height:i(t.height,o.height)}}export function resolveAnimation(t){const o=t.path===void 0?void 0:w(t.path);if(!(t.path!==void 0&&!o)&&!(t.effect==="path"&&!o))return{shape:t.shape,...t.paragraph===void 0?{}:{paragraph:t.paragraph},effect:t.effect,direction:t.direction??"from-bottom",start:t.start??"on-click",duration:t.duration??ANIMATION_DURATIONS[t.effect],delay:t.delay??0,...o?{path:o.map(e=>e.op==="close"?e:e.op!=="curve"?{...e,x:e.x*u,y:e.y*u}:{op:"curve",x1:e.x1*u,y1:e.y1*u,x2:e.x2*u,y2:e.y2*u,x:e.x*u,y:e.y*u})}:{}}}export function slideClock(t,o,e,r=0,i=0){const p=new Set(t.filter(s=>isEntrance(s.effect)).map(s=>s.shape)),f=[...o].filter(([s])=>!p.has(s)).map(([,s])=>s);let n=i+Math.max(0,...f);if(t.length===0)return{timed:[],rests:[Math.max(e,i,...f)]};const c=[],a=[];let h=0,y=i;for(const s of t){s.start==="on-click"?(c.push(n),h++,n+=r,y=n):s.start==="after-previous"&&(y=n);const l=y+s.delay,d=l+s.duration;a.push({...s,step:h,from:l,to:d}),n=Math.max(n,d);const m=o.get(s.shape);m!==void 0&&isEntrance(s.effect)&&(n=Math.max(n,l+m))}return c.push(n),{timed:a,rests:c}}export const SLIDE_SECONDS=4,componentSeconds=t=>t.dur??SLIDE_SECONDS,DECK_FPS=30;const A=t=>Math.ceil(t*DECK_FPS-1e-6)/DECK_FPS;export const inTransition=(t,o)=>t<o-1e-6;export function clockOf(t,o){const e=o?0:t.transition?.duration??0,r=slideClock(t.animations,new Map(t.shapes.flatMap(i=>i.component?[[i.name,componentSeconds(i.component)-1/DECK_FPS]]:[])),SLIDE_SECONDS-1/DECK_FPS,1/DECK_FPS,e);return{timed:r.timed,rests:r.rests.map(A),lead:e,comesOn:i=>r.timed.find(p=>p.shape===i&&isEntrance(p.effect))?.from??e,goesOff:i=>r.timed.find(p=>p.shape===i&&isExit(p.effect))?.to}}const g=1e-6,x={hidden:!1,opacity:1,x:0,y:0,scale:1},I=t=>1-(1-t)*(1-t);function O(t){const o=[];let e={x:0,y:0};for(const r of t){if(r.op==="close")continue;if(r.op!=="curve"){e={x:r.x,y:r.y},o.push(e);continue}const i=e;for(let p=1;p<=24;p++){const f=p/24,n=1-f,c=(a,h,y,s)=>n*n*n*a+3*n*n*f*h+3*n*f*f*y+f*f*f*s;o.push({x:c(i.x,r.x1,r.x2,r.x),y:c(i.y,r.y1,r.y2,r.y)})}e={x:r.x,y:r.y}}return o}export function pathPoint(t,o){const e=O(t),[r]=e;if(!r)return{x:0,y:0};let i=0;for(let f=1;f<e.length;f++){const[n,c]=[e[f-1]??r,e[f]??r];i+=Math.hypot(c.x-n.x,c.y-n.y)}let p=i*o;for(let f=1;f<e.length;f++){const[n,c]=[e[f-1]??r,e[f]??r],a=Math.hypot(c.x-n.x,c.y-n.y);if(p<=a&&a>0){const h=p/a;return{x:n.x+(c.x-n.x)*h,y:n.y+(c.y-n.y)*h}}p-=a}return e.at(-1)??r}function b(t,o,e){return t==="from-left"?{x:-(o.left+o.width),y:0}:t==="from-right"?{x:e.width-o.left,y:0}:t==="from-top"?{x:0,y:-(o.top+o.height)}:{x:0,y:e.height-o.top}}function S(t,o){const e={top:0,right:0,bottom:0,left:0};return t==="from-left"?e.right=o:t==="from-right"?e.left=o:t==="from-top"?e.bottom=o:e.top=o,e}function M(t,o,e,r){if(t.effect==="fade"||t.effect==="fade-out")return{opacity:o};if(t.effect==="zoom"||t.effect==="zoom-out")return{scale:o,opacity:o};if(t.effect==="wipe"||t.effect==="wipe-out")return{clip:S(t.direction,1-o)};if(t.effect==="fly-in"||t.effect==="fly-out"){const i=b(t.direction,e,r);return{x:i.x*(1-o),y:i.y*(1-o)}}return{}}export function drawnAt(t,o,e,r){let i={...x};const[p]=t,f=n=>o<n-g;if(p&&isEntrance(p.effect)&&f(p.from))return{...x,hidden:!0};for(const n of t){if(f(n.from))break;const c=n.to>n.from&&o<n.to-g?Math.min(1,(o-n.from)/(n.to-n.from)):1;if(n.effect==="path"&&n.path){const a=pathPoint(n.path,c);i={...i,x:a.x,y:a.y}}else n.effect==="pulse"?i={...i,scale:1+.05*Math.sin(c*Math.PI)}:isExit(n.effect)?i=c>=1?{...x,hidden:!0}:{...i,...M(n,1-(n.effect==="fly-out"?c*c:c),e,r)}:i={...x,...c<1?M(n,n.effect==="fly-in"?I(c):c,e,r):{}}}return i}export function animationTargets(t){const o=new Map;for(const e of t){const r=JSON.stringify([e.shape,e.paragraph??null]),i=o.get(r);i?i.animations.push(e):o.set(r,{shape:e.shape,...e.paragraph===void 0?{}:{paragraph:e.paragraph},animations:[e]})}return[...o.values()]}
|
|
2
|
+
import{pathSteps as E}from"./path.js";import{EMU_PER_PT as h}from"./units.js";export const ANIMATION_DURATIONS={appear:0,fade:.5,"fly-in":.5,"float-in":1,split:.5,wipe:.5,zoom:.5,disappear:0,"fade-out":.5,"fly-out":.5,"float-out":1,"split-out":.5,"wipe-out":.5,"zoom-out":.5,pulse:.5,"grow-shrink":2,spin:2,transparency:.5,path:2};const I=new Set(["disappear","fade-out","fly-out","float-out","split-out","wipe-out","zoom-out"]),A=new Set(["appear","fade","fly-in","float-in","split","wipe","zoom"]);export const isExit=t=>I.has(t),isEntrance=t=>A.has(t),TRANSITION_DURATIONS={fade:.7,push:1,wipe:1,split:1.5,reveal:2,cut:0,cover:1,uncover:1,zoom:1,morph:2};const x=["from-right","from-top","from-left","from-bottom"],w=[...x,"from-top-right","from-bottom-right","from-top-left","from-bottom-left"];export const TRANSITION_OPTIONS={fade:{directions:[],throughBlack:!0},push:{directions:x,throughBlack:!1},wipe:{directions:x,throughBlack:!1},split:{directions:["vertical-out","vertical-in","horizontal-out","horizontal-in"],throughBlack:!1},reveal:{directions:["from-right","from-left"],throughBlack:!0},cut:{directions:[],throughBlack:!0},cover:{directions:w,throughBlack:!1},uncover:{directions:w,throughBlack:!1},zoom:{directions:["in","out","rotate"],throughBlack:!1},morph:{directions:[],throughBlack:!1}};const S=["vertical-out","vertical-in","horizontal-out","horizontal-in"];export const EFFECT_OPTIONS={appear:{directions:[]},fade:{directions:[]},"fly-in":{directions:["from-bottom","from-top","from-left","from-right"]},"float-in":{directions:["up","down"]},split:{directions:S},wipe:{directions:["from-bottom","from-top","from-left","from-right"]},zoom:{directions:[]},disappear:{directions:[]},"fade-out":{directions:[]},"fly-out":{directions:["from-bottom","from-top","from-left","from-right"]},"float-out":{directions:["up","down"]},"split-out":{directions:S},"wipe-out":{directions:["from-bottom","from-top","from-left","from-right"]},"zoom-out":{directions:[]},pulse:{directions:[]},"grow-shrink":{directions:["both","horizontal","vertical"],amounts:[1.1,.5,1.5,4],amount:1.5},spin:{directions:["clockwise","counterclockwise"],amounts:[90,180,360,720],amount:360},transparency:{directions:[],amounts:[.25,.5,.75,1],amount:.5},path:{directions:[]}},effectTakes=(t,e)=>EFFECT_OPTIONS[t].directions.includes(e),transitionTakes=(t,e)=>TRANSITION_OPTIONS[t].directions.includes(e),resolveTransition=t=>{const e=TRANSITION_OPTIONS[t.type];return{type:t.type,direction:t.direction!==void 0&&e.directions.includes(t.direction)?t.direction:e.directions[0]??"from-right",throughBlack:t.through_black===!0&&e.throughBlack,duration:t.duration??TRANSITION_DURATIONS[t.type]}};const B={"from-left":{x:-1,y:0},"from-right":{x:1,y:0},"from-top":{x:0,y:-1},"from-bottom":{x:0,y:1},"from-top-right":{x:1,y:-1},"from-bottom-right":{x:1,y:1},"from-top-left":{x:-1,y:-1},"from-bottom-left":{x:-1,y:1}},m=t=>B[t]??{x:0,y:1},l={opacity:1,x:0,y:0,scale:1,rotate:0};export function barn(t,e){const n=t==="vertical-out"||t==="vertical-in";if(t==="vertical-out"||t==="horizontal-out"){const s=(1-e)/2;return{clip:n?{top:0,right:s,bottom:0,left:s}:{top:s,right:0,bottom:s,left:0}}}const f=e/2,i=1-f,r=[[0,0],[f,0],[f,1],[i,1],[i,0],[1,0],[1,1],[0,1]];return{polygon:n?r:r.map(([s,c])=>[c,s])}}export function transitionAt(t,e){const o={incoming:{...l},outgoing:{...l},outgoingOver:!1,black:!1},f=e<.5;switch(t.type){case"fade":return t.throughBlack?{...o,black:!0,outgoing:{...l,opacity:f?1-2*e:0},incoming:{...l,opacity:f?0:2*e-1}}:{...o,incoming:{...l,opacity:e}};case"cut":return t.throughBlack?{...o,black:!0,outgoing:{...l,opacity:0},incoming:{...l,opacity:e>=1?1:0}}:o;case"push":{const i=m(t.direction);return{...o,incoming:{...l,x:i.x*(1-e),y:i.y*(1-e)},outgoing:{...l,x:-i.x*e,y:-i.y*e}}}case"cover":{const i=m(t.direction);return{...o,incoming:{...l,x:i.x*(1-e),y:i.y*(1-e)}}}case"uncover":{const i=m(t.direction);return{...o,outgoingOver:!0,outgoing:{...l,x:-i.x*e,y:-i.y*e}}}case"reveal":{const i=m(t.direction);return t.throughBlack?{...o,outgoingOver:!0,black:!0,outgoing:{...l,x:-i.x*Math.min(1,2*e),opacity:f?1-2*e:0},incoming:{...l,opacity:f?0:2*e-1}}:{...o,outgoingOver:!0,outgoing:{...l,x:-i.x*e,opacity:1-e}}}case"wipe":return{...o,incoming:{...l,clip:O(t.direction,1-e)}};case"split":return{...o,incoming:{...l,...barn(t.direction,e)}};case"zoom":return t.direction==="out"?{...o,outgoingOver:!0,outgoing:{...l,scale:1-e,opacity:1-e}}:{...o,incoming:{...l,scale:e,opacity:t.direction==="rotate"?1:e,rotate:t.direction==="rotate"?-720*(1-e):0}};case"morph":return o}}export function morphFrame(t,e,n){const o=n*n*(3-2*n),f=(i,r)=>i+(r-i)*o;return{left:f(t.left,e.left),top:f(t.top,e.top),width:f(t.width,e.width),height:f(t.height,e.height)}}export const TEXT_DELAY=.1;const T=new Intl.Segmenter(void 0,{granularity:"grapheme"});export function textUnits(t,e){return e==="word"?t.split(/\s+/u).filter(n=>n!==""):[...T.segment(t)].map(n=>n.segment).filter(n=>!/^\s+$/u.test(n))}export function unitsAcross(t,e){const n=[];let o=[];return t.forEach((f,i)=>{if(e==="letter"){for(const r of T.segment(f))/^\s+$/u.test(r.segment)||n.push([{piece:i,start:r.index,end:r.index+r.segment.length}]);return}for(const r of f.matchAll(/\s+|\S+/gu))/^\s/u.test(r[0])?(o.length>0&&n.push(o),o=[]):o.push({piece:i,start:r.index,end:r.index+r[0].length})}),o.length>0&&n.push(o),n}export const roundOf=t=>t.iterate?t.duration*(1+Math.max(0,t.iterate.units-1)*t.iterate.delay):t.duration,spanOf=t=>roundOf(t)*(typeof t.repeat=="number"?t.repeat:1);export function resolveAnimation(t,e=1){const n=t.path===void 0?void 0:E(t.path);if(t.path!==void 0&&!n||t.effect==="path"&&!n)return;const o=EFFECT_OPTIONS[t.effect],f=o.amount===void 0?void 0:t.amount??o.amount;return{shape:t.shape,...t.paragraph===void 0?{}:{paragraph:t.paragraph},effect:t.effect,direction:t.direction!==void 0&&o.directions.includes(t.direction)?t.direction:o.directions[0]??"from-bottom",...f===void 0?{}:{amount:t.effect==="transparency"?Math.min(1,f):f},start:t.start??"on-click",duration:t.duration??ANIMATION_DURATIONS[t.effect],delay:t.delay??0,...t.animate_text===void 0?{}:{iterate:{by:t.animate_text,delay:t.text_delay??TEXT_DELAY,units:Math.max(1,e)}},...t.repeat===void 0||t.repeat===1?{}:{repeat:t.repeat},...t.rewind?{rewind:!0}:{},...n?{path:n.map(i=>i.op==="close"?i:i.op!=="curve"?{...i,x:i.x*h,y:i.y*h}:{op:"curve",x1:i.x1*h,y1:i.y1*h,x2:i.x2*h,y2:i.y2*h,x:i.x*h,y:i.y*h})}:{}}}export function slideClock(t,e,n,o=0,f=0){const i=new Set(t.filter(a=>isEntrance(a.effect)).map(a=>a.shape)),r=[...e].filter(([a])=>!i.has(a)).map(([,a])=>a);let s=f+Math.max(0,...r);if(t.length===0)return{timed:[],rests:[Math.max(n,f,...r)]};const c=[],d=[];let u=0,p=f;for(const a of t){a.start==="on-click"?(c.push(s),u++,s+=o,p=s):a.start==="after-previous"&&(p=s);const g=p+a.delay,v=g+spanOf(a);d.push({...a,step:u,from:g,to:v}),s=Math.max(s,v);const b=e.get(a.shape);b!==void 0&&isEntrance(a.effect)&&(s=Math.max(s,g+b))}c.push(s);for(const a of d)a.repeat==="until-next-click"?a.stop=c[a.step]??s:a.repeat==="until-end-of-slide"&&(a.stop=s);return{timed:d,rests:c}}export const SLIDE_SECONDS=4,componentSeconds=t=>t.dur??SLIDE_SECONDS,DECK_FPS=30;const M=t=>Math.ceil(t*DECK_FPS-1e-6)/DECK_FPS;export const inTransition=(t,e)=>t<e-1e-6;export function clockOf(t,e){const n=e?0:t.transition?.duration??0,o=slideClock(t.animations,new Map(t.shapes.flatMap(s=>s.component?[[s.name,componentSeconds(s.component)-1/DECK_FPS]]:[])),SLIDE_SECONDS-1/DECK_FPS,1/DECK_FPS,n),f=o.rests.map(M),i=s=>o.timed.find(c=>c.shape===s&&isEntrance(c.effect))?.from??n,r=new Map;for(const s of t.shapes){if(s.media?.playback?.start!=="on-click")continue;const c=f.at(-1)??n;r.set(s.name,c),f.push(M(c+1/DECK_FPS))}return{timed:o.timed,rests:f,lead:n,comesOn:i,goesOff:s=>o.timed.find(c=>c.shape===s&&isExit(c.effect))?.to,playsAt:s=>r.get(s)??i(s)}}const k=1e-6,y={hidden:!1,opacity:1,x:0,y:0,scale:1,sx:1,sy:1,rotate:0},N=t=>1-(1-t)*(1-t);function _(t){const e=[];let n={x:0,y:0};for(const o of t){if(o.op==="close")continue;if(o.op!=="curve"){n={x:o.x,y:o.y},e.push(n);continue}const f=n;for(let i=1;i<=24;i++){const r=i/24,s=1-r,c=(d,u,p,a)=>s*s*s*d+3*s*s*r*u+3*s*r*r*p+r*r*r*a;e.push({x:c(f.x,o.x1,o.x2,o.x),y:c(f.y,o.y1,o.y2,o.y)})}n={x:o.x,y:o.y}}return e}export function pathPoint(t,e){const n=_(t),[o]=n;if(!o)return{x:0,y:0};let f=0;for(let r=1;r<n.length;r++){const[s,c]=[n[r-1]??o,n[r]??o];f+=Math.hypot(c.x-s.x,c.y-s.y)}let i=f*e;for(let r=1;r<n.length;r++){const[s,c]=[n[r-1]??o,n[r]??o],d=Math.hypot(c.x-s.x,c.y-s.y);if(i<=d&&d>0){const u=i/d;return{x:s.x+(c.x-s.x)*u,y:s.y+(c.y-s.y)*u}}i-=d}return n.at(-1)??o}function P(t,e,n){return t==="from-left"?{x:-(e.left+e.width),y:0}:t==="from-right"?{x:n.width-e.left,y:0}:t==="from-top"?{x:0,y:-(e.top+e.height)}:{x:0,y:n.height-e.top}}function O(t,e){const n={top:0,right:0,bottom:0,left:0};return t==="from-left"?n.right=e:t==="from-right"?n.left=e:t==="from-top"?n.bottom=e:n.top=e,n}const D={"vertical-out":"vertical-in","vertical-in":"vertical-out","horizontal-out":"horizontal-in","horizontal-in":"horizontal-out"};function z(t,e,n,o){if(t.effect==="fade"||t.effect==="fade-out")return{opacity:e};if(t.effect==="zoom"||t.effect==="zoom-out")return{scale:e,opacity:e};if(t.effect==="wipe"||t.effect==="wipe-out")return{clip:O(t.direction,1-e)};if(t.effect==="split")return barn(t.direction,e);if(t.effect==="split-out")return barn(D[t.direction]??"vertical-in",e);if(t.effect==="float-in"||t.effect==="float-out"){const f=.1*o.height*(1-e),i=t.effect==="float-in"==(t.direction==="down")?-1:1;return{opacity:e,y:i*f}}if(t.effect==="fly-in"||t.effect==="fly-out"){const f=P(t.direction,n,o);return{x:f.x*(1-e),y:f.y*(1-e)}}return{}}export function drawnAt(t,e,n,o,f){const[i]=t;let r=i&&isEntrance(i.effect)?{...y,hidden:!0}:{...y};const s=c=>e<c-k;for(const c of t){const d=f!==void 0&&c.iterate?f*c.iterate.delay*c.duration:0;if(s(c.from+d))break;const u=R(c,e,d);if(u!==void 0)if(c.effect==="path"&&c.path){const p=pathPoint(c.path,u);r={...r,x:p.x,y:p.y}}else if(c.effect==="pulse")r={...r,scale:1+.05*Math.sin(u*Math.PI)};else if(c.effect==="grow-shrink"){const p=1+((c.amount??1.5)-1)*u;r={...r,sx:r.sx*(c.direction==="vertical"?1:p),sy:r.sy*(c.direction==="horizontal"?1:p)}}else if(c.effect==="spin"){const p=(c.amount??360)*u;r={...r,rotate:r.rotate+(c.direction==="counterclockwise"?-p:p)}}else c.effect==="transparency"?r={...r,opacity:r.opacity*(1-(c.amount??.5)*u)}:isExit(c.effect)?r=u>=1?{...y,hidden:!0}:{...r,...z(c,1-(c.effect==="fly-out"?u*u:u),n,o)}:r={...y,...u<1?z(c,c.effect==="fly-in"?N(u):u,n,o):{}}}return r}function R(t,e,n){const o=roundOf(t),f=r=>t.duration>0?Math.min(1,Math.max(0,(r-n)/t.duration)):1,i=typeof t.repeat=="string"?t.stop??1/0:t.to;if(e>=i-k){if(t.rewind)return;const r=typeof t.repeat=="number"?t.repeat%1:0;return r>k?f(o*r):1}return o<=0?1:f((e-t.from)%o)}export function animationTargets(t){const e=new Map;for(const n of t){const o=JSON.stringify([n.shape,n.paragraph??null]),f=e.get(o);f?f.animations.push(n):e.set(o,{shape:n.shape,...n.paragraph===void 0?{}:{paragraph:n.paragraph},animations:[n]})}return[...e.values()]}
|