@xuda.io/xuda-worker-bundle 1.3.2692 → 1.3.2693

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 (2) hide show
  1. package/index.js +275 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2450,10 +2450,19 @@ func.runtime.render.get_tree_node_id = function (nodeP, pathP) {
2450
2450
  };
2451
2451
  func.runtime.render.get_tree_controls = function (attributes) {
2452
2452
  const attrs = attributes || {};
2453
+ const get_first_defined = function (keys) {
2454
+ for (let index = 0; index < keys.length; index++) {
2455
+ const key = keys[index];
2456
+ if (Object.prototype.hasOwnProperty.call(attrs, key)) {
2457
+ return attrs[key];
2458
+ }
2459
+ }
2460
+ return null;
2461
+ };
2453
2462
  return {
2454
- xu_for: attrs['xu-for'] || attrs['xu-exp:xu-for'] || null,
2455
- xu_if: attrs['xu-if'] || attrs['xu-exp:xu-if'] || null,
2456
- xu_render: attrs['xu-render'] || attrs['xu-exp:xu-render'] || null,
2463
+ xu_for: get_first_defined(['xu-for', 'xu-exp:xu-for']),
2464
+ xu_if: get_first_defined(['xu-if', 'xu-exp:xu-if']),
2465
+ xu_render: get_first_defined(['xu-render', 'xu-exp:xu-render']),
2457
2466
  };
2458
2467
  };
2459
2468
  func.runtime.render.get_tree_node_capabilities = async function (options) {
@@ -2642,6 +2651,269 @@ func.runtime.render.sanitize_tree_for_debug = function (treeP) {
2642
2651
  };
2643
2652
  func.runtime.render.serialize_tree = function (treeP, spacing = 2) {
2644
2653
  return JSON.stringify(func.runtime.render.sanitize_tree_for_debug(treeP), null, spacing);
2654
+ };
2655
+ func.runtime = func.runtime || {};
2656
+ func.runtime.ui = func.runtime.ui || {};
2657
+ func.runtime.render = func.runtime.render || {};
2658
+ func.runtime.widgets = func.runtime.widgets || {};
2659
+
2660
+ // Shared string-renderer helpers live here so headless/server runtimes can materialize the render tree without a DOM.
2661
+
2662
+ func.runtime.render.HTML_VOID_TAGS = func.runtime.render.HTML_VOID_TAGS || {
2663
+ area: true,
2664
+ base: true,
2665
+ br: true,
2666
+ col: true,
2667
+ embed: true,
2668
+ hr: true,
2669
+ img: true,
2670
+ input: true,
2671
+ link: true,
2672
+ meta: true,
2673
+ param: true,
2674
+ source: true,
2675
+ track: true,
2676
+ wbr: true,
2677
+ };
2678
+ func.runtime.render.escape_html = function (value) {
2679
+ return `${value ?? ''}`
2680
+ .replaceAll('&', '&amp;')
2681
+ .replaceAll('<', '&lt;')
2682
+ .replaceAll('>', '&gt;')
2683
+ .replaceAll('"', '&quot;')
2684
+ .replaceAll("'", '&#039;');
2685
+ };
2686
+ func.runtime.render.escape_html_attribute = function (value) {
2687
+ return func.runtime.render.escape_html(value);
2688
+ };
2689
+ func.runtime.render.is_html_void_tag = function (tag_name) {
2690
+ return !!func.runtime.render.HTML_VOID_TAGS[(tag_name || '').toLowerCase()];
2691
+ };
2692
+ func.runtime.render.is_falsey_render_value = function (value) {
2693
+ if (value === false || value === null || typeof value === 'undefined') {
2694
+ return true;
2695
+ }
2696
+ if (typeof value === 'number') {
2697
+ return value === 0;
2698
+ }
2699
+ if (typeof value === 'string') {
2700
+ const normalized = value.trim().toLowerCase();
2701
+ return normalized === '' || normalized === 'false' || normalized === '0' || normalized === 'null' || normalized === 'undefined' || normalized === 'off' || normalized === 'no';
2702
+ }
2703
+ return false;
2704
+ };
2705
+ func.runtime.render.should_render_tree_node = function (treeP) {
2706
+ const controls = treeP?.meta?.controls || {};
2707
+ if (controls.xu_if !== null && controls.xu_if !== undefined && func.runtime.render.is_falsey_render_value(controls.xu_if)) {
2708
+ return false;
2709
+ }
2710
+ if (controls.xu_render !== null && controls.xu_render !== undefined && func.runtime.render.is_falsey_render_value(controls.xu_render)) {
2711
+ return false;
2712
+ }
2713
+ return true;
2714
+ };
2715
+ func.runtime.render.is_tree_control_attribute = function (key) {
2716
+ if (!key) {
2717
+ return false;
2718
+ }
2719
+ return (
2720
+ key.startsWith('xu-exp:') ||
2721
+ key === 'xu-widget' ||
2722
+ key === 'xu-method' ||
2723
+ key === 'xu-for' ||
2724
+ key === 'xu-for-key' ||
2725
+ key === 'xu-for-val' ||
2726
+ key === 'xu-if' ||
2727
+ key === 'xu-render' ||
2728
+ key === 'xu-bind' ||
2729
+ key === 'xu-content' ||
2730
+ key === 'xu-text' ||
2731
+ key === 'xu-html' ||
2732
+ key === 'xu-show' ||
2733
+ key === 'xu-panel-program' ||
2734
+ key === 'xu-teleport'
2735
+ );
2736
+ };
2737
+ func.runtime.render.get_string_renderer_tag_name = function (treeP) {
2738
+ switch (treeP?.kind) {
2739
+ case 'widget':
2740
+ case 'single_view':
2741
+ case 'multi_view':
2742
+ case 'panel':
2743
+ case 'teleport':
2744
+ return 'div';
2745
+ case 'placeholder':
2746
+ return null;
2747
+ case 'text':
2748
+ return null;
2749
+ default:
2750
+ return treeP?.tagName || 'div';
2751
+ }
2752
+ };
2753
+ func.runtime.render.get_tree_terminal_content = function (treeP) {
2754
+ const attributes = treeP?.attributes || {};
2755
+ if (typeof attributes['xu-html'] !== 'undefined' && attributes['xu-html'] !== null) {
2756
+ return {
2757
+ value: `${attributes['xu-html']}`,
2758
+ mode: 'html',
2759
+ };
2760
+ }
2761
+ if (typeof attributes['xu-content'] !== 'undefined' && attributes['xu-content'] !== null) {
2762
+ return {
2763
+ value: `${attributes['xu-content']}`,
2764
+ mode: 'html',
2765
+ };
2766
+ }
2767
+ if (typeof attributes['xu-text'] !== 'undefined' && attributes['xu-text'] !== null) {
2768
+ return {
2769
+ value: `${attributes['xu-text']}`,
2770
+ mode: 'text',
2771
+ };
2772
+ }
2773
+ if (treeP?.kind === 'text') {
2774
+ return {
2775
+ value: typeof treeP?.text !== 'undefined' && treeP?.text !== null ? `${treeP.text}` : `${treeP?.content || ''}`,
2776
+ mode: 'text',
2777
+ };
2778
+ }
2779
+ return null;
2780
+ };
2781
+ func.runtime.render.render_tree_terminal_content = function (treeP) {
2782
+ const terminal = func.runtime.render.get_tree_terminal_content(treeP);
2783
+ if (!terminal) {
2784
+ return null;
2785
+ }
2786
+ if (terminal.mode === 'html') {
2787
+ return terminal.value;
2788
+ }
2789
+ return func.runtime.render.escape_html(terminal.value);
2790
+ };
2791
+ func.runtime.render.get_widget_fallback_markup = function (treeP) {
2792
+ const widget_meta = treeP?.meta?.widget || {};
2793
+ const capability_state = widget_meta?.capabilities?.headless ? 'headless-capable' : 'browser-only';
2794
+ return `<!--xuda-widget:${func.runtime.render.escape_html(widget_meta.plugin_name || 'unknown')}:${capability_state}-->`;
2795
+ };
2796
+ func.runtime.render.get_tree_string_attributes = function (treeP, renderer_context) {
2797
+ const attributes = func.runtime.render.safe_clone_tree_value(treeP?.attributes || {});
2798
+ const attr_pairs = [];
2799
+ const keys = Object.keys(attributes);
2800
+
2801
+ for (let index = 0; index < keys.length; index++) {
2802
+ const key = keys[index];
2803
+ if (func.runtime.render.is_tree_control_attribute(key)) {
2804
+ continue;
2805
+ }
2806
+ const value = attributes[key];
2807
+ if (value === false || value === null || typeof value === 'undefined') {
2808
+ continue;
2809
+ }
2810
+ if (value === true) {
2811
+ attr_pairs.push(key);
2812
+ continue;
2813
+ }
2814
+ const normalized_value = typeof value === 'object' ? JSON.stringify(value) : `${value}`;
2815
+ attr_pairs.push(`${key}="${func.runtime.render.escape_html_attribute(normalized_value)}"`);
2816
+ }
2817
+
2818
+ attr_pairs.push(`data-xuda-kind="${func.runtime.render.escape_html_attribute(treeP?.kind || 'element')}"`);
2819
+ attr_pairs.push(`data-xuda-node-id="${func.runtime.render.escape_html_attribute(treeP?.id || treeP?.meta?.source_node_id || '')}"`);
2820
+ attr_pairs.push(`data-xuda-tree-id="${func.runtime.render.escape_html_attribute(treeP?.meta?.tree_id || '')}"`);
2821
+
2822
+ if (treeP?.kind === 'widget' && treeP?.meta?.widget) {
2823
+ attr_pairs.push(`data-xuda-widget="${func.runtime.render.escape_html_attribute(treeP.meta.widget.plugin_name || '')}"`);
2824
+ attr_pairs.push(`data-xuda-widget-method="${func.runtime.render.escape_html_attribute(treeP.meta.widget.method || '_default')}"`);
2825
+ attr_pairs.push(`data-xuda-widget-capability="${func.runtime.render.escape_html_attribute(treeP.meta.widget.capabilities?.headless ? 'headless' : 'browser')}"`);
2826
+ }
2827
+
2828
+ if (treeP?.kind === 'teleport' && treeP?.attributes?.['xu-teleport']) {
2829
+ attr_pairs.push(`data-xuda-teleport-target="${func.runtime.render.escape_html_attribute(treeP.attributes['xu-teleport'])}"`);
2830
+ }
2831
+
2832
+ if ((treeP?.meta?.controls?.xu_for !== null && treeP?.meta?.controls?.xu_for !== undefined) && !renderer_context?.strip_iteration_markers) {
2833
+ attr_pairs.push('data-xuda-xu-for="pending"');
2834
+ }
2835
+
2836
+ return attr_pairs.length ? ' ' + attr_pairs.join(' ') : '';
2837
+ };
2838
+ func.runtime.render.render_tree_children_to_string = async function (treeP, renderer_context) {
2839
+ if (!Array.isArray(treeP?.children) || !treeP.children.length) {
2840
+ return '';
2841
+ }
2842
+ let html = '';
2843
+ for (let index = 0; index < treeP.children.length; index++) {
2844
+ html += await func.runtime.render.render_tree_to_string(treeP.children[index], {
2845
+ ...renderer_context,
2846
+ parent_tree: treeP,
2847
+ });
2848
+ }
2849
+ return html;
2850
+ };
2851
+ func.runtime.render.render_tree_to_string = async function (treeP, renderer_context = {}) {
2852
+ if (!treeP) {
2853
+ return '';
2854
+ }
2855
+ if (Array.isArray(treeP)) {
2856
+ let html = '';
2857
+ for (let index = 0; index < treeP.length; index++) {
2858
+ html += await func.runtime.render.render_tree_to_string(treeP[index], renderer_context);
2859
+ }
2860
+ return html;
2861
+ }
2862
+
2863
+ const ensured_tree = await func.runtime.render.ensure_tree_node({
2864
+ SESSION_ID: renderer_context?.SESSION_ID,
2865
+ nodeP: treeP,
2866
+ paramsP: renderer_context?.paramsP,
2867
+ parent_infoP: renderer_context?.parent_infoP,
2868
+ keyP: renderer_context?.keyP,
2869
+ parent_nodeP: renderer_context?.parent_nodeP,
2870
+ });
2871
+
2872
+ if (!ensured_tree || !func.runtime.render.should_render_tree_node(ensured_tree)) {
2873
+ return '';
2874
+ }
2875
+
2876
+ if (ensured_tree.kind === 'placeholder') {
2877
+ if (renderer_context?.include_placeholders) {
2878
+ return `<!--xuda-placeholder:${func.runtime.render.escape_html(ensured_tree.id || '')}-->`;
2879
+ }
2880
+ return '';
2881
+ }
2882
+
2883
+ if (ensured_tree.kind === 'text') {
2884
+ return func.runtime.render.render_tree_terminal_content(ensured_tree) || '';
2885
+ }
2886
+
2887
+ const tag_name = func.runtime.render.get_string_renderer_tag_name(ensured_tree);
2888
+ if (!tag_name || tag_name.toLowerCase() === 'script') {
2889
+ return '';
2890
+ }
2891
+
2892
+ const attributes = func.runtime.render.get_tree_string_attributes(ensured_tree, renderer_context);
2893
+ const terminal_content = func.runtime.render.render_tree_terminal_content(ensured_tree);
2894
+ let children_html = terminal_content !== null ? terminal_content : await func.runtime.render.render_tree_children_to_string(ensured_tree, renderer_context);
2895
+
2896
+ if (ensured_tree.kind === 'widget' && !children_html) {
2897
+ children_html = func.runtime.render.get_widget_fallback_markup(ensured_tree);
2898
+ }
2899
+
2900
+ if (func.runtime.render.is_html_void_tag(tag_name)) {
2901
+ return `<${tag_name}${attributes}>`;
2902
+ }
2903
+
2904
+ return `<${tag_name}${attributes}>${children_html}</${tag_name}>`;
2905
+ };
2906
+ func.runtime.render.render_to_string = async function (options = {}) {
2907
+ const treeP = await func.runtime.render.ensure_tree_node({
2908
+ SESSION_ID: options.SESSION_ID,
2909
+ nodeP: options.treeP || options.nodeP,
2910
+ paramsP: options.paramsP,
2911
+ parent_infoP: options.parent_infoP,
2912
+ keyP: options.keyP,
2913
+ parent_nodeP: options.parent_nodeP,
2914
+ });
2915
+
2916
+ return await func.runtime.render.render_tree_to_string(treeP, options);
2645
2917
  };
2646
2918
  glb.DEBUG_INFO_OBJ = {};
2647
2919
  // var CONNECTION_ATTEMPTS = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-worker-bundle",
3
- "version": "1.3.2692",
3
+ "version": "1.3.2693",
4
4
  "description": "xuda framework",
5
5
  "main": "index.js",
6
6
  "scripts": {