@hmg-report-editor/rules 1.0.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/dist/index.cjs +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +669 -0
- package/package.json +29 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function m(o){return JSON.stringify([o.editorId,o.controlId])}const Ie=/【\s*([^】]+?)\s*】/g,be="CONTROL_RULE_FAILED",Y=100;function ve(o={}){const l=new Map,i=new Map,a=new Map,c=new Map,f=new Map,g=new Map,h=[];let w=new Set,q=new Map,R=null,T=null,y=0,P=0;const S=new Set,re={name:"hmg-widget-rules",getCurrentBatchId:()=>h[h.length-1],runBatch(e){h.push(Ce());try{const t=e();if(ne(t))throw new Error("runBatch requires a synchronous operation.");return t}finally{h.pop(),h.length===0&&ie()}},runWithoutEvaluation(e){if(h.length>0)throw new Error("runWithoutEvaluation cannot run inside an active rules batch.");y+=1;try{const t=e();if(ne(t))throw new Error("runWithoutEvaluation requires a synchronous operation.");return t}finally{y-=1,y===0&&de()}},onEditorReady(e){l.set(e.editorId,e)},onEditorDestroyed(e){l.get(e.editorId)===e&&l.delete(e.editorId);for(const t of Array.from(i.values()))t.editorId===e.editorId&&A(t)},onControlAdded(e,t){$(e,t);const n=m(e);if(y>0){S.add(n);return}E(new Set([n]),t),_(e,t)},onControlRemoved(e,t){const n=t.getControl(e.controlId);if(n){A(e),$(n,t),y>0&&S.add(m(n));return}const r=y>0?new Set:D(e);if(A(e),y>0){S.delete(m(e));return}E(r,t)},onControlValueChanged(e,t){const n=m(e.current);if(i.set(n,e.current),oe(e.previous,e.current),y>0){g.delete(n),S.add(n);return}_(e.current,t)},onControlMetadataChanged(e,t){const n=y>0?new Set:D(e.previous);if(A(e.previous),$(e.current,t),y>0){S.add(m(e.current));return}E(new Set([m(e.current)]),t),_(e.current,t),E(n,t)}};function $(e,t){const n=m(e);i.set(n,e);const r=b(e);if(r&&U(r,n),C(e.attrs.rules).length===0)return;if(!e.attrs.templateId){I(t,"Rule control is missing templateId and will be skipped.",{control:e});return}if(!e.attrs.batchId){I(t,"Rule control is missing batchId and will be skipped.",{control:e});return}const s=we(e);f.set(n,s);for(const d of s){let p=c.get(d);p||(p=new Set,c.set(d,p)),p.add(n)}}function A(e){const t=m(e);i.delete(t),g.delete(t);const n=b(e);n&&L(n,t);const r=f.get(t);if(r)for(const u of r){const s=c.get(u);s==null||s.delete(t),(s==null?void 0:s.size)===0&&c.delete(u)}f.delete(t)}function D(e){const t=b(e);return t?new Set(c.get(t)??[]):new Set}function oe(e,t){const n=b(e),r=b(t);n&&n!==r&&L(n,m(e)),r&&U(r,m(t))}function U(e,t){let n=a.get(e);n||(n=new Set,a.set(e,n)),n.add(t)}function L(e,t){const n=a.get(e);n==null||n.delete(t),(n==null?void 0:n.size)===0&&a.delete(e)}function ue(e,t){const n=a.get(e);let r;for(const s of n??[]){const d=i.get(s),p=d?l.get(d.editorId)??((t==null?void 0:t.editorId)===d.editorId?t:void 0):void 0,N=d?p==null?void 0:p.getControl(d.controlId):void 0;N&&b(N)===e?(i.set(s,N),r=s):(i.delete(s),n==null||n.delete(s))}if((n==null?void 0:n.size)===0&&a.delete(e),r)return r;const u=new Set(l.values());t&&u.add(t);for(const s of u)for(const d of s.getControls())if(b(d)===e){const p=m(d);i.set(p,d),U(e,p),r=p}return r}function _(e,t){const n=b(e);if(!n)return;const r=c.get(n);r&&E(new Set(r),t,m(e))}function E(e,t,n){if(!(y>0||e.size===0)){if(h.length>0&&!T){for(const r of e)w.add(r);B(q,n,e),R??(R=t);return}j(e,t,n)}}function ie(){if(w.size===0||!R){w.clear(),q.clear(),R=null;return}const e=w,t=q,n=R;w=new Set,q=new Map,R=null,j(e,n,void 0,t)}function j(e,t,n,r){if(e.size===0)return;if(T){B(T.propagationEdges,n,e),J(T,e,t,n);return}const u={evaluatingTargetKeys:new Set,queuedTargetKeys:new Set,processedTargetKeys:new Set,pendingTargetKeys:[],propagationEdges:ae(r),processedCount:0};B(u.propagationEdges,n,e),T=u,J(u,e,t,n);try{se(u,t)}finally{T=null}}function J(e,t,n,r){for(const u of t){if(e.evaluatingTargetKeys.has(u)){r&&k(e.propagationEdges,u,r)&&G(n,u);continue}if(!e.queuedTargetKeys.has(u)){if(e.processedTargetKeys.has(u)&&r&&k(e.propagationEdges,u,r)){G(n,u);continue}e.queuedTargetKeys.add(u),e.pendingTargetKeys.push(u)}}}function se(e,t){for(;e.pendingTargetKeys.length>0;){if(e.processedCount>=Y){I(t,"Rule evaluation limit exceeded and propagation was stopped.",{maxRuleEvaluations:Y,pendingTargetKeys:[...e.pendingTargetKeys]}),e.pendingTargetKeys=[],e.queuedTargetKeys.clear();return}const n=e.pendingTargetKeys.shift();if(n){e.queuedTargetKeys.delete(n),e.evaluatingTargetKeys.add(n),e.processedTargetKeys.add(n),e.processedCount+=1;try{le(n,t)}finally{e.evaluatingTargetKeys.delete(n)}}}}function B(e,t,n){if(!t)return;let r=e.get(t);r||(r=new Set,e.set(t,r));for(const u of n)r.add(u)}function ae(e){const t=new Map;for(const[n,r]of e??[])t.set(n,new Set(r));return t}function k(e,t,n){if(t===n)return!0;const r=[t],u=new Set;for(;r.length>0;){const s=r.pop();if(!(!s||u.has(s))){u.add(s);for(const d of e.get(s)??[]){if(d===n)return!0;u.has(d)||r.push(d)}}}return!1}function G(e,t){const n=i.get(t);I(e,"Rule cycle detected and skipped.",{editorId:n==null?void 0:n.editorId,controlId:n==null?void 0:n.controlId})}function le(e,t){const n=i.get(e);if(!n)return;const r=l.get(n.editorId)??(t.editorId===n.editorId?t:void 0),u=r==null?void 0:r.getControl(n.controlId);if(!r||!u)return;i.set(e,u);const s=C(u.attrs.rules);if(s.length===0)return;if(!u.attrs.templateId){I(r,"Rule target is missing templateId and will be skipped.",{target:u});return}if(!u.attrs.batchId){I(r,"Rule target is missing batchId and will be skipped.",{target:u});return}const d=Q(u,s,r);if(d){const p=d.value;r.updateControlAttrs(u.controlId,{value:p,ruleStyleColor:d.ruleStyleColor})&&g.set(e,p);return}if(u.attrs.noMatchDefault&&me(u)){const p=u.attrs.defaultValue??"";r.updateControlAttrs(u.controlId,{value:p,ruleStyleColor:null})&&g.set(e,p)}}function Q(e,t,n){let r=null;for(const u of t)for(const s of O(u)){if(!ce(e,s,n))continue;const d=fe(e,s,n);if(d!==null){r=d;break}}return r}function de(){P+=1;try{for(const e of S){const t=i.get(e);if(!t)continue;const n=l.get(t.editorId),r=n==null?void 0:n.getControl(t.controlId);if(!n||!r||!r.attrs.templateId||!r.attrs.batchId)continue;const u=C(r.attrs.rules);if(u.length===0)continue;const s=Q(r,u,n);s&&M(s.value)===M(r.attrs.value)&&g.set(e,s.value)}}finally{P-=1,S.clear()}}function ce(e,t,n){for(const r of Z(t))try{const u=pe(e,r,n);if(!he(u,r))return!1}catch(u){return I(n,"Rule premise failed and was skipped.",{target:e,premise:r,error:u}),!1}return!0}function fe(e,t,n){try{const r=t.result,u=r.type==="math"?ge(e,r,n):r.value,s=!!(r.style??r.bStyle);return{value:u,ruleStyleColor:s&&r.styleValue?r.styleValue:null}}catch(r){return I(n,"Rule result failed and was skipped.",{target:e,content:t,error:r}),null}}function pe(e,t,n){if(t.entryType==="math")return String(ee(X(e,t.inputSerialMath,n)));const r=K(t.inputSerialMath)[0];if(!r)throw new Error(`Rule premise has no widget reference: ${t.inputSerialMath}.`);return M(H(e,r,n))}function ge(e,t,n){const r=ee(X(e,t.value,n)),u=Re(t.exactType),s=t.exact?Math.max(0,Number(t.exactNum??0)):Math.max(0,15-Math.trunc(Math.abs(r)).toString().length);return String(Ee(r,u,s))}function X(e,t,n){const r=K(t);let u=t;for(const s of r){const d=H(e,s,n),p=v(d);if(p===null)throw new Error(`Referenced widget ${s} is not a number.`);u=u.replace(new RegExp(`【\\s*${Me(s)}\\s*】`,"g"),String(p))}return u}function H(e,t,n){const r=z(e.attrs.templateId,e.attrs.batchId,t),u=r?ue(r,n):void 0,s=u?i.get(u):void 0;if(!s)throw I(n,"Referenced rule control was not found.",{target:e,widgetNumber:t,templateId:e.attrs.templateId,batchId:e.attrs.batchId}),new Error(`Referenced widget not found: ${t}.`);return s.attrs.value}function he(e,t){const n=Te(t.condition),r=t.conditionDes??"",u=t.conditionRange??{};switch(n){case"inOption":return V(r,e);case"notInOption":return!V(r,e);case"inRange":return x(e,u);case"notInRange":return!x(e,u);case"empty":return e==="";case"notEmpty":return e!=="";case"include":return e.includes(r);case"notInclude":return!e.includes(r);case"=":return e===String(r);case"≠":return e!==String(r);case"greater":return F(e,r,(s,d)=>s>d);case"greaterEqual":return F(e,r,(s,d)=>s>=d);case"less":return F(e,r,(s,d)=>s<d);case"lessEqual":return F(e,r,(s,d)=>s<=d);case"isNumber":return v(e)!==null;case"isNotNumber":return v(e)===null;default:return!1}}function me(e){const t=M(e.attrs.value),n=m(e);return t===""||g.has(n)&&t===M(g.get(n))?!0:ye(e).has(t)}function ye(e){const t=new Set;for(const n of C(e.attrs.rules))for(const r of O(n))r.result.type!=="math"&&t.add(String(r.result.value??""));return t}function we(e){const t=new Set;for(const n of C(e.attrs.rules))for(const r of O(n)){for(const u of Z(r))for(const s of K(u.inputSerialMath)){const d=z(e.attrs.templateId,e.attrs.batchId,s);d&&t.add(d)}if(r.result.type==="math")for(const u of K(r.result.value)){const s=z(e.attrs.templateId,e.attrs.batchId,u);s&&t.add(s)}}return t}function I(e,t,n){var r;P>0||(e.warn(be,t,n),(r=o.onWarning)==null||r.call(o,{message:t,detail:n}))}return re}function C(o){return Array.isArray(o)?o:[]}function O(o){return o.contents??o.list??[]}function Z(o){return o.premises??o.premiss??[]}function K(o){return Array.from(o.matchAll(Ie),l=>l[1].trim()).filter(Boolean)}function b(o){return z(o.attrs.templateId,o.attrs.batchId,o.attrs.widgetNumber)}function z(o,l,i){const a=W(o),c=W(l),f=Se(i);if(!(!a||!c||!f))return`${a}_${c}_${f}`}function W(o){return o==null?void 0:String(o).trim()||void 0}function Se(o){const l=W(o);if(!l)return;const i=l.match(/^【\s*([^】]+?)\s*】$/);return((i==null?void 0:i[1])??l).trim()||void 0}function Te(o){switch(o){case">":return"greater";case">=":return"greaterEqual";case"<":return"less";case"<=":return"lessEqual";default:return o}}function M(o){return o==null?"":String(o)}function V(o,l){if(Array.isArray(o))return o.map(i=>String(i)).includes(l);if(typeof o=="string"){const i=o.trim();if(i.startsWith("["))try{const a=JSON.parse(i);return Array.isArray(a)&&a.map(c=>String(c)).includes(l)}catch{return o.includes(l)}return o.includes(l)}return!1}function x(o,l){const i=v(o),a=v(l.number1),c=v(l.number2);if(i===null||a===null||c===null)return!1;const f=l.symbol1??"greaterEqual",g=l.symbol2??"lessEqual",h=f==="greater"?i>a:i>=a,w=g==="less"?i<c:i<=c;return h&&w}function F(o,l,i){const a=v(o),c=v(l);return a!==null&&c!==null&&i(a,c)}function v(o){if(o==null||typeof o=="string"&&o.trim()==="")return null;const l=Number(o);return Number.isFinite(l)?l:null}function Re(o){return o==="2"||o==="3"?o:"1"}function Ee(o,l,i){const a=10**i;switch(l){case"2":return Math.ceil(o*a)/a;case"3":return Math.floor(o*a)/a;default:return Math.round(o*a)/a}}function ee(o){const l=Ne(o),i=[],a=[],c=()=>{const f=a.pop();if(!f)throw new Error("Formula operator stack is empty.");if(f==="u-"){const w=i.pop();if(w===void 0)throw new Error("Formula unary operand is missing.");i.push(-w);return}const g=i.pop(),h=i.pop();if(h===void 0||g===void 0)throw new Error("Formula operand is missing.");switch(f){case"+":i.push(h+g);return;case"-":i.push(h-g);return;case"*":i.push(h*g);return;case"/":i.push(h/g);return;default:throw new Error(`Unsupported formula operator: ${f}.`)}};for(const f of l){if(typeof f=="number"){i.push(f);continue}if(f==="("){a.push(f);continue}if(f===")"){for(;a.length>0&&a[a.length-1]!=="(";)c();if(a.pop()!=="(")throw new Error("Formula parentheses are not balanced.");continue}for(;a.length>0&&a[a.length-1]!=="("&&te(a[a.length-1])>=te(f);)c();a.push(f)}for(;a.length>0;){if(a[a.length-1]==="(")throw new Error("Formula parentheses are not balanced.");c()}if(i.length!==1||!Number.isFinite(i[0]))throw new Error("Formula result is invalid.");return i[0]}function Ne(o){const l=[];let i=0,a;for(;i<o.length;){const c=o[i];if(/\s/.test(c)){i+=1;continue}if(c==="("||c===")"){l.push(c),a=c,i+=1;continue}if("+-*/".includes(c)){const h=c==="-"&&(a===void 0||typeof a=="string"&&a!==")");l.push(h?"u-":c),a=h?"u-":c,i+=1;continue}const f=o.slice(i).match(/^\d+(?:\.\d+)?|^\.\d+/);if(!f)throw new Error(`Formula contains unsupported token near: ${o.slice(i)}.`);const g=Number(f[0]);if(!Number.isFinite(g))throw new Error(`Formula number is invalid: ${f[0]}.`);l.push(g),a=g,i+=f[0].length}return l}function te(o){return o==="u-"?3:o==="*"||o==="/"?2:o==="+"||o==="-"?1:0}function Ce(){const o=globalThis.crypto;return o!=null&&o.randomUUID?`batch_${o.randomUUID()}`:`batch_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`}function ne(o){return(typeof o=="object"||typeof o=="function")&&o!==null&&"then"in o&&typeof o.then=="function"}function Me(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}exports.createWidgetRulesPlugin=ve;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ReportControlAttrs, ReportControlPlugin, ReportControlRule, ReportControlRuleContent, ReportControlRulePremise, ReportControlRuleResult } from '@hmg-report-editor/core';
|
|
2
|
+
export type WidgetRulePremise = ReportControlRulePremise;
|
|
3
|
+
export type WidgetRuleResult = ReportControlRuleResult;
|
|
4
|
+
export type WidgetRuleContent = ReportControlRuleContent;
|
|
5
|
+
export type WidgetRule = ReportControlRule;
|
|
6
|
+
export type RuleControlAttrs = ReportControlAttrs & {
|
|
7
|
+
templateId: string;
|
|
8
|
+
batchId: string;
|
|
9
|
+
widgetNumber?: string;
|
|
10
|
+
rules?: WidgetRule[];
|
|
11
|
+
};
|
|
12
|
+
export type WidgetRulesPluginOptions = {
|
|
13
|
+
onWarning?: (warning: {
|
|
14
|
+
message: string;
|
|
15
|
+
detail?: unknown;
|
|
16
|
+
}) => void;
|
|
17
|
+
};
|
|
18
|
+
type SynchronousResult<T> = T extends PromiseLike<unknown> ? never : T;
|
|
19
|
+
export type WidgetRulesPlugin = ReportControlPlugin & {
|
|
20
|
+
runBatch<T>(operation: () => SynchronousResult<T>): SynchronousResult<T>;
|
|
21
|
+
runWithoutEvaluation<T>(operation: () => SynchronousResult<T>): SynchronousResult<T>;
|
|
22
|
+
};
|
|
23
|
+
/** 创建结构化控件规则插件。 */
|
|
24
|
+
export declare function createWidgetRulesPlugin(options?: WidgetRulesPluginOptions): WidgetRulesPlugin;
|
|
25
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
function m(o) {
|
|
2
|
+
return JSON.stringify([o.editorId, o.controlId]);
|
|
3
|
+
}
|
|
4
|
+
const Ie = /【\s*([^】]+?)\s*】/g, be = "CONTROL_RULE_FAILED", Y = 100;
|
|
5
|
+
function Me(o = {}) {
|
|
6
|
+
const l = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), h = [];
|
|
7
|
+
let w = /* @__PURE__ */ new Set(), q = /* @__PURE__ */ new Map(), E = null, T = null, y = 0, P = 0;
|
|
8
|
+
const S = /* @__PURE__ */ new Set(), re = {
|
|
9
|
+
name: "hmg-widget-rules",
|
|
10
|
+
getCurrentBatchId: () => h[h.length - 1],
|
|
11
|
+
runBatch(e) {
|
|
12
|
+
h.push(Ne());
|
|
13
|
+
try {
|
|
14
|
+
const t = e();
|
|
15
|
+
if (ne(t))
|
|
16
|
+
throw new Error("runBatch requires a synchronous operation.");
|
|
17
|
+
return t;
|
|
18
|
+
} finally {
|
|
19
|
+
h.pop(), h.length === 0 && se();
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
runWithoutEvaluation(e) {
|
|
23
|
+
if (h.length > 0)
|
|
24
|
+
throw new Error("runWithoutEvaluation cannot run inside an active rules batch.");
|
|
25
|
+
y += 1;
|
|
26
|
+
try {
|
|
27
|
+
const t = e();
|
|
28
|
+
if (ne(t))
|
|
29
|
+
throw new Error("runWithoutEvaluation requires a synchronous operation.");
|
|
30
|
+
return t;
|
|
31
|
+
} finally {
|
|
32
|
+
y -= 1, y === 0 && de();
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
onEditorReady(e) {
|
|
36
|
+
l.set(e.editorId, e);
|
|
37
|
+
},
|
|
38
|
+
onEditorDestroyed(e) {
|
|
39
|
+
l.get(e.editorId) === e && l.delete(e.editorId);
|
|
40
|
+
for (const t of Array.from(s.values()))
|
|
41
|
+
t.editorId === e.editorId && A(t);
|
|
42
|
+
},
|
|
43
|
+
onControlAdded(e, t) {
|
|
44
|
+
$(e, t);
|
|
45
|
+
const n = m(e);
|
|
46
|
+
if (y > 0) {
|
|
47
|
+
S.add(n);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
R(/* @__PURE__ */ new Set([n]), t), _(e, t);
|
|
51
|
+
},
|
|
52
|
+
onControlRemoved(e, t) {
|
|
53
|
+
const n = t.getControl(e.controlId);
|
|
54
|
+
if (n) {
|
|
55
|
+
A(e), $(n, t), y > 0 && S.add(m(n));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const r = y > 0 ? /* @__PURE__ */ new Set() : W(e);
|
|
59
|
+
if (A(e), y > 0) {
|
|
60
|
+
S.delete(m(e));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
R(r, t);
|
|
64
|
+
},
|
|
65
|
+
onControlValueChanged(e, t) {
|
|
66
|
+
const n = m(e.current);
|
|
67
|
+
if (s.set(n, e.current), oe(e.previous, e.current), y > 0) {
|
|
68
|
+
g.delete(n), S.add(n);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
_(e.current, t);
|
|
72
|
+
},
|
|
73
|
+
onControlMetadataChanged(e, t) {
|
|
74
|
+
const n = y > 0 ? /* @__PURE__ */ new Set() : W(e.previous);
|
|
75
|
+
if (A(e.previous), $(e.current, t), y > 0) {
|
|
76
|
+
S.add(m(e.current));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
R(/* @__PURE__ */ new Set([m(e.current)]), t), _(e.current, t), R(n, t);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
function $(e, t) {
|
|
83
|
+
const n = m(e);
|
|
84
|
+
s.set(n, e);
|
|
85
|
+
const r = b(e);
|
|
86
|
+
if (r && U(r, n), C(e.attrs.rules).length === 0)
|
|
87
|
+
return;
|
|
88
|
+
if (!e.attrs.templateId) {
|
|
89
|
+
I(t, "Rule control is missing templateId and will be skipped.", { control: e });
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (!e.attrs.batchId) {
|
|
93
|
+
I(t, "Rule control is missing batchId and will be skipped.", { control: e });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const i = we(e);
|
|
97
|
+
f.set(n, i);
|
|
98
|
+
for (const d of i) {
|
|
99
|
+
let p = c.get(d);
|
|
100
|
+
p || (p = /* @__PURE__ */ new Set(), c.set(d, p)), p.add(n);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function A(e) {
|
|
104
|
+
const t = m(e);
|
|
105
|
+
s.delete(t), g.delete(t);
|
|
106
|
+
const n = b(e);
|
|
107
|
+
n && L(n, t);
|
|
108
|
+
const r = f.get(t);
|
|
109
|
+
if (r)
|
|
110
|
+
for (const u of r) {
|
|
111
|
+
const i = c.get(u);
|
|
112
|
+
i == null || i.delete(t), (i == null ? void 0 : i.size) === 0 && c.delete(u);
|
|
113
|
+
}
|
|
114
|
+
f.delete(t);
|
|
115
|
+
}
|
|
116
|
+
function W(e) {
|
|
117
|
+
const t = b(e);
|
|
118
|
+
return t ? new Set(c.get(t) ?? []) : /* @__PURE__ */ new Set();
|
|
119
|
+
}
|
|
120
|
+
function oe(e, t) {
|
|
121
|
+
const n = b(e), r = b(t);
|
|
122
|
+
n && n !== r && L(n, m(e)), r && U(r, m(t));
|
|
123
|
+
}
|
|
124
|
+
function U(e, t) {
|
|
125
|
+
let n = a.get(e);
|
|
126
|
+
n || (n = /* @__PURE__ */ new Set(), a.set(e, n)), n.add(t);
|
|
127
|
+
}
|
|
128
|
+
function L(e, t) {
|
|
129
|
+
const n = a.get(e);
|
|
130
|
+
n == null || n.delete(t), (n == null ? void 0 : n.size) === 0 && a.delete(e);
|
|
131
|
+
}
|
|
132
|
+
function ue(e, t) {
|
|
133
|
+
const n = a.get(e);
|
|
134
|
+
let r;
|
|
135
|
+
for (const i of n ?? []) {
|
|
136
|
+
const d = s.get(i), p = d ? l.get(d.editorId) ?? ((t == null ? void 0 : t.editorId) === d.editorId ? t : void 0) : void 0, N = d ? p == null ? void 0 : p.getControl(d.controlId) : void 0;
|
|
137
|
+
N && b(N) === e ? (s.set(i, N), r = i) : (s.delete(i), n == null || n.delete(i));
|
|
138
|
+
}
|
|
139
|
+
if ((n == null ? void 0 : n.size) === 0 && a.delete(e), r)
|
|
140
|
+
return r;
|
|
141
|
+
const u = new Set(l.values());
|
|
142
|
+
t && u.add(t);
|
|
143
|
+
for (const i of u)
|
|
144
|
+
for (const d of i.getControls())
|
|
145
|
+
if (b(d) === e) {
|
|
146
|
+
const p = m(d);
|
|
147
|
+
s.set(p, d), U(e, p), r = p;
|
|
148
|
+
}
|
|
149
|
+
return r;
|
|
150
|
+
}
|
|
151
|
+
function _(e, t) {
|
|
152
|
+
const n = b(e);
|
|
153
|
+
if (!n)
|
|
154
|
+
return;
|
|
155
|
+
const r = c.get(n);
|
|
156
|
+
r && R(new Set(r), t, m(e));
|
|
157
|
+
}
|
|
158
|
+
function R(e, t, n) {
|
|
159
|
+
if (!(y > 0 || e.size === 0)) {
|
|
160
|
+
if (h.length > 0 && !T) {
|
|
161
|
+
for (const r of e)
|
|
162
|
+
w.add(r);
|
|
163
|
+
B(q, n, e), E ?? (E = t);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
j(e, t, n);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function se() {
|
|
170
|
+
if (w.size === 0 || !E) {
|
|
171
|
+
w.clear(), q.clear(), E = null;
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const e = w, t = q, n = E;
|
|
175
|
+
w = /* @__PURE__ */ new Set(), q = /* @__PURE__ */ new Map(), E = null, j(e, n, void 0, t);
|
|
176
|
+
}
|
|
177
|
+
function j(e, t, n, r) {
|
|
178
|
+
if (e.size === 0)
|
|
179
|
+
return;
|
|
180
|
+
if (T) {
|
|
181
|
+
B(T.propagationEdges, n, e), J(T, e, t, n);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const u = {
|
|
185
|
+
evaluatingTargetKeys: /* @__PURE__ */ new Set(),
|
|
186
|
+
queuedTargetKeys: /* @__PURE__ */ new Set(),
|
|
187
|
+
processedTargetKeys: /* @__PURE__ */ new Set(),
|
|
188
|
+
pendingTargetKeys: [],
|
|
189
|
+
propagationEdges: ae(r),
|
|
190
|
+
processedCount: 0
|
|
191
|
+
};
|
|
192
|
+
B(u.propagationEdges, n, e), T = u, J(u, e, t, n);
|
|
193
|
+
try {
|
|
194
|
+
ie(u, t);
|
|
195
|
+
} finally {
|
|
196
|
+
T = null;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function J(e, t, n, r) {
|
|
200
|
+
for (const u of t) {
|
|
201
|
+
if (e.evaluatingTargetKeys.has(u)) {
|
|
202
|
+
r && k(e.propagationEdges, u, r) && G(n, u);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (!e.queuedTargetKeys.has(u)) {
|
|
206
|
+
if (e.processedTargetKeys.has(u) && r && k(e.propagationEdges, u, r)) {
|
|
207
|
+
G(n, u);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
e.queuedTargetKeys.add(u), e.pendingTargetKeys.push(u);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function ie(e, t) {
|
|
215
|
+
for (; e.pendingTargetKeys.length > 0; ) {
|
|
216
|
+
if (e.processedCount >= Y) {
|
|
217
|
+
I(t, "Rule evaluation limit exceeded and propagation was stopped.", {
|
|
218
|
+
maxRuleEvaluations: Y,
|
|
219
|
+
pendingTargetKeys: [...e.pendingTargetKeys]
|
|
220
|
+
}), e.pendingTargetKeys = [], e.queuedTargetKeys.clear();
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const n = e.pendingTargetKeys.shift();
|
|
224
|
+
if (n) {
|
|
225
|
+
e.queuedTargetKeys.delete(n), e.evaluatingTargetKeys.add(n), e.processedTargetKeys.add(n), e.processedCount += 1;
|
|
226
|
+
try {
|
|
227
|
+
le(n, t);
|
|
228
|
+
} finally {
|
|
229
|
+
e.evaluatingTargetKeys.delete(n);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function B(e, t, n) {
|
|
235
|
+
if (!t)
|
|
236
|
+
return;
|
|
237
|
+
let r = e.get(t);
|
|
238
|
+
r || (r = /* @__PURE__ */ new Set(), e.set(t, r));
|
|
239
|
+
for (const u of n)
|
|
240
|
+
r.add(u);
|
|
241
|
+
}
|
|
242
|
+
function ae(e) {
|
|
243
|
+
const t = /* @__PURE__ */ new Map();
|
|
244
|
+
for (const [n, r] of e ?? [])
|
|
245
|
+
t.set(n, new Set(r));
|
|
246
|
+
return t;
|
|
247
|
+
}
|
|
248
|
+
function k(e, t, n) {
|
|
249
|
+
if (t === n)
|
|
250
|
+
return !0;
|
|
251
|
+
const r = [t], u = /* @__PURE__ */ new Set();
|
|
252
|
+
for (; r.length > 0; ) {
|
|
253
|
+
const i = r.pop();
|
|
254
|
+
if (!(!i || u.has(i))) {
|
|
255
|
+
u.add(i);
|
|
256
|
+
for (const d of e.get(i) ?? []) {
|
|
257
|
+
if (d === n)
|
|
258
|
+
return !0;
|
|
259
|
+
u.has(d) || r.push(d);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return !1;
|
|
264
|
+
}
|
|
265
|
+
function G(e, t) {
|
|
266
|
+
const n = s.get(t);
|
|
267
|
+
I(e, "Rule cycle detected and skipped.", {
|
|
268
|
+
editorId: n == null ? void 0 : n.editorId,
|
|
269
|
+
controlId: n == null ? void 0 : n.controlId
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
function le(e, t) {
|
|
273
|
+
const n = s.get(e);
|
|
274
|
+
if (!n)
|
|
275
|
+
return;
|
|
276
|
+
const r = l.get(n.editorId) ?? (t.editorId === n.editorId ? t : void 0), u = r == null ? void 0 : r.getControl(n.controlId);
|
|
277
|
+
if (!r || !u)
|
|
278
|
+
return;
|
|
279
|
+
s.set(e, u);
|
|
280
|
+
const i = C(u.attrs.rules);
|
|
281
|
+
if (i.length === 0)
|
|
282
|
+
return;
|
|
283
|
+
if (!u.attrs.templateId) {
|
|
284
|
+
I(r, "Rule target is missing templateId and will be skipped.", { target: u });
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (!u.attrs.batchId) {
|
|
288
|
+
I(r, "Rule target is missing batchId and will be skipped.", { target: u });
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const d = Q(u, i, r);
|
|
292
|
+
if (d) {
|
|
293
|
+
const p = d.value;
|
|
294
|
+
r.updateControlAttrs(u.controlId, {
|
|
295
|
+
value: p,
|
|
296
|
+
ruleStyleColor: d.ruleStyleColor
|
|
297
|
+
}) && g.set(e, p);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (u.attrs.noMatchDefault && me(u)) {
|
|
301
|
+
const p = u.attrs.defaultValue ?? "";
|
|
302
|
+
r.updateControlAttrs(u.controlId, {
|
|
303
|
+
value: p,
|
|
304
|
+
ruleStyleColor: null
|
|
305
|
+
}) && g.set(e, p);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function Q(e, t, n) {
|
|
309
|
+
let r = null;
|
|
310
|
+
for (const u of t)
|
|
311
|
+
for (const i of D(u)) {
|
|
312
|
+
if (!ce(e, i, n))
|
|
313
|
+
continue;
|
|
314
|
+
const d = fe(e, i, n);
|
|
315
|
+
if (d !== null) {
|
|
316
|
+
r = d;
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return r;
|
|
321
|
+
}
|
|
322
|
+
function de() {
|
|
323
|
+
P += 1;
|
|
324
|
+
try {
|
|
325
|
+
for (const e of S) {
|
|
326
|
+
const t = s.get(e);
|
|
327
|
+
if (!t)
|
|
328
|
+
continue;
|
|
329
|
+
const n = l.get(t.editorId), r = n == null ? void 0 : n.getControl(t.controlId);
|
|
330
|
+
if (!n || !r || !r.attrs.templateId || !r.attrs.batchId)
|
|
331
|
+
continue;
|
|
332
|
+
const u = C(r.attrs.rules);
|
|
333
|
+
if (u.length === 0)
|
|
334
|
+
continue;
|
|
335
|
+
const i = Q(r, u, n);
|
|
336
|
+
i && M(i.value) === M(r.attrs.value) && g.set(e, i.value);
|
|
337
|
+
}
|
|
338
|
+
} finally {
|
|
339
|
+
P -= 1, S.clear();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function ce(e, t, n) {
|
|
343
|
+
for (const r of Z(t))
|
|
344
|
+
try {
|
|
345
|
+
const u = pe(e, r, n);
|
|
346
|
+
if (!he(u, r))
|
|
347
|
+
return !1;
|
|
348
|
+
} catch (u) {
|
|
349
|
+
return I(n, "Rule premise failed and was skipped.", { target: e, premise: r, error: u }), !1;
|
|
350
|
+
}
|
|
351
|
+
return !0;
|
|
352
|
+
}
|
|
353
|
+
function fe(e, t, n) {
|
|
354
|
+
try {
|
|
355
|
+
const r = t.result, u = r.type === "math" ? ge(e, r, n) : r.value, i = !!(r.style ?? r.bStyle);
|
|
356
|
+
return {
|
|
357
|
+
value: u,
|
|
358
|
+
ruleStyleColor: i && r.styleValue ? r.styleValue : null
|
|
359
|
+
};
|
|
360
|
+
} catch (r) {
|
|
361
|
+
return I(n, "Rule result failed and was skipped.", { target: e, content: t, error: r }), null;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function pe(e, t, n) {
|
|
365
|
+
if (t.entryType === "math")
|
|
366
|
+
return String(ee(X(e, t.inputSerialMath, n)));
|
|
367
|
+
const r = K(t.inputSerialMath)[0];
|
|
368
|
+
if (!r)
|
|
369
|
+
throw new Error(`Rule premise has no widget reference: ${t.inputSerialMath}.`);
|
|
370
|
+
return M(H(e, r, n));
|
|
371
|
+
}
|
|
372
|
+
function ge(e, t, n) {
|
|
373
|
+
const r = ee(X(e, t.value, n)), u = Te(t.exactType), i = t.exact ? Math.max(0, Number(t.exactNum ?? 0)) : Math.max(0, 15 - Math.trunc(Math.abs(r)).toString().length);
|
|
374
|
+
return String(Ee(r, u, i));
|
|
375
|
+
}
|
|
376
|
+
function X(e, t, n) {
|
|
377
|
+
const r = K(t);
|
|
378
|
+
let u = t;
|
|
379
|
+
for (const i of r) {
|
|
380
|
+
const d = H(e, i, n), p = v(d);
|
|
381
|
+
if (p === null)
|
|
382
|
+
throw new Error(`Referenced widget ${i} is not a number.`);
|
|
383
|
+
u = u.replace(new RegExp(`【\\s*${Ce(i)}\\s*】`, "g"), String(p));
|
|
384
|
+
}
|
|
385
|
+
return u;
|
|
386
|
+
}
|
|
387
|
+
function H(e, t, n) {
|
|
388
|
+
const r = z(e.attrs.templateId, e.attrs.batchId, t), u = r ? ue(r, n) : void 0, i = u ? s.get(u) : void 0;
|
|
389
|
+
if (!i)
|
|
390
|
+
throw I(n, "Referenced rule control was not found.", {
|
|
391
|
+
target: e,
|
|
392
|
+
widgetNumber: t,
|
|
393
|
+
templateId: e.attrs.templateId,
|
|
394
|
+
batchId: e.attrs.batchId
|
|
395
|
+
}), new Error(`Referenced widget not found: ${t}.`);
|
|
396
|
+
return i.attrs.value;
|
|
397
|
+
}
|
|
398
|
+
function he(e, t) {
|
|
399
|
+
const n = Se(t.condition), r = t.conditionDes ?? "", u = t.conditionRange ?? {};
|
|
400
|
+
switch (n) {
|
|
401
|
+
case "inOption":
|
|
402
|
+
return V(r, e);
|
|
403
|
+
case "notInOption":
|
|
404
|
+
return !V(r, e);
|
|
405
|
+
case "inRange":
|
|
406
|
+
return x(e, u);
|
|
407
|
+
case "notInRange":
|
|
408
|
+
return !x(e, u);
|
|
409
|
+
case "empty":
|
|
410
|
+
return e === "";
|
|
411
|
+
case "notEmpty":
|
|
412
|
+
return e !== "";
|
|
413
|
+
case "include":
|
|
414
|
+
return e.includes(r);
|
|
415
|
+
case "notInclude":
|
|
416
|
+
return !e.includes(r);
|
|
417
|
+
case "=":
|
|
418
|
+
return e === String(r);
|
|
419
|
+
case "≠":
|
|
420
|
+
return e !== String(r);
|
|
421
|
+
case "greater":
|
|
422
|
+
return F(e, r, (i, d) => i > d);
|
|
423
|
+
case "greaterEqual":
|
|
424
|
+
return F(e, r, (i, d) => i >= d);
|
|
425
|
+
case "less":
|
|
426
|
+
return F(e, r, (i, d) => i < d);
|
|
427
|
+
case "lessEqual":
|
|
428
|
+
return F(e, r, (i, d) => i <= d);
|
|
429
|
+
case "isNumber":
|
|
430
|
+
return v(e) !== null;
|
|
431
|
+
case "isNotNumber":
|
|
432
|
+
return v(e) === null;
|
|
433
|
+
default:
|
|
434
|
+
return !1;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
function me(e) {
|
|
438
|
+
const t = M(e.attrs.value), n = m(e);
|
|
439
|
+
return t === "" || g.has(n) && t === M(g.get(n)) ? !0 : ye(e).has(t);
|
|
440
|
+
}
|
|
441
|
+
function ye(e) {
|
|
442
|
+
const t = /* @__PURE__ */ new Set();
|
|
443
|
+
for (const n of C(e.attrs.rules))
|
|
444
|
+
for (const r of D(n))
|
|
445
|
+
r.result.type !== "math" && t.add(String(r.result.value ?? ""));
|
|
446
|
+
return t;
|
|
447
|
+
}
|
|
448
|
+
function we(e) {
|
|
449
|
+
const t = /* @__PURE__ */ new Set();
|
|
450
|
+
for (const n of C(e.attrs.rules))
|
|
451
|
+
for (const r of D(n)) {
|
|
452
|
+
for (const u of Z(r))
|
|
453
|
+
for (const i of K(u.inputSerialMath)) {
|
|
454
|
+
const d = z(e.attrs.templateId, e.attrs.batchId, i);
|
|
455
|
+
d && t.add(d);
|
|
456
|
+
}
|
|
457
|
+
if (r.result.type === "math")
|
|
458
|
+
for (const u of K(r.result.value)) {
|
|
459
|
+
const i = z(e.attrs.templateId, e.attrs.batchId, u);
|
|
460
|
+
i && t.add(i);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return t;
|
|
464
|
+
}
|
|
465
|
+
function I(e, t, n) {
|
|
466
|
+
var r;
|
|
467
|
+
P > 0 || (e.warn(be, t, n), (r = o.onWarning) == null || r.call(o, { message: t, detail: n }));
|
|
468
|
+
}
|
|
469
|
+
return re;
|
|
470
|
+
}
|
|
471
|
+
function C(o) {
|
|
472
|
+
return Array.isArray(o) ? o : [];
|
|
473
|
+
}
|
|
474
|
+
function D(o) {
|
|
475
|
+
return o.contents ?? o.list ?? [];
|
|
476
|
+
}
|
|
477
|
+
function Z(o) {
|
|
478
|
+
return o.premises ?? o.premiss ?? [];
|
|
479
|
+
}
|
|
480
|
+
function K(o) {
|
|
481
|
+
return Array.from(o.matchAll(Ie), (l) => l[1].trim()).filter(Boolean);
|
|
482
|
+
}
|
|
483
|
+
function b(o) {
|
|
484
|
+
return z(o.attrs.templateId, o.attrs.batchId, o.attrs.widgetNumber);
|
|
485
|
+
}
|
|
486
|
+
function z(o, l, s) {
|
|
487
|
+
const a = O(o), c = O(l), f = ve(s);
|
|
488
|
+
if (!(!a || !c || !f))
|
|
489
|
+
return `${a}_${c}_${f}`;
|
|
490
|
+
}
|
|
491
|
+
function O(o) {
|
|
492
|
+
return o == null ? void 0 : String(o).trim() || void 0;
|
|
493
|
+
}
|
|
494
|
+
function ve(o) {
|
|
495
|
+
const l = O(o);
|
|
496
|
+
if (!l)
|
|
497
|
+
return;
|
|
498
|
+
const s = l.match(/^【\s*([^】]+?)\s*】$/);
|
|
499
|
+
return ((s == null ? void 0 : s[1]) ?? l).trim() || void 0;
|
|
500
|
+
}
|
|
501
|
+
function Se(o) {
|
|
502
|
+
switch (o) {
|
|
503
|
+
case ">":
|
|
504
|
+
return "greater";
|
|
505
|
+
case ">=":
|
|
506
|
+
return "greaterEqual";
|
|
507
|
+
case "<":
|
|
508
|
+
return "less";
|
|
509
|
+
case "<=":
|
|
510
|
+
return "lessEqual";
|
|
511
|
+
default:
|
|
512
|
+
return o;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
function M(o) {
|
|
516
|
+
return o == null ? "" : String(o);
|
|
517
|
+
}
|
|
518
|
+
function V(o, l) {
|
|
519
|
+
if (Array.isArray(o))
|
|
520
|
+
return o.map((s) => String(s)).includes(l);
|
|
521
|
+
if (typeof o == "string") {
|
|
522
|
+
const s = o.trim();
|
|
523
|
+
if (s.startsWith("["))
|
|
524
|
+
try {
|
|
525
|
+
const a = JSON.parse(s);
|
|
526
|
+
return Array.isArray(a) && a.map((c) => String(c)).includes(l);
|
|
527
|
+
} catch {
|
|
528
|
+
return o.includes(l);
|
|
529
|
+
}
|
|
530
|
+
return o.includes(l);
|
|
531
|
+
}
|
|
532
|
+
return !1;
|
|
533
|
+
}
|
|
534
|
+
function x(o, l) {
|
|
535
|
+
const s = v(o), a = v(l.number1), c = v(l.number2);
|
|
536
|
+
if (s === null || a === null || c === null)
|
|
537
|
+
return !1;
|
|
538
|
+
const f = l.symbol1 ?? "greaterEqual", g = l.symbol2 ?? "lessEqual", h = f === "greater" ? s > a : s >= a, w = g === "less" ? s < c : s <= c;
|
|
539
|
+
return h && w;
|
|
540
|
+
}
|
|
541
|
+
function F(o, l, s) {
|
|
542
|
+
const a = v(o), c = v(l);
|
|
543
|
+
return a !== null && c !== null && s(a, c);
|
|
544
|
+
}
|
|
545
|
+
function v(o) {
|
|
546
|
+
if (o == null || typeof o == "string" && o.trim() === "")
|
|
547
|
+
return null;
|
|
548
|
+
const l = Number(o);
|
|
549
|
+
return Number.isFinite(l) ? l : null;
|
|
550
|
+
}
|
|
551
|
+
function Te(o) {
|
|
552
|
+
return o === "2" || o === "3" ? o : "1";
|
|
553
|
+
}
|
|
554
|
+
function Ee(o, l, s) {
|
|
555
|
+
const a = 10 ** s;
|
|
556
|
+
switch (l) {
|
|
557
|
+
case "2":
|
|
558
|
+
return Math.ceil(o * a) / a;
|
|
559
|
+
case "3":
|
|
560
|
+
return Math.floor(o * a) / a;
|
|
561
|
+
default:
|
|
562
|
+
return Math.round(o * a) / a;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
function ee(o) {
|
|
566
|
+
const l = Re(o), s = [], a = [], c = () => {
|
|
567
|
+
const f = a.pop();
|
|
568
|
+
if (!f)
|
|
569
|
+
throw new Error("Formula operator stack is empty.");
|
|
570
|
+
if (f === "u-") {
|
|
571
|
+
const w = s.pop();
|
|
572
|
+
if (w === void 0)
|
|
573
|
+
throw new Error("Formula unary operand is missing.");
|
|
574
|
+
s.push(-w);
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
const g = s.pop(), h = s.pop();
|
|
578
|
+
if (h === void 0 || g === void 0)
|
|
579
|
+
throw new Error("Formula operand is missing.");
|
|
580
|
+
switch (f) {
|
|
581
|
+
case "+":
|
|
582
|
+
s.push(h + g);
|
|
583
|
+
return;
|
|
584
|
+
case "-":
|
|
585
|
+
s.push(h - g);
|
|
586
|
+
return;
|
|
587
|
+
case "*":
|
|
588
|
+
s.push(h * g);
|
|
589
|
+
return;
|
|
590
|
+
case "/":
|
|
591
|
+
s.push(h / g);
|
|
592
|
+
return;
|
|
593
|
+
default:
|
|
594
|
+
throw new Error(`Unsupported formula operator: ${f}.`);
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
for (const f of l) {
|
|
598
|
+
if (typeof f == "number") {
|
|
599
|
+
s.push(f);
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
if (f === "(") {
|
|
603
|
+
a.push(f);
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
606
|
+
if (f === ")") {
|
|
607
|
+
for (; a.length > 0 && a[a.length - 1] !== "("; )
|
|
608
|
+
c();
|
|
609
|
+
if (a.pop() !== "(")
|
|
610
|
+
throw new Error("Formula parentheses are not balanced.");
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
for (; a.length > 0 && a[a.length - 1] !== "(" && te(a[a.length - 1]) >= te(f); )
|
|
614
|
+
c();
|
|
615
|
+
a.push(f);
|
|
616
|
+
}
|
|
617
|
+
for (; a.length > 0; ) {
|
|
618
|
+
if (a[a.length - 1] === "(")
|
|
619
|
+
throw new Error("Formula parentheses are not balanced.");
|
|
620
|
+
c();
|
|
621
|
+
}
|
|
622
|
+
if (s.length !== 1 || !Number.isFinite(s[0]))
|
|
623
|
+
throw new Error("Formula result is invalid.");
|
|
624
|
+
return s[0];
|
|
625
|
+
}
|
|
626
|
+
function Re(o) {
|
|
627
|
+
const l = [];
|
|
628
|
+
let s = 0, a;
|
|
629
|
+
for (; s < o.length; ) {
|
|
630
|
+
const c = o[s];
|
|
631
|
+
if (/\s/.test(c)) {
|
|
632
|
+
s += 1;
|
|
633
|
+
continue;
|
|
634
|
+
}
|
|
635
|
+
if (c === "(" || c === ")") {
|
|
636
|
+
l.push(c), a = c, s += 1;
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
if ("+-*/".includes(c)) {
|
|
640
|
+
const h = c === "-" && (a === void 0 || typeof a == "string" && a !== ")");
|
|
641
|
+
l.push(h ? "u-" : c), a = h ? "u-" : c, s += 1;
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
const f = o.slice(s).match(/^\d+(?:\.\d+)?|^\.\d+/);
|
|
645
|
+
if (!f)
|
|
646
|
+
throw new Error(`Formula contains unsupported token near: ${o.slice(s)}.`);
|
|
647
|
+
const g = Number(f[0]);
|
|
648
|
+
if (!Number.isFinite(g))
|
|
649
|
+
throw new Error(`Formula number is invalid: ${f[0]}.`);
|
|
650
|
+
l.push(g), a = g, s += f[0].length;
|
|
651
|
+
}
|
|
652
|
+
return l;
|
|
653
|
+
}
|
|
654
|
+
function te(o) {
|
|
655
|
+
return o === "u-" ? 3 : o === "*" || o === "/" ? 2 : o === "+" || o === "-" ? 1 : 0;
|
|
656
|
+
}
|
|
657
|
+
function Ne() {
|
|
658
|
+
const o = globalThis.crypto;
|
|
659
|
+
return o != null && o.randomUUID ? `batch_${o.randomUUID()}` : `batch_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`;
|
|
660
|
+
}
|
|
661
|
+
function ne(o) {
|
|
662
|
+
return (typeof o == "object" || typeof o == "function") && o !== null && "then" in o && typeof o.then == "function";
|
|
663
|
+
}
|
|
664
|
+
function Ce(o) {
|
|
665
|
+
return o.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
666
|
+
}
|
|
667
|
+
export {
|
|
668
|
+
Me as createWidgetRulesPlugin
|
|
669
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hmg-report-editor/rules",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"registry": "https://registry.npmjs.org/"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist/index.cjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "vite build && tsc -p tsconfig.build.json && node ../../scripts/finalize-package-types.mjs .",
|
|
24
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@hmg-report-editor/core": "^1.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|