dknowc-dsh 1.0.4 → 1.1.1
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/README.md +9 -4
- package/package.json +2 -2
- package/skills/dknowc-ppt-assistant/README.md +54 -0
- package/skills/dknowc-ppt-assistant/SKILL.md +151 -0
- package/skills/dknowc-ppt-assistant/THIRD_PARTY_NOTICES.md +36 -0
- package/skills/dknowc-ppt-assistant/official-docs/output/.gitkeep +0 -0
- package/skills/dknowc-ppt-assistant/official-docs/search-results/.gitkeep +0 -0
- package/skills/dknowc-ppt-assistant/projects/.gitkeep +0 -0
- package/skills/dknowc-ppt-assistant/references/content-pack.md +55 -0
- package/skills/dknowc-ppt-assistant/references/material_usage.md +51 -0
- package/skills/dknowc-ppt-assistant/references/sample_effect.html +89 -0
- package/skills/dknowc-ppt-assistant/references/sample_search_result.md +48 -0
- package/skills/dknowc-ppt-assistant/references/search_intro.md +79 -0
- package/skills/dknowc-ppt-assistant/references/style-presets.md +126 -0
- package/skills/dknowc-ppt-assistant/references/svg-authoring.md +81 -0
- package/skills/dknowc-ppt-assistant/references/upstream-docs/svg-pipeline.md +842 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/01_cover.svg +28 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/02_quote.svg +38 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/03_origin.svg +96 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/README.md +15 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/design_spec.md +408 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/spec_lock.md +78 -0
- package/skills/dknowc-ppt-assistant/scripts/adapt_mcp_result.py +279 -0
- package/skills/dknowc-ppt-assistant/scripts/check_release.py +106 -0
- package/skills/dknowc-ppt-assistant/scripts/compact_svg_coordinates.py +345 -0
- package/skills/dknowc-ppt-assistant/scripts/config.py +707 -0
- package/skills/dknowc-ppt-assistant/scripts/console_encoding.py +33 -0
- package/skills/dknowc-ppt-assistant/scripts/error_helper.py +434 -0
- package/skills/dknowc-ppt-assistant/scripts/finalize_svg.py +507 -0
- package/skills/dknowc-ppt-assistant/scripts/hyperlink_contract.py +399 -0
- package/skills/dknowc-ppt-assistant/scripts/initialize.py +182 -0
- package/skills/dknowc-ppt-assistant/scripts/language_tags.py +283 -0
- package/skills/dknowc-ppt-assistant/scripts/mcp_direct.py +158 -0
- package/skills/dknowc-ppt-assistant/scripts/native_payloads.py +655 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_animation_presets.json +3440 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_animations.py +3965 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_effects.py +143 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_opc_validation.py +346 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/__init__.py +130 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/LICENSE-APACHE-2.0.txt +202 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/LICENSE-OPEN-XML-SDK-MIT.txt +23 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/NOTICE.md +54 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/presetShapeDefinitions.xml +19898 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/presetShapeSemantics.json +1217 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/shape_type_values.txt +187 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/errors.py +39 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/formula.py +336 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/loader.py +364 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/models.py +201 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/registry.py +270 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantic_hash.py +456 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantics.py +543 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/xml_safety.py +21 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/__init__.py +21 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/animation_import.py +287 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/chart_to_svg.py +2377 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/chartex_to_svg.py +422 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/color_resolver.py +894 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/converter.py +1143 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/custgeom_to_svg.py +165 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/effect_to_svg.py +410 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/emu_units.py +258 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/fill_to_svg.py +816 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/formula_import.py +611 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/hyperlinks.py +93 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/import_diagnostics.py +37 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/ln_to_svg.py +362 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/normalized_chart_svg.py +1217 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/ooxml_loader.py +506 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/pic_to_svg.py +653 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_authoring.py +894 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_registry_to_svg.py +216 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_svg_markup.py +198 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/prstgeom_to_svg.py +162 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/shape_walker.py +556 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/slide_to_svg.py +2002 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/tbl_to_svg.py +1841 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/transition_import.py +201 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/txbody_to_svg.py +1433 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_transitions.py +3153 -0
- package/skills/dknowc-ppt-assistant/scripts/preset_shape_svg.py +450 -0
- package/skills/dknowc-ppt-assistant/scripts/project_utils.py +645 -0
- package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +183 -0
- package/skills/dknowc-ppt-assistant/scripts/register_template.py +1327 -0
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +1048 -0
- package/skills/dknowc-ppt-assistant/scripts/resource_paths.py +282 -0
- package/skills/dknowc-ppt-assistant/scripts/shape_boolean_svg.py +189 -0
- package/skills/dknowc-ppt-assistant/scripts/slide_roster.py +44 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/__init__.py +12 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/align_embed_images.py +672 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/crop_images.py +370 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/embed_icons.py +564 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/embed_images.py +288 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/fix_image_aspect.py +389 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/flatten_tspan.py +948 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/svg_rect_to_path.py +346 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/__init__.py +15 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/checker.py +7791 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/cli.py +193 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/svg_contracts.py +1121 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/xml_support.py +35 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality_checker.py +59 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/__init__.py +37 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/animation_config.py +1622 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/canvas_contract.py +226 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/__init__.py +1 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/context.py +291 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/converter.py +1980 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/elements.py +5272 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/hyperlinks.py +162 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/paths.py +847 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/styles.py +752 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/text_properties.py +796 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_colors.py +283 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_fonts.py +330 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/utils.py +3555 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/geometry_properties.py +140 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/__init__.py +356 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_data.py +1449 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_style.py +886 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_xml.py +1495 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chartex.py +272 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/fallback_hash.py +161 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula.py +243 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_ast.py +592 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_compiler.py +96 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_omml.py +1049 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_parser.py +2181 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_profile.py +739 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_run_properties.py +234 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/inline_formula.py +311 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_attributes.py +182 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_common.py +806 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_status.py +190 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/table.py +1113 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/workbook.py +216 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/__init__.py +1 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/builder.py +6273 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/cli.py +2059 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/dimensions.py +189 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/discovery.py +120 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/media.py +160 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/narration.py +696 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/notes.py +336 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/slide_xml.py +138 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_structure.py +3457 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_validation.py +1536 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/semantic_markers.py +240 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/shape_boolean.py +1355 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/text_outline.py +1121 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/tspan_flattener.py +64 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/use_expander.py +577 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx.py +21 -0
- package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +336 -0
- package/skills/dknowc-ppt-assistant/scripts/update_spec.py +404 -0
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +142 -0
- package/skills/dknowc-ppt-assistant/workflows/routing.md +38 -0
- package/skills/dknowc-trusted-search/SKILL.md +8 -7
- package/skills/dknowc-trusted-search/scripts/adapt_mcp_result.py +19 -37
- package/skills/dknowc-trusted-search/scripts/deep_query.py +117 -137
- package/skills/dknowc-trusted-search/scripts/render_trace_html.py +27 -22
- package/src/index.js +7 -2
package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_run_properties.py
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
PPT Master - Native Formula Run Property Merge
|
|
4
|
+
|
|
5
|
+
Merge marker-level DrawingML defaults with compiler-owned local formula style
|
|
6
|
+
without discarding either source.
|
|
7
|
+
|
|
8
|
+
See references/native-formula.md for the owning formula-style contract.
|
|
9
|
+
|
|
10
|
+
Usage:
|
|
11
|
+
Imported by block and inline native formula builders.
|
|
12
|
+
|
|
13
|
+
Examples:
|
|
14
|
+
merge_formula_run_properties(run, marker_properties)
|
|
15
|
+
|
|
16
|
+
Dependencies:
|
|
17
|
+
None (only uses standard library)
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
from copy import deepcopy
|
|
23
|
+
from xml.etree import ElementTree as ET
|
|
24
|
+
|
|
25
|
+
from .formula_omml import validate_omml_resource_limits
|
|
26
|
+
from .formula_parser import FormulaCompileError
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
DML_NS = "http://schemas.openxmlformats.org/drawingml/2006/main"
|
|
30
|
+
MATH_NS = "http://schemas.openxmlformats.org/officeDocument/2006/math"
|
|
31
|
+
|
|
32
|
+
_DML_RUN_PROPERTIES = f"{{{DML_NS}}}rPr"
|
|
33
|
+
_MATH_RUN_PROPERTIES = f"{{{MATH_NS}}}rPr"
|
|
34
|
+
_MATH_CONTROL_PROPERTIES = f"{{{MATH_NS}}}ctrlPr"
|
|
35
|
+
_CONTROL_OWNER_TAGS = frozenset({
|
|
36
|
+
f"{{{MATH_NS}}}{name}"
|
|
37
|
+
for name in (
|
|
38
|
+
"accPr",
|
|
39
|
+
"barPr",
|
|
40
|
+
"borderBoxPr",
|
|
41
|
+
"boxPr",
|
|
42
|
+
"dPr",
|
|
43
|
+
"fPr",
|
|
44
|
+
"groupChrPr",
|
|
45
|
+
"naryPr",
|
|
46
|
+
"radPr",
|
|
47
|
+
)
|
|
48
|
+
})
|
|
49
|
+
_FILL_TAGS = frozenset({
|
|
50
|
+
f"{{{DML_NS}}}blipFill",
|
|
51
|
+
f"{{{DML_NS}}}gradFill",
|
|
52
|
+
f"{{{DML_NS}}}grpFill",
|
|
53
|
+
f"{{{DML_NS}}}noFill",
|
|
54
|
+
f"{{{DML_NS}}}pattFill",
|
|
55
|
+
f"{{{DML_NS}}}solidFill",
|
|
56
|
+
})
|
|
57
|
+
_COLOR_TAGS = frozenset({
|
|
58
|
+
f"{{{DML_NS}}}{name}"
|
|
59
|
+
for name in ("hslClr", "prstClr", "schemeClr", "scrgbClr", "srgbClr", "sysClr")
|
|
60
|
+
})
|
|
61
|
+
_ALPHA_TRANSFORM_TAGS = frozenset({
|
|
62
|
+
f"{{{DML_NS}}}{name}"
|
|
63
|
+
for name in ("alpha", "alphaMod", "alphaOff")
|
|
64
|
+
})
|
|
65
|
+
_RUN_PROPERTY_ORDER = {
|
|
66
|
+
f"{{{DML_NS}}}{name}": index
|
|
67
|
+
for index, names in enumerate((
|
|
68
|
+
("ln",),
|
|
69
|
+
("blipFill", "gradFill", "grpFill", "noFill", "pattFill", "solidFill"),
|
|
70
|
+
("effectDag", "effectLst"),
|
|
71
|
+
("highlight",),
|
|
72
|
+
("uLnTx",),
|
|
73
|
+
("uLn",),
|
|
74
|
+
("uFillTx",),
|
|
75
|
+
("uFill",),
|
|
76
|
+
("latin",),
|
|
77
|
+
("ea",),
|
|
78
|
+
("cs",),
|
|
79
|
+
("sym",),
|
|
80
|
+
("hlinkClick",),
|
|
81
|
+
("hlinkMouseOver",),
|
|
82
|
+
("rtl",),
|
|
83
|
+
("extLst",),
|
|
84
|
+
))
|
|
85
|
+
for name in names
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _replace_child_group(
|
|
90
|
+
target: ET.Element,
|
|
91
|
+
local: ET.Element,
|
|
92
|
+
tags: frozenset[str],
|
|
93
|
+
) -> None:
|
|
94
|
+
local_children = [child for child in local if child.tag in tags]
|
|
95
|
+
if not local_children:
|
|
96
|
+
return
|
|
97
|
+
positions = [index for index, child in enumerate(target) if child.tag in tags]
|
|
98
|
+
insert_at = positions[0] if positions else 0
|
|
99
|
+
for child in list(target):
|
|
100
|
+
if child.tag in tags:
|
|
101
|
+
target.remove(child)
|
|
102
|
+
for offset, child in enumerate(local_children):
|
|
103
|
+
target.insert(insert_at + offset, deepcopy(child))
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _inherit_default_fill_alpha(
|
|
107
|
+
default_properties: ET.Element,
|
|
108
|
+
local_properties: ET.Element,
|
|
109
|
+
) -> None:
|
|
110
|
+
default_fill = next(
|
|
111
|
+
(child for child in default_properties if child.tag in _FILL_TAGS),
|
|
112
|
+
None,
|
|
113
|
+
)
|
|
114
|
+
local_fill = next(
|
|
115
|
+
(child for child in local_properties if child.tag in _FILL_TAGS),
|
|
116
|
+
None,
|
|
117
|
+
)
|
|
118
|
+
if default_fill is None or local_fill is None:
|
|
119
|
+
return
|
|
120
|
+
default_color = next(
|
|
121
|
+
(child for child in default_fill if child.tag in _COLOR_TAGS),
|
|
122
|
+
None,
|
|
123
|
+
)
|
|
124
|
+
local_color = next(
|
|
125
|
+
(child for child in local_fill if child.tag in _COLOR_TAGS),
|
|
126
|
+
None,
|
|
127
|
+
)
|
|
128
|
+
if default_color is None or local_color is None:
|
|
129
|
+
return
|
|
130
|
+
if any(child.tag in _ALPHA_TRANSFORM_TAGS for child in local_color):
|
|
131
|
+
return
|
|
132
|
+
for child in default_color:
|
|
133
|
+
if child.tag in _ALPHA_TRANSFORM_TAGS:
|
|
134
|
+
local_color.append(deepcopy(child))
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _normalize_child_order(properties: ET.Element) -> None:
|
|
138
|
+
children = list(properties)
|
|
139
|
+
ordered = sorted(
|
|
140
|
+
enumerate(children),
|
|
141
|
+
key=lambda item: (
|
|
142
|
+
_RUN_PROPERTY_ORDER.get(item[1].tag, len(_RUN_PROPERTY_ORDER)),
|
|
143
|
+
item[0],
|
|
144
|
+
),
|
|
145
|
+
)
|
|
146
|
+
if [child for _, child in ordered] == children:
|
|
147
|
+
return
|
|
148
|
+
for child in children:
|
|
149
|
+
properties.remove(child)
|
|
150
|
+
for _, child in ordered:
|
|
151
|
+
properties.append(child)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _merged_properties(
|
|
155
|
+
default_properties: ET.Element,
|
|
156
|
+
local_properties: ET.Element | None,
|
|
157
|
+
) -> ET.Element:
|
|
158
|
+
merged = deepcopy(default_properties)
|
|
159
|
+
if local_properties is None:
|
|
160
|
+
_normalize_child_order(merged)
|
|
161
|
+
return merged
|
|
162
|
+
local = deepcopy(local_properties)
|
|
163
|
+
_inherit_default_fill_alpha(merged, local)
|
|
164
|
+
merged.attrib.update(local.attrib)
|
|
165
|
+
_replace_child_group(merged, local, _FILL_TAGS)
|
|
166
|
+
for child in local:
|
|
167
|
+
if child.tag in _FILL_TAGS:
|
|
168
|
+
continue
|
|
169
|
+
for existing in list(merged):
|
|
170
|
+
if existing.tag == child.tag:
|
|
171
|
+
merged.remove(existing)
|
|
172
|
+
merged.append(deepcopy(child))
|
|
173
|
+
_normalize_child_order(merged)
|
|
174
|
+
return merged
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def merge_formula_run_properties(
|
|
178
|
+
run: ET.Element,
|
|
179
|
+
default_properties: ET.Element,
|
|
180
|
+
) -> None:
|
|
181
|
+
"""Merge one formula run's local a:rPr over marker-level defaults."""
|
|
182
|
+
if default_properties.tag != _DML_RUN_PROPERTIES:
|
|
183
|
+
raise RuntimeError("Formula run defaults must use one a:rPr root")
|
|
184
|
+
local_properties = next(
|
|
185
|
+
(child for child in run if child.tag == _DML_RUN_PROPERTIES),
|
|
186
|
+
None,
|
|
187
|
+
)
|
|
188
|
+
merged = _merged_properties(default_properties, local_properties)
|
|
189
|
+
if local_properties is not None:
|
|
190
|
+
run.remove(local_properties)
|
|
191
|
+
insert_at = 1 if len(run) and run[0].tag == _MATH_RUN_PROPERTIES else 0
|
|
192
|
+
run.insert(insert_at, merged)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def merge_formula_control_properties(
|
|
196
|
+
root: ET.Element,
|
|
197
|
+
default_properties: ET.Element,
|
|
198
|
+
) -> None:
|
|
199
|
+
"""Merge marker defaults onto visible non-selectable math controls."""
|
|
200
|
+
if default_properties.tag != _DML_RUN_PROPERTIES:
|
|
201
|
+
raise RuntimeError("Formula control defaults must use one a:rPr root")
|
|
202
|
+
for owner in root.iter():
|
|
203
|
+
if owner.tag not in _CONTROL_OWNER_TAGS:
|
|
204
|
+
continue
|
|
205
|
+
control = next(
|
|
206
|
+
(child for child in owner if child.tag == _MATH_CONTROL_PROPERTIES),
|
|
207
|
+
None,
|
|
208
|
+
)
|
|
209
|
+
if control is None:
|
|
210
|
+
control = ET.SubElement(owner, _MATH_CONTROL_PROPERTIES)
|
|
211
|
+
local_properties = next(
|
|
212
|
+
(child for child in control if child.tag == _DML_RUN_PROPERTIES),
|
|
213
|
+
None,
|
|
214
|
+
)
|
|
215
|
+
merged = _merged_properties(default_properties, local_properties)
|
|
216
|
+
if local_properties is not None:
|
|
217
|
+
control.remove(local_properties)
|
|
218
|
+
control.insert(0, merged)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def serialize_styled_formula_omml(root: ET.Element) -> str:
|
|
222
|
+
"""Serialize styled OMML under the compiler's final size and depth limits."""
|
|
223
|
+
try:
|
|
224
|
+
xml = ET.tostring(root, encoding="unicode", short_empty_elements=True)
|
|
225
|
+
return validate_omml_resource_limits(xml)
|
|
226
|
+
except (FormulaCompileError, RecursionError) as exc:
|
|
227
|
+
raise RuntimeError(f"Invalid styled formula OMML: {exc}") from exc
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
__all__ = [
|
|
231
|
+
"merge_formula_control_properties",
|
|
232
|
+
"merge_formula_run_properties",
|
|
233
|
+
"serialize_styled_formula_omml",
|
|
234
|
+
]
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
PPT Master - Native Inline Formula Contract
|
|
4
|
+
|
|
5
|
+
Validate SVG inline-formula markers and build editable PowerPoint math runs.
|
|
6
|
+
|
|
7
|
+
See references/native-formula.md for the owning inline-formula contract.
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
Imported by the SVG quality checker and SVG-to-PPTX text converter.
|
|
11
|
+
|
|
12
|
+
Examples:
|
|
13
|
+
<tspan data-pptx-inline-formula="x_i^2">xᵢ²</tspan>
|
|
14
|
+
|
|
15
|
+
Dependencies:
|
|
16
|
+
None (only uses standard library and local PPT Master modules)
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from xml.etree import ElementTree as ET
|
|
22
|
+
|
|
23
|
+
from ..drawingml.utils import parse_inline_style, parse_svg_color
|
|
24
|
+
from .formula_compiler import (
|
|
25
|
+
FormulaCompileError,
|
|
26
|
+
compile_latex_to_inline_omml,
|
|
27
|
+
)
|
|
28
|
+
from .formula_run_properties import (
|
|
29
|
+
merge_formula_control_properties,
|
|
30
|
+
merge_formula_run_properties,
|
|
31
|
+
serialize_styled_formula_omml,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
SVG_NS = "http://www.w3.org/2000/svg"
|
|
36
|
+
DML_NS = "http://schemas.openxmlformats.org/drawingml/2006/main"
|
|
37
|
+
OFFICE_REL_NS = (
|
|
38
|
+
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"
|
|
39
|
+
)
|
|
40
|
+
MATH_NS = "http://schemas.openxmlformats.org/officeDocument/2006/math"
|
|
41
|
+
A14_NS = "http://schemas.microsoft.com/office/drawing/2010/main"
|
|
42
|
+
MC_NS = "http://schemas.openxmlformats.org/markup-compatibility/2006"
|
|
43
|
+
INLINE_FORMULA_ATTR = "data-pptx-inline-formula"
|
|
44
|
+
_SVG_TEXT = f"{{{SVG_NS}}}text"
|
|
45
|
+
_SVG_TSPAN = f"{{{SVG_NS}}}tspan"
|
|
46
|
+
_SVG_A = f"{{{SVG_NS}}}a"
|
|
47
|
+
_MATH_RUN = f"{{{MATH_NS}}}r"
|
|
48
|
+
_DML_RUN_PROPERTIES = f"{{{DML_NS}}}rPr"
|
|
49
|
+
_POSITION_ATTRIBUTES = ("x", "y", "dx", "dy")
|
|
50
|
+
_PARAGRAPH_ATTRIBUTES = (
|
|
51
|
+
"data-paragraph-line-height",
|
|
52
|
+
"data-paragraph-line-break",
|
|
53
|
+
"data-paragraph-soft-break",
|
|
54
|
+
"data-paragraph-space-before",
|
|
55
|
+
)
|
|
56
|
+
_NON_OUTPUT_ANCESTORS = frozenset({
|
|
57
|
+
"clipPath",
|
|
58
|
+
"desc",
|
|
59
|
+
"defs",
|
|
60
|
+
"filter",
|
|
61
|
+
"linearGradient",
|
|
62
|
+
"marker",
|
|
63
|
+
"mask",
|
|
64
|
+
"metadata",
|
|
65
|
+
"pattern",
|
|
66
|
+
"radialGradient",
|
|
67
|
+
"style",
|
|
68
|
+
"symbol",
|
|
69
|
+
"title",
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
for _prefix, _uri in (("a", DML_NS), ("m", MATH_NS)):
|
|
73
|
+
try:
|
|
74
|
+
ET.register_namespace(_prefix, _uri)
|
|
75
|
+
except (ValueError, AttributeError):
|
|
76
|
+
pass
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _marker_label(elem: ET.Element) -> str:
|
|
80
|
+
elem_id = (elem.get("id") or "").strip()
|
|
81
|
+
return f"<tspan id={elem_id!r}>" if elem_id else "<tspan>"
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def inline_formula_marker_errors(root: ET.Element) -> list[str]:
|
|
85
|
+
"""Return strict authoring errors for every inline-formula marker."""
|
|
86
|
+
errors: list[str] = []
|
|
87
|
+
parent_map = {child: parent for parent in root.iter() for child in parent}
|
|
88
|
+
markers = [
|
|
89
|
+
elem for elem in root.iter()
|
|
90
|
+
if elem.get(INLINE_FORMULA_ATTR) is not None
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
for marker in markers:
|
|
94
|
+
label = _marker_label(marker)
|
|
95
|
+
if marker.tag != _SVG_TSPAN:
|
|
96
|
+
tag = marker.tag.rsplit("}", 1)[-1]
|
|
97
|
+
errors.append(
|
|
98
|
+
f"{INLINE_FORMULA_ATTR} is only valid on <tspan>, found <{tag}>"
|
|
99
|
+
)
|
|
100
|
+
continue
|
|
101
|
+
|
|
102
|
+
if marker.get("data-pptx-replace-with") is not None:
|
|
103
|
+
errors.append(
|
|
104
|
+
f"{label} cannot also declare data-pptx-replace-with"
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
source = marker.get(INLINE_FORMULA_ATTR) or ""
|
|
108
|
+
if not source.strip():
|
|
109
|
+
errors.append(f"{label} requires non-empty {INLINE_FORMULA_ATTR}")
|
|
110
|
+
else:
|
|
111
|
+
try:
|
|
112
|
+
compile_latex_to_inline_omml(source)
|
|
113
|
+
except FormulaCompileError as exc:
|
|
114
|
+
errors.append(f"{label} has unsupported inline LaTeX: {exc}")
|
|
115
|
+
|
|
116
|
+
if list(marker):
|
|
117
|
+
errors.append(
|
|
118
|
+
f"{label} must contain preview text directly and cannot nest elements"
|
|
119
|
+
)
|
|
120
|
+
if not (marker.text or "").strip():
|
|
121
|
+
errors.append(f"{label} requires non-empty visible SVG preview text")
|
|
122
|
+
elif marker.text != marker.text.strip():
|
|
123
|
+
errors.append(
|
|
124
|
+
f"{label} preview cannot contain leading or trailing whitespace; "
|
|
125
|
+
"place spacing in the surrounding text"
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
positioned = [name for name in _POSITION_ATTRIBUTES if marker.get(name) is not None]
|
|
129
|
+
if positioned:
|
|
130
|
+
errors.append(
|
|
131
|
+
f"{label} is an inline run and cannot set " + ", ".join(positioned)
|
|
132
|
+
)
|
|
133
|
+
paragraph_attrs = [
|
|
134
|
+
name for name in _PARAGRAPH_ATTRIBUTES
|
|
135
|
+
if marker.get(name) is not None
|
|
136
|
+
]
|
|
137
|
+
if paragraph_attrs:
|
|
138
|
+
errors.append(
|
|
139
|
+
f"{label} cannot own paragraph layout metadata: "
|
|
140
|
+
+ ", ".join(paragraph_attrs)
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
effective_fill: str | None = None
|
|
144
|
+
style_owner: ET.Element | None = marker
|
|
145
|
+
while style_owner is not None:
|
|
146
|
+
inline_style = parse_inline_style(style_owner.get("style"))
|
|
147
|
+
effective_fill = inline_style.get("fill")
|
|
148
|
+
if effective_fill is None:
|
|
149
|
+
effective_fill = style_owner.get("fill")
|
|
150
|
+
if effective_fill is not None:
|
|
151
|
+
break
|
|
152
|
+
style_owner = parent_map.get(style_owner)
|
|
153
|
+
color, alpha = parse_svg_color(effective_fill or "#000000")
|
|
154
|
+
if color is None or alpha <= 0:
|
|
155
|
+
errors.append(
|
|
156
|
+
f"{label} requires one visible solid fill color inherited "
|
|
157
|
+
"from itself or its text ancestors"
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
parent = parent_map.get(marker)
|
|
161
|
+
text_owner: ET.Element | None = None
|
|
162
|
+
nested_marker = False
|
|
163
|
+
inside_block_formula = False
|
|
164
|
+
inside_native_replacement = False
|
|
165
|
+
inside_preserved_text = False
|
|
166
|
+
inside_placeholder = False
|
|
167
|
+
inside_skipped_transport = False
|
|
168
|
+
inside_baseline_shift = marker.get("baseline-shift") is not None
|
|
169
|
+
invalid_inline_container: str | None = None
|
|
170
|
+
non_output_ancestor: str | None = None
|
|
171
|
+
fixed_structure_layer: str | None = None
|
|
172
|
+
while parent is not None:
|
|
173
|
+
parent_tag = parent.tag.rsplit("}", 1)[-1]
|
|
174
|
+
if text_owner is None and parent.tag == _SVG_TEXT:
|
|
175
|
+
text_owner = parent
|
|
176
|
+
elif (
|
|
177
|
+
text_owner is None
|
|
178
|
+
and parent.tag not in {_SVG_A, _SVG_TSPAN}
|
|
179
|
+
and invalid_inline_container is None
|
|
180
|
+
):
|
|
181
|
+
invalid_inline_container = parent_tag
|
|
182
|
+
if parent_tag in _NON_OUTPUT_ANCESTORS:
|
|
183
|
+
non_output_ancestor = parent_tag
|
|
184
|
+
if parent.get(INLINE_FORMULA_ATTR) is not None:
|
|
185
|
+
nested_marker = True
|
|
186
|
+
if parent.get("baseline-shift") is not None:
|
|
187
|
+
inside_baseline_shift = True
|
|
188
|
+
replacement = (
|
|
189
|
+
parent.get("data-pptx-replace-with") or ""
|
|
190
|
+
).strip().lower()
|
|
191
|
+
if replacement:
|
|
192
|
+
inside_native_replacement = True
|
|
193
|
+
inside_block_formula = (
|
|
194
|
+
inside_block_formula or replacement == "formula"
|
|
195
|
+
)
|
|
196
|
+
if (parent.get("data-pptx-part") or "").strip() in {
|
|
197
|
+
"geometry-detail",
|
|
198
|
+
"geometry-preview",
|
|
199
|
+
}:
|
|
200
|
+
inside_skipped_transport = True
|
|
201
|
+
if parent.get("data-pptx-placeholder") is not None:
|
|
202
|
+
inside_placeholder = True
|
|
203
|
+
layer = (parent.get("data-pptx-layer") or "").strip().lower()
|
|
204
|
+
if layer in {"master", "layout"}:
|
|
205
|
+
fixed_structure_layer = layer
|
|
206
|
+
if any(
|
|
207
|
+
child.tag.rsplit("}", 1)[-1] == "metadata"
|
|
208
|
+
and child.get("data-pptx-part") == "txbody"
|
|
209
|
+
for child in parent
|
|
210
|
+
):
|
|
211
|
+
inside_preserved_text = True
|
|
212
|
+
parent = parent_map.get(parent)
|
|
213
|
+
if text_owner is None:
|
|
214
|
+
errors.append(f"{label} must be inside an SVG <text> element")
|
|
215
|
+
elif invalid_inline_container is not None:
|
|
216
|
+
errors.append(
|
|
217
|
+
f"{label} can only be nested through <tspan>/<a> elements before "
|
|
218
|
+
f"its owning <text>, found <{invalid_inline_container}>"
|
|
219
|
+
)
|
|
220
|
+
if non_output_ancestor is not None:
|
|
221
|
+
errors.append(
|
|
222
|
+
f"{label} cannot be placed inside non-output "
|
|
223
|
+
f"<{non_output_ancestor}> content"
|
|
224
|
+
)
|
|
225
|
+
if nested_marker:
|
|
226
|
+
errors.append(f"{label} cannot be nested inside another inline formula marker")
|
|
227
|
+
if inside_baseline_shift:
|
|
228
|
+
errors.append(
|
|
229
|
+
f"{label} cannot combine baseline-shift with an inline formula"
|
|
230
|
+
)
|
|
231
|
+
if inside_block_formula:
|
|
232
|
+
errors.append(
|
|
233
|
+
f"{label} cannot be placed inside a block formula preview"
|
|
234
|
+
)
|
|
235
|
+
elif inside_native_replacement:
|
|
236
|
+
errors.append(
|
|
237
|
+
f"{label} cannot be placed inside a native replacement subtree"
|
|
238
|
+
)
|
|
239
|
+
if inside_skipped_transport:
|
|
240
|
+
errors.append(
|
|
241
|
+
f"{label} cannot be placed inside non-output geometry transport"
|
|
242
|
+
)
|
|
243
|
+
if inside_preserved_text:
|
|
244
|
+
errors.append(
|
|
245
|
+
f"{label} cannot be placed inside an imported preserved txBody group"
|
|
246
|
+
)
|
|
247
|
+
if inside_placeholder:
|
|
248
|
+
errors.append(
|
|
249
|
+
f"{label} cannot be used inside a structured Layout placeholder"
|
|
250
|
+
)
|
|
251
|
+
if fixed_structure_layer is not None:
|
|
252
|
+
errors.append(
|
|
253
|
+
f"{label} cannot be used on the {fixed_structure_layer} layer; "
|
|
254
|
+
"inline formulas are slide-local text"
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
return errors
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def _apply_run_properties(omml: str, run_properties_xml: str) -> str:
|
|
261
|
+
"""Merge DrawingML defaults onto every Office Math leaf run."""
|
|
262
|
+
try:
|
|
263
|
+
root = ET.fromstring(omml)
|
|
264
|
+
wrapper = ET.fromstring(
|
|
265
|
+
f'<root xmlns:a="{DML_NS}" xmlns:r="{OFFICE_REL_NS}">'
|
|
266
|
+
f"{run_properties_xml}</root>"
|
|
267
|
+
)
|
|
268
|
+
except (ET.ParseError, RecursionError) as exc:
|
|
269
|
+
raise RuntimeError(f"Invalid inline formula XML: {exc}") from exc
|
|
270
|
+
if len(wrapper) != 1:
|
|
271
|
+
raise RuntimeError("Inline formula styling must contain one a:rPr root")
|
|
272
|
+
run_properties = wrapper[0]
|
|
273
|
+
if root.tag != f"{{{MATH_NS}}}oMath":
|
|
274
|
+
raise RuntimeError("Inline formula compiler must return one m:oMath root")
|
|
275
|
+
if run_properties.tag != _DML_RUN_PROPERTIES:
|
|
276
|
+
raise RuntimeError("Inline formula styling must use one a:rPr root")
|
|
277
|
+
|
|
278
|
+
for run in root.iter(_MATH_RUN):
|
|
279
|
+
merge_formula_run_properties(run, run_properties)
|
|
280
|
+
merge_formula_control_properties(root, run_properties)
|
|
281
|
+
|
|
282
|
+
return serialize_styled_formula_omml(root)
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def build_inline_formula_xml(latex: str, run_properties_xml: str) -> str:
|
|
286
|
+
"""Build one ``a14:m`` inline math zone for insertion inside ``a:p``."""
|
|
287
|
+
try:
|
|
288
|
+
omml = compile_latex_to_inline_omml(latex)
|
|
289
|
+
except FormulaCompileError as exc:
|
|
290
|
+
raise RuntimeError(f"Unsupported inline formula LaTeX: {exc}") from exc
|
|
291
|
+
styled = _apply_run_properties(omml, run_properties_xml)
|
|
292
|
+
return f"<a14:m>{styled}</a14:m>"
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def wrap_inline_formula_shape(shape_xml: str) -> str:
|
|
296
|
+
"""Wrap a text shape containing ``a14:m`` in its required MCE Choice."""
|
|
297
|
+
return (
|
|
298
|
+
f'<mc:AlternateContent xmlns:mc="{MC_NS}">'
|
|
299
|
+
f'<mc:Choice xmlns:a14="{A14_NS}" Requires="a14">'
|
|
300
|
+
f"{shape_xml}"
|
|
301
|
+
"</mc:Choice>"
|
|
302
|
+
"</mc:AlternateContent>"
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
__all__ = [
|
|
307
|
+
"INLINE_FORMULA_ATTR",
|
|
308
|
+
"build_inline_formula_xml",
|
|
309
|
+
"inline_formula_marker_errors",
|
|
310
|
+
"wrap_inline_formula_shape",
|
|
311
|
+
]
|