@project-ava-supernova/core 0.2.175 → 0.2.177

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.
Files changed (144) hide show
  1. package/dist/agent/agent.d.ts +3 -0
  2. package/dist/agent/agent.d.ts.map +1 -1
  3. package/dist/agent/agent.js +78 -52
  4. package/dist/agent/agent.js.map +1 -1
  5. package/dist/agent/system-prompt.d.ts +3 -2
  6. package/dist/agent/system-prompt.d.ts.map +1 -1
  7. package/dist/agent/system-prompt.js +1356 -1308
  8. package/dist/agent/system-prompt.js.map +1 -1
  9. package/dist/auto/aurora-router.d.ts +1 -1
  10. package/dist/auto/aurora-router.d.ts.map +1 -1
  11. package/dist/auto/aurora-router.js +4 -1
  12. package/dist/auto/aurora-router.js.map +1 -1
  13. package/dist/auto/auto-coordinator.d.ts.map +1 -1
  14. package/dist/auto/auto-coordinator.js +2 -1
  15. package/dist/auto/auto-coordinator.js.map +1 -1
  16. package/dist/auto/longxiang-router.d.ts.map +1 -1
  17. package/dist/auto/longxiang-router.js +1 -0
  18. package/dist/auto/longxiang-router.js.map +1 -1
  19. package/dist/auto/model-router.d.ts.map +1 -1
  20. package/dist/auto/model-router.js +1 -0
  21. package/dist/auto/model-router.js.map +1 -1
  22. package/dist/auto/supernova-router.d.ts.map +1 -1
  23. package/dist/auto/supernova-router.js +3 -0
  24. package/dist/auto/supernova-router.js.map +1 -1
  25. package/dist/auto/task-classifier.d.ts.map +1 -1
  26. package/dist/auto/task-classifier.js +8 -1
  27. package/dist/auto/task-classifier.js.map +1 -1
  28. package/dist/auto/types.d.ts +1 -1
  29. package/dist/auto/types.d.ts.map +1 -1
  30. package/dist/brand/brand-kits.d.ts +217 -0
  31. package/dist/brand/brand-kits.d.ts.map +1 -0
  32. package/dist/brand/brand-kits.js +681 -0
  33. package/dist/brand/brand-kits.js.map +1 -0
  34. package/dist/brand/kit-py.d.ts +7 -0
  35. package/dist/brand/kit-py.d.ts.map +1 -0
  36. package/dist/brand/kit-py.js +45 -0
  37. package/dist/brand/kit-py.js.map +1 -0
  38. package/dist/config/schema.d.ts +5 -0
  39. package/dist/config/schema.d.ts.map +1 -1
  40. package/dist/config/schema.js.map +1 -1
  41. package/dist/docs/data/tools.d.ts.map +1 -1
  42. package/dist/docs/data/tools.js +15 -0
  43. package/dist/docs/data/tools.js.map +1 -1
  44. package/dist/index.d.ts +16 -1
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +13 -0
  47. package/dist/index.js.map +1 -1
  48. package/dist/memory/config.d.ts +12 -0
  49. package/dist/memory/config.d.ts.map +1 -1
  50. package/dist/memory/config.js +12 -0
  51. package/dist/memory/config.js.map +1 -1
  52. package/dist/memory/memory-manager.d.ts +11 -0
  53. package/dist/memory/memory-manager.d.ts.map +1 -1
  54. package/dist/memory/memory-manager.js +90 -2
  55. package/dist/memory/memory-manager.js.map +1 -1
  56. package/dist/memory/project-brain.d.ts.map +1 -1
  57. package/dist/memory/project-brain.js +2 -1
  58. package/dist/memory/project-brain.js.map +1 -1
  59. package/dist/memory/tfidf.d.ts +10 -0
  60. package/dist/memory/tfidf.d.ts.map +1 -1
  61. package/dist/memory/tfidf.js +27 -0
  62. package/dist/memory/tfidf.js.map +1 -1
  63. package/dist/social/index.d.ts +48 -0
  64. package/dist/social/index.d.ts.map +1 -1
  65. package/dist/social/index.js +19 -0
  66. package/dist/social/index.js.map +1 -1
  67. package/dist/tools/blender/build-model.d.ts +52 -0
  68. package/dist/tools/blender/build-model.d.ts.map +1 -0
  69. package/dist/tools/blender/build-model.js +426 -0
  70. package/dist/tools/blender/build-model.js.map +1 -0
  71. package/dist/tools/blender/find-blender.d.ts +43 -0
  72. package/dist/tools/blender/find-blender.d.ts.map +1 -0
  73. package/dist/tools/blender/find-blender.js +154 -0
  74. package/dist/tools/blender/find-blender.js.map +1 -0
  75. package/dist/tools/blender/model-brief.d.ts +61 -0
  76. package/dist/tools/blender/model-brief.d.ts.map +1 -0
  77. package/dist/tools/blender/model-brief.js +117 -0
  78. package/dist/tools/blender/model-brief.js.map +1 -0
  79. package/dist/tools/blender/paths.d.ts +20 -0
  80. package/dist/tools/blender/paths.d.ts.map +1 -0
  81. package/dist/tools/blender/paths.js +37 -0
  82. package/dist/tools/blender/paths.js.map +1 -0
  83. package/dist/tools/blender/runner-py.d.ts +2 -0
  84. package/dist/tools/blender/runner-py.d.ts.map +1 -0
  85. package/dist/tools/blender/runner-py.js +442 -0
  86. package/dist/tools/blender/runner-py.js.map +1 -0
  87. package/dist/tools/brief-store.d.ts +25 -0
  88. package/dist/tools/brief-store.d.ts.map +1 -0
  89. package/dist/tools/brief-store.js +59 -0
  90. package/dist/tools/brief-store.js.map +1 -0
  91. package/dist/tools/check-posts.d.ts.map +1 -1
  92. package/dist/tools/check-posts.js +21 -3
  93. package/dist/tools/check-posts.js.map +1 -1
  94. package/dist/tools/design-checkin.d.ts +28 -0
  95. package/dist/tools/design-checkin.d.ts.map +1 -0
  96. package/dist/tools/design-checkin.js +74 -0
  97. package/dist/tools/design-checkin.js.map +1 -0
  98. package/dist/tools/design-docs.d.ts +37 -0
  99. package/dist/tools/design-docs.d.ts.map +1 -0
  100. package/dist/tools/design-docs.js +367 -0
  101. package/dist/tools/design-docs.js.map +1 -0
  102. package/dist/tools/design-fonts.d.ts +54 -0
  103. package/dist/tools/design-fonts.d.ts.map +1 -0
  104. package/dist/tools/design-fonts.js +312 -0
  105. package/dist/tools/design-fonts.js.map +1 -0
  106. package/dist/tools/design-studio-tools.d.ts +16 -0
  107. package/dist/tools/design-studio-tools.d.ts.map +1 -1
  108. package/dist/tools/design-studio-tools.js +288 -43
  109. package/dist/tools/design-studio-tools.js.map +1 -1
  110. package/dist/tools/generation-manager.d.ts +1 -1
  111. package/dist/tools/generation-manager.d.ts.map +1 -1
  112. package/dist/tools/gimp/build-image.d.ts +152 -0
  113. package/dist/tools/gimp/build-image.d.ts.map +1 -0
  114. package/dist/tools/gimp/build-image.js +809 -0
  115. package/dist/tools/gimp/build-image.js.map +1 -0
  116. package/dist/tools/gimp/find-gimp.d.ts +32 -0
  117. package/dist/tools/gimp/find-gimp.d.ts.map +1 -0
  118. package/dist/tools/gimp/find-gimp.js +149 -0
  119. package/dist/tools/gimp/find-gimp.js.map +1 -0
  120. package/dist/tools/gimp/runner-py.d.ts +2 -0
  121. package/dist/tools/gimp/runner-py.d.ts.map +1 -0
  122. package/dist/tools/gimp/runner-py.js +723 -0
  123. package/dist/tools/gimp/runner-py.js.map +1 -0
  124. package/dist/tools/propose-brief.d.ts.map +1 -1
  125. package/dist/tools/propose-brief.js +6 -1
  126. package/dist/tools/propose-brief.js.map +1 -1
  127. package/dist/tools/review-post.d.ts +25 -0
  128. package/dist/tools/review-post.d.ts.map +1 -0
  129. package/dist/tools/review-post.js +63 -0
  130. package/dist/tools/review-post.js.map +1 -0
  131. package/dist/tools/tool-registry.d.ts.map +1 -1
  132. package/dist/tools/tool-registry.js +39 -1
  133. package/dist/tools/tool-registry.js.map +1 -1
  134. package/dist/tools/tool-request-words.d.ts +7 -0
  135. package/dist/tools/tool-request-words.d.ts.map +1 -0
  136. package/dist/tools/tool-request-words.js +39 -0
  137. package/dist/tools/tool-request-words.js.map +1 -0
  138. package/dist/tools/write-post.d.ts.map +1 -1
  139. package/dist/tools/write-post.js +5 -1
  140. package/dist/tools/write-post.js.map +1 -1
  141. package/dist/tools/write-video-post.d.ts.map +1 -1
  142. package/dist/tools/write-video-post.js +6 -1
  143. package/dist/tools/write-video-post.js.map +1 -1
  144. package/package.json +1 -1
@@ -0,0 +1,723 @@
1
+ /**
2
+ * The Python that runs inside GIMP for design_build_image. A string so core
3
+ * stays a single bundle; written to the OS temp folder before each run.
4
+ * Proven on GIMP 3.2.6, 4 Nov 2026: an icon built, reopened and added to, a
5
+ * second image joining the set, and every guard refusal confirmed.
6
+ */
7
+ import { KIT_PY } from '../../brand/kit-py.js';
8
+ // prettier-ignore
9
+ export const GIMP_RUNNER_PY = String.raw `# Ava's GIMP runner. Started by design_build_image as:
10
+ # gimp-console -i --batch-interpreter python-fu-eval -b "exec(open(r'runner.py').read())" --quit
11
+ # with AVA_GIMP_JOB pointing at the job file. It installs the guard, runs Ava's
12
+ # script, then saves every image she touched as .xcf, exports a PNG of each and
13
+ # builds a preview. The last line it prints is the result.
14
+ import sys, os, json, time, traceback, shutil
15
+ import gi
16
+ gi.require_version('Gimp', '3.0')
17
+ gi.require_version('Gegl', '0.4')
18
+ from gi.repository import Gimp, Gegl, Gio
19
+
20
+ JOB = json.load(open(os.environ['AVA_GIMP_JOB'], encoding='utf-8'))
21
+ ASSET_DIR = os.path.realpath(JOB['assetDir'])
22
+ STARTED = time.time()
23
+ result = {'ok': False, 'files': [], 'warnings': [], 'images': [], 'report': [], 'looks': []}
24
+ ${KIT_PY}
25
+
26
+ def emit():
27
+ sys.stdout.write('\n@@AVA_RESULT@@' + json.dumps(result) + '\n')
28
+ sys.stdout.flush()
29
+
30
+ # ── The guard ────────────────────────────────────────────────────────────────
31
+ # Same as Blender's. GIMP's own file plug-ins run in other processes and are
32
+ # not seen here, which is why the tool also refuses absolute paths in the
33
+ # script itself. A guard, not a sandbox.
34
+ _TMP = os.path.join(ASSET_DIR, '.tmp')
35
+ os.makedirs(_TMP, exist_ok=True)
36
+ import tempfile
37
+ tempfile.tempdir = _TMP
38
+ _ALLOWED = [os.path.normcase(ASSET_DIR)]
39
+ def _inside(p):
40
+ try:
41
+ rp = os.path.normcase(os.path.realpath(os.fsdecode(p)))
42
+ except Exception:
43
+ return False
44
+ return any(rp == a or rp.startswith(a.rstrip(os.sep) + os.sep) for a in _ALLOWED)
45
+ _BLOCKED = {
46
+ 'subprocess.Popen': 'starting other programs', 'os.system': 'starting other programs',
47
+ 'os.exec': 'starting other programs', 'os.posix_spawn': 'starting other programs',
48
+ 'os.spawn': 'starting other programs', 'os.startfile': 'opening files in other programs',
49
+ 'os.kill': 'stopping other programs', 'webbrowser.open': 'opening a browser',
50
+ 'socket.connect': 'network access', 'socket.bind': 'network access',
51
+ 'socket.getaddrinfo': 'network access', 'socket.gethostbyname': 'network access',
52
+ 'urllib.Request': 'network access', 'ctypes.dlopen': 'loading native code',
53
+ 'ctypes.dlsym': 'calling native code', 'ctypes.call_function': 'calling native code',
54
+ 'winreg.CreateKey': 'changing the registry', 'winreg.SetValue': 'changing the registry',
55
+ 'winreg.DeleteKey': 'changing the registry', 'winreg.DeleteValue': 'changing the registry',
56
+ }
57
+ _WRITE_ARGS = {
58
+ 'os.remove': (0,), 'os.rmdir': (0,), 'os.mkdir': (0,), 'os.chmod': (0,),
59
+ 'os.truncate': (0,), 'os.utime': (0,), 'shutil.rmtree': (0,),
60
+ 'os.rename': (0, 1), 'shutil.move': (0, 1), 'shutil.copyfile': (1,),
61
+ 'shutil.copytree': (1,), 'os.symlink': (1,), 'os.link': (1,),
62
+ }
63
+ _WRITE_FLAGS = os.O_WRONLY | os.O_RDWR | os.O_CREAT | os.O_APPEND | os.O_TRUNC
64
+ def _refuse(why):
65
+ raise PermissionError(f'Blocked by the Design Studio guard: {why}. '
66
+ f'Scripts here may only make the image and write inside its own folder (ASSET_DIR).')
67
+ def _hook(event, args):
68
+ if event in _BLOCKED:
69
+ _refuse(_BLOCKED[event])
70
+ if event == 'open':
71
+ path, mode, flags = (list(args) + [None, None, 0])[:3]
72
+ if path is None or isinstance(path, int):
73
+ return
74
+ writing = (isinstance(mode, str) and any(c in mode for c in 'wax+')) or \
75
+ (mode is None and isinstance(flags, int) and flags & _WRITE_FLAGS)
76
+ if writing and not _inside(path):
77
+ _refuse(f'writing outside the folder ({os.fsdecode(path)})')
78
+ elif event in _WRITE_ARGS:
79
+ for i in _WRITE_ARGS[event]:
80
+ if i < len(args) and args[i] is not None and not isinstance(args[i], int) and not _inside(args[i]):
81
+ _refuse(f'changing files outside the folder ({os.fsdecode(args[i])})')
82
+
83
+ # ── Helpers ──────────────────────────────────────────────────────────────────
84
+ _open = {} # name -> Gimp.Image she touched this run
85
+
86
+ def _file(path):
87
+ return Gio.File.new_for_path(path)
88
+
89
+ def _safe_name(name):
90
+ n = ''.join(c if c.isalnum() or c in '-_' else '-' for c in str(name))
91
+ while '--' in n:
92
+ n = n.replace('--', '-')
93
+ n = n.strip('-')
94
+ if not n:
95
+ raise ValueError('an image needs a name')
96
+ return n
97
+
98
+ def ava_image(name=None, width=1024, height=1024):
99
+ """The image called 'name' in this piece of work: opens its saved .xcf —
100
+ including anything the person changed by hand in GIMP — or makes a new
101
+ transparent one the first time. With no name, the work's only image, or the
102
+ one named after the work. Call once per image; a set is several names.
103
+ Everything you touch is saved and exported after your script. Each run is a
104
+ new GIMP: this is the only way to reach saved work."""
105
+ saved = sorted(f[:-4] for f in os.listdir(ASSET_DIR) if f.endswith('.xcf'))
106
+ if name is None:
107
+ name = saved[0] if len(saved) == 1 else JOB.get('name') or 'image'
108
+ name = _safe_name(name)
109
+ if name in _open:
110
+ return _open[name]
111
+ # One piece of work splitting into two files cost her eight runs: a name
112
+ # that differs only in case or punctuation is the same image.
113
+ same = [s for s in saved if s.lower().replace('-', '') == name.lower().replace('-', '')]
114
+ if same:
115
+ name = same[0]
116
+ if name in _open:
117
+ return _open[name]
118
+ xcf = os.path.join(ASSET_DIR, name + '.xcf')
119
+ if os.path.exists(xcf):
120
+ img = Gimp.file_load(Gimp.RunMode.NONINTERACTIVE, _file(xcf))
121
+ else:
122
+ img = Gimp.Image.new(width, height, Gimp.ImageBaseType.RGB)
123
+ if saved:
124
+ result['warnings'].append(f'ava_image("{name}") started a NEW image. This work already has: {saved}. If this is a new piece of the set, carry on; if you meant one of those, use its exact name.')
125
+ _open[name] = img
126
+ return img
127
+
128
+ def ava_layer(image, name='Layer', fill=None):
129
+ """A new transparent layer the size of the image, on top. fill = a colour
130
+ like '#f0a24b' floods it."""
131
+ w, h = image.get_width(), image.get_height()
132
+ lay = Gimp.Layer.new(image, name, w, h, Gimp.ImageType.RGBA_IMAGE, 100, Gimp.LayerMode.NORMAL)
133
+ image.insert_layer(lay, None, 0)
134
+ if fill:
135
+ Gimp.context_set_foreground(Gegl.Color.new(fill))
136
+ lay.fill(Gimp.FillType.FOREGROUND)
137
+ return lay
138
+
139
+ def ava_place(image, path, name=None):
140
+ """Bring an image file into 'image' as a new layer — a Blender render, a
141
+ generated reference, another piece of the set. 'path' inside ASSET_DIR."""
142
+ full = path if os.path.isabs(path) else os.path.join(ASSET_DIR, path)
143
+ lay = Gimp.file_load_layer(Gimp.RunMode.NONINTERACTIVE, image, _file(full))
144
+ if name:
145
+ lay.set_name(name)
146
+ image.insert_layer(lay, None, 0)
147
+ return lay
148
+
149
+ def ava_filter(layer, op, **props):
150
+ """Run a GEGL filter on a layer and keep the result, e.g.
151
+ ava_filter(lay, 'gegl:dropshadow', x=4.0, y=4.0, radius=8.0).
152
+ Underscores in names become dashes."""
153
+ f = Gimp.DrawableFilter.new(layer, op, '')
154
+ cfg = f.get_config()
155
+ for k, v in props.items():
156
+ k = k.replace('_', '-')
157
+ if isinstance(v, str) and v.startswith('#'):
158
+ v = Gegl.Color.new(v)
159
+ cfg.set_property(k, v)
160
+ f.update()
161
+ layer.merge_filter(f)
162
+ return layer
163
+
164
+ def ava_export(image, filename, size=None):
165
+ """Export a flattened copy into ASSET_DIR/exports — size=(w, h) for an
166
+ exact size; PNG keeps transparency. The layered source is untouched."""
167
+ out = os.path.join(ASSET_DIR, 'exports')
168
+ os.makedirs(out, exist_ok=True)
169
+ _visible(image)
170
+ copy = image.duplicate()
171
+ copy.merge_visible_layers(Gimp.MergeType.CLIP_TO_IMAGE)
172
+ if size:
173
+ copy.scale(int(size[0]), int(size[1]))
174
+ Gimp.file_save(Gimp.RunMode.NONINTERACTIVE, copy, _file(os.path.join(out, filename)), None)
175
+ copy.delete()
176
+ print(f'AVA_EXPORT: exports/{filename}')
177
+ return 'exports/' + filename
178
+
179
+
180
+ _new_finals = []
181
+
182
+ def ava_final(image, filename, size=None):
183
+ """Make a finished file: the real thing, not a test. It goes in final/, shows
184
+ on the stage and in the Library, and is what brand kits offer. Use it when
185
+ the piece is done and they are happy. A run that fails adds nothing."""
186
+ _visible(image)
187
+ out = os.path.join(ASSET_DIR, 'final')
188
+ os.makedirs(out, exist_ok=True)
189
+ copy = image.duplicate()
190
+ copy.merge_visible_layers(Gimp.MergeType.CLIP_TO_IMAGE)
191
+ if size:
192
+ copy.scale(int(size[0]), int(size[1]))
193
+ Gimp.file_save(Gimp.RunMode.NONINTERACTIVE, copy, _file(os.path.join(out, filename)), None)
194
+ copy.delete()
195
+ _new_finals.append('final/' + filename)
196
+ print(f'AVA_FINAL: final/{filename}')
197
+ return 'final/' + filename
198
+
199
+
200
+ # ── Drawing helpers ──────────────────────────────────────────────────────────
201
+ # Her first logo lost 5 of 11 runs to GIMP 2 habits: a tuple where 3.2 wants
202
+ # separate numbers, Image.select_all, ChannelOps.ADD_EXCLUDE, layer.name. These
203
+ # are the verified 3.2 calls behind one shape vocabulary, so a step spends its
204
+ # run on the design and not on the API (4 Nov 2026).
205
+ Gimp.context_set_antialias(True)
206
+
207
+ _OPS = {'replace': Gimp.ChannelOps.REPLACE, 'add': Gimp.ChannelOps.ADD,
208
+ 'subtract': Gimp.ChannelOps.SUBTRACT, 'intersect': Gimp.ChannelOps.INTERSECT}
209
+
210
+ def _select(image, shape, op='replace'):
211
+ mode = _OPS[op]
212
+ if isinstance(shape, dict):
213
+ if 'rect' in shape:
214
+ x, y, w, h = shape['rect']
215
+ r = shape.get('radius', 0)
216
+ if r:
217
+ image.select_round_rectangle(mode, x, y, w, h, r, r)
218
+ else:
219
+ image.select_rectangle(mode, x, y, w, h)
220
+ elif 'ellipse' in shape:
221
+ x, y, w, h = shape['ellipse']
222
+ image.select_ellipse(mode, x, y, w, h)
223
+ elif 'svg' in shape:
224
+ w, h = image.get_width(), image.get_height()
225
+ svg = f'<svg xmlns="http://www.w3.org/2000/svg" width="{w}" height="{h}" viewBox="0 0 {w} {h}"><path d="{shape["svg"]}"/></svg>'
226
+ ok, paths = image.import_paths_from_string(svg, len(svg), True, False)
227
+ if not ok or not paths:
228
+ raise ValueError('That SVG path could not be read. Use d-attribute syntax: "M 10 10 C 40 0, 60 0, 90 10 Z"')
229
+ image.select_item(mode, paths[0])
230
+ for p in paths:
231
+ image.remove_path(p)
232
+ else:
233
+ raise ValueError('A shape is a list of points, or rect=(x,y,w,h), ellipse=(x,y,w,h), or svg="M ... Z"')
234
+ else:
235
+ pts = [float(n) for n in shape]
236
+ if len(pts) < 6 or len(pts) % 2:
237
+ raise ValueError('A polygon is a flat list: [x1, y1, x2, y2, x3, y3, ...]')
238
+ image.select_polygon(mode, pts)
239
+
240
+ def _shapes(shape):
241
+ return shape if isinstance(shape, tuple) else (shape,)
242
+
243
+ def ava_fill(layer, shape, colour):
244
+ """Fill a shape on a layer. shape: [x1,y1,x2,y2,...], dict(rect=(x,y,w,h),
245
+ radius=12), dict(ellipse=(x,y,w,h)), or dict(svg="M 10 10 C ... Z") for
246
+ smooth curves. Several shapes as a tuple are filled together."""
247
+ image = layer.get_image()
248
+ for i, s in enumerate(_shapes(shape)):
249
+ _select(image, s, 'replace' if i == 0 else 'add')
250
+ Gimp.context_set_foreground(Gegl.Color.new(colour))
251
+ layer.edit_fill(Gimp.FillType.FOREGROUND)
252
+ Gimp.Selection.none(image)
253
+ return layer
254
+
255
+ def ava_cut(layer, shape):
256
+ """Remove a shape from a layer: real transparency, for negative space."""
257
+ image = layer.get_image()
258
+ for i, s in enumerate(_shapes(shape)):
259
+ _select(image, s, 'replace' if i == 0 else 'add')
260
+ layer.edit_clear()
261
+ Gimp.Selection.none(image)
262
+ return layer
263
+
264
+ def ava_gradient(layer, shape, start, end, y0, y1):
265
+ """Fill a shape with a vertical gradient between two colours, top to bottom
266
+ from y0 to y1. Good for edge light and metal on a flat mark."""
267
+ image = layer.get_image()
268
+ for i, s in enumerate(_shapes(shape)):
269
+ _select(image, s, 'replace' if i == 0 else 'add')
270
+ Gimp.context_set_foreground(Gegl.Color.new(start))
271
+ Gimp.context_set_background(Gegl.Color.new(end))
272
+ Gimp.context_set_gradient_fg_bg_rgb()
273
+ layer.edit_gradient_fill(Gimp.GradientType.LINEAR, 0.0, False, 1, 0.0, False, 0.0, float(y0), 0.0, float(y1))
274
+ Gimp.Selection.none(image)
275
+ return layer
276
+
277
+ def ava_fonts(match=''):
278
+ """Font names installed here that contain 'match'."""
279
+ return sorted(f.get_name() for f in Gimp.fonts_get_list(match))
280
+
281
+ # ── Layers ───────────────────────────────────────────────────────────────────
282
+ # Thirteen of the title logo's 24 failed runs were guesses at these jobs:
283
+ # layer.duplicate, lower_layer, layer.remove, moving layers between images.
284
+
285
+ def _named(image, ref):
286
+ if not isinstance(ref, str):
287
+ return ref
288
+ for l in image.get_layers():
289
+ if l.get_name() == ref:
290
+ return l
291
+ raise ValueError(f'No layer called "{ref}". Layers here: {[l.get_name() for l in image.get_layers()]}')
292
+
293
+ def ava_copy_layer(layer, name=None, into=None):
294
+ """Copy a layer, on top of its own image or of another one (into=image)."""
295
+ dest = into or layer.get_image()
296
+ copy = Gimp.Layer.new_from_drawable(layer, dest)
297
+ dest.insert_layer(copy, None, 0)
298
+ _, x, y = layer.get_offsets()
299
+ copy.set_offsets(x, y)
300
+ if name:
301
+ copy.set_name(name)
302
+ return copy
303
+
304
+ def ava_remove(layer):
305
+ """Delete a layer."""
306
+ layer.get_image().remove_layer(layer)
307
+
308
+ def ava_move(layer, to=None, above=None, below=None):
309
+ """Change a layer's place: to='top', to='bottom', above=other or below=other."""
310
+ image = layer.get_image()
311
+ last = len(image.get_layers()) - 1
312
+ now = image.get_item_position(layer)
313
+ if to == 'top':
314
+ pos = 0
315
+ elif to == 'bottom':
316
+ pos = last
317
+ elif above is not None:
318
+ ref = image.get_item_position(_named(image, above))
319
+ pos = ref if ref < now else ref - 1
320
+ elif below is not None:
321
+ ref = image.get_item_position(_named(image, below))
322
+ pos = ref + 1 if ref < now else ref
323
+ else:
324
+ raise ValueError("Say where: to='top', to='bottom', above=layer or below=layer")
325
+ image.reorder_item(layer, None, max(0, min(last, pos)))
326
+ return layer
327
+
328
+ def _visible(image):
329
+ if not any(l.get_visible() for l in image.get_layers()):
330
+ raise ValueError('Nothing is visible in this image: every layer is hidden, or it has no layers.')
331
+
332
+ def ava_merged(image, layers=None, name='Merged'):
333
+ """A merged copy of some layers as ONE new layer on top of the same image,
334
+ leaving the originals editable. layers = names or layers; default is
335
+ everything visible. This is the safe way to derive a glow or a shadow."""
336
+ copy = image.duplicate()
337
+ if layers is not None:
338
+ keep = {l if isinstance(l, str) else l.get_name() for l in layers}
339
+ missing = keep - {l.get_name() for l in copy.get_layers()}
340
+ if missing:
341
+ raise ValueError(f'No layer called {sorted(missing)}. Layers here: {[l.get_name() for l in copy.get_layers()]}')
342
+ for l in copy.get_layers():
343
+ l.set_visible(l.get_name() in keep)
344
+ _visible(copy)
345
+ merged = copy.merge_visible_layers(Gimp.MergeType.CLIP_TO_IMAGE)
346
+ lay = Gimp.Layer.new_from_drawable(merged, image)
347
+ image.insert_layer(lay, None, 0)
348
+ _, x, y = merged.get_offsets()
349
+ lay.set_offsets(x, y)
350
+ lay.set_name(name)
351
+ lay.set_mode(Gimp.LayerMode.NORMAL)
352
+ lay.set_opacity(100.0)
353
+ lay.set_visible(True)
354
+ copy.delete()
355
+ return lay
356
+
357
+ def ava_glow(image, layers=None, radius=24.0, opacity=50.0, colour=None, name='Glow'):
358
+ """A real glow on its own switchable layer: a blurred merged copy, in Screen
359
+ mode. Call it twice for a tight bloom plus a wide halo. opacity is 0-100."""
360
+ if 0 < opacity <= 1:
361
+ raise ValueError(f'opacity is 0-100, so {opacity} would be invisible. Did you mean {opacity * 100:g}?')
362
+ lay = ava_merged(image, layers, name)
363
+ lay.resize_to_image_size() # a blur cannot spread past the layer's edge
364
+ if colour:
365
+ ava_filter(lay, 'gegl:color-overlay', value=colour)
366
+ ava_filter(lay, 'gegl:gaussian-blur', std_dev_x=float(radius), std_dev_y=float(radius))
367
+ lay.set_mode(Gimp.LayerMode.SCREEN)
368
+ lay.set_opacity(float(opacity))
369
+ return lay
370
+
371
+ def ava_pixel(image, x, y):
372
+ """The colour you would really see at x, y in the whole image, as '#RRGGBB',
373
+ or '#RRGGBBAA' where it isn't solid. Image coordinates, all layers combined."""
374
+ copy = image.duplicate()
375
+ _visible(copy)
376
+ merged = copy.merge_visible_layers(Gimp.MergeType.CLIP_TO_IMAGE)
377
+ _, ox, oy = merged.get_offsets()
378
+ w, h = merged.get_width(), merged.get_height()
379
+ lx, ly = int(x) - ox, int(y) - oy
380
+ if not (0 <= lx < w and 0 <= ly < h):
381
+ copy.delete()
382
+ return '#00000000'
383
+ c = merged.get_pixel(lx, ly)
384
+ copy.delete()
385
+ r, g, b, a = c.get_rgba_with_space(None)
386
+ hex_ = '#%02X%02X%02X' % tuple(int(round(max(0.0, min(1.0, v)) * 255)) for v in (r, g, b))
387
+ return hex_ if a >= 0.999 else hex_ + '%02X' % int(round(a * 255))
388
+
389
+ _TEST_NAMES = ('test', 'compare', 'comparison', 'thumb', 'proof', 'tmp', 'temp', 'scratch', 'draft', 'check', 'trial')
390
+
391
+ def _is_test(name):
392
+ low = name.lower()
393
+ return any(low == t or low.startswith((t + '-', t + '_', t + ' ')) for t in _TEST_NAMES)
394
+
395
+ def ava_images():
396
+ """The saved images in this work, by name."""
397
+ return sorted(f[:-4] for f in os.listdir(ASSET_DIR) if f.endswith('.xcf'))
398
+
399
+ # ── Seeing the work ──────────────────────────────────────────────────────────
400
+ # She only ever got the preview: every image in the folder on one sheet at
401
+ # 256px. Her exports and comparison sheets never reached her, so she measured
402
+ # pixels instead of looking (4 Nov 2026).
403
+ _LOOK_DIR = os.path.join(ASSET_DIR, '.look')
404
+ MAX_LOOKS = 4
405
+ _looks = []
406
+
407
+ def _path(p):
408
+ full = p if os.path.isabs(p) else os.path.join(ASSET_DIR, p)
409
+ if not os.path.exists(full):
410
+ raise ValueError(f'There is no file at {p}. Paths are relative to the work, e.g. exports/name.png or references/art.png.')
411
+ return full
412
+
413
+ def _load(what):
414
+ if isinstance(what, str):
415
+ return Gimp.file_load(Gimp.RunMode.NONINTERACTIVE, _file(_path(what)))
416
+ return what.duplicate()
417
+
418
+ def _is_colour(on):
419
+ return isinstance(on, str) and on.startswith('#')
420
+
421
+ def _keep_look(img, label):
422
+ if len(_looks) >= MAX_LOOKS:
423
+ result['warnings'].append(f'Only {MAX_LOOKS} looks come back per run; "{label}" was left out.')
424
+ return
425
+ os.makedirs(_LOOK_DIR, exist_ok=True)
426
+ path = os.path.join(_LOOK_DIR, f'{len(_looks) + 1}.png')
427
+ Gimp.file_save(Gimp.RunMode.NONINTERACTIVE, img, _file(path), None)
428
+ _looks.append({'file': os.path.basename(path), 'label': label})
429
+
430
+ def ava_show(what, crop=None, on='#24242c', label=None):
431
+ """Look at something as it really is, up to 1024px: an image, or a file such
432
+ as 'exports/logo.png'. crop=(x, y, w, h) zooms in. on= is what shows through
433
+ transparency: a colour, or a picture in the work such as
434
+ 'references/title.png'. Hidden layers stay hidden. Up to 4 come back to you."""
435
+ img = _load(what)
436
+ _visible(img)
437
+ if crop:
438
+ x, y, w, h = [int(n) for n in crop]
439
+ img.crop(w, h, x, y)
440
+ W, H = img.get_width(), img.get_height()
441
+ _lay_on(img, on)
442
+ img.flatten()
443
+ k = 1024 / max(W, H)
444
+ if k < 1 or crop:
445
+ k = min(k, 8)
446
+ Gimp.context_set_interpolation(Gimp.InterpolationType.NONE if k > 1 else Gimp.InterpolationType.CUBIC)
447
+ img.scale(max(1, int(W * k)), max(1, int(H * k)))
448
+ Gimp.context_set_interpolation(Gimp.InterpolationType.CUBIC)
449
+ _keep_look(img, label or (what if isinstance(what, str) else 'the image'))
450
+ img.delete()
451
+
452
+ def _lay_on(img, back):
453
+ """Put a colour or a picture behind everything, as a real bottom layer, so
454
+ Screen glows and the like composite against it as they will in use."""
455
+ W, H = img.get_width(), img.get_height()
456
+ if _is_colour(back):
457
+ bg = Gimp.Layer.new(img, 'bg', W, H, Gimp.ImageType.RGBA_IMAGE, 100, Gimp.LayerMode.NORMAL)
458
+ img.insert_layer(bg, None, len(img.get_layers()))
459
+ Gimp.context_set_foreground(Gegl.Color.new(back))
460
+ bg.fill(Gimp.FillType.FOREGROUND)
461
+ else:
462
+ bg = Gimp.file_load_layer(Gimp.RunMode.NONINTERACTIVE, img, _file(_path(back)))
463
+ img.insert_layer(bg, None, len(img.get_layers()))
464
+ bg.scale(W, H, False)
465
+ bg.set_offsets(0, 0)
466
+
467
+ def ava_proof(what, on=None, widths=(256, 120, 64), label=None):
468
+ """The proof sheet: the piece, cropped tight, composited large on each
469
+ background, with its real small sizes in true pixels below. on= colours
470
+ and/or pictures in the work, e.g. ('references/title.png', '#101014'); with
471
+ none, the kit's own surface beside plain light and mid, so work is tested
472
+ where it will live. Hide any backdrop layer first. Saved as
473
+ exports/proof.png and shown to you."""
474
+ if on is None:
475
+ on = (KIT.colour('surface'), '#f4f4f4', '#808080') if KIT else ('#f4f4f4', '#808080', '#101014')
476
+ src = _load(what)
477
+ _visible(src)
478
+ W, H = src.get_width(), src.get_height()
479
+ merged = src.merge_visible_layers(Gimp.MergeType.CLIP_TO_IMAGE)
480
+ src.select_item(Gimp.ChannelOps.REPLACE, merged)
481
+ bounds = Gimp.Selection.bounds(src)
482
+ src.delete()
483
+ x1, y1, x2, y2 = bounds[2:6] if bounds[1] else (0, 0, W, H)
484
+ pad = max(x2 - x1, y2 - y1) // 24
485
+ x1, y1, x2, y2 = max(0, x1 - pad), max(0, y1 - pad), min(W, x2 + pad), min(H, y2 + pad)
486
+ sw, sh = x2 - x1, y2 - y1
487
+ os.makedirs(_LOOK_DIR, exist_ok=True)
488
+ backs = [on] if isinstance(on, str) else list(on)
489
+ cw, big, strip = 1024 // len(backs), 300, 170
490
+ sheet = Gimp.Image.new(cw * len(backs), big + strip, Gimp.ImageBaseType.RGB)
491
+ def place(path, w, h, x, y):
492
+ lay = Gimp.file_load_layer(Gimp.RunMode.NONINTERACTIVE, sheet, _file(path))
493
+ sheet.insert_layer(lay, None, 0)
494
+ lay.scale(w, h, False)
495
+ lay.set_offsets(x, y)
496
+ Gimp.context_set_interpolation(Gimp.InterpolationType.CUBIC)
497
+ left_out = set()
498
+ for i, back in enumerate(backs):
499
+ x0 = i * cw
500
+ tile = _load(what)
501
+ _lay_on(tile, back)
502
+ tile.flatten()
503
+ # On a picture the large view is the whole frame, the piece where it
504
+ # really sits; a tight crop of a picture only reads as a patch.
505
+ full_path = None
506
+ if not _is_colour(back):
507
+ full_path = os.path.join(_LOOK_DIR, f'proof-{i}-full.png')
508
+ Gimp.file_save(Gimp.RunMode.NONINTERACTIVE, tile, _file(full_path), None)
509
+ tile.crop(sw, sh, x1, y1)
510
+ tile_path = os.path.join(_LOOK_DIR, f'proof-{i}.png')
511
+ Gimp.file_save(Gimp.RunMode.NONINTERACTIVE, tile, _file(tile_path), None)
512
+ tile.delete()
513
+ bg = Gimp.Layer.new(sheet, 'bg', cw, big + strip, Gimp.ImageType.RGBA_IMAGE, 100, Gimp.LayerMode.NORMAL)
514
+ sheet.insert_layer(bg, None, 0)
515
+ Gimp.context_set_foreground(Gegl.Color.new(back if _is_colour(back) else '#101014'))
516
+ bg.fill(Gimp.FillType.FOREGROUND)
517
+ bg.set_offsets(x0, 0)
518
+ big_w, big_h = (W, H) if full_path else (sw, sh)
519
+ k = min((cw - 24) / big_w, (big - 24) / big_h)
520
+ w, h = max(1, int(big_w * k)), max(1, int(big_h * k))
521
+ place(full_path or tile_path, w, h, x0 + (cw - w) // 2, (big - h) // 2)
522
+ px, py, row = x0 + 12, big + 8, 0
523
+ for wide in widths:
524
+ wide = int(wide)
525
+ h = max(1, round(sh * wide / sw))
526
+ if px > x0 + 12 and px + wide > x0 + cw - 8:
527
+ px, py, row = x0 + 12, py + row + 10, 0
528
+ if wide > cw - 20 or py + h > big + strip - 6:
529
+ left_out.add(wide)
530
+ continue
531
+ place(tile_path, wide, h, px, py)
532
+ px += wide + 12
533
+ row = max(row, h)
534
+ if left_out:
535
+ result['warnings'].append(f'The proof sheet had no room for widths {sorted(left_out)}px. Use fewer backgrounds or show that size with ava_show.')
536
+ sheet.flatten()
537
+ out = os.path.join(ASSET_DIR, 'exports')
538
+ os.makedirs(out, exist_ok=True)
539
+ Gimp.file_save(Gimp.RunMode.NONINTERACTIVE, sheet, _file(os.path.join(out, 'proof.png')), None)
540
+ print('AVA_EXPORT: exports/proof.png')
541
+ _keep_look(sheet, label or f'proof sheet, small widths {list(widths)}px')
542
+ sheet.delete()
543
+
544
+ # ── The report after every run ───────────────────────────────────────────────
545
+ # What the file really is, so a mistake shows without guessing: her glow sat at
546
+ # opacity 0.55 of 100 for about 12 runs, and opaque layers hid her wordmark for 12.
547
+ def _report(name, img):
548
+ W, H = img.get_width(), img.get_height()
549
+ lines, warns = [f'{name} ({W}×{H}), top layer first:'], []
550
+ layers = img.get_layers()
551
+ hiding = None
552
+ for l in layers[:40]:
553
+ n = l.get_name()
554
+ _, x, y = l.get_offsets()
555
+ w, h = l.get_width(), l.get_height()
556
+ op, on = l.get_opacity(), l.get_visible()
557
+ mode = l.get_mode().value_nick
558
+ try:
559
+ ink = (l.histogram(Gimp.HistogramChannel.ALPHA, 0.0, 1.0)[1] / 255) if l.has_alpha() else 1.0
560
+ except Exception:
561
+ ink = None
562
+ kind = 'text, ' if l.is_text_layer() else ''
563
+ lines.append(f' "{n}" {kind}{w}×{h} at {x},{y} · {mode} · opacity {op:g} · {"on" if on else "HIDDEN"}' +
564
+ (f' · covers {ink * w * h / (W * H) * 100:.1f}% of the canvas' if ink is not None else ''))
565
+ if not on:
566
+ continue
567
+ if hiding:
568
+ if ink:
569
+ warns.append(f'"{n}" cannot be seen: "{hiding}" is solid and sits on top of it.')
570
+ continue
571
+ if 0 < op <= 1:
572
+ warns.append(f'"{n}" opacity is {op:g}, and the scale is 0-100, so it is almost invisible. Did you mean {op * 100:g}?')
573
+ if ink == 0:
574
+ warns.append(f'"{n}" is empty: nothing is on it.')
575
+ if x >= W or y >= H or x + w <= 0 or y + h <= 0:
576
+ warns.append(f'"{n}" is completely off the canvas.')
577
+ if ink is not None and ink > 0.995 and op >= 99.9 and mode == 'normal' and x <= 0 and y <= 0 and x + w >= W and y + h >= H:
578
+ hiding = n
579
+ if not any(l.get_visible() for l in layers):
580
+ warns.append('Every layer is hidden, so this image exports as nothing.')
581
+ return lines, warns
582
+
583
+ def ava_text(image, text, font='Sans-serif Bold', size=96, colour='#ffffff', x=0, y=0, name=None, spacing=0.0):
584
+ """A real, editable text layer: the person can retype it in GIMP. size is
585
+ in pixels; spacing adds letter spacing. Check names with ava_fonts('rajdhani')."""
586
+ f = Gimp.Font.get_by_name(font)
587
+ if f is None:
588
+ near = ava_fonts(font.split()[0])[:12]
589
+ raise ValueError(f'No font called "{font}". Close matches: {near}. If this is the font they agreed, ask them whether you may install it, then use design_install_font.')
590
+ lay = Gimp.TextLayer.new(image, text, f, float(size), Gimp.Unit.pixel())
591
+ image.insert_layer(lay, None, 0)
592
+ lay.set_color(Gegl.Color.new(colour))
593
+ if spacing:
594
+ lay.set_letter_spacing(float(spacing))
595
+ lay.set_offsets(int(x), int(y))
596
+ lay.set_name(name or text[:40])
597
+ return lay
598
+
599
+ shutil.rmtree(_LOOK_DIR, ignore_errors=True)
600
+ sys.addaudithook(_hook)
601
+
602
+ # ── Ava's script ─────────────────────────────────────────────────────────────
603
+ script_path = os.path.join(ASSET_DIR, 'script.py')
604
+ ns = {'__name__': '__main__', '__file__': script_path, 'ASSET_DIR': ASSET_DIR,
605
+ 'Gimp': Gimp, 'Gegl': Gegl, 'Gio': Gio, 'os': os, 'KIT': KIT,
606
+ 'ava_copy_layer': ava_copy_layer, 'ava_remove': ava_remove, 'ava_move': ava_move, 'ava_merged': ava_merged,
607
+ 'ava_glow': ava_glow, 'ava_pixel': ava_pixel, 'ava_images': ava_images, 'ava_show': ava_show, 'ava_proof': ava_proof, 'ava_final': ava_final,
608
+ 'ava_image': ava_image, 'ava_layer': ava_layer, 'ava_place': ava_place,
609
+ 'ava_filter': ava_filter, 'ava_export': ava_export, 'ava_fill': ava_fill, 'ava_cut': ava_cut,
610
+ 'ava_gradient': ava_gradient, 'ava_text': ava_text, 'ava_fonts': ava_fonts}
611
+ try:
612
+ with open(script_path, encoding='utf-8') as f:
613
+ code = compile(f.read(), 'script.py', 'exec')
614
+ exec(code, ns)
615
+ except BaseException as e: # the saved work must stay as it was
616
+ result['error'] = ''.join(traceback.format_exception(type(e), e, e.__traceback__)[-12:])
617
+ emit()
618
+ raise SystemExit(0)
619
+
620
+ # ── Save, export, preview ────────────────────────────────────────────────────
621
+ try:
622
+ if not _open:
623
+ raise RuntimeError('The script made no image. Start with: img = ava_image("name", 512, 512)')
624
+ vdir = os.path.join(ASSET_DIR, 'versions')
625
+ stamp = time.strftime('%Y%m%d-%H%M%S')
626
+ saved_any = False
627
+ for name, img in _open.items():
628
+ if not img.get_layers():
629
+ # Saving one crashes GIMP's PNG writer, and an empty file on the
630
+ # stage is what split the title logo in two.
631
+ result['warnings'].append(f'"{name}" has no layers, so it was not saved. Saved images here: {ava_images()}.')
632
+ continue
633
+ saved_any = True
634
+ xcf = os.path.join(ASSET_DIR, name + '.xcf')
635
+ if os.path.exists(xcf): # keep the last 5 versions of each image
636
+ os.makedirs(vdir, exist_ok=True)
637
+ shutil.copy2(xcf, os.path.join(vdir, f'{name}.{stamp}.xcf'))
638
+ old = sorted(f for f in os.listdir(vdir) if f.startswith(name + '.'))
639
+ for f in old[:-5]:
640
+ os.remove(os.path.join(vdir, f))
641
+ Gimp.file_save(Gimp.RunMode.NONINTERACTIVE, img, _file(xcf), None)
642
+ copy = img.duplicate()
643
+ copy.merge_visible_layers(Gimp.MergeType.CLIP_TO_IMAGE)
644
+ Gimp.file_save(Gimp.RunMode.NONINTERACTIVE, copy, _file(os.path.join(ASSET_DIR, name + '.png')), None)
645
+ copy.delete()
646
+ result['images'].append({'name': name, 'width': img.get_width(), 'height': img.get_height(),
647
+ 'layers': len(img.get_layers())})
648
+ lines, warns = _report(name, img)
649
+ result['report'] += lines
650
+ result['warnings'] += warns
651
+ if not saved_any:
652
+ raise RuntimeError(f'Nothing to save: no image here has any layers. Saved images in this work: {ava_images()}. Open one by name, or add a layer.')
653
+ # Finals are written last, so a failed run can't add one.
654
+ finals_path = os.path.join(ASSET_DIR, 'finals.json')
655
+ try:
656
+ finals = json.load(open(finals_path, encoding='utf-8'))
657
+ except Exception:
658
+ finals = []
659
+ finals += [f for f in _new_finals if f not in finals]
660
+ if _new_finals:
661
+ json.dump(finals, open(finals_path, 'w', encoding='utf-8'), indent=2)
662
+ result['newFinals'] = _new_finals
663
+ # Preview: the finished files once there are any. Until then, the piece being
664
+ # worked on: what this run touched, leaving out her tests, so the person can
665
+ # always tell what the focus is. Every image at once told them nothing.
666
+ shown = [os.path.join(ASSET_DIR, f) for f in finals if os.path.exists(os.path.join(ASSET_DIR, f))]
667
+ if not shown:
668
+ saved_names = ava_images()
669
+ pieces = [n for n in saved_names if not _is_test(n)]
670
+ focus = [n for n in pieces if n in _open] or pieces or saved_names
671
+ try:
672
+ chosen = json.load(open(os.path.join(ASSET_DIR, 'main.json'), encoding='utf-8'))
673
+ if chosen in saved_names:
674
+ focus = [chosen]
675
+ except Exception:
676
+ pass
677
+ shown = [os.path.join(ASSET_DIR, n + '.png') for n in focus if os.path.exists(os.path.join(ASSET_DIR, n + '.png'))]
678
+ names = shown
679
+ cols = (min(len(names), 3) if len(names) <= 6 else 6) or 1
680
+ rows = (len(names) + cols - 1) // cols
681
+ cell = 768 if len(names) == 1 else 512 if len(names) <= 6 else 256
682
+ sheet = Gimp.Image.new(cols * cell, rows * cell, Gimp.ImageBaseType.RGB)
683
+ bg = Gimp.Layer.new(sheet, 'bg', cols * cell, rows * cell, Gimp.ImageType.RGBA_IMAGE, 100, Gimp.LayerMode.NORMAL)
684
+ sheet.insert_layer(bg, None, 0)
685
+ # Left empty on purpose: transparency stays real, so the room can show it.
686
+ for i, n in enumerate(names):
687
+ lay = Gimp.file_load_layer(Gimp.RunMode.NONINTERACTIVE, sheet, _file(n))
688
+ sheet.insert_layer(lay, None, 0)
689
+ w, h = lay.get_width(), lay.get_height()
690
+ k = min((cell - 16) / w, (cell - 16) / h)
691
+ nw, nh = max(1, int(w * k)), max(1, int(h * k))
692
+ lay.scale(nw, nh, False)
693
+ lay.set_offsets((i % cols) * cell + (cell - nw) // 2, (i // cols) * cell + (cell - nh) // 2)
694
+ sheet.merge_visible_layers(Gimp.MergeType.CLIP_TO_IMAGE)
695
+ Gimp.file_save(Gimp.RunMode.NONINTERACTIVE, sheet, _file(os.path.join(ASSET_DIR, 'preview.png')), None)
696
+ sheet.delete()
697
+ # What comes back to her: what she asked to see, else what this run touched.
698
+ try:
699
+ if not _looks:
700
+ for name, img in list(_open.items())[:MAX_LOOKS]:
701
+ if img.get_layers() and any(l.get_visible() for l in img.get_layers()):
702
+ ava_show(img, label=name)
703
+ result['looks'] = _looks
704
+ except Exception as e:
705
+ result['warnings'].append(f'Could not prepare the look: {e}')
706
+ result['files'] = sorted(f for f in os.listdir(ASSET_DIR) if f.endswith(('.xcf', '.png')))
707
+ ex = os.path.join(ASSET_DIR, 'exports')
708
+ if os.path.isdir(ex):
709
+ result['files'] += ['exports/' + f for f in sorted(os.listdir(ex))]
710
+ result['ok'] = True
711
+ result['seconds'] = round(time.time() - STARTED, 1)
712
+ except BaseException as e:
713
+ result['error'] = 'The script ran, but saving failed:\n' + \
714
+ ''.join(traceback.format_exception(type(e), e, e.__traceback__)[-8:])
715
+ shutil.rmtree(_TMP, ignore_errors=True)
716
+ emit()
717
+ for img in list(_open.values()):
718
+ try:
719
+ img.delete()
720
+ except Exception:
721
+ pass
722
+ `;
723
+ //# sourceMappingURL=runner-py.js.map