@claritylabs/cl-sdk 3.0.7 → 3.0.8

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.mjs CHANGED
@@ -9092,6 +9092,18 @@ function endorsementTitle(value) {
9092
9092
  function sourceNodeText(node) {
9093
9093
  return cleanText([node.title, node.description, node.textExcerpt].filter(Boolean).join(" "), "");
9094
9094
  }
9095
+ function looksLikeEndorsementStart(node) {
9096
+ const title = cleanText(node.title, "");
9097
+ const body = cleanText([node.textExcerpt, node.description].filter(Boolean).join(" "), "");
9098
+ const start = body.slice(0, 260);
9099
+ if (/\bthis endorsement changes the policy\b/i.test(start) && endorsementReference(start)) return true;
9100
+ if (/^(?:[A-Z]{2,}-)?END\s+0*[0-9]{1,4}\b/i.test(start)) return true;
9101
+ if (/^endorsement\s+(?:no\.?|number|#)\s*[A-Z0-9][A-Z0-9.-]*\b/i.test(start)) return true;
9102
+ return /^endorsement\s+(?:no\.?|number|#)\s*[A-Z0-9][A-Z0-9.-]*\b/i.test(title) && /\bthis endorsement changes the policy\b/i.test(body);
9103
+ }
9104
+ function endorsementStartTitle(node) {
9105
+ return looksLikeEndorsementStart(node) ? endorsementTitle(sourceNodeText(node)) : void 0;
9106
+ }
9095
9107
  function semanticGroupNodeId(documentId, kind, title, childNodeIds) {
9096
9108
  return [
9097
9109
  documentId.replace(/[^a-zA-Z0-9_.:-]/g, "_"),
@@ -9157,8 +9169,7 @@ function groupAdjacentChildren(params) {
9157
9169
  function applySemanticPageGrouping(sourceTree) {
9158
9170
  const relabeled = sourceTree.map((node) => {
9159
9171
  if (node.kind === "document" || node.kind === "page_group") return node;
9160
- const text = sourceNodeText(node);
9161
- const endorsement = endorsementTitle(text);
9172
+ const endorsement = endorsementStartTitle(node);
9162
9173
  if (endorsement && node.kind === "page") {
9163
9174
  return {
9164
9175
  ...node,
@@ -9194,7 +9205,7 @@ function applySemanticPageGrouping(sourceTree) {
9194
9205
  const declarationIds = [];
9195
9206
  for (let index = declarationsStartIndex; index < children.length; index += 1) {
9196
9207
  const child = children[index];
9197
- if (index > declarationsStartIndex && (looksLikePolicyFormStart(child) || endorsementTitle(sourceNodeText(child)))) break;
9208
+ if (index > declarationsStartIndex && (looksLikePolicyFormStart(child) || looksLikeEndorsementStart(child))) break;
9198
9209
  if (!looksLikeDeclarationsContinuation(child)) break;
9199
9210
  declarationIds.push(child.id);
9200
9211
  }
@@ -9213,7 +9224,7 @@ function applySemanticPageGrouping(sourceTree) {
9213
9224
  const policyIds = [];
9214
9225
  for (let index = policyStartIndex; index < children.length; index += 1) {
9215
9226
  const child = children[index];
9216
- if (index > policyStartIndex && endorsementTitle(sourceNodeText(child))) break;
9227
+ if (index > policyStartIndex && looksLikeEndorsementStart(child)) break;
9217
9228
  if (!looksLikePolicyFormContinuation(child)) break;
9218
9229
  policyIds.push(child.id);
9219
9230
  }
@@ -9252,8 +9263,19 @@ function endorsementGroupNodeId(documentId, parentId) {
9252
9263
  }
9253
9264
  function applyEndorsementGrouping(sourceTree) {
9254
9265
  const relabeledTree = sourceTree.map((node) => {
9255
- if (node.kind === "document" || isEndorsementGroup(node) || node.kind === "endorsement") return node;
9256
- const title = endorsementTitle([node.title, node.description, node.textExcerpt].filter(Boolean).join(" "));
9266
+ if (node.kind === "document" || isEndorsementGroup(node)) return node;
9267
+ const title = endorsementStartTitle(node);
9268
+ if (!title && node.kind === "endorsement") {
9269
+ return {
9270
+ ...node,
9271
+ kind: "page",
9272
+ title: node.pageStart ? `Page ${node.pageStart}` : cleanText(node.title, "Page"),
9273
+ metadata: {
9274
+ ...node.metadata,
9275
+ organizerRepair: "demote_incidental_endorsement_reference"
9276
+ }
9277
+ };
9278
+ }
9257
9279
  if (!title) return node;
9258
9280
  return {
9259
9281
  ...node,
@@ -9293,7 +9315,7 @@ function applyEndorsementGrouping(sourceTree) {
9293
9315
  });
9294
9316
  nextTree = nextTree.map((node) => {
9295
9317
  if (!endorsementGroupIds.has(node.parentId ?? "")) return node;
9296
- const title = endorsementTitle([node.title, node.description, node.textExcerpt].filter(Boolean).join(" "));
9318
+ const title = endorsementStartTitle(node);
9297
9319
  if (!title) return node;
9298
9320
  return {
9299
9321
  ...node,