@marvalt/wadapter 2.3.5 → 2.3.7

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.
@@ -16,10 +16,11 @@
16
16
  */
17
17
  import { GravityFormsConfig, GravityForm, GravityFormSubmission, GravityFormSubmissionResult } from '../types/gravity-forms';
18
18
  export declare class GravityFormsClient {
19
+ private proxyEndpoint;
19
20
  private config;
21
+ private useDirectMode;
20
22
  constructor(config: GravityFormsConfig);
21
23
  private makeRequest;
22
- private getBaseUrl;
23
24
  getForm(id: number): Promise<GravityForm>;
24
25
  getForms(): Promise<GravityForm[]>;
25
26
  getFormConfig(id: number): Promise<GravityForm>;
@@ -1 +1 @@
1
- {"version":3,"file":"gravity-forms-client.d.ts","sourceRoot":"","sources":["../../src/gravity-forms/gravity-forms-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAE7H,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAqB;gBAEvB,MAAM,EAAE,kBAAkB;YAIxB,WAAW;IAuDzB,OAAO,CAAC,UAAU;IASZ,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAYzC,QAAQ,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAUlC,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAU/C,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAUnG,SAAS,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC;CAM1F"}
1
+ {"version":3,"file":"gravity-forms-client.d.ts","sourceRoot":"","sources":["../../src/gravity-forms/gravity-forms-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAE7H,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,aAAa,CAAU;gBAEnB,MAAM,EAAE,kBAAkB;YAUxB,WAAW;IAsDnB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAMzC,QAAQ,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAMlC,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAM/C,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAiBnG,SAAS,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC;CAI1F"}
package/dist/index.d.ts CHANGED
@@ -545,6 +545,7 @@ interface GravityFormSubmission {
545
545
  source_page_confirmations?: any;
546
546
  target_page_number?: number;
547
547
  target_page_confirmations?: any;
548
+ headers?: Record<string, string>;
548
549
  }
549
550
  interface GravityFormSubmissionResult {
550
551
  success: boolean;
@@ -588,10 +589,11 @@ interface GravityFormsConfig {
588
589
  */
589
590
 
590
591
  declare class GravityFormsClient {
592
+ private proxyEndpoint;
591
593
  private config;
594
+ private useDirectMode;
592
595
  constructor(config: GravityFormsConfig);
593
596
  private makeRequest;
594
- private getBaseUrl;
595
597
  getForm(id: number): Promise<GravityForm$1>;
596
598
  getForms(): Promise<GravityForm$1[]>;
597
599
  getFormConfig(id: number): Promise<GravityForm$1>;
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import require$$0, { useState, useEffect, useCallback, createContext, useContext } from 'react';
1
+ import require$$0, { useState, useEffect, useCallback, useRef, useMemo, createContext, useContext } from 'react';
2
2
  import { writeFileSync } from 'fs';
3
3
  import { join } from 'path';
4
4
 
@@ -265,32 +265,35 @@ function transformWordPressMediaItems(media) {
265
265
  class GravityFormsClient {
266
266
  constructor(config) {
267
267
  this.config = config;
268
+ // Determine mode: direct for generators (Node.js), proxy for browser
269
+ this.useDirectMode = config.authMode === 'direct' && !!(config.username && config.password);
270
+ // Convention-based: Always use /api/gravity-forms-submit unless explicitly overridden
271
+ this.proxyEndpoint = config.proxyEndpoint || '/api/gravity-forms-submit';
268
272
  }
269
273
  async makeRequest(endpoint, options = {}) {
270
- // Construct URL based on auth mode
271
274
  let url;
272
- if (this.config.authMode === 'cloudflare_proxy') {
273
- // For proxy modes, pass the full REST path including /wp-json as query parameter
274
- const baseUrl = this.getBaseUrl();
275
- const fullEndpoint = `/wp-json${endpoint}`;
276
- url = `${baseUrl}?endpoint=${encodeURIComponent(fullEndpoint)}`;
277
- }
278
- else {
279
- // For direct mode, construct the full API URL
280
- url = `${this.config.apiUrl}${endpoint}`;
281
- }
282
275
  const headers = {
283
276
  'Content-Type': 'application/json',
284
277
  ...options.headers,
285
278
  };
286
- // Add authentication based on mode
287
- if (this.config.authMode === 'cloudflare_proxy') ;
288
- else {
289
- // Direct mode - use basic auth
279
+ if (this.useDirectMode) {
280
+ // Direct mode: Call WordPress API directly (for generators/Node.js)
281
+ url = `${this.config.apiUrl}${endpoint}`;
282
+ // Add Basic Auth
290
283
  if (this.config.username && this.config.password) {
291
284
  const credentials = btoa(`${this.config.username}:${this.config.password}`);
292
- headers.Authorization = `Basic ${credentials}`;
285
+ headers['Authorization'] = `Basic ${credentials}`;
293
286
  }
287
+ // Add CF Access headers if provided
288
+ if (this.config.cfAccessClientId && this.config.cfAccessClientSecret) {
289
+ headers['CF-Access-Client-Id'] = this.config.cfAccessClientId;
290
+ headers['CF-Access-Client-Secret'] = this.config.cfAccessClientSecret;
291
+ }
292
+ }
293
+ else {
294
+ // Proxy mode: Use Pages Function (for browser)
295
+ const proxyEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
296
+ url = `${this.proxyEndpoint}?endpoint=${encodeURIComponent(proxyEndpoint)}`;
294
297
  }
295
298
  const response = await fetch(url, {
296
299
  ...options,
@@ -315,56 +318,37 @@ class GravityFormsClient {
315
318
  throw new Error(`Failed to parse JSON response: ${error.message}`);
316
319
  }
317
320
  }
318
- getBaseUrl() {
319
- switch (this.config.authMode) {
320
- case 'cloudflare_proxy':
321
- return this.config.cloudflareWorkerUrl || '';
322
- default:
323
- return this.config.apiUrl || '';
324
- }
325
- }
326
321
  async getForm(id) {
327
- // If using custom endpoint (gf-api plugin), use it for both modes
328
- // Otherwise: proxy uses gf-api/v1, direct uses official gf/v2
329
- const useCustom = this.config.useCustomEndpoint;
330
- const endpoint = useCustom
331
- ? `/forms/${id}` // apiUrl already includes /wp-json/gf-api/v1
332
- : (this.config.authMode === 'cloudflare_proxy'
333
- ? `/gf-api/v1/forms/${id}`
334
- : `/wp-json/gf/v2/forms/${id}`);
322
+ // Always use custom gf-api/v1 endpoint (from custom plugin)
323
+ const endpoint = `/forms/${id}`;
335
324
  return this.makeRequest(endpoint);
336
325
  }
337
326
  async getForms() {
338
- const useCustom = this.config.useCustomEndpoint;
339
- const endpoint = useCustom
340
- ? '/forms' // apiUrl already includes /wp-json/gf-api/v1
341
- : (this.config.authMode === 'cloudflare_proxy'
342
- ? '/gf-api/v1/forms'
343
- : '/wp-json/gf/v2/forms');
327
+ // Always use custom gf-api/v1 endpoint (from custom plugin)
328
+ const endpoint = '/forms';
344
329
  return this.makeRequest(endpoint);
345
330
  }
346
331
  async getFormConfig(id) {
347
- const useCustom = this.config.useCustomEndpoint;
348
- const endpoint = useCustom
349
- ? `/forms/${id}/config` // apiUrl already includes /wp-json/gf-api/v1
350
- : (this.config.authMode === 'cloudflare_proxy'
351
- ? `/gf-api/v1/forms/${id}/config`
352
- : `/wp-json/gf/v2/forms/${id}`); // v2 returns full form including settings
332
+ // Always use custom gf-api/v1 endpoint (from custom plugin)
333
+ const endpoint = `/forms/${id}/config`;
353
334
  return this.makeRequest(endpoint);
354
335
  }
355
336
  async submitForm(formId, submission) {
356
- const endpoint = this.config.authMode === 'cloudflare_proxy'
357
- ? `/gf-api/v1/forms/${formId}/submit`
358
- : `/wp-json/gf/v2/forms/${formId}/submissions`; // official GF REST v2 submissions
337
+ // Always use custom gf-api/v1 submit endpoint (from custom plugin)
338
+ const endpoint = `/forms/${formId}/submit`;
339
+ // Merge custom headers (e.g., Turnstile token) with default headers
340
+ const headers = {
341
+ 'Content-Type': 'application/json',
342
+ ...(submission.headers || {}),
343
+ };
359
344
  return this.makeRequest(endpoint, {
360
345
  method: 'POST',
361
- body: JSON.stringify(submission),
346
+ headers,
347
+ body: JSON.stringify(submission.field_values),
362
348
  });
363
349
  }
364
350
  async getHealth() {
365
- const endpoint = this.config.authMode === 'cloudflare_proxy'
366
- ? '/gf-api/v1/health'
367
- : '/wp-json/gf/v2/health';
351
+ const endpoint = '/health';
368
352
  return this.makeRequest(endpoint);
369
353
  }
370
354
  }
@@ -1932,15 +1916,115 @@ const WordPressContent = ({ content, className = '', showExcerpt = false, showDa
1932
1916
  return (jsxRuntimeExports.jsxs("article", { className: `wordpress-content ${className}`, children: [jsxRuntimeExports.jsxs("header", { className: "content-header", children: [jsxRuntimeExports.jsx("h1", { className: "content-title", dangerouslySetInnerHTML: { __html: content.title.rendered } }), showDate && (jsxRuntimeExports.jsx("time", { className: "content-date", dateTime: content.date, children: new Date(content.date).toLocaleDateString() })), showAuthor && 'author' in content && (jsxRuntimeExports.jsxs("span", { className: "content-author", children: ["Author ID: ", content.author] }))] }), showExcerpt && content.excerpt && (jsxRuntimeExports.jsx("div", { className: "content-excerpt", dangerouslySetInnerHTML: { __html: content.excerpt.rendered } })), jsxRuntimeExports.jsx("div", { className: "content-body", dangerouslySetInnerHTML: { __html: content.content.rendered } })] }));
1933
1917
  };
1934
1918
 
1919
+ const TurnstileWidget = ({ siteKey, action, cData, onSuccess, onError, onExpire, theme = 'auto', size = 'normal', tabIndex, }) => {
1920
+ const widgetRef = useRef(null);
1921
+ const widgetId = useRef(null);
1922
+ const scriptLoaded = useRef(false);
1923
+ useEffect(() => {
1924
+ if (!widgetRef.current || !siteKey)
1925
+ return;
1926
+ const loadTurnstile = () => {
1927
+ if (window.turnstile && widgetRef.current && !widgetId.current) {
1928
+ try {
1929
+ widgetId.current = window.turnstile.render(widgetRef.current, {
1930
+ sitekey: siteKey,
1931
+ callback: onSuccess,
1932
+ 'error-callback': onError,
1933
+ 'expired-callback': onExpire,
1934
+ theme,
1935
+ size,
1936
+ tabindex: tabIndex,
1937
+ });
1938
+ }
1939
+ catch (error) {
1940
+ console.error('Failed to render Turnstile widget:', error);
1941
+ onError?.();
1942
+ }
1943
+ }
1944
+ };
1945
+ // Check if Turnstile is already loaded
1946
+ if (window.turnstile) {
1947
+ loadTurnstile();
1948
+ }
1949
+ else if (!scriptLoaded.current) {
1950
+ // Load Turnstile script
1951
+ scriptLoaded.current = true;
1952
+ const script = document.createElement('script');
1953
+ script.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js';
1954
+ script.async = true;
1955
+ script.defer = true;
1956
+ script.onload = loadTurnstile;
1957
+ script.onerror = () => {
1958
+ console.error('Failed to load Turnstile script');
1959
+ onError?.();
1960
+ };
1961
+ document.head.appendChild(script);
1962
+ }
1963
+ return () => {
1964
+ if (widgetId.current && window.turnstile) {
1965
+ try {
1966
+ window.turnstile.remove(widgetId.current);
1967
+ }
1968
+ catch (error) {
1969
+ console.error('Failed to remove Turnstile widget:', error);
1970
+ }
1971
+ widgetId.current = null;
1972
+ }
1973
+ };
1974
+ }, [siteKey, onSuccess, onError, onExpire, theme, size, tabIndex]);
1975
+ return jsxRuntimeExports.jsx("div", { ref: widgetRef, className: "cf-turnstile" });
1976
+ };
1977
+
1935
1978
  const GravityForm = ({ formId, config, className = '', onSubmit, onError, }) => {
1936
1979
  const { form, loading, error, submitting, result, submitForm } = useGravityForms(formId, config);
1937
1980
  const [formData, setFormData] = useState({});
1981
+ const [turnstileToken, setTurnstileToken] = useState(null);
1982
+ const [turnstileError, setTurnstileError] = useState(null);
1983
+ // Get Turnstile site key from environment - memoized to prevent re-renders
1984
+ const turnstilesiteKey = useMemo(() => {
1985
+ try {
1986
+ // @ts-ignore - import.meta is a Vite-specific global
1987
+ if (typeof import.meta !== 'undefined' && import.meta.env) {
1988
+ // @ts-ignore
1989
+ const key = import.meta.env.VITE_TURNSTILE_SITE_KEY;
1990
+ // Ensure we return a string or undefined, not an object
1991
+ return typeof key === 'string' ? key : undefined;
1992
+ }
1993
+ }
1994
+ catch (e) {
1995
+ // import.meta not available
1996
+ }
1997
+ return undefined;
1998
+ }, []); // Empty deps - site key doesn't change during runtime
1999
+ // Memoize Turnstile callbacks to prevent widget re-renders
2000
+ const handleTurnstileSuccess = useCallback((token) => {
2001
+ setTurnstileToken(token);
2002
+ setTurnstileError(null);
2003
+ }, []);
2004
+ const handleTurnstileError = useCallback(() => {
2005
+ setTurnstileToken(null);
2006
+ setTurnstileError('Verification failed. Please try again.');
2007
+ }, []);
2008
+ const handleTurnstileExpire = useCallback(() => {
2009
+ setTurnstileToken(null);
2010
+ setTurnstileError('Verification expired. Please verify again.');
2011
+ }, []);
1938
2012
  const handleSubmit = async (e) => {
1939
2013
  e.preventDefault();
2014
+ // Check Turnstile token if enabled
2015
+ if (turnstilesiteKey && !turnstileToken) {
2016
+ setTurnstileError('Please complete the verification');
2017
+ return;
2018
+ }
1940
2019
  try {
1941
2020
  const submission = {
1942
2021
  form_id: formId,
1943
2022
  field_values: formData,
2023
+ ...(turnstileToken ? {
2024
+ headers: {
2025
+ 'cf-turnstile-response': turnstileToken
2026
+ }
2027
+ } : {})
1944
2028
  };
1945
2029
  await submitForm(submission);
1946
2030
  if (onSubmit && result) {
@@ -1968,7 +2052,11 @@ const GravityForm = ({ formId, config, className = '', onSubmit, onError, }) =>
1968
2052
  if (!form) {
1969
2053
  return jsxRuntimeExports.jsx("div", { className: `gravity-form not-found ${className}`, children: "Form not found" });
1970
2054
  }
1971
- return (jsxRuntimeExports.jsx("div", { className: `gravity-form ${className}`, children: jsxRuntimeExports.jsxs("form", { onSubmit: handleSubmit, children: [jsxRuntimeExports.jsx("h2", { children: form.title }), form.description && jsxRuntimeExports.jsx("p", { children: form.description }), form.fields.map(field => (jsxRuntimeExports.jsxs("div", { className: `field field-${field.type}`, children: [jsxRuntimeExports.jsxs("label", { htmlFor: `field_${field.id}`, children: [field.label, field.required && jsxRuntimeExports.jsx("span", { className: "required", children: "*" })] }), field.description && (jsxRuntimeExports.jsx("p", { className: "field-description", children: field.description })), field.type === 'text' && (jsxRuntimeExports.jsx("input", { type: "text", id: `field_${field.id}`, name: field.label, required: field.required, placeholder: field.placeholder, onChange: (e) => handleFieldChange(field.id.toString(), e.target.value) })), field.type === 'email' && (jsxRuntimeExports.jsx("input", { type: "email", id: `field_${field.id}`, name: field.label, required: field.required, placeholder: field.placeholder, onChange: (e) => handleFieldChange(field.id.toString(), e.target.value) })), field.type === 'textarea' && (jsxRuntimeExports.jsx("textarea", { id: `field_${field.id}`, name: field.label, required: field.required, placeholder: field.placeholder, onChange: (e) => handleFieldChange(field.id.toString(), e.target.value) })), field.type === 'select' && field.choices && (jsxRuntimeExports.jsxs("select", { id: `field_${field.id}`, name: field.label, required: field.required, onChange: (e) => handleFieldChange(field.id.toString(), e.target.value), children: [jsxRuntimeExports.jsx("option", { value: "", children: "Select an option" }), field.choices.map((choice, index) => (jsxRuntimeExports.jsx("option", { value: choice.value, children: choice.text }, index)))] }))] }, field.id))), jsxRuntimeExports.jsx("button", { type: "submit", disabled: submitting, children: submitting ? 'Submitting...' : 'Submit' }), result && (jsxRuntimeExports.jsx("div", { className: `result ${result.success ? 'success' : 'error'}`, children: result.message }))] }) }));
2055
+ return (jsxRuntimeExports.jsx("div", { className: `gravity-form ${className}`, children: jsxRuntimeExports.jsxs("form", { onSubmit: handleSubmit, children: [jsxRuntimeExports.jsx("h2", { children: form.title }), form.description && jsxRuntimeExports.jsx("p", { children: form.description }), form.fields.map(field => (jsxRuntimeExports.jsxs("div", { className: `field field-${field.type}`, children: [jsxRuntimeExports.jsxs("label", { htmlFor: `field_${field.id}`, children: [field.label, field.required && jsxRuntimeExports.jsx("span", { className: "required", children: "*" })] }), field.description && (jsxRuntimeExports.jsx("p", { className: "field-description", children: field.description })), field.type === 'text' && (jsxRuntimeExports.jsx("input", { type: "text", id: `field_${field.id}`, name: field.label, required: field.required, placeholder: field.placeholder, onChange: (e) => handleFieldChange(field.id.toString(), e.target.value) })), field.type === 'email' && (jsxRuntimeExports.jsx("input", { type: "email", id: `field_${field.id}`, name: field.label, required: field.required, placeholder: field.placeholder, onChange: (e) => handleFieldChange(field.id.toString(), e.target.value) })), field.type === 'textarea' && (jsxRuntimeExports.jsx("textarea", { id: `field_${field.id}`, name: field.label, required: field.required, placeholder: field.placeholder, onChange: (e) => handleFieldChange(field.id.toString(), e.target.value) })), field.type === 'select' && field.choices && (jsxRuntimeExports.jsxs("select", { id: `field_${field.id}`, name: field.label, required: field.required, onChange: (e) => handleFieldChange(field.id.toString(), e.target.value), children: [jsxRuntimeExports.jsx("option", { value: "", children: "Select an option" }), field.choices.map((choice, index) => (jsxRuntimeExports.jsx("option", { value: choice.value, children: choice.text }, index)))] }))] }, field.id))), turnstilesiteKey && (jsxRuntimeExports.jsxs("div", { className: "form-turnstile", children: [jsxRuntimeExports.jsx(TurnstileWidget, { siteKey: turnstilesiteKey, onSuccess: handleTurnstileSuccess, onError: handleTurnstileError, onExpire: handleTurnstileExpire, theme: "auto", size: "normal" }), turnstileError && (jsxRuntimeExports.jsx("p", { className: "field-error turnstile-error", children: turnstileError }))] })), jsxRuntimeExports.jsx("button", { type: "submit", disabled: submitting || (!!turnstilesiteKey && !turnstileToken), children: submitting
2056
+ ? 'Submitting...'
2057
+ : (turnstilesiteKey && !turnstileToken)
2058
+ ? 'Complete verification first'
2059
+ : 'Submit' }), result && (jsxRuntimeExports.jsx("div", { className: `result ${result.success ? 'success' : 'error'}`, children: result.message }))] }) }));
1972
2060
  };
1973
2061
 
1974
2062
  const WordPressContext = createContext(undefined);
@@ -2091,7 +2179,7 @@ function getFormById(id) {
2091
2179
  return (gravityFormsStaticData?.forms ?? []).find(f => String(f.id) === key);
2092
2180
  }
2093
2181
 
2094
- let document;
2182
+ let document$1;
2095
2183
  let offset;
2096
2184
  let output;
2097
2185
  let stack;
@@ -2118,7 +2206,7 @@ function Frame(block, tokenStart, tokenLength, prevOffset, leadingHtmlStart) {
2118
2206
  };
2119
2207
  }
2120
2208
  const parse = (doc) => {
2121
- document = doc;
2209
+ document$1 = doc;
2122
2210
  offset = 0;
2123
2211
  output = [];
2124
2212
  stack = [];
@@ -2151,7 +2239,7 @@ function proceed() {
2151
2239
  if (null !== leadingHtmlStart) {
2152
2240
  output.push(
2153
2241
  Freeform(
2154
- document.substr(
2242
+ document$1.substr(
2155
2243
  leadingHtmlStart,
2156
2244
  startOffset - leadingHtmlStart
2157
2245
  )
@@ -2192,7 +2280,7 @@ function proceed() {
2192
2280
  return true;
2193
2281
  }
2194
2282
  const stackTop = stack.pop();
2195
- const html = document.substr(
2283
+ const html = document$1.substr(
2196
2284
  stackTop.prevOffset,
2197
2285
  startOffset - stackTop.prevOffset
2198
2286
  );
@@ -2220,7 +2308,7 @@ function parseJSON(input) {
2220
2308
  }
2221
2309
  }
2222
2310
  function nextToken() {
2223
- const matches = tokenizer.exec(document);
2311
+ const matches = tokenizer.exec(document$1);
2224
2312
  if (null === matches) {
2225
2313
  return ["no-more-tokens", "", null, 0, 0];
2226
2314
  }
@@ -2250,16 +2338,16 @@ function nextToken() {
2250
2338
  return ["block-opener", name, attrs, startedAt, length];
2251
2339
  }
2252
2340
  function addFreeform(rawLength) {
2253
- const length = document.length - offset;
2341
+ const length = document$1.length - offset;
2254
2342
  if (0 === length) {
2255
2343
  return;
2256
2344
  }
2257
- output.push(Freeform(document.substr(offset, length)));
2345
+ output.push(Freeform(document$1.substr(offset, length)));
2258
2346
  }
2259
2347
  function addInnerBlock(block, tokenStart, tokenLength, lastOffset) {
2260
2348
  const parent = stack[stack.length - 1];
2261
2349
  parent.block.innerBlocks.push(block);
2262
- const html = document.substr(
2350
+ const html = document$1.substr(
2263
2351
  parent.prevOffset,
2264
2352
  tokenStart - parent.prevOffset
2265
2353
  );
@@ -2272,7 +2360,7 @@ function addInnerBlock(block, tokenStart, tokenLength, lastOffset) {
2272
2360
  }
2273
2361
  function addBlockFromStack(endOffset) {
2274
2362
  const { block, leadingHtmlStart, prevOffset, tokenStart } = stack.pop();
2275
- const html = endOffset ? document.substr(prevOffset, endOffset - prevOffset) : document.substr(prevOffset);
2363
+ const html = endOffset ? document$1.substr(prevOffset, endOffset - prevOffset) : document$1.substr(prevOffset);
2276
2364
  if (html) {
2277
2365
  block.innerHTML += html;
2278
2366
  block.innerContent.push(html);
@@ -2280,7 +2368,7 @@ function addBlockFromStack(endOffset) {
2280
2368
  if (null !== leadingHtmlStart) {
2281
2369
  output.push(
2282
2370
  Freeform(
2283
- document.substr(
2371
+ document$1.substr(
2284
2372
  leadingHtmlStart,
2285
2373
  tokenStart - leadingHtmlStart
2286
2374
  )