@h-ai/ui 1.0.0-beta.33 → 1.0.0-beta.35

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 (36) hide show
  1. package/README.en.md +4 -0
  2. package/README.ja.md +4 -0
  3. package/README.md +4 -0
  4. package/auto-import.d.ts +2 -0
  5. package/auto-import.js +2 -0
  6. package/dist/components/compounds/CronExpressionBuilder.svelte +655 -0
  7. package/dist/components/compounds/CronExpressionBuilder.svelte.d.ts +40 -0
  8. package/dist/components/compounds/DatePicker.svelte +5 -1
  9. package/dist/components/compounds/DatePicker.svelte.d.ts +2 -0
  10. package/dist/components/compounds/ScheduleInput.svelte +475 -0
  11. package/dist/components/compounds/ScheduleInput.svelte.d.ts +51 -0
  12. package/dist/components/compounds/cron-expression-builder-types.d.ts +97 -0
  13. package/dist/components/compounds/cron-expression-builder-types.js +1 -0
  14. package/dist/components/compounds/cron-expression-builder.d.ts +63 -0
  15. package/dist/components/compounds/cron-expression-builder.js +293 -0
  16. package/dist/components/compounds/index.d.ts +6 -0
  17. package/dist/components/compounds/index.js +5 -0
  18. package/dist/components/compounds/schedule-input-config.d.ts +8 -0
  19. package/dist/components/compounds/schedule-input-config.js +7 -0
  20. package/dist/components/compounds/schedule-input.d.ts +170 -0
  21. package/dist/components/compounds/schedule-input.js +262 -0
  22. package/dist/components/scenes/ai/AiDocumentEditor.svelte +15 -3
  23. package/dist/components/scenes/ai/document-parse.d.ts +2 -0
  24. package/dist/components/scenes/ai/document-parse.js +9 -5
  25. package/dist/components/scenes/ai/document-source-range.d.ts +10 -0
  26. package/dist/components/scenes/ai/document-source-range.js +90 -0
  27. package/dist/components/scenes/ai/document-types.d.ts +20 -0
  28. package/dist/components/scenes/ai/index.d.ts +1 -1
  29. package/dist/components/scenes/ai/markdown-parse.d.ts +2 -0
  30. package/dist/components/scenes/ai/markdown-parse.js +8 -5
  31. package/dist/components/scenes/ai/safe-html.d.ts +12 -2
  32. package/dist/components/scenes/ai/safe-html.js +22 -8
  33. package/dist/messages/en-US.json +28 -0
  34. package/dist/messages/ja-JP.json +28 -0
  35. package/dist/messages/zh-CN.json +28 -0
  36. package/package.json +8 -2
@@ -119,6 +119,7 @@ export function isExternalLinkHref(href) {
119
119
  /**
120
120
  * 拒绝危险图片来源,保留允许的远程、相对或受控数据地址。
121
121
  * @param src - 待验证的图片候选地址。
122
+ * @param remoteImages - 是否允许需要网络请求的图片地址。
122
123
  * @returns 允许的图片地址,不安全或空输入返回空字符串。
123
124
  *
124
125
  * @example 模块内部上下文
@@ -126,12 +127,22 @@ export function isExternalLinkHref(href) {
126
127
  * const safe = sanitizeImageSrc('https://example.com/image.png')
127
128
  * ```
128
129
  */
129
- export function sanitizeImageSrc(src) {
130
+ export function sanitizeImageSrc(src, remoteImages = true) {
130
131
  const normalized = src?.trim() ?? '';
131
- return SAFE_IMAGE_SRC_REGEX.test(normalized)
132
+ return SAFE_IMAGE_SRC_REGEX.test(normalized) && (remoteImages || /^data:image\//i.test(normalized))
132
133
  ? normalized
133
134
  : '';
134
135
  }
136
+ /**
137
+ * 为被阻止的图片渲染已转义的替代文字。
138
+ * @example 模块内部上下文
139
+ * ```ts
140
+ * const placeholder = renderImagePlaceholder('图示')
141
+ * ```
142
+ */
143
+ export function renderImagePlaceholder(text) {
144
+ return `<span class="hai-md-image-placeholder">${escapeHtml(text)}</span>`;
145
+ }
135
146
  function sanitizeAlignValue(value) {
136
147
  const normalized = value?.trim().toLowerCase();
137
148
  return normalized && SAFE_ALIGN_VALUE_REGEX.test(normalized)
@@ -201,7 +212,7 @@ function readNextHtmlTag(source, startIndex) {
201
212
  }
202
213
  return null;
203
214
  }
204
- function readSanitizedAttributes(tagName, rawAttributes) {
215
+ function readSanitizedAttributes(tagName, rawAttributes, remoteImages) {
205
216
  const sanitized = {};
206
217
  for (const [attrName, attrValue] of parseHtmlAttributes(rawAttributes)) {
207
218
  if (tagName === 'a') {
@@ -215,7 +226,7 @@ function readSanitizedAttributes(tagName, rawAttributes) {
215
226
  }
216
227
  if (tagName === 'img') {
217
228
  if (attrName === 'src') {
218
- sanitized.src = sanitizeImageSrc(attrValue);
229
+ sanitized.src = sanitizeImageSrc(attrValue, remoteImages);
219
230
  }
220
231
  if (attrName === 'alt') {
221
232
  sanitized.alt = attrValue;
@@ -249,7 +260,7 @@ function readSanitizedAttributes(tagName, rawAttributes) {
249
260
  }
250
261
  return sanitized;
251
262
  }
252
- function sanitizeHtmlTag(rawTag) {
263
+ function sanitizeHtmlTag(rawTag, remoteImages) {
253
264
  if (!rawTag.startsWith('<') || !rawTag.endsWith('>')) {
254
265
  return escapeHtml(rawTag);
255
266
  }
@@ -284,7 +295,9 @@ function sanitizeHtmlTag(rawTag) {
284
295
  ? ''
285
296
  : `</${tagName}>`;
286
297
  }
287
- const attributes = readSanitizedAttributes(tagName, rawAttributes);
298
+ const attributes = readSanitizedAttributes(tagName, rawAttributes, remoteImages);
299
+ if (tagName === 'img' && !remoteImages && !attributes.src)
300
+ return renderImagePlaceholder(attributes.alt ?? '');
288
301
  const renderedAttributes = [];
289
302
  if (attributes.href !== undefined) {
290
303
  renderedAttributes.push(`href="${escapeHtml(attributes.href)}"`);
@@ -328,6 +341,7 @@ function sanitizeHtmlTag(rawTag) {
328
341
  * 消毒 Markdown 中嵌入的原始 HTML 片段。
329
342
  * 只重建白名单标签,其余内容保持转义。
330
343
  * @param fragment - 待消毒的 HTML 片段。
344
+ * @param remoteImages - 是否保留需要网络请求的图片地址。
331
345
  * @returns 仅保留白名单标签和安全属性的 HTML。
332
346
  *
333
347
  * @example 模块内部上下文
@@ -335,7 +349,7 @@ function sanitizeHtmlTag(rawTag) {
335
349
  * const safe = sanitizeMarkdownHtml('<p onclick="alert(1)">正文</p>')
336
350
  * ```
337
351
  */
338
- export function sanitizeMarkdownHtml(fragment) {
352
+ export function sanitizeMarkdownHtml(fragment, remoteImages = true) {
339
353
  if (!fragment) {
340
354
  return '';
341
355
  }
@@ -343,7 +357,7 @@ export function sanitizeMarkdownHtml(fragment) {
343
357
  let lastIndex = 0;
344
358
  for (let match = readNextHtmlTag(fragment, lastIndex); match; match = readNextHtmlTag(fragment, lastIndex)) {
345
359
  sanitized += escapeHtmlText(fragment.slice(lastIndex, match.start));
346
- sanitized += sanitizeHtmlTag(match.rawTag);
360
+ sanitized += sanitizeHtmlTag(match.rawTag, remoteImages);
347
361
  lastIndex = match.end;
348
362
  }
349
363
  sanitized += escapeHtmlText(fragment.slice(lastIndex));
@@ -419,6 +419,34 @@
419
419
  "form_pattern": "Enter a value in the required format.",
420
420
  "select_clear": "Clear selection",
421
421
  "select_no_match": "No matching options",
422
+ "schedule_input_mode": "Schedule input mode",
423
+ "schedule_input_mode_datetime": "Date and time",
424
+ "schedule_input_mode_cron": "Advanced Cron",
425
+ "schedule_input_date": "Date",
426
+ "schedule_input_hour": "Hour",
427
+ "schedule_input_minute": "Minute",
428
+ "schedule_input_timezone_hint": "Beijing Time (UTC+08:00)",
429
+ "schedule_input_timezone_explicit": "Time zone: {timezone}",
430
+ "schedule_input_cron_hint": "Enter minute, hour, day of month, month, and day of week.",
431
+ "schedule_input_cron_presets": "Presets",
432
+ "schedule_input_cron_mode_minute": "Every few minutes",
433
+ "schedule_input_cron_mode_hour": "Hourly",
434
+ "schedule_input_cron_mode_day": "Daily",
435
+ "schedule_input_cron_mode_week": "Weekly",
436
+ "schedule_input_cron_mode_month": "Monthly",
437
+ "schedule_input_cron_mode_custom": "Custom",
438
+ "schedule_input_cron_field_interval": "Interval (minutes)",
439
+ "schedule_input_cron_field_minute": "Minute",
440
+ "schedule_input_cron_field_time": "Time",
441
+ "schedule_input_cron_field_weekdays": "Weekdays",
442
+ "schedule_input_cron_field_month_day": "Day of month",
443
+ "schedule_input_cron_field_expression": "Cron expression",
444
+ "schedule_input_invalid_config": "This schedule input configuration is not supported.",
445
+ "schedule_input_required": "Choose a date and enter a time.",
446
+ "schedule_input_partial": "Complete the date, hour and minute.",
447
+ "schedule_input_invalid": "Enter a valid minute-precision date and time.",
448
+ "schedule_input_past": "The execution time must be in the future.",
449
+ "schedule_input_cron_invalid": "Enter a valid five-field Cron expression.",
422
450
  "feedback_optional_description": "A short description (optional)",
423
451
  "feedback_quick_hint": "You can submit now. Allowed diagnostic materials will be included.",
424
452
  "feedback_more": "More options",
@@ -419,6 +419,34 @@
419
419
  "form_pattern": "指定された形式で入力してください。",
420
420
  "select_clear": "選択をクリア",
421
421
  "select_no_match": "一致する選択肢がありません",
422
+ "schedule_input_mode": "スケジュール入力モード",
423
+ "schedule_input_mode_datetime": "日時",
424
+ "schedule_input_mode_cron": "高度な Cron",
425
+ "schedule_input_date": "日付",
426
+ "schedule_input_hour": "時",
427
+ "schedule_input_minute": "分",
428
+ "schedule_input_timezone_hint": "北京時間(UTC+08:00)",
429
+ "schedule_input_timezone_explicit": "タイムゾーン:{timezone}",
430
+ "schedule_input_cron_hint": "分、時、日、月、曜日の順で5フィールドを入力します。",
431
+ "schedule_input_cron_presets": "プリセット",
432
+ "schedule_input_cron_mode_minute": "数分ごと",
433
+ "schedule_input_cron_mode_hour": "毎時",
434
+ "schedule_input_cron_mode_day": "毎日",
435
+ "schedule_input_cron_mode_week": "毎週",
436
+ "schedule_input_cron_mode_month": "毎月",
437
+ "schedule_input_cron_mode_custom": "カスタム",
438
+ "schedule_input_cron_field_interval": "間隔(分)",
439
+ "schedule_input_cron_field_minute": "分",
440
+ "schedule_input_cron_field_time": "時刻",
441
+ "schedule_input_cron_field_weekdays": "曜日",
442
+ "schedule_input_cron_field_month_day": "月の日",
443
+ "schedule_input_cron_field_expression": "Cron 式",
444
+ "schedule_input_invalid_config": "このスケジュール入力設定はサポートされていません。",
445
+ "schedule_input_required": "日付を選択し、時刻を入力してください。",
446
+ "schedule_input_partial": "日付、時、分をすべて入力してください。",
447
+ "schedule_input_invalid": "分精度の有効な日時を入力してください。",
448
+ "schedule_input_past": "実行時刻は現在より後にしてください。",
449
+ "schedule_input_cron_invalid": "有効な5フィールド Cron 式を入力してください。",
422
450
  "feedback_optional_description": "簡単な説明(任意)",
423
451
  "feedback_quick_hint": "そのまま送信できます。許可された診断資料が添付されます。",
424
452
  "feedback_more": "その他のオプション",
@@ -419,6 +419,34 @@
419
419
  "form_pattern": "请按要求的格式填写。",
420
420
  "select_clear": "清空选择",
421
421
  "select_no_match": "无匹配选项",
422
+ "schedule_input_mode": "调度输入模式",
423
+ "schedule_input_mode_datetime": "日期与时间",
424
+ "schedule_input_mode_cron": "高级 Cron",
425
+ "schedule_input_date": "日期",
426
+ "schedule_input_hour": "小时",
427
+ "schedule_input_minute": "分钟",
428
+ "schedule_input_timezone_hint": "北京时间(UTC+08:00)",
429
+ "schedule_input_timezone_explicit": "时区:{timezone}",
430
+ "schedule_input_cron_hint": "按分钟、小时、日、月、星期的顺序输入五段表达式。",
431
+ "schedule_input_cron_presets": "预设",
432
+ "schedule_input_cron_mode_minute": "每隔几分钟",
433
+ "schedule_input_cron_mode_hour": "每小时",
434
+ "schedule_input_cron_mode_day": "每天",
435
+ "schedule_input_cron_mode_week": "每周",
436
+ "schedule_input_cron_mode_month": "每月",
437
+ "schedule_input_cron_mode_custom": "自定义",
438
+ "schedule_input_cron_field_interval": "间隔(分钟)",
439
+ "schedule_input_cron_field_minute": "分钟",
440
+ "schedule_input_cron_field_time": "时间",
441
+ "schedule_input_cron_field_weekdays": "星期",
442
+ "schedule_input_cron_field_month_day": "每月第几天",
443
+ "schedule_input_cron_field_expression": "Cron 表达式",
444
+ "schedule_input_invalid_config": "调度输入配置不受支持。",
445
+ "schedule_input_required": "请选择日期并填写时间。",
446
+ "schedule_input_partial": "请完整填写日期、小时和分钟。",
447
+ "schedule_input_invalid": "请输入有效的日期时间(分钟精度)。",
448
+ "schedule_input_past": "执行时间不能早于当前时间。",
449
+ "schedule_input_cron_invalid": "请输入有效的五段 Cron 表达式。",
422
450
  "feedback_optional_description": "一句话说明(可选)",
423
451
  "feedback_quick_hint": "可以直接提交。系统会附上允许收集的现场材料。",
424
452
  "feedback_more": "更多选项",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@h-ai/ui",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.33",
4
+ "version": "1.0.0-beta.35",
5
5
  "description": "Hai Framework UI component library for Svelte 5 Runes.",
6
6
  "license": "Apache-2.0",
7
7
  "svelte": "./dist/index.js",
@@ -43,6 +43,11 @@
43
43
  "svelte": "./dist/components/compounds/index.js",
44
44
  "import": "./dist/components/compounds/index.js"
45
45
  },
46
+ "./components/compounds/schedule-input": {
47
+ "types": "./dist/components/compounds/schedule-input-config.d.ts",
48
+ "svelte": "./dist/components/compounds/schedule-input-config.js",
49
+ "import": "./dist/components/compounds/schedule-input-config.js"
50
+ },
46
51
  "./components/index": {
47
52
  "types": "./dist/components/index.d.ts",
48
53
  "svelte": "./dist/components/index.js",
@@ -134,12 +139,13 @@
134
139
  "svelte": "^5.57.3"
135
140
  },
136
141
  "dependencies": {
137
- "@h-ai/core": "1.0.0-beta.33",
142
+ "@h-ai/core": "1.0.0-beta.35",
138
143
  "@internationalized/date": "^3.12.4",
139
144
  "@rrweb/replay": "^2.2.1",
140
145
  "@shikijs/langs": "^4.6.0",
141
146
  "altcha": "^3.5.0",
142
147
  "bits-ui": "^2.20.6",
148
+ "cron-parser": "5.6.1",
143
149
  "driver.js": "1.10.2",
144
150
  "html2canvas": "^1.4.1",
145
151
  "jspdf": "^4.2.1",