@vectoriox/iox-ui 5.159.0 → 5.160.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/package.json
CHANGED
|
@@ -151,24 +151,83 @@ export function generatePicturePrompt(request: Pick<GeneratePicturesRequest, 'pr
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
/** Words an image model draws badly: asked for inside the picture, they come out wrong (the honesty line). */
|
|
154
|
-
const
|
|
154
|
+
const WORD_TERMS_EN = 'logos?|texts?|words?|signs?|signage|letters?|lettering|captions?|titles?|headlines?|slogans?|typography|writing';
|
|
155
|
+
const WORD_TERMS_HE = 'כיתוב|טקסט|לוגו|כותרת|אותיות|שלט|סלוגן|מילים';
|
|
156
|
+
const WORDS_ASKED = new RegExp(`\\b(${WORD_TERMS_EN})\\b|${WORD_TERMS_HE}`, 'i');
|
|
155
157
|
|
|
156
|
-
/**
|
|
158
|
+
/**
|
|
159
|
+
* A NEGATED ask is the opposite of asking (iox-ui#136): "no text", "without words or logos", "text-free", "בלי טקסט",
|
|
160
|
+
* "ללא כיתוב או לוגו" are removed before the check. A list after the negation ("no text, logos or signs") goes with it.
|
|
161
|
+
*/
|
|
162
|
+
const WORD_TERM_ANY = `(?:${WORD_TERMS_EN}|${WORD_TERMS_HE})`;
|
|
163
|
+
const WORD_NEGATED = new RegExp(
|
|
164
|
+
`(?:\\b(?:no|without|free of|zero|never any|not any)\\s+(?:any\\s+)?|(?:בלי|ללא|אין|בלא)\\s+(?:שום\\s+)?)` +
|
|
165
|
+
`${WORD_TERM_ANY}(?:\\s*(?:,|/|\\bor\\b|\\band\\b|או|ו)\\s*(?:any\\s+)?${WORD_TERM_ANY})*` +
|
|
166
|
+
`|\\b(?:${WORD_TERMS_EN})[- ]free\\b`, 'giu');
|
|
167
|
+
|
|
168
|
+
/** Words QUOTED from the page (“…” or "…", as `describeFromPage` writes them) are context, not an ask to draw them. */
|
|
169
|
+
const QUOTED = /“[^”]*”|„[^“”]*[“”]|"[^"]*"/g;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* True when the owner's words ask for writing INSIDE the picture — the box says "put the words on the page". Quoted page
|
|
173
|
+
* words and negated asks ("no text") never count (iox-ui#136).
|
|
174
|
+
*/
|
|
157
175
|
export function promptAsksForWords(prompt: string): boolean {
|
|
158
|
-
|
|
176
|
+
const asked = (prompt ?? '').replace(QUOTED, ' ').replace(WORD_NEGATED, ' ');
|
|
177
|
+
return WORDS_ASKED.test(asked);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** The languages "Describe from the page" frames its sentence in; any other falls back to English. */
|
|
181
|
+
export enum DescribeLanguage {
|
|
182
|
+
En = 'en',
|
|
183
|
+
He = 'he',
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The frame of "Describe from the page", per language. Its own words never name writing (no "words", "text", "כיתוב"),
|
|
188
|
+
* so the box's words-in-pictures warning is never tripped by what the product wrote (iox-ui#136).
|
|
189
|
+
*/
|
|
190
|
+
const DESCRIBE_FRAMES: Readonly<Record<DescribeLanguage, {
|
|
191
|
+
readonly forBusiness: (business: string) => string;
|
|
192
|
+
readonly forPart: string;
|
|
193
|
+
readonly beside: (subject: string, words: string) => string;
|
|
194
|
+
readonly alone: (subject: string) => string;
|
|
195
|
+
}>> = {
|
|
196
|
+
[DescribeLanguage.En]: {
|
|
197
|
+
forBusiness: business => `A picture for ${business}`,
|
|
198
|
+
forPart: 'A picture for this part of the page',
|
|
199
|
+
beside: (subject, words) => `${subject}, beside the section that says “${words}”.`,
|
|
200
|
+
alone: subject => `${subject}.`,
|
|
201
|
+
},
|
|
202
|
+
[DescribeLanguage.He]: {
|
|
203
|
+
forBusiness: business => `תמונה עבור ${business}`,
|
|
204
|
+
forPart: 'תמונה לחלק הזה של העמוד',
|
|
205
|
+
beside: (subject, words) => `${subject}, ליד החלק שאומר “${words}”.`,
|
|
206
|
+
alone: subject => `${subject}.`,
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const HEBREW_LETTER = /[\u0590-\u05FF]/;
|
|
211
|
+
|
|
212
|
+
/** The frame's language: the admin's when it is one we write in, else the script of the page's words, else English. */
|
|
213
|
+
export function describeLanguageOf(locale: string | undefined, words: string): DescribeLanguage {
|
|
214
|
+
const base = (locale ?? '').toLowerCase().split(/[-_]/)[0];
|
|
215
|
+
if ((Object.values(DescribeLanguage) as string[]).includes(base)) return base as DescribeLanguage;
|
|
216
|
+
return HEBREW_LETTER.test(words) ? DescribeLanguage.He : DescribeLanguage.En;
|
|
159
217
|
}
|
|
160
218
|
|
|
161
219
|
/**
|
|
162
220
|
* "Describe from the page": the words the box fills in for the element that opened it — the section's own words and
|
|
163
221
|
* the kind of business, never the business's name (it would be drawn). No model is asked; empty when the page says
|
|
164
|
-
* nothing.
|
|
222
|
+
* nothing. Framed in the admin's language (`locale`; without one, the language the page's words are in).
|
|
165
223
|
*/
|
|
166
|
-
export function describeFromPage(context: { readonly business?: string; readonly words?: string }): string {
|
|
224
|
+
export function describeFromPage(context: { readonly business?: string; readonly words?: string; readonly locale?: string }): string {
|
|
167
225
|
const business = (context.business ?? '').trim();
|
|
168
|
-
const words = (context.words ?? '').replace(/\s+/g, ' ').trim().slice(0, 240);
|
|
226
|
+
const words = (context.words ?? '').replace(/\s+/g, ' ').replace(/[“”"]/g, '').trim().slice(0, 240);
|
|
169
227
|
if (!business && !words) return '';
|
|
170
|
-
const
|
|
171
|
-
|
|
228
|
+
const frame = DESCRIBE_FRAMES[describeLanguageOf(context.locale, `${words} ${business}`)];
|
|
229
|
+
const subject = business ? frame.forBusiness(business) : frame.forPart;
|
|
230
|
+
return (words ? frame.beside(subject, words) : frame.alone(subject)).slice(0, GENERATE_PROMPT_MAX);
|
|
172
231
|
}
|
|
173
232
|
|
|
174
233
|
// ── The cost, shown before the button ─────────────────────────────────────────────────────────
|